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 | *
|
---|
9 | * This library is free software; you can redistribute it and/or
|
---|
10 | * modify it under the terms of the GNU Lesser General Public
|
---|
11 | * License as published by the Free Software Foundation; either
|
---|
12 | * version 2.1 of the License, or (at your option) any later version.
|
---|
13 | *
|
---|
14 | * This library is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
17 | * Lesser General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU Lesser General Public
|
---|
20 | * License along with this library; if not, write to the Free Software
|
---|
21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
22 | */
|
---|
23 |
|
---|
24 | /*
|
---|
25 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
26 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
27 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
28 | * a choice of LGPL license versions is made available with the language indicating
|
---|
29 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
30 | * of the LGPL is applied is otherwise unspecified.
|
---|
31 | */
|
---|
32 |
|
---|
33 | #include "config.h"
|
---|
34 | #include "wined3d_private.h"
|
---|
35 |
|
---|
36 | WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
|
---|
37 | #define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
|
---|
38 |
|
---|
39 | HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT levels, WINED3DRESOURCETYPE resource_type,
|
---|
40 | IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct GlPixelFormatDesc *format_desc,
|
---|
41 | WINED3DPOOL pool, IUnknown *parent)
|
---|
42 | {
|
---|
43 | HRESULT hr;
|
---|
44 |
|
---|
45 | hr = resource_init((IWineD3DResource *)texture, resource_type, device, size, usage, format_desc, pool, parent);
|
---|
46 | if (FAILED(hr))
|
---|
47 | {
|
---|
48 | WARN("Failed to initialize resource, returning %#x\n", hr);
|
---|
49 | return hr;
|
---|
50 | }
|
---|
51 |
|
---|
52 | texture->baseTexture.levels = levels;
|
---|
53 | texture->baseTexture.filterType = (usage & WINED3DUSAGE_AUTOGENMIPMAP) ? WINED3DTEXF_LINEAR : WINED3DTEXF_NONE;
|
---|
54 | texture->baseTexture.LOD = 0;
|
---|
55 | texture->baseTexture.dirty = TRUE;
|
---|
56 | texture->baseTexture.srgbDirty = TRUE;
|
---|
57 | texture->baseTexture.is_srgb = FALSE;
|
---|
58 | texture->baseTexture.pow2Matrix_identity = TRUE;
|
---|
59 |
|
---|
60 | if (texture->resource.format_desc->Flags & WINED3DFMT_FLAG_FILTERING)
|
---|
61 | {
|
---|
62 | texture->baseTexture.minMipLookup = minMipLookup;
|
---|
63 | texture->baseTexture.magLookup = magLookup;
|
---|
64 | }
|
---|
65 | else
|
---|
66 | {
|
---|
67 | texture->baseTexture.minMipLookup = minMipLookup_noFilter;
|
---|
68 | texture->baseTexture.magLookup = magLookup_noFilter;
|
---|
69 | }
|
---|
70 |
|
---|
71 | return WINED3D_OK;
|
---|
72 | }
|
---|
73 |
|
---|
74 | void basetexture_cleanup(IWineD3DBaseTexture *iface)
|
---|
75 | {
|
---|
76 | basetexture_unload(iface);
|
---|
77 | resource_cleanup((IWineD3DResource *)iface);
|
---|
78 | }
|
---|
79 |
|
---|
80 | void basetexture_unload(IWineD3DBaseTexture *iface)
|
---|
81 | {
|
---|
82 | IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
|
---|
83 | IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
---|
84 |
|
---|
85 | if(This->baseTexture.textureName) {
|
---|
86 | ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
|
---|
87 | ENTER_GL();
|
---|
88 | glDeleteTextures(1, &This->baseTexture.textureName);
|
---|
89 | This->baseTexture.textureName = 0;
|
---|
90 | LEAVE_GL();
|
---|
91 | }
|
---|
92 |
|
---|
93 | if(This->baseTexture.srgbTextureName) {
|
---|
94 | ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
|
---|
95 | ENTER_GL();
|
---|
96 | glDeleteTextures(1, &This->baseTexture.srgbTextureName);
|
---|
97 | This->baseTexture.srgbTextureName = 0;
|
---|
98 | LEAVE_GL();
|
---|
99 | }
|
---|
100 | This->baseTexture.dirty = TRUE;
|
---|
101 | This->baseTexture.srgbDirty = TRUE;
|
---|
102 | }
|
---|
103 |
|
---|
104 | /* There is no OpenGL equivalent of setLOD, getLOD. All they do anyway is prioritize texture loading
|
---|
105 | * so just pretend that they work unless something really needs a failure. */
|
---|
106 | DWORD basetexture_set_lod(IWineD3DBaseTexture *iface, DWORD LODNew)
|
---|
107 | {
|
---|
108 | IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
|
---|
109 |
|
---|
110 | if (This->resource.pool != WINED3DPOOL_MANAGED) {
|
---|
111 | return WINED3DERR_INVALIDCALL;
|
---|
112 | }
|
---|
113 |
|
---|
114 | if(LODNew >= This->baseTexture.levels)
|
---|
115 | LODNew = This->baseTexture.levels - 1;
|
---|
116 | This->baseTexture.LOD = LODNew;
|
---|
117 |
|
---|
118 | TRACE("(%p) : set bogus LOD to %d\n", This, This->baseTexture.LOD);
|
---|
119 |
|
---|
120 | return This->baseTexture.LOD;
|
---|
121 | }
|
---|
122 |
|
---|
123 | DWORD basetexture_get_lod(IWineD3DBaseTexture *iface)
|
---|
124 | {
|
---|
125 | IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
|
---|
126 |
|
---|
127 | if (This->resource.pool != WINED3DPOOL_MANAGED) {
|
---|
128 | return WINED3DERR_INVALIDCALL;
|
---|
129 | }
|
---|
130 |
|
---|
131 | TRACE("(%p) : returning %d\n", This, This->baseTexture.LOD);
|
---|
132 |
|
---|
133 | return This->baseTexture.LOD;
|
---|
134 | }
|
---|
135 |
|
---|
136 | DWORD basetexture_get_level_count(IWineD3DBaseTexture *iface)
|
---|
137 | {
|
---|
138 | IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
|
---|
139 | TRACE("(%p) : returning %d\n", This, This->baseTexture.levels);
|
---|
140 | return This->baseTexture.levels;
|
---|
141 | }
|
---|
142 |
|
---|
143 | HRESULT basetexture_set_autogen_filter_type(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType)
|
---|
144 | {
|
---|
145 | IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
|
---|
146 | IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
|
---|
147 | UINT textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
|
---|
148 |
|
---|
149 | if (!(This->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP)) {
|
---|
150 | TRACE("(%p) : returning invalid call\n", This);
|
---|
151 | return WINED3DERR_INVALIDCALL;
|
---|
152 | }
|
---|
153 | if(This->baseTexture.filterType != FilterType) {
|
---|
154 | /* What about multithreading? Do we want all the context overhead just to set this value?
|
---|
155 | * Or should we delay the applying until the texture is used for drawing? For now, apply
|
---|
156 | * immediately.
|
---|
157 | */
|
---|
158 | ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
|
---|
159 | ENTER_GL();
|
---|
160 | glBindTexture(textureDimensions, This->baseTexture.textureName);
|
---|
161 | checkGLcall("glBindTexture");
|
---|
162 | switch(FilterType) {
|
---|
163 | case WINED3DTEXF_NONE:
|
---|
164 | case WINED3DTEXF_POINT:
|
---|
165 | glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_FASTEST);
|
---|
166 | checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_FASTEST)");
|
---|
167 |
|
---|
168 | break;
|
---|
169 | case WINED3DTEXF_LINEAR:
|
---|
170 | glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST);
|
---|
171 | checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST)");
|
---|
172 |
|
---|
173 | break;
|
---|
174 | default:
|
---|
175 | WARN("Unexpected filter type %d, setting to GL_NICEST\n", FilterType);
|
---|
176 | glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST);
|
---|
177 | checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST)");
|
---|
178 | }
|
---|
179 | LEAVE_GL();
|
---|
180 | }
|
---|
181 | This->baseTexture.filterType = FilterType;
|
---|
182 | TRACE("(%p) :\n", This);
|
---|
183 | return WINED3D_OK;
|
---|
184 | }
|
---|
185 |
|
---|
186 | WINED3DTEXTUREFILTERTYPE basetexture_get_autogen_filter_type(IWineD3DBaseTexture *iface)
|
---|
187 | {
|
---|
188 | IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
|
---|
189 |
|
---|
190 | FIXME("(%p) : stub\n", This);
|
---|
191 |
|
---|
192 | return This->baseTexture.filterType;
|
---|
193 | }
|
---|
194 |
|
---|
195 | void basetexture_generate_mipmaps(IWineD3DBaseTexture *iface)
|
---|
196 | {
|
---|
197 | IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
|
---|
198 | /* TODO: implement filters using GL_SGI_generate_mipmaps http://oss.sgi.com/projects/ogl-sample/registry/SGIS/generate_mipmap.txt */
|
---|
199 | FIXME("(%p) : stub\n", This);
|
---|
200 | return ;
|
---|
201 | }
|
---|
202 |
|
---|
203 | BOOL basetexture_set_dirty(IWineD3DBaseTexture *iface, BOOL dirty)
|
---|
204 | {
|
---|
205 | BOOL old;
|
---|
206 | IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
|
---|
207 | old = This->baseTexture.dirty || This->baseTexture.srgbDirty;
|
---|
208 | This->baseTexture.dirty = dirty;
|
---|
209 | This->baseTexture.srgbDirty = dirty;
|
---|
210 | return old;
|
---|
211 | }
|
---|
212 |
|
---|
213 | BOOL basetexture_get_dirty(IWineD3DBaseTexture *iface)
|
---|
214 | {
|
---|
215 | IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
|
---|
216 | return This->baseTexture.dirty || This->baseTexture.srgbDirty;
|
---|
217 | }
|
---|
218 |
|
---|
219 | /* Context activation is done by the caller. */
|
---|
220 | HRESULT basetexture_bind(IWineD3DBaseTexture *iface, BOOL srgb, BOOL *set_surface_desc)
|
---|
221 | {
|
---|
222 | IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
|
---|
223 | HRESULT hr = WINED3D_OK;
|
---|
224 | UINT textureDimensions;
|
---|
225 | BOOL isNewTexture = FALSE;
|
---|
226 | GLuint *texture;
|
---|
227 | DWORD *states;
|
---|
228 | TRACE("(%p) : About to bind texture\n", This);
|
---|
229 |
|
---|
230 | This->baseTexture.is_srgb = srgb; /* SRGB mode cache for PreLoad calls outside drawprim */
|
---|
231 | if(srgb) {
|
---|
232 | texture = &This->baseTexture.srgbTextureName;
|
---|
233 | states = This->baseTexture.srgbstates;
|
---|
234 | } else {
|
---|
235 | texture = &This->baseTexture.textureName;
|
---|
236 | states = This->baseTexture.states;
|
---|
237 | }
|
---|
238 |
|
---|
239 | textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
|
---|
240 | ENTER_GL();
|
---|
241 | /* Generate a texture name if we don't already have one */
|
---|
242 | if (*texture == 0) {
|
---|
243 | *set_surface_desc = TRUE;
|
---|
244 | glGenTextures(1, texture);
|
---|
245 | checkGLcall("glGenTextures");
|
---|
246 | TRACE("Generated texture %d\n", *texture);
|
---|
247 | if (This->resource.pool == WINED3DPOOL_DEFAULT) {
|
---|
248 | /* Tell opengl to try and keep this texture in video ram (well mostly) */
|
---|
249 | GLclampf tmp;
|
---|
250 | tmp = 0.9f;
|
---|
251 | glPrioritizeTextures(1, texture, &tmp);
|
---|
252 |
|
---|
253 | }
|
---|
254 | /* Initialise the state of the texture object
|
---|
255 | to the openGL defaults, not the directx defaults */
|
---|
256 | states[WINED3DTEXSTA_ADDRESSU] = WINED3DTADDRESS_WRAP;
|
---|
257 | states[WINED3DTEXSTA_ADDRESSV] = WINED3DTADDRESS_WRAP;
|
---|
258 | states[WINED3DTEXSTA_ADDRESSW] = WINED3DTADDRESS_WRAP;
|
---|
259 | states[WINED3DTEXSTA_BORDERCOLOR] = 0;
|
---|
260 | states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_LINEAR;
|
---|
261 | states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT; /* GL_NEAREST_MIPMAP_LINEAR */
|
---|
262 | states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_LINEAR; /* GL_NEAREST_MIPMAP_LINEAR */
|
---|
263 | states[WINED3DTEXSTA_MAXMIPLEVEL] = 0;
|
---|
264 | states[WINED3DTEXSTA_MAXANISOTROPY] = 1;
|
---|
265 | states[WINED3DTEXSTA_SRGBTEXTURE] = 0;
|
---|
266 | states[WINED3DTEXSTA_ELEMENTINDEX] = 0;
|
---|
267 | states[WINED3DTEXSTA_DMAPOFFSET] = 0;
|
---|
268 | states[WINED3DTEXSTA_TSSADDRESSW] = WINED3DTADDRESS_WRAP;
|
---|
269 | IWineD3DBaseTexture_SetDirty(iface, TRUE);
|
---|
270 | isNewTexture = TRUE;
|
---|
271 |
|
---|
272 | if(This->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP) {
|
---|
273 | /* This means double binding the texture at creation, but keeps the code simpler all
|
---|
274 | * in all, and the run-time path free from additional checks
|
---|
275 | */
|
---|
276 | glBindTexture(textureDimensions, *texture);
|
---|
277 | checkGLcall("glBindTexture");
|
---|
278 | glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
|
---|
279 | checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_SGIS, GL_TRUE)");
|
---|
280 | }
|
---|
281 | } else {
|
---|
282 | *set_surface_desc = FALSE;
|
---|
283 | }
|
---|
284 |
|
---|
285 | /* Bind the texture */
|
---|
286 | if (*texture != 0) {
|
---|
287 | glBindTexture(textureDimensions, *texture);
|
---|
288 | checkGLcall("glBindTexture");
|
---|
289 | if (isNewTexture) {
|
---|
290 | /* For a new texture we have to set the textures levels after binding the texture.
|
---|
291 | * In theory this is all we should ever have to do, but because ATI's drivers are broken, we
|
---|
292 | * also need to set the texture dimensions before the texture is set
|
---|
293 | * Beware that texture rectangles do not support mipmapping, but set the maxmiplevel if we're
|
---|
294 | * relying on the partial GL_ARB_texture_non_power_of_two emulation with texture rectangles
|
---|
295 | * (ie, do not care for cond_np2 here, just look for GL_TEXTURE_RECTANGLE_ARB)
|
---|
296 | */
|
---|
297 | if(textureDimensions != GL_TEXTURE_RECTANGLE_ARB) {
|
---|
298 | TRACE("Setting GL_TEXTURE_MAX_LEVEL to %d\n", This->baseTexture.levels - 1);
|
---|
299 | glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, This->baseTexture.levels - 1);
|
---|
300 | checkGLcall("glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, This->baseTexture.levels)");
|
---|
301 | }
|
---|
302 | if(textureDimensions==GL_TEXTURE_CUBE_MAP_ARB) {
|
---|
303 | /* Cubemaps are always set to clamp, regardless of the sampler state. */
|
---|
304 | glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
---|
305 | glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
---|
306 | glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
---|
307 | }
|
---|
308 | }
|
---|
309 | } else { /* this only happened if we've run out of openGL textures */
|
---|
310 | WARN("This texture doesn't have an openGL texture assigned to it\n");
|
---|
311 | hr = WINED3DERR_INVALIDCALL;
|
---|
312 | }
|
---|
313 |
|
---|
314 | LEAVE_GL();
|
---|
315 | return hr;
|
---|
316 | }
|
---|
317 |
|
---|
318 | /* GL locking is done by the caller */
|
---|
319 | static inline void apply_wrap(const GLint textureDimensions, const DWORD state, const GLint type,
|
---|
320 | BOOL cond_np2) {
|
---|
321 | GLint wrapParm;
|
---|
322 |
|
---|
323 | if (state < minLookup[WINELOOKUP_WARPPARAM] || state > maxLookup[WINELOOKUP_WARPPARAM]) {
|
---|
324 | FIXME("Unrecognized or unsupported WINED3DTADDRESS_U value %d\n", state);
|
---|
325 | } else {
|
---|
326 | if(textureDimensions==GL_TEXTURE_CUBE_MAP_ARB) {
|
---|
327 | /* Cubemaps are always set to clamp, regardless of the sampler state. */
|
---|
328 | wrapParm = GL_CLAMP_TO_EDGE;
|
---|
329 | } else if(cond_np2) {
|
---|
330 | if(state == WINED3DTADDRESS_WRAP) {
|
---|
331 | wrapParm = GL_CLAMP_TO_EDGE;
|
---|
332 | } else {
|
---|
333 | wrapParm = stateLookup[WINELOOKUP_WARPPARAM][state - minLookup[WINELOOKUP_WARPPARAM]];
|
---|
334 | }
|
---|
335 | } else {
|
---|
336 | wrapParm = stateLookup[WINELOOKUP_WARPPARAM][state - minLookup[WINELOOKUP_WARPPARAM]];
|
---|
337 | }
|
---|
338 | TRACE("Setting WRAP_S to %d for %x\n", wrapParm, textureDimensions);
|
---|
339 | glTexParameteri(textureDimensions, type, wrapParm);
|
---|
340 | checkGLcall("glTexParameteri(..., type, wrapParm)");
|
---|
341 | }
|
---|
342 | }
|
---|
343 |
|
---|
344 | /* GL locking is done by the caller (state handler) */
|
---|
345 | void basetexture_apply_state_changes(IWineD3DBaseTexture *iface,
|
---|
346 | const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1],
|
---|
347 | const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1])
|
---|
348 | {
|
---|
349 | IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
|
---|
350 | DWORD state, *states;
|
---|
351 | GLint textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
|
---|
352 | BOOL cond_np2 = IWineD3DBaseTexture_IsCondNP2(iface);
|
---|
353 | DWORD aniso;
|
---|
354 |
|
---|
355 | TRACE("iface %p, textureStates %p, samplerStates %p\n", iface, textureStates, samplerStates);
|
---|
356 |
|
---|
357 | if(This->baseTexture.is_srgb) {
|
---|
358 | states = This->baseTexture.srgbstates;
|
---|
359 | } else {
|
---|
360 | states = This->baseTexture.states;
|
---|
361 | }
|
---|
362 |
|
---|
363 | /* This function relies on the correct texture being bound and loaded. */
|
---|
364 |
|
---|
365 | if(samplerStates[WINED3DSAMP_ADDRESSU] != states[WINED3DTEXSTA_ADDRESSU]) {
|
---|
366 | state = samplerStates[WINED3DSAMP_ADDRESSU];
|
---|
367 | apply_wrap(textureDimensions, state, GL_TEXTURE_WRAP_S, cond_np2);
|
---|
368 | states[WINED3DTEXSTA_ADDRESSU] = state;
|
---|
369 | }
|
---|
370 |
|
---|
371 | if(samplerStates[WINED3DSAMP_ADDRESSV] != states[WINED3DTEXSTA_ADDRESSV]) {
|
---|
372 | state = samplerStates[WINED3DSAMP_ADDRESSV];
|
---|
373 | apply_wrap(textureDimensions, state, GL_TEXTURE_WRAP_T, cond_np2);
|
---|
374 | states[WINED3DTEXSTA_ADDRESSV] = state;
|
---|
375 | }
|
---|
376 |
|
---|
377 | if(samplerStates[WINED3DSAMP_ADDRESSW] != states[WINED3DTEXSTA_ADDRESSW]) {
|
---|
378 | state = samplerStates[WINED3DSAMP_ADDRESSW];
|
---|
379 | apply_wrap(textureDimensions, state, GL_TEXTURE_WRAP_R, cond_np2);
|
---|
380 | states[WINED3DTEXSTA_ADDRESSW] = state;
|
---|
381 | }
|
---|
382 |
|
---|
383 | if(samplerStates[WINED3DSAMP_BORDERCOLOR] != states[WINED3DTEXSTA_BORDERCOLOR]) {
|
---|
384 | float col[4];
|
---|
385 |
|
---|
386 | state = samplerStates[WINED3DSAMP_BORDERCOLOR];
|
---|
387 | D3DCOLORTOGLFLOAT4(state, col);
|
---|
388 | TRACE("Setting border color for %u to %x\n", textureDimensions, state);
|
---|
389 | glTexParameterfv(textureDimensions, GL_TEXTURE_BORDER_COLOR, &col[0]);
|
---|
390 | checkGLcall("glTexParameteri(..., GL_TEXTURE_BORDER_COLOR, ...)");
|
---|
391 | states[WINED3DTEXSTA_BORDERCOLOR] = state;
|
---|
392 | }
|
---|
393 |
|
---|
394 | if(samplerStates[WINED3DSAMP_MAGFILTER] != states[WINED3DTEXSTA_MAGFILTER]) {
|
---|
395 | GLint glValue;
|
---|
396 | state = samplerStates[WINED3DSAMP_MAGFILTER];
|
---|
397 | if (state > WINED3DTEXF_ANISOTROPIC) {
|
---|
398 | FIXME("Unrecognized or unsupported MAGFILTER* value %d\n", state);
|
---|
399 | }
|
---|
400 |
|
---|
401 | glValue = wined3d_gl_mag_filter(This->baseTexture.magLookup,
|
---|
402 | min(max(state, WINED3DTEXF_POINT), WINED3DTEXF_LINEAR));
|
---|
403 | TRACE("ValueMAG=%d setting MAGFILTER to %x\n", state, glValue);
|
---|
404 | glTexParameteri(textureDimensions, GL_TEXTURE_MAG_FILTER, glValue);
|
---|
405 |
|
---|
406 | states[WINED3DTEXSTA_MAGFILTER] = state;
|
---|
407 | }
|
---|
408 |
|
---|
409 | if((samplerStates[WINED3DSAMP_MINFILTER] != states[WINED3DTEXSTA_MINFILTER] ||
|
---|
410 | samplerStates[WINED3DSAMP_MIPFILTER] != states[WINED3DTEXSTA_MIPFILTER] ||
|
---|
411 | samplerStates[WINED3DSAMP_MAXMIPLEVEL] != states[WINED3DTEXSTA_MAXMIPLEVEL])) {
|
---|
412 | GLint glValue;
|
---|
413 |
|
---|
414 | states[WINED3DTEXSTA_MIPFILTER] = samplerStates[WINED3DSAMP_MIPFILTER];
|
---|
415 | states[WINED3DTEXSTA_MINFILTER] = samplerStates[WINED3DSAMP_MINFILTER];
|
---|
416 | states[WINED3DTEXSTA_MAXMIPLEVEL] = samplerStates[WINED3DSAMP_MAXMIPLEVEL];
|
---|
417 |
|
---|
418 | if (states[WINED3DTEXSTA_MINFILTER] > WINED3DTEXF_ANISOTROPIC
|
---|
419 | || states[WINED3DTEXSTA_MIPFILTER] > WINED3DTEXF_ANISOTROPIC)
|
---|
420 | {
|
---|
421 |
|
---|
422 | FIXME("Unrecognized or unsupported D3DSAMP_MINFILTER value %d D3DSAMP_MIPFILTER value %d\n",
|
---|
423 | states[WINED3DTEXSTA_MINFILTER],
|
---|
424 | states[WINED3DTEXSTA_MIPFILTER]);
|
---|
425 | }
|
---|
426 | glValue = wined3d_gl_min_mip_filter(This->baseTexture.minMipLookup,
|
---|
427 | min(max(samplerStates[WINED3DSAMP_MINFILTER], WINED3DTEXF_POINT), WINED3DTEXF_LINEAR),
|
---|
428 | min(max(samplerStates[WINED3DSAMP_MIPFILTER], WINED3DTEXF_NONE), WINED3DTEXF_LINEAR));
|
---|
429 |
|
---|
430 | TRACE("ValueMIN=%d, ValueMIP=%d, setting MINFILTER to %x\n",
|
---|
431 | samplerStates[WINED3DSAMP_MINFILTER],
|
---|
432 | samplerStates[WINED3DSAMP_MIPFILTER], glValue);
|
---|
433 | glTexParameteri(textureDimensions, GL_TEXTURE_MIN_FILTER, glValue);
|
---|
434 | checkGLcall("glTexParameter GL_TEXTURE_MIN_FILTER, ...");
|
---|
435 |
|
---|
436 | if(!cond_np2) {
|
---|
437 | if(states[WINED3DTEXSTA_MIPFILTER] == WINED3DTEXF_NONE) {
|
---|
438 | glValue = 0;
|
---|
439 | } else if(states[WINED3DTEXSTA_MAXMIPLEVEL] >= This->baseTexture.levels) {
|
---|
440 | glValue = This->baseTexture.levels - 1;
|
---|
441 | } else {
|
---|
442 | glValue = states[WINED3DTEXSTA_MAXMIPLEVEL];
|
---|
443 | }
|
---|
444 | glTexParameteri(textureDimensions, GL_TEXTURE_BASE_LEVEL, glValue);
|
---|
445 | }
|
---|
446 | }
|
---|
447 |
|
---|
448 | if ((states[WINED3DSAMP_MAGFILTER] != WINED3DTEXF_ANISOTROPIC
|
---|
449 | && states[WINED3DSAMP_MINFILTER] != WINED3DTEXF_ANISOTROPIC
|
---|
450 | && states[WINED3DSAMP_MIPFILTER] != WINED3DTEXF_ANISOTROPIC)
|
---|
451 | || cond_np2)
|
---|
452 | {
|
---|
453 | aniso = 1;
|
---|
454 | }
|
---|
455 | else
|
---|
456 | {
|
---|
457 | aniso = samplerStates[WINED3DSAMP_MAXANISOTROPY];
|
---|
458 | }
|
---|
459 |
|
---|
460 | if (states[WINED3DTEXSTA_MAXANISOTROPY] != aniso)
|
---|
461 | {
|
---|
462 | if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC))
|
---|
463 | {
|
---|
464 | glTexParameteri(textureDimensions, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso);
|
---|
465 | checkGLcall("glTexParameteri(GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso)");
|
---|
466 | }
|
---|
467 | else
|
---|
468 | {
|
---|
469 | WARN("Anisotropic filtering not supported.\n");
|
---|
470 | }
|
---|
471 | states[WINED3DTEXSTA_MAXANISOTROPY] = aniso;
|
---|
472 | }
|
---|
473 | }
|
---|