Refactored handling of StateAttiribute's that override the StateAttiribute::getMember() so that when they change their Member value they update the StateSet parents that own them to keep the StateSet's maps coherent.

This commit is contained in:
Robert Osfield
2016-06-25 12:24:19 +01:00
parent f74eaae665
commit 949aca196d
13 changed files with 105 additions and 105 deletions

View File

@@ -33,7 +33,7 @@ class OSG_EXPORT BlendEquationi : public BlendEquation
BlendEquationi(unsigned int buf, Equation equationRGB, Equation equationAlpha):
BlendEquation(equationRGB, equationAlpha),
_index(buf) {}
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
BlendEquationi(const BlendEquationi& cm,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
@@ -58,7 +58,7 @@ class OSG_EXPORT BlendEquationi : public BlendEquation
virtual unsigned int getMember() const { return _index; }
/** Set the renderbuffer index of the BlendEquationi. */
void setIndex(unsigned int buf) { _index = buf; }
void setIndex(unsigned int buf);
/** Get the renderbuffer index of the BlendEquationi. */
unsigned int getIndex() const { return _index; }

View File

@@ -57,7 +57,7 @@ class OSG_EXPORT BlendFunci : public BlendFunc
virtual unsigned int getMember() const { return _index; }
/** Set the renderbuffer index of the BlendFunci. */
void setIndex(unsigned int buf) { _index = buf; }
void setIndex(unsigned int buf);
/** Get the renderbuffer index of the BlendFunci. */
unsigned int getIndex() const { return _index; }

View File

@@ -51,16 +51,22 @@ class OSG_EXPORT BufferIndexBinding : public StateAttribute
GLenum getTarget() const { return _target; }
/** Set the renderbuffer index of the BlendEquationi. */
void setIndex(unsigned int index);
/** Get the index target.
*/
GLuint getIndex() const { return _index; }
/** Set the buffer object that will be bound to the index target.
*/
void setBufferObject(BufferObject *bo) { _bufferObject = bo; }
/** Get the buffer object to be bound.
*/
const BufferObject* getBufferObject() const { return _bufferObject.get(); }
BufferObject* getBufferObject(){ return _bufferObject.get(); }
/** Set the starting offset into the buffer object for data for
the indexed target. Note: the required alignment on the offset
may be quite large (e.g., 256 bytes on NVidia 8600M). This
@@ -68,16 +74,18 @@ class OSG_EXPORT BufferIndexBinding : public StateAttribute
*/
void setOffset(GLintptr offset) { _offset = offset; }
GLintptr getOffset() const { return _offset; }
/** Set the size of data for the indexed target.
*/
void setSize(GLsizeiptr size) { _size = size; }
GLsizeiptr getSize() const { return _size; }
virtual void apply(State& state) const;
protected:
virtual ~BufferIndexBinding();
const GLenum _target;
const GLuint _index;
GLuint _index;
ref_ptr<BufferObject> _bufferObject;
GLintptr _offset;
GLsizeiptr _size;

View File

@@ -53,7 +53,7 @@ class OSG_EXPORT ColorMaski : public ColorMask
virtual unsigned int getMember() const { return _index; }
/** Set the renderbuffer index of the ColorMaski. */
void setIndex(unsigned int buf) { _index = buf; }
void setIndex(unsigned int buf);
/** Get the renderbuffer index of the ColorMaski. */
unsigned int getIndex() const { return _index; }

View File

@@ -372,12 +372,26 @@ class OSG_EXPORT StateAttribute : public Object
ParentList _parents;
friend class osg::StateSet;
/** Helper class that make is easy to handle changes in a member value.*/
struct ReassignToParents
{
/** Constructor caches and then removes attribute for all of it's parents.*/
ReassignToParents(osg::StateAttribute* att);
/** Destructor then reassigns the attribute to all of the parents.*/
~ReassignToParents();
ref_ptr<StateAttribute> attribute;
ParentList parents;
};
ref_ptr<ShaderComponent> _shaderComponent;
ref_ptr<StateAttributeCallback> _updateCallback;
ref_ptr<StateAttributeCallback> _eventCallback;
};
}
}
#endif