Added osg::ShadeModel state attribute which encapsulates glShadeModel.
This commit is contained in:
@@ -42,6 +42,7 @@ C++FILES = \
|
||||
PolygonMode.cpp\
|
||||
PolygonOffset.cpp\
|
||||
Quat.cpp\
|
||||
ShadeModel.cpp\
|
||||
State.cpp\
|
||||
StateSet.cpp\
|
||||
Stencil.cpp \
|
||||
|
||||
19
src/osg/ShadeModel.cpp
Normal file
19
src/osg/ShadeModel.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <osg/GL>
|
||||
#include <osg/ShadeModel>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
ShadeModel::ShadeModel()
|
||||
{
|
||||
_mode = SMOOTH;
|
||||
}
|
||||
|
||||
|
||||
ShadeModel::~ShadeModel()
|
||||
{
|
||||
}
|
||||
|
||||
void ShadeModel::apply(State&) const
|
||||
{
|
||||
glShadeModel((GLenum)_mode);
|
||||
}
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <osg/LineSegment>
|
||||
#include <osg/PolygonMode>
|
||||
#include <osg/Texture>
|
||||
#include <osg/ShadeModel>
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <osgDB/WriteFile>
|
||||
@@ -852,14 +853,23 @@ void Viewer::keyboard(unsigned char key, int x, int y)
|
||||
break;
|
||||
|
||||
case 's' :
|
||||
{
|
||||
flat_shade = 1 - flat_shade ;
|
||||
osg::StateSet* stateset = sceneView->getGlobalStateSet();
|
||||
osg::ShadeModel* shademodel = dynamic_cast<osg::ShadeModel*>(stateset->getAttribute(osg::StateAttribute::SHADEMODEL));
|
||||
if (!shademodel)
|
||||
{
|
||||
shademodel = new osg::ShadeModel;
|
||||
stateset->setAttribute(shademodel,osg::StateAttribute::OVERRIDE);
|
||||
}
|
||||
|
||||
if( flat_shade )
|
||||
glShadeModel( GL_FLAT );
|
||||
shademodel->setMode( osg::ShadeModel::FLAT );
|
||||
else
|
||||
glShadeModel( GL_SMOOTH );
|
||||
|
||||
shademodel->setMode( osg::ShadeModel::SMOOTH );
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
case 'S' :
|
||||
{
|
||||
osg::notify(osg::NOTICE) << "Smoothing scene..."<< std::endl;
|
||||
|
||||
@@ -30,6 +30,7 @@ C++FILES = \
|
||||
PolygonMode.cpp\
|
||||
PolygonOffset.cpp\
|
||||
ReaderWriterOSG.cpp\
|
||||
ShadeModel.cpp\
|
||||
StateSet.cpp\
|
||||
Stencil.cpp\
|
||||
Switch.cpp\
|
||||
|
||||
62
src/osgPlugins/osg/ShadeModel.cpp
Normal file
62
src/osgPlugins/osg/ShadeModel.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "osg/ShadeModel"
|
||||
|
||||
#include "osgDB/Registry"
|
||||
#include "osgDB/Input"
|
||||
#include "osgDB/Output"
|
||||
|
||||
using namespace osg;
|
||||
using namespace osgDB;
|
||||
|
||||
// forward declare functions to use later.
|
||||
bool ShadeModel_readLocalData(Object& obj, Input& fr);
|
||||
bool ShadeModel_writeLocalData(const Object& obj, Output& fw);
|
||||
|
||||
// register the read and write functions with the osgDB::Registry.
|
||||
RegisterDotOsgWrapperProxy g_ShadeModelFuncProxy
|
||||
(
|
||||
new osg::ShadeModel,
|
||||
"ShadeModel",
|
||||
"Object StateAttribute ShadeModel",
|
||||
&ShadeModel_readLocalData,
|
||||
&ShadeModel_writeLocalData
|
||||
);
|
||||
|
||||
|
||||
bool ShadeModel_readLocalData(Object& obj,Input& fr)
|
||||
{
|
||||
bool iteratorAdvanced = false;
|
||||
|
||||
ShadeModel& shademodel = static_cast<ShadeModel&>(obj);
|
||||
|
||||
if (fr[0].matchWord("mode"))
|
||||
{
|
||||
if (fr[1].matchWord("FLAT"))
|
||||
{
|
||||
shademodel.setMode(ShadeModel::FLAT);
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
else if (fr[1].matchWord("SMOOTH"))
|
||||
{
|
||||
shademodel.setMode(ShadeModel::SMOOTH);
|
||||
fr+=2;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
|
||||
|
||||
bool ShadeModel_writeLocalData(const Object& obj, Output& fw)
|
||||
{
|
||||
|
||||
const ShadeModel& shademodel = static_cast<const ShadeModel&>(obj);
|
||||
|
||||
switch(shademodel.getMode())
|
||||
{
|
||||
case(ShadeModel::FLAT): fw.indent() << "mode FLAT" <<std::endl; break;
|
||||
case(ShadeModel::SMOOTH): fw.indent() << "mode SMOOTH" <<std::endl; break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user