Added osg::BufferObject and a made a number associated to accomodate this

new class. osg::BufferObject wraps up OpenGL pixel and array buffer objects.
Currently implementation is work in progress.
This commit is contained in:
Robert Osfield
2005-02-09 10:39:45 +00:00
parent 1a9b5ddbbf
commit 117c791a3b
34 changed files with 1017 additions and 253 deletions

View File

@@ -56,13 +56,15 @@ class SG_EXPORT Array : public Object
Array(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0):
_arrayType(arrayType),
_dataSize(dataSize),
_dataType(dataType) {}
_dataType(dataType),
_modifiedCount(0) {}
Array(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Object(array,copyop),
_arrayType(array._arrayType),
_dataSize(array._dataSize),
_dataType(array._dataType) {}
_dataType(array._dataType),
_modifiedCount(0) {}
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Array*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
@@ -85,6 +87,15 @@ class SG_EXPORT Array : public Object
virtual unsigned int getTotalDataSize() const = 0;
virtual unsigned int getNumElements() const = 0;
/** Dirty the primitive, which increments the modified count, to force buffer objects to update. */
inline 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; }
protected:
virtual ~Array() {}
@@ -92,6 +103,7 @@ class SG_EXPORT Array : public Object
Type _arrayType;
GLint _dataSize;
GLenum _dataType;
unsigned int _modifiedCount;
};
template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>

259
include/osg/BufferObject Normal file
View File

@@ -0,0 +1,259 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
*
* 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.
*
* 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
#include <osg/State>
#include <osg/buffered_value>
#ifndef GL_ARB_vertex_buffer_object
#define GL_ARB_vertex_buffer_object
// for compatibility with gl.h headers that don't support VBO,
#if defined(_WIN64)
typedef __int64 GLintptrARB;
typedef __int64 GLsizeiptrARB;
#elif defined(__ia64__) || defined(__x86_64__)
typedef long int GLintptrARB;
typedef long int GLsizeiptrARB;
#else
typedef int GLintptrARB;
typedef int GLsizeiptrARB;
#endif
#define GL_ARRAY_BUFFER_ARB 0x8892
#define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893
#define GL_PIXEL_PACK_BUFFER_ARB 0x88EB
#define GL_PIXEL_UNPACK_BUFFER_ARB 0x88EC
#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_PIXEL_PACK_BUFFER_BINDING_ARB 0x88ED
#define GL_PIXEL_UNPACK_BUFFER_BINDING_ARB 0x88EF
#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
namespace osg
{
class SG_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"; }
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; }
mutable buffered_value<unsigned int> modifiedCount;
unsigned int dataSize;
unsigned int offset;
};
inline bool isBufferObjectSupported(unsigned int contextID) const { return getExtensions(contextID,true)->isBufferObjectSupported(); }
inline GLuint& buffer(unsigned int contextID) const { return _bufferObjectList[contextID]; }
inline void bindBuffer(unsigned int contextID) const
{
Extensions* extensions = getExtensions(contextID,true);
extensions->glBindBuffer(_target,_bufferObjectList[contextID]);
}
inline void unbindBuffer(unsigned int contextID) const
{
Extensions* extensions = getExtensions(contextID,true);
extensions->glBindBuffer(_target,0);
}
virtual bool needsCompile(unsigned int contextID) const = 0;
virtual void compileBuffer(State& state) const = 0;
void releaseBuffer(State* state) const;
/** Use deleteVertexBufferObject instead of glDeleteBuffers to allow
* OpenGL buffer objects to be cached until they can be deleted
* by the OpenGL context in which they were created, specified
* by contextID.*/
static void deleteBufferObject(unsigned int contextID,GLuint globj);
/** flush all the cached display list which need to be deleted
* in the OpenGL context related to contextID.*/
void BufferObject::flushDeletedBufferObjects(unsigned int contextID,double /*currentTime*/, double& availableTime);
/** 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.*/
class SG_EXPORT Extensions : public osg::Referenced
{
public:
Extensions();
Extensions(const Extensions& rhs);
void lowestCommonDenominator(const Extensions& rhs);
void setupGLExtenions();
bool isBufferObjectSupported() const { return _glGenBuffers!=0; }
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;
protected:
typedef void (APIENTRY * GenBuffersProc) (GLsizei n, GLuint *buffers);
typedef void (APIENTRY * BindBufferProc) (GLenum target, GLuint buffer);
typedef void (APIENTRY * BufferDataProc) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage);
typedef void (APIENTRY * BufferSubDataProc) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data);
typedef void (APIENTRY * DeleteBuffersProc) (GLsizei n, const GLuint *buffers);
typedef GLboolean (APIENTRY * IsBufferProc) (GLuint buffer);
typedef void (APIENTRY * GetBufferSubDataProc) (GLenum target, GLintptrARB offset, GLsizeiptrARB size, GLvoid *data);
typedef GLvoid* (APIENTRY * MapBufferProc) (GLenum target, GLenum access);
typedef GLboolean (APIENTRY * UnmapBufferProc) (GLenum target);
typedef void (APIENTRY * GetBufferParameterivProc) (GLenum target, GLenum pname, GLint *params);
typedef void (APIENTRY * GetBufferPointervProc) (GLenum target, GLenum pname, GLvoid* *params);
GenBuffersProc _glGenBuffers;
BindBufferProc _glBindBuffer;
BufferDataProc _glBufferData;
BufferSubDataProc _glBufferSubData;
DeleteBuffersProc _glDeleteBuffers;
IsBufferProc _glIsBuffer;
GetBufferSubDataProc _glGetBufferSubData;
MapBufferProc _glMapBuffer;
UnmapBufferProc _glUnmapBuffer;
GetBufferParameterivProc _glGetBufferParameteriv;
GetBufferPointervProc _glGetBufferPointerv;
};
/** Function to call to get the extension of a specified context.
* If the Exentsion object for that context has not yet been created
* and the 'createIfNotInitalized' flag been set to false then returns NULL.
* If 'createIfNotInitalized' is true then the Extensions object is
* 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);
protected:
virtual ~BufferObject();
unsigned int computeRequiredTotalSize() const;
typedef osg::buffered_value<GLuint> GLObjectList;
typedef std::pair< BufferEntry, ref_ptr<Array> > BufferEntryArrayPair;
typedef std::pair< BufferEntry, ref_ptr<PrimitiveSet> > BufferEntryPrimitiveSetPair;
mutable GLObjectList _bufferObjectList;
GLenum _target;
GLenum _usage;
mutable unsigned int _totalSize;
};
class Image;
class SG_EXPORT PixelBufferObject : public BufferObject
{
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);
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 bool needsCompile(unsigned int contextID) const;
virtual void compileBuffer(State& state) const;
protected:
virtual ~PixelBufferObject();
unsigned int computeRequiredTotalSize() const;
BufferEntryImagePair _bufferEntryImagePair;
};
}
#endif

View File

@@ -15,58 +15,11 @@
#define OSG_DRAWABLE 1
#include <osg/BoundingBox>
#include <osg/State>
#include <osg/NodeVisitor>
#include <osg/Shape>
#include <osg/buffered_value>
#include <osg/BufferObject>
#include <osg/PrimitiveSet>
#ifndef GL_ARB_vertex_buffer_object
// for compatibility with gl.h headers that don't support VBO,
#if defined(_WIN64)
typedef __int64 GLintptrARB;
typedef __int64 GLsizeiptrARB;
#elif defined(__ia64__) || defined(__x86_64__)
typedef long int GLintptrARB;
typedef long int GLsizeiptrARB;
#else
typedef int GLintptrARB;
typedef int GLsizeiptrARB;
#endif
#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
#ifndef GL_NV_occlusion_query
@@ -395,7 +348,7 @@ class SG_EXPORT Drawable : public Object
* in the OpenGL context related to contextID.*/
static void flushDeletedDisplayLists(unsigned int contextID,double& availableTime);
/** Use deleteVertexBufferObject instead of glDeleteList to allow
/** Use deleteVertexBufferObject instead of glDeleteBuffers to allow
* OpenGL buffer objects to be cached until they can be deleted
* by the OpenGL context in which they were created, specified
* by contextID.*/
@@ -490,50 +443,6 @@ class SG_EXPORT Drawable : public Object
virtual void accept(ConstAttributeFunctor&) const {}
class PrimitiveFunctor
{
public:
virtual ~PrimitiveFunctor() {}
virtual void setVertexArray(unsigned int count,const Vec2* vertices) = 0;
virtual void setVertexArray(unsigned int count,const Vec3* vertices) = 0;
virtual void setVertexArray(unsigned int count,const Vec4* vertices) = 0;
virtual void drawArrays(GLenum mode,GLint first,GLsizei count) = 0;
virtual void drawElements(GLenum mode,GLsizei count,const GLubyte* indices) = 0;
virtual void drawElements(GLenum mode,GLsizei count,const GLushort* indices) = 0;
virtual void drawElements(GLenum mode,GLsizei count,const GLuint* indices) = 0;
virtual void begin(GLenum mode) = 0;
virtual void vertex(const Vec2& vert) = 0;
virtual void vertex(const Vec3& vert) = 0;
virtual void vertex(const Vec4& vert) = 0;
virtual void vertex(float x,float y) = 0;
virtual void vertex(float x,float y,float z) = 0;
virtual void vertex(float x,float y,float z,float w) = 0;
virtual void end() = 0;
};
class PrimitiveIndexFunctor
{
public:
virtual ~PrimitiveIndexFunctor() {}
virtual void setVertexArray(unsigned int count,const Vec2* vertices) = 0;
virtual void setVertexArray(unsigned int count,const Vec3* vertices) = 0;
virtual void setVertexArray(unsigned int count,const Vec4* vertices) = 0;
virtual void drawArrays(GLenum mode,GLint first,GLsizei count) = 0;
virtual void drawElements(GLenum mode,GLsizei count,const GLubyte* indices) = 0;
virtual void drawElements(GLenum mode,GLsizei count,const GLushort* indices) = 0;
virtual void drawElements(GLenum mode,GLsizei count,const GLuint* indices) = 0;
virtual void begin(GLenum mode) = 0;
virtual void vertex(unsigned int pos) = 0;
virtual void end() = 0;
};
/** Return true if the Drawable subclass supports accept(PrimitiveFunctor&).*/
virtual bool supports(PrimitiveFunctor&) const { return false; }

View File

@@ -14,8 +14,7 @@
#ifndef OSG_IMAGE
#define OSG_IMAGE 1
#include <osg/Object>
#include <osg/GL>
#include <osg/BufferObject>
#include <string>
#include <vector>
@@ -72,7 +71,6 @@ class SG_EXPORT Image : public Object
void setFileName(const std::string& fileName);
inline const std::string& getFileName() const { return _fileName; }
enum AllocationMode {
NO_DELETE,
USE_NEW_DELETE,
@@ -134,9 +132,6 @@ class SG_EXPORT Image : public Object
void copySubImage(int s_offset,int t_offset,int r_offset,osg::Image* source);
/** Width of image. */
inline int s() const { return _s; }
@@ -190,6 +185,7 @@ class SG_EXPORT Image : public Object
return _data+(column*getPixelSizeInBits())/8+row*getRowSizeInBytes()+image*getImageSizeInBytes();
}
/** Flip the image horizontally. */
void flipHorizontal();
@@ -204,14 +200,14 @@ class SG_EXPORT Image : public Object
*/
void ensureValidSizeForTexturing(GLint maxTextureSize);
/** Dirty the image, which increments the modified flag, to force osg::Texture to reload the image. */
inline void dirty() { ++_modifiedTag; }
/** Dirty the image, which increments the modified count, to force osg::Texture to reload the image. */
inline void dirty() { ++_modifiedCount; }
/** Set the modified tag value. Only used by osg::Texture when using texture subloading. */
inline void setModifiedTag(unsigned int value) { _modifiedTag=value; }
/** Set the modified count value. Used by osg::Texture when using texture subloading. */
inline void setModifiedCount(unsigned int value) { _modifiedCount=value; }
/** Get modified tag value. Only used by osg::Texture when using texture subloading. */
inline unsigned int getModifiedTag() const { return _modifiedTag; }
/** Get modified count value. Used by osg::Texture when using texture subloading. */
inline unsigned int getModifiedCount() const { return _modifiedCount; }
static bool isPackedType(GLenum type);
@@ -257,6 +253,15 @@ class SG_EXPORT Image : public Object
/** Return true if this image is translucent - i.e. it has alpha values that are less 1.0 (when normalized). */
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); }
/** Get the PixelBufferObject.*/
PixelBufferObject* getPixelBufferObject() { return _bufferObject.get(); }
/** Get the const PixelBufferObject.*/
const PixelBufferObject* getPixelBufferObject() const { return _bufferObject.get(); }
protected :
virtual ~Image();
@@ -278,9 +283,11 @@ class SG_EXPORT Image : public Object
void setData(unsigned char *data,AllocationMode allocationMode);
unsigned int _modifiedTag;
unsigned int _modifiedCount;
MipmapDataType _mipmapData;
ref_ptr<PixelBufferObject> _bufferObject;
};
class Geode;

View File

@@ -14,10 +14,63 @@
#ifndef OSG_PRIMITIVESET
#define OSG_PRIMITIVESET 1
#include <osg/Drawable>
#include <osg/GL>
#include <osg/Object>
#include <osg/buffered_value>
#include <osg/Vec2>
#include <osg/Vec3>
#include <osg/Vec4>
#include <vector>
namespace osg {
class State;
class PrimitiveFunctor
{
public:
virtual ~PrimitiveFunctor() {}
virtual void setVertexArray(unsigned int count,const Vec2* vertices) = 0;
virtual void setVertexArray(unsigned int count,const Vec3* vertices) = 0;
virtual void setVertexArray(unsigned int count,const Vec4* vertices) = 0;
virtual void drawArrays(GLenum mode,GLint first,GLsizei count) = 0;
virtual void drawElements(GLenum mode,GLsizei count,const GLubyte* indices) = 0;
virtual void drawElements(GLenum mode,GLsizei count,const GLushort* indices) = 0;
virtual void drawElements(GLenum mode,GLsizei count,const GLuint* indices) = 0;
virtual void begin(GLenum mode) = 0;
virtual void vertex(const Vec2& vert) = 0;
virtual void vertex(const Vec3& vert) = 0;
virtual void vertex(const Vec4& vert) = 0;
virtual void vertex(float x,float y) = 0;
virtual void vertex(float x,float y,float z) = 0;
virtual void vertex(float x,float y,float z,float w) = 0;
virtual void end() = 0;
};
class PrimitiveIndexFunctor
{
public:
virtual ~PrimitiveIndexFunctor() {}
virtual void setVertexArray(unsigned int count,const Vec2* vertices) = 0;
virtual void setVertexArray(unsigned int count,const Vec3* vertices) = 0;
virtual void setVertexArray(unsigned int count,const Vec4* vertices) = 0;
virtual void drawArrays(GLenum mode,GLint first,GLsizei count) = 0;
virtual void drawElements(GLenum mode,GLsizei count,const GLubyte* indices) = 0;
virtual void drawElements(GLenum mode,GLsizei count,const GLushort* indices) = 0;
virtual void drawElements(GLenum mode,GLsizei count,const GLuint* indices) = 0;
virtual void begin(GLenum mode) = 0;
virtual void vertex(unsigned int pos) = 0;
virtual void end() = 0;
};
#ifndef _MSC_VER
typedef std::vector<GLsizei> VectorSizei;
@@ -114,26 +167,31 @@ class PrimitiveSet : public Object
PrimitiveSet(Type primType=PrimitiveType,GLenum mode=0):
_primitiveType(primType),
_mode(mode) {}
_mode(mode),
_modifiedCount(0) {}
PrimitiveSet(const PrimitiveSet& prim,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Object(prim,copyop),
_primitiveType(prim._primitiveType),
_mode(prim._mode) {}
_mode(prim._mode),
_modifiedCount(0) {}
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const PrimitiveSet*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "PrimitiveSet"; }
Type getType() const { return _primitiveType; }
Type getType() const { return _primitiveType; }
virtual const GLvoid* getDataPointer() const { return 0; }
virtual unsigned int getTotalDataSize() const { return 0; }
virtual bool supportsBufferObject() const { return false; }
void setMode(GLenum mode) { _mode = mode; }
GLenum getMode() const { return _mode; }
virtual void draw(State& state, bool useVertexBufferObjects) const = 0;
virtual void accept(Drawable::PrimitiveFunctor& functor) const = 0;
virtual void accept(Drawable::PrimitiveIndexFunctor& functor) const = 0;
virtual void accept(PrimitiveFunctor& functor) const = 0;
virtual void accept(PrimitiveIndexFunctor& functor) const = 0;
virtual unsigned int index(unsigned int pos) const = 0;
virtual unsigned int getNumIndices() const = 0;
@@ -157,12 +215,22 @@ class PrimitiveSet : public Object
return 0;
}
/** Dirty the primitive, which increments the modified count, to force buffer objects to update. */
inline 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; }
protected:
virtual ~PrimitiveSet() {}
Type _primitiveType;
GLenum _mode;
Type _primitiveType;
GLenum _mode;
unsigned int _modifiedCount;
};
class SG_EXPORT DrawArrays : public PrimitiveSet
@@ -206,8 +274,8 @@ class SG_EXPORT DrawArrays : public PrimitiveSet
virtual void draw(State& state, bool useVertexBufferObjects) const;
virtual void accept(Drawable::PrimitiveFunctor& functor) const;
virtual void accept(Drawable::PrimitiveIndexFunctor& functor) const;
virtual void accept(PrimitiveFunctor& functor) const;
virtual void accept(PrimitiveIndexFunctor& functor) const;
virtual unsigned int getNumIndices() const { return _count; }
virtual unsigned int index(unsigned int pos) const { return _first+pos; }
@@ -262,8 +330,8 @@ class SG_EXPORT DrawArrayLengths : public PrimitiveSet, public VectorSizei
virtual void draw(State& state, bool useVertexBufferObjects) const;
virtual void accept(Drawable::PrimitiveFunctor& functor) const;
virtual void accept(Drawable::PrimitiveIndexFunctor& functor) const;
virtual void accept(PrimitiveFunctor& functor) const;
virtual void accept(PrimitiveIndexFunctor& functor) const;
virtual unsigned int getNumIndices() const;
virtual unsigned int index(unsigned int pos) const { return _first+pos; }
@@ -319,10 +387,14 @@ class SG_EXPORT DrawElementsUByte : public PrimitiveSet, public VectorUByte
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "DrawElementsUByte"; }
virtual const GLvoid* getDataPointer() const { return empty()?0:&front(); }
virtual unsigned int getTotalDataSize() const { return size(); }
virtual bool supportsBufferObject() const { return false; }
virtual void draw(State& state, bool useVertexBufferObjects) const ;
virtual void accept(Drawable::PrimitiveFunctor& functor) const;
virtual void accept(Drawable::PrimitiveIndexFunctor& functor) const;
virtual void accept(PrimitiveFunctor& functor) const;
virtual void accept(PrimitiveIndexFunctor& functor) const;
virtual unsigned int getNumIndices() const { return size(); }
virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
@@ -367,10 +439,14 @@ class SG_EXPORT DrawElementsUShort : public PrimitiveSet, public VectorUShort
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "DrawElementsUShort"; }
virtual const GLvoid* getDataPointer() const { return empty()?0:&front(); }
virtual unsigned int getTotalDataSize() const { return 2*size(); }
virtual bool supportsBufferObject() const { return false; }
virtual void draw(State& state, bool useVertexBufferObjects) const;
virtual void accept(Drawable::PrimitiveFunctor& functor) const;
virtual void accept(Drawable::PrimitiveIndexFunctor& functor) const;
virtual void accept(PrimitiveFunctor& functor) const;
virtual void accept(PrimitiveIndexFunctor& functor) const;
virtual unsigned int getNumIndices() const { return size(); }
virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
@@ -414,10 +490,14 @@ class SG_EXPORT DrawElementsUInt : public PrimitiveSet, public VectorUInt
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "DrawElementsUInt"; }
virtual const GLvoid* getDataPointer() const { return empty()?0:&front(); }
virtual unsigned int getTotalDataSize() const { return 4*size(); }
virtual bool supportsBufferObject() const { return false; }
virtual void draw(State& state, bool useVertexBufferObjects) const;
virtual void accept(Drawable::PrimitiveFunctor& functor) const;
virtual void accept(Drawable::PrimitiveIndexFunctor& functor) const;
virtual void accept(PrimitiveFunctor& functor) const;
virtual void accept(PrimitiveIndexFunctor& functor) const;
virtual unsigned int getNumIndices() const { return size(); }
virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }

View File

@@ -53,10 +53,10 @@ class SG_EXPORT Texture1D : public Texture
/** Gets the const texture image. */
inline const Image* getImage() const { return _image.get(); }
inline unsigned int& getModifiedTag(unsigned int contextID) const
inline unsigned int& getModifiedCount(unsigned int contextID) const
{
// get the modified tag for the current contextID.
return _modifiedTag[contextID];
// get the modified count for the current contextID.
return _modifiedCount[contextID];
}
@@ -152,8 +152,8 @@ class SG_EXPORT Texture1D : public Texture
ref_ptr<SubloadCallback> _subloadCallback;
typedef buffered_value<unsigned int> ImageModifiedTag;
mutable ImageModifiedTag _modifiedTag;
typedef buffered_value<unsigned int> ImageModifiedCount;
mutable ImageModifiedCount _modifiedCount;
};

View File

@@ -53,10 +53,10 @@ class SG_EXPORT Texture2D : public Texture
/** Gets the const texture image. */
inline const Image* getImage() const { return _image.get(); }
inline unsigned int& getModifiedTag(unsigned int contextID) const
inline unsigned int& getModifiedCount(unsigned int contextID) const
{
// get the modified tag for the current contextID.
return _modifiedTag[contextID];
// get the modified count for the current contextID.
return _modifiedCount[contextID];
}
@@ -159,8 +159,8 @@ class SG_EXPORT Texture2D : public Texture
ref_ptr<SubloadCallback> _subloadCallback;
typedef buffered_value<unsigned int> ImageModifiedTag;
mutable ImageModifiedTag _modifiedTag;
typedef buffered_value<unsigned int> ImageModifiedCount;
mutable ImageModifiedCount _modifiedCount;
};

View File

@@ -51,10 +51,10 @@ class SG_EXPORT Texture3D : public Texture
/** Gets the const texture image. */
inline const Image* getImage() const { return _image.get(); }
inline unsigned int& getModifiedTag(unsigned int contextID) const
inline unsigned int& getModifiedCount(unsigned int contextID) const
{
// get the modified tag for the current contextID.
return _modifiedTag[contextID];
// get the modified count for the current contextID.
return _modifiedCount[contextID];
}
/** Sets the texture image, ignoring face. */
@@ -221,8 +221,8 @@ class SG_EXPORT Texture3D : public Texture
ref_ptr<SubloadCallback> _subloadCallback;
typedef buffered_value<unsigned int> ImageModifiedTag;
mutable ImageModifiedTag _modifiedTag;
typedef buffered_value<unsigned int> ImageModifiedCount;
mutable ImageModifiedCount _modifiedCount;
};

View File

@@ -65,10 +65,10 @@ class SG_EXPORT TextureCubeMap : public Texture
/** Get the number of images that can be assigned to the Texture. */
virtual unsigned int getNumImages() const { return 6; }
inline unsigned int& getModifiedTag(unsigned int face,unsigned int contextID) const
inline unsigned int& getModifiedCount(unsigned int face,unsigned int contextID) const
{
// get the modified tag for the current contextID.
return _modifiedTag[face][contextID];
// get the modified count for the current contextID.
return _modifiedCount[face][contextID];
}
/** Set the texture width and height. If width or height are zero then
@@ -176,8 +176,8 @@ class SG_EXPORT TextureCubeMap : public Texture
ref_ptr<SubloadCallback> _subloadCallback;
typedef buffered_value<unsigned int> ImageModifiedTag;
mutable ImageModifiedTag _modifiedTag[6];
typedef buffered_value<unsigned int> ImageModifiedCount;
mutable ImageModifiedCount _modifiedCount[6];
};
}

View File

@@ -59,10 +59,10 @@ class SG_EXPORT TextureRectangle : public Texture
/** Get the const texture image. */
inline const Image* getImage() const { return _image.get(); }
inline unsigned int& getModifiedTag(unsigned int contextID) const
inline unsigned int& getModifiedCount(unsigned int contextID) const
{
// get the modified tag for the current contextID.
return _modifiedTag[contextID];
// get the modified count for the current contextID.
return _modifiedCount[contextID];
}
@@ -133,8 +133,8 @@ class SG_EXPORT TextureRectangle : public Texture
ref_ptr<SubloadCallback> _subloadCallback;
typedef buffered_value<unsigned int> ImageModifiedTag;
mutable ImageModifiedTag _modifiedTag;
typedef buffered_value<unsigned int> ImageModifiedCount;
mutable ImageModifiedCount _modifiedCount;
};
}

View File

@@ -14,13 +14,13 @@
#ifndef OSG_TRIANGLEFUNCTOR
#define OSG_TRIANGLEFUNCTOR 1
#include <osg/Drawable>
#include <osg/PrimitiveSet>
#include <osg/Notify>
namespace osg {
template<class T>
class TriangleFunctor : public Drawable::PrimitiveFunctor, public T
class TriangleFunctor : public PrimitiveFunctor, public T
{
public:

View File

@@ -14,13 +14,13 @@
#ifndef OSG_TRIANGLEINDEXFUNCTOR
#define OSG_TRIANGLEINDEXFUNCTOR 1
#include <osg/Drawable>
#include <osg/PrimitiveSet>
#include <osg/Notify>
namespace osg {
template<class T>
class TriangleIndexFunctor : public Drawable::PrimitiveIndexFunctor, public T
class TriangleIndexFunctor : public PrimitiveIndexFunctor, public T
{
public:

View File

@@ -230,10 +230,10 @@ public:
virtual void accept(osg::Drawable::ConstAttributeFunctor& af) const;
/** return true, osgText::Text does support accept(PrimitiveFunctor&) .*/
virtual bool supports(osg::Drawable::PrimitiveFunctor&) const { return true; }
virtual bool supports(osg::PrimitiveFunctor&) const { return true; }
/** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/
virtual void accept(osg::Drawable::PrimitiveFunctor& pf) const;
virtual void accept(osg::PrimitiveFunctor& pf) const;
// make Font a friend to allow it set the _font to 0 if the font is

View File

@@ -14,7 +14,7 @@
#ifndef OSGUTIL_STATISTICS
#define OSGUTIL_STATISTICS 1
#include <osg/Referenced>
#include <osg/PrimitiveSet>
#include <osg/Drawable>
#include <map>
@@ -34,7 +34,7 @@ namespace osgUtil {
* each trifan or tristrip = (length-2) triangles and so on.
*/
class Statistics : public osg::Drawable::PrimitiveFunctor
class Statistics : public osg::PrimitiveFunctor
{
public: