imm32: Correct a typo accidently using data instead of root_context.
[wine/gsoc_dplay.git] / dlls / wined3d / basetexture.c
blob34b6cbab7060850a345a4e6210f527da518b5ae2
1 /*
2 * IWineD3DBaseTexture Implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2002-2004 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
24 #include "wined3d_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
27 #define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
29 /* *******************************************
30 IWineD3DBaseTexture IUnknown parts follow
31 ******************************************* */
32 HRESULT WINAPI IWineD3DBaseTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, LPVOID *ppobj)
34 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
35 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
36 if (IsEqualGUID(riid, &IID_IUnknown)
37 || IsEqualGUID(riid, &IID_IWineD3DBase)
38 || IsEqualGUID(riid, &IID_IWineD3DResource)
39 || IsEqualGUID(riid, &IID_IWineD3DBaseTexture)) {
40 IUnknown_AddRef(iface);
41 *ppobj = This;
42 return S_OK;
44 *ppobj = NULL;
45 return E_NOINTERFACE;
48 ULONG WINAPI IWineD3DBaseTextureImpl_AddRef(IWineD3DBaseTexture *iface) {
49 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
50 ULONG ref = InterlockedIncrement(&This->resource.ref);
52 TRACE("(%p) : AddRef increasing from %d\n", This,ref - 1);
53 return ref;
56 ULONG WINAPI IWineD3DBaseTextureImpl_Release(IWineD3DBaseTexture *iface) {
57 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
58 ULONG ref = InterlockedDecrement(&This->resource.ref);
59 TRACE("(%p) : Releasing from %d\n", This, ref + 1);
60 if (ref == 0) {
61 IWineD3DBaseTextureImpl_CleanUp(iface);
62 HeapFree(GetProcessHeap(), 0, This);
64 return ref;
67 /* class static */
68 void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface) {
69 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
70 IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
72 TRACE("(%p) : textureName(%d)\n", This, This->baseTexture.textureName);
73 if (This->baseTexture.textureName != 0) {
74 ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
75 ENTER_GL();
76 TRACE("(%p) : Deleting texture %d\n", This, This->baseTexture.textureName);
77 glDeleteTextures(1, &This->baseTexture.textureName);
78 LEAVE_GL();
80 IWineD3DResourceImpl_CleanUp((IWineD3DResource *)iface);
83 /* ****************************************************
84 IWineD3DBaseTexture IWineD3DResource parts follow
85 **************************************************** */
86 HRESULT WINAPI IWineD3DBaseTextureImpl_GetDevice(IWineD3DBaseTexture *iface, IWineD3DDevice** ppDevice) {
87 return IWineD3DResourceImpl_GetDevice((IWineD3DResource *)iface, ppDevice);
90 HRESULT WINAPI IWineD3DBaseTextureImpl_SetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
91 return IWineD3DResourceImpl_SetPrivateData((IWineD3DResource *)iface, refguid, pData, SizeOfData, Flags);
94 HRESULT WINAPI IWineD3DBaseTextureImpl_GetPrivateData(IWineD3DBaseTexture *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
95 return IWineD3DResourceImpl_GetPrivateData((IWineD3DResource *)iface, refguid, pData, pSizeOfData);
98 HRESULT WINAPI IWineD3DBaseTextureImpl_FreePrivateData(IWineD3DBaseTexture *iface, REFGUID refguid) {
99 return IWineD3DResourceImpl_FreePrivateData((IWineD3DResource *)iface, refguid);
102 DWORD WINAPI IWineD3DBaseTextureImpl_SetPriority(IWineD3DBaseTexture *iface, DWORD PriorityNew) {
103 return IWineD3DResourceImpl_SetPriority((IWineD3DResource *)iface, PriorityNew);
106 DWORD WINAPI IWineD3DBaseTextureImpl_GetPriority(IWineD3DBaseTexture *iface) {
107 return IWineD3DResourceImpl_GetPriority((IWineD3DResource *)iface);
110 void WINAPI IWineD3DBaseTextureImpl_PreLoad(IWineD3DBaseTexture *iface) {
111 IWineD3DResourceImpl_PreLoad((IWineD3DResource *)iface);
114 void WINAPI IWineD3DBaseTextureImpl_UnLoad(IWineD3DBaseTexture *iface) {
115 IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
116 IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
118 if(This->baseTexture.textureName) {
119 ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
120 ENTER_GL();
121 glDeleteTextures(1, &This->baseTexture.textureName);
122 This->baseTexture.textureName = 0;
123 LEAVE_GL();
125 This->baseTexture.dirty = TRUE;
128 WINED3DRESOURCETYPE WINAPI IWineD3DBaseTextureImpl_GetType(IWineD3DBaseTexture *iface) {
129 return IWineD3DResourceImpl_GetType((IWineD3DResource *)iface);
132 HRESULT WINAPI IWineD3DBaseTextureImpl_GetParent(IWineD3DBaseTexture *iface, IUnknown **pParent) {
133 return IWineD3DResourceImpl_GetParent((IWineD3DResource *)iface, pParent);
136 /* ******************************************************
137 IWineD3DBaseTexture IWineD3DBaseTexture parts follow
138 ****************************************************** */
140 /* There is no OpenGL equivalent of setLOD, getLOD. All they do anyway is prioritize texture loading
141 * so just pretend that they work unless something really needs a failure. */
142 DWORD WINAPI IWineD3DBaseTextureImpl_SetLOD(IWineD3DBaseTexture *iface, DWORD LODNew) {
143 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
145 if (This->resource.pool != WINED3DPOOL_MANAGED) {
146 return WINED3DERR_INVALIDCALL;
149 if(LODNew >= This->baseTexture.levels)
150 LODNew = This->baseTexture.levels - 1;
151 This->baseTexture.LOD = LODNew;
153 TRACE("(%p) : set bogus LOD to %d\n", This, This->baseTexture.LOD);
155 return This->baseTexture.LOD;
158 DWORD WINAPI IWineD3DBaseTextureImpl_GetLOD(IWineD3DBaseTexture *iface) {
159 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
161 if (This->resource.pool != WINED3DPOOL_MANAGED) {
162 return WINED3DERR_INVALIDCALL;
165 TRACE("(%p) : returning %d\n", This, This->baseTexture.LOD);
167 return This->baseTexture.LOD;
170 DWORD WINAPI IWineD3DBaseTextureImpl_GetLevelCount(IWineD3DBaseTexture *iface) {
171 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
172 TRACE("(%p) : returning %d\n", This, This->baseTexture.levels);
173 return This->baseTexture.levels;
176 HRESULT WINAPI IWineD3DBaseTextureImpl_SetAutoGenFilterType(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE FilterType) {
177 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
178 IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
179 UINT textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
181 if (!(This->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP)) {
182 TRACE("(%p) : returning invalid call\n", This);
183 return WINED3DERR_INVALIDCALL;
185 if(This->baseTexture.filterType != FilterType) {
186 /* What about multithreading? Do we want all the context overhead just to set this value?
187 * Or should we delay the applying until the texture is used for drawing? For now, apply
188 * immediately.
190 ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
191 ENTER_GL();
192 glBindTexture(textureDimensions, This->baseTexture.textureName);
193 checkGLcall("glBindTexture");
194 switch(FilterType) {
195 case WINED3DTEXF_NONE:
196 case WINED3DTEXF_POINT:
197 glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_FASTEST);
198 checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_FASTEST)");
200 case WINED3DTEXF_LINEAR:
201 glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST);
202 checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST)");
204 default:
205 WARN("Unexpected filter type %d, setting to GL_NICEST\n", FilterType);
206 glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST);
207 checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST)");
209 LEAVE_GL();
211 This->baseTexture.filterType = FilterType;
212 TRACE("(%p) :\n", This);
213 return WINED3D_OK;
216 WINED3DTEXTUREFILTERTYPE WINAPI IWineD3DBaseTextureImpl_GetAutoGenFilterType(IWineD3DBaseTexture *iface) {
217 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
218 FIXME("(%p) : stub\n", This);
219 if (!(This->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP)) {
220 return WINED3DTEXF_NONE;
222 return This->baseTexture.filterType;
225 void WINAPI IWineD3DBaseTextureImpl_GenerateMipSubLevels(IWineD3DBaseTexture *iface) {
226 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
227 /* TODO: implement filters using GL_SGI_generate_mipmaps http://oss.sgi.com/projects/ogl-sample/registry/SGIS/generate_mipmap.txt */
228 FIXME("(%p) : stub\n", This);
229 return ;
232 /* Internal function, No d3d mapping */
233 BOOL WINAPI IWineD3DBaseTextureImpl_SetDirty(IWineD3DBaseTexture *iface, BOOL dirty) {
234 BOOL old;
235 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
236 old = This->baseTexture.dirty;
237 This->baseTexture.dirty = dirty;
238 return old;
241 BOOL WINAPI IWineD3DBaseTextureImpl_GetDirty(IWineD3DBaseTexture *iface) {
242 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
243 return This->baseTexture.dirty;
246 HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface) {
247 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
248 HRESULT hr = WINED3D_OK;
249 UINT textureDimensions;
250 BOOL isNewTexture = FALSE;
251 TRACE("(%p) : About to bind texture\n", This);
253 textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
254 ENTER_GL();
255 /* Generate a texture name if we don't already have one */
256 if (This->baseTexture.textureName == 0) {
257 glGenTextures(1, &This->baseTexture.textureName);
258 checkGLcall("glGenTextures");
259 TRACE("Generated texture %d\n", This->baseTexture.textureName);
260 if (This->resource.pool == WINED3DPOOL_DEFAULT) {
261 /* Tell opengl to try and keep this texture in video ram (well mostly) */
262 GLclampf tmp;
263 tmp = 0.9f;
264 glPrioritizeTextures(1, &This->baseTexture.textureName, &tmp);
267 /* Initialise the state of the texture object
268 to the openGL defaults, not the directx defaults */
269 This->baseTexture.states[WINED3DTEXSTA_ADDRESSU] = WINED3DTADDRESS_WRAP;
270 This->baseTexture.states[WINED3DTEXSTA_ADDRESSV] = WINED3DTADDRESS_WRAP;
271 This->baseTexture.states[WINED3DTEXSTA_ADDRESSW] = WINED3DTADDRESS_WRAP;
272 This->baseTexture.states[WINED3DTEXSTA_BORDERCOLOR] = 0;
273 This->baseTexture.states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_LINEAR;
274 This->baseTexture.states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT; /* GL_NEAREST_MIPMAP_LINEAR */
275 This->baseTexture.states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_LINEAR; /* GL_NEAREST_MIPMAP_LINEAR */
276 This->baseTexture.states[WINED3DTEXSTA_MAXMIPLEVEL] = 0;
277 This->baseTexture.states[WINED3DTEXSTA_MAXANISOTROPY] = 0;
278 This->baseTexture.states[WINED3DTEXSTA_SRGBTEXTURE] = 0;
279 This->baseTexture.states[WINED3DTEXSTA_ELEMENTINDEX] = 0;
280 This->baseTexture.states[WINED3DTEXSTA_DMAPOFFSET] = 0;
281 This->baseTexture.states[WINED3DTEXSTA_TSSADDRESSW] = WINED3DTADDRESS_WRAP;
282 IWineD3DBaseTexture_SetDirty(iface, TRUE);
283 isNewTexture = TRUE;
285 if(This->resource.usage & WINED3DUSAGE_AUTOGENMIPMAP) {
286 /* This means double binding the texture at creation, but keeps the code simpler all
287 * in all, and the run-time path free from additional checks
289 glBindTexture(textureDimensions, This->baseTexture.textureName);
290 checkGLcall("glBindTexture");
291 glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
292 checkGLcall("glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_SGIS, GL_TRUE)");
296 /* Bind the texture */
297 if (This->baseTexture.textureName != 0) {
298 glBindTexture(textureDimensions, This->baseTexture.textureName);
299 checkGLcall("glBindTexture");
300 if (isNewTexture) {
301 /* For a new texture we have to set the textures levels after binding the texture.
302 * In theory this is all we should ever have to do, but because ATI's drivers are broken, we
303 * also need to set the texture dimensions before the texture is set
304 * Beware that texture rectangles do not support mipmapping.
306 if(textureDimensions != GL_TEXTURE_RECTANGLE_ARB) {
307 TRACE("Setting GL_TEXTURE_MAX_LEVEL to %d\n", This->baseTexture.levels - 1);
308 glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, This->baseTexture.levels - 1);
309 checkGLcall("glTexParameteri(textureDimensions, GL_TEXTURE_MAX_LEVEL, This->baseTexture.levels)");
311 if(textureDimensions==GL_TEXTURE_CUBE_MAP_ARB) {
312 /* Cubemaps are always set to clamp, regardless of the sampler state. */
313 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
314 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
315 glTexParameteri(textureDimensions, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
319 } else { /* this only happened if we've run out of openGL textures */
320 WARN("This texture doesn't have an openGL texture assigned to it\n");
321 hr = WINED3DERR_INVALIDCALL;
324 LEAVE_GL();
325 return hr;
328 HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface) {
329 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
330 UINT textureDimensions;
332 TRACE("(%p) : About to bind texture\n", This);
333 textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
335 ENTER_GL();
337 glBindTexture(textureDimensions, 0);
338 #if 0 /* TODO: context manager support */
339 IWineD3DContextManager_PopState(This->contextManager, textureDimensions, ENABLED, NOW /* make sure the state is applied now */);
340 #else
341 glDisable(textureDimensions);
342 #endif
344 LEAVE_GL();
345 return WINED3D_OK;
348 UINT WINAPI IWineD3DBaseTextureImpl_GetTextureDimensions(IWineD3DBaseTexture *iface){
349 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
350 FIXME("(%p) : This shouldn't be called\n", This);
351 return WINED3D_OK;
354 static inline GLenum warpLookupType(WINED3DSAMPLERSTATETYPE Type) {
355 switch(Type) {
356 case WINED3DSAMP_ADDRESSU:
357 return GL_TEXTURE_WRAP_S;
358 case WINED3DSAMP_ADDRESSV:
359 return GL_TEXTURE_WRAP_T;
360 case WINED3DSAMP_ADDRESSW:
361 return GL_TEXTURE_WRAP_R;
362 default:
363 FIXME("Unexpected warp type %d\n", Type);
364 return 0;
368 static inline void apply_wrap(const GLint textureDimensions, const DWORD state, const GLint type) {
369 GLint wrapParm;
371 if (state < minLookup[WINELOOKUP_WARPPARAM] || state > maxLookup[WINELOOKUP_WARPPARAM]) {
372 FIXME("Unrecognized or unsupported WINED3DTADDRESS_U value %d\n", state);
373 } else {
374 if(textureDimensions==GL_TEXTURE_CUBE_MAP_ARB) {
375 /* Cubemaps are always set to clamp, regardless of the sampler state. */
376 wrapParm = GL_CLAMP_TO_EDGE;
377 } else if(textureDimensions==GL_TEXTURE_RECTANGLE_ARB) {
378 if(state == WINED3DTADDRESS_WRAP) {
379 wrapParm = GL_CLAMP_TO_EDGE;
380 } else {
381 wrapParm = stateLookup[WINELOOKUP_WARPPARAM][state - minLookup[WINELOOKUP_WARPPARAM]];
383 } else {
384 wrapParm = stateLookup[WINELOOKUP_WARPPARAM][state - minLookup[WINELOOKUP_WARPPARAM]];
386 TRACE("Setting WRAP_S to %d for %x\n", wrapParm, textureDimensions);
387 glTexParameteri(textureDimensions, type, wrapParm);
388 checkGLcall("glTexParameteri(..., type, wrapParm)");
392 void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface,
393 const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1],
394 const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]) {
395 IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
396 DWORD state;
397 GLint textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
399 IWineD3DBaseTexture_PreLoad(iface);
401 if(samplerStates[WINED3DSAMP_ADDRESSU] != This->baseTexture.states[WINED3DTEXSTA_ADDRESSU]) {
402 state = samplerStates[WINED3DSAMP_ADDRESSU];
403 apply_wrap(textureDimensions, state, GL_TEXTURE_WRAP_S);
404 This->baseTexture.states[WINED3DTEXSTA_ADDRESSU] = state;
407 if(samplerStates[WINED3DSAMP_ADDRESSV] != This->baseTexture.states[WINED3DTEXSTA_ADDRESSV]) {
408 state = samplerStates[WINED3DSAMP_ADDRESSV];
409 apply_wrap(textureDimensions, state, GL_TEXTURE_WRAP_T);
410 This->baseTexture.states[WINED3DTEXSTA_ADDRESSV] = state;
413 if(samplerStates[WINED3DSAMP_ADDRESSW] != This->baseTexture.states[WINED3DTEXSTA_ADDRESSW]) {
414 state = samplerStates[WINED3DSAMP_ADDRESSW];
415 apply_wrap(textureDimensions, state, GL_TEXTURE_WRAP_R);
416 This->baseTexture.states[WINED3DTEXSTA_ADDRESSW] = state;
419 if(samplerStates[WINED3DSAMP_BORDERCOLOR] != This->baseTexture.states[WINED3DTEXSTA_BORDERCOLOR]) {
420 float col[4];
422 state = samplerStates[WINED3DSAMP_BORDERCOLOR];
423 D3DCOLORTOGLFLOAT4(state, col);
424 TRACE("Setting border color for %u to %x\n", textureDimensions, state);
425 glTexParameterfv(textureDimensions, GL_TEXTURE_BORDER_COLOR, &col[0]);
426 checkGLcall("glTexParameteri(..., GL_TEXTURE_BORDER_COLOR, ...)");
427 This->baseTexture.states[WINED3DTEXSTA_BORDERCOLOR] = state;
430 if(samplerStates[WINED3DSAMP_MAGFILTER] != This->baseTexture.states[WINED3DTEXSTA_MAGFILTER]) {
431 GLint glValue;
432 state = samplerStates[WINED3DSAMP_MAGFILTER];
433 if (state < minLookup[WINELOOKUP_MAGFILTER] || state > maxLookup[WINELOOKUP_MAGFILTER]) {
434 FIXME("Unrecognized or unsupported MAGFILTER* value %d\n", state);
436 glValue = stateLookup[WINELOOKUP_MAGFILTER][state - minLookup[WINELOOKUP_MAGFILTER]];
437 TRACE("ValueMAG=%d setting MAGFILTER to %x\n", state, glValue);
438 glTexParameteri(textureDimensions, GL_TEXTURE_MAG_FILTER, glValue);
439 /* 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. */
440 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC) && WINED3DTEXF_ANISOTROPIC == state &&
441 textureDimensions != GL_TEXTURE_RECTANGLE_ARB) {
442 glTexParameteri(textureDimensions, GL_TEXTURE_MAX_ANISOTROPY_EXT, samplerStates[WINED3DSAMP_MAXANISOTROPY]);
444 This->baseTexture.states[WINED3DTEXSTA_MAGFILTER] = state;
447 if(textureDimensions != GL_TEXTURE_RECTANGLE_ARB &&
448 (samplerStates[WINED3DSAMP_MINFILTER] != This->baseTexture.states[WINED3DTEXSTA_MINFILTER] ||
449 samplerStates[WINED3DSAMP_MIPFILTER] != This->baseTexture.states[WINED3DTEXSTA_MIPFILTER] ||
450 samplerStates[WINED3DSAMP_MAXMIPLEVEL] != This->baseTexture.states[WINED3DTEXSTA_MAXMIPLEVEL])) {
451 GLint glValue;
453 This->baseTexture.states[WINED3DTEXSTA_MIPFILTER] = samplerStates[WINED3DSAMP_MIPFILTER];
454 This->baseTexture.states[WINED3DTEXSTA_MINFILTER] = samplerStates[WINED3DSAMP_MINFILTER];
455 This->baseTexture.states[WINED3DTEXSTA_MAXMIPLEVEL] = samplerStates[WINED3DSAMP_MAXMIPLEVEL];
457 if (This->baseTexture.states[WINED3DTEXSTA_MINFILTER] > WINED3DTEXF_ANISOTROPIC ||
458 This->baseTexture.states[WINED3DTEXSTA_MIPFILTER] > WINED3DTEXF_LINEAR)
461 FIXME("Unrecognized or unsupported D3DSAMP_MINFILTER value %d D3DSAMP_MIPFILTER value %d\n",
462 This->baseTexture.states[WINED3DTEXSTA_MINFILTER],
463 This->baseTexture.states[WINED3DTEXSTA_MIPFILTER]);
465 glValue = minMipLookup[min(max(samplerStates[WINED3DSAMP_MINFILTER],WINED3DTEXF_NONE), WINED3DTEXF_ANISOTROPIC)]
466 [min(max(samplerStates[WINED3DSAMP_MIPFILTER],WINED3DTEXF_NONE), WINED3DTEXF_LINEAR)];
468 TRACE("ValueMIN=%d, ValueMIP=%d, setting MINFILTER to %x\n",
469 samplerStates[WINED3DSAMP_MINFILTER],
470 samplerStates[WINED3DSAMP_MIPFILTER], glValue);
471 glTexParameteri(textureDimensions, GL_TEXTURE_MIN_FILTER, glValue);
472 checkGLcall("glTexParameter GL_TEXTURE_MIN_FILTER, ...");
474 if(This->baseTexture.states[WINED3DTEXSTA_MIPFILTER] == WINED3DTEXF_NONE) {
475 glValue = 0;
476 } else if(This->baseTexture.states[WINED3DTEXSTA_MAXMIPLEVEL] >= This->baseTexture.levels) {
477 glValue = This->baseTexture.levels - 1;
478 } else {
479 glValue = This->baseTexture.states[WINED3DTEXSTA_MAXMIPLEVEL];
481 glTexParameteri(textureDimensions, GL_TEXTURE_BASE_LEVEL, glValue);
484 if(samplerStates[WINED3DSAMP_MAXANISOTROPY] != This->baseTexture.states[WINED3DTEXSTA_MAXANISOTROPY]) {
485 if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC) && textureDimensions != GL_TEXTURE_RECTANGLE_ARB) {
486 glTexParameteri(textureDimensions, GL_TEXTURE_MAX_ANISOTROPY_EXT, samplerStates[WINED3DSAMP_MAXANISOTROPY]);
487 checkGLcall("glTexParameteri GL_TEXTURE_MAX_ANISOTROPY_EXT ...");
488 } else {
489 WARN("Unsupported in local OpenGL implementation: glTexParameteri GL_TEXTURE_MAX_ANISOTROPY_EXT\n");
491 This->baseTexture.states[WINED3DTEXSTA_MAXANISOTROPY] = samplerStates[WINED3DSAMP_MAXANISOTROPY];
496 static const IWineD3DBaseTextureVtbl IWineD3DBaseTexture_Vtbl =
498 /* IUnknown */
499 IWineD3DBaseTextureImpl_QueryInterface,
500 IWineD3DBaseTextureImpl_AddRef,
501 IWineD3DBaseTextureImpl_Release,
502 /* IWineD3DResource */
503 IWineD3DBaseTextureImpl_GetParent,
504 IWineD3DBaseTextureImpl_GetDevice,
505 IWineD3DBaseTextureImpl_SetPrivateData,
506 IWineD3DBaseTextureImpl_GetPrivateData,
507 IWineD3DBaseTextureImpl_FreePrivateData,
508 IWineD3DBaseTextureImpl_SetPriority,
509 IWineD3DBaseTextureImpl_GetPriority,
510 IWineD3DBaseTextureImpl_PreLoad,
511 IWineD3DBaseTextureImpl_UnLoad,
512 IWineD3DBaseTextureImpl_GetType,
513 /*IWineD3DBaseTexture*/
514 IWineD3DBaseTextureImpl_SetLOD,
515 IWineD3DBaseTextureImpl_GetLOD,
516 IWineD3DBaseTextureImpl_GetLevelCount,
517 IWineD3DBaseTextureImpl_SetAutoGenFilterType,
518 IWineD3DBaseTextureImpl_GetAutoGenFilterType,
519 IWineD3DBaseTextureImpl_GenerateMipSubLevels,
520 IWineD3DBaseTextureImpl_SetDirty,
521 IWineD3DBaseTextureImpl_GetDirty,
522 /* internal */
523 IWineD3DBaseTextureImpl_BindTexture,
524 IWineD3DBaseTextureImpl_UnBindTexture,
525 IWineD3DBaseTextureImpl_GetTextureDimensions,
526 IWineD3DBaseTextureImpl_ApplyStateChanges