wined3d: Pass format_desc to getColorBits() and getDepthStencilBits().

This commit is contained in:
Henri Verbeet 2009-03-24 10:09:24 +01:00 committed by Alexandre Julliard
parent a02d801888
commit dd1f0d9c48
4 changed files with 55 additions and 63 deletions

View File

@ -446,7 +446,9 @@ static WineD3DContext *AddContextToArray(IWineD3DDeviceImpl *This, HWND win_hand
} }
/* This function takes care of WineD3D pixel format selection. */ /* This function takes care of WineD3D pixel format selection. */
static int WineD3D_ChoosePixelFormat(IWineD3DDeviceImpl *This, HDC hdc, WINED3DFORMAT ColorFormat, WINED3DFORMAT DepthStencilFormat, BOOL auxBuffers, int numSamples, BOOL pbuffer, BOOL findCompatible) static int WineD3D_ChoosePixelFormat(IWineD3DDeviceImpl *This, HDC hdc,
const struct GlPixelFormatDesc *color_format_desc, const struct GlPixelFormatDesc *ds_format_desc,
BOOL auxBuffers, int numSamples, BOOL pbuffer, BOOL findCompatible)
{ {
int iPixelFormat=0; int iPixelFormat=0;
unsigned int matchtry; unsigned int matchtry;
@ -477,11 +479,13 @@ static int WineD3D_ChoosePixelFormat(IWineD3DDeviceImpl *This, HDC hdc, WINED3DF
int nCfgs = This->adapter->nCfgs; int nCfgs = This->adapter->nCfgs;
TRACE("ColorFormat=%s, DepthStencilFormat=%s, auxBuffers=%d, numSamples=%d, pbuffer=%d, findCompatible=%d\n", TRACE("ColorFormat=%s, DepthStencilFormat=%s, auxBuffers=%d, numSamples=%d, pbuffer=%d, findCompatible=%d\n",
debug_d3dformat(ColorFormat), debug_d3dformat(DepthStencilFormat), auxBuffers, numSamples, pbuffer, findCompatible); debug_d3dformat(color_format_desc->format), debug_d3dformat(ds_format_desc->format),
auxBuffers, numSamples, pbuffer, findCompatible);
if (!getColorBits(&This->adapter->gl_info, ColorFormat, &redBits, &greenBits, &blueBits, &alphaBits, &colorBits)) if (!getColorBits(color_format_desc, &redBits, &greenBits, &blueBits, &alphaBits, &colorBits))
{ {
ERR("Unable to get color bits for format %s (%#x)!\n", debug_d3dformat(ColorFormat), ColorFormat); ERR("Unable to get color bits for format %s (%#x)!\n",
debug_d3dformat(color_format_desc->format), color_format_desc->format);
return 0; return 0;
} }
@ -496,15 +500,14 @@ static int WineD3D_ChoosePixelFormat(IWineD3DDeviceImpl *This, HDC hdc, WINED3DF
* Likely a lot of other new bugs will be exposed. For that reason request a depth stencil surface all the * Likely a lot of other new bugs will be exposed. For that reason request a depth stencil surface all the
* time. It can cause a slight performance hit but fixes a lot of regressions. A fixme reminds of that this * time. It can cause a slight performance hit but fixes a lot of regressions. A fixme reminds of that this
* issue needs to be fixed. */ * issue needs to be fixed. */
if(DepthStencilFormat != WINED3DFMT_D24S8) if (ds_format_desc->format != WINED3DFMT_D24S8)
{
FIXME("Add OpenGL context recreation support to SetDepthStencilSurface\n"); FIXME("Add OpenGL context recreation support to SetDepthStencilSurface\n");
ds_format_desc = getFormatDescEntry(WINED3DFMT_D24S8, &This->adapter->gl_info);
DepthStencilFormat = WINED3DFMT_D24S8;
if(DepthStencilFormat) {
getDepthStencilBits(&This->adapter->gl_info, DepthStencilFormat, &depthBits, &stencilBits);
} }
getDepthStencilBits(ds_format_desc, &depthBits, &stencilBits);
for(matchtry = 0; matchtry < (sizeof(matches) / sizeof(matches[0])) && !iPixelFormat; matchtry++) { for(matchtry = 0; matchtry < (sizeof(matches) / sizeof(matches[0])) && !iPixelFormat; matchtry++) {
for(i=0; i<nCfgs; i++) { for(i=0; i<nCfgs; i++) {
BOOL exactDepthMatch = TRUE; BOOL exactDepthMatch = TRUE;
@ -615,7 +618,8 @@ static int WineD3D_ChoosePixelFormat(IWineD3DDeviceImpl *This, HDC hdc, WINED3DF
} }
} }
TRACE("Found iPixelFormat=%d for ColorFormat=%s, DepthStencilFormat=%s\n", iPixelFormat, debug_d3dformat(ColorFormat), debug_d3dformat(DepthStencilFormat)); TRACE("Found iPixelFormat=%d for ColorFormat=%s, DepthStencilFormat=%s\n",
iPixelFormat, debug_d3dformat(color_format_desc->format), debug_d3dformat(ds_format_desc->format));
return iPixelFormat; return iPixelFormat;
} }
@ -646,20 +650,21 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar
int iPixelFormat = 0; int iPixelFormat = 0;
IWineD3DSurface *StencilSurface = This->stencilBufferTarget; IWineD3DSurface *StencilSurface = This->stencilBufferTarget;
WINED3DFORMAT StencilBufferFormat = StencilSurface ? const struct GlPixelFormatDesc *ds_format_desc = StencilSurface
((IWineD3DSurfaceImpl *)StencilSurface)->resource.format_desc->format : 0; ? ((IWineD3DSurfaceImpl *)StencilSurface)->resource.format_desc
: getFormatDescEntry(WINED3DFMT_UNKNOWN, &This->adapter->gl_info);
/* Try to find a pixel format with pbuffer support. */ /* Try to find a pixel format with pbuffer support. */
iPixelFormat = WineD3D_ChoosePixelFormat(This, hdc_parent, target->resource.format_desc->format, iPixelFormat = WineD3D_ChoosePixelFormat(This, hdc_parent, target->resource.format_desc,
StencilBufferFormat, FALSE /* auxBuffers */, 0 /* numSamples */, TRUE /* PBUFFER */, ds_format_desc, FALSE /* auxBuffers */, 0 /* numSamples */, TRUE /* PBUFFER */,
FALSE /* findCompatible */); FALSE /* findCompatible */);
if(!iPixelFormat) { if(!iPixelFormat) {
TRACE("Trying to locate a compatible pixel format because an exact match failed.\n"); TRACE("Trying to locate a compatible pixel format because an exact match failed.\n");
/* For some reason we weren't able to find a format, try to find something instead of crashing. /* For some reason we weren't able to find a format, try to find something instead of crashing.
* A reason for failure could have been wglChoosePixelFormatARB strictness. */ * A reason for failure could have been wglChoosePixelFormatARB strictness. */
iPixelFormat = WineD3D_ChoosePixelFormat(This, hdc_parent, target->resource.format_desc->format, iPixelFormat = WineD3D_ChoosePixelFormat(This, hdc_parent, target->resource.format_desc,
StencilBufferFormat, FALSE /* auxBuffer */, 0 /* numSamples */, TRUE /* PBUFFER */, ds_format_desc, FALSE /* auxBuffer */, 0 /* numSamples */, TRUE /* PBUFFER */,
TRUE /* findCompatible */); TRUE /* findCompatible */);
} }
@ -691,8 +696,9 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar
PIXELFORMATDESCRIPTOR pfd; PIXELFORMATDESCRIPTOR pfd;
int iPixelFormat; int iPixelFormat;
int res; int res;
WINED3DFORMAT ColorFormat = target->resource.format_desc->format; const struct GlPixelFormatDesc *color_format_desc = target->resource.format_desc;
WINED3DFORMAT DepthStencilFormat = 0; const struct GlPixelFormatDesc *ds_format_desc = getFormatDescEntry(WINED3DFMT_UNKNOWN,
&This->adapter->gl_info);
BOOL auxBuffers = FALSE; BOOL auxBuffers = FALSE;
int numSamples = 0; int numSamples = 0;
@ -706,25 +712,25 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar
if(wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER) { if(wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER) {
auxBuffers = TRUE; auxBuffers = TRUE;
if (target->resource.format_desc->format == WINED3DFMT_X4R4G4B4) if (color_format_desc->format == WINED3DFMT_X4R4G4B4)
ColorFormat = WINED3DFMT_A4R4G4B4; color_format_desc = getFormatDescEntry(WINED3DFMT_A4R4G4B4, &This->adapter->gl_info);
else if(target->resource.format_desc->format == WINED3DFMT_X8R8G8B8) else if (color_format_desc->format == WINED3DFMT_X8R8G8B8)
ColorFormat = WINED3DFMT_A8R8G8B8; color_format_desc = getFormatDescEntry(WINED3DFMT_A8R8G8B8, &This->adapter->gl_info);
} }
/* DirectDraw supports 8bit paletted render targets and these are used by old games like Starcraft and C&C. /* DirectDraw supports 8bit paletted render targets and these are used by old games like Starcraft and C&C.
* Most modern hardware doesn't support 8bit natively so we perform some form of 8bit -> 32bit conversion. * Most modern hardware doesn't support 8bit natively so we perform some form of 8bit -> 32bit conversion.
* The conversion (ab)uses the alpha component for storing the palette index. For this reason we require * The conversion (ab)uses the alpha component for storing the palette index. For this reason we require
* a format with 8bit alpha, so request A8R8G8B8. */ * a format with 8bit alpha, so request A8R8G8B8. */
if(ColorFormat == WINED3DFMT_P8) if (color_format_desc->format == WINED3DFMT_P8)
ColorFormat = WINED3DFMT_A8R8G8B8; color_format_desc = getFormatDescEntry(WINED3DFMT_A8R8G8B8, &This->adapter->gl_info);
/* Retrieve the depth stencil format from the present parameters. /* Retrieve the depth stencil format from the present parameters.
* The choice of the proper format can give a nice performance boost * The choice of the proper format can give a nice performance boost
* in case of GPU limited programs. */ * in case of GPU limited programs. */
if(pPresentParms->EnableAutoDepthStencil) { if(pPresentParms->EnableAutoDepthStencil) {
TRACE("pPresentParms->EnableAutoDepthStencil=enabled; using AutoDepthStencilFormat=%s\n", debug_d3dformat(pPresentParms->AutoDepthStencilFormat)); TRACE("pPresentParms->EnableAutoDepthStencil=enabled; using AutoDepthStencilFormat=%s\n", debug_d3dformat(pPresentParms->AutoDepthStencilFormat));
DepthStencilFormat = pPresentParms->AutoDepthStencilFormat; ds_format_desc = getFormatDescEntry(pPresentParms->AutoDepthStencilFormat, &This->adapter->gl_info);
} }
/* D3D only allows multisampling when SwapEffect is set to WINED3DSWAPEFFECT_DISCARD */ /* D3D only allows multisampling when SwapEffect is set to WINED3DSWAPEFFECT_DISCARD */
@ -738,12 +744,14 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar
} }
/* Try to find a pixel format which matches our requirements */ /* Try to find a pixel format which matches our requirements */
iPixelFormat = WineD3D_ChoosePixelFormat(This, hdc, ColorFormat, DepthStencilFormat, auxBuffers, numSamples, FALSE /* PBUFFER */, FALSE /* findCompatible */); iPixelFormat = WineD3D_ChoosePixelFormat(This, hdc, color_format_desc, ds_format_desc,
auxBuffers, numSamples, FALSE /* PBUFFER */, FALSE /* findCompatible */);
/* Try to locate a compatible format if we weren't able to find anything */ /* Try to locate a compatible format if we weren't able to find anything */
if(!iPixelFormat) { if(!iPixelFormat) {
TRACE("Trying to locate a compatible pixel format because an exact match failed.\n"); TRACE("Trying to locate a compatible pixel format because an exact match failed.\n");
iPixelFormat = WineD3D_ChoosePixelFormat(This, hdc, ColorFormat, DepthStencilFormat, auxBuffers, 0 /* numSamples */, FALSE /* PBUFFER */, TRUE /* findCompatible */ ); iPixelFormat = WineD3D_ChoosePixelFormat(This, hdc, color_format_desc, ds_format_desc,
auxBuffers, 0 /* numSamples */, FALSE /* PBUFFER */, TRUE /* findCompatible */ );
} }
/* If we still don't have a pixel format, something is very wrong as ChoosePixelFormat barely fails */ /* If we still don't have a pixel format, something is very wrong as ChoosePixelFormat barely fails */

View File

@ -1722,7 +1722,7 @@ static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(const WineD3D_GL_I
return FALSE; return FALSE;
if(cfg->iPixelType == WGL_TYPE_RGBA_ARB) { /* Integer RGBA formats */ if(cfg->iPixelType == WGL_TYPE_RGBA_ARB) { /* Integer RGBA formats */
if (!getColorBits(gl_info, format_desc->format, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits)) if (!getColorBits(format_desc, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits))
{ {
ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(format_desc->format)); ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(format_desc->format));
return FALSE; return FALSE;
@ -1771,7 +1771,7 @@ static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(const WineD3D_GL_In
if(!cfg) if(!cfg)
return FALSE; return FALSE;
if (!getDepthStencilBits(gl_info, format_desc->format, &depthSize, &stencilSize)) if (!getDepthStencilBits(format_desc, &depthSize, &stencilSize))
{ {
ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(format_desc->format)); ERR("Unable to check compatibility for Format=%s\n", debug_d3dformat(format_desc->format));
return FALSE; return FALSE;
@ -1898,7 +1898,7 @@ static HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, U
int i, nCfgs; int i, nCfgs;
const WineD3D_PixelFormat *cfgs; const WineD3D_PixelFormat *cfgs;
if (!getColorBits(&adapter->gl_info, SurfaceFormat, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits)) if (!getColorBits(glDesc, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits))
{ {
ERR("Unable to color bits for format %#x, can't check multisampling capability!\n", SurfaceFormat); ERR("Unable to color bits for format %#x, can't check multisampling capability!\n", SurfaceFormat);
return WINED3DERR_NOTAVAILABLE; return WINED3DERR_NOTAVAILABLE;
@ -2090,10 +2090,8 @@ static BOOL CheckRenderTargetCapability(struct WineD3DAdapter *adapter,
short AdapterRed, AdapterGreen, AdapterBlue, AdapterAlpha, AdapterTotalSize; short AdapterRed, AdapterGreen, AdapterBlue, AdapterAlpha, AdapterTotalSize;
short CheckRed, CheckGreen, CheckBlue, CheckAlpha, CheckTotalSize; short CheckRed, CheckGreen, CheckBlue, CheckAlpha, CheckTotalSize;
getColorBits(&adapter->gl_info, adapter_format_desc->format, getColorBits(adapter_format_desc, &AdapterRed, &AdapterGreen, &AdapterBlue, &AdapterAlpha, &AdapterTotalSize);
&AdapterRed, &AdapterGreen, &AdapterBlue, &AdapterAlpha, &AdapterTotalSize); getColorBits(check_format_desc, &CheckRed, &CheckGreen, &CheckBlue, &CheckAlpha, &CheckTotalSize);
getColorBits(&adapter->gl_info, check_format_desc->format,
&CheckRed, &CheckGreen, &CheckBlue, &CheckAlpha, &CheckTotalSize);
/* In backbuffer mode the front and backbuffer share the same WGL pixelformat. /* In backbuffer mode the front and backbuffer share the same WGL pixelformat.
* The format must match in RGB, alpha is allowed to be different. (Only the backbuffer can have alpha) */ * The format must match in RGB, alpha is allowed to be different. (Only the backbuffer can have alpha) */

View File

@ -1571,13 +1571,11 @@ unsigned int count_bits(unsigned int mask)
/* Helper function for retrieving color info for ChoosePixelFormat and wglChoosePixelFormatARB. /* Helper function for retrieving color info for ChoosePixelFormat and wglChoosePixelFormatARB.
* The later function requires individual color components. */ * The later function requires individual color components. */
BOOL getColorBits(const WineD3D_GL_Info *gl_info, WINED3DFORMAT fmt, BOOL getColorBits(const struct GlPixelFormatDesc *format_desc,
short *redSize, short *greenSize, short *blueSize, short *alphaSize, short *totalSize) short *redSize, short *greenSize, short *blueSize, short *alphaSize, short *totalSize)
{ {
const struct GlPixelFormatDesc *format_desc; TRACE("fmt: %s\n", debug_d3dformat(format_desc->format));
switch(format_desc->format)
TRACE("fmt: %s\n", debug_d3dformat(fmt));
switch(fmt)
{ {
case WINED3DFMT_X8R8G8B8: case WINED3DFMT_X8R8G8B8:
case WINED3DFMT_R8G8B8: case WINED3DFMT_R8G8B8:
@ -1594,33 +1592,26 @@ BOOL getColorBits(const WineD3D_GL_Info *gl_info, WINED3DFORMAT fmt,
case WINED3DFMT_P8: case WINED3DFMT_P8:
break; break;
default: default:
ERR("Unsupported format: %s\n", debug_d3dformat(fmt)); ERR("Unsupported format: %s\n", debug_d3dformat(format_desc->format));
return FALSE; return FALSE;
} }
format_desc = getFormatDescEntry(fmt, gl_info);
if (!format_desc)
{
ERR("Unable to look up format: 0x%x\n", fmt);
return FALSE;
}
*redSize = count_bits(format_desc->red_mask); *redSize = count_bits(format_desc->red_mask);
*greenSize = count_bits(format_desc->green_mask); *greenSize = count_bits(format_desc->green_mask);
*blueSize = count_bits(format_desc->blue_mask); *blueSize = count_bits(format_desc->blue_mask);
*alphaSize = count_bits(format_desc->alpha_mask); *alphaSize = count_bits(format_desc->alpha_mask);
*totalSize = *redSize + *greenSize + *blueSize + *alphaSize; *totalSize = *redSize + *greenSize + *blueSize + *alphaSize;
TRACE("Returning red: %d, green: %d, blue: %d, alpha: %d, total: %d for fmt=%s\n", *redSize, *greenSize, *blueSize, *alphaSize, *totalSize, debug_d3dformat(fmt)); TRACE("Returning red: %d, green: %d, blue: %d, alpha: %d, total: %d for fmt=%s\n",
*redSize, *greenSize, *blueSize, *alphaSize, *totalSize, debug_d3dformat(format_desc->format));
return TRUE; return TRUE;
} }
/* Helper function for retrieving depth/stencil info for ChoosePixelFormat and wglChoosePixelFormatARB */ /* Helper function for retrieving depth/stencil info for ChoosePixelFormat and wglChoosePixelFormatARB */
BOOL getDepthStencilBits(const WineD3D_GL_Info *gl_info, WINED3DFORMAT fmt, short *depthSize, short *stencilSize) BOOL getDepthStencilBits(const struct GlPixelFormatDesc *format_desc, short *depthSize, short *stencilSize)
{ {
const struct GlPixelFormatDesc *format_desc; TRACE("fmt: %s\n", debug_d3dformat(format_desc->format));
switch(format_desc->format)
TRACE("fmt: %s\n", debug_d3dformat(fmt));
switch(fmt)
{ {
case WINED3DFMT_D16_LOCKABLE: case WINED3DFMT_D16_LOCKABLE:
case WINED3DFMT_D16_UNORM: case WINED3DFMT_D16_UNORM:
@ -1633,20 +1624,15 @@ BOOL getDepthStencilBits(const WineD3D_GL_Info *gl_info, WINED3DFORMAT fmt, shor
case WINED3DFMT_D32F_LOCKABLE: case WINED3DFMT_D32F_LOCKABLE:
break; break;
default: default:
FIXME("Unsupported stencil format: %s\n", debug_d3dformat(fmt)); FIXME("Unsupported stencil format: %s\n", debug_d3dformat(format_desc->format));
return FALSE; return FALSE;
} }
format_desc = getFormatDescEntry(fmt, gl_info);
if (!format_desc)
{
ERR("Unable to look up format: 0x%x\n", fmt);
return FALSE;
}
*depthSize = format_desc->depth_size; *depthSize = format_desc->depth_size;
*stencilSize = format_desc->stencil_size; *stencilSize = format_desc->stencil_size;
TRACE("Returning depthSize: %d and stencilSize: %d for fmt=%s\n", *depthSize, *stencilSize, debug_d3dformat(fmt)); TRACE("Returning depthSize: %d and stencilSize: %d for fmt=%s\n",
*depthSize, *stencilSize, debug_d3dformat(format_desc->format));
return TRUE; return TRUE;
} }

View File

@ -2090,9 +2090,9 @@ void surface_set_compatible_renderbuffer(IWineD3DSurface *iface, unsigned int wi
void surface_set_texture_name(IWineD3DSurface *iface, GLuint name, BOOL srgb_name); void surface_set_texture_name(IWineD3DSurface *iface, GLuint name, BOOL srgb_name);
void surface_set_texture_target(IWineD3DSurface *iface, GLenum target); void surface_set_texture_target(IWineD3DSurface *iface, GLenum target);
BOOL getColorBits(const WineD3D_GL_Info *gl_info, WINED3DFORMAT fmt, BOOL getColorBits(const struct GlPixelFormatDesc *format_desc,
short *redSize, short *greenSize, short *blueSize, short *alphaSize, short *totalSize); short *redSize, short *greenSize, short *blueSize, short *alphaSize, short *totalSize);
BOOL getDepthStencilBits(const WineD3D_GL_Info *gl_info, WINED3DFORMAT fmt, short *depthSize, short *stencilSize); BOOL getDepthStencilBits(const struct GlPixelFormatDesc *format_desc, short *depthSize, short *stencilSize);
/* Math utils */ /* Math utils */
void multiply_matrix(WINED3DMATRIX *dest, const WINED3DMATRIX *src1, const WINED3DMATRIX *src2); void multiply_matrix(WINED3DMATRIX *dest, const WINED3DMATRIX *src1, const WINED3DMATRIX *src2);