2 * IWineD3DCubeTexture implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wined3d_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
27 #define GLINFO_LOCATION ((IWineD3DImpl *)(((IWineD3DDeviceImpl *)This->resource.wineD3DDevice)->wineD3D))->gl_info
29 static const GLenum cube_targets[6] = {
30 #if defined(GL_VERSION_1_3)
31 GL_TEXTURE_CUBE_MAP_POSITIVE_X,
32 GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
33 GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
34 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
35 GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
36 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
38 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
39 GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
40 GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
41 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
42 GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
43 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
47 /* *******************************************
48 IWineD3DCubeTexture IUnknown parts follow
49 ******************************************* */
50 HRESULT WINAPI IWineD3DCubeTextureImpl_QueryInterface(IWineD3DCubeTexture *iface, REFIID riid, LPVOID *ppobj)
52 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
53 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
54 if (IsEqualGUID(riid, &IID_IUnknown)
55 || IsEqualGUID(riid, &IID_IWineD3DResource)
56 || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)
57 || IsEqualGUID(riid, &IID_IWineD3DTexture)) {
58 IUnknown_AddRef(iface);
65 ULONG WINAPI IWineD3DCubeTextureImpl_AddRef(IWineD3DCubeTexture *iface) {
66 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
67 TRACE("(%p) : AddRef increasing from %ld\n", This, This->resource.ref);
68 IUnknown_AddRef(This->resource.parent);
69 return InterlockedIncrement(&This->resource.ref);
72 ULONG WINAPI IWineD3DCubeTextureImpl_Release(IWineD3DCubeTexture *iface) {
73 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
75 TRACE("(%p) : Releasing from %ld\n", This, This->resource.ref);
76 ref = InterlockedDecrement(&This->resource.ref);
79 for (i = 0; i < This->baseTexture.levels; i++) {
80 for (j = 0; j < 6; j++) {
81 if (This->surfaces[j][i] != NULL) {
82 TRACE("(%p) : Releasing surface%d %d %p\n", This, j, i, This->surfaces[j][i]);
83 IWineD3DSurface_Release((IWineD3DSurface *) This->surfaces[j][i]);
87 if(This->baseTexture.textureName != 0){
89 TRACE("Deleting texture %d\n", This->baseTexture.textureName);
90 glDeleteTextures(1, &This->baseTexture.textureName);
93 HeapFree(GetProcessHeap(), 0, This);
95 IUnknown_Release(This->resource.parent); /* Released the reference to the d3dx object */
100 /* ****************************************************
101 IWineD3DCubeTexture IWineD3DResource parts follow
102 **************************************************** */
103 HRESULT WINAPI IWineD3DCubeTextureImpl_GetDevice(IWineD3DCubeTexture *iface, IWineD3DDevice** ppDevice) {
104 return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
107 HRESULT WINAPI IWineD3DCubeTextureImpl_SetPrivateData(IWineD3DCubeTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
108 return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
111 HRESULT WINAPI IWineD3DCubeTextureImpl_GetPrivateData(IWineD3DCubeTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
112 return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
115 HRESULT WINAPI IWineD3DCubeTextureImpl_FreePrivateData(IWineD3DCubeTexture *iface, REFGUID refguid) {
116 return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
119 DWORD WINAPI IWineD3DCubeTextureImpl_SetPriority(IWineD3DCubeTexture *iface, DWORD PriorityNew) {
120 return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
123 DWORD WINAPI IWineD3DCubeTextureImpl_GetPriority(IWineD3DCubeTexture *iface) {
124 return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
127 void WINAPI IWineD3DCubeTextureImpl_PreLoad(IWineD3DCubeTexture *iface) {
128 /* Override the IWineD3DResource Preload method */
130 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
132 TRACE("(%p) : About to load texture: dirtified(%d)\n", This, This->baseTexture.dirty);
135 #if 0 /* TODO: context manager support */
136 IWineD3DContextManager_PushState(This->contextManager, GL_TEXTURE_CUBE_MAP_ARB, ENABLED, NOW /* make sure the state is applied now */);
138 glEnable(GL_TEXTURE_CUBE_MAP_ARB);
141 /* Generate a texture name if we don't already have one */
142 if (This->baseTexture.textureName == 0) {
143 glGenTextures(1, &This->baseTexture.textureName);
144 checkGLcall("glGenTextures");
145 TRACE("Generated texture %d\n", This->baseTexture.textureName);
146 if (This->baseTexture.pool == D3DPOOL_DEFAULT) {
147 /* Tell opengl to try and keep this texture in video ram (well mostly) */
150 glPrioritizeTextures(1, &This->baseTexture.textureName, &tmp);
154 /* Bind the texture */
155 if (This->baseTexture.textureName != 0) {
156 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, This->baseTexture.textureName);
157 checkGLcall("glBindTexture");
158 } else { /* this only happened if we've run out of openGL textures */
159 WARN("This texture doesn't have an openGL texture assigned to it\n");
163 /* If were dirty then reload the surfaces */
164 if(This->baseTexture.dirty != FALSE) {
165 for (i = 0; i < This->baseTexture.levels; i++) {
166 for (j = 0; j < 6; j++)
167 IWineD3DSurface_LoadTexture((IWineD3DSurface *) This->surfaces[j][i], cube_targets[j], i);
169 /* No longer dirty */
170 This->baseTexture.dirty = FALSE;
174 /* Always need to reset the number of mipmap levels when rebinding as it is
175 a property of the active texture unit, and another texture may have set it
176 to a different value */
177 TRACE("Setting GL_TEXTURE_MAX_LEVEL to %d\n", This->baseTexture.levels - 1);
178 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAX_LEVEL, This->baseTexture.levels - 1);
179 checkGLcall("glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, This->baseTexture.levels)");
181 #if 0 /* TODO: context manager support */
182 IWineD3DContextManager_PopState(This->contextManager, GL_TEXTURE_CUBE_MAP_ARB, DISABLED, DELAYED);
189 D3DRESOURCETYPE WINAPI IWineD3DCubeTextureImpl_GetType(IWineD3DCubeTexture *iface) {
190 return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
193 HRESULT WINAPI IWineD3DCubeTextureImpl_GetParent(IWineD3DCubeTexture *iface, IUnknown **pParent) {
194 return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
197 /* ******************************************************
198 IWineD3DCubeTexture IWineD3DBaseTexture parts follow
199 ****************************************************** */
200 DWORD WINAPI IWineD3DCubeTextureImpl_SetLOD(IWineD3DCubeTexture *iface, DWORD LODNew) {
201 return IWineD3DBaseTextureImpl_SetLOD((IWineD3DBaseTexture *)iface, LODNew);
204 DWORD WINAPI IWineD3DCubeTextureImpl_GetLOD(IWineD3DCubeTexture *iface) {
205 return IWineD3DBaseTextureImpl_GetLOD((IWineD3DBaseTexture *)iface);
208 DWORD WINAPI IWineD3DCubeTextureImpl_GetLevelCount(IWineD3DCubeTexture *iface) {
209 return IWineD3DBaseTextureImpl_GetLevelCount((IWineD3DBaseTexture *)iface);
212 HRESULT WINAPI IWineD3DCubeTextureImpl_SetAutoGenFilterType(IWineD3DCubeTexture *iface, D3DTEXTUREFILTERTYPE FilterType) {
213 return IWineD3DBaseTextureImpl_SetAutoGenFilterType((IWineD3DBaseTexture *)iface, FilterType);
216 D3DTEXTUREFILTERTYPE WINAPI IWineD3DCubeTextureImpl_GetAutoGenFilterType(IWineD3DCubeTexture *iface) {
217 return IWineD3DBaseTextureImpl_GetAutoGenFilterType((IWineD3DBaseTexture *)iface);
220 void WINAPI IWineD3DCubeTextureImpl_GenerateMipSubLevels(IWineD3DCubeTexture *iface) {
221 return IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
224 /* Internal function, No d3d mapping */
225 BOOL WINAPI IWineD3DCubeTextureImpl_SetDirty(IWineD3DCubeTexture *iface, BOOL dirty) {
226 return IWineD3DBaseTextureImpl_SetDirty((IWineD3DBaseTexture *)iface, dirty);
229 /* Internal function, No d3d mapping */
230 BOOL WINAPI IWineD3DCubeTextureImpl_GetDirty(IWineD3DCubeTexture *iface) {
231 return IWineD3DBaseTextureImpl_GetDirty((IWineD3DBaseTexture *)iface);
234 HRESULT WINAPI IWineD3DCubeTextureImpl_BindTexture(IWineD3DCubeTexture *iface) {
235 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
236 TRACE("(%p) : %d \n", This, This->baseTexture.textureName);
238 #if 0 /* TODO: context manager support */
239 IWineD3DContextManager_PushState(This->contextManager, GL_TEXTURE_CUBE_MAP_ARB, ENABLED, NOW /* make sure the state is applied now */);
241 glEnable(GL_TEXTURE_CUBE_MAP_ARB);
243 glBindTexture(GLTEXTURECUBEMAP, This->baseTexture.textureName);
248 HRESULT WINAPI IWineD3DCubeTextureImpl_UnBindTexture(IWineD3DCubeTexture *iface) {
249 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
250 TRACE("(%p) \n", This);
253 glBindTexture(GLTEXTURECUBEMAP, 0);
254 #if 0 /* TODO: context manager support */
255 IWineD3DContextManager_PopState(This->contextManager, GL_TEXTURE_CUBE_MAP_ARB, ENABLED, NOW /* make sure the state is applied now */);
257 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
264 UINT WINAPI IWineD3DCubeTextureImpl_GetTextureDimensions(IWineD3DCubeTexture *iface){
265 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
266 TRACE("(%p) \n", This);
268 return GLTEXTURECUBEMAP;
271 /* *******************************************
272 IWineD3DCubeTexture IWineD3DCubeTexture parts follow
273 ******************************************* */
274 HRESULT WINAPI IWineD3DCubeTextureImpl_GetLevelDesc(IWineD3DCubeTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
275 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
277 if (Level < This->baseTexture.levels) {
278 TRACE("(%p) level (%d)\n", This, Level);
279 return IWineD3DSurface_GetDesc((IWineD3DSurface *) This->surfaces[0][Level], pDesc);
281 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
282 return D3DERR_INVALIDCALL;
285 HRESULT WINAPI IWineD3DCubeTextureImpl_GetCubeMapSurface(IWineD3DCubeTexture *iface, D3DCUBEMAP_FACES FaceType, UINT Level, IWineD3DSurface** ppCubeMapSurface) {
286 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
287 if (Level < This->baseTexture.levels) {
288 *ppCubeMapSurface = (IWineD3DSurface *) This->surfaces[FaceType][Level];
289 IWineD3DSurface_AddRef((IWineD3DSurface *) *ppCubeMapSurface);
290 TRACE("(%p) -> faceType(%d) level(%d) returning surface@%p \n", This, FaceType, Level, This->surfaces[FaceType][Level]);
292 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
293 return D3DERR_INVALIDCALL;
298 HRESULT WINAPI IWineD3DCubeTextureImpl_LockRect(IWineD3DCubeTexture *iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
300 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
302 if (Level < This->baseTexture.levels) {
303 hr = IWineD3DSurface_LockRect((IWineD3DSurface *) This->surfaces[FaceType][Level], pLockedRect, pRect, Flags);
304 TRACE("(%p) -> faceType(%d) level(%d) returning memory@%p success(%lu)\n", This, FaceType, Level, pLockedRect->pBits, hr);
306 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
307 return D3DERR_INVALIDCALL;
312 HRESULT WINAPI IWineD3DCubeTextureImpl_UnlockRect(IWineD3DCubeTexture *iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
314 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
316 if (Level < This->baseTexture.levels) {
317 hr = IWineD3DSurface_UnlockRect((IWineD3DSurface *) This->surfaces[FaceType][Level]);
318 TRACE("(%p) -> faceType(%d) level(%d) success(%lu)\n", This, FaceType, Level, hr);
320 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
321 return D3DERR_INVALIDCALL;
326 HRESULT WINAPI IWineD3DCubeTextureImpl_AddDirtyRect(IWineD3DCubeTexture *iface, D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
327 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
328 This->baseTexture.dirty = TRUE;
329 TRACE("(%p) : dirtyfication of faceType(%d) Level (0)\n", This, FaceType);
330 return IWineD3DSurface_AddDirtyRect((IWineD3DSurface *) This->surfaces[FaceType][0], pDirtyRect);
334 IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl =
337 IWineD3DCubeTextureImpl_QueryInterface,
338 IWineD3DCubeTextureImpl_AddRef,
339 IWineD3DCubeTextureImpl_Release,
340 /* IWineD3DResource */
341 IWineD3DCubeTextureImpl_GetParent,
342 IWineD3DCubeTextureImpl_GetDevice,
343 IWineD3DCubeTextureImpl_SetPrivateData,
344 IWineD3DCubeTextureImpl_GetPrivateData,
345 IWineD3DCubeTextureImpl_FreePrivateData,
346 IWineD3DCubeTextureImpl_SetPriority,
347 IWineD3DCubeTextureImpl_GetPriority,
348 IWineD3DCubeTextureImpl_PreLoad,
349 IWineD3DCubeTextureImpl_GetType,
351 IWineD3DCubeTextureImpl_SetLOD,
352 IWineD3DCubeTextureImpl_GetLOD,
353 IWineD3DCubeTextureImpl_GetLevelCount,
354 IWineD3DCubeTextureImpl_SetAutoGenFilterType,
355 IWineD3DCubeTextureImpl_GetAutoGenFilterType,
356 IWineD3DCubeTextureImpl_GenerateMipSubLevels,
357 IWineD3DCubeTextureImpl_SetDirty,
358 IWineD3DCubeTextureImpl_GetDirty,
359 IWineD3DCubeTextureImpl_BindTexture,
360 IWineD3DCubeTextureImpl_UnBindTexture,
361 IWineD3DCubeTextureImpl_GetTextureDimensions,
363 IWineD3DCubeTextureImpl_GetLevelDesc,
364 IWineD3DCubeTextureImpl_GetCubeMapSurface,
365 IWineD3DCubeTextureImpl_LockRect,
366 IWineD3DCubeTextureImpl_UnlockRect,
367 IWineD3DCubeTextureImpl_AddDirtyRect