wined3d: Pass format_desc to getColorBits() and getDepthStencilBits().
This commit is contained in:
parent
a02d801888
commit
dd1f0d9c48
|
@ -446,7 +446,9 @@ static WineD3DContext *AddContextToArray(IWineD3DDeviceImpl *This, HWND win_hand
|
|||
}
|
||||
|
||||
/* 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;
|
||||
unsigned int matchtry;
|
||||
|
@ -477,11 +479,13 @@ static int WineD3D_ChoosePixelFormat(IWineD3DDeviceImpl *This, HDC hdc, WINED3DF
|
|||
int nCfgs = This->adapter->nCfgs;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
* 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. */
|
||||
if(DepthStencilFormat != WINED3DFMT_D24S8)
|
||||
if (ds_format_desc->format != WINED3DFMT_D24S8)
|
||||
{
|
||||
FIXME("Add OpenGL context recreation support to SetDepthStencilSurface\n");
|
||||
|
||||
DepthStencilFormat = WINED3DFMT_D24S8;
|
||||
|
||||
if(DepthStencilFormat) {
|
||||
getDepthStencilBits(&This->adapter->gl_info, DepthStencilFormat, &depthBits, &stencilBits);
|
||||
ds_format_desc = getFormatDescEntry(WINED3DFMT_D24S8, &This->adapter->gl_info);
|
||||
}
|
||||
|
||||
getDepthStencilBits(ds_format_desc, &depthBits, &stencilBits);
|
||||
|
||||
for(matchtry = 0; matchtry < (sizeof(matches) / sizeof(matches[0])) && !iPixelFormat; matchtry++) {
|
||||
for(i=0; i<nCfgs; i++) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -646,20 +650,21 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar
|
|||
int iPixelFormat = 0;
|
||||
|
||||
IWineD3DSurface *StencilSurface = This->stencilBufferTarget;
|
||||
WINED3DFORMAT StencilBufferFormat = StencilSurface ?
|
||||
((IWineD3DSurfaceImpl *)StencilSurface)->resource.format_desc->format : 0;
|
||||
const struct GlPixelFormatDesc *ds_format_desc = StencilSurface
|
||||
? ((IWineD3DSurfaceImpl *)StencilSurface)->resource.format_desc
|
||||
: getFormatDescEntry(WINED3DFMT_UNKNOWN, &This->adapter->gl_info);
|
||||
|
||||
/* Try to find a pixel format with pbuffer support. */
|
||||
iPixelFormat = WineD3D_ChoosePixelFormat(This, hdc_parent, target->resource.format_desc->format,
|
||||
StencilBufferFormat, FALSE /* auxBuffers */, 0 /* numSamples */, TRUE /* PBUFFER */,
|
||||
iPixelFormat = WineD3D_ChoosePixelFormat(This, hdc_parent, target->resource.format_desc,
|
||||
ds_format_desc, FALSE /* auxBuffers */, 0 /* numSamples */, TRUE /* PBUFFER */,
|
||||
FALSE /* findCompatible */);
|
||||
if(!iPixelFormat) {
|
||||
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.
|
||||
* A reason for failure could have been wglChoosePixelFormatARB strictness. */
|
||||
iPixelFormat = WineD3D_ChoosePixelFormat(This, hdc_parent, target->resource.format_desc->format,
|
||||
StencilBufferFormat, FALSE /* auxBuffer */, 0 /* numSamples */, TRUE /* PBUFFER */,
|
||||
iPixelFormat = WineD3D_ChoosePixelFormat(This, hdc_parent, target->resource.format_desc,
|
||||
ds_format_desc, FALSE /* auxBuffer */, 0 /* numSamples */, TRUE /* PBUFFER */,
|
||||
TRUE /* findCompatible */);
|
||||
}
|
||||
|
||||
|
@ -691,8 +696,9 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar
|
|||
PIXELFORMATDESCRIPTOR pfd;
|
||||
int iPixelFormat;
|
||||
int res;
|
||||
WINED3DFORMAT ColorFormat = target->resource.format_desc->format;
|
||||
WINED3DFORMAT DepthStencilFormat = 0;
|
||||
const struct GlPixelFormatDesc *color_format_desc = target->resource.format_desc;
|
||||
const struct GlPixelFormatDesc *ds_format_desc = getFormatDescEntry(WINED3DFMT_UNKNOWN,
|
||||
&This->adapter->gl_info);
|
||||
BOOL auxBuffers = FALSE;
|
||||
int numSamples = 0;
|
||||
|
||||
|
@ -706,25 +712,25 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar
|
|||
if(wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER) {
|
||||
auxBuffers = TRUE;
|
||||
|
||||
if (target->resource.format_desc->format == WINED3DFMT_X4R4G4B4)
|
||||
ColorFormat = WINED3DFMT_A4R4G4B4;
|
||||
else if(target->resource.format_desc->format == WINED3DFMT_X8R8G8B8)
|
||||
ColorFormat = WINED3DFMT_A8R8G8B8;
|
||||
if (color_format_desc->format == WINED3DFMT_X4R4G4B4)
|
||||
color_format_desc = getFormatDescEntry(WINED3DFMT_A4R4G4B4, &This->adapter->gl_info);
|
||||
else if (color_format_desc->format == WINED3DFMT_X8R8G8B8)
|
||||
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.
|
||||
* 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
|
||||
* a format with 8bit alpha, so request A8R8G8B8. */
|
||||
if(ColorFormat == WINED3DFMT_P8)
|
||||
ColorFormat = WINED3DFMT_A8R8G8B8;
|
||||
if (color_format_desc->format == WINED3DFMT_P8)
|
||||
color_format_desc = getFormatDescEntry(WINED3DFMT_A8R8G8B8, &This->adapter->gl_info);
|
||||
|
||||
/* Retrieve the depth stencil format from the present parameters.
|
||||
* The choice of the proper format can give a nice performance boost
|
||||
* in case of GPU limited programs. */
|
||||
if(pPresentParms->EnableAutoDepthStencil) {
|
||||
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 */
|
||||
|
@ -738,12 +744,14 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar
|
|||
}
|
||||
|
||||
/* 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 */
|
||||
if(!iPixelFormat) {
|
||||
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 */
|
||||
|
|
|
@ -1722,7 +1722,7 @@ static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(const WineD3D_GL_I
|
|||
return FALSE;
|
||||
|
||||
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));
|
||||
return FALSE;
|
||||
|
@ -1771,7 +1771,7 @@ static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(const WineD3D_GL_In
|
|||
if(!cfg)
|
||||
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));
|
||||
return FALSE;
|
||||
|
@ -1898,7 +1898,7 @@ static HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, U
|
|||
int i, nCfgs;
|
||||
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);
|
||||
return WINED3DERR_NOTAVAILABLE;
|
||||
|
@ -2090,10 +2090,8 @@ static BOOL CheckRenderTargetCapability(struct WineD3DAdapter *adapter,
|
|||
short AdapterRed, AdapterGreen, AdapterBlue, AdapterAlpha, AdapterTotalSize;
|
||||
short CheckRed, CheckGreen, CheckBlue, CheckAlpha, CheckTotalSize;
|
||||
|
||||
getColorBits(&adapter->gl_info, adapter_format_desc->format,
|
||||
&AdapterRed, &AdapterGreen, &AdapterBlue, &AdapterAlpha, &AdapterTotalSize);
|
||||
getColorBits(&adapter->gl_info, check_format_desc->format,
|
||||
&CheckRed, &CheckGreen, &CheckBlue, &CheckAlpha, &CheckTotalSize);
|
||||
getColorBits(adapter_format_desc, &AdapterRed, &AdapterGreen, &AdapterBlue, &AdapterAlpha, &AdapterTotalSize);
|
||||
getColorBits(check_format_desc, &CheckRed, &CheckGreen, &CheckBlue, &CheckAlpha, &CheckTotalSize);
|
||||
|
||||
/* 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) */
|
||||
|
|
|
@ -1571,13 +1571,11 @@ unsigned int count_bits(unsigned int mask)
|
|||
|
||||
/* Helper function for retrieving color info for ChoosePixelFormat and wglChoosePixelFormatARB.
|
||||
* 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)
|
||||
{
|
||||
const struct GlPixelFormatDesc *format_desc;
|
||||
|
||||
TRACE("fmt: %s\n", debug_d3dformat(fmt));
|
||||
switch(fmt)
|
||||
TRACE("fmt: %s\n", debug_d3dformat(format_desc->format));
|
||||
switch(format_desc->format)
|
||||
{
|
||||
case WINED3DFMT_X8R8G8B8:
|
||||
case WINED3DFMT_R8G8B8:
|
||||
|
@ -1594,33 +1592,26 @@ BOOL getColorBits(const WineD3D_GL_Info *gl_info, WINED3DFORMAT fmt,
|
|||
case WINED3DFMT_P8:
|
||||
break;
|
||||
default:
|
||||
ERR("Unsupported format: %s\n", debug_d3dformat(fmt));
|
||||
ERR("Unsupported format: %s\n", debug_d3dformat(format_desc->format));
|
||||
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);
|
||||
*greenSize = count_bits(format_desc->green_mask);
|
||||
*blueSize = count_bits(format_desc->blue_mask);
|
||||
*alphaSize = count_bits(format_desc->alpha_mask);
|
||||
*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;
|
||||
}
|
||||
|
||||
/* 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(fmt));
|
||||
switch(fmt)
|
||||
TRACE("fmt: %s\n", debug_d3dformat(format_desc->format));
|
||||
switch(format_desc->format)
|
||||
{
|
||||
case WINED3DFMT_D16_LOCKABLE:
|
||||
case WINED3DFMT_D16_UNORM:
|
||||
|
@ -1633,20 +1624,15 @@ BOOL getDepthStencilBits(const WineD3D_GL_Info *gl_info, WINED3DFORMAT fmt, shor
|
|||
case WINED3DFMT_D32F_LOCKABLE:
|
||||
break;
|
||||
default:
|
||||
FIXME("Unsupported stencil format: %s\n", debug_d3dformat(fmt));
|
||||
FIXME("Unsupported stencil format: %s\n", debug_d3dformat(format_desc->format));
|
||||
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;
|
||||
*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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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_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);
|
||||
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 */
|
||||
void multiply_matrix(WINED3DMATRIX *dest, const WINED3DMATRIX *src1, const WINED3DMATRIX *src2);
|
||||
|
|
Loading…
Reference in New Issue