Moved Drawable across to using osg::buffered_value.
Added new osg::State::setInterleavedArray() method. Added new osg::Group::setNode(uint,Node*) method. Cleaned up and fixed the osg::Texture's handling of dirtyTextureParamters().
This commit is contained in:
parent
42fb3c5987
commit
5fca8ea229
@ -10,10 +10,7 @@
|
||||
#include <osg/Types>
|
||||
#include <osg/NodeVisitor>
|
||||
#include <osg/Shape>
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <osg/buffered_value>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@ -381,18 +378,13 @@ class SG_EXPORT Drawable : public Object
|
||||
bool _supportsDisplayList;
|
||||
bool _useDisplayList;
|
||||
|
||||
typedef std::vector<uint> GLObjectList;
|
||||
typedef osg::buffered_value<uint> GLObjectList;
|
||||
mutable GLObjectList _globjList;
|
||||
|
||||
ref_ptr<AppCallback> _appCallback;
|
||||
ref_ptr<DrawCallback> _drawCallback;
|
||||
ref_ptr<CullCallback> _cullCallback;
|
||||
|
||||
// static cache of deleted display lists which can only
|
||||
// by completely deleted once the appropriate OpenGL context
|
||||
// is set.
|
||||
typedef std::map<uint,std::set<uint> > DeletedDisplayListCache;
|
||||
static DeletedDisplayListCache s_deletedDisplayListCache;
|
||||
|
||||
};
|
||||
|
||||
@ -405,9 +397,6 @@ inline void Drawable::draw(State& state)
|
||||
// current OpenGL context.
|
||||
uint contextID = state.getContextID();
|
||||
|
||||
// fill in array if required.
|
||||
while (_globjList.size()<=contextID) _globjList.push_back(0);
|
||||
|
||||
// get the globj for the current contextID.
|
||||
uint& globj = _globjList[contextID];
|
||||
|
||||
|
@ -50,17 +50,23 @@ class SG_EXPORT Group : public Node
|
||||
virtual bool removeChild( Node *child );
|
||||
|
||||
/** Replace specified Node with another Node.
|
||||
* Decrement the reference count origNode and increments the
|
||||
* Equivalent to setChild(findChildNum(orignChild),node),
|
||||
* see docs for setChild for futher details on implementation.*/
|
||||
virtual bool replaceChild( Node *origChild, Node* newChild );
|
||||
|
||||
/** return the number of chilren nodes.*/
|
||||
inline unsigned int getNumChildren() const { return _children.size(); }
|
||||
|
||||
/** set child node at position i.
|
||||
* return true if set correctly, false on failure (if node==NULL || i is out of range).
|
||||
* When set can be successful applied, the algorithm is : decrement the reference count origNode and increments the
|
||||
* reference count of newNode, and dirty the bounding sphere
|
||||
* to force it to recompute on next getBound() and returns true.
|
||||
* If origNode is not found then return false and do not
|
||||
* add newNode. If newNode is NULL then return false and do
|
||||
* not remove origNode. Also returns false if newChild is a Scene node.
|
||||
*/
|
||||
virtual bool replaceChild( Node *origChild, Node* newChild );
|
||||
|
||||
/** return the number of chilren nodes.*/
|
||||
inline unsigned int getNumChildren() const { return _children.size(); }
|
||||
virtual bool setChild( unsigned int i, Node* node );
|
||||
|
||||
/** return child node at position i.*/
|
||||
inline Node* getChild( unsigned int i ) { return _children[i].get(); }
|
||||
@ -113,11 +119,11 @@ class SG_EXPORT Group : public Node
|
||||
/** Find the index number of child, return a value between
|
||||
* 0 and _children.size()-1 if found, if not found then
|
||||
* return _children.size().*/
|
||||
inline unsigned int findChildNo( const Node* node ) const
|
||||
inline unsigned int findChildNum( const Node* node ) const
|
||||
{
|
||||
for (unsigned int childNo=0;childNo<_children.size();++childNo)
|
||||
for (unsigned int childNum=0;childNum<_children.size();++childNum)
|
||||
{
|
||||
if (_children[childNo]==node) return childNo;
|
||||
if (_children[childNum]==node) return childNum;
|
||||
}
|
||||
return _children.size(); // node not found.
|
||||
}
|
||||
|
@ -221,6 +221,13 @@ class SG_EXPORT State : public Referenced
|
||||
/** dirty the vertex, normal, color, tex coords, secenday color, fog coord and index arrays.*/
|
||||
void dirtyAllVertexArrays();
|
||||
|
||||
|
||||
/** Wrapper around glInterleavedArrays(..).
|
||||
* also resets the internal array points and modes within osg::State to keep the other
|
||||
* vertex array operations consistent. */
|
||||
void setInterleavedArrays( GLenum format, GLsizei stride, void* pointer);
|
||||
|
||||
|
||||
/** wrapper around glEnableClientState(GL_VERTEX_ARRAY);glVertexPointer(..);
|
||||
* note, only updates values that change.*/
|
||||
inline void setVertexPointer( GLint size, GLenum type,
|
||||
|
@ -177,39 +177,6 @@ class SG_EXPORT Texture : public osg::StateAttribute
|
||||
bool isCompressedInternalFormat() const;
|
||||
|
||||
|
||||
// /** Get the handle to the texture object for the current context.*/
|
||||
// /** return the OpenGL texture object for specified context.*/
|
||||
// inline GLuint& getTextureObject(uint contextID) const
|
||||
// {
|
||||
// // pad out handle list if required.
|
||||
// if (_handleList.size()<=contextID)
|
||||
// _handleList.resize(contextID+1,0);
|
||||
//
|
||||
// // get the globj for the current contextID.
|
||||
// return _handleList[contextID];
|
||||
// }
|
||||
//
|
||||
// inline uint& getModifiedTag(uint contextID) const
|
||||
// {
|
||||
// // pad out handle list if required.
|
||||
// if (_modifiedTag.size()<=contextID)
|
||||
// _modifiedTag.resize(contextID+1,0);
|
||||
//
|
||||
// // get the modified tag for the current contextID.
|
||||
// return _modifiedTag[contextID];
|
||||
// }
|
||||
//
|
||||
// inline uint& getTextureParameterDirty(uint contextID) const
|
||||
// {
|
||||
// // pad out handle list if required.
|
||||
// if (_texParametersDirtyList.size()<=contextID)
|
||||
// _texParametersDirtyList.resize(contextID+1,0);
|
||||
//
|
||||
// // get the dirty flag for the current contextID.
|
||||
// return _texParametersDirtyList[contextID];
|
||||
// }
|
||||
|
||||
|
||||
/** Get the handle to the texture object for the current context.*/
|
||||
/** return the OpenGL texture object for specified context.*/
|
||||
inline GLuint& getTextureObject(uint contextID) const
|
||||
@ -330,15 +297,12 @@ class SG_EXPORT Texture : public osg::StateAttribute
|
||||
/** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
|
||||
int compareTexture(const Texture& rhs) const;
|
||||
|
||||
// typedef std::vector<GLuint> TextureNameList;
|
||||
typedef buffered_value<GLuint> TextureNameList;
|
||||
mutable TextureNameList _handleList;
|
||||
|
||||
// typedef std::vector<uint> ImageModifiedTag;
|
||||
typedef buffered_value<uint> ImageModifiedTag;
|
||||
mutable ImageModifiedTag _modifiedTag;
|
||||
|
||||
// typedef std::vector<uint> TexParameterDirtyList;
|
||||
typedef buffered_value<uint> TexParameterDirtyList;
|
||||
mutable TexParameterDirtyList _texParametersDirtyList;
|
||||
|
||||
|
@ -8,15 +8,19 @@
|
||||
#include <osg/Node>
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
Drawable::DeletedDisplayListCache Drawable::s_deletedDisplayListCache;
|
||||
// static cache of deleted display lists which can only
|
||||
// by completely deleted once the appropriate OpenGL context
|
||||
// is set. Used osg::Drawable::deleteDisplayList(..) and flushDeletedDisplayLists(..) below.
|
||||
typedef std::map<GLuint,std::set<GLuint> > DeletedDisplayListCache;
|
||||
static DeletedDisplayListCache s_deletedDisplayListCache;
|
||||
|
||||
Drawable::Drawable()
|
||||
{
|
||||
_globjList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0);
|
||||
|
||||
_bbox_computed = false;
|
||||
|
||||
// Note, if your are defining a subclass from drawable which is
|
||||
@ -26,7 +30,6 @@ Drawable::Drawable()
|
||||
// dynamic updating of data.
|
||||
_supportsDisplayList = true;
|
||||
_useDisplayList = true;
|
||||
|
||||
}
|
||||
|
||||
Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop):
|
||||
@ -38,10 +41,10 @@ Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop):
|
||||
_shape(copyop(drawable._shape.get())),
|
||||
_supportsDisplayList(drawable._supportsDisplayList),
|
||||
_useDisplayList(drawable._useDisplayList),
|
||||
_globjList(drawable._globjList),
|
||||
_drawCallback(drawable._drawCallback),
|
||||
_cullCallback(drawable._cullCallback)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
Drawable::~Drawable()
|
||||
{
|
||||
@ -90,9 +93,6 @@ void Drawable::compile(State& state)
|
||||
// current OpenGL context.
|
||||
uint contextID = state.getContextID();
|
||||
|
||||
// fill in array if required.
|
||||
while (_globjList.size()<=contextID) _globjList.push_back(0);
|
||||
|
||||
// get the globj for the current contextID.
|
||||
uint& globj = _globjList[contextID];
|
||||
|
||||
|
@ -11,6 +11,8 @@
|
||||
#include <osg/Geometry>
|
||||
#include <osg/ShadeModel>
|
||||
|
||||
#include <set>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
GeoSet::GeoSet()
|
||||
|
@ -146,15 +146,28 @@ bool Group::replaceChild( Node *origNode, Node *newNode )
|
||||
{
|
||||
if (newNode==NULL || origNode==newNode) return false;
|
||||
|
||||
ChildList::iterator itr = findNode(origNode);
|
||||
if (itr!=_children.end())
|
||||
unsigned int pos = findChildNum(origNode);
|
||||
if (pos<_children.size())
|
||||
{
|
||||
return setChild(pos,newNode);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Group::setChild( unsigned int i, Node* newNode )
|
||||
{
|
||||
if (i<_children.size() && newNode)
|
||||
{
|
||||
|
||||
Node* origNode = _children[i].get();
|
||||
|
||||
// first remove for origNode's parent list.
|
||||
origNode->removeParent(this);
|
||||
|
||||
// note ref_ptr<> automatically handles decrementing origNode's reference count,
|
||||
// and inccrementing newNode's reference count.
|
||||
*itr = newNode;
|
||||
_children[i] = newNode;
|
||||
|
||||
// register as parent of child.
|
||||
newNode->addParent(this);
|
||||
|
@ -69,7 +69,7 @@ bool LOD::addChild(Node *child, float min, float max)
|
||||
bool LOD::removeChild( Node *child )
|
||||
{
|
||||
// find the child's position.
|
||||
unsigned int pos=findChildNo(child);
|
||||
unsigned int pos=findChildNum(child);
|
||||
if (pos==_children.size()) return false;
|
||||
|
||||
_rangeList.erase(_rangeList.begin()+pos);
|
||||
|
@ -427,6 +427,17 @@ void State::dirtyAllVertexArrays()
|
||||
dirtySecondaryColorPointer();
|
||||
}
|
||||
|
||||
void State::setInterleavedArrays( GLenum format, GLsizei stride, void* pointer)
|
||||
{
|
||||
glInterleavedArrays( format, stride, pointer);
|
||||
|
||||
// the crude way, assume that all arrays have been effected so dirty them and
|
||||
// disable them...
|
||||
dirtyAllVertexArrays();
|
||||
disableAllVertexArrays();
|
||||
}
|
||||
|
||||
|
||||
typedef void (APIENTRY * ActiveTextureProc) (GLenum texture);
|
||||
|
||||
bool State::setClientActiveTextureUnit( unsigned int unit )
|
||||
|
@ -61,7 +61,7 @@ bool Switch::addChild( Node *child, bool value )
|
||||
bool Switch::removeChild( Node *child )
|
||||
{
|
||||
// find the child's position.
|
||||
unsigned int pos=findChildNo(child);
|
||||
unsigned int pos=findChildNum(child);
|
||||
if (pos==_children.size()) return false;
|
||||
|
||||
_values.erase(_values.begin()+pos);
|
||||
@ -78,7 +78,7 @@ void Switch::setValue(unsigned int pos,bool value)
|
||||
void Switch::setValue(const Node* child,bool value)
|
||||
{
|
||||
// find the child's position.
|
||||
unsigned int pos=findChildNo(child);
|
||||
unsigned int pos=findChildNum(child);
|
||||
if (pos==_children.size()) return;
|
||||
|
||||
_values[pos]=value;
|
||||
@ -93,7 +93,7 @@ bool Switch::getValue(unsigned int pos) const
|
||||
bool Switch::getValue(const Node* child) const
|
||||
{
|
||||
// find the child's position.
|
||||
unsigned int pos=findChildNo(child);
|
||||
unsigned int pos=findChildNum(child);
|
||||
if (pos==_children.size()) return false;
|
||||
|
||||
return _values[pos];
|
||||
|
@ -19,9 +19,6 @@ Texture::Texture():
|
||||
_internalFormatMode(USE_IMAGE_DATA_FORMAT),
|
||||
_internalFormat(0)
|
||||
{
|
||||
// _handleList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0);
|
||||
// _modifiedTag.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0);
|
||||
// _texParametersDirtyList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),true);
|
||||
}
|
||||
|
||||
Texture::Texture(const Texture& text,const CopyOp& copyop):
|
||||
@ -36,9 +33,6 @@ Texture::Texture(const Texture& text,const CopyOp& copyop):
|
||||
_internalFormatMode(text._internalFormatMode),
|
||||
_internalFormat(text._internalFormat)
|
||||
{
|
||||
// _handleList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0);
|
||||
// _modifiedTag.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0);
|
||||
// _texParametersDirtyList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),true);
|
||||
}
|
||||
|
||||
Texture::~Texture()
|
||||
@ -134,7 +128,7 @@ void Texture::dirtyTextureParameters()
|
||||
{
|
||||
for(uint i=0;i<_texParametersDirtyList.size();++i)
|
||||
{
|
||||
_texParametersDirtyList[i] = 0;
|
||||
_texParametersDirtyList[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user