VirtualBox

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

Last change on this file since 33085 was 33046, checked in by vboxsync, 14 years ago

crOpenGL/wddm: some texture mirroring code

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