Get rid of the no longer used ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
[wine] / dlls / d3d8 / cubetexture.c
1 /*
2  * IDirect3DCubeTexture8 implementation
3  *
4  * Copyright 2002 Jason Edmeades
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "wingdi.h"
29 #include "wine/debug.h"
30
31 #include "d3d8_private.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
34
35 /* IDirect3DCubeTexture8 IUnknown parts follow: */
36 HRESULT WINAPI IDirect3DCubeTexture8Impl_QueryInterface(LPDIRECT3DCUBETEXTURE8 iface,REFIID riid,LPVOID *ppobj)
37 {
38     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
39     TRACE("(%p) : QueryInterface\n", This);
40     if (IsEqualGUID(riid, &IID_IUnknown)
41         || IsEqualGUID(riid, &IID_IDirect3DResource8)
42         || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
43         || IsEqualGUID(riid, &IID_IDirect3DCubeTexture8)) {
44         IDirect3DCubeTexture8Impl_AddRef(iface);
45         *ppobj = This;
46         return D3D_OK;
47     }
48
49     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
50     return E_NOINTERFACE;
51 }
52
53 ULONG WINAPI IDirect3DCubeTexture8Impl_AddRef(LPDIRECT3DCUBETEXTURE8 iface) {
54     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
55     TRACE("(%p) : AddRef from %ld\n", This, This->ref);
56     return ++(This->ref);
57 }
58
59 ULONG WINAPI IDirect3DCubeTexture8Impl_Release(LPDIRECT3DCUBETEXTURE8 iface) {
60     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
61     ULONG ref = --This->ref;
62     int i;
63     int j;
64
65     TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
66     if (ref == 0) {
67         for (i = 0; i < This->levels; i++) {
68           for (j = 0; j < 6; j++) { 
69             if (This->surfaces[j][i] != NULL) {
70               TRACE("(%p) : Releasing surface %p\n", This, This->surfaces[j][i]);
71               IDirect3DSurface8Impl_Release((LPDIRECT3DSURFACE8) This->surfaces[j][i]);
72             }
73           }
74         }
75         HeapFree(GetProcessHeap(), 0, This);
76     }
77     return ref;
78 }
79
80 /* IDirect3DCubeTexture8 (Inherited from IDirect3DResource8) */
81 HRESULT  WINAPI        IDirect3DCubeTexture8Impl_GetDevice(LPDIRECT3DCUBETEXTURE8 iface, IDirect3DDevice8** ppDevice) {
82     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
83     TRACE("(%p) : returning %p\n", This, This->Device);
84     *ppDevice = (LPDIRECT3DDEVICE8) This->Device;
85     /**
86      * Note  Calling this method will increase the internal reference count 
87      * on the IDirect3DDevice8 interface. 
88      */
89     IDirect3DDevice8Impl_AddRef(*ppDevice);
90     return D3D_OK;
91 }
92 HRESULT  WINAPI        IDirect3DCubeTexture8Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
93     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
94     FIXME("(%p) : stub\n", This);    
95     return D3D_OK;
96 }
97 HRESULT  WINAPI        IDirect3DCubeTexture8Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
98     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
99     FIXME("(%p) : stub\n", This);    
100     return D3D_OK;
101 }
102 HRESULT  WINAPI        IDirect3DCubeTexture8Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid) {
103     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
104     FIXME("(%p) : stub\n", This);    
105     return D3D_OK;
106 }
107 DWORD    WINAPI        IDirect3DCubeTexture8Impl_SetPriority(LPDIRECT3DCUBETEXTURE8 iface, DWORD PriorityNew) {
108     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
109     FIXME("(%p) : stub\n", This);    
110     return 0;
111 }
112 DWORD    WINAPI        IDirect3DCubeTexture8Impl_GetPriority(LPDIRECT3DCUBETEXTURE8 iface) {
113     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
114     FIXME("(%p) : stub\n", This);    
115     return 0;
116 }
117
118 static const GLenum cube_targets[6] = {
119 #if defined(GL_VERSION_1_3)
120   GL_TEXTURE_CUBE_MAP_POSITIVE_X,
121   GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
122   GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
123   GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
124   GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
125   GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
126 #else
127   GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
128   GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
129   GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
130   GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
131   GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
132   GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
133 #endif
134 };
135
136 void     WINAPI        IDirect3DCubeTexture8Impl_PreLoad(LPDIRECT3DCUBETEXTURE8 iface) {
137     int i;
138     int j;
139     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
140     TRACE("(%p) : About to load texture: dirtified(%d)\n", This, This->Dirty);
141
142     ENTER_GL();
143
144     for (i = 0; i < This->levels; i++) {
145       if (i == 0 && This->surfaces[0][0]->textureName != 0 && This->Dirty == FALSE) {
146         glEnable(GL_TEXTURE_CUBE_MAP_ARB);
147 #if defined(GL_VERSION_1_3)
148         glBindTexture(GL_TEXTURE_CUBE_MAP, This->surfaces[0][0]->textureName);
149 #else
150         glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, This->surfaces[0][0]->textureName);
151 #endif
152         checkGLcall("glBindTexture");
153         TRACE("Texture %p (level %d) given name %d\n", This->surfaces[0][0], i, This->surfaces[0][0]->textureName);
154         /* No need to walk through all mip-map levels, since already all assigned */
155         i = This->levels;
156       } else {
157         if (i == 0) {
158           if (This->surfaces[0][0]->textureName == 0) {
159             glGenTextures(1, &This->surfaces[0][0]->textureName);
160             checkGLcall("glGenTextures");
161             TRACE("Texture %p (level %d) given name %d\n", This->surfaces[0][i], i, This->surfaces[0][0]->textureName);
162           }
163
164 #if defined(GL_VERSION_1_3)
165           glBindTexture(GL_TEXTURE_CUBE_MAP, This->surfaces[0][0]->textureName);
166 #else
167           glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, This->surfaces[0][0]->textureName);
168 #endif
169           checkGLcall("glBindTexture");
170
171           TRACE("Setting GL_TEXTURE_MAX_LEVEL to %d\n", This->levels - 1);
172 #if defined(GL_VERSION_1_3)
173           glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, This->levels - 1); 
174 #else
175           glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAX_LEVEL, This->levels - 1); 
176 #endif
177           checkGLcall("glTexParameteri(GL_TEXTURE_CUBE, GL_TEXTURE_MAX_LEVEL, This->levels - 1)");
178         }
179         
180         for (j = 0; j < 6; j++) {
181           IDirect3DSurface8Impl_LoadTexture((LPDIRECT3DSURFACE8) This->surfaces[j][i], cube_targets[j], i); 
182 #if 0
183           static int gen = 0;
184           char buffer[4096];
185           snprintf(buffer, sizeof(buffer), "/tmp/cube%d_face%d_level%d_%d.png", This->surfaces[0][0]->textureName, j, i, ++gen);
186           IDirect3DSurface8Impl_SaveSnapshot((LPDIRECT3DSURFACE8) This->surfaces[j][i], buffer);
187 #endif
188         }
189         /* Removed glTexParameterf now TextureStageStates are initialized at startup */
190         This->Dirty = FALSE;
191       }
192     }
193
194     LEAVE_GL();
195
196     return ;
197 }
198
199 D3DRESOURCETYPE WINAPI IDirect3DCubeTexture8Impl_GetType(LPDIRECT3DCUBETEXTURE8 iface) {
200     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
201     TRACE("(%p) : returning %d\n", This, This->ResourceType);
202     return This->ResourceType;
203 }
204
205 /* IDirect3DCubeTexture8 (Inherited from IDirect3DBaseTexture8) */
206 DWORD    WINAPI        IDirect3DCubeTexture8Impl_SetLOD(LPDIRECT3DCUBETEXTURE8 iface, DWORD LODNew) {
207     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
208     FIXME("(%p) : stub\n", This);    
209     return 0;
210 }
211 DWORD    WINAPI        IDirect3DCubeTexture8Impl_GetLOD(LPDIRECT3DCUBETEXTURE8 iface) {
212     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
213     FIXME("(%p) : stub\n", This);    
214     return 0;
215 }
216
217 DWORD    WINAPI        IDirect3DCubeTexture8Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE8 iface) {
218     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
219     TRACE("(%p) : returning %d\n", This, This->levels);
220     return This->levels;
221 }
222
223 /* IDirect3DCubeTexture8 */
224 HRESULT  WINAPI        IDirect3DCubeTexture8Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE8 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
225     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
226     if (Level < This->levels) {
227         TRACE("(%p) level (%d)\n", This, Level);
228         return IDirect3DSurface8Impl_GetDesc((LPDIRECT3DSURFACE8) This->surfaces[0][Level], pDesc);
229     } else {
230         FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
231         return D3DERR_INVALIDCALL;
232     }
233     return D3D_OK;
234 }
235 HRESULT  WINAPI        IDirect3DCubeTexture8Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface8** ppCubeMapSurface) {
236     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
237     if (Level < This->levels) {
238         *ppCubeMapSurface = (LPDIRECT3DSURFACE8) This->surfaces[FaceType][Level];
239         IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) *ppCubeMapSurface);
240         TRACE("(%p) -> faceType(%d) level(%d) returning surface@%p \n", This, FaceType, Level, This->surfaces[FaceType][Level]);
241     } else {
242         FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
243         return D3DERR_INVALIDCALL;
244     }
245     return D3D_OK;
246 }
247 HRESULT  WINAPI        IDirect3DCubeTexture8Impl_LockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
248     HRESULT hr;
249     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
250     if (Level < This->levels) {
251       /**
252        * Not dirtified while Surfaces don't notify dirtification
253        * This->Dirty = TRUE;
254        */
255       hr = IDirect3DSurface8Impl_LockRect((LPDIRECT3DSURFACE8) This->surfaces[FaceType][Level], pLockedRect, pRect, Flags);
256       TRACE("(%p) -> faceType(%d) level(%d) returning memory@%p success(%lu)\n", This, FaceType, Level, pLockedRect->pBits, hr);
257     } else {
258       FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
259       return D3DERR_INVALIDCALL;
260     }
261     return hr;
262 }
263 HRESULT  WINAPI        IDirect3DCubeTexture8Impl_UnlockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
264     HRESULT hr;
265     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
266     if (Level < This->levels) {
267       hr = IDirect3DSurface8Impl_UnlockRect((LPDIRECT3DSURFACE8) This->surfaces[FaceType][Level]);
268       TRACE("(%p) -> faceType(%d) level(%d) success(%lu)\n", This, FaceType, Level, hr);
269     } else {
270       FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
271       return D3DERR_INVALIDCALL;
272     }
273     return hr;
274 }
275 HRESULT  WINAPI        IDirect3DCubeTexture8Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
276     ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
277     This->Dirty = TRUE;
278     TRACE("(%p) : dirtyfication of faceType(%d) Level (0)\n", This, FaceType);    
279     return IDirect3DSurface8Impl_AddDirtyRect((LPDIRECT3DSURFACE8) This->surfaces[FaceType][0], pDirtyRect);
280 }
281
282
283 IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl =
284 {
285     IDirect3DCubeTexture8Impl_QueryInterface,
286     IDirect3DCubeTexture8Impl_AddRef,
287     IDirect3DCubeTexture8Impl_Release,
288     IDirect3DCubeTexture8Impl_GetDevice,
289     IDirect3DCubeTexture8Impl_SetPrivateData,
290     IDirect3DCubeTexture8Impl_GetPrivateData,
291     IDirect3DCubeTexture8Impl_FreePrivateData,
292     IDirect3DCubeTexture8Impl_SetPriority,
293     IDirect3DCubeTexture8Impl_GetPriority,
294     IDirect3DCubeTexture8Impl_PreLoad,
295     IDirect3DCubeTexture8Impl_GetType,
296     IDirect3DCubeTexture8Impl_SetLOD,
297     IDirect3DCubeTexture8Impl_GetLOD,
298     IDirect3DCubeTexture8Impl_GetLevelCount,
299     IDirect3DCubeTexture8Impl_GetLevelDesc,
300     IDirect3DCubeTexture8Impl_GetCubeMapSurface,
301     IDirect3DCubeTexture8Impl_LockRect,
302     IDirect3DCubeTexture8Impl_UnlockRect,
303     IDirect3DCubeTexture8Impl_AddDirtyRect
304 };