VertexBufferControl.cc 1.38 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/Controller/VertexBufferControl.hh>
Robert Menzel's avatar
Robert Menzel committed
7

Robert Menzel's avatar
Robert Menzel committed
8
using namespace ACGL::OpenGL;
Robert Menzel's avatar
Robert Menzel committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

SharedVertexBuffer VertexBufferControl::create(void)
{
    GLenum mode = GL_TRIANGLES;
    GLsizei elements = 0;
    if(mpElementArrayBuffer)
    {
        mode = mpElementArrayBuffer->getMode();
        elements = mpElementArrayBuffer->getElements();
    }
    else if(mArrayBuffers.size() > 0 && mArrayBuffers[0])
    {
        mode = mArrayBuffers[0]->getMode();
        elements = mArrayBuffers[0]->getElements();
    }

25
    SharedVertexBuffer vertexBuffer(new VertexBuffer());
Robert Menzel's avatar
Robert Menzel committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

    vertexBuffer->setElementArrayBuffer(mpElementArrayBuffer);

    for(VertexBuffer::ArrayBufferVec::size_type i = 0; i < mArrayBuffers.size(); i++)
    {
        vertexBuffer->attachArrayBuffer(mArrayBuffers[i]);
    }

    for(AttributeDefineVec::size_type i = 0; i < mAttributeDefines.size(); i++)
    {
        vertexBuffer->attachAttribute(
            mAttributeDefines[i].name,
            mAttributeDefines[i].bufferID,
            mAttributeDefines[i].attributeName);
    }

    return vertexBuffer;
}