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
29 #include "wine/debug.h"
31 #include "d3d8_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
35 /* IDirect3DTexture8 IUnknown parts follow: */
36 HRESULT WINAPI IDirect3DTexture8Impl_QueryInterface(LPDIRECT3DTEXTURE8 iface, REFIID riid, LPVOID *ppobj)
38 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
39 TRACE("(%p) : QueryInterface for %s\n", This, debugstr_guid(riid));
40 if (IsEqualGUID(riid, &IID_IUnknown)
41 || IsEqualGUID(riid, &IID_IDirect3DResource8)
42 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
43 || IsEqualGUID(riid, &IID_IDirect3DTexture8)) {
44 IDirect3DTexture8Impl_AddRef(iface);
49 WARN("(%p)->(%s,%p) not found\n", This, debugstr_guid(riid), ppobj);
53 ULONG WINAPI IDirect3DTexture8Impl_AddRef(LPDIRECT3DTEXTURE8 iface) {
54 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
55 ULONG ref = InterlockedIncrement(&This->ref);
57 TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
62 ULONG WINAPI IDirect3DTexture8Impl_Release(LPDIRECT3DTEXTURE8 iface) {
63 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
64 ULONG ref = InterlockedDecrement(&This->ref);
67 TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
70 for (i = 0; i < This->levels; i++) {
71 if (This->surfaces[i] != NULL) {
72 TRACE("(%p) : Releasing surface %p\n", This, This->surfaces[i]);
73 IDirect3DSurface8Impl_Release((LPDIRECT3DSURFACE8) This->surfaces[i]);
76 HeapFree(GetProcessHeap(), 0, This);
81 /* IDirect3DTexture8 IDirect3DResource8 Interface follow: */
82 HRESULT WINAPI IDirect3DTexture8Impl_GetDevice(LPDIRECT3DTEXTURE8 iface, IDirect3DDevice8** ppDevice) {
83 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
84 TRACE("(%p) : returning %p\n", This, This->Device);
85 *ppDevice = (LPDIRECT3DDEVICE8) This->Device;
87 * Note Calling this method will increase the internal reference count
88 * on the IDirect3DDevice8 interface.
90 IDirect3DDevice8Impl_AddRef(*ppDevice);
93 HRESULT WINAPI IDirect3DTexture8Impl_SetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
94 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
95 FIXME("(%p) : stub\n", This); return D3D_OK;
97 HRESULT WINAPI IDirect3DTexture8Impl_GetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
98 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
99 FIXME("(%p) : stub\n", This); return D3D_OK;
101 HRESULT WINAPI IDirect3DTexture8Impl_FreePrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid) {
102 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
103 FIXME("(%p) : stub\n", This); return D3D_OK;
105 DWORD WINAPI IDirect3DTexture8Impl_SetPriority(LPDIRECT3DTEXTURE8 iface, DWORD PriorityNew) {
106 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
107 FIXME("(%p) : stub\n", This);
110 DWORD WINAPI IDirect3DTexture8Impl_GetPriority(LPDIRECT3DTEXTURE8 iface) {
111 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
112 FIXME("(%p) : stub\n", This);
115 void WINAPI IDirect3DTexture8Impl_PreLoad(LPDIRECT3DTEXTURE8 iface) {
117 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
118 TRACE("(%p) : About to load texture\n", This);
122 for (i = 0; i < This->levels; i++) {
123 if (i == 0 && This->surfaces[i]->textureName != 0 && This->Dirty == FALSE) {
124 glBindTexture(GL_TEXTURE_2D, This->surfaces[i]->textureName);
125 checkGLcall("glBindTexture");
126 TRACE("Texture %p (level %d) given name %d\n", This->surfaces[i], i, This->surfaces[i]->textureName);
127 /* No need to walk through all mip-map levels, since already all assigned */
132 if (This->surfaces[i]->textureName == 0) {
133 glGenTextures(1, &This->surfaces[i]->textureName);
134 checkGLcall("glGenTextures");
135 TRACE("Texture %p (level %d) given name %d\n", This->surfaces[i], i, This->surfaces[i]->textureName);
138 glBindTexture(GL_TEXTURE_2D, This->surfaces[i]->textureName);
139 checkGLcall("glBindTexture");
141 IDirect3DSurface8Impl_LoadTexture((LPDIRECT3DSURFACE8) This->surfaces[i], GL_TEXTURE_2D, i);
145 /* No longer dirty */
148 /* Always need to reset the number of mipmap levels when rebinding as it is
149 a property of the active texture unit, and another texture may have set it
150 to a different value */
151 TRACE("Setting GL_TEXTURE_MAX_LEVEL to %d\n", This->levels - 1);
152 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, This->levels - 1);
153 checkGLcall("glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, This->levels)");
159 D3DRESOURCETYPE WINAPI IDirect3DTexture8Impl_GetType(LPDIRECT3DTEXTURE8 iface) {
160 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
161 TRACE("(%p) : is %d \n", This, This->ResourceType);
162 return This->ResourceType;
165 /* IDirect3DTexture8 IDirect3DBaseTexture8 Interface follow: */
166 DWORD WINAPI IDirect3DTexture8Impl_SetLOD(LPDIRECT3DTEXTURE8 iface, DWORD LODNew) {
167 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
168 FIXME("(%p) : stub\n", This);
171 DWORD WINAPI IDirect3DTexture8Impl_GetLOD(LPDIRECT3DTEXTURE8 iface) {
172 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
173 FIXME("(%p) : stub\n", This);
176 DWORD WINAPI IDirect3DTexture8Impl_GetLevelCount(LPDIRECT3DTEXTURE8 iface) {
177 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
178 TRACE("(%p) : returning %d\n", This, This->levels);
182 /* IDirect3DTexture8 */
183 HRESULT WINAPI IDirect3DTexture8Impl_GetLevelDesc(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
184 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
186 if (Level < This->levels) {
187 TRACE("(%p) Level (%d)\n", This, Level);
188 return IDirect3DSurface8Impl_GetDesc((LPDIRECT3DSURFACE8) This->surfaces[Level], pDesc);
190 FIXME("Levels seems too high?!!\n");
191 return D3DERR_INVALIDCALL;
193 HRESULT WINAPI IDirect3DTexture8Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE8 iface, UINT Level, IDirect3DSurface8** ppSurfaceLevel) {
194 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
195 *ppSurfaceLevel = (LPDIRECT3DSURFACE8)This->surfaces[Level];
196 IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) This->surfaces[Level]);
197 TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level);
200 HRESULT WINAPI IDirect3DTexture8Impl_LockRect(LPDIRECT3DTEXTURE8 iface, UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags) {
202 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
203 TRACE("(%p) Level (%d)\n", This, Level);
204 if (Level < This->levels) {
206 * Not dirtified while Surfaces don't notify dirtification
207 * This->Dirty = TRUE;
209 hr = IDirect3DSurface8Impl_LockRect((LPDIRECT3DSURFACE8) This->surfaces[Level], pLockedRect, pRect, Flags);
210 TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
212 FIXME("Levels seems too high?!!\n");
213 return D3DERR_INVALIDCALL;
217 HRESULT WINAPI IDirect3DTexture8Impl_UnlockRect(LPDIRECT3DTEXTURE8 iface, UINT Level) {
219 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
220 TRACE("(%p) Level (%d)\n", This, Level);
221 if (Level < This->levels) {
222 hr = IDirect3DSurface8Impl_UnlockRect((LPDIRECT3DSURFACE8) This->surfaces[Level]);
223 TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
225 FIXME("Levels seems too high?!!\n");
226 return D3DERR_INVALIDCALL;
230 HRESULT WINAPI IDirect3DTexture8Impl_AddDirtyRect(LPDIRECT3DTEXTURE8 iface, CONST RECT* pDirtyRect) {
231 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
233 TRACE("(%p) : dirtyfication of surface Level (0)\n", This);
234 return IDirect3DSurface8Impl_AddDirtyRect((LPDIRECT3DSURFACE8) This->surfaces[0], pDirtyRect);
238 IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl =
240 IDirect3DTexture8Impl_QueryInterface,
241 IDirect3DTexture8Impl_AddRef,
242 IDirect3DTexture8Impl_Release,
243 IDirect3DTexture8Impl_GetDevice,
244 IDirect3DTexture8Impl_SetPrivateData,
245 IDirect3DTexture8Impl_GetPrivateData,
246 IDirect3DTexture8Impl_FreePrivateData,
247 IDirect3DTexture8Impl_SetPriority,
248 IDirect3DTexture8Impl_GetPriority,
249 IDirect3DTexture8Impl_PreLoad,
250 IDirect3DTexture8Impl_GetType,
251 IDirect3DTexture8Impl_SetLOD,
252 IDirect3DTexture8Impl_GetLOD,
253 IDirect3DTexture8Impl_GetLevelCount,
254 IDirect3DTexture8Impl_GetLevelDesc,
255 IDirect3DTexture8Impl_GetSurfaceLevel,
256 IDirect3DTexture8Impl_LockRect,
257 IDirect3DTexture8Impl_UnlockRect,
258 IDirect3DTexture8Impl_AddDirtyRect