Add support for HCBT_SYSCOMMAND hook, add logging for HCBT_SYSCOMMAND
[wine.git] / dlls / d3d8 / cubetexture.c
blob04ad395fead40e6dfbfeed67d4ee04b89edd2573
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 <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "wingdi.h"
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 IDirect3DCubeTexture8Impl *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);
45 *ppobj = This;
46 return D3D_OK;
49 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
50 return E_NOINTERFACE;
53 ULONG WINAPI IDirect3DCubeTexture8Impl_AddRef(LPDIRECT3DCUBETEXTURE8 iface) {
54 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
55 TRACE("(%p) : AddRef from %ld\n", This, This->ref);
56 return ++(This->ref);
59 ULONG WINAPI IDirect3DCubeTexture8Impl_Release(LPDIRECT3DCUBETEXTURE8 iface) {
60 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
61 ULONG ref = --This->ref;
62 unsigned int i, j;
64 TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
65 if (ref == 0) {
66 for (i = 0; i < This->levels; i++) {
67 for (j = 0; j < 6; j++) {
68 if (This->surfaces[j][i] != NULL) {
69 TRACE("(%p) : Releasing surface %p\n", This, This->surfaces[j][i]);
70 IDirect3DSurface8Impl_Release((LPDIRECT3DSURFACE8) This->surfaces[j][i]);
74 HeapFree(GetProcessHeap(), 0, This);
76 return ref;
79 /* IDirect3DCubeTexture8 (Inherited from IDirect3DResource8) */
80 HRESULT WINAPI IDirect3DCubeTexture8Impl_GetDevice(LPDIRECT3DCUBETEXTURE8 iface, IDirect3DDevice8** ppDevice) {
81 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
82 TRACE("(%p) : returning %p\n", This, This->Device);
83 *ppDevice = (LPDIRECT3DDEVICE8) This->Device;
84 /**
85 * Note Calling this method will increase the internal reference count
86 * on the IDirect3DDevice8 interface.
88 IDirect3DDevice8Impl_AddRef(*ppDevice);
89 return D3D_OK;
91 HRESULT WINAPI IDirect3DCubeTexture8Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
92 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
93 FIXME("(%p) : stub\n", This);
94 return D3D_OK;
96 HRESULT WINAPI IDirect3DCubeTexture8Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
97 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
98 FIXME("(%p) : stub\n", This);
99 return D3D_OK;
101 HRESULT WINAPI IDirect3DCubeTexture8Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid) {
102 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
103 FIXME("(%p) : stub\n", This);
104 return D3D_OK;
106 DWORD WINAPI IDirect3DCubeTexture8Impl_SetPriority(LPDIRECT3DCUBETEXTURE8 iface, DWORD PriorityNew) {
107 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
108 FIXME("(%p) : stub\n", This);
109 return 0;
111 DWORD WINAPI IDirect3DCubeTexture8Impl_GetPriority(LPDIRECT3DCUBETEXTURE8 iface) {
112 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
113 FIXME("(%p) : stub\n", This);
114 return 0;
117 static const GLenum cube_targets[6] = {
118 #if defined(GL_VERSION_1_3)
119 GL_TEXTURE_CUBE_MAP_POSITIVE_X,
120 GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
121 GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
122 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
123 GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
124 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
125 #else
126 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
127 GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
128 GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
129 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
130 GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
131 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
132 #endif
135 void WINAPI IDirect3DCubeTexture8Impl_PreLoad(LPDIRECT3DCUBETEXTURE8 iface) {
136 unsigned int i, j;
137 IDirect3DCubeTexture8Impl *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 IDirect3DCubeTexture8Impl *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 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
206 FIXME("(%p) : stub\n", This);
207 return 0;
209 DWORD WINAPI IDirect3DCubeTexture8Impl_GetLOD(LPDIRECT3DCUBETEXTURE8 iface) {
210 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
211 FIXME("(%p) : stub\n", This);
212 return 0;
215 DWORD WINAPI IDirect3DCubeTexture8Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE8 iface) {
216 IDirect3DCubeTexture8Impl *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 IDirect3DCubeTexture8Impl *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 IDirect3DCubeTexture8Impl *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 IDirect3DCubeTexture8Impl *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 IDirect3DCubeTexture8Impl *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 IDirect3DCubeTexture8Impl *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 IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl =
283 IDirect3DCubeTexture8Impl_QueryInterface,
284 IDirect3DCubeTexture8Impl_AddRef,
285 IDirect3DCubeTexture8Impl_Release,
286 IDirect3DCubeTexture8Impl_GetDevice,
287 IDirect3DCubeTexture8Impl_SetPrivateData,
288 IDirect3DCubeTexture8Impl_GetPrivateData,
289 IDirect3DCubeTexture8Impl_FreePrivateData,
290 IDirect3DCubeTexture8Impl_SetPriority,
291 IDirect3DCubeTexture8Impl_GetPriority,
292 IDirect3DCubeTexture8Impl_PreLoad,
293 IDirect3DCubeTexture8Impl_GetType,
294 IDirect3DCubeTexture8Impl_SetLOD,
295 IDirect3DCubeTexture8Impl_GetLOD,
296 IDirect3DCubeTexture8Impl_GetLevelCount,
297 IDirect3DCubeTexture8Impl_GetLevelDesc,
298 IDirect3DCubeTexture8Impl_GetCubeMapSurface,
299 IDirect3DCubeTexture8Impl_LockRect,
300 IDirect3DCubeTexture8Impl_UnlockRect,
301 IDirect3DCubeTexture8Impl_AddDirtyRect