Make all newly created surfces dirty, so that they are loaded properly
[wine/multimedia.git] / dlls / wined3d / texture.c
blob980693857ad7c2540a8fee7b86c1fdc47ae46d95
1 /*
2 * IDirect3DTexture9 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
23 #include "config.h"
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);
41 *ppobj = This;
42 return D3D_OK;
44 return E_NOINTERFACE;
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 IUnknown_AddRef(This->resource.parent);
51 return InterlockedIncrement(&This->resource.ref);
54 ULONG WINAPI IWineD3DTextureImpl_Release(IWineD3DTexture *iface) {
55 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
56 ULONG ref;
57 TRACE("(%p) : Releasing from %ld\n", This, This->resource.ref);
58 ref = InterlockedDecrement(&This->resource.ref);
59 if (ref == 0) {
60 int i;
61 for (i = 0; i < This->baseTexture.levels; i++) {
62 if (This->surfaces[i] != NULL) {
63 /* Because the surfaces were created using a callback we need to release there parent otehrwise we leave the parent hanging */
64 IUnknown* surfaceParent;
65 IWineD3DSurface_GetParent(This->surfaces[i], &surfaceParent);
66 IUnknown_Release(surfaceParent);
67 IUnknown_Release(surfaceParent);
71 IWineD3DBaseTextureImpl_CleanUp((IWineD3DBaseTexture *)iface);
72 HeapFree(GetProcessHeap(), 0, This);
73 } else {
74 IUnknown_Release(This->resource.parent); /* Released the reference to the d3dx object */
76 return ref;
79 /* ****************************************************
80 IWineD3DTexture IWineD3DResource parts follow
81 **************************************************** */
82 HRESULT WINAPI IWineD3DTextureImpl_GetDevice(IWineD3DTexture *iface, IWineD3DDevice** ppDevice) {
83 return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
86 HRESULT WINAPI IWineD3DTextureImpl_SetPrivateData(IWineD3DTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
87 return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
90 HRESULT WINAPI IWineD3DTextureImpl_GetPrivateData(IWineD3DTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
91 return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
94 HRESULT WINAPI IWineD3DTextureImpl_FreePrivateData(IWineD3DTexture *iface, REFGUID refguid) {
95 return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
98 DWORD WINAPI IWineD3DTextureImpl_SetPriority(IWineD3DTexture *iface, DWORD PriorityNew) {
99 return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
102 DWORD WINAPI IWineD3DTextureImpl_GetPriority(IWineD3DTexture *iface) {
103 return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
106 void WINAPI IWineD3DTextureImpl_PreLoad(IWineD3DTexture *iface) {
108 /* Override the IWineD3DResource PreLoad method */
109 unsigned int i;
110 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
112 TRACE("(%p) : About to load texture\n", This);
114 IWineD3DTexture_BindTexture(iface);
115 ENTER_GL();
116 /* If were dirty then reload the surfaces */
117 if(This->baseTexture.dirty != FALSE) {
118 for (i = 0; i < This->baseTexture.levels; i++) {
119 IWineD3DSurface_LoadTexture(This->surfaces[i], GL_TEXTURE_2D, i);
122 /* No longer dirty */
123 This->baseTexture.dirty = FALSE;
125 LEAVE_GL();
127 return ;
130 D3DRESOURCETYPE WINAPI IWineD3DTextureImpl_GetType(IWineD3DTexture *iface) {
131 return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
134 HRESULT WINAPI IWineD3DTextureImpl_GetParent(IWineD3DTexture *iface, IUnknown **pParent) {
135 return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
138 /* ******************************************************
139 IWineD3DTexture IWineD3DBaseTexture parts follow
140 ****************************************************** */
141 DWORD WINAPI IWineD3DTextureImpl_SetLOD(IWineD3DTexture *iface, DWORD LODNew) {
142 return IWineD3DBaseTextureImpl_SetLOD((IWineD3DBaseTexture *)iface, LODNew);
145 DWORD WINAPI IWineD3DTextureImpl_GetLOD(IWineD3DTexture *iface) {
146 return IWineD3DBaseTextureImpl_GetLOD((IWineD3DBaseTexture *)iface);
149 DWORD WINAPI IWineD3DTextureImpl_GetLevelCount(IWineD3DTexture *iface) {
150 return IWineD3DBaseTextureImpl_GetLevelCount((IWineD3DBaseTexture *)iface);
153 HRESULT WINAPI IWineD3DTextureImpl_SetAutoGenFilterType(IWineD3DTexture *iface, D3DTEXTUREFILTERTYPE FilterType) {
154 return IWineD3DBaseTextureImpl_SetAutoGenFilterType((IWineD3DBaseTexture *)iface, FilterType);
157 D3DTEXTUREFILTERTYPE WINAPI IWineD3DTextureImpl_GetAutoGenFilterType(IWineD3DTexture *iface) {
158 return IWineD3DBaseTextureImpl_GetAutoGenFilterType((IWineD3DBaseTexture *)iface);
161 void WINAPI IWineD3DTextureImpl_GenerateMipSubLevels(IWineD3DTexture *iface) {
162 return IWineD3DBaseTextureImpl_GenerateMipSubLevels((IWineD3DBaseTexture *)iface);
165 /* Internal function, No d3d mapping */
166 BOOL WINAPI IWineD3DTextureImpl_SetDirty(IWineD3DTexture *iface, BOOL dirty) {
167 return IWineD3DBaseTextureImpl_SetDirty((IWineD3DBaseTexture *)iface, TRUE);
170 BOOL WINAPI IWineD3DTextureImpl_GetDirty(IWineD3DTexture *iface) {
171 return IWineD3DBaseTextureImpl_GetDirty((IWineD3DBaseTexture *)iface);
174 HRESULT WINAPI IWineD3DTextureImpl_BindTexture(IWineD3DTexture *iface) {
175 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
176 TRACE("(%p) : relay to BaseTexture \n", This);
177 return IWineD3DBaseTextureImpl_BindTexture((IWineD3DBaseTexture *)iface);
180 HRESULT WINAPI IWineD3DTextureImpl_UnBindTexture(IWineD3DTexture *iface) {
181 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
182 TRACE("(%p) : relay to BaseTexture \n", This);
183 return IWineD3DBaseTextureImpl_UnBindTexture((IWineD3DBaseTexture *)iface);
186 UINT WINAPI IWineD3DTextureImpl_GetTextureDimensions(IWineD3DTexture *iface) {
187 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
188 TRACE("(%p) \n", This);
190 return GL_TEXTURE_2D;
194 /* *******************************************
195 IWineD3DTexture IWineD3DTexture parts follow
196 ******************************************* */
197 HRESULT WINAPI IWineD3DTextureImpl_GetLevelDesc(IWineD3DTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
198 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
200 if (Level < This->baseTexture.levels) {
201 TRACE("(%p) Level (%d)\n", This, Level);
202 return IWineD3DSurface_GetDesc((IWineD3DSurface *) This->surfaces[Level], pDesc);
204 FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
205 return D3DERR_INVALIDCALL;
208 HRESULT WINAPI IWineD3DTextureImpl_GetSurfaceLevel(IWineD3DTexture *iface, UINT Level, IWineD3DSurface** ppSurfaceLevel) {
209 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
210 HRESULT hr = D3DERR_INVALIDCALL;
212 if (Level < This->baseTexture.levels) {
213 *ppSurfaceLevel = This->surfaces[Level];
214 IWineD3DSurface_AddRef((IWineD3DSurface*) This->surfaces[Level]);
215 hr = D3D_OK;
216 TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level);
218 if (D3D_OK != hr) {
219 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
220 *ppSurfaceLevel = NULL; /* Just to be on the safe side.. */
222 return hr;
225 HRESULT WINAPI IWineD3DTextureImpl_LockRect(IWineD3DTexture *iface, UINT Level, D3DLOCKED_RECT *pLockedRect,
226 CONST RECT *pRect, DWORD Flags) {
227 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
228 HRESULT hr = D3DERR_INVALIDCALL;
230 if (Level < This->baseTexture.levels) {
231 hr = IWineD3DSurface_LockRect((IWineD3DSurface *) This->surfaces[Level], pLockedRect, pRect, Flags);
233 if (D3D_OK == hr) {
234 TRACE("(%p) Level (%d) success\n", This, Level);
235 } else {
236 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
239 return hr;
242 HRESULT WINAPI IWineD3DTextureImpl_UnlockRect(IWineD3DTexture *iface, UINT Level) {
243 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
244 HRESULT hr = D3DERR_INVALIDCALL;
246 if (Level < This->baseTexture.levels) {
247 hr = IWineD3DSurface_UnlockRect(This->surfaces[Level]);
249 if ( D3D_OK == hr) {
250 TRACE("(%p) Level (%d) success\n", This, Level);
251 } else {
252 WARN("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
254 return hr;
257 HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRect(IWineD3DTexture *iface, CONST RECT* pDirtyRect) {
258 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
259 This->baseTexture.dirty = TRUE;
260 TRACE("(%p) : dirtyfication of surface Level (0)\n", This);
261 return IWineD3DSurface_AddDirtyRect((IWineD3DSurface *)This->surfaces[0], pDirtyRect);
264 const IWineD3DTextureVtbl IWineD3DTexture_Vtbl =
266 /* IUnknown */
267 IWineD3DTextureImpl_QueryInterface,
268 IWineD3DTextureImpl_AddRef,
269 IWineD3DTextureImpl_Release,
270 /* IWineD3DResource */
271 IWineD3DTextureImpl_GetParent,
272 IWineD3DTextureImpl_GetDevice,
273 IWineD3DTextureImpl_SetPrivateData,
274 IWineD3DTextureImpl_GetPrivateData,
275 IWineD3DTextureImpl_FreePrivateData,
276 IWineD3DTextureImpl_SetPriority,
277 IWineD3DTextureImpl_GetPriority,
278 IWineD3DTextureImpl_PreLoad,
279 IWineD3DTextureImpl_GetType,
280 /* IWineD3DBaseTexture */
281 IWineD3DTextureImpl_SetLOD,
282 IWineD3DTextureImpl_GetLOD,
283 IWineD3DTextureImpl_GetLevelCount,
284 IWineD3DTextureImpl_SetAutoGenFilterType,
285 IWineD3DTextureImpl_GetAutoGenFilterType,
286 IWineD3DTextureImpl_GenerateMipSubLevels,
287 IWineD3DTextureImpl_SetDirty,
288 IWineD3DTextureImpl_GetDirty,
289 IWineD3DTextureImpl_BindTexture,
290 IWineD3DTextureImpl_UnBindTexture,
291 IWineD3DTextureImpl_GetTextureDimensions,
292 /* IWineD3DTexture */
293 IWineD3DTextureImpl_GetLevelDesc,
294 IWineD3DTextureImpl_GetSurfaceLevel,
295 IWineD3DTextureImpl_LockRect,
296 IWineD3DTextureImpl_UnlockRect,
297 IWineD3DTextureImpl_AddDirtyRect