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