2 * IWineD3DTexture implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wined3d_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
27 #define GLINFO_LOCATION ((IWineD3DImpl *)(((IWineD3DDeviceImpl *)This->resource.wineD3DDevice)->wineD3D))->gl_info
29 /* *******************************************
30 IWineD3DTexture IUnknown parts follow
31 ******************************************* */
32 HRESULT WINAPI IWineD3DTextureImpl_QueryInterface(IWineD3DTexture *iface, REFIID riid, LPVOID *ppobj)
34 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
35 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
36 if (IsEqualGUID(riid, &IID_IUnknown)
37 || IsEqualGUID(riid, &IID_IWineD3DResource)
38 || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)
39 || IsEqualGUID(riid, &IID_IWineD3DTexture)){
40 IUnknown_AddRef(iface);
47 ULONG WINAPI IWineD3DTextureImpl_AddRef(IWineD3DTexture *iface) {
48 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
49 TRACE("(%p) : AddRef increasing from %ld\n", This, This->resource.ref);
50 return InterlockedIncrement(&This->resource.ref);
53 ULONG WINAPI IWineD3DTextureImpl_Release(IWineD3DTexture *iface) {
54 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
56 TRACE("(%p) : Releasing from %ld\n", This, This->resource.ref);
57 ref = InterlockedDecrement(&This->resource.ref);
61 TRACE("(%p) : Cleaning up\n",This);
62 for (i = 0; i < This->baseTexture.levels; i++) {
63 if (This->surfaces[i] != NULL) {
64 /* Because the surfaces were created using a callback we need to release there parent otehrwise we leave the parent hanging */
65 IUnknown* surfaceParent;
66 /* Clean out the texture name we gave to the suface so that the surface doesn't try and release it */
67 IWineD3DSurface_SetGlTextureDesc(This->surfaces[i], 0, 0);
68 IWineD3DSurface_GetParent(This->surfaces[i], &surfaceParent);
69 IUnknown_Release(surfaceParent);
70 IUnknown_Release(surfaceParent);
74 IWineD3DBaseTextureImpl_CleanUp((IWineD3DBaseTexture *)iface);
75 HeapFree(GetProcessHeap(), 0, This);
80 /* ****************************************************
81 IWineD3DTexture IWineD3DResource parts follow
82 **************************************************** */
83 HRESULT WINAPI IWineD3DTextureImpl_GetDevice(IWineD3DTexture *iface, IWineD3DDevice** ppDevice) {
84 return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
87 HRESULT WINAPI IWineD3DTextureImpl_SetPrivateData(IWineD3DTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
88 return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
91 HRESULT WINAPI IWineD3DTextureImpl_GetPrivateData(IWineD3DTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
92 return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
95 HRESULT WINAPI IWineD3DTextureImpl_FreePrivateData(IWineD3DTexture *iface, REFGUID refguid) {
96 return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
99 DWORD WINAPI IWineD3DTextureImpl_SetPriority(IWineD3DTexture *iface, DWORD PriorityNew) {
100 return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
103 DWORD WINAPI IWineD3DTextureImpl_GetPriority(IWineD3DTexture *iface) {
104 return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
107 void WINAPI IWineD3DTextureImpl_PreLoad(IWineD3DTexture *iface) {
109 /* Override the IWineD3DResource PreLoad method */
111 BOOL setGlTextureDesc = FALSE;
112 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
114 TRACE("(%p) : About to load texture\n", This);
116 if (This->baseTexture.textureName == 0) setGlTextureDesc = TRUE;
118 IWineD3DTexture_BindTexture(iface);
120 /* If were dirty then reload the surfaces */
121 if(This->baseTexture.dirty != FALSE) {
123 for (i = 0; i < This->baseTexture.levels; i++) {
125 IWineD3DSurface_SetGlTextureDesc(This->surfaces[i], This->baseTexture.textureName, IWineD3DTexture_GetTextureDimensions(iface));
126 IWineD3DSurface_LoadTexture(This->surfaces[i]);
129 /* No longer dirty */
130 This->baseTexture.dirty = FALSE;
132 TRACE("(%p) Texture not dirty, nothing to do\n" , iface);
139 D3DRESOURCETYPE WINAPI IWineD3DTextureImpl_GetType(IWineD3DTexture *iface) {
140 return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
143 HRESULT WINAPI IWineD3DTextureImpl_GetParent(IWineD3DTexture *iface, IUnknown **pParent) {
144 return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
147 /* ******************************************************
148 IWineD3DTexture IWineD3DBaseTexture parts follow
149 ****************************************************** */
150 DWORD WINAPI IWineD3DTextureImpl_SetLOD(IWineD3DTexture *iface, DWORD LODNew) {
151 return IWineD3DBaseTextureImpl_SetLOD((IWineD3DBaseTexture *)iface, LODNew);
154 DWORD WINAPI IWineD3DTextureImpl_GetLOD(IWineD3DTexture *iface) {
155 return IWineD3DBaseTextureImpl_GetLOD((IWineD3DBaseTexture *)iface);
158 DWORD WINAPI IWineD3DTextureImpl_GetLevelCount(IWineD3DTexture *iface) {
159 return IWineD3DBaseTextureImpl_GetLevelCount((IWineD3DBaseTexture *)iface);
162 HRESULT WINAPI IWineD3DTextureImpl_SetAutoGenFilterType(IWineD3DTexture *iface, D3DTEXTUREFILTERTYPE FilterType) {
163 return IWineD3DBaseTextureImpl_SetAutoGenFilterType((IWineD3DBaseTexture *)iface, FilterType);
166 D3DTEXTUREFILTERTYPE WINAPI IWineD3DTextureImpl_GetAutoGenFilterType(IWineD3DTexture *iface) {
167 return IWineD3DBaseTextureImpl_GetAutoGenFilterType((IWineD3DBaseTexture *)iface);
170 void WINAPI IWineD3DTextureImpl_GenerateMipSubLevels(IWineD3DTexture *iface) {
171 return IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
174 /* Internal function, No d3d mapping */
175 BOOL WINAPI IWineD3DTextureImpl_SetDirty(IWineD3DTexture *iface, BOOL dirty) {
176 return IWineD3DBaseTextureImpl_SetDirty((IWineD3DBaseTexture *)iface, TRUE);
179 BOOL WINAPI IWineD3DTextureImpl_GetDirty(IWineD3DTexture *iface) {
180 return IWineD3DBaseTextureImpl_GetDirty((IWineD3DBaseTexture *)iface);
183 HRESULT WINAPI IWineD3DTextureImpl_BindTexture(IWineD3DTexture *iface) {
184 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
185 TRACE("(%p) : relay to BaseTexture \n", This);
186 return IWineD3DBaseTextureImpl_BindTexture((IWineD3DBaseTexture *)iface);
189 HRESULT WINAPI IWineD3DTextureImpl_UnBindTexture(IWineD3DTexture *iface) {
190 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
191 TRACE("(%p) : relay to BaseTexture \n", This);
192 return IWineD3DBaseTextureImpl_UnBindTexture((IWineD3DBaseTexture *)iface);
195 UINT WINAPI IWineD3DTextureImpl_GetTextureDimensions(IWineD3DTexture *iface) {
196 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
197 TRACE("(%p) \n", This);
199 return GL_TEXTURE_2D;
203 /* *******************************************
204 IWineD3DTexture IWineD3DTexture parts follow
205 ******************************************* */
206 HRESULT WINAPI IWineD3DTextureImpl_GetLevelDesc(IWineD3DTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
207 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
209 if (Level < This->baseTexture.levels) {
210 TRACE("(%p) Level (%d)\n", This, Level);
211 return IWineD3DSurface_GetDesc(This->surfaces[Level], pDesc);
213 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
214 return D3DERR_INVALIDCALL;
217 HRESULT WINAPI IWineD3DTextureImpl_GetSurfaceLevel(IWineD3DTexture *iface, UINT Level, IWineD3DSurface** ppSurfaceLevel) {
218 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
219 HRESULT hr = D3DERR_INVALIDCALL;
221 if (Level < This->baseTexture.levels) {
222 *ppSurfaceLevel = This->surfaces[Level];
223 IWineD3DSurface_AddRef((IWineD3DSurface*) This->surfaces[Level]);
225 TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level);
228 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
229 *ppSurfaceLevel = NULL; /* Just to be on the safe side.. */
234 HRESULT WINAPI IWineD3DTextureImpl_LockRect(IWineD3DTexture *iface, UINT Level, D3DLOCKED_RECT *pLockedRect,
235 CONST RECT *pRect, DWORD Flags) {
236 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
237 HRESULT hr = D3DERR_INVALIDCALL;
239 if (Level < This->baseTexture.levels) {
240 hr = IWineD3DSurface_LockRect(This->surfaces[Level], pLockedRect, pRect, Flags);
243 TRACE("(%p) Level (%d) success\n", This, Level);
245 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
251 HRESULT WINAPI IWineD3DTextureImpl_UnlockRect(IWineD3DTexture *iface, UINT Level) {
252 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
253 HRESULT hr = D3DERR_INVALIDCALL;
255 if (Level < This->baseTexture.levels) {
256 hr = IWineD3DSurface_UnlockRect(This->surfaces[Level]);
259 TRACE("(%p) Level (%d) success\n", This, Level);
261 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
266 HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRect(IWineD3DTexture *iface, CONST RECT* pDirtyRect) {
267 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
268 This->baseTexture.dirty = TRUE;
269 TRACE("(%p) : dirtyfication of surface Level (0)\n", This);
270 return IWineD3DSurface_AddDirtyRect(This->surfaces[0], pDirtyRect);
273 const IWineD3DTextureVtbl IWineD3DTexture_Vtbl =
276 IWineD3DTextureImpl_QueryInterface,
277 IWineD3DTextureImpl_AddRef,
278 IWineD3DTextureImpl_Release,
279 /* IWineD3DResource */
280 IWineD3DTextureImpl_GetParent,
281 IWineD3DTextureImpl_GetDevice,
282 IWineD3DTextureImpl_SetPrivateData,
283 IWineD3DTextureImpl_GetPrivateData,
284 IWineD3DTextureImpl_FreePrivateData,
285 IWineD3DTextureImpl_SetPriority,
286 IWineD3DTextureImpl_GetPriority,
287 IWineD3DTextureImpl_PreLoad,
288 IWineD3DTextureImpl_GetType,
289 /* IWineD3DBaseTexture */
290 IWineD3DTextureImpl_SetLOD,
291 IWineD3DTextureImpl_GetLOD,
292 IWineD3DTextureImpl_GetLevelCount,
293 IWineD3DTextureImpl_SetAutoGenFilterType,
294 IWineD3DTextureImpl_GetAutoGenFilterType,
295 IWineD3DTextureImpl_GenerateMipSubLevels,
296 IWineD3DTextureImpl_SetDirty,
297 IWineD3DTextureImpl_GetDirty,
298 IWineD3DTextureImpl_BindTexture,
299 IWineD3DTextureImpl_UnBindTexture,
300 IWineD3DTextureImpl_GetTextureDimensions,
301 /* IWineD3DTexture */
302 IWineD3DTextureImpl_GetLevelDesc,
303 IWineD3DTextureImpl_GetSurfaceLevel,
304 IWineD3DTextureImpl_LockRect,
305 IWineD3DTextureImpl_UnlockRect,
306 IWineD3DTextureImpl_AddDirtyRect