Backported GL2/3, GLES2/3 compatible Text and StatsHandler shaders to OSG-3.4
This commit is contained in:
@@ -34,6 +34,13 @@ using namespace std;
|
||||
|
||||
static osg::ApplicationUsageProxy Font_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_TEXT_INCREMENTAL_SUBLOADING <type>","ON | OFF");
|
||||
|
||||
#if (!defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GLES3_AVAILABLE))
|
||||
#define GLSL_VERSION_STR "330 core"
|
||||
#define GLYPH_CMP "r"
|
||||
#else
|
||||
#define GLSL_VERSION_STR "300 es"
|
||||
#define GLYPH_CMP "a"
|
||||
#endif
|
||||
|
||||
osg::ref_ptr<Font>& Font::getDefaultFont()
|
||||
{
|
||||
@@ -240,7 +247,109 @@ Font::Font(FontImplementation* implementation):
|
||||
|
||||
_texenv = new osg::TexEnv;
|
||||
_stateset = new osg::StateSet;
|
||||
|
||||
_stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
||||
_stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
|
||||
_stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
|
||||
|
||||
#if defined(OSG_GL_FIXED_FUNCTION_AVAILABLE)
|
||||
|
||||
OSG_INFO<<"Font::Font() Fixed function pipeline"<<std::endl;
|
||||
|
||||
_stateset->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON);
|
||||
#endif
|
||||
|
||||
#if defined(OSG_GL3_AVAILABLE) || defined(OSG_GLES3_AVAILABLE)
|
||||
{
|
||||
|
||||
OSG_INFO<<"Font::Font() Setting up GL3 compatible shaders"<<std::endl;
|
||||
|
||||
static const char* gl3_TextVertexShader = {
|
||||
"#version " GLSL_VERSION_STR "\n"
|
||||
"// gl3_TextVertexShader\n"
|
||||
"#ifdef GL_ES\n"
|
||||
" precision highp float;\n"
|
||||
"#endif\n"
|
||||
"in vec4 osg_Vertex;\n"
|
||||
"in vec4 osg_Color;\n"
|
||||
"in vec4 osg_MultiTexCoord0;\n"
|
||||
"uniform mat4 osg_ModelViewProjectionMatrix;\n"
|
||||
"out vec2 texCoord;\n"
|
||||
"out vec4 vertexColor;\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex;\n"
|
||||
" texCoord = osg_MultiTexCoord0.xy;\n"
|
||||
" vertexColor = osg_Color; \n"
|
||||
"}\n"
|
||||
};
|
||||
|
||||
static const char* gl3_TextFragmentShader = {
|
||||
"#version " GLSL_VERSION_STR "\n"
|
||||
"// gl3_TextFragmentShader\n"
|
||||
"#ifdef GL_ES\n"
|
||||
" precision highp float;\n"
|
||||
"#endif\n"
|
||||
"uniform sampler2D glyphTexture;\n"
|
||||
"in vec2 texCoord;\n"
|
||||
"in vec4 vertexColor;\n"
|
||||
"out vec4 color;\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" if (texCoord.x>=0.0) color = vertexColor * vec4(1.0, 1.0, 1.0, texture(glyphTexture, texCoord)." GLYPH_CMP ");\n"
|
||||
" else color = vertexColor;\n"
|
||||
"}\n"
|
||||
};
|
||||
|
||||
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 defined(OSG_GL2_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
|
||||
{
|
||||
OSG_INFO<<"Font::Font() Setting up GL2 compatible shaders"<<std::endl;
|
||||
|
||||
static const char* gl2_TextVertexShader = {
|
||||
"// gl2_TextVertexShader\n"
|
||||
"#ifdef GL_ES\n"
|
||||
" precision highp float;\n"
|
||||
"#endif\n"
|
||||
"varying vec2 texCoord;\n"
|
||||
"varying vec4 vertexColor;\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
|
||||
" texCoord = gl_MultiTexCoord0.xy;\n"
|
||||
" vertexColor = gl_Color; \n"
|
||||
"}\n"
|
||||
};
|
||||
|
||||
static const char* gl2_TextFragmentShader = {
|
||||
"// gl2_TextFragmentShader\n"
|
||||
"#ifdef GL_ES\n"
|
||||
" precision highp float;\n"
|
||||
"#endif\n"
|
||||
"uniform sampler2D glyphTexture;\n"
|
||||
"varying vec2 texCoord;\n"
|
||||
"varying vec4 vertexColor;\n"
|
||||
"void main(void)\n"
|
||||
"{\n"
|
||||
" if (texCoord.x>=0.0) gl_FragColor = vertexColor * vec4(1.0, 1.0, 1.0, texture2D(glyphTexture, texCoord).a);\n"
|
||||
" else gl_FragColor = vertexColor;\n"
|
||||
"}\n"
|
||||
};
|
||||
|
||||
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));
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
char *ptr;
|
||||
if( (ptr = getenv("OSG_MAX_TEXTURE_SIZE")) != 0)
|
||||
|
||||
Reference in New Issue
Block a user