fusion/tests: Fix compilation on systems that don't support nameless unions.
[wine/testsucceed.git] / dlls / wined3d / basetexture.c
blob0ad043326d4951a94eb849b3d874f2ab1a59d921
1 /*
2 * IWineD3DBaseTexture Implementation
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
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.
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.
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
24 #include "config.h"
25 #include "wined3d_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
28 #define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
30 /* *******************************************
31 IWineD3DBaseTexture IUnknown parts follow
32 ******************************************* */
33 HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, LPVOID *ppobj)
35 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
36 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
37 if (IsEqualGUID(riid, &IID_IUnknown)
38 || IsEqualGUID(riid, &IID_IWineD3DBase)
39 || IsEqualGUID(riid, &IID_IWineD3DResource)
40 || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)) {
41 IUnknown_AddRef(iface);
42 *ppobj = This;
43 return S_OK;
45 *ppobj = NULL;
46 return E_NOINTERFACE;
49 ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface) {
50 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
51 ULONG ref = InterlockedIncrement(&This->resource.ref);
53 TRACE("(%p) : AddRef increasing from %d\n", This,ref - 1);
54 return ref;
57 ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface) {
58 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
59 ULONG ref = InterlockedDecrement(&This->resource.ref);
60 TRACE("(%p) : Releasing from %d\n", This, ref + 1);
61 if (ref == 0) {
62 IWineD3DBaseTextureImpl_CleanUp(iface);
63 HeapFree(GetProcessHeap(), 0, This);
65 return ref;
68 /* class static */
69 void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface) {
70 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
71 IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
73 TRACE("(%p) : textureName(%d)\n", This, This->baseTexture.textureName);
74 if (This->baseTexture.textureName != 0) {
75 ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
76 ENTER_GL();
77 TRACE("(%p) : Deleting texture %d\n", This, This->baseTexture.textureName);
78 glDeleteTextures(1, &This->baseTexture.textureName);
79 LEAVE_GL();
81 IWineD3DResourceImpl_CleanUp((IWineD3DResource *)iface);
84 /* ****************************************************
85 IWineD3DBaseTexture IWineD3DResource parts follow
86 **************************************************** */
87 HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice** ppDevice) {
88 return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
91 HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
92 return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
95 HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
96 return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
99 HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID refguid) {
100 return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
103 DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD PriorityNew) {
104 return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
107 DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface) {
108 return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
111 void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface) {
112 IWineD3DResourceImpl_PreLoad((IWineD3DResource *)iface);
115 void WINAPI IWineD3DBaseTextureImpl_UnLoad(IWineD3DBaseTexture *iface) {
116 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
117 IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
119 if(This->baseTexture.textureName) {
120 ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
121 ENTER_GL();
122 glDeleteTextures(1, &This->baseTexture.textureName);
123 This->baseTexture.textureName = 0;
124 LEAVE_GL();
126 This->baseTexture.dirty = TRUE;
129 WINED3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface) {
130 return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
133 HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent) {
134 return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
137 /* ******************************************************
138 IWineD3DBaseTexture IWineD3DBaseTexture parts follow
139 ****************************************************** */
141 /* There is no OpenGL equivalent of setLOD, getLOD. All they do anyway is prioritize texture loading
142 * so just pretend that they work unless something really needs a failure. */
143 DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew) {
144 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
146 if (This->resource.pool != WINED3DPOOL_MANAGED) {
147 return WINED3DERR_INVALIDCALL;
150 if(LODNew >= This->baseTexture.levels)
151 LODNew = This->baseTexture.levels - 1;
152 This->baseTexture.LOD = LODNew;
154 TRACE("(%p) : set bogus LOD to %d\n", This, This->baseTexture.LOD);
156 return This->baseTexture.LOD;
159 DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface) {
160 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
162 if (This->resource.pool != WINED3DPOOL_MANAGED) {
163 return WINED3DERR_INVALIDCALL;
166 TRACE("(%p) : returning %d\n", This, This->baseTexture.LOD);
168 return This->baseTexture.LOD;
171 DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface) {
172 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
173 TRACE("(%p) : returning %d\n", This, This->baseTexture.levels);
174 return This->baseTexture.levels;
177 HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
178 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
179 IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
180 UINT textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
182 if (!(This->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP)) {
183 TRACE("(%p) : returning invalid call\n", This);
184 return WINED3DERR_INVALIDCALL;
186 if(This->baseTexture.filterType != FilterType) {
187 /* What about multithreading? Do we want all the context overhead just to set this value?
188 * Or should we delay the applying until the texture is used for drawing? For now, apply
189 * immediately.
191 ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
192 ENTER_GL();
193 glBindTexture(textureDimensions, This->baseTexture.textureName);
194 checkGLcall("glBindTexture");
195 switch(FilterType) {
196 case WINED3DTEXF_NONE:
197 case WINED3DTEXF_POINT:
198 glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_FASTEST);
199 checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_FASTEST)");
201 case WINED3DTEXF_LINEAR:
202 glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST);
203 checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST)");
205 default:
206 WARN("Unexpected filter type %d, setting to GL_NICEST\n", FilterType);
207 glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST);
208 checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST)");
210 LEAVE_GL();
212 This->baseTexture.filterType = FilterType;
213 TRACE("(%p) :\n", This);
214 return WINED3D_OK;
217 WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface) {
218 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
219 FIXME("(%p) : stub\n", This);
220 if (!(This->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP)) {
221 return WINED3DTEXF_NONE;
223 return This->baseTexture.filterType;
226 void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface) {
227 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
228 /* TODO: implement filters using GL_SGI_generate_mipmaps http://oss.sgi.com/projects/ogl-sample/registry/SGIS/generate_mipmap.txt */
229 FIXME("(%p) : stub\n", This);
230 return ;
233 /* Internal function, No d3d mapping */
234 BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL dirty) {
235 BOOL old;
236 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
237 old = This->baseTexture.dirty;
238 This->baseTexture.dirty = dirty;
239 return old;
242 BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface) {
243 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
244 return This->baseTexture.dirty;
247 HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface) {
248 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
249 HRESULT hr = WINED3D_OK;
250 UINT textureDimensions;
251 BOOL isNewTexture = FALSE;
252 TRACE("(%p) : About to bind texture\n", This);
254 textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
255 ENTER_GL();
256 /* Generate a texture name if we don't already have one */
257 if (This->baseTexture.textureName == 0) {
258 glGenTextures(1, &This->baseTexture.textureName);
259 checkGLcall("glGenTextures");
260 TRACE("Generated texture %d\n", This->baseTexture.textureName);
261 if (This->resource.pool == WINED3DPOOL_DEFAULT) {
262 /* Tell opengl to try and keep this texture in video ram (well mostly) */
263 GLclampf tmp;
264 tmp = 0.9f;
265 glPrioritizeTextures(1, &This->baseTexture.textureName, &tmp);
268 /* Initialise the state of the texture object
269 to the openGL defaults, not the directx defaults */
270 This->baseTexture.states[WINED3DTEXSTA_ADDRESSU] = WINED3DTADDRESS_WRAP;
271 This->baseTexture.states[WINED3DTEXSTA_ADDRESSV] = WINED3DTADDRESS_WRAP;
272 This->baseTexture.states[WINED3DTEXSTA_ADDRESSW] = WINED3DTADDRESS_WRAP;
273 This->baseTexture.states[WINED3DTEXSTA_BORDERCOLOR] = 0;
274 This->baseTexture.states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_LINEAR;
275 This->baseTexture.states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT; /* GL_NEAREST_MIPMAP_LINEAR */
276 This->baseTexture.states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_LINEAR; /* GL_NEAREST_MIPMAP_LINEAR */
277 This->baseTexture.states[WINED3DTEXSTA_MAXMIPLEVEL] = 0;
278 This->baseTexture.states[WINED3DTEXSTA_MAXANISOTROPY] = 0;
279 This->baseTexture.states[WINED3DTEXSTA_SRGBTEXTURE] = 0;
280 This->baseTexture.states[WINED3DTEXSTA_ELEMENTINDEX] = 0;
281 This->baseTexture.states[WINED3DTEXSTA_DMAPOFFSET] = 0;
282 This->baseTexture.states[WINED3DTEXSTA_TSSADDRESSW] = WINED3DTADDRESS_WRAP;
283 IWineD3DBaseTexture_SetDirty(iface, TRUE);
284 isNewTexture = TRUE;
286 if(This->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP) {
287 /* This means double binding the texture at creation, but keeps the code simpler all
288 * in all, and the run-time path free from additional checks
290 glBindTexture(textureDimensions, This->baseTexture.textureName);
291 checkGLcall("glBindTexture");
292 glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
293 checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_SGIS, GL_TRUE)");
297 /* Bind the texture */
298 if (This->baseTexture.textureName != 0) {
299 glBindTexture(textureDimensions, This->baseTexture.textureName);
300 checkGLcall("glBindTexture");
301 if (isNewTexture) {
302 /* For a new texture we have to set the textures levels after binding the texture.
303 * In theory this is all we should ever have to do, but because ATI's drivers are broken, we
304 * also need to set the texture dimensions before the texture is set
305 * Beware that texture rectangles do not support mipmapping.
307 if(textureDimensions != GL_TEXTURE_RECTANGLE_ARB) {
308 TRACE("Setting GL_TEXTURE_MAX_LEVEL to %d\n", This->baseTexture.levels - 1);
309 glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, This->baseTexture.levels - 1);
310 checkGLcall("glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, This->baseTexture.levels)");
312 if(textureDimensions==GL_TEXTURE_CUBE_MAP_ARB) {
313 /* Cubemaps are always set to clamp, regardless of the sampler state. */
314 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
315 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
316 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
320 } else { /* this only happened if we've run out of openGL textures */
321 WARN("This texture doesn't have an openGL texture assigned to it\n");
322 hr = WINED3DERR_INVALIDCALL;
325 LEAVE_GL();
326 return hr;
329 HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface) {
330 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
331 UINT textureDimensions;
333 TRACE("(%p) : About to bind texture\n", This);
334 textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
336 ENTER_GL();
338 glBindTexture(textureDimensions, 0);
339 #if 0 /* TODO: context manager support */
340 IWineD3DContextManager_PopState(This->contextManager, textureDimensions, ENABLED, NOW /* make sure the state is applied now */);
341 #else
342 glDisable(textureDimensions);
343 #endif
345 LEAVE_GL();
346 return WINED3D_OK;
349 UINT WINAPI IWineD3DBaseTextureImpl_GetTextureDimensions(IWineD3DBaseTexture *iface){
350 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
351 FIXME("(%p) : This shouldn't be called\n", This);
352 return WINED3D_OK;
355 static inline GLenum warpLookupType(WINED3DSAMPLERSTATETYPE Type) {
356 switch(Type) {
357 case WINED3DSAMP_ADDRESSU:
358 return GL_TEXTURE_WRAP_S;
359 case WINED3DSAMP_ADDRESSV:
360 return GL_TEXTURE_WRAP_T;
361 case WINED3DSAMP_ADDRESSW:
362 return GL_TEXTURE_WRAP_R;
363 default:
364 FIXME("Unexpected warp type %d\n", Type);
365 return 0;
369 static inline void apply_wrap(const GLint textureDimensions, const DWORD state, const GLint type) {
370 GLint wrapParm;
372 if (state < minLookup[WINELOOKUP_WARPPARAM] || state > maxLookup[WINELOOKUP_WARPPARAM]) {
373 FIXME("Unrecognized or unsupported WINED3DTADDRESS_U value %d\n", state);
374 } else {
375 if(textureDimensions==GL_TEXTURE_CUBE_MAP_ARB) {
376 /* Cubemaps are always set to clamp, regardless of the sampler state. */
377 wrapParm = GL_CLAMP_TO_EDGE;
378 } else if(textureDimensions==GL_TEXTURE_RECTANGLE_ARB) {
379 if(state == WINED3DTADDRESS_WRAP) {
380 wrapParm = GL_CLAMP_TO_EDGE;
381 } else {
382 wrapParm = stateLookup[WINELOOKUP_WARPPARAM][state - minLookup[WINELOOKUP_WARPPARAM]];
384 } else {
385 wrapParm = stateLookup[WINELOOKUP_WARPPARAM][state - minLookup[WINELOOKUP_WARPPARAM]];
387 TRACE("Setting WRAP_S to %d for %x\n", wrapParm, textureDimensions);
388 glTexParameteri(textureDimensions, type, wrapParm);
389 checkGLcall("glTexParameteri(..., type, wrapParm)");
393 void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface,
394 const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1],
395 const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]) {
396 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
397 DWORD state;
398 GLint textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
400 IWineD3DBaseTexture_PreLoad(iface);
402 if(samplerStates[WINED3DSAMP_ADDRESSU] != This->baseTexture.states[WINED3DTEXSTA_ADDRESSU]) {
403 state = samplerStates[WINED3DSAMP_ADDRESSU];
404 apply_wrap(textureDimensions, state, GL_TEXTURE_WRAP_S);
405 This->baseTexture.states[WINED3DTEXSTA_ADDRESSU] = state;
408 if(samplerStates[WINED3DSAMP_ADDRESSV] != This->baseTexture.states[WINED3DTEXSTA_ADDRESSV]) {
409 state = samplerStates[WINED3DSAMP_ADDRESSV];
410 apply_wrap(textureDimensions, state, GL_TEXTURE_WRAP_T);
411 This->baseTexture.states[WINED3DTEXSTA_ADDRESSV] = state;
414 if(samplerStates[WINED3DSAMP_ADDRESSW] != This->baseTexture.states[WINED3DTEXSTA_ADDRESSW]) {
415 state = samplerStates[WINED3DSAMP_ADDRESSW];
416 apply_wrap(textureDimensions, state, GL_TEXTURE_WRAP_R);
417 This->baseTexture.states[WINED3DTEXSTA_ADDRESSW] = state;
420 if(samplerStates[WINED3DSAMP_BORDERCOLOR] != This->baseTexture.states[WINED3DTEXSTA_BORDERCOLOR]) {
421 float col[4];
423 state = samplerStates[WINED3DSAMP_BORDERCOLOR];
424 D3DCOLORTOGLFLOAT4(state, col);
425 TRACE("Setting border color for %u to %x\n", textureDimensions, state);
426 glTexParameterfv(textureDimensions, GL_TEXTURE_BORDER_COLOR, &col[0]);
427 checkGLcall("glTexParameteri(..., GL_TEXTURE_BORDER_COLOR, ...)");
428 This->baseTexture.states[WINED3DTEXSTA_BORDERCOLOR] = state;
431 if(samplerStates[WINED3DSAMP_MAGFILTER] != This->baseTexture.states[WINED3DTEXSTA_MAGFILTER]) {
432 GLint glValue;
433 state = samplerStates[WINED3DSAMP_MAGFILTER];
434 if (state < minLookup[WINELOOKUP_MAGFILTER] || state > maxLookup[WINELOOKUP_MAGFILTER]) {
435 FIXME("Unrecognized or unsupported MAGFILTER* value %d\n", state);
437 glValue = stateLookup[WINELOOKUP_MAGFILTER][state - minLookup[WINELOOKUP_MAGFILTER]];
438 TRACE("ValueMAG=%d setting MAGFILTER to %x\n", state, glValue);
439 glTexParameteri(textureDimensions, GL_TEXTURE_MAG_FILTER, glValue);
440 /* We need to reset the Anisotropic filtering state when we change the mag filter to WINED3DTEXF_ANISOTROPIC (this seems a bit weird, check the documentation to see how it should be switched off. */
441 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC) && WINED3DTEXF_ANISOTROPIC == state &&
442 textureDimensions != GL_TEXTURE_RECTANGLE_ARB) {
443 glTexParameteri(textureDimensions, GL_TEXTURE_MAX_ANISOTROPY_EXT, samplerStates[WINED3DSAMP_MAXANISOTROPY]);
445 This->baseTexture.states[WINED3DTEXSTA_MAGFILTER] = state;
448 if(textureDimensions != GL_TEXTURE_RECTANGLE_ARB &&
449 (samplerStates[WINED3DSAMP_MINFILTER] != This->baseTexture.states[WINED3DTEXSTA_MINFILTER] ||
450 samplerStates[WINED3DSAMP_MIPFILTER] != This->baseTexture.states[WINED3DTEXSTA_MIPFILTER] ||
451 samplerStates[WINED3DSAMP_MAXMIPLEVEL] != This->baseTexture.states[WINED3DTEXSTA_MAXMIPLEVEL])) {
452 GLint glValue;
454 This->baseTexture.states[WINED3DTEXSTA_MIPFILTER] = samplerStates[WINED3DSAMP_MIPFILTER];
455 This->baseTexture.states[WINED3DTEXSTA_MINFILTER] = samplerStates[WINED3DSAMP_MINFILTER];
456 This->baseTexture.states[WINED3DTEXSTA_MAXMIPLEVEL] = samplerStates[WINED3DSAMP_MAXMIPLEVEL];
458 if (This->baseTexture.states[WINED3DTEXSTA_MINFILTER] > WINED3DTEXF_ANISOTROPIC ||
459 This->baseTexture.states[WINED3DTEXSTA_MIPFILTER] > WINED3DTEXF_LINEAR)
462 FIXME("Unrecognized or unsupported D3DSAMP_MINFILTER value %d D3DSAMP_MIPFILTER value %d\n",
463 This->baseTexture.states[WINED3DTEXSTA_MINFILTER],
464 This->baseTexture.states[WINED3DTEXSTA_MIPFILTER]);
466 glValue = minMipLookup[min(max(samplerStates[WINED3DSAMP_MINFILTER],WINED3DTEXF_NONE), WINED3DTEXF_ANISOTROPIC)]
467 [min(max(samplerStates[WINED3DSAMP_MIPFILTER],WINED3DTEXF_NONE), WINED3DTEXF_LINEAR)];
469 TRACE("ValueMIN=%d, ValueMIP=%d, setting MINFILTER to %x\n",
470 samplerStates[WINED3DSAMP_MINFILTER],
471 samplerStates[WINED3DSAMP_MIPFILTER], glValue);
472 glTexParameteri(textureDimensions, GL_TEXTURE_MIN_FILTER, glValue);
473 checkGLcall("glTexParameter GL_TEXTURE_MIN_FILTER, ...");
475 if(This->baseTexture.states[WINED3DTEXSTA_MIPFILTER] == WINED3DTEXF_NONE) {
476 glValue = 0;
477 } else if(This->baseTexture.states[WINED3DTEXSTA_MAXMIPLEVEL] >= This->baseTexture.levels) {
478 glValue = This->baseTexture.levels - 1;
479 } else {
480 glValue = This->baseTexture.states[WINED3DTEXSTA_MAXMIPLEVEL];
482 glTexParameteri(textureDimensions, GL_TEXTURE_BASE_LEVEL, glValue);
485 if(samplerStates[WINED3DSAMP_MAXANISOTROPY] != This->baseTexture.states[WINED3DTEXSTA_MAXANISOTROPY]) {
486 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC) && textureDimensions != GL_TEXTURE_RECTANGLE_ARB) {
487 glTexParameteri(textureDimensions, GL_TEXTURE_MAX_ANISOTROPY_EXT, samplerStates[WINED3DSAMP_MAXANISOTROPY]);
488 checkGLcall("glTexParameteri GL_TEXTURE_MAX_ANISOTROPY_EXT ...");
489 } else {
490 WARN("Unsupported in local OpenGL implementation: glTexParameteri GL_TEXTURE_MAX_ANISOTROPY_EXT\n");
492 This->baseTexture.states[WINED3DTEXSTA_MAXANISOTROPY] = samplerStates[WINED3DSAMP_MAXANISOTROPY];
497 static const IWineD3DBaseTextureVtbl IWineD3DBaseTexture_Vtbl =
499 /* IUnknown */
500 IWineD3DBaseTextureImpl_QueryInterface,
501 IWineD3DBaseTextureImpl_AddRef,
502 IWineD3DBaseTextureImpl_Release,
503 /* IWineD3DResource */
504 IWineD3DBaseTextureImpl_GetParent,
505 IWineD3DBaseTextureImpl_GetDevice,
506 IWineD3DBaseTextureImpl_SetPrivateData,
507 IWineD3DBaseTextureImpl_GetPrivateData,
508 IWineD3DBaseTextureImpl_FreePrivateData,
509 IWineD3DBaseTextureImpl_SetPriority,
510 IWineD3DBaseTextureImpl_GetPriority,
511 IWineD3DBaseTextureImpl_PreLoad,
512 IWineD3DBaseTextureImpl_UnLoad,
513 IWineD3DBaseTextureImpl_GetType,
514 /*IWineD3DBaseTexture*/
515 IWineD3DBaseTextureImpl_SetLOD,
516 IWineD3DBaseTextureImpl_GetLOD,
517 IWineD3DBaseTextureImpl_GetLevelCount,
518 IWineD3DBaseTextureImpl_SetAutoGenFilterType,
519 IWineD3DBaseTextureImpl_GetAutoGenFilterType,
520 IWineD3DBaseTextureImpl_GenerateMipSubLevels,
521 IWineD3DBaseTextureImpl_SetDirty,
522 IWineD3DBaseTextureImpl_GetDirty,
523 /* internal */
524 IWineD3DBaseTextureImpl_BindTexture,
525 IWineD3DBaseTextureImpl_UnBindTexture,
526 IWineD3DBaseTextureImpl_GetTextureDimensions,
527 IWineD3DBaseTextureImpl_ApplyStateChanges