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
29 #include "wine/debug.h"
31 #include "d3d8_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(d3d
);
35 /* IDirect3DCubeTexture8 IUnknown parts follow: */
36 HRESULT WINAPI
IDirect3DCubeTexture8Impl_QueryInterface(LPDIRECT3DCUBETEXTURE8 iface
,REFIID riid
,LPVOID
*ppobj
)
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
);
49 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppobj
);
53 ULONG WINAPI
IDirect3DCubeTexture8Impl_AddRef(LPDIRECT3DCUBETEXTURE8 iface
) {
54 ICOM_THIS(IDirect3DCubeTexture8Impl
,iface
);
55 TRACE("(%p) : AddRef from %ld\n", This
, This
->ref
);
59 ULONG WINAPI
IDirect3DCubeTexture8Impl_Release(LPDIRECT3DCUBETEXTURE8 iface
) {
60 ICOM_THIS(IDirect3DCubeTexture8Impl
,iface
);
61 ULONG ref
= --This
->ref
;
65 TRACE("(%p) : ReleaseRef to %ld\n", This
, This
->ref
);
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
]);
75 HeapFree(GetProcessHeap(), 0, This
);
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
;
86 * Note Calling this method will increase the internal reference count
87 * on the IDirect3DDevice8 interface.
89 IDirect3DDevice8Impl_AddRef(*ppDevice
);
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
);
97 HRESULT WINAPI
IDirect3DCubeTexture8Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE8 iface
, REFGUID refguid
, void* pData
, DWORD
* pSizeOfData
) {
98 ICOM_THIS(IDirect3DCubeTexture8Impl
,iface
);
99 FIXME("(%p) : stub\n", This
);
102 HRESULT WINAPI
IDirect3DCubeTexture8Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE8 iface
, REFGUID refguid
) {
103 ICOM_THIS(IDirect3DCubeTexture8Impl
,iface
);
104 FIXME("(%p) : stub\n", This
);
107 DWORD WINAPI
IDirect3DCubeTexture8Impl_SetPriority(LPDIRECT3DCUBETEXTURE8 iface
, DWORD PriorityNew
) {
108 ICOM_THIS(IDirect3DCubeTexture8Impl
,iface
);
109 FIXME("(%p) : stub\n", This
);
112 DWORD WINAPI
IDirect3DCubeTexture8Impl_GetPriority(LPDIRECT3DCUBETEXTURE8 iface
) {
113 ICOM_THIS(IDirect3DCubeTexture8Impl
,iface
);
114 FIXME("(%p) : stub\n", This
);
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
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
136 void WINAPI
IDirect3DCubeTexture8Impl_PreLoad(LPDIRECT3DCUBETEXTURE8 iface
) {
139 ICOM_THIS(IDirect3DCubeTexture8Impl
,iface
);
140 TRACE("(%p) : About to load texture: dirtified(%d)\n", This
, This
->Dirty
);
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
);
150 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, This
->surfaces
[0][0]->textureName
);
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 */
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
);
164 #if defined(GL_VERSION_1_3)
165 glBindTexture(GL_TEXTURE_CUBE_MAP
, This
->surfaces
[0][0]->textureName
);
167 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, This
->surfaces
[0][0]->textureName
);
169 checkGLcall("glBindTexture");
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);
175 glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MAX_LEVEL
, This
->levels
- 1);
177 checkGLcall("glTexParameteri(GL_TEXTURE_CUBE, GL_TEXTURE_MAX_LEVEL, This->levels - 1)");
180 for (j
= 0; j
< 6; j
++) {
181 IDirect3DSurface8Impl_LoadTexture((LPDIRECT3DSURFACE8
) This
->surfaces
[j
][i
], cube_targets
[j
], i
);
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
);
189 /* Removed glTexParameterf now TextureStageStates are initialized at startup */
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
;
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
);
211 DWORD WINAPI
IDirect3DCubeTexture8Impl_GetLOD(LPDIRECT3DCUBETEXTURE8 iface
) {
212 ICOM_THIS(IDirect3DCubeTexture8Impl
,iface
);
213 FIXME("(%p) : stub\n", This
);
217 DWORD WINAPI
IDirect3DCubeTexture8Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE8 iface
) {
218 ICOM_THIS(IDirect3DCubeTexture8Impl
,iface
);
219 TRACE("(%p) : returning %d\n", This
, This
->levels
);
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
);
230 FIXME("(%p) level(%d) overflow Levels(%d)\n", This
, Level
, This
->levels
);
231 return D3DERR_INVALIDCALL
;
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
]);
242 FIXME("(%p) level(%d) overflow Levels(%d)\n", This
, Level
, This
->levels
);
243 return D3DERR_INVALIDCALL
;
247 HRESULT WINAPI
IDirect3DCubeTexture8Impl_LockRect(LPDIRECT3DCUBETEXTURE8 iface
, D3DCUBEMAP_FACES FaceType
, UINT Level
, D3DLOCKED_RECT
* pLockedRect
, CONST RECT
* pRect
, DWORD Flags
) {
249 ICOM_THIS(IDirect3DCubeTexture8Impl
,iface
);
250 if (Level
< This
->levels
) {
252 * Not dirtified while Surfaces don't notify dirtification
253 * This->Dirty = TRUE;
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
);
258 FIXME("(%p) level(%d) overflow Levels(%d)\n", This
, Level
, This
->levels
);
259 return D3DERR_INVALIDCALL
;
263 HRESULT WINAPI
IDirect3DCubeTexture8Impl_UnlockRect(LPDIRECT3DCUBETEXTURE8 iface
, D3DCUBEMAP_FACES FaceType
, UINT Level
) {
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
);
270 FIXME("(%p) level(%d) overflow Levels(%d)\n", This
, Level
, This
->levels
);
271 return D3DERR_INVALIDCALL
;
275 HRESULT WINAPI
IDirect3DCubeTexture8Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE8 iface
, D3DCUBEMAP_FACES FaceType
, CONST RECT
* pDirtyRect
) {
276 ICOM_THIS(IDirect3DCubeTexture8Impl
,iface
);
278 TRACE("(%p) : dirtyfication of faceType(%d) Level (0)\n", This
, FaceType
);
279 return IDirect3DSurface8Impl_AddDirtyRect((LPDIRECT3DSURFACE8
) This
->surfaces
[FaceType
][0], pDirtyRect
);
283 ICOM_VTABLE(IDirect3DCubeTexture8
) Direct3DCubeTexture8_Vtbl
=
285 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
286 IDirect3DCubeTexture8Impl_QueryInterface
,
287 IDirect3DCubeTexture8Impl_AddRef
,
288 IDirect3DCubeTexture8Impl_Release
,
289 IDirect3DCubeTexture8Impl_GetDevice
,
290 IDirect3DCubeTexture8Impl_SetPrivateData
,
291 IDirect3DCubeTexture8Impl_GetPrivateData
,
292 IDirect3DCubeTexture8Impl_FreePrivateData
,
293 IDirect3DCubeTexture8Impl_SetPriority
,
294 IDirect3DCubeTexture8Impl_GetPriority
,
295 IDirect3DCubeTexture8Impl_PreLoad
,
296 IDirect3DCubeTexture8Impl_GetType
,
297 IDirect3DCubeTexture8Impl_SetLOD
,
298 IDirect3DCubeTexture8Impl_GetLOD
,
299 IDirect3DCubeTexture8Impl_GetLevelCount
,
300 IDirect3DCubeTexture8Impl_GetLevelDesc
,
301 IDirect3DCubeTexture8Impl_GetCubeMapSurface
,
302 IDirect3DCubeTexture8Impl_LockRect
,
303 IDirect3DCubeTexture8Impl_UnlockRect
,
304 IDirect3DCubeTexture8Impl_AddDirtyRect