Implemented most of the changes required for supporting multitexturing in
the osg::State/osg::StateSet/osg::StateAttribute and related classes.
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
#define OSG_ALPHAFUNC 1
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -41,9 +40,9 @@ class SG_EXPORT AlphaFunc : public StateAttribute
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
ds.setMode(GL_ALPHA_TEST,value);
|
||||
modes.push_back(GL_ALPHA_TEST);
|
||||
}
|
||||
|
||||
enum ComparisonFunction {
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <osg/Plane>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -51,9 +50,9 @@ class SG_EXPORT ClipPlane : public StateAttribute
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
ds.setMode((GLMode)(GL_CLIP_PLANE0+_clipPlaneNum),value);
|
||||
modes.push_back((GLMode)(GL_CLIP_PLANE0+_clipPlaneNum));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <osg/Export>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Types>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <osg/GL>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -39,9 +38,9 @@ class SG_EXPORT CullFace : public StateAttribute
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
ds.setMode(GL_CULL_FACE,value);
|
||||
modes.push_back(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
enum Mode {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#define OSG_DEPTH 1
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Types>
|
||||
|
||||
namespace osg {
|
||||
@@ -47,9 +46,9 @@ class SG_EXPORT Depth : public StateAttribute
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
ds.setMode(GL_DEPTH_TEST,value);
|
||||
modes.push_back(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
enum Function
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#define OSG_DRAWABLE 1
|
||||
|
||||
#include <osg/BoundingBox>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/State>
|
||||
#include <osg/Types>
|
||||
#include <osg/Vec2>
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#define OSG_FOG 1
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Types>
|
||||
#include <osg/Vec4>
|
||||
|
||||
@@ -48,9 +47,9 @@ class SG_EXPORT Fog : public StateAttribute
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
ds.setMode(GL_FOG,value);
|
||||
modes.push_back(GL_FOG);
|
||||
}
|
||||
|
||||
enum Mode {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#define OSG_LIGHT 1
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Vec4>
|
||||
|
||||
@@ -59,9 +58,9 @@ class SG_EXPORT Light : public StateAttribute
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
ds.setMode(GL_LIGHT0+_lightnum,value);
|
||||
modes.push_back(GL_LIGHT0+_lightnum);
|
||||
}
|
||||
|
||||
/** Set which OpenGL light to operate on.*/
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#define OSG_LIGHTMODEL 1
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Vec4>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#define OSG_LINESTIPPLE 1
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -38,12 +37,11 @@ class SG_EXPORT LineStipple : public StateAttribute
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
ds.setMode(GL_LINE_STIPPLE,value);
|
||||
modes.push_back(GL_LINE_STIPPLE);
|
||||
}
|
||||
|
||||
|
||||
void setFactor(const int factor);
|
||||
inline const int getFactor() const { return _factor; }
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#define OSG_LineWidth 1
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <osg/Vec4>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
|
||||
namespace osg {
|
||||
/** Material - encapsulates OpenGL glMaterial state.*/
|
||||
@@ -69,12 +68,12 @@ class SG_EXPORT Material : public StateAttribute
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
// Have to think about the role of _colorMode
|
||||
// in setting the colormaterial... also need to take the
|
||||
// color material enable/disable out of the the apply()...
|
||||
ds.setMode(GL_COLOR_MATERIAL,value);
|
||||
modes.push_back(GL_COLOR_MATERIAL);
|
||||
}
|
||||
|
||||
virtual void apply(State& state) const;
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <osg/Vec3>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -42,9 +41,9 @@ class SG_EXPORT Point : public StateAttribute
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
ds.setMode(GL_POINT_SMOOTH,value);
|
||||
modes.push_back(GL_POINT_SMOOTH);
|
||||
}
|
||||
|
||||
void setSize(const float size);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#define OSG_POLYGONOFFSET 1
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -39,11 +38,11 @@ class SG_EXPORT PolygonOffset : public StateAttribute
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
ds.setMode(GL_POLYGON_OFFSET_FILL,value);
|
||||
ds.setMode(GL_POLYGON_OFFSET_LINE,value);
|
||||
ds.setMode(GL_POLYGON_OFFSET_POINT,value);
|
||||
modes.push_back(GL_POLYGON_OFFSET_FILL);
|
||||
modes.push_back(GL_POLYGON_OFFSET_LINE);
|
||||
modes.push_back(GL_POLYGON_OFFSET_POINT);
|
||||
}
|
||||
|
||||
inline void setFactor(const float factor) { _factor = factor; }
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <osg/GL>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
||||
@@ -120,11 +120,9 @@ class SG_EXPORT State : public Referenced
|
||||
|
||||
inline const bool applyTextureMode(unsigned int unit, const StateAttribute::GLMode mode,const bool enabled)
|
||||
{
|
||||
if (unit>=_textureModeMapList.size()) _textureModeMapList.resize(unit);
|
||||
ModeMap& modeMap = _textureModeMapList[unit];
|
||||
|
||||
ModeMap& modeMap = getOrCreateTextureModeMap(unit);
|
||||
ModeStack& ms = modeMap[mode];
|
||||
ms.changed = true;
|
||||
ms.changed = true;
|
||||
return applyMode(mode,enabled,ms);
|
||||
}
|
||||
|
||||
@@ -138,9 +136,7 @@ class SG_EXPORT State : public Referenced
|
||||
|
||||
inline const bool applyTextureAttribute(unsigned int unit, const StateAttribute* attribute)
|
||||
{
|
||||
if (unit>=_textureAttributeMapList.size()) _textureAttributeMapList.resize(unit);
|
||||
AttributeMap& attributeMap = _textureAttributeMapList[unit];
|
||||
|
||||
AttributeMap& attributeMap = getOrCreateTextureAttributeMap(unit);
|
||||
AttributeStack& as = attributeMap[attribute->getType()];
|
||||
as.changed = true;
|
||||
return applyAttribute(attribute,as);
|
||||
@@ -505,6 +501,7 @@ class SG_EXPORT State : public Referenced
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
typedef std::map<StateAttribute::GLMode,ModeStack> ModeMap;
|
||||
typedef std::vector<ModeMap> TextureModeMapList;
|
||||
|
||||
@@ -516,10 +513,10 @@ class SG_EXPORT State : public Referenced
|
||||
|
||||
ModeMap _modeMap;
|
||||
AttributeMap _attributeMap;
|
||||
|
||||
|
||||
TextureModeMapList _textureModeMapList;
|
||||
TextureAttributeMapList _textureAttributeMapList;
|
||||
|
||||
|
||||
StateSetStack _drawStateStack;
|
||||
|
||||
struct EnabledArrayPair
|
||||
@@ -543,8 +540,419 @@ class SG_EXPORT State : public Referenced
|
||||
unsigned int _currentActiveTextureUnit;
|
||||
unsigned int _currentClientActiveTextureUnit;
|
||||
|
||||
inline ModeMap& getOrCreateTextureModeMap(unsigned int unit)
|
||||
{
|
||||
if (unit>=_textureModeMapList.size()) _textureModeMapList.resize(unit+1);
|
||||
return _textureModeMapList[unit];
|
||||
}
|
||||
|
||||
|
||||
inline AttributeMap& getOrCreateTextureAttributeMap(unsigned int unit)
|
||||
{
|
||||
if (unit>=_textureAttributeMapList.size()) _textureAttributeMapList.resize(unit+1);
|
||||
return _textureAttributeMapList[unit];
|
||||
}
|
||||
|
||||
inline void pushModeList(ModeMap& modeMap,const StateSet::ModeList& modeList);
|
||||
inline void pushAttributeList(AttributeMap& attributeMap,const StateSet::AttributeList& attributeList);
|
||||
|
||||
inline void popModeList(ModeMap& modeMap,const StateSet::ModeList& modeList);
|
||||
inline void popAttributeList(AttributeMap& attributeMap,const StateSet::AttributeList& attributeList);
|
||||
|
||||
inline void applyModeList(ModeMap& modeMap,const StateSet::ModeList& modeList);
|
||||
inline void applyAttributeList(AttributeMap& attributeMap,const StateSet::AttributeList& attributeList);
|
||||
|
||||
inline void applyModeMap(ModeMap& modeMap);
|
||||
inline void applyAttributeMap(AttributeMap& attributeMap);
|
||||
|
||||
void haveAppliedMode(ModeMap& modeMap,const StateAttribute::GLMode mode,const StateAttribute::GLModeValue value);
|
||||
void haveAppliedMode(ModeMap& modeMap,const StateAttribute::GLMode mode);
|
||||
void haveAppliedAttribute(AttributeMap& attributeMap,const StateAttribute* attribute);
|
||||
void haveAppliedAttribute(AttributeMap& attributeMap,const StateAttribute::Type type);
|
||||
const bool getLastAppliedMode(const ModeMap& modeMap,const StateAttribute::GLMode mode) const;
|
||||
const StateAttribute* getLastAppliedAttribute(const AttributeMap& attributeMap,const StateAttribute::Type type) const;
|
||||
|
||||
};
|
||||
|
||||
inline void State::pushModeList(ModeMap& modeMap,const StateSet::ModeList& modeList)
|
||||
{
|
||||
for(StateSet::ModeList::const_iterator mitr=modeList.begin();
|
||||
mitr!=modeList.end();
|
||||
++mitr)
|
||||
{
|
||||
// get the mode stack for incomming GLmode {mitr->first}.
|
||||
ModeStack& ms = modeMap[mitr->first];
|
||||
if (ms.valueVec.empty())
|
||||
{
|
||||
// first pair so simply push incomming pair to back.
|
||||
ms.valueVec.push_back(mitr->second);
|
||||
}
|
||||
else if (ms.valueVec.back() & StateAttribute::OVERRIDE) // check the existing override flag
|
||||
{
|
||||
// push existing back since override keeps the previoius value.
|
||||
ms.valueVec.push_back(ms.valueVec.back());
|
||||
}
|
||||
else
|
||||
{
|
||||
// no override on so simply push incomming pair to back.
|
||||
ms.valueVec.push_back(mitr->second);
|
||||
}
|
||||
ms.changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
inline void State::pushAttributeList(AttributeMap& attributeMap,const StateSet::AttributeList& attributeList)
|
||||
{
|
||||
for(StateSet::AttributeList::const_iterator aitr=attributeList.begin();
|
||||
aitr!=attributeList.end();
|
||||
++aitr)
|
||||
{
|
||||
// get the attribute stack for incomming type {aitr->first}.
|
||||
AttributeStack& as = attributeMap[aitr->first];
|
||||
if (as.attributeVec.empty())
|
||||
{
|
||||
// first pair so simply push incomming pair to back.
|
||||
as.attributeVec.push_back(
|
||||
AttributePair(aitr->second.first.get(),aitr->second.second));
|
||||
}
|
||||
else if (as.attributeVec.back().second & StateAttribute::OVERRIDE) // check the existing override flag
|
||||
{
|
||||
// push existing back since override keeps the previoius value.
|
||||
as.attributeVec.push_back(as.attributeVec.back());
|
||||
}
|
||||
else
|
||||
{
|
||||
// no override on so simply push incomming pair to back.
|
||||
as.attributeVec.push_back(
|
||||
AttributePair(aitr->second.first.get(),aitr->second.second));
|
||||
}
|
||||
as.changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
inline void State::popModeList(ModeMap& modeMap,const StateSet::ModeList& modeList)
|
||||
{
|
||||
for(StateSet::ModeList::const_iterator mitr=modeList.begin();
|
||||
mitr!=modeList.end();
|
||||
++mitr)
|
||||
{
|
||||
// get the mode stack for incomming GLmode {mitr->first}.
|
||||
ModeStack& ms = modeMap[mitr->first];
|
||||
if (!ms.valueVec.empty())
|
||||
{
|
||||
ms.valueVec.pop_back();
|
||||
}
|
||||
ms.changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
inline void State::popAttributeList(AttributeMap& attributeMap,const StateSet::AttributeList& attributeList)
|
||||
{
|
||||
for(StateSet::AttributeList::const_iterator aitr=attributeList.begin();
|
||||
aitr!=attributeList.end();
|
||||
++aitr)
|
||||
{
|
||||
// get the attribute stack for incomming type {aitr->first}.
|
||||
AttributeStack& as = attributeMap[aitr->first];
|
||||
if (!as.attributeVec.empty())
|
||||
{
|
||||
as.attributeVec.pop_back();
|
||||
}
|
||||
as.changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
inline void State::applyModeList(ModeMap& modeMap,const StateSet::ModeList& modeList)
|
||||
{
|
||||
StateSet::ModeList::const_iterator ds_mitr = modeList.begin();
|
||||
ModeMap::iterator this_mitr=modeMap.begin();
|
||||
|
||||
while (this_mitr!=modeMap.end() && ds_mitr!=modeList.end())
|
||||
{
|
||||
if (this_mitr->first<ds_mitr->first)
|
||||
{
|
||||
|
||||
// note GLMode = this_mitr->first
|
||||
ModeStack& ms = this_mitr->second;
|
||||
if (ms.changed)
|
||||
{
|
||||
ms.changed = false;
|
||||
if (!ms.valueVec.empty())
|
||||
{
|
||||
bool new_value = ms.valueVec.back() & StateAttribute::ON;
|
||||
applyMode(this_mitr->first,new_value,ms);
|
||||
}
|
||||
else
|
||||
{
|
||||
// assume default of disabled.
|
||||
applyMode(this_mitr->first,ms.global_default_value,ms);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
++this_mitr;
|
||||
|
||||
}
|
||||
else if (ds_mitr->first<this_mitr->first)
|
||||
{
|
||||
|
||||
// ds_mitr->first is a new mode, therefore
|
||||
// need to insert a new mode entry for ds_mistr->first.
|
||||
ModeStack& ms = modeMap[ds_mitr->first];
|
||||
|
||||
bool new_value = ds_mitr->second & StateAttribute::ON;
|
||||
applyMode(ds_mitr->first,new_value,ms);
|
||||
|
||||
// will need to disable this mode on next apply so set it to changed.
|
||||
ms.changed = true;
|
||||
|
||||
++ds_mitr;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// this_mitr & ds_mitr refer to the same mode, check the overide
|
||||
// if any otherwise just apply the incomming mode.
|
||||
|
||||
ModeStack& ms = this_mitr->second;
|
||||
|
||||
if (!ms.valueVec.empty() && ms.valueVec.back() & StateAttribute::OVERRIDE)
|
||||
{
|
||||
// override is on, there just treat as a normal apply on modes.
|
||||
|
||||
if (ms.changed)
|
||||
{
|
||||
ms.changed = false;
|
||||
bool new_value = ms.valueVec.back() & StateAttribute::ON;
|
||||
applyMode(this_mitr->first,new_value,ms);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// no override on or no previous entry, therefore consider incomming mode.
|
||||
bool new_value = ds_mitr->second & StateAttribute::ON;
|
||||
if (applyMode(ds_mitr->first,new_value,ms))
|
||||
{
|
||||
ms.changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
++this_mitr;
|
||||
++ds_mitr;
|
||||
}
|
||||
}
|
||||
|
||||
// iterator over the remaining state modes to apply any previous changes.
|
||||
for(;
|
||||
this_mitr!=modeMap.end();
|
||||
++this_mitr)
|
||||
{
|
||||
// note GLMode = this_mitr->first
|
||||
ModeStack& ms = this_mitr->second;
|
||||
if (ms.changed)
|
||||
{
|
||||
ms.changed = false;
|
||||
if (!ms.valueVec.empty())
|
||||
{
|
||||
bool new_value = ms.valueVec.back() & StateAttribute::ON;
|
||||
applyMode(this_mitr->first,new_value,ms);
|
||||
}
|
||||
else
|
||||
{
|
||||
// assume default of disabled.
|
||||
applyMode(this_mitr->first,ms.global_default_value,ms);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// iterator over the remaining incomming modes to apply any new mode.
|
||||
for(;
|
||||
ds_mitr!=modeList.end();
|
||||
++ds_mitr)
|
||||
{
|
||||
ModeStack& ms = modeMap[ds_mitr->first];
|
||||
|
||||
bool new_value = ds_mitr->second & StateAttribute::ON;
|
||||
applyMode(ds_mitr->first,new_value,ms);
|
||||
|
||||
// will need to disable this mode on next apply so set it to changed.
|
||||
ms.changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
inline void State::applyAttributeList(AttributeMap& attributeMap,const StateSet::AttributeList& attributeList)
|
||||
{
|
||||
StateSet::AttributeList::const_iterator ds_aitr=attributeList.begin();
|
||||
|
||||
AttributeMap::iterator this_aitr=attributeMap.begin();
|
||||
|
||||
while (this_aitr!=attributeMap.end() && ds_aitr!=attributeList.end())
|
||||
{
|
||||
if (this_aitr->first<ds_aitr->first)
|
||||
{
|
||||
|
||||
// note attribute type = this_aitr->first
|
||||
AttributeStack& as = this_aitr->second;
|
||||
if (as.changed)
|
||||
{
|
||||
as.changed = false;
|
||||
if (!as.attributeVec.empty())
|
||||
{
|
||||
const StateAttribute* new_attr = as.attributeVec.back().first;
|
||||
applyAttribute(new_attr,as);
|
||||
}
|
||||
else
|
||||
{
|
||||
applyGlobalDefaultAttribute(as);
|
||||
}
|
||||
}
|
||||
|
||||
++this_aitr;
|
||||
|
||||
}
|
||||
else if (ds_aitr->first<this_aitr->first)
|
||||
{
|
||||
|
||||
// ds_mitr->first is a new attribute, therefore
|
||||
// need to insert a new attribute entry for ds_aistr->first.
|
||||
AttributeStack& as = attributeMap[ds_aitr->first];
|
||||
|
||||
const StateAttribute* new_attr = ds_aitr->second.first.get();
|
||||
applyAttribute(new_attr,as);
|
||||
|
||||
// will need to disable this mode on next apply so set it to changed.
|
||||
as.changed = true;
|
||||
|
||||
++ds_aitr;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// this_mitr & ds_mitr refer to the same mode, check the overide
|
||||
// if any otherwise just apply the incomming mode.
|
||||
|
||||
AttributeStack& as = this_aitr->second;
|
||||
|
||||
if (!as.attributeVec.empty() && as.attributeVec.back().second)
|
||||
{
|
||||
// override is os, there just treat as a normal apply on modes.
|
||||
|
||||
if (as.changed)
|
||||
{
|
||||
as.changed = false;
|
||||
const StateAttribute* new_attr = as.attributeVec.back().first;
|
||||
applyAttribute(new_attr,as);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// no override on or no previous entry, therefore consider incomming mode.
|
||||
const StateAttribute* new_attr = ds_aitr->second.first.get();
|
||||
if (applyAttribute(new_attr,as))
|
||||
{
|
||||
as.changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
++this_aitr;
|
||||
++ds_aitr;
|
||||
}
|
||||
}
|
||||
|
||||
// iterator over the remaining state modes to apply any previous changes.
|
||||
for(;
|
||||
this_aitr!=attributeMap.end();
|
||||
++this_aitr)
|
||||
{
|
||||
// note attribute type = this_aitr->first
|
||||
AttributeStack& as = this_aitr->second;
|
||||
if (as.changed)
|
||||
{
|
||||
as.changed = false;
|
||||
if (!as.attributeVec.empty())
|
||||
{
|
||||
const StateAttribute* new_attr = as.attributeVec.back().first;
|
||||
applyAttribute(new_attr,as);
|
||||
}
|
||||
else
|
||||
{
|
||||
applyGlobalDefaultAttribute(as);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// iterator over the remaining incomming modes to apply any new mode.
|
||||
for(;
|
||||
ds_aitr!=attributeList.end();
|
||||
++ds_aitr)
|
||||
{
|
||||
// ds_mitr->first is a new attribute, therefore
|
||||
// need to insert a new attribute entry for ds_aistr->first.
|
||||
AttributeStack& as = attributeMap[ds_aitr->first];
|
||||
|
||||
const StateAttribute* new_attr = ds_aitr->second.first.get();
|
||||
applyAttribute(new_attr,as);
|
||||
|
||||
// will need to update this attribute on next apply so set it to changed.
|
||||
as.changed = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline void State::applyModeMap(ModeMap& modeMap)
|
||||
{
|
||||
for(ModeMap::iterator mitr=modeMap.begin();
|
||||
mitr!=modeMap.end();
|
||||
++mitr)
|
||||
{
|
||||
// note GLMode = mitr->first
|
||||
ModeStack& ms = mitr->second;
|
||||
if (ms.changed)
|
||||
{
|
||||
ms.changed = false;
|
||||
if (!ms.valueVec.empty())
|
||||
{
|
||||
bool new_value = ms.valueVec.back() & StateAttribute::ON;
|
||||
applyMode(mitr->first,new_value,ms);
|
||||
}
|
||||
else
|
||||
{
|
||||
// assume default of disabled.
|
||||
applyMode(mitr->first,ms.global_default_value,ms);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void State::applyAttributeMap(AttributeMap& attributeMap)
|
||||
{
|
||||
for(AttributeMap::iterator aitr=attributeMap.begin();
|
||||
aitr!=attributeMap.end();
|
||||
++aitr)
|
||||
{
|
||||
AttributeStack& as = aitr->second;
|
||||
if (as.changed)
|
||||
{
|
||||
as.changed = false;
|
||||
if (!as.attributeVec.empty())
|
||||
{
|
||||
const StateAttribute* new_attr = as.attributeVec.back().first;
|
||||
applyAttribute(new_attr,as);
|
||||
}
|
||||
else
|
||||
{
|
||||
applyGlobalDefaultAttribute(as);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <osg/GL>
|
||||
|
||||
#include <typeinfo>
|
||||
#include <vector>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -174,6 +175,8 @@ class SG_EXPORT StateAttribute : public Object
|
||||
/** return the Type identifier of the attribute's class type.*/
|
||||
virtual const Type getType() const = 0;
|
||||
|
||||
/** return true if StateAttribute is a type which controls texturing and needs to be issued w.r.t to specific texture unit.*/
|
||||
virtual bool isTextureAttribute() const { return false; }
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const StateAttribute& sa) const = 0;
|
||||
@@ -181,9 +184,10 @@ class SG_EXPORT StateAttribute : public Object
|
||||
bool operator < (const StateAttribute& rhs) const { return compare(rhs)<0; }
|
||||
bool operator == (const StateAttribute& rhs) const { return compare(rhs)==0; }
|
||||
bool operator != (const StateAttribute& rhs) const { return compare(rhs)!=0; }
|
||||
|
||||
|
||||
virtual void setStateSetModes(StateSet&,const GLModeValue) const
|
||||
|
||||
/** return the modes associated with this StateSet*/
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& /*modes*/) const
|
||||
{
|
||||
// default to no GLMode's associated with use of the StateAttribute.
|
||||
}
|
||||
|
||||
@@ -157,7 +157,9 @@ class SG_EXPORT StateSet : public Object
|
||||
inline const TextureAttributeList& getTextureAttributeList() const { return _textureAttributeList; }
|
||||
|
||||
|
||||
|
||||
void setAssociatedModes(const StateAttribute* attribute, const StateAttribute::GLModeValue value);
|
||||
|
||||
void setAssociatedTextureModes(unsigned int unit,const StateAttribute* attribute, const StateAttribute::GLModeValue value);
|
||||
|
||||
enum RenderingHint
|
||||
{
|
||||
@@ -230,6 +232,21 @@ class SG_EXPORT StateSet : public Object
|
||||
if (unit>=_textureAttributeList.size()) _textureAttributeList.resize(unit+1);
|
||||
return _textureAttributeList[unit];
|
||||
}
|
||||
|
||||
int compareModes(const ModeList& lhs,const ModeList& rhs);
|
||||
int compareAttributePtrs(const AttributeList& lhs,const AttributeList& rhs);
|
||||
int compareAttributeContents(const AttributeList& lhs,const AttributeList& rhs);
|
||||
|
||||
void setMode(ModeList& modeList,const StateAttribute::GLMode mode, const StateAttribute::GLModeValue value);
|
||||
void setModeToInherit(ModeList& modeList,const StateAttribute::GLMode mode);
|
||||
const StateAttribute::GLModeValue getMode(const ModeList& modeList,const StateAttribute::GLMode mode) const;
|
||||
void setAssociatedModes(ModeList& modeList,const StateAttribute* attribute, const StateAttribute::GLModeValue value);
|
||||
|
||||
void setAttribute(AttributeList& attributeList,StateAttribute *attribute, const StateAttribute::OverrideValue value=StateAttribute::OFF);
|
||||
|
||||
StateAttribute* getAttribute(AttributeList& attributeList,const StateAttribute::Type type);
|
||||
const StateAttribute* getAttribute(const AttributeList& attributeList,const StateAttribute::Type type) const;
|
||||
const RefAttributePair* getAttributePair(const AttributeList& attributeList,const StateAttribute::Type type) const;
|
||||
|
||||
int _renderingHint;
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#define OSG_STENCIL 1
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Types>
|
||||
|
||||
namespace osg {
|
||||
@@ -53,9 +52,9 @@ class SG_EXPORT Stencil : public StateAttribute
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
ds.setMode(GL_STENCIL_TEST,value);
|
||||
modes.push_back(GL_STENCIL_TEST);
|
||||
}
|
||||
|
||||
enum Function
|
||||
|
||||
@@ -25,6 +25,8 @@ class SG_EXPORT TexEnv : public StateAttribute
|
||||
|
||||
META_StateAttribute(osg, TexEnv, TEXENV);
|
||||
|
||||
virtual bool isTextureAttribute() const { return true; }
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const StateAttribute& sa) const
|
||||
{
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <osg/Vec4>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -37,6 +36,8 @@ class SG_EXPORT TexGen : public StateAttribute
|
||||
|
||||
META_StateAttribute(osg, TexGen, TEXGEN);
|
||||
|
||||
virtual bool isTextureAttribute() const { return true; }
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const StateAttribute& sa) const
|
||||
{
|
||||
@@ -54,10 +55,10 @@ class SG_EXPORT TexGen : public StateAttribute
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
ds.setMode(GL_TEXTURE_GEN_S,value);
|
||||
ds.setMode(GL_TEXTURE_GEN_T,value);
|
||||
modes.push_back(GL_TEXTURE_GEN_S);
|
||||
modes.push_back(GL_TEXTURE_GEN_T);
|
||||
|
||||
// Not happy with turning all tex gen paramters on
|
||||
// as the OSG currently only supports 2D textures and therefore
|
||||
@@ -69,9 +70,8 @@ class SG_EXPORT TexGen : public StateAttribute
|
||||
// The tidy up is now happening, but will have a think before
|
||||
// resolving the below parameters.
|
||||
|
||||
// ds.setMode(GL_TEXTURE_GEN_R,value);
|
||||
// ds.setMode(GL_TEXTURE_GEN_Q,value);
|
||||
|
||||
modes.push_back(GL_TEXTURE_GEN_R);
|
||||
modes.push_back(GL_TEXTURE_GEN_Q);
|
||||
}
|
||||
|
||||
virtual void apply(State& state) const;
|
||||
|
||||
@@ -24,6 +24,8 @@ class SG_EXPORT TexMat : public StateAttribute
|
||||
|
||||
META_StateAttribute(osg, TexMat, TEXMAT);
|
||||
|
||||
virtual bool isTextureAttribute() const { return true; }
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const StateAttribute& sa) const
|
||||
{
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <osg/Types>
|
||||
#include <osg/Image>
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Vec4>
|
||||
|
||||
@@ -103,12 +102,14 @@ class SG_EXPORT Texture : public StateAttribute
|
||||
|
||||
META_StateAttribute(osg, Texture,TEXTURE);
|
||||
|
||||
virtual bool isTextureAttribute() const { return true; }
|
||||
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
virtual int compare(const StateAttribute& rhs) const;
|
||||
|
||||
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
ds.setMode(_target,value);
|
||||
modes.push_back(_target);
|
||||
}
|
||||
|
||||
/** Set the texture image. */
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#define OSG_TRANSPARENCY 1
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -39,9 +38,9 @@ class SG_EXPORT Transparency : public StateAttribute
|
||||
return 0; // passed all the above comparison macro's, must be equal.
|
||||
}
|
||||
|
||||
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
|
||||
virtual void getAssociatedModes(std::vector<GLMode>& modes) const
|
||||
{
|
||||
ds.setMode(GL_BLEND,value);
|
||||
modes.push_back(GL_BLEND);
|
||||
}
|
||||
|
||||
enum TransparencyMode {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#define OSG_VIEWPORT 1
|
||||
|
||||
#include <osg/StateAttribute>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Types>
|
||||
#include <osg/Matrix>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user