1 | /*
|
---|
2 | * IWineD3DVolumeTexture implementation
|
---|
3 | *
|
---|
4 | * Copyright 2002-2005 Jason Edmeades
|
---|
5 | * Copyright 2002-2005 Raphael Junqueira
|
---|
6 | * Copyright 2005 Oliver Stieber
|
---|
7 | * Copyright 2009 Henri Verbeet for CodeWeavers
|
---|
8 | *
|
---|
9 | * This library is free software; you can redistribute it and/or
|
---|
10 | * modify it under the terms of the GNU Lesser General Public
|
---|
11 | * License as published by the Free Software Foundation; either
|
---|
12 | * version 2.1 of the License, or (at your option) any later version.
|
---|
13 | *
|
---|
14 | * This library is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
17 | * Lesser General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU Lesser General Public
|
---|
20 | * License along with this library; if not, write to the Free Software
|
---|
21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
22 | */
|
---|
23 |
|
---|
24 | /*
|
---|
25 | * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
26 | * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
|
---|
27 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
28 | * a choice of LGPL license versions is made available with the language indicating
|
---|
29 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
30 | * of the LGPL is applied is otherwise unspecified.
|
---|
31 | */
|
---|
32 |
|
---|
33 | #include "config.h"
|
---|
34 | #include "wined3d_private.h"
|
---|
35 |
|
---|
36 | WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
|
---|
37 |
|
---|
38 | static void volumetexture_internal_preload(IWineD3DBaseTexture *iface, enum WINED3DSRGB srgb)
|
---|
39 | {
|
---|
40 | /* Override the IWineD3DResource Preload method. */
|
---|
41 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
42 | IWineD3DDeviceImpl *device = This->resource.device;
|
---|
43 | const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
---|
44 | struct wined3d_context *context = NULL;
|
---|
45 | BOOL srgb_mode = This->baseTexture.is_srgb;
|
---|
46 | BOOL srgb_was_toggled = FALSE;
|
---|
47 | unsigned int i;
|
---|
48 |
|
---|
49 | TRACE("(%p) : About to load texture.\n", This);
|
---|
50 |
|
---|
51 | if (!device->isInDraw) context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
|
---|
52 | else if (gl_info->supported[EXT_TEXTURE_SRGB] && This->baseTexture.bindCount > 0)
|
---|
53 | {
|
---|
54 | srgb_mode = device->stateBlock->samplerState[This->baseTexture.sampler][WINED3DSAMP_SRGBTEXTURE];
|
---|
55 | srgb_was_toggled = This->baseTexture.is_srgb != srgb_mode;
|
---|
56 | This->baseTexture.is_srgb = srgb_mode;
|
---|
57 | }
|
---|
58 |
|
---|
59 | /* If the texture is marked dirty or the srgb sampler setting has changed
|
---|
60 | * since the last load then reload the volumes. */
|
---|
61 | if (This->baseTexture.texture_rgb.dirty)
|
---|
62 | {
|
---|
63 | for (i = 0; i < This->baseTexture.levels; ++i)
|
---|
64 | {
|
---|
65 | IWineD3DVolume_LoadTexture(This->volumes[i], i, srgb_mode);
|
---|
66 | }
|
---|
67 | }
|
---|
68 | else if (srgb_was_toggled)
|
---|
69 | {
|
---|
70 | for (i = 0; i < This->baseTexture.levels; ++i)
|
---|
71 | {
|
---|
72 | volume_add_dirty_box(This->volumes[i], NULL);
|
---|
73 | IWineD3DVolume_LoadTexture(This->volumes[i], i, srgb_mode);
|
---|
74 | }
|
---|
75 | }
|
---|
76 | else
|
---|
77 | {
|
---|
78 | TRACE("(%p) Texture not dirty, nothing to do.\n", iface);
|
---|
79 | }
|
---|
80 |
|
---|
81 | if (context) context_release(context);
|
---|
82 |
|
---|
83 | /* No longer dirty */
|
---|
84 | This->baseTexture.texture_rgb.dirty = FALSE;
|
---|
85 | }
|
---|
86 |
|
---|
87 | static void volumetexture_cleanup(IWineD3DVolumeTextureImpl *This)
|
---|
88 | {
|
---|
89 | unsigned int i;
|
---|
90 |
|
---|
91 | TRACE("(%p) : Cleaning up.\n", This);
|
---|
92 |
|
---|
93 | for (i = 0; i < This->baseTexture.levels; ++i)
|
---|
94 | {
|
---|
95 | IWineD3DVolume *volume = This->volumes[i];
|
---|
96 |
|
---|
97 | if (volume)
|
---|
98 | {
|
---|
99 | /* Cleanup the container. */
|
---|
100 | IWineD3DVolume_SetContainer(volume, NULL);
|
---|
101 | IWineD3DVolume_Release(volume);
|
---|
102 | }
|
---|
103 | }
|
---|
104 | basetexture_cleanup((IWineD3DBaseTexture *)This);
|
---|
105 | }
|
---|
106 |
|
---|
107 | /* *******************************************
|
---|
108 | IWineD3DTexture IUnknown parts follow
|
---|
109 | ******************************************* */
|
---|
110 |
|
---|
111 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_QueryInterface(IWineD3DVolumeTexture *iface, REFIID riid, LPVOID *ppobj)
|
---|
112 | {
|
---|
113 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
114 | TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
|
---|
115 | if (IsEqualGUID(riid, &IID_IUnknown)
|
---|
116 | || IsEqualGUID(riid, &IID_IWineD3DBase)
|
---|
117 | || IsEqualGUID(riid, &IID_IWineD3DResource)
|
---|
118 | || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)
|
---|
119 | || IsEqualGUID(riid, &IID_IWineD3DVolumeTexture)) {
|
---|
120 | IUnknown_AddRef(iface);
|
---|
121 | *ppobj = This;
|
---|
122 | return S_OK;
|
---|
123 | }
|
---|
124 | *ppobj = NULL;
|
---|
125 | return E_NOINTERFACE;
|
---|
126 | }
|
---|
127 |
|
---|
128 | static ULONG WINAPI IWineD3DVolumeTextureImpl_AddRef(IWineD3DVolumeTexture *iface) {
|
---|
129 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
130 | TRACE("(%p) : AddRef increasing from %d\n", This, This->resource.ref);
|
---|
131 | return InterlockedIncrement(&This->resource.ref);
|
---|
132 | }
|
---|
133 |
|
---|
134 | static ULONG WINAPI IWineD3DVolumeTextureImpl_Release(IWineD3DVolumeTexture *iface) {
|
---|
135 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
136 | ULONG ref;
|
---|
137 | TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
|
---|
138 | ref = InterlockedDecrement(&This->resource.ref);
|
---|
139 | if (!ref)
|
---|
140 | {
|
---|
141 | volumetexture_cleanup(This);
|
---|
142 | This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
|
---|
143 | HeapFree(GetProcessHeap(), 0, This);
|
---|
144 | }
|
---|
145 | return ref;
|
---|
146 | }
|
---|
147 |
|
---|
148 | /* ****************************************************
|
---|
149 | IWineD3DVolumeTexture IWineD3DResource parts follow
|
---|
150 | **************************************************** */
|
---|
151 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_SetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
|
---|
152 | return resource_set_private_data((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
|
---|
153 | }
|
---|
154 |
|
---|
155 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetPrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
|
---|
156 | return resource_get_private_data((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
|
---|
157 | }
|
---|
158 |
|
---|
159 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_FreePrivateData(IWineD3DVolumeTexture *iface, REFGUID refguid) {
|
---|
160 | return resource_free_private_data((IWineD3DResource *)iface, refguid);
|
---|
161 | }
|
---|
162 |
|
---|
163 | static DWORD WINAPI IWineD3DVolumeTextureImpl_SetPriority(IWineD3DVolumeTexture *iface, DWORD PriorityNew) {
|
---|
164 | return resource_set_priority((IWineD3DResource *)iface, PriorityNew);
|
---|
165 | }
|
---|
166 |
|
---|
167 | static DWORD WINAPI IWineD3DVolumeTextureImpl_GetPriority(IWineD3DVolumeTexture *iface) {
|
---|
168 | return resource_get_priority((IWineD3DResource *)iface);
|
---|
169 | }
|
---|
170 |
|
---|
171 | static void WINAPI IWineD3DVolumeTextureImpl_PreLoad(IWineD3DVolumeTexture *iface) {
|
---|
172 | volumetexture_internal_preload((IWineD3DBaseTexture *) iface, SRGB_ANY);
|
---|
173 | }
|
---|
174 |
|
---|
175 | static void WINAPI IWineD3DVolumeTextureImpl_UnLoad(IWineD3DVolumeTexture *iface) {
|
---|
176 | unsigned int i;
|
---|
177 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
178 | TRACE("(%p)\n", This);
|
---|
179 |
|
---|
180 | /* Unload all the surfaces and reset the texture name. If UnLoad was called on the
|
---|
181 | * surface before, this one will be a NOP and vice versa. Unloading an unloaded
|
---|
182 | * surface is fine
|
---|
183 | */
|
---|
184 | for (i = 0; i < This->baseTexture.levels; i++) {
|
---|
185 | IWineD3DVolume_UnLoad(This->volumes[i]);
|
---|
186 | }
|
---|
187 |
|
---|
188 | basetexture_unload((IWineD3DBaseTexture *)iface);
|
---|
189 | }
|
---|
190 |
|
---|
191 | static WINED3DRESOURCETYPE WINAPI IWineD3DVolumeTextureImpl_GetType(IWineD3DVolumeTexture *iface) {
|
---|
192 | return resource_get_type((IWineD3DResource *)iface);
|
---|
193 | }
|
---|
194 |
|
---|
195 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetParent(IWineD3DVolumeTexture *iface, IUnknown **pParent) {
|
---|
196 | return resource_get_parent((IWineD3DResource *)iface, pParent);
|
---|
197 | }
|
---|
198 |
|
---|
199 | /* ******************************************************
|
---|
200 | IWineD3DVolumeTexture IWineD3DBaseTexture parts follow
|
---|
201 | ****************************************************** */
|
---|
202 | static DWORD WINAPI IWineD3DVolumeTextureImpl_SetLOD(IWineD3DVolumeTexture *iface, DWORD LODNew) {
|
---|
203 | return basetexture_set_lod((IWineD3DBaseTexture *)iface, LODNew);
|
---|
204 | }
|
---|
205 |
|
---|
206 | static DWORD WINAPI IWineD3DVolumeTextureImpl_GetLOD(IWineD3DVolumeTexture *iface) {
|
---|
207 | return basetexture_get_lod((IWineD3DBaseTexture *)iface);
|
---|
208 | }
|
---|
209 |
|
---|
210 | static DWORD WINAPI IWineD3DVolumeTextureImpl_GetLevelCount(IWineD3DVolumeTexture *iface) {
|
---|
211 | return basetexture_get_level_count((IWineD3DBaseTexture *)iface);
|
---|
212 | }
|
---|
213 |
|
---|
214 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_SetAutoGenFilterType(IWineD3DVolumeTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
|
---|
215 | return basetexture_set_autogen_filter_type((IWineD3DBaseTexture *)iface, FilterType);
|
---|
216 | }
|
---|
217 |
|
---|
218 | static WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DVolumeTextureImpl_GetAutoGenFilterType(IWineD3DVolumeTexture *iface) {
|
---|
219 | return basetexture_get_autogen_filter_type((IWineD3DBaseTexture *)iface);
|
---|
220 | }
|
---|
221 |
|
---|
222 | static void WINAPI IWineD3DVolumeTextureImpl_GenerateMipSubLevels(IWineD3DVolumeTexture *iface) {
|
---|
223 | basetexture_generate_mipmaps((IWineD3DBaseTexture *)iface);
|
---|
224 | }
|
---|
225 |
|
---|
226 | /* Internal function, No d3d mapping */
|
---|
227 | static BOOL WINAPI IWineD3DVolumeTextureImpl_SetDirty(IWineD3DVolumeTexture *iface, BOOL dirty) {
|
---|
228 | return basetexture_set_dirty((IWineD3DBaseTexture *)iface, dirty);
|
---|
229 | }
|
---|
230 |
|
---|
231 | static BOOL WINAPI IWineD3DVolumeTextureImpl_GetDirty(IWineD3DVolumeTexture *iface) {
|
---|
232 | return basetexture_get_dirty((IWineD3DBaseTexture *)iface);
|
---|
233 | }
|
---|
234 |
|
---|
235 | /* Context activation is done by the caller. */
|
---|
236 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_BindTexture(IWineD3DVolumeTexture *iface, BOOL srgb)
|
---|
237 | {
|
---|
238 | BOOL dummy;
|
---|
239 |
|
---|
240 | TRACE("iface %p, srgb %#x.\n", iface, srgb);
|
---|
241 |
|
---|
242 | return basetexture_bind((IWineD3DBaseTexture *)iface, srgb, &dummy);
|
---|
243 | }
|
---|
244 |
|
---|
245 | static UINT WINAPI IWineD3DVolumeTextureImpl_GetTextureDimensions(IWineD3DVolumeTexture *iface)
|
---|
246 | {
|
---|
247 | TRACE("iface %p.\n", iface);
|
---|
248 |
|
---|
249 | return GL_TEXTURE_3D;
|
---|
250 | }
|
---|
251 |
|
---|
252 | static BOOL WINAPI IWineD3DVolumeTextureImpl_IsCondNP2(IWineD3DVolumeTexture *iface)
|
---|
253 | {
|
---|
254 | TRACE("iface %p.\n", iface);
|
---|
255 |
|
---|
256 | return FALSE;
|
---|
257 | }
|
---|
258 |
|
---|
259 | /* *******************************************
|
---|
260 | IWineD3DVolumeTexture IWineD3DVolumeTexture parts follow
|
---|
261 | ******************************************* */
|
---|
262 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetLevelDesc(IWineD3DVolumeTexture *iface, UINT Level,WINED3DVOLUME_DESC *pDesc) {
|
---|
263 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
264 | if (Level < This->baseTexture.levels) {
|
---|
265 | TRACE("(%p) Level (%d)\n", This, Level);
|
---|
266 | return IWineD3DVolume_GetDesc(This->volumes[Level], pDesc);
|
---|
267 | } else {
|
---|
268 | WARN("(%p) Level (%d)\n", This, Level);
|
---|
269 | }
|
---|
270 | return WINED3D_OK;
|
---|
271 | }
|
---|
272 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetVolumeLevel(IWineD3DVolumeTexture *iface, UINT Level, IWineD3DVolume** ppVolumeLevel) {
|
---|
273 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
274 | if (Level < This->baseTexture.levels) {
|
---|
275 | *ppVolumeLevel = This->volumes[Level];
|
---|
276 | IWineD3DVolume_AddRef(*ppVolumeLevel);
|
---|
277 | TRACE("(%p) -> level(%d) returning volume@%p\n", This, Level, *ppVolumeLevel);
|
---|
278 | } else {
|
---|
279 | WARN("(%p) Level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
|
---|
280 | return WINED3DERR_INVALIDCALL;
|
---|
281 | }
|
---|
282 | return WINED3D_OK;
|
---|
283 |
|
---|
284 | }
|
---|
285 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_LockBox(IWineD3DVolumeTexture *iface, UINT Level, WINED3DLOCKED_BOX* pLockedVolume, CONST WINED3DBOX* pBox, DWORD Flags) {
|
---|
286 | HRESULT hr;
|
---|
287 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
288 |
|
---|
289 | if (Level < This->baseTexture.levels) {
|
---|
290 | hr = IWineD3DVolume_LockBox(This->volumes[Level], pLockedVolume, pBox, Flags);
|
---|
291 | TRACE("(%p) Level (%d) success(%u)\n", This, Level, hr);
|
---|
292 |
|
---|
293 | } else {
|
---|
294 | FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
|
---|
295 | return WINED3DERR_INVALIDCALL;
|
---|
296 | }
|
---|
297 | return hr;
|
---|
298 | }
|
---|
299 |
|
---|
300 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_UnlockBox(IWineD3DVolumeTexture *iface, UINT Level) {
|
---|
301 | HRESULT hr;
|
---|
302 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
303 |
|
---|
304 | if (Level < This->baseTexture.levels) {
|
---|
305 | hr = IWineD3DVolume_UnlockBox(This->volumes[Level]);
|
---|
306 | TRACE("(%p) -> level(%d) success(%u)\n", This, Level, hr);
|
---|
307 |
|
---|
308 | } else {
|
---|
309 | FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->baseTexture.levels);
|
---|
310 | return WINED3DERR_INVALIDCALL;
|
---|
311 | }
|
---|
312 | return hr;
|
---|
313 | }
|
---|
314 |
|
---|
315 | static HRESULT WINAPI IWineD3DVolumeTextureImpl_AddDirtyBox(IWineD3DVolumeTexture *iface, CONST WINED3DBOX* pDirtyBox) {
|
---|
316 | IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
|
---|
317 | This->baseTexture.texture_rgb.dirty = TRUE;
|
---|
318 | This->baseTexture.texture_srgb.dirty = TRUE;
|
---|
319 | TRACE("(%p) : dirtyfication of volume Level (0)\n", This);
|
---|
320 | volume_add_dirty_box(This->volumes[0], pDirtyBox);
|
---|
321 |
|
---|
322 | return WINED3D_OK;
|
---|
323 | }
|
---|
324 |
|
---|
325 | static const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl =
|
---|
326 | {
|
---|
327 | /* IUnknown */
|
---|
328 | IWineD3DVolumeTextureImpl_QueryInterface,
|
---|
329 | IWineD3DVolumeTextureImpl_AddRef,
|
---|
330 | IWineD3DVolumeTextureImpl_Release,
|
---|
331 | /* resource */
|
---|
332 | IWineD3DVolumeTextureImpl_GetParent,
|
---|
333 | IWineD3DVolumeTextureImpl_SetPrivateData,
|
---|
334 | IWineD3DVolumeTextureImpl_GetPrivateData,
|
---|
335 | IWineD3DVolumeTextureImpl_FreePrivateData,
|
---|
336 | IWineD3DVolumeTextureImpl_SetPriority,
|
---|
337 | IWineD3DVolumeTextureImpl_GetPriority,
|
---|
338 | IWineD3DVolumeTextureImpl_PreLoad,
|
---|
339 | IWineD3DVolumeTextureImpl_UnLoad,
|
---|
340 | IWineD3DVolumeTextureImpl_GetType,
|
---|
341 | /* BaseTexture */
|
---|
342 | IWineD3DVolumeTextureImpl_SetLOD,
|
---|
343 | IWineD3DVolumeTextureImpl_GetLOD,
|
---|
344 | IWineD3DVolumeTextureImpl_GetLevelCount,
|
---|
345 | IWineD3DVolumeTextureImpl_SetAutoGenFilterType,
|
---|
346 | IWineD3DVolumeTextureImpl_GetAutoGenFilterType,
|
---|
347 | IWineD3DVolumeTextureImpl_GenerateMipSubLevels,
|
---|
348 | IWineD3DVolumeTextureImpl_SetDirty,
|
---|
349 | IWineD3DVolumeTextureImpl_GetDirty,
|
---|
350 | /* not in d3d */
|
---|
351 | IWineD3DVolumeTextureImpl_BindTexture,
|
---|
352 | IWineD3DVolumeTextureImpl_GetTextureDimensions,
|
---|
353 | IWineD3DVolumeTextureImpl_IsCondNP2,
|
---|
354 | /* volume texture */
|
---|
355 | IWineD3DVolumeTextureImpl_GetLevelDesc,
|
---|
356 | IWineD3DVolumeTextureImpl_GetVolumeLevel,
|
---|
357 | IWineD3DVolumeTextureImpl_LockBox,
|
---|
358 | IWineD3DVolumeTextureImpl_UnlockBox,
|
---|
359 | IWineD3DVolumeTextureImpl_AddDirtyBox
|
---|
360 | };
|
---|
361 |
|
---|
362 | HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT height,
|
---|
363 | UINT depth, UINT levels, IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format,
|
---|
364 | WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
|
---|
365 | {
|
---|
366 | const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
---|
367 | const struct wined3d_format_desc *format_desc = getFormatDescEntry(format, gl_info);
|
---|
368 | UINT tmp_w, tmp_h, tmp_d;
|
---|
369 | unsigned int i;
|
---|
370 | HRESULT hr;
|
---|
371 |
|
---|
372 | /* TODO: It should only be possible to create textures for formats
|
---|
373 | * that are reported as supported. */
|
---|
374 | if (WINED3DFMT_UNKNOWN >= format)
|
---|
375 | {
|
---|
376 | WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
|
---|
377 | return WINED3DERR_INVALIDCALL;
|
---|
378 | }
|
---|
379 |
|
---|
380 | if (!gl_info->supported[EXT_TEXTURE3D])
|
---|
381 | {
|
---|
382 | WARN("(%p) : Texture cannot be created - no volume texture support.\n", texture);
|
---|
383 | return WINED3DERR_INVALIDCALL;
|
---|
384 | }
|
---|
385 |
|
---|
386 | /* Calculate levels for mip mapping. */
|
---|
387 | if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
|
---|
388 | {
|
---|
389 | if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
|
---|
390 | {
|
---|
391 | WARN("No mipmap generation support, returning D3DERR_INVALIDCALL.\n");
|
---|
392 | return WINED3DERR_INVALIDCALL;
|
---|
393 | }
|
---|
394 |
|
---|
395 | if (levels > 1)
|
---|
396 | {
|
---|
397 | WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL.\n");
|
---|
398 | return WINED3DERR_INVALIDCALL;
|
---|
399 | }
|
---|
400 |
|
---|
401 | levels = 1;
|
---|
402 | }
|
---|
403 | else if (!levels)
|
---|
404 | {
|
---|
405 | levels = wined3d_log2i(max(max(width, height), depth)) + 1;
|
---|
406 | TRACE("Calculated levels = %u.\n", levels);
|
---|
407 | }
|
---|
408 |
|
---|
409 | texture->lpVtbl = &IWineD3DVolumeTexture_Vtbl;
|
---|
410 |
|
---|
411 | hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_VOLUMETEXTURE,
|
---|
412 | device, 0, usage, format_desc, pool, parent, parent_ops
|
---|
413 | #ifdef VBOX_WITH_WDDM
|
---|
414 | , NULL, NULL
|
---|
415 | #endif
|
---|
416 | );
|
---|
417 | if (FAILED(hr))
|
---|
418 | {
|
---|
419 | WARN("Failed to initialize basetexture, returning %#x.\n", hr);
|
---|
420 | return hr;
|
---|
421 | }
|
---|
422 |
|
---|
423 | /* Is NP2 support for volumes needed? */
|
---|
424 | texture->baseTexture.pow2Matrix[0] = 1.0f;
|
---|
425 | texture->baseTexture.pow2Matrix[5] = 1.0f;
|
---|
426 | texture->baseTexture.pow2Matrix[10] = 1.0f;
|
---|
427 | texture->baseTexture.pow2Matrix[15] = 1.0f;
|
---|
428 |
|
---|
429 | /* Generate all the surfaces. */
|
---|
430 | tmp_w = width;
|
---|
431 | tmp_h = height;
|
---|
432 | tmp_d = depth;
|
---|
433 |
|
---|
434 | for (i = 0; i < texture->baseTexture.levels; ++i)
|
---|
435 | {
|
---|
436 | /* Create the volume. */
|
---|
437 | hr = IWineD3DDeviceParent_CreateVolume(device->device_parent, parent,
|
---|
438 | tmp_w, tmp_h, tmp_d, format, pool, usage, &texture->volumes[i]);
|
---|
439 | if (FAILED(hr))
|
---|
440 | {
|
---|
441 | ERR("Creating a volume for the volume texture failed, hr %#x.\n", hr);
|
---|
442 | texture->volumes[i] = NULL;
|
---|
443 | volumetexture_cleanup(texture);
|
---|
444 | return hr;
|
---|
445 | }
|
---|
446 |
|
---|
447 | /* Set its container to this texture. */
|
---|
448 | IWineD3DVolume_SetContainer(texture->volumes[i], (IWineD3DBase *)texture);
|
---|
449 |
|
---|
450 | /* Calculate the next mipmap level. */
|
---|
451 | tmp_w = max(1, tmp_w >> 1);
|
---|
452 | tmp_h = max(1, tmp_h >> 1);
|
---|
453 | tmp_d = max(1, tmp_d >> 1);
|
---|
454 | }
|
---|
455 | texture->baseTexture.internal_preload = volumetexture_internal_preload;
|
---|
456 |
|
---|
457 | return WINED3D_OK;
|
---|
458 | }
|
---|