Added support for set/getUniform and set/getProgram into osg::StateSet.
This commit is contained in:
@@ -18,8 +18,11 @@
|
||||
#include <osg/ShadowVolumeOccluder>
|
||||
#include <osg/Referenced>
|
||||
|
||||
|
||||
namespace osg {
|
||||
|
||||
#define COMPILE_WITH_SHADOW_OCCLUSION_CULLING
|
||||
|
||||
/** A CullingSet class which contains a frustum and a list of occluders. */
|
||||
class SG_EXPORT CullingSet : public Referenced
|
||||
{
|
||||
@@ -222,7 +225,7 @@ class SG_EXPORT CullingSet : public Referenced
|
||||
{
|
||||
if (((bs.center()*_pixelSizeVector)*_smallFeatureCullingPixelSize)>bs.radius()) return true;
|
||||
}
|
||||
|
||||
#ifdef COMPILE_WITH_SHADOW_OCCLUSION_CULLING
|
||||
if (_mask&SHADOW_OCCLUSION_CULLING)
|
||||
{
|
||||
// is it in one of the shadow occluder volumes.
|
||||
@@ -236,7 +239,7 @@ class SG_EXPORT CullingSet : public Referenced
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -244,6 +247,7 @@ class SG_EXPORT CullingSet : public Referenced
|
||||
{
|
||||
_frustum.pushCurrentMask();
|
||||
|
||||
#ifdef COMPILE_WITH_SHADOW_OCCLUSION_CULLING
|
||||
if (!_occluderList.empty())
|
||||
{
|
||||
for(OccluderList::iterator itr=_occluderList.begin();
|
||||
@@ -253,12 +257,14 @@ class SG_EXPORT CullingSet : public Referenced
|
||||
itr->pushCurrentMask();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void popCurrentMask()
|
||||
{
|
||||
_frustum.popCurrentMask();
|
||||
|
||||
#ifdef COMPILE_WITH_SHADOW_OCCLUSION_CULLING
|
||||
if (!_occluderList.empty())
|
||||
{
|
||||
for(OccluderList::iterator itr=_occluderList.begin();
|
||||
@@ -268,6 +274,7 @@ class SG_EXPORT CullingSet : public Referenced
|
||||
itr->popCurrentMask();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void disableAndPushOccludersCurrentMask(NodePath& nodePath);
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
#ifndef OSG_PROGRAM
|
||||
#define OSG_PROGRAM 1
|
||||
|
||||
#include <osg/State>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/buffered_value>
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Vec2>
|
||||
@@ -41,6 +39,8 @@
|
||||
|
||||
namespace osg {
|
||||
|
||||
class State;
|
||||
|
||||
class SG_EXPORT GL2Extensions : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
@@ -312,7 +312,7 @@ typedef std::vector< ShaderPtr > ShaderList;
|
||||
* configuration.
|
||||
*/
|
||||
|
||||
class SG_EXPORT Program : public osg::StateAttribute
|
||||
class SG_EXPORT Program : public osg::Object
|
||||
{
|
||||
public:
|
||||
Program();
|
||||
@@ -320,10 +320,10 @@ class SG_EXPORT Program : public osg::StateAttribute
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
Program(const Program& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_StateAttribute(osg, Program, PROGRAM);
|
||||
META_Object(osg, Program);
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const osg::StateAttribute& sa) const;
|
||||
virtual int compare(const osg::Program& sa) const;
|
||||
|
||||
/** If enabled, activate our program in the GL pipeline,
|
||||
* performing any rebuild operations that might be pending. */
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace osg {
|
||||
* configuration.
|
||||
*/
|
||||
|
||||
class SG_EXPORT Shader : public osg::Referenced
|
||||
class SG_EXPORT Shader : public osg::Object
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
@@ -176,10 +176,6 @@ class SG_EXPORT StateAttribute : public Object
|
||||
REGISTER_COMBINERS,
|
||||
// osgNVParse
|
||||
PROGRAM_PARSER,
|
||||
|
||||
/// core GLSL
|
||||
PROGRAM,
|
||||
UNIFORM,
|
||||
};
|
||||
|
||||
/** Simple pairing between an attribute type and the member within that attribute type group.*/
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/ref_ptr>
|
||||
|
||||
#include <osg/Uniform>
|
||||
#include <osg/Program>
|
||||
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@@ -252,6 +256,56 @@ class SG_EXPORT StateSet : public Object
|
||||
|
||||
void setAssociatedTextureModes(unsigned int unit,const StateAttribute* attribute, StateAttribute::GLModeValue value);
|
||||
|
||||
|
||||
|
||||
|
||||
/** Simple pairing between an attribute and its override flag.*/
|
||||
typedef std::pair<ref_ptr<Uniform>,StateAttribute::OverrideValue> RefUniformPair;
|
||||
|
||||
/** a container to map <StateAttribyte::Types,Member> to their respective RefAttributePair.*/
|
||||
typedef std::map<std::string,RefUniformPair> UniformList;
|
||||
|
||||
/** Set this StateSet to contain specified uniform and override flag.*/
|
||||
void setUniform(Uniform* uniform, StateAttribute::OverrideValue value=StateAttribute::OFF);
|
||||
|
||||
/** remove uniform of specified name from StateSet.*/
|
||||
void removeUniform(const std::string& name);
|
||||
|
||||
/** remove attribute from StateSet.*/
|
||||
void removeUniform(Uniform* attribute);
|
||||
|
||||
/** Get Uniform for specified name.
|
||||
* Returns NULL if no matching uniform is contained within StateSet.*/
|
||||
Uniform* getUniform(const std::string& name);
|
||||
|
||||
/** Get const Uniform for specified name.
|
||||
* Returns NULL if no matching uniform is contained within StateSet.*/
|
||||
const Uniform* getUniform(const std::string& name) const;
|
||||
|
||||
/** Get specified RefUniformPair for specified type.
|
||||
* Returns NULL if no type is contained within StateSet.*/
|
||||
const RefUniformPair* getUniformPair(const std::string& name) const;
|
||||
|
||||
/** set the list of all Uniforms contained in this StateSet.*/
|
||||
inline void setUniformList(UniformList& al) { _uniformList=al; }
|
||||
|
||||
/** return the list of all Uniforms contained in this StateSet.*/
|
||||
inline UniformList& getUniformList() { return _uniformList; }
|
||||
|
||||
/** return the const list of all Uniforms contained in this const StateSet.*/
|
||||
inline const UniformList& getUniformList() const { return _uniformList; }
|
||||
|
||||
|
||||
void setProgram(Program* program) { _program = program; }
|
||||
|
||||
Program* getProgram() { return _program.get(); }
|
||||
|
||||
const Program* getProgram() const { return _program.get(); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
enum RenderingHint
|
||||
{
|
||||
DEFAULT_BIN = 0,
|
||||
@@ -330,6 +384,9 @@ class SG_EXPORT StateSet : public Object
|
||||
TextureModeList _textureModeList;
|
||||
TextureAttributeList _textureAttributeList;
|
||||
|
||||
UniformList _uniformList;
|
||||
osg::ref_ptr<osg::Program> _program;
|
||||
|
||||
inline ModeList& getOrCreateTextureModeList(unsigned int unit)
|
||||
{
|
||||
if (unit>=_textureModeList.size()) _textureModeList.resize(unit+1);
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Vec4>
|
||||
#include <osg/Matrix>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/GL>
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -127,9 +127,9 @@ typedef char GLchar;
|
||||
namespace osg {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/** Uniform is an osg::StateAttribute to encapsulate glUniform values */
|
||||
/** Uniform encapsulates glUniform values */
|
||||
|
||||
class SG_EXPORT Uniform : public StateAttribute
|
||||
class SG_EXPORT Uniform : public Object
|
||||
{
|
||||
public:
|
||||
class Value
|
||||
@@ -146,7 +146,7 @@ class SG_EXPORT Uniform : public StateAttribute
|
||||
INT_VEC4 = GL_INT_VEC4,
|
||||
BOOL = GL_BOOL,
|
||||
BOOL_VEC2 = GL_BOOL_VEC2,
|
||||
BOOL_VEC3 = GL_BOOL_VEC3,
|
||||
BOOL_VEC3 = GL_BOOL_VEC3,
|
||||
BOOL_VEC4 = GL_BOOL_VEC4,
|
||||
FLOAT_MAT2 = GL_FLOAT_MAT2,
|
||||
FLOAT_MAT3 = GL_FLOAT_MAT3,
|
||||
@@ -162,6 +162,7 @@ class SG_EXPORT Uniform : public StateAttribute
|
||||
|
||||
Value( const char* name, Type type );
|
||||
Value( const Value& rhs );
|
||||
|
||||
|
||||
/** Get the name of glUniform. */
|
||||
const std::string& getName() const { return _name; }
|
||||
@@ -249,19 +250,21 @@ class SG_EXPORT Uniform : public StateAttribute
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
||||
Uniform(const Uniform& gu,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_StateAttribute(osg, Uniform, UNIFORM);
|
||||
META_Object(osg, Uniform);
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
|
||||
virtual int compare(const StateAttribute& sa) const
|
||||
virtual int compare(const Uniform& rhs) const
|
||||
{
|
||||
// check if the types are equal and then create the rhs variable
|
||||
// used by the COMPARE_StateAttribute_Parameter macros below.
|
||||
COMPARE_StateAttribute_Types(Uniform,sa)
|
||||
|
||||
return _value.compare( rhs._value );
|
||||
}
|
||||
|
||||
virtual void apply( State& state ) const;
|
||||
bool operator < (const Uniform& rhs) const
|
||||
{
|
||||
if (_value.getName()<rhs._value.getName()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string& getName() const { return _value.getName(); }
|
||||
|
||||
/** assignment */
|
||||
bool set( float f );
|
||||
|
||||
Reference in New Issue
Block a user