Adusted Font shaders to use gl3 path on gles3, iphone example using inbuilt shaders

This commit is contained in:
Thomas Hogarth
2017-03-20 19:35:01 +00:00
parent b493657c47
commit 630af80635
4 changed files with 115 additions and 624 deletions

View File

@@ -18,7 +18,6 @@
// global programs
osg::ref_ptr<osg::Program> _vertColorProgram;
osg::ref_ptr<osg::Program> _textProgram;
@interface MyViewController : UIViewController
@@ -85,10 +84,7 @@ osg::Camera* createHUD(unsigned int w, unsigned int h)
text->setPosition(position);
text->setText("A simple multi-touch-example\n1 touch = rotate, \n2 touches = drag + scale, \n3 touches = home");
text->setColor(osg::Vec4(0.9,0.1,0.1,1.0));
#if defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE)
text->getOrCreateStateSet()->setAttributeAndModes(_textProgram, osg::StateAttribute::ON);
text->getOrCreateStateSet()->addUniform(new osg::Uniform("glyphTexture",0));
#endif
geode->addDrawable( text );
}
@@ -137,10 +133,6 @@ private:
text->setPosition(osg::Vec3(110,0,0));
text->setDataVariance(osg::Object::DYNAMIC);
text->setText(ss.str());
#if defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE)
text->getOrCreateStateSet()->setAttributeAndModes(_textProgram, osg::StateAttribute::ON);
text->getOrCreateStateSet()->addUniform(new osg::Uniform("glyphTexture",0));
#endif
geode->addDrawable( text );
@@ -328,10 +320,6 @@ private:
// create our default programs
#if defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE)
_textProgram = new osg::Program();
_textProgram->addShader( new osg::Shader(osg::Shader::VERTEX, TextShaderVert));
_textProgram->addShader( new osg::Shader(osg::Shader::FRAGMENT, TextShaderFrag));
_vertColorProgram = new osg::Program();
_vertColorProgram->addShader( new osg::Shader(osg::Shader::VERTEX, ColorShaderVert));
_vertColorProgram->addShader( new osg::Shader(osg::Shader::FRAGMENT, ColorShaderFrag));

View File

@@ -57,68 +57,3 @@ const char* ColorShaderFrag = NULL;
#endif
//
// text shader
//
#if OSG_GLES3_FEATURES
const char* TextShaderVert =
"#version 300 es\n"
"in vec4 osg_Vertex;\n"
"in vec4 osg_Color;\n"
"in vec4 osg_MultiTexCoord0;\n"
"uniform mat4 osg_ModelViewProjectionMatrix;\n"
"out vec4 vertColor;\n"
"out vec4 texCoord;\n"
"void main()\n"
"{\n"
" gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex;\n"
" vertColor = osg_Color;\n"
" texCoord = osg_MultiTexCoord0;\n"
"}\n";
const char* TextShaderFrag =
"#version 300 es\n"
"in lowp vec4 vertColor;\n"
"in lowp vec4 texCoord;\n"
"uniform sampler2D glyphTexture;\n"
"out lowp vec4 fragColor;\n"
"void main()\n"
"{\n"
" fragColor = vertColor * texture(glyphTexture, texCoord.xy).a;\n"
"}\n";
#elif OSG_GLES2_FEATURES
const char* TextShaderVert =
"#version 100\n"
"attribute vec4 osg_Vertex;\n"
"attribute vec4 osg_Color;\n"
"attribute vec4 osg_MultiTexCoord0;\n"
"uniform mat4 osg_ModelViewProjectionMatrix;\n"
"varying vec4 vertColor;\n"
"varying vec4 texCoord;\n"
"void main()\n"
"{\n"
" gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex;\n"
" vertColor = osg_Color;\n"
" texCoord = osg_MultiTexCoord0;\n"
"}\n";
const char* TextShaderFrag =
"#version 100\n"
"varying lowp vec4 vertColor;\n"
"varying lowp vec4 texCoord;\n"
"uniform sampler2D glyphTexture;\n"
"void main()\n"
"{\n"
" gl_FragColor = vertColor * texture2D(glyphTexture, texCoord.xy).a;\n"
"}\n";
#else
const char* TextShaderVert = NULL;
const char* TextShaderFrag = NULL;
#endif