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"
|
|
|
|
|
2005-08-03 21:49:05 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
|
2009-06-03 10:47:25 +02:00
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
static HRESULT wined3d_texture_init(struct wined3d_texture *texture, const struct wined3d_texture_ops *texture_ops,
|
2013-06-05 11:06:10 +02:00
|
|
|
UINT layer_count, UINT level_count, const struct wined3d_resource_desc *desc, struct wined3d_device *device,
|
2013-06-04 09:57:06 +02:00
|
|
|
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);
|
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, "
|
|
|
|
"device %p, parent %p, parent_ops %p, resource_ops %p.\n",
|
|
|
|
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,
|
|
|
|
device, parent, parent_ops, resource_ops);
|
|
|
|
|
|
|
|
if (FAILED(hr = resource_init(&texture->resource, device, desc->resource_type, format,
|
|
|
|
desc->multisample_type, desc->multisample_quality, desc->usage, desc->pool,
|
|
|
|
desc->width, desc->height, desc->depth, 0, parent, parent_ops, resource_ops)))
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
WARN("Failed to initialize resource, returning %#x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->texture_ops = texture_ops;
|
|
|
|
texture->sub_resources = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
level_count * layer_count * sizeof(*texture->sub_resources));
|
|
|
|
if (!texture->sub_resources)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
ERR("Failed to allocate sub-resource array.\n");
|
|
|
|
resource_cleanup(&texture->resource);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
texture->texture_rgb.dirty = TRUE;
|
|
|
|
texture->texture_srgb.dirty = TRUE;
|
2011-03-28 21:58:44 +02:00
|
|
|
texture->flags = WINED3D_TEXTURE_POW2_MAT_IDENT;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
if (texture->resource.format->flags & WINED3DFMT_FLAG_FILTERING)
|
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->min_mip_lookup = minMipLookup;
|
|
|
|
texture->mag_lookup = magLookup;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->min_mip_lookup = minMipLookup_noFilter;
|
|
|
|
texture->mag_lookup = magLookup_noFilter;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A GL context is provided by the caller */
|
2012-07-24 11:32:27 +02:00
|
|
|
static void gltexture_delete(const struct wined3d_gl_info *gl_info, struct gl_texture *tex)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
static void wined3d_texture_unload(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;
|
2011-03-18 19:10:58 +01:00
|
|
|
struct wined3d_context *context = NULL;
|
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
if (texture->texture_rgb.name || texture->texture_srgb.name)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
}
|
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
if (texture->texture_rgb.name)
|
2012-07-24 11:32:27 +02:00
|
|
|
gltexture_delete(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)
|
2012-07-24 11:32:27 +02:00
|
|
|
gltexture_delete(context->gl_info, &texture->texture_srgb);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
if (context) context_release(context);
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
wined3d_texture_set_dirty(texture, TRUE);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
resource_unload(&texture->resource);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
UINT sub_count = texture->level_count * texture->layer_count;
|
2011-03-18 19:10:58 +01:00
|
|
|
UINT i;
|
|
|
|
|
|
|
|
TRACE("texture %p.\n", texture);
|
|
|
|
|
|
|
|
for (i = 0; i < sub_count; ++i)
|
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
struct wined3d_resource *sub_resource = texture->sub_resources[i];
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
if (sub_resource)
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->texture_ops->texture_sub_resource_cleanup(sub_resource);
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
wined3d_texture_unload(texture);
|
2011-03-28 21:58:42 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, texture->sub_resources);
|
2011-03-18 19:10:58 +01:00
|
|
|
resource_cleanup(&texture->resource);
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
void wined3d_texture_set_dirty(struct wined3d_texture *texture, BOOL dirty)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->texture_rgb.dirty = dirty;
|
|
|
|
texture->texture_srgb.dirty = dirty;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2011-01-04 17:42:03 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2011-03-18 19:10:59 +01:00
|
|
|
static HRESULT wined3d_texture_bind(struct wined3d_texture *texture,
|
2011-07-27 23:21:25 +02:00
|
|
|
struct wined3d_context *context, BOOL srgb, BOOL *set_surface_desc)
|
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;
|
2011-03-18 19:10:58 +01:00
|
|
|
struct gl_texture *gl_tex;
|
|
|
|
BOOL new_texture = FALSE;
|
|
|
|
HRESULT hr = WINED3D_OK;
|
|
|
|
GLenum target;
|
|
|
|
|
2011-07-27 23:21:25 +02:00
|
|
|
TRACE("texture %p, context %p, srgb %#x, set_surface_desc %p.\n", texture, context, srgb, set_surface_desc);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
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;
|
|
|
|
|
2011-07-27 23:21:25 +02:00
|
|
|
gl_tex = wined3d_texture_get_gl_texture(texture, context->gl_info, srgb);
|
2011-03-28 21:58:42 +02:00
|
|
|
target = texture->target;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
/* Generate a texture name if we don't already have one. */
|
|
|
|
if (!gl_tex->name)
|
|
|
|
{
|
|
|
|
*set_surface_desc = TRUE;
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &gl_tex->name);
|
2011-03-18 19:10:58 +01:00
|
|
|
checkGLcall("glGenTextures");
|
|
|
|
TRACE("Generated texture %d.\n", gl_tex->name);
|
2012-01-17 21:13:37 +01:00
|
|
|
if (texture->resource.pool == WINED3D_POOL_DEFAULT)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
/* Tell OpenGL to try and keep this texture in video ram (well mostly). */
|
|
|
|
GLclampf tmp = 0.9f;
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glPrioritizeTextures(1, &gl_tex->name, &tmp);
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
/* Initialise the state of the texture object to the OpenGL defaults,
|
|
|
|
* not the D3D defaults. */
|
2012-01-10 20:37:02 +01:00
|
|
|
gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3D_TADDRESS_WRAP;
|
|
|
|
gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3D_TADDRESS_WRAP;
|
|
|
|
gl_tex->states[WINED3DTEXSTA_ADDRESSW] = WINED3D_TADDRESS_WRAP;
|
2011-03-18 19:10:58 +01:00
|
|
|
gl_tex->states[WINED3DTEXSTA_BORDERCOLOR] = 0;
|
2012-01-12 21:43:12 +01:00
|
|
|
gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3D_TEXF_LINEAR;
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3D_TEXF_POINT; /* GL_NEAREST_MIPMAP_LINEAR */
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3D_TEXF_LINEAR; /* GL_NEAREST_MIPMAP_LINEAR */
|
2011-03-18 19:10:58 +01:00
|
|
|
gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] = 0;
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] = 1;
|
2011-07-27 23:21:25 +02:00
|
|
|
if (context->gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
|
2011-03-18 19:10:58 +01:00
|
|
|
gl_tex->states[WINED3DTEXSTA_SRGBTEXTURE] = TRUE;
|
|
|
|
else
|
|
|
|
gl_tex->states[WINED3DTEXSTA_SRGBTEXTURE] = srgb;
|
|
|
|
gl_tex->states[WINED3DTEXSTA_SHADOW] = FALSE;
|
2011-03-18 19:10:59 +01:00
|
|
|
wined3d_texture_set_dirty(texture, TRUE);
|
2011-03-18 19:10:58 +01:00
|
|
|
new_texture = TRUE;
|
|
|
|
|
|
|
|
if (texture->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP)
|
|
|
|
{
|
|
|
|
/* This means double binding the texture at creation, but keeps
|
|
|
|
* the code simpler all in all, and the run-time path free from
|
|
|
|
* additional checks. */
|
2011-08-26 01:12:26 +02:00
|
|
|
context_bind_texture(context, target, gl_tex->name);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
|
2011-03-18 19:10:58 +01:00
|
|
|
checkGLcall("glTexParameteri(target, GL_GENERATE_MIPMAP_SGIS, GL_TRUE)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*set_surface_desc = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_tex->name)
|
|
|
|
{
|
2011-08-26 01:12:26 +02:00
|
|
|
context_bind_texture(context, target, gl_tex->name);
|
2011-03-18 19:10:58 +01:00
|
|
|
if (new_texture)
|
|
|
|
{
|
|
|
|
/* 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)
|
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
TRACE("Setting GL_TEXTURE_MAX_LEVEL to %u.\n", texture->level_count - 1);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, texture->level_count - 1);
|
2011-03-28 21:58:42 +02:00
|
|
|
checkGLcall("glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, texture->level_count)");
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
if (target == GL_TEXTURE_CUBE_MAP_ARB)
|
|
|
|
{
|
|
|
|
/* Cubemaps are always set to clamp, regardless of the sampler state. */
|
2012-07-24 11:32:27 +02:00
|
|
|
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);
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("This texture doesn't have an OpenGL texture assigned to it.\n");
|
|
|
|
hr = WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2011-03-18 19:10:58 +01:00
|
|
|
static void apply_wrap(const struct wined3d_gl_info *gl_info, GLenum target,
|
2012-01-10 20:37:02 +01:00
|
|
|
enum wined3d_texture_address d3d_wrap, GLenum param, BOOL cond_np2)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
GLint gl_wrap;
|
|
|
|
|
2012-01-10 20:37:02 +01:00
|
|
|
if (d3d_wrap < WINED3D_TADDRESS_WRAP || d3d_wrap > WINED3D_TADDRESS_MIRROR_ONCE)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2012-01-10 20:37:02 +01:00
|
|
|
FIXME("Unrecognized or unsupported texture address mode %#x.\n", d3d_wrap);
|
2011-03-18 19:10:58 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Cubemaps are always set to clamp, regardless of the sampler state. */
|
|
|
|
if (target == GL_TEXTURE_CUBE_MAP_ARB
|
2012-01-10 20:37:02 +01:00
|
|
|
|| (cond_np2 && d3d_wrap == WINED3D_TADDRESS_WRAP))
|
2011-03-18 19:10:58 +01:00
|
|
|
gl_wrap = GL_CLAMP_TO_EDGE;
|
|
|
|
else
|
2012-01-10 20:37:02 +01:00
|
|
|
gl_wrap = gl_info->wrap_lookup[d3d_wrap - WINED3D_TADDRESS_WRAP];
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
TRACE("Setting param %#x to %#x for target %#x.\n", param, gl_wrap, target);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, param, gl_wrap);
|
2011-03-18 19:10:58 +01:00
|
|
|
checkGLcall("glTexParameteri(target, param, gl_wrap)");
|
|
|
|
}
|
|
|
|
|
2012-12-10 21:54:36 +01:00
|
|
|
/* Context activation is done by the caller (state handler). */
|
2011-03-18 19:10:59 +01:00
|
|
|
void wined3d_texture_apply_state_changes(struct wined3d_texture *texture,
|
2011-03-18 19:10:58 +01:00
|
|
|
const DWORD sampler_states[WINED3D_HIGHEST_SAMPLER_STATE + 1],
|
|
|
|
const struct wined3d_gl_info *gl_info)
|
|
|
|
{
|
2011-03-28 21:58:43 +02:00
|
|
|
BOOL cond_np2 = texture->flags & WINED3D_TEXTURE_COND_NP2;
|
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;
|
|
|
|
DWORD aniso;
|
|
|
|
|
|
|
|
TRACE("texture %p, sampler_states %p.\n", texture, sampler_states);
|
|
|
|
|
2011-03-28 21:58:45 +02:00
|
|
|
gl_tex = wined3d_texture_get_gl_texture(texture, gl_info,
|
|
|
|
texture->flags & WINED3D_TEXTURE_IS_SRGB);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
/* This function relies on the correct texture being bound and loaded. */
|
|
|
|
|
2012-01-08 21:14:59 +01:00
|
|
|
if (sampler_states[WINED3D_SAMP_ADDRESS_U] != gl_tex->states[WINED3DTEXSTA_ADDRESSU])
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2012-01-08 21:14:59 +01:00
|
|
|
state = sampler_states[WINED3D_SAMP_ADDRESS_U];
|
2011-03-18 19:10:58 +01:00
|
|
|
apply_wrap(gl_info, target, state, GL_TEXTURE_WRAP_S, cond_np2);
|
|
|
|
gl_tex->states[WINED3DTEXSTA_ADDRESSU] = state;
|
|
|
|
}
|
|
|
|
|
2012-01-08 21:14:59 +01:00
|
|
|
if (sampler_states[WINED3D_SAMP_ADDRESS_V] != gl_tex->states[WINED3DTEXSTA_ADDRESSV])
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2012-01-08 21:14:59 +01:00
|
|
|
state = sampler_states[WINED3D_SAMP_ADDRESS_V];
|
2011-03-18 19:10:58 +01:00
|
|
|
apply_wrap(gl_info, target, state, GL_TEXTURE_WRAP_T, cond_np2);
|
|
|
|
gl_tex->states[WINED3DTEXSTA_ADDRESSV] = state;
|
|
|
|
}
|
|
|
|
|
2012-01-08 21:14:59 +01:00
|
|
|
if (sampler_states[WINED3D_SAMP_ADDRESS_W] != gl_tex->states[WINED3DTEXSTA_ADDRESSW])
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2012-01-08 21:14:59 +01:00
|
|
|
state = sampler_states[WINED3D_SAMP_ADDRESS_W];
|
2011-03-18 19:10:58 +01:00
|
|
|
apply_wrap(gl_info, target, state, GL_TEXTURE_WRAP_R, cond_np2);
|
|
|
|
gl_tex->states[WINED3DTEXSTA_ADDRESSW] = state;
|
|
|
|
}
|
|
|
|
|
2012-01-08 21:14:59 +01:00
|
|
|
if (sampler_states[WINED3D_SAMP_BORDER_COLOR] != gl_tex->states[WINED3DTEXSTA_BORDERCOLOR])
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
float col[4];
|
|
|
|
|
2012-01-08 21:14:59 +01:00
|
|
|
state = sampler_states[WINED3D_SAMP_BORDER_COLOR];
|
2011-03-18 19:10:58 +01:00
|
|
|
D3DCOLORTOGLFLOAT4(state, col);
|
|
|
|
TRACE("Setting border color for %#x to %#x.\n", target, state);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, &col[0]);
|
2011-03-18 19:10:58 +01:00
|
|
|
checkGLcall("glTexParameterfv(..., GL_TEXTURE_BORDER_COLOR, ...)");
|
|
|
|
gl_tex->states[WINED3DTEXSTA_BORDERCOLOR] = state;
|
|
|
|
}
|
|
|
|
|
2012-01-08 21:14:59 +01:00
|
|
|
if (sampler_states[WINED3D_SAMP_MAG_FILTER] != gl_tex->states[WINED3DTEXSTA_MAGFILTER])
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
GLint gl_value;
|
|
|
|
|
2012-01-08 21:14:59 +01:00
|
|
|
state = sampler_states[WINED3D_SAMP_MAG_FILTER];
|
2012-01-12 21:43:12 +01:00
|
|
|
if (state > WINED3D_TEXF_ANISOTROPIC)
|
2011-03-18 19:10:58 +01:00
|
|
|
FIXME("Unrecognized or unsupported MAGFILTER* value %d.\n", state);
|
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
gl_value = wined3d_gl_mag_filter(texture->mag_lookup,
|
2012-01-12 21:43:12 +01:00
|
|
|
min(max(state, WINED3D_TEXF_POINT), WINED3D_TEXF_LINEAR));
|
2011-03-18 19:10:58 +01:00
|
|
|
TRACE("ValueMAG=%#x setting MAGFILTER to %#x.\n", state, gl_value);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAG_FILTER, gl_value);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MAGFILTER] = state;
|
|
|
|
}
|
|
|
|
|
2012-01-08 21:14:59 +01:00
|
|
|
if ((sampler_states[WINED3D_SAMP_MIN_FILTER] != gl_tex->states[WINED3DTEXSTA_MINFILTER]
|
|
|
|
|| sampler_states[WINED3D_SAMP_MIP_FILTER] != gl_tex->states[WINED3DTEXSTA_MIPFILTER]
|
|
|
|
|| sampler_states[WINED3D_SAMP_MAX_MIP_LEVEL] != gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL]))
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
GLint gl_value;
|
|
|
|
|
2012-01-08 21:14:59 +01:00
|
|
|
gl_tex->states[WINED3DTEXSTA_MIPFILTER] = sampler_states[WINED3D_SAMP_MIP_FILTER];
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MINFILTER] = sampler_states[WINED3D_SAMP_MIN_FILTER];
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] = sampler_states[WINED3D_SAMP_MAX_MIP_LEVEL];
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2012-01-12 21:43:12 +01:00
|
|
|
if (gl_tex->states[WINED3DTEXSTA_MINFILTER] > WINED3D_TEXF_ANISOTROPIC
|
|
|
|
|| gl_tex->states[WINED3DTEXSTA_MIPFILTER] > WINED3D_TEXF_ANISOTROPIC)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2012-01-08 21:14:59 +01:00
|
|
|
FIXME("Unrecognized or unsupported MIN_FILTER value %#x MIP_FILTER value %#x.\n",
|
2011-03-18 19:10:58 +01:00
|
|
|
gl_tex->states[WINED3DTEXSTA_MINFILTER],
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MIPFILTER]);
|
|
|
|
}
|
2011-03-28 21:58:42 +02:00
|
|
|
gl_value = wined3d_gl_min_mip_filter(texture->min_mip_lookup,
|
2012-01-12 21:43:12 +01:00
|
|
|
min(max(sampler_states[WINED3D_SAMP_MIN_FILTER], WINED3D_TEXF_POINT), WINED3D_TEXF_LINEAR),
|
|
|
|
min(max(sampler_states[WINED3D_SAMP_MIP_FILTER], WINED3D_TEXF_NONE), WINED3D_TEXF_LINEAR));
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
TRACE("ValueMIN=%#x, ValueMIP=%#x, setting MINFILTER to %#x.\n",
|
2012-01-08 21:14:59 +01:00
|
|
|
sampler_states[WINED3D_SAMP_MIN_FILTER],
|
|
|
|
sampler_states[WINED3D_SAMP_MIP_FILTER], gl_value);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MIN_FILTER, gl_value);
|
2011-03-18 19:10:58 +01:00
|
|
|
checkGLcall("glTexParameter GL_TEXTURE_MIN_FILTER, ...");
|
|
|
|
|
|
|
|
if (!cond_np2)
|
|
|
|
{
|
2012-01-12 21:43:12 +01:00
|
|
|
if (gl_tex->states[WINED3DTEXSTA_MIPFILTER] == WINED3D_TEXF_NONE)
|
2011-03-28 21:58:42 +02:00
|
|
|
gl_value = texture->lod;
|
|
|
|
else if (gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] >= texture->level_count)
|
|
|
|
gl_value = texture->level_count - 1;
|
|
|
|
else if (gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] < texture->lod)
|
|
|
|
/* texture->lod is already clamped in the setter. */
|
|
|
|
gl_value = texture->lod;
|
2011-03-18 19:10:58 +01:00
|
|
|
else
|
|
|
|
gl_value = gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL];
|
|
|
|
|
2012-01-08 21:14:59 +01:00
|
|
|
/* Note that WINED3D_SAMP_MAX_MIP_LEVEL specifies the largest mipmap
|
2011-03-18 19:10:58 +01:00
|
|
|
* (default 0), while GL_TEXTURE_MAX_LEVEL specifies the smallest
|
2012-01-08 21:14:59 +01:00
|
|
|
* mimap used (default 1000). So WINED3D_SAMP_MAX_MIP_LEVEL
|
2011-03-18 19:10:58 +01:00
|
|
|
* corresponds to GL_TEXTURE_BASE_LEVEL. */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, gl_value);
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-12 21:43:12 +01:00
|
|
|
if ((gl_tex->states[WINED3DTEXSTA_MAGFILTER] != WINED3D_TEXF_ANISOTROPIC
|
|
|
|
&& gl_tex->states[WINED3DTEXSTA_MINFILTER] != WINED3D_TEXF_ANISOTROPIC
|
|
|
|
&& gl_tex->states[WINED3DTEXSTA_MIPFILTER] != WINED3D_TEXF_ANISOTROPIC)
|
2011-03-18 19:10:58 +01:00
|
|
|
|| cond_np2)
|
|
|
|
aniso = 1;
|
|
|
|
else
|
2012-01-08 21:14:59 +01:00
|
|
|
aniso = sampler_states[WINED3D_SAMP_MAX_ANISOTROPY];
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
if (gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] != aniso)
|
|
|
|
{
|
|
|
|
if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso);
|
2011-03-18 19:10:58 +01:00
|
|
|
checkGLcall("glTexParameteri(GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso)");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Anisotropic filtering not supported.\n");
|
|
|
|
}
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] = aniso;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* These should always be the same unless EXT_texture_sRGB_decode is supported. */
|
2012-01-08 21:14:59 +01:00
|
|
|
if (sampler_states[WINED3D_SAMP_SRGB_TEXTURE] != gl_tex->states[WINED3DTEXSTA_SRGBTEXTURE])
|
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,
|
2012-01-08 21:14:59 +01:00
|
|
|
sampler_states[WINED3D_SAMP_SRGB_TEXTURE] ? GL_DECODE_EXT : GL_SKIP_DECODE_EXT);
|
2011-03-18 19:10:58 +01:00
|
|
|
checkGLcall("glTexParameteri(GL_TEXTURE_SRGB_DECODE_EXT)");
|
2012-01-08 21:14:59 +01:00
|
|
|
gl_tex->states[WINED3DTEXSTA_SRGBTEXTURE] = sampler_states[WINED3D_SAMP_SRGB_TEXTURE];
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(texture->resource.format->flags & WINED3DFMT_FLAG_SHADOW)
|
|
|
|
!= !gl_tex->states[WINED3DTEXSTA_SHADOW])
|
|
|
|
{
|
|
|
|
if (texture->resource.format->flags & WINED3DFMT_FLAG_SHADOW)
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);
|
|
|
|
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
|
|
|
checkGLcall("glTexParameteri(target, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB)");
|
|
|
|
gl_tex->states[WINED3DTEXSTA_SHADOW] = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
|
2011-03-18 19:10:58 +01:00
|
|
|
checkGLcall("glTexParameteri(target, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE)");
|
|
|
|
gl_tex->states[WINED3DTEXSTA_SHADOW] = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
ULONG refcount = InterlockedIncrement(&texture->resource.ref);
|
|
|
|
|
|
|
|
TRACE("%p increasing refcount to %u.\n", texture, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
ULONG refcount = InterlockedDecrement(&texture->resource.ref);
|
|
|
|
|
|
|
|
TRACE("%p decreasing refcount to %u.\n", texture, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
2011-03-18 19:10:59 +01:00
|
|
|
wined3d_texture_cleanup(texture);
|
2011-03-18 19:10:58 +01:00
|
|
|
texture->resource.parent_ops->wined3d_object_destroyed(texture->resource.parent);
|
|
|
|
HeapFree(GetProcessHeap(), 0, texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
DWORD CDECL wined3d_texture_set_priority(struct wined3d_texture *texture, DWORD priority)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2011-03-18 19:10:59 +01:00
|
|
|
return resource_set_priority(&texture->resource, priority);
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
DWORD CDECL wined3d_texture_get_priority(const struct wined3d_texture *texture)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2011-03-18 19:10:59 +01:00
|
|
|
return resource_get_priority(&texture->resource);
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
void CDECL wined3d_texture_preload(struct wined3d_texture *texture)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->texture_ops->texture_preload(texture, SRGB_ANY);
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->lod = lod;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->texture_rgb.states[WINED3DTEXSTA_MAXMIPLEVEL] = ~0U;
|
|
|
|
texture->texture_srgb.states[WINED3DTEXSTA_MAXMIPLEVEL] = ~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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
struct wined3d_resource * CDECL wined3d_texture_get_sub_resource(struct wined3d_texture *texture,
|
2011-03-18 19:10:58 +01:00
|
|
|
UINT sub_resource_idx)
|
|
|
|
{
|
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
|
|
|
|
2011-03-28 21:58:42 +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
|
|
|
{
|
|
|
|
struct wined3d_resource *sub_resource;
|
|
|
|
|
|
|
|
TRACE("texture %p, layer %u, dirty_region %p.\n", texture, layer, dirty_region);
|
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
if (!(sub_resource = wined3d_texture_get_sub_resource(texture, layer * texture->level_count)))
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
WARN("Failed to get sub-resource.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
wined3d_texture_set_dirty(texture, TRUE);
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->texture_ops->texture_sub_resource_add_dirty_region(sub_resource, dirty_region);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
2011-03-18 19:10:59 +01:00
|
|
|
static HRESULT texture2d_bind(struct wined3d_texture *texture,
|
2011-07-27 23:21:25 +02:00
|
|
|
struct wined3d_context *context, BOOL srgb)
|
2011-01-04 17:42:03 +01:00
|
|
|
{
|
2012-07-24 11:32:27 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2011-01-04 17:42:03 +01:00
|
|
|
BOOL set_gl_texture_desc;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2011-07-27 23:21:25 +02:00
|
|
|
TRACE("texture %p, context %p, srgb %#x.\n", texture, context, srgb);
|
2011-01-04 17:42:03 +01:00
|
|
|
|
2011-07-27 23:21:25 +02:00
|
|
|
hr = wined3d_texture_bind(texture, context, srgb, &set_gl_texture_desc);
|
2011-01-04 17:42:03 +01:00
|
|
|
if (set_gl_texture_desc && SUCCEEDED(hr))
|
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
UINT sub_count = texture->level_count * texture->layer_count;
|
2011-07-27 23:21:25 +02:00
|
|
|
BOOL srgb_tex = !context->gl_info->supported[EXT_TEXTURE_SRGB_DECODE]
|
2011-03-28 21:58:45 +02:00
|
|
|
&& (texture->flags & WINED3D_TEXTURE_IS_SRGB);
|
2011-01-04 17:42:03 +01:00
|
|
|
struct gl_texture *gl_tex;
|
2011-03-03 09:24:10 +01:00
|
|
|
UINT i;
|
2011-01-04 17:42:03 +01:00
|
|
|
|
2011-07-27 23:21:25 +02:00
|
|
|
gl_tex = wined3d_texture_get_gl_texture(texture, context->gl_info, srgb_tex);
|
2011-01-04 17:42:03 +01:00
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
for (i = 0; i < sub_count; ++i)
|
2011-01-04 17:42:03 +01:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *surface = surface_from_resource(texture->sub_resources[i]);
|
2011-03-03 09:24:10 +01:00
|
|
|
surface_set_texture_name(surface, gl_tex->name, srgb_tex);
|
2011-01-04 17:42:03 +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. */
|
2011-03-28 21:58:43 +02:00
|
|
|
if (texture->flags & WINED3D_TEXTURE_COND_NP2)
|
2011-01-04 17:42:03 +01:00
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
GLenum target = texture->target;
|
2011-01-04 17:42:03 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
2011-01-04 17:42:03 +01:00
|
|
|
checkGLcall("glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)");
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2011-01-04 17:42:03 +01:00
|
|
|
checkGLcall("glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)");
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
2011-01-04 17:42:03 +01:00
|
|
|
checkGLcall("glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)");
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
2011-01-04 17:42:03 +01:00
|
|
|
checkGLcall("glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)");
|
2012-01-10 20:37:02 +01:00
|
|
|
gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3D_TADDRESS_CLAMP;
|
|
|
|
gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3D_TADDRESS_CLAMP;
|
2012-01-12 21:43:12 +01:00
|
|
|
gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3D_TEXF_POINT;
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3D_TEXF_POINT;
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3D_TEXF_NONE;
|
2011-01-04 17:42:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-07-15 01:14:52 +02:00
|
|
|
static BOOL texture_srgb_mode(const struct wined3d_texture *texture, enum WINED3DSRGB srgb)
|
2011-05-18 22:30:17 +02:00
|
|
|
{
|
|
|
|
switch (srgb)
|
|
|
|
{
|
|
|
|
case SRGB_RGB:
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
case SRGB_SRGB:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return texture->flags & WINED3D_TEXTURE_IS_SRGB;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
static void texture2d_preload(struct wined3d_texture *texture, enum WINED3DSRGB srgb)
|
2009-06-03 10:47:25 +02:00
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
UINT sub_count = texture->level_count * texture->layer_count;
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_device *device = texture->resource.device;
|
2011-03-03 09:24:10 +01:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context = NULL;
|
2011-03-03 09:24:08 +01:00
|
|
|
struct gl_texture *gl_tex;
|
2009-06-03 10:47:25 +02:00
|
|
|
BOOL srgb_mode;
|
2011-03-18 19:10:58 +01:00
|
|
|
UINT i;
|
2009-06-03 10:47:25 +02:00
|
|
|
|
2011-01-03 18:51:41 +01:00
|
|
|
TRACE("texture %p, srgb %#x.\n", texture, srgb);
|
2009-06-03 10:47:25 +02:00
|
|
|
|
2011-05-18 22:30:17 +02:00
|
|
|
srgb_mode = texture_srgb_mode(texture, srgb);
|
2011-03-18 19:10:59 +01:00
|
|
|
gl_tex = wined3d_texture_get_gl_texture(texture, gl_info, srgb_mode);
|
2009-06-03 10:47:25 +02:00
|
|
|
|
|
|
|
if (!device->isInDraw)
|
|
|
|
{
|
2011-03-18 19:10:58 +01:00
|
|
|
/* No danger of recursive calls, context_acquire() sets isInDraw to TRUE
|
|
|
|
* when loading offscreen render targets into the texture. */
|
2010-05-03 22:03:28 +02:00
|
|
|
context = context_acquire(device, NULL);
|
2009-06-03 10:47:25 +02:00
|
|
|
}
|
|
|
|
|
2011-03-03 09:24:08 +01:00
|
|
|
if (gl_tex->dirty)
|
2009-06-03 10:47:25 +02:00
|
|
|
{
|
2011-03-18 19:10:58 +01:00
|
|
|
/* Reload the surfaces if the texture is marked dirty. */
|
|
|
|
for (i = 0; i < sub_count; ++i)
|
2009-06-03 10:47:25 +02:00
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
surface_load(surface_from_resource(texture->sub_resources[i]), srgb_mode);
|
2009-06-03 10:47:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-03 18:51:41 +01:00
|
|
|
TRACE("Texture %p not dirty, nothing to do.\n", texture);
|
2009-06-03 10:47:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* No longer dirty. */
|
2011-03-03 09:24:08 +01:00
|
|
|
gl_tex->dirty = FALSE;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
if (context) context_release(context);
|
2009-06-03 10:47:25 +02:00
|
|
|
}
|
2005-01-17 14:44:57 +01:00
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
static void texture2d_sub_resource_add_dirty_region(struct wined3d_resource *sub_resource,
|
2011-12-06 22:57:47 +01:00
|
|
|
const struct wined3d_box *dirty_region)
|
2011-03-17 23:15:11 +01:00
|
|
|
{
|
|
|
|
surface_add_dirty_rect(surface_from_resource(sub_resource), dirty_region);
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
static void texture2d_sub_resource_cleanup(struct wined3d_resource *sub_resource)
|
2011-03-17 23:15:12 +01:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *surface = surface_from_resource(sub_resource);
|
2011-03-17 23:15:12 +01:00
|
|
|
|
|
|
|
/* Clean out the texture name we gave to the surface so that the
|
2011-03-18 19:10:58 +01:00
|
|
|
* surface doesn't try and release it. */
|
2011-03-17 23:15:12 +01:00
|
|
|
surface_set_texture_name(surface, 0, TRUE);
|
|
|
|
surface_set_texture_name(surface, 0, FALSE);
|
2012-10-23 21:01:05 +02:00
|
|
|
surface_set_texture_target(surface, 0, 0);
|
2013-06-03 09:19:35 +02:00
|
|
|
surface_set_container(surface, NULL);
|
2011-04-29 13:03:41 +02:00
|
|
|
wined3d_surface_decref(surface);
|
2011-03-17 23:15:12 +01:00
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
static void texture2d_unload(struct wined3d_resource *resource)
|
2011-02-28 08:05:39 +01:00
|
|
|
{
|
2011-03-18 19:10:59 +01:00
|
|
|
struct wined3d_texture *texture = wined3d_texture_from_resource(resource);
|
2011-03-28 21:58:42 +02:00
|
|
|
UINT sub_count = texture->level_count * texture->layer_count;
|
2011-03-18 19:10:58 +01:00
|
|
|
UINT i;
|
2011-02-28 08:05:39 +01:00
|
|
|
|
|
|
|
TRACE("texture %p.\n", texture);
|
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
for (i = 0; i < sub_count; ++i)
|
2011-02-28 08:05:39 +01:00
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
struct wined3d_resource *sub_resource = texture->sub_resources[i];
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *surface = surface_from_resource(sub_resource);
|
2011-02-28 08:05:39 +01:00
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
sub_resource->resource_ops->resource_unload(sub_resource);
|
2011-03-18 19:10:58 +01:00
|
|
|
surface_set_texture_name(surface, 0, FALSE); /* Delete RGB name */
|
|
|
|
surface_set_texture_name(surface, 0, TRUE); /* Delete sRGB name */
|
2011-02-28 08:05:39 +01:00
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
wined3d_texture_unload(texture);
|
2011-02-28 08:05:39 +01:00
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
static const struct wined3d_texture_ops texture2d_ops =
|
2011-01-07 10:16:39 +01:00
|
|
|
{
|
2011-03-18 19:10:58 +01:00
|
|
|
texture2d_bind,
|
|
|
|
texture2d_preload,
|
|
|
|
texture2d_sub_resource_add_dirty_region,
|
|
|
|
texture2d_sub_resource_cleanup,
|
|
|
|
};
|
2005-01-17 14:44:57 +01:00
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
static const struct wined3d_resource_ops texture2d_resource_ops =
|
2011-01-03 18:51:41 +01:00
|
|
|
{
|
2011-03-18 19:10:58 +01:00
|
|
|
texture2d_unload,
|
|
|
|
};
|
2009-02-17 00:25:51 +01:00
|
|
|
|
2013-06-05 11:06:12 +02:00
|
|
|
static HRESULT cubetexture_init(struct wined3d_texture *texture, const struct wined3d_resource_desc *desc,
|
2013-06-06 10:51:47 +02:00
|
|
|
UINT levels, DWORD surface_flags, struct wined3d_device *device, void *parent,
|
|
|
|
const struct wined3d_parent_ops *parent_ops)
|
2011-01-07 10:16:41 +01:00
|
|
|
{
|
2011-03-18 19:10:58 +01:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2013-06-05 11:06:12 +02:00
|
|
|
struct wined3d_resource_desc surface_desc;
|
2011-03-18 19:10:58 +01:00
|
|
|
unsigned int i, j;
|
|
|
|
HRESULT hr;
|
2005-01-17 14:44:57 +01:00
|
|
|
|
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-05 11:06:12 +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;
|
|
|
|
}
|
2010-08-31 18:41:40 +02:00
|
|
|
|
2013-06-05 11:06:12 +02:00
|
|
|
if (!gl_info->supported[ARB_TEXTURE_CUBE_MAP] && desc->pool != WINED3D_POOL_SCRATCH)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
WARN("(%p) : Tried to create not supported cube texture.\n", texture);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2005-01-17 14:44:57 +01:00
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
/* Calculate levels for mip mapping */
|
2013-06-05 11:06:12 +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;
|
|
|
|
}
|
2005-01-17 14:44:57 +01:00
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
if (levels > 1)
|
|
|
|
{
|
|
|
|
WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2005-01-17 14:44:57 +01:00
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
levels = 1;
|
|
|
|
}
|
|
|
|
else if (!levels)
|
|
|
|
{
|
2013-06-05 11:06:12 +02:00
|
|
|
levels = wined3d_log2i(desc->width) + 1;
|
2011-03-18 19:10:58 +01:00
|
|
|
TRACE("Calculated levels = %u.\n", levels);
|
|
|
|
}
|
2005-01-17 14:44:57 +01:00
|
|
|
|
2013-04-16 14:48:32 +02:00
|
|
|
if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
|
|
|
|
{
|
|
|
|
UINT pow2_edge_length = 1;
|
2013-06-05 11:06:12 +02:00
|
|
|
while (pow2_edge_length < desc->width)
|
|
|
|
pow2_edge_length <<= 1;
|
2013-04-16 14:48:32 +02:00
|
|
|
|
2013-06-05 11:06:12 +02:00
|
|
|
if (desc->width != pow2_edge_length)
|
2013-04-16 14:48:32 +02:00
|
|
|
{
|
2013-06-05 11:06:12 +02:00
|
|
|
if (desc->pool == WINED3D_POOL_SCRATCH)
|
2013-04-16 14:48:32 +02:00
|
|
|
{
|
|
|
|
/* SCRATCH textures cannot be used for texturing */
|
|
|
|
WARN("Creating a scratch NPOT cube texture despite lack of HW support.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-05 11:06:12 +02:00
|
|
|
WARN("Attempted to create a NPOT cube texture (edge length %u) without GL support.\n", desc->width);
|
2013-04-16 14:48:32 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-05 11:06:10 +02:00
|
|
|
if (FAILED(hr = wined3d_texture_init(texture, &texture2d_ops, 6, levels,
|
2013-06-05 11:06:12 +02:00
|
|
|
desc, device, parent, parent_ops, &texture2d_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;
|
|
|
|
}
|
2005-01-17 14:44:57 +01:00
|
|
|
|
2013-04-16 14:48:32 +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;
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->target = GL_TEXTURE_CUBE_MAP_ARB;
|
2010-04-22 18:55:59 +02:00
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
/* Generate all the surfaces. */
|
2013-06-05 11:06:12 +02:00
|
|
|
surface_desc = *desc;
|
|
|
|
surface_desc.resource_type = WINED3D_RTYPE_SURFACE;
|
2011-03-28 21:58:42 +02:00
|
|
|
for (i = 0; i < texture->level_count; ++i)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
/* Create the 6 faces. */
|
|
|
|
for (j = 0; j < 6; ++j)
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
};
|
2011-03-28 21:58:42 +02:00
|
|
|
UINT idx = j * texture->level_count + i;
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *surface;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2012-10-24 21:23:36 +02:00
|
|
|
if (FAILED(hr = device->device_parent->ops->create_texture_surface(device->device_parent,
|
2013-06-06 10:51:47 +02:00
|
|
|
parent, &surface_desc, idx, surface_flags, &surface)))
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
FIXME("(%p) Failed to create surface, hr %#x.\n", texture, hr);
|
2011-03-18 19:10:59 +01:00
|
|
|
wined3d_texture_cleanup(texture);
|
2011-03-18 19:10:58 +01:00
|
|
|
return hr;
|
|
|
|
}
|
2010-04-22 18:55:59 +02:00
|
|
|
|
2013-06-03 09:19:35 +02:00
|
|
|
surface_set_container(surface, texture);
|
2012-10-23 21:01:05 +02:00
|
|
|
surface_set_texture_target(surface, cube_targets[j], i);
|
2011-04-29 13:03:42 +02:00
|
|
|
texture->sub_resources[idx] = &surface->resource;
|
2011-03-18 19:10:58 +01:00
|
|
|
TRACE("Created surface level %u @ %p.\n", i, surface);
|
|
|
|
}
|
2013-06-05 11:06:12 +02:00
|
|
|
surface_desc.width = max(1, surface_desc.width >> 1);
|
|
|
|
surface_desc.height = surface_desc.width;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
2005-01-17 14:44:57 +01:00
|
|
|
|
2011-03-18 19:10:58 +01:00
|
|
|
return WINED3D_OK;
|
2005-01-17 14:44:57 +01:00
|
|
|
}
|
|
|
|
|
2013-06-05 11:06:11 +02:00
|
|
|
static HRESULT texture_init(struct wined3d_texture *texture, const struct wined3d_resource_desc *desc,
|
2013-06-06 10:51:47 +02:00
|
|
|
UINT levels, DWORD surface_flags, struct wined3d_device *device, void *parent,
|
|
|
|
const struct wined3d_parent_ops *parent_ops)
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
2013-06-05 11:06:11 +02:00
|
|
|
struct wined3d_resource_desc surface_desc;
|
2009-09-16 08:37:21 +02:00
|
|
|
UINT pow2_width, pow2_height;
|
|
|
|
unsigned int i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Non-power2 support. */
|
|
|
|
if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
|
|
|
|
{
|
2013-06-05 11:06:11 +02:00
|
|
|
pow2_width = desc->width;
|
|
|
|
pow2_height = desc->height;
|
2009-09-16 08:37:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Find the nearest pow2 match. */
|
|
|
|
pow2_width = pow2_height = 1;
|
2013-06-05 11:06:11 +02:00
|
|
|
while (pow2_width < desc->width)
|
|
|
|
pow2_width <<= 1;
|
|
|
|
while (pow2_height < desc->height)
|
|
|
|
pow2_height <<= 1;
|
2009-09-16 08:37:21 +02:00
|
|
|
|
2013-06-05 11:06:11 +02:00
|
|
|
if (pow2_width != desc->width || pow2_height != desc->height)
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
2013-04-16 14:48:32 +02:00
|
|
|
/* levels == 0 returns an error as well */
|
|
|
|
if (levels != 1)
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
2013-06-05 11:06:11 +02:00
|
|
|
if (desc->pool == WINED3D_POOL_SCRATCH)
|
2013-04-16 14:48:32 +02:00
|
|
|
{
|
|
|
|
WARN("Creating a scratch mipmapped NPOT texture despite lack of HW support.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Attempted to create a mipmapped NPOT texture without unconditional NPOT support.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (levels > 1)
|
|
|
|
{
|
|
|
|
WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning WINED3DERR_INVALIDCALL.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
levels = 1;
|
|
|
|
}
|
|
|
|
else if (!levels)
|
|
|
|
{
|
2013-06-05 11:06:11 +02:00
|
|
|
levels = wined3d_log2i(max(desc->width, desc->height)) + 1;
|
2009-09-16 08:37:21 +02:00
|
|
|
TRACE("Calculated levels = %u.\n", levels);
|
|
|
|
}
|
|
|
|
|
2013-06-05 11:06:10 +02:00
|
|
|
if (FAILED(hr = wined3d_texture_init(texture, &texture2d_ops, 1, levels,
|
2013-06-05 11:06:11 +02:00
|
|
|
desc, device, parent, parent_ops, &texture2d_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. */
|
2013-06-05 11:06:11 +02:00
|
|
|
if (gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT]
|
|
|
|
&& (desc->width != pow2_width || desc->height != pow2_height))
|
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;
|
|
|
|
texture->pow2_matrix[10] = 1.0f;
|
|
|
|
texture->pow2_matrix[15] = 1.0f;
|
|
|
|
texture->target = GL_TEXTURE_2D;
|
2011-03-28 21:58:43 +02:00
|
|
|
texture->flags |= WINED3D_TEXTURE_COND_NP2;
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->min_mip_lookup = minMipLookup_noFilter;
|
2009-09-16 08:37:21 +02:00
|
|
|
}
|
2013-08-28 10:09:57 +02:00
|
|
|
else if (gl_info->supported[ARB_TEXTURE_RECTANGLE]
|
|
|
|
&& (desc->width != pow2_width || desc->height != pow2_height))
|
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;
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->pow2_matrix[10] = 1.0f;
|
|
|
|
texture->pow2_matrix[15] = 1.0f;
|
|
|
|
texture->target = GL_TEXTURE_RECTANGLE_ARB;
|
2011-03-28 21:58:43 +02:00
|
|
|
texture->flags |= WINED3D_TEXTURE_COND_NP2;
|
2013-04-12 14:12:40 +02:00
|
|
|
texture->flags &= ~WINED3D_TEXTURE_POW2_MAT_IDENT;
|
2009-09-16 08:37:21 +02:00
|
|
|
|
2010-11-12 13:12:05 +01:00
|
|
|
if (texture->resource.format->flags & WINED3DFMT_FLAG_FILTERING)
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->min_mip_lookup = minMipLookup_noMip;
|
2009-09-16 08:37:21 +02:00
|
|
|
else
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->min_mip_lookup = minMipLookup_noFilter;
|
2009-09-16 08:37:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-05 11:06:11 +02:00
|
|
|
if ((desc->width != pow2_width) || (desc->height != pow2_height))
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
2013-06-05 11:06:11 +02:00
|
|
|
texture->pow2_matrix[0] = (((float)desc->width) / ((float)pow2_width));
|
|
|
|
texture->pow2_matrix[5] = (((float)desc->height) / ((float)pow2_height));
|
2011-03-28 21:58:44 +02:00
|
|
|
texture->flags &= ~WINED3D_TEXTURE_POW2_MAT_IDENT;
|
2009-09-16 08:37:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->pow2_matrix[0] = 1.0f;
|
|
|
|
texture->pow2_matrix[5] = 1.0f;
|
2009-09-16 08:37:21 +02:00
|
|
|
}
|
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
texture->pow2_matrix[10] = 1.0f;
|
|
|
|
texture->pow2_matrix[15] = 1.0f;
|
|
|
|
texture->target = GL_TEXTURE_2D;
|
2009-09-16 08:37:21 +02:00
|
|
|
}
|
2011-03-28 21:58:42 +02:00
|
|
|
TRACE("xf(%f) yf(%f)\n", texture->pow2_matrix[0], texture->pow2_matrix[5]);
|
2009-09-16 08:37:21 +02:00
|
|
|
|
|
|
|
/* Generate all the surfaces. */
|
2013-06-05 11:06:11 +02:00
|
|
|
surface_desc = *desc;
|
|
|
|
surface_desc.resource_type = WINED3D_RTYPE_SURFACE;
|
2011-03-28 21:58:42 +02:00
|
|
|
for (i = 0; i < texture->level_count; ++i)
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *surface;
|
2010-04-22 18:55:57 +02:00
|
|
|
|
2009-09-16 08:37:21 +02:00
|
|
|
/* Use the callback to create the texture surface. */
|
2012-10-24 21:23:36 +02:00
|
|
|
if (FAILED(hr = device->device_parent->ops->create_texture_surface(device->device_parent,
|
2013-06-06 10:51:47 +02:00
|
|
|
parent, &surface_desc, i, surface_flags, &surface)))
|
2009-09-16 08:37:21 +02:00
|
|
|
{
|
|
|
|
FIXME("Failed to create surface %p, hr %#x\n", texture, hr);
|
2011-03-18 19:10:59 +01:00
|
|
|
wined3d_texture_cleanup(texture);
|
2009-09-16 08:37:21 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2013-06-03 09:19:35 +02:00
|
|
|
surface_set_container(surface, texture);
|
2012-10-23 21:01:05 +02:00
|
|
|
surface_set_texture_target(surface, texture->target, i);
|
2011-04-29 13:03:42 +02:00
|
|
|
texture->sub_resources[i] = &surface->resource;
|
2010-04-22 18:55:57 +02:00
|
|
|
TRACE("Created surface level %u @ %p.\n", i, surface);
|
2009-09-16 08:37:21 +02:00
|
|
|
/* Calculate the next mipmap level. */
|
2013-06-05 11:06:11 +02:00
|
|
|
surface_desc.width = max(1, surface_desc.width >> 1);
|
|
|
|
surface_desc.height = max(1, surface_desc.height >> 1);
|
2009-09-16 08:37:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
/* Context activation is done by the caller. */
|
2011-03-18 19:10:59 +01:00
|
|
|
static HRESULT texture3d_bind(struct wined3d_texture *texture,
|
2011-07-27 23:21:25 +02:00
|
|
|
struct wined3d_context *context, BOOL srgb)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
BOOL dummy;
|
|
|
|
|
2011-07-27 23:21:25 +02:00
|
|
|
TRACE("texture %p, context %p, srgb %#x.\n", texture, context, srgb);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2011-07-27 23:21:25 +02:00
|
|
|
return wined3d_texture_bind(texture, context, srgb, &dummy);
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
static void texture3d_preload(struct wined3d_texture *texture, enum WINED3DSRGB srgb)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2013-08-26 02:01:29 +02:00
|
|
|
UINT sub_count = texture->level_count * texture->layer_count;
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_device *device = texture->resource.device;
|
2013-08-26 02:01:29 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
struct wined3d_context *context = NULL;
|
|
|
|
struct gl_texture *gl_tex;
|
|
|
|
BOOL srgb_mode;
|
|
|
|
UINT i;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
TRACE("texture %p, srgb %#x.\n", texture, srgb);
|
|
|
|
|
2013-08-26 02:01:29 +02:00
|
|
|
srgb_mode = texture_srgb_mode(texture, srgb);
|
|
|
|
gl_tex = wined3d_texture_get_gl_texture(texture, gl_info, srgb_mode);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2013-08-26 02:01:29 +02:00
|
|
|
if (gl_tex->dirty)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2013-08-26 02:01:29 +02:00
|
|
|
context = context_acquire(device, NULL);
|
|
|
|
|
|
|
|
/* Reload the surfaces if the texture is marked dirty. */
|
|
|
|
for (i = 0; i < sub_count; ++i)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2013-08-22 14:57:54 +02:00
|
|
|
wined3d_volume_load(volume_from_resource(texture->sub_resources[i]), context,
|
2013-08-26 02:01:29 +02:00
|
|
|
srgb_mode);
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
2013-08-26 02:01:29 +02:00
|
|
|
|
|
|
|
context_release(context);
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Texture %p not dirty, nothing to do.\n", texture);
|
|
|
|
}
|
|
|
|
|
2013-08-26 02:01:29 +02:00
|
|
|
/* No longer dirty. */
|
|
|
|
gl_tex->dirty = FALSE;
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void texture3d_sub_resource_add_dirty_region(struct wined3d_resource *sub_resource,
|
2011-12-06 22:57:47 +01:00
|
|
|
const struct wined3d_box *dirty_region)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void texture3d_sub_resource_cleanup(struct wined3d_resource *sub_resource)
|
|
|
|
{
|
2011-04-14 22:41:48 +02:00
|
|
|
struct wined3d_volume *volume = volume_from_resource(sub_resource);
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
/* Cleanup the container. */
|
|
|
|
volume_set_container(volume, NULL);
|
2011-04-14 22:41:47 +02:00
|
|
|
wined3d_volume_decref(volume);
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void texture3d_unload(struct wined3d_resource *resource)
|
|
|
|
{
|
2011-03-18 19:10:59 +01:00
|
|
|
struct wined3d_texture *texture = wined3d_texture_from_resource(resource);
|
2011-03-18 19:10:58 +01:00
|
|
|
UINT i;
|
|
|
|
|
|
|
|
TRACE("texture %p.\n", texture);
|
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
for (i = 0; i < texture->level_count; ++i)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2011-03-28 21:58:42 +02:00
|
|
|
struct wined3d_resource *sub_resource = texture->sub_resources[i];
|
2011-03-18 19:10:58 +01:00
|
|
|
sub_resource->resource_ops->resource_unload(sub_resource);
|
|
|
|
}
|
|
|
|
|
2011-03-18 19:10:59 +01:00
|
|
|
wined3d_texture_unload(texture);
|
2011-03-18 19:10:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wined3d_texture_ops texture3d_ops =
|
|
|
|
{
|
|
|
|
texture3d_bind,
|
|
|
|
texture3d_preload,
|
|
|
|
texture3d_sub_resource_add_dirty_region,
|
|
|
|
texture3d_sub_resource_cleanup,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct wined3d_resource_ops texture3d_resource_ops =
|
|
|
|
{
|
|
|
|
texture3d_unload,
|
|
|
|
};
|
|
|
|
|
2013-06-06 10:51:46 +02:00
|
|
|
static HRESULT volumetexture_init(struct wined3d_texture *texture, const struct wined3d_resource_desc *desc,
|
|
|
|
UINT levels, struct wined3d_device *device, void *parent, const struct wined3d_parent_ops *parent_ops)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
UINT tmp_w, tmp_h, tmp_d;
|
|
|
|
unsigned int i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (levels > 1)
|
|
|
|
{
|
|
|
|
WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
levels = 1;
|
|
|
|
}
|
|
|
|
else if (!levels)
|
|
|
|
{
|
2013-06-06 10:51:46 +02:00
|
|
|
levels = wined3d_log2i(max(max(desc->width, desc->height), desc->depth)) + 1;
|
2011-03-18 19:10:58 +01:00
|
|
|
TRACE("Calculated levels = %u.\n", levels);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-05 11:06:10 +02:00
|
|
|
if (FAILED(hr = wined3d_texture_init(texture, &texture3d_ops, 1, levels,
|
2013-06-06 10:51:46 +02:00
|
|
|
desc, device, parent, parent_ops, &texture3d_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
|
|
|
|
|
|
|
/* Generate all the surfaces. */
|
2013-06-06 10:51:46 +02:00
|
|
|
tmp_w = desc->width;
|
|
|
|
tmp_h = desc->height;
|
|
|
|
tmp_d = desc->depth;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
2011-03-28 21:58:42 +02:00
|
|
|
for (i = 0; i < texture->level_count; ++i)
|
2011-03-18 19:10:58 +01:00
|
|
|
{
|
2011-04-14 22:41:48 +02:00
|
|
|
struct wined3d_volume *volume;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
/* Create the volume. */
|
2011-05-18 22:30:13 +02:00
|
|
|
hr = device->device_parent->ops->create_volume(device->device_parent, parent,
|
2013-08-22 14:57:54 +02:00
|
|
|
tmp_w, tmp_h, tmp_d, i, desc->format, desc->pool, desc->usage, &volume);
|
2011-03-18 19:10:58 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Creating a volume for the volume texture failed, hr %#x.\n", hr);
|
2011-03-18 19:10:59 +01:00
|
|
|
wined3d_texture_cleanup(texture);
|
2011-03-18 19:10:58 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set its container to this texture. */
|
2011-04-14 22:41:48 +02:00
|
|
|
volume_set_container(volume, texture);
|
|
|
|
texture->sub_resources[i] = &volume->resource;
|
2011-03-18 19:10:58 +01:00
|
|
|
|
|
|
|
/* Calculate the next mipmap level. */
|
|
|
|
tmp_w = max(1, tmp_w >> 1);
|
|
|
|
tmp_h = max(1, tmp_h >> 1);
|
|
|
|
tmp_d = max(1, tmp_d >> 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2013-06-05 11:06:11 +02:00
|
|
|
HRESULT CDECL wined3d_texture_create_2d(struct wined3d_device *device, const struct wined3d_resource_desc *desc,
|
2013-06-06 10:51:47 +02:00
|
|
|
UINT level_count, DWORD surface_flags, 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;
|
|
|
|
|
2013-06-06 10:51:47 +02:00
|
|
|
TRACE("device %p, desc %p, level_count %u, surface_flags %#x, parent %p, parent_ops %p, texture %p.\n",
|
|
|
|
device, desc, level_count, surface_flags, parent, parent_ops, texture);
|
2011-05-10 21:18:47 +02:00
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
*texture = NULL;
|
|
|
|
return WINED3DERR_OUTOFVIDEOMEMORY;
|
|
|
|
}
|
|
|
|
|
2013-06-06 10:51:47 +02:00
|
|
|
if (FAILED(hr = texture_init(object, desc, level_count, surface_flags, device, parent, parent_ops)))
|
2011-05-10 21:18:47 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to initialize texture, returning %#x.\n", hr);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
*texture = NULL;
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created texture %p.\n", object);
|
|
|
|
*texture = object;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-06 10:51:46 +02:00
|
|
|
HRESULT CDECL wined3d_texture_create_3d(struct wined3d_device *device, const struct wined3d_resource_desc *desc,
|
|
|
|
UINT level_count, 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;
|
|
|
|
|
2013-06-06 10:51:46 +02:00
|
|
|
TRACE("device %p, desc %p, level_count %u, parent %p, parent_ops %p, texture %p.\n",
|
|
|
|
device, desc, level_count, parent, parent_ops, texture);
|
2011-05-10 21:18:47 +02:00
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
*texture = NULL;
|
|
|
|
return WINED3DERR_OUTOFVIDEOMEMORY;
|
|
|
|
}
|
|
|
|
|
2013-06-06 10:51:46 +02:00
|
|
|
if (FAILED(hr = volumetexture_init(object, desc, level_count, device, parent, parent_ops)))
|
2011-05-10 21:18:47 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to initialize volumetexture, returning %#x\n", hr);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
*texture = NULL;
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created texture %p.\n", object);
|
|
|
|
*texture = object;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-05 11:06:12 +02:00
|
|
|
HRESULT CDECL wined3d_texture_create_cube(struct wined3d_device *device, const struct wined3d_resource_desc *desc,
|
2013-06-06 10:51:47 +02:00
|
|
|
UINT level_count, DWORD surface_flags, 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;
|
|
|
|
|
2013-06-06 10:51:47 +02:00
|
|
|
TRACE("device %p, desc %p, level_count %u, surface_flags %#x, parent %p, parent_ops %p, texture %p.\n",
|
|
|
|
device, desc, level_count, surface_flags, parent, parent_ops, texture);
|
2011-05-10 21:18:47 +02:00
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
*texture = NULL;
|
|
|
|
return WINED3DERR_OUTOFVIDEOMEMORY;
|
|
|
|
}
|
|
|
|
|
2013-06-06 10:51:47 +02:00
|
|
|
if (FAILED(hr = cubetexture_init(object, desc, level_count, surface_flags, device, parent, parent_ops)))
|
2011-05-10 21:18:47 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to initialize cubetexture, returning %#x\n", hr);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
*texture = NULL;
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created texture %p.\n", object);
|
|
|
|
*texture = object;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|