2005-01-17 14:44:57 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2002-2005 Jason Edmeades
|
2005-03-29 21:01:00 +02:00
|
|
|
* Copyright 2002-2005 Raphael Junqueira
|
2005-07-13 16:15:54 +02:00
|
|
|
* Copyright 2005 Oliver Stieber
|
2011-04-14 22:41:47 +02:00
|
|
|
* Copyright 2009-2011 Henri Verbeet for CodeWeavers
|
2005-01-17 14:44:57 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-01-17 14:44:57 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
2008-09-17 17:51:44 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
|
2010-05-24 09:56:36 +02:00
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2011-07-27 23:21:25 +02:00
|
|
|
static void volume_bind_and_dirtify(const struct wined3d_volume *volume, struct wined3d_context *context)
|
2011-01-18 17:55:20 +01:00
|
|
|
{
|
2011-03-18 19:11:00 +01:00
|
|
|
struct wined3d_texture *container = volume->container;
|
2009-08-17 09:39:07 +02:00
|
|
|
DWORD active_sampler;
|
2008-09-17 17:50:40 +02:00
|
|
|
|
|
|
|
/* We don't need a specific texture unit, but after binding the texture the current unit is dirty.
|
|
|
|
* Read the unit back instead of switching to 0, this avoids messing around with the state manager's
|
|
|
|
* gl states. The current texture unit should always be a valid one.
|
|
|
|
*
|
|
|
|
* To be more specific, this is tricky because we can implicitly be called
|
|
|
|
* from sampler() in state.c. This means we can't touch anything other than
|
|
|
|
* whatever happens to be the currently active texture, or we would risk
|
2011-07-26 23:01:26 +02:00
|
|
|
* marking already applied sampler states dirty again. */
|
|
|
|
active_sampler = volume->resource.device->rev_tex_unit_map[context->active_texture];
|
2008-09-17 17:50:40 +02:00
|
|
|
|
2009-08-17 09:39:07 +02:00
|
|
|
if (active_sampler != WINED3D_UNMAPPED_STAGE)
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(volume->resource.device, STATE_SAMPLER(active_sampler));
|
2008-09-17 17:50:40 +02:00
|
|
|
|
2011-07-27 23:21:25 +02:00
|
|
|
container->texture_ops->texture_bind(container, context, FALSE);
|
2008-09-17 17:50:40 +02:00
|
|
|
}
|
|
|
|
|
2011-12-06 22:57:47 +01:00
|
|
|
void volume_add_dirty_box(struct wined3d_volume *volume, const struct wined3d_box *dirty_box)
|
2009-01-14 10:01:10 +01:00
|
|
|
{
|
2011-01-18 17:55:19 +01:00
|
|
|
volume->dirty = TRUE;
|
2009-01-14 10:01:10 +01:00
|
|
|
if (dirty_box)
|
|
|
|
{
|
2011-12-06 22:57:47 +01:00
|
|
|
volume->lockedBox.left = min(volume->lockedBox.left, dirty_box->left);
|
|
|
|
volume->lockedBox.top = min(volume->lockedBox.top, dirty_box->top);
|
|
|
|
volume->lockedBox.front = min(volume->lockedBox.front, dirty_box->front);
|
|
|
|
volume->lockedBox.right = max(volume->lockedBox.right, dirty_box->right);
|
|
|
|
volume->lockedBox.bottom = max(volume->lockedBox.bottom, dirty_box->bottom);
|
|
|
|
volume->lockedBox.back = max(volume->lockedBox.back, dirty_box->back);
|
2009-01-14 10:01:10 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-06 22:57:47 +01:00
|
|
|
volume->lockedBox.left = 0;
|
|
|
|
volume->lockedBox.top = 0;
|
|
|
|
volume->lockedBox.front = 0;
|
|
|
|
volume->lockedBox.right = volume->resource.width;
|
|
|
|
volume->lockedBox.bottom = volume->resource.height;
|
|
|
|
volume->lockedBox.back = volume->resource.depth;
|
2009-01-14 10:01:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:48 +02:00
|
|
|
void volume_set_container(struct wined3d_volume *volume, struct wined3d_texture *container)
|
2010-08-16 20:00:22 +02:00
|
|
|
{
|
|
|
|
TRACE("volume %p, container %p.\n", volume, container);
|
|
|
|
|
|
|
|
volume->container = container;
|
|
|
|
}
|
|
|
|
|
2011-01-20 19:52:01 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2011-07-27 23:21:25 +02:00
|
|
|
void volume_load(const struct wined3d_volume *volume, struct wined3d_context *context, UINT level, BOOL srgb_mode)
|
2011-01-20 19:52:01 +01:00
|
|
|
{
|
2011-07-27 23:21:25 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2011-01-20 19:52:01 +01:00
|
|
|
const struct wined3d_format *format = volume->resource.format;
|
|
|
|
|
2011-07-27 23:21:25 +02:00
|
|
|
TRACE("volume %p, context %p, level %u, srgb %#x, format %s (%#x).\n",
|
|
|
|
volume, context, level, srgb_mode, debug_d3dformat(format->id), format->id);
|
2011-01-20 19:52:01 +01:00
|
|
|
|
2011-07-27 23:21:25 +02:00
|
|
|
volume_bind_and_dirtify(volume, context);
|
2011-01-20 19:52:01 +01:00
|
|
|
|
|
|
|
ENTER_GL();
|
|
|
|
GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D, level, format->glInternal,
|
2011-03-08 19:41:07 +01:00
|
|
|
volume->resource.width, volume->resource.height, volume->resource.depth,
|
2011-01-20 19:52:01 +01:00
|
|
|
0, format->glFormat, format->glType, volume->resource.allocatedMemory));
|
|
|
|
checkGLcall("glTexImage3D");
|
|
|
|
LEAVE_GL();
|
|
|
|
|
|
|
|
/* When adding code releasing volume->resource.allocatedMemory to save
|
|
|
|
* data keep in mind that GL_UNPACK_CLIENT_STORAGE_APPLE is enabled by
|
|
|
|
* default if supported(GL_APPLE_client_storage). Thus do not release
|
|
|
|
* volume->resource.allocatedMemory if GL_APPLE_client_storage is
|
|
|
|
* supported. */
|
|
|
|
}
|
|
|
|
|
2011-02-28 08:05:39 +01:00
|
|
|
/* Do not call while under the GL lock. */
|
2011-03-01 09:47:56 +01:00
|
|
|
static void volume_unload(struct wined3d_resource *resource)
|
2011-02-28 08:05:39 +01:00
|
|
|
{
|
|
|
|
TRACE("texture %p.\n", resource);
|
|
|
|
|
|
|
|
/* The whole content is shadowed on This->resource.allocatedMemory, and
|
|
|
|
* the texture name is managed by the VolumeTexture container. */
|
|
|
|
|
|
|
|
resource_unload(resource);
|
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
ULONG CDECL wined3d_volume_incref(struct wined3d_volume *volume)
|
2005-01-17 14:44:57 +01:00
|
|
|
{
|
2011-04-15 18:33:38 +02:00
|
|
|
ULONG refcount;
|
|
|
|
|
|
|
|
if (volume->container)
|
|
|
|
{
|
|
|
|
TRACE("Forwarding to container %p.\n", volume->container);
|
|
|
|
return wined3d_texture_incref(volume->container);
|
|
|
|
}
|
|
|
|
|
|
|
|
refcount = InterlockedIncrement(&volume->resource.ref);
|
2009-12-21 23:17:24 +01:00
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
TRACE("%p increasing refcount to %u.\n", volume, refcount);
|
2009-12-21 23:17:24 +01:00
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
return refcount;
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2011-04-14 22:41:47 +02:00
|
|
|
ULONG CDECL wined3d_volume_decref(struct wined3d_volume *volume)
|
|
|
|
{
|
2011-04-15 18:33:38 +02:00
|
|
|
ULONG refcount;
|
|
|
|
|
|
|
|
if (volume->container)
|
|
|
|
{
|
|
|
|
TRACE("Forwarding to container %p.\n", volume->container);
|
|
|
|
return wined3d_texture_decref(volume->container);
|
|
|
|
}
|
|
|
|
|
|
|
|
refcount = InterlockedDecrement(&volume->resource.ref);
|
2011-04-14 22:41:47 +02:00
|
|
|
|
|
|
|
TRACE("%p decreasing refcount to %u.\n", volume, refcount);
|
2010-09-14 13:38:39 +02:00
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
if (!refcount)
|
2010-09-14 13:38:39 +02:00
|
|
|
{
|
2011-04-14 22:41:47 +02:00
|
|
|
resource_cleanup(&volume->resource);
|
|
|
|
volume->resource.parent_ops->wined3d_object_destroyed(volume->resource.parent);
|
|
|
|
HeapFree(GetProcessHeap(), 0, volume);
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
2011-04-14 22:41:47 +02:00
|
|
|
|
|
|
|
return refcount;
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
void * CDECL wined3d_volume_get_parent(const struct wined3d_volume *volume)
|
2010-08-31 18:41:40 +02:00
|
|
|
{
|
2011-04-14 22:41:47 +02:00
|
|
|
TRACE("volume %p.\n", volume);
|
2010-08-31 18:41:40 +02:00
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
return volume->resource.parent;
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
DWORD CDECL wined3d_volume_set_priority(struct wined3d_volume *volume, DWORD priority)
|
2011-01-07 10:16:40 +01:00
|
|
|
{
|
2011-04-14 22:41:47 +02:00
|
|
|
return resource_set_priority(&volume->resource, priority);
|
2005-03-29 21:01:00 +02:00
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
DWORD CDECL wined3d_volume_get_priority(const struct wined3d_volume *volume)
|
2011-01-07 10:16:39 +01:00
|
|
|
{
|
2011-04-14 22:41:47 +02:00
|
|
|
return resource_get_priority(&volume->resource);
|
2005-03-29 21:01:00 +02:00
|
|
|
}
|
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2011-04-14 22:41:47 +02:00
|
|
|
void CDECL wined3d_volume_preload(struct wined3d_volume *volume)
|
|
|
|
{
|
|
|
|
FIXME("volume %p stub!\n", volume);
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
struct wined3d_resource * CDECL wined3d_volume_get_resource(struct wined3d_volume *volume)
|
2010-08-25 20:46:50 +02:00
|
|
|
{
|
2011-04-14 22:41:47 +02:00
|
|
|
TRACE("volume %p.\n", volume);
|
2010-09-06 22:18:54 +02:00
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
return &volume->resource;
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume,
|
2011-12-06 22:57:47 +01:00
|
|
|
struct wined3d_mapped_box *mapped_box, const struct wined3d_box *box, DWORD flags)
|
2010-10-14 13:04:02 +02:00
|
|
|
{
|
2011-12-05 22:06:57 +01:00
|
|
|
TRACE("volume %p, mapped_box %p, box %p, flags %#x.\n",
|
|
|
|
volume, mapped_box, box, flags);
|
2005-01-17 14:44:57 +01:00
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
if (!volume->resource.allocatedMemory)
|
|
|
|
volume->resource.allocatedMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, volume->resource.size);
|
2007-02-20 23:02:30 +01:00
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
TRACE("allocatedMemory %p.\n", volume->resource.allocatedMemory);
|
2005-01-17 14:44:57 +01:00
|
|
|
|
2011-12-05 22:06:57 +01:00
|
|
|
mapped_box->row_pitch = volume->resource.format->byte_count * volume->resource.width; /* Bytes / row */
|
|
|
|
mapped_box->slice_pitch = volume->resource.format->byte_count
|
2011-04-14 22:41:47 +02:00
|
|
|
* volume->resource.width * volume->resource.height; /* Bytes / slice */
|
|
|
|
if (!box)
|
|
|
|
{
|
2005-01-17 14:44:57 +01:00
|
|
|
TRACE("No box supplied - all is ok\n");
|
2011-12-05 22:06:57 +01:00
|
|
|
mapped_box->data = volume->resource.allocatedMemory;
|
2011-12-06 22:57:47 +01:00
|
|
|
volume->lockedBox.left = 0;
|
|
|
|
volume->lockedBox.top = 0;
|
|
|
|
volume->lockedBox.front = 0;
|
|
|
|
volume->lockedBox.right = volume->resource.width;
|
|
|
|
volume->lockedBox.bottom = volume->resource.height;
|
|
|
|
volume->lockedBox.back = volume->resource.depth;
|
2011-04-14 22:41:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-06 22:57:47 +01:00
|
|
|
TRACE("Lock Box (%p) = l %u, t %u, r %u, b %u, fr %u, ba %u\n",
|
|
|
|
box, box->left, box->top, box->right, box->bottom, box->front, box->back);
|
2011-12-05 22:06:57 +01:00
|
|
|
mapped_box->data = volume->resource.allocatedMemory
|
2011-12-06 22:57:47 +01:00
|
|
|
+ (mapped_box->slice_pitch * box->front) /* FIXME: is front < back or vica versa? */
|
|
|
|
+ (mapped_box->row_pitch * box->top)
|
|
|
|
+ (box->left * volume->resource.format->byte_count);
|
|
|
|
volume->lockedBox.left = box->left;
|
|
|
|
volume->lockedBox.top = box->top;
|
|
|
|
volume->lockedBox.front = box->front;
|
|
|
|
volume->lockedBox.right = box->right;
|
|
|
|
volume->lockedBox.bottom = box->bottom;
|
|
|
|
volume->lockedBox.back = box->back;
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2010-11-18 20:50:40 +01:00
|
|
|
if (!(flags & (WINED3DLOCK_NO_DIRTY_UPDATE | WINED3DLOCK_READONLY)))
|
2010-08-16 20:00:24 +02:00
|
|
|
{
|
2011-04-14 22:41:47 +02:00
|
|
|
volume_add_dirty_box(volume, &volume->lockedBox);
|
|
|
|
wined3d_texture_set_dirty(volume->container, TRUE);
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
volume->locked = TRUE;
|
|
|
|
|
|
|
|
TRACE("Returning memory %p, row pitch %d, slice pitch %d.\n",
|
2011-12-05 22:06:57 +01:00
|
|
|
mapped_box->data, mapped_box->row_pitch, mapped_box->slice_pitch);
|
2011-04-14 22:41:47 +02:00
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
struct wined3d_volume * CDECL wined3d_volume_from_resource(struct wined3d_resource *resource)
|
2011-03-14 21:02:57 +01:00
|
|
|
{
|
2011-04-14 22:41:47 +02:00
|
|
|
return volume_from_resource(resource);
|
2011-03-14 21:02:57 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 22:41:47 +02:00
|
|
|
HRESULT CDECL wined3d_volume_unmap(struct wined3d_volume *volume)
|
2010-10-14 13:04:02 +02:00
|
|
|
{
|
2011-04-14 22:41:47 +02:00
|
|
|
TRACE("volume %p.\n", volume);
|
|
|
|
|
|
|
|
if (!volume->locked)
|
2009-12-16 19:55:57 +01:00
|
|
|
{
|
2011-04-14 22:41:47 +02:00
|
|
|
WARN("Trying to unlock unlocked volume %p.\n", volume);
|
2009-12-16 19:55:57 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
2011-04-14 22:41:47 +02:00
|
|
|
|
|
|
|
volume->locked = FALSE;
|
|
|
|
memset(&volume->lockedBox, 0, sizeof(volume->lockedBox));
|
|
|
|
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
|
|
|
|
2011-02-28 08:05:39 +01:00
|
|
|
static const struct wined3d_resource_ops volume_resource_ops =
|
|
|
|
{
|
|
|
|
volume_unload,
|
|
|
|
};
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
static HRESULT volume_init(struct wined3d_volume *volume, struct wined3d_device *device, UINT width,
|
2010-08-23 18:28:10 +02:00
|
|
|
UINT height, UINT depth, DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool,
|
2010-08-31 18:41:40 +02:00
|
|
|
void *parent, const struct wined3d_parent_ops *parent_ops)
|
2009-09-16 08:37:16 +02:00
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2010-08-30 20:29:49 +02:00
|
|
|
const struct wined3d_format *format = wined3d_get_format(gl_info, format_id);
|
2009-09-16 08:37:16 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!gl_info->supported[EXT_TEXTURE3D])
|
|
|
|
{
|
|
|
|
WARN("Volume cannot be created - no volume texture support.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2012-01-17 21:13:36 +01:00
|
|
|
hr = resource_init(&volume->resource, device, WINED3D_RTYPE_VOLUME, format,
|
2012-01-08 21:15:00 +01:00
|
|
|
WINED3D_MULTISAMPLE_NONE, 0, usage, pool, width, height, depth,
|
2011-03-08 19:41:07 +01:00
|
|
|
width * height * depth * format->byte_count, parent, parent_ops,
|
|
|
|
&volume_resource_ops);
|
2009-09-16 08:37:16 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to initialize resource, returning %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
volume->lockable = TRUE;
|
|
|
|
volume->locked = FALSE;
|
|
|
|
memset(&volume->lockedBox, 0, sizeof(volume->lockedBox));
|
|
|
|
volume->dirty = TRUE;
|
|
|
|
|
2011-01-18 17:55:19 +01:00
|
|
|
volume_add_dirty_box(volume, NULL);
|
2009-09-16 08:37:16 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
HRESULT CDECL wined3d_volume_create(struct wined3d_device *device, UINT width, UINT height,
|
2011-05-10 21:18:47 +02:00
|
|
|
UINT depth, DWORD usage, enum wined3d_format_id format_id, WINED3DPOOL pool, void *parent,
|
|
|
|
const struct wined3d_parent_ops *parent_ops, struct wined3d_volume **volume)
|
|
|
|
{
|
|
|
|
struct wined3d_volume *object;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("device %p, width %u, height %u, depth %u, usage %#x, format %s, pool %s\n",
|
|
|
|
device, width, height, depth, usage, debug_d3dformat(format_id), debug_d3dpool(pool));
|
|
|
|
TRACE("parent %p, parent_ops %p, volume %p.\n", parent, parent_ops, volume);
|
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
ERR("Out of memory\n");
|
|
|
|
*volume = NULL;
|
|
|
|
return WINED3DERR_OUTOFVIDEOMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = volume_init(object, device, width, height, depth, usage, format_id, pool, parent, parent_ops);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to initialize volume, returning %#x.\n", hr);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created volume %p.\n", object);
|
|
|
|
*volume = object;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|