Commit ba4db533 authored by Robert Menzel's avatar Robert Menzel

added new AB & EAB based on Buffer, not used yet, just for finding a good API

parent e07f05dd
......@@ -34,6 +34,8 @@
#include <vector>
#include <tr1/memory>
#include <ACGL/OpenGL/Objects/Buffer.hh>
namespace ACGL{
namespace OpenGL{
......@@ -221,6 +223,173 @@ protected:
ACGL_SHARED_TYPEDEF(ArrayBuffer)
class ArrayBufferX : Buffer
{
// ==================================================================================================== \/
// ============================================================================================ STRUCTS \/
// ==================================================================================================== \/
public:
//! Each attribute has a size (#components, e.g. normal with x/y/z => 3) and an offset in the stride (in bytes)
struct Attribute
{
std::string name; // human readable name, can be used to match the attribute to shader programs
GLenum type; // GL_FLOAT, GL_UNSIGNED_BYTE etc.
GLint size; // #elements per attribute
GLuint offset; // offset in bytes into the array
GLboolean normalized; // int types can get normalzed to 0..1 / -1..1 by GL
};
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
public:
typedef std::vector< Attribute > AttributeVec;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
ArrayBufferX()
: Buffer(GL_ARRAY_BUFFER),
//mElements(0),
mStride(0),
mAttributes()
{}
ArrayBufferX( SharedBufferObject _pBuffer )
: Buffer(_pBuffer, GL_ARRAY_BUFFER),
//mElements(0),
mStride(0),
mAttributes()
{}
// ==================================================================================================== \/
// ============================================================================================ GETTERS \/
// ==================================================================================================== \/
public:
//inline GLsizei getElements (void) const { return mElements; }
inline GLsizei getStride (void) const { return mStride; }
inline const AttributeVec& getAttributes (void) const { return mAttributes; }
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
//int_t getAttributeIndexByName(const std::string& _nameInArray) const;
/* Attributes:
*
* _type is the GL type
* _size the number of elements in this attribute (1..4)
* _normalized is the attribute normalization for int types
*
* Want to add tightly packed attributes in order?
* -> use defineAttribute()
*
* Want to add attributes with individual padding in order?
* -> use defineAttributeWithPadding()
*
* Want to add attributes out-of-order?
* -> use defineAttributeWithOffset()
*
* The stride size gets always set to the minimal stride size that covers all defined attributes (/w padding).
* All define methods can get mixed!
*
*
* ab->defineAttribute( "pos", GL_FLOAT, 3 ); // stride: 12 bytes
* ab->defineAttributeWithPadding( "color", GL_CHAR, 3, 1 ); // stride: 12 + 3 + 1 = 16 bytes
* ab->defineAttributeWithOffset( "colorNorm", GL_CHAR, 3, 12, GL_TRUE ); // stride is still 16 as 12+3 <= 16!
*/
//! Adds the attribute at the end of the existing attributes, stride gets computed automatically
void defineAttribute(
const std::string& _name,
GLenum _type,
GLint _size,
GLboolean _normalized = GL_FALSE)
{
GLuint offset = mStride;
Attribute attribute = { _name, _type, _size, offset, _normalized };
defineAttribute(attribute);
}
//! Adds the attribute at the end of the existing attributes, stride gets computed automatically
//! + extra padding in bytes
void defineAttributeWithPadding(
const std::string& _name,
GLenum _type,
GLint _size,
GLuint _padding,
GLboolean _normalized = GL_FALSE)
{
Attribute attribute = { _name, _type, _size, (GLuint)mStride, _normalized };
defineAttribute(attribute);
// defineAttribute will shift the mStride to the end of this attribute, so we only have to
// add the explicit padding:
mStride += _padding;
}
//! Adds an attribute defined by an offset: this way an attribute can get added at arbitrary
//! locations in the stride. If it's added at the end, the stride gets resized.
void defineAttributeWithOffset(
const std::string& _name,
GLenum _type,
GLint _size,
GLuint _offset,
GLboolean _normalized = GL_FALSE)
{
Attribute attribute = { _name, _type, _size, _offset, _normalized };
defineAttribute(attribute);
}
//! Takes care of a valid stride size and adds the attribute
void defineAttribute( const Attribute &_attribute )
{
// this way attribute definitions don't have to be in order!
mStride = std::max( (GLsizei)_attribute.offset + getGLTypeSize(_attribute.type)*_attribute.size,
mStride);
mAttributes.push_back( _attribute );
}
//! Setting of the stride size explicitly is not needed if the attributes are defined correctly (with padding)
inline void setStride( GLsizei _stride ) {
mStride = _stride;
}
//! removes all attributes
inline void removeAttributes(void)
{
mStride = 0;
mAttributes.clear();
}
//! Overloaded from the base class to _prevent_ redefining of the binding target! (see Buffer)
inline void setTarget( GLenum ) {
ACGL::Utils::error() << "DON'T redefine the target binding point of an ArrayBuffer" << std::endl;
}
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
//GLsizei mElements;
GLsizei mStride;
AttributeVec mAttributes;
};
ACGL_SHARED_TYPEDEF(ArrayBufferX)
} // OpenGL
} // ACGL
......
......@@ -25,6 +25,7 @@
#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Tools.hh>
#include <ACGL/OpenGL/Objects/Buffer.hh>
#include <tr1/memory>
......@@ -147,6 +148,61 @@ protected:
ACGL_SHARED_TYPEDEF(ElementArrayBuffer)
class ElementArrayBufferX : Buffer
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
ElementArrayBufferX( GLenum _type = GL_UNSIGNED_INT)
: Buffer(GL_ELEMENT_ARRAY_BUFFER), mType(_type)
{}
ElementArrayBufferX( SharedBufferObject _pBuffer, GLenum _type = GL_UNSIGNED_INT)
: Buffer(_pBuffer, GL_ELEMENT_ARRAY_BUFFER), mType(_type)
{}
// ==================================================================================================== \/
// ============================================================================================ GETTERS \/
// ==================================================================================================== \/
public:
inline GLenum getType(void) const { return mType; }
// ==================================================================================================== \/
// ============================================================================================ SETTERS \/
// ==================================================================================================== \/
public:
//! _type has to be one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT and indicates the
//! datatype of the indices
inline void setType (GLenum _type)
{
mType = _type;
}
//! Overloaded from the base class to _prevent_ redefining of the binding target! (see Buffer)
inline void setTarget( GLenum ) {
ACGL::Utils::error() << "DON'T redefine the target binding point of an ElementArrayBuffer" << std::endl;
}
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
//! index data type: GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT
GLenum mType;
};
ACGL_SHARED_TYPEDEF(ElementArrayBufferX)
} // OpenGL
} // ACGL
......
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