15#ifndef OSG_BUFFEROBJECT
16#define OSG_BUFFEROBJECT 1
29#ifndef GL_ARB_vertex_buffer_object
30 #define GL_ARRAY_BUFFER_ARB 0x8892
31 #define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893
32 #define GL_ARRAY_BUFFER_BINDING_ARB 0x8894
33 #define GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB 0x8895
34 #define GL_VERTEX_ARRAY_BUFFER_BINDING_ARB 0x8896
35 #define GL_NORMAL_ARRAY_BUFFER_BINDING_ARB 0x8897
36 #define GL_COLOR_ARRAY_BUFFER_BINDING_ARB 0x8898
37 #define GL_INDEX_ARRAY_BUFFER_BINDING_ARB 0x8899
38 #define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB 0x889A
39 #define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB 0x889B
40 #define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB 0x889C
41 #define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB 0x889D
42 #define GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB 0x889E
43 #define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB 0x889F
44 #define GL_STREAM_DRAW_ARB 0x88E0
45 #define GL_STREAM_READ_ARB 0x88E1
46 #define GL_STREAM_COPY_ARB 0x88E2
47 #define GL_STATIC_DRAW_ARB 0x88E4
48 #define GL_STATIC_READ_ARB 0x88E5
49 #define GL_STATIC_COPY_ARB 0x88E6
50 #define GL_DYNAMIC_DRAW_ARB 0x88E8
51 #define GL_DYNAMIC_READ_ARB 0x88E9
52 #define GL_DYNAMIC_COPY_ARB 0x88EA
53 #define GL_READ_ONLY_ARB 0x88B8
54 #define GL_WRITE_ONLY_ARB 0x88B9
55 #define GL_READ_WRITE_ARB 0x88BA
56 #define GL_BUFFER_SIZE_ARB 0x8764
57 #define GL_BUFFER_USAGE_ARB 0x8765
58 #define GL_BUFFER_ACCESS_ARB 0x88BB
59 #define GL_BUFFER_MAPPED_ARB 0x88BC
60 #define GL_BUFFER_MAP_POINTER_ARB 0x88BD
64 #define GL_STREAM_DRAW 0x88E0
65 #define GL_STREAM_READ 0x88E1
66 #define GL_STREAM_COPY 0x88E2
67 #define GL_STATIC_DRAW 0x88E4
68 #define GL_STATIC_READ 0x88E5
69 #define GL_STATIC_COPY 0x88E6
70 #define GL_DYNAMIC_DRAW 0x88E8
71 #define GL_DYNAMIC_READ 0x88E9
72 #define GL_DYNAMIC_COPY 0x88EA
76 #define GL_PIXEL_PACK_BUFFER 0x88EB
77 #define GL_PIXEL_UNPACK_BUFFER 0x88EC
78 #define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED
79 #define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF
83#ifndef GL_ARB_pixel_buffer_object
84 #define GL_PIXEL_PACK_BUFFER_ARB 0x88EB
85 #define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC
86 #define GL_PIXEL_PACK_BUFFER_BINDING_ARB 0x88ED
87 #define GL_PIXEL_UNPACK_BUFFER_BINDING_ARB 0x88EF
131 void setProfile(GLenum target, GLenum usage,
unsigned int size)
157 if (bufferAlignment<2)
return pos;
158 if ((pos%bufferAlignment)==0)
return pos;
159 return ((pos/bufferAlignment)+1)*bufferAlignment;
188 if (&rhs==
this)
return *
this;
212 inline void bindBuffer();
421 virtual const char*
className()
const {
return "BufferObject"; }
514 virtual const char*
className()
const {
return "BufferData"; }
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
std::list< ref_ptr< GLBufferObject > > GLBufferObjectList
Definition BufferObject:274
unsigned int computeBufferAlignment(unsigned int pos, unsigned int bufferAlignment)
Definition BufferObject:155
ptrdiff_t GLsizeiptr
Definition GLDefines:691
Implements a simple buffered value for values that need to be buffered on a per graphics context basi...
Definition buffered_value:27
Definition buffered_value:79
Definition BufferObject:98
bool operator==(const BufferObjectProfile &rhs) const
Definition BufferObject:124
bool operator<(const BufferObjectProfile &rhs) const
Definition BufferObject:115
BufferObjectProfile & operator=(const BufferObjectProfile &rhs)
Definition BufferObject:138
GLenum _size
Definition BufferObject:148
BufferObjectProfile()
Definition BufferObject:100
void setProfile(GLenum target, GLenum usage, unsigned int size)
Definition BufferObject:131
BufferObjectProfile(GLenum target, GLenum usage, unsigned int size)
Definition BufferObject:105
GLenum _target
Definition BufferObject:146
GLenum _usage
Definition BufferObject:147
BufferObjectProfile(const BufferObjectProfile &bpo)
Definition BufferObject:110
Definition BufferObject:164
GLuint & getGLObjectID()
Definition BufferObject:208
void setBufferObject(BufferObject *bufferObject)
void setProfile(const BufferObjectProfile &profile)
Definition BufferObject:169
void dirty()
Definition BufferObject:224
virtual ~GLBufferObject()
GLsizeiptr getOffset(unsigned int i) const
Definition BufferObject:210
unsigned int _allocatedSize
Definition BufferObject:253
GLBufferObject(unsigned int contextID, BufferObject *bufferObject, unsigned int glObjectID=0)
const BufferObjectProfile & getProfile() const
Definition BufferObject:170
void unbindBuffer()
Definition BufferObject:214
void setBufferDataHasBeenRead(const osg::BufferData *bd)
void bindBuffer()
Definition BufferObject:771
BufferEntries _bufferEntries
Definition BufferObject:258
bool hasAllBufferDataBeenRead() const
bool isPBOSupported() const
Definition BufferObject:234
BufferObject * _bufferObject
Definition BufferObject:260
unsigned int _contextID
Definition BufferObject:249
void assign(BufferObject *bufferObject)
bool _dirty
Definition BufferObject:255
GLExtensions * _extensions
Definition BufferObject:270
GLuint getGLObjectID() const
Definition BufferObject:209
BufferObjectProfile _profile
Definition BufferObject:252
unsigned int getContextID() const
Definition BufferObject:206
bool isDirty() const
Definition BufferObject:222
GLBufferObjectSet * _set
Definition BufferObject:264
GLuint _glObjectID
Definition BufferObject:250
std::vector< BufferEntry > BufferEntries
Definition BufferObject:257
unsigned int computeBufferAlignment(unsigned int pos, unsigned int bufferAlignment) const
Definition BufferObject:244
GLBufferObject * _previous
Definition BufferObject:265
void release()
release GLBufferObject to the orphan list to be reused or deleted.
unsigned int _frameLastUsed
Definition BufferObject:267
BufferObject * getBufferObject()
Definition BufferObject:173
GLBufferObject * _next
Definition BufferObject:266
unsigned int modifiedCount
Definition BufferObject:200
BufferEntry(const BufferEntry &rhs)
Definition BufferObject:179
BufferEntry()
Definition BufferObject:177
unsigned int getNumClients() const
BufferData * dataSource
Definition BufferObject:203
unsigned int numRead
Definition BufferObject:199
unsigned int offset
Definition BufferObject:202
unsigned int dataSize
Definition BufferObject:201
Definition BufferObject:277
void flushDeletedGLBufferObjects(double currentTime, double &availableTime)
void remove(GLBufferObject *to)
osg::ref_ptr< GLBufferObject > takeFromOrphans(BufferObject *bufferObject)
unsigned int computeNumGLBufferObjectsInList() const
BufferObjectProfile _profile
Definition BufferObject:322
void deleteAllGLBufferObjects()
GLBufferObject * _head
Definition BufferObject:327
GLBufferObjectList _pendingOrphanedGLBufferObjects
Definition BufferObject:325
void addToBack(GLBufferObject *to)
void orphan(GLBufferObject *to)
bool checkConsistency() const
virtual ~GLBufferObjectSet()
unsigned int getNumOrphans() const
Definition BufferObject:310
unsigned int _numOfGLBufferObjects
Definition BufferObject:323
void moveToBack(GLBufferObject *to)
void flushAllDeletedGLBufferObjects()
GLBufferObjectSet(GLBufferObjectManager *parent, const BufferObjectProfile &profile)
GLBufferObjectList _orphanedGLBufferObjects
Definition BufferObject:324
osg::ref_ptr< GLBufferObject > takeOrGenerate(BufferObject *bufferObject)
unsigned int getNumOfGLBufferObjects() const
Definition BufferObject:309
unsigned int _contextID
Definition BufferObject:321
void discardAllGLBufferObjects()
OpenThreads::Mutex _mutex
Definition BufferObject:318
void discardAllDeletedGLBufferObjects()
GLBufferObjectManager * getParent()
Definition BufferObject:306
unsigned int size() const
Definition BufferObject:300
GLBufferObjectManager * _parent
Definition BufferObject:320
GLBufferObject * _tail
Definition BufferObject:328
unsigned int getNumPendingOrphans() const
Definition BufferObject:311
void moveToSet(GLBufferObject *to, GLBufferObjectSet *set)
bool makeSpace(unsigned int &size)
void handlePendingOrphandedGLBufferObjects()
const BufferObjectProfile & getProfile() const
Definition BufferObject:281
Definition BufferObject:332
osg::ref_ptr< GLBufferObject > generateGLBufferObject(const osg::BufferObject *bufferObject)
unsigned int _maxGLBufferObjectPoolSize
Definition BufferObject:392
unsigned int & getCurrGLBufferObjectPoolSize()
Definition BufferObject:345
unsigned int getCurrGLBufferObjectPoolSize() const
Definition BufferObject:346
GLBufferObjectSet * getGLBufferObjectSet(const BufferObjectProfile &profile)
double _deleteTime
Definition BufferObject:399
GLBufferObjectSetMap _glBufferObjectSetMap
Definition BufferObject:393
void discardAllDeletedGLObjects()
bool hasSpace(unsigned int size) const
Definition BufferObject:351
unsigned int & getNumberApplied()
Definition BufferObject:380
unsigned int & getNumberOrphanedGLBufferObjects()
Definition BufferObject:341
void setCurrGLBufferObjectPoolSize(unsigned int size)
Definition BufferObject:344
unsigned int _currGLBufferObjectPoolSize
Definition BufferObject:391
unsigned int _numGenerated
Definition BufferObject:401
unsigned int getNumberOrphanedGLBufferObjects() const
Definition BufferObject:342
unsigned int _numActiveGLBufferObjects
Definition BufferObject:389
unsigned int & getNumberDeleted()
Definition BufferObject:374
unsigned int _numDeleted
Definition BufferObject:398
unsigned int _numFrames
Definition BufferObject:397
GLBufferObjectManager(unsigned int contextID)
void setNumberActiveGLBufferObjects(unsigned int size)
Definition BufferObject:336
unsigned int & getNumberGenerated()
Definition BufferObject:377
void setMaxGLBufferObjectPoolSize(unsigned int size)
double _applyTime
Definition BufferObject:405
void deleteAllGLObjects()
Do a GL delete all OpenGL objects.
void newFrame(osg::FrameStamp *fs)
Signal that a new frame has started.
unsigned int getNumberActiveGLBufferObjects() const
Definition BufferObject:338
unsigned int & getNumberFrames()
Definition BufferObject:372
unsigned int & getFrameNumber()
Definition BufferObject:371
void flushAllDeletedGLObjects()
Flush all deleted OpenGL objects.
unsigned int _numOrphanedGLBufferObjects
Definition BufferObject:390
double & getApplyTime()
Definition BufferObject:381
unsigned int & getNumberActiveGLBufferObjects()
Definition BufferObject:337
void handlePendingOrphandedGLBufferObjects()
void discardAllGLObjects()
Discard all OpenGL objects.
void recomputeStats(std::ostream &out) const
std::map< BufferObjectProfile, osg::ref_ptr< GLBufferObjectSet > > GLBufferObjectSetMap
Definition BufferObject:387
void flushDeletedGLObjects(double currentTime, double &availableTime)
Flush all deleted OpenGL objects within the specified availableTime.
void reportStats(std::ostream &out)
unsigned int _numApplied
Definition BufferObject:404
unsigned int _frameNumber
Definition BufferObject:395
virtual ~GLBufferObjectManager()
double & getGenerateTime()
Definition BufferObject:378
bool makeSpace(unsigned int size)
unsigned int getMaxGLBufferObjectPoolSize() const
Definition BufferObject:349
double _generateTime
Definition BufferObject:402
double & getDeleteTime()
Definition BufferObject:375
void setNumberOrphanedGLBufferObjects(unsigned int size)
Definition BufferObject:340
Definition BufferObject:411
void setTarget(GLenum target)
Definition BufferObject:423
void setBufferData(unsigned int index, BufferData *bd)
osg::buffered_object< osg::ref_ptr< GLBufferObject > > GLBufferObjects
Definition BufferObject:483
std::vector< BufferData * > BufferDataList
Definition BufferObject:482
void setUsage(GLenum usage)
Set what type of usage the buffer object will have.
Definition BufferObject:431
BufferObject(const BufferObject &bo, const CopyOp ©op=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
GLBufferObject * getGLBufferObject(unsigned int contextID) const
Definition BufferObject:469
virtual bool isSameKindAs(const Object *obj) const
Definition BufferObject:419
GLenum getTarget() const
Definition BufferObject:424
BufferObjectProfile _profile
Definition BufferObject:485
void removeBufferData(BufferData *bd)
static void deleteBufferObject(unsigned int contextID, GLuint globj)
deprecated, provided for backwards compatibility.
BufferDataList _bufferDataList
Definition BufferObject:489
GLenum getUsage() const
Get the type of usage the buffer object has been set up for.
Definition BufferObject:434
void releaseGLObjects(State *state=0) const
If State is non-zero, this function releases OpenGL objects for the specified graphics context.
unsigned int getNumBufferData() const
Definition BufferObject:465
BufferData * getBufferData(unsigned int index)
Definition BufferObject:462
GLBufferObjects _glBufferObjects
Definition BufferObject:491
void removeBufferData(unsigned int index)
void setGLBufferObject(unsigned int contextID, GLBufferObject *glbo)
Definition BufferObject:467
bool getCopyDataAndReleaseGLBufferObject() const
Get whether the BufferObject should use a GLBufferObject just for copying the BufferData and release ...
Definition BufferObject:444
GLBufferObject * getOrCreateGLBufferObject(unsigned int contextID) const
BufferObjectProfile & getProfile()
Definition BufferObject:436
void setCopyDataAndReleaseGLBufferObject(bool copyAndRelease)
Set whether the BufferObject should use a GLBufferObject just for copying the BufferData and release ...
Definition BufferObject:441
const BufferObjectProfile & getProfile() const
Definition BufferObject:437
bool _copyDataAndReleaseGLBufferObject
Definition BufferObject:487
virtual void resizeGLObjectBuffers(unsigned int maxSize)
Resize any per context GLObject buffers to specified size.
virtual const char * className() const
return the name of the object's class type.
Definition BufferObject:421
unsigned int computeRequiredBufferSize() const
const BufferData * getBufferData(unsigned int index) const
Definition BufferObject:463
virtual const char * libraryName() const
return the name of the object's library.
Definition BufferObject:420
unsigned int addBufferData(BufferData *bd)
Definition BufferObject:495
void addClient(osg::Object *)
Definition BufferObject:579
unsigned int getNumClients() const
Definition BufferObject:577
virtual const osg::PrimitiveSet * asPrimitiveSet() const
Definition BufferObject:523
BufferObject * getBufferObject()
Definition BufferObject:529
unsigned int _numClients
Definition BufferObject:593
const BufferObject * getBufferObject() const
Definition BufferObject:530
osg::ref_ptr< ModifiedCallback > _modifiedCallback
Definition BufferObject:591
virtual osg::Image * asImage()
Convert 'this' into a Image pointer if Object is a Image, otherwise return 0.
Definition BufferObject:525
GLBufferObject * getGLBufferObject(unsigned int contextID) const
Definition BufferObject:535
unsigned int getModifiedCount() const
Get modified count value.
Definition BufferObject:567
virtual osg::Array * asArray()
Definition BufferObject:519
virtual const GLvoid * getDataPointer() const =0
virtual const osg::Array * asArray() const
Definition BufferObject:520
BufferData()
Definition BufferObject:498
osg::ref_ptr< BufferObject > _bufferObject
Definition BufferObject:590
virtual bool isSameKindAs(const Object *obj) const
Definition BufferObject:512
const ModifiedCallback * getModifiedCallback() const
Definition BufferObject:552
virtual osg::PrimitiveSet * asPrimitiveSet()
Definition BufferObject:522
virtual unsigned int getTotalDataSize() const =0
unsigned int _modifiedCount
Definition BufferObject:587
void removeClient(osg::Object *)
Definition BufferObject:581
virtual const osg::Image * asImage() const
Convert 'this' into a Image pointer if Object is a Image, otherwise return 0.
Definition BufferObject:526
GLBufferObject * getOrCreateGLBufferObject(unsigned int contextID) const
Definition BufferObject:536
void dirty()
Dirty the primitive, which increments the modified count, to force buffer objects to update.
Definition BufferObject:556
unsigned int _bufferIndex
Definition BufferObject:589
void setModifiedCount(unsigned int value)
Set the modified count value.
Definition BufferObject:564
void setModifiedCallback(ModifiedCallback *md)
Definition BufferObject:550
ModifiedCallback * getModifiedCallback()
Definition BufferObject:551
unsigned int getBufferIndex() const
Definition BufferObject:533
virtual const char * libraryName() const
return the name of the object's library.
Definition BufferObject:513
void setBufferIndex(unsigned int index)
Definition BufferObject:532
BufferData(const BufferData &bd, const CopyOp ©op=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
Definition BufferObject:505
void setBufferObject(BufferObject *bufferObject)
virtual const char * className() const
return the name of the object's class type.
Definition BufferObject:514
virtual void resizeGLObjectBuffers(unsigned int maxSize)
Resize any per context GLObject buffers to specified size.
void releaseGLObjects(State *state=0) const
If State is non-zero, this function releases OpenGL objects for the specified graphics context.
Definition BufferObject:539
ModifiedCallback()
Definition BufferObject:540
ModifiedCallback(const ModifiedCallback &org, const CopyOp ©op)
Definition BufferObject:542
META_Object(osg, ModifiedCallback)
virtual void modified(BufferData *) const
Definition BufferObject:547
virtual ~VertexBufferObject()
const Array * getArray(unsigned int i) const
void removeArray(osg::Array *array)
unsigned int addArray(osg::Array *array)
Array * getArray(unsigned int i)
void setArray(unsigned int i, Array *array)
META_Object(osg, VertexBufferObject)
VertexBufferObject(const VertexBufferObject &vbo, const CopyOp ©op=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
const DrawElements * getDrawElements(unsigned int i) const
unsigned int addDrawElements(osg::DrawElements *PrimitiveSet)
virtual ~ElementBufferObject()
void removeDrawElements(osg::DrawElements *PrimitiveSet)
void setDrawElements(unsigned int i, DrawElements *PrimitiveSet)
ElementBufferObject(const ElementBufferObject &pbo, const CopyOp ©op=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
DrawElements * getDrawElements(unsigned int i)
META_Object(osg, ElementBufferObject)
META_Object(osg, DrawIndirectBufferObject)
void removeArray(osg::Array *array)
void setArray(unsigned int i, Array *array)
virtual ~DrawIndirectBufferObject()
DrawIndirectBufferObject(const DrawIndirectBufferObject &vbo, const CopyOp ©op=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
unsigned int addArray(osg::Array *array)
Array * getArray(unsigned int i)
const Array * getArray(unsigned int i) const
DrawIndirectBufferObject()
void setImage(osg::Image *image)
const Image * getImage() const
PixelBufferObject(const PixelBufferObject &pbo, const CopyOp ©op=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
bool isPBOSupported(unsigned int contextID) const
Definition BufferObject:683
PixelBufferObject(osg::Image *image=0)
META_Object(osg, PixelBufferObject)
virtual ~PixelBufferObject()
virtual ~PixelDataBufferObject()
osg::buffered_value< unsigned int > ModeList
Definition BufferObject:743
void setDataSize(unsigned int size)
Set new size of the buffer object. This will reallocate the memory on the next compile.
Definition BufferObject:705
Mode
Definition BufferObject:726
@ WRITE
Buffer is in write mode (.
Definition BufferObject:734
@ NONE
A normal mode of this data buffer.
Definition BufferObject:728
@ READ
Buffer is in read mode (.
Definition BufferObject:731
virtual void resizeGLObjectBuffers(unsigned int maxSize)
Resize any per context GLObject buffers to specified size.
unsigned int getDataSize() const
Get data size of the used buffer.
Definition BufferObject:708
virtual void compileBuffer(State &state) const
Compile the buffer (reallocate the memory if buffer is dirty)
PixelDataBufferObject(const PixelDataBufferObject &pbo, const CopyOp ©op=CopyOp::SHALLOW_COPY)
META_Object(osg, PixelDataBufferObject)
virtual void bindBufferInReadMode(State &state)
Bind the buffer in read mode, which means that data can be downloaded from the buffer (note: GL_PIXEL...
Mode getMode(unsigned int contextID) const
Definition BufferObject:737
virtual void unbindBuffer(unsigned int contextID) const
Unbind the buffer.
virtual void bindBufferInWriteMode(State &state)
Bind the buffer in write mode, which means following OpenGL instructions will write data into the buf...
ModeList _mode
Definition BufferObject:745
UniformBufferObject(const UniformBufferObject &ubo, const CopyOp ©op=CopyOp::SHALLOW_COPY)
virtual ~UniformBufferObject()
META_Object(osg, UniformBufferObject)
virtual ~AtomicCounterBufferObject()
META_Object(osg, AtomicCounterBufferObject)
AtomicCounterBufferObject(const AtomicCounterBufferObject &ubo, const CopyOp ©op=CopyOp::SHALLOW_COPY)
AtomicCounterBufferObject()
ShaderStorageBufferObject(const ShaderStorageBufferObject &ubo, const CopyOp ©op=CopyOp::SHALLOW_COPY)
META_Object(osg, ShaderStorageBufferObject)
ShaderStorageBufferObject()
virtual ~ShaderStorageBufferObject()
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Class which encapsulates the frame number, reference time and calendar time of specific frame,...
Definition FrameStamp:35
Main GLExtensions class for managing OpenGL extensions per graphics context.
Definition GLExtensions:160
GraphicsObjectManager(const std::string &name, unsigned int contextID)
Image class for encapsulating the storage texture image data.
Definition Image:179
Base class/standard interface for objects which require IO support, cloning and reference counting.
Definition Object:61
Object()
Construct an object.
Definition Object:69
Definition PrimitiveSet:125
Definition PrimitiveSet:337
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,...
Definition State:80
#define NULL
Definition Export:55
#define OSG_EXPORT
Definition Export:39