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