From 4aa59c3df6c324a6e6f9d540eac25e88b9c28acd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 27 Apr 2008 12:46:28 +0000 Subject: [PATCH] no real changes, clarified the usage of WX_GL_DOUBLEBUFFER; documented it and other WX_GL_XXX constants lost during doxygen transition; simplified wxMSW code a bit git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53379 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/glcanvas.h | 38 ++++++++++---------- interface/glcanvas.h | 83 ++++++++++++++++++++++++++++++++++++++----- src/msw/glcanvas.cpp | 56 ++++++++++++++++------------- 3 files changed, 124 insertions(+), 53 deletions(-) diff --git a/include/wx/glcanvas.h b/include/wx/glcanvas.h index e02657cc96..a7043a70d8 100644 --- a/include/wx/glcanvas.h +++ b/include/wx/glcanvas.h @@ -27,27 +27,27 @@ class WXDLLIMPEXP_FWD_GL wxGLContext; // Constants for attributes list // ---------------------------------------------------------------------------- -// The generic OpenGL implementation doesn't support most of these options, -// such as stereo, auxiliary buffers, alpha channel, and accumulator buffer. -// Other implementations may actually support them. +// Notice that not all implementation support options such as stereo, auxiliary +// buffers, alpha channel, and accumulator buffer, use IsDisplaySupported() to +// check for individual attributes support. enum { - WX_GL_RGBA=1, /* use true color palette */ - WX_GL_BUFFER_SIZE, /* bits for buffer if not WX_GL_RGBA */ - WX_GL_LEVEL, /* 0 for main buffer, >0 for overlay, <0 for underlay */ - WX_GL_DOUBLEBUFFER, /* use doublebuffer */ - WX_GL_STEREO, /* use stereoscopic display */ - WX_GL_AUX_BUFFERS, /* number of auxiliary buffers */ - WX_GL_MIN_RED, /* use red buffer with most bits (> MIN_RED bits) */ - WX_GL_MIN_GREEN, /* use green buffer with most bits (> MIN_GREEN bits) */ - WX_GL_MIN_BLUE, /* use blue buffer with most bits (> MIN_BLUE bits) */ - WX_GL_MIN_ALPHA, /* use alpha buffer with most bits (> MIN_ALPHA bits) */ - WX_GL_DEPTH_SIZE, /* bits for Z-buffer (0,16,32) */ - WX_GL_STENCIL_SIZE, /* bits for stencil buffer */ - WX_GL_MIN_ACCUM_RED, /* use red accum buffer with most bits (> MIN_ACCUM_RED bits) */ - WX_GL_MIN_ACCUM_GREEN, /* use green buffer with most bits (> MIN_ACCUM_GREEN bits) */ - WX_GL_MIN_ACCUM_BLUE, /* use blue buffer with most bits (> MIN_ACCUM_BLUE bits) */ - WX_GL_MIN_ACCUM_ALPHA /* use alpha buffer with most bits (> MIN_ACCUM_ALPHA bits) */ + WX_GL_RGBA = 1, // use true color palette (on if no attrs specified) + WX_GL_BUFFER_SIZE, // bits for buffer if not WX_GL_RGBA + WX_GL_LEVEL, // 0 for main buffer, >0 for overlay, <0 for underlay + WX_GL_DOUBLEBUFFER, // use double buffering (on if no attrs specified) + WX_GL_STEREO, // use stereoscopic display + WX_GL_AUX_BUFFERS, // number of auxiliary buffers + WX_GL_MIN_RED, // use red buffer with most bits (> MIN_RED bits) + WX_GL_MIN_GREEN, // use green buffer with most bits (> MIN_GREEN bits) + WX_GL_MIN_BLUE, // use blue buffer with most bits (> MIN_BLUE bits) + WX_GL_MIN_ALPHA, // use alpha buffer with most bits (> MIN_ALPHA bits) + WX_GL_DEPTH_SIZE, // bits for Z-buffer (0,16,32) + WX_GL_STENCIL_SIZE, // bits for stencil buffer + WX_GL_MIN_ACCUM_RED, // use red accum buffer with most bits (> MIN_ACCUM_RED bits) + WX_GL_MIN_ACCUM_GREEN, // use green buffer with most bits (> MIN_ACCUM_GREEN bits) + WX_GL_MIN_ACCUM_BLUE, // use blue buffer with most bits (> MIN_ACCUM_BLUE bits) + WX_GL_MIN_ACCUM_ALPHA // use alpha buffer with most bits (> MIN_ACCUM_ALPHA bits) }; #define wxGLCanvasName _T("GLCanvas") diff --git a/interface/glcanvas.h b/interface/glcanvas.h index 84e4847348..89fcd6da94 100644 --- a/interface/glcanvas.h +++ b/interface/glcanvas.h @@ -71,7 +71,64 @@ public: void SetCurrent(const wxGLCanvas& win); }; +/** + Constants for use with wxGLCanvas. + + Notice that not all implementation support options such as stereo, + auxiliary buffers, alpha channel, and accumulator buffer, use + wxGLCanvas::IsDisplaySupported() to check for individual attributes support. + */ +enum +{ + /// Use true color palette (on if no attributes at all specified). + WX_GL_RGBA = 1, + + /// Specifies the number of bits for buffer if not WX_GL_RGBA. + WX_GL_BUFFER_SIZE, + + /// Must be followed by 0 for main buffer, >0 for overlay, <0 for underlay. + WX_GL_LEVEL, + + /// Use double buffering if present (on if no attributes specified). + WX_GL_DOUBLEBUFFER, + + /// Use stereoscopic display. + WX_GL_STEREO, + + /// Specifies number of auxiliary buffers. + WX_GL_AUX_BUFFERS, + + /// Use red buffer with most bits (> MIN_RED bits) + WX_GL_MIN_RED, + + /// Use green buffer with most bits (> MIN_GREEN bits) + WX_GL_MIN_GREEN, + /// Use blue buffer with most bits (> MIN_BLUE bits) + WX_GL_MIN_BLUE, + + /// Use alpha buffer with most bits (> MIN_ALPHA bits) + WX_GL_MIN_ALPHA, + + /// Specifies number of bits for Z-buffer (typically 0, 16 or 32). + WX_GL_DEPTH_SIZE, + + /// Specifies number of bits for stencil buffer. + WX_GL_STENCIL_SIZE, + + /// Specifies minimal number of red accumulator bits. + WX_GL_MIN_ACCUM_RED, + + /// Specifies minimal number of green accumulator bits. + WX_GL_MIN_ACCUM_GREEN, + + /// Specifies minimal number of blue accumulator bits. + WX_GL_MIN_ACCUM_BLUE, + + /// Specifies minimal number of alpha accumulator bits. + WX_GL_MIN_ACCUM_ALPHA + +}; /** @class wxGLCanvas @@ -141,15 +198,23 @@ public: @param name Window name. @param attribList - Array of integers. With this parameter you can set the device context - attributes associated to this window. - This array is zero-terminated: it should be set up with constants described - in the table above. - If a constant should be followed by a value, put it in the next array - position. - For example, the WX_GL_DEPTH_SIZE should be followed by the value that - indicates the number of - bits for the depth buffer, so: + Array of integers. With this parameter you can set the device + context attributes associated to this window. This array is + zero-terminated: it should be set up with constants described in + the table above. If a constant should be followed by a value, put + it in the next array position. For example, the WX_GL_DEPTH_SIZE + should be followed by the value that indicates the number of bits + for the depth buffer, e.g: + @code + attribList[n++] = WX_GL_DEPTH_SIZE; + attribList[n++] = 32; + attribList[n] = 0; // terminate the list + @endcode + If the attribute list is not specified at all, i.e. if this + parameter is @NULL, the default attributes including @c WX_GL_RGBA + and @c WX_GL_DOUBLEBUFFER are used. But notice that if you do + specify some attributes you also need to explicitly include these + two default attributes in the list if you need them. @param palette Palette for indexed colour (i.e. non WX_GL_RGBA) mode. Ignored under most platforms. diff --git a/src/msw/glcanvas.cpp b/src/msw/glcanvas.cpp index 7355383805..cefcac96a9 100644 --- a/src/msw/glcanvas.cpp +++ b/src/msw/glcanvas.cpp @@ -332,21 +332,22 @@ AdjustPFDForAttributes(PIXELFORMATDESCRIPTOR& pfd, const int *attribList) if ( !attribList ) return; + // remove default attributes pfd.dwFlags &= ~PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_COLORINDEX; - pfd.cColorBits = 0; - int arg=0; - while ( attribList[arg] ) + for ( int arg = 0; attribList[arg]; ) { switch ( attribList[arg++] ) { case WX_GL_RGBA: pfd.iPixelType = PFD_TYPE_RGBA; break; + case WX_GL_BUFFER_SIZE: pfd.cColorBits = attribList[arg++]; break; + case WX_GL_LEVEL: // this member looks like it may be obsolete if ( attribList[arg] > 0 ) @@ -357,52 +358,58 @@ AdjustPFDForAttributes(PIXELFORMATDESCRIPTOR& pfd, const int *attribList) pfd.iLayerType = PFD_MAIN_PLANE; arg++; break; + case WX_GL_DOUBLEBUFFER: pfd.dwFlags |= PFD_DOUBLEBUFFER; break; + case WX_GL_STEREO: pfd.dwFlags |= PFD_STEREO; break; + case WX_GL_AUX_BUFFERS: pfd.cAuxBuffers = attribList[arg++]; break; + case WX_GL_MIN_RED: - pfd.cColorBits = (pfd.cColorBits + - (pfd.cRedBits = attribList[arg++])); + pfd.cColorBits += (pfd.cRedBits = attribList[arg++]); break; + case WX_GL_MIN_GREEN: - pfd.cColorBits = (pfd.cColorBits + - (pfd.cGreenBits = attribList[arg++])); + pfd.cColorBits += (pfd.cGreenBits = attribList[arg++]); break; + case WX_GL_MIN_BLUE: - pfd.cColorBits = (pfd.cColorBits + - (pfd.cBlueBits = attribList[arg++])); + pfd.cColorBits += (pfd.cBlueBits = attribList[arg++]); break; + case WX_GL_MIN_ALPHA: // doesn't count in cColorBits pfd.cAlphaBits = attribList[arg++]; break; + case WX_GL_DEPTH_SIZE: pfd.cDepthBits = attribList[arg++]; break; + case WX_GL_STENCIL_SIZE: pfd.cStencilBits = attribList[arg++]; break; + case WX_GL_MIN_ACCUM_RED: - pfd.cAccumBits = (pfd.cAccumBits + - (pfd.cAccumRedBits = attribList[arg++])); + pfd.cAccumBits += (pfd.cAccumRedBits = attribList[arg++]); break; + case WX_GL_MIN_ACCUM_GREEN: - pfd.cAccumBits = (pfd.cAccumBits + - (pfd.cAccumGreenBits = attribList[arg++])); + pfd.cAccumBits += (pfd.cAccumGreenBits = attribList[arg++]); break; + case WX_GL_MIN_ACCUM_BLUE: - pfd.cAccumBits = (pfd.cAccumBits + - (pfd.cAccumBlueBits = attribList[arg++])); + pfd.cAccumBits += (pfd.cAccumBlueBits = attribList[arg++]); break; + case WX_GL_MIN_ACCUM_ALPHA: - pfd.cAccumBits = (pfd.cAccumBits + - (pfd.cAccumAlphaBits = attribList[arg++])); + pfd.cAccumBits += (pfd.cAccumAlphaBits = attribList[arg++]); break; } } @@ -421,14 +428,13 @@ wxGLCanvas::ChooseMatchingPixelFormat(HDC hdc, 1, // version PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | - PFD_DOUBLEBUFFER, // support double-buffering - PFD_TYPE_RGBA, // color type - 16, // preferred color depth - 0, 0, 0, 0, 0, 0, // color bits (ignored) - 0, // no alpha buffer - 0, // alpha bits (ignored) - 0, // no accumulation buffer - 0, 0, 0, 0, // accumulator bits (ignored) + PFD_DOUBLEBUFFER, // use double-buffering by default + PFD_TYPE_RGBA, // default pixel type + 0, // preferred color depth (don't care) + 0, 0, 0, 0, 0, 0, // color bits and shift bits (ignored) + 0, 0, // alpha bits and shift (ignored) + 0, // accumulation total bits + 0, 0, 0, 0, // accumulator RGBA bits (not used) 16, // depth buffer 0, // no stencil buffer 0, // no auxiliary buffers -- 2.45.2