From 1c9f1b8eb1a33691b39a247067e408eab94f4c14 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 1 Dec 2005 14:09:38 +0000 Subject: [PATCH] Added TestSupportCallback to properly handle querry of OpenGL support of vertex texturing in GLSL. --- .../osgshaderterrain/osgshaderterrain.cpp | 62 ++++++++++++------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/examples/osgshaderterrain/osgshaderterrain.cpp b/examples/osgshaderterrain/osgshaderterrain.cpp index d63fe9f6d..a9fe927c1 100644 --- a/examples/osgshaderterrain/osgshaderterrain.cpp +++ b/examples/osgshaderterrain/osgshaderterrain.cpp @@ -729,6 +729,39 @@ osg::Node* ForestTechniqueManager::createScene(unsigned int /*numTreesToCreates* return scene; } +class TestSupportCallback : public osgProducer::OsgCameraGroup::RealizeCallback +{ + public: + TestSupportCallback():_supported(true),_errorMessage() {} + + virtual void operator()( osgProducer::OsgCameraGroup&, osgProducer::OsgSceneHandler& sh, const Producer::RenderSurface& ) + { + unsigned int contextID = sh.getSceneView()->getState()->getContextID(); + osg::GL2Extensions* gl2ext = osg::GL2Extensions::Get(contextID,true); + if( gl2ext ) + { + if( !gl2ext->isGlslSupported() ) + { + _supported = false; + _errorMessage = "ERROR: GLSL not supported by OpenGL driver."; + } + + GLint numVertexTexUnits = 0; + glGetIntegerv( GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &numVertexTexUnits ); + if( numVertexTexUnits <= 0 ) + { + _supported = false; + _errorMessage = "ERROR: vertex texturing not supported by OpenGL driver."; + } + } + + } + + bool _supported; + std::string _errorMessage; + +}; + int main( int argc, char **argv ) { @@ -777,31 +810,16 @@ int main( int argc, char **argv ) // add model to viewer. viewer.setSceneData( node ); + osg::ref_ptr testSupportCallback = new TestSupportCallback(); + viewer.setRealizeCallback(testSupportCallback.get()); + // create the windows and run the threads. viewer.realize(); - - // not all hardware can support vertex texturing, so check first. - for(unsigned int contextID = 0; - contextIDgetMaxNumberOfGraphicsContexts(); - ++contextID) + + if (!testSupportCallback->_supported) { - osg::GL2Extensions* gl2ext = osg::GL2Extensions::Get(contextID,false); - if( gl2ext ) - { - if( !gl2ext->isGlslSupported() ) - { - std::cout<<"ERROR: GLSL not supported by OpenGL driver."<_errorMessage<