oleaut32: Use implementation pointer to avoid casts.
[wine] / dlls / wined3d / basetexture.c
1 /*
2  * IWineD3DBaseTexture Implementation
3  *
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-2010 Henri Verbeet for CodeWeavers
9  *
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.
14  *
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.
19  *
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
23  */
24
25 #include "config.h"
26 #include "wined3d_private.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
29
30 HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT layer_count, UINT level_count,
31         WINED3DRESOURCETYPE resource_type, IWineD3DDeviceImpl *device, DWORD usage,
32         const struct wined3d_format *format, WINED3DPOOL pool, void *parent,
33         const struct wined3d_parent_ops *parent_ops)
34 {
35     HRESULT hr;
36
37     hr = resource_init((IWineD3DResource *)texture, resource_type, device,
38             0, usage, format, pool, parent, parent_ops);
39     if (FAILED(hr))
40     {
41         WARN("Failed to initialize resource, returning %#x\n", hr);
42         return hr;
43     }
44
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)
48     {
49         ERR("Failed to allocate sub-resource array.\n");
50         resource_cleanup((IWineD3DResource *)texture);
51         return E_OUTOFMEMORY;
52     }
53
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;
62
63     if (texture->resource.format->flags & WINED3DFMT_FLAG_FILTERING)
64     {
65         texture->baseTexture.minMipLookup = minMipLookup;
66         texture->baseTexture.magLookup = magLookup;
67     }
68     else
69     {
70         texture->baseTexture.minMipLookup = minMipLookup_noFilter;
71         texture->baseTexture.magLookup = magLookup_noFilter;
72     }
73
74     return WINED3D_OK;
75 }
76
77 void basetexture_cleanup(IWineD3DBaseTextureImpl *texture)
78 {
79     basetexture_unload(texture);
80     HeapFree(GetProcessHeap(), 0, texture->baseTexture.sub_resources);
81     resource_cleanup((IWineD3DResource *)texture);
82 }
83
84 IWineD3DResourceImpl *basetexture_get_sub_resource(IWineD3DBaseTextureImpl *texture, UINT sub_resource_idx)
85 {
86     UINT sub_count = texture->baseTexture.level_count * texture->baseTexture.layer_count;
87
88     if (sub_resource_idx >= sub_count)
89     {
90         WARN("sub_resource_idx %u >= sub_count %u.\n", sub_resource_idx, sub_count);
91         return NULL;
92     }
93
94     return texture->baseTexture.sub_resources[sub_resource_idx];
95 }
96
97 /* A GL context is provided by the caller */
98 static void gltexture_delete(struct gl_texture *tex)
99 {
100     ENTER_GL();
101     glDeleteTextures(1, &tex->name);
102     LEAVE_GL();
103     tex->name = 0;
104 }
105
106 void basetexture_unload(IWineD3DBaseTextureImpl *texture)
107 {
108     IWineD3DDeviceImpl *device = texture->resource.device;
109     struct wined3d_context *context = NULL;
110
111     if (texture->baseTexture.texture_rgb.name || texture->baseTexture.texture_srgb.name)
112     {
113         context = context_acquire(device, NULL);
114     }
115
116     if (texture->baseTexture.texture_rgb.name)
117         gltexture_delete(&texture->baseTexture.texture_rgb);
118
119     if (texture->baseTexture.texture_srgb.name)
120         gltexture_delete(&texture->baseTexture.texture_srgb);
121
122     if (context) context_release(context);
123
124     texture->baseTexture.texture_rgb.dirty = TRUE;
125     texture->baseTexture.texture_srgb.dirty = TRUE;
126
127     resource_unload((IWineD3DResourceImpl *)texture);
128 }
129
130 DWORD basetexture_set_lod(IWineD3DBaseTextureImpl *texture, DWORD lod)
131 {
132     DWORD old = texture->baseTexture.LOD;
133
134     TRACE("texture %p, lod %u.\n", texture, lod);
135
136     /* The d3d9:texture test shows that SetLOD is ignored on non-managed
137      * textures. The call always returns 0, and GetLOD always returns 0. */
138     if (texture->resource.pool != WINED3DPOOL_MANAGED)
139     {
140         TRACE("Ignoring SetLOD on %s texture, returning 0.\n", debug_d3dpool(texture->resource.pool));
141         return 0;
142     }
143
144     if (lod >= texture->baseTexture.level_count)
145         lod = texture->baseTexture.level_count - 1;
146
147     if (texture->baseTexture.LOD != lod)
148     {
149         texture->baseTexture.LOD = lod;
150
151         texture->baseTexture.texture_rgb.states[WINED3DTEXSTA_MAXMIPLEVEL] = ~0U;
152         texture->baseTexture.texture_srgb.states[WINED3DTEXSTA_MAXMIPLEVEL] = ~0U;
153         if (texture->baseTexture.bindCount)
154             IWineD3DDeviceImpl_MarkStateDirty(texture->resource.device, STATE_SAMPLER(texture->baseTexture.sampler));
155     }
156
157     return old;
158 }
159
160 DWORD basetexture_get_lod(IWineD3DBaseTextureImpl *texture)
161 {
162     TRACE("texture %p, returning %u.\n", texture, texture->baseTexture.LOD);
163
164     return texture->baseTexture.LOD;
165 }
166
167 DWORD basetexture_get_level_count(IWineD3DBaseTextureImpl *texture)
168 {
169     TRACE("texture %p, returning %u.\n", texture, texture->baseTexture.level_count);
170     return texture->baseTexture.level_count;
171 }
172
173 HRESULT basetexture_set_autogen_filter_type(IWineD3DBaseTextureImpl *texture, WINED3DTEXTUREFILTERTYPE filter_type)
174 {
175     TRACE("texture %p, filter_type %s.\n", texture, debug_d3dtexturefiltertype(filter_type));
176
177     if (!(texture->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP))
178     {
179         WARN("Texture doesn't have AUTOGENMIPMAP usage.\n");
180         return WINED3DERR_INVALIDCALL;
181     }
182
183     if (texture->baseTexture.filterType != filter_type)
184     {
185         GLenum target = texture->baseTexture.target;
186         struct wined3d_context *context;
187
188         context = context_acquire(texture->resource.device, NULL);
189
190         ENTER_GL();
191         glBindTexture(target, texture->baseTexture.texture_rgb.name);
192         checkGLcall("glBindTexture");
193         switch (filter_type)
194         {
195             case WINED3DTEXF_NONE:
196             case WINED3DTEXF_POINT:
197                 glTexParameteri(target, GL_GENERATE_MIPMAP_HINT_SGIS, GL_FASTEST);
198                 checkGLcall("glTexParameteri(target, GL_GENERATE_MIPMAP_HINT_SGIS, GL_FASTEST)");
199                 break;
200
201             case WINED3DTEXF_LINEAR:
202                 glTexParameteri(target, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST);
203                 checkGLcall("glTexParameteri(target, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST)");
204                 break;
205
206             default:
207                 WARN("Unexpected filter type %#x, setting to GL_NICEST.\n", filter_type);
208                 glTexParameteri(target, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST);
209                 checkGLcall("glTexParameteri(target, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST)");
210                 break;
211         }
212         LEAVE_GL();
213
214         context_release(context);
215     }
216     texture->baseTexture.filterType = filter_type;
217
218     return WINED3D_OK;
219 }
220
221 WINED3DTEXTUREFILTERTYPE basetexture_get_autogen_filter_type(IWineD3DBaseTextureImpl *texture)
222 {
223     TRACE("texture %p.\n", texture);
224
225     return texture->baseTexture.filterType;
226 }
227
228 void basetexture_generate_mipmaps(IWineD3DBaseTextureImpl *texture)
229 {
230     /* TODO: Implement filters using GL_SGI_generate_mipmaps. */
231     FIXME("texture %p stub!\n", texture);
232 }
233
234 BOOL basetexture_set_dirty(IWineD3DBaseTextureImpl *texture, BOOL dirty)
235 {
236     BOOL old;
237
238     old = texture->baseTexture.texture_rgb.dirty || texture->baseTexture.texture_srgb.dirty;
239     texture->baseTexture.texture_rgb.dirty = dirty;
240     texture->baseTexture.texture_srgb.dirty = dirty;
241
242     return old;
243 }
244
245 /* Context activation is done by the caller. */
246 HRESULT basetexture_bind(IWineD3DBaseTextureImpl *texture, BOOL srgb, BOOL *set_surface_desc)
247 {
248     HRESULT hr = WINED3D_OK;
249     GLenum textureDimensions;
250     BOOL isNewTexture = FALSE;
251     struct gl_texture *gl_tex;
252
253     TRACE("texture %p, srgb %#x, set_surface_desc %p.\n", texture, srgb, set_surface_desc);
254
255     texture->baseTexture.is_srgb = srgb; /* SRGB mode cache for PreLoad calls outside drawprim */
256     if (srgb)
257         gl_tex = &texture->baseTexture.texture_srgb;
258     else
259         gl_tex = &texture->baseTexture.texture_rgb;
260
261     textureDimensions = texture->baseTexture.target;
262
263     ENTER_GL();
264     /* Generate a texture name if we don't already have one */
265     if (!gl_tex->name)
266     {
267         *set_surface_desc = TRUE;
268         glGenTextures(1, &gl_tex->name);
269         checkGLcall("glGenTextures");
270         TRACE("Generated texture %d\n", gl_tex->name);
271         if (texture->resource.pool == WINED3DPOOL_DEFAULT)
272         {
273             /* Tell opengl to try and keep this texture in video ram (well mostly) */
274             GLclampf tmp;
275             tmp = 0.9f;
276             glPrioritizeTextures(1, &gl_tex->name, &tmp);
277
278         }
279         /* Initialise the state of the texture object
280         to the openGL defaults, not the directx defaults */
281         gl_tex->states[WINED3DTEXSTA_ADDRESSU]      = WINED3DTADDRESS_WRAP;
282         gl_tex->states[WINED3DTEXSTA_ADDRESSV]      = WINED3DTADDRESS_WRAP;
283         gl_tex->states[WINED3DTEXSTA_ADDRESSW]      = WINED3DTADDRESS_WRAP;
284         gl_tex->states[WINED3DTEXSTA_BORDERCOLOR]   = 0;
285         gl_tex->states[WINED3DTEXSTA_MAGFILTER]     = WINED3DTEXF_LINEAR;
286         gl_tex->states[WINED3DTEXSTA_MINFILTER]     = WINED3DTEXF_POINT; /* GL_NEAREST_MIPMAP_LINEAR */
287         gl_tex->states[WINED3DTEXSTA_MIPFILTER]     = WINED3DTEXF_LINEAR; /* GL_NEAREST_MIPMAP_LINEAR */
288         gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL]   = 0;
289         gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] = 1;
290         gl_tex->states[WINED3DTEXSTA_SRGBTEXTURE]   = 0;
291         gl_tex->states[WINED3DTEXSTA_SHADOW]        = FALSE;
292         basetexture_set_dirty(texture, TRUE);
293         isNewTexture = TRUE;
294
295         if (texture->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP)
296         {
297             /* This means double binding the texture at creation, but keeps the code simpler all
298              * in all, and the run-time path free from additional checks
299              */
300             glBindTexture(textureDimensions, gl_tex->name);
301             checkGLcall("glBindTexture");
302             glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
303             checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_SGIS, GL_TRUE)");
304         }
305     } else {
306         *set_surface_desc = FALSE;
307     }
308
309     /* Bind the texture */
310     if (gl_tex->name)
311     {
312         glBindTexture(textureDimensions, gl_tex->name);
313         checkGLcall("glBindTexture");
314         if (isNewTexture) {
315             /* For a new texture we have to set the textures levels after binding the texture.
316              * In theory this is all we should ever have to do, but because ATI's drivers are broken, we
317              * also need to set the texture dimensions before the texture is set
318              * Beware that texture rectangles do not support mipmapping, but set the maxmiplevel if we're
319              * relying on the partial GL_ARB_texture_non_power_of_two emulation with texture rectangles
320              * (ie, do not care for cond_np2 here, just look for GL_TEXTURE_RECTANGLE_ARB)
321              */
322             if (textureDimensions != GL_TEXTURE_RECTANGLE_ARB)
323             {
324                 TRACE("Setting GL_TEXTURE_MAX_LEVEL to %u.\n", texture->baseTexture.level_count - 1);
325                 glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, texture->baseTexture.level_count - 1);
326                 checkGLcall("glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, texture->baseTexture.level_count)");
327             }
328             if(textureDimensions==GL_TEXTURE_CUBE_MAP_ARB) {
329                 /* Cubemaps are always set to clamp, regardless of the sampler state. */
330                 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
331                 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
332                 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
333             }
334         }
335     } else { /* this only happened if we've run out of openGL textures */
336         WARN("This texture doesn't have an openGL texture assigned to it\n");
337         hr =  WINED3DERR_INVALIDCALL;
338     }
339
340     LEAVE_GL();
341     return hr;
342 }
343
344 /* GL locking is done by the caller */
345 static void apply_wrap(const struct wined3d_gl_info *gl_info, GLenum target,
346         WINED3DTEXTUREADDRESS d3d_wrap, GLenum param, BOOL cond_np2)
347 {
348     GLint gl_wrap;
349
350     if (d3d_wrap < WINED3DTADDRESS_WRAP || d3d_wrap > WINED3DTADDRESS_MIRRORONCE)
351     {
352         FIXME("Unrecognized or unsupported WINED3DTEXTUREADDRESS %#x.\n", d3d_wrap);
353         return;
354     }
355
356     if (target == GL_TEXTURE_CUBE_MAP_ARB
357             || (cond_np2 && d3d_wrap == WINED3DTADDRESS_WRAP))
358     {
359         /* Cubemaps are always set to clamp, regardless of the sampler state. */
360         gl_wrap = GL_CLAMP_TO_EDGE;
361     }
362     else
363     {
364         gl_wrap = gl_info->wrap_lookup[d3d_wrap - WINED3DTADDRESS_WRAP];
365     }
366
367     TRACE("Setting param %#x to %#x for target %#x.\n", param, gl_wrap, target);
368     glTexParameteri(target, param, gl_wrap);
369     checkGLcall("glTexParameteri(target, param, gl_wrap)");
370 }
371
372 /* GL locking is done by the caller (state handler) */
373 void basetexture_apply_state_changes(IWineD3DBaseTextureImpl *texture,
374         const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1],
375         const struct wined3d_gl_info *gl_info)
376 {
377     BOOL cond_np2 = IWineD3DBaseTexture_IsCondNP2((IWineD3DBaseTexture *)texture);
378     GLenum textureDimensions = texture->baseTexture.target;
379     DWORD state;
380     DWORD aniso;
381     struct gl_texture *gl_tex;
382
383     TRACE("texture %p, samplerStates %p\n", texture, samplerStates);
384
385     if (texture->baseTexture.is_srgb)
386         gl_tex = &texture->baseTexture.texture_srgb;
387     else
388         gl_tex = &texture->baseTexture.texture_rgb;
389
390     /* This function relies on the correct texture being bound and loaded. */
391
392     if(samplerStates[WINED3DSAMP_ADDRESSU]      != gl_tex->states[WINED3DTEXSTA_ADDRESSU]) {
393         state = samplerStates[WINED3DSAMP_ADDRESSU];
394         apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_S, cond_np2);
395         gl_tex->states[WINED3DTEXSTA_ADDRESSU] = state;
396     }
397
398     if(samplerStates[WINED3DSAMP_ADDRESSV]      != gl_tex->states[WINED3DTEXSTA_ADDRESSV]) {
399         state = samplerStates[WINED3DSAMP_ADDRESSV];
400         apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_T, cond_np2);
401         gl_tex->states[WINED3DTEXSTA_ADDRESSV] = state;
402     }
403
404     if(samplerStates[WINED3DSAMP_ADDRESSW]      != gl_tex->states[WINED3DTEXSTA_ADDRESSW]) {
405         state = samplerStates[WINED3DSAMP_ADDRESSW];
406         apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_R, cond_np2);
407         gl_tex->states[WINED3DTEXSTA_ADDRESSW] = state;
408     }
409
410     if(samplerStates[WINED3DSAMP_BORDERCOLOR]   != gl_tex->states[WINED3DTEXSTA_BORDERCOLOR]) {
411         float col[4];
412
413         state = samplerStates[WINED3DSAMP_BORDERCOLOR];
414         D3DCOLORTOGLFLOAT4(state, col);
415         TRACE("Setting border color for %u to %x\n", textureDimensions, state);
416         glTexParameterfv(textureDimensions, GL_TEXTURE_BORDER_COLOR, &col[0]);
417         checkGLcall("glTexParameterfv(..., GL_TEXTURE_BORDER_COLOR, ...)");
418         gl_tex->states[WINED3DTEXSTA_BORDERCOLOR] = state;
419     }
420
421     if(samplerStates[WINED3DSAMP_MAGFILTER]     != gl_tex->states[WINED3DTEXSTA_MAGFILTER]) {
422         GLint glValue;
423         state = samplerStates[WINED3DSAMP_MAGFILTER];
424         if (state > WINED3DTEXF_ANISOTROPIC) {
425             FIXME("Unrecognized or unsupported MAGFILTER* value %d\n", state);
426         }
427
428         glValue = wined3d_gl_mag_filter(texture->baseTexture.magLookup,
429                 min(max(state, WINED3DTEXF_POINT), WINED3DTEXF_LINEAR));
430         TRACE("ValueMAG=%d setting MAGFILTER to %x\n", state, glValue);
431         glTexParameteri(textureDimensions, GL_TEXTURE_MAG_FILTER, glValue);
432
433         gl_tex->states[WINED3DTEXSTA_MAGFILTER] = state;
434     }
435
436     if((samplerStates[WINED3DSAMP_MINFILTER]     != gl_tex->states[WINED3DTEXSTA_MINFILTER] ||
437         samplerStates[WINED3DSAMP_MIPFILTER]     != gl_tex->states[WINED3DTEXSTA_MIPFILTER] ||
438         samplerStates[WINED3DSAMP_MAXMIPLEVEL]   != gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL])) {
439         GLint glValue;
440
441         gl_tex->states[WINED3DTEXSTA_MIPFILTER] = samplerStates[WINED3DSAMP_MIPFILTER];
442         gl_tex->states[WINED3DTEXSTA_MINFILTER] = samplerStates[WINED3DSAMP_MINFILTER];
443         gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] = samplerStates[WINED3DSAMP_MAXMIPLEVEL];
444
445         if (gl_tex->states[WINED3DTEXSTA_MINFILTER] > WINED3DTEXF_ANISOTROPIC
446             || gl_tex->states[WINED3DTEXSTA_MIPFILTER] > WINED3DTEXF_ANISOTROPIC)
447         {
448
449             FIXME("Unrecognized or unsupported D3DSAMP_MINFILTER value %d D3DSAMP_MIPFILTER value %d\n",
450                   gl_tex->states[WINED3DTEXSTA_MINFILTER],
451                   gl_tex->states[WINED3DTEXSTA_MIPFILTER]);
452         }
453         glValue = wined3d_gl_min_mip_filter(texture->baseTexture.minMipLookup,
454                 min(max(samplerStates[WINED3DSAMP_MINFILTER], WINED3DTEXF_POINT), WINED3DTEXF_LINEAR),
455                 min(max(samplerStates[WINED3DSAMP_MIPFILTER], WINED3DTEXF_NONE), WINED3DTEXF_LINEAR));
456
457         TRACE("ValueMIN=%d, ValueMIP=%d, setting MINFILTER to %x\n",
458               samplerStates[WINED3DSAMP_MINFILTER],
459               samplerStates[WINED3DSAMP_MIPFILTER], glValue);
460         glTexParameteri(textureDimensions, GL_TEXTURE_MIN_FILTER, glValue);
461         checkGLcall("glTexParameter GL_TEXTURE_MIN_FILTER, ...");
462
463         if (!cond_np2)
464         {
465             if (gl_tex->states[WINED3DTEXSTA_MIPFILTER] == WINED3DTEXF_NONE)
466                 glValue = texture->baseTexture.LOD;
467             else if (gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] >= texture->baseTexture.level_count)
468                 glValue = texture->baseTexture.level_count - 1;
469             else if (gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] < texture->baseTexture.LOD)
470                 /* baseTexture.LOD is already clamped in the setter */
471                 glValue = texture->baseTexture.LOD;
472             else
473                 glValue = gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL];
474
475             /* Note that D3DSAMP_MAXMIPLEVEL specifies the biggest mipmap(default 0), while
476              * GL_TEXTURE_MAX_LEVEL specifies the smallest mimap used(default 1000).
477              * So D3DSAMP_MAXMIPLEVEL is the same as GL_TEXTURE_BASE_LEVEL.
478              */
479             glTexParameteri(textureDimensions, GL_TEXTURE_BASE_LEVEL, glValue);
480         }
481     }
482
483     if ((gl_tex->states[WINED3DTEXSTA_MAGFILTER] != WINED3DTEXF_ANISOTROPIC
484          && gl_tex->states[WINED3DTEXSTA_MINFILTER] != WINED3DTEXF_ANISOTROPIC
485          && gl_tex->states[WINED3DTEXSTA_MIPFILTER] != WINED3DTEXF_ANISOTROPIC)
486             || cond_np2)
487     {
488         aniso = 1;
489     }
490     else
491     {
492         aniso = samplerStates[WINED3DSAMP_MAXANISOTROPY];
493     }
494
495     if (gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] != aniso)
496     {
497         if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
498         {
499             glTexParameteri(textureDimensions, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso);
500             checkGLcall("glTexParameteri(GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso)");
501         }
502         else
503         {
504             WARN("Anisotropic filtering not supported.\n");
505         }
506         gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] = aniso;
507     }
508
509     if (!(texture->resource.format->flags & WINED3DFMT_FLAG_SHADOW)
510             != !gl_tex->states[WINED3DTEXSTA_SHADOW])
511     {
512         if (texture->resource.format->flags & WINED3DFMT_FLAG_SHADOW)
513         {
514             glTexParameteri(textureDimensions, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);
515             glTexParameteri(textureDimensions, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
516             checkGLcall("glTexParameteri(textureDimensions, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB)");
517             gl_tex->states[WINED3DTEXSTA_SHADOW] = TRUE;
518         }
519         else
520         {
521             glTexParameteri(textureDimensions, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
522             checkGLcall("glTexParameteri(textureDimensions, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE)");
523             gl_tex->states[WINED3DTEXSTA_SHADOW] = FALSE;
524         }
525     }
526 }