ArrayBuffer.cc 1.95 KB
Newer Older
Robert Menzel's avatar
Robert Menzel committed
1
2
3
4
5
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University         //
// All rights reserved.                                                       //
////////////////////////////////////////////////////////////////////////////////

Robert Menzel's avatar
Robert Menzel committed
6
#include <ACGL/OpenGL/Objects/ArrayBuffer.hh>
Robert Menzel's avatar
Robert Menzel committed
7
8

using namespace ACGL;
Robert Menzel's avatar
Robert Menzel committed
9
using namespace ACGL::OpenGL;
Robert Menzel's avatar
Robert Menzel committed
10

Robert Menzel's avatar
Robert Menzel committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
void ArrayBuffer::defineAttribute(
    const std::string& _name,
    GLenum _type,
    GLint  _size,
    GLboolean _normalized)
{
    GLuint offset = mStride;
    Attribute attribute = { _name, _type, _size, offset, _normalized };
    defineAttribute(attribute);
}

void ArrayBuffer::defineAttributeWithPadding(
    const std::string& _name,
    GLenum _type,
    GLint  _size,
    GLuint _padding,
    GLboolean _normalized)
{
    GLuint offset = mStride;
    Attribute attribute = { _name, _type, _size, offset, _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;
}

void ArrayBuffer::defineAttributeWithOffset(
    const std::string& _name,
    GLenum _type,
    GLint  _size,
    GLuint _offset,
    GLboolean _normalized)
{
    Attribute attribute = { _name, _type, _size, _offset, _normalized };
    defineAttribute(attribute);
}

void ArrayBuffer::defineAttribute( const Attribute &_attribute )
{
    // this way attribute definitions don't have to be in order!
    GLsizei attributeWidth = getGLTypeSize(_attribute.type)*_attribute.size; // in bytes
    mStride = std::max( (GLsizei)_attribute.offset + attributeWidth, mStride);
    mAttributes.push_back( _attribute );
}

Robert Menzel's avatar
Robert Menzel committed
56
57
58
59
60
61
62
int_t ArrayBuffer::getAttributeIndexByName(const std::string& _nameInArray) const
{
    for(AttributeVec::size_type i = 0; i < mAttributes.size(); ++i)
        if(mAttributes[i].name == _nameInArray)
            return i;
    return -1;
}