#include #include #include #include #include #include #include #include "pbuffer.h" namespace osg { bool isWGLExtensionSupported(const char *extension); } // WGL_ARB_pbuffer static WGLCreatePBufferProc wglCreatePBuffer; static WGLGetPBufferDCProc wglGetPBufferDC; static WGLReleasePBufferDCProc wglReleasePBufferDC; static WGLDestroyPBufferProc wglDestroyPBuffer; static WGLQueryPBufferProc wglQueryPBuffer; // WGL_ARB_pixel_format static WGLGetPixelFormatAttribivProc wglGetPixelFormatAttribiv; static WGLGetPixelFormatAttribfvProc wglGetPixelFormatAttribfv; static WGLChoosePixelFormatProc wglChoosePixelFormat; // WGL_ARB_render_texture static WGLBindTexImageProc wglBindTexImage; static WGLReleaseTexImageProc wglReleaseTexImage; static WGLSetPbufferAttribProc wglSetPbufferAttrib; #ifdef _WIN32 #ifndef WGL_ARB_extensions_string #define WGL_ARB_extensions_string 1 typedef const char * (WINAPI * WGLGetExtensionsStringProc) (HDC hDC); #endif #endif #ifdef _WIN32 bool osg::isWGLExtensionSupported(const char *extension) { typedef std::set ExtensionSet; static ExtensionSet s_extensionSet; static const char* s_extensions = NULL; static WGLGetExtensionsStringProc wglGetExtensionsString = (WGLGetExtensionsStringProc)osg::getGLExtensionFuncPtr("wglGetExtensionsStringARB"); if (wglGetExtensionsString == NULL) return false; if (s_extensions==NULL) { // get the extension list from OpenGL. s_extensions = (const char*)wglGetExtensionsString(::wglGetCurrentDC()); if (s_extensions==NULL) return false; // insert the ' ' delimiated extensions words into the extensionSet. const char *startOfWord = s_extensions; const char *endOfWord; while ((endOfWord = strchr(startOfWord,' '))!=NULL) { s_extensionSet.insert(std::string(startOfWord,endOfWord)); startOfWord = endOfWord+1; } if (*startOfWord!=0) s_extensionSet.insert(std::string(startOfWord)); osg::notify(osg::INFO)<<"OpenGL extensions supported by installed OpenGL drivers are:"<~PBuffer(); initialize(); } } // This function actually does the creation of the p-buffer. // It can only be called once a window has already been created. void PBuffer::initialize() { setupGLExtenions(); HDC hdc = wglGetCurrentDC(); HGLRC hglrc = wglGetCurrentContext(); // Query for a suitable pixel format based on the specified mode. std::vector iattributes; std::vector fattributes; // P-buffer will be used with OpenGL iattributes.push_back(WGL_SUPPORT_OPENGL_ARB); iattributes.push_back(true); // Since we are trying to create a pbuffer, the pixel format we // request (and subsequently use) must be "p-buffer capable". iattributes.push_back(WGL_DRAW_TO_PBUFFER_ARB); iattributes.push_back(true); // Bind to texture iattributes.push_back(WGL_BIND_TO_TEXTURE_RGBA_ARB); iattributes.push_back(true); //iattributes.push_back(WGL_ACCELERATION_ARB); //iattributes.push_back(WGL_FULL_ACCELERATION_ARB); if (_RGB) { iattributes.push_back(WGL_PIXEL_TYPE_ARB); iattributes.push_back(WGL_TYPE_RGBA_ARB); // We require a minimum of 8-bits for each R, G, B, and A. iattributes.push_back(WGL_RED_BITS_ARB); iattributes.push_back(8); iattributes.push_back(WGL_GREEN_BITS_ARB); iattributes.push_back(8); iattributes.push_back(WGL_BLUE_BITS_ARB); iattributes.push_back(8); if (_minimumNumberAlphaBits > 0) { iattributes.push_back(WGL_ALPHA_BITS_ARB); iattributes.push_back(_minimumNumberAlphaBits); } } else { iattributes.push_back(WGL_PIXEL_TYPE_ARB); iattributes.push_back(WGL_TYPE_COLORINDEX_ARB); } iattributes.push_back(WGL_DOUBLE_BUFFER_ARB); iattributes.push_back(_doubleBuffer); if (_minimumNumberDepthBits > 0) { iattributes.push_back(WGL_DEPTH_BITS_ARB); iattributes.push_back(_minimumNumberDepthBits); } if (_minimumNumberStencilBits > 0) { iattributes.push_back(WGL_STENCIL_BITS_ARB); iattributes.push_back(_minimumNumberStencilBits); } if (_minimumNumberAccumulationBits > 0) { iattributes.push_back(WGL_ACCUM_BITS_ARB); iattributes.push_back(_minimumNumberAccumulationBits); } // Terminate array iattributes.push_back(0); // Now obtain a list of pixel formats that meet these minimum requirements. int format; int pformat[MAX_PFORMATS]; unsigned int nformats=0; if ( !wglChoosePixelFormat( hdc, &iattributes.front(), &fattributes.front(), MAX_PFORMATS, pformat, &nformats ) ) { osg::notify(osg::FATAL)<< "pbuffer creation error: Couldn't find a suitable pixel format." < pbattr; // Texture format pbattr.push_back(WGL_TEXTURE_FORMAT_ARB); pbattr.push_back(WGL_TEXTURE_RGBA_ARB); #if 1 // Texture target pbattr.push_back(WGL_TEXTURE_TARGET_ARB); pbattr.push_back(WGL_TEXTURE_2D_ARB); #else // Cubemap pbattr.push_back(WGL_TEXTURE_TARGET_ARB); pbattr.push_back(WGL_TEXTURE_CUBE_MAP_ARB); // Cubemap face pbattr.push_back(WGL_CUBE_MAP_FACE_ARB); pbattr.push_back(WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB); #endif // Terminate array pbattr.push_back(0); iattributes[0] = 0; _hPBuffer = wglCreatePBuffer( hdc, format, _width, _height, &pbattr.front() ); if ( !_hPBuffer ) { DWORD err = GetLastError(); osg::notify(osg::FATAL)<< "pbuffer creation error: wglCreatePBufferARB() failed\n" <