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
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);
47 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
51 ULONG WINAPI IDirect3DCubeTexture8Impl_AddRef(LPDIRECT3DCUBETEXTURE8 iface) {
52 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
53 TRACE("(%p) : AddRef from %ld\n", This, This->ref);
57 ULONG WINAPI IDirect3DCubeTexture8Impl_Release(LPDIRECT3DCUBETEXTURE8 iface) {
58 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
59 ULONG ref = --This->ref;
63 TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
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);
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;
84 * Note Calling this method will increase the internal reference count
85 * on the IDirect3DDevice8 interface.
87 IDirect3DDevice8Impl_AddRef(*ppDevice);
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);
95 HRESULT WINAPI IDirect3DCubeTexture8Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
96 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
97 FIXME("(%p) : stub\n", This);
100 HRESULT WINAPI IDirect3DCubeTexture8Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid) {
101 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
102 FIXME("(%p) : stub\n", This);
105 DWORD WINAPI IDirect3DCubeTexture8Impl_SetPriority(LPDIRECT3DCUBETEXTURE8 iface, DWORD PriorityNew) {
106 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
107 FIXME("(%p) : stub\n", This);
110 DWORD WINAPI IDirect3DCubeTexture8Impl_GetPriority(LPDIRECT3DCUBETEXTURE8 iface) {
111 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
112 FIXME("(%p) : stub\n", This);
116 static const GLenum cube_targets[6] = {
117 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
118 GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
119 GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
120 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
121 GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
122 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
125 void WINAPI IDirect3DCubeTexture8Impl_PreLoad(LPDIRECT3DCUBETEXTURE8 iface) {
128 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
129 TRACE("(%p) : About to load texture\n", This);
130 for (i = 0; i < This->levels; i++) {
131 if (i == 0 && This->surfaces[0][i]->textureName != 0 && This->Dirty == FALSE) {
132 glBindTexture(GL_TEXTURE_CUBE_MAP, This->surfaces[0][i]->textureName);
133 checkGLcall("glBindTexture");
134 TRACE("Texture %p (level %d) given name %d\n", This->surfaces[0][i], i, This->surfaces[0][i]->textureName);
135 /* No need to walk through all mip-map levels, since already all assigned */
139 if (This->surfaces[0][i]->textureName == 0) {
140 glGenTextures(1, &This->surfaces[0][i]->textureName);
141 checkGLcall("glGenTextures");
142 TRACE("Texture %p (level %d) given name %d\n", This->surfaces[0][i], i, This->surfaces[0][i]->textureName);
145 glBindTexture(GL_TEXTURE_CUBE_MAP, This->surfaces[0][i]->textureName);
146 checkGLcall("glBindTexture");
148 TRACE("Setting GL_TEXTURE_MAX_LEVEL to %d\n", This->levels - 1);
149 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, This->levels - 1);
150 checkGLcall("glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, This->levels - 1)");
153 for (j = 0; j < 6; j++) {
154 TRACE("Calling glTexImage2D %x i=%d, intfmt=%x, w=%d, h=%d,d=%d, glFmt=%x, glType=%lx, Mem=%p\n",
155 cube_targets[j], i, fmt2glintFmt(This->format),
156 This->surfaces[j][i]->myDesc.Width, This->surfaces[j][i]->myDesc.Height,
157 0, fmt2glFmt(This->format), fmt2glType(This->format),
158 This->surfaces[j][i]->allocatedMemory);
159 glTexImage2D(cube_targets[j],
161 fmt2glintFmt(This->format),
162 This->surfaces[j][i]->myDesc.Width,
163 This->surfaces[j][i]->myDesc.Height,
165 fmt2glFmt(This->format),
166 fmt2glType(This->format),
167 This->surfaces[j][i]->allocatedMemory);
168 checkGLcall("glTexImage2D");
170 /* Removed glTexParameterf now TextureStageStates are initialized at startup */
177 D3DRESOURCETYPE WINAPI IDirect3DCubeTexture8Impl_GetType(LPDIRECT3DCUBETEXTURE8 iface) {
178 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
179 TRACE("(%p) : returning %d\n", This, This->ResourceType);
180 return This->ResourceType;
183 /* IDirect3DCubeTexture8 (Inherited from IDirect3DBaseTexture8) */
184 DWORD WINAPI IDirect3DCubeTexture8Impl_SetLOD(LPDIRECT3DCUBETEXTURE8 iface, DWORD LODNew) {
185 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
186 FIXME("(%p) : stub\n", This);
189 DWORD WINAPI IDirect3DCubeTexture8Impl_GetLOD(LPDIRECT3DCUBETEXTURE8 iface) {
190 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
191 FIXME("(%p) : stub\n", This);
195 DWORD WINAPI IDirect3DCubeTexture8Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE8 iface) {
196 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
197 TRACE("(%p) : returning %d\n", This, This->levels);
201 /* IDirect3DCubeTexture8 */
202 HRESULT WINAPI IDirect3DCubeTexture8Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE8 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
203 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
204 if (Level < This->levels) {
205 TRACE("(%p) level (%d)\n", This, Level);
206 return IDirect3DSurface8Impl_GetDesc((LPDIRECT3DSURFACE8) This->surfaces[0][Level], pDesc);
208 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
209 return D3DERR_INVALIDCALL;
213 HRESULT WINAPI IDirect3DCubeTexture8Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface8** ppCubeMapSurface) {
214 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
215 if (Level < This->levels) {
216 *ppCubeMapSurface = (LPDIRECT3DSURFACE8) This->surfaces[FaceType][Level];
217 IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) *ppCubeMapSurface);
218 TRACE("(%p) -> faceType(%d) level(%d) returning surface@%p \n", This, FaceType, Level, This->surfaces[FaceType][Level]);
220 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
221 return D3DERR_INVALIDCALL;
225 HRESULT WINAPI IDirect3DCubeTexture8Impl_LockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
227 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
228 if (Level < This->levels) {
230 * Not dirtified while Surfaces don't notify dirtification
231 * This->Dirty = TRUE;
233 hr = IDirect3DSurface8_LockRect((LPDIRECT3DSURFACE8) This->surfaces[FaceType][Level], pLockedRect, pRect, Flags);
234 TRACE("(%p) -> faceType(%d) level(%d) returning memory@%p success(%lu)\n", This, FaceType, Level, pLockedRect->pBits, hr);
236 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
237 return D3DERR_INVALIDCALL;
241 HRESULT WINAPI IDirect3DCubeTexture8Impl_UnlockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
243 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
244 if (Level < This->levels) {
245 hr = IDirect3DSurface8_UnlockRect((LPDIRECT3DSURFACE8) This->surfaces[FaceType][Level]);
246 FIXME("(%p) -> faceType(%d) level(%d) success(%lu)\n", This, FaceType, Level, hr);
248 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
249 return D3DERR_INVALIDCALL;
253 HRESULT WINAPI IDirect3DCubeTexture8Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
254 ICOM_THIS(IDirect3DCubeTexture8Impl,iface);
256 FIXME("(%p) : stub\n", This);
261 ICOM_VTABLE(IDirect3DCubeTexture8) Direct3DCubeTexture8_Vtbl =
263 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
264 IDirect3DCubeTexture8Impl_QueryInterface,
265 IDirect3DCubeTexture8Impl_AddRef,
266 IDirect3DCubeTexture8Impl_Release,
267 IDirect3DCubeTexture8Impl_GetDevice,
268 IDirect3DCubeTexture8Impl_SetPrivateData,
269 IDirect3DCubeTexture8Impl_GetPrivateData,
270 IDirect3DCubeTexture8Impl_FreePrivateData,
271 IDirect3DCubeTexture8Impl_SetPriority,
272 IDirect3DCubeTexture8Impl_GetPriority,
273 IDirect3DCubeTexture8Impl_PreLoad,
274 IDirect3DCubeTexture8Impl_GetType,
275 IDirect3DCubeTexture8Impl_SetLOD,
276 IDirect3DCubeTexture8Impl_GetLOD,
277 IDirect3DCubeTexture8Impl_GetLevelCount,
278 IDirect3DCubeTexture8Impl_GetLevelDesc,
279 IDirect3DCubeTexture8Impl_GetCubeMapSurface,
280 IDirect3DCubeTexture8Impl_LockRect,
281 IDirect3DCubeTexture8Impl_UnlockRect,
282 IDirect3DCubeTexture8Impl_AddDirtyRect