2007-06-12 22:20:16 +08:00
|
|
|
/* OpenSceneGraph example, osgshaders.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
2003-07-15 18:45:46 +08:00
|
|
|
*/
|
|
|
|
|
2006-06-08 20:07:11 +08:00
|
|
|
/* file: examples/osgshaders/GL2Scene.cpp
|
|
|
|
* author: Mike Weiblen 2005-05-01
|
2003-07-15 18:45:46 +08:00
|
|
|
*
|
|
|
|
* Compose a scene of several instances of a model, with a different
|
|
|
|
* OpenGL Shading Language shader applied to each.
|
|
|
|
*
|
|
|
|
* See http://www.3dlabs.com/opengl2/ for more information regarding
|
|
|
|
* the OpenGL Shading Language.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <osg/ShapeDrawable>
|
|
|
|
#include <osg/PositionAttitudeTransform>
|
|
|
|
#include <osg/Geode>
|
2003-10-05 19:30:54 +08:00
|
|
|
#include <osg/Node>
|
|
|
|
#include <osg/Material>
|
2003-07-15 18:45:46 +08:00
|
|
|
#include <osg/Notify>
|
2003-10-05 19:30:54 +08:00
|
|
|
#include <osg/Vec3>
|
|
|
|
#include <osg/Texture1D>
|
|
|
|
#include <osg/Texture2D>
|
|
|
|
#include <osg/Texture3D>
|
2003-07-15 18:45:46 +08:00
|
|
|
#include <osgDB/ReadFile>
|
|
|
|
#include <osgUtil/Optimizer>
|
2005-04-08 04:20:09 +08:00
|
|
|
|
|
|
|
#include <osg/Program>
|
|
|
|
#include <osg/Shader>
|
|
|
|
#include <osg/Uniform>
|
2011-12-14 05:14:33 +08:00
|
|
|
#include <osgUtil/PerlinNoise>
|
2003-07-15 18:45:46 +08:00
|
|
|
|
2005-04-13 22:31:25 +08:00
|
|
|
#include <iostream>
|
|
|
|
|
2003-10-05 19:30:54 +08:00
|
|
|
#include "GL2Scene.h"
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static osg::Image*
|
|
|
|
make1DSineImage( int texSize )
|
|
|
|
{
|
|
|
|
const float PI = 3.1415927;
|
|
|
|
|
|
|
|
osg::Image* image = new osg::Image;
|
|
|
|
image->setImage(texSize, 1, 1,
|
2005-05-02 17:34:27 +08:00
|
|
|
4, GL_RGBA, GL_UNSIGNED_BYTE,
|
|
|
|
new unsigned char[4 * texSize],
|
|
|
|
osg::Image::USE_NEW_DELETE);
|
2003-10-05 19:30:54 +08:00
|
|
|
|
|
|
|
GLubyte* ptr = image->data();
|
|
|
|
float inc = 2. * PI / (float)texSize;
|
|
|
|
for(int i = 0; i < texSize; i++)
|
|
|
|
{
|
2005-05-02 17:34:27 +08:00
|
|
|
*ptr++ = (GLubyte)((sinf(i * inc) * 0.5 + 0.5) * 255.);
|
|
|
|
*ptr++ = 0;
|
|
|
|
*ptr++ = 0;
|
|
|
|
*ptr++ = 1;
|
2003-10-05 19:30:54 +08:00
|
|
|
}
|
2005-05-02 17:34:27 +08:00
|
|
|
return image;
|
2003-10-05 19:30:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static osg::Texture1D*
|
|
|
|
make1DSineTexture( int texSize )
|
|
|
|
{
|
|
|
|
osg::Texture1D* sineTexture = new osg::Texture1D;
|
|
|
|
sineTexture->setWrap(osg::Texture1D::WRAP_S, osg::Texture1D::REPEAT);
|
|
|
|
sineTexture->setFilter(osg::Texture1D::MIN_FILTER, osg::Texture1D::LINEAR);
|
|
|
|
sineTexture->setFilter(osg::Texture1D::MAG_FILTER, osg::Texture1D::LINEAR);
|
|
|
|
sineTexture->setImage( make1DSineImage(texSize) );
|
|
|
|
return sineTexture;
|
|
|
|
}
|
2003-07-15 18:45:46 +08:00
|
|
|
|
2003-10-05 19:30:54 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2005-05-02 17:34:27 +08:00
|
|
|
// in-line GLSL source code for the "microshader" example
|
2003-07-15 18:45:46 +08:00
|
|
|
|
|
|
|
static const char *microshaderVertSource = {
|
2005-05-02 17:34:27 +08:00
|
|
|
"// microshader - colors a fragment based on its position\n"
|
|
|
|
"varying vec4 color;\n"
|
|
|
|
"void main(void)\n"
|
|
|
|
"{\n"
|
|
|
|
" color = gl_Vertex;\n"
|
|
|
|
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
|
|
|
|
"}\n"
|
2003-07-15 18:45:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *microshaderFragSource = {
|
2005-05-02 17:34:27 +08:00
|
|
|
"varying vec4 color;\n"
|
|
|
|
"void main(void)\n"
|
|
|
|
"{\n"
|
|
|
|
" gl_FragColor = clamp( color, 0.0, 1.0 );\n"
|
|
|
|
"}\n"
|
2003-07-15 18:45:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2003-10-05 19:30:54 +08:00
|
|
|
static osg::ref_ptr<osg::Group> rootNode;
|
2003-07-15 18:45:46 +08:00
|
|
|
|
2006-05-15 23:46:08 +08:00
|
|
|
// Create some geometry upon which to render GLSL shaders.
|
2003-07-15 18:45:46 +08:00
|
|
|
static osg::Geode*
|
|
|
|
CreateModel()
|
|
|
|
{
|
|
|
|
osg::Geode* geode = new osg::Geode();
|
|
|
|
geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),1.0f)));
|
|
|
|
geode->addDrawable(new osg::ShapeDrawable(new osg::Cone(osg::Vec3(2.2f,0.0f,-0.4f),0.9f,1.8f)));
|
|
|
|
geode->addDrawable(new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(4.4f,0.0f,0.0f),1.0f,1.4f)));
|
|
|
|
return geode;
|
|
|
|
}
|
|
|
|
|
2003-10-05 19:30:54 +08:00
|
|
|
// Add a reference to the masterModel at the specified translation, and
|
|
|
|
// return its StateSet so we can easily attach StateAttributes.
|
|
|
|
static osg::StateSet*
|
|
|
|
ModelInstance()
|
|
|
|
{
|
|
|
|
static float zvalue = 0.0f;
|
|
|
|
static osg::Node* masterModel = CreateModel();
|
|
|
|
|
|
|
|
osg::PositionAttitudeTransform* xform = new osg::PositionAttitudeTransform();
|
|
|
|
xform->setPosition(osg::Vec3( 0.0f, -1.0f, zvalue ));
|
|
|
|
zvalue = zvalue + 2.2f;
|
|
|
|
xform->addChild(masterModel);
|
|
|
|
rootNode->addChild(xform);
|
|
|
|
return xform->getOrCreateStateSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
// load source from a file.
|
2003-07-15 18:45:46 +08:00
|
|
|
static void
|
2005-04-08 04:20:09 +08:00
|
|
|
LoadShaderSource( osg::Shader* shader, const std::string& fileName )
|
2003-07-15 18:45:46 +08:00
|
|
|
{
|
2017-11-28 02:38:37 +08:00
|
|
|
osg::ref_ptr<osg::Shader> loaded_shader = osgDB::readRefShaderFile(fileName);
|
|
|
|
if (loaded_shader)
|
2003-07-15 18:45:46 +08:00
|
|
|
{
|
2017-11-28 02:38:37 +08:00
|
|
|
shader->setShaderSource( loaded_shader->getShaderSource() );
|
2003-07-15 18:45:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-05-02 17:34:27 +08:00
|
|
|
osg::notify(osg::WARN) << "File \"" << fileName << "\" not found." << std::endl;
|
2003-07-15 18:45:46 +08:00
|
|
|
}
|
2003-10-05 19:30:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// rude but convenient globals
|
|
|
|
|
2005-04-08 04:20:09 +08:00
|
|
|
static osg::Program* BlockyProgram;
|
|
|
|
static osg::Shader* BlockyVertObj;
|
|
|
|
static osg::Shader* BlockyFragObj;
|
|
|
|
|
|
|
|
static osg::Program* ErodedProgram;
|
|
|
|
static osg::Shader* ErodedVertObj;
|
|
|
|
static osg::Shader* ErodedFragObj;
|
2003-10-05 19:30:54 +08:00
|
|
|
|
2005-04-08 04:20:09 +08:00
|
|
|
static osg::Program* MarbleProgram;
|
|
|
|
static osg::Shader* MarbleVertObj;
|
|
|
|
static osg::Shader* MarbleFragObj;
|
2003-10-05 19:30:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2005-04-25 21:37:12 +08:00
|
|
|
// for demo simplicity, this one callback animates all the shaders, instancing
|
|
|
|
// for each uniform but with a specific operation each time.
|
2003-10-05 19:30:54 +08:00
|
|
|
|
2015-06-03 17:07:41 +08:00
|
|
|
class AnimateCallback: public osg::UniformCallback
|
2003-10-05 19:30:54 +08:00
|
|
|
{
|
|
|
|
public:
|
2005-04-25 21:37:12 +08:00
|
|
|
|
|
|
|
enum Operation
|
|
|
|
{
|
|
|
|
OFFSET,
|
|
|
|
SIN,
|
|
|
|
COLOR1,
|
|
|
|
COLOR2
|
|
|
|
};
|
|
|
|
|
2005-05-02 17:34:27 +08:00
|
|
|
AnimateCallback(Operation op) : _enabled(true),_operation(op) {}
|
|
|
|
|
|
|
|
virtual void operator() ( osg::Uniform* uniform, osg::NodeVisitor* nv )
|
|
|
|
{
|
|
|
|
if( _enabled )
|
|
|
|
{
|
2007-01-25 20:02:51 +08:00
|
|
|
float angle = 2.0 * nv->getFrameStamp()->getSimulationTime();
|
2005-05-02 17:34:27 +08:00
|
|
|
float sine = sinf( angle ); // -1 -> 1
|
|
|
|
float v01 = 0.5f * sine + 0.5f; // 0 -> 1
|
|
|
|
float v10 = 1.0f - v01; // 1 -> 0
|
2005-04-25 21:37:12 +08:00
|
|
|
switch(_operation)
|
|
|
|
{
|
|
|
|
case OFFSET : uniform->set( osg::Vec3(0.505f, 0.8f*v01, 0.0f) ); break;
|
|
|
|
case SIN : uniform->set( sine ); break;
|
|
|
|
case COLOR1 : uniform->set( osg::Vec3(v10, 0.0f, 0.0f) ); break;
|
2005-05-02 17:34:27 +08:00
|
|
|
case COLOR2 : uniform->set( osg::Vec3(v01, v01, v10) ); break;
|
2005-04-25 21:37:12 +08:00
|
|
|
}
|
2005-05-02 17:34:27 +08:00
|
|
|
}
|
|
|
|
}
|
2003-10-05 19:30:54 +08:00
|
|
|
|
|
|
|
private:
|
2005-05-02 17:34:27 +08:00
|
|
|
bool _enabled;
|
2005-04-25 21:37:12 +08:00
|
|
|
Operation _operation;
|
2003-10-05 19:30:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2006-05-15 23:46:08 +08:00
|
|
|
// Compose a scenegraph with examples of GLSL shaders
|
2003-10-05 19:30:54 +08:00
|
|
|
|
2005-05-02 17:34:27 +08:00
|
|
|
#define TEXUNIT_SINE 1
|
|
|
|
#define TEXUNIT_NOISE 2
|
2004-09-26 18:27:25 +08:00
|
|
|
|
2003-10-05 19:30:54 +08:00
|
|
|
osg::ref_ptr<osg::Group>
|
|
|
|
GL2Scene::buildScene()
|
|
|
|
{
|
2011-12-14 05:14:33 +08:00
|
|
|
osg::Texture3D* noiseTexture = osgUtil::create3DNoiseTexture( 32 /*128*/ );
|
2003-10-05 19:30:54 +08:00
|
|
|
osg::Texture1D* sineTexture = make1DSineTexture( 32 /*1024*/ );
|
|
|
|
|
|
|
|
// the root of our scenegraph.
|
|
|
|
rootNode = new osg::Group;
|
|
|
|
|
2005-04-08 04:20:09 +08:00
|
|
|
// attach some Uniforms to the root, to be inherited by Programs.
|
|
|
|
{
|
2005-05-02 17:34:27 +08:00
|
|
|
osg::Uniform* OffsetUniform = new osg::Uniform( "Offset", osg::Vec3(0.0f, 0.0f, 0.0f) );
|
|
|
|
osg::Uniform* SineUniform = new osg::Uniform( "Sine", 0.0f );
|
|
|
|
osg::Uniform* Color1Uniform = new osg::Uniform( "Color1", osg::Vec3(0.0f, 0.0f, 0.0f) );
|
|
|
|
osg::Uniform* Color2Uniform = new osg::Uniform( "Color2", osg::Vec3(0.0f, 0.0f, 0.0f) );
|
2005-04-25 21:37:12 +08:00
|
|
|
|
|
|
|
OffsetUniform->setUpdateCallback(new AnimateCallback(AnimateCallback::OFFSET));
|
|
|
|
SineUniform->setUpdateCallback(new AnimateCallback(AnimateCallback::SIN));
|
|
|
|
Color1Uniform->setUpdateCallback(new AnimateCallback(AnimateCallback::COLOR1));
|
|
|
|
Color2Uniform->setUpdateCallback(new AnimateCallback(AnimateCallback::COLOR2));
|
2005-04-08 04:20:09 +08:00
|
|
|
|
2005-05-02 17:34:27 +08:00
|
|
|
osg::StateSet* ss = rootNode->getOrCreateStateSet();
|
|
|
|
ss->addUniform( OffsetUniform );
|
|
|
|
ss->addUniform( SineUniform );
|
|
|
|
ss->addUniform( Color1Uniform );
|
|
|
|
ss->addUniform( Color2Uniform );
|
2005-04-08 04:20:09 +08:00
|
|
|
}
|
|
|
|
|
2003-10-05 19:30:54 +08:00
|
|
|
// the simple Microshader (its source appears earlier in this file)
|
2003-07-15 18:45:46 +08:00
|
|
|
{
|
2005-05-02 17:34:27 +08:00
|
|
|
osg::StateSet* ss = ModelInstance();
|
|
|
|
osg::Program* program = new osg::Program;
|
|
|
|
program->setName( "microshader" );
|
|
|
|
_programList.push_back( program );
|
|
|
|
program->addShader( new osg::Shader( osg::Shader::VERTEX, microshaderVertSource ) );
|
|
|
|
program->addShader( new osg::Shader( osg::Shader::FRAGMENT, microshaderFragSource ) );
|
|
|
|
ss->setAttributeAndModes( program, osg::StateAttribute::ON );
|
2003-07-15 18:45:46 +08:00
|
|
|
}
|
2003-10-05 19:30:54 +08:00
|
|
|
|
|
|
|
// the "blocky" shader, a simple animation test
|
|
|
|
{
|
2005-05-02 17:34:27 +08:00
|
|
|
osg::StateSet* ss = ModelInstance();
|
|
|
|
BlockyProgram = new osg::Program;
|
|
|
|
BlockyProgram->setName( "blocky" );
|
|
|
|
_programList.push_back( BlockyProgram );
|
|
|
|
BlockyVertObj = new osg::Shader( osg::Shader::VERTEX );
|
|
|
|
BlockyFragObj = new osg::Shader( osg::Shader::FRAGMENT );
|
|
|
|
BlockyProgram->addShader( BlockyFragObj );
|
|
|
|
BlockyProgram->addShader( BlockyVertObj );
|
|
|
|
ss->setAttributeAndModes(BlockyProgram, osg::StateAttribute::ON);
|
2003-10-05 19:30:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// the "eroded" shader, uses a noise texture to discard fragments
|
|
|
|
{
|
2005-05-02 17:34:27 +08:00
|
|
|
osg::StateSet* ss = ModelInstance();
|
|
|
|
ss->setTextureAttribute(TEXUNIT_NOISE, noiseTexture);
|
|
|
|
ErodedProgram = new osg::Program;
|
|
|
|
ErodedProgram->setName( "eroded" );
|
|
|
|
_programList.push_back( ErodedProgram );
|
|
|
|
ErodedVertObj = new osg::Shader( osg::Shader::VERTEX );
|
|
|
|
ErodedFragObj = new osg::Shader( osg::Shader::FRAGMENT );
|
|
|
|
ErodedProgram->addShader( ErodedFragObj );
|
|
|
|
ErodedProgram->addShader( ErodedVertObj );
|
|
|
|
ss->setAttributeAndModes(ErodedProgram, osg::StateAttribute::ON);
|
|
|
|
|
|
|
|
ss->addUniform( new osg::Uniform("LightPosition", osg::Vec3(0.0f, 0.0f, 4.0f)) );
|
|
|
|
ss->addUniform( new osg::Uniform("Scale", 1.0f) );
|
|
|
|
ss->addUniform( new osg::Uniform("sampler3d", TEXUNIT_NOISE) );
|
2003-10-05 19:30:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// the "marble" shader, uses two textures
|
|
|
|
{
|
2005-05-02 17:34:27 +08:00
|
|
|
osg::StateSet* ss = ModelInstance();
|
|
|
|
ss->setTextureAttribute(TEXUNIT_NOISE, noiseTexture);
|
|
|
|
ss->setTextureAttribute(TEXUNIT_SINE, sineTexture);
|
|
|
|
MarbleProgram = new osg::Program;
|
|
|
|
MarbleProgram->setName( "marble" );
|
|
|
|
_programList.push_back( MarbleProgram );
|
|
|
|
MarbleVertObj = new osg::Shader( osg::Shader::VERTEX );
|
|
|
|
MarbleFragObj = new osg::Shader( osg::Shader::FRAGMENT );
|
|
|
|
MarbleProgram->addShader( MarbleFragObj );
|
|
|
|
MarbleProgram->addShader( MarbleVertObj );
|
|
|
|
ss->setAttributeAndModes(MarbleProgram, osg::StateAttribute::ON);
|
|
|
|
|
|
|
|
ss->addUniform( new osg::Uniform("NoiseTex", TEXUNIT_NOISE) );
|
|
|
|
ss->addUniform( new osg::Uniform("SineTex", TEXUNIT_SINE) );
|
2003-10-05 19:30:54 +08:00
|
|
|
}
|
|
|
|
|
2004-01-03 17:06:52 +08:00
|
|
|
#ifdef INTERNAL_3DLABS //[
|
2003-10-05 19:30:54 +08:00
|
|
|
// regular GL 1.x texturing for comparison.
|
2004-01-03 17:06:52 +08:00
|
|
|
osg::StateSet* ss = ModelInstance();
|
|
|
|
osg::Texture2D* tex0 = new osg::Texture2D;
|
|
|
|
tex0->setImage( osgDB::readImageFile( "images/3dl-ge100.png" ) );
|
|
|
|
ss->setTextureAttributeAndModes(0, tex0, osg::StateAttribute::ON);
|
|
|
|
#endif //]
|
2003-10-05 19:30:54 +08:00
|
|
|
|
|
|
|
reloadShaderSource();
|
|
|
|
|
2004-01-03 17:06:52 +08:00
|
|
|
#ifdef INTERNAL_3DLABS //[
|
2003-10-05 19:30:54 +08:00
|
|
|
// add logo overlays
|
2004-01-03 17:06:52 +08:00
|
|
|
rootNode->addChild( osgDB::readNodeFile( "3dl_ogl.logo" ) );
|
|
|
|
#endif //]
|
2003-10-05 19:30:54 +08:00
|
|
|
|
|
|
|
return rootNode;
|
2003-07-15 18:45:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2003-10-05 19:30:54 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2003-07-15 18:45:46 +08:00
|
|
|
|
2003-10-05 19:30:54 +08:00
|
|
|
GL2Scene::GL2Scene()
|
2003-07-15 18:45:46 +08:00
|
|
|
{
|
2003-10-05 19:30:54 +08:00
|
|
|
_rootNode = buildScene();
|
|
|
|
_shadersEnabled = true;
|
|
|
|
}
|
2003-07-15 18:45:46 +08:00
|
|
|
|
2003-10-05 19:30:54 +08:00
|
|
|
GL2Scene::~GL2Scene()
|
|
|
|
{
|
|
|
|
}
|
2003-07-15 18:45:46 +08:00
|
|
|
|
2003-10-05 19:30:54 +08:00
|
|
|
void
|
|
|
|
GL2Scene::reloadShaderSource()
|
|
|
|
{
|
2005-04-13 22:12:06 +08:00
|
|
|
osg::notify(osg::INFO) << "reloadShaderSource()" << std::endl;
|
2003-07-15 18:45:46 +08:00
|
|
|
|
2003-10-05 19:30:54 +08:00
|
|
|
LoadShaderSource( BlockyVertObj, "shaders/blocky.vert" );
|
|
|
|
LoadShaderSource( BlockyFragObj, "shaders/blocky.frag" );
|
2003-07-15 18:45:46 +08:00
|
|
|
|
2003-10-05 19:30:54 +08:00
|
|
|
LoadShaderSource( ErodedVertObj, "shaders/eroded.vert" );
|
|
|
|
LoadShaderSource( ErodedFragObj, "shaders/eroded.frag" );
|
2003-07-15 18:45:46 +08:00
|
|
|
|
2003-10-05 19:30:54 +08:00
|
|
|
LoadShaderSource( MarbleVertObj, "shaders/marble.vert" );
|
|
|
|
LoadShaderSource( MarbleFragObj, "shaders/marble.frag" );
|
2003-07-15 18:45:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-05 19:30:54 +08:00
|
|
|
// mew 2003-09-19 : TODO Need to revisit how to better control
|
2005-04-08 04:20:09 +08:00
|
|
|
// osg::Program enable state in OSG core. glProgram are
|
2003-10-05 19:30:54 +08:00
|
|
|
// different enough from other GL state that StateSet::setAttributeAndModes()
|
|
|
|
// doesn't fit well, so came up with a local implementation.
|
2003-07-15 18:45:46 +08:00
|
|
|
void
|
2003-10-05 19:30:54 +08:00
|
|
|
GL2Scene::toggleShaderEnable()
|
2003-07-15 18:45:46 +08:00
|
|
|
{
|
2003-10-05 19:30:54 +08:00
|
|
|
_shadersEnabled = ! _shadersEnabled;
|
|
|
|
osg::notify(osg::WARN) << "shader enable = " <<
|
2005-05-02 17:34:27 +08:00
|
|
|
((_shadersEnabled) ? "ON" : "OFF") << std::endl;
|
2005-04-08 04:20:09 +08:00
|
|
|
for( unsigned int i = 0; i < _programList.size(); i++ )
|
2003-10-05 19:30:54 +08:00
|
|
|
{
|
2005-05-02 17:34:27 +08:00
|
|
|
//_programList[i]->enable( _shadersEnabled );
|
2003-10-05 19:30:54 +08:00
|
|
|
}
|
2003-07-15 18:45:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*EOF*/
|