VertexBuffer.cc 1.67 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/VertexBuffer.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
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

int_t VertexBuffer::getAttributeIndexByName(const std::string& _name) const
{
    for(AttributeVec::size_type i = 0; i < mAttributes.size(); ++i)
        if(mAttributes[i].name == _name)
            return i;
    return -1;
}

void VertexBuffer::render(void) const
{
    if(mpElementArrayBuffer)
        mpElementArrayBuffer->bind();

    int_t currentBufferID = -1;
    for(AttributeVec::size_type i = 0; i < mAttributes.size(); ++i)
    {
        if(mAttributes[i].bufferID != currentBufferID)
        {
            currentBufferID = mAttributes[i].bufferID;
            mArrayBuffers[currentBufferID]->bind();
        }
32
        mArrayBuffers[currentBufferID]->setAttributePointer(mAttributes[i].attributeID, i);
Robert Menzel's avatar
Robert Menzel committed
33
        glEnableVertexAttribArray(i);
34
        openGLRareError();
Robert Menzel's avatar
Robert Menzel committed
35
36
37
38
39
40
41
42
43
44
45
46
47
    }

    draw();

    currentBufferID = -1;
    for(AttributeVec::size_type i = 0; i < mAttributes.size(); ++i)
    {
        if(mAttributes[i].bufferID != currentBufferID)
        {
            currentBufferID = mAttributes[i].bufferID;
            mArrayBuffers[currentBufferID]->bind();
        }
        glDisableVertexAttribArray(i);
48
        openGLRareError();
Robert Menzel's avatar
Robert Menzel committed
49
50
    }

51
    /*
Robert Menzel's avatar
Robert Menzel committed
52
53
54
    if(mpElementArrayBuffer)
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
55
    */
Robert Menzel's avatar
Robert Menzel committed
56
}