Merge pull request #318 from mp3butcher/osganimation
change the design of BufferIndexBinding to work with BufferData instead of BufferObject +matrix transpose
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
* Copyright (C) 2010 Tim Moore
|
||||
* Copyright (C) 2012 David Callu
|
||||
* Copyright (C) 2017 Julien Valentin
|
||||
*
|
||||
* 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
|
||||
@@ -24,23 +25,25 @@
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
||||
BufferIndexBinding::BufferIndexBinding(GLenum target, GLuint index)
|
||||
: _target(target), _index(index), _offset(0), _size(0)
|
||||
:_target(target), _bufferData(0), _index(index), _offset(0), _size(0)
|
||||
{
|
||||
}
|
||||
|
||||
BufferIndexBinding::BufferIndexBinding(GLenum target, GLuint index, BufferObject* bo,
|
||||
BufferIndexBinding::BufferIndexBinding(GLenum target, GLuint index, BufferData* bo,
|
||||
GLintptr offset, GLsizeiptr size)
|
||||
: _target(target), _index(index), _bufferObject(bo), _offset(offset), _size(size)
|
||||
: _target(target), _index(index), _offset(offset), _size(size)
|
||||
{
|
||||
setBufferData(bo);
|
||||
}
|
||||
|
||||
BufferIndexBinding::BufferIndexBinding(const BufferIndexBinding& rhs, const CopyOp& copyop)
|
||||
: StateAttribute(rhs, copyop),
|
||||
_target(rhs._target), _index(rhs._index),
|
||||
_bufferObject(static_cast<BufferObject*>(copyop(rhs._bufferObject.get()))),
|
||||
_offset(rhs._offset),
|
||||
_size(rhs._size)
|
||||
BufferIndexBinding::BufferIndexBinding(const BufferIndexBinding& rhs, const CopyOp& copyop):StateAttribute(rhs,copyop),
|
||||
_target(rhs._target),
|
||||
_bufferData(static_cast<BufferData*>(copyop(rhs._bufferData.get()))),
|
||||
_index(rhs._index),
|
||||
_offset(rhs._offset),
|
||||
_size(rhs._size)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -59,15 +62,13 @@ void BufferIndexBinding::setIndex(unsigned int index)
|
||||
|
||||
void BufferIndexBinding::apply(State& state) const
|
||||
{
|
||||
if (_bufferObject.valid())
|
||||
if (_bufferData.valid())
|
||||
{
|
||||
GLBufferObject* glObject
|
||||
= _bufferObject->getOrCreateGLBufferObject(state.getContextID());
|
||||
if (!glObject->_extensions->isUniformBufferObjectSupported)
|
||||
return;
|
||||
= _bufferData->getBufferObject()->getOrCreateGLBufferObject(state.getContextID());
|
||||
if (glObject->isDirty()) glObject->compileBuffer();
|
||||
glObject->_extensions->glBindBufferRange(_target, _index,
|
||||
glObject->getGLObjectID(), _offset, _size);
|
||||
glObject->getGLObjectID(), glObject->getOffset(_bufferData->getBufferIndex())+_offset, _size-_offset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,30 +78,30 @@ UniformBufferBinding::UniformBufferBinding()
|
||||
}
|
||||
|
||||
UniformBufferBinding::UniformBufferBinding(GLuint index)
|
||||
: BufferIndexBinding(GL_UNIFORM_BUFFER, index)
|
||||
: BufferIndexBinding(GL_UNIFORM_BUFFER, index)
|
||||
{
|
||||
}
|
||||
|
||||
UniformBufferBinding::UniformBufferBinding(GLuint index, BufferObject* bo, GLintptr offset,
|
||||
GLsizeiptr size)
|
||||
UniformBufferBinding::UniformBufferBinding(GLuint index, BufferData* bo, GLintptr offset,
|
||||
GLsizeiptr size)
|
||||
: BufferIndexBinding(GL_UNIFORM_BUFFER, index, bo, offset, size)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
UniformBufferBinding::UniformBufferBinding(const UniformBufferBinding& rhs,
|
||||
const CopyOp& copyop)
|
||||
const CopyOp& copyop)
|
||||
: BufferIndexBinding(rhs, copyop)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TransformFeedbackBufferBinding::TransformFeedbackBufferBinding(GLuint index)
|
||||
: BufferIndexBinding(GL_TRANSFORM_FEEDBACK_BUFFER, index)
|
||||
: BufferIndexBinding(GL_TRANSFORM_FEEDBACK_BUFFER, index)
|
||||
{
|
||||
}
|
||||
|
||||
TransformFeedbackBufferBinding::TransformFeedbackBufferBinding(GLuint index, BufferObject* bo, GLintptr offset, GLsizeiptr size)
|
||||
TransformFeedbackBufferBinding::TransformFeedbackBufferBinding(GLuint index, BufferData* bo, GLintptr offset, GLsizeiptr size)
|
||||
: BufferIndexBinding(GL_TRANSFORM_FEEDBACK_BUFFER, index, bo, offset, size)
|
||||
{
|
||||
|
||||
@@ -113,11 +114,11 @@ TransformFeedbackBufferBinding::TransformFeedbackBufferBinding(const TransformFe
|
||||
|
||||
|
||||
AtomicCounterBufferBinding::AtomicCounterBufferBinding(GLuint index)
|
||||
: BufferIndexBinding(GL_ATOMIC_COUNTER_BUFFER, index)
|
||||
: BufferIndexBinding(GL_ATOMIC_COUNTER_BUFFER, index)
|
||||
{
|
||||
}
|
||||
|
||||
AtomicCounterBufferBinding::AtomicCounterBufferBinding(GLuint index, BufferObject* bo, GLintptr offset, GLsizeiptr size)
|
||||
AtomicCounterBufferBinding::AtomicCounterBufferBinding(GLuint index, BufferData* bo, GLintptr offset, GLsizeiptr size)
|
||||
: BufferIndexBinding(GL_ATOMIC_COUNTER_BUFFER, index, bo, offset, size)
|
||||
{
|
||||
|
||||
@@ -130,9 +131,9 @@ AtomicCounterBufferBinding::AtomicCounterBufferBinding(const AtomicCounterBuffer
|
||||
|
||||
void AtomicCounterBufferBinding::readData(osg::State & state, osg::UIntArray & uintArray) const
|
||||
{
|
||||
if (!_bufferObject) return;
|
||||
if (!_bufferData) return;
|
||||
|
||||
GLBufferObject* bo = _bufferObject->getOrCreateGLBufferObject( state.getContextID() );
|
||||
GLBufferObject* bo = _bufferData->getBufferObject()->getOrCreateGLBufferObject( state.getContextID() );
|
||||
if (!bo) return;
|
||||
|
||||
|
||||
@@ -143,7 +144,7 @@ void AtomicCounterBufferBinding::readData(osg::State & state, osg::UIntArray & u
|
||||
bo->_extensions->glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, bo->getGLObjectID());
|
||||
|
||||
GLubyte* src = (GLubyte*)bo->_extensions->glMapBuffer(GL_ATOMIC_COUNTER_BUFFER,
|
||||
GL_READ_ONLY_ARB);
|
||||
GL_READ_ONLY_ARB);
|
||||
if(src)
|
||||
{
|
||||
size_t size = osg::minimum<int>(_size, uintArray.getTotalDataSize());
|
||||
@@ -161,7 +162,7 @@ ShaderStorageBufferBinding::ShaderStorageBufferBinding(GLuint index)
|
||||
{
|
||||
}
|
||||
|
||||
ShaderStorageBufferBinding::ShaderStorageBufferBinding(GLuint index, BufferObject* bo, GLintptr offset, GLsizeiptr size)
|
||||
ShaderStorageBufferBinding::ShaderStorageBufferBinding(GLuint index, BufferData* bo, GLintptr offset, GLsizeiptr size)
|
||||
: BufferIndexBinding(GL_SHADER_STORAGE_BUFFER, index, bo, offset, size)
|
||||
{
|
||||
|
||||
@@ -173,26 +174,24 @@ ShaderStorageBufferBinding::ShaderStorageBufferBinding(const ShaderStorageBuffer
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
DrawIndirectBufferBinding::DrawIndirectBufferBinding( )
|
||||
: BufferIndexBinding(GL_DRAW_INDIRECT_BUFFER, 0)
|
||||
{
|
||||
}
|
||||
void DrawIndirectBufferBinding::apply(State& state) const
|
||||
{
|
||||
if (_bufferObject.valid())
|
||||
if (_bufferData.valid())
|
||||
{
|
||||
BufferObject * bo = _bufferData->getBufferObject();
|
||||
GLBufferObject* glObject
|
||||
= _bufferObject->getOrCreateGLBufferObject(state.getContextID());
|
||||
= bo->getOrCreateGLBufferObject(state.getContextID());
|
||||
if (!glObject->_extensions->isUniformBufferObjectSupported)
|
||||
return;
|
||||
// if (glObject->isDirty()) glObject->compileBuffer();
|
||||
if (glObject->isDirty()) glObject->compileBuffer();
|
||||
glObject->_extensions->glBindBuffer (_target, glObject->getGLObjectID());
|
||||
}
|
||||
}
|
||||
DrawIndirectBufferBinding::DrawIndirectBufferBinding( BufferObject* bo)
|
||||
DrawIndirectBufferBinding::DrawIndirectBufferBinding( BufferData* bo)
|
||||
: BufferIndexBinding(GL_DRAW_INDIRECT_BUFFER, 0, bo, 0, 0)
|
||||
{
|
||||
|
||||
|
||||
@@ -742,6 +742,41 @@ inline T SGL_ABS(T a)
|
||||
#define SGL_SWAP(a,b,temp) ((temp)=(a),(a)=(b),(b)=(temp))
|
||||
#endif
|
||||
|
||||
bool Matrix_implementation::transpose(const Matrix_implementation&mat){
|
||||
if (&mat==this) {
|
||||
Matrix_implementation tm(mat);
|
||||
return transpose(tm);
|
||||
}
|
||||
_mat[0][1]=mat._mat[1][0];
|
||||
_mat[0][2]=mat._mat[2][0];
|
||||
_mat[0][3]=mat._mat[3][0];
|
||||
_mat[1][0]=mat._mat[0][1];
|
||||
_mat[1][2]=mat._mat[2][1];
|
||||
_mat[1][3]=mat._mat[3][1];
|
||||
_mat[2][0]=mat._mat[0][2];
|
||||
_mat[2][1]=mat._mat[1][2];
|
||||
_mat[2][3]=mat._mat[3][2];
|
||||
_mat[3][0]=mat._mat[0][3];
|
||||
_mat[3][1]=mat._mat[1][3];
|
||||
_mat[3][2]=mat._mat[2][3];
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Matrix_implementation::transpose3x3(const Matrix_implementation&mat){
|
||||
if (&mat==this) {
|
||||
Matrix_implementation tm(mat);
|
||||
return transpose3x3(tm);
|
||||
}
|
||||
_mat[0][1]=mat._mat[1][0];
|
||||
_mat[0][2]=mat._mat[2][0];
|
||||
_mat[1][0]=mat._mat[0][1];
|
||||
_mat[1][2]=mat._mat[2][1];
|
||||
_mat[2][0]=mat._mat[0][2];
|
||||
_mat[2][1]=mat._mat[1][2];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Matrix_implementation::invert_4x4( const Matrix_implementation& mat )
|
||||
{
|
||||
if (&mat==this) {
|
||||
@@ -763,7 +798,7 @@ bool Matrix_implementation::invert_4x4( const Matrix_implementation& mat )
|
||||
for(i=0;i<4;i++)
|
||||
{
|
||||
big=0.0;
|
||||
for (j=0; j<4; j++)
|
||||
for (j=0; j<4; ++j)
|
||||
if (ipiv[j] != 1)
|
||||
for (k=0; k<4; k++)
|
||||
{
|
||||
@@ -781,7 +816,7 @@ bool Matrix_implementation::invert_4x4( const Matrix_implementation& mat )
|
||||
}
|
||||
++(ipiv[icol]);
|
||||
if (irow != icol)
|
||||
for (l=0; l<4; l++) SGL_SWAP(operator()(irow,l),
|
||||
for (l=0; l<4; ++l) SGL_SWAP(operator()(irow,l),
|
||||
operator()(icol,l),
|
||||
temp);
|
||||
|
||||
@@ -792,13 +827,13 @@ bool Matrix_implementation::invert_4x4( const Matrix_implementation& mat )
|
||||
|
||||
pivinv = 1.0/operator()(icol,icol);
|
||||
operator()(icol,icol) = 1;
|
||||
for (l=0; l<4; l++) operator()(icol,l) *= pivinv;
|
||||
for (ll=0; ll<4; ll++)
|
||||
for (l=0; l<4; ++l) operator()(icol,l) *= pivinv;
|
||||
for (ll=0; ll<4; ++ll)
|
||||
if (ll != icol)
|
||||
{
|
||||
dum=operator()(ll,icol);
|
||||
operator()(ll,icol) = 0;
|
||||
for (l=0; l<4; l++) operator()(ll,l) -= operator()(icol,l)*dum;
|
||||
for (l=0; l<4; ++l) operator()(ll,l) -= operator()(icol,l)*dum;
|
||||
}
|
||||
}
|
||||
for (int lx=4; lx>0; --lx)
|
||||
|
||||
86
src/osgWrappers/serializers/osg/BufferIndexBinding.cpp
Normal file
86
src/osgWrappers/serializers/osg/BufferIndexBinding.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
#include <osg/BufferIndexBinding>
|
||||
#include <osg/BufferObject>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
#define ADD_GLUINT_SERIALIZER(PROP, DEF) \
|
||||
wrapper->addSerializer( new osgDB::PropByValSerializer< MyClass, GLuint >( \
|
||||
#PROP, ((unsigned int)(DEF)), &MyClass::get##PROP, &MyClass::set##PROP), osgDB::BaseSerializer::RW_UINT )
|
||||
|
||||
#define GLsizei_ptrSERIALIZER(TYPE,XXX) \
|
||||
static bool check##XXX( const TYPE& node )\
|
||||
{ return node.get##XXX()>0;}\
|
||||
static bool read##XXX( osgDB::InputStream& is, TYPE& node )\
|
||||
{\
|
||||
unsigned int size = 0; is >> size ; node.set##XXX(size); return true;\
|
||||
}\
|
||||
static bool write##XXX( osgDB::OutputStream& os, const TYPE& node )\
|
||||
{\
|
||||
unsigned int size = node.get##XXX(); os << size << std::endl; return true;\
|
||||
}
|
||||
|
||||
GLsizei_ptrSERIALIZER(osg::BufferIndexBinding,Size)
|
||||
GLsizei_ptrSERIALIZER(osg::BufferIndexBinding,Offset)
|
||||
|
||||
|
||||
namespace wrap_osgBufferIndexBinding
|
||||
{
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( BufferIndexBinding,
|
||||
/*new osg::BufferIndexBinding*/NULL,
|
||||
osg::BufferIndexBinding,
|
||||
"osg::Object osg::StateAttribute osg::BufferIndexBinding" )
|
||||
{
|
||||
|
||||
ADD_GLENUM_SERIALIZER( Target,GLenum, GL_BUFFER); // _target
|
||||
ADD_OBJECT_SERIALIZER( BufferData, osg::BufferData, NULL ); // _bufferObject
|
||||
ADD_GLUINT_SERIALIZER( Index, 0); // _index
|
||||
|
||||
ADD_USER_SERIALIZER(Size);
|
||||
ADD_USER_SERIALIZER(Offset);
|
||||
}
|
||||
}
|
||||
namespace wrap_osgUniformBufferBinding
|
||||
{
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( UniformBufferBinding,
|
||||
new osg::UniformBufferBinding,
|
||||
osg::UniformBufferBinding,
|
||||
"osg::Object osg::StateAttribute osg::BufferIndexBinding osg::UniformBufferBinding" )
|
||||
{
|
||||
}
|
||||
}
|
||||
namespace wrap_osgTransformFeedbackBufferBinding
|
||||
{
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( TransformFeedbackBufferBinding,
|
||||
new osg::TransformFeedbackBufferBinding,
|
||||
osg::TransformFeedbackBufferBinding,
|
||||
"osg::Object osg::StateAttribute osg::BufferIndexBinding osg::TransformFeedbackBufferBinding" )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
namespace wrap_osgAtomicCounterBufferBinding
|
||||
{
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( AtomicCounterBufferBinding,
|
||||
new osg::AtomicCounterBufferBinding,
|
||||
osg::AtomicCounterBufferBinding,
|
||||
"osg::Object osg::StateAttribute osg::BufferIndexBinding osg::AtomicCounterBufferBinding" )
|
||||
{
|
||||
}
|
||||
}
|
||||
namespace wrap_osgShaderStorageBufferBinding
|
||||
{
|
||||
|
||||
REGISTER_OBJECT_WRAPPER( ShaderStorageBufferBinding,
|
||||
new osg::ShaderStorageBufferBinding,
|
||||
osg::ShaderStorageBufferBinding,
|
||||
"osg::Object osg::StateAttribute osg::BufferIndexBinding osg::ShaderStorageBufferBinding" )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user