diff --git a/include/osg/DisplaySettings b/include/osg/DisplaySettings index 060ec6ec9..6821d14e9 100644 --- a/include/osg/DisplaySettings +++ b/include/osg/DisplaySettings @@ -310,6 +310,19 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced VertexBufferHint getVertexBufferHint() const { return _vertexBufferHint; } + enum ShaderHint + { + SHADER_NONE, + SHADER_GL2, + SHADER_GLES2, + SHADER_GL3, + SHADER_GLES3 + }; + + void setShaderHint(ShaderHint hint) { _shaderHint = hint; } + ShaderHint getShaderHint() const { return _shaderHint; } + + void setKeystoneHint(bool enabled) { _keystoneHint = enabled; } bool getKeystoneHint() const { return _keystoneHint; } @@ -323,7 +336,8 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced Objects& getKeystones() { return _keystones; } const Objects& getKeystones() const { return _keystones; } - enum OSXMenubarBehavior { + enum OSXMenubarBehavior + { MENUBAR_AUTO_HIDE, MENUBAR_FORCE_HIDE, MENUBAR_FORCE_SHOW @@ -400,6 +414,7 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced unsigned int _syncSwapBuffers; VertexBufferHint _vertexBufferHint; + ShaderHint _shaderHint; bool _keystoneHint; FileNames _keystoneFileNames; diff --git a/src/osg/DisplaySettings.cpp b/src/osg/DisplaySettings.cpp index 0aadd67dd..d17043eec 100644 --- a/src/osg/DisplaySettings.cpp +++ b/src/osg/DisplaySettings.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -117,6 +118,7 @@ void DisplaySettings::setDisplaySettings(const DisplaySettings& vs) _swapMethod = vs._swapMethod; _vertexBufferHint = vs._vertexBufferHint; + _shaderHint = vs._shaderHint; _keystoneHint = vs._keystoneHint; _keystoneFileNames = vs._keystoneFileNames; @@ -247,6 +249,24 @@ void DisplaySettings::setDefaults() // _vertexBufferHint = VERTEX_BUFFER_OBJECT; // _vertexBufferHint = VERTEX_ARRAY_OBJECT; +#if defined(OSG_GLES3_AVAILABLE) + _shaderHint = SHADER_GLES3; + OSG_NOTICE<<"DisplaySettings::SHADER_GLES3"<getShaderHint(); + if (shaderHint==osg::DisplaySettings::SHADER_GL3 || shaderHint==osg::DisplaySettings::SHADER_GLES3) + { + OSG_INFO<<" StateSet::setGlobalDefaults() Setting up GL3 compatible shaders"< program = new osg::Program; - program->addShader(new osg::Shader(osg::Shader::VERTEX, gl3_VertexShader)); - program->addShader(new osg::Shader(osg::Shader::FRAGMENT, gl3_FragmentShader)); - setAttributeAndModes(program.get()); - setTextureAttribute(0, createDefaultTexture()); - addUniform(new osg::Uniform("baseTexture", 0)); - -#elif SHADERS_GL2 - - OSG_INFO<<" StateSet::setGlobalDefaults() Setting up GL2 compatible shaders"< program = new osg::Program; - program->addShader(new osg::Shader(osg::Shader::VERTEX, gl2_VertexShader)); - program->addShader(new osg::Shader(osg::Shader::FRAGMENT, gl2_FragmentShader)); - setAttributeAndModes(program.get()); - setTextureAttribute(0, createDefaultTexture()); - addUniform(new osg::Uniform("baseTexture", 0)); - -#endif + osg::ref_ptr program = new osg::Program; + program->addShader(new osg::Shader(osg::Shader::VERTEX, gl3_VertexShader)); + program->addShader(new osg::Shader(osg::Shader::FRAGMENT, gl3_FragmentShader)); + setAttributeAndModes(program.get()); + setTextureAttribute(0, createDefaultTexture()); + addUniform(new osg::Uniform("baseTexture", 0)); + } + else if (shaderHint==osg::DisplaySettings::SHADER_GL2 || shaderHint==osg::DisplaySettings::SHADER_GLES2) + { + OSG_INFO<<" StateSet::setGlobalDefaults() Setting up GL2 compatible shaders"< program = new osg::Program; + program->addShader(new osg::Shader(osg::Shader::VERTEX, gl2_VertexShader)); + program->addShader(new osg::Shader(osg::Shader::FRAGMENT, gl2_FragmentShader)); + setAttributeAndModes(program.get()); + setTextureAttribute(0, createDefaultTexture()); + addUniform(new osg::Uniform("baseTexture", 0)); + } } diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index d5dc0f8fd..c06392640 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -32,16 +32,10 @@ using namespace osgText; using namespace std; -#define SHADERS_GL3 (defined(OSG_GL3_AVAILABLE) || defined(OSG_GLES3_AVAILABLE)) -#define SHADERS_GL2 (!defined(OSG_GL_FIXED_FUNCTION_AVAILABLE) && !defined(OSG_GL3_AVAILABLE) && !defined(OSG_GLES3_AVAILABLE)) -#define IS_ES (defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE)) - -#if SHADERS_GL3 - -#if !IS_ES +#if (!defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GLES3_AVAILABLE)) #define GLSL_VERSION_STR "330 core" #define GLYPH_CMP "r" -#else +#else #define GLSL_VERSION_STR "300 es" #define GLYPH_CMP "a" #endif @@ -83,10 +77,6 @@ static const char* gl3_TextFragmentShader = { "}\n" }; -#endif - - -#if SHADERS_GL2 static const char* gl2_TextVertexShader = { "// gl2_TextVertexShader\n" "#ifdef GL_ES\n" @@ -116,7 +106,6 @@ static const char* gl2_TextFragmentShader = { " else gl_FragColor = vertexColor;\n" "}\n" }; -#endif osg::ref_ptr& Font::getDefaultFont() { @@ -335,27 +324,32 @@ Font::Font(FontImplementation* implementation): _stateset->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON); #endif -#if SHADERS_GL3 + osg::DisplaySettings::ShaderHint shaderHint = osg::DisplaySettings::instance()->getShaderHint(); + if (shaderHint==osg::DisplaySettings::SHADER_GL3 || shaderHint==osg::DisplaySettings::SHADER_GLES3) + { - OSG_INFO<<"Font::Font() Setting up GL3 compatible shaders"< program = new osg::Program; - program->addShader(new osg::Shader(osg::Shader::VERTEX, gl3_TextVertexShader)); - program->addShader(new osg::Shader(osg::Shader::FRAGMENT, gl3_TextFragmentShader)); - _stateset->setAttributeAndModes(program.get()); - _stateset->addUniform(new osg::Uniform("glyphTexture", 0)); + osg::ref_ptr program = new osg::Program; + program->addShader(new osg::Shader(osg::Shader::VERTEX, gl3_TextVertexShader)); + program->addShader(new osg::Shader(osg::Shader::FRAGMENT, gl3_TextFragmentShader)); + _stateset->setAttributeAndModes(program.get()); + _stateset->addUniform(new osg::Uniform("glyphTexture", 0)); -#elif SHADERS_GL2 + } + else if (shaderHint==osg::DisplaySettings::SHADER_GL2 || shaderHint==osg::DisplaySettings::SHADER_GLES2) + { - OSG_INFO<<"Font::Font() Setting up GL2 compatible shaders"< program = new osg::Program; - program->addShader(new osg::Shader(osg::Shader::VERTEX, gl2_TextVertexShader)); - program->addShader(new osg::Shader(osg::Shader::FRAGMENT, gl2_TextFragmentShader)); - _stateset->setAttributeAndModes(program.get()); - _stateset->addUniform(new osg::Uniform("glyphTexture", 0)); + OSG_INFO<<"Font::Font() Setting up GL2 compatible shaders"< program = new osg::Program; + program->addShader(new osg::Shader(osg::Shader::VERTEX, gl2_TextVertexShader)); + program->addShader(new osg::Shader(osg::Shader::FRAGMENT, gl2_TextFragmentShader)); + _stateset->setAttributeAndModes(program.get()); + _stateset->addUniform(new osg::Uniform("glyphTexture", 0)); + + } char *ptr; if( (ptr = getenv("OSG_MAX_TEXTURE_SIZE")) != 0) diff --git a/src/osgViewer/StatsHandler.cpp b/src/osgViewer/StatsHandler.cpp index 6a82943f8..6b56a62db 100644 --- a/src/osgViewer/StatsHandler.cpp +++ b/src/osgViewer/StatsHandler.cpp @@ -28,13 +28,14 @@ namespace osgViewer { -#define FIXED_FUNCTION defined(OSG_GL_FIXED_FUNCTION_AVAILABLE) -#define SHADERS_GL3 (defined(OSG_GL3_AVAILABLE)) -#define SHADERS_GL2 !FIXED_FUNCTION && !SHADERS_GL3 +#if (!defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GLES3_AVAILABLE)) + #define GLSL_VERSION_STR "330 core" +#else + #define GLSL_VERSION_STR "300 es" +#endif -#if SHADERS_GL3 static const char* gl3_StatsVertexShader = { - "#version 330 core\n" + "#version " GLSL_VERSION_STR "\n" "// gl3_StatsVertexShader\n" "#ifdef GL_ES\n" " precision highp float;\n" @@ -51,7 +52,7 @@ static const char* gl3_StatsVertexShader = { }; static const char* gl3_StatsFragmentShader = { - "#version 330 core\n" + "#version " GLSL_VERSION_STR "\n" "// gl3_StatsFragmentShader\n" "#ifdef GL_ES\n" " precision highp float;\n" @@ -64,10 +65,6 @@ static const char* gl3_StatsFragmentShader = { "}\n" }; -#endif - - -#if SHADERS_GL2 static const char* gl2_StatsVertexShader = { "// gl2_StatsVertexShader\n" "#ifdef GL_ES\n" @@ -92,7 +89,6 @@ static const char* gl2_StatsFragmentShader = { " gl_FragColor = vertexColor;\n" "}\n" }; -#endif StatsHandler::StatsHandler(): _keyEventTogglesOnScreenStats('s'), @@ -121,26 +117,31 @@ StatsHandler::StatsHandler(): _camera->setRenderer(new Renderer(_camera.get())); _camera->setProjectionResizePolicy(osg::Camera::FIXED); -#if SHADERS_GL3 + osg::DisplaySettings::ShaderHint shaderHint = osg::DisplaySettings::instance()->getShaderHint(); + if (shaderHint==osg::DisplaySettings::SHADER_GL3 || shaderHint==osg::DisplaySettings::SHADER_GLES3) + { - OSG_INFO<<"StatsHandler::StatsHandler() Setting up GL3 compatible shaders"< program = new osg::Program; - program->addShader(new osg::Shader(osg::Shader::VERTEX, gl3_StatsVertexShader)); - program->addShader(new osg::Shader(osg::Shader::FRAGMENT, gl3_StatsFragmentShader)); - _camera->getOrCreateStateSet()->setAttributeAndModes(program.get()); + osg::ref_ptr program = new osg::Program; + program->addShader(new osg::Shader(osg::Shader::VERTEX, gl3_StatsVertexShader)); + program->addShader(new osg::Shader(osg::Shader::FRAGMENT, gl3_StatsFragmentShader)); + _camera->getOrCreateStateSet()->setAttributeAndModes(program.get()); + } + else if (shaderHint==osg::DisplaySettings::SHADER_GL2 || shaderHint==osg::DisplaySettings::SHADER_GLES2) + { -#elif SHADERS_GL2 + OSG_INFO<<"StatsHandler::StatsHandler() Setting up GL2 compatible shaders"< program = new osg::Program; - program->addShader(new osg::Shader(osg::Shader::VERTEX, gl2_StatsVertexShader)); - program->addShader(new osg::Shader(osg::Shader::FRAGMENT, gl2_StatsFragmentShader)); - _camera->getOrCreateStateSet()->setAttributeAndModes(program.get()); -#else - OSG_INFO<<"StatsHandler::StatsHandler() Fixed pipeline"< program = new osg::Program; + program->addShader(new osg::Shader(osg::Shader::VERTEX, gl2_StatsVertexShader)); + program->addShader(new osg::Shader(osg::Shader::FRAGMENT, gl2_StatsFragmentShader)); + _camera->getOrCreateStateSet()->setAttributeAndModes(program.get()); + } + else + { + OSG_INFO<<"StatsHandler::StatsHandler() Fixed pipeline"<