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; }
|
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; }
|
void setKeystoneHint(bool enabled) { _keystoneHint = enabled; }
|
||||||
bool getKeystoneHint() const { return _keystoneHint; }
|
bool getKeystoneHint() const { return _keystoneHint; }
|
||||||
|
|
||||||
@ -323,7 +336,8 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced
|
|||||||
Objects& getKeystones() { return _keystones; }
|
Objects& getKeystones() { return _keystones; }
|
||||||
const Objects& getKeystones() const { return _keystones; }
|
const Objects& getKeystones() const { return _keystones; }
|
||||||
|
|
||||||
enum OSXMenubarBehavior {
|
enum OSXMenubarBehavior
|
||||||
|
{
|
||||||
MENUBAR_AUTO_HIDE,
|
MENUBAR_AUTO_HIDE,
|
||||||
MENUBAR_FORCE_HIDE,
|
MENUBAR_FORCE_HIDE,
|
||||||
MENUBAR_FORCE_SHOW
|
MENUBAR_FORCE_SHOW
|
||||||
@ -400,6 +414,7 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced
|
|||||||
unsigned int _syncSwapBuffers;
|
unsigned int _syncSwapBuffers;
|
||||||
|
|
||||||
VertexBufferHint _vertexBufferHint;
|
VertexBufferHint _vertexBufferHint;
|
||||||
|
ShaderHint _shaderHint;
|
||||||
|
|
||||||
bool _keystoneHint;
|
bool _keystoneHint;
|
||||||
FileNames _keystoneFileNames;
|
FileNames _keystoneFileNames;
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include <osg/ApplicationUsage>
|
#include <osg/ApplicationUsage>
|
||||||
#include <osg/Math>
|
#include <osg/Math>
|
||||||
#include <osg/Notify>
|
#include <osg/Notify>
|
||||||
|
#include <osg/GL>
|
||||||
#include <osg/ref_ptr>
|
#include <osg/ref_ptr>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -117,6 +118,7 @@ void DisplaySettings::setDisplaySettings(const DisplaySettings& vs)
|
|||||||
_swapMethod = vs._swapMethod;
|
_swapMethod = vs._swapMethod;
|
||||||
|
|
||||||
_vertexBufferHint = vs._vertexBufferHint;
|
_vertexBufferHint = vs._vertexBufferHint;
|
||||||
|
_shaderHint = vs._shaderHint;
|
||||||
|
|
||||||
_keystoneHint = vs._keystoneHint;
|
_keystoneHint = vs._keystoneHint;
|
||||||
_keystoneFileNames = vs._keystoneFileNames;
|
_keystoneFileNames = vs._keystoneFileNames;
|
||||||
@ -247,6 +249,24 @@ void DisplaySettings::setDefaults()
|
|||||||
// _vertexBufferHint = VERTEX_BUFFER_OBJECT;
|
// _vertexBufferHint = VERTEX_BUFFER_OBJECT;
|
||||||
// _vertexBufferHint = VERTEX_ARRAY_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;
|
_keystoneHint = false;
|
||||||
|
|
||||||
_OSXMenubarBehavior = MENUBAR_AUTO_HIDE;
|
_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( (ptr = getenv("OSG_KEYSTONE")) != 0)
|
||||||
{
|
{
|
||||||
if (strcmp(ptr,"OFF")==0)
|
if (strcmp(ptr,"OFF")==0)
|
||||||
|
@ -40,13 +40,7 @@
|
|||||||
using namespace osg;
|
using namespace osg;
|
||||||
|
|
||||||
|
|
||||||
#define SHADERS_GL3 (defined(OSG_GL3_AVAILABLE) || defined(OSG_GLES3_AVAILABLE))
|
#if (!defined(OSG_GLES2_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
|
|
||||||
#define GLSL_VERSION_STR "330 core"
|
#define GLSL_VERSION_STR "330 core"
|
||||||
#else
|
#else
|
||||||
#define GLSL_VERSION_STR "300 es"
|
#define GLSL_VERSION_STR "300 es"
|
||||||
@ -88,10 +82,7 @@ static const char* gl3_FragmentShader = {
|
|||||||
"}\n"
|
"}\n"
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if SHADERS_GL2
|
|
||||||
static const char* gl2_VertexShader = {
|
static const char* gl2_VertexShader = {
|
||||||
"// gl2_VertexShader\n"
|
"// gl2_VertexShader\n"
|
||||||
"#ifdef GL_ES\n"
|
"#ifdef GL_ES\n"
|
||||||
@ -120,7 +111,6 @@ static const char* gl2_FragmentShader = {
|
|||||||
" gl_FragColor = vertexColor * texture2D(baseTexture, texCoord);\n"
|
" gl_FragColor = vertexColor * texture2D(baseTexture, texCoord);\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
extern osg::Texture2D* createDefaultTexture()
|
extern osg::Texture2D* createDefaultTexture()
|
||||||
@ -702,8 +692,9 @@ void StateSet::setGlobalDefaults()
|
|||||||
|
|
||||||
OSG_INFO<<"void StateSet::setGlobalDefaults()"<<std::endl;
|
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;
|
osg::ref_ptr<osg::Program> program = new osg::Program;
|
||||||
@ -712,8 +703,9 @@ void StateSet::setGlobalDefaults()
|
|||||||
setAttributeAndModes(program.get());
|
setAttributeAndModes(program.get());
|
||||||
setTextureAttribute(0, createDefaultTexture());
|
setTextureAttribute(0, createDefaultTexture());
|
||||||
addUniform(new osg::Uniform("baseTexture", 0));
|
addUniform(new osg::Uniform("baseTexture", 0));
|
||||||
|
}
|
||||||
#elif SHADERS_GL2
|
else if (shaderHint==osg::DisplaySettings::SHADER_GL2 || shaderHint==osg::DisplaySettings::SHADER_GLES2)
|
||||||
|
{
|
||||||
|
|
||||||
OSG_INFO<<" StateSet::setGlobalDefaults() Setting up GL2 compatible shaders"<<std::endl;
|
OSG_INFO<<" StateSet::setGlobalDefaults() Setting up GL2 compatible shaders"<<std::endl;
|
||||||
|
|
||||||
@ -723,10 +715,7 @@ void StateSet::setGlobalDefaults()
|
|||||||
setAttributeAndModes(program.get());
|
setAttributeAndModes(program.get());
|
||||||
setTextureAttribute(0, createDefaultTexture());
|
setTextureAttribute(0, createDefaultTexture());
|
||||||
addUniform(new osg::Uniform("baseTexture", 0));
|
addUniform(new osg::Uniform("baseTexture", 0));
|
||||||
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,13 +32,7 @@
|
|||||||
using namespace osgText;
|
using namespace osgText;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define SHADERS_GL3 (defined(OSG_GL3_AVAILABLE) || defined(OSG_GLES3_AVAILABLE))
|
#if (!defined(OSG_GLES2_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
|
|
||||||
#define GLSL_VERSION_STR "330 core"
|
#define GLSL_VERSION_STR "330 core"
|
||||||
#define GLYPH_CMP "r"
|
#define GLYPH_CMP "r"
|
||||||
#else
|
#else
|
||||||
@ -83,10 +77,6 @@ static const char* gl3_TextFragmentShader = {
|
|||||||
"}\n"
|
"}\n"
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if SHADERS_GL2
|
|
||||||
static const char* gl2_TextVertexShader = {
|
static const char* gl2_TextVertexShader = {
|
||||||
"// gl2_TextVertexShader\n"
|
"// gl2_TextVertexShader\n"
|
||||||
"#ifdef GL_ES\n"
|
"#ifdef GL_ES\n"
|
||||||
@ -116,7 +106,6 @@ static const char* gl2_TextFragmentShader = {
|
|||||||
" else gl_FragColor = vertexColor;\n"
|
" else gl_FragColor = vertexColor;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
osg::ref_ptr<Font>& Font::getDefaultFont()
|
osg::ref_ptr<Font>& Font::getDefaultFont()
|
||||||
{
|
{
|
||||||
@ -335,7 +324,9 @@ Font::Font(FontImplementation* implementation):
|
|||||||
_stateset->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON);
|
_stateset->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON);
|
||||||
#endif
|
#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;
|
||||||
|
|
||||||
@ -345,7 +336,10 @@ Font::Font(FontImplementation* implementation):
|
|||||||
_stateset->setAttributeAndModes(program.get());
|
_stateset->setAttributeAndModes(program.get());
|
||||||
_stateset->addUniform(new osg::Uniform("glyphTexture", 0));
|
_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_INFO<<"Font::Font() Setting up GL2 compatible shaders"<<std::endl;
|
||||||
|
|
||||||
@ -355,7 +349,7 @@ Font::Font(FontImplementation* implementation):
|
|||||||
_stateset->setAttributeAndModes(program.get());
|
_stateset->setAttributeAndModes(program.get());
|
||||||
_stateset->addUniform(new osg::Uniform("glyphTexture", 0));
|
_stateset->addUniform(new osg::Uniform("glyphTexture", 0));
|
||||||
|
|
||||||
#endif
|
}
|
||||||
|
|
||||||
char *ptr;
|
char *ptr;
|
||||||
if( (ptr = getenv("OSG_MAX_TEXTURE_SIZE")) != 0)
|
if( (ptr = getenv("OSG_MAX_TEXTURE_SIZE")) != 0)
|
||||||
|
@ -28,13 +28,14 @@
|
|||||||
namespace osgViewer
|
namespace osgViewer
|
||||||
{
|
{
|
||||||
|
|
||||||
#define FIXED_FUNCTION defined(OSG_GL_FIXED_FUNCTION_AVAILABLE)
|
#if (!defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GLES3_AVAILABLE))
|
||||||
#define SHADERS_GL3 (defined(OSG_GL3_AVAILABLE))
|
#define GLSL_VERSION_STR "330 core"
|
||||||
#define SHADERS_GL2 !FIXED_FUNCTION && !SHADERS_GL3
|
#else
|
||||||
|
#define GLSL_VERSION_STR "300 es"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if SHADERS_GL3
|
|
||||||
static const char* gl3_StatsVertexShader = {
|
static const char* gl3_StatsVertexShader = {
|
||||||
"#version 330 core\n"
|
"#version " GLSL_VERSION_STR "\n"
|
||||||
"// gl3_StatsVertexShader\n"
|
"// gl3_StatsVertexShader\n"
|
||||||
"#ifdef GL_ES\n"
|
"#ifdef GL_ES\n"
|
||||||
" precision highp float;\n"
|
" precision highp float;\n"
|
||||||
@ -51,7 +52,7 @@ static const char* gl3_StatsVertexShader = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const char* gl3_StatsFragmentShader = {
|
static const char* gl3_StatsFragmentShader = {
|
||||||
"#version 330 core\n"
|
"#version " GLSL_VERSION_STR "\n"
|
||||||
"// gl3_StatsFragmentShader\n"
|
"// gl3_StatsFragmentShader\n"
|
||||||
"#ifdef GL_ES\n"
|
"#ifdef GL_ES\n"
|
||||||
" precision highp float;\n"
|
" precision highp float;\n"
|
||||||
@ -64,10 +65,6 @@ static const char* gl3_StatsFragmentShader = {
|
|||||||
"}\n"
|
"}\n"
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if SHADERS_GL2
|
|
||||||
static const char* gl2_StatsVertexShader = {
|
static const char* gl2_StatsVertexShader = {
|
||||||
"// gl2_StatsVertexShader\n"
|
"// gl2_StatsVertexShader\n"
|
||||||
"#ifdef GL_ES\n"
|
"#ifdef GL_ES\n"
|
||||||
@ -92,7 +89,6 @@ static const char* gl2_StatsFragmentShader = {
|
|||||||
" gl_FragColor = vertexColor;\n"
|
" gl_FragColor = vertexColor;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
StatsHandler::StatsHandler():
|
StatsHandler::StatsHandler():
|
||||||
_keyEventTogglesOnScreenStats('s'),
|
_keyEventTogglesOnScreenStats('s'),
|
||||||
@ -121,7 +117,9 @@ StatsHandler::StatsHandler():
|
|||||||
_camera->setRenderer(new Renderer(_camera.get()));
|
_camera->setRenderer(new Renderer(_camera.get()));
|
||||||
_camera->setProjectionResizePolicy(osg::Camera::FIXED);
|
_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;
|
||||||
|
|
||||||
@ -129,8 +127,9 @@ StatsHandler::StatsHandler():
|
|||||||
program->addShader(new osg::Shader(osg::Shader::VERTEX, gl3_StatsVertexShader));
|
program->addShader(new osg::Shader(osg::Shader::VERTEX, gl3_StatsVertexShader));
|
||||||
program->addShader(new osg::Shader(osg::Shader::FRAGMENT, gl3_StatsFragmentShader));
|
program->addShader(new osg::Shader(osg::Shader::FRAGMENT, gl3_StatsFragmentShader));
|
||||||
_camera->getOrCreateStateSet()->setAttributeAndModes(program.get());
|
_camera->getOrCreateStateSet()->setAttributeAndModes(program.get());
|
||||||
|
}
|
||||||
#elif SHADERS_GL2
|
else if (shaderHint==osg::DisplaySettings::SHADER_GL2 || shaderHint==osg::DisplaySettings::SHADER_GLES2)
|
||||||
|
{
|
||||||
|
|
||||||
OSG_INFO<<"StatsHandler::StatsHandler() Setting up GL2 compatible shaders"<<std::endl;
|
OSG_INFO<<"StatsHandler::StatsHandler() Setting up GL2 compatible shaders"<<std::endl;
|
||||||
|
|
||||||
@ -138,9 +137,11 @@ StatsHandler::StatsHandler():
|
|||||||
program->addShader(new osg::Shader(osg::Shader::VERTEX, gl2_StatsVertexShader));
|
program->addShader(new osg::Shader(osg::Shader::VERTEX, gl2_StatsVertexShader));
|
||||||
program->addShader(new osg::Shader(osg::Shader::FRAGMENT, gl2_StatsFragmentShader));
|
program->addShader(new osg::Shader(osg::Shader::FRAGMENT, gl2_StatsFragmentShader));
|
||||||
_camera->getOrCreateStateSet()->setAttributeAndModes(program.get());
|
_camera->getOrCreateStateSet()->setAttributeAndModes(program.get());
|
||||||
#else
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
OSG_INFO<<"StatsHandler::StatsHandler() Fixed pipeline"<<std::endl;
|
OSG_INFO<<"StatsHandler::StatsHandler() Fixed pipeline"<<std::endl;
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatsHandler::collectWhichCamerasToRenderStatsFor(osgViewer::ViewerBase* viewer, osgViewer::ViewerBase::Cameras& cameras)
|
void StatsHandler::collectWhichCamerasToRenderStatsFor(osgViewer::ViewerBase* viewer, osgViewer::ViewerBase::Cameras& cameras)
|
||||||
|
Loading…
Reference in New Issue
Block a user