Commit bb6f9b02 authored by Oliver Stieber's avatar Oliver Stieber Committed by Alexandre Julliard

Move the setting of states from device to basetexture, states that

relate to the opengl texture object will only be updated when they are out of sync, this reduces the number of texture object state changes during game play in Axis and allies from several hundreds to 0 or 1.
parent 3b5c2221
......@@ -217,6 +217,13 @@ UINT WINAPI IWineD3DCubeTextureImpl_GetTextureDimensions(IWineD3DCubeTexture *if
return GL_TEXTURE_CUBE_MAP_ARB;
}
void WINAPI IWineD3DCubeTextureImpl_ApplyStateChanges(IWineD3DCubeTexture *iface,
const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1],
const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]) {
IWineD3DBaseTextureImpl_ApplyStateChanges((IWineD3DBaseTexture *)iface, textureStates, samplerStates);
}
/* *******************************************
IWineD3DCubeTexture IWineD3DCubeTexture parts follow
******************************************* */
......@@ -319,6 +326,7 @@ const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl =
IWineD3DCubeTextureImpl_BindTexture,
IWineD3DCubeTextureImpl_UnBindTexture,
IWineD3DCubeTextureImpl_GetTextureDimensions,
IWineD3DCubeTextureImpl_ApplyStateChanges,
/* IWineD3DCubeTexture */
IWineD3DCubeTextureImpl_GetLevelDesc,
IWineD3DCubeTextureImpl_GetCubeMapSurface,
......
......@@ -58,6 +58,15 @@ inline static Display *get_display( HDC hdc )
return display;
}
/* lookup tables */
int minLookup[MAX_LOOKUPS];
int maxLookup[MAX_LOOKUPS];
DWORD *stateLookup[MAX_LOOKUPS];
DWORD minMipLookup[D3DTEXF_ANISOTROPIC + 1][D3DTEXF_LINEAR + 1];
/**
* Note: GL seems to trap if GetDeviceCaps is called before any HWND's created
* ie there is no GL Context - Get a default rendering context to enable the
......@@ -204,7 +213,8 @@ static BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info, Display* display)
Bool test = 0;
int major, minor;
WineD3D_Context *fake_ctx = NULL;
BOOL gotContext = FALSE;
BOOL gotContext = FALSE;
int i;
/* Make sure that we've got a context */
if (glXGetCurrentContext() == NULL) {
......@@ -562,6 +572,55 @@ static BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info, Display* display)
}
}
/* Load all the lookup tables
TODO: It may be a good idea to make minLookup and maxLookup const and populate them in wined3d_private.h where they are declared */
minLookup[WINELOOKUP_WARPPARAM] = D3DTADDRESS_WRAP;
maxLookup[WINELOOKUP_WARPPARAM] = D3DTADDRESS_MIRRORONCE;
minLookup[WINELOOKUP_MAGFILTER] = D3DTEXF_NONE;
maxLookup[WINELOOKUP_MAGFILTER] = D3DTEXF_ANISOTROPIC;
for (i = 0; i < MAX_LOOKUPS; i++) {
stateLookup[i] = HeapAlloc(GetProcessHeap(), 0, sizeof(*stateLookup[i]) * (1 + maxLookup[i] - minLookup[MAX_LOOKUPS]) );
}
stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_WRAP - minLookup[WINELOOKUP_WARPPARAM]] = GL_REPEAT;
stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_CLAMP - minLookup[WINELOOKUP_WARPPARAM]] = GL_CLAMP_TO_EDGE;
stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_BORDER - minLookup[WINELOOKUP_WARPPARAM]] =
gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_MIRROR - minLookup[WINELOOKUP_WARPPARAM]] =
gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
stateLookup[WINELOOKUP_WARPPARAM][D3DTADDRESS_MIRRORONCE - minLookup[WINELOOKUP_WARPPARAM]] =
gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT;
stateLookup[WINELOOKUP_MAGFILTER][D3DTEXF_NONE - minLookup[WINELOOKUP_MAGFILTER]] = GL_NEAREST;
stateLookup[WINELOOKUP_MAGFILTER][D3DTEXF_POINT - minLookup[WINELOOKUP_MAGFILTER]] = GL_NEAREST;
stateLookup[WINELOOKUP_MAGFILTER][D3DTEXF_LINEAR - minLookup[WINELOOKUP_MAGFILTER]] = GL_LINEAR;
stateLookup[WINELOOKUP_MAGFILTER][D3DTEXF_ANISOTROPIC - minLookup[WINELOOKUP_MAGFILTER]] =
gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR : GL_NEAREST;
minMipLookup[D3DTEXF_NONE][D3DTEXF_NONE] = GL_LINEAR;
minMipLookup[D3DTEXF_NONE][D3DTEXF_POINT] = GL_LINEAR;
minMipLookup[D3DTEXF_NONE][D3DTEXF_LINEAR] = GL_LINEAR;
minMipLookup[D3DTEXF_POINT][D3DTEXF_NONE] = GL_NEAREST;
minMipLookup[D3DTEXF_POINT][D3DTEXF_POINT] = GL_NEAREST_MIPMAP_NEAREST;
minMipLookup[D3DTEXF_POINT][D3DTEXF_LINEAR] = GL_NEAREST_MIPMAP_LINEAR;
minMipLookup[D3DTEXF_LINEAR][D3DTEXF_NONE] = GL_LINEAR;
minMipLookup[D3DTEXF_LINEAR][D3DTEXF_POINT] = GL_LINEAR_MIPMAP_NEAREST;
minMipLookup[D3DTEXF_LINEAR][D3DTEXF_LINEAR] = GL_LINEAR_MIPMAP_LINEAR;
minMipLookup[D3DTEXF_ANISOTROPIC][D3DTEXF_NONE] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ?
GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
minMipLookup[D3DTEXF_ANISOTROPIC][D3DTEXF_POINT] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR;
minMipLookup[D3DTEXF_ANISOTROPIC][D3DTEXF_LINEAR] = gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC] ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR;
/* TODO: config lookups */
#define USE_GL_FUNC(type, pfn) gl_info->pfn = (type) glXGetProcAddressARB( (const GLubyte *) #pfn);
GL_EXT_FUNCS_GEN;
#undef USE_GL_FUNC
......
......@@ -199,6 +199,11 @@ UINT WINAPI IWineD3DTextureImpl_GetTextureDimensions(IWineD3DTexture *iface) {
return GL_TEXTURE_2D;
}
void WINAPI IWineD3DTextureImpl_ApplyStateChanges(IWineD3DTexture *iface,
const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1],
const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]) {
IWineD3DBaseTextureImpl_ApplyStateChanges((IWineD3DBaseTexture *)iface, textureStates, samplerStates);
}
/* *******************************************
IWineD3DTexture IWineD3DTexture parts follow
......@@ -298,6 +303,7 @@ const IWineD3DTextureVtbl IWineD3DTexture_Vtbl =
IWineD3DTextureImpl_BindTexture,
IWineD3DTextureImpl_UnBindTexture,
IWineD3DTextureImpl_GetTextureDimensions,
IWineD3DTextureImpl_ApplyStateChanges,
/* IWineD3DTexture */
IWineD3DTextureImpl_GetLevelDesc,
IWineD3DTextureImpl_GetSurfaceLevel,
......
......@@ -182,6 +182,15 @@ UINT WINAPI IWineD3DVolumeTextureImpl_GetTextureDimensions(IWineD3DVolumeTexture
return GL_TEXTURE_3D;
}
void WINAPI IWineD3DVolumeTextureImpl_ApplyStateChanges(IWineD3DVolumeTexture *iface,
const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1],
const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]) {
IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
TRACE("(%p) : nothing to do, passing to base texture\n", This);
IWineD3DBaseTextureImpl_ApplyStateChanges((IWineD3DBaseTexture *)iface, textureStates, samplerStates);
}
/* *******************************************
IWineD3DVolumeTexture IWineD3DVolumeTexture parts follow
******************************************* */
......@@ -274,6 +283,7 @@ const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl =
IWineD3DVolumeTextureImpl_BindTexture,
IWineD3DVolumeTextureImpl_UnBindTexture,
IWineD3DVolumeTextureImpl_GetTextureDimensions,
IWineD3DVolumeTextureImpl_ApplyStateChanges,
/* volume texture */
IWineD3DVolumeTextureImpl_GetLevelDesc,
IWineD3DVolumeTextureImpl_GetVolumeLevel,
......
......@@ -66,6 +66,46 @@ extern const DWORD SavedVertexStates_R[NUM_SAVEDVERTEXSTATES_R];
extern const DWORD SavedVertexStates_T[NUM_SAVEDVERTEXSTATES_T];
extern const DWORD SavedVertexStates_S[NUM_SAVEDVERTEXSTATES_S];
typedef enum _WINELOOKUP {
WINELOOKUP_WARPPARAM = 0,
WINELOOKUP_MAGFILTER = 1,
MAX_LOOKUPS = 2
} WINELOOKUP;
extern int minLookup[MAX_LOOKUPS];
extern int maxLookup[MAX_LOOKUPS];
extern DWORD *stateLookup[MAX_LOOKUPS];
extern DWORD minMipLookup[D3DTEXF_ANISOTROPIC + 1][D3DTEXF_LINEAR + 1];
#if 0
/* NOTE: Make sure these are in the correct numerical order. (see /include/d3d9types.h typedef enum _D3DDECLTYPE) */
UINT static const glTypeLookup[D3DDECLTYPE_UNUSED][5] = {
{D3DDECLTYPE_FLOAT1, 1, GL_FLOAT , GL_FALSE ,sizeof(float)},
{D3DDECLTYPE_FLOAT2, 2, GL_FLOAT , GL_FALSE ,sizeof(float)},
{D3DDECLTYPE_FLOAT3, 3, GL_FLOAT , GL_FALSE ,sizeof(float)},
{D3DDECLTYPE_FLOAT4, 4, GL_FLOAT , GL_FALSE ,sizeof(float)},
{D3DDECLTYPE_D3DCOLOR, 4, GL_UNSIGNED_BYTE , GL_TRUE ,sizeof(BYTE)},
{D3DDECLTYPE_UBYTE4, 4, GL_UNSIGNED_BYTE , GL_FALSE ,sizeof(BYTE)},
{D3DDECLTYPE_SHORT2, 2, GL_SHORT , GL_FALSE ,sizeof(short int)},
{D3DDECLTYPE_SHORT4, 4, GL_SHORT , GL_FALSE ,sizeof(short int)},
{D3DDECLTYPE_UBYTE4N, 4, GL_UNSIGNED_BYTE , GL_FALSE ,sizeof(BYTE)},
{D3DDECLTYPE_SHORT2N, 2, GL_SHORT , GL_FALSE ,sizeof(short int)},
{D3DDECLTYPE_SHORT4N, 4, GL_SHORT , GL_FALSE ,sizeof(short int)},
{D3DDECLTYPE_USHORT2N, 2, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
{D3DDECLTYPE_USHORT4N, 4, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
{D3DDECLTYPE_UDEC3, 3, GL_UNSIGNED_SHORT , GL_FALSE ,sizeof(short int)},
{D3DDECLTYPE_DEC3N, 3, GL_SHORT , GL_FALSE ,sizeof(short int)},
{D3DDECLTYPE_FLOAT16_2, 2, GL_FLOAT , GL_FALSE ,sizeof(short int)},
{D3DDECLTYPE_FLOAT16_4, 4, GL_FLOAT , GL_FALSE ,sizeof(short int)}};
#define WINED3D_ATR_TYPE(_attribute) glTypeLookup[sd->u.s._attribute.dwType][0]
#define WINED3D_ATR_SIZE(_attribute) glTypeLookup[sd->u.s._attribute.dwType][1]
#define WINED3D_ATR_GLTYPE(_attribute) glTypeLookup[sd->u.s._attribute.dwType][2]
#define WINED3D_ATR_GLSOMETHING(_attribute) glTypeLookup[sd->u.s._attribute.dwType][3]
#define WINED3D_ATR_TYPESIZE(_attribute) glTypeLookup[sd->u.s._attribute.dwType][4]
#endif
/**
* Settings
*/
......@@ -583,6 +623,34 @@ typedef struct IWineD3DIndexBufferImpl
extern const IWineD3DIndexBufferVtbl IWineD3DIndexBuffer_Vtbl;
/*****************************************************************************
* IWineD3DBaseTexture D3D- > openGL state map lookups
*/
#define WINED3DFUNC_NOTSUPPORTED -2
#define WINED3DFUNC_UNIMPLEMENTED -1
typedef enum winetexturestates {
WINED3DTEXSTA_ADDRESSU = 0,
WINED3DTEXSTA_ADDRESSV = 1,
WINED3DTEXSTA_ADDRESSW = 2,
WINED3DTEXSTA_BORDERCOLOR = 3,
WINED3DTEXSTA_MAGFILTER = 4,
WINED3DTEXSTA_MINFILTER = 5,
WINED3DTEXSTA_MIPFILTER = 6,
WINED3DTEXSTA_MAXMIPLEVEL = 7,
WINED3DTEXSTA_MAXANISOTROPY = 8,
WINED3DTEXSTA_SRGBTEXTURE = 9,
WINED3DTEXSTA_ELEMENTINDEX = 10,
WINED3DTEXSTA_DMAPOFFSET = 11,
WINED3DTEXSTA_TSSADDRESSW = 12,
MAX_WINETEXTURESTATES = 13,
} winetexturestates;
typedef struct Wined3dTextureStateMap {
CONST int state;
int function;
} Wined3dTextureStateMap;
/*****************************************************************************
* IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
*/
typedef struct IWineD3DBaseTextureClass
......@@ -591,9 +659,10 @@ typedef struct IWineD3DBaseTextureClass
BOOL dirty;
D3DFORMAT format;
DWORD usage;
UINT textureName;
UINT textureName;
UINT LOD;
D3DTEXTUREFILTERTYPE filterType;
DWORD states[MAX_WINETEXTURESTATES];
} IWineD3DBaseTextureClass;
......@@ -1007,6 +1076,7 @@ int D3DFmtMakeGlCfg(D3DFORMAT BackBufferFormat, D3DFORMAT StencilBufferFormat, i
extern HRESULT WINAPI IWineD3DVertexBufferImpl_ReleaseMemory(IWineD3DVertexBuffer* iface);
extern HRESULT WINAPI IWineD3DBaseTextureImpl_BindTexture(IWineD3DBaseTexture *iface);
extern HRESULT WINAPI IWineD3DBaseTextureImpl_UnBindTexture(IWineD3DBaseTexture *iface);
extern void WINAPI IWineD3DBaseTextureImpl_ApplyStateChanges(IWineD3DBaseTexture *iface, const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
/*** class static members ***/
void IWineD3DBaseTextureImpl_CleanUp(IWineD3DBaseTexture *iface);
......
......@@ -691,6 +691,7 @@ DECLARE_INTERFACE_(IWineD3DBaseTexture,IWineD3DResource)
STDMETHOD(BindTexture)(THIS) PURE;
STDMETHOD(UnBindTexture)(THIS) PURE;
STDMETHOD_(UINT, GetTextureDimensions)(THIS) PURE;
STDMETHOD_(void, ApplyStateChanges)(THIS_ const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]) PURE;
};
#undef INTERFACE
......@@ -723,6 +724,7 @@ DECLARE_INTERFACE_(IWineD3DBaseTexture,IWineD3DResource)
#define IWineD3DBaseTexture_BindTexture(p) (p)->lpVtbl->BindTexture(p)
#define IWineD3DBaseTexture_UnBindTexture(p) (p)->lpVtbl->UnBindTexture(p)
#define IWineD3DBaseTexture_GetTextureDimensions(p) (p)->lpVtbl->GetTextureDimensions(p)
#define IWineD3DBaseTexture_ApplyStateChanges(p,a,b) (p)->lpVtbl->ApplyStateChanges(p,a,b)
#endif
/*****************************************************************************
......@@ -757,6 +759,7 @@ DECLARE_INTERFACE_(IWineD3DTexture,IWineD3DBaseTexture)
STDMETHOD(BindTexture)(THIS) PURE;
STDMETHOD(UnBindTexture)(THIS) PURE;
STDMETHOD_(UINT, GetTextureDimensions)(THIS) PURE;
STDMETHOD_(void, ApplyStateChanges)(THIS_ const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]) PURE;
/*** IWineD3DTexture methods ***/
STDMETHOD(GetLevelDesc)(THIS_ UINT Level, WINED3DSURFACE_DESC* pDesc) PURE;
STDMETHOD(GetSurfaceLevel)(THIS_ UINT Level, struct IWineD3DSurface** ppSurfaceLevel) PURE;
......@@ -793,6 +796,7 @@ DECLARE_INTERFACE_(IWineD3DTexture,IWineD3DBaseTexture)
#define IWineD3DTexture_BindTexture(p) (p)->lpVtbl->BindTexture(p)
#define IWineD3DTexture_UnBindTexture(p) (p)->lpVtbl->UnBindTexture(p)
#define IWineD3DTexture_GetTextureDimensions(p) (p)->lpVtbl->GetTextureDimensions(p)
#define IWineD3DTexture_ApplyStateChanges(p,a,b) (p)->lpVtbl->ApplyStateChanges(p,a,b)
/*** IWineD3DTexture methods ***/
#define IWineD3DTexture_GetLevelDesc(p,a,b) (p)->lpVtbl->GetLevelDesc(p,a,b)
#define IWineD3DTexture_GetSurfaceLevel(p,a,b) (p)->lpVtbl->GetSurfaceLevel(p,a,b)
......@@ -833,6 +837,7 @@ DECLARE_INTERFACE_(IWineD3DCubeTexture,IWineD3DBaseTexture)
STDMETHOD(BindTexture)(THIS) PURE;
STDMETHOD(UnBindTexture)(THIS) PURE;
STDMETHOD_(UINT, GetTextureDimensions)(THIS) PURE;
STDMETHOD_(void, ApplyStateChanges)(THIS_ DWORD const textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]) PURE;
/*** IWineD3DCubeTexture methods ***/
STDMETHOD(GetLevelDesc)(THIS_ UINT Level,WINED3DSURFACE_DESC* pDesc) PURE;
STDMETHOD(GetCubeMapSurface)(THIS_ D3DCUBEMAP_FACES FaceType, UINT Level, struct IWineD3DSurface** ppCubeMapSurface) PURE;
......@@ -869,6 +874,7 @@ DECLARE_INTERFACE_(IWineD3DCubeTexture,IWineD3DBaseTexture)
#define IWineD3DCubeTexture_BindTexture(p) (p)->lpVtbl->BindTexture(p)
#define IWineD3DCubeTexture_UnBindTexture(p) (p)->lpVtbl->UnBindTexture(p)
#define IWineD3DCubeTexture_GetTextureDimensions(p) (p)->lpVtbl->GetTextureDimensions(p)
#define IWineD3DCubeTexture_ApplyStateChanges(p,a,b) (p)->lpVtbl->ApplyStateChanges(p,a,b)
/*** IWineD3DCubeTexture methods ***/
#define IWineD3DCubeTexture_GetLevelDesc(p,a,b) (p)->lpVtbl->GetLevelDesc(p,a,b)
#define IWineD3DCubeTexture_GetCubeMapSurface(p,a,b,c) (p)->lpVtbl->GetCubeMapSurface(p,a,b,c)
......@@ -909,7 +915,8 @@ DECLARE_INTERFACE_(IWineD3DVolumeTexture,IWineD3DBaseTexture)
STDMETHOD_(BOOL, GetDirty)(THIS) PURE;
STDMETHOD(BindTexture)(THIS) PURE;
STDMETHOD(UnBindTexture)(THIS) PURE;
STDMETHOD_(UINT, GetTextureDimensions)(THIS) PURE;
STDMETHOD_(UINT, GetTextureDimensions)(THIS) PURE;
STDMETHOD_(void, ApplyStateChanges)(THIS_ const DWORD textureStates[WINED3D_HIGHEST_TEXTURE_STATE + 1], const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1]) PURE;
/*** IWineD3DVolumeTexture methods ***/
STDMETHOD(GetLevelDesc)(THIS_ UINT Level, WINED3DVOLUME_DESC *pDesc) PURE;
STDMETHOD(GetVolumeLevel)(THIS_ UINT Level, struct IWineD3DVolume** ppVolumeLevel) PURE;
......@@ -946,6 +953,7 @@ DECLARE_INTERFACE_(IWineD3DVolumeTexture,IWineD3DBaseTexture)
#define IWineD3DVolumeTexture_BindTexture(p) (p)->lpVtbl->BindTexture(p)
#define IWineD3DVolumeTexture_UnBindTexture(p) (p)->lpVtbl->UnBindTexture(p)
#define IWineD3DVolumeTexture_GetTextureDimensions(p) (p)->lpVtbl->GetTextureDimensions(p)
#define IWineD3DVolumeTexture_ApplyStateChanges(p,a,b) (p)->lpVtbl->ApplyStateChanges(p,a,b)
/*** IWineD3DVolumeTexture methods ***/
#define IWineD3DVolumeTexture_GetLevelDesc(p,a,b) (p)->lpVtbl->GetLevelDesc(p,a,b)
#define IWineD3DVolumeTexture_GetVolumeLevel(p,a,b) (p)->lpVtbl->GetVolumeLevel(p,a,b)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment