VirtualBox

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

Last change on this file since 32891 was 32622, checked in by vboxsync, 14 years ago

wddm: VBOXWDDM->VBOX_WITH_WDDM

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