2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2012-03-29 17:43:12 +08:00
|
|
|
* Copyright (C) 2012 David Callu
|
2005-02-09 18:39:45 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2005-02-09 18:39:45 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSG_BUFFEROBJECT
|
|
|
|
#define OSG_BUFFEROBJECT 1
|
|
|
|
|
2005-04-11 23:17:24 +08:00
|
|
|
#include <osg/GL>
|
|
|
|
#include <osg/Object>
|
2005-02-09 18:39:45 +08:00
|
|
|
#include <osg/buffered_value>
|
2009-10-03 17:25:23 +08:00
|
|
|
#include <osg/FrameStamp>
|
|
|
|
|
2011-01-25 05:12:25 +08:00
|
|
|
#include <iosfwd>
|
2009-10-03 17:25:23 +08:00
|
|
|
#include <list>
|
|
|
|
#include <map>
|
2005-02-09 18:39:45 +08:00
|
|
|
|
2011-09-13 00:17:33 +08:00
|
|
|
// identify GLES 1.1
|
|
|
|
#if (defined(GL_VERSION_ES_CM_1_0) && GL_VERSION_ES_CM_1_0 > 0) || \
|
|
|
|
(defined(GL_VERSION_ES_CM_1_1) && GL_VERSION_ES_CM_1_1 > 0)
|
2005-02-09 18:39:45 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
#define OPENGLES_1_1_FOUND 1
|
2011-09-13 00:17:33 +08:00
|
|
|
|
|
|
|
#endif
|
2005-02-09 18:39:45 +08:00
|
|
|
|
2011-09-13 00:17:33 +08:00
|
|
|
// for compatibility with gl.h headers that don't support VBO,
|
|
|
|
//GL_VERSION_1_5 and GL_ARB_vertex_buffer_object provide these types for OpenGL
|
|
|
|
//all ES versions except GL_OES_VERSION_1_0 provide these types for OpenGL ES
|
|
|
|
#if !defined(GL_VERSION_1_5) && !defined(GL_ARB_vertex_buffer_object) \
|
|
|
|
&& !defined(GL_ES_VERSION_2_0) && !defined(OPENGLES_1_1_FOUND)
|
2005-02-09 18:39:45 +08:00
|
|
|
#if defined(_WIN64)
|
2011-09-13 00:17:33 +08:00
|
|
|
typedef __int64 GLintptr;
|
|
|
|
typedef __int64 GLsizeiptr;
|
2014-11-28 18:54:40 +08:00
|
|
|
#elif defined(__ia64__) || defined(__x86_64__) || defined(__ANDROID__)
|
2011-09-13 00:17:33 +08:00
|
|
|
typedef long int GLintptr;
|
|
|
|
typedef long int GLsizeiptr;
|
2005-02-09 18:39:45 +08:00
|
|
|
#else
|
2011-09-13 00:17:33 +08:00
|
|
|
typedef int GLintptr;
|
|
|
|
typedef int GLsizeiptr;
|
2005-02-09 18:39:45 +08:00
|
|
|
#endif
|
2011-09-13 00:17:33 +08:00
|
|
|
#endif
|
2005-02-09 18:39:45 +08:00
|
|
|
|
2011-09-13 00:17:33 +08:00
|
|
|
#ifndef GL_ARB_vertex_buffer_object
|
|
|
|
#define GL_ARB_vertex_buffer_object
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2011-09-13 00:17:33 +08:00
|
|
|
typedef GLintptr GLintptrARB;
|
|
|
|
typedef GLsizeiptr GLsizeiptrARB;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-02-09 18:39:45 +08:00
|
|
|
#define GL_ARRAY_BUFFER_ARB 0x8892
|
|
|
|
#define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893
|
|
|
|
#define GL_ARRAY_BUFFER_BINDING_ARB 0x8894
|
|
|
|
#define GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB 0x8895
|
|
|
|
#define GL_VERTEX_ARRAY_BUFFER_BINDING_ARB 0x8896
|
|
|
|
#define GL_NORMAL_ARRAY_BUFFER_BINDING_ARB 0x8897
|
|
|
|
#define GL_COLOR_ARRAY_BUFFER_BINDING_ARB 0x8898
|
|
|
|
#define GL_INDEX_ARRAY_BUFFER_BINDING_ARB 0x8899
|
|
|
|
#define GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB 0x889A
|
|
|
|
#define GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB 0x889B
|
|
|
|
#define GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB 0x889C
|
|
|
|
#define GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB 0x889D
|
|
|
|
#define GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB 0x889E
|
|
|
|
#define GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB 0x889F
|
|
|
|
#define GL_STREAM_DRAW_ARB 0x88E0
|
|
|
|
#define GL_STREAM_READ_ARB 0x88E1
|
|
|
|
#define GL_STREAM_COPY_ARB 0x88E2
|
|
|
|
#define GL_STATIC_DRAW_ARB 0x88E4
|
|
|
|
#define GL_STATIC_READ_ARB 0x88E5
|
|
|
|
#define GL_STATIC_COPY_ARB 0x88E6
|
|
|
|
#define GL_DYNAMIC_DRAW_ARB 0x88E8
|
|
|
|
#define GL_DYNAMIC_READ_ARB 0x88E9
|
|
|
|
#define GL_DYNAMIC_COPY_ARB 0x88EA
|
|
|
|
#define GL_READ_ONLY_ARB 0x88B8
|
|
|
|
#define GL_WRITE_ONLY_ARB 0x88B9
|
|
|
|
#define GL_READ_WRITE_ARB 0x88BA
|
|
|
|
#define GL_BUFFER_SIZE_ARB 0x8764
|
|
|
|
#define GL_BUFFER_USAGE_ARB 0x8765
|
|
|
|
#define GL_BUFFER_ACCESS_ARB 0x88BB
|
|
|
|
#define GL_BUFFER_MAPPED_ARB 0x88BC
|
|
|
|
#define GL_BUFFER_MAP_POINTER_ARB 0x88BD
|
|
|
|
#endif
|
|
|
|
|
2008-05-24 19:05:10 +08:00
|
|
|
#ifndef GL_VERSION_1_5
|
|
|
|
#define GL_STREAM_DRAW 0x88E0
|
|
|
|
#define GL_STREAM_READ 0x88E1
|
|
|
|
#define GL_STREAM_COPY 0x88E2
|
|
|
|
#define GL_STATIC_DRAW 0x88E4
|
|
|
|
#define GL_STATIC_READ 0x88E5
|
|
|
|
#define GL_STATIC_COPY 0x88E6
|
|
|
|
#define GL_DYNAMIC_DRAW 0x88E8
|
|
|
|
#define GL_DYNAMIC_READ 0x88E9
|
|
|
|
#define GL_DYNAMIC_COPY 0x88EA
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef GL_VERSION_2_1
|
|
|
|
#define GL_PIXEL_PACK_BUFFER 0x88EB
|
|
|
|
#define GL_PIXEL_UNPACK_BUFFER 0x88EC
|
|
|
|
#define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED
|
|
|
|
#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-02-11 04:14:22 +08:00
|
|
|
#ifndef GL_ARB_pixel_buffer_object
|
2008-05-24 19:05:10 +08:00
|
|
|
#define GL_PIXEL_PACK_BUFFER_ARB 0x88EB
|
|
|
|
#define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC
|
2005-02-11 04:14:22 +08:00
|
|
|
#define GL_PIXEL_PACK_BUFFER_BINDING_ARB 0x88ED
|
|
|
|
#define GL_PIXEL_UNPACK_BUFFER_BINDING_ARB 0x88EF
|
|
|
|
#endif
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
namespace osg
|
2005-02-09 18:39:45 +08:00
|
|
|
{
|
|
|
|
|
2005-04-11 23:17:24 +08:00
|
|
|
class State;
|
2009-10-02 04:19:42 +08:00
|
|
|
class BufferData;
|
|
|
|
class BufferObject;
|
2005-04-11 23:17:24 +08:00
|
|
|
|
2009-10-03 17:25:23 +08:00
|
|
|
class BufferObjectProfile
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BufferObjectProfile():
|
|
|
|
_target(0),
|
|
|
|
_usage(0),
|
|
|
|
_size(0) {}
|
|
|
|
|
|
|
|
BufferObjectProfile(GLenum target, GLenum usage, unsigned int size):
|
|
|
|
_target(target),
|
|
|
|
_usage(usage),
|
|
|
|
_size(size) {}
|
|
|
|
|
|
|
|
BufferObjectProfile(const BufferObjectProfile& bpo):
|
|
|
|
_target(bpo._target),
|
|
|
|
_usage(bpo._usage),
|
|
|
|
_size(bpo._size) {}
|
|
|
|
|
|
|
|
bool operator < (const BufferObjectProfile& rhs) const
|
|
|
|
{
|
|
|
|
if (_target < rhs._target) return true;
|
|
|
|
else if (_target > rhs._target) return false;
|
|
|
|
if (_usage < rhs._usage) return true;
|
|
|
|
else if (_usage > rhs._usage) return false;
|
|
|
|
return _size < rhs._size;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator == (const BufferObjectProfile& rhs) const
|
|
|
|
{
|
|
|
|
return (_target == rhs._target) &&
|
|
|
|
(_usage == rhs._usage) &&
|
|
|
|
(_size == rhs._size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setProfile(GLenum target, GLenum usage, unsigned int size)
|
|
|
|
{
|
|
|
|
_target = target;
|
|
|
|
_usage = usage;
|
|
|
|
_size = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
BufferObjectProfile& operator = (const BufferObjectProfile& rhs)
|
|
|
|
{
|
|
|
|
_target = rhs._target;
|
|
|
|
_usage = rhs._usage;
|
|
|
|
_size = rhs._size;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLenum _target;
|
|
|
|
GLenum _usage;
|
|
|
|
GLenum _size;
|
|
|
|
};
|
|
|
|
|
|
|
|
// forward declare
|
|
|
|
class GLBufferObjectSet;
|
|
|
|
class GLBufferObjectManager;
|
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
class OSG_EXPORT GLBufferObject : public Referenced
|
2005-02-09 18:39:45 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2010-01-14 02:46:52 +08:00
|
|
|
GLBufferObject(unsigned int contextID, BufferObject* bufferObject, unsigned int glObjectID=0);
|
2005-02-09 18:39:45 +08:00
|
|
|
|
2009-10-03 17:25:23 +08:00
|
|
|
void setProfile(const BufferObjectProfile& profile) { _profile = profile; }
|
|
|
|
const BufferObjectProfile& getProfile() const { return _profile; }
|
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
void setBufferObject(BufferObject* bufferObject);
|
|
|
|
BufferObject* getBufferObject() { return _bufferObject; }
|
2007-06-30 22:30:44 +08:00
|
|
|
|
2005-02-09 18:39:45 +08:00
|
|
|
struct BufferEntry
|
|
|
|
{
|
2013-06-28 00:44:32 +08:00
|
|
|
BufferEntry(): numRead(0), modifiedCount(0),dataSize(0),offset(0),dataSource(0) {}
|
2009-10-02 04:19:42 +08:00
|
|
|
|
|
|
|
BufferEntry(const BufferEntry& rhs):
|
2013-06-28 00:44:32 +08:00
|
|
|
numRead(rhs.numRead),
|
2009-10-02 04:19:42 +08:00
|
|
|
modifiedCount(rhs.modifiedCount),
|
|
|
|
dataSize(rhs.dataSize),
|
|
|
|
offset(rhs.offset),
|
|
|
|
dataSource(rhs.dataSource) {}
|
|
|
|
|
|
|
|
BufferEntry& operator = (const BufferEntry& rhs)
|
|
|
|
{
|
|
|
|
if (&rhs==this) return *this;
|
2013-06-28 00:44:32 +08:00
|
|
|
numRead = rhs.numRead;
|
2009-10-02 04:19:42 +08:00
|
|
|
modifiedCount = rhs.modifiedCount;
|
|
|
|
dataSize = rhs.dataSize;
|
|
|
|
offset = rhs.offset;
|
|
|
|
dataSource = rhs.dataSource;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-06-28 00:44:32 +08:00
|
|
|
unsigned int getNumClients() const;
|
|
|
|
|
|
|
|
unsigned int numRead;
|
2009-10-02 04:19:42 +08:00
|
|
|
unsigned int modifiedCount;
|
2009-10-07 17:39:45 +08:00
|
|
|
unsigned int dataSize;
|
|
|
|
unsigned int offset;
|
2009-10-02 04:19:42 +08:00
|
|
|
BufferData* dataSource;
|
2005-02-09 18:39:45 +08:00
|
|
|
};
|
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
inline unsigned int getContextID() const { return _contextID; }
|
2005-02-09 18:39:45 +08:00
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
inline GLuint& getGLObjectID() { return _glObjectID; }
|
|
|
|
inline GLuint getGLObjectID() const { return _glObjectID; }
|
|
|
|
inline GLsizeiptrARB getOffset(unsigned int i) const { return _bufferEntries[i].offset; }
|
|
|
|
|
2009-11-27 19:43:18 +08:00
|
|
|
inline void bindBuffer();
|
2005-02-09 18:39:45 +08:00
|
|
|
|
2009-10-03 17:25:23 +08:00
|
|
|
inline void unbindBuffer()
|
2012-03-22 01:36:20 +08:00
|
|
|
{
|
2009-10-03 17:25:23 +08:00
|
|
|
_extensions->glBindBuffer(_profile._target,0);
|
2005-02-09 18:39:45 +08:00
|
|
|
}
|
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
inline bool isDirty() const { return _dirty; }
|
2007-04-30 20:18:27 +08:00
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
void dirty() { _dirty = true; }
|
2007-04-30 20:18:27 +08:00
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
void clear();
|
2007-05-02 02:03:32 +08:00
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
void compileBuffer();
|
|
|
|
|
|
|
|
void deleteGLObject();
|
|
|
|
|
|
|
|
void assign(BufferObject* bufferObject);
|
|
|
|
|
|
|
|
bool isPBOSupported() const { return _extensions->isPBOSupported(); }
|
|
|
|
|
|
|
|
static GLBufferObject* createGLBufferObject(unsigned int contextID, const BufferObject* bufferObject);
|
2005-02-09 18:39:45 +08:00
|
|
|
|
2009-11-26 20:33:07 +08:00
|
|
|
static void deleteAllBufferObjects(unsigned int contextID);
|
|
|
|
static void discardAllBufferObjects(unsigned int contextID);
|
2009-10-03 17:25:23 +08:00
|
|
|
static void flushAllDeletedBufferObjects(unsigned int contextID);
|
|
|
|
static void discardAllDeletedBufferObjects(unsigned int contextID);
|
|
|
|
static void flushDeletedBufferObjects(unsigned int contextID,double currentTime, double& availbleTime);
|
|
|
|
static void releaseGLBufferObject(unsigned int contextID, GLBufferObject* to);
|
2008-01-08 21:24:29 +08:00
|
|
|
|
2005-02-09 18:39:45 +08:00
|
|
|
/** Extensions class which encapsulates the querying of extensions and
|
|
|
|
* associated function pointers, and provide convenience wrappers to
|
|
|
|
* check for the extensions or use the associated functions.*/
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT Extensions : public osg::Referenced
|
2005-02-09 18:39:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2005-04-26 21:15:27 +08:00
|
|
|
Extensions(unsigned int contextID);
|
2005-02-09 18:39:45 +08:00
|
|
|
|
|
|
|
Extensions(const Extensions& rhs);
|
|
|
|
|
|
|
|
void lowestCommonDenominator(const Extensions& rhs);
|
|
|
|
|
2007-06-28 04:36:16 +08:00
|
|
|
void setupGLExtensions(unsigned int contextID);
|
2005-02-09 18:39:45 +08:00
|
|
|
|
|
|
|
bool isBufferObjectSupported() const { return _glGenBuffers!=0; }
|
2006-08-25 16:48:16 +08:00
|
|
|
bool isPBOSupported() const { return _isPBOSupported; }
|
2010-11-30 01:43:27 +08:00
|
|
|
bool isUniformBufferObjectSupported() const { return _isUniformBufferObjectSupported; }
|
2013-05-22 20:49:46 +08:00
|
|
|
bool isTBOSupported() const { return _isTBOSupported; }
|
2005-02-09 18:39:45 +08:00
|
|
|
|
|
|
|
void glGenBuffers (GLsizei n, GLuint *buffers) const;
|
|
|
|
void glBindBuffer (GLenum target, GLuint buffer) const;
|
|
|
|
void glBufferData (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage) const;
|
|
|
|
void glBufferSubData (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data) const;
|
|
|
|
void glDeleteBuffers (GLsizei n, const GLuint *buffers) const;
|
|
|
|
GLboolean glIsBuffer (GLuint buffer) const;
|
|
|
|
void glGetBufferSubData (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data) const;
|
|
|
|
GLvoid* glMapBuffer (GLenum target, GLenum access) const;
|
|
|
|
GLboolean glUnmapBuffer (GLenum target) const;
|
|
|
|
void glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params) const;
|
|
|
|
void glGetBufferPointerv (GLenum target, GLenum pname, GLvoid* *params) const;
|
2010-11-30 01:43:27 +08:00
|
|
|
void glBindBufferRange (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
|
|
|
|
void glBindBufferBase (GLenum target, GLuint index, GLuint buffer);
|
2013-05-22 20:49:46 +08:00
|
|
|
void glTexBuffer( GLenum target, GLenum internalFormat, GLuint buffer ) const;
|
2005-02-09 18:39:45 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2010-04-29 05:22:44 +08:00
|
|
|
typedef void (GL_APIENTRY * GenBuffersProc) (GLsizei n, GLuint *buffers);
|
|
|
|
typedef void (GL_APIENTRY * BindBufferProc) (GLenum target, GLuint buffer);
|
|
|
|
typedef void (GL_APIENTRY * BufferDataProc) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage);
|
|
|
|
typedef void (GL_APIENTRY * BufferSubDataProc) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data);
|
|
|
|
typedef void (GL_APIENTRY * DeleteBuffersProc) (GLsizei n, const GLuint *buffers);
|
|
|
|
typedef GLboolean (GL_APIENTRY * IsBufferProc) (GLuint buffer);
|
|
|
|
typedef void (GL_APIENTRY * GetBufferSubDataProc) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data);
|
|
|
|
typedef GLvoid* (GL_APIENTRY * MapBufferProc) (GLenum target, GLenum access);
|
|
|
|
typedef GLboolean (GL_APIENTRY * UnmapBufferProc) (GLenum target);
|
|
|
|
typedef void (GL_APIENTRY * GetBufferParameterivProc) (GLenum target, GLenum pname, GLint *params);
|
|
|
|
typedef void (GL_APIENTRY * GetBufferPointervProc) (GLenum target, GLenum pname, GLvoid* *params);
|
2010-11-30 01:43:27 +08:00
|
|
|
typedef void (GL_APIENTRY * BindBufferRangeProc) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size);
|
|
|
|
typedef void (GL_APIENTRY * BindBufferBaseProc) (GLenum target, GLuint index, GLuint buffer);
|
2013-05-22 20:49:46 +08:00
|
|
|
typedef void (GL_APIENTRY *TexBufferProc ) ( GLenum target, GLenum internalFormat, GLuint buffer );
|
2010-11-30 01:43:27 +08:00
|
|
|
|
2005-02-09 18:39:45 +08:00
|
|
|
|
|
|
|
GenBuffersProc _glGenBuffers;
|
|
|
|
BindBufferProc _glBindBuffer;
|
|
|
|
BufferDataProc _glBufferData;
|
|
|
|
BufferSubDataProc _glBufferSubData;
|
|
|
|
DeleteBuffersProc _glDeleteBuffers;
|
|
|
|
IsBufferProc _glIsBuffer;
|
|
|
|
GetBufferSubDataProc _glGetBufferSubData;
|
|
|
|
MapBufferProc _glMapBuffer;
|
|
|
|
UnmapBufferProc _glUnmapBuffer;
|
|
|
|
GetBufferParameterivProc _glGetBufferParameteriv;
|
|
|
|
GetBufferPointervProc _glGetBufferPointerv;
|
2010-11-30 01:43:27 +08:00
|
|
|
BindBufferRangeProc _glBindBufferRange;
|
|
|
|
BindBufferBaseProc _glBindBufferBase;
|
2013-05-22 20:49:46 +08:00
|
|
|
TexBufferProc _glTexBuffer;
|
2005-02-09 18:39:45 +08:00
|
|
|
|
2006-08-25 16:48:16 +08:00
|
|
|
bool _isPBOSupported;
|
2010-11-30 01:43:27 +08:00
|
|
|
bool _isUniformBufferObjectSupported;
|
2013-05-22 20:49:46 +08:00
|
|
|
bool _isTBOSupported;
|
2005-02-09 18:39:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Function to call to get the extension of a specified context.
|
2012-03-22 01:36:20 +08:00
|
|
|
* If the Extension object for that context has not yet been created
|
2005-02-09 18:39:45 +08:00
|
|
|
* and the 'createIfNotInitalized' flag been set to false then returns NULL.
|
2012-03-22 01:36:20 +08:00
|
|
|
* If 'createIfNotInitalized' is true then the Extensions object is
|
2005-02-09 18:39:45 +08:00
|
|
|
* automatically created. However, in this case the extension object is
|
|
|
|
* only created with the graphics context associated with ContextID..*/
|
|
|
|
static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized);
|
|
|
|
|
|
|
|
/** setExtensions allows users to override the extensions across graphics contexts.
|
|
|
|
* typically used when you have different extensions supported across graphics pipes
|
|
|
|
* but need to ensure that they all use the same low common denominator extensions.*/
|
|
|
|
static void setExtensions(unsigned int contextID,Extensions* extensions);
|
|
|
|
|
2013-06-28 00:44:32 +08:00
|
|
|
bool hasAllBufferDataBeenRead() const;
|
|
|
|
|
|
|
|
void setBufferDataHasBeenRead(const osg::BufferData* bd);
|
|
|
|
|
2005-02-09 18:39:45 +08:00
|
|
|
protected:
|
2009-11-26 20:33:07 +08:00
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
virtual ~GLBufferObject();
|
2005-02-09 18:39:45 +08:00
|
|
|
|
2011-06-14 18:15:12 +08:00
|
|
|
unsigned int computeBufferAlignment(unsigned int pos, unsigned int bufferAlignment) const
|
|
|
|
{
|
|
|
|
if (bufferAlignment<2) return pos;
|
|
|
|
if ((pos%bufferAlignment)==0) return pos;
|
|
|
|
return ((pos/bufferAlignment)+1)*bufferAlignment;
|
|
|
|
}
|
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
unsigned int _contextID;
|
|
|
|
GLuint _glObjectID;
|
2005-02-09 18:39:45 +08:00
|
|
|
|
2009-10-03 17:25:23 +08:00
|
|
|
BufferObjectProfile _profile;
|
|
|
|
unsigned int _allocatedSize;
|
2009-10-02 04:19:42 +08:00
|
|
|
|
|
|
|
bool _dirty;
|
|
|
|
|
|
|
|
typedef std::vector<BufferEntry> BufferEntries;
|
|
|
|
BufferEntries _bufferEntries;
|
|
|
|
|
|
|
|
BufferObject* _bufferObject;
|
|
|
|
|
2009-10-03 17:25:23 +08:00
|
|
|
public:
|
|
|
|
|
|
|
|
GLBufferObjectSet* _set;
|
|
|
|
GLBufferObject* _previous;
|
|
|
|
GLBufferObject* _next;
|
|
|
|
unsigned int _frameLastUsed;
|
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
public:
|
|
|
|
Extensions* _extensions;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2009-10-03 17:25:23 +08:00
|
|
|
typedef std::list< ref_ptr<GLBufferObject> > GLBufferObjectList;
|
|
|
|
|
|
|
|
class OSG_EXPORT GLBufferObjectSet : public Referenced
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GLBufferObjectSet(GLBufferObjectManager* parent, const BufferObjectProfile& profile);
|
|
|
|
|
2010-12-15 03:29:01 +08:00
|
|
|
const BufferObjectProfile& getProfile() const { return _profile; }
|
|
|
|
|
2009-10-03 17:25:23 +08:00
|
|
|
void handlePendingOrphandedGLBufferObjects();
|
2009-11-26 20:33:07 +08:00
|
|
|
|
|
|
|
void deleteAllGLBufferObjects();
|
|
|
|
void discardAllGLBufferObjects();
|
2009-10-03 17:25:23 +08:00
|
|
|
void flushAllDeletedGLBufferObjects();
|
|
|
|
void discardAllDeletedGLBufferObjects();
|
|
|
|
void flushDeletedGLBufferObjects(double currentTime, double& availableTime);
|
|
|
|
|
|
|
|
GLBufferObject* takeFromOrphans(BufferObject* bufferObject);
|
|
|
|
GLBufferObject* takeOrGenerate(BufferObject* bufferObject);
|
|
|
|
|
|
|
|
void moveToBack(GLBufferObject* to);
|
|
|
|
void addToBack(GLBufferObject* to);
|
|
|
|
void orphan(GLBufferObject* to);
|
|
|
|
void remove(GLBufferObject* to);
|
2009-10-06 21:42:12 +08:00
|
|
|
void moveToSet(GLBufferObject* to, GLBufferObjectSet* set);
|
2009-10-03 17:25:23 +08:00
|
|
|
|
|
|
|
unsigned int size() const { return _profile._size * _numOfGLBufferObjects; }
|
|
|
|
|
|
|
|
bool makeSpace(unsigned int& size);
|
|
|
|
|
|
|
|
bool checkConsistency() const;
|
|
|
|
|
|
|
|
GLBufferObjectManager* getParent() { return _parent; }
|
|
|
|
|
2010-12-15 03:29:01 +08:00
|
|
|
unsigned int computeNumGLBufferObjectsInList() const;
|
|
|
|
unsigned int getNumOfGLBufferObjects() const { return _numOfGLBufferObjects; }
|
2013-05-15 00:12:21 +08:00
|
|
|
unsigned int getNumOrphans() const { return static_cast<unsigned int>(_orphanedGLBufferObjects.size()); }
|
|
|
|
unsigned int getNumPendingOrphans() const { return static_cast<unsigned int>(_pendingOrphanedGLBufferObjects.size()); }
|
2010-12-15 03:29:01 +08:00
|
|
|
|
2009-10-03 17:25:23 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~GLBufferObjectSet();
|
|
|
|
|
|
|
|
OpenThreads::Mutex _mutex;
|
|
|
|
|
|
|
|
GLBufferObjectManager* _parent;
|
|
|
|
unsigned int _contextID;
|
|
|
|
BufferObjectProfile _profile;
|
|
|
|
unsigned int _numOfGLBufferObjects;
|
|
|
|
GLBufferObjectList _orphanedGLBufferObjects;
|
|
|
|
GLBufferObjectList _pendingOrphanedGLBufferObjects;
|
|
|
|
|
|
|
|
GLBufferObject* _head;
|
|
|
|
GLBufferObject* _tail;
|
|
|
|
};
|
|
|
|
|
|
|
|
class OSG_EXPORT GLBufferObjectManager : public osg::Referenced
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GLBufferObjectManager(unsigned int contextID);
|
|
|
|
|
|
|
|
unsigned int getContextID() const { return _contextID; }
|
|
|
|
|
|
|
|
|
|
|
|
void setNumberActiveGLBufferObjects(unsigned int size) { _numActiveGLBufferObjects = size; }
|
|
|
|
unsigned int& getNumberActiveGLBufferObjects() { return _numActiveGLBufferObjects; }
|
|
|
|
unsigned int getNumberActiveGLBufferObjects() const { return _numActiveGLBufferObjects; }
|
|
|
|
|
|
|
|
void setNumberOrphanedGLBufferObjects(unsigned int size) { _numOrphanedGLBufferObjects = size; }
|
|
|
|
unsigned int& getNumberOrphanedGLBufferObjects() { return _numOrphanedGLBufferObjects; }
|
|
|
|
unsigned int getNumberOrphanedGLBufferObjects() const { return _numOrphanedGLBufferObjects; }
|
|
|
|
|
|
|
|
void setCurrGLBufferObjectPoolSize(unsigned int size) { _currGLBufferObjectPoolSize = size; }
|
|
|
|
unsigned int& getCurrGLBufferObjectPoolSize() { return _currGLBufferObjectPoolSize; }
|
|
|
|
unsigned int getCurrGLBufferObjectPoolSize() const { return _currGLBufferObjectPoolSize; }
|
|
|
|
|
|
|
|
void setMaxGLBufferObjectPoolSize(unsigned int size);
|
|
|
|
unsigned int getMaxGLBufferObjectPoolSize() const { return _maxGLBufferObjectPoolSize; }
|
|
|
|
|
|
|
|
bool hasSpace(unsigned int size) const { return (_currGLBufferObjectPoolSize+size)<=_maxGLBufferObjectPoolSize; }
|
|
|
|
bool makeSpace(unsigned int size);
|
|
|
|
|
|
|
|
GLBufferObject* generateGLBufferObject(const osg::BufferObject* bufferObject);
|
|
|
|
|
|
|
|
void handlePendingOrphandedGLBufferObjects();
|
2009-11-26 20:33:07 +08:00
|
|
|
|
|
|
|
void deleteAllGLBufferObjects();
|
|
|
|
void discardAllGLBufferObjects();
|
2009-10-03 17:25:23 +08:00
|
|
|
void flushAllDeletedGLBufferObjects();
|
|
|
|
void discardAllDeletedGLBufferObjects();
|
|
|
|
void flushDeletedGLBufferObjects(double currentTime, double& availableTime);
|
|
|
|
void releaseGLBufferObject(GLBufferObject* to);
|
|
|
|
|
|
|
|
GLBufferObjectSet* getGLBufferObjectSet(const BufferObjectProfile& profile);
|
|
|
|
|
|
|
|
void newFrame(osg::FrameStamp* fs);
|
|
|
|
void resetStats();
|
2010-12-15 03:29:01 +08:00
|
|
|
void reportStats(std::ostream& out);
|
|
|
|
void recomputeStats(std::ostream& out);
|
2009-10-03 17:25:23 +08:00
|
|
|
|
|
|
|
unsigned int& getFrameNumber() { return _frameNumber; }
|
|
|
|
unsigned int& getNumberFrames() { return _numFrames; }
|
|
|
|
|
|
|
|
unsigned int& getNumberDeleted() { return _numDeleted; }
|
|
|
|
double& getDeleteTime() { return _deleteTime; }
|
|
|
|
|
|
|
|
unsigned int& getNumberGenerated() { return _numGenerated; }
|
|
|
|
double& getGenerateTime() { return _generateTime; }
|
|
|
|
|
|
|
|
unsigned int& getNumberApplied() { return _numApplied; }
|
|
|
|
double& getApplyTime() { return _applyTime; }
|
|
|
|
|
|
|
|
static osg::ref_ptr<GLBufferObjectManager>& getGLBufferObjectManager(unsigned int contextID);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
typedef std::map< BufferObjectProfile, osg::ref_ptr<GLBufferObjectSet> > GLBufferObjectSetMap;
|
|
|
|
unsigned int _contextID;
|
|
|
|
unsigned int _numActiveGLBufferObjects;
|
|
|
|
unsigned int _numOrphanedGLBufferObjects;
|
|
|
|
unsigned int _currGLBufferObjectPoolSize;
|
|
|
|
unsigned int _maxGLBufferObjectPoolSize;
|
|
|
|
GLBufferObjectSetMap _glBufferObjectSetMap;
|
|
|
|
|
|
|
|
unsigned int _frameNumber;
|
|
|
|
|
|
|
|
unsigned int _numFrames;
|
|
|
|
unsigned int _numDeleted;
|
|
|
|
double _deleteTime;
|
|
|
|
|
|
|
|
unsigned int _numGenerated;
|
|
|
|
double _generateTime;
|
|
|
|
|
|
|
|
unsigned int _numApplied;
|
|
|
|
double _applyTime;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
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"; }
|
|
|
|
|
2009-10-03 17:25:23 +08:00
|
|
|
void setTarget(GLenum target) { _profile._target = target; }
|
|
|
|
GLenum getTarget() const { return _profile._target; }
|
2009-10-02 04:19:42 +08:00
|
|
|
|
|
|
|
/** 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.
|
|
|
|
*/
|
2009-10-03 17:25:23 +08:00
|
|
|
void setUsage(GLenum usage) { _profile._usage = usage; }
|
2009-10-02 04:19:42 +08:00
|
|
|
|
|
|
|
/** Get the type of usage the buffer object has been set up for.*/
|
2009-10-03 17:25:23 +08:00
|
|
|
GLenum getUsage() const { return _profile._usage; }
|
|
|
|
|
|
|
|
BufferObjectProfile& getProfile() { return _profile; }
|
|
|
|
const BufferObjectProfile& getProfile() const { return _profile; }
|
2009-10-02 04:19:42 +08:00
|
|
|
|
2011-02-07 22:19:58 +08:00
|
|
|
|
|
|
|
/** Set whether the BufferObject should use a GLBufferObject just for copying the BufferData and release it immmediately so that it may be reused.*/
|
|
|
|
void setCopyDataAndReleaseGLBufferObject(bool copyAndRelease) { _copyDataAndReleaseGLBufferObject = copyAndRelease; }
|
|
|
|
|
|
|
|
/** Get whether the BufferObject should use a GLBufferObject just for copying the BufferData and release it immmediately.*/
|
|
|
|
bool getCopyDataAndReleaseGLBufferObject() const { return _copyDataAndReleaseGLBufferObject; }
|
|
|
|
|
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
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]; }
|
|
|
|
|
2013-05-15 00:12:21 +08:00
|
|
|
unsigned int getNumBufferData() const { return static_cast<unsigned int>(_bufferDataList.size()); }
|
2009-10-02 04:19:42 +08:00
|
|
|
|
2009-10-03 17:25:23 +08:00
|
|
|
void setGLBufferObject(unsigned int contextID, GLBufferObject* glbo) { _glBufferObjects[contextID] = glbo; }
|
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2009-10-03 17:25:23 +08:00
|
|
|
unsigned int computeRequiredBufferSize() const;
|
|
|
|
|
2010-01-14 02:46:52 +08:00
|
|
|
/** deprecated, provided for backwards compatibility.*/
|
|
|
|
static void deleteBufferObject(unsigned int contextID,GLuint globj);
|
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
~BufferObject();
|
|
|
|
|
|
|
|
typedef std::vector< BufferData* > BufferDataList;
|
|
|
|
typedef osg::buffered_object< osg::ref_ptr<GLBufferObject> > GLBufferObjects;
|
|
|
|
|
2009-10-03 17:25:23 +08:00
|
|
|
BufferObjectProfile _profile;
|
|
|
|
|
2011-02-07 22:19:58 +08:00
|
|
|
bool _copyDataAndReleaseGLBufferObject;
|
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
BufferDataList _bufferDataList;
|
|
|
|
|
|
|
|
mutable GLBufferObjects _glBufferObjects;
|
2005-02-09 18:39:45 +08:00
|
|
|
};
|
|
|
|
|
2009-10-04 16:52:01 +08:00
|
|
|
class OSG_EXPORT BufferData : public Object
|
2009-10-02 04:19:42 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
BufferData():
|
|
|
|
Object(true),
|
|
|
|
_modifiedCount(0),
|
2013-06-28 00:44:32 +08:00
|
|
|
_bufferIndex(0),
|
|
|
|
_numClients(0) {}
|
2009-10-02 04:19:42 +08:00
|
|
|
|
|
|
|
/** 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),
|
2010-04-14 02:42:58 +08:00
|
|
|
_bufferIndex(0),
|
2013-06-28 00:44:32 +08:00
|
|
|
_modifiedCallback(bd._modifiedCallback),
|
|
|
|
_numClients(0) {}
|
2009-10-02 04:19:42 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2012-01-24 22:34:02 +08:00
|
|
|
virtual osg::Array* asArray() { return 0; }
|
|
|
|
virtual const osg::Array* asArray() const { return 0; }
|
|
|
|
|
|
|
|
virtual osg::PrimitiveSet* asPrimitiveSet() { return 0; }
|
|
|
|
virtual const osg::PrimitiveSet* asPrimitiveSet() const { return 0; }
|
|
|
|
|
|
|
|
virtual osg::Image* asImage() { return 0; }
|
|
|
|
virtual const osg::Image* asImage() const { return 0; }
|
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
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; }
|
|
|
|
|
2010-04-14 02:42:58 +08:00
|
|
|
struct ModifiedCallback : public virtual osg::Object
|
|
|
|
{
|
|
|
|
ModifiedCallback() {}
|
|
|
|
|
|
|
|
ModifiedCallback(const ModifiedCallback&,const CopyOp&) {}
|
|
|
|
|
|
|
|
META_Object(osg,ModifiedCallback);
|
|
|
|
|
2010-05-01 03:41:24 +08:00
|
|
|
virtual void modified(BufferData* /*bufferData*/) const {}
|
2010-04-14 02:42:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void setModifiedCallback(ModifiedCallback* md) { _modifiedCallback = md; }
|
|
|
|
ModifiedCallback* getModifiedCallback() { return _modifiedCallback.get(); }
|
|
|
|
const ModifiedCallback* getModifiedCallback() const { return _modifiedCallback.get(); }
|
|
|
|
|
|
|
|
/** Dirty the primitive, which increments the modified count, to force buffer objects to update.
|
|
|
|
* If a ModifiedCallback is attached to this BufferData then the callback is called prior to the bufferObject's dirty is called. */
|
|
|
|
inline void dirty()
|
|
|
|
{
|
|
|
|
++_modifiedCount;
|
|
|
|
if (_modifiedCallback.valid()) _modifiedCallback->modified(this);
|
|
|
|
if (_bufferObject.valid()) _bufferObject->dirty();
|
|
|
|
}
|
2009-10-02 04:19:42 +08:00
|
|
|
|
|
|
|
/** Set the modified count value.*/
|
|
|
|
inline void setModifiedCount(unsigned int value) { _modifiedCount=value; }
|
|
|
|
|
|
|
|
/** Get modified count value.*/
|
|
|
|
inline unsigned int getModifiedCount() const { return _modifiedCount; }
|
|
|
|
|
2010-12-14 01:09:31 +08:00
|
|
|
/** 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;
|
|
|
|
|
2013-06-28 00:44:32 +08:00
|
|
|
unsigned int getNumClients() const { return _numClients; }
|
|
|
|
|
2013-06-28 20:00:43 +08:00
|
|
|
void addClient(osg::Object * /*client*/) { ++_numClients; }
|
2013-06-28 00:44:32 +08:00
|
|
|
|
2013-06-28 22:08:36 +08:00
|
|
|
void removeClient(osg::Object * /*client*/) { --_numClients; }
|
2013-06-28 00:44:32 +08:00
|
|
|
|
2010-12-14 01:09:31 +08:00
|
|
|
protected:
|
2009-10-02 04:19:42 +08:00
|
|
|
|
|
|
|
virtual ~BufferData();
|
|
|
|
|
|
|
|
unsigned int _modifiedCount;
|
|
|
|
|
|
|
|
unsigned int _bufferIndex;
|
|
|
|
osg::ref_ptr<BufferObject> _bufferObject;
|
2010-04-14 02:42:58 +08:00
|
|
|
osg::ref_ptr<ModifiedCallback> _modifiedCallback;
|
2013-06-28 00:44:32 +08:00
|
|
|
|
|
|
|
unsigned int _numClients;
|
2009-10-02 04:19:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-04-26 02:50:11 +08:00
|
|
|
class Array;
|
|
|
|
class OSG_EXPORT VertexBufferObject : public BufferObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
VertexBufferObject();
|
|
|
|
|
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
|
|
|
VertexBufferObject(const VertexBufferObject& vbo,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
|
|
|
|
|
|
|
META_Object(osg,VertexBufferObject);
|
|
|
|
|
|
|
|
unsigned int addArray(osg::Array* array);
|
2007-05-02 02:03:32 +08:00
|
|
|
void removeArray(osg::Array* array);
|
2007-04-26 02:50:11 +08:00
|
|
|
|
|
|
|
void setArray(unsigned int i, Array* array);
|
2009-10-02 04:19:42 +08:00
|
|
|
Array* getArray(unsigned int i);
|
|
|
|
const Array* getArray(unsigned int i) const;
|
2007-04-26 02:50:11 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~VertexBufferObject();
|
|
|
|
};
|
|
|
|
|
|
|
|
class DrawElements;
|
2007-05-01 14:28:20 +08:00
|
|
|
class OSG_EXPORT ElementBufferObject : public BufferObject
|
2007-04-26 02:50:11 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2007-05-01 14:28:20 +08:00
|
|
|
ElementBufferObject();
|
2007-04-26 02:50:11 +08:00
|
|
|
|
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
2007-05-01 14:28:20 +08:00
|
|
|
ElementBufferObject(const ElementBufferObject& pbo,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
2007-04-26 02:50:11 +08:00
|
|
|
|
2007-05-01 14:28:20 +08:00
|
|
|
META_Object(osg,ElementBufferObject);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-04-26 02:50:11 +08:00
|
|
|
unsigned int addDrawElements(osg::DrawElements* PrimitiveSet);
|
2007-05-02 02:03:32 +08:00
|
|
|
void removeDrawElements(osg::DrawElements* PrimitiveSet);
|
2007-04-26 02:50:11 +08:00
|
|
|
|
|
|
|
void setDrawElements(unsigned int i, DrawElements* PrimitiveSet);
|
2009-10-02 04:19:42 +08:00
|
|
|
DrawElements* getDrawElements(unsigned int i);
|
|
|
|
const DrawElements* getDrawElements(unsigned int i) const;
|
2007-04-26 02:50:11 +08:00
|
|
|
|
|
|
|
protected:
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-05-01 14:28:20 +08:00
|
|
|
virtual ~ElementBufferObject();
|
2007-04-26 02:50:11 +08:00
|
|
|
};
|
|
|
|
|
2005-02-09 18:39:45 +08:00
|
|
|
class Image;
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT PixelBufferObject : public BufferObject
|
2005-02-09 18:39:45 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
PixelBufferObject(osg::Image* image=0);
|
|
|
|
|
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
|
|
|
PixelBufferObject(const PixelBufferObject& pbo,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
|
|
|
|
|
|
|
META_Object(osg,PixelBufferObject);
|
|
|
|
|
|
|
|
void setImage(osg::Image* image);
|
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
Image* getImage();
|
|
|
|
const Image* getImage() const;
|
2005-02-09 18:39:45 +08:00
|
|
|
|
2009-10-02 04:19:42 +08:00
|
|
|
bool isPBOSupported(unsigned int contextID) const { return _glBufferObjects[contextID]->isPBOSupported(); }
|
2005-02-09 18:39:45 +08:00
|
|
|
|
|
|
|
protected:
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-02-09 18:39:45 +08:00
|
|
|
virtual ~PixelBufferObject();
|
|
|
|
};
|
|
|
|
|
2008-12-01 21:28:13 +08:00
|
|
|
/**
|
|
|
|
* This object represent a general class of pixel buffer objects,
|
|
|
|
* which are capable of allocating buffer object (memory)
|
|
|
|
* on the GPU. The memory can then be used either for CPU-GPU
|
|
|
|
* pixel transfer or directly for GPU-GPU transfer, without CPU intervention.
|
|
|
|
**/
|
|
|
|
class OSG_EXPORT PixelDataBufferObject : public BufferObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PixelDataBufferObject();
|
|
|
|
PixelDataBufferObject(const PixelDataBufferObject& pbo, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
|
|
|
|
|
|
|
META_Object(osg, PixelDataBufferObject);
|
|
|
|
|
|
|
|
//! Set new size of the buffer object. This will reallocate the memory on the next compile
|
2009-10-03 17:25:23 +08:00
|
|
|
inline void setDataSize(unsigned int size) { _profile._size = size; dirty(); }
|
2008-12-01 21:28:13 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
//! Get data size of the used buffer
|
2009-10-03 17:25:23 +08:00
|
|
|
inline unsigned int getDataSize() const { return _profile._size; }
|
2008-12-01 21:28:13 +08:00
|
|
|
|
|
|
|
//! Compile the buffer (reallocate the memory if buffer is dirty)
|
|
|
|
virtual void compileBuffer(State& state) const;
|
|
|
|
|
|
|
|
//! Bind the buffer in read mode, which means that data can be downloaded from the buffer (note: GL_PIXEL_UNPACK_BUFFER_ARB)
|
|
|
|
virtual void bindBufferInReadMode(State& state);
|
|
|
|
|
|
|
|
//! Bind the buffer in write mode, which means following OpenGL instructions will write data into the buffer (note: GL_PIXEL_PACK_BUFFER_ARB)
|
|
|
|
virtual void bindBufferInWriteMode(State& state);
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
//! Unbind the buffer
|
2008-12-01 21:28:13 +08:00
|
|
|
virtual void unbindBuffer(unsigned int contextID) const;
|
|
|
|
|
|
|
|
/** Resize any per context GLObject buffers to specified size. */
|
|
|
|
virtual void resizeGLObjectBuffers(unsigned int maxSize);
|
|
|
|
|
|
|
|
enum Mode
|
|
|
|
{
|
|
|
|
//! A normal mode of this data buffer
|
|
|
|
NONE = 0,
|
|
|
|
|
|
|
|
//! Buffer is in read mode (@see bindBufferInReadMode)
|
|
|
|
READ = 1,
|
|
|
|
|
|
|
|
//! Buffer is in write mode (@see bindBufferInWriteMode)
|
|
|
|
WRITE = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
Mode getMode(unsigned int contextID) const { return (Mode)_mode[contextID]; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~PixelDataBufferObject();
|
|
|
|
|
|
|
|
typedef osg::buffered_value<unsigned int> ModeList;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-12-01 21:28:13 +08:00
|
|
|
mutable ModeList _mode;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-12-01 21:28:13 +08:00
|
|
|
};
|
|
|
|
|
2010-11-30 01:43:27 +08:00
|
|
|
class OSG_EXPORT UniformBufferObject : public BufferObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UniformBufferObject();
|
|
|
|
UniformBufferObject(const UniformBufferObject& ubo, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
|
|
|
META_Object(osg, UniformBufferObject);
|
|
|
|
protected:
|
|
|
|
virtual ~UniformBufferObject();
|
|
|
|
};
|
|
|
|
|
2012-03-29 17:43:12 +08:00
|
|
|
class OSG_EXPORT AtomicCounterBufferObject : public BufferObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AtomicCounterBufferObject();
|
|
|
|
AtomicCounterBufferObject(const AtomicCounterBufferObject& ubo, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
|
|
|
META_Object(osg, AtomicCounterBufferObject);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~AtomicCounterBufferObject();
|
|
|
|
};
|
|
|
|
|
2009-11-27 19:43:18 +08:00
|
|
|
inline void GLBufferObject::bindBuffer()
|
|
|
|
{
|
|
|
|
_extensions->glBindBuffer(_profile._target,_glObjectID);
|
|
|
|
if (_set) _set->moveToBack(this);
|
|
|
|
}
|
2005-02-09 18:39:45 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|