2 * IDirect3DTexture9 implementation
4 * Copyright 2002-2005 Jason Edmeades
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wined3d_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
26 #define GLINFO_LOCATION ((IWineD3DImpl *)(((IWineD3DDeviceImpl *)This->resource.wineD3DDevice)->wineD3D))->gl_info
28 /* *******************************************
29 IWineD3DTexture IUnknown parts follow
30 ******************************************* */
31 HRESULT WINAPI IWineD3DTextureImpl_QueryInterface(IWineD3DTexture *iface, REFIID riid, LPVOID *ppobj)
33 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
34 WARN("(%p)->(%s,%p) should not be called\n",This,debugstr_guid(riid),ppobj);
38 ULONG WINAPI IWineD3DTextureImpl_AddRef(IWineD3DTexture *iface) {
39 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
40 TRACE("(%p) : AddRef increasing from %ld\n", This, This->resource.ref);
41 IUnknown_AddRef(This->resource.parent);
42 return InterlockedIncrement(&This->resource.ref);
45 ULONG WINAPI IWineD3DTextureImpl_Release(IWineD3DTexture *iface) {
46 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
48 TRACE("(%p) : Releasing from %ld\n", This, This->resource.ref);
49 ref = InterlockedDecrement(&This->resource.ref);
52 for (i = 0; i < This->baseTexture.levels; i++) {
53 if (This->surfaces[i] != NULL) {
54 TRACE("(%p) : Releasing surface %p\n", This, This->surfaces[i]);
55 IWineD3DSurface_Release((IWineD3DSurface *) This->surfaces[i]);
58 IWineD3DDevice_Release((IWineD3DDevice *)This->resource.wineD3DDevice);
59 HeapFree(GetProcessHeap(), 0, This);
61 IUnknown_Release(This->resource.parent); /* Released the reference to the d3dx object */
66 /* ****************************************************
67 IWineD3DTexture IWineD3DResource parts follow
68 **************************************************** */
69 HRESULT WINAPI IWineD3DTextureImpl_GetDevice(IWineD3DTexture *iface, IWineD3DDevice** ppDevice) {
70 return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
73 HRESULT WINAPI IWineD3DTextureImpl_SetPrivateData(IWineD3DTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
74 return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
77 HRESULT WINAPI IWineD3DTextureImpl_GetPrivateData(IWineD3DTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
78 return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
81 HRESULT WINAPI IWineD3DTextureImpl_FreePrivateData(IWineD3DTexture *iface, REFGUID refguid) {
82 return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
85 DWORD WINAPI IWineD3DTextureImpl_SetPriority(IWineD3DTexture *iface, DWORD PriorityNew) {
86 return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
89 DWORD WINAPI IWineD3DTextureImpl_GetPriority(IWineD3DTexture *iface) {
90 return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
93 void WINAPI IWineD3DTextureImpl_PreLoad(IWineD3DTexture *iface) {
94 /* Override the IWineD3DResource Preload method */
96 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
98 TRACE("(%p) : About to load texture\n", This);
102 for (i = 0; i < This->baseTexture.levels; i++) {
103 if (i == 0 && This->surfaces[i]->textureName != 0 && This->baseTexture.dirty == FALSE) {
104 glBindTexture(GL_TEXTURE_2D, This->surfaces[i]->textureName);
105 checkGLcall("glBindTexture");
106 TRACE("Texture %p (level %d) given name %d\n", This->surfaces[i], i, This->surfaces[i]->textureName);
107 /* No need to walk through all mip-map levels, since already all assigned */
108 i = This->baseTexture.levels;
112 if (This->surfaces[i]->textureName == 0) {
113 glGenTextures(1, &This->surfaces[i]->textureName);
114 checkGLcall("glGenTextures");
115 TRACE("Texture %p (level %d) given name %d\n", This->surfaces[i], i, This->surfaces[i]->textureName);
118 glBindTexture(GL_TEXTURE_2D, This->surfaces[i]->textureName);
119 checkGLcall("glBindTexture");
121 IWineD3DSurface_LoadTexture((IWineD3DSurface *) This->surfaces[i], GL_TEXTURE_2D, i);
125 /* No longer dirty */
126 This->baseTexture.dirty = FALSE;
128 /* Always need to reset the number of mipmap levels when rebinding as it is
129 a property of the active texture unit, and another texture may have set it
130 to a different value */
131 TRACE("Setting GL_TEXTURE_MAX_LEVEL to %d\n", This->baseTexture.levels - 1);
132 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, This->baseTexture.levels - 1);
133 checkGLcall("glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, This->levels)");
140 D3DRESOURCETYPE WINAPI IWineD3DTextureImpl_GetType(IWineD3DTexture *iface) {
141 return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
144 HRESULT WINAPI IWineD3DTextureImpl_GetParent(IWineD3DTexture *iface, IUnknown **pParent) {
145 return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
148 /* ******************************************************
149 IWineD3DTexture IWineD3DBaseTexture parts follow
150 ****************************************************** */
151 DWORD WINAPI IWineD3DTextureImpl_SetLOD(IWineD3DTexture *iface, DWORD LODNew) {
152 return IWineD3DBaseTextureImpl_SetLOD((IWineD3DBaseTexture *)iface, LODNew);
155 DWORD WINAPI IWineD3DTextureImpl_GetLOD(IWineD3DTexture *iface) {
156 return IWineD3DBaseTextureImpl_GetLOD((IWineD3DBaseTexture *)iface);
159 DWORD WINAPI IWineD3DTextureImpl_GetLevelCount(IWineD3DTexture *iface) {
160 return IWineD3DBaseTextureImpl_GetLevelCount((IWineD3DBaseTexture *)iface);
163 HRESULT WINAPI IWineD3DTextureImpl_SetAutoGenFilterType(IWineD3DTexture *iface, D3DTEXTUREFILTERTYPE FilterType) {
164 return IWineD3DBaseTextureImpl_SetAutoGenFilterType((IWineD3DBaseTexture *)iface, FilterType);
167 D3DTEXTUREFILTERTYPE WINAPI IWineD3DTextureImpl_GetAutoGenFilterType(IWineD3DTexture *iface) {
168 return IWineD3DBaseTextureImpl_GetAutoGenFilterType((IWineD3DBaseTexture *)iface);
171 void WINAPI IWineD3DTextureImpl_GenerateMipSubLevels(IWineD3DTexture *iface) {
172 return IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
175 /* Internal function, No d3d mapping */
176 BOOL WINAPI IWineD3DTextureImpl_SetDirty(IWineD3DTexture *iface, BOOL dirty) {
177 return IWineD3DBaseTextureImpl_SetDirty((IWineD3DBaseTexture *)iface, TRUE);
180 BOOL WINAPI IWineD3DTextureImpl_GetDirty(IWineD3DTexture *iface) {
181 return IWineD3DBaseTextureImpl_GetDirty((IWineD3DBaseTexture *)iface);
184 /* *******************************************
185 IWineD3DTexture IWineD3DTexture parts follow
186 ******************************************* */
187 HRESULT WINAPI IWineD3DTextureImpl_GetLevelDesc(IWineD3DTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
188 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
190 if (Level < This->baseTexture.levels) {
191 TRACE("(%p) Level (%d)\n", This, Level);
192 return IWineD3DSurface_GetDesc((IWineD3DSurface *) This->surfaces[Level], pDesc);
194 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
195 return D3DERR_INVALIDCALL;
198 HRESULT WINAPI IWineD3DTextureImpl_GetSurfaceLevel(IWineD3DTexture *iface, UINT Level, IWineD3DSurface** ppSurfaceLevel) {
199 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
200 *ppSurfaceLevel = (IWineD3DSurface *) This->surfaces[Level];
201 IWineD3DSurface_AddRef((IWineD3DSurface *) This->surfaces[Level]);
202 TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level);
206 HRESULT WINAPI IWineD3DTextureImpl_LockRect(IWineD3DTexture *iface, UINT Level, D3DLOCKED_RECT *pLockedRect,
207 CONST RECT *pRect, DWORD Flags) {
209 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
211 if (Level < This->baseTexture.levels) {
213 hr = IWineD3DSurface_LockRect((IWineD3DSurface *) This->surfaces[Level], pLockedRect, pRect, Flags);
214 TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
216 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
217 return D3DERR_INVALIDCALL;
222 HRESULT WINAPI IWineD3DTextureImpl_UnlockRect(IWineD3DTexture *iface, UINT Level) {
224 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
226 if (Level < This->baseTexture.levels) {
227 hr = IWineD3DSurface_UnlockRect((IWineD3DSurface *) This->surfaces[Level]);
228 TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
230 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
231 return D3DERR_INVALIDCALL;
236 HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRect(IWineD3DTexture *iface, CONST RECT* pDirtyRect) {
237 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
238 This->baseTexture.dirty = TRUE;
239 TRACE("(%p) : dirtyfication of surface Level (0)\n", This);
240 return IWineD3DSurface_AddDirtyRect((IWineD3DSurface *)This->surfaces[0], pDirtyRect);
243 IWineD3DTextureVtbl IWineD3DTexture_Vtbl =
245 IWineD3DTextureImpl_QueryInterface,
246 IWineD3DTextureImpl_AddRef,
247 IWineD3DTextureImpl_Release,
248 IWineD3DTextureImpl_GetParent,
249 IWineD3DTextureImpl_GetDevice,
250 IWineD3DTextureImpl_SetPrivateData,
251 IWineD3DTextureImpl_GetPrivateData,
252 IWineD3DTextureImpl_FreePrivateData,
253 IWineD3DTextureImpl_SetPriority,
254 IWineD3DTextureImpl_GetPriority,
255 IWineD3DTextureImpl_PreLoad,
256 IWineD3DTextureImpl_GetType,
257 IWineD3DTextureImpl_SetLOD,
258 IWineD3DTextureImpl_GetLOD,
259 IWineD3DTextureImpl_GetLevelCount,
260 IWineD3DTextureImpl_SetAutoGenFilterType,
261 IWineD3DTextureImpl_GetAutoGenFilterType,
262 IWineD3DTextureImpl_GenerateMipSubLevels,
263 IWineD3DTextureImpl_SetDirty,
264 IWineD3DTextureImpl_GetDirty,
265 IWineD3DTextureImpl_GetLevelDesc,
266 IWineD3DTextureImpl_GetSurfaceLevel,
267 IWineD3DTextureImpl_LockRect,
268 IWineD3DTextureImpl_UnlockRect,
269 IWineD3DTextureImpl_AddDirtyRect