2004-12-07 15:29:12 +01:00
|
|
|
/*
|
|
|
|
* IWineD3DBaseTexture Implementation
|
|
|
|
*
|
|
|
|
* Copyright 2002-2004 Jason Edmeades
|
2005-03-14 11:12:52 +01:00
|
|
|
* Copyright 2002-2004 Raphael Junqueira
|
|
|
|
* Copyright 2005 Oliver Stieber
|
2008-10-18 19:21:20 +02:00
|
|
|
* Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
2010-11-12 13:12:05 +01:00
|
|
|
* Copyright 2009-2010 Henri Verbeet for CodeWeavers
|
2004-12-07 15:29:12 +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
|
2004-12-07 15:29:12 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
2005-08-03 13:00:28 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
|
2004-12-07 15:29:12 +01:00
|
|
|
|
2011-01-04 17:42:03 +01:00
|
|
|
HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, const struct wined3d_texture_ops *texture_ops,
|
|
|
|
UINT layer_count, UINT level_count, WINED3DRESOURCETYPE resource_type, IWineD3DDeviceImpl *device,
|
|
|
|
DWORD usage, const struct wined3d_format *format, WINED3DPOOL pool, void *parent,
|
2011-02-28 08:05:39 +01:00
|
|
|
const struct wined3d_parent_ops *parent_ops, const struct wined3d_resource_ops *resource_ops)
|
2009-01-12 10:17:50 +01:00
|
|
|
{
|
2009-06-02 09:01:17 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2011-03-08 19:41:07 +01:00
|
|
|
hr = resource_init(&texture->resource, device, resource_type, format,
|
|
|
|
WINED3DMULTISAMPLE_NONE, 0, usage, pool, 0, 0, 0, 0,
|
|
|
|
parent, parent_ops, resource_ops);
|
2009-06-02 09:01:17 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to initialize resource, returning %#x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-01-04 17:42:03 +01:00
|
|
|
texture->baseTexture.texture_ops = texture_ops;
|
2010-04-22 18:55:57 +02:00
|
|
|
texture->baseTexture.sub_resources = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
level_count * layer_count * sizeof(*texture->baseTexture.sub_resources));
|
|
|
|
if (!texture->baseTexture.sub_resources)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate sub-resource array.\n");
|
2011-03-01 09:47:56 +01:00
|
|
|
resource_cleanup(&texture->resource);
|
2010-04-22 18:55:57 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
texture->baseTexture.layer_count = layer_count;
|
|
|
|
texture->baseTexture.level_count = level_count;
|
2009-06-02 09:01:17 +02:00
|
|
|
texture->baseTexture.filterType = (usage & WINED3DUSAGE_AUTOGENMIPMAP) ? WINED3DTEXF_LINEAR : WINED3DTEXF_NONE;
|
|
|
|
texture->baseTexture.LOD = 0;
|
2009-09-19 14:59:27 +02:00
|
|
|
texture->baseTexture.texture_rgb.dirty = TRUE;
|
|
|
|
texture->baseTexture.texture_srgb.dirty = TRUE;
|
2009-06-02 09:01:17 +02:00
|
|
|
texture->baseTexture.is_srgb = FALSE;
|
|
|
|
texture->baseTexture.pow2Matrix_identity = TRUE;
|
|
|
|
|
2010-11-12 13:12:05 +01:00
|
|
|
if (texture->resource.format->flags & WINED3DFMT_FLAG_FILTERING)
|
2009-08-05 09:01:00 +02:00
|
|
|
{
|
|
|
|
texture->baseTexture.minMipLookup = minMipLookup;
|
|
|
|
texture->baseTexture.magLookup = magLookup;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
texture->baseTexture.minMipLookup = minMipLookup_noFilter;
|
|
|
|
texture->baseTexture.magLookup = magLookup_noFilter;
|
|
|
|
}
|
|
|
|
|
2009-06-02 09:01:17 +02:00
|
|
|
return WINED3D_OK;
|
2009-01-12 10:17:50 +01:00
|
|
|
}
|
|
|
|
|
2010-12-15 21:06:25 +01:00
|
|
|
void basetexture_cleanup(IWineD3DBaseTextureImpl *texture)
|
2008-12-02 18:41:32 +01:00
|
|
|
{
|
2010-12-15 21:06:25 +01:00
|
|
|
basetexture_unload(texture);
|
|
|
|
HeapFree(GetProcessHeap(), 0, texture->baseTexture.sub_resources);
|
2011-03-01 09:47:56 +01:00
|
|
|
resource_cleanup(&texture->resource);
|
2005-03-29 21:01:00 +02:00
|
|
|
}
|
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
struct wined3d_resource *basetexture_get_sub_resource(IWineD3DBaseTextureImpl *texture, UINT sub_resource_idx)
|
2010-04-22 18:55:59 +02:00
|
|
|
{
|
2010-10-25 12:33:39 +02:00
|
|
|
UINT sub_count = texture->baseTexture.level_count * texture->baseTexture.layer_count;
|
2010-04-22 18:55:59 +02:00
|
|
|
|
2010-10-25 12:33:39 +02:00
|
|
|
if (sub_resource_idx >= sub_count)
|
2010-04-22 18:55:59 +02:00
|
|
|
{
|
2010-10-25 12:33:39 +02:00
|
|
|
WARN("sub_resource_idx %u >= sub_count %u.\n", sub_resource_idx, sub_count);
|
2010-04-22 18:55:59 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-25 12:33:39 +02:00
|
|
|
return texture->baseTexture.sub_resources[sub_resource_idx];
|
2010-04-22 18:55:59 +02:00
|
|
|
}
|
|
|
|
|
2009-09-19 15:06:35 +02:00
|
|
|
/* A GL context is provided by the caller */
|
|
|
|
static void gltexture_delete(struct gl_texture *tex)
|
|
|
|
{
|
|
|
|
ENTER_GL();
|
|
|
|
glDeleteTextures(1, &tex->name);
|
|
|
|
LEAVE_GL();
|
|
|
|
tex->name = 0;
|
|
|
|
}
|
|
|
|
|
2010-12-15 21:06:24 +01:00
|
|
|
void basetexture_unload(IWineD3DBaseTextureImpl *texture)
|
2008-12-02 18:41:32 +01:00
|
|
|
{
|
2010-12-15 21:06:24 +01:00
|
|
|
IWineD3DDeviceImpl *device = texture->resource.device;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context = NULL;
|
2008-01-25 18:18:06 +01:00
|
|
|
|
2010-12-15 21:06:24 +01:00
|
|
|
if (texture->baseTexture.texture_rgb.name || texture->baseTexture.texture_srgb.name)
|
2009-10-28 11:00:11 +01:00
|
|
|
{
|
2010-05-03 22:03:28 +02:00
|
|
|
context = context_acquire(device, NULL);
|
2009-06-10 08:01:02 +02:00
|
|
|
}
|
|
|
|
|
2010-12-15 21:06:24 +01:00
|
|
|
if (texture->baseTexture.texture_rgb.name)
|
|
|
|
gltexture_delete(&texture->baseTexture.texture_rgb);
|
|
|
|
|
|
|
|
if (texture->baseTexture.texture_srgb.name)
|
|
|
|
gltexture_delete(&texture->baseTexture.texture_srgb);
|
2009-10-28 11:00:11 +01:00
|
|
|
|
|
|
|
if (context) context_release(context);
|
|
|
|
|
2011-03-02 08:55:47 +01:00
|
|
|
basetexture_set_dirty(texture, TRUE);
|
2010-08-15 23:21:42 +02:00
|
|
|
|
2011-03-01 09:47:56 +01:00
|
|
|
resource_unload(&texture->resource);
|
2008-01-12 22:56:30 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 12:26:35 +01:00
|
|
|
DWORD basetexture_set_lod(IWineD3DBaseTextureImpl *texture, DWORD lod)
|
2008-12-02 18:41:32 +01:00
|
|
|
{
|
2011-01-02 12:26:35 +01:00
|
|
|
DWORD old = texture->baseTexture.LOD;
|
|
|
|
|
|
|
|
TRACE("texture %p, lod %u.\n", texture, lod);
|
2005-06-23 18:44:19 +02:00
|
|
|
|
2009-08-30 22:02:51 +02:00
|
|
|
/* The d3d9:texture test shows that SetLOD is ignored on non-managed
|
2011-01-02 12:26:35 +01:00
|
|
|
* textures. The call always returns 0, and GetLOD always returns 0. */
|
|
|
|
if (texture->resource.pool != WINED3DPOOL_MANAGED)
|
|
|
|
{
|
|
|
|
TRACE("Ignoring SetLOD on %s texture, returning 0.\n", debug_d3dpool(texture->resource.pool));
|
2009-08-30 22:02:51 +02:00
|
|
|
return 0;
|
2005-06-23 18:44:19 +02:00
|
|
|
}
|
|
|
|
|
2011-01-02 12:26:35 +01:00
|
|
|
if (lod >= texture->baseTexture.level_count)
|
|
|
|
lod = texture->baseTexture.level_count - 1;
|
2005-06-23 18:44:19 +02:00
|
|
|
|
2011-01-02 12:26:35 +01:00
|
|
|
if (texture->baseTexture.LOD != lod)
|
|
|
|
{
|
|
|
|
texture->baseTexture.LOD = lod;
|
2005-06-23 18:44:19 +02:00
|
|
|
|
2011-01-02 12:26:35 +01:00
|
|
|
texture->baseTexture.texture_rgb.states[WINED3DTEXSTA_MAXMIPLEVEL] = ~0U;
|
|
|
|
texture->baseTexture.texture_srgb.states[WINED3DTEXSTA_MAXMIPLEVEL] = ~0U;
|
|
|
|
if (texture->baseTexture.bindCount)
|
|
|
|
IWineD3DDeviceImpl_MarkStateDirty(texture->resource.device, STATE_SAMPLER(texture->baseTexture.sampler));
|
2009-08-30 22:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return old;
|
2004-12-07 15:29:12 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 12:26:36 +01:00
|
|
|
DWORD basetexture_get_lod(IWineD3DBaseTextureImpl *texture)
|
2008-12-02 18:41:32 +01:00
|
|
|
{
|
2011-01-02 12:26:36 +01:00
|
|
|
TRACE("texture %p, returning %u.\n", texture, texture->baseTexture.LOD);
|
2005-06-23 18:44:19 +02:00
|
|
|
|
2011-01-02 12:26:36 +01:00
|
|
|
return texture->baseTexture.LOD;
|
2004-12-07 15:29:12 +01:00
|
|
|
}
|
|
|
|
|
2010-12-15 21:06:26 +01:00
|
|
|
DWORD basetexture_get_level_count(IWineD3DBaseTextureImpl *texture)
|
2008-12-02 18:41:32 +01:00
|
|
|
{
|
2010-12-15 21:06:26 +01:00
|
|
|
TRACE("texture %p, returning %u.\n", texture, texture->baseTexture.level_count);
|
|
|
|
return texture->baseTexture.level_count;
|
2004-12-07 15:29:12 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 12:26:37 +01:00
|
|
|
HRESULT basetexture_set_autogen_filter_type(IWineD3DBaseTextureImpl *texture, WINED3DTEXTUREFILTERTYPE filter_type)
|
2008-12-02 18:41:32 +01:00
|
|
|
{
|
2011-01-02 12:26:37 +01:00
|
|
|
TRACE("texture %p, filter_type %s.\n", texture, debug_d3dtexturefiltertype(filter_type));
|
|
|
|
|
|
|
|
if (!(texture->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP))
|
|
|
|
{
|
|
|
|
WARN("Texture doesn't have AUTOGENMIPMAP usage.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (texture->baseTexture.filterType != filter_type)
|
|
|
|
{
|
|
|
|
GLenum target = texture->baseTexture.target;
|
|
|
|
struct wined3d_context *context;
|
|
|
|
|
|
|
|
context = context_acquire(texture->resource.device, NULL);
|
|
|
|
|
|
|
|
ENTER_GL();
|
|
|
|
glBindTexture(target, texture->baseTexture.texture_rgb.name);
|
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
switch (filter_type)
|
|
|
|
{
|
|
|
|
case WINED3DTEXF_NONE:
|
|
|
|
case WINED3DTEXF_POINT:
|
|
|
|
glTexParameteri(target, GL_GENERATE_MIPMAP_HINT_SGIS, GL_FASTEST);
|
|
|
|
checkGLcall("glTexParameteri(target, GL_GENERATE_MIPMAP_HINT_SGIS, GL_FASTEST)");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WINED3DTEXF_LINEAR:
|
|
|
|
glTexParameteri(target, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST);
|
|
|
|
checkGLcall("glTexParameteri(target, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST)");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
WARN("Unexpected filter type %#x, setting to GL_NICEST.\n", filter_type);
|
|
|
|
glTexParameteri(target, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST);
|
|
|
|
checkGLcall("glTexParameteri(target, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST)");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
LEAVE_GL();
|
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
}
|
|
|
|
texture->baseTexture.filterType = filter_type;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
2004-12-07 15:29:12 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 12:26:38 +01:00
|
|
|
WINED3DTEXTUREFILTERTYPE basetexture_get_autogen_filter_type(IWineD3DBaseTextureImpl *texture)
|
2008-12-02 18:41:32 +01:00
|
|
|
{
|
2011-01-02 12:26:38 +01:00
|
|
|
TRACE("texture %p.\n", texture);
|
2009-08-05 09:01:01 +02:00
|
|
|
|
2011-01-02 12:26:38 +01:00
|
|
|
return texture->baseTexture.filterType;
|
2004-12-07 15:29:12 +01:00
|
|
|
}
|
|
|
|
|
2011-01-03 18:51:38 +01:00
|
|
|
void basetexture_generate_mipmaps(IWineD3DBaseTextureImpl *texture)
|
2008-12-02 18:41:32 +01:00
|
|
|
{
|
2009-12-21 23:17:26 +01:00
|
|
|
/* TODO: Implement filters using GL_SGI_generate_mipmaps. */
|
2011-01-03 18:51:38 +01:00
|
|
|
FIXME("texture %p stub!\n", texture);
|
2004-12-07 15:29:12 +01:00
|
|
|
}
|
|
|
|
|
2011-03-02 08:55:46 +01:00
|
|
|
void basetexture_set_dirty(IWineD3DBaseTextureImpl *texture, BOOL dirty)
|
2008-12-02 18:41:32 +01:00
|
|
|
{
|
2010-12-08 18:28:09 +01:00
|
|
|
texture->baseTexture.texture_rgb.dirty = dirty;
|
|
|
|
texture->baseTexture.texture_srgb.dirty = dirty;
|
2005-01-09 18:37:02 +01:00
|
|
|
}
|
|
|
|
|
2009-06-26 10:07:12 +02:00
|
|
|
/* Context activation is done by the caller. */
|
2011-03-03 09:24:11 +01:00
|
|
|
HRESULT basetexture_bind(IWineD3DBaseTextureImpl *texture,
|
|
|
|
const struct wined3d_gl_info *gl_info, BOOL srgb, BOOL *set_surface_desc)
|
2008-12-02 18:41:32 +01:00
|
|
|
{
|
2006-04-07 12:51:12 +02:00
|
|
|
HRESULT hr = WINED3D_OK;
|
2010-09-17 11:59:39 +02:00
|
|
|
GLenum textureDimensions;
|
2005-07-18 11:07:17 +02:00
|
|
|
BOOL isNewTexture = FALSE;
|
2009-09-19 14:59:27 +02:00
|
|
|
struct gl_texture *gl_tex;
|
2005-03-29 21:01:00 +02:00
|
|
|
|
2011-01-03 18:51:39 +01:00
|
|
|
TRACE("texture %p, srgb %#x, set_surface_desc %p.\n", texture, srgb, set_surface_desc);
|
|
|
|
|
|
|
|
texture->baseTexture.is_srgb = srgb; /* SRGB mode cache for PreLoad calls outside drawprim */
|
2011-03-03 09:24:10 +01:00
|
|
|
gl_tex = basetexture_get_gl_texture(texture, gl_info, srgb);
|
2011-01-03 18:51:39 +01:00
|
|
|
|
|
|
|
textureDimensions = texture->baseTexture.target;
|
2009-01-16 16:22:09 +01:00
|
|
|
|
2005-03-29 21:01:00 +02:00
|
|
|
ENTER_GL();
|
|
|
|
/* Generate a texture name if we don't already have one */
|
2010-09-14 13:38:39 +02:00
|
|
|
if (!gl_tex->name)
|
|
|
|
{
|
2009-01-16 16:22:09 +01:00
|
|
|
*set_surface_desc = TRUE;
|
2009-09-19 14:59:27 +02:00
|
|
|
glGenTextures(1, &gl_tex->name);
|
2005-03-29 21:01:00 +02:00
|
|
|
checkGLcall("glGenTextures");
|
2009-09-19 14:59:27 +02:00
|
|
|
TRACE("Generated texture %d\n", gl_tex->name);
|
2011-01-03 18:51:39 +01:00
|
|
|
if (texture->resource.pool == WINED3DPOOL_DEFAULT)
|
|
|
|
{
|
2005-03-29 21:01:00 +02:00
|
|
|
/* Tell opengl to try and keep this texture in video ram (well mostly) */
|
|
|
|
GLclampf tmp;
|
|
|
|
tmp = 0.9f;
|
2009-09-19 14:59:27 +02:00
|
|
|
glPrioritizeTextures(1, &gl_tex->name, &tmp);
|
2005-08-03 13:00:28 +02:00
|
|
|
|
|
|
|
}
|
2005-11-23 20:14:43 +01:00
|
|
|
/* Initialise the state of the texture object
|
2005-08-03 13:00:28 +02:00
|
|
|
to the openGL defaults, not the directx defaults */
|
2009-09-19 14:59:27 +02:00
|
|
|
gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3DTADDRESS_WRAP;
|
|
|
|
gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3DTADDRESS_WRAP;
|
|
|
|
gl_tex->states[WINED3DTEXSTA_ADDRESSW] = WINED3DTADDRESS_WRAP;
|
|
|
|
gl_tex->states[WINED3DTEXSTA_BORDERCOLOR] = 0;
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_LINEAR;
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT; /* GL_NEAREST_MIPMAP_LINEAR */
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_LINEAR; /* GL_NEAREST_MIPMAP_LINEAR */
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] = 0;
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] = 1;
|
2011-03-03 09:24:10 +01:00
|
|
|
if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
|
|
|
|
gl_tex->states[WINED3DTEXSTA_SRGBTEXTURE] = TRUE;
|
|
|
|
else
|
|
|
|
gl_tex->states[WINED3DTEXSTA_SRGBTEXTURE] = srgb;
|
2010-05-17 11:14:48 +02:00
|
|
|
gl_tex->states[WINED3DTEXSTA_SHADOW] = FALSE;
|
2011-01-03 18:51:39 +01:00
|
|
|
basetexture_set_dirty(texture, TRUE);
|
2005-07-18 11:07:17 +02:00
|
|
|
isNewTexture = TRUE;
|
2007-08-31 20:56:15 +02:00
|
|
|
|
2011-01-03 18:51:39 +01:00
|
|
|
if (texture->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP)
|
|
|
|
{
|
2007-08-31 20:56:15 +02:00
|
|
|
/* 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
|
|
|
|
*/
|
2009-09-19 14:59:27 +02:00
|
|
|
glBindTexture(textureDimensions, gl_tex->name);
|
2007-08-31 20:56:15 +02:00
|
|
|
checkGLcall("glBindTexture");
|
|
|
|
glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
|
|
|
|
checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_SGIS, GL_TRUE)");
|
|
|
|
}
|
2009-01-16 16:22:09 +01:00
|
|
|
} else {
|
|
|
|
*set_surface_desc = FALSE;
|
2005-03-29 21:01:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Bind the texture */
|
2010-09-14 13:38:39 +02:00
|
|
|
if (gl_tex->name)
|
|
|
|
{
|
2009-09-19 14:59:27 +02:00
|
|
|
glBindTexture(textureDimensions, gl_tex->name);
|
2005-03-29 21:01:00 +02:00
|
|
|
checkGLcall("glBindTexture");
|
2005-08-03 21:49:05 +02:00
|
|
|
if (isNewTexture) {
|
2006-10-15 17:05:01 +02:00
|
|
|
/* For a new texture we have to set the textures levels after binding the texture.
|
2007-11-27 22:25:07 +01:00
|
|
|
* In theory this is all we should ever have to do, but because ATI's drivers are broken, we
|
|
|
|
* also need to set the texture dimensions before the texture is set
|
2008-07-09 01:59:10 +02:00
|
|
|
* 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
|
|
|
|
* (ie, do not care for cond_np2 here, just look for GL_TEXTURE_RECTANGLE_ARB)
|
2007-11-27 22:25:07 +01:00
|
|
|
*/
|
2010-04-22 18:55:57 +02:00
|
|
|
if (textureDimensions != GL_TEXTURE_RECTANGLE_ARB)
|
|
|
|
{
|
2011-01-03 18:51:39 +01:00
|
|
|
TRACE("Setting GL_TEXTURE_MAX_LEVEL to %u.\n", texture->baseTexture.level_count - 1);
|
|
|
|
glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, texture->baseTexture.level_count - 1);
|
|
|
|
checkGLcall("glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, texture->baseTexture.level_count)");
|
2007-11-27 22:25:07 +01:00
|
|
|
}
|
2007-03-10 14:37:28 +01:00
|
|
|
if(textureDimensions==GL_TEXTURE_CUBE_MAP_ARB) {
|
2008-01-09 20:37:05 +01:00
|
|
|
/* Cubemaps are always set to clamp, regardless of the sampler state. */
|
2007-03-10 14:37:28 +01:00
|
|
|
glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
|
|
|
}
|
2005-08-22 12:07:10 +02:00
|
|
|
}
|
2005-03-29 21:01:00 +02:00
|
|
|
} else { /* this only happened if we've run out of openGL textures */
|
|
|
|
WARN("This texture doesn't have an openGL texture assigned to it\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
hr = WINED3DERR_INVALIDCALL;
|
2005-03-29 21:01:00 +02:00
|
|
|
}
|
|
|
|
|
2005-06-23 18:44:19 +02:00
|
|
|
LEAVE_GL();
|
|
|
|
return hr;
|
2005-03-14 11:12:52 +01:00
|
|
|
}
|
2005-06-23 18:44:19 +02:00
|
|
|
|
2009-05-14 19:40:56 +02:00
|
|
|
/* GL locking is done by the caller */
|
2010-01-03 21:18:22 +01:00
|
|
|
static void apply_wrap(const struct wined3d_gl_info *gl_info, GLenum target,
|
|
|
|
WINED3DTEXTUREADDRESS d3d_wrap, GLenum param, BOOL cond_np2)
|
2009-10-23 10:26:10 +02:00
|
|
|
{
|
|
|
|
GLint gl_wrap;
|
2007-08-12 13:37:17 +02:00
|
|
|
|
2009-10-23 10:26:10 +02:00
|
|
|
if (d3d_wrap < WINED3DTADDRESS_WRAP || d3d_wrap > WINED3DTADDRESS_MIRRORONCE)
|
|
|
|
{
|
|
|
|
FIXME("Unrecognized or unsupported WINED3DTEXTUREADDRESS %#x.\n", d3d_wrap);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target == GL_TEXTURE_CUBE_MAP_ARB
|
|
|
|
|| (cond_np2 && d3d_wrap == WINED3DTADDRESS_WRAP))
|
|
|
|
{
|
|
|
|
/* Cubemaps are always set to clamp, regardless of the sampler state. */
|
|
|
|
gl_wrap = GL_CLAMP_TO_EDGE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-03 21:18:22 +01:00
|
|
|
gl_wrap = gl_info->wrap_lookup[d3d_wrap - WINED3DTADDRESS_WRAP];
|
2007-08-12 13:37:17 +02:00
|
|
|
}
|
2009-10-23 10:26:10 +02:00
|
|
|
|
|
|
|
TRACE("Setting param %#x to %#x for target %#x.\n", param, gl_wrap, target);
|
|
|
|
glTexParameteri(target, param, gl_wrap);
|
|
|
|
checkGLcall("glTexParameteri(target, param, gl_wrap)");
|
2007-08-12 13:37:17 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 19:40:56 +02:00
|
|
|
/* GL locking is done by the caller (state handler) */
|
2011-01-03 18:51:40 +01:00
|
|
|
void basetexture_apply_state_changes(IWineD3DBaseTextureImpl *texture,
|
2010-01-03 21:18:22 +01:00
|
|
|
const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1],
|
|
|
|
const struct wined3d_gl_info *gl_info)
|
2008-12-02 18:41:32 +01:00
|
|
|
{
|
2011-01-03 18:51:40 +01:00
|
|
|
BOOL cond_np2 = IWineD3DBaseTexture_IsCondNP2((IWineD3DBaseTexture *)texture);
|
|
|
|
GLenum textureDimensions = texture->baseTexture.target;
|
2009-09-19 14:59:27 +02:00
|
|
|
DWORD state;
|
2009-08-04 08:30:20 +02:00
|
|
|
DWORD aniso;
|
2009-09-19 14:59:27 +02:00
|
|
|
struct gl_texture *gl_tex;
|
2007-08-12 13:37:17 +02:00
|
|
|
|
2011-01-03 18:51:40 +01:00
|
|
|
TRACE("texture %p, samplerStates %p\n", texture, samplerStates);
|
2009-05-12 16:19:55 +02:00
|
|
|
|
2011-03-03 09:24:10 +01:00
|
|
|
gl_tex = basetexture_get_gl_texture(texture, gl_info, texture->baseTexture.is_srgb);
|
2009-01-16 16:22:09 +01:00
|
|
|
|
2009-05-12 16:19:55 +02:00
|
|
|
/* This function relies on the correct texture being bound and loaded. */
|
2007-08-12 13:37:17 +02:00
|
|
|
|
2009-09-19 14:59:27 +02:00
|
|
|
if(samplerStates[WINED3DSAMP_ADDRESSU] != gl_tex->states[WINED3DTEXSTA_ADDRESSU]) {
|
2007-08-12 13:37:17 +02:00
|
|
|
state = samplerStates[WINED3DSAMP_ADDRESSU];
|
2010-01-03 21:18:22 +01:00
|
|
|
apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_S, cond_np2);
|
2009-09-19 14:59:27 +02:00
|
|
|
gl_tex->states[WINED3DTEXSTA_ADDRESSU] = state;
|
2007-08-12 13:37:17 +02:00
|
|
|
}
|
|
|
|
|
2009-09-19 14:59:27 +02:00
|
|
|
if(samplerStates[WINED3DSAMP_ADDRESSV] != gl_tex->states[WINED3DTEXSTA_ADDRESSV]) {
|
2007-08-12 13:37:17 +02:00
|
|
|
state = samplerStates[WINED3DSAMP_ADDRESSV];
|
2010-01-03 21:18:22 +01:00
|
|
|
apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_T, cond_np2);
|
2009-09-19 14:59:27 +02:00
|
|
|
gl_tex->states[WINED3DTEXSTA_ADDRESSV] = state;
|
2007-08-12 13:37:17 +02:00
|
|
|
}
|
|
|
|
|
2009-09-19 14:59:27 +02:00
|
|
|
if(samplerStates[WINED3DSAMP_ADDRESSW] != gl_tex->states[WINED3DTEXSTA_ADDRESSW]) {
|
2007-08-12 13:37:17 +02:00
|
|
|
state = samplerStates[WINED3DSAMP_ADDRESSW];
|
2010-01-03 21:18:22 +01:00
|
|
|
apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_R, cond_np2);
|
2009-09-19 14:59:27 +02:00
|
|
|
gl_tex->states[WINED3DTEXSTA_ADDRESSW] = state;
|
2007-08-12 13:37:17 +02:00
|
|
|
}
|
|
|
|
|
2009-09-19 14:59:27 +02:00
|
|
|
if(samplerStates[WINED3DSAMP_BORDERCOLOR] != gl_tex->states[WINED3DTEXSTA_BORDERCOLOR]) {
|
2007-08-12 13:37:17 +02:00
|
|
|
float col[4];
|
|
|
|
|
|
|
|
state = samplerStates[WINED3DSAMP_BORDERCOLOR];
|
|
|
|
D3DCOLORTOGLFLOAT4(state, col);
|
|
|
|
TRACE("Setting border color for %u to %x\n", textureDimensions, state);
|
|
|
|
glTexParameterfv(textureDimensions, GL_TEXTURE_BORDER_COLOR, &col[0]);
|
2010-11-05 11:17:51 +01:00
|
|
|
checkGLcall("glTexParameterfv(..., GL_TEXTURE_BORDER_COLOR, ...)");
|
2009-09-19 14:59:27 +02:00
|
|
|
gl_tex->states[WINED3DTEXSTA_BORDERCOLOR] = state;
|
2007-08-12 13:37:17 +02:00
|
|
|
}
|
|
|
|
|
2009-09-19 14:59:27 +02:00
|
|
|
if(samplerStates[WINED3DSAMP_MAGFILTER] != gl_tex->states[WINED3DTEXSTA_MAGFILTER]) {
|
2007-08-12 13:37:17 +02:00
|
|
|
GLint glValue;
|
|
|
|
state = samplerStates[WINED3DSAMP_MAGFILTER];
|
2008-05-09 23:32:32 +02:00
|
|
|
if (state > WINED3DTEXF_ANISOTROPIC) {
|
2007-08-12 13:37:17 +02:00
|
|
|
FIXME("Unrecognized or unsupported MAGFILTER* value %d\n", state);
|
2009-08-05 09:00:59 +02:00
|
|
|
}
|
2009-08-05 09:01:02 +02:00
|
|
|
|
2011-01-03 18:51:40 +01:00
|
|
|
glValue = wined3d_gl_mag_filter(texture->baseTexture.magLookup,
|
2009-08-05 09:01:02 +02:00
|
|
|
min(max(state, WINED3DTEXF_POINT), WINED3DTEXF_LINEAR));
|
|
|
|
TRACE("ValueMAG=%d setting MAGFILTER to %x\n", state, glValue);
|
|
|
|
glTexParameteri(textureDimensions, GL_TEXTURE_MAG_FILTER, glValue);
|
|
|
|
|
2009-09-19 14:59:27 +02:00
|
|
|
gl_tex->states[WINED3DTEXSTA_MAGFILTER] = state;
|
2007-08-12 13:37:17 +02:00
|
|
|
}
|
|
|
|
|
2009-09-19 14:59:27 +02:00
|
|
|
if((samplerStates[WINED3DSAMP_MINFILTER] != gl_tex->states[WINED3DTEXSTA_MINFILTER] ||
|
|
|
|
samplerStates[WINED3DSAMP_MIPFILTER] != gl_tex->states[WINED3DTEXSTA_MIPFILTER] ||
|
|
|
|
samplerStates[WINED3DSAMP_MAXMIPLEVEL] != gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL])) {
|
2007-08-12 13:37:17 +02:00
|
|
|
GLint glValue;
|
|
|
|
|
2009-09-19 14:59:27 +02:00
|
|
|
gl_tex->states[WINED3DTEXSTA_MIPFILTER] = samplerStates[WINED3DSAMP_MIPFILTER];
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MINFILTER] = samplerStates[WINED3DSAMP_MINFILTER];
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] = samplerStates[WINED3DSAMP_MAXMIPLEVEL];
|
2007-08-12 13:37:17 +02:00
|
|
|
|
2009-09-19 14:59:27 +02:00
|
|
|
if (gl_tex->states[WINED3DTEXSTA_MINFILTER] > WINED3DTEXF_ANISOTROPIC
|
|
|
|
|| gl_tex->states[WINED3DTEXSTA_MIPFILTER] > WINED3DTEXF_ANISOTROPIC)
|
2007-08-12 13:37:17 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
FIXME("Unrecognized or unsupported D3DSAMP_MINFILTER value %d D3DSAMP_MIPFILTER value %d\n",
|
2009-09-19 14:59:27 +02:00
|
|
|
gl_tex->states[WINED3DTEXSTA_MINFILTER],
|
|
|
|
gl_tex->states[WINED3DTEXSTA_MIPFILTER]);
|
2007-08-12 13:37:17 +02:00
|
|
|
}
|
2011-01-03 18:51:40 +01:00
|
|
|
glValue = wined3d_gl_min_mip_filter(texture->baseTexture.minMipLookup,
|
2009-08-05 09:01:03 +02:00
|
|
|
min(max(samplerStates[WINED3DSAMP_MINFILTER], WINED3DTEXF_POINT), WINED3DTEXF_LINEAR),
|
2009-08-05 09:01:02 +02:00
|
|
|
min(max(samplerStates[WINED3DSAMP_MIPFILTER], WINED3DTEXF_NONE), WINED3DTEXF_LINEAR));
|
2007-08-12 13:37:17 +02:00
|
|
|
|
|
|
|
TRACE("ValueMIN=%d, ValueMIP=%d, setting MINFILTER to %x\n",
|
|
|
|
samplerStates[WINED3DSAMP_MINFILTER],
|
|
|
|
samplerStates[WINED3DSAMP_MIPFILTER], glValue);
|
|
|
|
glTexParameteri(textureDimensions, GL_TEXTURE_MIN_FILTER, glValue);
|
|
|
|
checkGLcall("glTexParameter GL_TEXTURE_MIN_FILTER, ...");
|
|
|
|
|
2010-04-22 18:55:57 +02:00
|
|
|
if (!cond_np2)
|
|
|
|
{
|
|
|
|
if (gl_tex->states[WINED3DTEXSTA_MIPFILTER] == WINED3DTEXF_NONE)
|
2011-01-03 18:51:40 +01:00
|
|
|
glValue = texture->baseTexture.LOD;
|
|
|
|
else if (gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] >= texture->baseTexture.level_count)
|
|
|
|
glValue = texture->baseTexture.level_count - 1;
|
|
|
|
else if (gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] < texture->baseTexture.LOD)
|
2009-08-30 22:02:17 +02:00
|
|
|
/* baseTexture.LOD is already clamped in the setter */
|
2011-01-03 18:51:40 +01:00
|
|
|
glValue = texture->baseTexture.LOD;
|
2010-04-22 18:55:57 +02:00
|
|
|
else
|
2009-09-19 14:59:27 +02:00
|
|
|
glValue = gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL];
|
2010-04-22 18:55:57 +02:00
|
|
|
|
2009-08-30 17:46:38 +02:00
|
|
|
/* Note that D3DSAMP_MAXMIPLEVEL specifies the biggest mipmap(default 0), while
|
|
|
|
* GL_TEXTURE_MAX_LEVEL specifies the smallest mimap used(default 1000).
|
|
|
|
* So D3DSAMP_MAXMIPLEVEL is the same as GL_TEXTURE_BASE_LEVEL.
|
|
|
|
*/
|
2008-07-09 01:59:10 +02:00
|
|
|
glTexParameteri(textureDimensions, GL_TEXTURE_BASE_LEVEL, glValue);
|
2007-08-12 13:37:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-19 15:00:37 +02:00
|
|
|
if ((gl_tex->states[WINED3DTEXSTA_MAGFILTER] != WINED3DTEXF_ANISOTROPIC
|
|
|
|
&& gl_tex->states[WINED3DTEXSTA_MINFILTER] != WINED3DTEXF_ANISOTROPIC
|
|
|
|
&& gl_tex->states[WINED3DTEXSTA_MIPFILTER] != WINED3DTEXF_ANISOTROPIC)
|
2009-08-04 08:30:20 +02:00
|
|
|
|| cond_np2)
|
|
|
|
{
|
|
|
|
aniso = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aniso = samplerStates[WINED3DSAMP_MAXANISOTROPY];
|
|
|
|
}
|
|
|
|
|
2009-09-19 14:59:27 +02:00
|
|
|
if (gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] != aniso)
|
2009-08-04 08:30:20 +02:00
|
|
|
{
|
2009-10-29 10:37:11 +01:00
|
|
|
if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
|
2009-08-04 08:30:20 +02:00
|
|
|
{
|
|
|
|
glTexParameteri(textureDimensions, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso);
|
|
|
|
checkGLcall("glTexParameteri(GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso)");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Anisotropic filtering not supported.\n");
|
2005-08-03 13:00:28 +02:00
|
|
|
}
|
2009-09-19 14:59:27 +02:00
|
|
|
gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] = aniso;
|
2005-08-03 13:00:28 +02:00
|
|
|
}
|
2010-05-17 11:14:48 +02:00
|
|
|
|
2011-03-03 09:24:10 +01:00
|
|
|
/* These should always be the same unless EXT_texture_sRGB_decode is supported. */
|
|
|
|
if (samplerStates[WINED3DSAMP_SRGBTEXTURE] != gl_tex->states[WINED3DTEXSTA_SRGBTEXTURE])
|
|
|
|
{
|
|
|
|
glTexParameteri(textureDimensions, GL_TEXTURE_SRGB_DECODE_EXT,
|
|
|
|
samplerStates[WINED3DSAMP_SRGBTEXTURE] ? GL_DECODE_EXT : GL_SKIP_DECODE_EXT);
|
|
|
|
checkGLcall("glTexParameteri(GL_TEXTURE_SRGB_DECODE_EXT)");
|
|
|
|
}
|
|
|
|
|
2011-01-03 18:51:40 +01:00
|
|
|
if (!(texture->resource.format->flags & WINED3DFMT_FLAG_SHADOW)
|
2010-05-17 11:14:48 +02:00
|
|
|
!= !gl_tex->states[WINED3DTEXSTA_SHADOW])
|
|
|
|
{
|
2011-01-03 18:51:40 +01:00
|
|
|
if (texture->resource.format->flags & WINED3DFMT_FLAG_SHADOW)
|
2010-05-17 11:14:48 +02:00
|
|
|
{
|
|
|
|
glTexParameteri(textureDimensions, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);
|
|
|
|
glTexParameteri(textureDimensions, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
|
|
|
|
checkGLcall("glTexParameteri(textureDimensions, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB)");
|
|
|
|
gl_tex->states[WINED3DTEXSTA_SHADOW] = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glTexParameteri(textureDimensions, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
|
|
|
|
checkGLcall("glTexParameteri(textureDimensions, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE)");
|
|
|
|
gl_tex->states[WINED3DTEXSTA_SHADOW] = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2005-08-03 13:00:28 +02:00
|
|
|
}
|