Spelling fix.
[wine/wine-kai.git] / dlls / d3d8 / cubetexture.c
blobc44889cae4f858276e586f3ab05845132be7e3a7
1 /*
2 * IDirect3DCubeTexture8 implementation
4 * Copyright 2002 Jason Edmeades
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.
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.
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
21 #include "config.h"
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wingdi.h"
27 #include "wine/debug.h"
29 #include "d3d8_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
33 /* IDirect3DCubeTexture8 IUnknown parts follow: */
34 HRESULT WINAPI IDirect3DCubeTexture8Impl_QueryInterface(LPDIRECT3DCUBETEXTURE8 iface,REFIID riid,LPVOID *ppobj)
36 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
37 TRACE("(%p) : QueryInterface\n", This);
38 if (IsEqualGUID(riid, &IID_IUnknown)
39 || IsEqualGUID(riid, &IID_IDirect3DResource8)
40 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
41 || IsEqualGUID(riid, &IID_IDirect3DCubeTexture8)) {
42 IDirect3DCubeTexture8Impl_AddRef(iface);
43 *ppobj = This;
44 return D3D_OK;
47 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
48 return E_NOINTERFACE;
51 ULONG WINAPI IDirect3DCubeTexture8Impl_AddRef(LPDIRECT3DCUBETEXTURE8 iface) {
52 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
53 TRACE("(%p) : AddRef from %ld\n", This, This->ref);
54 return ++(This->ref);
57 ULONG WINAPI IDirect3DCubeTexture8Impl_Release(LPDIRECT3DCUBETEXTURE8 iface) {
58 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
59 ULONG ref = --This->ref;
60 int i;
61 int j;
63 TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
64 if (ref == 0) {
65 for (i = 0; i < This->levels; i++) {
66 for (j = 0; j < 6; j++) {
67 if (This->surfaces[j][i] != NULL) {
68 TRACE("(%p) : Releasing surface %p\n", This, This->surfaces[j][i]);
69 IDirect3DSurface8Impl_Release((LPDIRECT3DSURFACE8) This->surfaces[j][i]);
73 HeapFree(GetProcessHeap(), 0, This);
75 return ref;
78 /* IDirect3DCubeTexture8 (Inherited from IDirect3DResource8) */
79 HRESULT WINAPI IDirect3DCubeTexture8Impl_GetDevice(LPDIRECT3DCUBETEXTURE8 iface, IDirect3DDevice8** ppDevice) {
80 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
81 TRACE("(%p) : returning %p\n", This, This->Device);
82 *ppDevice = (LPDIRECT3DDEVICE8) This->Device;
83 /**
84 * Note Calling this method will increase the internal reference count
85 * on the IDirect3DDevice8 interface.
87 IDirect3DDevice8Impl_AddRef(*ppDevice);
88 return D3D_OK;
90 HRESULT WINAPI IDirect3DCubeTexture8Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
91 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
92 FIXME("(%p) : stub\n", This);
93 return D3D_OK;
95 HRESULT WINAPI IDirect3DCubeTexture8Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
96 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
97 FIXME("(%p) : stub\n", This);
98 return D3D_OK;
100 HRESULT WINAPI IDirect3DCubeTexture8Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid) {
101 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
102 FIXME("(%p) : stub\n", This);
103 return D3D_OK;
105 DWORD WINAPI IDirect3DCubeTexture8Impl_SetPriority(LPDIRECT3DCUBETEXTURE8 iface, DWORD PriorityNew) {
106 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
107 FIXME("(%p) : stub\n", This);
108 return 0;
110 DWORD WINAPI IDirect3DCubeTexture8Impl_GetPriority(LPDIRECT3DCUBETEXTURE8 iface) {
111 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
112 FIXME("(%p) : stub\n", This);
113 return 0;
116 static const GLenum cube_targets[6] = {
117 #if defined(GL_VERSION_1_3)
118 GL_TEXTURE_CUBE_MAP_POSITIVE_X,
119 GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
120 GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
121 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
122 GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
123 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
124 #else
125 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
126 GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
127 GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
128 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
129 GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
130 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
131 #endif
134 void WINAPI IDirect3DCubeTexture8Impl_PreLoad(LPDIRECT3DCUBETEXTURE8 iface) {
135 int i;
136 int j;
137 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
138 TRACE("(%p) : About to load texture: dirtified(%d)\n", This, This->Dirty);
140 ENTER_GL();
142 for (i = 0; i < This->levels; i++) {
143 if (i == 0 && This->surfaces[0][0]->textureName != 0 && This->Dirty == FALSE) {
144 glEnable(GL_TEXTURE_CUBE_MAP_ARB);
145 #if defined(GL_VERSION_1_3)
146 glBindTexture(GL_TEXTURE_CUBE_MAP, This->surfaces[0][0]->textureName);
147 #else
148 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, This->surfaces[0][0]->textureName);
149 #endif
150 checkGLcall("glBindTexture");
151 TRACE("Texture %p (level %d) given name %d\n", This->surfaces[0][0], i, This->surfaces[0][0]->textureName);
152 /* No need to walk through all mip-map levels, since already all assigned */
153 i = This->levels;
154 } else {
155 if (i == 0) {
156 if (This->surfaces[0][0]->textureName == 0) {
157 glGenTextures(1, &This->surfaces[0][0]->textureName);
158 checkGLcall("glGenTextures");
159 TRACE("Texture %p (level %d) given name %d\n", This->surfaces[0][i], i, This->surfaces[0][0]->textureName);
162 #if defined(GL_VERSION_1_3)
163 glBindTexture(GL_TEXTURE_CUBE_MAP, This->surfaces[0][0]->textureName);
164 #else
165 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, This->surfaces[0][0]->textureName);
166 #endif
167 checkGLcall("glBindTexture");
169 TRACE("Setting GL_TEXTURE_MAX_LEVEL to %d\n", This->levels - 1);
170 #if defined(GL_VERSION_1_3)
171 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, This->levels - 1);
172 #else
173 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAX_LEVEL, This->levels - 1);
174 #endif
175 checkGLcall("glTexParameteri(GL_TEXTURE_CUBE, GL_TEXTURE_MAX_LEVEL, This->levels - 1)");
178 for (j = 0; j < 6; j++) {
179 IDirect3DSurface8Impl_LoadTexture((LPDIRECT3DSURFACE8) This->surfaces[j][i], cube_targets[j], i);
180 #if 0
181 static int gen = 0;
182 char buffer[4096];
183 snprintf(buffer, sizeof(buffer), "/tmp/cube%d_face%d_level%d_%d.png", This->surfaces[0][0]->textureName, j, i, ++gen);
184 IDirect3DSurface8Impl_SaveSnapshot((LPDIRECT3DSURFACE8) This->surfaces[j][i], buffer);
185 #endif
187 /* Removed glTexParameterf now TextureStageStates are initialized at startup */
188 This->Dirty = FALSE;
192 LEAVE_GL();
194 return ;
197 D3DRESOURCETYPE WINAPI IDirect3DCubeTexture8Impl_GetType(LPDIRECT3DCUBETEXTURE8 iface) {
198 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
199 TRACE("(%p) : returning %d\n", This, This->ResourceType);
200 return This->ResourceType;
203 /* IDirect3DCubeTexture8 (Inherited from IDirect3DBaseTexture8) */
204 DWORD WINAPI IDirect3DCubeTexture8Impl_SetLOD(LPDIRECT3DCUBETEXTURE8 iface, DWORD LODNew) {
205 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
206 FIXME("(%p) : stub\n", This);
207 return 0;
209 DWORD WINAPI IDirect3DCubeTexture8Impl_GetLOD(LPDIRECT3DCUBETEXTURE8 iface) {
210 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
211 FIXME("(%p) : stub\n", This);
212 return 0;
215 DWORD WINAPI IDirect3DCubeTexture8Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE8 iface) {
216 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
217 TRACE("(%p) : returning %d\n", This, This->levels);
218 return This->levels;
221 /* IDirect3DCubeTexture8 */
222 HRESULT WINAPI IDirect3DCubeTexture8Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE8 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
223 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
224 if (Level < This->levels) {
225 TRACE("(%p) level (%d)\n", This, Level);
226 return IDirect3DSurface8Impl_GetDesc((LPDIRECT3DSURFACE8) This->surfaces[0][Level], pDesc);
227 } else {
228 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
229 return D3DERR_INVALIDCALL;
231 return D3D_OK;
233 HRESULT WINAPI IDirect3DCubeTexture8Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface8** ppCubeMapSurface) {
234 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
235 if (Level < This->levels) {
236 *ppCubeMapSurface = (LPDIRECT3DSURFACE8) This->surfaces[FaceType][Level];
237 IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) *ppCubeMapSurface);
238 TRACE("(%p) -> faceType(%d) level(%d) returning surface@%p \n", This, FaceType, Level, This->surfaces[FaceType][Level]);
239 } else {
240 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
241 return D3DERR_INVALIDCALL;
243 return D3D_OK;
245 HRESULT WINAPI IDirect3DCubeTexture8Impl_LockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
246 HRESULT hr;
247 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
248 if (Level < This->levels) {
250 * Not dirtified while Surfaces don't notify dirtification
251 * This->Dirty = TRUE;
253 hr = IDirect3DSurface8Impl_LockRect((LPDIRECT3DSURFACE8) This->surfaces[FaceType][Level], pLockedRect, pRect, Flags);
254 TRACE("(%p) -> faceType(%d) level(%d) returning memory@%p success(%lu)\n", This, FaceType, Level, pLockedRect->pBits, hr);
255 } else {
256 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
257 return D3DERR_INVALIDCALL;
259 return hr;
261 HRESULT WINAPI IDirect3DCubeTexture8Impl_UnlockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
262 HRESULT hr;
263 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
264 if (Level < This->levels) {
265 hr = IDirect3DSurface8Impl_UnlockRect((LPDIRECT3DSURFACE8) This->surfaces[FaceType][Level]);
266 TRACE("(%p) -> faceType(%d) level(%d) success(%lu)\n", This, FaceType, Level, hr);
267 } else {
268 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
269 return D3DERR_INVALIDCALL;
271 return hr;
273 HRESULT WINAPI IDirect3DCubeTexture8Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
274 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
275 This->Dirty = TRUE;
276 TRACE("(%p) : dirtyfication of faceType(%d) Level (0)\n", This, FaceType);
277 return IDirect3DSurface8Impl_AddDirtyRect((LPDIRECT3DSURFACE8) This->surfaces[FaceType][0], pDirtyRect);
281 ICOM_VTABLE(IDirect3DCubeTexture8) Direct3DCubeTexture8_Vtbl =
283 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
284 IDirect3DCubeTexture8Impl_QueryInterface,
285 IDirect3DCubeTexture8Impl_AddRef,
286 IDirect3DCubeTexture8Impl_Release,
287 IDirect3DCubeTexture8Impl_GetDevice,
288 IDirect3DCubeTexture8Impl_SetPrivateData,
289 IDirect3DCubeTexture8Impl_GetPrivateData,
290 IDirect3DCubeTexture8Impl_FreePrivateData,
291 IDirect3DCubeTexture8Impl_SetPriority,
292 IDirect3DCubeTexture8Impl_GetPriority,
293 IDirect3DCubeTexture8Impl_PreLoad,
294 IDirect3DCubeTexture8Impl_GetType,
295 IDirect3DCubeTexture8Impl_SetLOD,
296 IDirect3DCubeTexture8Impl_GetLOD,
297 IDirect3DCubeTexture8Impl_GetLevelCount,
298 IDirect3DCubeTexture8Impl_GetLevelDesc,
299 IDirect3DCubeTexture8Impl_GetCubeMapSurface,
300 IDirect3DCubeTexture8Impl_LockRect,
301 IDirect3DCubeTexture8Impl_UnlockRect,
302 IDirect3DCubeTexture8Impl_AddDirtyRect