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:
Robert Osfield
2002-07-09 09:35:42 +00:00
parent 419e1360d5
commit 0c943945f7
36 changed files with 1054 additions and 593 deletions

View File

@@ -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 {

View File

@@ -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));
}

View File

@@ -7,7 +7,6 @@
#include <osg/Export>
#include <osg/StateAttribute>
#include <osg/StateSet>
#include <osg/Types>
namespace osg {

View File

@@ -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 {

View File

@@ -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

View File

@@ -6,7 +6,6 @@
#define OSG_DRAWABLE 1
#include <osg/BoundingBox>
#include <osg/StateSet>
#include <osg/State>
#include <osg/Types>
#include <osg/Vec2>

View File

@@ -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 {

View File

@@ -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.*/

View File

@@ -6,7 +6,6 @@
#define OSG_LIGHTMODEL 1
#include <osg/StateAttribute>
#include <osg/StateSet>
#include <osg/Vec4>
namespace osg {

View File

@@ -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; }

View File

@@ -6,7 +6,6 @@
#define OSG_LineWidth 1
#include <osg/StateAttribute>
#include <osg/StateSet>
namespace osg {

View File

@@ -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;

View File

@@ -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);

View File

@@ -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; }

View File

@@ -7,7 +7,6 @@
#include <osg/GL>
#include <osg/StateAttribute>
#include <osg/StateSet>
namespace osg {

View File

@@ -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

View File

@@ -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.
}

View File

@@ -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;

View File

@@ -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

View File

@@ -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
{

View File

@@ -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;

View File

@@ -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
{

View File

@@ -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. */

View File

@@ -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 {

View File

@@ -6,7 +6,6 @@
#define OSG_VIEWPORT 1
#include <osg/StateAttribute>
#include <osg/StateSet>
#include <osg/Types>
#include <osg/Matrix>

View File

@@ -102,7 +102,7 @@ void ClipNode::setStateSetModes(StateSet& stateset,const StateAttribute::GLModeV
itr!=_planes.end();
++itr)
{
(*itr)->setStateSetModes(stateset,value);
stateset.setAssociatedModes(itr->get(),value);
}
}

View File

@@ -419,6 +419,8 @@ void GeoSet::computeNumVerts() const
const bool GeoSet::computeBound() const
{
_bbox.init();
if( _iaformat == IA_OFF && _coords == (Vec3 *)0 ) return false;
if( _numcoords == 0 )
@@ -430,7 +432,6 @@ const bool GeoSet::computeBound() const
return false;
Vec3 center(0.0f,0.0f,0.0f);
_bbox.init();
int i;
if( _iaformat == IA_OFF )
@@ -1005,7 +1006,7 @@ void GeoSet::applyPrimitiveOperation(PrimitiveFunctor& functor)
if (_cindex._is_ushort)
functor.drawElements( (GLenum)_oglprimtype, _primLengths[i],&_cindex._ptr._ushort[index] );
else
functor.drawElements( (GLenum)_oglprimtype, _primLengths[i],&_cindex._ptr._ushort[index] );
functor.drawElements( (GLenum)_oglprimtype, _primLengths[i],&_cindex._ptr._uint[index] );
}
else
functor.drawArrays( (GLenum)_oglprimtype, index, _primLengths[i] );

View File

@@ -29,7 +29,7 @@ void LightSource::setStateSetModes(StateSet& stateset,const StateAttribute::GLMo
{
if (_light.valid())
{
_light->setStateSetModes(stateset,value);
stateset.setAssociatedModes(_light.get(),value);
}
}

View File

@@ -35,7 +35,8 @@ void State::reset()
_modeMap[GL_DEPTH_TEST].global_default_value = true;
_modeMap[GL_DEPTH_TEST].changed = true;
// go through all active StateAttribute's, applying where appropriate.
// go through all active StateAttribute's, setting to change to force update,
// the idea is to leave only the global defaults left.
for(AttributeMap::iterator aitr=_attributeMap.begin();
aitr!=_attributeMap.end();
++aitr)
@@ -44,9 +45,33 @@ void State::reset()
as.attributeVec.clear();
as.last_applied_attribute = NULL;
as.changed = true;
}
}
// we can do a straight clear, we arn't intrested in GL_DEPTH_TEST defaults in texture modes.
for(TextureModeMapList::iterator tmmItr=_textureModeMapList.begin();
tmmItr!=_textureModeMapList.end();
++tmmItr)
{
tmmItr->clear();
}
// _attributeMap.clear();
// empty all the texture attributes as per normal attributes, leaving only the global defaults left.
for(TextureAttributeMapList::iterator tamItr=_textureAttributeMapList.begin();
tamItr!=_textureAttributeMapList.end();
++tamItr)
{
AttributeMap& attributeMap = *tamItr;
// go through all active StateAttribute's, setting to change to force update.
for(AttributeMap::iterator aitr=attributeMap.begin();
aitr!=attributeMap.end();
++aitr)
{
AttributeStack& as = aitr->second;
as.attributeVec.clear();
as.last_applied_attribute = NULL;
as.changed = true;
}
}
_drawStateStack.clear();
@@ -59,62 +84,24 @@ void State::pushStateSet(const StateSet* dstate)
_drawStateStack.push_back(dstate);
if (dstate)
{
// iterator through all OpenGL modes in incomming StateSet
// for each GLMode entry push it to the back of the appropriate
// mode stack, taking into consideration current override status.
const StateSet::ModeList& ds_modeList = dstate->getModeList();
for(StateSet::ModeList::const_iterator mitr=ds_modeList.begin();
mitr!=ds_modeList.end();
++mitr)
pushModeList(_modeMap,dstate->getModeList());
// iterator through texture modes.
unsigned int unit;
const StateSet::TextureModeList& ds_textureModeList = dstate->getTextureModeList();
for(unit=0;unit<ds_textureModeList.size();++unit)
{
// 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;
pushModeList(getOrCreateTextureModeMap(unit),ds_textureModeList[unit]);
}
// iterator through all StateAttribute's in incomming StateSet
// for each Type entry push it to the back of the appropriate
// attribute stack, taking into consideration current override status.
const StateSet::AttributeList& ds_attributeList = dstate->getAttributeList();
for(StateSet::AttributeList::const_iterator aitr=ds_attributeList.begin();
aitr!=ds_attributeList.end();
++aitr)
pushAttributeList(_attributeMap,dstate->getAttributeList());
// iterator through texture attributes.
const StateSet::TextureAttributeList& ds_textureAttributeList = dstate->getTextureAttributeList();
for(unit=0;unit<ds_textureAttributeList.size();++unit)
{
// 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;
pushAttributeList(getOrCreateTextureAttributeMap(unit),ds_textureAttributeList[unit]);
}
}
@@ -129,38 +116,23 @@ void State::popStateSet()
if (dstate)
{
// iterator through all OpenGL modes in incomming StateSet
// for each GLMode entry pop_back of the appropriate
// mode stack.
const StateSet::ModeList& ds_modeList = dstate->getModeList();
for(StateSet::ModeList::const_iterator mitr=ds_modeList.begin();
mitr!=ds_modeList.end();
++mitr)
popModeList(_modeMap,dstate->getModeList());
// iterator through texture modes.
unsigned int unit;
const StateSet::TextureModeList& ds_textureModeList = dstate->getTextureModeList();
for(unit=0;unit<ds_textureModeList.size();++unit)
{
// 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;
popModeList(getOrCreateTextureModeMap(unit),ds_textureModeList[unit]);
}
// iterator through all StateAttribute's in incomming StateSet
// for each Type entry pop_back of the appropriate
// attribute stack.
const StateSet::AttributeList& ds_attributeList = dstate->getAttributeList();
for(StateSet::AttributeList::const_iterator aitr=ds_attributeList.begin();
aitr!=ds_attributeList.end();
++aitr)
popAttributeList(_attributeMap,dstate->getAttributeList());
// iterator through texture attributes.
const StateSet::TextureAttributeList& ds_textureAttributeList = dstate->getTextureAttributeList();
for(unit=0;unit<ds_textureAttributeList.size();++unit)
{
// 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;
popAttributeList(getOrCreateTextureAttributeMap(unit),ds_textureAttributeList[unit]);
}
}
@@ -209,253 +181,28 @@ void State::apply(const StateSet* dstate)
if (dstate)
{
// then handle mode changes.
applyModeList(_modeMap,dstate->getModeList());
applyAttributeList(_attributeMap,dstate->getAttributeList());
const StateSet::TextureModeList& ds_textureModeList = dstate->getTextureModeList();
const StateSet::TextureAttributeList& ds_textureAttributeList = dstate->getTextureAttributeList();
unsigned int unit;
unsigned int unitMax = std::max(ds_textureModeList.size(),ds_textureAttributeList.size());
unitMax = std::max(unitMax,_textureModeMapList.size());
unitMax = std::max(unitMax,_textureAttributeMapList.size());
for(unit=0;unit<unitMax;++unit)
{
const StateSet::ModeList& ds_modeList = dstate->getModeList();
StateSet::ModeList::const_iterator ds_mitr = ds_modeList.begin();
ModeMap::iterator this_mitr=_modeMap.begin();
while (this_mitr!=_modeMap.end() && ds_mitr!=ds_modeList.end())
if (setActiveTextureUnit(unit))
{
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!=ds_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;
if (unit<ds_textureModeList.size()) applyModeList(getOrCreateTextureModeMap(unit),ds_textureModeList[unit]);
else if (unit<_textureModeMapList.size()) applyModeMap(_textureModeMapList[unit]);
if (unit<ds_textureAttributeList.size()) applyAttributeList(getOrCreateTextureAttributeMap(unit),ds_textureAttributeList[unit]);
else if (unit<_textureAttributeMapList.size()) applyAttributeMap(_textureAttributeMapList[unit]);
}
}
// first handle attribute changes
{
const StateSet::AttributeList& ds_attributeList = dstate->getAttributeList();
StateSet::AttributeList::const_iterator ds_aitr=ds_attributeList.begin();
AttributeMap::iterator this_aitr=_attributeMap.begin();
while (this_aitr!=_attributeMap.end() && ds_aitr!=ds_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!=ds_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;
}
}
}
else
{
@@ -470,58 +217,90 @@ void State::apply()
// go through all active OpenGL modes, enabling/disable where
// appropriate.
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);
}
}
}
applyModeMap(_modeMap);
// go through all active StateAttribute's, applying where appropriate.
for(AttributeMap::iterator aitr=_attributeMap.begin();
aitr!=_attributeMap.end();
++aitr)
applyAttributeMap(_attributeMap);
unsigned int unit;
unsigned int unitMax = std::max(_textureModeMapList.size(),_textureAttributeMapList.size());
for(unit=0;unit<unitMax;++unit)
{
AttributeStack& as = aitr->second;
if (as.changed)
if (setActiveTextureUnit(unit))
{
as.changed = false;
if (!as.attributeVec.empty())
{
const StateAttribute* new_attr = as.attributeVec.back().first;
applyAttribute(new_attr,as);
}
else
{
applyGlobalDefaultAttribute(as);
}
if (unit<_textureModeMapList.size()) applyModeMap(_textureModeMapList[unit]);
if (unit<_textureAttributeMapList.size()) applyAttributeMap(_textureAttributeMapList[unit]);
}
}
}
}
/** mode has been set externally, update state to reflect this setting.*/
void State::haveAppliedMode(const StateAttribute::GLMode mode,const StateAttribute::GLModeValue value)
{
ModeStack& ms = _modeMap[mode];
haveAppliedMode(_modeMap,mode,value);
}
void State::haveAppliedMode(const StateAttribute::GLMode mode)
{
haveAppliedMode(_modeMap,mode);
}
void State::haveAppliedAttribute(const StateAttribute* attribute)
{
haveAppliedAttribute(_attributeMap,attribute);
}
void State::haveAppliedAttribute(const StateAttribute::Type type)
{
haveAppliedAttribute(_attributeMap,type);
}
const bool State::getLastAppliedMode(const StateAttribute::GLMode mode) const
{
return getLastAppliedMode(_modeMap,mode);
}
const StateAttribute* State::getLastAppliedAttribute(const StateAttribute::Type type) const
{
return getLastAppliedAttribute(_attributeMap,type);
}
void State::haveAppliedTextureMode(unsigned int unit,const StateAttribute::GLMode mode,const StateAttribute::GLModeValue value)
{
haveAppliedMode(getOrCreateTextureModeMap(unit),mode,value);
}
void State::haveAppliedTextureMode(unsigned int unit,const StateAttribute::GLMode mode)
{
haveAppliedMode(getOrCreateTextureModeMap(unit),mode);
}
void State::haveAppliedTextureAttribute(unsigned int unit,const StateAttribute* attribute)
{
haveAppliedAttribute(getOrCreateTextureAttributeMap(unit),attribute);
}
void State::haveAppliedTextureAttribute(unsigned int unit,const StateAttribute::Type type)
{
haveAppliedAttribute(getOrCreateTextureAttributeMap(unit),type);
}
const bool State::getLastAppliedTextureMode(unsigned int unit,const StateAttribute::GLMode mode) const
{
if (unit>=_textureModeMapList.size()) return false;
return getLastAppliedMode(_textureModeMapList[unit],mode);
}
const StateAttribute* State::getLastAppliedTextureAttribute(unsigned int unit,const StateAttribute::Type type) const
{
if (unit>=_textureAttributeMapList.size()) return false;
return getLastAppliedAttribute(_textureAttributeMapList[unit],type);
}
void State::haveAppliedMode(ModeMap& modeMap,const StateAttribute::GLMode mode,const StateAttribute::GLModeValue value)
{
ModeStack& ms = modeMap[mode];
ms.last_applied_value = value & StateAttribute::ON;
@@ -530,9 +309,9 @@ void State::haveAppliedMode(const StateAttribute::GLMode mode,const StateAttribu
}
/** mode has been set externally, update state to reflect this setting.*/
void State::haveAppliedMode(const StateAttribute::GLMode mode)
void State::haveAppliedMode(ModeMap& modeMap,const StateAttribute::GLMode mode)
{
ModeStack& ms = _modeMap[mode];
ModeStack& ms = modeMap[mode];
// don't know what last applied value is can't apply it.
// assume that it has changed by toggle the value of last_applied_value.
@@ -543,11 +322,11 @@ void State::haveAppliedMode(const StateAttribute::GLMode mode)
}
/** attribute has been applied externally, update state to reflect this setting.*/
void State::haveAppliedAttribute(const StateAttribute* attribute)
void State::haveAppliedAttribute(AttributeMap& attributeMap,const StateAttribute* attribute)
{
if (attribute)
{
AttributeStack& as = _attributeMap[attribute->getType()];
AttributeStack& as = attributeMap[attribute->getType()];
as.last_applied_attribute = attribute;
@@ -556,11 +335,11 @@ void State::haveAppliedAttribute(const StateAttribute* attribute)
}
}
void State::haveAppliedAttribute(const StateAttribute::Type type)
void State::haveAppliedAttribute(AttributeMap& attributeMap,const StateAttribute::Type type)
{
AttributeMap::iterator itr = _attributeMap.find(type);
if (itr!=_attributeMap.end())
AttributeMap::iterator itr = attributeMap.find(type);
if (itr!=attributeMap.end())
{
AttributeStack& as = itr->second;
as.last_applied_attribute = 0L;
@@ -570,10 +349,10 @@ void State::haveAppliedAttribute(const StateAttribute::Type type)
}
}
const bool State::getLastAppliedMode(const StateAttribute::GLMode mode) const
const bool State::getLastAppliedMode(const ModeMap& modeMap,const StateAttribute::GLMode mode) const
{
ModeMap::const_iterator itr = _modeMap.find(mode);
if (itr!=_modeMap.end())
ModeMap::const_iterator itr = modeMap.find(mode);
if (itr!=modeMap.end())
{
const ModeStack& ms = itr->second;
return ms.last_applied_value;
@@ -584,10 +363,10 @@ const bool State::getLastAppliedMode(const StateAttribute::GLMode mode) const
}
}
const StateAttribute* State::getLastAppliedAttribute(const StateAttribute::Type type) const
const StateAttribute* State::getLastAppliedAttribute(const AttributeMap& attributeMap,const StateAttribute::Type type) const
{
AttributeMap::const_iterator itr = _attributeMap.find(type);
if (itr!=_attributeMap.end())
AttributeMap::const_iterator itr = attributeMap.find(type);
if (itr!=attributeMap.end())
{
const AttributeStack& as = itr->second;
return as.last_applied_attribute;
@@ -598,7 +377,6 @@ const StateAttribute* State::getLastAppliedAttribute(const StateAttribute::Type
}
}
Polytope State::getViewFrustum() const
{
Polytope cv;

View File

@@ -230,6 +230,73 @@ int StateSet::compare(const StateSet& rhs,bool compareAttributeContents) const
return 0;
}
int StateSet::compareModes(const ModeList& lhs,const ModeList& rhs)
{
ModeList::const_iterator lhs_mode_itr = lhs.begin();
ModeList::const_iterator rhs_mode_itr = rhs.begin();
while (lhs_mode_itr!=lhs.end() && rhs_mode_itr!=rhs.end())
{
if (lhs_mode_itr->first<rhs_mode_itr->first) return -1;
else if (rhs_mode_itr->first<lhs_mode_itr->first) return 1;
if (lhs_mode_itr->second<rhs_mode_itr->second) return -1;
else if (rhs_mode_itr->second<lhs_mode_itr->second) return 1;
++lhs_mode_itr;
++rhs_mode_itr;
}
if (lhs_mode_itr==lhs.end())
{
if (rhs_mode_itr!=rhs.end()) return -1;
}
else if (rhs_mode_itr == rhs.end()) return 1;
return 0;
}
int StateSet::compareAttributePtrs(const AttributeList& lhs,const AttributeList& rhs)
{
AttributeList::const_iterator lhs_attr_itr = lhs.begin();
AttributeList::const_iterator rhs_attr_itr = rhs.begin();
while (lhs_attr_itr!=lhs.end() && rhs_attr_itr!=rhs.end())
{
if (lhs_attr_itr->first<rhs_attr_itr->first) return -1;
else if (rhs_attr_itr->first<lhs_attr_itr->first) return 1;
if (lhs_attr_itr->second.first<rhs_attr_itr->second.first) return -1;
else if (rhs_attr_itr->second.first<lhs_attr_itr->second.first) return 1;
if (lhs_attr_itr->second.second<rhs_attr_itr->second.second) return -1;
else if (rhs_attr_itr->second.second<lhs_attr_itr->second.second) return 1;
++lhs_attr_itr;
++rhs_attr_itr;
}
if (lhs_attr_itr==lhs.end())
{
if (rhs_attr_itr!=rhs.end()) return -1;
}
else if (rhs_attr_itr == rhs.end()) return 1;
return 0;
}
int StateSet::compareAttributeContents(const AttributeList& lhs,const AttributeList& rhs)
{
AttributeList::const_iterator lhs_attr_itr = lhs.begin();
AttributeList::const_iterator rhs_attr_itr = rhs.begin();
while (lhs_attr_itr!=lhs.end() && rhs_attr_itr!=rhs.end())
{
if (lhs_attr_itr->first<rhs_attr_itr->first) return -1;
else if (rhs_attr_itr->first<lhs_attr_itr->first) return 1;
if (*(lhs_attr_itr->second.first)<*(rhs_attr_itr->second.first)) return -1;
else if (*(rhs_attr_itr->second.first)<*(lhs_attr_itr->second.first)) return 1;
if (lhs_attr_itr->second.second<rhs_attr_itr->second.second) return -1;
else if (rhs_attr_itr->second.second<lhs_attr_itr->second.second) return 1;
++lhs_attr_itr;
++rhs_attr_itr;
}
if (lhs_attr_itr==lhs.end())
{
if (rhs_attr_itr!=rhs.end()) return -1;
}
else if (rhs_attr_itr == rhs.end()) return 1;
return 0;
}
void StateSet::setGlobalDefaults()
{
_renderingHint = DEFAULT_BIN;
@@ -244,30 +311,6 @@ void StateSet::setGlobalDefaults()
Material *material = osgNew Material;
material->setColorMode(Material::AMBIENT_AND_DIFFUSE);
setAttributeAndModes(material,StateAttribute::ON);
/*
setMode(GL_LIGHTING,StateAttribute::OFF);
setMode(GL_FOG,StateAttribute::OFF);
setMode(GL_POINT_SMOOTH,StateAttribute::OFF);
setMode(GL_TEXTURE_2D,StateAttribute::OFF);
setMode(GL_TEXTURE_GEN_S,StateAttribute::OFF);
setMode(GL_TEXTURE_GEN_T,StateAttribute::OFF);
setMode(GL_TEXTURE_GEN_R,StateAttribute::OFF);
setMode(GL_TEXTURE_GEN_Q,StateAttribute::OFF);
setAttributeAndModes(osgNew AlphaFunc,StateAttribute::OFF);
setAttributeAndModes(osgNew CullFace,StateAttribute::ON);
setAttributeAndModes(osgNew FrontFace,StateAttribute::ON);
Material *material = osgNew Material;
material->setColorMode(Material::AMBIENT_AND_DIFFUSE);
setAttributeAndModes(material,StateAttribute::ON);
setAttributeAndModes(osgNew PolygonMode,StateAttribute::OFF);
setAttributeAndModes(osgNew Transparency,StateAttribute::OFF);
setAttributeAndModes(osgNew Depth,StateAttribute::ON);
*/
}
@@ -402,45 +445,60 @@ void StateSet::merge(const StateSet& rhs)
void StateSet::setMode(const StateAttribute::GLMode mode, const StateAttribute::GLModeValue value)
{
if ((value&StateAttribute::INHERIT)) setModeToInherit(mode);
else _modeList[mode] = value;
setMode(_modeList,mode,value);
}
void StateSet::setModeToInherit(const StateAttribute::GLMode mode)
{
ModeList::iterator itr = _modeList.find(mode);
if (itr!=_modeList.end())
{
_modeList.erase(itr);
}
setModeToInherit(_modeList,mode);
}
const StateAttribute::GLModeValue StateSet::getMode(const StateAttribute::GLMode mode) const
{
ModeList::const_iterator itr = _modeList.find(mode);
if (itr!=_modeList.end())
{
return itr->second;
}
else
return StateAttribute::INHERIT;
return getMode(_modeList,mode);
}
void StateSet::setAttribute(StateAttribute *attribute, const StateAttribute::OverrideValue value)
{
if (attribute)
{
if ((value&StateAttribute::INHERIT)) setAttributeToInherit(attribute->getType());
else _attributeList[attribute->getType()] = RefAttributePair(attribute,value&StateAttribute::OVERRIDE);
}
if (!attribute->isTextureAttribute())
{
setAttribute(_attributeList,attribute,value);
}
else
{
notify(NOTICE)<<"Warning: texture attribute '"<<attribute->className()<<"'passed to setAttribute(attr,value), "<<std::endl;
notify(NOTICE)<<" assuming setTextureAttribute(unit=0,attr,value) instead."<<std::endl;
notify(NOTICE)<<" please change calling code to use appropriate call."<<std::endl;
setTextureAttribute(0,attribute,value);
}
}
}
void StateSet::setAttributeAndModes(StateAttribute *attribute, const StateAttribute::GLModeValue value)
{
if (attribute)
{
_attributeList[attribute->getType()] = RefAttributePair(attribute,value&StateAttribute::OVERRIDE);
attribute->setStateSetModes(*this,value);
if (!attribute->isTextureAttribute())
{
if (value&StateAttribute::INHERIT)
{
setAttributeToInherit(attribute->getType());
}
else
{
setAttribute(_attributeList,attribute,value);
setAssociatedModes(_modeList,attribute,value);
}
}
else
{
notify(NOTICE)<<"Warning: texture attribute '"<<attribute->className()<<"' passed to setAttributeAndModes(attr,value), "<<std::endl;
notify(NOTICE)<<" assuming setTextureAttributeAndModes(unit=0,attr,value) instead."<<std::endl;
notify(NOTICE)<<" please change calling code to use appropriate call."<<std::endl;
setTextureAttributeAndModes(0,attribute,value);
}
}
}
@@ -449,86 +507,65 @@ void StateSet::setAttributeToInherit(const StateAttribute::Type type)
AttributeList::iterator itr = _attributeList.find(type);
if (itr!=_attributeList.end())
{
itr->second.first->setStateSetModes(*this,StateAttribute::INHERIT);
setAssociatedModes(_modeList,itr->second.first.get(),StateAttribute::INHERIT);
_attributeList.erase(itr);
}
}
StateAttribute* StateSet::getAttribute(const StateAttribute::Type type)
{
AttributeList::iterator itr = _attributeList.find(type);
if (itr!=_attributeList.end())
{
return itr->second.first.get();
}
else
return NULL;
return getAttribute(_attributeList,type);
}
const StateAttribute* StateSet::getAttribute(const StateAttribute::Type type) const
{
AttributeList::const_iterator itr = _attributeList.find(type);
if (itr!=_attributeList.end())
{
return itr->second.first.get();
}
else
return NULL;
return getAttribute(_attributeList,type);
}
const StateSet::RefAttributePair* StateSet::getAttributePair(const StateAttribute::Type type) const
{
AttributeList::const_iterator itr = _attributeList.find(type);
if (itr!=_attributeList.end())
{
return &(itr->second);
}
else
return NULL;
return getAttributePair(_attributeList,type);
}
void StateSet::setAssociatedModes(const StateAttribute* attribute, const StateAttribute::GLModeValue value)
{
setAssociatedModes(_modeList,attribute,value);
}
void StateSet::setTextureMode(unsigned int unit,const StateAttribute::GLMode mode, const StateAttribute::GLModeValue value)
{
ModeList& modeList = getOrCreateTextureModeList(unit);
if ((value&StateAttribute::INHERIT)) setTextureModeToInherit(unit,mode);
else modeList[mode] = value;
setMode(getOrCreateTextureModeList(unit),mode,value);
}
void StateSet::setTextureModeToInherit(unsigned int unit,const StateAttribute::GLMode mode)
{
if (unit>=_textureModeList.size()) return;
ModeList& modeList = _textureModeList[unit];
ModeList::iterator itr = modeList.find(mode);
if (itr!=modeList.end())
{
modeList.erase(itr);
}
setModeToInherit(_textureModeList[unit],mode);
}
const StateAttribute::GLModeValue StateSet::getTextureMode(unsigned int unit,const StateAttribute::GLMode mode) const
{
if (unit>=_textureModeList.size()) return StateAttribute::INHERIT;
const ModeList& modeList = _textureModeList[unit];
ModeList::const_iterator itr = modeList.find(mode);
if (itr!=modeList.end())
{
return itr->second;
}
else
return StateAttribute::INHERIT;
return getMode(_textureModeList[unit],mode);
}
void StateSet::setTextureAttribute(unsigned int unit,StateAttribute *attribute, const StateAttribute::OverrideValue value)
{
if (attribute)
{
AttributeList& attributeList = getOrCreateTextureAttributeList(unit);
if ((value&StateAttribute::INHERIT)) setAttributeToInherit(attribute->getType());
else attributeList[attribute->getType()] = RefAttributePair(attribute,value&StateAttribute::OVERRIDE);
if (attribute->isTextureAttribute())
{
setAttribute(getOrCreateTextureAttributeList(unit),attribute,value);
}
else
{
notify(NOTICE)<<"Warning: texture attribute '"<<attribute->className()<<"' passed to setTextureAttribute(unit,attr,value), "<<std::endl;
notify(NOTICE)<<" assuming setAttribute(attr,value) instead."<<std::endl;
notify(NOTICE)<<" please change calling code to use appropriate call."<<std::endl;
setAttribute(attribute,value);
}
}
}
@@ -537,9 +574,26 @@ void StateSet::setTextureAttributeAndModes(unsigned int unit,StateAttribute *att
{
if (attribute)
{
AttributeList& attributeList = getOrCreateTextureAttributeList(unit);
attributeList[attribute->getType()] = RefAttributePair(attribute,value&StateAttribute::OVERRIDE);
attribute->setStateSetModes(*this,value);
if (attribute->isTextureAttribute())
{
if (value&StateAttribute::INHERIT)
{
setTextureAttributeToInherit(unit,attribute->getType());
}
else
{
setAttribute(getOrCreateTextureAttributeList(unit),attribute,value);
setAssociatedModes(getOrCreateTextureModeList(unit),attribute,value);
}
}
else
{
notify(NOTICE)<<"Warning: non texture attribute '"<<attribute->className()<<"' passed to setTextureAttributeAndModes(unit,attr,value), "<<std::endl;
notify(NOTICE)<<" assuming setAttributeAndModes(attr,value) instead."<<std::endl;
notify(NOTICE)<<" please change calling code to use appropriate call."<<std::endl;
setAttribute(attribute,value);
}
}
}
@@ -551,7 +605,10 @@ void StateSet::setTextureAttributeToInherit(unsigned int unit,const StateAttribu
AttributeList::iterator itr = attributeList.find(type);
if (itr!=attributeList.end())
{
itr->second.first->setStateSetModes(*this,StateAttribute::INHERIT);
if (unit<_textureModeList.size())
{
setAssociatedModes(_textureModeList[unit],itr->second.first.get(),StateAttribute::INHERIT);
}
attributeList.erase(itr);
}
}
@@ -560,44 +617,27 @@ void StateSet::setTextureAttributeToInherit(unsigned int unit,const StateAttribu
StateAttribute* StateSet::getTextureAttribute(unsigned int unit,const StateAttribute::Type type)
{
if (unit>=_textureAttributeList.size()) return 0;
AttributeList& attributeList = _textureAttributeList[unit];
AttributeList::iterator itr = attributeList.find(type);
if (itr!=attributeList.end())
{
return itr->second.first.get();
}
else
return NULL;
return getAttribute(_textureAttributeList[unit],type);
}
const StateAttribute* StateSet::getTextureAttribute(unsigned int unit,const StateAttribute::Type type) const
{
if (unit>=_textureAttributeList.size()) return 0;
const AttributeList& attributeList = _textureAttributeList[unit];
AttributeList::const_iterator itr = attributeList.find(type);
if (itr!=attributeList.end())
{
return itr->second.first.get();
}
else
return NULL;
return getAttribute(_textureAttributeList[unit],type);
}
const StateSet::RefAttributePair* StateSet::getTextureAttributePair(unsigned int unit,const StateAttribute::Type type) const
{
if (unit>=_textureAttributeList.size()) return 0;
const AttributeList& attributeList = _textureAttributeList[unit];
AttributeList::const_iterator itr = attributeList.find(type);
if (itr!=attributeList.end())
{
return &(itr->second);
}
else
return NULL;
return getAttributePair(_textureAttributeList[unit],type);
}
void StateSet::setAssociatedTextureModes(unsigned int unit,const StateAttribute* attribute, const StateAttribute::GLModeValue value)
{
setAssociatedModes(getOrCreateTextureModeList(unit),attribute,value);
}
void StateSet::compile(State& state) const
@@ -649,7 +689,88 @@ void StateSet::setRendingBinToInherit()
_binName = "";
}
void StateSet::setMode(ModeList& modeList,const StateAttribute::GLMode mode, const StateAttribute::GLModeValue value)
{
if ((value&StateAttribute::INHERIT)) setModeToInherit(modeList,mode);
else modeList[mode] = value;
}
void StateSet::setModeToInherit(ModeList& modeList,const StateAttribute::GLMode mode)
{
ModeList::iterator itr = modeList.find(mode);
if (itr!=modeList.end())
{
modeList.erase(itr);
}
}
const StateAttribute::GLModeValue StateSet::getMode(const ModeList& modeList,const StateAttribute::GLMode mode) const
{
ModeList::const_iterator itr = modeList.find(mode);
if (itr!=modeList.end())
{
return itr->second;
}
else
return StateAttribute::INHERIT;
}
void StateSet::setAssociatedModes(ModeList& modeList,const StateAttribute* attribute, const StateAttribute::GLModeValue value)
{
// get the associated modes.
std::vector<StateAttribute::GLMode> modes;
attribute->getAssociatedModes(modes);
// set the modes on the StateSet.
for(std::vector<StateAttribute::GLMode>::iterator itr=modes.begin();
itr!=modes.end();
++itr)
{
setMode(modeList,*itr,value);
}
}
void StateSet::setAttribute(AttributeList& attributeList,StateAttribute *attribute, const StateAttribute::OverrideValue value)
{
if (attribute)
{
attributeList[attribute->getType()] = RefAttributePair(attribute,value&StateAttribute::OVERRIDE);
}
}
StateAttribute* StateSet::getAttribute(AttributeList& attributeList,const StateAttribute::Type type)
{
AttributeList::iterator itr = attributeList.find(type);
if (itr!=attributeList.end())
{
return itr->second.first.get();
}
else
return NULL;
}
const StateAttribute* StateSet::getAttribute(const AttributeList& attributeList,const StateAttribute::Type type) const
{
AttributeList::const_iterator itr = attributeList.find(type);
if (itr!=attributeList.end())
{
return itr->second.first.get();
}
else
return NULL;
}
const StateSet::RefAttributePair* StateSet::getAttributePair(const AttributeList& attributeList,const StateAttribute::Type type) const
{
AttributeList::const_iterator itr = attributeList.find(type);
if (itr!=attributeList.end())
{
return &(itr->second);
}
else
return NULL;
}

View File

@@ -197,12 +197,11 @@ void Texture::apply(State& state) const
}
else if (_image.valid() && _image->data())
{
glBindTexture( _target, handle );
uint& modifiedTag = getModifiedTag(contextID);
if (_subloadMode == AUTO ||
(_subloadMode == IF_DIRTY && modifiedTag != _image->getModifiedTag()))
{
glBindTexture( _target, handle );
if (_texParamtersDirty) applyTexParameters(_target,state);
glTexSubImage2D(_target, 0,
_subloadOffsX, _subloadOffsY,

View File

@@ -661,9 +661,16 @@ StateSet* Attr::createOsgStateSet()
// break;
}
osgStateSet->setAttribute( osgTexEnv );
osgStateSet->setAttributeAndModes( osgTexture, StateAttribute::ON );
// I have just ported the two below set*Attribute lines to use the new
// texture attribute methods, however this tieing to the texture unit 0
// is probably inappropriate. Perhaps it would be better to create a
// StateSet to store the texture an modes, it is probably best
// to use an intermediate data structure for the flt loader to use to
// encapsulate ATTR files. Need to speak to Brede about this issue.
// Robert Osfield, July 9th 2002.
osgStateSet->setTextureAttribute( 0, osgTexEnv );
osgStateSet->setTextureAttributeAndModes( 0, osgTexture, StateAttribute::ON );
return osgStateSet;
}

View File

@@ -465,6 +465,9 @@ void ConvertFromFLT::visitTexturePalette(osg::Group& , TexturePaletteRecord* rec
pTexturePool->addTexture(nIndex, osgStateSet);
return; // Texture already loaded
}
unsigned int unit = 0;
// Read texture and attribute file
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(pFilename);
@@ -490,26 +493,28 @@ void ConvertFromFLT::visitTexturePalette(osg::Group& , TexturePaletteRecord* rec
osg::Texture* osgTexture = new osg::Texture;
osgTexture->setWrap(osg::Texture::WRAP_S,osg::Texture::REPEAT);
osgTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::REPEAT);
osgStateSet->setAttributeAndModes(osgTexture,osg::StateAttribute::ON);
osgStateSet->setTextureAttributeAndModes( unit, osgTexture,osg::StateAttribute::ON);
osg::TexEnv* osgTexEnv = new osg::TexEnv;
osgTexEnv->setMode(osg::TexEnv::MODULATE);
osgStateSet->setAttribute( osgTexEnv );
osgStateSet->setTextureAttribute( unit, osgTexEnv );
}
osg::Texture *osgTexture = dynamic_cast<osg::Texture*>(osgStateSet->getAttribute( osg::StateAttribute::TEXTURE));
osg::Texture *osgTexture = dynamic_cast<osg::Texture*>(osgStateSet->getTextureAttribute( unit, osg::StateAttribute::TEXTURE));
if (osgTexture == NULL)
{
osgTexture = new osg::Texture;
osgStateSet->setAttributeAndModes(osgTexture,osg::StateAttribute::ON);
osgStateSet->setTextureAttributeAndModes( unit, osgTexture,osg::StateAttribute::ON);
}
osgTexture->setImage(image.get());
// Add new texture to registry pool
// ( umm... should this have reference to the texture unit? RO. July2002)
Registry::instance()->addTexture(pFilename, osgStateSet);
// Also add to local pool to be able to get texture by index.
// ( umm... should this have reference to the texture unit? RO. July2002)
pTexturePool->addTexture(nIndex, osgStateSet);
}
}
@@ -913,7 +918,7 @@ void ConvertFromFLT::visitFace(GeoSetBuilder* pBuilder, FaceRecord* rec)
osgStateSet->merge(*textureStateSet);
// Alpha channel in texture?
osg::Texture *osgTexture = dynamic_cast<osg::Texture*>(textureStateSet->getAttribute( osg::StateAttribute::TEXTURE));
osg::Texture *osgTexture = dynamic_cast<osg::Texture*>(textureStateSet->getTextureAttribute( 0, osg::StateAttribute::TEXTURE));
if (osgTexture)
{
osg::Image* osgImage = osgTexture->getImage();
@@ -931,7 +936,7 @@ void ConvertFromFLT::visitFace(GeoSetBuilder* pBuilder, FaceRecord* rec)
{
osg::TexGen* osgTexGen = new osg::TexGen;
osgTexGen->setMode(osg::TexGen::SPHERE_MAP);
osgStateSet->setAttributeAndModes(osgTexGen,osg::StateAttribute::ON);
osgStateSet->setTextueAttributeAndModes( 0, osgTexGen,osg::StateAttribute::ON);
}
#endif

View File

@@ -221,7 +221,7 @@ bool GeoState_readLocalData(Object& obj, Input& fr)
statset.setAttribute(attribute);
if (attribute->getType()==StateAttribute::TEXGEN)
attribute->setStateSetModes(statset,texgening);
statset.setAssociatedModes(attribute,texgening);
iteratorAdvanced = true;
}
@@ -347,6 +347,74 @@ bool StateSet_readLocalData(Object& obj, Input& fr)
stateset.setAttribute(attribute);
iteratorAdvanced = true;
}
while(fr.matchSequence("textureUnit %i {"))
{
int entry = fr[0].getNoNestedBrackets();
unsigned int unit=0;
fr[1].getUInt(unit);
fr+=3;
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
bool localIteratorAdvanced = false;
bool readingMode = true;
StateAttribute::GLModeValue value;
while (readingMode)
{
readingMode=false;
if (fr[0].isInt())
{
if (StateSet_matchModeStr(fr[1].getStr(),value))
{
int mode;
fr[0].getInt(mode);
stateset.setTextureMode(unit,(StateAttribute::GLMode)mode,value);
fr+=2;
localIteratorAdvanced = true;
readingMode=true;
}
}
else
if (fr[0].getStr())
{
if (StateSet_matchModeStr(fr[1].getStr(),value))
{
GLNameToGLModeMap::iterator nitr = s_GLNameToGLModeMap.find(fr[0].getStr());
if (nitr!=s_GLNameToGLModeMap.end())
{
StateAttribute::GLMode mode = nitr->second;
stateset.setTextureMode(unit,mode,value);
fr+=2;
localIteratorAdvanced = true;
readingMode=true;
}
}
}
}
StateAttribute* attribute = NULL;
while((attribute=fr.readStateAttribute())!=NULL)
{
stateset.setTextureAttribute(unit,attribute);
localIteratorAdvanced = true;
}
if (!localIteratorAdvanced)
fr.advanceOverCurrentFieldOrBlock();
}
// skip over trailing '}'
++fr;
iteratorAdvanced = true;
}
return iteratorAdvanced;
}
@@ -409,6 +477,49 @@ bool StateSet_writeLocalData(const Object& obj, Output& fw)
{
fw.writeObject(*(sitr->second.first));
}
const StateSet::TextureModeList& tml = stateset.getTextureModeList();
const StateSet::TextureAttributeList& tal = stateset.getTextureAttributeList();
unsigned int maxUnit = std::max(tml.size(),tal.size());
for(unsigned int unit=0;unit<maxUnit;++unit)
{
fw.indent()<<"textureUnit "<<unit<<" {"<< std::endl;
fw.moveIn();
if (unit<tml.size())
{
const StateSet::ModeList& ml = tml[unit];
for(StateSet::ModeList::const_iterator mitr=ml.begin();
mitr!=ml.end();
++mitr)
{
GLModeToGLNameMap::iterator nitr = s_GLModeToGLNameMap.find(mitr->first);
if (nitr!=s_GLModeToGLNameMap.end())
{
fw.indent() << nitr->second << " " << StateSet_getModeStr(mitr->second) << std::endl;
}
else
{
// no name defined for GLMode so just pass its value to fw.
fw.indent() << "0x" << std::hex << (osg::uint)mitr->first << std::dec <<" " << StateSet_getModeStr(mitr->second) << std::endl;
}
}
}
if (unit<tal.size())
{
const StateSet::AttributeList& sl = tal[unit];
for(StateSet::AttributeList::const_iterator sitr=sl.begin();
sitr!=sl.end();
++sitr)
{
fw.writeObject(*(sitr->second.first));
}
}
fw.moveOut();
fw.indent()<<"}"<< std::endl;
}
return true;
}

View File

@@ -72,7 +72,9 @@ void Optimizer::optimize(osg::Node* node, unsigned int options)
if (options & SHARE_DUPLICATE_STATE)
{
#if (defined(_MSC_VER) && _MSC_VER<1300 && !defined(_STLPORT_VERSION))
osg::notify(osg::INFO)<<"Warning: VisualStudio 6.0 build, unable to run state optimizer"<<std::endl;
osg::notify(osg::NOTICE)<<"Warning: VisualStudio 6.0 native STL build, unable to run state optimizer due to bugs in its STL."<<std::endl;
osg::notify(osg::NOTICE)<<" This may impare performance significantly for larger models. It is recommend that one "<<std::endl;
osg::notify(osg::NOTICE)<<" compiles against STLport or use Visual Studio .NET compiler which also fix these VS 6.0 STL bugs "<<std::endl;
#else
StateVisitor osv;
node->accept(osv);
@@ -216,9 +218,12 @@ void Optimizer::StateVisitor::optimize()
{
// create map from state attributes to stateset which contain them.
typedef std::set<osg::StateSet*> StateSetList;
typedef std::pair<osg::StateSet*,unsigned int> StateSetUnitPair;
typedef std::set<StateSetUnitPair> StateSetList;
typedef std::map<osg::StateAttribute*,StateSetList> AttributeToStateSetMap;
const unsigned int NON_TEXTURE_ATTRIBUTE = 0xffffffff;
AttributeToStateSetMap _attributeToStateSetMap;
// NOTE will need to track state attribute override value too.
@@ -234,9 +239,26 @@ void Optimizer::StateVisitor::optimize()
{
if (aitr->second.first->getDataVariance()==osg::Object::STATIC)
{
_attributeToStateSetMap[aitr->second.first.get()].insert(sitr->first);
_attributeToStateSetMap[aitr->second.first.get()].insert(StateSetUnitPair(sitr->first,NON_TEXTURE_ATTRIBUTE));
}
}
osg::StateSet::TextureAttributeList& texAttributes = sitr->first->getTextureAttributeList();
for(unsigned int unit=0;unit<texAttributes.size();++unit)
{
osg::StateSet::AttributeList& attributes = texAttributes[unit];
for(osg::StateSet::AttributeList::iterator aitr= attributes.begin();
aitr!=attributes.end();
++aitr)
{
if (aitr->second.first->getDataVariance()==osg::Object::STATIC)
{
_attributeToStateSetMap[aitr->second.first.get()].insert(StateSetUnitPair(sitr->first,unit));
}
}
}
}
if (_attributeToStateSetMap.size()<2)
@@ -284,8 +306,10 @@ void Optimizer::StateVisitor::optimize()
++sitr)
{
osg::notify(osg::INFO) << " replace duplicate "<<*current<<" with "<<*first_unique<< std::endl;
osg::StateSet* stateset = *sitr;
stateset->setAttribute(*first_unique);
osg::StateSet* stateset = sitr->first;
unsigned int unit = sitr->second;
if (unit==NON_TEXTURE_ATTRIBUTE) stateset->setAttribute(*first_unique);
else stateset->setTextureAttribute(unit,*first_unique);
}
}
else first_unique = current;

View File

@@ -88,7 +88,7 @@ void SceneView::setDefaults()
// enable lighting by default.
_globalState->setMode(GL_LIGHTING, osg::StateAttribute::ON);
_light->setStateSetModes(*_globalState,osg::StateAttribute::ON);
_globalState->setAssociatedModes(_light.get(),osg::StateAttribute::ON);
// enable depth testing by default.
_globalState->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
@@ -98,10 +98,10 @@ void SceneView::setDefaults()
alphafunc->setFunction(osg::AlphaFunc::GREATER,0.0f);
_globalState->setAttributeAndModes(alphafunc, osg::StateAttribute::ON);
// set up an alphafunc by default to speed up blending operations.
osg::TexEnv* texenv = osgNew osg::TexEnv;
texenv->setMode(osg::TexEnv::MODULATE);
_globalState->setAttributeAndModes(texenv, osg::StateAttribute::ON);
// set up an texture environment by default to speed up blending operations.
osg::TexEnv* texenv = osgNew osg::TexEnv;
texenv->setMode(osg::TexEnv::MODULATE);
_globalState->setTextureAttributeAndModes(0,texenv, osg::StateAttribute::ON);
osg::LightModel* lightmodel = osgNew osg::LightModel;
lightmodel->setAmbientIntensity(osg::Vec4(0.0f,0.0f,0.0f,1.0f));