Added osg::ShadeModel state attribute which encapsulates glShadeModel.
This commit is contained in:
parent
7a7322f7b0
commit
4ea7de39c6
@ -249,6 +249,10 @@ SOURCE=..\..\src\osg\Quat.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\ShadeModel.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\State.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@ -505,6 +509,10 @@ SOURCE=..\..\Include\Osg\Referenced
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\ShadeModel
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\State
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -206,6 +206,10 @@ SOURCE=..\..\..\src\osgPlugins\osg\ReaderWriterOSG.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\osg\ShadeModel.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\src\osgPlugins\osg\StateSet.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
58
include/osg/ShadeModel
Normal file
58
include/osg/ShadeModel
Normal file
@ -0,0 +1,58 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSG_SHADEMODEL
|
||||
#define OSG_SHADEMODEL 1
|
||||
|
||||
#include <osg/GL>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
|
||||
namespace osg {
|
||||
|
||||
/** Class which encapsulates glShadeModel(..).
|
||||
*/
|
||||
class SG_EXPORT ShadeModel : public StateAttribute
|
||||
{
|
||||
public :
|
||||
|
||||
ShadeModel();
|
||||
|
||||
META_StateAttribute(ShadeModel, SHADEMODEL);
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const StateAttribute& sa) const
|
||||
{
|
||||
// check the types are equal and then create the rhs variable
|
||||
// used by the COMPARE_StateAttribute_Paramter macro's below.
|
||||
COMPARE_StateAttribute_Types(ShadeModel,sa)
|
||||
|
||||
// compare each paramter in turn against the rhs.
|
||||
COMPARE_StateAttribute_Parameter(_mode)
|
||||
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
enum Mode {
|
||||
FLAT = GL_FLAT,
|
||||
SMOOTH = GL_SMOOTH
|
||||
};
|
||||
|
||||
inline void setMode(const Mode mode) { _mode = mode; }
|
||||
|
||||
inline const Mode getMode() const { return _mode; }
|
||||
|
||||
virtual void apply(State& state) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~ShadeModel();
|
||||
|
||||
Mode _mode;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -123,7 +123,8 @@ class SG_EXPORT StateAttribute : public Object
|
||||
|
||||
POINT =LIGHT_7+1,
|
||||
LINEWIDTH =POINT+1,
|
||||
POLYGONMODE =LINEWIDTH+1,
|
||||
SHADEMODEL =LINEWIDTH+1,
|
||||
POLYGONMODE =SHADEMODEL+1,
|
||||
POLYGONOFFSET =POLYGONMODE+1,
|
||||
TEXENV =POLYGONOFFSET+1,
|
||||
TEXGEN =TEXENV+1,
|
||||
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user