Commit 2f7b1f60 authored by Robert Menzel's avatar Robert Menzel

Added getElements to AB and size caching to Buffer

parent b946f8ab
......@@ -259,14 +259,12 @@ public:
public:
ArrayBufferX()
: Buffer(GL_ARRAY_BUFFER),
//mElements(0),
mStride(0),
mAttributes()
{}
ArrayBufferX( SharedBufferObject _pBuffer )
: Buffer(_pBuffer, GL_ARRAY_BUFFER),
//mElements(0),
mStride(0),
mAttributes()
{}
......@@ -275,7 +273,7 @@ public:
// ============================================================================================ GETTERS \/
// ==================================================================================================== \/
public:
//inline GLsizei getElements (void) const { return mElements; }
inline GLsizei getElements (void) const { return mSize/mStride; }
inline GLsizei getStride (void) const { return mStride; }
inline const AttributeVec& getAttributes (void) const { return mAttributes; }
......
......@@ -79,7 +79,7 @@ class Buffer
public:
//! Most common default: a new Buffer corresponds to a new GL resource. You might decide on a binding point
//! now or later.
Buffer( GLenum _target ) : mTarget(_target)
Buffer( GLenum _target ) : mTarget(_target), mSize(0)
{
mBuffer = SharedBufferObject( new BufferObject() );
}
......@@ -94,7 +94,8 @@ public:
*/
Buffer( SharedBufferObject _pBuffer, GLenum _target )
: mTarget(_target),
mBuffer( _pBuffer )
mBuffer( _pBuffer ),
mSize(0)
{}
// ==================================================================================================== \/
......@@ -130,11 +131,11 @@ private:
//! not side effect free! will bind this buffer to it's last target!
//! caching of these values on RAM could be a good idea if needed very often!
inline GLint64 getSize() { return getParameter64( GL_BUFFER_SIZE ); }
//inline GLint64 getSize() { return getParameter64( GL_BUFFER_SIZE ); }
inline GLint64 getMapOffset() { return getParameter64( GL_BUFFER_MAP_OFFSET ); }
inline GLint64 getMapLength() { return getParameter64( GL_BUFFER_MAP_LENGTH ); }
#else // OpenGL pre 3.2:
inline GLint getSize() { return getParameter ( GL_BUFFER_SIZE ); }
//inline GLint getSize() { return getParameter ( GL_BUFFER_SIZE ); }
inline GLint getMapOffset() { return getParameter ( GL_BUFFER_MAP_OFFSET ); }
inline GLint getMapLength() { return getParameter ( GL_BUFFER_MAP_LENGTH ); }
#endif // OpenGL >= 3.2
......@@ -143,6 +144,8 @@ private:
inline GLint getAccessFlags() { return (GLint) getParameter ( GL_BUFFER_ACCESS_FLAGS ); }
inline GLboolean isMapped() { return (GLboolean) getParameter ( GL_BUFFER_MAPPED ); }
inline GLint64 getSize() { return mSize; }
// ===================================================================================================== \/
// ============================================================================================ WRAPPERS \/
// ===================================================================================================== \/
......@@ -164,6 +167,7 @@ public:
//! Set data for this buffer. Use only to init the buffer!
//! Note: The function is not const, because it changes the corresponding GPU data
inline void setData( GLenum _target, GLsizeiptr _size, const GLvoid *_pData = NULL, GLenum _usage = GL_STATIC_DRAW ) {
mSize = _size;
bind( _target );
glBufferData( _target, _size, _pData, _usage );
openGLRareError();
......@@ -289,6 +293,7 @@ public:
// =================================================================================================== \/
protected:
GLenum mTarget;
GLint64 mSize; // as this might get queried often (e.g. ArrayBuffer) we will explicitly mirror it in RAM)
SharedBufferObject mBuffer;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment