Commit c2fe617c authored by Robert Menzel's avatar Robert Menzel

added support for vertex array divisor

parent 2e0b0057
......@@ -78,6 +78,7 @@ public:
GLint size; // #elements per attribute, size in bytes would be: size*sizeof(type)
GLuint offset; // offset in bytes into the array
GLboolean normalized; // int types can get normalzed to 0..1 / -1..1 by GL, useful e.g. for colors
GLuint divisor; // vertex divisor for instancing, supported since OpenGL 3.3
};
// ===================================================================================================== \/
......@@ -109,7 +110,7 @@ public:
// ==================================================================================================== \/
public:
//! elements is the number of vertices (unless this AB should get interpreted in a strange way):
//! elements is the number of vertices or instances (if the divisor is != 0):
inline GLsizei getElements (void) const { return (GLsizei) (mStride==0?0:(mSize/mStride)); }
//! size in bytes of all attributes that make up one element (vertex):
......@@ -126,16 +127,16 @@ public:
// ==================================================================================================== \/
public:
//! 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);
void defineAttribute( const std::string& _name, GLenum _type, GLint _size, GLboolean _normalized = GL_FALSE, GLuint _divisor = 0);
//! Adds the attribute at the end of the existing attributes, stride gets computed automatically
//! + extra padding in bytes at the end
void defineAttributeWithPadding( const std::string& _name, GLenum _type, GLint _size, GLuint _padding, GLboolean _normalized = GL_FALSE);
void defineAttributeWithPadding( const std::string& _name, GLenum _type, GLint _size, GLuint _padding, GLboolean _normalized = GL_FALSE, GLuint _divisor = 0);
//! 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. This way attributes can even
//! overlap, hope you know what you're doing...
void defineAttributeWithOffset( const std::string& _name, GLenum _type, GLint _size, GLuint _offset, GLboolean _normalized = GL_FALSE);
void defineAttributeWithOffset( const std::string& _name, GLenum _type, GLint _size, GLuint _offset, GLboolean _normalized = GL_FALSE, GLuint _divisor = 0);
//! Takes care of a valid stride size and adds the attribute
void defineAttribute( const Attribute &_attribute );
......
......@@ -12,10 +12,11 @@ void ArrayBuffer::defineAttribute(
const std::string& _name,
GLenum _type,
GLint _size,
GLboolean _normalized)
GLboolean _normalized,
GLuint _divisor )
{
GLuint offset = mStride;
Attribute attribute = { _name, _type, _size, offset, _normalized };
Attribute attribute = { _name, _type, _size, offset, _normalized, _divisor };
defineAttribute(attribute);
}
......@@ -24,10 +25,11 @@ void ArrayBuffer::defineAttributeWithPadding(
GLenum _type,
GLint _size,
GLuint _padding,
GLboolean _normalized)
GLboolean _normalized,
GLuint _divisor )
{
GLuint offset = mStride;
Attribute attribute = { _name, _type, _size, offset, _normalized };
Attribute attribute = { _name, _type, _size, offset, _normalized, _divisor };
defineAttribute(attribute);
// defineAttribute will shift the mStride to the end of this attribute, so we only have to
// add the explicit padding:
......@@ -39,9 +41,10 @@ void ArrayBuffer::defineAttributeWithOffset(
GLenum _type,
GLint _size,
GLuint _offset,
GLboolean _normalized)
GLboolean _normalized,
GLuint _divisor )
{
Attribute attribute = { _name, _type, _size, _offset, _normalized };
Attribute attribute = { _name, _type, _size, _offset, _normalized, _divisor };
defineAttribute(attribute);
}
......
......@@ -209,6 +209,9 @@ void VertexArrayObject::setAttributePointer( GLuint _index )
mAttributes[_index].arrayBuffer->getStride(),
reinterpret_cast<GLvoid*>(arrayBufferAttribute.offset)
);
#if (ACGL_OPENGL_VERSION >= 33)
glVertexAttribDivisor( _index, arrayBufferAttribute.divisor );
#endif
glEnableVertexAttribArray(_index);
}
......
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