2005-01-17 14:44:57 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2002-2005 Jason Edmeades
|
2005-03-14 11:12:52 +01:00
|
|
|
* Copyright 2002-2005 Raphael Junqueira
|
|
|
|
* Copyright 2005 Oliver Stieber
|
2013-04-16 14:48:32 +02:00
|
|
|
* Copyright 2007-2009, 2013 Stefan Dösinger for CodeWeavers
|
2011-03-18 19:10:58 +01: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"
|
2012-06-01 16:56:21 +02:00
|
|
|
#include "wine/port.h"
|
2005-01-17 14:44:57 +01:00
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
2016-03-29 16:45:35 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
2016-03-11 16:01:43 +01:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
|
2014-07-01 07:52:30 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(winediag);
|
2009-06-03 10:47:25 +02:00
|
|
|
|
2016-04-20 19:29:11 +02:00
|
|
|
#define WINED3D_TEXTURE_DYNAMIC_MAP_THRESHOLD 50
|
|
|
|
|
2016-04-18 19:06:27 +02:00
|
|
|
static BOOL wined3d_texture_use_pbo(const struct wined3d_texture *texture, const struct wined3d_gl_info *gl_info)
|
2016-03-14 17:02:17 +01:00
|
|
|
{
|
|
|
|
return texture->resource.pool == WINED3D_POOL_DEFAULT
|
|
|
|
&& texture->resource.access_flags & WINED3D_RESOURCE_ACCESS_CPU
|
|
|
|
&& gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]
|
|
|
|
&& !texture->resource.format->convert
|
|
|
|
&& !(texture->flags & (WINED3D_TEXTURE_PIN_SYSMEM | WINED3D_TEXTURE_COND_NP2_EMULATED));
|
|
|
|
}
|
|
|
|
|
2016-05-26 00:08:27 +02:00
|
|
|
static BOOL wined3d_texture_use_immutable_storage(const struct wined3d_texture *texture,
|
|
|
|
const struct wined3d_gl_info *gl_info)
|
|
|
|
{
|
|
|
|
/* We don't expect to create texture views for textures with height-scaled formats.
|
2016-05-29 12:38:56 +02:00
|
|
|
* Besides, ARB_texture_storage doesn't allow specifying exact sizes for all levels. */
|
2016-05-26 00:08:27 +02:00
|
|
|
return gl_info->supported[ARB_TEXTURE_STORAGE]
|
|
|
|
&& !(texture->resource.format_flags & WINED3DFMT_FLAG_HEIGHT_SCALE);
|
|
|
|
}
|
|
|
|
|
2016-03-23 17:58:23 +01:00
|
|
|
GLenum wined3d_texture_get_gl_buffer(const struct wined3d_texture *texture)
|
|
|
|
{
|
|
|
|
const struct wined3d_swapchain *swapchain = texture->swapchain;
|
|
|
|
|
|
|
|
TRACE("texture %p.\n", texture);
|
|
|
|
|
|
|
|
if (!swapchain)
|
|
|
|
{
|
|
|
|
ERR("Texture %p is not part of a swapchain.\n", texture);
|
|
|
|
return GL_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (swapchain->back_buffers && swapchain->back_buffers[0] == texture)
|
|
|
|
{
|
|
|
|
if (swapchain->render_to_fbo)
|
|
|
|
{
|
|
|
|
TRACE("Returning GL_COLOR_ATTACHMENT0.\n");
|
|
|
|
return GL_COLOR_ATTACHMENT0;
|
|
|
|
}
|
|
|
|
TRACE("Returning GL_BACK.\n");
|
|
|
|
return GL_BACK;
|
|
|
|
}
|
|
|
|
else if (texture == swapchain->front_buffer)
|
|
|
|
{
|
|
|
|
TRACE("Returning GL_FRONT.\n");
|
|
|
|
return GL_FRONT;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("Higher back buffer, returning GL_BACK.\n");
|
|
|
|
return GL_BACK;
|
|
|
|
}
|
|
|
|
|
2016-07-28 13:29:40 +02:00
|
|
|
static DWORD wined3d_resource_access_from_location(DWORD location)
|
|
|
|
{
|
|
|
|
switch (location)
|
|
|
|
{
|
|
|
|
case WINED3D_LOCATION_DISCARDED:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_SYSMEM:
|
|
|
|
return WINED3D_RESOURCE_ACCESS_CPU;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_BUFFER:
|
|
|
|
case WINED3D_LOCATION_TEXTURE_RGB:
|
|
|
|
case WINED3D_LOCATION_TEXTURE_SRGB:
|
|
|
|
return WINED3D_RESOURCE_ACCESS_GPU;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled location %#x.\n", location);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-20 19:29:11 +02:00
|
|
|
static void wined3d_texture_evict_sysmem(struct wined3d_texture *texture)
|
|
|
|
{
|
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
|
|
|
unsigned int i, sub_count;
|
|
|
|
|
|
|
|
if (texture->flags & (WINED3D_TEXTURE_CONVERTED | WINED3D_TEXTURE_PIN_SYSMEM)
|
|
|
|
|| texture->download_count > WINED3D_TEXTURE_DYNAMIC_MAP_THRESHOLD)
|
|
|
|
{
|
|
|
|
TRACE("Not evicting system memory for texture %p.\n", texture);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Evicting system memory for texture %p.\n", texture);
|
|
|
|
|
|
|
|
sub_count = texture->level_count * texture->layer_count;
|
|
|
|
for (i = 0; i < sub_count; ++i)
|
|
|
|
{
|
|
|
|
sub_resource = &texture->sub_resources[i];
|
|
|
|
if (sub_resource->locations == WINED3D_LOCATION_SYSMEM)
|
|
|
|
ERR("WINED3D_LOCATION_SYSMEM is the only location for sub-resource %u of texture %p.\n",
|
|
|
|
i, texture);
|
|
|
|
sub_resource->locations &= ~WINED3D_LOCATION_SYSMEM;
|
|
|
|
}
|
2016-04-20 19:29:12 +02:00
|
|
|
wined3d_resource_free_sysmem(&texture->resource);
|
2016-04-20 19:29:11 +02:00
|
|
|
}
|
|
|
|
|
2016-03-29 16:45:36 +02:00
|
|
|
void wined3d_texture_validate_location(struct wined3d_texture *texture,
|
|
|
|
unsigned int sub_resource_idx, DWORD location)
|
|
|
|
{
|
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2016-04-20 19:29:11 +02:00
|
|
|
DWORD previous_locations;
|
2016-03-29 16:45:36 +02:00
|
|
|
|
|
|
|
TRACE("texture %p, sub_resource_idx %u, location %s.\n",
|
|
|
|
texture, sub_resource_idx, wined3d_debug_location(location));
|
|
|
|
|
|
|
|
sub_resource = &texture->sub_resources[sub_resource_idx];
|
2016-04-20 19:29:11 +02:00
|
|
|
previous_locations = sub_resource->locations;
|
2016-03-29 16:45:36 +02:00
|
|
|
sub_resource->locations |= location;
|
2016-04-20 19:29:11 +02:00
|
|
|
if (previous_locations == WINED3D_LOCATION_SYSMEM && location != WINED3D_LOCATION_SYSMEM
|
|
|
|
&& !--texture->sysmem_count)
|
|
|
|
wined3d_texture_evict_sysmem(texture);
|
2016-03-29 16:45:36 +02:00
|
|
|
|
|
|
|
TRACE("New locations flags are %s.\n", wined3d_debug_location(sub_resource->locations));
|
|
|
|
}
|
|
|
|
|
2016-05-15 15:39:46 +02:00
|
|
|
static void wined3d_texture_set_dirty(struct wined3d_texture *texture)
|
|
|
|
{
|
|
|
|
texture->flags &= ~(WINED3D_TEXTURE_RGB_VALID | WINED3D_TEXTURE_SRGB_VALID);
|
|
|
|
}
|
|
|
|
|
2016-03-30 21:30:19 +02:00
|
|
|
void wined3d_texture_invalidate_location(struct wined3d_texture *texture,
|
|
|
|
unsigned int sub_resource_idx, DWORD location)
|
|
|
|
{
|
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
|
|
|
|
|
|
|
TRACE("texture %p, sub_resource_idx %u, location %s.\n",
|
|
|
|
texture, sub_resource_idx, wined3d_debug_location(location));
|
|
|
|
|
|
|
|
if (location & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
|
|
|
|
wined3d_texture_set_dirty(texture);
|
|
|
|
|
|
|
|
sub_resource = &texture->sub_resources[sub_resource_idx];
|
|
|
|
sub_resource->locations &= ~location;
|
2016-04-20 19:29:11 +02:00
|
|
|
if (sub_resource->locations == WINED3D_LOCATION_SYSMEM)
|
|
|
|
++texture->sysmem_count;
|
2016-03-30 21:30:19 +02:00
|
|
|
|
|
|
|
TRACE("New locations flags are %s.\n", wined3d_debug_location(sub_resource->locations));
|
|
|
|
|
|
|
|
if (!sub_resource->locations)
|
|
|
|
ERR("Sub-resource %u of texture %p does not have any up to date location.\n",
|
|
|
|
sub_resource_idx, texture);
|
|
|
|
}
|
|
|
|
|
2016-08-01 12:49:07 +02:00
|
|
|
/* Context activation is done by the caller. Context may be NULL in
|
|
|
|
* WINED3D_NO3D mode. */
|
2016-08-02 12:26:29 +02:00
|
|
|
BOOL wined3d_texture_load_location(struct wined3d_texture *texture,
|
2016-08-01 12:49:07 +02:00
|
|
|
unsigned int sub_resource_idx, struct wined3d_context *context, DWORD location)
|
|
|
|
{
|
|
|
|
return texture->texture_ops->texture_load_location(texture, sub_resource_idx, context, location);
|
|
|
|
}
|
|
|
|
|
2016-04-14 19:32:45 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2016-04-14 19:32:46 +02:00
|
|
|
void *wined3d_texture_map_bo_address(const struct wined3d_bo_address *data, size_t size,
|
2016-04-14 19:32:45 +02:00
|
|
|
const struct wined3d_gl_info *gl_info, GLenum binding, DWORD flags)
|
|
|
|
{
|
|
|
|
BYTE *memory;
|
|
|
|
|
|
|
|
if (!data->buffer_object)
|
|
|
|
return data->addr;
|
|
|
|
|
|
|
|
GL_EXTCALL(glBindBuffer(binding, data->buffer_object));
|
|
|
|
|
|
|
|
if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
|
|
|
|
{
|
|
|
|
GLbitfield map_flags = wined3d_resource_gl_map_flags(flags) & ~GL_MAP_FLUSH_EXPLICIT_BIT;
|
|
|
|
memory = GL_EXTCALL(glMapBufferRange(binding, (INT_PTR)data->addr, size, map_flags));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memory = GL_EXTCALL(glMapBuffer(binding, wined3d_resource_gl_legacy_map_flags(flags)));
|
|
|
|
memory += (INT_PTR)data->addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_EXTCALL(glBindBuffer(binding, 0));
|
|
|
|
checkGLcall("Map buffer object");
|
|
|
|
|
|
|
|
return memory;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
2016-04-14 19:32:46 +02:00
|
|
|
void wined3d_texture_unmap_bo_address(const struct wined3d_bo_address *data,
|
2016-04-14 19:32:45 +02:00
|
|
|
const struct wined3d_gl_info *gl_info, GLenum binding)
|
|
|
|
{
|
|
|
|
if (!data->buffer_object)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GL_EXTCALL(glBindBuffer(binding, data->buffer_object));
|
|
|
|
GL_EXTCALL(glUnmapBuffer(binding));
|
|
|
|
GL_EXTCALL(glBindBuffer(binding, 0));
|
|
|
|
checkGLcall("Unmap buffer object");
|
|
|
|
}
|
|
|
|
|
2016-03-31 22:48:54 +02:00
|
|
|
void wined3d_texture_get_memory(struct wined3d_texture *texture, unsigned int sub_resource_idx,
|
|
|
|
struct wined3d_bo_address *data, DWORD locations)
|
|
|
|
{
|
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
|
|
|
|
|
|
|
TRACE("texture %p, sub_resource_idx %u, data %p, locations %s.\n",
|
|
|
|
texture, sub_resource_idx, data, wined3d_debug_location(locations));
|
|
|
|
|
|
|
|
sub_resource = &texture->sub_resources[sub_resource_idx];
|
|
|
|
if (locations & WINED3D_LOCATION_BUFFER)
|
|
|
|
{
|
|
|
|
data->addr = NULL;
|
|
|
|
data->buffer_object = sub_resource->buffer_object;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (locations & WINED3D_LOCATION_USER_MEMORY)
|
|
|
|
{
|
|
|
|
data->addr = texture->user_memory;
|
|
|
|
data->buffer_object = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (locations & WINED3D_LOCATION_SYSMEM)
|
|
|
|
{
|
2016-04-20 19:29:12 +02:00
|
|
|
data->addr = texture->resource.heap_memory;
|
|
|
|
data->addr += sub_resource->offset;
|
2016-03-31 22:48:54 +02:00
|
|
|
data->buffer_object = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR("Unexpected locations %s.\n", wined3d_debug_location(locations));
|
|
|
|
data->addr = NULL;
|
|
|
|
data->buffer_object = 0;
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
static HRESULT wined3d_texture_init(struct wined3d_texture *texture, const struct wined3d_texture_ops *texture_ops,
|
2016-01-27 00:06:25 +01:00
|
|
|
UINT layer_count, UINT level_count, const struct wined3d_resource_desc *desc, DWORD flags,
|
2015-06-06 17:53:53 +02:00
|
|
|
struct wined3d_device *device, void *parent, const struct wined3d_parent_ops *parent_ops,
|
|
|
|
const struct wined3d_resource_ops *resource_ops)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2013-06-05 11:06:10 +02:00
|
|
|
const struct wined3d_format *format = wined3d_get_format(&device->adapter->gl_info, desc->format);
|
2016-04-20 19:29:12 +02:00
|
|
|
unsigned int i, j, size, offset = 0;
|
2011-03-18 19:10:58 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2013-06-05 11:06:10 +02:00
|
|
|
TRACE("texture %p, texture_ops %p, layer_count %u, level_count %u, resource_type %s, format %s, "
|
|
|
|
"multisample_type %#x, multisample_quality %#x, usage %s, pool %s, width %u, height %u, depth %u, "
|
2016-01-27 00:06:25 +01:00
|
|
|
"flags %#x, device %p, parent %p, parent_ops %p, resource_ops %p.\n",
|
2013-06-05 11:06:10 +02:00
|
|
|
texture, texture_ops, layer_count, level_count, debug_d3dresourcetype(desc->resource_type),
|
|
|
|
debug_d3dformat(desc->format), desc->multisample_type, desc->multisample_quality,
|
|
|
|
debug_d3dusage(desc->usage), debug_d3dpool(desc->pool), desc->width, desc->height, desc->depth,
|
2016-01-27 00:06:25 +01:00
|
|
|
flags, device, parent, parent_ops, resource_ops);
|
2013-06-05 11:06:10 +02:00
|
|
|
|
2016-04-20 19:29:12 +02:00
|
|
|
if (!desc->width || !desc->height || !desc->depth)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
for (i = 0; i < layer_count; ++i)
|
|
|
|
{
|
|
|
|
for (j = 0; j < level_count; ++j)
|
|
|
|
{
|
|
|
|
unsigned int idx = i * level_count + j;
|
|
|
|
|
|
|
|
size = wined3d_format_calculate_size(format, device->surface_alignment,
|
|
|
|
max(1, desc->width >> j), max(1, desc->height >> j), max(1, desc->depth >> j));
|
|
|
|
texture->sub_resources[idx].offset = offset;
|
|
|
|
texture->sub_resources[idx].size = size;
|
|
|
|
offset += size;
|
|
|
|
}
|
|
|
|
offset = (offset + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!offset)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2015-06-06 17:53:53 +02:00
|
|
|
if (FAILED(hr = resource_init(&texture->resource, device, desc->resource_type, format,
|
2013-06-05 11:06:10 +02:00
|
|
|
desc->multisample_type, desc->multisample_quality, desc->usage, desc->pool,
|
2016-04-20 19:29:12 +02:00
|
|
|
desc->width, desc->height, desc->depth, offset, parent, parent_ops, resource_ops)))
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2014-07-01 07:52:30 +02:00
|
|
|
static unsigned int once;
|
|
|
|
|
2015-04-24 10:33:47 +02:00
|
|
|
/* DXTn 3D textures are not supported. Do not write the ERR for them. */
|
2014-07-01 07:52:30 +02:00
|
|
|
if ((desc->format == WINED3DFMT_DXT1 || desc->format == WINED3DFMT_DXT2 || desc->format == WINED3DFMT_DXT3
|
|
|
|
|| desc->format == WINED3DFMT_DXT4 || desc->format == WINED3DFMT_DXT5)
|
2015-06-06 17:53:53 +02:00
|
|
|
&& !(format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_TEXTURE)
|
2016-01-27 00:06:24 +01:00
|
|
|
&& desc->resource_type != WINED3D_RTYPE_TEXTURE_3D && !once++)
|
2014-07-01 07:52:30 +02:00
|
|
|
ERR_(winediag)("The application tried to create a DXTn texture, but the driver does not support them.\n");
|
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
WARN("Failed to initialize resource, returning %#x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
2014-08-20 13:20:01 +02:00
|
|
|
wined3d_resource_update_draw_binding(&texture->resource);
|
2016-03-14 17:02:17 +01:00
|
|
|
if ((flags & WINED3D_TEXTURE_CREATE_MAPPABLE) || desc->format == WINED3DFMT_D16_LOCKABLE)
|
|
|
|
texture->resource.access_flags |= WINED3D_RESOURCE_ACCESS_CPU;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->texture_ops = texture_ops;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->layer_count = layer_count;
|
|
|
|
texture->level_count = level_count;
|
2013-06-05 11:06:10 +02:00
|
|
|
texture->filter_type = (desc->usage & WINED3DUSAGE_AUTOGENMIPMAP) ? WINED3D_TEXF_LINEAR : WINED3D_TEXF_NONE;
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->lod = 0;
|
2016-03-21 17:40:11 +01:00
|
|
|
texture->flags |= WINED3D_TEXTURE_POW2_MAT_IDENT | WINED3D_TEXTURE_NORMALIZED_COORDS;
|
2016-04-13 12:18:47 +02:00
|
|
|
if (flags & WINED3D_TEXTURE_CREATE_GET_DC_LENIENT)
|
|
|
|
texture->flags |= WINED3D_TEXTURE_PIN_SYSMEM | WINED3D_TEXTURE_GET_DC_LENIENT;
|
2016-04-14 19:32:47 +02:00
|
|
|
if (flags & WINED3D_TEXTURE_CREATE_DISCARD)
|
|
|
|
texture->flags |= WINED3D_TEXTURE_DISCARD;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-02 19:24:21 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2016-04-18 19:06:27 +02:00
|
|
|
static void wined3d_texture_remove_buffer_object(struct wined3d_texture *texture,
|
2016-03-02 19:24:21 +01:00
|
|
|
unsigned int sub_resource_idx, const struct wined3d_gl_info *gl_info)
|
|
|
|
{
|
|
|
|
GLuint *buffer_object;
|
|
|
|
|
|
|
|
buffer_object = &texture->sub_resources[sub_resource_idx].buffer_object;
|
|
|
|
GL_EXTCALL(glDeleteBuffers(1, buffer_object));
|
|
|
|
checkGLcall("glDeleteBuffers");
|
2016-03-30 21:30:19 +02:00
|
|
|
wined3d_texture_invalidate_location(texture, sub_resource_idx, WINED3D_LOCATION_BUFFER);
|
2016-03-02 19:24:21 +01:00
|
|
|
*buffer_object = 0;
|
|
|
|
|
|
|
|
TRACE("Deleted buffer object %u for texture %p, sub-resource %u.\n",
|
|
|
|
*buffer_object, texture, sub_resource_idx);
|
|
|
|
}
|
|
|
|
|
2016-04-18 19:06:27 +02:00
|
|
|
static void wined3d_texture_update_map_binding(struct wined3d_texture *texture)
|
|
|
|
{
|
|
|
|
unsigned int sub_count = texture->level_count * texture->layer_count;
|
|
|
|
const struct wined3d_device *device = texture->resource.device;
|
|
|
|
DWORD map_binding = texture->update_map_binding;
|
|
|
|
struct wined3d_context *context = NULL;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (device->d3d_initialized)
|
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
|
|
|
|
for (i = 0; i < sub_count; ++i)
|
|
|
|
{
|
|
|
|
if (texture->sub_resources[i].locations == texture->resource.map_binding
|
2016-08-01 12:49:07 +02:00
|
|
|
&& !wined3d_texture_load_location(texture, i, context, map_binding))
|
2016-04-18 19:06:27 +02:00
|
|
|
ERR("Failed to load location %s.\n", wined3d_debug_location(map_binding));
|
|
|
|
if (texture->resource.map_binding == WINED3D_LOCATION_BUFFER)
|
|
|
|
wined3d_texture_remove_buffer_object(texture, i, context->gl_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context)
|
|
|
|
context_release(context);
|
|
|
|
|
|
|
|
texture->resource.map_binding = map_binding;
|
|
|
|
texture->update_map_binding = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wined3d_texture_set_map_binding(struct wined3d_texture *texture, DWORD map_binding)
|
|
|
|
{
|
|
|
|
texture->update_map_binding = map_binding;
|
|
|
|
if (!texture->resource.map_count)
|
|
|
|
wined3d_texture_update_map_binding(texture);
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
/* A GL context is provided by the caller */
|
2016-02-21 22:29:59 +01:00
|
|
|
static void gltexture_delete(struct wined3d_device *device, const struct wined3d_gl_info *gl_info,
|
|
|
|
struct gl_texture *tex)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2016-02-21 22:29:59 +01:00
|
|
|
context_gl_resource_released(device, tex->name, FALSE);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex->name);
|
2011-03-18 19:10:58 +01:00
|
|
|
tex->name = 0;
|
|
|
|
}
|
|
|
|
|
2016-05-26 00:08:27 +02:00
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
/* The caller is responsible for binding the correct texture. */
|
|
|
|
static void wined3d_texture_allocate_gl_mutable_storage(struct wined3d_texture *texture,
|
|
|
|
GLenum gl_internal_format, const struct wined3d_format *format,
|
|
|
|
const struct wined3d_gl_info *gl_info)
|
|
|
|
{
|
|
|
|
unsigned int i, sub_call_count;
|
|
|
|
|
|
|
|
sub_call_count = texture->level_count;
|
|
|
|
if (texture->target != GL_TEXTURE_2D_ARRAY)
|
|
|
|
sub_call_count *= texture->layer_count;
|
|
|
|
|
|
|
|
for (i = 0; i < sub_call_count; ++i)
|
|
|
|
{
|
|
|
|
struct wined3d_surface *surface = texture->sub_resources[i].u.surface;
|
|
|
|
GLsizei width, height;
|
|
|
|
|
|
|
|
width = wined3d_texture_get_level_pow2_width(texture, surface->texture_level);
|
|
|
|
height = wined3d_texture_get_level_pow2_height(texture, surface->texture_level);
|
|
|
|
if (texture->resource.format_flags & WINED3DFMT_FLAG_HEIGHT_SCALE)
|
|
|
|
{
|
|
|
|
height *= format->height_scale.numerator;
|
|
|
|
height /= format->height_scale.denominator;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("surface %p, target %#x, level %u, width %u, height %u.\n",
|
|
|
|
surface, surface->texture_target, surface->texture_level, width, height);
|
|
|
|
|
|
|
|
if (texture->target == GL_TEXTURE_2D_ARRAY)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glTexImage3D(surface->texture_target, surface->texture_level,
|
|
|
|
gl_internal_format, width, height, texture->layer_count, 0,
|
|
|
|
format->glFormat, format->glType, NULL));
|
|
|
|
checkGLcall("glTexImage3D");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glTexImage2D(surface->texture_target, surface->texture_level,
|
|
|
|
gl_internal_format, width, height, 0, format->glFormat, format->glType, NULL);
|
|
|
|
checkGLcall("glTexImage2D");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
/* The caller is responsible for binding the correct texture. */
|
|
|
|
static void wined3d_texture_allocate_gl_immutable_storage(struct wined3d_texture *texture,
|
|
|
|
GLenum gl_internal_format, const struct wined3d_gl_info *gl_info)
|
|
|
|
{
|
|
|
|
GLsizei width = wined3d_texture_get_level_pow2_width(texture, 0);
|
|
|
|
GLsizei height = wined3d_texture_get_level_pow2_height(texture, 0);
|
|
|
|
|
|
|
|
if (texture->target == GL_TEXTURE_2D_ARRAY)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glTexStorage3D(texture->target, texture->level_count, gl_internal_format,
|
|
|
|
width, height, texture->layer_count));
|
|
|
|
checkGLcall("glTexStorage3D");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glTexStorage2D(texture->target, texture->level_count, gl_internal_format,
|
|
|
|
width, height));
|
|
|
|
checkGLcall("glTexStorage2D");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-21 00:10:21 +01:00
|
|
|
static void wined3d_texture_unload_gl_texture(struct wined3d_texture *texture)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_device *device = texture->resource.device;
|
2016-04-18 19:06:26 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = NULL;
|
2011-03-18 19:10:58 +01:00
|
|
|
struct wined3d_context *context = NULL;
|
|
|
|
|
2016-04-18 19:06:26 +02:00
|
|
|
if (texture->texture_rgb.name || texture->texture_srgb.name
|
|
|
|
|| texture->rb_multisample || texture->rb_resolved)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
context = context_acquire(device, NULL);
|
2016-04-18 19:06:26 +02:00
|
|
|
gl_info = context->gl_info;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
if (texture->texture_rgb.name)
|
2016-02-21 22:29:59 +01:00
|
|
|
gltexture_delete(device, context->gl_info, &texture->texture_rgb);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
if (texture->texture_srgb.name)
|
2016-02-21 22:29:59 +01:00
|
|
|
gltexture_delete(device, context->gl_info, &texture->texture_srgb);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2016-04-18 19:06:26 +02:00
|
|
|
if (texture->rb_multisample)
|
|
|
|
{
|
|
|
|
TRACE("Deleting multisample renderbuffer %u.\n", texture->rb_multisample);
|
|
|
|
context_gl_resource_released(device, texture->rb_multisample, TRUE);
|
|
|
|
gl_info->fbo_ops.glDeleteRenderbuffers(1, &texture->rb_multisample);
|
2016-04-25 17:19:28 +02:00
|
|
|
texture->rb_multisample = 0;
|
2016-04-18 19:06:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (texture->rb_resolved)
|
|
|
|
{
|
|
|
|
TRACE("Deleting resolved renderbuffer %u.\n", texture->rb_resolved);
|
|
|
|
context_gl_resource_released(device, texture->rb_resolved, TRUE);
|
|
|
|
gl_info->fbo_ops.glDeleteRenderbuffers(1, &texture->rb_resolved);
|
2016-04-25 17:19:28 +02:00
|
|
|
texture->rb_resolved = 0;
|
2016-04-18 19:06:26 +02:00
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
if (context) context_release(context);
|
|
|
|
|
2013-09-09 10:26:17 +02:00
|
|
|
wined3d_texture_set_dirty(texture);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
resource_unload(&texture->resource);
|
|
|
|
}
|
|
|
|
|
2016-07-08 10:59:03 +02:00
|
|
|
static void wined3d_texture_sub_resources_destroyed(struct wined3d_texture *texture)
|
|
|
|
{
|
|
|
|
unsigned int sub_count = texture->level_count * texture->layer_count;
|
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sub_count; ++i)
|
|
|
|
{
|
|
|
|
sub_resource = &texture->sub_resources[i];
|
|
|
|
if (sub_resource->parent)
|
|
|
|
{
|
|
|
|
TRACE("sub-resource %u.\n", i);
|
|
|
|
sub_resource->parent_ops->wined3d_object_destroyed(sub_resource->parent);
|
|
|
|
sub_resource->parent = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
static void wined3d_texture_cleanup(struct wined3d_texture *texture)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2016-03-02 19:24:19 +01:00
|
|
|
unsigned int sub_count = texture->level_count * texture->layer_count;
|
|
|
|
struct wined3d_device *device = texture->resource.device;
|
|
|
|
struct wined3d_context *context = NULL;
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
GLuint buffer_object;
|
|
|
|
unsigned int i;
|
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
TRACE("texture %p.\n", texture);
|
|
|
|
|
2016-03-02 19:24:19 +01:00
|
|
|
for (i = 0; i < sub_count; ++i)
|
|
|
|
{
|
|
|
|
if (!(buffer_object = texture->sub_resources[i].buffer_object))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
TRACE("Deleting buffer object %u.\n", buffer_object);
|
|
|
|
|
|
|
|
/* We may not be able to get a context in wined3d_texture_cleanup() in
|
|
|
|
* general, but if a buffer object was previously created we can. */
|
|
|
|
if (!context)
|
|
|
|
{
|
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
gl_info = context->gl_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_EXTCALL(glDeleteBuffers(1, &buffer_object));
|
|
|
|
}
|
|
|
|
if (context)
|
|
|
|
context_release(context);
|
|
|
|
|
2016-03-02 19:24:13 +01:00
|
|
|
texture->texture_ops->texture_cleanup_sub_resources(texture);
|
2013-11-21 00:10:21 +01:00
|
|
|
wined3d_texture_unload_gl_texture(texture);
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2014-08-20 13:20:00 +02:00
|
|
|
void wined3d_texture_set_swapchain(struct wined3d_texture *texture, struct wined3d_swapchain *swapchain)
|
|
|
|
{
|
|
|
|
texture->swapchain = swapchain;
|
2014-08-20 13:20:01 +02:00
|
|
|
wined3d_resource_update_draw_binding(&texture->resource);
|
2014-08-20 13:20:00 +02:00
|
|
|
}
|
|
|
|
|
2011-01-04 17:42:03 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2013-11-21 00:10:17 +01:00
|
|
|
void wined3d_texture_bind(struct wined3d_texture *texture,
|
|
|
|
struct wined3d_context *context, BOOL srgb)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2016-03-23 21:19:10 +01:00
|
|
|
const struct wined3d_format *format = texture->resource.format;
|
|
|
|
const struct color_fixup_desc fixup = format->color_fixup;
|
2011-03-18 19:10:58 +01:00
|
|
|
struct gl_texture *gl_tex;
|
|
|
|
GLenum target;
|
|
|
|
|
2013-11-21 00:10:17 +01:00
|
|
|
TRACE("texture %p, context %p, srgb %#x.\n", texture, context, srgb);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2016-02-08 00:04:37 +01:00
|
|
|
if (!needs_separate_srgb_gl_texture(context))
|
2013-10-09 12:38:00 +02:00
|
|
|
srgb = FALSE;
|
|
|
|
|
2011-03-28 21:58:45 +02:00
|
|
|
/* sRGB mode cache for preload() calls outside drawprim. */
|
|
|
|
if (srgb)
|
|
|
|
texture->flags |= WINED3D_TEXTURE_IS_SRGB;
|
|
|
|
else
|
|
|
|
texture->flags &= ~WINED3D_TEXTURE_IS_SRGB;
|
|
|
|
|
2013-10-09 12:38:00 +02:00
|
|
|
gl_tex = wined3d_texture_get_gl_texture(texture, srgb);
|
2011-03-28 21:58:42 +02:00
|
|
|
target = texture->target;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2013-11-21 00:10:18 +01:00
|
|
|
if (gl_tex->name)
|
|
|
|
{
|
|
|
|
context_bind_texture(context, target, gl_tex->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &gl_tex->name);
|
|
|
|
checkGLcall("glGenTextures");
|
|
|
|
TRACE("Generated texture %d.\n", gl_tex->name);
|
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
if (!gl_tex->name)
|
|
|
|
{
|
2013-11-21 00:10:18 +01:00
|
|
|
ERR("Failed to generate a texture name.\n");
|
|
|
|
return;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2013-11-21 00:10:18 +01:00
|
|
|
/* Initialise the state of the texture object to the OpenGL defaults, not
|
|
|
|
* the wined3d defaults. */
|
2015-01-15 17:19:04 +01:00
|
|
|
gl_tex->sampler_desc.address_u = WINED3D_TADDRESS_WRAP;
|
|
|
|
gl_tex->sampler_desc.address_v = WINED3D_TADDRESS_WRAP;
|
|
|
|
gl_tex->sampler_desc.address_w = WINED3D_TADDRESS_WRAP;
|
|
|
|
memset(gl_tex->sampler_desc.border_color, 0, sizeof(gl_tex->sampler_desc.border_color));
|
|
|
|
gl_tex->sampler_desc.mag_filter = WINED3D_TEXF_LINEAR;
|
|
|
|
gl_tex->sampler_desc.min_filter = WINED3D_TEXF_POINT; /* GL_NEAREST_MIPMAP_LINEAR */
|
|
|
|
gl_tex->sampler_desc.mip_filter = WINED3D_TEXF_LINEAR; /* GL_NEAREST_MIPMAP_LINEAR */
|
|
|
|
gl_tex->sampler_desc.lod_bias = 0.0f;
|
|
|
|
gl_tex->sampler_desc.min_lod = -1000.0f;
|
|
|
|
gl_tex->sampler_desc.max_lod = 1000.0f;
|
|
|
|
gl_tex->sampler_desc.max_anisotropy = 1;
|
|
|
|
gl_tex->sampler_desc.compare = FALSE;
|
|
|
|
gl_tex->sampler_desc.comparison_func = WINED3D_CMP_LESSEQUAL;
|
2013-11-21 00:10:18 +01:00
|
|
|
if (context->gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
|
2015-01-15 17:19:04 +01:00
|
|
|
gl_tex->sampler_desc.srgb_decode = TRUE;
|
2013-11-21 00:10:18 +01:00
|
|
|
else
|
2015-01-15 17:19:04 +01:00
|
|
|
gl_tex->sampler_desc.srgb_decode = srgb;
|
|
|
|
gl_tex->base_level = 0;
|
2013-11-21 00:10:18 +01:00
|
|
|
wined3d_texture_set_dirty(texture);
|
|
|
|
|
2013-11-20 10:04:33 +01:00
|
|
|
context_bind_texture(context, target, gl_tex->name);
|
2013-11-21 00:10:18 +01:00
|
|
|
|
|
|
|
if (texture->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP)
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
|
|
|
|
checkGLcall("glTexParameteri(target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE)");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For a new texture we have to set the texture levels after binding the
|
|
|
|
* texture. Beware that texture rectangles do not support mipmapping, but
|
|
|
|
* set the maxmiplevel if we're relying on the partial
|
|
|
|
* GL_ARB_texture_non_power_of_two emulation with texture rectangles.
|
|
|
|
* (I.e., do not care about cond_np2 here, just look for
|
|
|
|
* GL_TEXTURE_RECTANGLE_ARB.) */
|
|
|
|
if (target != GL_TEXTURE_RECTANGLE_ARB)
|
|
|
|
{
|
|
|
|
TRACE("Setting GL_TEXTURE_MAX_LEVEL to %u.\n", texture->level_count - 1);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, texture->level_count - 1);
|
|
|
|
checkGLcall("glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, texture->level_count)");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target == GL_TEXTURE_CUBE_MAP_ARB)
|
|
|
|
{
|
|
|
|
/* Cubemaps are always set to clamp, regardless of the sampler state. */
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (texture->flags & WINED3D_TEXTURE_COND_NP2)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2013-11-21 00:10:18 +01:00
|
|
|
/* Conditinal non power of two textures use a different clamping
|
|
|
|
* default. If we're using the GL_WINE_normalized_texrect partial
|
|
|
|
* driver emulation, we're dealing with a GL_TEXTURE_2D texture which
|
|
|
|
* has the address mode set to repeat - something that prevents us
|
|
|
|
* from hitting the accelerated codepath. Thus manually set the GL
|
|
|
|
* state. The same applies to filtering. Even if the texture has only
|
|
|
|
* one mip level, the default LINEAR_MIPMAP_LINEAR filter causes a SW
|
|
|
|
* fallback on macos. */
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
checkGLcall("glTexParameteri");
|
2015-01-15 17:19:04 +01:00
|
|
|
gl_tex->sampler_desc.address_u = WINED3D_TADDRESS_CLAMP;
|
|
|
|
gl_tex->sampler_desc.address_v = WINED3D_TADDRESS_CLAMP;
|
|
|
|
gl_tex->sampler_desc.mag_filter = WINED3D_TEXF_POINT;
|
|
|
|
gl_tex->sampler_desc.min_filter = WINED3D_TEXF_POINT;
|
|
|
|
gl_tex->sampler_desc.mip_filter = WINED3D_TEXF_NONE;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
2015-10-21 00:24:05 +02:00
|
|
|
|
2015-10-22 17:37:50 +02:00
|
|
|
if (gl_info->supported[WINED3D_GL_LEGACY_CONTEXT] && gl_info->supported[ARB_DEPTH_TEXTURE])
|
|
|
|
{
|
2015-10-21 00:24:05 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
|
2015-10-22 17:37:50 +02:00
|
|
|
checkGLcall("glTexParameteri(GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY)");
|
|
|
|
}
|
2016-03-23 21:19:10 +01:00
|
|
|
|
|
|
|
if (!is_identity_fixup(fixup) && can_use_texture_swizzle(gl_info, format))
|
|
|
|
{
|
|
|
|
static const GLenum swizzle_source[] =
|
|
|
|
{
|
|
|
|
GL_ZERO, /* CHANNEL_SOURCE_ZERO */
|
|
|
|
GL_ONE, /* CHANNEL_SOURCE_ONE */
|
|
|
|
GL_RED, /* CHANNEL_SOURCE_X */
|
|
|
|
GL_GREEN, /* CHANNEL_SOURCE_Y */
|
|
|
|
GL_BLUE, /* CHANNEL_SOURCE_Z */
|
|
|
|
GL_ALPHA, /* CHANNEL_SOURCE_W */
|
|
|
|
};
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
GLint x, y, z, w;
|
|
|
|
}
|
|
|
|
swizzle;
|
|
|
|
|
|
|
|
swizzle.x = swizzle_source[fixup.x_source];
|
|
|
|
swizzle.y = swizzle_source[fixup.y_source];
|
|
|
|
swizzle.z = swizzle_source[fixup.z_source];
|
|
|
|
swizzle.w = swizzle_source[fixup.w_source];
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, &swizzle.x);
|
|
|
|
checkGLcall("glTexParameteriv(GL_TEXTURE_SWIZZLE_RGBA)");
|
|
|
|
}
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2013-11-21 00:10:20 +01:00
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
void wined3d_texture_bind_and_dirtify(struct wined3d_texture *texture,
|
|
|
|
struct wined3d_context *context, BOOL srgb)
|
|
|
|
{
|
|
|
|
DWORD active_sampler;
|
|
|
|
|
|
|
|
/* 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 marking already applied sampler states dirty again. */
|
|
|
|
active_sampler = context->rev_tex_unit_map[context->active_texture];
|
|
|
|
if (active_sampler != WINED3D_UNMAPPED_STAGE)
|
|
|
|
context_invalidate_state(context, STATE_SAMPLER(active_sampler));
|
2015-08-18 11:24:09 +02:00
|
|
|
/* FIXME: Ideally we'd only do this when touching a binding that's used by
|
|
|
|
* a shader. */
|
|
|
|
context_invalidate_state(context, STATE_SHADER_RESOURCE_BINDING);
|
2013-11-21 00:10:20 +01:00
|
|
|
|
|
|
|
wined3d_texture_bind(texture, context, srgb);
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller (state handler). */
|
2015-01-15 17:19:05 +01:00
|
|
|
/* This function relies on the correct texture being bound and loaded. */
|
|
|
|
void wined3d_texture_apply_sampler_desc(struct wined3d_texture *texture,
|
2016-02-12 11:06:09 +01:00
|
|
|
const struct wined3d_sampler_desc *sampler_desc, const struct wined3d_context *context)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2016-02-12 11:06:09 +01:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2011-03-28 21:58:42 +02:00
|
|
|
GLenum target = texture->target;
|
2011-03-18 19:10:58 +01:00
|
|
|
struct gl_texture *gl_tex;
|
|
|
|
DWORD state;
|
|
|
|
|
2016-02-12 11:06:09 +01:00
|
|
|
TRACE("texture %p, sampler_desc %p, context %p.\n", texture, sampler_desc, context);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2013-10-09 12:38:00 +02:00
|
|
|
gl_tex = wined3d_texture_get_gl_texture(texture, texture->flags & WINED3D_TEXTURE_IS_SRGB);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2015-01-15 17:19:05 +01:00
|
|
|
state = sampler_desc->address_u;
|
|
|
|
if (state != gl_tex->sampler_desc.address_u)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2015-01-15 17:19:05 +01:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_S,
|
|
|
|
gl_info->wrap_lookup[state - WINED3D_TADDRESS_WRAP]);
|
2015-01-15 17:19:04 +01:00
|
|
|
gl_tex->sampler_desc.address_u = state;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2015-01-15 17:19:05 +01:00
|
|
|
state = sampler_desc->address_v;
|
|
|
|
if (state != gl_tex->sampler_desc.address_v)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2015-01-15 17:19:05 +01:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_T,
|
|
|
|
gl_info->wrap_lookup[state - WINED3D_TADDRESS_WRAP]);
|
2015-01-15 17:19:04 +01:00
|
|
|
gl_tex->sampler_desc.address_v = state;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2015-01-15 17:19:05 +01:00
|
|
|
state = sampler_desc->address_w;
|
|
|
|
if (state != gl_tex->sampler_desc.address_w)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2015-01-15 17:19:05 +01:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_R,
|
|
|
|
gl_info->wrap_lookup[state - WINED3D_TADDRESS_WRAP]);
|
2015-01-15 17:19:04 +01:00
|
|
|
gl_tex->sampler_desc.address_w = state;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2015-01-15 17:19:05 +01:00
|
|
|
if (memcmp(gl_tex->sampler_desc.border_color, sampler_desc->border_color,
|
|
|
|
sizeof(gl_tex->sampler_desc.border_color)))
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2015-01-15 17:19:05 +01:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, &sampler_desc->border_color[0]);
|
|
|
|
memcpy(gl_tex->sampler_desc.border_color, sampler_desc->border_color,
|
|
|
|
sizeof(gl_tex->sampler_desc.border_color));
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2015-01-15 17:19:05 +01:00
|
|
|
state = sampler_desc->mag_filter;
|
|
|
|
if (state != gl_tex->sampler_desc.mag_filter)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2015-01-15 17:19:05 +01:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAG_FILTER, wined3d_gl_mag_filter(state));
|
2015-01-15 17:19:04 +01:00
|
|
|
gl_tex->sampler_desc.mag_filter = state;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2015-01-15 17:19:05 +01:00
|
|
|
if (sampler_desc->min_filter != gl_tex->sampler_desc.min_filter
|
|
|
|
|| sampler_desc->mip_filter != gl_tex->sampler_desc.mip_filter)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2015-01-15 17:19:05 +01:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
|
|
|
|
wined3d_gl_min_mip_filter(sampler_desc->min_filter, sampler_desc->mip_filter));
|
|
|
|
gl_tex->sampler_desc.min_filter = sampler_desc->min_filter;
|
|
|
|
gl_tex->sampler_desc.mip_filter = sampler_desc->mip_filter;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2015-01-15 17:19:05 +01:00
|
|
|
state = sampler_desc->max_anisotropy;
|
|
|
|
if (state != gl_tex->sampler_desc.max_anisotropy)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
|
2015-01-15 17:19:05 +01:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, state);
|
2011-03-18 19:10:58 +01:00
|
|
|
else
|
|
|
|
WARN("Anisotropic filtering not supported.\n");
|
2015-01-15 17:19:05 +01:00
|
|
|
gl_tex->sampler_desc.max_anisotropy = state;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2016-02-12 11:06:09 +01:00
|
|
|
if (!sampler_desc->srgb_decode != !gl_tex->sampler_desc.srgb_decode
|
|
|
|
&& (context->d3d_info->wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL)
|
|
|
|
&& gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_SRGB_DECODE_EXT,
|
2015-01-15 17:19:05 +01:00
|
|
|
sampler_desc->srgb_decode ? GL_DECODE_EXT : GL_SKIP_DECODE_EXT);
|
|
|
|
gl_tex->sampler_desc.srgb_decode = sampler_desc->srgb_decode;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2015-01-15 17:19:05 +01:00
|
|
|
if (!sampler_desc->compare != !gl_tex->sampler_desc.compare)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2015-01-15 17:19:05 +01:00
|
|
|
if (sampler_desc->compare)
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
|
2011-03-18 19:10:58 +01:00
|
|
|
else
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
|
2015-01-15 17:19:05 +01:00
|
|
|
gl_tex->sampler_desc.compare = sampler_desc->compare;
|
|
|
|
}
|
|
|
|
|
|
|
|
checkGLcall("Texture parameter application");
|
|
|
|
|
|
|
|
if (gl_info->supported[EXT_TEXTURE_LOD_BIAS])
|
|
|
|
{
|
|
|
|
gl_info->gl_ops.gl.p_glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
|
|
|
|
GL_TEXTURE_LOD_BIAS_EXT, sampler_desc->lod_bias);
|
|
|
|
checkGLcall("glTexEnvf(GL_TEXTURE_LOD_BIAS_EXT, ...)");
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
ULONG CDECL wined3d_texture_incref(struct wined3d_texture *texture)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2014-08-20 13:20:00 +02:00
|
|
|
ULONG refcount;
|
|
|
|
|
|
|
|
TRACE("texture %p, swapchain %p.\n", texture, texture->swapchain);
|
|
|
|
|
|
|
|
if (texture->swapchain)
|
|
|
|
return wined3d_swapchain_incref(texture->swapchain);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2014-08-20 13:20:00 +02:00
|
|
|
refcount = InterlockedIncrement(&texture->resource.ref);
|
2011-03-18 19:10:58 +01:00
|
|
|
TRACE("%p increasing refcount to %u.\n", texture, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2016-07-08 10:59:03 +02:00
|
|
|
static void wined3d_texture_cleanup_sync(struct wined3d_texture *texture)
|
|
|
|
{
|
|
|
|
wined3d_texture_sub_resources_destroyed(texture);
|
|
|
|
resource_cleanup(&texture->resource);
|
2016-07-08 10:59:05 +02:00
|
|
|
wined3d_resource_wait_idle(&texture->resource);
|
2016-07-08 10:59:03 +02:00
|
|
|
wined3d_texture_cleanup(texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wined3d_texture_destroy_object(void *object)
|
|
|
|
{
|
|
|
|
wined3d_texture_cleanup(object);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
ULONG CDECL wined3d_texture_decref(struct wined3d_texture *texture)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2014-08-20 13:20:00 +02:00
|
|
|
ULONG refcount;
|
|
|
|
|
|
|
|
TRACE("texture %p, swapchain %p.\n", texture, texture->swapchain);
|
|
|
|
|
|
|
|
if (texture->swapchain)
|
|
|
|
return wined3d_swapchain_decref(texture->swapchain);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2014-08-20 13:20:00 +02:00
|
|
|
refcount = InterlockedDecrement(&texture->resource.ref);
|
2011-03-18 19:10:58 +01:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", texture, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
2016-07-08 10:59:03 +02:00
|
|
|
wined3d_texture_sub_resources_destroyed(texture);
|
2011-03-18 19:10:58 +01:00
|
|
|
texture->resource.parent_ops->wined3d_object_destroyed(texture->resource.parent);
|
2016-07-08 10:59:03 +02:00
|
|
|
resource_cleanup(&texture->resource);
|
|
|
|
wined3d_cs_emit_destroy_object(texture->resource.device->cs, wined3d_texture_destroy_object, texture);
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2011-06-17 21:00:01 +02:00
|
|
|
struct wined3d_resource * CDECL wined3d_texture_get_resource(struct wined3d_texture *texture)
|
|
|
|
{
|
|
|
|
TRACE("texture %p.\n", texture);
|
|
|
|
|
|
|
|
return &texture->resource;
|
|
|
|
}
|
|
|
|
|
2015-04-09 22:48:11 +02:00
|
|
|
static BOOL color_key_equal(const struct wined3d_color_key *c1, struct wined3d_color_key *c2)
|
|
|
|
{
|
|
|
|
return c1->color_space_low_value == c2->color_space_low_value
|
|
|
|
&& c1->color_space_high_value == c2->color_space_high_value;
|
|
|
|
}
|
|
|
|
|
2013-11-22 10:45:02 +01:00
|
|
|
/* Context activation is done by the caller */
|
|
|
|
void wined3d_texture_load(struct wined3d_texture *texture,
|
2013-11-22 10:45:04 +01:00
|
|
|
struct wined3d_context *context, BOOL srgb)
|
2013-11-22 10:45:02 +01:00
|
|
|
{
|
|
|
|
UINT sub_count = texture->level_count * texture->layer_count;
|
2015-04-10 12:05:54 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = context->d3d_info;
|
2013-11-22 10:45:02 +01:00
|
|
|
DWORD flag;
|
|
|
|
UINT i;
|
|
|
|
|
2015-09-18 15:54:41 +02:00
|
|
|
TRACE("texture %p, context %p, srgb %#x.\n", texture, context, srgb);
|
2013-11-22 10:45:02 +01:00
|
|
|
|
2016-02-08 00:04:37 +01:00
|
|
|
if (!needs_separate_srgb_gl_texture(context))
|
2013-11-22 10:45:04 +01:00
|
|
|
srgb = FALSE;
|
2013-11-22 10:45:02 +01:00
|
|
|
|
2013-11-22 10:45:04 +01:00
|
|
|
if (srgb)
|
2013-11-22 10:45:02 +01:00
|
|
|
flag = WINED3D_TEXTURE_SRGB_VALID;
|
|
|
|
else
|
|
|
|
flag = WINED3D_TEXTURE_RGB_VALID;
|
|
|
|
|
2015-04-10 12:05:54 +02:00
|
|
|
if (!d3d_info->shader_color_key
|
|
|
|
&& (!(texture->async.flags & WINED3D_TEXTURE_ASYNC_COLOR_KEY)
|
2015-04-09 22:48:11 +02:00
|
|
|
!= !(texture->async.color_key_flags & WINED3D_CKEY_SRC_BLT)
|
|
|
|
|| (texture->async.flags & WINED3D_TEXTURE_ASYNC_COLOR_KEY
|
2015-04-10 12:05:54 +02:00
|
|
|
&& !color_key_equal(&texture->async.gl_color_key, &texture->async.src_blt_color_key))))
|
2015-02-17 23:09:36 +01:00
|
|
|
{
|
|
|
|
unsigned int sub_count = texture->level_count * texture->layer_count;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
TRACE("Reloading because of color key value change.\n");
|
|
|
|
for (i = 0; i < sub_count; i++)
|
2016-03-15 16:55:15 +01:00
|
|
|
{
|
2016-08-01 12:49:07 +02:00
|
|
|
if (!wined3d_texture_load_location(texture, i, context, texture->resource.map_binding))
|
2016-04-18 19:06:27 +02:00
|
|
|
ERR("Failed to load location %s.\n", wined3d_debug_location(texture->resource.map_binding));
|
2016-03-15 16:55:15 +01:00
|
|
|
else
|
2016-04-18 19:06:27 +02:00
|
|
|
wined3d_texture_invalidate_location(texture, i, ~texture->resource.map_binding);
|
2016-03-15 16:55:15 +01:00
|
|
|
}
|
2015-02-17 23:09:36 +01:00
|
|
|
|
2015-04-09 22:48:11 +02:00
|
|
|
texture->async.gl_color_key = texture->async.src_blt_color_key;
|
2015-02-17 23:09:36 +01:00
|
|
|
}
|
|
|
|
|
2013-11-22 10:45:02 +01:00
|
|
|
if (texture->flags & flag)
|
|
|
|
{
|
|
|
|
TRACE("Texture %p not dirty, nothing to do.\n", texture);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reload the surfaces if the texture is marked dirty. */
|
|
|
|
for (i = 0; i < sub_count; ++i)
|
|
|
|
{
|
2016-08-01 12:49:07 +02:00
|
|
|
if (!wined3d_texture_load_location(texture, i, context,
|
2016-04-06 19:12:07 +02:00
|
|
|
srgb ? WINED3D_LOCATION_TEXTURE_SRGB : WINED3D_LOCATION_TEXTURE_RGB))
|
|
|
|
ERR("Failed to load location (srgb %#x).\n", srgb);
|
2013-11-22 10:45:02 +01:00
|
|
|
}
|
|
|
|
texture->flags |= flag;
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
void * CDECL wined3d_texture_get_parent(const struct wined3d_texture *texture)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2011-03-18 19:10:59 +01:00
|
|
|
TRACE("texture %p.\n", texture);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
return texture->resource.parent;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2016-03-11 16:01:43 +01:00
|
|
|
static BOOL wined3d_texture_check_box_dimensions(const struct wined3d_texture *texture,
|
|
|
|
unsigned int level, const struct wined3d_box *box)
|
|
|
|
{
|
|
|
|
if (box->left >= box->right
|
|
|
|
|| box->top >= box->bottom
|
|
|
|
|| box->front >= box->back)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (box->right > wined3d_texture_get_level_width(texture, level)
|
|
|
|
|| box->bottom > wined3d_texture_get_level_height(texture, level)
|
|
|
|
|| box->back > wined3d_texture_get_level_depth(texture, level))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-02-12 11:06:07 +01:00
|
|
|
void CDECL wined3d_texture_get_pitch(const struct wined3d_texture *texture,
|
2016-02-09 21:29:58 +01:00
|
|
|
unsigned int level, unsigned int *row_pitch, unsigned int *slice_pitch)
|
|
|
|
{
|
|
|
|
const struct wined3d_resource *resource = &texture->resource;
|
2016-03-09 16:21:54 +01:00
|
|
|
unsigned int width = wined3d_texture_get_level_width(texture, level);
|
|
|
|
unsigned int height = wined3d_texture_get_level_height(texture, level);
|
2016-02-09 21:29:58 +01:00
|
|
|
|
|
|
|
if (texture->row_pitch)
|
|
|
|
{
|
|
|
|
*row_pitch = texture->row_pitch;
|
|
|
|
*slice_pitch = texture->slice_pitch;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wined3d_format_calculate_pitch(resource->format, resource->device->surface_alignment,
|
|
|
|
width, height, row_pitch, slice_pitch);
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
DWORD CDECL wined3d_texture_set_lod(struct wined3d_texture *texture, DWORD lod)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
DWORD old = texture->lod;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
TRACE("texture %p, lod %u.\n", texture, lod);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
/* The d3d9:texture test shows that SetLOD is ignored on non-managed
|
|
|
|
* textures. The call always returns 0, and GetLOD always returns 0. */
|
2012-01-17 21:13:37 +01:00
|
|
|
if (texture->resource.pool != WINED3D_POOL_MANAGED)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
TRACE("Ignoring SetLOD on %s texture, returning 0.\n", debug_d3dpool(texture->resource.pool));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
if (lod >= texture->level_count)
|
|
|
|
lod = texture->level_count - 1;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
if (texture->lod != lod)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2016-08-10 18:44:47 +02:00
|
|
|
wined3d_resource_wait_idle(&texture->resource);
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->lod = lod;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2015-01-15 17:19:04 +01:00
|
|
|
texture->texture_rgb.base_level = ~0u;
|
|
|
|
texture->texture_srgb.base_level = ~0u;
|
2012-04-25 21:24:22 +02:00
|
|
|
if (texture->resource.bind_count)
|
2011-06-05 22:48:51 +02:00
|
|
|
device_invalidate_state(texture->resource.device, STATE_SAMPLER(texture->sampler));
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
DWORD CDECL wined3d_texture_get_lod(const struct wined3d_texture *texture)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
TRACE("texture %p, returning %u.\n", texture, texture->lod);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
return texture->lod;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
DWORD CDECL wined3d_texture_get_level_count(const struct wined3d_texture *texture)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
TRACE("texture %p, returning %u.\n", texture, texture->level_count);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
return texture->level_count;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
HRESULT CDECL wined3d_texture_set_autogen_filter_type(struct wined3d_texture *texture,
|
2012-01-12 21:43:12 +01:00
|
|
|
enum wined3d_texture_filter_type filter_type)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2011-04-20 22:09:23 +02:00
|
|
|
FIXME("texture %p, filter_type %s stub!\n", texture, debug_d3dtexturefiltertype(filter_type));
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
if (!(texture->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP))
|
|
|
|
{
|
|
|
|
WARN("Texture doesn't have AUTOGENMIPMAP usage.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->filter_type = filter_type;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-12 21:43:12 +01:00
|
|
|
enum wined3d_texture_filter_type CDECL wined3d_texture_get_autogen_filter_type(const struct wined3d_texture *texture)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2011-03-18 19:10:59 +01:00
|
|
|
TRACE("texture %p.\n", texture);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
return texture->filter_type;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2014-01-09 12:17:00 +01:00
|
|
|
HRESULT CDECL wined3d_texture_set_color_key(struct wined3d_texture *texture,
|
|
|
|
DWORD flags, const struct wined3d_color_key *color_key)
|
|
|
|
{
|
2015-04-09 22:48:11 +02:00
|
|
|
struct wined3d_device *device = texture->resource.device;
|
2015-08-23 21:59:35 +02:00
|
|
|
static const DWORD all_flags = WINED3D_CKEY_DST_BLT | WINED3D_CKEY_DST_OVERLAY
|
|
|
|
| WINED3D_CKEY_SRC_BLT | WINED3D_CKEY_SRC_OVERLAY;
|
2015-04-09 22:48:11 +02:00
|
|
|
|
2014-01-09 12:17:00 +01:00
|
|
|
TRACE("texture %p, flags %#x, color_key %p.\n", texture, flags, color_key);
|
|
|
|
|
2015-04-09 22:48:11 +02:00
|
|
|
if (flags & ~all_flags)
|
2014-01-09 12:17:00 +01:00
|
|
|
{
|
2015-04-09 22:48:11 +02:00
|
|
|
WARN("Invalid flags passed, returning WINED3DERR_INVALIDCALL.\n");
|
2014-01-09 12:17:00 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2015-04-09 22:48:11 +02:00
|
|
|
wined3d_cs_emit_set_color_key(device->cs, texture, flags, color_key);
|
2014-01-09 12:17:00 +01:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-29 09:11:54 +02:00
|
|
|
HRESULT CDECL wined3d_texture_update_desc(struct wined3d_texture *texture, UINT width, UINT height,
|
|
|
|
enum wined3d_format_id format_id, enum wined3d_multisample_type multisample_type,
|
|
|
|
UINT multisample_quality, void *mem, UINT pitch)
|
|
|
|
{
|
|
|
|
struct wined3d_device *device = texture->resource.device;
|
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
const struct wined3d_format *format = wined3d_get_format(gl_info, format_id);
|
|
|
|
UINT resource_size = wined3d_format_calculate_size(format, device->surface_alignment, width, height, 1);
|
2016-03-28 18:58:01 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2014-09-29 09:11:54 +02:00
|
|
|
struct wined3d_surface *surface;
|
2016-03-14 17:02:18 +01:00
|
|
|
DWORD valid_location = 0;
|
|
|
|
BOOL create_dib = FALSE;
|
2014-09-29 09:11:54 +02:00
|
|
|
|
|
|
|
TRACE("texture %p, width %u, height %u, format %s, multisample_type %#x, multisample_quality %u, "
|
|
|
|
"mem %p, pitch %u.\n",
|
2016-02-26 08:00:06 +01:00
|
|
|
texture, width, height, debug_d3dformat(format_id), multisample_type, multisample_quality, mem, pitch);
|
2014-09-29 09:11:54 +02:00
|
|
|
|
|
|
|
if (!resource_size)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
if (texture->level_count * texture->layer_count > 1)
|
|
|
|
{
|
|
|
|
WARN("Texture has multiple sub-resources, not supported.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2016-01-27 00:06:24 +01:00
|
|
|
if (texture->resource.type == WINED3D_RTYPE_TEXTURE_3D)
|
2014-09-29 09:11:54 +02:00
|
|
|
{
|
2016-01-27 00:06:24 +01:00
|
|
|
WARN("Not supported on 3D textures.\n");
|
2014-09-29 09:11:54 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2015-02-18 19:21:00 +01:00
|
|
|
}
|
|
|
|
|
2016-04-13 12:18:48 +02:00
|
|
|
if (texture->resource.map_count)
|
|
|
|
{
|
|
|
|
WARN("Texture is mapped.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2015-02-18 19:21:00 +01:00
|
|
|
/* We have no way of supporting a pitch that is not a multiple of the pixel
|
|
|
|
* byte width short of uploading the texture row-by-row.
|
|
|
|
* Fortunately that's not an issue since D3D9Ex doesn't allow a custom pitch
|
|
|
|
* for user-memory textures (it always expects packed data) while DirectDraw
|
|
|
|
* requires a 4-byte aligned pitch and doesn't support texture formats
|
|
|
|
* larger than 4 bytes per pixel nor any format using 3 bytes per pixel.
|
|
|
|
* This check is here to verify that the assumption holds. */
|
|
|
|
if (pitch % texture->resource.format->byte_count)
|
|
|
|
{
|
|
|
|
WARN("Pitch unsupported, not a multiple of the texture format byte width.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2014-09-29 09:11:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (device->d3d_initialized)
|
2016-08-10 18:44:45 +02:00
|
|
|
wined3d_cs_emit_unload_resource(device->cs, &texture->resource);
|
2014-09-29 09:11:54 +02:00
|
|
|
|
2016-04-13 12:18:48 +02:00
|
|
|
sub_resource = &texture->sub_resources[0];
|
|
|
|
surface = sub_resource->u.surface;
|
2016-04-14 19:32:46 +02:00
|
|
|
if (surface->dc)
|
|
|
|
{
|
|
|
|
wined3d_surface_destroy_dc(surface);
|
2016-03-14 17:02:18 +01:00
|
|
|
create_dib = TRUE;
|
|
|
|
}
|
|
|
|
|
2016-04-20 19:29:12 +02:00
|
|
|
wined3d_resource_free_sysmem(&texture->resource);
|
2014-09-29 09:11:54 +02:00
|
|
|
|
2016-02-09 21:29:58 +01:00
|
|
|
if ((texture->row_pitch = pitch))
|
|
|
|
texture->slice_pitch = height * pitch;
|
|
|
|
else
|
|
|
|
/* User memory surfaces don't have the regular surface alignment. */
|
|
|
|
wined3d_format_calculate_pitch(format, 1, width, height,
|
|
|
|
&texture->row_pitch, &texture->slice_pitch);
|
2016-02-08 18:32:04 +01:00
|
|
|
|
2016-03-14 17:02:18 +01:00
|
|
|
texture->resource.format = format;
|
|
|
|
texture->resource.multisample_type = multisample_type;
|
|
|
|
texture->resource.multisample_quality = multisample_quality;
|
|
|
|
texture->resource.width = width;
|
|
|
|
texture->resource.height = height;
|
2016-04-20 19:29:12 +02:00
|
|
|
texture->resource.size = texture->slice_pitch;
|
|
|
|
sub_resource->size = texture->slice_pitch;
|
2016-04-20 19:29:11 +02:00
|
|
|
sub_resource->locations = WINED3D_LOCATION_DISCARDED;
|
2016-03-14 17:02:18 +01:00
|
|
|
|
2016-02-18 17:30:01 +01:00
|
|
|
if (((width & (width - 1)) || (height & (height - 1))) && !gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO]
|
|
|
|
&& !gl_info->supported[ARB_TEXTURE_RECTANGLE] && !gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT])
|
2016-03-14 17:02:18 +01:00
|
|
|
{
|
2016-02-18 17:30:01 +01:00
|
|
|
texture->flags |= WINED3D_TEXTURE_COND_NP2_EMULATED;
|
2016-04-13 19:09:54 +02:00
|
|
|
texture->pow2_width = texture->pow2_height = 1;
|
|
|
|
while (texture->pow2_width < width)
|
|
|
|
texture->pow2_width <<= 1;
|
|
|
|
while (texture->pow2_height < height)
|
|
|
|
texture->pow2_height <<= 1;
|
2016-03-14 17:02:18 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
texture->flags &= ~WINED3D_TEXTURE_COND_NP2_EMULATED;
|
2016-04-13 19:09:54 +02:00
|
|
|
texture->pow2_width = width;
|
|
|
|
texture->pow2_height = height;
|
2016-03-14 17:02:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((texture->user_memory = mem))
|
|
|
|
{
|
2016-04-18 19:06:27 +02:00
|
|
|
texture->resource.map_binding = WINED3D_LOCATION_USER_MEMORY;
|
2016-03-14 17:02:18 +01:00
|
|
|
valid_location = WINED3D_LOCATION_USER_MEMORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-17 14:01:55 +02:00
|
|
|
wined3d_texture_prepare_location(texture, 0, NULL, WINED3D_LOCATION_SYSMEM);
|
2016-03-14 17:02:18 +01:00
|
|
|
valid_location = WINED3D_LOCATION_SYSMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The format might be changed to a format that needs conversion.
|
|
|
|
* If the surface didn't use PBOs previously but could now, don't
|
|
|
|
* change it - whatever made us not use PBOs might come back, e.g.
|
|
|
|
* color keys. */
|
2016-04-18 19:06:27 +02:00
|
|
|
if (texture->resource.map_binding == WINED3D_LOCATION_BUFFER && !wined3d_texture_use_pbo(texture, gl_info))
|
|
|
|
texture->resource.map_binding = WINED3D_LOCATION_SYSMEM;
|
2016-02-18 17:30:01 +01:00
|
|
|
|
2016-03-29 16:45:36 +02:00
|
|
|
wined3d_texture_validate_location(texture, 0, valid_location);
|
2016-04-20 19:29:11 +02:00
|
|
|
wined3d_texture_invalidate_location(texture, 0, ~valid_location);
|
2016-03-14 17:02:18 +01:00
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
if (create_dib)
|
|
|
|
wined3d_surface_create_dc(surface);
|
|
|
|
|
2016-03-14 17:02:18 +01:00
|
|
|
return WINED3D_OK;
|
2014-09-29 09:11:54 +02:00
|
|
|
}
|
|
|
|
|
2016-03-02 19:24:20 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2016-04-18 19:06:32 +02:00
|
|
|
static void wined3d_texture_prepare_buffer_object(struct wined3d_texture *texture,
|
2016-03-02 19:24:20 +01:00
|
|
|
unsigned int sub_resource_idx, const struct wined3d_gl_info *gl_info)
|
|
|
|
{
|
2016-04-20 19:29:12 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2016-03-02 19:24:20 +01:00
|
|
|
|
2016-04-20 19:29:12 +02:00
|
|
|
sub_resource = &texture->sub_resources[sub_resource_idx];
|
|
|
|
if (sub_resource->buffer_object)
|
2016-03-02 19:24:20 +01:00
|
|
|
return;
|
|
|
|
|
2016-04-20 19:29:12 +02:00
|
|
|
GL_EXTCALL(glGenBuffers(1, &sub_resource->buffer_object));
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, sub_resource->buffer_object));
|
|
|
|
GL_EXTCALL(glBufferData(GL_PIXEL_UNPACK_BUFFER, sub_resource->size, NULL, GL_STREAM_DRAW));
|
2016-03-02 19:24:20 +01:00
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
|
|
|
|
checkGLcall("Create buffer object");
|
|
|
|
|
|
|
|
TRACE("Created buffer object %u for texture %p, sub-resource %u.\n",
|
2016-04-20 19:29:12 +02:00
|
|
|
sub_resource->buffer_object, texture, sub_resource_idx);
|
2016-03-02 19:24:20 +01:00
|
|
|
}
|
|
|
|
|
2016-03-22 11:26:59 +01:00
|
|
|
static void wined3d_texture_force_reload(struct wined3d_texture *texture)
|
|
|
|
{
|
|
|
|
unsigned int sub_count = texture->level_count * texture->layer_count;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
texture->flags &= ~(WINED3D_TEXTURE_RGB_ALLOCATED | WINED3D_TEXTURE_SRGB_ALLOCATED
|
|
|
|
| WINED3D_TEXTURE_CONVERTED);
|
|
|
|
texture->async.flags &= ~WINED3D_TEXTURE_ASYNC_COLOR_KEY;
|
|
|
|
for (i = 0; i < sub_count; ++i)
|
|
|
|
{
|
2016-03-30 21:30:19 +02:00
|
|
|
wined3d_texture_invalidate_location(texture, i,
|
2016-03-22 11:26:59 +01:00
|
|
|
WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-08 08:47:19 +02:00
|
|
|
void wined3d_texture_prepare_texture(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
|
|
|
|
{
|
2014-10-08 08:47:20 +02:00
|
|
|
DWORD alloc_flag = srgb ? WINED3D_TEXTURE_SRGB_ALLOCATED : WINED3D_TEXTURE_RGB_ALLOCATED;
|
2015-04-10 12:05:54 +02:00
|
|
|
const struct wined3d_d3d_info *d3d_info = context->d3d_info;
|
2014-10-08 08:47:20 +02:00
|
|
|
|
2015-04-10 12:05:54 +02:00
|
|
|
if (!d3d_info->shader_color_key
|
|
|
|
&& !(texture->async.flags & WINED3D_TEXTURE_ASYNC_COLOR_KEY)
|
2015-04-09 22:48:11 +02:00
|
|
|
!= !(texture->async.color_key_flags & WINED3D_CKEY_SRC_BLT))
|
2015-04-10 12:05:54 +02:00
|
|
|
{
|
2015-02-17 23:09:36 +01:00
|
|
|
wined3d_texture_force_reload(texture);
|
|
|
|
|
2015-04-10 12:05:54 +02:00
|
|
|
if (texture->async.color_key_flags & WINED3D_CKEY_SRC_BLT)
|
|
|
|
texture->async.flags |= WINED3D_TEXTURE_ASYNC_COLOR_KEY;
|
|
|
|
}
|
|
|
|
|
2014-10-08 08:47:20 +02:00
|
|
|
if (texture->flags & alloc_flag)
|
|
|
|
return;
|
|
|
|
|
2014-10-08 08:47:19 +02:00
|
|
|
texture->texture_ops->texture_prepare_texture(texture, context, srgb);
|
2014-10-08 08:47:20 +02:00
|
|
|
texture->flags |= alloc_flag;
|
|
|
|
}
|
|
|
|
|
2016-04-18 19:06:32 +02:00
|
|
|
static void wined3d_texture_prepare_rb(struct wined3d_texture *texture,
|
2016-04-18 19:06:26 +02:00
|
|
|
const struct wined3d_gl_info *gl_info, BOOL multisample)
|
|
|
|
{
|
|
|
|
const struct wined3d_format *format = texture->resource.format;
|
|
|
|
|
|
|
|
if (multisample)
|
|
|
|
{
|
|
|
|
DWORD samples;
|
|
|
|
|
|
|
|
if (texture->rb_multisample)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* TODO: NVIDIA expose their Coverage Sample Anti-Aliasing (CSAA)
|
|
|
|
* feature through type == MULTISAMPLE_XX and quality != 0. This could
|
|
|
|
* be mapped to GL_NV_framebuffer_multisample_coverage.
|
|
|
|
*
|
|
|
|
* AMD have a similar feature called Enhanced Quality Anti-Aliasing
|
|
|
|
* (EQAA), but it does not have an equivalent OpenGL extension. */
|
|
|
|
|
|
|
|
/* We advertise as many WINED3D_MULTISAMPLE_NON_MASKABLE quality
|
|
|
|
* levels as the count of advertised multisample types for the texture
|
|
|
|
* format. */
|
|
|
|
if (texture->resource.multisample_type == WINED3D_MULTISAMPLE_NON_MASKABLE)
|
|
|
|
{
|
|
|
|
unsigned int i, count = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(format->multisample_types) * 8; ++i)
|
|
|
|
{
|
|
|
|
if (format->multisample_types & 1u << i)
|
|
|
|
{
|
|
|
|
if (texture->resource.multisample_quality == count++)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
samples = i + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
samples = texture->resource.multisample_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_info->fbo_ops.glGenRenderbuffers(1, &texture->rb_multisample);
|
|
|
|
gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, texture->rb_multisample);
|
|
|
|
gl_info->fbo_ops.glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples,
|
|
|
|
format->glInternal, texture->resource.width, texture->resource.height);
|
|
|
|
checkGLcall("glRenderbufferStorageMultisample()");
|
|
|
|
TRACE("Created multisample rb %u.\n", texture->rb_multisample);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (texture->rb_resolved)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gl_info->fbo_ops.glGenRenderbuffers(1, &texture->rb_resolved);
|
|
|
|
gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, texture->rb_resolved);
|
|
|
|
gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, format->glInternal,
|
|
|
|
texture->resource.width, texture->resource.height);
|
|
|
|
checkGLcall("glRenderbufferStorage()");
|
|
|
|
TRACE("Created resolved rb %u.\n", texture->rb_resolved);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-18 19:06:32 +02:00
|
|
|
/* Context activation is done by the caller. Context may be NULL in
|
|
|
|
* WINED3D_NO3D mode. */
|
|
|
|
BOOL wined3d_texture_prepare_location(struct wined3d_texture *texture, unsigned int sub_resource_idx,
|
|
|
|
struct wined3d_context *context, DWORD location)
|
|
|
|
{
|
|
|
|
switch (location)
|
|
|
|
{
|
|
|
|
case WINED3D_LOCATION_SYSMEM:
|
2016-04-20 19:29:12 +02:00
|
|
|
if (texture->resource.heap_memory)
|
2016-04-18 19:06:32 +02:00
|
|
|
return TRUE;
|
|
|
|
|
2016-04-20 19:29:12 +02:00
|
|
|
if (!wined3d_resource_allocate_sysmem(&texture->resource))
|
2016-04-18 19:06:32 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to allocate system memory.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_USER_MEMORY:
|
|
|
|
if (!texture->user_memory)
|
|
|
|
ERR("Map binding is set to WINED3D_LOCATION_USER_MEMORY but surface->user_memory is NULL.\n");
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_BUFFER:
|
|
|
|
wined3d_texture_prepare_buffer_object(texture, sub_resource_idx, context->gl_info);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_TEXTURE_RGB:
|
|
|
|
wined3d_texture_prepare_texture(texture, context, FALSE);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_TEXTURE_SRGB:
|
|
|
|
wined3d_texture_prepare_texture(texture, context, TRUE);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_DRAWABLE:
|
|
|
|
if (!texture->swapchain)
|
|
|
|
ERR("Texture %p does not have a drawable.\n", texture);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_RB_MULTISAMPLE:
|
|
|
|
wined3d_texture_prepare_rb(texture, context->gl_info, TRUE);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_RB_RESOLVED:
|
|
|
|
wined3d_texture_prepare_rb(texture, context->gl_info, FALSE);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR("Invalid location %s.\n", wined3d_debug_location(location));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
void CDECL wined3d_texture_generate_mipmaps(struct wined3d_texture *texture)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
/* TODO: Implement filters using GL_SGI_generate_mipmaps. */
|
2011-03-18 19:10:59 +01:00
|
|
|
FIXME("texture %p stub!\n", texture);
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2016-04-04 18:43:02 +02:00
|
|
|
struct wined3d_texture_sub_resource *wined3d_texture_get_sub_resource(struct wined3d_texture *texture,
|
|
|
|
unsigned int sub_resource_idx)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
UINT sub_count = texture->level_count * texture->layer_count;
|
2011-03-18 19:10:59 +01:00
|
|
|
|
|
|
|
TRACE("texture %p, sub_resource_idx %u.\n", texture, sub_resource_idx);
|
|
|
|
|
|
|
|
if (sub_resource_idx >= sub_count)
|
|
|
|
{
|
|
|
|
WARN("sub_resource_idx %u >= sub_count %u.\n", sub_resource_idx, sub_count);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2016-04-04 18:43:02 +02:00
|
|
|
return &texture->sub_resources[sub_resource_idx];
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
HRESULT CDECL wined3d_texture_add_dirty_region(struct wined3d_texture *texture,
|
2011-12-06 22:57:47 +01:00
|
|
|
UINT layer, const struct wined3d_box *dirty_region)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2016-03-15 16:55:15 +01:00
|
|
|
struct wined3d_context *context;
|
|
|
|
unsigned int sub_resource_idx;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2016-02-03 22:23:00 +01:00
|
|
|
TRACE("texture %p, layer %u, dirty_region %s.\n", texture, layer, debug_box(dirty_region));
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2016-04-18 19:06:27 +02:00
|
|
|
if (layer >= texture->layer_count)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2016-04-18 19:06:27 +02:00
|
|
|
WARN("Invalid layer %u specified.\n", layer);
|
2011-03-18 19:10:58 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2016-04-18 19:06:27 +02:00
|
|
|
sub_resource_idx = layer * texture->level_count;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2016-03-15 16:55:15 +01:00
|
|
|
if (dirty_region)
|
|
|
|
FIXME("Ignoring dirty_region %s.\n", debug_box(dirty_region));
|
|
|
|
|
|
|
|
context = context_acquire(texture->resource.device, NULL);
|
2016-08-01 12:49:07 +02:00
|
|
|
if (!wined3d_texture_load_location(texture, sub_resource_idx, context, texture->resource.map_binding))
|
2016-03-15 16:55:15 +01:00
|
|
|
{
|
2016-04-18 19:06:27 +02:00
|
|
|
ERR("Failed to load location %s.\n", wined3d_debug_location(texture->resource.map_binding));
|
2016-03-15 16:55:15 +01:00
|
|
|
context_release(context);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2016-04-18 19:06:27 +02:00
|
|
|
wined3d_texture_invalidate_location(texture, sub_resource_idx, ~texture->resource.map_binding);
|
2016-03-15 16:55:15 +01:00
|
|
|
context_release(context);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2016-08-01 12:49:03 +02:00
|
|
|
void wined3d_texture_upload_data(struct wined3d_texture *texture, unsigned int sub_resource_idx,
|
2016-07-29 12:34:32 +02:00
|
|
|
const struct wined3d_context *context, const struct wined3d_const_bo_address *data,
|
|
|
|
unsigned int row_pitch, unsigned int slice_pitch)
|
2015-01-05 13:24:58 +01:00
|
|
|
{
|
2016-07-29 12:34:32 +02:00
|
|
|
texture->texture_ops->texture_upload_data(texture, sub_resource_idx,
|
|
|
|
context, data, row_pitch, slice_pitch);
|
2015-01-05 13:24:58 +01:00
|
|
|
}
|
|
|
|
|
2016-04-07 19:38:02 +02:00
|
|
|
static void texture2d_upload_data(struct wined3d_texture *texture, unsigned int sub_resource_idx,
|
2016-07-29 12:34:31 +02:00
|
|
|
const struct wined3d_context *context, const struct wined3d_const_bo_address *data,
|
|
|
|
unsigned int row_pitch, unsigned int slice_pitch)
|
2015-01-05 13:24:58 +01:00
|
|
|
{
|
|
|
|
static const POINT dst_point = {0, 0};
|
2016-04-07 19:38:02 +02:00
|
|
|
unsigned int texture_level;
|
2015-01-05 13:24:58 +01:00
|
|
|
RECT src_rect;
|
|
|
|
|
2016-04-07 19:38:02 +02:00
|
|
|
texture_level = sub_resource_idx % texture->level_count;
|
|
|
|
SetRect(&src_rect, 0, 0, wined3d_texture_get_level_width(texture, texture_level),
|
|
|
|
wined3d_texture_get_level_height(texture, texture_level));
|
2015-01-05 13:24:58 +01:00
|
|
|
|
2016-04-07 19:38:02 +02:00
|
|
|
wined3d_surface_upload_data(texture->sub_resources[sub_resource_idx].u.surface, context->gl_info,
|
2016-07-29 12:34:31 +02:00
|
|
|
texture->resource.format, &src_rect, row_pitch, &dst_point, FALSE, data);
|
2015-01-05 13:24:58 +01:00
|
|
|
}
|
|
|
|
|
2016-03-11 16:01:43 +01:00
|
|
|
static BOOL texture2d_load_location(struct wined3d_texture *texture, unsigned int sub_resource_idx,
|
|
|
|
struct wined3d_context *context, DWORD location)
|
|
|
|
{
|
|
|
|
return SUCCEEDED(surface_load_location(texture->sub_resources[sub_resource_idx].u.surface, context, location));
|
|
|
|
}
|
|
|
|
|
2014-10-08 08:47:19 +02:00
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
static void texture2d_prepare_texture(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
|
|
|
|
{
|
|
|
|
const struct wined3d_format *format = texture->resource.format;
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
const struct wined3d_color_key_conversion *conversion;
|
|
|
|
GLenum internal;
|
|
|
|
|
2015-09-18 15:54:41 +02:00
|
|
|
TRACE("texture %p, context %p, format %s.\n", texture, context, debug_d3dformat(format->id));
|
2014-10-08 08:47:19 +02:00
|
|
|
|
|
|
|
if (format->convert)
|
|
|
|
{
|
2014-10-08 08:47:22 +02:00
|
|
|
texture->flags |= WINED3D_TEXTURE_CONVERTED;
|
2014-10-08 08:47:19 +02:00
|
|
|
}
|
|
|
|
else if ((conversion = wined3d_format_get_color_key_conversion(texture, TRUE)))
|
|
|
|
{
|
2014-10-08 08:47:22 +02:00
|
|
|
texture->flags |= WINED3D_TEXTURE_CONVERTED;
|
2014-10-08 08:47:19 +02:00
|
|
|
format = wined3d_get_format(gl_info, conversion->dst_format);
|
|
|
|
TRACE("Using format %s for color key conversion.\n", debug_d3dformat(format->id));
|
|
|
|
}
|
|
|
|
|
|
|
|
wined3d_texture_bind_and_dirtify(texture, context, srgb);
|
|
|
|
|
|
|
|
if (srgb)
|
|
|
|
internal = format->glGammaInternal;
|
|
|
|
else if (texture->resource.usage & WINED3DUSAGE_RENDERTARGET
|
|
|
|
&& wined3d_resource_is_offscreen(&texture->resource))
|
|
|
|
internal = format->rtInternal;
|
|
|
|
else
|
|
|
|
internal = format->glInternal;
|
|
|
|
|
|
|
|
if (!internal)
|
|
|
|
FIXME("No GL internal format for format %s.\n", debug_d3dformat(format->id));
|
|
|
|
|
|
|
|
TRACE("internal %#x, format %#x, type %#x.\n", internal, format->glFormat, format->glType);
|
|
|
|
|
2016-05-26 00:08:27 +02:00
|
|
|
if (wined3d_texture_use_immutable_storage(texture, gl_info))
|
|
|
|
wined3d_texture_allocate_gl_immutable_storage(texture, internal, gl_info);
|
|
|
|
else
|
|
|
|
wined3d_texture_allocate_gl_mutable_storage(texture, internal, format, gl_info);
|
2014-10-08 08:47:19 +02:00
|
|
|
}
|
|
|
|
|
2016-03-02 19:24:13 +01:00
|
|
|
static void texture2d_cleanup_sub_resources(struct wined3d_texture *texture)
|
|
|
|
{
|
|
|
|
unsigned int sub_count = texture->level_count * texture->layer_count;
|
2016-04-21 17:05:04 +02:00
|
|
|
struct wined3d_device *device = texture->resource.device;
|
2016-04-20 19:29:14 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2016-04-21 17:05:04 +02:00
|
|
|
struct wined3d_renderbuffer_entry *entry, *entry2;
|
|
|
|
const struct wined3d_gl_info *gl_info = NULL;
|
|
|
|
struct wined3d_context *context = NULL;
|
|
|
|
struct wined3d_surface *overlay, *cur;
|
2016-03-02 19:24:13 +01:00
|
|
|
struct wined3d_surface *surface;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sub_count; ++i)
|
|
|
|
{
|
2016-04-20 19:29:14 +02:00
|
|
|
sub_resource = &texture->sub_resources[i];
|
2016-04-21 17:05:04 +02:00
|
|
|
if (!(surface = sub_resource->u.surface))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
TRACE("surface %p.\n", surface);
|
|
|
|
|
|
|
|
if (!context && !list_empty(&surface->renderbuffers))
|
2016-03-02 19:24:13 +01:00
|
|
|
{
|
2016-04-21 17:05:04 +02:00
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
gl_info = context->gl_info;
|
|
|
|
}
|
2016-03-02 19:24:13 +01:00
|
|
|
|
2016-04-21 17:05:04 +02:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &surface->renderbuffers, struct wined3d_renderbuffer_entry, entry)
|
|
|
|
{
|
|
|
|
TRACE("Deleting renderbuffer %u.\n", entry->id);
|
|
|
|
context_gl_resource_released(device, entry->id, TRUE);
|
|
|
|
gl_info->fbo_ops.glDeleteRenderbuffers(1, &entry->id);
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry);
|
2016-03-02 19:24:13 +01:00
|
|
|
}
|
2016-04-21 17:05:04 +02:00
|
|
|
|
|
|
|
if (surface->dc)
|
|
|
|
wined3d_surface_destroy_dc(surface);
|
|
|
|
|
|
|
|
if (surface->overlay_dest)
|
|
|
|
list_remove(&surface->overlay_entry);
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(overlay, cur, &surface->overlays, struct wined3d_surface, overlay_entry)
|
|
|
|
{
|
|
|
|
list_remove(&overlay->overlay_entry);
|
|
|
|
overlay->overlay_dest = NULL;
|
|
|
|
}
|
2016-03-02 19:24:13 +01:00
|
|
|
}
|
2016-04-21 17:05:04 +02:00
|
|
|
if (context)
|
|
|
|
context_release(context);
|
2016-03-02 19:24:13 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, texture->sub_resources[0].u.surface);
|
|
|
|
}
|
|
|
|
|
2013-11-21 00:10:21 +01:00
|
|
|
static const struct wined3d_texture_ops texture2d_ops =
|
|
|
|
{
|
2016-04-07 19:38:02 +02:00
|
|
|
texture2d_upload_data,
|
2016-03-11 16:01:43 +01:00
|
|
|
texture2d_load_location,
|
2014-10-08 08:47:19 +02:00
|
|
|
texture2d_prepare_texture,
|
2016-03-02 19:24:13 +01:00
|
|
|
texture2d_cleanup_sub_resources,
|
2013-11-21 00:10:21 +01:00
|
|
|
};
|
|
|
|
|
2016-04-20 19:29:13 +02:00
|
|
|
struct wined3d_texture * __cdecl wined3d_texture_from_resource(struct wined3d_resource *resource)
|
|
|
|
{
|
|
|
|
return texture_from_resource(resource);
|
|
|
|
}
|
|
|
|
|
2014-08-21 09:55:52 +02:00
|
|
|
static ULONG texture_resource_incref(struct wined3d_resource *resource)
|
|
|
|
{
|
2016-04-20 19:29:13 +02:00
|
|
|
return wined3d_texture_incref(texture_from_resource(resource));
|
2014-08-21 09:55:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG texture_resource_decref(struct wined3d_resource *resource)
|
|
|
|
{
|
2016-04-20 19:29:13 +02:00
|
|
|
return wined3d_texture_decref(texture_from_resource(resource));
|
2014-08-21 09:55:52 +02:00
|
|
|
}
|
|
|
|
|
2016-08-10 18:44:48 +02:00
|
|
|
static void texture_resource_preload(struct wined3d_resource *resource)
|
|
|
|
{
|
|
|
|
struct wined3d_texture *texture = texture_from_resource(resource);
|
|
|
|
struct wined3d_context *context;
|
|
|
|
|
|
|
|
context = context_acquire(resource->device, NULL);
|
|
|
|
wined3d_texture_load(texture, context, texture->flags & WINED3D_TEXTURE_IS_SRGB);
|
|
|
|
context_release(context);
|
|
|
|
}
|
|
|
|
|
2013-11-21 00:10:21 +01:00
|
|
|
static void wined3d_texture_unload(struct wined3d_resource *resource)
|
2011-02-28 08:05:39 +01:00
|
|
|
{
|
2016-04-20 19:29:13 +02:00
|
|
|
struct wined3d_texture *texture = texture_from_resource(resource);
|
2011-03-28 21:58:42 +02:00
|
|
|
UINT sub_count = texture->level_count * texture->layer_count;
|
2016-04-18 19:06:28 +02:00
|
|
|
struct wined3d_device *device = resource->device;
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
struct wined3d_context *context;
|
2011-03-18 19:10:58 +01:00
|
|
|
UINT i;
|
2011-02-28 08:05:39 +01:00
|
|
|
|
|
|
|
TRACE("texture %p.\n", texture);
|
|
|
|
|
2016-04-18 19:06:28 +02:00
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
for (i = 0; i < sub_count; ++i)
|
2011-02-28 08:05:39 +01:00
|
|
|
{
|
2016-04-18 19:06:28 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[i];
|
2016-03-02 19:24:21 +01:00
|
|
|
|
2016-04-18 19:06:28 +02:00
|
|
|
if (resource->pool != WINED3D_POOL_DEFAULT
|
2016-08-01 12:49:07 +02:00
|
|
|
&& wined3d_texture_load_location(texture, i, context, resource->map_binding))
|
2016-03-02 19:24:21 +01:00
|
|
|
{
|
2016-04-18 19:06:28 +02:00
|
|
|
wined3d_texture_invalidate_location(texture, i, ~resource->map_binding);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We should only get here on device reset/teardown for implicit
|
|
|
|
* resources. */
|
|
|
|
if (resource->pool != WINED3D_POOL_DEFAULT || resource->type != WINED3D_RTYPE_TEXTURE_2D)
|
|
|
|
ERR("Discarding %s %p sub-resource %u in the %s pool.\n", debug_d3dresourcetype(resource->type),
|
|
|
|
resource, i, debug_d3dpool(resource->pool));
|
|
|
|
wined3d_texture_validate_location(texture, i, WINED3D_LOCATION_DISCARDED);
|
|
|
|
wined3d_texture_invalidate_location(texture, i, ~WINED3D_LOCATION_DISCARDED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sub_resource->buffer_object)
|
2016-03-02 19:24:21 +01:00
|
|
|
wined3d_texture_remove_buffer_object(texture, i, context->gl_info);
|
2016-04-18 19:06:28 +02:00
|
|
|
|
|
|
|
if (resource->type == WINED3D_RTYPE_TEXTURE_2D)
|
|
|
|
{
|
|
|
|
struct wined3d_surface *surface = sub_resource->u.surface;
|
|
|
|
struct wined3d_renderbuffer_entry *entry, *entry2;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &surface->renderbuffers, struct wined3d_renderbuffer_entry, entry)
|
|
|
|
{
|
|
|
|
context_gl_resource_released(device, entry->id, TRUE);
|
|
|
|
gl_info->fbo_ops.glDeleteRenderbuffers(1, &entry->id);
|
|
|
|
list_remove(&entry->entry);
|
|
|
|
HeapFree(GetProcessHeap(), 0, entry);
|
|
|
|
}
|
|
|
|
list_init(&surface->renderbuffers);
|
|
|
|
surface->current_renderbuffer = NULL;
|
2016-03-02 19:24:21 +01:00
|
|
|
}
|
2011-02-28 08:05:39 +01:00
|
|
|
}
|
2016-04-18 19:06:28 +02:00
|
|
|
|
|
|
|
context_release(context);
|
2011-02-28 08:05:39 +01:00
|
|
|
|
2014-10-22 21:56:38 +02:00
|
|
|
wined3d_texture_force_reload(texture);
|
2013-11-21 00:10:21 +01:00
|
|
|
wined3d_texture_unload_gl_texture(texture);
|
2011-02-28 08:05:39 +01:00
|
|
|
}
|
|
|
|
|
2016-03-11 16:01:43 +01:00
|
|
|
static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx,
|
2015-11-02 17:12:25 +01:00
|
|
|
struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags)
|
|
|
|
{
|
2016-03-11 16:01:43 +01:00
|
|
|
const struct wined3d_format *format = resource->format;
|
2016-04-04 18:43:02 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2016-03-11 16:01:43 +01:00
|
|
|
struct wined3d_device *device = resource->device;
|
|
|
|
unsigned int fmt_flags = resource->format_flags;
|
|
|
|
const struct wined3d_gl_info *gl_info = NULL;
|
|
|
|
struct wined3d_context *context = NULL;
|
|
|
|
struct wined3d_texture *texture;
|
2016-03-31 22:48:54 +02:00
|
|
|
struct wined3d_bo_address data;
|
2016-03-11 16:01:43 +01:00
|
|
|
unsigned int texture_level;
|
|
|
|
BYTE *base_memory;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
TRACE("resource %p, sub_resource_idx %u, map_desc %p, box %s, flags %#x.\n",
|
|
|
|
resource, sub_resource_idx, map_desc, debug_box(box), flags);
|
2015-11-02 17:12:25 +01:00
|
|
|
|
2016-04-20 19:29:13 +02:00
|
|
|
texture = texture_from_resource(resource);
|
2016-03-11 16:01:43 +01:00
|
|
|
if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
|
2015-11-02 17:12:25 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2016-03-11 16:01:43 +01:00
|
|
|
texture_level = sub_resource_idx % texture->level_count;
|
|
|
|
if (box && !wined3d_texture_check_box_dimensions(texture, texture_level, box))
|
|
|
|
{
|
|
|
|
WARN("Map box is invalid.\n");
|
|
|
|
if (resource->type != WINED3D_RTYPE_TEXTURE_2D)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((fmt_flags & WINED3DFMT_FLAG_BLOCKS) && box
|
|
|
|
&& !wined3d_texture_check_block_align(texture, texture_level, box))
|
|
|
|
{
|
|
|
|
WARN("Map box %s is misaligned for %ux%u blocks.\n",
|
|
|
|
debug_box(box), format->block_width, format->block_height);
|
|
|
|
if (resource->type != WINED3D_RTYPE_TEXTURE_2D || resource->pool == WINED3D_POOL_DEFAULT)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(resource->access_flags & WINED3D_RESOURCE_ACCESS_CPU))
|
|
|
|
{
|
|
|
|
WARN("Trying to map unmappable texture.\n");
|
|
|
|
if (resource->type != WINED3D_RTYPE_TEXTURE_2D)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2016-04-13 12:18:48 +02:00
|
|
|
if (texture->flags & WINED3D_TEXTURE_DC_IN_USE)
|
|
|
|
{
|
|
|
|
WARN("DC is in use.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2016-04-10 18:09:27 +02:00
|
|
|
if (sub_resource->map_count)
|
2016-03-11 16:01:43 +01:00
|
|
|
{
|
|
|
|
WARN("Sub-resource is already mapped.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = wined3d_resource_sanitize_map_flags(resource, flags);
|
|
|
|
|
|
|
|
if (device->d3d_initialized)
|
|
|
|
{
|
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
gl_info = context->gl_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & WINED3D_MAP_DISCARD)
|
|
|
|
{
|
|
|
|
TRACE("WINED3D_MAP_DISCARD flag passed, marking %s as up to date.\n",
|
2016-04-18 19:06:27 +02:00
|
|
|
wined3d_debug_location(texture->resource.map_binding));
|
2016-04-18 19:06:32 +02:00
|
|
|
if ((ret = wined3d_texture_prepare_location(texture, sub_resource_idx,
|
|
|
|
context, texture->resource.map_binding)))
|
2016-04-18 19:06:27 +02:00
|
|
|
wined3d_texture_validate_location(texture, sub_resource_idx, texture->resource.map_binding);
|
2016-03-11 16:01:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (resource->usage & WINED3DUSAGE_DYNAMIC)
|
|
|
|
WARN_(d3d_perf)("Mapping a dynamic texture without WINED3D_MAP_DISCARD.\n");
|
2016-08-01 12:49:07 +02:00
|
|
|
ret = wined3d_texture_load_location(texture, sub_resource_idx, context, texture->resource.map_binding);
|
2016-03-11 16:01:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
ERR("Failed to prepare location.\n");
|
|
|
|
context_release(context);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(flags & (WINED3D_MAP_NO_DIRTY_UPDATE | WINED3D_MAP_READONLY)))
|
2016-04-18 19:06:27 +02:00
|
|
|
wined3d_texture_invalidate_location(texture, sub_resource_idx, ~texture->resource.map_binding);
|
2016-03-11 16:01:43 +01:00
|
|
|
|
2016-04-18 19:06:27 +02:00
|
|
|
wined3d_texture_get_memory(texture, sub_resource_idx, &data, texture->resource.map_binding);
|
2016-04-20 19:29:12 +02:00
|
|
|
base_memory = wined3d_texture_map_bo_address(&data, sub_resource->size,
|
2016-04-14 19:32:45 +02:00
|
|
|
gl_info, GL_PIXEL_UNPACK_BUFFER, flags);
|
|
|
|
TRACE("Base memory pointer %p.\n", base_memory);
|
2016-03-11 16:01:43 +01:00
|
|
|
|
|
|
|
if (context)
|
|
|
|
context_release(context);
|
|
|
|
|
|
|
|
if (fmt_flags & WINED3DFMT_FLAG_BROKEN_PITCH)
|
|
|
|
{
|
|
|
|
map_desc->row_pitch = wined3d_texture_get_level_width(texture, texture_level) * format->byte_count;
|
|
|
|
map_desc->slice_pitch = wined3d_texture_get_level_height(texture, texture_level) * map_desc->row_pitch;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wined3d_texture_get_pitch(texture, texture_level, &map_desc->row_pitch, &map_desc->slice_pitch);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!box)
|
|
|
|
{
|
|
|
|
map_desc->data = base_memory;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((fmt_flags & (WINED3DFMT_FLAG_BLOCKS | WINED3DFMT_FLAG_BROKEN_PITCH)) == WINED3DFMT_FLAG_BLOCKS)
|
|
|
|
{
|
|
|
|
/* Compressed textures are block based, so calculate the offset of
|
|
|
|
* the block that contains the top-left pixel of the mapped box. */
|
|
|
|
map_desc->data = base_memory
|
|
|
|
+ (box->front * map_desc->slice_pitch)
|
|
|
|
+ ((box->top / format->block_height) * map_desc->row_pitch)
|
|
|
|
+ ((box->left / format->block_width) * format->block_byte_count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
map_desc->data = base_memory
|
|
|
|
+ (box->front * map_desc->slice_pitch)
|
|
|
|
+ (box->top * map_desc->row_pitch)
|
|
|
|
+ (box->left * format->byte_count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (texture->swapchain && texture->swapchain->front_buffer == texture)
|
|
|
|
{
|
|
|
|
RECT *r = &texture->swapchain->front_buffer_update;
|
|
|
|
|
|
|
|
if (!box)
|
|
|
|
SetRect(r, 0, 0, resource->width, resource->height);
|
|
|
|
else
|
|
|
|
SetRect(r, box->left, box->top, box->right, box->bottom);
|
|
|
|
TRACE("Mapped front buffer %s.\n", wine_dbgstr_rect(r));
|
|
|
|
}
|
|
|
|
|
2016-04-10 18:09:26 +02:00
|
|
|
++resource->map_count;
|
2016-04-10 18:09:27 +02:00
|
|
|
++sub_resource->map_count;
|
2016-03-11 16:01:43 +01:00
|
|
|
|
|
|
|
TRACE("Returning memory %p, row pitch %u, slice pitch %u.\n",
|
|
|
|
map_desc->data, map_desc->row_pitch, map_desc->slice_pitch);
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
2015-11-02 17:12:25 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 16:21:58 +01:00
|
|
|
static HRESULT texture_resource_sub_resource_unmap(struct wined3d_resource *resource, unsigned int sub_resource_idx)
|
2015-11-02 17:12:26 +01:00
|
|
|
{
|
2016-04-04 18:43:02 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2016-04-14 19:32:45 +02:00
|
|
|
struct wined3d_device *device = resource->device;
|
|
|
|
const struct wined3d_gl_info *gl_info = NULL;
|
|
|
|
struct wined3d_context *context = NULL;
|
2016-03-09 16:21:58 +01:00
|
|
|
struct wined3d_texture *texture;
|
2016-04-14 19:32:45 +02:00
|
|
|
struct wined3d_bo_address data;
|
2015-11-02 17:12:26 +01:00
|
|
|
|
2016-03-09 16:21:58 +01:00
|
|
|
TRACE("resource %p, sub_resource_idx %u.\n", resource, sub_resource_idx);
|
|
|
|
|
2016-04-20 19:29:13 +02:00
|
|
|
texture = texture_from_resource(resource);
|
2016-03-09 16:21:58 +01:00
|
|
|
if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
|
2015-11-02 17:12:26 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2016-04-10 18:09:27 +02:00
|
|
|
if (!sub_resource->map_count)
|
2016-03-09 16:21:58 +01:00
|
|
|
{
|
|
|
|
WARN("Trying to unmap unmapped sub-resource.\n");
|
2016-04-13 12:18:48 +02:00
|
|
|
if (texture->flags & WINED3D_TEXTURE_DC_IN_USE)
|
|
|
|
return WINED3D_OK;
|
2016-03-09 16:21:58 +01:00
|
|
|
return WINEDDERR_NOTLOCKED;
|
|
|
|
}
|
|
|
|
|
2016-04-14 19:32:45 +02:00
|
|
|
if (device->d3d_initialized)
|
2016-03-09 16:21:58 +01:00
|
|
|
{
|
2016-04-14 19:32:45 +02:00
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
gl_info = context->gl_info;
|
|
|
|
}
|
2016-03-09 16:21:58 +01:00
|
|
|
|
2016-04-18 19:06:27 +02:00
|
|
|
wined3d_texture_get_memory(texture, sub_resource_idx, &data, texture->resource.map_binding);
|
2016-04-14 19:32:45 +02:00
|
|
|
wined3d_texture_unmap_bo_address(&data, gl_info, GL_PIXEL_UNPACK_BUFFER);
|
2016-03-09 16:21:58 +01:00
|
|
|
|
2016-04-14 19:32:45 +02:00
|
|
|
if (context)
|
|
|
|
context_release(context);
|
2016-03-09 16:21:58 +01:00
|
|
|
|
|
|
|
if (texture->swapchain && texture->swapchain->front_buffer == texture)
|
|
|
|
{
|
2016-04-14 19:32:45 +02:00
|
|
|
if (!(sub_resource->locations & (WINED3D_LOCATION_DRAWABLE | WINED3D_LOCATION_TEXTURE_RGB)))
|
2016-03-09 16:21:58 +01:00
|
|
|
texture->swapchain->swapchain_ops->swapchain_frontbuffer_updated(texture->swapchain);
|
|
|
|
}
|
|
|
|
else if (resource->format_flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL))
|
|
|
|
{
|
|
|
|
FIXME("Depth / stencil buffer locking is not implemented.\n");
|
|
|
|
}
|
|
|
|
|
2016-04-10 18:09:27 +02:00
|
|
|
--sub_resource->map_count;
|
2016-04-18 19:06:27 +02:00
|
|
|
if (!--resource->map_count && texture->update_map_binding)
|
|
|
|
wined3d_texture_update_map_binding(texture);
|
2016-03-09 16:21:58 +01:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
2015-11-02 17:12:26 +01:00
|
|
|
}
|
|
|
|
|
2016-03-11 16:01:43 +01:00
|
|
|
static const struct wined3d_resource_ops texture_resource_ops =
|
2011-01-03 18:51:41 +01:00
|
|
|
{
|
2014-08-21 09:55:52 +02:00
|
|
|
texture_resource_incref,
|
|
|
|
texture_resource_decref,
|
2016-08-10 18:44:48 +02:00
|
|
|
texture_resource_preload,
|
2013-11-21 00:10:21 +01:00
|
|
|
wined3d_texture_unload,
|
2016-03-11 16:01:43 +01:00
|
|
|
texture_resource_sub_resource_map,
|
2016-03-09 16:21:58 +01:00
|
|
|
texture_resource_sub_resource_unmap,
|
2011-03-18 19:10:58 +01:00
|
|
|
};
|
2009-02-17 00:25:51 +01:00
|
|
|
|
2013-06-05 11:06:11 +02:00
|
|
|
static HRESULT texture_init(struct wined3d_texture *texture, const struct wined3d_resource_desc *desc,
|
2016-02-16 17:17:25 +01:00
|
|
|
unsigned int layer_count, unsigned int level_count, DWORD flags, struct wined3d_device *device,
|
|
|
|
void *parent, const struct wined3d_parent_ops *parent_ops)
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
2016-03-02 19:24:13 +01:00
|
|
|
struct wined3d_device_parent *device_parent = device->device_parent;
|
2009-09-16 08:37:21 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2016-03-02 19:24:13 +01:00
|
|
|
struct wined3d_surface *surfaces;
|
2009-09-16 08:37:21 +02:00
|
|
|
UINT pow2_width, pow2_height;
|
2016-02-03 22:22:59 +01:00
|
|
|
unsigned int i, j;
|
2009-09-16 08:37:21 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2016-04-25 12:25:30 +02:00
|
|
|
if (!(desc->usage & WINED3DUSAGE_LEGACY_CUBEMAP) && layer_count > 1
|
|
|
|
&& !gl_info->supported[EXT_TEXTURE_ARRAY])
|
|
|
|
{
|
|
|
|
WARN("OpenGL implementation does not support array textures.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2016-04-25 12:25:29 +02:00
|
|
|
|
2009-09-16 08:37:21 +02:00
|
|
|
/* TODO: It should only be possible to create textures for formats
|
|
|
|
* that are reported as supported. */
|
2013-06-05 11:06:11 +02:00
|
|
|
if (WINED3DFMT_UNKNOWN >= desc->format)
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
|
|
|
WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2016-04-14 19:32:48 +02:00
|
|
|
if (desc->usage & WINED3DUSAGE_DYNAMIC && desc->pool == WINED3D_POOL_MANAGED)
|
|
|
|
FIXME("Trying to create a managed texture with dynamic usage.\n");
|
|
|
|
if (!(desc->usage & (WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_RENDERTARGET | WINED3DUSAGE_DEPTHSTENCIL))
|
|
|
|
&& (flags & WINED3D_TEXTURE_CREATE_MAPPABLE))
|
|
|
|
WARN("Creating a mappable texture in the default pool that doesn't specify dynamic usage.\n");
|
|
|
|
if (desc->usage & WINED3DUSAGE_RENDERTARGET && desc->pool != WINED3D_POOL_DEFAULT)
|
|
|
|
FIXME("Trying to create a render target that isn't in the default pool.\n");
|
|
|
|
|
2016-03-21 17:40:11 +01:00
|
|
|
pow2_width = desc->width;
|
|
|
|
pow2_height = desc->height;
|
|
|
|
if (((desc->width & (desc->width - 1)) || (desc->height & (desc->height - 1)))
|
|
|
|
&& !gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
2016-03-21 17:40:11 +01:00
|
|
|
/* level_count == 0 returns an error as well. */
|
2016-04-25 12:25:29 +02:00
|
|
|
if (level_count != 1 || layer_count != 1)
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
2016-03-21 17:40:11 +01:00
|
|
|
if (desc->pool != WINED3D_POOL_SCRATCH)
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
2016-04-25 12:25:29 +02:00
|
|
|
WARN("Attempted to create a mipmapped/cube/array NPOT texture without unconditional NPOT support.\n");
|
2016-03-21 17:40:11 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2009-09-16 08:37:21 +02:00
|
|
|
}
|
2016-03-21 17:40:11 +01:00
|
|
|
|
2016-04-25 12:25:29 +02:00
|
|
|
WARN("Creating a scratch mipmapped/cube/array NPOT texture despite lack of HW support.\n");
|
2016-03-21 17:40:11 +01:00
|
|
|
}
|
|
|
|
texture->flags |= WINED3D_TEXTURE_COND_NP2;
|
|
|
|
|
|
|
|
if (!gl_info->supported[ARB_TEXTURE_RECTANGLE] && !gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT])
|
|
|
|
{
|
2016-03-21 17:40:12 +01:00
|
|
|
const struct wined3d_format *format = wined3d_get_format(gl_info, desc->format);
|
|
|
|
|
|
|
|
/* TODO: Add support for non-power-of-two compressed textures. */
|
|
|
|
if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D]
|
|
|
|
& (WINED3DFMT_FLAG_COMPRESSED | WINED3DFMT_FLAG_HEIGHT_SCALE))
|
|
|
|
{
|
|
|
|
FIXME("Compressed or height scaled non-power-of-two (%ux%u) textures are not supported.\n",
|
|
|
|
desc->width, desc->height);
|
|
|
|
return WINED3DERR_NOTAVAILABLE;
|
|
|
|
}
|
|
|
|
|
2016-03-21 17:40:11 +01:00
|
|
|
/* Find the nearest pow2 match. */
|
|
|
|
pow2_width = pow2_height = 1;
|
|
|
|
while (pow2_width < desc->width)
|
|
|
|
pow2_width <<= 1;
|
|
|
|
while (pow2_height < desc->height)
|
|
|
|
pow2_height <<= 1;
|
|
|
|
texture->flags |= WINED3D_TEXTURE_COND_NP2_EMULATED;
|
2009-09-16 08:37:21 +02:00
|
|
|
}
|
|
|
|
}
|
2016-04-13 19:09:54 +02:00
|
|
|
texture->pow2_width = pow2_width;
|
|
|
|
texture->pow2_height = pow2_height;
|
2009-09-16 08:37:21 +02:00
|
|
|
|
2016-03-21 17:40:11 +01:00
|
|
|
if ((pow2_width > gl_info->limits.texture_size || pow2_height > gl_info->limits.texture_size)
|
|
|
|
&& (desc->usage & WINED3DUSAGE_TEXTURE))
|
|
|
|
{
|
|
|
|
/* One of four options:
|
|
|
|
* 1: Do the same as we do with NPOT and scale the texture. (Any
|
|
|
|
* texture ops would require the texture to be scaled which is
|
|
|
|
* potentially slow.)
|
|
|
|
* 2: Set the texture to the maximum size (bad idea).
|
|
|
|
* 3: WARN and return WINED3DERR_NOTAVAILABLE.
|
|
|
|
* 4: Create the surface, but allow it to be used only for DirectDraw
|
|
|
|
* Blts. Some apps (e.g. Swat 3) create textures with a height of
|
|
|
|
* 16 and a width > 3000 and blt 16x16 letter areas from them to
|
|
|
|
* the render target. */
|
|
|
|
if (desc->pool == WINED3D_POOL_DEFAULT || desc->pool == WINED3D_POOL_MANAGED)
|
|
|
|
{
|
|
|
|
WARN("Dimensions (%ux%u) exceed the maximum texture size.\n", pow2_width, pow2_height);
|
|
|
|
return WINED3DERR_NOTAVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We should never use this surface in combination with OpenGL. */
|
|
|
|
TRACE("Creating an oversized (%ux%u) surface.\n", pow2_width, pow2_height);
|
|
|
|
}
|
|
|
|
|
2009-09-16 08:37:21 +02:00
|
|
|
/* Calculate levels for mip mapping. */
|
2013-06-05 11:06:11 +02:00
|
|
|
if (desc->usage & WINED3DUSAGE_AUTOGENMIPMAP)
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
|
|
|
if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
|
|
|
|
{
|
|
|
|
WARN("No mipmap generation support, returning WINED3DERR_INVALIDCALL.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2016-02-03 22:22:59 +01:00
|
|
|
if (level_count != 1)
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
2015-01-05 13:24:57 +01:00
|
|
|
WARN("WINED3DUSAGE_AUTOGENMIPMAP is set, and level count != 1, returning WINED3DERR_INVALIDCALL.\n");
|
2009-09-16 08:37:21 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-03 22:22:59 +01:00
|
|
|
if (FAILED(hr = wined3d_texture_init(texture, &texture2d_ops, layer_count, level_count, desc,
|
2016-03-11 16:01:43 +01:00
|
|
|
flags, device, parent, parent_ops, &texture_resource_ops)))
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
2011-03-18 19:10:59 +01:00
|
|
|
WARN("Failed to initialize texture, returning %#x.\n", hr);
|
2009-09-16 08:37:21 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2013-08-28 10:09:57 +02:00
|
|
|
/* Precalculated scaling for 'faked' non power of two texture coords. */
|
2015-06-06 17:53:53 +02:00
|
|
|
if (texture->resource.gl_type == WINED3D_GL_RES_TYPE_TEX_RECT)
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
2013-06-05 11:06:11 +02:00
|
|
|
texture->pow2_matrix[0] = (float)desc->width;
|
|
|
|
texture->pow2_matrix[5] = (float)desc->height;
|
2014-10-09 11:50:47 +02:00
|
|
|
texture->flags &= ~(WINED3D_TEXTURE_POW2_MAT_IDENT | WINED3D_TEXTURE_NORMALIZED_COORDS);
|
2016-03-21 17:40:11 +01:00
|
|
|
texture->target = GL_TEXTURE_RECTANGLE_ARB;
|
2009-09-16 08:37:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-21 17:40:11 +01:00
|
|
|
if (texture->flags & WINED3D_TEXTURE_COND_NP2_EMULATED)
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
2016-03-21 17:40:11 +01:00
|
|
|
texture->pow2_matrix[0] = (((float)desc->width) / ((float)pow2_width));
|
|
|
|
texture->pow2_matrix[5] = (((float)desc->height) / ((float)pow2_height));
|
|
|
|
texture->flags &= ~WINED3D_TEXTURE_POW2_MAT_IDENT;
|
2009-09-16 08:37:21 +02:00
|
|
|
}
|
2016-03-21 17:40:11 +01:00
|
|
|
else
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->pow2_matrix[0] = 1.0f;
|
|
|
|
texture->pow2_matrix[5] = 1.0f;
|
2015-04-26 16:09:12 +02:00
|
|
|
}
|
2016-03-21 17:40:11 +01:00
|
|
|
if (desc->usage & WINED3DUSAGE_LEGACY_CUBEMAP)
|
|
|
|
texture->target = GL_TEXTURE_CUBE_MAP_ARB;
|
2016-04-25 12:25:30 +02:00
|
|
|
else if (layer_count > 1)
|
|
|
|
texture->target = GL_TEXTURE_2D_ARRAY;
|
2015-04-26 16:09:12 +02:00
|
|
|
else
|
2016-03-21 17:40:11 +01:00
|
|
|
texture->target = GL_TEXTURE_2D;
|
2009-09-16 08:37:21 +02:00
|
|
|
}
|
2016-03-21 17:40:11 +01:00
|
|
|
texture->pow2_matrix[10] = 1.0f;
|
|
|
|
texture->pow2_matrix[15] = 1.0f;
|
|
|
|
TRACE("x scale %.8e, y scale %.8e.\n", texture->pow2_matrix[0], texture->pow2_matrix[5]);
|
2009-09-16 08:37:21 +02:00
|
|
|
|
2016-04-18 19:06:27 +02:00
|
|
|
if (wined3d_texture_use_pbo(texture, gl_info))
|
|
|
|
texture->resource.map_binding = WINED3D_LOCATION_BUFFER;
|
|
|
|
|
2016-05-23 18:06:27 +02:00
|
|
|
if (level_count > ~(SIZE_T)0 / layer_count
|
|
|
|
|| !(surfaces = wined3d_calloc(level_count * layer_count, sizeof(*surfaces))))
|
2016-03-02 19:24:13 +01:00
|
|
|
{
|
2016-07-08 10:59:03 +02:00
|
|
|
wined3d_texture_cleanup_sync(texture);
|
2016-03-02 19:24:13 +01:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2009-09-16 08:37:21 +02:00
|
|
|
/* Generate all the surfaces. */
|
2011-03-28 21:58:42 +02:00
|
|
|
for (i = 0; i < texture->level_count; ++i)
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
2016-02-03 22:22:59 +01:00
|
|
|
for (j = 0; j < texture->layer_count; ++j)
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
2016-02-03 22:22:59 +01:00
|
|
|
static const GLenum cube_targets[6] =
|
|
|
|
{
|
|
|
|
GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
|
|
|
|
GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
|
|
|
|
GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
|
|
|
|
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
|
|
|
|
GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
|
|
|
|
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
|
|
|
|
};
|
2016-04-20 19:29:11 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2016-02-03 22:22:59 +01:00
|
|
|
unsigned int idx = j * texture->level_count + i;
|
|
|
|
struct wined3d_surface *surface;
|
|
|
|
|
2016-03-02 19:24:13 +01:00
|
|
|
surface = &surfaces[idx];
|
2016-04-21 17:05:04 +02:00
|
|
|
surface->container = texture;
|
|
|
|
surface->texture_target = desc->usage & WINED3DUSAGE_LEGACY_CUBEMAP ? cube_targets[j] : texture->target;
|
|
|
|
surface->texture_level = i;
|
|
|
|
surface->texture_layer = j;
|
|
|
|
list_init(&surface->renderbuffers);
|
|
|
|
list_init(&surface->overlays);
|
2016-03-02 19:24:13 +01:00
|
|
|
|
2016-04-20 19:29:11 +02:00
|
|
|
sub_resource = &texture->sub_resources[idx];
|
|
|
|
sub_resource->locations = WINED3D_LOCATION_DISCARDED;
|
|
|
|
sub_resource->u.surface = surface;
|
|
|
|
if (!(texture->resource.usage & WINED3DUSAGE_DEPTHSTENCIL))
|
|
|
|
{
|
|
|
|
wined3d_texture_validate_location(texture, idx, WINED3D_LOCATION_SYSMEM);
|
|
|
|
wined3d_texture_invalidate_location(texture, idx, ~WINED3D_LOCATION_SYSMEM);
|
|
|
|
}
|
|
|
|
|
2016-03-02 19:24:13 +01:00
|
|
|
if (FAILED(hr = device_parent->ops->surface_created(device_parent,
|
2016-04-20 19:29:14 +02:00
|
|
|
texture, idx, &sub_resource->parent, &sub_resource->parent_ops)))
|
2016-02-03 22:22:59 +01:00
|
|
|
{
|
2016-03-02 19:24:13 +01:00
|
|
|
WARN("Failed to create surface parent, hr %#x.\n", hr);
|
2016-07-08 10:59:02 +02:00
|
|
|
sub_resource->parent = NULL;
|
2016-07-08 10:59:03 +02:00
|
|
|
wined3d_texture_cleanup_sync(texture);
|
2016-02-03 22:22:59 +01:00
|
|
|
return hr;
|
|
|
|
}
|
2009-09-16 08:37:21 +02:00
|
|
|
|
2016-04-20 19:29:14 +02:00
|
|
|
TRACE("parent %p, parent_ops %p.\n", sub_resource->parent, sub_resource->parent_ops);
|
2016-03-02 19:24:13 +01:00
|
|
|
|
|
|
|
TRACE("Created surface level %u, layer %u @ %p.\n", i, j, surface);
|
2016-04-14 19:32:46 +02:00
|
|
|
|
|
|
|
if (((desc->usage & WINED3DUSAGE_OWNDC) || (device->wined3d->flags & WINED3D_NO3D))
|
|
|
|
&& FAILED(hr = wined3d_surface_create_dc(surface)))
|
|
|
|
{
|
2016-07-08 10:59:03 +02:00
|
|
|
wined3d_texture_cleanup_sync(texture);
|
2016-04-14 19:32:46 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2016-02-03 22:22:59 +01:00
|
|
|
}
|
2009-09-16 08:37:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2016-08-01 12:49:06 +02:00
|
|
|
/* This call just uploads data, the caller is responsible for binding the
|
|
|
|
* correct texture. */
|
|
|
|
/* Context activation is done by the caller. */
|
2016-04-07 19:38:02 +02:00
|
|
|
static void texture3d_upload_data(struct wined3d_texture *texture, unsigned int sub_resource_idx,
|
2016-07-29 12:34:31 +02:00
|
|
|
const struct wined3d_context *context, const struct wined3d_const_bo_address *data,
|
|
|
|
unsigned int row_pitch, unsigned int slice_pitch)
|
2015-01-05 13:24:58 +01:00
|
|
|
{
|
2016-08-01 12:49:06 +02:00
|
|
|
const struct wined3d_format *format = texture->resource.format;
|
|
|
|
unsigned int level = sub_resource_idx % texture->level_count;
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2016-07-29 12:34:31 +02:00
|
|
|
unsigned int dst_row_pitch, dst_slice_pitch;
|
2016-08-01 12:49:06 +02:00
|
|
|
unsigned int width, height, depth;
|
|
|
|
const void *mem = data->addr;
|
|
|
|
void *converted_mem = NULL;
|
|
|
|
|
|
|
|
TRACE("texture %p, sub_resource_idx %u, context %p, data {%#x:%p}, row_pitch %#x, slice_pitch %#x.\n",
|
|
|
|
texture, sub_resource_idx, context, data->buffer_object, data->addr, row_pitch, slice_pitch);
|
|
|
|
|
|
|
|
width = wined3d_texture_get_level_width(texture, level);
|
|
|
|
height = wined3d_texture_get_level_height(texture, level);
|
|
|
|
depth = wined3d_texture_get_level_depth(texture, level);
|
|
|
|
|
|
|
|
if (format->convert)
|
|
|
|
{
|
|
|
|
if (data->buffer_object)
|
|
|
|
ERR("Loading a converted texture from a PBO.\n");
|
|
|
|
if (texture->resource.format_flags & WINED3DFMT_FLAG_BLOCKS)
|
|
|
|
ERR("Converting a block-based format.\n");
|
|
|
|
|
|
|
|
dst_row_pitch = width * format->conv_byte_count;
|
|
|
|
dst_slice_pitch = dst_row_pitch * height;
|
|
|
|
|
|
|
|
converted_mem = wined3d_calloc(depth, dst_slice_pitch);
|
|
|
|
format->convert(data->addr, converted_mem, row_pitch, slice_pitch,
|
|
|
|
dst_row_pitch, dst_slice_pitch, width, height, depth);
|
|
|
|
mem = converted_mem;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wined3d_texture_get_pitch(texture, sub_resource_idx, &dst_row_pitch, &dst_slice_pitch);
|
|
|
|
if (row_pitch != dst_row_pitch || slice_pitch != dst_slice_pitch)
|
|
|
|
FIXME("Ignoring row/slice pitch (%u/%u).\n", row_pitch, slice_pitch);
|
|
|
|
}
|
2015-01-05 13:24:58 +01:00
|
|
|
|
2016-08-01 12:49:06 +02:00
|
|
|
if (data->buffer_object)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, data->buffer_object));
|
|
|
|
checkGLcall("glBindBuffer");
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_EXTCALL(glTexSubImage3D(GL_TEXTURE_3D, level, 0, 0, 0,
|
|
|
|
width, height, depth, format->glFormat, format->glType, mem));
|
|
|
|
checkGLcall("glTexSubImage3D");
|
|
|
|
|
|
|
|
if (data->buffer_object)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
|
|
|
|
checkGLcall("glBindBuffer");
|
|
|
|
}
|
2015-01-05 13:24:58 +01:00
|
|
|
|
2016-08-01 12:49:06 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, converted_mem);
|
2015-01-05 13:24:58 +01:00
|
|
|
}
|
|
|
|
|
2016-07-28 13:29:40 +02:00
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
static void texture3d_download_data(struct wined3d_texture *texture, unsigned int sub_resource_idx,
|
|
|
|
const struct wined3d_context *context, const struct wined3d_bo_address *data)
|
|
|
|
{
|
|
|
|
const struct wined3d_format *format = texture->resource.format;
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
|
|
|
|
if (format->convert)
|
|
|
|
{
|
|
|
|
FIXME("Attempting to download a converted volume, format %s.\n",
|
|
|
|
debug_d3dformat(format->id));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->buffer_object)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, data->buffer_object));
|
|
|
|
checkGLcall("glBindBuffer");
|
|
|
|
}
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_3D, sub_resource_idx,
|
|
|
|
format->glFormat, format->glType, data->addr);
|
|
|
|
checkGLcall("glGetTexImage");
|
|
|
|
|
|
|
|
if (data->buffer_object)
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
|
|
|
|
checkGLcall("glBindBuffer");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
|
|
|
static void texture3d_srgb_transfer(struct wined3d_texture *texture, unsigned int sub_resource_idx,
|
|
|
|
struct wined3d_context *context, BOOL dest_is_srgb)
|
|
|
|
{
|
|
|
|
struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[sub_resource_idx];
|
2016-08-01 12:49:04 +02:00
|
|
|
unsigned int row_pitch, slice_pitch;
|
2016-07-28 13:29:40 +02:00
|
|
|
struct wined3d_bo_address data;
|
|
|
|
|
|
|
|
/* Optimisations are possible, but the effort should be put into either
|
|
|
|
* implementing EXT_SRGB_DECODE in the driver or finding out why we
|
|
|
|
* picked the wrong copy for the original upload and fixing that.
|
|
|
|
*
|
|
|
|
* Also keep in mind that we want to avoid using resource.heap_memory
|
|
|
|
* for DEFAULT pool surfaces. */
|
|
|
|
WARN_(d3d_perf)("Performing slow rgb/srgb volume transfer.\n");
|
|
|
|
data.buffer_object = 0;
|
|
|
|
if (!(data.addr = HeapAlloc(GetProcessHeap(), 0, sub_resource->size)))
|
|
|
|
return;
|
|
|
|
|
2016-08-01 12:49:04 +02:00
|
|
|
wined3d_texture_get_pitch(texture, sub_resource_idx, &row_pitch, &slice_pitch);
|
2016-07-28 13:29:40 +02:00
|
|
|
wined3d_texture_bind_and_dirtify(texture, context, !dest_is_srgb);
|
|
|
|
texture3d_download_data(texture, sub_resource_idx, context, &data);
|
|
|
|
wined3d_texture_bind_and_dirtify(texture, context, dest_is_srgb);
|
2016-08-01 12:49:04 +02:00
|
|
|
texture3d_upload_data(texture, sub_resource_idx, context,
|
|
|
|
wined3d_const_bo_address(&data), row_pitch, slice_pitch);
|
2016-07-28 13:29:40 +02:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, data.addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
2016-03-11 16:01:43 +01:00
|
|
|
static BOOL texture3d_load_location(struct wined3d_texture *texture, unsigned int sub_resource_idx,
|
|
|
|
struct wined3d_context *context, DWORD location)
|
|
|
|
{
|
2016-07-28 13:29:40 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[sub_resource_idx];
|
|
|
|
DWORD required_access = wined3d_resource_access_from_location(location);
|
2016-08-01 12:49:05 +02:00
|
|
|
unsigned int row_pitch, slice_pitch;
|
2016-07-28 13:29:40 +02:00
|
|
|
|
|
|
|
TRACE("texture %p, sub_resource_idx %u, context %p, location %s.\n",
|
|
|
|
texture, sub_resource_idx, context, wined3d_debug_location(location));
|
|
|
|
|
|
|
|
TRACE("Current resource location %s.\n", wined3d_debug_location(sub_resource->locations));
|
|
|
|
|
|
|
|
if ((sub_resource->locations & location) == location)
|
|
|
|
{
|
|
|
|
TRACE("Location(s) already up to date.\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((texture->resource.access_flags & required_access) != required_access)
|
|
|
|
{
|
|
|
|
ERR("Operation requires %#x access, but volume only has %#x.\n",
|
|
|
|
required_access, texture->resource.access_flags);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wined3d_texture_prepare_location(texture, sub_resource_idx, context, location))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (sub_resource->locations & WINED3D_LOCATION_DISCARDED)
|
|
|
|
{
|
|
|
|
TRACE("Volume previously discarded, nothing to do.\n");
|
|
|
|
wined3d_texture_validate_location(texture, sub_resource_idx, location);
|
|
|
|
wined3d_texture_invalidate_location(texture, sub_resource_idx, WINED3D_LOCATION_DISCARDED);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (location)
|
|
|
|
{
|
|
|
|
case WINED3D_LOCATION_TEXTURE_RGB:
|
|
|
|
case WINED3D_LOCATION_TEXTURE_SRGB:
|
|
|
|
if (sub_resource->locations & WINED3D_LOCATION_SYSMEM)
|
|
|
|
{
|
|
|
|
struct wined3d_const_bo_address data = {0, texture->resource.heap_memory};
|
|
|
|
data.addr += sub_resource->offset;
|
|
|
|
wined3d_texture_bind_and_dirtify(texture, context,
|
|
|
|
location == WINED3D_LOCATION_TEXTURE_SRGB);
|
2016-08-01 12:49:05 +02:00
|
|
|
wined3d_texture_get_pitch(texture, sub_resource_idx, &row_pitch, &slice_pitch);
|
|
|
|
texture3d_upload_data(texture, sub_resource_idx, context, &data, row_pitch, slice_pitch);
|
2016-07-28 13:29:40 +02:00
|
|
|
}
|
|
|
|
else if (sub_resource->locations & WINED3D_LOCATION_BUFFER)
|
|
|
|
{
|
|
|
|
struct wined3d_const_bo_address data = {sub_resource->buffer_object, NULL};
|
|
|
|
wined3d_texture_bind_and_dirtify(texture, context,
|
|
|
|
location == WINED3D_LOCATION_TEXTURE_SRGB);
|
2016-08-01 12:49:05 +02:00
|
|
|
wined3d_texture_get_pitch(texture, sub_resource_idx, &row_pitch, &slice_pitch);
|
|
|
|
texture3d_upload_data(texture, sub_resource_idx, context, &data, row_pitch, slice_pitch);
|
2016-07-28 13:29:40 +02:00
|
|
|
}
|
|
|
|
else if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB)
|
|
|
|
{
|
|
|
|
texture3d_srgb_transfer(texture, sub_resource_idx, context, TRUE);
|
|
|
|
}
|
|
|
|
else if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_SRGB)
|
|
|
|
{
|
|
|
|
texture3d_srgb_transfer(texture, sub_resource_idx, context, FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Implement texture loading from %s.\n", wined3d_debug_location(sub_resource->locations));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_SYSMEM:
|
|
|
|
if (sub_resource->locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
|
|
|
|
{
|
|
|
|
struct wined3d_bo_address data = {0, texture->resource.heap_memory};
|
|
|
|
|
|
|
|
data.addr += sub_resource->offset;
|
|
|
|
if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB)
|
|
|
|
wined3d_texture_bind_and_dirtify(texture, context, FALSE);
|
|
|
|
else
|
|
|
|
wined3d_texture_bind_and_dirtify(texture, context, TRUE);
|
|
|
|
|
|
|
|
texture3d_download_data(texture, sub_resource_idx, context, &data);
|
|
|
|
++texture->download_count;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Implement WINED3D_LOCATION_SYSMEM loading from %s.\n",
|
|
|
|
wined3d_debug_location(sub_resource->locations));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3D_LOCATION_BUFFER:
|
|
|
|
if (sub_resource->locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
|
|
|
|
{
|
|
|
|
struct wined3d_bo_address data = {sub_resource->buffer_object, NULL};
|
|
|
|
|
|
|
|
if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB)
|
|
|
|
wined3d_texture_bind_and_dirtify(texture, context, FALSE);
|
|
|
|
else
|
|
|
|
wined3d_texture_bind_and_dirtify(texture, context, TRUE);
|
|
|
|
|
|
|
|
texture3d_download_data(texture, sub_resource_idx, context, &data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Implement WINED3D_LOCATION_BUFFER loading from %s.\n",
|
|
|
|
wined3d_debug_location(sub_resource->locations));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Implement %s loading from %s.\n", wined3d_debug_location(location),
|
|
|
|
wined3d_debug_location(sub_resource->locations));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
wined3d_texture_validate_location(texture, sub_resource_idx, location);
|
|
|
|
|
|
|
|
return TRUE;
|
2016-03-11 16:01:43 +01:00
|
|
|
}
|
|
|
|
|
2014-10-08 08:47:19 +02:00
|
|
|
static void texture3d_prepare_texture(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
|
|
|
|
{
|
|
|
|
const struct wined3d_format *format = texture->resource.format;
|
2016-05-26 00:08:28 +02:00
|
|
|
GLenum internal = srgb ? format->glGammaInternal : format->glInternal;
|
|
|
|
unsigned int sub_count = texture->level_count * texture->layer_count;
|
2014-10-08 08:47:19 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
wined3d_texture_bind_and_dirtify(texture, context, srgb);
|
|
|
|
|
2016-05-26 00:08:28 +02:00
|
|
|
if (wined3d_texture_use_immutable_storage(texture, gl_info))
|
2014-10-08 08:47:19 +02:00
|
|
|
{
|
2016-05-26 00:08:28 +02:00
|
|
|
GL_EXTCALL(glTexStorage3D(GL_TEXTURE_3D, texture->level_count, internal,
|
|
|
|
wined3d_texture_get_level_width(texture, 0),
|
|
|
|
wined3d_texture_get_level_height(texture, 0),
|
|
|
|
wined3d_texture_get_level_depth(texture, 0)));
|
|
|
|
checkGLcall("glTexStorage3D");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < sub_count; ++i)
|
|
|
|
{
|
2016-07-29 12:34:30 +02:00
|
|
|
GL_EXTCALL(glTexImage3D(GL_TEXTURE_3D, i, internal,
|
|
|
|
wined3d_texture_get_level_width(texture, i),
|
|
|
|
wined3d_texture_get_level_height(texture, i),
|
|
|
|
wined3d_texture_get_level_depth(texture, i),
|
2016-05-26 00:08:28 +02:00
|
|
|
0, format->glFormat, format->glType, NULL));
|
|
|
|
checkGLcall("glTexImage3D");
|
|
|
|
}
|
2014-10-08 08:47:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-02 19:24:13 +01:00
|
|
|
static void texture3d_cleanup_sub_resources(struct wined3d_texture *texture)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
static const struct wined3d_texture_ops texture3d_ops =
|
|
|
|
{
|
2016-04-07 19:38:02 +02:00
|
|
|
texture3d_upload_data,
|
2016-03-11 16:01:43 +01:00
|
|
|
texture3d_load_location,
|
2014-10-08 08:47:19 +02:00
|
|
|
texture3d_prepare_texture,
|
2016-03-02 19:24:13 +01:00
|
|
|
texture3d_cleanup_sub_resources,
|
2011-03-18 19:10:58 +01:00
|
|
|
};
|
|
|
|
|
2016-02-17 18:35:35 +01:00
|
|
|
BOOL wined3d_texture_check_block_align(const struct wined3d_texture *texture,
|
|
|
|
unsigned int level, const struct wined3d_box *box)
|
|
|
|
{
|
|
|
|
const struct wined3d_format *format = texture->resource.format;
|
2016-03-09 16:21:54 +01:00
|
|
|
unsigned int height = wined3d_texture_get_level_height(texture, level);
|
|
|
|
unsigned int width = wined3d_texture_get_level_width(texture, level);
|
2016-02-17 18:35:35 +01:00
|
|
|
unsigned int width_mask, height_mask;
|
|
|
|
|
|
|
|
if ((box->left >= box->right)
|
|
|
|
|| (box->top >= box->bottom)
|
|
|
|
|| (box->right > width)
|
|
|
|
|| (box->bottom > height))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* This assumes power of two block sizes, but NPOT block sizes would be
|
|
|
|
* silly anyway.
|
|
|
|
*
|
|
|
|
* This also assumes that the format's block depth is 1. */
|
|
|
|
width_mask = format->block_width - 1;
|
|
|
|
height_mask = format->block_height - 1;
|
|
|
|
|
|
|
|
if ((box->left & width_mask) || (box->top & height_mask)
|
|
|
|
|| (box->right & width_mask && box->right != width)
|
|
|
|
|| (box->bottom & height_mask && box->bottom != height))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-06-06 10:51:46 +02:00
|
|
|
static HRESULT volumetexture_init(struct wined3d_texture *texture, const struct wined3d_resource_desc *desc,
|
2016-04-25 12:25:29 +02:00
|
|
|
UINT layer_count, UINT level_count, struct wined3d_device *device, void *parent,
|
|
|
|
const struct wined3d_parent_ops *parent_ops)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2016-03-02 19:24:13 +01:00
|
|
|
struct wined3d_device_parent *device_parent = device->device_parent;
|
2011-03-18 19:10:58 +01:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
unsigned int i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-04-25 12:25:29 +02:00
|
|
|
if (layer_count != 1)
|
|
|
|
{
|
|
|
|
ERR("Invalid layer count for volume texture.\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
/* TODO: It should only be possible to create textures for formats
|
|
|
|
* that are reported as supported. */
|
2013-06-06 10:51:46 +02:00
|
|
|
if (WINED3DFMT_UNKNOWN >= desc->format)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gl_info->supported[EXT_TEXTURE3D])
|
|
|
|
{
|
|
|
|
WARN("(%p) : Texture cannot be created - no volume texture support.\n", texture);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate levels for mip mapping. */
|
2013-06-06 10:51:46 +02:00
|
|
|
if (desc->usage & WINED3DUSAGE_AUTOGENMIPMAP)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
|
|
|
|
{
|
|
|
|
WARN("No mipmap generation support, returning D3DERR_INVALIDCALL.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2016-04-25 12:25:29 +02:00
|
|
|
if (level_count != 1)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2015-01-05 13:24:57 +01:00
|
|
|
WARN("WINED3DUSAGE_AUTOGENMIPMAP is set, and level count != 1, returning D3DERR_INVALIDCALL.\n");
|
2011-03-18 19:10:58 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-14 19:32:49 +02:00
|
|
|
if (desc->usage & WINED3DUSAGE_DYNAMIC && (desc->pool == WINED3D_POOL_MANAGED
|
|
|
|
|| desc->pool == WINED3D_POOL_SCRATCH))
|
|
|
|
{
|
|
|
|
WARN("Attempted to create a DYNAMIC texture in pool %s.\n", debug_d3dpool(desc->pool));
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2013-04-16 14:48:32 +02:00
|
|
|
if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
|
|
|
|
{
|
|
|
|
UINT pow2_w, pow2_h, pow2_d;
|
|
|
|
pow2_w = 1;
|
2013-06-06 10:51:46 +02:00
|
|
|
while (pow2_w < desc->width)
|
|
|
|
pow2_w <<= 1;
|
2013-04-16 14:48:32 +02:00
|
|
|
pow2_h = 1;
|
2013-06-06 10:51:46 +02:00
|
|
|
while (pow2_h < desc->height)
|
|
|
|
pow2_h <<= 1;
|
2013-04-16 14:48:32 +02:00
|
|
|
pow2_d = 1;
|
2013-06-06 10:51:46 +02:00
|
|
|
while (pow2_d < desc->depth)
|
|
|
|
pow2_d <<= 1;
|
2013-04-16 14:48:32 +02:00
|
|
|
|
2013-06-06 10:51:46 +02:00
|
|
|
if (pow2_w != desc->width || pow2_h != desc->height || pow2_d != desc->depth)
|
2013-04-16 14:48:32 +02:00
|
|
|
{
|
2013-06-06 10:51:46 +02:00
|
|
|
if (desc->pool == WINED3D_POOL_SCRATCH)
|
2013-04-16 14:48:32 +02:00
|
|
|
{
|
|
|
|
WARN("Creating a scratch NPOT volume texture despite lack of HW support.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-06 10:51:46 +02:00
|
|
|
WARN("Attempted to create a NPOT volume texture (%u, %u, %u) without GL support.\n",
|
|
|
|
desc->width, desc->height, desc->depth);
|
2013-04-16 14:48:32 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-25 12:25:29 +02:00
|
|
|
if (FAILED(hr = wined3d_texture_init(texture, &texture3d_ops, 1, level_count, desc,
|
2016-03-11 16:01:43 +01:00
|
|
|
0, device, parent, parent_ops, &texture_resource_ops)))
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2011-03-18 19:10:59 +01:00
|
|
|
WARN("Failed to initialize texture, returning %#x.\n", hr);
|
2011-03-18 19:10:58 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->pow2_matrix[0] = 1.0f;
|
|
|
|
texture->pow2_matrix[5] = 1.0f;
|
|
|
|
texture->pow2_matrix[10] = 1.0f;
|
|
|
|
texture->pow2_matrix[15] = 1.0f;
|
|
|
|
texture->target = GL_TEXTURE_3D;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2016-04-18 19:06:27 +02:00
|
|
|
if (wined3d_texture_use_pbo(texture, gl_info))
|
2016-04-20 19:29:12 +02:00
|
|
|
{
|
|
|
|
wined3d_resource_free_sysmem(&texture->resource);
|
2016-04-18 19:06:27 +02:00
|
|
|
texture->resource.map_binding = WINED3D_LOCATION_BUFFER;
|
2016-04-20 19:29:12 +02:00
|
|
|
}
|
2016-04-18 19:06:27 +02:00
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
/* Generate all the surfaces. */
|
2011-03-28 21:58:42 +02:00
|
|
|
for (i = 0; i < texture->level_count; ++i)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2016-04-20 19:29:11 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2016-03-02 19:24:13 +01:00
|
|
|
|
2016-04-20 19:29:11 +02:00
|
|
|
sub_resource = &texture->sub_resources[i];
|
|
|
|
sub_resource->locations = WINED3D_LOCATION_DISCARDED;
|
|
|
|
|
2016-03-02 19:24:13 +01:00
|
|
|
if (FAILED(hr = device_parent->ops->volume_created(device_parent,
|
2016-04-20 19:29:14 +02:00
|
|
|
texture, i, &sub_resource->parent, &sub_resource->parent_ops)))
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2016-03-02 19:24:13 +01:00
|
|
|
WARN("Failed to create volume parent, hr %#x.\n", hr);
|
2016-07-08 10:59:02 +02:00
|
|
|
sub_resource->parent = NULL;
|
2016-07-08 10:59:03 +02:00
|
|
|
wined3d_texture_cleanup_sync(texture);
|
2011-03-18 19:10:58 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2016-03-02 19:24:13 +01:00
|
|
|
TRACE("parent %p, parent_ops %p.\n", parent, parent_ops);
|
|
|
|
|
2016-07-29 12:34:30 +02:00
|
|
|
TRACE("Created volume level %u.\n", i);
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2016-01-27 20:44:37 +01:00
|
|
|
HRESULT CDECL wined3d_texture_blt(struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
|
|
|
|
const RECT *dst_rect, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx,
|
2016-02-15 18:18:03 +01:00
|
|
|
const RECT *src_rect, DWORD flags, const struct wined3d_blt_fx *fx, enum wined3d_texture_filter_type filter)
|
2015-10-16 13:59:19 +02:00
|
|
|
{
|
2016-04-04 18:43:02 +02:00
|
|
|
struct wined3d_texture_sub_resource *dst_resource, *src_resource = NULL;
|
2015-10-16 13:59:19 +02:00
|
|
|
|
2016-01-27 20:44:37 +01:00
|
|
|
TRACE("dst_texture %p, dst_sub_resource_idx %u, dst_rect %s, src_texture %p, "
|
|
|
|
"src_sub_resource_idx %u, src_rect %s, flags %#x, fx %p, filter %s.\n",
|
|
|
|
dst_texture, dst_sub_resource_idx, wine_dbgstr_rect(dst_rect), src_texture,
|
|
|
|
src_sub_resource_idx, wine_dbgstr_rect(src_rect), flags, fx, debug_d3dtexturefiltertype(filter));
|
2015-10-16 13:59:19 +02:00
|
|
|
|
|
|
|
if (!(dst_resource = wined3d_texture_get_sub_resource(dst_texture, dst_sub_resource_idx))
|
2016-04-04 18:43:02 +02:00
|
|
|
|| dst_texture->resource.type != WINED3D_RTYPE_TEXTURE_2D)
|
2015-10-16 13:59:19 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
if (src_texture)
|
|
|
|
{
|
|
|
|
if (!(src_resource = wined3d_texture_get_sub_resource(src_texture, src_sub_resource_idx))
|
2016-04-04 18:43:02 +02:00
|
|
|
|| src_texture->resource.type != WINED3D_RTYPE_TEXTURE_2D)
|
2015-10-16 13:59:19 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2016-04-04 18:43:02 +02:00
|
|
|
return wined3d_surface_blt(dst_resource->u.surface, dst_rect,
|
|
|
|
src_resource ? src_resource->u.surface : NULL, src_rect, flags, fx, filter);
|
2015-10-16 13:59:19 +02:00
|
|
|
}
|
|
|
|
|
2016-02-05 21:31:02 +01:00
|
|
|
HRESULT CDECL wined3d_texture_get_overlay_position(const struct wined3d_texture *texture,
|
|
|
|
unsigned int sub_resource_idx, LONG *x, LONG *y)
|
|
|
|
{
|
|
|
|
struct wined3d_surface *surface;
|
|
|
|
|
|
|
|
TRACE("texture %p, sub_resource_idx %u, x %p, y %p.\n", texture, sub_resource_idx, x, y);
|
|
|
|
|
|
|
|
if (!(texture->resource.usage & WINED3DUSAGE_OVERLAY) || texture->resource.type != WINED3D_RTYPE_TEXTURE_2D
|
2016-04-04 18:43:02 +02:00
|
|
|
|| sub_resource_idx >= texture->level_count * texture->layer_count)
|
2016-02-05 21:31:02 +01:00
|
|
|
{
|
|
|
|
WARN("Invalid sub-resource specified.\n");
|
|
|
|
return WINEDDERR_NOTAOVERLAYSURFACE;
|
|
|
|
}
|
|
|
|
|
2016-04-04 18:43:02 +02:00
|
|
|
surface = texture->sub_resources[sub_resource_idx].u.surface;
|
2016-02-05 21:31:02 +01:00
|
|
|
if (!surface->overlay_dest)
|
|
|
|
{
|
|
|
|
TRACE("Overlay not visible.\n");
|
|
|
|
*x = 0;
|
|
|
|
*y = 0;
|
|
|
|
return WINEDDERR_OVERLAYNOTVISIBLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*x = surface->overlay_destrect.left;
|
|
|
|
*y = surface->overlay_destrect.top;
|
|
|
|
|
|
|
|
TRACE("Returning position %d, %d.\n", *x, *y);
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2016-02-05 21:31:03 +01:00
|
|
|
HRESULT CDECL wined3d_texture_set_overlay_position(struct wined3d_texture *texture,
|
|
|
|
unsigned int sub_resource_idx, LONG x, LONG y)
|
|
|
|
{
|
2016-04-04 18:43:02 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2016-02-05 21:31:03 +01:00
|
|
|
struct wined3d_surface *surface;
|
|
|
|
LONG w, h;
|
|
|
|
|
|
|
|
TRACE("texture %p, sub_resource_idx %u, x %d, y %d.\n", texture, sub_resource_idx, x, y);
|
|
|
|
|
|
|
|
if (!(texture->resource.usage & WINED3DUSAGE_OVERLAY) || texture->resource.type != WINED3D_RTYPE_TEXTURE_2D
|
|
|
|
|| !(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
|
|
|
|
{
|
|
|
|
WARN("Invalid sub-resource specified.\n");
|
|
|
|
return WINEDDERR_NOTAOVERLAYSURFACE;
|
|
|
|
}
|
|
|
|
|
2016-04-04 18:43:02 +02:00
|
|
|
surface = sub_resource->u.surface;
|
2016-02-05 21:31:03 +01:00
|
|
|
w = surface->overlay_destrect.right - surface->overlay_destrect.left;
|
|
|
|
h = surface->overlay_destrect.bottom - surface->overlay_destrect.top;
|
2016-07-30 22:00:33 +02:00
|
|
|
SetRect(&surface->overlay_destrect, x, y, x + w, y + h);
|
2016-02-05 21:31:03 +01:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2016-02-08 18:32:01 +01:00
|
|
|
HRESULT CDECL wined3d_texture_update_overlay(struct wined3d_texture *texture, unsigned int sub_resource_idx,
|
|
|
|
const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
|
2016-02-15 18:18:00 +01:00
|
|
|
const RECT *dst_rect, DWORD flags)
|
2016-02-08 18:32:01 +01:00
|
|
|
{
|
2016-04-04 18:43:02 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource, *dst_sub_resource;
|
2016-02-08 18:32:01 +01:00
|
|
|
struct wined3d_surface *surface, *dst_surface;
|
|
|
|
|
|
|
|
TRACE("texture %p, sub_resource_idx %u, src_rect %s, dst_texture %p, "
|
2016-02-15 18:18:00 +01:00
|
|
|
"dst_sub_resource_idx %u, dst_rect %s, flags %#x.\n",
|
2016-02-08 18:32:01 +01:00
|
|
|
texture, sub_resource_idx, wine_dbgstr_rect(src_rect), dst_texture,
|
2016-02-15 18:18:00 +01:00
|
|
|
dst_sub_resource_idx, wine_dbgstr_rect(dst_rect), flags);
|
2016-02-08 18:32:01 +01:00
|
|
|
|
|
|
|
if (!(texture->resource.usage & WINED3DUSAGE_OVERLAY) || texture->resource.type != WINED3D_RTYPE_TEXTURE_2D
|
|
|
|
|| !(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
|
|
|
|
{
|
|
|
|
WARN("Invalid sub-resource specified.\n");
|
|
|
|
return WINEDDERR_NOTAOVERLAYSURFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dst_texture || dst_texture->resource.type != WINED3D_RTYPE_TEXTURE_2D
|
|
|
|
|| !(dst_sub_resource = wined3d_texture_get_sub_resource(dst_texture, dst_sub_resource_idx)))
|
|
|
|
{
|
|
|
|
WARN("Invalid destination sub-resource specified.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2016-04-04 18:43:02 +02:00
|
|
|
surface = sub_resource->u.surface;
|
2016-02-08 18:32:01 +01:00
|
|
|
if (src_rect)
|
|
|
|
surface->overlay_srcrect = *src_rect;
|
|
|
|
else
|
2016-04-11 18:34:43 +02:00
|
|
|
SetRect(&surface->overlay_srcrect, 0, 0,
|
|
|
|
wined3d_texture_get_level_width(texture, surface->texture_level),
|
|
|
|
wined3d_texture_get_level_height(texture, surface->texture_level));
|
2016-02-08 18:32:01 +01:00
|
|
|
|
2016-04-04 18:43:02 +02:00
|
|
|
dst_surface = dst_sub_resource->u.surface;
|
2016-02-08 18:32:01 +01:00
|
|
|
if (dst_rect)
|
|
|
|
surface->overlay_destrect = *dst_rect;
|
|
|
|
else
|
2016-04-11 18:34:43 +02:00
|
|
|
SetRect(&surface->overlay_destrect, 0, 0,
|
|
|
|
wined3d_texture_get_level_width(dst_texture, dst_surface->texture_level),
|
|
|
|
wined3d_texture_get_level_height(dst_texture, dst_surface->texture_level));
|
2016-02-08 18:32:01 +01:00
|
|
|
|
|
|
|
if (surface->overlay_dest && (surface->overlay_dest != dst_surface || flags & WINEDDOVER_HIDE))
|
|
|
|
{
|
|
|
|
surface->overlay_dest = NULL;
|
|
|
|
list_remove(&surface->overlay_entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & WINEDDOVER_SHOW)
|
|
|
|
{
|
|
|
|
if (surface->overlay_dest != dst_surface)
|
|
|
|
{
|
|
|
|
surface->overlay_dest = dst_surface;
|
|
|
|
list_add_tail(&dst_surface->overlays, &surface->overlay_entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (flags & WINEDDOVER_HIDE)
|
|
|
|
{
|
|
|
|
/* Tests show that the rectangles are erased on hide. */
|
2016-03-03 09:31:52 +01:00
|
|
|
SetRectEmpty(&surface->overlay_srcrect);
|
|
|
|
SetRectEmpty(&surface->overlay_destrect);
|
2016-02-08 18:32:01 +01:00
|
|
|
surface->overlay_dest = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2016-02-16 17:17:27 +01:00
|
|
|
void * CDECL wined3d_texture_get_sub_resource_parent(struct wined3d_texture *texture, unsigned int sub_resource_idx)
|
|
|
|
{
|
|
|
|
unsigned int sub_count = texture->level_count * texture->layer_count;
|
|
|
|
|
|
|
|
TRACE("texture %p, sub_resource_idx %u.\n", texture, sub_resource_idx);
|
|
|
|
|
|
|
|
if (sub_resource_idx >= sub_count)
|
|
|
|
{
|
|
|
|
WARN("sub_resource_idx %u >= sub_count %u.\n", sub_resource_idx, sub_count);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-04-20 19:29:14 +02:00
|
|
|
return texture->sub_resources[sub_resource_idx].parent;
|
2016-02-16 17:17:27 +01:00
|
|
|
}
|
|
|
|
|
2016-02-29 11:38:21 +01:00
|
|
|
void CDECL wined3d_texture_set_sub_resource_parent(struct wined3d_texture *texture,
|
|
|
|
unsigned int sub_resource_idx, void *parent)
|
|
|
|
{
|
|
|
|
unsigned int sub_count = texture->level_count * texture->layer_count;
|
|
|
|
|
|
|
|
TRACE("texture %p, sub_resource_idx %u, parent %p.\n", texture, sub_resource_idx, parent);
|
|
|
|
|
|
|
|
if (sub_resource_idx >= sub_count)
|
|
|
|
{
|
|
|
|
WARN("sub_resource_idx %u >= sub_count %u.\n", sub_resource_idx, sub_count);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-20 19:29:14 +02:00
|
|
|
texture->sub_resources[sub_resource_idx].parent = parent;
|
2016-02-29 11:38:21 +01:00
|
|
|
}
|
|
|
|
|
2016-02-29 11:38:25 +01:00
|
|
|
HRESULT CDECL wined3d_texture_get_sub_resource_desc(const struct wined3d_texture *texture,
|
|
|
|
unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc)
|
|
|
|
{
|
|
|
|
unsigned int sub_count = texture->level_count * texture->layer_count;
|
|
|
|
const struct wined3d_resource *resource;
|
|
|
|
unsigned int level_idx;
|
|
|
|
|
|
|
|
TRACE("texture %p, sub_resource_idx %u, desc %p.\n", texture, sub_resource_idx, desc);
|
|
|
|
|
|
|
|
if (sub_resource_idx >= sub_count)
|
|
|
|
{
|
|
|
|
WARN("sub_resource_idx %u >= sub_count %u.\n", sub_resource_idx, sub_count);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
resource = &texture->resource;
|
|
|
|
desc->format = resource->format->id;
|
|
|
|
desc->multisample_type = resource->multisample_type;
|
|
|
|
desc->multisample_quality = resource->multisample_quality;
|
|
|
|
desc->usage = resource->usage;
|
|
|
|
desc->pool = resource->pool;
|
|
|
|
|
|
|
|
level_idx = sub_resource_idx % texture->level_count;
|
2016-03-09 16:21:54 +01:00
|
|
|
desc->width = wined3d_texture_get_level_width(texture, level_idx);
|
|
|
|
desc->height = wined3d_texture_get_level_height(texture, level_idx);
|
|
|
|
desc->depth = wined3d_texture_get_level_depth(texture, level_idx);
|
2016-04-20 19:29:12 +02:00
|
|
|
desc->size = texture->sub_resources[sub_resource_idx].size;
|
2016-02-29 11:38:25 +01:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2013-11-27 11:04:48 +01:00
|
|
|
HRESULT CDECL wined3d_texture_create(struct wined3d_device *device, const struct wined3d_resource_desc *desc,
|
2016-04-25 12:25:29 +02:00
|
|
|
UINT layer_count, UINT level_count, DWORD flags, const struct wined3d_sub_resource_data *data,
|
|
|
|
void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture)
|
2011-05-10 21:18:47 +02:00
|
|
|
{
|
|
|
|
struct wined3d_texture *object;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-04-25 12:25:29 +02:00
|
|
|
TRACE("device %p, desc %p, layer_count %u, level_count %u, flags %#x, data %p, "
|
|
|
|
"parent %p, parent_ops %p, texture %p.\n",
|
|
|
|
device, desc, layer_count, level_count, flags, data, parent, parent_ops, texture);
|
|
|
|
|
|
|
|
if (!layer_count)
|
|
|
|
{
|
|
|
|
WARN("Invalid layer count.\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
if ((desc->usage & WINED3DUSAGE_LEGACY_CUBEMAP) && layer_count != 6)
|
|
|
|
{
|
|
|
|
ERR("Invalid layer count %u for legacy cubemap.\n", layer_count);
|
|
|
|
layer_count = 6;
|
|
|
|
}
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2015-01-05 13:24:57 +01:00
|
|
|
if (!level_count)
|
|
|
|
{
|
|
|
|
WARN("Invalid level count.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2016-01-28 00:15:44 +01:00
|
|
|
if (desc->multisample_type != WINED3D_MULTISAMPLE_NONE)
|
|
|
|
{
|
|
|
|
const struct wined3d_format *format = wined3d_get_format(&device->adapter->gl_info, desc->format);
|
|
|
|
|
|
|
|
if (desc->multisample_type == WINED3D_MULTISAMPLE_NON_MASKABLE
|
|
|
|
&& desc->multisample_quality >= wined3d_popcount(format->multisample_types))
|
|
|
|
{
|
|
|
|
WARN("Unsupported quality level %u requested for WINED3D_MULTISAMPLE_NON_MASKABLE.\n",
|
|
|
|
desc->multisample_quality);
|
|
|
|
return WINED3DERR_NOTAVAILABLE;
|
|
|
|
}
|
|
|
|
if (desc->multisample_type != WINED3D_MULTISAMPLE_NON_MASKABLE
|
|
|
|
&& (!(format->multisample_types & 1u << (desc->multisample_type - 1))
|
|
|
|
|| desc->multisample_quality))
|
|
|
|
{
|
|
|
|
WARN("Unsupported multisample type %u quality %u requested.\n", desc->multisample_type,
|
|
|
|
desc->multisample_quality);
|
|
|
|
return WINED3DERR_NOTAVAILABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-16 17:17:25 +01:00
|
|
|
if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
FIELD_OFFSET(struct wined3d_texture, sub_resources[level_count * layer_count]))))
|
2013-11-27 11:04:48 +01:00
|
|
|
return E_OUTOFMEMORY;
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2013-11-27 11:04:48 +01:00
|
|
|
switch (desc->resource_type)
|
2011-05-10 21:18:47 +02:00
|
|
|
{
|
2016-01-27 00:06:23 +01:00
|
|
|
case WINED3D_RTYPE_TEXTURE_2D:
|
2016-02-16 17:17:25 +01:00
|
|
|
hr = texture_init(object, desc, layer_count, level_count, flags, device, parent, parent_ops);
|
2013-11-27 11:04:48 +01:00
|
|
|
break;
|
|
|
|
|
2016-01-27 00:06:24 +01:00
|
|
|
case WINED3D_RTYPE_TEXTURE_3D:
|
2016-04-25 12:25:29 +02:00
|
|
|
hr = volumetexture_init(object, desc, layer_count, level_count, device, parent, parent_ops);
|
2013-11-27 11:04:48 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR("Invalid resource type %s.\n", debug_d3dresourcetype(desc->resource_type));
|
|
|
|
hr = WINED3DERR_INVALIDCALL;
|
|
|
|
break;
|
2011-05-10 21:18:47 +02:00
|
|
|
}
|
|
|
|
|
2013-11-27 11:04:48 +01:00
|
|
|
if (FAILED(hr))
|
2011-05-10 21:18:47 +02:00
|
|
|
{
|
2013-11-27 11:04:48 +01:00
|
|
|
WARN("Failed to initialize texture, returning %#x.\n", hr);
|
2011-05-10 21:18:47 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2015-01-05 13:24:58 +01:00
|
|
|
/* FIXME: We'd like to avoid ever allocating system memory for the texture
|
|
|
|
* in this case. */
|
2016-07-29 12:34:32 +02:00
|
|
|
if (data)
|
2015-07-31 09:46:28 +02:00
|
|
|
{
|
2016-07-29 12:34:32 +02:00
|
|
|
unsigned int sub_count = level_count * layer_count;
|
|
|
|
struct wined3d_context *context;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sub_count; ++i)
|
|
|
|
{
|
|
|
|
if (!data[i].data)
|
|
|
|
{
|
|
|
|
WARN("Invalid sub-resource data specified for sub-resource %u.\n", i);
|
|
|
|
wined3d_texture_cleanup_sync(object);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
|
|
|
|
wined3d_texture_prepare_texture(object, context, FALSE);
|
|
|
|
wined3d_texture_bind_and_dirtify(object, context, FALSE);
|
|
|
|
|
|
|
|
for (i = 0; i < sub_count; ++i)
|
|
|
|
{
|
|
|
|
const struct wined3d_const_bo_address addr = {0, data[i].data};
|
|
|
|
|
|
|
|
wined3d_texture_upload_data(object, i, context, &addr, data[i].row_pitch, data[i].slice_pitch);
|
|
|
|
wined3d_texture_validate_location(object, i, WINED3D_LOCATION_TEXTURE_RGB);
|
|
|
|
wined3d_texture_invalidate_location(object, i, ~WINED3D_LOCATION_TEXTURE_RGB);
|
|
|
|
}
|
|
|
|
|
|
|
|
context_release(context);
|
2015-07-31 09:46:28 +02:00
|
|
|
}
|
2015-01-05 13:24:58 +01:00
|
|
|
|
2011-05-10 21:18:47 +02:00
|
|
|
TRACE("Created texture %p.\n", object);
|
|
|
|
*texture = object;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2015-10-06 10:36:48 +02:00
|
|
|
|
2015-10-28 14:02:12 +01:00
|
|
|
HRESULT CDECL wined3d_texture_get_dc(struct wined3d_texture *texture, unsigned int sub_resource_idx, HDC *dc)
|
|
|
|
{
|
2016-02-01 18:42:11 +01:00
|
|
|
struct wined3d_device *device = texture->resource.device;
|
2016-04-04 18:43:02 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2016-02-01 18:42:11 +01:00
|
|
|
struct wined3d_context *context = NULL;
|
|
|
|
struct wined3d_surface *surface;
|
2016-04-14 19:32:46 +02:00
|
|
|
HRESULT hr = WINED3D_OK;
|
2015-10-28 14:02:12 +01:00
|
|
|
|
|
|
|
TRACE("texture %p, sub_resource_idx %u, dc %p.\n", texture, sub_resource_idx, dc);
|
|
|
|
|
|
|
|
if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2016-04-04 18:43:02 +02:00
|
|
|
if (texture->resource.type != WINED3D_RTYPE_TEXTURE_2D)
|
2015-10-28 14:02:12 +01:00
|
|
|
{
|
|
|
|
WARN("Not supported on %s resources.\n", debug_d3dresourcetype(texture->resource.type));
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2016-04-04 18:43:02 +02:00
|
|
|
surface = sub_resource->u.surface;
|
2016-02-01 18:42:11 +01:00
|
|
|
|
2016-04-13 12:18:48 +02:00
|
|
|
if (texture->resource.map_count && !(texture->flags & WINED3D_TEXTURE_GET_DC_LENIENT))
|
2016-02-01 18:42:11 +01:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
if (device->d3d_initialized)
|
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
|
2016-08-05 12:38:58 +02:00
|
|
|
wined3d_texture_load_location(texture, sub_resource_idx, context, texture->resource.map_binding);
|
2016-04-18 19:06:27 +02:00
|
|
|
wined3d_texture_invalidate_location(texture, sub_resource_idx, ~texture->resource.map_binding);
|
2016-02-01 18:42:11 +01:00
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
if (!surface->dc)
|
|
|
|
hr = wined3d_surface_create_dc(surface);
|
2016-02-01 18:42:11 +01:00
|
|
|
if (context)
|
|
|
|
context_release(context);
|
2016-04-14 19:32:46 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2016-02-01 18:42:11 +01:00
|
|
|
|
2016-04-13 12:18:47 +02:00
|
|
|
if (!(texture->flags & WINED3D_TEXTURE_GET_DC_LENIENT))
|
2016-04-13 12:18:48 +02:00
|
|
|
texture->flags |= WINED3D_TEXTURE_DC_IN_USE;
|
2016-04-10 18:09:26 +02:00
|
|
|
++texture->resource.map_count;
|
2016-04-10 18:09:27 +02:00
|
|
|
++sub_resource->map_count;
|
2016-02-01 18:42:11 +01:00
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
*dc = surface->dc;
|
2016-02-01 18:42:11 +01:00
|
|
|
TRACE("Returning dc %p.\n", *dc);
|
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
return hr;
|
2015-10-28 14:02:12 +01:00
|
|
|
}
|
2015-10-28 14:02:13 +01:00
|
|
|
|
|
|
|
HRESULT CDECL wined3d_texture_release_dc(struct wined3d_texture *texture, unsigned int sub_resource_idx, HDC dc)
|
|
|
|
{
|
2016-02-01 18:42:11 +01:00
|
|
|
struct wined3d_device *device = texture->resource.device;
|
2016-04-04 18:43:02 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2016-02-01 18:42:11 +01:00
|
|
|
struct wined3d_surface *surface;
|
2015-10-28 14:02:13 +01:00
|
|
|
|
|
|
|
TRACE("texture %p, sub_resource_idx %u, dc %p.\n", texture, sub_resource_idx, dc);
|
|
|
|
|
|
|
|
if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2016-04-04 18:43:02 +02:00
|
|
|
if (texture->resource.type != WINED3D_RTYPE_TEXTURE_2D)
|
2015-10-28 14:02:13 +01:00
|
|
|
{
|
|
|
|
WARN("Not supported on %s resources.\n", debug_d3dresourcetype(texture->resource.type));
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2016-04-04 18:43:02 +02:00
|
|
|
surface = sub_resource->u.surface;
|
2016-02-01 18:42:11 +01:00
|
|
|
|
2016-04-13 12:18:48 +02:00
|
|
|
if (!(texture->flags & (WINED3D_TEXTURE_GET_DC_LENIENT | WINED3D_TEXTURE_DC_IN_USE)))
|
2016-04-13 12:18:47 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2016-02-01 18:42:11 +01:00
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
if (surface->dc != dc)
|
2016-02-01 18:42:11 +01:00
|
|
|
{
|
2016-04-14 19:32:46 +02:00
|
|
|
WARN("Application tries to release invalid DC %p, surface DC is %p.\n", dc, surface->dc);
|
2016-04-13 12:18:47 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2016-02-01 18:42:11 +01:00
|
|
|
}
|
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
if (!(texture->resource.usage & WINED3DUSAGE_OWNDC) && !(device->wined3d->flags & WINED3D_NO3D))
|
|
|
|
wined3d_surface_destroy_dc(surface);
|
|
|
|
|
2016-04-10 18:09:27 +02:00
|
|
|
--sub_resource->map_count;
|
2016-04-18 19:06:27 +02:00
|
|
|
if (!--texture->resource.map_count && texture->update_map_binding)
|
|
|
|
wined3d_texture_update_map_binding(texture);
|
2016-04-13 12:18:47 +02:00
|
|
|
if (!(texture->flags & WINED3D_TEXTURE_GET_DC_LENIENT))
|
2016-04-13 12:18:48 +02:00
|
|
|
texture->flags &= ~WINED3D_TEXTURE_DC_IN_USE;
|
2016-02-01 18:42:11 +01:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
2015-10-28 14:02:13 +01:00
|
|
|
}
|