From 76461b3ab2012dd677fff7aea8893eafbfdce7d5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 22 Dec 2006 21:53:44 +0000 Subject: [PATCH] Added support for sample and sampleBuffers to osg::GraphicsContext::Traits and cleaned up the Traits naming --- examples/osgcamera/osgcamera.cpp | 6 +- include/osg/GraphicsContext | 118 ++++++++++-------- src/osg/GraphicsContext.cpp | 9 ++ .../GraphicsContextImplementation.cpp | 56 ++++----- src/osgUtil/RenderStage.cpp | 43 +++---- src/osgUtil/SceneView.cpp | 4 +- src/osgViewer/GraphicsWindowX11.cpp | 91 +++++++------- src/osgViewer/View.cpp | 32 ++--- 8 files changed, 193 insertions(+), 166 deletions(-) diff --git a/examples/osgcamera/osgcamera.cpp b/examples/osgcamera/osgcamera.cpp index f7cdc6193..24388bd45 100644 --- a/examples/osgcamera/osgcamera.cpp +++ b/examples/osgcamera/osgcamera.cpp @@ -39,9 +39,13 @@ int main( int argc, char **argv ) viewer.setUpViewAcrossAllScreens(); viewer.realize(); - while(!viewer.done()) + unsigned int numFrames = 0; + unsigned int maxFrames = 100; + + while(!viewer.done() && numFrames #include #include +#include using namespace osg; @@ -39,6 +40,14 @@ GraphicsContext* GraphicsContext::createGraphicsContext(Traits* traits) } +std::string GraphicsContext::ScreenIdentifier::displayName() const +{ + std::stringstream ostr; + ostr< ContextIDMap; static ContextIDMap s_contextIDMap; static OpenThreads::Mutex s_contextIDMapMutex; diff --git a/src/osgProducer/GraphicsContextImplementation.cpp b/src/osgProducer/GraphicsContextImplementation.cpp index e85316d73..50ae28dc1 100644 --- a/src/osgProducer/GraphicsContextImplementation.cpp +++ b/src/osgProducer/GraphicsContextImplementation.cpp @@ -22,7 +22,7 @@ namespace osgProducer { struct MyWindowingSystemInterface : public osg::GraphicsContext::WindowingSystemInterface { - virtual unsigned int getNumScreens(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier) + virtual unsigned int getNumScreens(const osg::GraphicsContext::ScreenIdentifier& /*screenIdentifier*/) { return Producer::RenderSurface::getNumberOfScreens(); } @@ -30,9 +30,9 @@ namespace osgProducer virtual void getScreenResolution(const osg::GraphicsContext::ScreenIdentifier& screenIdentifier, unsigned int& width, unsigned int& height) { osg::ref_ptr rs = new Producer::RenderSurface; - rs->setHostName(screenIdentifier._hostName); - rs->setDisplayNum(screenIdentifier._displayNum); - rs->setScreenNum(screenIdentifier._screenNum); + rs->setHostName(screenIdentifier.hostName); + rs->setDisplayNum(screenIdentifier.displayNum); + rs->setScreenNum(screenIdentifier.screenNum); rs->getScreenSize(width, height); } @@ -66,11 +66,11 @@ GraphicsContextImplementation::GraphicsContextImplementation(Traits* traits) _traits = traits; _rs = new Producer::RenderSurface; - _rs->setWindowName(traits->_windowName); - _rs->setWindowRectangle(traits->_x, traits->_y, traits->_width, traits->_height); - _rs->useBorder(traits->_windowDecoration); - _rs->setDisplayNum(traits->_displayNum); - _rs->setScreenNum(traits->_screenNum); + _rs->setWindowName(traits->windowName); + _rs->setWindowRectangle(traits->x, traits->y, traits->width, traits->height); + _rs->useBorder(traits->windowDecoration); + _rs->setDisplayNum(traits->displayNum); + _rs->setScreenNum(traits->screenNum); // set the visual chooser @@ -81,35 +81,35 @@ GraphicsContextImplementation::GraphicsContextImplementation(Traits* traits) _rs->setVisualChooser(rs_vc); } - rs_vc->setRedSize(_traits->_red); - rs_vc->setGreenSize(_traits->_green); - rs_vc->setBlueSize(_traits->_blue); - rs_vc->setAlphaSize(_traits->_alpha); + rs_vc->setRedSize(_traits->red); + rs_vc->setGreenSize(_traits->green); + rs_vc->setBlueSize(_traits->blue); + rs_vc->setAlphaSize(_traits->alpha); - rs_vc->setDepthSize(_traits->_depth); - rs_vc->setStencilSize(_traits->_stencil); + rs_vc->setDepthSize(_traits->depth); + rs_vc->setStencilSize(_traits->stencil); - if (_traits->_doubleBuffer) rs_vc->useDoubleBuffer(); + if (_traits->doubleBuffer) rs_vc->useDoubleBuffer(); rs_vc->addAttribute( Producer::VisualChooser::RGBA ); // Always use UseGL rs_vc->addAttribute( Producer::VisualChooser::UseGL ); - if (traits->_pbuffer) + if (traits->pbuffer) { _rs->setDrawableType(Producer::RenderSurface::DrawableType_PBuffer); - if (traits->_target) + if (traits->target) { - _rs->setRenderToTextureOptions(traits->_mipMapGeneration ? Producer::RenderSurface::RequestSpaceForMipMaps : + _rs->setRenderToTextureOptions(traits->mipMapGeneration ? Producer::RenderSurface::RequestSpaceForMipMaps : Producer::RenderSurface::RenderToTextureOptions_Default); - _rs->setRenderToTextureMipMapLevel(traits->_level); - _rs->setRenderToTextureMode(traits->_alpha>0 ? Producer::RenderSurface::RenderToRGBATexture : + _rs->setRenderToTextureMipMapLevel(traits->level); + _rs->setRenderToTextureMode(traits->alpha>0 ? Producer::RenderSurface::RenderToRGBATexture : Producer::RenderSurface::RenderToRGBTexture); - switch(traits->_target) + switch(traits->target) { case(GL_TEXTURE_1D) : _rs->setRenderToTextureTarget(Producer::RenderSurface::Texture1D); @@ -134,7 +134,7 @@ GraphicsContextImplementation::GraphicsContextImplementation(Traits* traits) case(GL_TEXTURE_CUBE_MAP_POSITIVE_Z) : case(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z) : _rs->setRenderToTextureTarget(Producer::RenderSurface::TextureCUBE); - _rs->setRenderToTextureFace( Producer::RenderSurface::CubeMapFace(traits->_target - GL_TEXTURE_CUBE_MAP_POSITIVE_X)); + _rs->setRenderToTextureFace( Producer::RenderSurface::CubeMapFace(traits->target - GL_TEXTURE_CUBE_MAP_POSITIVE_X)); break; } @@ -142,7 +142,7 @@ GraphicsContextImplementation::GraphicsContextImplementation(Traits* traits) } - GraphicsContextImplementation* sharedContext = dynamic_cast(traits->_sharedContext); + GraphicsContextImplementation* sharedContext = dynamic_cast(traits->sharedContext); if (sharedContext) { @@ -184,9 +184,9 @@ GraphicsContextImplementation::GraphicsContextImplementation(Producer::RenderSur _closeOnDestruction = false; _traits = new osg::GraphicsContext::Traits; - _traits->_windowName = _rs->getWindowName(); - _traits->_displayNum = _rs->getDisplayNum(); - _traits->_screenNum = _rs->getScreenNum(); + _traits->windowName = _rs->getWindowName(); + _traits->displayNum = _rs->getDisplayNum(); + _traits->screenNum = _rs->getScreenNum(); } GraphicsContextImplementation::~GraphicsContextImplementation() @@ -198,7 +198,7 @@ bool GraphicsContextImplementation::realizeImplementation() { if (_rs.valid()) { - GraphicsContextImplementation* sharedContext = dynamic_cast(_traits->_sharedContext); + GraphicsContextImplementation* sharedContext = dynamic_cast(_traits->sharedContext); if (sharedContext) { diff --git a/src/osgUtil/RenderStage.cpp b/src/osgUtil/RenderStage.cpp index f34fb25f8..917563abd 100644 --- a/src/osgUtil/RenderStage.cpp +++ b/src/osgUtil/RenderStage.cpp @@ -437,14 +437,14 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) // set up the traits of the graphics context that we want osg::ref_ptr traits = new osg::GraphicsContext::Traits; - traits->_width = width; - traits->_height = height; + traits->width = width; + traits->height = height; - // osg::notify(osg::NOTICE)<<"traits = "<_width<<" "<_height<height<_pbuffer = (renderTargetImplemntation==osg::Camera::PIXEL_BUFFER || renderTargetImplemntation==osg::Camera::PIXEL_BUFFER_RTT); - traits->_windowDecoration = (renderTargetImplemntation==osg::Camera::SEPERATE_WINDOW); - traits->_doubleBuffer = (renderTargetImplemntation==osg::Camera::SEPERATE_WINDOW); + traits->pbuffer = (renderTargetImplemntation==osg::Camera::PIXEL_BUFFER || renderTargetImplemntation==osg::Camera::PIXEL_BUFFER_RTT); + traits->windowDecoration = (renderTargetImplemntation==osg::Camera::SEPERATE_WINDOW); + traits->doubleBuffer = (renderTargetImplemntation==osg::Camera::SEPERATE_WINDOW); osg::Texture* pBufferTexture = 0; GLenum bufferFormat = GL_NONE; @@ -465,13 +465,13 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) { case(osg::Camera::DEPTH_BUFFER): { - traits->_depth = 24; + traits->depth = 24; depthAttached = true; break; } case(osg::Camera::STENCIL_BUFFER): { - traits->_stencil = 8; + traits->stencil = 8; stencilAttached = true; break; } @@ -503,10 +503,10 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) if (renderTargetImplemntation==osg::Camera::PIXEL_BUFFER_RTT) { - traits->_target = bufferFormat; - traits->_level = level; - traits->_face = face; - traits->_mipMapGeneration = attachment._mipMapGeneration; + traits->target = bufferFormat; + traits->level = level; + traits->face = face; + traits->mipMapGeneration = attachment._mipMapGeneration; } break; } @@ -526,29 +526,30 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) if (!depthAttached) { - traits->_depth = 24; + traits->depth = 24; } if (!colorAttached) { if (bufferFormat == GL_NONE) bufferFormat = GL_RGB; - traits->_red = 8; - traits->_green = 8; - traits->_blue = 8; - traits->_alpha = (bufferFormat==GL_RGBA) ? 8 : 0; + traits->red = 8; + traits->green = 8; + traits->blue = 8; + traits->alpha = (bufferFormat==GL_RGBA) ? 8 : 0; } // share OpenGL objects if possible... if (state.getGraphicsContext()) { - traits->_sharedContext = state.getGraphicsContext(); + traits->sharedContext = state.getGraphicsContext(); - const osg::GraphicsContext::Traits* sharedTraits = traits->_sharedContext->getTraits(); + const osg::GraphicsContext::Traits* sharedTraits = traits->sharedContext->getTraits(); if (sharedTraits) { - traits->_displayNum = sharedTraits->_displayNum; - traits->_screenNum = sharedTraits->_screenNum; + traits->hostName = sharedTraits->hostName; + traits->displayNum = sharedTraits->displayNum; + traits->screenNum = sharedTraits->screenNum; } } diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index 4657b71e4..9081cbeab 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -117,7 +117,9 @@ SceneView::SceneView(DisplaySettings* ds) _interlacedStereoStencilHeight = 0; } -SceneView::SceneView(const SceneView& rhs, const osg::CopyOp&) +SceneView::SceneView(const SceneView& rhs, const osg::CopyOp& copyop): + osg::Object(rhs,copyop), + osg::CullSettings(rhs) { _displaySettings = rhs._displaySettings; diff --git a/src/osgViewer/GraphicsWindowX11.cpp b/src/osgViewer/GraphicsWindowX11.cpp index 37d48633c..7f322c38b 100644 --- a/src/osgViewer/GraphicsWindowX11.cpp +++ b/src/osgViewer/GraphicsWindowX11.cpp @@ -87,19 +87,25 @@ bool GraphicsWindowX11::createVisualInfo() attributes.push_back(GLX_RGBA); - if (_traits->_doubleBuffer) attributes.push_back(GLX_DOUBLEBUFFER); + if (_traits->doubleBuffer) attributes.push_back(GLX_DOUBLEBUFFER); - if (_traits->_quadBufferStereo) attributes.push_back(GLX_STEREO); + if (_traits->quadBufferStereo) attributes.push_back(GLX_STEREO); - attributes.push_back(GLX_RED_SIZE); attributes.push_back(_traits->_red); - attributes.push_back(GLX_GREEN_SIZE); attributes.push_back(_traits->_green); - attributes.push_back(GLX_BLUE_SIZE); attributes.push_back(_traits->_blue); - attributes.push_back(GLX_DEPTH_SIZE); attributes.push_back(_traits->_depth); + attributes.push_back(GLX_RED_SIZE); attributes.push_back(_traits->red); + attributes.push_back(GLX_GREEN_SIZE); attributes.push_back(_traits->green); + attributes.push_back(GLX_BLUE_SIZE); attributes.push_back(_traits->blue); + attributes.push_back(GLX_DEPTH_SIZE); attributes.push_back(_traits->depth); - if (_traits->_alpha) { attributes.push_back(GLX_ALPHA_SIZE); attributes.push_back(_traits->_alpha); } + if (_traits->alpha) { attributes.push_back(GLX_ALPHA_SIZE); attributes.push_back(_traits->alpha); } - if (_traits->_stencil) { attributes.push_back(GLX_STENCIL_SIZE); attributes.push_back(_traits->_stencil); } + if (_traits->stencil) { attributes.push_back(GLX_STENCIL_SIZE); attributes.push_back(_traits->stencil); } +#if defined(GLX_SAMPLE_BUFFERS) && defined (GLX_SAMPLES) + + if (_traits->sampleBuffers) { attributes.push_back(GLX_SAMPLE_BUFFERS); attributes.push_back(_traits->sampleBuffers); } + if (_traits->sampleBuffers) { attributes.push_back(GLX_SAMPLES); attributes.push_back(_traits->samples); } + +#endif // TODO // GLX_AUX_BUFFERS // GLX_ACCUM_RED_SIZE @@ -109,7 +115,7 @@ bool GraphicsWindowX11::createVisualInfo() attributes.push_back(None); - _visualInfo = glXChooseVisual( _display, _traits->_screenNum, &(attributes.front()) ); + _visualInfo = glXChooseVisual( _display, _traits->screenNum, &(attributes.front()) ); return _visualInfo != 0; } @@ -173,8 +179,8 @@ void GraphicsWindowX11::setWindowDecoration(bool flag) #if 0 // now update the window dimensions to account for any size changes made by the window manager, XGetWindowAttributes( _display, _window, &watt ); - _traits->_width = watt.width; - _traits->_height = watt.height; + _traits->width = watt.width; + _traits->height = watt.height; #endif } @@ -186,22 +192,20 @@ void GraphicsWindowX11::init() { if (!_traits || _initialized) return; - const char* displayString = _traits->_hostName.c_str(); - _display = XOpenDisplay(displayString); + _display = XOpenDisplay(_traits->displayName().c_str()); - unsigned int screen = _traits->_screenNum; + unsigned int screen = _traits->screenNum; if (!_display) { - osg::notify(osg::NOTICE)<<"Error: Unable to open display \"" << XDisplayName(displayString) << "\". Is the DISPLAY environmental variable set?"<displayName().c_str()) << "\". Is the DISPLAY environmental variable set?"<displayName().c_str()) <<" has no GLX extension." << std::endl; XCloseDisplay( _display ); _display = 0; @@ -249,9 +253,9 @@ void GraphicsWindowX11::init() } _window = XCreateWindow( _display, _parent, - _traits->_x, - _traits->_y, - _traits->_width, _traits->_height, 0, + _traits->x, + _traits->y, + _traits->width, _traits->height, 0, _visualInfo->depth, InputOutput, _visualInfo->visual, mask, &swatt ); @@ -268,14 +272,14 @@ void GraphicsWindowX11::init() sh.flags &= 0x7; sh.flags |= USPosition; sh.flags &= 0xB; - sh.x = _traits->_x; - sh.y = _traits->_y; - sh.width = _traits->_width; - sh.height = _traits->_height; - XSetStandardProperties( _display, _window, _traits->_windowName.c_str(), _traits->_windowName.c_str(), None, 0, 0, &sh); + sh.x = _traits->x; + sh.y = _traits->y; + sh.width = _traits->width; + sh.height = _traits->height; + XSetStandardProperties( _display, _window, _traits->windowName.c_str(), _traits->windowName.c_str(), None, 0, 0, &sh); #if 1 - setWindowDecoration(_traits->_windowDecoration); + setWindowDecoration(_traits->windowDecoration); #else setWindowDecoration(true); #endif @@ -314,8 +318,8 @@ void GraphicsWindowX11::init() // now update the window dimensions to account for any size changes made by the window manager, XGetWindowAttributes( _display, _window, &watt ); - _traits->_width = watt.width; - _traits->_height = watt.height; + _traits->width = watt.width; + _traits->height = watt.height; //osg::notify(osg::NOTICE)<<"After sync apply.x = "<_pbuffer) + if (traits->pbuffer) { return new GraphicsContextX11(traits); } diff --git a/src/osgViewer/View.cpp b/src/osgViewer/View.cpp index ba515a17f..f82995980 100644 --- a/src/osgViewer/View.cpp +++ b/src/osgViewer/View.cpp @@ -24,7 +24,7 @@ public: virtual ~ActionAdapter() {} virtual void requestRedraw() { /*osg::notify(osg::NOTICE)<<"requestRedraw()"<getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); osg::ref_ptr traits = new osg::GraphicsContext::Traits; - traits->_x = 0; - traits->_y = 0; - traits->_width = width; - traits->_height = height; - traits->_windowDecoration = false; - traits->_doubleBuffer = true; - traits->_sharedContext = 0; + traits->x = 0; + traits->y = 0; + traits->width = width; + traits->height = height; + traits->windowDecoration = false; + traits->doubleBuffer = true; + traits->sharedContext = 0; osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get()); @@ -123,14 +123,14 @@ void View::setUpViewAcrossAllScreens() wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(i), width, height); osg::ref_ptr traits = new osg::GraphicsContext::Traits; - traits->_screenNum = i; - traits->_x = 0; - traits->_y = 0; - traits->_width = width; - traits->_height = height; - traits->_windowDecoration = false; - traits->_doubleBuffer = true; - traits->_sharedContext = 0; + traits->screenNum = i; + traits->x = 0; + traits->y = 0; + traits->width = width; + traits->height = height; + traits->windowDecoration = false; + traits->doubleBuffer = true; + traits->sharedContext = 0; osg::ref_ptr gc = osg::GraphicsContext::createGraphicsContext(traits.get());