1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-06-30 12:14:08 +03:00

0022779: Pixel format should be chosen to support stencil buffer

This commit is contained in:
AGV 2011-10-28 13:49:20 +00:00 committed by bugmaster
parent 6dfe1db18d
commit f7ae443ad8

View File

@ -199,7 +199,7 @@ __declspec( dllexport ) int __fastcall __OpenGl_INIT__ (
{ {
XVisualInfo aVisInfo; XVisualInfo aVisInfo;
int aNbItems; int aNbItems;
int isGl, isDoubleBuffer, isRGBA, aDepthSize; int isGl, isDoubleBuffer, isRGBA, aDepthSize, aStencilSize;
unsigned long aVisInfoMask = VisualIDMask | VisualScreenMask; unsigned long aVisInfoMask = VisualIDMask | VisualScreenMask;
aVisInfo.visualid = wattr.visual->visualid; aVisInfo.visualid = wattr.visual->visualid;
aVisInfo.screen = DefaultScreen (disp); aVisInfo.screen = DefaultScreen (disp);
@ -219,7 +219,11 @@ __declspec( dllexport ) int __fastcall __OpenGl_INIT__ (
if (glXGetConfig (disp, vis, GLX_DEPTH_SIZE, &aDepthSize) != 0) if (glXGetConfig (disp, vis, GLX_DEPTH_SIZE, &aDepthSize) != 0)
aDepthSize = 0; aDepthSize = 0;
if (!isGl || !aDepthSize || !isRGBA || isDoubleBuffer != DBuffer) if (glXGetConfig (disp, vis, GLX_STENCIL_SIZE, &aStencilSize) != 0)
aStencilSize = 0;
if (!isGl || !aDepthSize || !aStencilSize ||
!isRGBA || isDoubleBuffer != DBuffer)
{ {
XFree (vis); XFree (vis);
vis = NULL; vis = NULL;
@ -231,12 +235,15 @@ __declspec( dllexport ) int __fastcall __OpenGl_INIT__ (
if (vis == NULL) if (vis == 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;
@ -990,12 +997,14 @@ __declspec( dllexport ) int __fastcall __OpenGl_INIT__ (
{ {
int iPixelFormat = 0; int iPixelFormat = 0;
int iGood = 0; int iGood = 0;
int i, j; int i, j, k;
PIXELFORMATDESCRIPTOR pfd0; PIXELFORMATDESCRIPTOR pfd0;
char string[ CALL_DEF_STRING_LENGTH ]; char string[ CALL_DEF_STRING_LENGTH ];
BOOL DBuffer = TRUE; BOOL DBuffer = TRUE;
const int sBits[] = { 8, 1 };
const int cBits[] = { 32, 24 }; const int cBits[] = { 32, 24 };
const int dBits[] = { 32, 24, 16 }; const int dBits[] = { 32, 24, 16 };
int goodBits[3] = { 0, 0, 0 };
if (call_util_osd_getenv ("CALL_OPENGL_NO_DBF", if (call_util_osd_getenv ("CALL_OPENGL_NO_DBF",
string, CALL_DEF_STRING_LENGTH)) string, CALL_DEF_STRING_LENGTH))
@ -1028,7 +1037,17 @@ __declspec( dllexport ) int __fastcall __OpenGl_INIT__ (
pfd0.dwDamageMask = 0; pfd0.dwDamageMask = 0;
hte -> nUsed = 1; hte -> nUsed = 1;
/*
This loop tries to find the pixel format with parameters not worse
than given in sBits, cBits, dBits, giving the priority to color bits
then depth bits, with stencil bits having the lowest priority.
If the needed combination is not found then the iGood value is used, it
is rememebered during the loop as the best ever found combination.
*/
for (k = 0; k < sizeof(sBits) / sizeof(int); k++) {
pfd0.cStencilBits = sBits[k];
for (i = 0; i < sizeof(dBits) / sizeof(int); i++) { for (i = 0; i < sizeof(dBits) / sizeof(int); i++) {
pfd0.cDepthBits = dBits[i]; pfd0.cDepthBits = dBits[i];
@ -1041,17 +1060,38 @@ __declspec( dllexport ) int __fastcall __OpenGl_INIT__ (
if (iPixelFormat) { if (iPixelFormat) {
pfd->cDepthBits = 0; pfd->cDepthBits = 0;
pfd->cColorBits = 0; pfd->cColorBits = 0;
pfd->cStencilBits = 0;
DescribePixelFormat (hte -> hDC, iPixelFormat, DescribePixelFormat (hte -> hDC, iPixelFormat,
sizeof ( PIXELFORMATDESCRIPTOR ), pfd); sizeof ( PIXELFORMATDESCRIPTOR ), pfd);
if (pfd->cColorBits >= cBits[j] && pfd->cDepthBits >= dBits[i]) if (pfd->cColorBits >= cBits[j] &&
break; pfd->cDepthBits >= dBits[i] &&
if (iGood == 0) pfd->cStencilBits >= sBits[k])
break; /* found - stop the lookup immediately */
if (pfd->cColorBits > goodBits[0]) {
goodBits[0] = pfd->cColorBits;
goodBits[1] = pfd->cDepthBits;
goodBits[2] = pfd->cStencilBits;
iGood = iPixelFormat;
} else if (pfd->cColorBits == goodBits[0]) {
if (pfd->cDepthBits > goodBits[1]) {
goodBits[1] = pfd->cDepthBits;
goodBits[2] = pfd->cStencilBits;
iGood = iPixelFormat;
} else if (pfd->cDepthBits == goodBits[1]) {
if (pfd->cStencilBits > goodBits[2]) {
goodBits[2] = pfd->cStencilBits;
iGood = iPixelFormat; iGood = iPixelFormat;
} }
} }
}
}
}
if (j < sizeof(cBits) / sizeof(int)) if (j < sizeof(cBits) / sizeof(int))
break; break;
} }
if (i < sizeof(dBits) / sizeof(int))
break;
}
if ( !iPixelFormat ) if ( !iPixelFormat )
iPixelFormat = iGood; iPixelFormat = iGood;