Replaced macro based selection of which shaders to use by default with DisplaySettings::setShaderHint() and OSG_SHADER=HINT=GL2|GL3|GLES2|GLES3|NONE controls
This commit is contained in:
parent
ec5cbe18d5
commit
6308b497f2
@ -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;
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <osg/ApplicationUsage>
|
||||
#include <osg/Math>
|
||||
#include <osg/Notify>
|
||||
#include <osg/GL>
|
||||
#include <osg/ref_ptr>
|
||||
|
||||
#include <algorithm>
|
||||
@ -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"<<std::endl;
|
||||
#elif defined(OSG_GLES2_AVAILABLE)
|
||||
_shaderHint = SHADER_GLES2;
|
||||
OSG_NOTICE<<"DisplaySettings::SHADER_GLES2"<<std::endl;
|
||||
#elif defined(OSG_GL3_AVAILABLE)
|
||||
_shaderHint = SHADER_GL3;
|
||||
OSG_NOTICE<<"DisplaySettings::SHADER_GL3"<<std::endl;
|
||||
#elif defined(OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE)
|
||||
OSG_NOTICE<<"DisplaySettings::SHADER_NONE"<<std::endl;
|
||||
_shaderHint = SHADER_NONE;
|
||||
#else
|
||||
OSG_NOTICE<<"DisplaySettings::SHADER_GL2"<<std::endl;
|
||||
_shaderHint = SHADER_GL2;
|
||||
#endif
|
||||
|
||||
|
||||
_keystoneHint = false;
|
||||
|
||||
_OSXMenubarBehavior = MENUBAR_AUTO_HIDE;
|
||||
@ -701,6 +721,31 @@ void DisplaySettings::readEnvironmentalVariables()
|
||||
}
|
||||
|
||||
|
||||
if ((ptr = getenv("OSG_SHADER_HINT")) != 0)
|
||||
{
|
||||
if (strcmp(ptr,"GL2")==0)
|
||||
{
|
||||
_shaderHint = SHADER_GL2;
|
||||
}
|
||||
else if (strcmp(ptr,"GL3")==0)
|
||||
{
|
||||
_shaderHint = SHADER_GL3;
|
||||
}
|
||||
else if (strcmp(ptr,"GLES2")==0)
|
||||
{
|
||||
_shaderHint = SHADER_GLES2;
|
||||
}
|
||||
else if (strcmp(ptr,"GLES3")==0)
|
||||
{
|
||||
_shaderHint = SHADER_GLES3;
|
||||
}
|
||||
else if (strcmp(ptr,"NONE")==0)
|
||||
{
|
||||
_shaderHint = SHADER_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( (ptr = getenv("OSG_KEYSTONE")) != 0)
|
||||
{
|
||||
if (strcmp(ptr,"OFF")==0)
|
||||
|
@ -40,13 +40,7 @@
|
||||
using namespace osg;
|
||||
|
||||
|
||||
#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"
|
||||
#else
|
||||
#define GLSL_VERSION_STR "300 es"
|
||||
@ -88,10 +82,7 @@ static const char* gl3_FragmentShader = {
|
||||
"}\n"
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if SHADERS_GL2
|
||||
static const char* gl2_VertexShader = {
|
||||
"// gl2_VertexShader\n"
|
||||
"#ifdef GL_ES\n"
|
||||
@ -120,7 +111,6 @@ static const char* gl2_FragmentShader = {
|
||||
" gl_FragColor = vertexColor * texture2D(baseTexture, texCoord);\n"
|
||||
"}\n"
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
extern osg::Texture2D* createDefaultTexture()
|
||||
@ -702,31 +692,30 @@ void StateSet::setGlobalDefaults()
|
||||
|
||||
OSG_INFO<<"void StateSet::setGlobalDefaults()"<<std::endl;
|
||||
|
||||
#if SHADERS_GL3
|
||||
osg::DisplaySettings::ShaderHint shaderHint = osg::DisplaySettings::instance()->getShaderHint();
|
||||
if (shaderHint==osg::DisplaySettings::SHADER_GL3 || shaderHint==osg::DisplaySettings::SHADER_GLES3)
|
||||
{
|
||||
OSG_INFO<<" StateSet::setGlobalDefaults() Setting up GL3 compatible shaders"<<std::endl;
|
||||
|
||||
OSG_INFO<<" StateSet::setGlobalDefaults() Setting up GL3 compatible shaders"<<std::endl;
|
||||
|
||||
osg::ref_ptr<osg::Program> 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"<<std::endl;
|
||||
|
||||
osg::ref_ptr<osg::Program> 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<osg::Program> 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"<<std::endl;
|
||||
|
||||
osg::ref_ptr<osg::Program> 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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>& 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"<<std::endl;
|
||||
OSG_INFO<<"Font::Font() Setting up GL3 compatible shaders"<<std::endl;
|
||||
|
||||
osg::ref_ptr<osg::Program> 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<osg::Program> 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"<<std::endl;
|
||||
|
||||
osg::ref_ptr<osg::Program> 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"<<std::endl;
|
||||
|
||||
#endif
|
||||
osg::ref_ptr<osg::Program> 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)
|
||||
|
@ -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"<<std::endl;
|
||||
OSG_INFO<<"StatsHandler::StatsHandler() Setting up GL3 compatible shaders"<<std::endl;
|
||||
|
||||
osg::ref_ptr<osg::Program> 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<osg::Program> 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"<<std::endl;
|
||||
|
||||
OSG_INFO<<"StatsHandler::StatsHandler() Setting up GL2 compatible shaders"<<std::endl;
|
||||
|
||||
osg::ref_ptr<osg::Program> 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"<<std::endl;
|
||||
#endif
|
||||
osg::ref_ptr<osg::Program> 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"<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void StatsHandler::collectWhichCamerasToRenderStatsFor(osgViewer::ViewerBase* viewer, osgViewer::ViewerBase::Cameras& cameras)
|
||||
|
Loading…
Reference in New Issue
Block a user