2 * IDirect3DTexture8 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 /* IDirect3DTexture8 IUnknown parts follow: */
34 HRESULT WINAPI IDirect3DTexture8Impl_QueryInterface(LPDIRECT3DTEXTURE8 iface, REFIID riid, LPVOID *ppobj)
36 ICOM_THIS(IDirect3DTexture8Impl,iface);
37 TRACE("(%p) : QueryInterface for %s\n", This, debugstr_guid(riid));
38 if (IsEqualGUID(riid, &IID_IUnknown)
39 || IsEqualGUID(riid, &IID_IDirect3DResource8)
40 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
41 || IsEqualGUID(riid, &IID_IDirect3DTexture8)) {
42 IDirect3DTexture8Impl_AddRef(iface);
47 WARN("(%p)->(%s,%p) not found\n", This, debugstr_guid(riid), ppobj);
51 ULONG WINAPI IDirect3DTexture8Impl_AddRef(LPDIRECT3DTEXTURE8 iface) {
52 ICOM_THIS(IDirect3DTexture8Impl,iface);
53 TRACE("(%p) : AddRef from %ld\n", This, This->ref);
57 ULONG WINAPI IDirect3DTexture8Impl_Release(LPDIRECT3DTEXTURE8 iface) {
58 ICOM_THIS(IDirect3DTexture8Impl,iface);
59 ULONG ref = --This->ref;
62 TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
64 for (i = 0; i < This->levels; i++) {
65 if (This->surfaces[i] != NULL) {
66 TRACE("(%p) : Releasing surface %p\n", This, This->surfaces[i]);
67 IDirect3DSurface8Impl_Release((LPDIRECT3DSURFACE8) This->surfaces[i]);
70 HeapFree(GetProcessHeap(), 0, This);
75 /* IDirect3DTexture8 IDirect3DResource8 Interface follow: */
76 HRESULT WINAPI IDirect3DTexture8Impl_GetDevice(LPDIRECT3DTEXTURE8 iface, IDirect3DDevice8** ppDevice) {
77 ICOM_THIS(IDirect3DTexture8Impl,iface);
78 TRACE("(%p) : returning %p\n", This, This->Device);
79 *ppDevice = (LPDIRECT3DDEVICE8) This->Device;
81 * Note Calling this method will increase the internal reference count
82 * on the IDirect3DDevice8 interface.
84 IDirect3DDevice8Impl_AddRef(*ppDevice);
87 HRESULT WINAPI IDirect3DTexture8Impl_SetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
88 ICOM_THIS(IDirect3DTexture8Impl,iface);
89 FIXME("(%p) : stub\n", This); return D3D_OK;
91 HRESULT WINAPI IDirect3DTexture8Impl_GetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
92 ICOM_THIS(IDirect3DTexture8Impl,iface);
93 FIXME("(%p) : stub\n", This); return D3D_OK;
95 HRESULT WINAPI IDirect3DTexture8Impl_FreePrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid) {
96 ICOM_THIS(IDirect3DTexture8Impl,iface);
97 FIXME("(%p) : stub\n", This); return D3D_OK;
99 DWORD WINAPI IDirect3DTexture8Impl_SetPriority(LPDIRECT3DTEXTURE8 iface, DWORD PriorityNew) {
100 ICOM_THIS(IDirect3DTexture8Impl,iface);
101 FIXME("(%p) : stub\n", This);
104 DWORD WINAPI IDirect3DTexture8Impl_GetPriority(LPDIRECT3DTEXTURE8 iface) {
105 ICOM_THIS(IDirect3DTexture8Impl,iface);
106 FIXME("(%p) : stub\n", This);
109 void WINAPI IDirect3DTexture8Impl_PreLoad(LPDIRECT3DTEXTURE8 iface) {
111 ICOM_THIS(IDirect3DTexture8Impl,iface);
112 TRACE("(%p) : About to load texture\n", This);
116 for (i = 0; i < This->levels; i++) {
117 if (i == 0 && This->surfaces[i]->textureName != 0 && This->Dirty == FALSE) {
118 glBindTexture(GL_TEXTURE_2D, This->surfaces[i]->textureName);
119 checkGLcall("glBindTexture");
120 TRACE("Texture %p (level %d) given name %d\n", This->surfaces[i], i, This->surfaces[i]->textureName);
121 /* No need to walk through all mip-map levels, since already all assigned */
126 if (This->surfaces[i]->textureName == 0) {
127 glGenTextures(1, &This->surfaces[i]->textureName);
128 checkGLcall("glGenTextures");
129 TRACE("Texture %p (level %d) given name %d\n", This->surfaces[i], i, This->surfaces[i]->textureName);
132 glBindTexture(GL_TEXTURE_2D, This->surfaces[i]->textureName);
133 checkGLcall("glBindTexture");
135 IDirect3DSurface8Impl_LoadTexture((LPDIRECT3DSURFACE8) This->surfaces[i], GL_TEXTURE_2D, i);
139 /* No longer dirty */
142 /* Always need to reset the number of mipmap levels when rebinding as it is
143 a property of the active texture unit, and another texture may have set it
144 to a different value */
145 TRACE("Setting GL_TEXTURE_MAX_LEVEL to %d\n", This->levels - 1);
146 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, This->levels - 1);
147 checkGLcall("glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, This->levels)");
153 D3DRESOURCETYPE WINAPI IDirect3DTexture8Impl_GetType(LPDIRECT3DTEXTURE8 iface) {
154 ICOM_THIS(IDirect3DTexture8Impl,iface);
155 TRACE("(%p) : is %d \n", This, This->ResourceType);
156 return This->ResourceType;
159 /* IDirect3DTexture8 IDirect3DBaseTexture8 Interface follow: */
160 DWORD WINAPI IDirect3DTexture8Impl_SetLOD(LPDIRECT3DTEXTURE8 iface, DWORD LODNew) {
161 ICOM_THIS(IDirect3DTexture8Impl,iface);
162 FIXME("(%p) : stub\n", This);
165 DWORD WINAPI IDirect3DTexture8Impl_GetLOD(LPDIRECT3DTEXTURE8 iface) {
166 ICOM_THIS(IDirect3DTexture8Impl,iface);
167 FIXME("(%p) : stub\n", This);
170 DWORD WINAPI IDirect3DTexture8Impl_GetLevelCount(LPDIRECT3DTEXTURE8 iface) {
171 ICOM_THIS(IDirect3DTexture8Impl,iface);
172 TRACE("(%p) : returning %d\n", This, This->levels);
176 /* IDirect3DTexture8 */
177 HRESULT WINAPI IDirect3DTexture8Impl_GetLevelDesc(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
178 ICOM_THIS(IDirect3DTexture8Impl,iface);
180 if (Level < This->levels) {
181 TRACE("(%p) Level (%d)\n", This, Level);
182 return IDirect3DSurface8Impl_GetDesc((LPDIRECT3DSURFACE8) This->surfaces[Level], pDesc);
184 FIXME("Levels seems too high?!!\n");
185 return D3DERR_INVALIDCALL;
189 HRESULT WINAPI IDirect3DTexture8Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE8 iface, UINT Level, IDirect3DSurface8** ppSurfaceLevel) {
190 ICOM_THIS(IDirect3DTexture8Impl,iface);
191 *ppSurfaceLevel = (LPDIRECT3DSURFACE8)This->surfaces[Level];
192 IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) This->surfaces[Level]);
193 TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level);
196 HRESULT WINAPI IDirect3DTexture8Impl_LockRect(LPDIRECT3DTEXTURE8 iface, UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags) {
198 ICOM_THIS(IDirect3DTexture8Impl,iface);
199 TRACE("(%p) Level (%d)\n", This, Level);
200 if (Level < This->levels) {
202 * Not dirtified while Surfaces don't notify dirtification
203 * This->Dirty = TRUE;
205 hr = IDirect3DSurface8Impl_LockRect((LPDIRECT3DSURFACE8) This->surfaces[Level], pLockedRect, pRect, Flags);
206 TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
208 FIXME("Levels seems too high?!!\n");
209 return D3DERR_INVALIDCALL;
213 HRESULT WINAPI IDirect3DTexture8Impl_UnlockRect(LPDIRECT3DTEXTURE8 iface, UINT Level) {
215 ICOM_THIS(IDirect3DTexture8Impl,iface);
216 TRACE("(%p) Level (%d)\n", This, Level);
217 if (Level < This->levels) {
218 hr = IDirect3DSurface8Impl_UnlockRect((LPDIRECT3DSURFACE8) This->surfaces[Level]);
219 TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
221 FIXME("Levels seems too high?!!\n");
222 return D3DERR_INVALIDCALL;
226 HRESULT WINAPI IDirect3DTexture8Impl_AddDirtyRect(LPDIRECT3DTEXTURE8 iface, CONST RECT* pDirtyRect) {
227 ICOM_THIS(IDirect3DTexture8Impl,iface);
229 TRACE("(%p) : dirtyfication of surface Level (0)\n", This);
230 return IDirect3DSurface8Impl_AddDirtyRect((LPDIRECT3DSURFACE8) This->surfaces[0], pDirtyRect);
234 ICOM_VTABLE(IDirect3DTexture8) Direct3DTexture8_Vtbl =
236 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
237 IDirect3DTexture8Impl_QueryInterface,
238 IDirect3DTexture8Impl_AddRef,
239 IDirect3DTexture8Impl_Release,
240 IDirect3DTexture8Impl_GetDevice,
241 IDirect3DTexture8Impl_SetPrivateData,
242 IDirect3DTexture8Impl_GetPrivateData,
243 IDirect3DTexture8Impl_FreePrivateData,
244 IDirect3DTexture8Impl_SetPriority,
245 IDirect3DTexture8Impl_GetPriority,
246 IDirect3DTexture8Impl_PreLoad,
247 IDirect3DTexture8Impl_GetType,
248 IDirect3DTexture8Impl_SetLOD,
249 IDirect3DTexture8Impl_GetLOD,
250 IDirect3DTexture8Impl_GetLevelCount,
251 IDirect3DTexture8Impl_GetLevelDesc,
252 IDirect3DTexture8Impl_GetSurfaceLevel,
253 IDirect3DTexture8Impl_LockRect,
254 IDirect3DTexture8Impl_UnlockRect,
255 IDirect3DTexture8Impl_AddDirtyRect