Revision: 8810
          http://playerstage.svn.sourceforge.net/playerstage/?rev=8810&view=rev
Author:   natepak
Date:     2010-06-30 14:54:08 +0000 (Wed, 30 Jun 2010)

Log Message:
-----------
Added check of graphic card capabilities to enable/disable RT shaders

Modified Paths:
--------------
    code/gazebo/trunk/server/rendering/OgreAdaptor.cc
    code/gazebo/trunk/server/rendering/OgreAdaptor.hh
    code/gazebo/trunk/server/rendering/RTShaderSystem.cc
    code/gazebo/trunk/server/rendering/RTShaderSystem.hh

Modified: code/gazebo/trunk/server/rendering/OgreAdaptor.cc
===================================================================
--- code/gazebo/trunk/server/rendering/OgreAdaptor.cc   2010-06-30 02:24:20 UTC 
(rev 8809)
+++ code/gazebo/trunk/server/rendering/OgreAdaptor.cc   2010-06-30 14:54:08 UTC 
(rev 8810)
@@ -133,6 +133,8 @@
 
   // Initialize the root node, and don't create a window
   this->root->initialise(false);
+
+
 }
 
 
////////////////////////////////////////////////////////////////////////////////
@@ -253,25 +255,23 @@
       exit(-1);
     }
   }
-  
 
-  // Create our frame listener and register it
-  /*this->frameListener = new OgreFrameListener();
-  this->root->addFrameListener(this->frameListener);
-  */
-
   this->raySceneQuery = this->sceneMgr->createRayQuery( Ogre::Ray() );
   this->raySceneQuery->setSortByDistance(true);
   this->raySceneQuery->setQueryMask(Ogre::SceneManager::ENTITY_TYPE_MASK);
 
-  RTShaderSystem::Instance()->Init();
+  if (this->HasGLSL())
+    RTShaderSystem::Instance()->Init();
 }
 
+
+
 
////////////////////////////////////////////////////////////////////////////////
 /// Finalize
 void OgreAdaptor::Fini()
 {
-  RTShaderSystem::Instance()->Fini();
+  if (this->HasGLSL())
+    RTShaderSystem::Instance()->Fini();
 }
  
 
////////////////////////////////////////////////////////////////////////////////
@@ -452,6 +452,7 @@
   */
 
   this->root->setRenderSystem(renderSys);
+
 }
 
 
@@ -637,5 +638,26 @@
   }
 }
 
+////////////////////////////////////////////////////////////////////////////////
+// Returns true if the graphics card support GLSL
+bool OgreAdaptor::HasGLSL()
+{
+  const Ogre::RenderSystemCapabilities *capabilities;
+  Ogre::RenderSystemCapabilities::ShaderProfiles profiles;
+  Ogre::RenderSystemCapabilities::ShaderProfiles::const_iterator iter;
 
+  capabilities = this->root->getRenderSystem()->getCapabilities();
+  profiles = capabilities->getSupportedShaderProfiles();
 
+  iter = std::find(profiles.begin(), profiles.end(), "glsl2");
+
+  // Print all the shader profiles
+  /*std::cout << "Shader profiles:\n";
+  for (iter = profiles.begin(); iter != profiles.end(); iter++)
+  {
+    std::cout << *iter << "\n";
+  }
+  */
+
+  return iter != profiles.end();
+}

Modified: code/gazebo/trunk/server/rendering/OgreAdaptor.hh
===================================================================
--- code/gazebo/trunk/server/rendering/OgreAdaptor.hh   2010-06-30 02:24:20 UTC 
(rev 8809)
+++ code/gazebo/trunk/server/rendering/OgreAdaptor.hh   2010-06-30 14:54:08 UTC 
(rev 8810)
@@ -119,6 +119,9 @@
 
     public: void PrintSceneGraph();
 
+    /// \brief Returns true if the graphics card support GLSL
+    public: bool HasGLSL();
+
     /// \brief Print scene graph
     private: void PrintSceneGraphHelper(std::string prefix, 
                                         Ogre::Node *node);

Modified: code/gazebo/trunk/server/rendering/RTShaderSystem.cc
===================================================================
--- code/gazebo/trunk/server/rendering/RTShaderSystem.cc        2010-06-30 
02:24:20 UTC (rev 8809)
+++ code/gazebo/trunk/server/rendering/RTShaderSystem.cc        2010-06-30 
14:54:08 UTC (rev 8810)
@@ -43,6 +43,7 @@
 /// Constructor
 RTShaderSystem::RTShaderSystem()
 {
+  this->initialized = false;
 }
 
 
////////////////////////////////////////////////////////////////////////////////
@@ -158,6 +159,8 @@
 
     // Invalidate the scheme in order to re-generate all shaders based 
technique related to this scheme.
     
this->shaderGenerator->invalidateScheme(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME);
+
+    this->initialized = true;
   }
   else
     gzerr(0) << "RT Shader system failed to initialize\n";
@@ -166,7 +169,9 @@
 
 void RTShaderSystem::Fini()
 {
-#if INCLUDE_RTSHADER && OGRE_VERSION_MAJOR >= 1 && OGRE_VERSION_MINOR >= 
MINOR_VERSION
+  if (!this->initialized)
+    return;
+
   // Restore default scheme.
   
Ogre::MaterialManager::getSingleton().setActiveScheme(Ogre::MaterialManager::DEFAULT_SCHEME_NAME);
 
@@ -184,46 +189,49 @@
     Ogre::RTShader::ShaderGenerator::finalize();
     this->shaderGenerator = NULL;
   }
-#endif
 }
 
 
////////////////////////////////////////////////////////////////////////////////
 // Set an Ogre::Entity to use RT shaders
 void RTShaderSystem::AttachEntity(OgreVisual *vis)
 {
-#if INCLUDE_RTSHADER && OGRE_VERSION_MAJOR >= 1 && OGRE_VERSION_MINOR >= 
MINOR_VERSION
+  if (!this->initialized)
+    return;
+
   this->GenerateShaders(vis);
   this->entities.push_back(vis);
-#endif
 }
 
 
////////////////////////////////////////////////////////////////////////////////
 // Remove and entity
 void RTShaderSystem::DetachEntity(OgreVisual *vis)
 {
-#if INCLUDE_RTSHADER && OGRE_VERSION_MAJOR >= 1 && OGRE_VERSION_MINOR >= 
MINOR_VERSION
+  if (!this->initialized)
+    return;
+
   this->entities.remove(vis);
-#endif
 }
 
 
////////////////////////////////////////////////////////////////////////////////
 /// Update the shaders
 void RTShaderSystem::UpdateShaders()
 {
-#if INCLUDE_RTSHADER && OGRE_VERSION_MAJOR >= 1 && OGRE_VERSION_MINOR >= 
MINOR_VERSION
+  if (!this->initialized)
+    return;
+
   std::list<OgreVisual*>::iterator iter;
 
   // Update all the shaders
   for (iter = this->entities.begin(); iter != this->entities.end(); iter++)
     this->GenerateShaders(*iter);
-#endif
 }
 
 
////////////////////////////////////////////////////////////////////////////////
 /// Generate shaders for an entity
 void RTShaderSystem::GenerateShaders(OgreVisual *vis)
 {
-#if INCLUDE_RTSHADER && OGRE_VERSION_MAJOR >= 1 && OGRE_VERSION_MINOR >= 
MINOR_VERSION
+  if (!this->initialized)
+    return;
 
   for (unsigned int k=0; k < vis->sceneNode->numAttachedObjects(); k++)
   {
@@ -306,5 +314,4 @@
 
     }
   }
-#endif
 }

Modified: code/gazebo/trunk/server/rendering/RTShaderSystem.hh
===================================================================
--- code/gazebo/trunk/server/rendering/RTShaderSystem.hh        2010-06-30 
02:24:20 UTC (rev 8809)
+++ code/gazebo/trunk/server/rendering/RTShaderSystem.hh        2010-06-30 
14:54:08 UTC (rev 8810)
@@ -95,6 +95,8 @@
     private: std::list<OgreVisual*> entities;
 #endif
 
+    private: bool initialized;
+
     private: friend class DestroyerT<RTShaderSystem>;
     private: friend class SingletonT<RTShaderSystem>;
   };


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to