From Pavel Moloshtan, added support for storing primitive sets in VBO's
This commit is contained in:
parent
342444d5bb
commit
888d9e2a25
@ -130,7 +130,7 @@ class PrimitiveSet : public Object
|
||||
void setMode(GLenum mode) { _mode = mode; }
|
||||
GLenum getMode() const { return _mode; }
|
||||
|
||||
virtual void draw() const = 0;
|
||||
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;
|
||||
@ -204,7 +204,7 @@ class SG_EXPORT DrawArrays : public PrimitiveSet
|
||||
void setCount(GLsizei count) { _count = count; }
|
||||
GLsizei getCount() const { return _count; }
|
||||
|
||||
virtual void draw() const;
|
||||
virtual void draw(State& state, bool useVertexBufferObjects) const;
|
||||
|
||||
virtual void accept(Drawable::PrimitiveFunctor& functor) const;
|
||||
virtual void accept(Drawable::PrimitiveIndexFunctor& functor) const;
|
||||
@ -260,7 +260,7 @@ class SG_EXPORT DrawArrayLengths : public PrimitiveSet, public VectorSizei
|
||||
void setFirst(GLint first) { _first = first; }
|
||||
GLint getFirst() const { return _first; }
|
||||
|
||||
virtual void draw() const;
|
||||
virtual void draw(State& state, bool useVertexBufferObjects) const;
|
||||
|
||||
virtual void accept(Drawable::PrimitiveFunctor& functor) const;
|
||||
virtual void accept(Drawable::PrimitiveIndexFunctor& functor) const;
|
||||
@ -319,7 +319,7 @@ class SG_EXPORT DrawElementsUByte : public PrimitiveSet, public VectorUByte
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
virtual const char* className() const { return "DrawElementsUByte"; }
|
||||
|
||||
virtual void draw() const ;
|
||||
virtual void draw(State& state, bool useVertexBufferObjects) const ;
|
||||
|
||||
virtual void accept(Drawable::PrimitiveFunctor& functor) const;
|
||||
virtual void accept(Drawable::PrimitiveIndexFunctor& functor) const;
|
||||
@ -330,6 +330,9 @@ class SG_EXPORT DrawElementsUByte : public PrimitiveSet, public VectorUByte
|
||||
|
||||
protected:
|
||||
|
||||
typedef osg::buffered_value<GLuint> GLObjectList;
|
||||
mutable GLObjectList _vboList;
|
||||
|
||||
virtual ~DrawElementsUByte() {}
|
||||
};
|
||||
|
||||
@ -364,7 +367,7 @@ class SG_EXPORT DrawElementsUShort : public PrimitiveSet, public VectorUShort
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
virtual const char* className() const { return "DrawElementsUShort"; }
|
||||
|
||||
virtual void draw() const;
|
||||
virtual void draw(State& state, bool useVertexBufferObjects) const;
|
||||
|
||||
virtual void accept(Drawable::PrimitiveFunctor& functor) const;
|
||||
virtual void accept(Drawable::PrimitiveIndexFunctor& functor) const;
|
||||
@ -375,6 +378,9 @@ class SG_EXPORT DrawElementsUShort : public PrimitiveSet, public VectorUShort
|
||||
|
||||
protected:
|
||||
|
||||
typedef osg::buffered_value<GLuint> GLObjectList;
|
||||
mutable GLObjectList _vboList;
|
||||
|
||||
virtual ~DrawElementsUShort() {}
|
||||
};
|
||||
|
||||
@ -408,7 +414,7 @@ class SG_EXPORT DrawElementsUInt : public PrimitiveSet, public VectorUInt
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
virtual const char* className() const { return "DrawElementsUInt"; }
|
||||
|
||||
virtual void draw() const;
|
||||
virtual void draw(State& state, bool useVertexBufferObjects) const;
|
||||
|
||||
virtual void accept(Drawable::PrimitiveFunctor& functor) const;
|
||||
virtual void accept(Drawable::PrimitiveIndexFunctor& functor) const;
|
||||
@ -419,6 +425,9 @@ class SG_EXPORT DrawElementsUInt : public PrimitiveSet, public VectorUInt
|
||||
|
||||
protected:
|
||||
|
||||
typedef osg::buffered_value<GLuint> GLObjectList;
|
||||
mutable GLObjectList _vboList;
|
||||
|
||||
virtual ~DrawElementsUInt() {}
|
||||
};
|
||||
|
||||
|
@ -354,6 +354,32 @@ class SG_EXPORT Quat
|
||||
As t goes from 0 to 1, the Quat object goes from "from" to "to". */
|
||||
void slerp ( value_type t, const Quat& from, const Quat& to);
|
||||
|
||||
/** Rotate a vector by this quaternion.*/
|
||||
Vec3f operator* (const Vec3f& v) const
|
||||
{
|
||||
// nVidia SDK implementation
|
||||
Vec3f uv, uuv;
|
||||
Vec3f qvec(_v[0], _v[1], _v[2]);
|
||||
uv = qvec ^ v;
|
||||
uuv = qvec ^ uv;
|
||||
uv *= ( 2.0f * _v[3] );
|
||||
uuv *= 2.0f;
|
||||
return v + uv + uuv;
|
||||
}
|
||||
|
||||
/** Rotate a vector by this quaternion.*/
|
||||
Vec3d operator* (const Vec3d& v) const
|
||||
{
|
||||
// nVidia SDK implementation
|
||||
Vec3d uv, uuv;
|
||||
Vec3d qvec(_v[0], _v[1], _v[2]);
|
||||
uv = qvec ^ v;
|
||||
uuv = qvec ^ uv;
|
||||
uv *= ( 2.0f * _v[3] );
|
||||
uuv *= 2.0f;
|
||||
return v + uv + uuv;
|
||||
}
|
||||
|
||||
friend inline std::ostream& operator << (std::ostream& output, const Quat& vec);
|
||||
|
||||
protected:
|
||||
|
@ -1148,7 +1148,7 @@ void Geometry::drawImplementation(State& state) const
|
||||
}
|
||||
}
|
||||
|
||||
(*itr)->draw();
|
||||
(*itr)->draw(state, usingVertexBufferObjects);
|
||||
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
using namespace osg;
|
||||
|
||||
void DrawArrays::draw() const
|
||||
void DrawArrays::draw(State&, bool) const
|
||||
{
|
||||
glDrawArrays(_mode,_first,_count);
|
||||
}
|
||||
@ -29,7 +29,7 @@ void DrawArrays::accept(Drawable::PrimitiveIndexFunctor& functor) const
|
||||
functor.drawArrays(_mode,_first,_count);
|
||||
}
|
||||
|
||||
void DrawArrayLengths::draw() const
|
||||
void DrawArrayLengths::draw(State&, bool) const
|
||||
{
|
||||
GLint first = _first;
|
||||
for(VectorSizei::const_iterator itr=begin();
|
||||
@ -77,9 +77,31 @@ unsigned int DrawArrayLengths::getNumIndices() const
|
||||
return count;
|
||||
}
|
||||
|
||||
void DrawElementsUByte::draw() const
|
||||
void DrawElementsUByte::draw(State& state, bool useVertexBufferObjects) const
|
||||
{
|
||||
glDrawElements(_mode,size(),GL_UNSIGNED_BYTE,&front());
|
||||
if (useVertexBufferObjects)
|
||||
{
|
||||
const Drawable::Extensions* extensions = Drawable::getExtensions(state.getContextID(), true);
|
||||
|
||||
GLuint& buffer = _vboList[state.getContextID()];
|
||||
if (!buffer)
|
||||
{
|
||||
extensions->glGenBuffers(1, &buffer);
|
||||
extensions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, buffer);
|
||||
extensions->glBufferData(GL_ELEMENT_ARRAY_BUFFER_ARB, size() * sizeof(GL_UNSIGNED_BYTE), &front(), GL_STATIC_DRAW_ARB);
|
||||
}
|
||||
else
|
||||
{
|
||||
extensions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, buffer);
|
||||
}
|
||||
|
||||
glDrawElements(_mode, size(), GL_UNSIGNED_BYTE, 0);
|
||||
extensions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDrawElements(_mode, size(), GL_UNSIGNED_BYTE, &front());
|
||||
}
|
||||
}
|
||||
|
||||
void DrawElementsUByte::accept(Drawable::PrimitiveFunctor& functor) const
|
||||
@ -103,9 +125,31 @@ void DrawElementsUByte::offsetIndices(int offset)
|
||||
}
|
||||
|
||||
|
||||
void DrawElementsUShort::draw() const
|
||||
void DrawElementsUShort::draw(State& state, bool useVertexBufferObjects) const
|
||||
{
|
||||
glDrawElements(_mode,size(),GL_UNSIGNED_SHORT,&front());
|
||||
if (useVertexBufferObjects)
|
||||
{
|
||||
const Drawable::Extensions* extensions = Drawable::getExtensions(state.getContextID(), true);
|
||||
|
||||
GLuint& buffer = _vboList[state.getContextID()];
|
||||
if (!buffer)
|
||||
{
|
||||
extensions->glGenBuffers(1, &buffer);
|
||||
extensions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, buffer);
|
||||
extensions->glBufferData(GL_ELEMENT_ARRAY_BUFFER_ARB, size() * sizeof(GL_UNSIGNED_SHORT), &front(), GL_STATIC_DRAW_ARB);
|
||||
}
|
||||
else
|
||||
{
|
||||
extensions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, buffer);
|
||||
}
|
||||
|
||||
glDrawElements(_mode, size(), GL_UNSIGNED_SHORT, 0);
|
||||
extensions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDrawElements(_mode, size(), GL_UNSIGNED_SHORT, &front());
|
||||
}
|
||||
}
|
||||
|
||||
void DrawElementsUShort::accept(Drawable::PrimitiveFunctor& functor) const
|
||||
@ -129,9 +173,31 @@ void DrawElementsUShort::offsetIndices(int offset)
|
||||
}
|
||||
|
||||
|
||||
void DrawElementsUInt::draw() const
|
||||
void DrawElementsUInt::draw(State& state, bool useVertexBufferObjects) const
|
||||
{
|
||||
glDrawElements(_mode,size(),GL_UNSIGNED_INT,&front());
|
||||
if (useVertexBufferObjects)
|
||||
{
|
||||
const Drawable::Extensions* extensions = Drawable::getExtensions(state.getContextID(), true);
|
||||
|
||||
GLuint& buffer = _vboList[state.getContextID()];
|
||||
if (!buffer)
|
||||
{
|
||||
extensions->glGenBuffers(1, &buffer);
|
||||
extensions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, buffer);
|
||||
extensions->glBufferData(GL_ELEMENT_ARRAY_BUFFER_ARB, size() * sizeof(GL_UNSIGNED_INT), &front(), GL_STATIC_DRAW_ARB);
|
||||
}
|
||||
else
|
||||
{
|
||||
extensions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, buffer);
|
||||
}
|
||||
|
||||
glDrawElements(_mode, size(), GL_UNSIGNED_INT, 0);
|
||||
extensions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDrawElements(_mode, size(), GL_UNSIGNED_INT, &front());
|
||||
}
|
||||
}
|
||||
|
||||
void DrawElementsUInt::accept(Drawable::PrimitiveFunctor& functor) const
|
||||
|
Loading…
Reference in New Issue
Block a user