msi: Only initialize a component's state if it is linked with a feature.
[wine/wine-gecko.git] / dlls / wined3d / volume.c
blob375a59c178032ac5ce6765f0d5993a3a749da88a
1 /*
2 * IWineD3DVolume 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 IWineD3DVolume IUnknown parts follow
31 ******************************************* */
32 static HRESULT WINAPI IWineD3DVolumeImpl_QueryInterface(IWineD3DVolume *iface, REFIID riid, LPVOID *ppobj)
34 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
35 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
36 if (IsEqualGUID(riid, &IID_IUnknown)
37 || IsEqualGUID(riid, &IID_IWineD3DBase)
38 || IsEqualGUID(riid, &IID_IWineD3DVolume)){
39 IUnknown_AddRef(iface);
40 *ppobj = This;
41 return S_OK;
43 *ppobj = NULL;
44 return E_NOINTERFACE;
47 static ULONG WINAPI IWineD3DVolumeImpl_AddRef(IWineD3DVolume *iface) {
48 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
49 TRACE("(%p) : AddRef increasing from %d\n", This, This->resource.ref);
50 return InterlockedIncrement(&This->resource.ref);
53 static ULONG WINAPI IWineD3DVolumeImpl_Release(IWineD3DVolume *iface) {
54 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
55 ULONG ref;
56 TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
57 ref = InterlockedDecrement(&This->resource.ref);
58 if (ref == 0) {
59 IWineD3DResourceImpl_CleanUp((IWineD3DResource *)iface);
60 HeapFree(GetProcessHeap(), 0, This);
62 return ref;
65 /* ****************************************************
66 IWineD3DVolume IWineD3DResource parts follow
67 **************************************************** */
68 static HRESULT WINAPI IWineD3DVolumeImpl_GetParent(IWineD3DVolume *iface, IUnknown **pParent) {
69 return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
72 static HRESULT WINAPI IWineD3DVolumeImpl_GetDevice(IWineD3DVolume *iface, IWineD3DDevice** ppDevice) {
73 return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
76 static HRESULT WINAPI IWineD3DVolumeImpl_SetPrivateData(IWineD3DVolume *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
77 return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
80 static HRESULT WINAPI IWineD3DVolumeImpl_GetPrivateData(IWineD3DVolume *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
81 return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
84 static HRESULT WINAPI IWineD3DVolumeImpl_FreePrivateData(IWineD3DVolume *iface, REFGUID refguid) {
85 return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
88 static DWORD WINAPI IWineD3DVolumeImpl_SetPriority(IWineD3DVolume *iface, DWORD PriorityNew) {
89 return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
92 static DWORD WINAPI IWineD3DVolumeImpl_GetPriority(IWineD3DVolume *iface) {
93 return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
96 static void WINAPI IWineD3DVolumeImpl_PreLoad(IWineD3DVolume *iface) {
97 return IWineD3DResourceImpl_PreLoad((IWineD3DResource *)iface);
100 static WINED3DRESOURCETYPE WINAPI IWineD3DVolumeImpl_GetType(IWineD3DVolume *iface) {
101 return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
104 /* *******************************************
105 IWineD3DVolume parts follow
106 ******************************************* */
107 static HRESULT WINAPI IWineD3DVolumeImpl_GetContainerParent(IWineD3DVolume *iface, IUnknown **ppContainerParent) {
108 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
110 TRACE("(%p) : ppContainerParent %p\n", This, ppContainerParent);
112 if (!ppContainerParent) {
113 ERR("(%p) : Called without a valid ppContainerParent\n", This);
116 if (This->container) {
117 IWineD3DBase_GetParent(This->container, ppContainerParent);
118 if (!ppContainerParent) {
119 /* WineD3D objects should always have a parent */
120 ERR("(%p) : GetParent returned NULL\n", This);
122 IUnknown_Release(*ppContainerParent); /* GetParent adds a reference; we want just the pointer */
123 } else {
124 *ppContainerParent = NULL;
127 return WINED3D_OK;
130 static HRESULT WINAPI IWineD3DVolumeImpl_GetContainer(IWineD3DVolume *iface, REFIID riid, void** ppContainer) {
131 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
133 TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
135 if (!ppContainer) {
136 ERR("Called without a valid ppContainer.\n");
139 /* Although surfaces can be standalone, volumes can't */
140 if (!This->container) {
141 ERR("Volume without an container. Should not happen.\n");
144 TRACE("Relaying to QueryInterface\n");
145 return IUnknown_QueryInterface(This->container, riid, ppContainer);
148 static HRESULT WINAPI IWineD3DVolumeImpl_GetDesc(IWineD3DVolume *iface, WINED3DVOLUME_DESC* pDesc) {
149 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
150 TRACE("(%p) : copying into %p\n", This, pDesc);
152 *(pDesc->Format) = This->resource.format;
153 *(pDesc->Type) = This->resource.resourceType;
154 *(pDesc->Usage) = This->resource.usage;
155 *(pDesc->Pool) = This->resource.pool;
156 *(pDesc->Size) = This->resource.size; /* dx8 only */
157 *(pDesc->Width) = This->currentDesc.Width;
158 *(pDesc->Height) = This->currentDesc.Height;
159 *(pDesc->Depth) = This->currentDesc.Depth;
160 return WINED3D_OK;
163 static HRESULT WINAPI IWineD3DVolumeImpl_LockBox(IWineD3DVolume *iface, WINED3DLOCKED_BOX* pLockedVolume, CONST WINED3DBOX* pBox, DWORD Flags) {
164 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
165 FIXME("(%p) : pBox=%p stub\n", This, pBox);
167 /* fixme: should we really lock as such? */
168 TRACE("(%p) : box=%p, output pbox=%p, allMem=%p\n", This, pBox, pLockedVolume, This->resource.allocatedMemory);
170 pLockedVolume->RowPitch = This->bytesPerPixel * This->currentDesc.Width; /* Bytes / row */
171 pLockedVolume->SlicePitch = This->bytesPerPixel * This->currentDesc.Width * This->currentDesc.Height; /* Bytes / slice */
172 if (!pBox) {
173 TRACE("No box supplied - all is ok\n");
174 pLockedVolume->pBits = This->resource.allocatedMemory;
175 This->lockedBox.Left = 0;
176 This->lockedBox.Top = 0;
177 This->lockedBox.Front = 0;
178 This->lockedBox.Right = This->currentDesc.Width;
179 This->lockedBox.Bottom = This->currentDesc.Height;
180 This->lockedBox.Back = This->currentDesc.Depth;
181 } else {
182 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);
183 pLockedVolume->pBits = This->resource.allocatedMemory +
184 (pLockedVolume->SlicePitch * pBox->Front) + /* FIXME: is front < back or vica versa? */
185 (pLockedVolume->RowPitch * pBox->Top) +
186 (pBox->Left * This->bytesPerPixel);
187 This->lockedBox.Left = pBox->Left;
188 This->lockedBox.Top = pBox->Top;
189 This->lockedBox.Front = pBox->Front;
190 This->lockedBox.Right = pBox->Right;
191 This->lockedBox.Bottom = pBox->Bottom;
192 This->lockedBox.Back = pBox->Back;
195 if (Flags & (WINED3DLOCK_NO_DIRTY_UPDATE | WINED3DLOCK_READONLY)) {
196 /* Don't dirtify */
197 } else {
199 * Dirtify on lock
200 * as seen in msdn docs
202 IWineD3DVolume_AddDirtyBox(iface, &This->lockedBox);
204 /** Dirtify Container if needed */
205 if (NULL != This->container) {
207 IWineD3DVolumeTexture *cont = (IWineD3DVolumeTexture*) This->container;
208 WINED3DRESOURCETYPE containerType = IWineD3DBaseTexture_GetType((IWineD3DBaseTexture *) cont);
210 if (containerType == WINED3DRTYPE_VOLUMETEXTURE) {
211 IWineD3DBaseTextureImpl* pTexture = (IWineD3DBaseTextureImpl*) cont;
212 pTexture->baseTexture.dirty = TRUE;
213 } else {
214 FIXME("Set dirty on container type %d\n", containerType);
219 This->locked = TRUE;
220 TRACE("returning memory@%p rpitch(%d) spitch(%d)\n", pLockedVolume->pBits, pLockedVolume->RowPitch, pLockedVolume->SlicePitch);
221 return WINED3D_OK;
224 static HRESULT WINAPI IWineD3DVolumeImpl_UnlockBox(IWineD3DVolume *iface) {
225 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
226 if (!This->locked) {
227 ERR("trying to lock unlocked volume@%p\n", This);
228 return WINED3DERR_INVALIDCALL;
230 TRACE("(%p) : unlocking volume\n", This);
231 This->locked = FALSE;
232 memset(&This->lockedBox, 0, sizeof(RECT));
233 return WINED3D_OK;
236 /* Internal use functions follow : */
238 static HRESULT WINAPI IWineD3DVolumeImpl_CleanDirtyBox(IWineD3DVolume *iface) {
239 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
240 This->dirty = FALSE;
241 This->lockedBox.Left = This->currentDesc.Width;
242 This->lockedBox.Top = This->currentDesc.Height;
243 This->lockedBox.Front = This->currentDesc.Depth;
244 This->lockedBox.Right = 0;
245 This->lockedBox.Bottom = 0;
246 This->lockedBox.Back = 0;
247 return WINED3D_OK;
250 static HRESULT WINAPI IWineD3DVolumeImpl_AddDirtyBox(IWineD3DVolume *iface, CONST WINED3DBOX* pDirtyBox) {
251 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
252 This->dirty = TRUE;
253 if (NULL != pDirtyBox) {
254 This->lockedBox.Left = min(This->lockedBox.Left, pDirtyBox->Left);
255 This->lockedBox.Top = min(This->lockedBox.Top, pDirtyBox->Top);
256 This->lockedBox.Front = min(This->lockedBox.Front, pDirtyBox->Front);
257 This->lockedBox.Right = max(This->lockedBox.Right, pDirtyBox->Right);
258 This->lockedBox.Bottom = max(This->lockedBox.Bottom, pDirtyBox->Bottom);
259 This->lockedBox.Back = max(This->lockedBox.Back, pDirtyBox->Back);
260 } else {
261 This->lockedBox.Left = 0;
262 This->lockedBox.Top = 0;
263 This->lockedBox.Front = 0;
264 This->lockedBox.Right = This->currentDesc.Width;
265 This->lockedBox.Bottom = This->currentDesc.Height;
266 This->lockedBox.Back = This->currentDesc.Depth;
268 return WINED3D_OK;
271 static HRESULT WINAPI IWineD3DVolumeImpl_SetContainer(IWineD3DVolume *iface, IWineD3DBase* container) {
272 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
274 TRACE("This %p, container %p\n", This, container);
276 /* We can't keep a reference to the container, since the container already keeps a reference to us. */
278 TRACE("Setting container to %p from %p\n", container, This->container);
279 This->container = container;
281 return WINED3D_OK;
284 static HRESULT WINAPI IWineD3DVolumeImpl_LoadTexture(IWineD3DVolume *iface, GLenum gl_level) {
285 IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
286 const PixelFormatDesc *formatEntry = getFormatDescEntry(This->resource.format);
288 if(GL_SUPPORT(EXT_TEXTURE3D)) {
289 TRACE("Calling glTexImage3D %x level=%d, intfmt=%x, w=%d, h=%d,d=%d, 0=%d, glFmt=%x, glType=%x, Mem=%p\n",
290 GL_TEXTURE_3D,
291 gl_level,
292 formatEntry->glInternal,
293 This->currentDesc.Width,
294 This->currentDesc.Height,
295 This->currentDesc.Depth,
297 formatEntry->glFormat,
298 formatEntry->glType,
299 This->resource.allocatedMemory);
300 GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D,
301 gl_level,
302 formatEntry->glInternal,
303 This->currentDesc.Width,
304 This->currentDesc.Height,
305 This->currentDesc.Depth,
307 formatEntry->glFormat,
308 formatEntry->glType,
309 This->resource.allocatedMemory));
310 checkGLcall("glTexImage3D");
311 } else
312 WARN("This OpenGL implementation doesn't support 3D textures\n");
314 return WINED3D_OK;
318 const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl =
320 /* IUnknown */
321 IWineD3DVolumeImpl_QueryInterface,
322 IWineD3DVolumeImpl_AddRef,
323 IWineD3DVolumeImpl_Release,
324 /* IWineD3DResource */
325 IWineD3DVolumeImpl_GetParent,
326 IWineD3DVolumeImpl_GetDevice,
327 IWineD3DVolumeImpl_SetPrivateData,
328 IWineD3DVolumeImpl_GetPrivateData,
329 IWineD3DVolumeImpl_FreePrivateData,
330 IWineD3DVolumeImpl_SetPriority,
331 IWineD3DVolumeImpl_GetPriority,
332 IWineD3DVolumeImpl_PreLoad,
333 IWineD3DVolumeImpl_GetType,
334 /* IWineD3DVolume */
335 IWineD3DVolumeImpl_GetContainerParent,
336 IWineD3DVolumeImpl_GetContainer,
337 IWineD3DVolumeImpl_GetDesc,
338 IWineD3DVolumeImpl_LockBox,
339 IWineD3DVolumeImpl_UnlockBox,
340 /* Internal interface */
341 IWineD3DVolumeImpl_AddDirtyBox,
342 IWineD3DVolumeImpl_CleanDirtyBox,
343 IWineD3DVolumeImpl_LoadTexture,
344 IWineD3DVolumeImpl_SetContainer