Commit 89b187f0 authored by Robert Menzel's avatar Robert Menzel

added support for integer attributes

parent ce772262
......@@ -79,6 +79,7 @@ public:
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. Default is 0 (== off)
GLboolean isIntegerInShader; // should the data get read as vec or ivec ?
};
// ===================================================================================================== \/
......@@ -128,15 +129,18 @@ 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, GLuint _divisor = 0);
void defineIntegerAttribute( 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, GLuint _divisor = 0);
void defineAttributeWithPadding( const std::string& _name, GLenum _type, GLint _size, GLuint _padding, GLboolean _normalized = GL_FALSE, GLuint _divisor = 0);
void defineIntegerAttributeWithPadding( 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, GLuint _divisor = 0);
void defineAttributeWithOffset( const std::string& _name, GLenum _type, GLint _size, GLuint _offset, GLboolean _normalized = GL_FALSE, GLuint _divisor = 0);
void defineIntegerAttributeWithOffset( 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 );
......
......@@ -8,6 +8,9 @@
using namespace ACGL;
using namespace ACGL::OpenGL;
//
// float attributes:
//
void ArrayBuffer::defineAttribute(
const std::string& _name,
GLenum _type,
......@@ -16,7 +19,7 @@ void ArrayBuffer::defineAttribute(
GLuint _divisor )
{
GLuint offset = mStride;
Attribute attribute = { _name, _type, _size, offset, _normalized, _divisor };
Attribute attribute = { _name, _type, _size, offset, _normalized, _divisor, GL_FALSE };
defineAttribute(attribute);
}
......@@ -29,7 +32,7 @@ void ArrayBuffer::defineAttributeWithPadding(
GLuint _divisor )
{
GLuint offset = mStride;
Attribute attribute = { _name, _type, _size, offset, _normalized, _divisor };
Attribute attribute = { _name, _type, _size, offset, _normalized, _divisor, GL_FALSE };
defineAttribute(attribute);
// defineAttribute will shift the mStride to the end of this attribute, so we only have to
// add the explicit padding:
......@@ -44,10 +47,57 @@ void ArrayBuffer::defineAttributeWithOffset(
GLboolean _normalized,
GLuint _divisor )
{
Attribute attribute = { _name, _type, _size, _offset, _normalized, _divisor };
Attribute attribute = { _name, _type, _size, _offset, _normalized, _divisor, GL_FALSE };
defineAttribute(attribute);
}
//
// integer attributes:
//
void ArrayBuffer::defineIntegerAttribute(
const std::string& _name,
GLenum _type,
GLint _size,
GLboolean _normalized,
GLuint _divisor )
{
GLuint offset = mStride;
Attribute attribute = { _name, _type, _size, offset, _normalized, _divisor, GL_TRUE };
defineAttribute(attribute);
}
void ArrayBuffer::defineIntegerAttributeWithPadding(
const std::string& _name,
GLenum _type,
GLint _size,
GLuint _padding,
GLboolean _normalized,
GLuint _divisor )
{
GLuint offset = mStride;
Attribute attribute = { _name, _type, _size, offset, _normalized, _divisor, GL_TRUE };
defineAttribute(attribute);
// defineAttribute will shift the mStride to the end of this attribute, so we only have to
// add the explicit padding:
mStride += _padding;
}
void ArrayBuffer::defineIntegerAttributeWithOffset(
const std::string& _name,
GLenum _type,
GLint _size,
GLuint _offset,
GLboolean _normalized,
GLuint _divisor )
{
Attribute attribute = { _name, _type, _size, _offset, _normalized, _divisor, GL_TRUE };
defineAttribute(attribute);
}
//
// int/float already defined by the Attribute:
//
void ArrayBuffer::defineAttribute( const Attribute &_attribute )
{
// this way attribute definitions don't have to be in order!
......
......@@ -201,18 +201,31 @@ SharedLocationMappings VertexArrayObject::getAttributeLocations() const
return locationMap;
}
void VertexArrayObject::setAttributePointer( GLuint _index )
{
mAttributes[_index].arrayBuffer->bind();
ArrayBuffer::Attribute arrayBufferAttribute = mAttributes[_index].arrayBuffer->getAttribute(mAttributes[_index].attributeID);
glVertexAttribPointer(_index,
arrayBufferAttribute.size,
arrayBufferAttribute.type,
arrayBufferAttribute.normalized,
mAttributes[_index].arrayBuffer->getStride(),
reinterpret_cast<GLvoid*>(arrayBufferAttribute.offset)
);
if (arrayBufferAttribute.isIntegerInShader == GL_TRUE) {
// read out as a int, ivecN
glVertexAttribIPointer(_index,
arrayBufferAttribute.size,
arrayBufferAttribute.type,
mAttributes[_index].arrayBuffer->getStride(),
reinterpret_cast<GLvoid*>(arrayBufferAttribute.offset)
);
} else {
// read out as a float, vecN
glVertexAttribPointer(_index,
arrayBufferAttribute.size,
arrayBufferAttribute.type,
arrayBufferAttribute.normalized,
mAttributes[_index].arrayBuffer->getStride(),
reinterpret_cast<GLvoid*>(arrayBufferAttribute.offset)
);
}
#if (ACGL_OPENGL_VERSION >= 33)
glVertexAttribDivisor( _index, arrayBufferAttribute.divisor );
#endif
......
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