Sync with trunk head (r49139)
[reactos.git] / dll / directx / wine / wined3d / volume.c
index 42e61e6..8d42d54 100644 (file)
@@ -30,7 +30,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
 static void volume_bind_and_dirtify(IWineD3DVolume *iface) {
     IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
     const struct wined3d_gl_info *gl_info = &This->resource.device->adapter->gl_info;
-    IWineD3DVolumeTexture *texture;
     DWORD active_sampler;
 
     /* We don't need a specific texture unit, but after binding the texture the current unit is dirty.
@@ -60,12 +59,7 @@ static void volume_bind_and_dirtify(IWineD3DVolume *iface) {
         IWineD3DDeviceImpl_MarkStateDirty(This->resource.device, STATE_SAMPLER(active_sampler));
     }
 
-    if (SUCCEEDED(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DVolumeTexture, (void **)&texture))) {
-        IWineD3DVolumeTexture_BindTexture(texture, FALSE);
-        IWineD3DVolumeTexture_Release(texture);
-    } else {
-        ERR("Volume should be part of a volume texture\n");
-    }
+    IWineD3DVolumeTexture_BindTexture((IWineD3DVolumeTexture *)This->container, FALSE);
 }
 
 void volume_add_dirty_box(IWineD3DVolume *iface, const WINED3DBOX *dirty_box)
@@ -93,6 +87,13 @@ void volume_add_dirty_box(IWineD3DVolume *iface, const WINED3DBOX *dirty_box)
     }
 }
 
+void volume_set_container(IWineD3DVolumeImpl *volume, struct IWineD3DVolumeTextureImpl *container)
+{
+    TRACE("volume %p, container %p.\n", volume, container);
+
+    volume->container = container;
+}
+
 /* *******************************************
    IWineD3DVolume IUnknown parts follow
    ******************************************* */
@@ -122,12 +123,15 @@ static ULONG WINAPI IWineD3DVolumeImpl_AddRef(IWineD3DVolume *iface) {
     return InterlockedIncrement(&This->resource.ref);
 }
 
+/* Do not call while under the GL lock. */
 static ULONG WINAPI IWineD3DVolumeImpl_Release(IWineD3DVolume *iface) {
     IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
     ULONG ref;
     TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
     ref = InterlockedDecrement(&This->resource.ref);
-    if (ref == 0) {
+
+    if (!ref)
+    {
         resource_cleanup((IWineD3DResource *)iface);
         This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
         HeapFree(GetProcessHeap(), 0, This);
@@ -138,8 +142,11 @@ static ULONG WINAPI IWineD3DVolumeImpl_Release(IWineD3DVolume *iface) {
 /* ****************************************************
    IWineD3DVolume IWineD3DResource parts follow
    **************************************************** */
-static HRESULT WINAPI IWineD3DVolumeImpl_GetParent(IWineD3DVolume *iface, IUnknown **pParent) {
-    return resource_get_parent((IWineD3DResource *)iface, pParent);
+static void * WINAPI IWineD3DVolumeImpl_GetParent(IWineD3DVolume *iface)
+{
+    TRACE("iface %p.\n", iface);
+
+    return ((IWineD3DVolumeImpl *)iface)->resource.parent;
 }
 
 static HRESULT WINAPI IWineD3DVolumeImpl_SetPrivateData(IWineD3DVolume *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
@@ -162,58 +169,40 @@ static DWORD WINAPI IWineD3DVolumeImpl_GetPriority(IWineD3DVolume *iface) {
     return resource_get_priority((IWineD3DResource *)iface);
 }
 
+/* Do not call while under the GL lock. */
 static void WINAPI IWineD3DVolumeImpl_PreLoad(IWineD3DVolume *iface) {
     FIXME("iface %p stub!\n", iface);
 }
 
-static void WINAPI IWineD3DVolumeImpl_UnLoad(IWineD3DVolume *iface) {
-    /* The whole content is shadowed on This->resource.allocatedMemory, and the
-     * texture name is managed by the VolumeTexture container
-     */
-    TRACE("(%p): Nothing to do\n", iface);
+/* Do not call while under the GL lock. */
+static void WINAPI IWineD3DVolumeImpl_UnLoad(IWineD3DVolume *iface)
+{
+    TRACE("iface %p.\n", iface);
+
+    /* The whole content is shadowed on This->resource.allocatedMemory, and
+     * the texture name is managed by the VolumeTexture container. */
+
+    resource_unload((IWineD3DResourceImpl *)iface);
 }
 
 static WINED3DRESOURCETYPE WINAPI IWineD3DVolumeImpl_GetType(IWineD3DVolume *iface) {
     return resource_get_type((IWineD3DResource *)iface);
 }
 
-/* *******************************************
-   IWineD3DVolume parts follow
-   ******************************************* */
-static HRESULT WINAPI IWineD3DVolumeImpl_GetContainer(IWineD3DVolume *iface, REFIID riid, void** ppContainer) {
-    IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
-
-    TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
-
-    if (!ppContainer) {
-        ERR("Called without a valid ppContainer.\n");
-        return E_FAIL;
-    }
-
-    /* Although surfaces can be standalone, volumes can't */
-    if (!This->container) {
-        ERR("Volume without an container. Should not happen.\n");
-        return E_FAIL;
-    }
-
-    TRACE("Relaying to QueryInterface\n");
-    return IUnknown_QueryInterface(This->container, riid, ppContainer);
-}
-
-static HRESULT WINAPI IWineD3DVolumeImpl_GetDesc(IWineD3DVolume *iface, WINED3DVOLUME_DESC* pDesc) {
-    IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
-    TRACE("(%p) : copying into %p\n", This, pDesc);
-
-    pDesc->Format = This->resource.format_desc->format;
-    pDesc->Type = This->resource.resourceType;
-    pDesc->Usage = This->resource.usage;
-    pDesc->Pool = This->resource.pool;
-    pDesc->Size = This->resource.size; /* dx8 only */
-    pDesc->Width = This->currentDesc.Width;
-    pDesc->Height = This->currentDesc.Height;
-    pDesc->Depth = This->currentDesc.Depth;
-
-    return WINED3D_OK;
+static void WINAPI IWineD3DVolumeImpl_GetDesc(IWineD3DVolume *iface, WINED3DVOLUME_DESC *desc)
+{
+    IWineD3DVolumeImpl *volume = (IWineD3DVolumeImpl *)iface;
+
+    TRACE("iface %p, desc %p.\n", iface, desc);
+
+    desc->Format = volume->resource.format->id;
+    desc->Type = volume->resource.resourceType;
+    desc->Usage = volume->resource.usage;
+    desc->Pool = volume->resource.pool;
+    desc->Size = volume->resource.size; /* dx8 only */
+    desc->Width = volume->currentDesc.Width;
+    desc->Height = volume->currentDesc.Height;
+    desc->Depth = volume->currentDesc.Depth;
 }
 
 static HRESULT WINAPI IWineD3DVolumeImpl_LockBox(IWineD3DVolume *iface, WINED3DLOCKED_BOX* pLockedVolume, CONST WINED3DBOX* pBox, DWORD Flags) {
@@ -227,8 +216,8 @@ static HRESULT WINAPI IWineD3DVolumeImpl_LockBox(IWineD3DVolume *iface, WINED3DL
     /* fixme: should we really lock as such? */
     TRACE("(%p) : box=%p, output pbox=%p, allMem=%p\n", This, pBox, pLockedVolume, This->resource.allocatedMemory);
 
-    pLockedVolume->RowPitch = This->resource.format_desc->byte_count * This->currentDesc.Width; /* Bytes / row   */
-    pLockedVolume->SlicePitch = This->resource.format_desc->byte_count
+    pLockedVolume->RowPitch = This->resource.format->byte_count * This->currentDesc.Width; /* Bytes / row   */
+    pLockedVolume->SlicePitch = This->resource.format->byte_count
             * This->currentDesc.Width * This->currentDesc.Height;                               /* Bytes / slice */
     if (!pBox) {
         TRACE("No box supplied - all is ok\n");
@@ -244,7 +233,7 @@ static HRESULT WINAPI IWineD3DVolumeImpl_LockBox(IWineD3DVolume *iface, WINED3DL
         pLockedVolume->pBits = This->resource.allocatedMemory
                 + (pLockedVolume->SlicePitch * pBox->Front)     /* FIXME: is front < back or vica versa? */
                 + (pLockedVolume->RowPitch * pBox->Top)
-                + (pBox->Left * This->resource.format_desc->byte_count);
+                + (pBox->Left * This->resource.format->byte_count);
         This->lockedBox.Left   = pBox->Left;
         This->lockedBox.Top    = pBox->Top;
         This->lockedBox.Front  = pBox->Front;
@@ -255,27 +244,12 @@ static HRESULT WINAPI IWineD3DVolumeImpl_LockBox(IWineD3DVolume *iface, WINED3DL
 
     if (Flags & (WINED3DLOCK_NO_DIRTY_UPDATE | WINED3DLOCK_READONLY)) {
       /* Don't dirtify */
-    } else {
-      /**
-       * Dirtify on lock
-       * as seen in msdn docs
-       */
-      volume_add_dirty_box(iface, &This->lockedBox);
-
-      /**  Dirtify Container if needed */
-      if (NULL != This->container) {
-
-        IWineD3DVolumeTexture *cont = (IWineD3DVolumeTexture*) This->container;
-        WINED3DRESOURCETYPE containerType = IWineD3DBaseTexture_GetType((IWineD3DBaseTexture *) cont);
-
-        if (containerType == WINED3DRTYPE_VOLUMETEXTURE) {
-          IWineD3DBaseTextureImpl* pTexture = (IWineD3DBaseTextureImpl*) cont;
-          pTexture->baseTexture.texture_rgb.dirty = TRUE;
-          pTexture->baseTexture.texture_srgb.dirty = TRUE;
-        } else {
-          FIXME("Set dirty on container type %d\n", containerType);
-        }
-      }
+    }
+    else
+    {
+        volume_add_dirty_box(iface, &This->lockedBox);
+        This->container->baseTexture.texture_rgb.dirty = TRUE;
+        This->container->baseTexture.texture_srgb.dirty = TRUE;
     }
 
     This->locked = TRUE;
@@ -298,53 +272,26 @@ static HRESULT WINAPI IWineD3DVolumeImpl_UnlockBox(IWineD3DVolume *iface) {
 
 /* Internal use functions follow : */
 
-static HRESULT WINAPI IWineD3DVolumeImpl_SetContainer(IWineD3DVolume *iface, IWineD3DBase* container) {
-    IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
-
-    TRACE("This %p, container %p\n", This, container);
-
-    /* We can't keep a reference to the container, since the container already keeps a reference to us. */
-
-    TRACE("Setting container to %p from %p\n", container, This->container);
-    This->container = container;
-
-    return WINED3D_OK;
-}
-
 /* Context activation is done by the caller. */
 static HRESULT WINAPI IWineD3DVolumeImpl_LoadTexture(IWineD3DVolume *iface, int gl_level, BOOL srgb_mode)
 {
     IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
     const struct wined3d_gl_info *gl_info = &This->resource.device->adapter->gl_info;
-    const struct wined3d_format_desc *glDesc = This->resource.format_desc;
+    const struct wined3d_format *format = This->resource.format;
 
-    TRACE("(%p) : level %u, format %s (0x%08x)\n", This, gl_level, debug_d3dformat(glDesc->format), glDesc->format);
+    TRACE("iface %p, level %u, srgb %#x, format %s (%#x).\n",
+            iface, gl_level, srgb_mode, debug_d3dformat(format->id), format->id);
 
     volume_bind_and_dirtify(iface);
 
     TRACE("Calling glTexImage3D %x level=%d, intfmt=%x, w=%d, h=%d,d=%d, 0=%d, glFmt=%x, glType=%x, Mem=%p\n",
-            GL_TEXTURE_3D,
-            gl_level,
-            glDesc->glInternal,
-            This->currentDesc.Width,
-            This->currentDesc.Height,
-            This->currentDesc.Depth,
-            0,
-            glDesc->glFormat,
-            glDesc->glType,
-            This->resource.allocatedMemory);
+            GL_TEXTURE_3D, gl_level, format->glInternal, This->currentDesc.Width, This->currentDesc.Height,
+            This->currentDesc.Depth, 0, format->glFormat, format->glType, This->resource.allocatedMemory);
 
     ENTER_GL();
-    GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D,
-                gl_level,
-                glDesc->glInternal,
-                This->currentDesc.Width,
-                This->currentDesc.Height,
-                This->currentDesc.Depth,
-                0,
-                glDesc->glFormat,
-                glDesc->glType,
-                This->resource.allocatedMemory));
+    GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D, gl_level, format->glInternal,
+            This->currentDesc.Width, This->currentDesc.Height, This->currentDesc.Depth,
+            0, format->glFormat, format->glType, This->resource.allocatedMemory));
     checkGLcall("glTexImage3D");
     LEAVE_GL();
 
@@ -373,21 +320,19 @@ static const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl =
     IWineD3DVolumeImpl_UnLoad,
     IWineD3DVolumeImpl_GetType,
     /* IWineD3DVolume */
-    IWineD3DVolumeImpl_GetContainer,
     IWineD3DVolumeImpl_GetDesc,
     IWineD3DVolumeImpl_LockBox,
     IWineD3DVolumeImpl_UnlockBox,
     /* Internal interface */
     IWineD3DVolumeImpl_LoadTexture,
-    IWineD3DVolumeImpl_SetContainer
 };
 
 HRESULT volume_init(IWineD3DVolumeImpl *volume, IWineD3DDeviceImpl *device, UINT width,
-        UINT height, UINT depth, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
-        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+        UINT height, UINT depth, DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool,
+        void *parent, const struct wined3d_parent_ops *parent_ops)
 {
     const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
-    const struct wined3d_format_desc *format_desc = getFormatDescEntry(format, gl_info);
+    const struct wined3d_format *format = wined3d_get_format(gl_info, format_id);
     HRESULT hr;
 
     if (!gl_info->supported[EXT_TEXTURE3D])
@@ -399,7 +344,7 @@ HRESULT volume_init(IWineD3DVolumeImpl *volume, IWineD3DDeviceImpl *device, UINT
     volume->lpVtbl = &IWineD3DVolume_Vtbl;
 
     hr = resource_init((IWineD3DResource *)volume, WINED3DRTYPE_VOLUME, device,
-            width * height * depth * format_desc->byte_count, usage, format_desc, pool, parent, parent_ops);
+            width * height * depth * format->byte_count, usage, format, pool, parent, parent_ops);
     if (FAILED(hr))
     {
         WARN("Failed to initialize resource, returning %#x.\n", hr);