2004-11-10 17:56:03 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield
|
|
|
|
* Copyright (C) 2003-2004 3Dlabs Inc. Ltd.
|
2003-07-15 18:45:46 +08:00
|
|
|
*
|
|
|
|
* This application is open source and may be redistributed and/or modified
|
|
|
|
* freely and without restriction, both in commericial and non commericial applications,
|
|
|
|
* as long as this copyright notice is maintained.
|
|
|
|
*
|
|
|
|
* This application is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* file: examples/osgshaders/GL2Scene.cpp
|
2004-11-10 17:56:03 +08:00
|
|
|
* author: Mike Weiblen 2004-11-09
|
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 <osgDB/FileUtils>
|
|
|
|
#include <osgUtil/Optimizer>
|
|
|
|
#include <osgGL2/ProgramObject>
|
|
|
|
|
2003-10-05 19:30:54 +08:00
|
|
|
#include "GL2Scene.h"
|
|
|
|
#include "Noise.h"
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static osg::Image*
|
|
|
|
make3DNoiseImage(int texSize)
|
|
|
|
{
|
|
|
|
osg::Image* image = new osg::Image;
|
|
|
|
image->setImage(texSize, texSize, texSize,
|
|
|
|
4, GL_RGBA, GL_UNSIGNED_BYTE,
|
|
|
|
new unsigned char[4 * texSize * texSize * texSize],
|
|
|
|
osg::Image::USE_NEW_DELETE);
|
|
|
|
|
|
|
|
const int startFrequency = 4;
|
|
|
|
const int numOctaves = 4;
|
|
|
|
|
|
|
|
int f, i, j, k, inc;
|
|
|
|
double ni[3];
|
|
|
|
double inci, incj, inck;
|
|
|
|
int frequency = startFrequency;
|
|
|
|
GLubyte *ptr;
|
|
|
|
double amp = 0.5;
|
|
|
|
|
|
|
|
osg::notify(osg::INFO) << "creating 3D noise texture... ";
|
|
|
|
|
|
|
|
for (f = 0, inc = 0; f < numOctaves; ++f, frequency *= 2, ++inc, amp *= 0.5)
|
|
|
|
{
|
|
|
|
SetNoiseFrequency(frequency);
|
|
|
|
ptr = image->data();
|
|
|
|
ni[0] = ni[1] = ni[2] = 0;
|
|
|
|
|
|
|
|
inci = 1.0 / (texSize / frequency);
|
|
|
|
for (i = 0; i < texSize; ++i, ni[0] += inci)
|
|
|
|
{
|
|
|
|
incj = 1.0 / (texSize / frequency);
|
|
|
|
for (j = 0; j < texSize; ++j, ni[1] += incj)
|
|
|
|
{
|
|
|
|
inck = 1.0 / (texSize / frequency);
|
|
|
|
for (k = 0; k < texSize; ++k, ni[2] += inck, ptr += 4)
|
|
|
|
{
|
|
|
|
*(ptr+inc) = (GLubyte) (((noise3(ni) + 1.0) * amp) * 128.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::notify(osg::INFO) << "DONE" << std::endl;
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
static osg::Texture3D*
|
|
|
|
make3DNoiseTexture(int texSize )
|
|
|
|
{
|
|
|
|
osg::Texture3D* noiseTexture = new osg::Texture3D;
|
|
|
|
noiseTexture->setFilter(osg::Texture3D::MIN_FILTER, osg::Texture3D::LINEAR);
|
|
|
|
noiseTexture->setFilter(osg::Texture3D::MAG_FILTER, osg::Texture3D::LINEAR);
|
|
|
|
noiseTexture->setWrap(osg::Texture3D::WRAP_S, osg::Texture3D::REPEAT);
|
|
|
|
noiseTexture->setWrap(osg::Texture3D::WRAP_T, osg::Texture3D::REPEAT);
|
|
|
|
noiseTexture->setWrap(osg::Texture3D::WRAP_R, osg::Texture3D::REPEAT);
|
|
|
|
noiseTexture->setImage( make3DNoiseImage(texSize) );
|
|
|
|
return noiseTexture;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static osg::Image*
|
|
|
|
make1DSineImage( int texSize )
|
|
|
|
{
|
|
|
|
const float PI = 3.1415927;
|
|
|
|
|
|
|
|
osg::Image* image = new osg::Image;
|
|
|
|
image->setImage(texSize, 1, 1,
|
|
|
|
4, GL_RGBA, GL_UNSIGNED_BYTE,
|
|
|
|
new unsigned char[4 * texSize],
|
|
|
|
osg::Image::USE_NEW_DELETE);
|
|
|
|
|
|
|
|
GLubyte* ptr = image->data();
|
|
|
|
float inc = 2. * PI / (float)texSize;
|
|
|
|
for(int i = 0; i < texSize; i++)
|
|
|
|
{
|
|
|
|
*ptr++ = (GLubyte)((sinf(i * inc) * 0.5 + 0.5) * 255.);
|
|
|
|
*ptr++ = 0;
|
|
|
|
*ptr++ = 0;
|
|
|
|
*ptr++ = 1;
|
|
|
|
}
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// OpenGL Shading Language source code for the "microshader" example,
|
|
|
|
// which simply colors a fragment based on its location.
|
2003-07-15 18:45:46 +08:00
|
|
|
|
|
|
|
static const char *microshaderVertSource = {
|
2003-10-05 19:30:54 +08:00
|
|
|
"varying vec4 color;"
|
2003-07-15 18:45:46 +08:00
|
|
|
"void main(void)"
|
|
|
|
"{"
|
2003-10-05 19:30:54 +08:00
|
|
|
"color = gl_Vertex;"
|
2003-07-15 18:45:46 +08:00
|
|
|
"gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
|
|
|
|
"}"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *microshaderFragSource = {
|
2003-10-05 19:30:54 +08:00
|
|
|
"varying vec4 color;"
|
2003-07-15 18:45:46 +08:00
|
|
|
"void main(void)"
|
|
|
|
"{"
|
2004-01-03 17:06:52 +08:00
|
|
|
"gl_FragColor = clamp( color, 0.0, 1.0 );"
|
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
|
|
|
|
|
|
|
// Create some geometry upon which to render GL2 shaders.
|
|
|
|
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
|
2003-10-05 19:30:54 +08:00
|
|
|
LoadShaderSource( osgGL2::ShaderObject* obj, const std::string& fileName )
|
2003-07-15 18:45:46 +08:00
|
|
|
{
|
2003-10-05 19:30:54 +08:00
|
|
|
std::string fqFileName = osgDB::findDataFile(fileName);
|
|
|
|
if( fqFileName.length() != 0 )
|
2003-07-15 18:45:46 +08:00
|
|
|
{
|
2003-10-05 19:30:54 +08:00
|
|
|
obj->loadShaderSourceFromFile( fqFileName.c_str() );
|
2003-07-15 18:45:46 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-10-05 19:30:54 +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
|
|
|
|
|
|
|
|
static osgGL2::ProgramObject* BlockyProgObj;
|
|
|
|
static osgGL2::ShaderObject* BlockyVertObj;
|
|
|
|
static osgGL2::ShaderObject* BlockyFragObj;
|
|
|
|
|
|
|
|
static osgGL2::ProgramObject* ErodedProgObj;
|
|
|
|
static osgGL2::ShaderObject* ErodedVertObj;
|
|
|
|
static osgGL2::ShaderObject* ErodedFragObj;
|
|
|
|
|
|
|
|
static osgGL2::ProgramObject* MarbleProgObj;
|
|
|
|
static osgGL2::ShaderObject* MarbleVertObj;
|
|
|
|
static osgGL2::ShaderObject* MarbleFragObj;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2004-11-10 17:56:03 +08:00
|
|
|
// for demo simplicity, this one callback animates all the shaders.
|
2003-10-05 19:30:54 +08:00
|
|
|
|
|
|
|
class AnimateCallback: public osg::NodeCallback
|
|
|
|
{
|
|
|
|
public:
|
2004-11-10 17:56:03 +08:00
|
|
|
AnimateCallback() : osg::NodeCallback(), _enabled(true) {}
|
2003-10-05 19:30:54 +08:00
|
|
|
|
|
|
|
virtual void operator() ( osg::Node* node, osg::NodeVisitor* nv )
|
|
|
|
{
|
|
|
|
if( _enabled )
|
|
|
|
{
|
|
|
|
float angle = 2.0 * nv->getFrameStamp()->getReferenceTime();
|
|
|
|
float sine = sinf( angle ); // -1 -> 1
|
|
|
|
float v01 = 0.5f * sine + 0.5f; // 0 -> 1
|
|
|
|
float v10 = 1.0f - v01; // 1 -> 0
|
|
|
|
|
|
|
|
ErodedProgObj->setUniform( "Offset", osg::Vec3(0.505f, 0.8f*v01, 0.0f) );
|
|
|
|
|
|
|
|
MarbleProgObj->setUniform( "Offset", osg::Vec3(0.505f, 0.8f*v01, 0.0f) );
|
2003-07-15 18:45:46 +08:00
|
|
|
|
2003-10-05 19:30:54 +08:00
|
|
|
BlockyProgObj->setUniform( "Sine", sine );
|
|
|
|
BlockyProgObj->setUniform( "Color1", osg::Vec3(v10, 0.0f, 0.0f) );
|
|
|
|
BlockyProgObj->setUniform( "Color2", osg::Vec3(v01, v01, v10) );
|
|
|
|
}
|
|
|
|
traverse(node, nv);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool _enabled;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Compose a scenegraph with examples of GL2 shaders
|
|
|
|
|
2004-09-26 18:27:25 +08:00
|
|
|
#define TEXUNIT_SINE 1
|
|
|
|
#define TEXUNIT_NOISE 2
|
|
|
|
|
2003-10-05 19:30:54 +08:00
|
|
|
osg::ref_ptr<osg::Group>
|
|
|
|
GL2Scene::buildScene()
|
|
|
|
{
|
|
|
|
osg::Texture3D* noiseTexture = make3DNoiseTexture( 32 /*128*/ );
|
|
|
|
osg::Texture1D* sineTexture = make1DSineTexture( 32 /*1024*/ );
|
|
|
|
|
|
|
|
// the root of our scenegraph.
|
|
|
|
rootNode = new osg::Group;
|
2004-11-10 17:56:03 +08:00
|
|
|
rootNode->setUpdateCallback( new AnimateCallback );
|
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
|
|
|
{
|
2003-10-05 19:30:54 +08:00
|
|
|
osg::StateSet* ss = ModelInstance();
|
|
|
|
osgGL2::ProgramObject* progObj = new osgGL2::ProgramObject;
|
|
|
|
_progObjList.push_back( progObj );
|
|
|
|
progObj->addShader( new osgGL2::ShaderObject(
|
|
|
|
osgGL2::ShaderObject::VERTEX, microshaderVertSource ) );
|
|
|
|
progObj->addShader( new osgGL2::ShaderObject(
|
|
|
|
osgGL2::ShaderObject::FRAGMENT, microshaderFragSource ) );
|
|
|
|
ss->setAttributeAndModes( progObj, 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
|
|
|
|
{
|
|
|
|
osg::StateSet* ss = ModelInstance();
|
|
|
|
BlockyProgObj = new osgGL2::ProgramObject;
|
|
|
|
_progObjList.push_back( BlockyProgObj );
|
|
|
|
BlockyVertObj = new osgGL2::ShaderObject( osgGL2::ShaderObject::VERTEX );
|
|
|
|
BlockyFragObj = new osgGL2::ShaderObject( osgGL2::ShaderObject::FRAGMENT );
|
|
|
|
BlockyProgObj->addShader( BlockyFragObj );
|
|
|
|
BlockyProgObj->addShader( BlockyVertObj );
|
|
|
|
ss->setAttributeAndModes(BlockyProgObj, osg::StateAttribute::ON);
|
|
|
|
}
|
|
|
|
|
|
|
|
// the "eroded" shader, uses a noise texture to discard fragments
|
|
|
|
{
|
|
|
|
osg::StateSet* ss = ModelInstance();
|
2004-09-26 18:27:25 +08:00
|
|
|
ss->setTextureAttribute(TEXUNIT_NOISE, noiseTexture);
|
2003-10-05 19:30:54 +08:00
|
|
|
ErodedProgObj = new osgGL2::ProgramObject;
|
|
|
|
_progObjList.push_back( ErodedProgObj );
|
|
|
|
ErodedVertObj = new osgGL2::ShaderObject( osgGL2::ShaderObject::VERTEX );
|
|
|
|
ErodedFragObj = new osgGL2::ShaderObject( osgGL2::ShaderObject::FRAGMENT );
|
|
|
|
ErodedProgObj->addShader( ErodedFragObj );
|
|
|
|
ErodedProgObj->addShader( ErodedVertObj );
|
|
|
|
ss->setAttributeAndModes(ErodedProgObj, osg::StateAttribute::ON);
|
|
|
|
}
|
|
|
|
|
|
|
|
// the "marble" shader, uses two textures
|
|
|
|
{
|
|
|
|
osg::StateSet* ss = ModelInstance();
|
2004-09-26 18:27:25 +08:00
|
|
|
ss->setTextureAttribute(TEXUNIT_NOISE, noiseTexture);
|
|
|
|
ss->setTextureAttribute(TEXUNIT_SINE, sineTexture);
|
2003-10-05 19:30:54 +08:00
|
|
|
MarbleProgObj = new osgGL2::ProgramObject;
|
|
|
|
_progObjList.push_back( MarbleProgObj );
|
|
|
|
MarbleVertObj = new osgGL2::ShaderObject( osgGL2::ShaderObject::VERTEX );
|
|
|
|
MarbleFragObj = new osgGL2::ShaderObject( osgGL2::ShaderObject::FRAGMENT );
|
|
|
|
MarbleProgObj->addShader( MarbleFragObj );
|
|
|
|
MarbleProgObj->addShader( MarbleVertObj );
|
|
|
|
ss->setAttributeAndModes(MarbleProgObj, osg::StateAttribute::ON);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// mew 2003-09-19 : This way of configuring the shaders is temporary,
|
|
|
|
// pending a move to an osgFX-based approach.
|
|
|
|
void
|
|
|
|
GL2Scene::reloadShaderSource()
|
|
|
|
{
|
|
|
|
osg::notify(osg::WARN) << "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" );
|
|
|
|
ErodedProgObj->setUniform( "LightPosition", osg::Vec3(0.0f, 0.0f, 4.0f) );
|
|
|
|
ErodedProgObj->setUniform( "Scale", 1.0f );
|
2004-09-26 18:27:25 +08:00
|
|
|
ErodedProgObj->setSampler( "sampler3d", TEXUNIT_NOISE );
|
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" );
|
2004-09-26 18:27:25 +08:00
|
|
|
MarbleProgObj->setSampler( "Noise", TEXUNIT_NOISE );
|
|
|
|
MarbleProgObj->setSampler( "Sine", TEXUNIT_SINE );
|
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
|
|
|
|
// osgGL2::ProgramObject enable state in OSG core. glProgramObjects are
|
|
|
|
// 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 = " <<
|
|
|
|
((_shadersEnabled) ? "ON" : "OFF") << std::endl;
|
|
|
|
for( unsigned int i = 0; i < _progObjList.size(); i++ )
|
|
|
|
{
|
|
|
|
_progObjList[i]->enable( _shadersEnabled );
|
|
|
|
}
|
2003-07-15 18:45:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*EOF*/
|
|
|
|
|