wined3d: read_from_framebuffer_texture() isn't suitable for readback of onscreen...
[wine/testsucceed.git] / dlls / wined3d / basetexture.c
blobdeab4fb2362abd859cba117ce9c529c090dc65b0
1 /*
2 * IWineD3DBaseTexture Implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2002-2004 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
7 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
8 * Copyright 2009 Henri Verbeet for CodeWeavers
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "config.h"
26 #include "wined3d_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
30 HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT layer_count, UINT level_count,
31 WINED3DRESOURCETYPE resource_type, IWineD3DDeviceImpl *device, UINT size, DWORD usage,
32 const struct wined3d_format_desc *format_desc, WINED3DPOOL pool, IUnknown *parent,
33 const struct wined3d_parent_ops *parent_ops)
35 HRESULT hr;
37 hr = resource_init((IWineD3DResource *)texture, resource_type, device,
38 size, usage, format_desc, pool, parent, parent_ops);
39 if (FAILED(hr))
41 WARN("Failed to initialize resource, returning %#x\n", hr);
42 return hr;
45 texture->baseTexture.sub_resources = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
46 level_count * layer_count * sizeof(*texture->baseTexture.sub_resources));
47 if (!texture->baseTexture.sub_resources)
49 ERR("Failed to allocate sub-resource array.\n");
50 resource_cleanup((IWineD3DResource *)texture);
51 return E_OUTOFMEMORY;
54 texture->baseTexture.layer_count = layer_count;
55 texture->baseTexture.level_count = level_count;
56 texture->baseTexture.filterType = (usage & WINED3DUSAGE_AUTOGENMIPMAP) ? WINED3DTEXF_LINEAR : WINED3DTEXF_NONE;
57 texture->baseTexture.LOD = 0;
58 texture->baseTexture.texture_rgb.dirty = TRUE;
59 texture->baseTexture.texture_srgb.dirty = TRUE;
60 texture->baseTexture.is_srgb = FALSE;
61 texture->baseTexture.pow2Matrix_identity = TRUE;
63 if (texture->resource.format_desc->Flags & WINED3DFMT_FLAG_FILTERING)
65 texture->baseTexture.minMipLookup = minMipLookup;
66 texture->baseTexture.magLookup = magLookup;
68 else
70 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
71 texture->baseTexture.magLookup = magLookup_noFilter;
74 return WINED3D_OK;
77 void basetexture_cleanup(IWineD3DBaseTexture *iface)
79 basetexture_unload(iface);
80 HeapFree(GetProcessHeap(), 0, ((IWineD3DBaseTextureImpl *)iface)->baseTexture.sub_resources);
81 resource_cleanup((IWineD3DResource *)iface);
84 IWineD3DResourceImpl *basetexture_get_sub_resource(IWineD3DBaseTextureImpl *texture, UINT layer, UINT level)
86 if (layer >= texture->baseTexture.layer_count)
88 WARN("layer %u >= layer_count %u.\n", layer, texture->baseTexture.layer_count);
89 return NULL;
92 if (level >= texture->baseTexture.level_count)
94 WARN("level %u >= level_count %u.\n", level, texture->baseTexture.level_count);
95 return NULL;
98 return texture->baseTexture.sub_resources[layer * texture->baseTexture.level_count + level];
101 /* A GL context is provided by the caller */
102 static void gltexture_delete(struct gl_texture *tex)
104 ENTER_GL();
105 glDeleteTextures(1, &tex->name);
106 LEAVE_GL();
107 tex->name = 0;
110 void basetexture_unload(IWineD3DBaseTexture *iface)
112 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
113 IWineD3DDeviceImpl *device = This->resource.device;
114 struct wined3d_context *context = NULL;
116 if (This->baseTexture.texture_rgb.name || This->baseTexture.texture_srgb.name)
118 context = context_acquire(device, NULL);
121 if(This->baseTexture.texture_rgb.name) {
122 gltexture_delete(&This->baseTexture.texture_rgb);
124 if(This->baseTexture.texture_srgb.name) {
125 gltexture_delete(&This->baseTexture.texture_srgb);
128 if (context) context_release(context);
130 This->baseTexture.texture_rgb.dirty = TRUE;
131 This->baseTexture.texture_srgb.dirty = TRUE;
134 DWORD basetexture_set_lod(IWineD3DBaseTexture *iface, DWORD LODNew)
136 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
137 DWORD old = This->baseTexture.LOD;
139 /* The d3d9:texture test shows that SetLOD is ignored on non-managed
140 * textures. The call always returns 0, and GetLOD always returns 0
142 if (This->resource.pool != WINED3DPOOL_MANAGED) {
143 TRACE("Ignoring SetLOD on %s texture, returning 0\n", debug_d3dpool(This->resource.pool));
144 return 0;
147 if (LODNew >= This->baseTexture.level_count)
148 LODNew = This->baseTexture.level_count - 1;
150 if(This->baseTexture.LOD != LODNew) {
151 This->baseTexture.LOD = LODNew;
153 This->baseTexture.texture_rgb.states[WINED3DTEXSTA_MAXMIPLEVEL] = ~0U;
154 This->baseTexture.texture_srgb.states[WINED3DTEXSTA_MAXMIPLEVEL] = ~0U;
155 if(This->baseTexture.bindCount) {
156 IWineD3DDeviceImpl_MarkStateDirty(This->resource.device, STATE_SAMPLER(This->baseTexture.sampler));
160 TRACE("(%p) : set LOD to %d\n", This, This->baseTexture.LOD);
162 return old;
165 DWORD basetexture_get_lod(IWineD3DBaseTexture *iface)
167 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
169 TRACE("(%p) : returning %d\n", This, This->baseTexture.LOD);
171 return This->baseTexture.LOD;
174 DWORD basetexture_get_level_count(IWineD3DBaseTexture *iface)
176 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
177 TRACE("iface %p, returning %u.\n", iface, This->baseTexture.level_count);
178 return This->baseTexture.level_count;
181 HRESULT basetexture_set_autogen_filter_type(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType)
183 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
184 IWineD3DDeviceImpl *device = This->resource.device;
185 UINT textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
187 if (!(This->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP)) {
188 TRACE("(%p) : returning invalid call\n", This);
189 return WINED3DERR_INVALIDCALL;
191 if(This->baseTexture.filterType != FilterType) {
192 /* What about multithreading? Do we want all the context overhead just to set this value?
193 * Or should we delay the applying until the texture is used for drawing? For now, apply
194 * immediately.
196 struct wined3d_context *context = context_acquire(device, NULL);
198 ENTER_GL();
199 glBindTexture(textureDimensions, This->baseTexture.texture_rgb.name);
200 checkGLcall("glBindTexture");
201 switch(FilterType) {
202 case WINED3DTEXF_NONE:
203 case WINED3DTEXF_POINT:
204 glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_FASTEST);
205 checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_FASTEST)");
207 break;
208 case WINED3DTEXF_LINEAR:
209 glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST);
210 checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST)");
212 break;
213 default:
214 WARN("Unexpected filter type %d, setting to GL_NICEST\n", FilterType);
215 glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST);
216 checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST)");
218 LEAVE_GL();
220 context_release(context);
222 This->baseTexture.filterType = FilterType;
223 TRACE("(%p) :\n", This);
224 return WINED3D_OK;
227 WINED3DTEXTUREFILTERTYPE basetexture_get_autogen_filter_type(IWineD3DBaseTexture *iface)
229 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
231 FIXME("(%p) : stub\n", This);
233 return This->baseTexture.filterType;
236 void basetexture_generate_mipmaps(IWineD3DBaseTexture *iface)
238 /* TODO: Implement filters using GL_SGI_generate_mipmaps. */
239 FIXME("iface %p stub!\n", iface);
242 BOOL basetexture_set_dirty(IWineD3DBaseTexture *iface, BOOL dirty)
244 BOOL old;
245 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
246 old = This->baseTexture.texture_rgb.dirty || This->baseTexture.texture_srgb.dirty;
247 This->baseTexture.texture_rgb.dirty = dirty;
248 This->baseTexture.texture_srgb.dirty = dirty;
249 return old;
252 BOOL basetexture_get_dirty(IWineD3DBaseTexture *iface)
254 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
255 return This->baseTexture.texture_rgb.dirty || This->baseTexture.texture_srgb.dirty;
258 /* Context activation is done by the caller. */
259 HRESULT basetexture_bind(IWineD3DBaseTexture *iface, BOOL srgb, BOOL *set_surface_desc)
261 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
262 HRESULT hr = WINED3D_OK;
263 UINT textureDimensions;
264 BOOL isNewTexture = FALSE;
265 struct gl_texture *gl_tex;
266 TRACE("(%p) : About to bind texture\n", This);
268 This->baseTexture.is_srgb = srgb; /* SRGB mode cache for PreLoad calls outside drawprim */
269 if(srgb) {
270 gl_tex = &This->baseTexture.texture_srgb;
271 } else {
272 gl_tex = &This->baseTexture.texture_rgb;
275 textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
276 ENTER_GL();
277 /* Generate a texture name if we don't already have one */
278 if (gl_tex->name == 0) {
279 *set_surface_desc = TRUE;
280 glGenTextures(1, &gl_tex->name);
281 checkGLcall("glGenTextures");
282 TRACE("Generated texture %d\n", gl_tex->name);
283 if (This->resource.pool == WINED3DPOOL_DEFAULT) {
284 /* Tell opengl to try and keep this texture in video ram (well mostly) */
285 GLclampf tmp;
286 tmp = 0.9f;
287 glPrioritizeTextures(1, &gl_tex->name, &tmp);
290 /* Initialise the state of the texture object
291 to the openGL defaults, not the directx defaults */
292 gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3DTADDRESS_WRAP;
293 gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3DTADDRESS_WRAP;
294 gl_tex->states[WINED3DTEXSTA_ADDRESSW] = WINED3DTADDRESS_WRAP;
295 gl_tex->states[WINED3DTEXSTA_BORDERCOLOR] = 0;
296 gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_LINEAR;
297 gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT; /* GL_NEAREST_MIPMAP_LINEAR */
298 gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_LINEAR; /* GL_NEAREST_MIPMAP_LINEAR */
299 gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] = 0;
300 gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] = 1;
301 gl_tex->states[WINED3DTEXSTA_SRGBTEXTURE] = 0;
302 gl_tex->states[WINED3DTEXSTA_SHADOW] = FALSE;
303 IWineD3DBaseTexture_SetDirty(iface, TRUE);
304 isNewTexture = TRUE;
306 if(This->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP) {
307 /* This means double binding the texture at creation, but keeps the code simpler all
308 * in all, and the run-time path free from additional checks
310 glBindTexture(textureDimensions, gl_tex->name);
311 checkGLcall("glBindTexture");
312 glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
313 checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_SGIS, GL_TRUE)");
315 } else {
316 *set_surface_desc = FALSE;
319 /* Bind the texture */
320 if (gl_tex->name != 0) {
321 glBindTexture(textureDimensions, gl_tex->name);
322 checkGLcall("glBindTexture");
323 if (isNewTexture) {
324 /* For a new texture we have to set the textures levels after binding the texture.
325 * In theory this is all we should ever have to do, but because ATI's drivers are broken, we
326 * also need to set the texture dimensions before the texture is set
327 * Beware that texture rectangles do not support mipmapping, but set the maxmiplevel if we're
328 * relying on the partial GL_ARB_texture_non_power_of_two emulation with texture rectangles
329 * (ie, do not care for cond_np2 here, just look for GL_TEXTURE_RECTANGLE_ARB)
331 if (textureDimensions != GL_TEXTURE_RECTANGLE_ARB)
333 TRACE("Setting GL_TEXTURE_MAX_LEVEL to %u.\n", This->baseTexture.level_count - 1);
334 glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, This->baseTexture.level_count - 1);
335 checkGLcall("glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, This->baseTexture.level_count)");
337 if(textureDimensions==GL_TEXTURE_CUBE_MAP_ARB) {
338 /* Cubemaps are always set to clamp, regardless of the sampler state. */
339 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
340 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
341 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
344 } else { /* this only happened if we've run out of openGL textures */
345 WARN("This texture doesn't have an openGL texture assigned to it\n");
346 hr = WINED3DERR_INVALIDCALL;
349 LEAVE_GL();
350 return hr;
353 /* GL locking is done by the caller */
354 static void apply_wrap(const struct wined3d_gl_info *gl_info, GLenum target,
355 WINED3DTEXTUREADDRESS d3d_wrap, GLenum param, BOOL cond_np2)
357 GLint gl_wrap;
359 if (d3d_wrap < WINED3DTADDRESS_WRAP || d3d_wrap > WINED3DTADDRESS_MIRRORONCE)
361 FIXME("Unrecognized or unsupported WINED3DTEXTUREADDRESS %#x.\n", d3d_wrap);
362 return;
365 if (target == GL_TEXTURE_CUBE_MAP_ARB
366 || (cond_np2 && d3d_wrap == WINED3DTADDRESS_WRAP))
368 /* Cubemaps are always set to clamp, regardless of the sampler state. */
369 gl_wrap = GL_CLAMP_TO_EDGE;
371 else
373 gl_wrap = gl_info->wrap_lookup[d3d_wrap - WINED3DTADDRESS_WRAP];
376 TRACE("Setting param %#x to %#x for target %#x.\n", param, gl_wrap, target);
377 glTexParameteri(target, param, gl_wrap);
378 checkGLcall("glTexParameteri(target, param, gl_wrap)");
381 /* GL locking is done by the caller (state handler) */
382 void basetexture_apply_state_changes(IWineD3DBaseTexture *iface,
383 const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1],
384 const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1],
385 const struct wined3d_gl_info *gl_info)
387 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
388 DWORD state;
389 GLint textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
390 BOOL cond_np2 = IWineD3DBaseTexture_IsCondNP2(iface);
391 DWORD aniso;
392 struct gl_texture *gl_tex;
394 TRACE("iface %p, textureStates %p, samplerStates %p\n", iface, textureStates, samplerStates);
396 if(This->baseTexture.is_srgb) {
397 gl_tex = &This->baseTexture.texture_srgb;
398 } else {
399 gl_tex = &This->baseTexture.texture_rgb;
402 /* This function relies on the correct texture being bound and loaded. */
404 if(samplerStates[WINED3DSAMP_ADDRESSU] != gl_tex->states[WINED3DTEXSTA_ADDRESSU]) {
405 state = samplerStates[WINED3DSAMP_ADDRESSU];
406 apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_S, cond_np2);
407 gl_tex->states[WINED3DTEXSTA_ADDRESSU] = state;
410 if(samplerStates[WINED3DSAMP_ADDRESSV] != gl_tex->states[WINED3DTEXSTA_ADDRESSV]) {
411 state = samplerStates[WINED3DSAMP_ADDRESSV];
412 apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_T, cond_np2);
413 gl_tex->states[WINED3DTEXSTA_ADDRESSV] = state;
416 if(samplerStates[WINED3DSAMP_ADDRESSW] != gl_tex->states[WINED3DTEXSTA_ADDRESSW]) {
417 state = samplerStates[WINED3DSAMP_ADDRESSW];
418 apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_R, cond_np2);
419 gl_tex->states[WINED3DTEXSTA_ADDRESSW] = state;
422 if(samplerStates[WINED3DSAMP_BORDERCOLOR] != gl_tex->states[WINED3DTEXSTA_BORDERCOLOR]) {
423 float col[4];
425 state = samplerStates[WINED3DSAMP_BORDERCOLOR];
426 D3DCOLORTOGLFLOAT4(state, col);
427 TRACE("Setting border color for %u to %x\n", textureDimensions, state);
428 glTexParameterfv(textureDimensions, GL_TEXTURE_BORDER_COLOR, &col[0]);
429 checkGLcall("glTexParameteri(..., GL_TEXTURE_BORDER_COLOR, ...)");
430 gl_tex->states[WINED3DTEXSTA_BORDERCOLOR] = state;
433 if(samplerStates[WINED3DSAMP_MAGFILTER] != gl_tex->states[WINED3DTEXSTA_MAGFILTER]) {
434 GLint glValue;
435 state = samplerStates[WINED3DSAMP_MAGFILTER];
436 if (state > WINED3DTEXF_ANISOTROPIC) {
437 FIXME("Unrecognized or unsupported MAGFILTER* value %d\n", state);
440 glValue = wined3d_gl_mag_filter(This->baseTexture.magLookup,
441 min(max(state, WINED3DTEXF_POINT), WINED3DTEXF_LINEAR));
442 TRACE("ValueMAG=%d setting MAGFILTER to %x\n", state, glValue);
443 glTexParameteri(textureDimensions, GL_TEXTURE_MAG_FILTER, glValue);
445 gl_tex->states[WINED3DTEXSTA_MAGFILTER] = state;
448 if((samplerStates[WINED3DSAMP_MINFILTER] != gl_tex->states[WINED3DTEXSTA_MINFILTER] ||
449 samplerStates[WINED3DSAMP_MIPFILTER] != gl_tex->states[WINED3DTEXSTA_MIPFILTER] ||
450 samplerStates[WINED3DSAMP_MAXMIPLEVEL] != gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL])) {
451 GLint glValue;
453 gl_tex->states[WINED3DTEXSTA_MIPFILTER] = samplerStates[WINED3DSAMP_MIPFILTER];
454 gl_tex->states[WINED3DTEXSTA_MINFILTER] = samplerStates[WINED3DSAMP_MINFILTER];
455 gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] = samplerStates[WINED3DSAMP_MAXMIPLEVEL];
457 if (gl_tex->states[WINED3DTEXSTA_MINFILTER] > WINED3DTEXF_ANISOTROPIC
458 || gl_tex->states[WINED3DTEXSTA_MIPFILTER] > WINED3DTEXF_ANISOTROPIC)
461 FIXME("Unrecognized or unsupported D3DSAMP_MINFILTER value %d D3DSAMP_MIPFILTER value %d\n",
462 gl_tex->states[WINED3DTEXSTA_MINFILTER],
463 gl_tex->states[WINED3DTEXSTA_MIPFILTER]);
465 glValue = wined3d_gl_min_mip_filter(This->baseTexture.minMipLookup,
466 min(max(samplerStates[WINED3DSAMP_MINFILTER], WINED3DTEXF_POINT), WINED3DTEXF_LINEAR),
467 min(max(samplerStates[WINED3DSAMP_MIPFILTER], WINED3DTEXF_NONE), WINED3DTEXF_LINEAR));
469 TRACE("ValueMIN=%d, ValueMIP=%d, setting MINFILTER to %x\n",
470 samplerStates[WINED3DSAMP_MINFILTER],
471 samplerStates[WINED3DSAMP_MIPFILTER], glValue);
472 glTexParameteri(textureDimensions, GL_TEXTURE_MIN_FILTER, glValue);
473 checkGLcall("glTexParameter GL_TEXTURE_MIN_FILTER, ...");
475 if (!cond_np2)
477 if (gl_tex->states[WINED3DTEXSTA_MIPFILTER] == WINED3DTEXF_NONE)
478 glValue = This->baseTexture.LOD;
479 else if (gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] >= This->baseTexture.level_count)
480 glValue = This->baseTexture.level_count - 1;
481 else if (gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] < This->baseTexture.LOD)
482 /* baseTexture.LOD is already clamped in the setter */
483 glValue = This->baseTexture.LOD;
484 else
485 glValue = gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL];
487 /* Note that D3DSAMP_MAXMIPLEVEL specifies the biggest mipmap(default 0), while
488 * GL_TEXTURE_MAX_LEVEL specifies the smallest mimap used(default 1000).
489 * So D3DSAMP_MAXMIPLEVEL is the same as GL_TEXTURE_BASE_LEVEL.
491 glTexParameteri(textureDimensions, GL_TEXTURE_BASE_LEVEL, glValue);
495 if ((gl_tex->states[WINED3DTEXSTA_MAGFILTER] != WINED3DTEXF_ANISOTROPIC
496 && gl_tex->states[WINED3DTEXSTA_MINFILTER] != WINED3DTEXF_ANISOTROPIC
497 && gl_tex->states[WINED3DTEXSTA_MIPFILTER] != WINED3DTEXF_ANISOTROPIC)
498 || cond_np2)
500 aniso = 1;
502 else
504 aniso = samplerStates[WINED3DSAMP_MAXANISOTROPY];
507 if (gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] != aniso)
509 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
511 glTexParameteri(textureDimensions, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso);
512 checkGLcall("glTexParameteri(GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso)");
514 else
516 WARN("Anisotropic filtering not supported.\n");
518 gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] = aniso;
521 if (!(This->resource.format_desc->Flags & WINED3DFMT_FLAG_SHADOW)
522 != !gl_tex->states[WINED3DTEXSTA_SHADOW])
524 if (This->resource.format_desc->Flags & WINED3DFMT_FLAG_SHADOW)
526 glTexParameteri(textureDimensions, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);
527 glTexParameteri(textureDimensions, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
528 checkGLcall("glTexParameteri(textureDimensions, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB)");
529 gl_tex->states[WINED3DTEXSTA_SHADOW] = TRUE;
531 else
533 glTexParameteri(textureDimensions, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
534 checkGLcall("glTexParameteri(textureDimensions, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE)");
535 gl_tex->states[WINED3DTEXSTA_SHADOW] = FALSE;