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 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);
95 IWineD3DBaseTextureImpl_CleanUp((IWineD3DBaseTexture *) iface);
96 HeapFree(GetProcessHeap(), 0, This);
98 IUnknown_Release(This->resource.parent); /* Released the reference to the d3dx object */
103 /* ****************************************************
104 IWineD3DCubeTexture IWineD3DResource parts follow
105 **************************************************** */
106 HRESULT WINAPI IWineD3DCubeTextureImpl_GetDevice(IWineD3DCubeTexture *iface, IWineD3DDevice** ppDevice) {
107 return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
110 HRESULT WINAPI IWineD3DCubeTextureImpl_SetPrivateData(IWineD3DCubeTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
111 return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
114 HRESULT WINAPI IWineD3DCubeTextureImpl_GetPrivateData(IWineD3DCubeTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
115 return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
118 HRESULT WINAPI IWineD3DCubeTextureImpl_FreePrivateData(IWineD3DCubeTexture *iface, REFGUID refguid) {
119 return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
122 DWORD WINAPI IWineD3DCubeTextureImpl_SetPriority(IWineD3DCubeTexture *iface, DWORD PriorityNew) {
123 return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
126 DWORD WINAPI IWineD3DCubeTextureImpl_GetPriority(IWineD3DCubeTexture *iface) {
127 return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
130 void WINAPI IWineD3DCubeTextureImpl_PreLoad(IWineD3DCubeTexture *iface) {
131 /* Override the IWineD3DResource Preload method */
133 BOOL setGlTextureDesc = FALSE;
134 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
136 TRACE("(%p) : About to load texture: dirtified(%d)\n", This, This->baseTexture.dirty);
138 if (This->baseTexture.textureName == 0) setGlTextureDesc = TRUE;
140 IWineD3DCubeTexture_BindTexture(iface);
143 /* If were dirty then reload the surfaces */
144 if (This->baseTexture.dirty != FALSE) {
145 for (i = 0; i < This->baseTexture.levels; i++) {
146 for (j = 0; j < 6; j++)
148 IWineD3DSurface_SetGlTextureDesc(This->surfaces[j][i], This->baseTexture.textureName, cube_targets[j]);
149 IWineD3DSurface_LoadTexture((IWineD3DSurface *) This->surfaces[j][i]);
151 /* No longer dirty */
152 This->baseTexture.dirty = FALSE;
158 D3DRESOURCETYPE WINAPI IWineD3DCubeTextureImpl_GetType(IWineD3DCubeTexture *iface) {
159 return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
162 HRESULT WINAPI IWineD3DCubeTextureImpl_GetParent(IWineD3DCubeTexture *iface, IUnknown **pParent) {
163 return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
166 /* ******************************************************
167 IWineD3DCubeTexture IWineD3DBaseTexture parts follow
168 ****************************************************** */
169 DWORD WINAPI IWineD3DCubeTextureImpl_SetLOD(IWineD3DCubeTexture *iface, DWORD LODNew) {
170 return IWineD3DBaseTextureImpl_SetLOD((IWineD3DBaseTexture *)iface, LODNew);
173 DWORD WINAPI IWineD3DCubeTextureImpl_GetLOD(IWineD3DCubeTexture *iface) {
174 return IWineD3DBaseTextureImpl_GetLOD((IWineD3DBaseTexture *)iface);
177 DWORD WINAPI IWineD3DCubeTextureImpl_GetLevelCount(IWineD3DCubeTexture *iface) {
178 return IWineD3DBaseTextureImpl_GetLevelCount((IWineD3DBaseTexture *)iface);
181 HRESULT WINAPI IWineD3DCubeTextureImpl_SetAutoGenFilterType(IWineD3DCubeTexture *iface, D3DTEXTUREFILTERTYPE FilterType) {
182 return IWineD3DBaseTextureImpl_SetAutoGenFilterType((IWineD3DBaseTexture *)iface, FilterType);
185 D3DTEXTUREFILTERTYPE WINAPI IWineD3DCubeTextureImpl_GetAutoGenFilterType(IWineD3DCubeTexture *iface) {
186 return IWineD3DBaseTextureImpl_GetAutoGenFilterType((IWineD3DBaseTexture *)iface);
189 void WINAPI IWineD3DCubeTextureImpl_GenerateMipSubLevels(IWineD3DCubeTexture *iface) {
190 return IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
193 /* Internal function, No d3d mapping */
194 BOOL WINAPI IWineD3DCubeTextureImpl_SetDirty(IWineD3DCubeTexture *iface, BOOL dirty) {
195 return IWineD3DBaseTextureImpl_SetDirty((IWineD3DBaseTexture *)iface, dirty);
198 /* Internal function, No d3d mapping */
199 BOOL WINAPI IWineD3DCubeTextureImpl_GetDirty(IWineD3DCubeTexture *iface) {
200 return IWineD3DBaseTextureImpl_GetDirty((IWineD3DBaseTexture *)iface);
203 HRESULT WINAPI IWineD3DCubeTextureImpl_BindTexture(IWineD3DCubeTexture *iface) {
204 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
205 TRACE("(%p) : relay to BaseTexture \n", This);
206 return IWineD3DBaseTextureImpl_BindTexture((IWineD3DBaseTexture *)iface);
209 HRESULT WINAPI IWineD3DCubeTextureImpl_UnBindTexture(IWineD3DCubeTexture *iface) {
210 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
211 TRACE("(%p) : relay to BaseTexture \n", This);
212 return IWineD3DBaseTextureImpl_UnBindTexture((IWineD3DBaseTexture *)iface);
215 UINT WINAPI IWineD3DCubeTextureImpl_GetTextureDimensions(IWineD3DCubeTexture *iface){
216 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
217 TRACE("(%p) \n", This);
219 return GLTEXTURECUBEMAP;
222 /* *******************************************
223 IWineD3DCubeTexture IWineD3DCubeTexture parts follow
224 ******************************************* */
225 HRESULT WINAPI IWineD3DCubeTextureImpl_GetLevelDesc(IWineD3DCubeTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
226 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
228 if (Level < This->baseTexture.levels) {
229 TRACE("(%p) level (%d)\n", This, Level);
230 return IWineD3DSurface_GetDesc((IWineD3DSurface *) This->surfaces[0][Level], pDesc);
232 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
233 return D3DERR_INVALIDCALL;
236 HRESULT WINAPI IWineD3DCubeTextureImpl_GetCubeMapSurface(IWineD3DCubeTexture *iface, D3DCUBEMAP_FACES FaceType, UINT Level, IWineD3DSurface** ppCubeMapSurface) {
237 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
238 if (Level < This->baseTexture.levels) {
239 *ppCubeMapSurface = (IWineD3DSurface *) This->surfaces[FaceType][Level];
240 IWineD3DSurface_AddRef((IWineD3DSurface *) *ppCubeMapSurface);
241 TRACE("(%p) -> faceType(%d) level(%d) returning surface@%p \n", This, FaceType, Level, This->surfaces[FaceType][Level]);
243 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
244 return D3DERR_INVALIDCALL;
249 HRESULT WINAPI IWineD3DCubeTextureImpl_LockRect(IWineD3DCubeTexture *iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
251 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
253 if (Level < This->baseTexture.levels) {
254 hr = IWineD3DSurface_LockRect((IWineD3DSurface *) This->surfaces[FaceType][Level], pLockedRect, pRect, Flags);
255 TRACE("(%p) -> faceType(%d) level(%d) returning memory@%p success(%lu)\n", This, FaceType, Level, pLockedRect->pBits, hr);
257 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
258 return D3DERR_INVALIDCALL;
263 HRESULT WINAPI IWineD3DCubeTextureImpl_UnlockRect(IWineD3DCubeTexture *iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
265 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
267 if (Level < This->baseTexture.levels) {
268 hr = IWineD3DSurface_UnlockRect((IWineD3DSurface *) This->surfaces[FaceType][Level]);
269 TRACE("(%p) -> faceType(%d) level(%d) success(%lu)\n", This, FaceType, Level, hr);
271 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
272 return D3DERR_INVALIDCALL;
277 HRESULT WINAPI IWineD3DCubeTextureImpl_AddDirtyRect(IWineD3DCubeTexture *iface, D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
278 IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
279 This->baseTexture.dirty = TRUE;
280 TRACE("(%p) : dirtyfication of faceType(%d) Level (0)\n", This, FaceType);
281 return IWineD3DSurface_AddDirtyRect((IWineD3DSurface *) This->surfaces[FaceType][0], pDirtyRect);
285 const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl =
288 IWineD3DCubeTextureImpl_QueryInterface,
289 IWineD3DCubeTextureImpl_AddRef,
290 IWineD3DCubeTextureImpl_Release,
291 /* IWineD3DResource */
292 IWineD3DCubeTextureImpl_GetParent,
293 IWineD3DCubeTextureImpl_GetDevice,
294 IWineD3DCubeTextureImpl_SetPrivateData,
295 IWineD3DCubeTextureImpl_GetPrivateData,
296 IWineD3DCubeTextureImpl_FreePrivateData,
297 IWineD3DCubeTextureImpl_SetPriority,
298 IWineD3DCubeTextureImpl_GetPriority,
299 IWineD3DCubeTextureImpl_PreLoad,
300 IWineD3DCubeTextureImpl_GetType,
301 /* IWineD3DBaseTexture */
302 IWineD3DCubeTextureImpl_SetLOD,
303 IWineD3DCubeTextureImpl_GetLOD,
304 IWineD3DCubeTextureImpl_GetLevelCount,
305 IWineD3DCubeTextureImpl_SetAutoGenFilterType,
306 IWineD3DCubeTextureImpl_GetAutoGenFilterType,
307 IWineD3DCubeTextureImpl_GenerateMipSubLevels,
308 IWineD3DCubeTextureImpl_SetDirty,
309 IWineD3DCubeTextureImpl_GetDirty,
310 IWineD3DCubeTextureImpl_BindTexture,
311 IWineD3DCubeTextureImpl_UnBindTexture,
312 IWineD3DCubeTextureImpl_GetTextureDimensions,
313 /* IWineD3DCubeTexture */
314 IWineD3DCubeTextureImpl_GetLevelDesc,
315 IWineD3DCubeTextureImpl_GetCubeMapSurface,
316 IWineD3DCubeTextureImpl_LockRect,
317 IWineD3DCubeTextureImpl_UnlockRect,
318 IWineD3DCubeTextureImpl_AddDirtyRect