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