1 | /*
|
---|
2 | * IWineD3DVolume 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_surface);
|
---|
36 | #define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
|
---|
37 |
|
---|
38 | static void volume_bind_and_dirtify(IWineD3DVolume *iface) {
|
---|
39 | IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
|
---|
40 | IWineD3DVolumeTexture *texture;
|
---|
41 | int active_sampler;
|
---|
42 |
|
---|
43 | /* We don't need a specific texture unit, but after binding the texture the current unit is dirty.
|
---|
44 | * Read the unit back instead of switching to 0, this avoids messing around with the state manager's
|
---|
45 | * gl states. The current texture unit should always be a valid one.
|
---|
46 | *
|
---|
47 | * To be more specific, this is tricky because we can implicitly be called
|
---|
48 | * from sampler() in state.c. This means we can't touch anything other than
|
---|
49 | * whatever happens to be the currently active texture, or we would risk
|
---|
50 | * marking already applied sampler states dirty again.
|
---|
51 | *
|
---|
52 | * TODO: Track the current active texture per GL context instead of using glGet
|
---|
53 | */
|
---|
54 | if (GL_SUPPORT(ARB_MULTITEXTURE)) {
|
---|
55 | GLint active_texture;
|
---|
56 | ENTER_GL();
|
---|
57 | glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
|
---|
58 | LEAVE_GL();
|
---|
59 | active_sampler = This->resource.wineD3DDevice->rev_tex_unit_map[active_texture - GL_TEXTURE0_ARB];
|
---|
60 | } else {
|
---|
61 | active_sampler = 0;
|
---|
62 | }
|
---|
63 |
|
---|
64 | if (active_sampler != -1) {
|
---|
65 | IWineD3DDeviceImpl_MarkStateDirty(This->resource.wineD3DDevice, STATE_SAMPLER(active_sampler));
|
---|
66 | }
|
---|
67 |
|
---|
68 | if (SUCCEEDED(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DVolumeTexture, (void **)&texture))) {
|
---|
69 | IWineD3DVolumeTexture_BindTexture(texture, FALSE);
|
---|
70 | IWineD3DVolumeTexture_Release(texture);
|
---|
71 | } else {
|
---|
72 | ERR("Volume should be part of a volume texture\n");
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | void volume_add_dirty_box(IWineD3DVolume *iface, const WINED3DBOX *dirty_box)
|
---|
77 | {
|
---|
78 | IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
|
---|
79 |
|
---|
80 | This->dirty = TRUE;
|
---|
81 | if (dirty_box)
|
---|
82 | {
|
---|
83 | This->lockedBox.Left = min(This->lockedBox.Left, dirty_box->Left);
|
---|
84 | This->lockedBox.Top = min(This->lockedBox.Top, dirty_box->Top);
|
---|
85 | This->lockedBox.Front = min(This->lockedBox.Front, dirty_box->Front);
|
---|
86 | This->lockedBox.Right = max(This->lockedBox.Right, dirty_box->Right);
|
---|
87 | This->lockedBox.Bottom = max(This->lockedBox.Bottom, dirty_box->Bottom);
|
---|
88 | This->lockedBox.Back = max(This->lockedBox.Back, dirty_box->Back);
|
---|
89 | }
|
---|
90 | else
|
---|
91 | {
|
---|
92 | This->lockedBox.Left = 0;
|
---|
93 | This->lockedBox.Top = 0;
|
---|
94 | This->lockedBox.Front = 0;
|
---|
95 | This->lockedBox.Right = This->currentDesc.Width;
|
---|
96 | This->lockedBox.Bottom = This->currentDesc.Height;
|
---|
97 | This->lockedBox.Back = This->currentDesc.Depth;
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | /* *******************************************
|
---|
102 | IWineD3DVolume IUnknown parts follow
|
---|
103 | ******************************************* */
|
---|
104 | static HRESULT WINAPI IWineD3DVolumeImpl_QueryInterface(IWineD3DVolume *iface, REFIID riid, LPVOID *ppobj)
|
---|
105 | {
|
---|
106 | IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
|
---|
107 | TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
|
---|
108 | if (IsEqualGUID(riid, &IID_IUnknown)
|
---|
109 | || IsEqualGUID(riid, &IID_IWineD3DBase)
|
---|
110 | || IsEqualGUID(riid, &IID_IWineD3DVolume)){
|
---|
111 | IUnknown_AddRef(iface);
|
---|
112 | *ppobj = This;
|
---|
113 | return S_OK;
|
---|
114 | }
|
---|
115 | *ppobj = NULL;
|
---|
116 | return E_NOINTERFACE;
|
---|
117 | }
|
---|
118 |
|
---|
119 | static ULONG WINAPI IWineD3DVolumeImpl_AddRef(IWineD3DVolume *iface) {
|
---|
120 | IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
|
---|
121 | TRACE("(%p) : AddRef increasing from %d\n", This, This->resource.ref);
|
---|
122 | return InterlockedIncrement(&This->resource.ref);
|
---|
123 | }
|
---|
124 |
|
---|
125 | static ULONG WINAPI IWineD3DVolumeImpl_Release(IWineD3DVolume *iface) {
|
---|
126 | IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
|
---|
127 | ULONG ref;
|
---|
128 | TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
|
---|
129 | ref = InterlockedDecrement(&This->resource.ref);
|
---|
130 | if (ref == 0) {
|
---|
131 | resource_cleanup((IWineD3DResource *)iface);
|
---|
132 | HeapFree(GetProcessHeap(), 0, This);
|
---|
133 | }
|
---|
134 | return ref;
|
---|
135 | }
|
---|
136 |
|
---|
137 | /* ****************************************************
|
---|
138 | IWineD3DVolume IWineD3DResource parts follow
|
---|
139 | **************************************************** */
|
---|
140 | static HRESULT WINAPI IWineD3DVolumeImpl_GetParent(IWineD3DVolume *iface, IUnknown **pParent) {
|
---|
141 | return resource_get_parent((IWineD3DResource *)iface, pParent);
|
---|
142 | }
|
---|
143 |
|
---|
144 | static HRESULT WINAPI IWineD3DVolumeImpl_GetDevice(IWineD3DVolume *iface, IWineD3DDevice** ppDevice) {
|
---|
145 | return resource_get_device((IWineD3DResource *)iface, ppDevice);
|
---|
146 | }
|
---|
147 |
|
---|
148 | static HRESULT WINAPI IWineD3DVolumeImpl_SetPrivateData(IWineD3DVolume *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
|
---|
149 | return resource_set_private_data((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
|
---|
150 | }
|
---|
151 |
|
---|
152 | static HRESULT WINAPI IWineD3DVolumeImpl_GetPrivateData(IWineD3DVolume *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
|
---|
153 | return resource_get_private_data((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
|
---|
154 | }
|
---|
155 |
|
---|
156 | static HRESULT WINAPI IWineD3DVolumeImpl_FreePrivateData(IWineD3DVolume *iface, REFGUID refguid) {
|
---|
157 | return resource_free_private_data((IWineD3DResource *)iface, refguid);
|
---|
158 | }
|
---|
159 |
|
---|
160 | static DWORD WINAPI IWineD3DVolumeImpl_SetPriority(IWineD3DVolume *iface, DWORD PriorityNew) {
|
---|
161 | return resource_set_priority((IWineD3DResource *)iface, PriorityNew);
|
---|
162 | }
|
---|
163 |
|
---|
164 | static DWORD WINAPI IWineD3DVolumeImpl_GetPriority(IWineD3DVolume *iface) {
|
---|
165 | return resource_get_priority((IWineD3DResource *)iface);
|
---|
166 | }
|
---|
167 |
|
---|
168 | static void WINAPI IWineD3DVolumeImpl_PreLoad(IWineD3DVolume *iface) {
|
---|
169 | FIXME("iface %p stub!\n", iface);
|
---|
170 | }
|
---|
171 |
|
---|
172 | static void WINAPI IWineD3DVolumeImpl_UnLoad(IWineD3DVolume *iface) {
|
---|
173 | /* The whole content is shadowed on This->resource.allocatedMemory, and the
|
---|
174 | * texture name is managed by the VolumeTexture container
|
---|
175 | */
|
---|
176 | TRACE("(%p): Nothing to do\n", iface);
|
---|
177 | }
|
---|
178 |
|
---|
179 | static WINED3DRESOURCETYPE WINAPI IWineD3DVolumeImpl_GetType(IWineD3DVolume *iface) {
|
---|
180 | return resource_get_type((IWineD3DResource *)iface);
|
---|
181 | }
|
---|
182 |
|
---|
183 | /* *******************************************
|
---|
184 | IWineD3DVolume parts follow
|
---|
185 | ******************************************* */
|
---|
186 | static HRESULT WINAPI IWineD3DVolumeImpl_GetContainer(IWineD3DVolume *iface, REFIID riid, void** ppContainer) {
|
---|
187 | IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
|
---|
188 |
|
---|
189 | TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
|
---|
190 |
|
---|
191 | if (!ppContainer) {
|
---|
192 | ERR("Called without a valid ppContainer.\n");
|
---|
193 | }
|
---|
194 |
|
---|
195 | /* Although surfaces can be standalone, volumes can't */
|
---|
196 | if (!This->container) {
|
---|
197 | ERR("Volume without an container. Should not happen.\n");
|
---|
198 | }
|
---|
199 |
|
---|
200 | TRACE("Relaying to QueryInterface\n");
|
---|
201 | return IUnknown_QueryInterface(This->container, riid, ppContainer);
|
---|
202 | }
|
---|
203 |
|
---|
204 | static HRESULT WINAPI IWineD3DVolumeImpl_GetDesc(IWineD3DVolume *iface, WINED3DVOLUME_DESC* pDesc) {
|
---|
205 | IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
|
---|
206 | TRACE("(%p) : copying into %p\n", This, pDesc);
|
---|
207 |
|
---|
208 | *(pDesc->Format) = This->resource.format_desc->format;
|
---|
209 | *(pDesc->Type) = This->resource.resourceType;
|
---|
210 | *(pDesc->Usage) = This->resource.usage;
|
---|
211 | *(pDesc->Pool) = This->resource.pool;
|
---|
212 | *(pDesc->Size) = This->resource.size; /* dx8 only */
|
---|
213 | *(pDesc->Width) = This->currentDesc.Width;
|
---|
214 | *(pDesc->Height) = This->currentDesc.Height;
|
---|
215 | *(pDesc->Depth) = This->currentDesc.Depth;
|
---|
216 | return WINED3D_OK;
|
---|
217 | }
|
---|
218 |
|
---|
219 | static HRESULT WINAPI IWineD3DVolumeImpl_LockBox(IWineD3DVolume *iface, WINED3DLOCKED_BOX* pLockedVolume, CONST WINED3DBOX* pBox, DWORD Flags) {
|
---|
220 | IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
|
---|
221 | FIXME("(%p) : pBox=%p stub\n", This, pBox);
|
---|
222 |
|
---|
223 | if(!This->resource.allocatedMemory) {
|
---|
224 | This->resource.allocatedMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->resource.size);
|
---|
225 | }
|
---|
226 |
|
---|
227 | /* fixme: should we really lock as such? */
|
---|
228 | TRACE("(%p) : box=%p, output pbox=%p, allMem=%p\n", This, pBox, pLockedVolume, This->resource.allocatedMemory);
|
---|
229 |
|
---|
230 | pLockedVolume->RowPitch = This->resource.format_desc->byte_count * This->currentDesc.Width; /* Bytes / row */
|
---|
231 | pLockedVolume->SlicePitch = This->resource.format_desc->byte_count
|
---|
232 | * This->currentDesc.Width * This->currentDesc.Height; /* Bytes / slice */
|
---|
233 | if (!pBox) {
|
---|
234 | TRACE("No box supplied - all is ok\n");
|
---|
235 | pLockedVolume->pBits = This->resource.allocatedMemory;
|
---|
236 | This->lockedBox.Left = 0;
|
---|
237 | This->lockedBox.Top = 0;
|
---|
238 | This->lockedBox.Front = 0;
|
---|
239 | This->lockedBox.Right = This->currentDesc.Width;
|
---|
240 | This->lockedBox.Bottom = This->currentDesc.Height;
|
---|
241 | This->lockedBox.Back = This->currentDesc.Depth;
|
---|
242 | } else {
|
---|
243 | TRACE("Lock Box (%p) = l %d, t %d, r %d, b %d, fr %d, ba %d\n", pBox, pBox->Left, pBox->Top, pBox->Right, pBox->Bottom, pBox->Front, pBox->Back);
|
---|
244 | pLockedVolume->pBits = This->resource.allocatedMemory
|
---|
245 | + (pLockedVolume->SlicePitch * pBox->Front) /* FIXME: is front < back or vica versa? */
|
---|
246 | + (pLockedVolume->RowPitch * pBox->Top)
|
---|
247 | + (pBox->Left * This->resource.format_desc->byte_count);
|
---|
248 | This->lockedBox.Left = pBox->Left;
|
---|
249 | This->lockedBox.Top = pBox->Top;
|
---|
250 | This->lockedBox.Front = pBox->Front;
|
---|
251 | This->lockedBox.Right = pBox->Right;
|
---|
252 | This->lockedBox.Bottom = pBox->Bottom;
|
---|
253 | This->lockedBox.Back = pBox->Back;
|
---|
254 | }
|
---|
255 |
|
---|
256 | if (Flags & (WINED3DLOCK_NO_DIRTY_UPDATE | WINED3DLOCK_READONLY)) {
|
---|
257 | /* Don't dirtify */
|
---|
258 | } else {
|
---|
259 | /**
|
---|
260 | * Dirtify on lock
|
---|
261 | * as seen in msdn docs
|
---|
262 | */
|
---|
263 | volume_add_dirty_box(iface, &This->lockedBox);
|
---|
264 |
|
---|
265 | /** Dirtify Container if needed */
|
---|
266 | if (NULL != This->container) {
|
---|
267 |
|
---|
268 | IWineD3DVolumeTexture *cont = (IWineD3DVolumeTexture*) This->container;
|
---|
269 | WINED3DRESOURCETYPE containerType = IWineD3DBaseTexture_GetType((IWineD3DBaseTexture *) cont);
|
---|
270 |
|
---|
271 | if (containerType == WINED3DRTYPE_VOLUMETEXTURE) {
|
---|
272 | IWineD3DBaseTextureImpl* pTexture = (IWineD3DBaseTextureImpl*) cont;
|
---|
273 | pTexture->baseTexture.dirty = TRUE;
|
---|
274 | } else {
|
---|
275 | FIXME("Set dirty on container type %d\n", containerType);
|
---|
276 | }
|
---|
277 | }
|
---|
278 | }
|
---|
279 |
|
---|
280 | This->locked = TRUE;
|
---|
281 | TRACE("returning memory@%p rpitch(%d) spitch(%d)\n", pLockedVolume->pBits, pLockedVolume->RowPitch, pLockedVolume->SlicePitch);
|
---|
282 | return WINED3D_OK;
|
---|
283 | }
|
---|
284 |
|
---|
285 | static HRESULT WINAPI IWineD3DVolumeImpl_UnlockBox(IWineD3DVolume *iface) {
|
---|
286 | IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
|
---|
287 | if (!This->locked) {
|
---|
288 | ERR("trying to lock unlocked volume@%p\n", This);
|
---|
289 | return WINED3DERR_INVALIDCALL;
|
---|
290 | }
|
---|
291 | TRACE("(%p) : unlocking volume\n", This);
|
---|
292 | This->locked = FALSE;
|
---|
293 | memset(&This->lockedBox, 0, sizeof(RECT));
|
---|
294 | return WINED3D_OK;
|
---|
295 | }
|
---|
296 |
|
---|
297 | /* Internal use functions follow : */
|
---|
298 |
|
---|
299 | static HRESULT WINAPI IWineD3DVolumeImpl_SetContainer(IWineD3DVolume *iface, IWineD3DBase* container) {
|
---|
300 | IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
|
---|
301 |
|
---|
302 | TRACE("This %p, container %p\n", This, container);
|
---|
303 |
|
---|
304 | /* We can't keep a reference to the container, since the container already keeps a reference to us. */
|
---|
305 |
|
---|
306 | TRACE("Setting container to %p from %p\n", container, This->container);
|
---|
307 | This->container = container;
|
---|
308 |
|
---|
309 | return WINED3D_OK;
|
---|
310 | }
|
---|
311 |
|
---|
312 | static HRESULT WINAPI IWineD3DVolumeImpl_LoadTexture(IWineD3DVolume *iface, int gl_level, BOOL srgb_mode) {
|
---|
313 | IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
|
---|
314 | const struct GlPixelFormatDesc *glDesc = This->resource.format_desc;
|
---|
315 |
|
---|
316 | TRACE("(%p) : level %u, format %s (0x%08x)\n", This, gl_level, debug_d3dformat(glDesc->format), glDesc->format);
|
---|
317 |
|
---|
318 | volume_bind_and_dirtify(iface);
|
---|
319 |
|
---|
320 | TRACE("Calling glTexImage3D %x level=%d, intfmt=%x, w=%d, h=%d,d=%d, 0=%d, glFmt=%x, glType=%x, Mem=%p\n",
|
---|
321 | GL_TEXTURE_3D,
|
---|
322 | gl_level,
|
---|
323 | glDesc->glInternal,
|
---|
324 | This->currentDesc.Width,
|
---|
325 | This->currentDesc.Height,
|
---|
326 | This->currentDesc.Depth,
|
---|
327 | 0,
|
---|
328 | glDesc->glFormat,
|
---|
329 | glDesc->glType,
|
---|
330 | This->resource.allocatedMemory);
|
---|
331 |
|
---|
332 | ENTER_GL();
|
---|
333 | GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D,
|
---|
334 | gl_level,
|
---|
335 | glDesc->glInternal,
|
---|
336 | This->currentDesc.Width,
|
---|
337 | This->currentDesc.Height,
|
---|
338 | This->currentDesc.Depth,
|
---|
339 | 0,
|
---|
340 | glDesc->glFormat,
|
---|
341 | glDesc->glType,
|
---|
342 | This->resource.allocatedMemory));
|
---|
343 | checkGLcall("glTexImage3D");
|
---|
344 | LEAVE_GL();
|
---|
345 |
|
---|
346 | /* When adding code releasing This->resource.allocatedMemory to save data keep in mind that
|
---|
347 | * GL_UNPACK_CLIENT_STORAGE_APPLE is enabled by default if supported(GL_APPLE_client_storage).
|
---|
348 | * Thus do not release This->resource.allocatedMemory if GL_APPLE_client_storage is supported.
|
---|
349 | */
|
---|
350 | return WINED3D_OK;
|
---|
351 |
|
---|
352 | }
|
---|
353 |
|
---|
354 | const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl =
|
---|
355 | {
|
---|
356 | /* IUnknown */
|
---|
357 | IWineD3DVolumeImpl_QueryInterface,
|
---|
358 | IWineD3DVolumeImpl_AddRef,
|
---|
359 | IWineD3DVolumeImpl_Release,
|
---|
360 | /* IWineD3DResource */
|
---|
361 | IWineD3DVolumeImpl_GetParent,
|
---|
362 | IWineD3DVolumeImpl_GetDevice,
|
---|
363 | IWineD3DVolumeImpl_SetPrivateData,
|
---|
364 | IWineD3DVolumeImpl_GetPrivateData,
|
---|
365 | IWineD3DVolumeImpl_FreePrivateData,
|
---|
366 | IWineD3DVolumeImpl_SetPriority,
|
---|
367 | IWineD3DVolumeImpl_GetPriority,
|
---|
368 | IWineD3DVolumeImpl_PreLoad,
|
---|
369 | IWineD3DVolumeImpl_UnLoad,
|
---|
370 | IWineD3DVolumeImpl_GetType,
|
---|
371 | /* IWineD3DVolume */
|
---|
372 | IWineD3DVolumeImpl_GetContainer,
|
---|
373 | IWineD3DVolumeImpl_GetDesc,
|
---|
374 | IWineD3DVolumeImpl_LockBox,
|
---|
375 | IWineD3DVolumeImpl_UnlockBox,
|
---|
376 | /* Internal interface */
|
---|
377 | IWineD3DVolumeImpl_LoadTexture,
|
---|
378 | IWineD3DVolumeImpl_SetContainer
|
---|
379 | };
|
---|