VirtualBox

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

Last change on this file since 39899 was 39899, checked in by vboxsync, 13 years ago

wine/wddm: shared resource handling fixes, state fixes - working powershell_ise

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

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