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_IWineD3DBase
)
56 || IsEqualGUID(riid
, &IID_IWineD3DResource
)
57 || IsEqualGUID(riid
, &IID_IWineD3DBaseTexture
)
58 || IsEqualGUID(riid
, &IID_IWineD3DTexture
)) {
59 IUnknown_AddRef(iface
);
66 ULONG WINAPI
IWineD3DCubeTextureImpl_AddRef(IWineD3DCubeTexture
*iface
) {
67 IWineD3DCubeTextureImpl
*This
= (IWineD3DCubeTextureImpl
*)iface
;
68 TRACE("(%p) : AddRef increasing from %ld\n", This
, This
->resource
.ref
);
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 TRACE("(%p) : Cleaning up\n",This
);
80 for (i
= 0; i
< This
->baseTexture
.levels
; i
++) {
81 for (j
= 0; j
< 6; j
++) {
82 if (This
->surfaces
[j
][i
] != NULL
) {
83 /* Because the surfaces were created using a callback we need to release there parent otehrwise we leave the parent hanging */
84 IUnknown
* surfaceParent
;
85 /* Clean out the texture name we gave to the suface so that the surface doesn't try and release it */
86 IWineD3DSurface_SetGlTextureDesc(This
->surfaces
[j
][i
], 0, 0);
87 TRACE("(%p) : Releasing surface%d %d %p\n", This
, j
, i
, This
->surfaces
[j
][i
]);
88 IWineD3DSurface_GetParent(This
->surfaces
[j
][i
], &surfaceParent
);
89 IUnknown_Release(surfaceParent
);
90 IUnknown_Release(surfaceParent
);
94 IWineD3DBaseTextureImpl_CleanUp((IWineD3DBaseTexture
*) iface
);
95 /* finally delete the object */
96 HeapFree(GetProcessHeap(), 0, This
);
101 /* ****************************************************
102 IWineD3DCubeTexture IWineD3DResource parts follow
103 **************************************************** */
104 HRESULT WINAPI
IWineD3DCubeTextureImpl_GetDevice(IWineD3DCubeTexture
*iface
, IWineD3DDevice
** ppDevice
) {
105 return IWineD3DResourceImpl_GetDevice((IWineD3DResource
*)iface
, ppDevice
);
108 HRESULT WINAPI
IWineD3DCubeTextureImpl_SetPrivateData(IWineD3DCubeTexture
*iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
) {
109 return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource
*)iface
, refguid
, pData
, SizeOfData
, Flags
);
112 HRESULT WINAPI
IWineD3DCubeTextureImpl_GetPrivateData(IWineD3DCubeTexture
*iface
, REFGUID refguid
, void* pData
, DWORD
* pSizeOfData
) {
113 return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource
*)iface
, refguid
, pData
, pSizeOfData
);
116 HRESULT WINAPI
IWineD3DCubeTextureImpl_FreePrivateData(IWineD3DCubeTexture
*iface
, REFGUID refguid
) {
117 return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource
*)iface
, refguid
);
120 DWORD WINAPI
IWineD3DCubeTextureImpl_SetPriority(IWineD3DCubeTexture
*iface
, DWORD PriorityNew
) {
121 return IWineD3DResourceImpl_SetPriority((IWineD3DResource
*)iface
, PriorityNew
);
124 DWORD WINAPI
IWineD3DCubeTextureImpl_GetPriority(IWineD3DCubeTexture
*iface
) {
125 return IWineD3DResourceImpl_GetPriority((IWineD3DResource
*)iface
);
128 void WINAPI
IWineD3DCubeTextureImpl_PreLoad(IWineD3DCubeTexture
*iface
) {
129 /* Override the IWineD3DResource Preload method */
131 BOOL setGlTextureDesc
= FALSE
;
132 IWineD3DCubeTextureImpl
*This
= (IWineD3DCubeTextureImpl
*)iface
;
134 TRACE("(%p) : About to load texture: dirtified(%d)\n", This
, This
->baseTexture
.dirty
);
136 if (This
->baseTexture
.textureName
== 0) setGlTextureDesc
= TRUE
;
138 IWineD3DCubeTexture_BindTexture(iface
);
141 /* If were dirty then reload the surfaces */
142 if (This
->baseTexture
.dirty
!= FALSE
) {
143 for (i
= 0; i
< This
->baseTexture
.levels
; i
++) {
144 for (j
= D3DCUBEMAP_FACE_POSITIVE_X
; j
<= D3DCUBEMAP_FACE_NEGATIVE_Z
; j
++) {
146 IWineD3DSurface_SetGlTextureDesc(This
->surfaces
[j
][i
], This
->baseTexture
.textureName
, cube_targets
[j
]);
147 IWineD3DSurface_LoadTexture(This
->surfaces
[j
][i
]);
150 /* No longer dirty */
151 This
->baseTexture
.dirty
= FALSE
;
157 D3DRESOURCETYPE WINAPI
IWineD3DCubeTextureImpl_GetType(IWineD3DCubeTexture
*iface
) {
158 return IWineD3DResourceImpl_GetType((IWineD3DResource
*)iface
);
161 HRESULT WINAPI
IWineD3DCubeTextureImpl_GetParent(IWineD3DCubeTexture
*iface
, IUnknown
**pParent
) {
162 return IWineD3DResourceImpl_GetParent((IWineD3DResource
*)iface
, pParent
);
165 /* ******************************************************
166 IWineD3DCubeTexture IWineD3DBaseTexture parts follow
167 ****************************************************** */
168 DWORD WINAPI
IWineD3DCubeTextureImpl_SetLOD(IWineD3DCubeTexture
*iface
, DWORD LODNew
) {
169 return IWineD3DBaseTextureImpl_SetLOD((IWineD3DBaseTexture
*)iface
, LODNew
);
172 DWORD WINAPI
IWineD3DCubeTextureImpl_GetLOD(IWineD3DCubeTexture
*iface
) {
173 return IWineD3DBaseTextureImpl_GetLOD((IWineD3DBaseTexture
*)iface
);
176 DWORD WINAPI
IWineD3DCubeTextureImpl_GetLevelCount(IWineD3DCubeTexture
*iface
) {
177 return IWineD3DBaseTextureImpl_GetLevelCount((IWineD3DBaseTexture
*)iface
);
180 HRESULT WINAPI
IWineD3DCubeTextureImpl_SetAutoGenFilterType(IWineD3DCubeTexture
*iface
, D3DTEXTUREFILTERTYPE FilterType
) {
181 return IWineD3DBaseTextureImpl_SetAutoGenFilterType((IWineD3DBaseTexture
*)iface
, FilterType
);
184 D3DTEXTUREFILTERTYPE WINAPI
IWineD3DCubeTextureImpl_GetAutoGenFilterType(IWineD3DCubeTexture
*iface
) {
185 return IWineD3DBaseTextureImpl_GetAutoGenFilterType((IWineD3DBaseTexture
*)iface
);
188 void WINAPI
IWineD3DCubeTextureImpl_GenerateMipSubLevels(IWineD3DCubeTexture
*iface
) {
189 return IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture
*)iface
);
192 /* Internal function, No d3d mapping */
193 BOOL WINAPI
IWineD3DCubeTextureImpl_SetDirty(IWineD3DCubeTexture
*iface
, BOOL dirty
) {
194 return IWineD3DBaseTextureImpl_SetDirty((IWineD3DBaseTexture
*)iface
, dirty
);
197 /* Internal function, No d3d mapping */
198 BOOL WINAPI
IWineD3DCubeTextureImpl_GetDirty(IWineD3DCubeTexture
*iface
) {
199 return IWineD3DBaseTextureImpl_GetDirty((IWineD3DBaseTexture
*)iface
);
202 HRESULT WINAPI
IWineD3DCubeTextureImpl_BindTexture(IWineD3DCubeTexture
*iface
) {
203 IWineD3DCubeTextureImpl
*This
= (IWineD3DCubeTextureImpl
*)iface
;
204 TRACE("(%p) : relay to BaseTexture\n", This
);
205 return IWineD3DBaseTextureImpl_BindTexture((IWineD3DBaseTexture
*)iface
);
208 HRESULT WINAPI
IWineD3DCubeTextureImpl_UnBindTexture(IWineD3DCubeTexture
*iface
) {
209 IWineD3DCubeTextureImpl
*This
= (IWineD3DCubeTextureImpl
*)iface
;
210 TRACE("(%p) : relay to BaseTexture\n", This
);
211 return IWineD3DBaseTextureImpl_UnBindTexture((IWineD3DBaseTexture
*)iface
);
214 UINT WINAPI
IWineD3DCubeTextureImpl_GetTextureDimensions(IWineD3DCubeTexture
*iface
){
215 IWineD3DCubeTextureImpl
*This
= (IWineD3DCubeTextureImpl
*)iface
;
216 TRACE("(%p)\n", This
);
218 return GL_TEXTURE_CUBE_MAP_ARB
;
221 void WINAPI
IWineD3DCubeTextureImpl_ApplyStateChanges(IWineD3DCubeTexture
*iface
,
222 const DWORD textureStates
[WINED3D_HIGHEST_TEXTURE_STATE
+ 1],
223 const DWORD samplerStates
[WINED3D_HIGHEST_SAMPLER_STATE
+ 1]) {
224 IWineD3DCubeTextureImpl
*This
= (IWineD3DCubeTextureImpl
*)iface
;
226 IWineD3DBaseTextureImpl_ApplyStateChanges((IWineD3DBaseTexture
*)iface
, textureStates
, samplerStates
);
229 /* Apply non-power2 mappings and texture offsets so long as the texture coords aren't projected or generated */
230 if(This
->pow2scalingFactor
!= 1.0f
) {
231 if((textureStates
[WINED3DTSS_TEXCOORDINDEX
] & 0xFFFF0000) == D3DTSS_TCI_PASSTHRU
&& (~textureStates
[WINED3DTSS_TEXTURETRANSFORMFLAGS
] & D3DTTFF_PROJECTED
)) {
232 glMatrixMode(GL_TEXTURE
);
233 memset(matrix
, 0 , sizeof(matrix
));
235 matrix
[0] = This
->pow2scalingFactor
;
236 matrix
[5] = This
->pow2scalingFactor
;
237 matrix
[10] = This
->pow2scalingFactor
;
238 #if 0 /* Translation fixup is no longer required (here for reminder) */
239 matrix
[12] = -0.25f
/ (float)This
->edgeLength
;
240 matrix
[13] = -0.75f
/ (float)This
->edgeLength
;
241 matrix
[14] = -0.25f
/ (float)This
->edgeLength
;
243 TRACE("(%p) Setup Matrix:\n", This
);
244 TRACE(" %f %f %f %f\n", matrix
[0], matrix
[1], matrix
[2], matrix
[3]);
245 TRACE(" %f %f %f %f\n", matrix
[4], matrix
[5], matrix
[6], matrix
[7]);
246 TRACE(" %f %f %f %f\n", matrix
[8], matrix
[9], matrix
[10], matrix
[11]);
247 TRACE(" %f %f %f %f\n", matrix
[12], matrix
[13], matrix
[14], matrix
[15]);
249 glMultMatrixf(matrix
);
251 /* I don't expect nonpower 2 textures to be used with generated texture coordinates, but if they are present a fixme. */
252 FIXME("Non-power2 texture being used with generated texture coords\n");
259 /* *******************************************
260 IWineD3DCubeTexture IWineD3DCubeTexture parts follow
261 ******************************************* */
262 HRESULT WINAPI
IWineD3DCubeTextureImpl_GetLevelDesc(IWineD3DCubeTexture
*iface
, UINT Level
, WINED3DSURFACE_DESC
* pDesc
) {
263 IWineD3DCubeTextureImpl
*This
= (IWineD3DCubeTextureImpl
*)iface
;
265 if (Level
< This
->baseTexture
.levels
) {
266 TRACE("(%p) level (%d)\n", This
, Level
);
267 return IWineD3DSurface_GetDesc(This
->surfaces
[0][Level
], pDesc
);
269 FIXME("(%p) level(%d) overflow Levels(%d)\n", This
, Level
, This
->baseTexture
.levels
);
270 return D3DERR_INVALIDCALL
;
273 HRESULT WINAPI
IWineD3DCubeTextureImpl_GetCubeMapSurface(IWineD3DCubeTexture
*iface
, D3DCUBEMAP_FACES FaceType
, UINT Level
, IWineD3DSurface
** ppCubeMapSurface
) {
274 IWineD3DCubeTextureImpl
*This
= (IWineD3DCubeTextureImpl
*)iface
;
275 HRESULT hr
= D3DERR_INVALIDCALL
;
277 if (Level
< This
->baseTexture
.levels
&& FaceType
>= D3DCUBEMAP_FACE_POSITIVE_X
&& FaceType
<= D3DCUBEMAP_FACE_NEGATIVE_Z
) {
278 *ppCubeMapSurface
= This
->surfaces
[FaceType
][Level
];
279 IWineD3DSurface_AddRef(*ppCubeMapSurface
);
284 TRACE("(%p) -> faceType(%d) level(%d) returning surface@%p\n", This
, FaceType
, Level
, This
->surfaces
[FaceType
][Level
]);
286 WARN("(%p) level(%d) overflow Levels(%d) Or FaceType(%d)\n", This
, Level
, This
->baseTexture
.levels
, FaceType
);
292 HRESULT WINAPI
IWineD3DCubeTextureImpl_LockRect(IWineD3DCubeTexture
*iface
, D3DCUBEMAP_FACES FaceType
, UINT Level
, D3DLOCKED_RECT
* pLockedRect
, CONST RECT
* pRect
, DWORD Flags
) {
293 HRESULT hr
= D3DERR_INVALIDCALL
;
294 IWineD3DCubeTextureImpl
*This
= (IWineD3DCubeTextureImpl
*)iface
;
296 if (Level
< This
->baseTexture
.levels
&& FaceType
>= D3DCUBEMAP_FACE_POSITIVE_X
&& FaceType
<= D3DCUBEMAP_FACE_NEGATIVE_Z
) {
297 hr
= IWineD3DSurface_LockRect(This
->surfaces
[FaceType
][Level
], pLockedRect
, pRect
, Flags
);
301 TRACE("(%p) -> faceType(%d) level(%d) returning memory@%p success(%lu)\n", This
, FaceType
, Level
, pLockedRect
->pBits
, hr
);
303 WARN("(%p) level(%d) overflow Levels(%d) Or FaceType(%d)\n", This
, Level
, This
->baseTexture
.levels
, FaceType
);
309 HRESULT WINAPI
IWineD3DCubeTextureImpl_UnlockRect(IWineD3DCubeTexture
*iface
, D3DCUBEMAP_FACES FaceType
, UINT Level
) {
310 HRESULT hr
= D3DERR_INVALIDCALL
;
311 IWineD3DCubeTextureImpl
*This
= (IWineD3DCubeTextureImpl
*)iface
;
313 if (Level
< This
->baseTexture
.levels
&& FaceType
>= D3DCUBEMAP_FACE_POSITIVE_X
&& FaceType
<= D3DCUBEMAP_FACE_NEGATIVE_Z
) {
314 hr
= IWineD3DSurface_UnlockRect(This
->surfaces
[FaceType
][Level
]);
318 TRACE("(%p) -> faceType(%d) level(%d) success(%lu)\n", This
, FaceType
, Level
, hr
);
320 WARN("(%p) level(%d) overflow Levels(%d) Or FaceType(%d)\n", This
, Level
, This
->baseTexture
.levels
, FaceType
);
325 HRESULT WINAPI
IWineD3DCubeTextureImpl_AddDirtyRect(IWineD3DCubeTexture
*iface
, D3DCUBEMAP_FACES FaceType
, CONST RECT
* pDirtyRect
) {
326 HRESULT hr
= D3DERR_INVALIDCALL
;
327 IWineD3DCubeTextureImpl
*This
= (IWineD3DCubeTextureImpl
*)iface
;
328 This
->baseTexture
.dirty
= TRUE
;
329 TRACE("(%p) : dirtyfication of faceType(%d) Level (0)\n", This
, FaceType
);
330 if (FaceType
>= D3DCUBEMAP_FACE_POSITIVE_X
&& FaceType
<= D3DCUBEMAP_FACE_NEGATIVE_Z
) {
331 hr
= IWineD3DSurface_AddDirtyRect(This
->surfaces
[FaceType
][0], pDirtyRect
);
333 WARN("(%p) overflow FaceType(%d)\n", This
, FaceType
);
339 const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl
=
342 IWineD3DCubeTextureImpl_QueryInterface
,
343 IWineD3DCubeTextureImpl_AddRef
,
344 IWineD3DCubeTextureImpl_Release
,
345 /* IWineD3DResource */
346 IWineD3DCubeTextureImpl_GetParent
,
347 IWineD3DCubeTextureImpl_GetDevice
,
348 IWineD3DCubeTextureImpl_SetPrivateData
,
349 IWineD3DCubeTextureImpl_GetPrivateData
,
350 IWineD3DCubeTextureImpl_FreePrivateData
,
351 IWineD3DCubeTextureImpl_SetPriority
,
352 IWineD3DCubeTextureImpl_GetPriority
,
353 IWineD3DCubeTextureImpl_PreLoad
,
354 IWineD3DCubeTextureImpl_GetType
,
355 /* IWineD3DBaseTexture */
356 IWineD3DCubeTextureImpl_SetLOD
,
357 IWineD3DCubeTextureImpl_GetLOD
,
358 IWineD3DCubeTextureImpl_GetLevelCount
,
359 IWineD3DCubeTextureImpl_SetAutoGenFilterType
,
360 IWineD3DCubeTextureImpl_GetAutoGenFilterType
,
361 IWineD3DCubeTextureImpl_GenerateMipSubLevels
,
362 IWineD3DCubeTextureImpl_SetDirty
,
363 IWineD3DCubeTextureImpl_GetDirty
,
364 IWineD3DCubeTextureImpl_BindTexture
,
365 IWineD3DCubeTextureImpl_UnBindTexture
,
366 IWineD3DCubeTextureImpl_GetTextureDimensions
,
367 IWineD3DCubeTextureImpl_ApplyStateChanges
,
368 /* IWineD3DCubeTexture */
369 IWineD3DCubeTextureImpl_GetLevelDesc
,
370 IWineD3DCubeTextureImpl_GetCubeMapSurface
,
371 IWineD3DCubeTextureImpl_LockRect
,
372 IWineD3DCubeTextureImpl_UnlockRect
,
373 IWineD3DCubeTextureImpl_AddDirtyRect