vertexarrayobject.h 3.37 KB
Newer Older
1
2
3
4
5
#ifndef VERTEXATTRIBUTE_H__
#define VERTEXATTRIBUTE_H__

#include "tgt/exception.h"
#include "tgt/tgt_gl.h"
6
#include "tgt/types.h"
7
8
9
10
11
12
13
14
15
16
17
18
19

#include <string>
#include <vector>
#include <map>

namespace tgt {
    class BufferObject;
    class Shader;
    class VertexArrayObject;

    /**
     * Wrapper class for OpenGL Vertex Array Objects.
     * 
20
     * \see     http://www.opengl.org/wiki/Vertex_Array_Object
21
22
23
     * \note    Because all member methods require a valid locked OpenGL context, we have 
     *          implicit thread-safety.
     */
24
    class TGT_API VertexArrayObject {
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    public:
        VertexArrayObject(bool autoBind = true) throw (tgt::Exception);

        /**
         * Destructor, deletes the whole VAO.
         */
        ~VertexArrayObject();

        /**
         * Binds this VertexArrayObject to the current OpenGL context.
         */
        void bind();

        /**
         * Unbinds this VertexArrayObject from the current OpenGL context.
         */
        void unbind();

43
44
45
46
47
        /**
         * Binds the provided buffer \a bufferObject as index buffer to this VAO.
         * \param   bufferObject    Buffer to use as element index buffer.
         */
        void bindIndexBuffer(BufferObject* bufferObject);
48

49
        /**
50
         * Add a VertexAttribute for \a bufferObject to this VertexArrayObject.
51
52
         * A VertexAttribute refers to a BufferObject and defines where to find the (geometry, normal, ...) data
         * in it.
53
54
55
56
         * \param   location        Location where this VertexAttribute is bound to the vertex shader.
         * \param   bufferObject    BufferObject to bind
         * \param   stride          Stride
         * \param   offset          Offset
57
         */
58
        void setVertexAttributePointer(GLuint location, BufferObject* bufferObject, GLsizei stride = 0, size_t offset = 0, bool enable = true);
59
60

        /**
61
62
         * Enables the VertexAttribute with the given location in the OpenGL client state.
         * \param   location   Index of the VertexAttribute to enable.
63
         */
64
        void enableVertexAttribute(GLuint location);
65

66
        /**
67
68
69
         * Enables the VertexAttribute assigned to the given BufferObject.
         * \note    The BufferObject has to be added to this VAO first using setVertexAttributePointer().
         * \param   bufferObject    BufferObject whose VertexAttribute shall be enabled
70
         */
71
        void enableVertexAttribute(BufferObject* bufferObject);
72

73
74
        /**
         * Disables the VertexAttribute with the given index in the OpenGL client state.
75
         * \param   location   Index of the VertexAttribute to disable.
76
         */
77
        void disableVertexAttribute(GLuint location);
78

79
        /**
80
81
82
         * Disables the VertexAttribute assigned to the given BufferObject.
         * \note    The BufferObject has to be added to this VAO first using setVertexAttributePointer().
         * \param   bufferObject    BufferObject whose VertexAttribute shall be disabled
83
         */
84
        void disableVertexAttribute(BufferObject* bufferObject);
85
86
87

    protected:

88
        GLuint _id;         ///< Id of the internal OpenGL handle to the VAO.
89

90
        std::map<BufferObject*, GLuint> _locationMap;   ///< Mapping added BufferObjects to locations.
91
92
93
94
95
96

        static const std::string loggerCat_;
    };
}

#endif // VERTEXATTRIBUTE_H__