Introduced new BufferObject design + implementation in preperation of implementing a pool system for buffer objects
This commit is contained in:
@@ -43,7 +43,7 @@ class ConstArrayVisitor;
|
||||
class ValueVisitor;
|
||||
class ConstValueVisitor;
|
||||
|
||||
class OSG_EXPORT Array : public Object
|
||||
class OSG_EXPORT Array : public BufferData
|
||||
{
|
||||
|
||||
public:
|
||||
@@ -77,17 +77,13 @@ class OSG_EXPORT Array : public Object
|
||||
Array(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0):
|
||||
_arrayType(arrayType),
|
||||
_dataSize(dataSize),
|
||||
_dataType(dataType),
|
||||
_modifiedCount(0),
|
||||
_vboOffset(0) {}
|
||||
_dataType(dataType) {}
|
||||
|
||||
Array(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Object(array,copyop),
|
||||
BufferData(array,copyop),
|
||||
_arrayType(array._arrayType),
|
||||
_dataSize(array._dataSize),
|
||||
_dataType(array._dataType),
|
||||
_modifiedCount(0),
|
||||
_vboOffset(0) {}
|
||||
_dataType(array._dataType) {}
|
||||
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Array*>(obj)!=NULL; }
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
@@ -113,61 +109,22 @@ class OSG_EXPORT Array : public Object
|
||||
/** Frees unused space on this vector - i.e. the difference between size() and max_size() of the underlying vector.*/
|
||||
virtual void trim() {}
|
||||
|
||||
/** Dirty the primitive, which increments the modified count, to force buffer objects to update. */
|
||||
inline void dirty() { ++_modifiedCount; if (_vbo.valid()) _vbo->dirty(); }
|
||||
|
||||
/** Set the modified count value.*/
|
||||
inline void setModifiedCount(unsigned int value) { _modifiedCount=value; }
|
||||
|
||||
/** Get modified count value.*/
|
||||
inline unsigned int getModifiedCount() const { return _modifiedCount; }
|
||||
|
||||
/** Set the VertexBufferObject.*/
|
||||
inline void setVertexBufferObject(osg::VertexBufferObject* vbo)
|
||||
{
|
||||
if (_vbo == vbo) return;
|
||||
|
||||
if (_vbo.valid())
|
||||
{
|
||||
_vbo->removeArray(this);
|
||||
}
|
||||
|
||||
_vbo = vbo;
|
||||
|
||||
if (_vbo.valid())
|
||||
{
|
||||
_vbo->addArray(this);
|
||||
}
|
||||
}
|
||||
|
||||
inline void setVertexBufferObject(osg::VertexBufferObject* vbo) { setBufferObject(vbo); }
|
||||
|
||||
/** Get the VertexBufferObject. If no VBO is assigned returns NULL*/
|
||||
inline osg::VertexBufferObject* getVertexBufferObject() { return _vbo.get(); }
|
||||
inline osg::VertexBufferObject* getVertexBufferObject() { return dynamic_cast<osg::VertexBufferObject*>(_bufferObject.get()); }
|
||||
|
||||
/** Get the const VertexBufferObject. If no VBO is assigned returns NULL*/
|
||||
inline const osg::VertexBufferObject* getVertexBufferObject() const { return _vbo.get(); }
|
||||
|
||||
/** Set the offset into the VertexBufferObject, if used.*/
|
||||
void setVertexBufferObjectOffset(const GLvoid* offset ) const { _vboOffset = offset; }
|
||||
|
||||
/** Get the offset into the VertexBufferObject, if used.*/
|
||||
const GLvoid* getVertexBufferObjectOffset() const { return _vboOffset; }
|
||||
inline const osg::VertexBufferObject* getVertexBufferObject() const { return dynamic_cast<const osg::VertexBufferObject*>(_bufferObject.get()); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Array()
|
||||
{
|
||||
if (_vbo.valid())
|
||||
{
|
||||
_vbo->removeArray(this);
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~Array() {}
|
||||
|
||||
Type _arrayType;
|
||||
GLint _dataSize;
|
||||
GLenum _dataType;
|
||||
unsigned int _modifiedCount;
|
||||
osg::ref_ptr<osg::VertexBufferObject> _vbo;
|
||||
mutable const GLvoid* _vboOffset;
|
||||
};
|
||||
|
||||
template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
|
||||
|
||||
@@ -99,72 +99,75 @@ namespace osg
|
||||
{
|
||||
|
||||
class State;
|
||||
class BufferData;
|
||||
class BufferObject;
|
||||
|
||||
class OSG_EXPORT BufferObject : public Object
|
||||
class OSG_EXPORT GLBufferObject : public Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
BufferObject();
|
||||
GLBufferObject(unsigned int contextID, BufferObject* bufferObject=0);
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
BufferObject(const BufferObject& bo,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const BufferObject*>(obj)!=NULL; }
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
virtual const char* className() const { return "BufferObject"; }
|
||||
|
||||
/** Set what type of usage the buffer object will have. Options are:
|
||||
* GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY,
|
||||
* GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY,
|
||||
* GL_DYNAMIC_DRAW, GL_DYNAMIC_READ, or GL_DYNAMIC_COPY.
|
||||
*/
|
||||
void setUsage(GLenum usage) { _usage = usage; }
|
||||
|
||||
/** Get the type of usage the buffer object has been set up for.*/
|
||||
GLenum getUsage() const { return _usage; }
|
||||
void setBufferObject(BufferObject* bufferObject);
|
||||
BufferObject* getBufferObject() { return _bufferObject; }
|
||||
|
||||
struct BufferEntry
|
||||
{
|
||||
BufferEntry(): dataSize(0),offset(0) {}
|
||||
BufferEntry(const BufferEntry& be): modifiedCount(be.modifiedCount),dataSize(be.dataSize),offset(be.offset) {}
|
||||
|
||||
BufferEntry& operator = (const BufferEntry& be) { modifiedCount=be.modifiedCount; dataSize=be.dataSize; offset=be.offset; return *this; }
|
||||
BufferEntry(): modifiedCount(0),dataSize(0),offset(0),dataSource(0) {}
|
||||
|
||||
mutable buffered_value<unsigned int> modifiedCount;
|
||||
mutable unsigned int dataSize;
|
||||
mutable unsigned int offset;
|
||||
BufferEntry(const BufferEntry& rhs):
|
||||
modifiedCount(rhs.modifiedCount),
|
||||
dataSize(rhs.dataSize),
|
||||
offset(rhs.offset),
|
||||
dataSource(rhs.dataSource) {}
|
||||
|
||||
BufferEntry& operator = (const BufferEntry& rhs)
|
||||
{
|
||||
if (&rhs==this) return *this;
|
||||
modifiedCount = rhs.modifiedCount;
|
||||
dataSize = rhs.dataSize;
|
||||
offset = rhs.offset;
|
||||
dataSource = rhs.dataSource;
|
||||
return *this;
|
||||
}
|
||||
|
||||
unsigned int modifiedCount;
|
||||
GLsizeiptrARB dataSize;
|
||||
GLsizeiptrARB offset;
|
||||
BufferData* dataSource;
|
||||
};
|
||||
|
||||
inline bool isBufferObjectSupported(unsigned int contextID) const { return getExtensions(contextID,true)->isBufferObjectSupported(); }
|
||||
inline bool isPBOSupported(unsigned int contextID) const { return getExtensions(contextID,true)->isPBOSupported(); }
|
||||
inline unsigned int getContextID() const { return _contextID; }
|
||||
|
||||
inline GLuint& buffer(unsigned int contextID) const { return _bufferObjectList[contextID]; }
|
||||
|
||||
inline void bindBuffer(unsigned int contextID) const
|
||||
inline GLuint& getGLObjectID() { return _glObjectID; }
|
||||
inline GLuint getGLObjectID() const { return _glObjectID; }
|
||||
inline GLsizeiptrARB getOffset(unsigned int i) const { return _bufferEntries[i].offset; }
|
||||
|
||||
inline void bindBuffer() const
|
||||
{
|
||||
Extensions* extensions = getExtensions(contextID,true);
|
||||
extensions->glBindBuffer(_target,_bufferObjectList[contextID]);
|
||||
_extensions->glBindBuffer(_target,_glObjectID);
|
||||
}
|
||||
|
||||
virtual void unbindBuffer(unsigned int contextID) const
|
||||
inline void unbindBuffer() const
|
||||
{
|
||||
Extensions* extensions = getExtensions(contextID,true);
|
||||
extensions->glBindBuffer(_target,0);
|
||||
_extensions->glBindBuffer(_target,0);
|
||||
}
|
||||
|
||||
inline void dirty() { _compiledList.setAllElementsTo(0); }
|
||||
inline bool isDirty() const { return _dirty; }
|
||||
|
||||
bool isDirty(unsigned int contextID) const { return _compiledList[contextID]==0; }
|
||||
void dirty() { _dirty = true; }
|
||||
|
||||
virtual void compileBuffer(State& state) const = 0;
|
||||
|
||||
/** Resize any per context GLObject buffers to specified size. */
|
||||
virtual void resizeGLObjectBuffers(unsigned int maxSize);
|
||||
void clear();
|
||||
|
||||
/** If State is non-zero, this function releases OpenGL objects for
|
||||
* the specified graphics context. Otherwise, releases OpenGL objects
|
||||
* for all graphics contexts. */
|
||||
void releaseGLObjects(State* state=0) const;
|
||||
void compileBuffer();
|
||||
|
||||
void deleteGLObject();
|
||||
|
||||
void assign(BufferObject* bufferObject);
|
||||
|
||||
bool isPBOSupported() const { return _extensions->isPBOSupported(); }
|
||||
|
||||
static GLBufferObject* createGLBufferObject(unsigned int contextID, const BufferObject* bufferObject);
|
||||
|
||||
|
||||
/** Use deleteVertexBufferObject instead of glDeleteBuffers to allow
|
||||
@@ -256,19 +259,148 @@ class OSG_EXPORT BufferObject : public Object
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~BufferObject();
|
||||
|
||||
typedef osg::buffered_value<GLuint> GLObjectList;
|
||||
typedef osg::buffered_value<unsigned int> CompiledList;
|
||||
virtual ~GLBufferObject();
|
||||
|
||||
mutable GLObjectList _bufferObjectList;
|
||||
mutable CompiledList _compiledList;
|
||||
unsigned int _contextID;
|
||||
GLuint _glObjectID;
|
||||
|
||||
GLenum _target;
|
||||
GLenum _usage;
|
||||
|
||||
bool _dirty;
|
||||
|
||||
mutable unsigned int _totalSize;
|
||||
|
||||
typedef std::vector<BufferEntry> BufferEntries;
|
||||
BufferEntries _bufferEntries;
|
||||
|
||||
BufferObject* _bufferObject;
|
||||
|
||||
public:
|
||||
Extensions* _extensions;
|
||||
|
||||
};
|
||||
|
||||
class OSG_EXPORT BufferObject : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
BufferObject();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
BufferObject(const BufferObject& bo,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const BufferObject*>(obj)!=NULL; }
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
virtual const char* className() const { return "BufferObject"; }
|
||||
|
||||
void setTarget(GLenum target) { _target = target; }
|
||||
GLenum getTarget() const { return _target; }
|
||||
|
||||
/** Set what type of usage the buffer object will have. Options are:
|
||||
* GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY,
|
||||
* GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY,
|
||||
* GL_DYNAMIC_DRAW, GL_DYNAMIC_READ, or GL_DYNAMIC_COPY.
|
||||
*/
|
||||
void setUsage(GLenum usage) { _usage = usage; }
|
||||
|
||||
/** Get the type of usage the buffer object has been set up for.*/
|
||||
GLenum getUsage() const { return _usage; }
|
||||
|
||||
void dirty();
|
||||
|
||||
/** Resize any per context GLObject buffers to specified size. */
|
||||
virtual void resizeGLObjectBuffers(unsigned int maxSize);
|
||||
|
||||
/** If State is non-zero, this function releases OpenGL objects for
|
||||
* the specified graphics context. Otherwise, releases OpenGL objects
|
||||
* for all graphics contexts. */
|
||||
void releaseGLObjects(State* state=0) const;
|
||||
|
||||
unsigned int addBufferData(BufferData* bd);
|
||||
void removeBufferData(unsigned int index);
|
||||
void removeBufferData(BufferData* bd);
|
||||
|
||||
void setBufferData(unsigned int index, BufferData* bd);
|
||||
BufferData* getBufferData(unsigned int index) { return _bufferDataList[index]; }
|
||||
const BufferData* getBufferData(unsigned int index) const { return _bufferDataList[index]; }
|
||||
|
||||
unsigned int getNumBufferData() const { return _bufferDataList.size(); }
|
||||
|
||||
GLBufferObject* getGLBufferObject(unsigned int contextID) const { return _glBufferObjects[contextID].get(); }
|
||||
|
||||
GLBufferObject* getOrCreateGLBufferObject(unsigned int contextID) const
|
||||
{
|
||||
if (!_glBufferObjects[contextID]) _glBufferObjects[contextID] = GLBufferObject::createGLBufferObject(contextID, this);
|
||||
return _glBufferObjects[contextID].get();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
~BufferObject();
|
||||
|
||||
typedef std::vector< BufferData* > BufferDataList;
|
||||
typedef osg::buffered_object< osg::ref_ptr<GLBufferObject> > GLBufferObjects;
|
||||
|
||||
GLenum _target;
|
||||
GLenum _usage;
|
||||
BufferDataList _bufferDataList;
|
||||
|
||||
mutable GLBufferObjects _glBufferObjects;
|
||||
};
|
||||
|
||||
class BufferData : public Object
|
||||
{
|
||||
public:
|
||||
|
||||
BufferData():
|
||||
Object(true),
|
||||
_modifiedCount(0),
|
||||
_bufferIndex(0) {}
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
BufferData(const BufferData& bd,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
osg::Object(bd,copyop),
|
||||
_modifiedCount(0),
|
||||
_bufferIndex(0) {}
|
||||
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const BufferData*>(obj)!=NULL; }
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
virtual const char* className() const { return "BufferData"; }
|
||||
|
||||
virtual const GLvoid* getDataPointer() const = 0;
|
||||
virtual unsigned int getTotalDataSize() const = 0;
|
||||
|
||||
void setBufferObject(BufferObject* bufferObject);
|
||||
BufferObject* getBufferObject() { return _bufferObject.get(); }
|
||||
const BufferObject* getBufferObject() const { return _bufferObject.get(); }
|
||||
|
||||
void setBufferIndex(unsigned int index) { _bufferIndex = index; }
|
||||
unsigned int getBufferIndex() const { return _bufferIndex; }
|
||||
|
||||
GLBufferObject* getGLBufferObject(unsigned int contextID) const { return _bufferObject.valid() ? _bufferObject->getGLBufferObject(contextID) : 0; }
|
||||
GLBufferObject* getOrCreateGLBufferObject(unsigned int contextID) const { return _bufferObject.valid() ? _bufferObject->getOrCreateGLBufferObject(contextID) : 0; }
|
||||
|
||||
/** Dirty the primitive, which increments the modified count, to force buffer objects to update. */
|
||||
inline void dirty() { ++_modifiedCount; if (_bufferObject.valid()) _bufferObject->dirty(); }
|
||||
|
||||
/** Set the modified count value.*/
|
||||
inline void setModifiedCount(unsigned int value) { _modifiedCount=value; }
|
||||
|
||||
/** Get modified count value.*/
|
||||
inline unsigned int getModifiedCount() const { return _modifiedCount; }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~BufferData();
|
||||
|
||||
unsigned int _modifiedCount;
|
||||
|
||||
unsigned int _bufferIndex;
|
||||
osg::ref_ptr<BufferObject> _bufferObject;
|
||||
};
|
||||
|
||||
|
||||
class Array;
|
||||
class OSG_EXPORT VertexBufferObject : public BufferObject
|
||||
{
|
||||
@@ -280,29 +412,16 @@ class OSG_EXPORT VertexBufferObject : public BufferObject
|
||||
VertexBufferObject(const VertexBufferObject& vbo,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osg,VertexBufferObject);
|
||||
|
||||
typedef std::pair< BufferEntry, Array* > BufferEntryArrayPair;
|
||||
typedef std::vector< BufferEntryArrayPair > BufferEntryArrayPairs;
|
||||
|
||||
unsigned int addArray(osg::Array* array);
|
||||
void removeArray(osg::Array* array);
|
||||
|
||||
void setArray(unsigned int i, Array* array);
|
||||
Array* getArray(unsigned int i) { return _bufferEntryArrayPairs[i].second; }
|
||||
const Array* getArray(unsigned int i) const { return _bufferEntryArrayPairs[i].second; }
|
||||
|
||||
const GLvoid* getOffset(unsigned int i) const { return (const GLvoid*)(((char *)0)+(_bufferEntryArrayPairs[i].first.offset)); }
|
||||
|
||||
virtual void compileBuffer(State& state) const;
|
||||
|
||||
/** Resize any per context GLObject buffers to specified size. */
|
||||
virtual void resizeGLObjectBuffers(unsigned int maxSize);
|
||||
Array* getArray(unsigned int i);
|
||||
const Array* getArray(unsigned int i) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~VertexBufferObject();
|
||||
|
||||
BufferEntryArrayPairs _bufferEntryArrayPairs;
|
||||
};
|
||||
|
||||
class DrawElements;
|
||||
@@ -317,28 +436,16 @@ class OSG_EXPORT ElementBufferObject : public BufferObject
|
||||
|
||||
META_Object(osg,ElementBufferObject);
|
||||
|
||||
typedef std::pair< BufferEntry, DrawElements* > BufferEntryDrawElementsPair;
|
||||
typedef std::vector< BufferEntryDrawElementsPair > BufferEntryDrawElementsPairs;
|
||||
|
||||
unsigned int addDrawElements(osg::DrawElements* PrimitiveSet);
|
||||
void removeDrawElements(osg::DrawElements* PrimitiveSet);
|
||||
|
||||
void setDrawElements(unsigned int i, DrawElements* PrimitiveSet);
|
||||
DrawElements* getDrawElements(unsigned int i) { return _bufferEntryDrawElementsPairs[i].second; }
|
||||
const DrawElements* getDrawElements(unsigned int i) const { return _bufferEntryDrawElementsPairs[i].second; }
|
||||
|
||||
const GLvoid* getOffset(unsigned int i) const { return (const GLvoid*)(((char *)0)+(_bufferEntryDrawElementsPairs[i].first.offset)); }
|
||||
|
||||
virtual void compileBuffer(State& state) const;
|
||||
|
||||
/** Resize any per context GLObject buffers to specified size. */
|
||||
virtual void resizeGLObjectBuffers(unsigned int maxSize);
|
||||
DrawElements* getDrawElements(unsigned int i);
|
||||
const DrawElements* getDrawElements(unsigned int i) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~ElementBufferObject();
|
||||
|
||||
BufferEntryDrawElementsPairs _bufferEntryDrawElementsPairs;
|
||||
};
|
||||
|
||||
class Image;
|
||||
@@ -352,26 +459,17 @@ class OSG_EXPORT PixelBufferObject : public BufferObject
|
||||
PixelBufferObject(const PixelBufferObject& pbo,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osg,PixelBufferObject);
|
||||
|
||||
typedef std::pair< BufferEntry, Image* > BufferEntryImagePair;
|
||||
|
||||
void setImage(osg::Image* image);
|
||||
|
||||
Image* getImage() { return _bufferEntryImagePair.second; }
|
||||
const Image* getImage() const { return _bufferEntryImagePair.second; }
|
||||
|
||||
unsigned int offset() const { return _bufferEntryImagePair.first.offset; }
|
||||
|
||||
virtual void compileBuffer(State& state) const;
|
||||
Image* getImage();
|
||||
const Image* getImage() const;
|
||||
|
||||
/** Resize any per context GLObject buffers to specified size. */
|
||||
virtual void resizeGLObjectBuffers(unsigned int maxSize);
|
||||
bool isPBOSupported(unsigned int contextID) const { return _glBufferObjects[contextID]->isPBOSupported(); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~PixelBufferObject();
|
||||
|
||||
BufferEntryImagePair _bufferEntryImagePair;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -389,10 +487,10 @@ class OSG_EXPORT PixelDataBufferObject : public BufferObject
|
||||
META_Object(osg, PixelDataBufferObject);
|
||||
|
||||
//! Set new size of the buffer object. This will reallocate the memory on the next compile
|
||||
inline void setDataSize(unsigned int size) { _bufferData.dataSize = size; dirty(); }
|
||||
inline void setDataSize(unsigned int size) { _dataSize = size; dirty(); }
|
||||
|
||||
//! Get data size of the used buffer
|
||||
inline unsigned int getDataSize() { return _bufferData.dataSize; }
|
||||
inline unsigned int getDataSize() const { return _dataSize; }
|
||||
|
||||
//! Compile the buffer (reallocate the memory if buffer is dirty)
|
||||
virtual void compileBuffer(State& state) const;
|
||||
@@ -427,7 +525,7 @@ class OSG_EXPORT PixelDataBufferObject : public BufferObject
|
||||
|
||||
virtual ~PixelDataBufferObject();
|
||||
|
||||
BufferEntry _bufferData;
|
||||
unsigned int _dataSize;
|
||||
|
||||
typedef osg::buffered_value<unsigned int> ModeList;
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace osg {
|
||||
class NodeVisitor;
|
||||
|
||||
/** Image class for encapsulating the storage texture image data. */
|
||||
class OSG_EXPORT Image : public Object
|
||||
class OSG_EXPORT Image : public BufferData
|
||||
{
|
||||
|
||||
public :
|
||||
@@ -77,6 +77,9 @@ class OSG_EXPORT Image : public Object
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
virtual const char* className() const { return "Image"; }
|
||||
|
||||
virtual const GLvoid* getDataPointer() const { return data(); }
|
||||
virtual unsigned int getTotalDataSize() const { return getTotalSizeInBytesIncludingMipmaps(); }
|
||||
|
||||
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
|
||||
virtual int compare(const Image& rhs) const;
|
||||
|
||||
@@ -252,16 +255,6 @@ class OSG_EXPORT Image : public Object
|
||||
* the host machine.
|
||||
*/
|
||||
void ensureValidSizeForTexturing(GLint maxTextureSize);
|
||||
|
||||
/** Dirty the image, which increments the modified count, to force osg::Texture to reload the image. */
|
||||
inline void dirty() { ++_modifiedCount; if (_bufferObject.valid()) _bufferObject->dirty(); }
|
||||
|
||||
/** Set the modified count value. Used by osg::Texture when using texture subloading. */
|
||||
inline void setModifiedCount(unsigned int value) { _modifiedCount=value; }
|
||||
|
||||
/** Get modified count value. Used by osg::Texture when using texture subloading. */
|
||||
inline unsigned int getModifiedCount() const { return _modifiedCount; }
|
||||
|
||||
|
||||
static bool isPackedType(GLenum type);
|
||||
static GLenum computePixelFormat(GLenum pixelFormat);
|
||||
@@ -316,15 +309,15 @@ class OSG_EXPORT Image : public Object
|
||||
virtual bool isImageTranslucent() const;
|
||||
|
||||
/** Set the optional PixelBufferObject used to map the image memory efficiently to graphics memory. */
|
||||
void setPixelBufferObject(PixelBufferObject* buffer) { _bufferObject = buffer; if (_bufferObject.valid()) _bufferObject->setImage(this); }
|
||||
void setPixelBufferObject(PixelBufferObject* buffer) { setBufferObject(buffer); }
|
||||
|
||||
/** Get the PixelBufferObject.*/
|
||||
PixelBufferObject* getPixelBufferObject() { return _bufferObject.get(); }
|
||||
/** Get the PixelBufferObject.*/
|
||||
PixelBufferObject* getPixelBufferObject() { return dynamic_cast<PixelBufferObject*>(_bufferObject.get()); }
|
||||
|
||||
/** Get the const PixelBufferObject.*/
|
||||
const PixelBufferObject* getPixelBufferObject() const { return _bufferObject.get(); }
|
||||
/** Get the const PixelBufferObject.*/
|
||||
const PixelBufferObject* getPixelBufferObject() const { return dynamic_cast<const PixelBufferObject*>(_bufferObject.get()); }
|
||||
|
||||
virtual void update(NodeVisitor* /*nv*/) {}
|
||||
virtual void update(NodeVisitor* /*nv*/) {}
|
||||
|
||||
/** method for sending pointer events to images that are acting as front ends to interactive surfaces such as a vnc or browser window. Return true if handled. */
|
||||
virtual bool sendPointerEvent(int /*x*/, int /*y*/, int /*buttonMask*/) { return false; }
|
||||
@@ -361,8 +354,6 @@ class OSG_EXPORT Image : public Object
|
||||
|
||||
void setData(unsigned char* data,AllocationMode allocationMode);
|
||||
|
||||
unsigned int _modifiedCount;
|
||||
|
||||
MipmapDataType _mipmapData;
|
||||
|
||||
ref_ptr<PixelBufferObject> _bufferObject;
|
||||
|
||||
@@ -147,7 +147,7 @@ public:
|
||||
|
||||
class DrawElements;
|
||||
|
||||
class OSG_EXPORT PrimitiveSet : public Object
|
||||
class OSG_EXPORT PrimitiveSet : public BufferData
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -179,15 +179,13 @@ class OSG_EXPORT PrimitiveSet : public Object
|
||||
_primitiveType(primType),
|
||||
_numInstances(numInstances),
|
||||
_mode(mode),
|
||||
_modifiedCount(0),
|
||||
_rangeModifiedCount(0) {}
|
||||
|
||||
PrimitiveSet(const PrimitiveSet& prim,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Object(prim,copyop),
|
||||
BufferData(prim,copyop),
|
||||
_primitiveType(prim._primitiveType),
|
||||
_numInstances(prim._numInstances),
|
||||
_mode(prim._mode),
|
||||
_modifiedCount(0),
|
||||
_rangeModifiedCount(0) {}
|
||||
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const PrimitiveSet*>(obj)!=NULL; }
|
||||
@@ -219,23 +217,6 @@ class OSG_EXPORT PrimitiveSet : public Object
|
||||
|
||||
virtual unsigned int getNumPrimitives() const;
|
||||
|
||||
/** Dirty the primitive, which increments the modified count, to force buffer objects to update. */
|
||||
virtual void dirty() { ++_modifiedCount; }
|
||||
|
||||
/** Set the modified count value.*/
|
||||
inline void setModifiedCount(unsigned int value) { _modifiedCount=value; }
|
||||
|
||||
/** Get modified count value.*/
|
||||
inline unsigned int getModifiedCount() const { return _modifiedCount; }
|
||||
|
||||
/** Resize any per context GLObject buffers to specified size. */
|
||||
virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/) {}
|
||||
|
||||
/** If State is non-zero, this function releases OpenGL objects for
|
||||
* the specified graphics context. Otherwise, releases OpenGL objects
|
||||
* for all graphics contexts. */
|
||||
virtual void releaseGLObjects(State* /*state*/=0) const {}
|
||||
|
||||
virtual void computeRange() const {}
|
||||
|
||||
protected:
|
||||
@@ -245,31 +226,7 @@ class OSG_EXPORT PrimitiveSet : public Object
|
||||
Type _primitiveType;
|
||||
int _numInstances;
|
||||
GLenum _mode;
|
||||
unsigned int _modifiedCount;
|
||||
mutable unsigned int _rangeModifiedCount;
|
||||
|
||||
struct ObjectIDModifiedCountPair
|
||||
{
|
||||
ObjectIDModifiedCountPair():
|
||||
_objectID(0),
|
||||
_modifiedCount(0) {}
|
||||
|
||||
ObjectIDModifiedCountPair(const ObjectIDModifiedCountPair& obj):
|
||||
_objectID(obj._objectID),
|
||||
_modifiedCount(obj._modifiedCount) {}
|
||||
|
||||
ObjectIDModifiedCountPair& operator = (const ObjectIDModifiedCountPair& obj)
|
||||
{
|
||||
_objectID = obj._objectID;
|
||||
_modifiedCount = obj._modifiedCount;
|
||||
return *this;
|
||||
}
|
||||
|
||||
GLuint _objectID;
|
||||
unsigned int _modifiedCount;
|
||||
};
|
||||
|
||||
typedef osg::buffered_object<ObjectIDModifiedCountPair> GLObjectList;
|
||||
};
|
||||
|
||||
class OSG_EXPORT DrawArrays : public PrimitiveSet
|
||||
@@ -392,83 +349,32 @@ class DrawElements : public PrimitiveSet
|
||||
public:
|
||||
|
||||
DrawElements(Type primType=PrimitiveType, GLenum mode=0, int numInstances=0):
|
||||
PrimitiveSet(primType,mode, numInstances),
|
||||
_eboOffset(0) {}
|
||||
PrimitiveSet(primType,mode, numInstances) {}
|
||||
|
||||
DrawElements(const DrawElements& copy,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
PrimitiveSet(copy,copyop),
|
||||
_eboOffset(0) {}
|
||||
PrimitiveSet(copy,copyop) {}
|
||||
|
||||
|
||||
virtual DrawElements* getDrawElements() { return this; }
|
||||
virtual const DrawElements* getDrawElements() const { return this; }
|
||||
|
||||
virtual void dirty() { ++_modifiedCount; if (_ebo.valid()) _ebo->dirty(); }
|
||||
|
||||
/** Set the ElementBufferObject.*/
|
||||
inline void setElementBufferObject(osg::ElementBufferObject* ebo)
|
||||
{
|
||||
if (_ebo == ebo) return;
|
||||
|
||||
if (_ebo.valid())
|
||||
{
|
||||
_ebo->removeDrawElements(this);
|
||||
}
|
||||
|
||||
_ebo = ebo;
|
||||
inline void setElementBufferObject(osg::ElementBufferObject* ebo) { setBufferObject(ebo); }
|
||||
|
||||
if (_ebo.valid())
|
||||
{
|
||||
_ebo->addDrawElements(this);
|
||||
}
|
||||
}
|
||||
|
||||
/** Get the ElementBufferObject. If no EBO is assigned returns NULL*/
|
||||
inline osg::ElementBufferObject* getElementBufferObject() { return _ebo.get(); }
|
||||
inline osg::ElementBufferObject* getElementBufferObject() { return dynamic_cast<osg::ElementBufferObject*>(_bufferObject.get()); }
|
||||
|
||||
/** Get the const ElementBufferObject. If no EBO is assigned returns NULL*/
|
||||
inline const osg::ElementBufferObject* getElementBufferObject() const { return _ebo.get(); }
|
||||
inline const osg::ElementBufferObject* getElementBufferObject() const { return dynamic_cast<const osg::ElementBufferObject*>(_bufferObject.get()); }
|
||||
|
||||
/** Set the offset into the ElementBufferObject, if used.*/
|
||||
inline void setElementBufferObjectOffset(const GLvoid* offset) const { _eboOffset = offset; }
|
||||
|
||||
/** Get the offset into the ElementBufferOffset, if used.*/
|
||||
inline const GLvoid* getElementBufferObjectOffset() const { return _eboOffset; }
|
||||
|
||||
|
||||
/** Resize any per context GLObject buffers to specified size. */
|
||||
virtual void resizeGLObjectBuffers(unsigned int maxSize)
|
||||
{
|
||||
if (_ebo.valid()) _ebo->resizeGLObjectBuffers(maxSize);
|
||||
}
|
||||
|
||||
/** If State is non-zero, this function releases OpenGL objects for
|
||||
* the specified graphics context. Otherwise, releases OpenGL objects
|
||||
* for all graphics contexts. */
|
||||
virtual void releaseGLObjects(State* state=0) const
|
||||
{
|
||||
if (_ebo.valid()) _ebo->releaseGLObjects(state);
|
||||
}
|
||||
|
||||
|
||||
virtual void reserveElements(unsigned int numIndices) = 0;
|
||||
virtual void setElement(unsigned int, unsigned int) = 0;
|
||||
virtual unsigned int getElement(unsigned int) = 0;
|
||||
virtual void addElement(unsigned int) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~DrawElements()
|
||||
{
|
||||
if (_ebo.valid())
|
||||
{
|
||||
_ebo->removeDrawElements(this);
|
||||
}
|
||||
}
|
||||
|
||||
osg::ref_ptr<ElementBufferObject> _ebo;
|
||||
mutable const GLvoid* _eboOffset;
|
||||
|
||||
virtual ~DrawElements() {}
|
||||
};
|
||||
|
||||
class OSG_EXPORT DrawElementsUByte : public DrawElements, public VectorGLubyte
|
||||
|
||||
@@ -405,13 +405,13 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
void dirtyAllVertexArrays();
|
||||
|
||||
|
||||
void setCurrentVertexBufferObject(osg::VertexBufferObject* vbo) { _currentVBO = vbo; }
|
||||
const VertexBufferObject* getCurrentVertexBufferObject() { return _currentVBO; }
|
||||
inline void bindVertexBufferObject(const osg::VertexBufferObject* vbo)
|
||||
void setCurrentVertexBufferObject(osg::GLBufferObject* vbo) { _currentVBO = vbo; }
|
||||
const GLBufferObject* getCurrentVertexBufferObject() { return _currentVBO; }
|
||||
inline void bindVertexBufferObject(osg::GLBufferObject* vbo)
|
||||
{
|
||||
if (vbo == _currentVBO) return;
|
||||
if (vbo->isDirty(_contextID)) vbo->compileBuffer(*this);
|
||||
else _glBindBuffer(GL_ARRAY_BUFFER_ARB,vbo->buffer(_contextID));
|
||||
if (vbo->isDirty()) vbo->compileBuffer();
|
||||
else _glBindBuffer(GL_ARRAY_BUFFER_ARB,vbo->getGLObjectID());
|
||||
_currentVBO = vbo;
|
||||
}
|
||||
|
||||
@@ -422,14 +422,14 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
_currentVBO = 0;
|
||||
}
|
||||
|
||||
void setCurrentElementBufferObject(osg::ElementBufferObject* ebo) { _currentEBO = ebo; }
|
||||
const ElementBufferObject* getCurrentElementBufferObject() { return _currentEBO; }
|
||||
void setCurrentElementBufferObject(osg::GLBufferObject* ebo) { _currentEBO = ebo; }
|
||||
const GLBufferObject* getCurrentElementBufferObject() { return _currentEBO; }
|
||||
|
||||
inline void bindElementBufferObject(const osg::ElementBufferObject* ebo)
|
||||
inline void bindElementBufferObject(osg::GLBufferObject* ebo)
|
||||
{
|
||||
if (ebo == _currentEBO) return;
|
||||
if (ebo->isDirty(_contextID)) ebo->compileBuffer(*this);
|
||||
else _glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,ebo->buffer(_contextID));
|
||||
if (ebo->isDirty()) ebo->compileBuffer();
|
||||
else _glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,ebo->getGLObjectID());
|
||||
_currentEBO = ebo;
|
||||
}
|
||||
|
||||
@@ -440,15 +440,15 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
_currentEBO = 0;
|
||||
}
|
||||
|
||||
void setCurrentPixelBufferObject(osg::PixelBufferObject* pbo) { _currentPBO = pbo; }
|
||||
const PixelBufferObject* getCurrentPixelBufferObject() { return _currentPBO; }
|
||||
void setCurrentPixelBufferObject(osg::GLBufferObject* pbo) { _currentPBO = pbo; }
|
||||
const GLBufferObject* getCurrentPixelBufferObject() { return _currentPBO; }
|
||||
|
||||
inline void bindPixelBufferObject(const osg::PixelBufferObject* pbo)
|
||||
inline void bindPixelBufferObject(osg::GLBufferObject* pbo)
|
||||
{
|
||||
if (pbo == _currentPBO) return;
|
||||
|
||||
if (pbo->isDirty(_contextID)) pbo->compileBuffer(*this);
|
||||
else _glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB,pbo->buffer(_contextID));
|
||||
if (pbo->isDirty()) pbo->compileBuffer();
|
||||
else _glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB,pbo->getGLObjectID());
|
||||
|
||||
_currentPBO = pbo;
|
||||
}
|
||||
@@ -485,11 +485,11 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
const VertexBufferObject* vbo = array->getVertexBufferObject();
|
||||
GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID);
|
||||
if (vbo)
|
||||
{
|
||||
bindVertexBufferObject(vbo);
|
||||
setVertexPointer(array->getDataSize(),array->getDataType(),0,array->getVertexBufferObjectOffset());
|
||||
setVertexPointer(array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -542,11 +542,11 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
const VertexBufferObject* vbo = array->getVertexBufferObject();
|
||||
GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID);
|
||||
if (vbo)
|
||||
{
|
||||
bindVertexBufferObject(vbo);
|
||||
setNormalPointer(array->getDataType(),0,array->getVertexBufferObjectOffset());
|
||||
setNormalPointer(array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -598,11 +598,11 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
const VertexBufferObject* vbo = array->getVertexBufferObject();
|
||||
GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID);
|
||||
if (vbo)
|
||||
{
|
||||
bindVertexBufferObject(vbo);
|
||||
setColorPointer(array->getDataSize(),array->getDataType(),0,array->getVertexBufferObjectOffset());
|
||||
setColorPointer(array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -659,15 +659,11 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
const VertexBufferObject* vbo = array->getVertexBufferObject();
|
||||
GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID);
|
||||
if (vbo)
|
||||
{
|
||||
bindVertexBufferObject(vbo);
|
||||
#if 0
|
||||
setSecondaryColorPointer(array->getDataSize(),array->getDataType(),0,vbo->getOffset(array->getVertexBufferObjectIndex()));
|
||||
#else
|
||||
setSecondaryColorPointer(array->getDataSize(),array->getDataType(),0,array->getVertexBufferObjectOffset());
|
||||
#endif
|
||||
setSecondaryColorPointer(array->getDataSize(),array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -745,15 +741,11 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
const VertexBufferObject* vbo = array->getVertexBufferObject();
|
||||
GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID);
|
||||
if (vbo)
|
||||
{
|
||||
bindVertexBufferObject(vbo);
|
||||
#if 0
|
||||
setFogCoordPointer(array->getDataType(),0,vbo->getOffset(array->getVertexBufferObjectIndex()));
|
||||
#else
|
||||
setFogCoordPointer(array->getDataType(),0,array->getVertexBufferObjectOffset());
|
||||
#endif
|
||||
setFogCoordPointer(array->getDataType(),0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -794,15 +786,11 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
const VertexBufferObject* vbo = array->getVertexBufferObject();
|
||||
GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID);
|
||||
if (vbo)
|
||||
{
|
||||
bindVertexBufferObject(vbo);
|
||||
#if 0
|
||||
setTexCoordPointer(unit, array->getDataSize(),array->getDataType(),0,vbo->getOffset(array->getVertexBufferObjectIndex()));
|
||||
#else
|
||||
setTexCoordPointer(unit, array->getDataSize(),array->getDataType(),0,array->getVertexBufferObjectOffset());
|
||||
#endif
|
||||
setTexCoordPointer(unit, array->getDataSize(),array->getDataType(),0, (const GLvoid *)(vbo->getOffset(array->getBufferIndex())));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -916,15 +904,11 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
const VertexBufferObject* vbo = array->getVertexBufferObject();
|
||||
GLBufferObject* vbo = array->getOrCreateGLBufferObject(_contextID);
|
||||
if (vbo)
|
||||
{
|
||||
bindVertexBufferObject(vbo);
|
||||
#if 0
|
||||
setVertexAttribPointer(unit, array->getDataSize(),array->getDataType(),normalized,0,vbo->getOffset(array->getVertexBufferObjectIndex()));
|
||||
#else
|
||||
setVertexAttribPointer(unit, array->getDataSize(),array->getDataType(),normalized,0,array->getVertexBufferObjectOffset());
|
||||
#endif
|
||||
setVertexAttribPointer(unit, array->getDataSize(),array->getDataType(),normalized,0,(const GLvoid *)(vbo->getOffset(array->getBufferIndex())));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1279,9 +1263,9 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
|
||||
unsigned int _currentActiveTextureUnit;
|
||||
unsigned int _currentClientActiveTextureUnit;
|
||||
const VertexBufferObject* _currentVBO;
|
||||
const ElementBufferObject* _currentEBO;
|
||||
const PixelBufferObject* _currentPBO;
|
||||
GLBufferObject* _currentVBO;
|
||||
GLBufferObject* _currentEBO;
|
||||
GLBufferObject* _currentPBO;
|
||||
|
||||
|
||||
inline ModeMap& getOrCreateTextureModeMap(unsigned int unit)
|
||||
|
||||
Reference in New Issue
Block a user