2001-09-20 05:19:47 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <osg/StateSet>
|
|
|
|
#include <osg/State>
|
|
|
|
#include <osg/Notify>
|
|
|
|
|
|
|
|
#include <osg/AlphaFunc>
|
|
|
|
#include <osg/Material>
|
|
|
|
#include <osg/CullFace>
|
|
|
|
#include <osg/FrontFace>
|
|
|
|
#include <osg/PolygonMode>
|
2002-07-13 02:12:01 +08:00
|
|
|
#include <osg/BlendFunc>
|
2001-09-30 02:34:26 +08:00
|
|
|
#include <osg/Depth>
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
|
|
|
StateSet::StateSet()
|
|
|
|
{
|
Added DataVariance enum and set/get fields to osg::Object to help identify
which objects have values that vary over the lifetime of the object (DYNAMIC)
and ones that do not vary (STATIC). Removed the equivalent code in
osg::Transform, StateSet and StateAttribute, as these are now encompassed
by the new DataVariance field.
Removed MatrixMode enum from Matrix, and associated fields/parameters from
osg::Transfrom and osg::NodeVisitor, since MatrixMode was not providing
any useful functionality, but made the interface more complex (MatrixMode
was an experimental API)
Added ReferenceFrame field to osg::Transform which allows users to specify
transforms that are relative to their parents (the default, and previous behavior)
or absolute reference frame, which can be used for HUD's, camera relative
light sources etc etc. Note, the view frustum culling for absolute Transform
are disabled, and all their parents up to the root are also automatically
have view frustum culling disabled. However, once passed an absolute Transform
node culling will return to its default state of on, so you can still cull
underneath an absolute transform, its only the culling above which is disabled.
2002-04-12 07:20:23 +08:00
|
|
|
setDataVariance(osg::StateAttribute::STATIC);
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
_renderingHint = DEFAULT_BIN;
|
|
|
|
|
|
|
|
setRendingBinToInherit();
|
|
|
|
}
|
|
|
|
|
2002-01-29 22:04:06 +08:00
|
|
|
StateSet::StateSet(const StateSet& rhs,const CopyOp& copyop):Object(rhs,copyop)
|
2001-10-23 06:02:47 +08:00
|
|
|
{
|
|
|
|
_modeList = rhs._modeList;
|
2002-01-29 20:52:04 +08:00
|
|
|
|
|
|
|
for(AttributeList::const_iterator itr=rhs._attributeList.begin();
|
|
|
|
itr!=rhs._attributeList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
StateAttribute::Type type = itr->first;
|
|
|
|
const RefAttributePair& rap = itr->second;
|
2002-01-29 22:04:06 +08:00
|
|
|
StateAttribute* attr = copyop(rap.first.get());
|
2002-01-29 20:52:04 +08:00
|
|
|
if (attr) _attributeList[type]=RefAttributePair(attr,rap.second);
|
|
|
|
}
|
2001-10-23 06:02:47 +08:00
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
// copy texture related modes.
|
|
|
|
_textureModeList = rhs._textureModeList;
|
|
|
|
|
|
|
|
// set up the size of the texture attribute list.
|
|
|
|
_textureAttributeList.resize(rhs._textureAttributeList.size());
|
|
|
|
|
|
|
|
// copy the contents across.
|
|
|
|
for(unsigned int i=0;i<rhs._textureAttributeList.size();++i)
|
|
|
|
{
|
|
|
|
|
|
|
|
AttributeList& lhs_attributeList = _textureAttributeList[i];
|
|
|
|
const AttributeList& rhs_attributeList = rhs._textureAttributeList[i];
|
|
|
|
for(AttributeList::const_iterator itr=rhs_attributeList.begin();
|
|
|
|
itr!=rhs_attributeList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
StateAttribute::Type type = itr->first;
|
|
|
|
const RefAttributePair& rap = itr->second;
|
|
|
|
StateAttribute* attr = copyop(rap.first.get());
|
|
|
|
if (attr) lhs_attributeList[type]=RefAttributePair(attr,rap.second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-23 06:02:47 +08:00
|
|
|
_renderingHint = rhs._renderingHint;
|
|
|
|
|
|
|
|
_binMode = rhs._binMode;
|
|
|
|
_binNum = rhs._binNum;
|
|
|
|
_binName = rhs._binName;
|
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
StateSet::~StateSet()
|
|
|
|
{
|
|
|
|
// note, all attached state attributes will be automatically
|
|
|
|
// unreferenced by ref_ptr<> and therefore there is no need to
|
|
|
|
// delete the memory manually.
|
|
|
|
}
|
|
|
|
|
2001-11-01 04:04:32 +08:00
|
|
|
int StateSet::compare(const StateSet& rhs,bool compareAttributeContents) const
|
2001-10-02 07:02:14 +08:00
|
|
|
{
|
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
if (_textureAttributeList.size()<rhs._textureAttributeList.size()) return -1;
|
|
|
|
if (_textureAttributeList.size()>rhs._textureAttributeList.size()) return 1;
|
|
|
|
|
|
|
|
for(unsigned int ai=0;ai<_textureAttributeList.size();++ai)
|
|
|
|
{
|
|
|
|
const AttributeList& rhs_attributeList = _textureAttributeList[ai];
|
|
|
|
const AttributeList& lhs_attributeList = rhs._textureAttributeList[ai];
|
|
|
|
if (compareAttributeContents)
|
|
|
|
{
|
|
|
|
// now check to see how the attributes compare.
|
|
|
|
AttributeList::const_iterator lhs_attr_itr = lhs_attributeList.begin();
|
|
|
|
AttributeList::const_iterator rhs_attr_itr = rhs_attributeList.begin();
|
|
|
|
while (lhs_attr_itr!=lhs_attributeList.end() && rhs_attr_itr!=rhs_attributeList.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_attributeList.end())
|
|
|
|
{
|
|
|
|
if (rhs_attr_itr!=rhs_attributeList.end()) return -1;
|
|
|
|
}
|
|
|
|
else if (rhs_attr_itr == rhs_attributeList.end()) return 1;
|
|
|
|
}
|
|
|
|
else // just compare pointers.
|
|
|
|
{
|
|
|
|
// now check to see how the attributes compare.
|
|
|
|
AttributeList::const_iterator lhs_attr_itr = lhs_attributeList.begin();
|
|
|
|
AttributeList::const_iterator rhs_attr_itr = rhs_attributeList.begin();
|
|
|
|
while (lhs_attr_itr!=lhs_attributeList.end() && rhs_attr_itr!=rhs_attributeList.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_attributeList.end())
|
|
|
|
{
|
|
|
|
if (rhs_attr_itr!=rhs_attributeList.end()) return -1;
|
|
|
|
}
|
|
|
|
else if (rhs_attr_itr == rhs_attributeList.end()) return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// now check the rest of the non texture attributes
|
2001-11-01 04:04:32 +08:00
|
|
|
if (compareAttributeContents)
|
2001-10-02 07:02:14 +08:00
|
|
|
{
|
2001-11-01 04:04:32 +08:00
|
|
|
// now check to see how the attributes compare.
|
|
|
|
AttributeList::const_iterator lhs_attr_itr = _attributeList.begin();
|
|
|
|
AttributeList::const_iterator rhs_attr_itr = rhs._attributeList.begin();
|
|
|
|
while (lhs_attr_itr!=_attributeList.end() && rhs_attr_itr!=rhs._attributeList.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==_attributeList.end())
|
|
|
|
{
|
|
|
|
if (rhs_attr_itr!=rhs._attributeList.end()) return -1;
|
|
|
|
}
|
|
|
|
else if (rhs_attr_itr == rhs._attributeList.end()) return 1;
|
2001-10-02 07:02:14 +08:00
|
|
|
}
|
2001-11-01 04:04:32 +08:00
|
|
|
else // just compare pointers.
|
2001-10-02 07:02:14 +08:00
|
|
|
{
|
2001-11-01 04:04:32 +08:00
|
|
|
// now check to see how the attributes compare.
|
|
|
|
AttributeList::const_iterator lhs_attr_itr = _attributeList.begin();
|
|
|
|
AttributeList::const_iterator rhs_attr_itr = rhs._attributeList.begin();
|
|
|
|
while (lhs_attr_itr!=_attributeList.end() && rhs_attr_itr!=rhs._attributeList.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==_attributeList.end())
|
|
|
|
{
|
|
|
|
if (rhs_attr_itr!=rhs._attributeList.end()) return -1;
|
|
|
|
}
|
|
|
|
else if (rhs_attr_itr == rhs._attributeList.end()) return 1;
|
2001-10-02 07:02:14 +08:00
|
|
|
}
|
2001-11-01 04:04:32 +08:00
|
|
|
|
2001-10-04 22:39:24 +08:00
|
|
|
// we've got here so attributes must be equal...
|
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
|
|
|
|
if (_textureModeList.size()<rhs._textureModeList.size()) return -1;
|
|
|
|
if (_textureModeList.size()>rhs._textureModeList.size()) return 1;
|
|
|
|
|
2001-10-04 22:39:24 +08:00
|
|
|
// check to see how the modes compare.
|
2002-07-07 22:40:41 +08:00
|
|
|
// first check the rest of the texture modes
|
|
|
|
for(unsigned int ti=0;ti<_textureModeList.size();++ti)
|
|
|
|
{
|
|
|
|
const ModeList& lhs_modeList = _textureModeList[ti];
|
|
|
|
const ModeList& rhs_modeList = rhs._textureModeList[ti];
|
|
|
|
|
|
|
|
ModeList::const_iterator lhs_mode_itr = lhs_modeList.begin();
|
|
|
|
ModeList::const_iterator rhs_mode_itr = rhs_modeList.begin();
|
|
|
|
while (lhs_mode_itr!=lhs_modeList.end() && rhs_mode_itr!=rhs_modeList.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_modeList.end())
|
|
|
|
{
|
|
|
|
if (rhs_mode_itr!=rhs_modeList.end()) return -1;
|
|
|
|
}
|
|
|
|
else if (rhs_mode_itr == rhs_modeList.end()) return 1;
|
|
|
|
}
|
2001-10-04 22:39:24 +08:00
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
// check non texture modes.
|
2001-10-04 22:39:24 +08:00
|
|
|
ModeList::const_iterator lhs_mode_itr = _modeList.begin();
|
|
|
|
ModeList::const_iterator rhs_mode_itr = rhs._modeList.begin();
|
|
|
|
while (lhs_mode_itr!=_modeList.end() && rhs_mode_itr!=rhs._modeList.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==_modeList.end())
|
|
|
|
{
|
|
|
|
if (rhs_mode_itr!=rhs._modeList.end()) return -1;
|
|
|
|
}
|
|
|
|
else if (rhs_mode_itr == rhs._modeList.end()) return 1;
|
|
|
|
|
2001-10-02 07:02:14 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-07-09 17:35:42 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
void StateSet::setGlobalDefaults()
|
|
|
|
{
|
|
|
|
_renderingHint = DEFAULT_BIN;
|
|
|
|
|
|
|
|
setRendingBinToInherit();
|
|
|
|
|
2001-10-15 22:07:54 +08:00
|
|
|
|
2002-04-22 06:05:26 +08:00
|
|
|
setMode(GL_DEPTH_TEST,StateAttribute::ON);
|
2002-03-27 07:52:52 +08:00
|
|
|
setAttributeAndModes(osgNew AlphaFunc,StateAttribute::OFF);
|
2002-07-13 02:12:01 +08:00
|
|
|
setAttributeAndModes(osgNew BlendFunc,StateAttribute::OFF);
|
2001-10-15 22:07:54 +08:00
|
|
|
|
2002-03-27 07:52:52 +08:00
|
|
|
Material *material = osgNew Material;
|
2001-10-15 22:07:54 +08:00
|
|
|
material->setColorMode(Material::AMBIENT_AND_DIFFUSE);
|
|
|
|
setAttributeAndModes(material,StateAttribute::ON);
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StateSet::setAllToInherit()
|
|
|
|
{
|
|
|
|
_renderingHint = DEFAULT_BIN;
|
|
|
|
|
|
|
|
setRendingBinToInherit();
|
|
|
|
|
|
|
|
_modeList.clear();
|
|
|
|
_attributeList.clear();
|
2002-07-07 22:40:41 +08:00
|
|
|
|
|
|
|
_textureModeList.clear();
|
|
|
|
_textureAttributeList.clear();
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
2001-10-14 17:58:49 +08:00
|
|
|
void StateSet::merge(const StateSet& rhs)
|
|
|
|
{
|
|
|
|
// merge the modes of rhs into this,
|
|
|
|
// this overrides rhs if OVERRIDE defined in this.
|
|
|
|
for(ModeList::const_iterator rhs_mitr = rhs._modeList.begin();
|
2001-12-01 04:53:50 +08:00
|
|
|
rhs_mitr != rhs._modeList.end();
|
2001-10-14 17:58:49 +08:00
|
|
|
++rhs_mitr)
|
|
|
|
{
|
|
|
|
ModeList::iterator lhs_mitr = _modeList.find(rhs_mitr->first);
|
|
|
|
if (lhs_mitr!=_modeList.end())
|
|
|
|
{
|
|
|
|
if (!(lhs_mitr->second & StateAttribute::OVERRIDE))
|
|
|
|
{
|
|
|
|
// override isn't on in rhs, so overrite it with incomming
|
|
|
|
// value.
|
|
|
|
lhs_mitr->second = rhs_mitr->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// entry doesn't exist so insert it.
|
|
|
|
_modeList.insert(*rhs_mitr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// merge the attributes of rhs into this,
|
|
|
|
// this overrides rhs if OVERRIDE defined in this.
|
|
|
|
for(AttributeList::const_iterator rhs_aitr = rhs._attributeList.begin();
|
2001-12-01 04:53:50 +08:00
|
|
|
rhs_aitr != rhs._attributeList.end();
|
2001-10-14 17:58:49 +08:00
|
|
|
++rhs_aitr)
|
|
|
|
{
|
|
|
|
AttributeList::iterator lhs_aitr = _attributeList.find(rhs_aitr->first);
|
|
|
|
if (lhs_aitr!=_attributeList.end())
|
|
|
|
{
|
|
|
|
if (!(lhs_aitr->second.second & StateAttribute::OVERRIDE))
|
|
|
|
{
|
|
|
|
// override isn't on in rhs, so overrite it with incomming
|
|
|
|
// value.
|
|
|
|
lhs_aitr->second = rhs_aitr->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// entry doesn't exist so insert it.
|
|
|
|
_attributeList.insert(*rhs_aitr);
|
|
|
|
}
|
|
|
|
}
|
2001-12-01 04:53:50 +08:00
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
|
|
|
|
if (_textureModeList.size()<rhs._textureModeList.size()) _textureModeList.resize(rhs._textureModeList.size());
|
|
|
|
for(unsigned int mi=0;mi<rhs._textureModeList.size();++mi)
|
|
|
|
{
|
|
|
|
ModeList& lhs_modeList = _textureModeList[mi];
|
|
|
|
const ModeList& rhs_modeList = rhs._textureModeList[mi];
|
|
|
|
// merge the modes of rhs into this,
|
|
|
|
// this overrides rhs if OVERRIDE defined in this.
|
|
|
|
for(ModeList::const_iterator rhs_mitr = rhs_modeList.begin();
|
|
|
|
rhs_mitr != rhs_modeList.end();
|
|
|
|
++rhs_mitr)
|
|
|
|
{
|
|
|
|
ModeList::iterator lhs_mitr = lhs_modeList.find(rhs_mitr->first);
|
|
|
|
if (lhs_mitr!=lhs_modeList.end())
|
|
|
|
{
|
|
|
|
if (!(lhs_mitr->second & StateAttribute::OVERRIDE))
|
|
|
|
{
|
|
|
|
// override isn't on in rhs, so overrite it with incomming
|
|
|
|
// value.
|
|
|
|
lhs_mitr->second = rhs_mitr->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// entry doesn't exist so insert it.
|
|
|
|
lhs_modeList.insert(*rhs_mitr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_textureAttributeList.size()<rhs._textureAttributeList.size()) _textureAttributeList.resize(rhs._textureAttributeList.size());
|
|
|
|
for(unsigned int ai=0;ai<rhs._textureAttributeList.size();++ai)
|
|
|
|
{
|
|
|
|
AttributeList& lhs_attributeList = _textureAttributeList[ai];
|
|
|
|
const AttributeList& rhs_attributeList = rhs._textureAttributeList[ai];
|
|
|
|
|
|
|
|
// merge the attributes of rhs into this,
|
|
|
|
// this overrides rhs if OVERRIDE defined in this.
|
|
|
|
for(AttributeList::const_iterator rhs_aitr = rhs_attributeList.begin();
|
|
|
|
rhs_aitr != rhs_attributeList.end();
|
|
|
|
++rhs_aitr)
|
|
|
|
{
|
|
|
|
AttributeList::iterator lhs_aitr = lhs_attributeList.find(rhs_aitr->first);
|
|
|
|
if (lhs_aitr!=lhs_attributeList.end())
|
|
|
|
{
|
|
|
|
if (!(lhs_aitr->second.second & StateAttribute::OVERRIDE))
|
|
|
|
{
|
|
|
|
// override isn't on in rhs, so overrite it with incomming
|
|
|
|
// value.
|
|
|
|
lhs_aitr->second = rhs_aitr->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// entry doesn't exist so insert it.
|
|
|
|
lhs_attributeList.insert(*rhs_aitr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-01 04:53:50 +08:00
|
|
|
// need to merge rendering hints
|
|
|
|
// but will need to think how best to do this first
|
|
|
|
// RO, Nov. 2001.
|
|
|
|
|
2001-10-14 17:58:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
void StateSet::setMode(const StateAttribute::GLMode mode, const StateAttribute::GLModeValue value)
|
|
|
|
{
|
2002-07-09 17:35:42 +08:00
|
|
|
setMode(_modeList,mode,value);
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StateSet::setModeToInherit(const StateAttribute::GLMode mode)
|
|
|
|
{
|
2002-07-09 17:35:42 +08:00
|
|
|
setModeToInherit(_modeList,mode);
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const StateAttribute::GLModeValue StateSet::getMode(const StateAttribute::GLMode mode) const
|
|
|
|
{
|
2002-07-09 17:35:42 +08:00
|
|
|
return getMode(_modeList,mode);
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StateSet::setAttribute(StateAttribute *attribute, const StateAttribute::OverrideValue value)
|
|
|
|
{
|
|
|
|
if (attribute)
|
|
|
|
{
|
2002-07-09 17:35:42 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StateSet::setAttributeAndModes(StateAttribute *attribute, const StateAttribute::GLModeValue value)
|
|
|
|
{
|
|
|
|
if (attribute)
|
|
|
|
{
|
2002-07-09 17:35:42 +08:00
|
|
|
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);
|
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StateSet::setAttributeToInherit(const StateAttribute::Type type)
|
|
|
|
{
|
|
|
|
AttributeList::iterator itr = _attributeList.find(type);
|
|
|
|
if (itr!=_attributeList.end())
|
|
|
|
{
|
2002-07-09 17:35:42 +08:00
|
|
|
setAssociatedModes(_modeList,itr->second.first.get(),StateAttribute::INHERIT);
|
2001-09-20 05:19:47 +08:00
|
|
|
_attributeList.erase(itr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-29 00:56:19 +08:00
|
|
|
StateAttribute* StateSet::getAttribute(const StateAttribute::Type type)
|
|
|
|
{
|
2002-07-09 17:35:42 +08:00
|
|
|
return getAttribute(_attributeList,type);
|
2001-09-29 00:56:19 +08:00
|
|
|
}
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
const StateAttribute* StateSet::getAttribute(const StateAttribute::Type type) const
|
|
|
|
{
|
2002-07-09 17:35:42 +08:00
|
|
|
return getAttribute(_attributeList,type);
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const StateSet::RefAttributePair* StateSet::getAttributePair(const StateAttribute::Type type) const
|
|
|
|
{
|
2002-07-09 17:35:42 +08:00
|
|
|
return getAttributePair(_attributeList,type);
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
2002-07-09 17:35:42 +08:00
|
|
|
void StateSet::setAssociatedModes(const StateAttribute* attribute, const StateAttribute::GLModeValue value)
|
|
|
|
{
|
|
|
|
setAssociatedModes(_modeList,attribute,value);
|
|
|
|
}
|
2002-07-07 22:40:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
void StateSet::setTextureMode(unsigned int unit,const StateAttribute::GLMode mode, const StateAttribute::GLModeValue value)
|
|
|
|
{
|
2002-07-09 17:35:42 +08:00
|
|
|
setMode(getOrCreateTextureModeList(unit),mode,value);
|
2002-07-07 22:40:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StateSet::setTextureModeToInherit(unsigned int unit,const StateAttribute::GLMode mode)
|
|
|
|
{
|
|
|
|
if (unit>=_textureModeList.size()) return;
|
2002-07-09 17:35:42 +08:00
|
|
|
setModeToInherit(_textureModeList[unit],mode);
|
2002-07-07 22:40:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const StateAttribute::GLModeValue StateSet::getTextureMode(unsigned int unit,const StateAttribute::GLMode mode) const
|
|
|
|
{
|
|
|
|
if (unit>=_textureModeList.size()) return StateAttribute::INHERIT;
|
2002-07-09 17:35:42 +08:00
|
|
|
return getMode(_textureModeList[unit],mode);
|
2002-07-07 22:40:41 +08:00
|
|
|
}
|
|
|
|
|
2002-07-08 01:42:34 +08:00
|
|
|
void StateSet::setTextureAttribute(unsigned int unit,StateAttribute *attribute, const StateAttribute::OverrideValue value)
|
2002-07-07 22:40:41 +08:00
|
|
|
{
|
|
|
|
if (attribute)
|
|
|
|
{
|
2002-07-09 17:35:42 +08:00
|
|
|
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);
|
|
|
|
}
|
2002-07-07 22:40:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-08 01:42:34 +08:00
|
|
|
void StateSet::setTextureAttributeAndModes(unsigned int unit,StateAttribute *attribute, const StateAttribute::GLModeValue value)
|
2002-07-07 22:40:41 +08:00
|
|
|
{
|
|
|
|
if (attribute)
|
|
|
|
{
|
2002-07-09 17:35:42 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2002-07-07 22:40:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StateSet::setTextureAttributeToInherit(unsigned int unit,const StateAttribute::Type type)
|
|
|
|
{
|
|
|
|
if (unit>=_textureAttributeList.size()) return;
|
|
|
|
AttributeList& attributeList = _textureAttributeList[unit];
|
|
|
|
AttributeList::iterator itr = attributeList.find(type);
|
|
|
|
if (itr!=attributeList.end())
|
|
|
|
{
|
2002-07-09 17:35:42 +08:00
|
|
|
if (unit<_textureModeList.size())
|
|
|
|
{
|
|
|
|
setAssociatedModes(_textureModeList[unit],itr->second.first.get(),StateAttribute::INHERIT);
|
|
|
|
}
|
2002-07-07 22:40:41 +08:00
|
|
|
attributeList.erase(itr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StateAttribute* StateSet::getTextureAttribute(unsigned int unit,const StateAttribute::Type type)
|
|
|
|
{
|
|
|
|
if (unit>=_textureAttributeList.size()) return 0;
|
2002-07-09 17:35:42 +08:00
|
|
|
return getAttribute(_textureAttributeList[unit],type);
|
2002-07-07 22:40:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const StateAttribute* StateSet::getTextureAttribute(unsigned int unit,const StateAttribute::Type type) const
|
|
|
|
{
|
|
|
|
if (unit>=_textureAttributeList.size()) return 0;
|
2002-07-09 17:35:42 +08:00
|
|
|
return getAttribute(_textureAttributeList[unit],type);
|
2002-07-07 22:40:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const StateSet::RefAttributePair* StateSet::getTextureAttributePair(unsigned int unit,const StateAttribute::Type type) const
|
|
|
|
{
|
|
|
|
if (unit>=_textureAttributeList.size()) return 0;
|
2002-07-09 17:35:42 +08:00
|
|
|
return getAttributePair(_textureAttributeList[unit],type);
|
2002-07-07 22:40:41 +08:00
|
|
|
}
|
|
|
|
|
2002-07-09 17:35:42 +08:00
|
|
|
void StateSet::setAssociatedTextureModes(unsigned int unit,const StateAttribute* attribute, const StateAttribute::GLModeValue value)
|
|
|
|
{
|
|
|
|
setAssociatedModes(getOrCreateTextureModeList(unit),attribute,value);
|
|
|
|
}
|
2002-07-07 22:40:41 +08:00
|
|
|
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
void StateSet::compile(State& state) const
|
|
|
|
{
|
|
|
|
for(AttributeList::const_iterator itr = _attributeList.begin();
|
|
|
|
itr!=_attributeList.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
itr->second.first->compile(state);
|
|
|
|
}
|
2002-07-07 22:40:41 +08:00
|
|
|
|
|
|
|
for(TextureAttributeList::const_iterator taitr=_textureAttributeList.begin();
|
|
|
|
taitr!=_textureAttributeList.end();
|
|
|
|
++taitr)
|
|
|
|
{
|
|
|
|
for(AttributeList::const_iterator itr = taitr->begin();
|
|
|
|
itr!=taitr->end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
itr->second.first->compile(state);
|
|
|
|
}
|
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void StateSet::setRenderingHint(const int hint)
|
|
|
|
{
|
|
|
|
_renderingHint = hint;
|
|
|
|
// temporary hack to get new render bins working.
|
|
|
|
if (_renderingHint==TRANSPARENT_BIN)
|
|
|
|
{
|
|
|
|
_binMode = USE_RENDERBIN_DETAILS;
|
|
|
|
_binNum = 1;
|
|
|
|
_binName = "DepthSortedBin";
|
|
|
|
// _binName = "RenderBin";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StateSet::setRenderBinDetails(const int binNum,const std::string& binName,const RenderBinMode mode)
|
|
|
|
{
|
|
|
|
_binMode = mode;
|
|
|
|
_binNum = binNum;
|
|
|
|
_binName = binName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StateSet::setRendingBinToInherit()
|
|
|
|
{
|
|
|
|
_binMode = INHERIT_RENDERBIN_DETAILS;
|
|
|
|
_binNum = 0;
|
|
|
|
_binName = "";
|
|
|
|
}
|
2002-07-07 22:40:41 +08:00
|
|
|
|
2002-07-09 17:35:42 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
|
2002-07-09 17:35:42 +08:00
|
|
|
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;
|
|
|
|
}
|
2002-07-07 22:40:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|