VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/basetexture.c@ 33750

Last change on this file since 33750 was 33732, checked in by vboxsync, 14 years ago

wddm/3d: fix memory corruption

  • Property svn:eol-style set to native
File size: 21.0 KB
Line 
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/*
26 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
27 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
28 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
29 * a choice of LGPL license versions is made available with the language indicating
30 * that LGPLv2 or any later version may be used, or where a choice of which version
31 * of the LGPL is applied is otherwise unspecified.
32 */
33
34#include "config.h"
35#include "wined3d_private.h"
36
37WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
38
39HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT levels, WINED3DRESOURCETYPE resource_type,
40 IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct wined3d_format_desc *format_desc,
41 WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops
42#ifdef VBOX_WITH_WDDM
43 , HANDLE *shared_handle
44 , void *pvClientMem
45#endif
46 )
47{
48 HRESULT hr;
49
50 if (levels > MAX_MIP_LEVELS)
51 {
52 WARN("Too many texture levels %d", levels);
53 return WINED3DERR_INVALIDCALL;
54 }
55
56 hr = resource_init((IWineD3DResource *)texture, resource_type, device,
57 size, usage, format_desc, pool, parent, parent_ops
58#ifdef VBOX_WITH_WDDM
59 , shared_handle, pvClientMem
60#endif
61 );
62 if (FAILED(hr))
63 {
64 WARN("Failed to initialize resource, returning %#x\n", hr);
65 return hr;
66 }
67
68 texture->baseTexture.levels = levels;
69 texture->baseTexture.filterType = (usage & WINED3DUSAGE_AUTOGENMIPMAP) ? WINED3DTEXF_LINEAR : WINED3DTEXF_NONE;
70 texture->baseTexture.LOD = 0;
71 texture->baseTexture.texture_rgb.dirty = TRUE;
72 texture->baseTexture.texture_srgb.dirty = TRUE;
73 texture->baseTexture.is_srgb = FALSE;
74 texture->baseTexture.pow2Matrix_identity = TRUE;
75#if defined(VBOX_WITH_WDDM) && defined(DEBUG_leo)
76 texture->baseTexture.t_mirror = FALSE;
77#else
78 texture->baseTexture.t_mirror = FALSE;
79#endif
80
81 if (texture->resource.format_desc->Flags & WINED3DFMT_FLAG_FILTERING)
82 {
83 texture->baseTexture.minMipLookup = minMipLookup;
84 texture->baseTexture.magLookup = magLookup;
85 }
86 else
87 {
88 texture->baseTexture.minMipLookup = minMipLookup_noFilter;
89 texture->baseTexture.magLookup = magLookup_noFilter;
90 }
91
92 return WINED3D_OK;
93}
94
95void basetexture_cleanup(IWineD3DBaseTexture *iface)
96{
97 basetexture_unload(iface);
98 resource_cleanup((IWineD3DResource *)iface);
99}
100
101/* A GL context is provided by the caller */
102static void gltexture_delete(struct gl_texture *tex)
103{
104 ENTER_GL();
105 glDeleteTextures(1, &tex->name);
106 LEAVE_GL();
107 tex->name = 0;
108}
109
110void basetexture_unload(IWineD3DBaseTexture *iface)
111{
112 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
113 IWineD3DDeviceImpl *device = This->resource.device;
114 struct wined3d_context *context = NULL;
115
116 if (This->baseTexture.texture_rgb.name || This->baseTexture.texture_srgb.name)
117 {
118 context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
119 }
120
121 if(This->baseTexture.texture_rgb.name) {
122 gltexture_delete(&This->baseTexture.texture_rgb);
123 }
124 if(This->baseTexture.texture_srgb.name) {
125 gltexture_delete(&This->baseTexture.texture_srgb);
126 }
127
128 if (context) context_release(context);
129
130 This->baseTexture.texture_rgb.dirty = TRUE;
131 This->baseTexture.texture_srgb.dirty = TRUE;
132}
133
134DWORD basetexture_set_lod(IWineD3DBaseTexture *iface, DWORD LODNew)
135{
136 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
137 DWORD old = This->baseTexture.LOD;
138
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
141 */
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;
145 }
146
147 if(LODNew >= This->baseTexture.levels)
148 LODNew = This->baseTexture.levels - 1;
149
150 if(This->baseTexture.LOD != LODNew) {
151 This->baseTexture.LOD = LODNew;
152
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));
157 }
158 }
159
160 TRACE("(%p) : set LOD to %d\n", This, This->baseTexture.LOD);
161
162 return old;
163}
164
165DWORD basetexture_get_lod(IWineD3DBaseTexture *iface)
166{
167 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
168
169 TRACE("(%p) : returning %d\n", This, This->baseTexture.LOD);
170
171 return This->baseTexture.LOD;
172}
173
174DWORD basetexture_get_level_count(IWineD3DBaseTexture *iface)
175{
176 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
177 TRACE("(%p) : returning %d\n", This, This->baseTexture.levels);
178 return This->baseTexture.levels;
179}
180
181HRESULT basetexture_set_autogen_filter_type(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType)
182{
183 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
184 IWineD3DDeviceImpl *device = This->resource.device;
185 UINT textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
186
187 if (!(This->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP)) {
188 TRACE("(%p) : returning invalid call\n", This);
189 return WINED3DERR_INVALIDCALL;
190 }
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.
195 */
196 struct wined3d_context *context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
197
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)");
206
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)");
211
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)");
217 }
218 LEAVE_GL();
219
220 context_release(context);
221 }
222 This->baseTexture.filterType = FilterType;
223 TRACE("(%p) :\n", This);
224 return WINED3D_OK;
225}
226
227WINED3DTEXTUREFILTERTYPE basetexture_get_autogen_filter_type(IWineD3DBaseTexture *iface)
228{
229 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
230
231 FIXME("(%p) : stub\n", This);
232
233 return This->baseTexture.filterType;
234}
235
236void basetexture_generate_mipmaps(IWineD3DBaseTexture *iface)
237{
238 /* TODO: Implement filters using GL_SGI_generate_mipmaps. */
239 FIXME("iface %p stub!\n", iface);
240}
241
242BOOL basetexture_set_dirty(IWineD3DBaseTexture *iface, BOOL dirty)
243{
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;
250}
251
252BOOL basetexture_get_dirty(IWineD3DBaseTexture *iface)
253{
254 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
255 return This->baseTexture.texture_rgb.dirty || This->baseTexture.texture_srgb.dirty;
256}
257
258/* Context activation is done by the caller. */
259HRESULT basetexture_bind(IWineD3DBaseTexture *iface, BOOL srgb, BOOL *set_surface_desc)
260{
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);
267
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;
273 }
274
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#ifdef VBOX_WITH_WDDM
281 if (VBOXSHRC_IS_SHARED_OPENED(This))
282 {
283 gl_tex->name = VBOXSHRC_GET_SHAREHANDLE(This);
284 }
285 else
286#endif
287 {
288 glGenTextures(1, &gl_tex->name);
289#ifdef VBOX_WITH_WDDM
290 if (VBOXSHRC_IS_SHARED(This))
291 {
292 VBOXSHRC_SET_SHAREHANDLE(This, gl_tex->name);
293 }
294#endif
295 }
296 checkGLcall("glGenTextures");
297 TRACE("Generated texture %d\n", gl_tex->name);
298 if (This->resource.pool == WINED3DPOOL_DEFAULT) {
299 /* Tell opengl to try and keep this texture in video ram (well mostly) */
300 GLclampf tmp;
301 tmp = 0.9f;
302 glPrioritizeTextures(1, &gl_tex->name, &tmp);
303
304 }
305 /* Initialise the state of the texture object
306 to the openGL defaults, not the directx defaults */
307 gl_tex->states[WINED3DTEXSTA_ADDRESSU] = WINED3DTADDRESS_WRAP;
308 gl_tex->states[WINED3DTEXSTA_ADDRESSV] = WINED3DTADDRESS_WRAP;
309 gl_tex->states[WINED3DTEXSTA_ADDRESSW] = WINED3DTADDRESS_WRAP;
310 gl_tex->states[WINED3DTEXSTA_BORDERCOLOR] = 0;
311 gl_tex->states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_LINEAR;
312 gl_tex->states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT; /* GL_NEAREST_MIPMAP_LINEAR */
313 gl_tex->states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_LINEAR; /* GL_NEAREST_MIPMAP_LINEAR */
314 gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] = 0;
315 gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] = 1;
316 gl_tex->states[WINED3DTEXSTA_SRGBTEXTURE] = 0;
317 gl_tex->states[WINED3DTEXSTA_ELEMENTINDEX] = 0;
318 gl_tex->states[WINED3DTEXSTA_DMAPOFFSET] = 0;
319 gl_tex->states[WINED3DTEXSTA_TSSADDRESSW] = WINED3DTADDRESS_WRAP;
320 IWineD3DBaseTexture_SetDirty(iface, TRUE);
321 isNewTexture = TRUE;
322
323 if(This->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP) {
324 /* This means double binding the texture at creation, but keeps the code simpler all
325 * in all, and the run-time path free from additional checks
326 */
327 glBindTexture(textureDimensions, gl_tex->name);
328 checkGLcall("glBindTexture");
329 glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
330 checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_SGIS, GL_TRUE)");
331 }
332 } else {
333 *set_surface_desc = FALSE;
334 }
335
336 /* Bind the texture */
337 if (gl_tex->name != 0) {
338 glBindTexture(textureDimensions, gl_tex->name);
339 checkGLcall("glBindTexture");
340 if (isNewTexture) {
341 /* For a new texture we have to set the textures levels after binding the texture.
342 * In theory this is all we should ever have to do, but because ATI's drivers are broken, we
343 * also need to set the texture dimensions before the texture is set
344 * Beware that texture rectangles do not support mipmapping, but set the maxmiplevel if we're
345 * relying on the partial GL_ARB_texture_non_power_of_two emulation with texture rectangles
346 * (ie, do not care for cond_np2 here, just look for GL_TEXTURE_RECTANGLE_ARB)
347 */
348 if(textureDimensions != GL_TEXTURE_RECTANGLE_ARB) {
349 TRACE("Setting GL_TEXTURE_MAX_LEVEL to %d\n", This->baseTexture.levels - 1);
350 glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, This->baseTexture.levels - 1);
351 checkGLcall("glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, This->baseTexture.levels)");
352 }
353 if(textureDimensions==GL_TEXTURE_CUBE_MAP_ARB) {
354 /* Cubemaps are always set to clamp, regardless of the sampler state. */
355 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
356 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
357 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
358 }
359 }
360 } else { /* this only happened if we've run out of openGL textures */
361 WARN("This texture doesn't have an openGL texture assigned to it\n");
362 hr = WINED3DERR_INVALIDCALL;
363 }
364
365 LEAVE_GL();
366 return hr;
367}
368
369/* GL locking is done by the caller */
370static void apply_wrap(const struct wined3d_gl_info *gl_info, GLenum target,
371 WINED3DTEXTUREADDRESS d3d_wrap, GLenum param, BOOL cond_np2)
372{
373 GLint gl_wrap;
374
375 if (d3d_wrap < WINED3DTADDRESS_WRAP || d3d_wrap > WINED3DTADDRESS_MIRRORONCE)
376 {
377 FIXME("Unrecognized or unsupported WINED3DTEXTUREADDRESS %#x.\n", d3d_wrap);
378 return;
379 }
380
381 if (target == GL_TEXTURE_CUBE_MAP_ARB
382 || (cond_np2 && d3d_wrap == WINED3DTADDRESS_WRAP))
383 {
384 /* Cubemaps are always set to clamp, regardless of the sampler state. */
385 gl_wrap = GL_CLAMP_TO_EDGE;
386 }
387 else
388 {
389 gl_wrap = gl_info->wrap_lookup[d3d_wrap - WINED3DTADDRESS_WRAP];
390 }
391
392 TRACE("Setting param %#x to %#x for target %#x.\n", param, gl_wrap, target);
393 glTexParameteri(target, param, gl_wrap);
394 checkGLcall("glTexParameteri(target, param, gl_wrap)");
395}
396
397/* GL locking is done by the caller (state handler) */
398void basetexture_apply_state_changes(IWineD3DBaseTexture *iface,
399 const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1],
400 const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1],
401 const struct wined3d_gl_info *gl_info)
402{
403 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
404 DWORD state;
405 GLint textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
406 BOOL cond_np2 = IWineD3DBaseTexture_IsCondNP2(iface);
407 DWORD aniso;
408 struct gl_texture *gl_tex;
409
410 TRACE("iface %p, textureStates %p, samplerStates %p\n", iface, textureStates, samplerStates);
411
412 if(This->baseTexture.is_srgb) {
413 gl_tex = &This->baseTexture.texture_srgb;
414 } else {
415 gl_tex = &This->baseTexture.texture_rgb;
416 }
417
418 /* This function relies on the correct texture being bound and loaded. */
419
420 if(samplerStates[WINED3DSAMP_ADDRESSU] != gl_tex->states[WINED3DTEXSTA_ADDRESSU]) {
421 state = samplerStates[WINED3DSAMP_ADDRESSU];
422 apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_S, cond_np2);
423 gl_tex->states[WINED3DTEXSTA_ADDRESSU] = state;
424 }
425
426 if(samplerStates[WINED3DSAMP_ADDRESSV] != gl_tex->states[WINED3DTEXSTA_ADDRESSV]) {
427 state = samplerStates[WINED3DSAMP_ADDRESSV];
428 apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_T, cond_np2);
429 gl_tex->states[WINED3DTEXSTA_ADDRESSV] = state;
430 }
431
432 if(samplerStates[WINED3DSAMP_ADDRESSW] != gl_tex->states[WINED3DTEXSTA_ADDRESSW]) {
433 state = samplerStates[WINED3DSAMP_ADDRESSW];
434 apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_R, cond_np2);
435 gl_tex->states[WINED3DTEXSTA_ADDRESSW] = state;
436 }
437
438 if(samplerStates[WINED3DSAMP_BORDERCOLOR] != gl_tex->states[WINED3DTEXSTA_BORDERCOLOR]) {
439 float col[4];
440
441 state = samplerStates[WINED3DSAMP_BORDERCOLOR];
442 D3DCOLORTOGLFLOAT4(state, col);
443 TRACE("Setting border color for %u to %x\n", textureDimensions, state);
444 glTexParameterfv(textureDimensions, GL_TEXTURE_BORDER_COLOR, &col[0]);
445 checkGLcall("glTexParameteri(..., GL_TEXTURE_BORDER_COLOR, ...)");
446 gl_tex->states[WINED3DTEXSTA_BORDERCOLOR] = state;
447 }
448
449 if(samplerStates[WINED3DSAMP_MAGFILTER] != gl_tex->states[WINED3DTEXSTA_MAGFILTER]) {
450 GLint glValue;
451 state = samplerStates[WINED3DSAMP_MAGFILTER];
452 if (state > WINED3DTEXF_ANISOTROPIC) {
453 FIXME("Unrecognized or unsupported MAGFILTER* value %d\n", state);
454 }
455
456 glValue = wined3d_gl_mag_filter(This->baseTexture.magLookup,
457 min(max(state, WINED3DTEXF_POINT), WINED3DTEXF_LINEAR));
458 TRACE("ValueMAG=%d setting MAGFILTER to %x\n", state, glValue);
459 glTexParameteri(textureDimensions, GL_TEXTURE_MAG_FILTER, glValue);
460
461 gl_tex->states[WINED3DTEXSTA_MAGFILTER] = state;
462 }
463
464 if((samplerStates[WINED3DSAMP_MINFILTER] != gl_tex->states[WINED3DTEXSTA_MINFILTER] ||
465 samplerStates[WINED3DSAMP_MIPFILTER] != gl_tex->states[WINED3DTEXSTA_MIPFILTER] ||
466 samplerStates[WINED3DSAMP_MAXMIPLEVEL] != gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL])) {
467 GLint glValue;
468
469 gl_tex->states[WINED3DTEXSTA_MIPFILTER] = samplerStates[WINED3DSAMP_MIPFILTER];
470 gl_tex->states[WINED3DTEXSTA_MINFILTER] = samplerStates[WINED3DSAMP_MINFILTER];
471 gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] = samplerStates[WINED3DSAMP_MAXMIPLEVEL];
472
473 if (gl_tex->states[WINED3DTEXSTA_MINFILTER] > WINED3DTEXF_ANISOTROPIC
474 || gl_tex->states[WINED3DTEXSTA_MIPFILTER] > WINED3DTEXF_ANISOTROPIC)
475 {
476
477 FIXME("Unrecognized or unsupported D3DSAMP_MINFILTER value %d D3DSAMP_MIPFILTER value %d\n",
478 gl_tex->states[WINED3DTEXSTA_MINFILTER],
479 gl_tex->states[WINED3DTEXSTA_MIPFILTER]);
480 }
481 glValue = wined3d_gl_min_mip_filter(This->baseTexture.minMipLookup,
482 min(max(samplerStates[WINED3DSAMP_MINFILTER], WINED3DTEXF_POINT), WINED3DTEXF_LINEAR),
483 min(max(samplerStates[WINED3DSAMP_MIPFILTER], WINED3DTEXF_NONE), WINED3DTEXF_LINEAR));
484
485 TRACE("ValueMIN=%d, ValueMIP=%d, setting MINFILTER to %x\n",
486 samplerStates[WINED3DSAMP_MINFILTER],
487 samplerStates[WINED3DSAMP_MIPFILTER], glValue);
488 glTexParameteri(textureDimensions, GL_TEXTURE_MIN_FILTER, glValue);
489 checkGLcall("glTexParameter GL_TEXTURE_MIN_FILTER, ...");
490
491 if(!cond_np2) {
492 if(gl_tex->states[WINED3DTEXSTA_MIPFILTER] == WINED3DTEXF_NONE) {
493 glValue = This->baseTexture.LOD;
494 } else if(gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] >= This->baseTexture.levels) {
495 glValue = This->baseTexture.levels - 1;
496 } else if(gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] < This->baseTexture.LOD) {
497 /* baseTexture.LOD is already clamped in the setter */
498 glValue = This->baseTexture.LOD;
499 } else {
500 glValue = gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL];
501 }
502 /* Note that D3DSAMP_MAXMIPLEVEL specifies the biggest mipmap(default 0), while
503 * GL_TEXTURE_MAX_LEVEL specifies the smallest mimap used(default 1000).
504 * So D3DSAMP_MAXMIPLEVEL is the same as GL_TEXTURE_BASE_LEVEL.
505 */
506 glTexParameteri(textureDimensions, GL_TEXTURE_BASE_LEVEL, glValue);
507 }
508 }
509
510 if ((gl_tex->states[WINED3DTEXSTA_MAGFILTER] != WINED3DTEXF_ANISOTROPIC
511 && gl_tex->states[WINED3DTEXSTA_MINFILTER] != WINED3DTEXF_ANISOTROPIC
512 && gl_tex->states[WINED3DTEXSTA_MIPFILTER] != WINED3DTEXF_ANISOTROPIC)
513 || cond_np2)
514 {
515 aniso = 1;
516 }
517 else
518 {
519 aniso = samplerStates[WINED3DSAMP_MAXANISOTROPY];
520 }
521
522 if (gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] != aniso)
523 {
524 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
525 {
526 glTexParameteri(textureDimensions, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso);
527 checkGLcall("glTexParameteri(GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso)");
528 }
529 else
530 {
531 WARN("Anisotropic filtering not supported.\n");
532 }
533 gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] = aniso;
534 }
535}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette