Commit d2016ff8 authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

wined3d: Store the gl format table in the gl info structure.

parent a0131a32
......@@ -6,7 +6,7 @@
* Copyright 2003-2004 Raphael Junqueira
* Copyright 2004 Christian Costa
* Copyright 2005 Oliver Stieber
* Copyright 2006 Stefan Dsinger for CodeWeavers
* Copyright 2006-2007 Stefan Dsinger for CodeWeavers
* Copyright 2006-2007 Henri Verbeet
* Copyright 2007 Andrew Riedi
*
......@@ -576,8 +576,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateSurface(IWineD3DDevice *iface, U
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
IWineD3DSurfaceImpl *object; /*NOTE: impl ref allowed since this is a create function */
unsigned int Size = 1;
const GlPixelFormatDesc *glDesc;
const StaticPixelFormatDesc *tableEntry = getFormatDescEntry(Format, &glDesc);
const StaticPixelFormatDesc *tableEntry = getFormatDescEntry(Format, NULL, NULL);
TRACE("(%p) Create surface\n",This);
/** FIXME: Check ranges on the inputs are valid
......@@ -644,15 +643,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateSurface(IWineD3DDevice *iface, U
object->currentDesc.Height = Height;
object->currentDesc.MultiSampleType = MultiSample;
object->currentDesc.MultiSampleQuality = MultisampleQuality;
/* Setup some glformat defaults */
object->glDescription.glFormat = glDesc->glFormat;
object->glDescription.glFormatInternal = glDesc->glInternal;
object->glDescription.glType = glDesc->glType;
object->glDescription.textureName = 0;
object->glDescription.level = Level;
object->glDescription.target = GL_TEXTURE_2D;
/* Flags */
object->Flags = 0;
......@@ -923,7 +914,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVolume(IWineD3DDevice *iface,
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
IWineD3DVolumeImpl *object; /** NOTE: impl ref allowed since this is a create function **/
const StaticPixelFormatDesc *formatDesc = getFormatDescEntry(Format, NULL);
const StaticPixelFormatDesc *formatDesc = getFormatDescEntry(Format, NULL, NULL);
D3DCREATERESOURCEOBJECTINSTANCE(object, Volume, WINED3DRTYPE_VOLUME, ((Width * formatDesc->bpp) * Height * Depth))
......@@ -2040,7 +2031,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetDisplayMode(IWineD3DDevice *iface, U
DEVMODEW devmode;
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
LONG ret;
const StaticPixelFormatDesc *formatDesc = getFormatDescEntry(pMode->Format, NULL);
const StaticPixelFormatDesc *formatDesc = getFormatDescEntry(pMode->Format, NULL, NULL);
RECT clip_rc;
TRACE("(%p)->(%d,%p) Mode=%dx%dx@%d, %s\n", This, iSwapChain, pMode, pMode->Width, pMode->Height, pMode->RefreshRate, debug_d3dformat(pMode->Format));
......@@ -5986,7 +5977,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetCursorProperties(IWineD3DDevice* i
if (SUCCEEDED(IWineD3DSurface_LockRect(pCursorBitmap, &rect, NULL, WINED3DLOCK_READONLY)))
{
const GlPixelFormatDesc *glDesc;
const StaticPixelFormatDesc *tableEntry = getFormatDescEntry(WINED3DFMT_A8R8G8B8, &glDesc);
const StaticPixelFormatDesc *tableEntry = getFormatDescEntry(WINED3DFMT_A8R8G8B8, &GLINFO_LOCATION, &glDesc);
char *mem, *bits = (char *)rect.pBits;
GLint intfmt = glDesc->glInternal;
GLint format = glDesc->glFormat;
......
......@@ -2556,11 +2556,20 @@ BOOL InitAdapters(void) {
HeapFree(GetProcessHeap(), 0, Adapters);
return FALSE;
}
ret = initPixelFormats(&Adapters[0].gl_info);
if(!ret) {
ERR("Failed to init gl formats\n");
XFree(Adapters[0].cfgs);
HeapFree(GetProcessHeap(), 0, Adapters);
return FALSE;
}
Adapters[0].driver = "Display";
Adapters[0].description = "Direct3D HAL";
select_shader_mode(&Adapters[0].gl_info, WINED3DDEVTYPE_HAL, &ps_selected_mode, &vs_selected_mode);
select_shader_max_constants(ps_selected_mode, vs_selected_mode, &Adapters[0].gl_info);
}
numAdapters = 1;
TRACE("%d adapters successfully initialized\n", numAdapters);
......
......@@ -347,7 +347,7 @@ static void state_alpha(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3D
surf = (IWineD3DSurfaceImpl *) ((IWineD3DTextureImpl *)stateblock->textures[0])->surfaces[0];
if(surf->CKeyFlags & WINEDDSD_CKSRCBLT) {
const StaticPixelFormatDesc *fmt = getFormatDescEntry(surf->resource.format, NULL);
const StaticPixelFormatDesc *fmt = getFormatDescEntry(surf->resource.format, NULL, NULL);
/* The surface conversion does not do color keying conversion for surfaces that have an alpha
* channel on their own. Likewise, the alpha test shouldn't be set up for color keying if the
* surface has alpha bits
......@@ -1783,7 +1783,7 @@ static void tex_alphaop(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3D
IWineD3DSurfaceImpl *surf = (IWineD3DSurfaceImpl *) ((IWineD3DTextureImpl *) stateblock->textures[0])->surfaces[0];
if(surf->CKeyFlags & WINEDDSD_CKSRCBLT &&
getFormatDescEntry(surf->resource.format, NULL)->alphaMask == 0x00000000) {
getFormatDescEntry(surf->resource.format, NULL, NULL)->alphaMask == 0x00000000) {
/* Color keying needs to pass alpha values from the texture through to have the alpha test work properly.
* On the other hand applications can still use texture combiners apparently. This code takes care that apps
......
......@@ -276,7 +276,7 @@ void surface_set_compatible_renderbuffer(IWineD3DSurface *iface, unsigned int wi
if (!renderbuffer) {
const GlPixelFormatDesc *glDesc;
getFormatDescEntry(This->resource.format, &glDesc);
getFormatDescEntry(This->resource.format, &GLINFO_LOCATION, &glDesc);
GL_EXTCALL(glGenRenderbuffersEXT(1, &renderbuffer));
GL_EXTCALL(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderbuffer));
......@@ -1262,7 +1262,7 @@ HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC) {
DWORD *masks;
HRESULT hr;
RGBQUAD col[256];
const StaticPixelFormatDesc *formatEntry = getFormatDescEntry(This->resource.format, NULL);
const StaticPixelFormatDesc *formatEntry = getFormatDescEntry(This->resource.format, NULL, NULL);
TRACE("(%p)->(%p)\n",This,pHDC);
......@@ -1484,7 +1484,7 @@ HRESULT WINAPI IWineD3DSurfaceImpl_ReleaseDC(IWineD3DSurface *iface, HDC hDC) {
static HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_texturing, GLenum *format, GLenum *internal, GLenum *type, CONVERT_TYPES *convert, int *target_bpp, BOOL srgb_mode) {
BOOL colorkey_active = need_alpha_ck && (This->CKeyFlags & WINEDDSD_CKSRCBLT);
const GlPixelFormatDesc *glDesc;
getFormatDescEntry(This->resource.format, &glDesc);
getFormatDescEntry(This->resource.format, &GLINFO_LOCATION, &glDesc);
/* Default values: From the surface */
*format = glDesc->glFormat;
......@@ -2251,7 +2251,7 @@ HRESULT WINAPI IWineD3DSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3D
HRESULT WINAPI IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format) {
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
const GlPixelFormatDesc *glDesc;
const StaticPixelFormatDesc *formatEntry = getFormatDescEntry(format, &glDesc);
const StaticPixelFormatDesc *formatEntry = getFormatDescEntry(format, &GLINFO_LOCATION, &glDesc);
if (This->resource.format != WINED3DFMT_UNKNOWN) {
FIXME("(%p) : The format of the surface must be WINED3DFORMAT_UNKNOWN\n", This);
......@@ -3439,6 +3439,16 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_PrivateSetup(IWineD3DSurface *iface) {
/** Check against the maximum texture sizes supported by the video card **/
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
unsigned int pow2Width, pow2Height;
const GlPixelFormatDesc *glDesc;
const StaticPixelFormatDesc *tableEntry = getFormatDescEntry(This->resource.format, &GLINFO_LOCATION, &glDesc);
/* Setup some glformat defaults */
This->glDescription.glFormat = glDesc->glFormat;
This->glDescription.glFormatInternal = glDesc->glInternal;
This->glDescription.glType = glDesc->glType;
This->glDescription.textureName = 0;
This->glDescription.target = GL_TEXTURE_2D;
/* Non-power2 support */
if (GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO)) {
......
......@@ -8,7 +8,7 @@
* Copyright 2002-2003 Raphael Junqueira
* Copyright 2004 Christian Costa
* Copyright 2005 Oliver Stieber
* Copyright 2006 Stefan Dsinger
* Copyright 2006-2008 Stefan Dsinger
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -536,7 +536,7 @@ IWineGDISurfaceImpl_Blt(IWineD3DSurface *iface,
dfmt = This->resource.format;
slock = dlock;
sfmt = dfmt;
sEntry = getFormatDescEntry(sfmt, NULL);
sEntry = getFormatDescEntry(sfmt, NULL, NULL);
dEntry = sEntry;
}
else
......@@ -546,9 +546,9 @@ IWineGDISurfaceImpl_Blt(IWineD3DSurface *iface,
IWineD3DSurface_LockRect(SrcSurface, &slock, NULL, WINED3DLOCK_READONLY);
sfmt = Src->resource.format;
}
sEntry = getFormatDescEntry(sfmt, NULL);
sEntry = getFormatDescEntry(sfmt, NULL, NULL);
dfmt = This->resource.format;
dEntry = getFormatDescEntry(dfmt, NULL);
dEntry = getFormatDescEntry(dfmt, NULL, NULL);
IWineD3DSurface_LockRect(iface, &dlock,NULL,0);
}
......@@ -1221,7 +1221,7 @@ IWineGDISurfaceImpl_BltFast(IWineD3DSurface *iface,
assert(This->resource.allocatedMemory != NULL);
sbuf = (BYTE *)This->resource.allocatedMemory + lock_src.top * pitch + lock_src.left * bpp;
dbuf = (BYTE *)This->resource.allocatedMemory + lock_dst.top * pitch + lock_dst.left * bpp;
sEntry = getFormatDescEntry(Src->resource.format, NULL);
sEntry = getFormatDescEntry(Src->resource.format, NULL, NULL);
dEntry = sEntry;
}
else
......@@ -1235,8 +1235,8 @@ IWineGDISurfaceImpl_BltFast(IWineD3DSurface *iface,
dbuf = dlock.pBits;
TRACE("Dst is at %p, Src is at %p\n", dbuf, sbuf);
sEntry = getFormatDescEntry(Src->resource.format, NULL);
dEntry = getFormatDescEntry(This->resource.format, NULL);
sEntry = getFormatDescEntry(Src->resource.format, NULL, NULL);
dEntry = getFormatDescEntry(This->resource.format, NULL, NULL);
}
/* Handle first the FOURCC surfaces... */
......@@ -1414,7 +1414,7 @@ const char* filename)
IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
static char *output = NULL;
static int size = 0;
const StaticPixelFormatDesc *formatEntry = getFormatDescEntry(This->resource.format, NULL);
const StaticPixelFormatDesc *formatEntry = getFormatDescEntry(This->resource.format, NULL, NULL);
if (This->pow2Width > size) {
output = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->pow2Width * 3);
......
......@@ -185,30 +185,50 @@ GlPixelFormatDesc gl_formats[] = {
{GL_COLOR_INDEX ,GL_COLOR_INDEX ,GL_COLOR_INDEX ,GL_UNSIGNED_SHORT }
};
const StaticPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt, const GlPixelFormatDesc **glDesc)
{
static inline int getFmtIdx(WINED3DFORMAT fmt) {
/* First check if the format is at the position of its value.
* This will catch the argb formats before the loop is entered
*/
if(fmt < (sizeof(formats) / sizeof(formats[0])) && formats[fmt].format == fmt) {
if(glDesc) *glDesc = &gl_formats[fmt];
return &formats[fmt];
return fmt;
} else {
unsigned int i;
for(i = 0; i < (sizeof(formats) / sizeof(formats[0])); i++) {
if(formats[i].format == fmt) {
if(glDesc) *glDesc = &gl_formats[i];
return &formats[i];
return i;
}
}
}
return -1;
}
BOOL initPixelFormats(WineD3D_GL_Info *gl_info)
{
/* Will be replaced with some more sophisticated initialization later */
gl_info->gl_formats = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(gl_formats));
if(!gl_info->gl_formats) return FALSE;
memcpy(gl_info->gl_formats, &gl_formats, sizeof(gl_formats));
return TRUE;
}
const StaticPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt, WineD3D_GL_Info *gl_info, const GlPixelFormatDesc **glDesc)
{
int idx = getFmtIdx(fmt);
if(idx == -1) {
FIXME("Can't find format %s(%d) in the format lookup table\n", debug_d3dformat(fmt), fmt);
if(fmt == WINED3DFMT_UNKNOWN) {
ERR("Format table corrupt - Can't find WINED3DFMT_UNKNOWN\n");
/* Get the caller a valid pointer */
idx = getFmtIdx(WINED3DFMT_UNKNOWN);
}
if(glDesc) {
if(!gl_info) {
ERR("OpenGL pixel format information was requested, but no gl info structure passed\n");
return NULL;
}
/* Get the caller a valid pointer */
return getFormatDescEntry(WINED3DFMT_UNKNOWN, glDesc);
*glDesc = &gl_info->gl_formats[idx];
}
return &formats[idx];
}
/*****************************************************************************
......
......@@ -266,7 +266,7 @@ static HRESULT WINAPI IWineD3DVolumeImpl_LoadTexture(IWineD3DVolume *iface, int
IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
WINED3DFORMAT format = This->resource.format;
const GlPixelFormatDesc *glDesc;
getFormatDescEntry(format, &glDesc);
getFormatDescEntry(format, &GLINFO_LOCATION, &glDesc);
TRACE("(%p) : level %u, format %s (0x%08x)\n", This, gl_level, debug_d3dformat(format), format);
......
......@@ -570,6 +570,7 @@ struct PLIGHTINFOEL {
extern const WINED3DLIGHT WINED3D_default_light;
/* The adapter structure */
typedef struct GLPixelFormatDesc GLPixelFormatDesc;
struct WineD3DAdapter
{
POINT monitorPoint;
......@@ -582,6 +583,7 @@ struct WineD3DAdapter
};
extern BOOL InitAdapters(void);
extern BOOL initPixelFormats(WineD3D_GL_Info *gl_info);
/*****************************************************************************
* High order patch management
......@@ -2040,12 +2042,8 @@ typedef struct {
BOOL isFourcc;
} StaticPixelFormatDesc;
typedef struct {
/* Array uses the same indices as the static pixelformat */
GLint glInternal, glGammaInternal, glFormat, glType;
} GlPixelFormatDesc;
const StaticPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt,
WineD3D_GL_Info *gl_info,
const GlPixelFormatDesc **glDesc);
static inline BOOL use_vs(IWineD3DDeviceImpl *device) {
......
......@@ -1948,6 +1948,11 @@ typedef enum _GL_SupportedExt {
/****************************************************
* Structures
****************************************************/
typedef struct {
GLint glInternal, glGammaInternal, glFormat, glType;
} GlPixelFormatDesc;
#define USE_GL_FUNC(type, pfn) type pfn;
typedef struct _WineD3D_GL_Info {
......@@ -2005,6 +2010,8 @@ typedef struct _WineD3D_GL_Info {
/** OpenGL 2.0 functions ptr */
/* GL2_FUNCS_GEN; */
/**/
GlPixelFormatDesc *gl_formats;
} WineD3D_GL_Info;
#undef USE_GL_FUNC
......
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