1 | /*
|
---|
2 | * IWineD3DVolumeTexture implementation
|
---|
3 | *
|
---|
4 | * Copyright 2002-2005 Jason Edmeades
|
---|
5 | * Copyright 2002-2005 Raphael Junqueira
|
---|
6 | * Copyright 2005 Oliver Stieber
|
---|
7 | *
|
---|
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.
|
---|
12 | *
|
---|
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.
|
---|
17 | *
|
---|
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
25 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
26 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
27 | * a choice of LGPL license versions is made available with the language indicating
|
---|
28 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
29 | * of the LGPL is applied is otherwise unspecified.
|
---|
30 | */
|
---|
31 |
|
---|
32 | #include "config.h"
|
---|
33 | #include "wined3d_private.h"
|
---|
34 |
|
---|
35 | WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
|
---|
36 | #define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
|
---|
37 |
|
---|
38 | /* *******************************************
|
---|
39 | IWineD3DTexture IUnknown parts follow
|
---|
40 | ******************************************* */
|
---|
41 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_QueryInterface(IWineD3DVolumeTexture *iface, REFIID riid, LPVOID *ppobj)
|
---|
42 | {
|
---|
43 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
44 | TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
|
---|
45 | if (IsEqualGUID(riid, &IID_IUnknown)
|
---|
46 | || IsEqualGUID(riid, &IID_IWineD3DBase)
|
---|
47 | || IsEqualGUID(riid, &IID_IWineD3DResource)
|
---|
48 | || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)
|
---|
49 | || IsEqualGUID(riid, &IID_IWineD3DVolumeTexture)) {
|
---|
50 | IUnknown_AddRef(iface);
|
---|
51 | *ppobj = This;
|
---|
52 | return S_OK;
|
---|
53 | }
|
---|
54 | *ppobj = NULL;
|
---|
55 | return E_NOINTERFACE;
|
---|
56 | }
|
---|
57 |
|
---|
58 | static ULONG WINAPI IWineD3DVolumeTextureImpl_AddRef(IWineD3DVolumeTexture *iface) {
|
---|
59 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
60 | TRACE("(%p) : AddRef increasing from %d\n", This, This->resource.ref);
|
---|
61 | return InterlockedIncrement(&This->resource.ref);
|
---|
62 | }
|
---|
63 |
|
---|
64 | static ULONG WINAPI IWineD3DVolumeTextureImpl_Release(IWineD3DVolumeTexture *iface) {
|
---|
65 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
66 | ULONG ref;
|
---|
67 | TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
|
---|
68 | ref = InterlockedDecrement(&This->resource.ref);
|
---|
69 | if (ref == 0) {
|
---|
70 | IWineD3DVolumeTexture_Destroy(iface, D3DCB_DefaultDestroyVolume);
|
---|
71 | }
|
---|
72 | return ref;
|
---|
73 | }
|
---|
74 |
|
---|
75 | /* ****************************************************
|
---|
76 | IWineD3DVolumeTexture IWineD3DResource parts follow
|
---|
77 | **************************************************** */
|
---|
78 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetDevice(IWineD3DVolumeTexture *iface, IWineD3DDevice** ppDevice) {
|
---|
79 | return resource_get_device((IWineD3DResource *)iface, ppDevice);
|
---|
80 | }
|
---|
81 |
|
---|
82 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_SetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
|
---|
83 | return resource_set_private_data((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
|
---|
84 | }
|
---|
85 |
|
---|
86 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
|
---|
87 | return resource_get_private_data((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
|
---|
88 | }
|
---|
89 |
|
---|
90 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_FreePrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid) {
|
---|
91 | return resource_free_private_data((IWineD3DResource *)iface, refguid);
|
---|
92 | }
|
---|
93 |
|
---|
94 | static DWORD WINAPI IWineD3DVolumeTextureImpl_SetPriority(IWineD3DVolumeTexture *iface, DWORD PriorityNew) {
|
---|
95 | return resource_set_priority((IWineD3DResource *)iface, PriorityNew);
|
---|
96 | }
|
---|
97 |
|
---|
98 | static DWORD WINAPI IWineD3DVolumeTextureImpl_GetPriority(IWineD3DVolumeTexture *iface) {
|
---|
99 | return resource_get_priority((IWineD3DResource *)iface);
|
---|
100 | }
|
---|
101 |
|
---|
102 | void volumetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb) {
|
---|
103 | /* Overrider the IWineD3DResource Preload method */
|
---|
104 | unsigned int i;
|
---|
105 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
106 | IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
---|
107 | BOOL srgb_mode = This->baseTexture.is_srgb;
|
---|
108 | BOOL srgb_was_toggled = FALSE;
|
---|
109 |
|
---|
110 | TRACE("(%p) : About to load texture\n", This);
|
---|
111 |
|
---|
112 | if(!device->isInDraw) {
|
---|
113 | ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
|
---|
114 | } else if (GL_SUPPORT(EXT_TEXTURE_SRGB) && This->baseTexture.bindCount > 0) {
|
---|
115 | srgb_mode = device->stateBlock->samplerState[This->baseTexture.sampler][WINED3DSAMP_SRGBTEXTURE];
|
---|
116 | srgb_was_toggled = This->baseTexture.is_srgb != srgb_mode;
|
---|
117 | This->baseTexture.is_srgb = srgb_mode;
|
---|
118 | }
|
---|
119 |
|
---|
120 | /* If the texture is marked dirty or the srgb sampler setting has changed since the last load then reload the surfaces */
|
---|
121 | if (This->baseTexture.dirty) {
|
---|
122 | for (i = 0; i < This->baseTexture.levels; i++)
|
---|
123 | IWineD3DVolume_LoadTexture(This->volumes[i], i, srgb_mode);
|
---|
124 | } else if (srgb_was_toggled) {
|
---|
125 | for (i = 0; i < This->baseTexture.levels; i++) {
|
---|
126 | volume_add_dirty_box(This->volumes[i], NULL);
|
---|
127 | IWineD3DVolume_LoadTexture(This->volumes[i], i, srgb_mode);
|
---|
128 | }
|
---|
129 | } else {
|
---|
130 | TRACE("(%p) Texture not dirty, nothing to do\n" , iface);
|
---|
131 | }
|
---|
132 |
|
---|
133 | /* No longer dirty */
|
---|
134 | This->baseTexture.dirty = FALSE;
|
---|
135 |
|
---|
136 | return ;
|
---|
137 | }
|
---|
138 |
|
---|
139 | static void WINAPI IWineD3DVolumeTextureImpl_PreLoad(IWineD3DVolumeTexture *iface) {
|
---|
140 | volumetexture_internal_preload((IWineD3DBaseTexture *) iface, SRGB_ANY);
|
---|
141 | }
|
---|
142 |
|
---|
143 | static void WINAPI IWineD3DVolumeTextureImpl_UnLoad(IWineD3DVolumeTexture *iface) {
|
---|
144 | unsigned int i;
|
---|
145 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
146 | TRACE("(%p)\n", This);
|
---|
147 |
|
---|
148 | /* Unload all the surfaces and reset the texture name. If UnLoad was called on the
|
---|
149 | * surface before, this one will be a NOP and vice versa. Unloading an unloaded
|
---|
150 | * surface is fine
|
---|
151 | */
|
---|
152 | for (i = 0; i < This->baseTexture.levels; i++) {
|
---|
153 | IWineD3DVolume_UnLoad(This->volumes[i]);
|
---|
154 | }
|
---|
155 |
|
---|
156 | basetexture_unload((IWineD3DBaseTexture *)iface);
|
---|
157 | }
|
---|
158 |
|
---|
159 | static WINED3DRESOURCETYPE WINAPI IWineD3DVolumeTextureImpl_GetType(IWineD3DVolumeTexture *iface) {
|
---|
160 | return resource_get_type((IWineD3DResource *)iface);
|
---|
161 | }
|
---|
162 |
|
---|
163 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetParent(IWineD3DVolumeTexture *iface, IUnknown **pParent) {
|
---|
164 | return resource_get_parent((IWineD3DResource *)iface, pParent);
|
---|
165 | }
|
---|
166 |
|
---|
167 | /* ******************************************************
|
---|
168 | IWineD3DVolumeTexture IWineD3DBaseTexture parts follow
|
---|
169 | ****************************************************** */
|
---|
170 | static DWORD WINAPI IWineD3DVolumeTextureImpl_SetLOD(IWineD3DVolumeTexture *iface, DWORD LODNew) {
|
---|
171 | return basetexture_set_lod((IWineD3DBaseTexture *)iface, LODNew);
|
---|
172 | }
|
---|
173 |
|
---|
174 | static DWORD WINAPI IWineD3DVolumeTextureImpl_GetLOD(IWineD3DVolumeTexture *iface) {
|
---|
175 | return basetexture_get_lod((IWineD3DBaseTexture *)iface);
|
---|
176 | }
|
---|
177 |
|
---|
178 | static DWORD WINAPI IWineD3DVolumeTextureImpl_GetLevelCount(IWineD3DVolumeTexture *iface) {
|
---|
179 | return basetexture_get_level_count((IWineD3DBaseTexture *)iface);
|
---|
180 | }
|
---|
181 |
|
---|
182 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_SetAutoGenFilterType(IWineD3DVolumeTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
|
---|
183 | return basetexture_set_autogen_filter_type((IWineD3DBaseTexture *)iface, FilterType);
|
---|
184 | }
|
---|
185 |
|
---|
186 | static WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DVolumeTextureImpl_GetAutoGenFilterType(IWineD3DVolumeTexture *iface) {
|
---|
187 | return basetexture_get_autogen_filter_type((IWineD3DBaseTexture *)iface);
|
---|
188 | }
|
---|
189 |
|
---|
190 | static void WINAPI IWineD3DVolumeTextureImpl_GenerateMipSubLevels(IWineD3DVolumeTexture *iface) {
|
---|
191 | basetexture_generate_mipmaps((IWineD3DBaseTexture *)iface);
|
---|
192 | }
|
---|
193 |
|
---|
194 | /* Internal function, No d3d mapping */
|
---|
195 | static BOOL WINAPI IWineD3DVolumeTextureImpl_SetDirty(IWineD3DVolumeTexture *iface, BOOL dirty) {
|
---|
196 | return basetexture_set_dirty((IWineD3DBaseTexture *)iface, dirty);
|
---|
197 | }
|
---|
198 |
|
---|
199 | static BOOL WINAPI IWineD3DVolumeTextureImpl_GetDirty(IWineD3DVolumeTexture *iface) {
|
---|
200 | return basetexture_get_dirty((IWineD3DBaseTexture *)iface);
|
---|
201 | }
|
---|
202 |
|
---|
203 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_BindTexture(IWineD3DVolumeTexture *iface, BOOL srgb) {
|
---|
204 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
205 | BOOL dummy;
|
---|
206 | TRACE("(%p) : relay to BaseTexture\n", This);
|
---|
207 | return basetexture_bind((IWineD3DBaseTexture *)iface, srgb, &dummy);
|
---|
208 | }
|
---|
209 |
|
---|
210 | static UINT WINAPI IWineD3DVolumeTextureImpl_GetTextureDimensions(IWineD3DVolumeTexture *iface) {
|
---|
211 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
212 | TRACE("(%p)\n", This);
|
---|
213 | return GL_TEXTURE_3D;
|
---|
214 | }
|
---|
215 |
|
---|
216 | static BOOL WINAPI IWineD3DVolumeTextureImpl_IsCondNP2(IWineD3DVolumeTexture *iface) {
|
---|
217 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
218 | TRACE("(%p)\n", This);
|
---|
219 |
|
---|
220 | return FALSE;
|
---|
221 | }
|
---|
222 |
|
---|
223 | static void WINAPI IWineD3DVolumeTextureImpl_ApplyStateChanges(IWineD3DVolumeTexture *iface,
|
---|
224 | const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1],
|
---|
225 | const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]) {
|
---|
226 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
227 | TRACE("(%p) : nothing to do, passing to base texture\n", This);
|
---|
228 | basetexture_apply_state_changes((IWineD3DBaseTexture *)iface, textureStates, samplerStates);
|
---|
229 | }
|
---|
230 |
|
---|
231 |
|
---|
232 | /* *******************************************
|
---|
233 | IWineD3DVolumeTexture IWineD3DVolumeTexture parts follow
|
---|
234 | ******************************************* */
|
---|
235 | static void WINAPI IWineD3DVolumeTextureImpl_Destroy(IWineD3DVolumeTexture *iface, D3DCB_DESTROYVOLUMEFN D3DCB_DestroyVolume) {
|
---|
236 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
237 | unsigned int i;
|
---|
238 | TRACE("(%p) : Cleaning up\n",This);
|
---|
239 | for (i = 0; i < This->baseTexture.levels; i++) {
|
---|
240 | if (This->volumes[i] != NULL) {
|
---|
241 | /* Cleanup the container */
|
---|
242 | IWineD3DVolume_SetContainer(This->volumes[i], 0);
|
---|
243 | D3DCB_DestroyVolume(This->volumes[i]);
|
---|
244 | }
|
---|
245 | }
|
---|
246 | basetexture_cleanup((IWineD3DBaseTexture *)iface);
|
---|
247 | HeapFree(GetProcessHeap(), 0, This);
|
---|
248 | }
|
---|
249 |
|
---|
250 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetLevelDesc(IWineD3DVolumeTexture *iface, UINT Level,WINED3DVOLUME_DESC *pDesc) {
|
---|
251 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
252 | if (Level < This->baseTexture.levels) {
|
---|
253 | TRACE("(%p) Level (%d)\n", This, Level);
|
---|
254 | return IWineD3DVolume_GetDesc(This->volumes[Level], pDesc);
|
---|
255 | } else {
|
---|
256 | WARN("(%p) Level (%d)\n", This, Level);
|
---|
257 | }
|
---|
258 | return WINED3D_OK;
|
---|
259 | }
|
---|
260 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetVolumeLevel(IWineD3DVolumeTexture *iface, UINT Level, IWineD3DVolume** ppVolumeLevel) {
|
---|
261 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
262 | if (Level < This->baseTexture.levels) {
|
---|
263 | *ppVolumeLevel = This->volumes[Level];
|
---|
264 | IWineD3DVolume_AddRef(*ppVolumeLevel);
|
---|
265 | TRACE("(%p) -> level(%d) returning volume@%p\n", This, Level, *ppVolumeLevel);
|
---|
266 | } else {
|
---|
267 | WARN("(%p) Level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
|
---|
268 | return WINED3DERR_INVALIDCALL;
|
---|
269 | }
|
---|
270 | return WINED3D_OK;
|
---|
271 |
|
---|
272 | }
|
---|
273 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_LockBox(IWineD3DVolumeTexture *iface, UINT Level, WINED3DLOCKED_BOX* pLockedVolume, CONST WINED3DBOX* pBox, DWORD Flags) {
|
---|
274 | HRESULT hr;
|
---|
275 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
276 |
|
---|
277 | if (Level < This->baseTexture.levels) {
|
---|
278 | hr = IWineD3DVolume_LockBox(This->volumes[Level], pLockedVolume, pBox, Flags);
|
---|
279 | TRACE("(%p) Level (%d) success(%u)\n", This, Level, hr);
|
---|
280 |
|
---|
281 | } else {
|
---|
282 | FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
|
---|
283 | return WINED3DERR_INVALIDCALL;
|
---|
284 | }
|
---|
285 | return hr;
|
---|
286 | }
|
---|
287 |
|
---|
288 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_UnlockBox(IWineD3DVolumeTexture *iface, UINT Level) {
|
---|
289 | HRESULT hr;
|
---|
290 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
291 |
|
---|
292 | if (Level < This->baseTexture.levels) {
|
---|
293 | hr = IWineD3DVolume_UnlockBox(This->volumes[Level]);
|
---|
294 | TRACE("(%p) -> level(%d) success(%u)\n", This, Level, hr);
|
---|
295 |
|
---|
296 | } else {
|
---|
297 | FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
|
---|
298 | return WINED3DERR_INVALIDCALL;
|
---|
299 | }
|
---|
300 | return hr;
|
---|
301 | }
|
---|
302 |
|
---|
303 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_AddDirtyBox(IWineD3DVolumeTexture *iface, CONST WINED3DBOX* pDirtyBox) {
|
---|
304 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
305 | This->baseTexture.dirty = TRUE;
|
---|
306 | TRACE("(%p) : dirtyfication of volume Level (0)\n", This);
|
---|
307 | volume_add_dirty_box(This->volumes[0], pDirtyBox);
|
---|
308 |
|
---|
309 | return WINED3D_OK;
|
---|
310 | }
|
---|
311 |
|
---|
312 | const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl =
|
---|
313 | {
|
---|
314 | /* IUnknown */
|
---|
315 | IWineD3DVolumeTextureImpl_QueryInterface,
|
---|
316 | IWineD3DVolumeTextureImpl_AddRef,
|
---|
317 | IWineD3DVolumeTextureImpl_Release,
|
---|
318 | /* resource */
|
---|
319 | IWineD3DVolumeTextureImpl_GetParent,
|
---|
320 | IWineD3DVolumeTextureImpl_GetDevice,
|
---|
321 | IWineD3DVolumeTextureImpl_SetPrivateData,
|
---|
322 | IWineD3DVolumeTextureImpl_GetPrivateData,
|
---|
323 | IWineD3DVolumeTextureImpl_FreePrivateData,
|
---|
324 | IWineD3DVolumeTextureImpl_SetPriority,
|
---|
325 | IWineD3DVolumeTextureImpl_GetPriority,
|
---|
326 | IWineD3DVolumeTextureImpl_PreLoad,
|
---|
327 | IWineD3DVolumeTextureImpl_UnLoad,
|
---|
328 | IWineD3DVolumeTextureImpl_GetType,
|
---|
329 | /* BaseTexture */
|
---|
330 | IWineD3DVolumeTextureImpl_SetLOD,
|
---|
331 | IWineD3DVolumeTextureImpl_GetLOD,
|
---|
332 | IWineD3DVolumeTextureImpl_GetLevelCount,
|
---|
333 | IWineD3DVolumeTextureImpl_SetAutoGenFilterType,
|
---|
334 | IWineD3DVolumeTextureImpl_GetAutoGenFilterType,
|
---|
335 | IWineD3DVolumeTextureImpl_GenerateMipSubLevels,
|
---|
336 | IWineD3DVolumeTextureImpl_SetDirty,
|
---|
337 | IWineD3DVolumeTextureImpl_GetDirty,
|
---|
338 | /* not in d3d */
|
---|
339 | IWineD3DVolumeTextureImpl_BindTexture,
|
---|
340 | IWineD3DVolumeTextureImpl_GetTextureDimensions,
|
---|
341 | IWineD3DVolumeTextureImpl_IsCondNP2,
|
---|
342 | IWineD3DVolumeTextureImpl_ApplyStateChanges,
|
---|
343 | /* volume texture */
|
---|
344 | IWineD3DVolumeTextureImpl_Destroy,
|
---|
345 | IWineD3DVolumeTextureImpl_GetLevelDesc,
|
---|
346 | IWineD3DVolumeTextureImpl_GetVolumeLevel,
|
---|
347 | IWineD3DVolumeTextureImpl_LockBox,
|
---|
348 | IWineD3DVolumeTextureImpl_UnlockBox,
|
---|
349 | IWineD3DVolumeTextureImpl_AddDirtyBox
|
---|
350 | };
|
---|