VirtualBox

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

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

wddm/3d: shared resource destroy handling fixes

  • Property svn:eol-style set to native
File size: 21.9 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#ifdef VBOX_WITH_WDDM
299 Assert(!VBOXSHRC_IS_DISABLED(This));
300#endif
301
302 This->baseTexture.is_srgb = srgb; /* SRGB mode cache for PreLoad calls outside drawprim */
303 if(srgb) {
304 gl_tex = &This->baseTexture.texture_srgb;
305 } else {
306 gl_tex = &This->baseTexture.texture_rgb;
307 }
308
309 textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
310 ENTER_GL();
311 /* Generate a texture name if we don't already have one */
312 if (gl_tex->name == 0) {
313 *set_surface_desc = TRUE;
314#ifdef VBOX_WITH_WDDM
315 if (VBOXSHRC_IS_SHARED_OPENED(This))
316 {
317 ERR("should not be here!");
318 gl_tex->name = (GLuint)VBOXSHRC_GET_SHAREHANDLE(This);
319 TRACE("Assigned shared texture %d\n", gl_tex->name);
320 }
321 else
322#endif
323 {
324 isNewTexture = TRUE;
325 glGenTextures(1, &gl_tex->name);
326 checkGLcall("glGenTextures");
327 TRACE("Generated texture %d\n", gl_tex->name);
328#ifdef VBOX_WITH_WDDM
329 if (VBOXSHRC_IS_SHARED(This))
330 {
331 VBOXSHRC_SET_SHAREHANDLE(This, gl_tex->name);
332 }
333#endif
334 }
335#ifndef VBOX_WITH_WDDM
336 if (This->resource.pool == WINED3DPOOL_DEFAULT) {
337 /* Tell opengl to try and keep this texture in video ram (well mostly) */
338 GLclampf tmp;
339 tmp = 0.9f;
340 glPrioritizeTextures(1, &gl_tex->name, &tmp);
341
342 }
343#else
344 /* chromium code on host fails to resolve texture name to texture obj for some reason
345 * @todo: investigate */
346#endif
347 /* Initialise the state of the texture object
348 to the openGL defaults, not the directx defaults */
349 basetexture_state_init(iface, gl_tex);
350
351 if(isNewTexture
352 && This->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP) {
353 /* This means double binding the texture at creation, but keeps the code simpler all
354 * in all, and the run-time path free from additional checks
355 */
356 glBindTexture(textureDimensions, gl_tex->name);
357 checkGLcall("glBindTexture");
358 glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
359 checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_SGIS, GL_TRUE)");
360 }
361 } else {
362 *set_surface_desc = FALSE;
363 }
364
365 /* Bind the texture */
366 if (gl_tex->name != 0) {
367 glBindTexture(textureDimensions, gl_tex->name);
368 checkGLcall("glBindTexture");
369 if (isNewTexture) {
370 /* For a new texture we have to set the textures levels after binding the texture.
371 * In theory this is all we should ever have to do, but because ATI's drivers are broken, we
372 * also need to set the texture dimensions before the texture is set
373 * Beware that texture rectangles do not support mipmapping, but set the maxmiplevel if we're
374 * relying on the partial GL_ARB_texture_non_power_of_two emulation with texture rectangles
375 * (ie, do not care for cond_np2 here, just look for GL_TEXTURE_RECTANGLE_ARB)
376 */
377 if(textureDimensions != GL_TEXTURE_RECTANGLE_ARB) {
378 TRACE("Setting GL_TEXTURE_MAX_LEVEL to %d\n", This->baseTexture.levels - 1);
379 glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, This->baseTexture.levels - 1);
380 checkGLcall("glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, This->baseTexture.levels)");
381 }
382 if(textureDimensions==GL_TEXTURE_CUBE_MAP_ARB) {
383 /* Cubemaps are always set to clamp, regardless of the sampler state. */
384 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
385 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
386 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
387 }
388 }
389 } else { /* this only happened if we've run out of openGL textures */
390 WARN("This texture doesn't have an openGL texture assigned to it\n");
391 hr = WINED3DERR_INVALIDCALL;
392 }
393
394 LEAVE_GL();
395 return hr;
396}
397
398/* GL locking is done by the caller */
399static void apply_wrap(const struct wined3d_gl_info *gl_info, GLenum target,
400 WINED3DTEXTUREADDRESS d3d_wrap, GLenum param, BOOL cond_np2)
401{
402 GLint gl_wrap;
403
404 if (d3d_wrap < WINED3DTADDRESS_WRAP || d3d_wrap > WINED3DTADDRESS_MIRRORONCE)
405 {
406 FIXME("Unrecognized or unsupported WINED3DTEXTUREADDRESS %#x.\n", d3d_wrap);
407 return;
408 }
409
410 if (target == GL_TEXTURE_CUBE_MAP_ARB
411 || (cond_np2 && d3d_wrap == WINED3DTADDRESS_WRAP))
412 {
413 /* Cubemaps are always set to clamp, regardless of the sampler state. */
414 gl_wrap = GL_CLAMP_TO_EDGE;
415 }
416 else
417 {
418 gl_wrap = gl_info->wrap_lookup[d3d_wrap - WINED3DTADDRESS_WRAP];
419 }
420
421 TRACE("Setting param %#x to %#x for target %#x.\n", param, gl_wrap, target);
422 glTexParameteri(target, param, gl_wrap);
423 checkGLcall("glTexParameteri(target, param, gl_wrap)");
424}
425
426/* GL locking is done by the caller (state handler) */
427void basetexture_apply_state_changes(IWineD3DBaseTexture *iface,
428 const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1],
429 const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1],
430 const struct wined3d_gl_info *gl_info)
431{
432 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
433 DWORD state;
434 GLint textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
435 BOOL cond_np2 = IWineD3DBaseTexture_IsCondNP2(iface);
436 DWORD aniso;
437 struct gl_texture *gl_tex;
438
439 TRACE("iface %p, textureStates %p, samplerStates %p\n", iface, textureStates, samplerStates);
440
441 if(This->baseTexture.is_srgb) {
442 gl_tex = &This->baseTexture.texture_srgb;
443 } else {
444 gl_tex = &This->baseTexture.texture_rgb;
445 }
446
447 /* This function relies on the correct texture being bound and loaded. */
448
449 if(samplerStates[WINED3DSAMP_ADDRESSU] != gl_tex->states[WINED3DTEXSTA_ADDRESSU]) {
450 state = samplerStates[WINED3DSAMP_ADDRESSU];
451 apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_S, cond_np2);
452 gl_tex->states[WINED3DTEXSTA_ADDRESSU] = state;
453 }
454
455 if(samplerStates[WINED3DSAMP_ADDRESSV] != gl_tex->states[WINED3DTEXSTA_ADDRESSV]) {
456 state = samplerStates[WINED3DSAMP_ADDRESSV];
457 apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_T, cond_np2);
458 gl_tex->states[WINED3DTEXSTA_ADDRESSV] = state;
459 }
460
461 if(samplerStates[WINED3DSAMP_ADDRESSW] != gl_tex->states[WINED3DTEXSTA_ADDRESSW]) {
462 state = samplerStates[WINED3DSAMP_ADDRESSW];
463 apply_wrap(gl_info, textureDimensions, state, GL_TEXTURE_WRAP_R, cond_np2);
464 gl_tex->states[WINED3DTEXSTA_ADDRESSW] = state;
465 }
466
467 if(samplerStates[WINED3DSAMP_BORDERCOLOR] != gl_tex->states[WINED3DTEXSTA_BORDERCOLOR]) {
468 float col[4];
469
470 state = samplerStates[WINED3DSAMP_BORDERCOLOR];
471 D3DCOLORTOGLFLOAT4(state, col);
472 TRACE("Setting border color for %u to %x\n", textureDimensions, state);
473 glTexParameterfv(textureDimensions, GL_TEXTURE_BORDER_COLOR, &col[0]);
474 checkGLcall("glTexParameteri(..., GL_TEXTURE_BORDER_COLOR, ...)");
475 gl_tex->states[WINED3DTEXSTA_BORDERCOLOR] = state;
476 }
477
478 if(samplerStates[WINED3DSAMP_MAGFILTER] != gl_tex->states[WINED3DTEXSTA_MAGFILTER]) {
479 GLint glValue;
480 state = samplerStates[WINED3DSAMP_MAGFILTER];
481 if (state > WINED3DTEXF_ANISOTROPIC) {
482 FIXME("Unrecognized or unsupported MAGFILTER* value %d\n", state);
483 }
484
485 glValue = wined3d_gl_mag_filter(This->baseTexture.magLookup,
486 min(max(state, WINED3DTEXF_POINT), WINED3DTEXF_LINEAR));
487 TRACE("ValueMAG=%d setting MAGFILTER to %x\n", state, glValue);
488 glTexParameteri(textureDimensions, GL_TEXTURE_MAG_FILTER, glValue);
489
490 gl_tex->states[WINED3DTEXSTA_MAGFILTER] = state;
491 }
492
493 if((samplerStates[WINED3DSAMP_MINFILTER] != gl_tex->states[WINED3DTEXSTA_MINFILTER] ||
494 samplerStates[WINED3DSAMP_MIPFILTER] != gl_tex->states[WINED3DTEXSTA_MIPFILTER] ||
495 samplerStates[WINED3DSAMP_MAXMIPLEVEL] != gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL])) {
496 GLint glValue;
497
498 gl_tex->states[WINED3DTEXSTA_MIPFILTER] = samplerStates[WINED3DSAMP_MIPFILTER];
499 gl_tex->states[WINED3DTEXSTA_MINFILTER] = samplerStates[WINED3DSAMP_MINFILTER];
500 gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] = samplerStates[WINED3DSAMP_MAXMIPLEVEL];
501
502 if (gl_tex->states[WINED3DTEXSTA_MINFILTER] > WINED3DTEXF_ANISOTROPIC
503 || gl_tex->states[WINED3DTEXSTA_MIPFILTER] > WINED3DTEXF_ANISOTROPIC)
504 {
505
506 FIXME("Unrecognized or unsupported D3DSAMP_MINFILTER value %d D3DSAMP_MIPFILTER value %d\n",
507 gl_tex->states[WINED3DTEXSTA_MINFILTER],
508 gl_tex->states[WINED3DTEXSTA_MIPFILTER]);
509 }
510 glValue = wined3d_gl_min_mip_filter(This->baseTexture.minMipLookup,
511 min(max(samplerStates[WINED3DSAMP_MINFILTER], WINED3DTEXF_POINT), WINED3DTEXF_LINEAR),
512 min(max(samplerStates[WINED3DSAMP_MIPFILTER], WINED3DTEXF_NONE), WINED3DTEXF_LINEAR));
513
514 TRACE("ValueMIN=%d, ValueMIP=%d, setting MINFILTER to %x\n",
515 samplerStates[WINED3DSAMP_MINFILTER],
516 samplerStates[WINED3DSAMP_MIPFILTER], glValue);
517 glTexParameteri(textureDimensions, GL_TEXTURE_MIN_FILTER, glValue);
518 checkGLcall("glTexParameter GL_TEXTURE_MIN_FILTER, ...");
519
520 if(!cond_np2) {
521 if(gl_tex->states[WINED3DTEXSTA_MIPFILTER] == WINED3DTEXF_NONE) {
522 glValue = This->baseTexture.LOD;
523 } else if(gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] >= This->baseTexture.levels) {
524 glValue = This->baseTexture.levels - 1;
525 } else if(gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] < This->baseTexture.LOD) {
526 /* baseTexture.LOD is already clamped in the setter */
527 glValue = This->baseTexture.LOD;
528 } else {
529 glValue = gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL];
530 }
531 /* Note that D3DSAMP_MAXMIPLEVEL specifies the biggest mipmap(default 0), while
532 * GL_TEXTURE_MAX_LEVEL specifies the smallest mimap used(default 1000).
533 * So D3DSAMP_MAXMIPLEVEL is the same as GL_TEXTURE_BASE_LEVEL.
534 */
535 glTexParameteri(textureDimensions, GL_TEXTURE_BASE_LEVEL, glValue);
536 }
537 }
538
539 if ((gl_tex->states[WINED3DTEXSTA_MAGFILTER] != WINED3DTEXF_ANISOTROPIC
540 && gl_tex->states[WINED3DTEXSTA_MINFILTER] != WINED3DTEXF_ANISOTROPIC
541 && gl_tex->states[WINED3DTEXSTA_MIPFILTER] != WINED3DTEXF_ANISOTROPIC)
542 || cond_np2)
543 {
544 aniso = 1;
545 }
546 else
547 {
548 aniso = samplerStates[WINED3DSAMP_MAXANISOTROPY];
549 }
550
551 if (gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] != aniso)
552 {
553 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
554 {
555 glTexParameteri(textureDimensions, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso);
556 checkGLcall("glTexParameteri(GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso)");
557 }
558 else
559 {
560 WARN("Anisotropic filtering not supported.\n");
561 }
562 gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] = aniso;
563 }
564}
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