VirtualBox

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

最後變更 在這個檔案從39150是 38982,由 vboxsync 提交於 13 年 前

wddm: proper ie rendering under win8 (shared resource open & destroy fixes, zero-init resources on creaate, etc.)

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

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