VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volume.c@ 16684

Last change on this file since 16684 was 16477, checked in by vboxsync, 16 years ago

LGPL disclaimer by filemuncher

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette