mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-06-05 11:24:17 +03:00
0022779: Pixel format should be chosen to support stencil buffer
Missing code in find_pixel_format() function was restored. Coding rules applied Added changes in GLX part
This commit is contained in:
parent
9edc5e12b6
commit
3d8969b13b
@ -38,49 +38,89 @@ namespace
|
|||||||
static const TEL_COLOUR THE_DEFAULT_BG_COLOR = { { 0.F, 0.F, 0.F, 1.F } };
|
static const TEL_COLOUR THE_DEFAULT_BG_COLOR = { { 0.F, 0.F, 0.F, 1.F } };
|
||||||
|
|
||||||
#if (defined(_WIN32) || defined(__WIN32__))
|
#if (defined(_WIN32) || defined(__WIN32__))
|
||||||
static int find_pixel_format (HDC hDC, PIXELFORMATDESCRIPTOR* pfd, const Standard_Boolean dbuff)
|
static int find_pixel_format (HDC theDevCtx,
|
||||||
|
PIXELFORMATDESCRIPTOR& thePixelFrmt,
|
||||||
|
const Standard_Boolean theIsDoubleBuff)
|
||||||
{
|
{
|
||||||
PIXELFORMATDESCRIPTOR pfd0;
|
PIXELFORMATDESCRIPTOR aPixelFrmtTmp;
|
||||||
memset (&pfd0, 0, sizeof (PIXELFORMATDESCRIPTOR));
|
memset (&aPixelFrmtTmp, 0, sizeof (PIXELFORMATDESCRIPTOR));
|
||||||
pfd0.nSize = sizeof (PIXELFORMATDESCRIPTOR);
|
aPixelFrmtTmp.nSize = sizeof (PIXELFORMATDESCRIPTOR);
|
||||||
pfd0.nVersion = 1;
|
aPixelFrmtTmp.nVersion = 1;
|
||||||
pfd0.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | (dbuff ? PFD_DOUBLEBUFFER : PFD_SUPPORT_GDI);
|
aPixelFrmtTmp.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | (theIsDoubleBuff ? PFD_DOUBLEBUFFER : PFD_SUPPORT_GDI);
|
||||||
pfd0.iPixelType = PFD_TYPE_RGBA;
|
aPixelFrmtTmp.iPixelType = PFD_TYPE_RGBA;
|
||||||
pfd0.iLayerType = PFD_MAIN_PLANE;
|
aPixelFrmtTmp.iLayerType = PFD_MAIN_PLANE;
|
||||||
|
|
||||||
int iPixelFormat = 0;
|
const int BUFF_BITS_STENCIL[] = { 8, 1 };
|
||||||
int iGood = 0;
|
const int BUFF_BITS_COLOR[] = { 32, 24 };
|
||||||
const int cBits[] = { 32, 24 };
|
const int BUFF_BITS_DEPTH[] = { 32, 24, 16 };
|
||||||
const int dBits[] = { 32, 24, 16 };
|
|
||||||
|
|
||||||
int i, j;
|
int aGoodBits[] = { 0, 0, 0 };
|
||||||
for (i = 0; i < sizeof(dBits) / sizeof(int); i++)
|
int aPixelFrmtIdLast = 0;
|
||||||
|
int aPixelFrmtIdGood = 0;
|
||||||
|
Standard_Size aStencilIter = 0, aColorIter = 0, aDepthIter = 0;
|
||||||
|
for (aStencilIter = 0; aStencilIter < sizeof(BUFF_BITS_STENCIL) / sizeof(int); ++aStencilIter)
|
||||||
{
|
{
|
||||||
pfd0.cDepthBits = dBits[i];
|
aPixelFrmtTmp.cStencilBits = BUFF_BITS_STENCIL[aStencilIter];
|
||||||
iGood = 0;
|
for (aDepthIter = 0; aDepthIter < sizeof(BUFF_BITS_DEPTH) / sizeof(int); ++aDepthIter)
|
||||||
for (j = 0; j < sizeof(cBits) / sizeof(int); j++)
|
|
||||||
{
|
{
|
||||||
pfd0.cColorBits = cBits[j];
|
aPixelFrmtTmp.cDepthBits = BUFF_BITS_DEPTH[aDepthIter];
|
||||||
iPixelFormat = ChoosePixelFormat (hDC, &pfd0);
|
aPixelFrmtIdGood = 0;
|
||||||
if (iPixelFormat)
|
for (aColorIter = 0; aColorIter < sizeof(BUFF_BITS_COLOR) / sizeof(int); ++aColorIter)
|
||||||
{
|
{
|
||||||
pfd->cDepthBits = 0;
|
aPixelFrmtTmp.cColorBits = BUFF_BITS_COLOR[aColorIter];
|
||||||
pfd->cColorBits = 0;
|
aPixelFrmtIdLast = ChoosePixelFormat (theDevCtx, &aPixelFrmtTmp);
|
||||||
DescribePixelFormat (hDC, iPixelFormat, sizeof (PIXELFORMATDESCRIPTOR), pfd);
|
if (aPixelFrmtIdLast == 0)
|
||||||
if (pfd->cColorBits >= cBits[j] && pfd->cDepthBits >= dBits[i])
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
thePixelFrmt.cDepthBits = 0;
|
||||||
|
thePixelFrmt.cColorBits = 0;
|
||||||
|
thePixelFrmt.cStencilBits = 0;
|
||||||
|
DescribePixelFormat (theDevCtx, aPixelFrmtIdLast, sizeof(PIXELFORMATDESCRIPTOR), &thePixelFrmt);
|
||||||
|
if (thePixelFrmt.cColorBits >= BUFF_BITS_COLOR[aColorIter]
|
||||||
|
&& thePixelFrmt.cDepthBits >= BUFF_BITS_DEPTH[aDepthIter]
|
||||||
|
&& thePixelFrmt.cStencilBits >= BUFF_BITS_STENCIL[aStencilIter])
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
if (iGood == 0)
|
}
|
||||||
iGood = iPixelFormat;
|
if (thePixelFrmt.cColorBits > aGoodBits[0])
|
||||||
|
{
|
||||||
|
aGoodBits[0] = thePixelFrmt.cColorBits;
|
||||||
|
aGoodBits[1] = thePixelFrmt.cDepthBits;
|
||||||
|
aGoodBits[2] = thePixelFrmt.cStencilBits;
|
||||||
|
aPixelFrmtIdGood = aPixelFrmtIdLast;
|
||||||
|
}
|
||||||
|
else if (thePixelFrmt.cColorBits == aGoodBits[0])
|
||||||
|
{
|
||||||
|
if (thePixelFrmt.cDepthBits > aGoodBits[1])
|
||||||
|
{
|
||||||
|
aGoodBits[1] = thePixelFrmt.cDepthBits;
|
||||||
|
aGoodBits[2] = thePixelFrmt.cStencilBits;
|
||||||
|
aPixelFrmtIdGood = aPixelFrmtIdLast;
|
||||||
|
}
|
||||||
|
else if (thePixelFrmt.cDepthBits == aGoodBits[1])
|
||||||
|
{
|
||||||
|
if(thePixelFrmt.cStencilBits > aGoodBits[2])
|
||||||
|
{
|
||||||
|
aGoodBits[2] = thePixelFrmt.cStencilBits;
|
||||||
|
aPixelFrmtIdGood = aPixelFrmtIdLast;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (aColorIter < sizeof(BUFF_BITS_COLOR) / sizeof(int))
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (j < sizeof(cBits) / sizeof(int))
|
if (aDepthIter < sizeof(BUFF_BITS_DEPTH) / sizeof(int))
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iPixelFormat == 0)
|
return (aPixelFrmtIdLast == 0) ? aPixelFrmtIdGood : aPixelFrmtIdLast;
|
||||||
iPixelFormat = iGood;
|
|
||||||
|
|
||||||
return iPixelFormat;
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static Bool WaitForNotify (Display* theDisp, XEvent* theEv, char* theArg)
|
static Bool WaitForNotify (Display* theDisp, XEvent* theEv, char* theArg)
|
||||||
@ -120,9 +160,9 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_Display)& theDisplay,
|
|||||||
HDC aWindowDC = GetDC (aWindow);
|
HDC aWindowDC = GetDC (aWindow);
|
||||||
HGLRC aGContext = (HGLRC )theGContext;
|
HGLRC aGContext = (HGLRC )theGContext;
|
||||||
|
|
||||||
PIXELFORMATDESCRIPTOR pfd;
|
PIXELFORMATDESCRIPTOR aPixelFrmt;
|
||||||
int iPixelFormat = find_pixel_format (aWindowDC, &pfd, myDisplay->DBuffer());
|
const int aPixelFrmtId = find_pixel_format (aWindowDC, aPixelFrmt, myDisplay->DBuffer());
|
||||||
if (iPixelFormat == 0)
|
if (aPixelFrmtId == 0)
|
||||||
{
|
{
|
||||||
ReleaseDC (aWindow, aWindowDC);
|
ReleaseDC (aWindow, aWindowDC);
|
||||||
|
|
||||||
@ -132,21 +172,25 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_Display)& theDisplay,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pfd.dwFlags & PFD_NEED_PALETTE)
|
if (aPixelFrmt.dwFlags & PFD_NEED_PALETTE)
|
||||||
{
|
{
|
||||||
WINDOW_DATA* wd = (WINDOW_DATA* )GetWindowLongPtr (aWindow, GWLP_USERDATA);
|
WINDOW_DATA* aWndData = (WINDOW_DATA* )GetWindowLongPtr (aWindow, GWLP_USERDATA);
|
||||||
|
|
||||||
mySysPalInUse = (pfd.dwFlags & PFD_NEED_SYSTEM_PALETTE) ? TRUE : FALSE;
|
mySysPalInUse = (aPixelFrmt.dwFlags & PFD_NEED_SYSTEM_PALETTE) ? TRUE : FALSE;
|
||||||
InterfaceGraphic_RealizePalette (aWindowDC, wd->hPal, FALSE, mySysPalInUse);
|
InterfaceGraphic_RealizePalette (aWindowDC, aWndData->hPal, FALSE, mySysPalInUse);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myDither)
|
if (myDither)
|
||||||
myDither = (pfd.cColorBits <= 8);
|
{
|
||||||
|
myDither = (aPixelFrmt.cColorBits <= 8);
|
||||||
|
}
|
||||||
|
|
||||||
if (myBackDither)
|
if (myBackDither)
|
||||||
myBackDither = (pfd.cColorBits <= 8);
|
{
|
||||||
|
myBackDither = (aPixelFrmt.cColorBits <= 8);
|
||||||
|
}
|
||||||
|
|
||||||
if (!SetPixelFormat (aWindowDC, iPixelFormat, &pfd))
|
if (!SetPixelFormat (aWindowDC, aPixelFrmtId, &aPixelFrmt))
|
||||||
{
|
{
|
||||||
ReleaseDC (aWindow, aWindowDC);
|
ReleaseDC (aWindow, aWindowDC);
|
||||||
|
|
||||||
@ -216,7 +260,7 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_Display)& theDisplay,
|
|||||||
if (aVis != NULL)
|
if (aVis != NULL)
|
||||||
{
|
{
|
||||||
// check Visual for OpenGl context's parameters compability
|
// check Visual for OpenGl context's parameters compability
|
||||||
int isGl = 0, isDoubleBuffer = 0, isRGBA = 0, aDepthSize = 0;
|
int isGl = 0, isDoubleBuffer = 0, isRGBA = 0, aDepthSize = 0, aStencilSize = 0;
|
||||||
|
|
||||||
if (glXGetConfig (aDisp, aVis, GLX_USE_GL, &isGl) != 0)
|
if (glXGetConfig (aDisp, aVis, GLX_USE_GL, &isGl) != 0)
|
||||||
isGl = 0;
|
isGl = 0;
|
||||||
@ -230,6 +274,9 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_Display)& theDisplay,
|
|||||||
if (glXGetConfig (aDisp, aVis, GLX_DEPTH_SIZE, &aDepthSize) != 0)
|
if (glXGetConfig (aDisp, aVis, GLX_DEPTH_SIZE, &aDepthSize) != 0)
|
||||||
aDepthSize = 0;
|
aDepthSize = 0;
|
||||||
|
|
||||||
|
if (glXGetConfig (aDisp, aVis, GLX_STENCIL_SIZE, &aStencilSize) != 0)
|
||||||
|
aStencilSize = 0;
|
||||||
|
|
||||||
if (!isGl || !aDepthSize || !isRGBA || (isDoubleBuffer ? 1 : 0) != (myDisplay->DBuffer()? 1 : 0))
|
if (!isGl || !aDepthSize || !isRGBA || (isDoubleBuffer ? 1 : 0) != (myDisplay->DBuffer()? 1 : 0))
|
||||||
{
|
{
|
||||||
XFree (aVis);
|
XFree (aVis);
|
||||||
@ -241,12 +288,15 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_Display)& theDisplay,
|
|||||||
if (aVis == NULL)
|
if (aVis == NULL)
|
||||||
{
|
{
|
||||||
int anIter = 0;
|
int anIter = 0;
|
||||||
int anAttribs[11];
|
int anAttribs[13];
|
||||||
anAttribs[anIter++] = GLX_RGBA;
|
anAttribs[anIter++] = GLX_RGBA;
|
||||||
|
|
||||||
anAttribs[anIter++] = GLX_DEPTH_SIZE;
|
anAttribs[anIter++] = GLX_DEPTH_SIZE;
|
||||||
anAttribs[anIter++] = 1;
|
anAttribs[anIter++] = 1;
|
||||||
|
|
||||||
|
anAttribs[anIter++] = GLX_STENCIL_SIZE;
|
||||||
|
anAttribs[anIter++] = 1;
|
||||||
|
|
||||||
anAttribs[anIter++] = GLX_RED_SIZE;
|
anAttribs[anIter++] = GLX_RED_SIZE;
|
||||||
anAttribs[anIter++] = (wattr.depth <= 8) ? 0 : 1;
|
anAttribs[anIter++] = (wattr.depth <= 8) ? 0 : 1;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user