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