ElementArrayBuffer.hh 3.76 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.                                                       //
////////////////////////////////////////////////////////////////////////////////

6
7
#ifndef ACGL_OPENGL_OBJECTS_ELEMENTBUFFERDATA_HH
#define ACGL_OPENGL_OBJECTS_ELEMENTBUFFERDATA_HH
Robert Menzel's avatar
Robert Menzel committed
8

Robert Menzel's avatar
Robert Menzel committed
9
/**
10
11
12
13
14
15
16
17
18
19
20
21
22
 * An ElementArrayBuffer is an index into ArrayBuffers and defines which
 * elements of that array should be drawn in which order.
 *
 * The combination of (multiple) attributes of (multiple) ArrayBuffers
 * and one (optional) ElementArrayBuffer is a VertexBufferObject or VertexArrayObject.
 *
 * Note: In some documents ElementArrayBuffer are called VertexBufferObjects, VBOs
 *       or IndexBufferObjects (IBOs). But ArrayBuffers can also be called VBOs...
 *       The original extension that introduced these two new buffer types was called
 *       ARB_vertex_buffer_object but the buffers itself are called ArrayBuffer and
 *       ElementArrayBuffer.
 */

Robert Menzel's avatar
Robert Menzel committed
23
24
#include <ACGL/ACGL.hh>

25
#include <ACGL/Base/Macros.hh>
Robert Menzel's avatar
Robert Menzel committed
26
27
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Tools.hh>
28
#include <ACGL/OpenGL/Objects/Buffer.hh>
Robert Menzel's avatar
Robert Menzel committed
29

Robert Menzel's avatar
Robert Menzel committed
30
31

namespace ACGL{
Robert Menzel's avatar
Robert Menzel committed
32
namespace OpenGL{
Robert Menzel's avatar
Robert Menzel committed
33

Robert Menzel's avatar
Robert Menzel committed
34
class ElementArrayBuffer : public Buffer
Robert Menzel's avatar
Robert Menzel committed
35
36
37
38
39
{
    // ========================================================================================================= \/
    // ============================================================================================ CONSTRUCTORS \/
    // ========================================================================================================= \/
public:
Robert Menzel's avatar
Robert Menzel committed
40
    ElementArrayBuffer( GLenum _type = GL_UNSIGNED_INT)
41
42
43
        : Buffer(GL_ELEMENT_ARRAY_BUFFER), mType(_type)
    {}

Robert Menzel's avatar
Robert Menzel committed
44
    ElementArrayBuffer( SharedBufferObject _pBuffer, GLenum _type  = GL_UNSIGNED_INT)
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
         : Buffer(_pBuffer, GL_ELEMENT_ARRAY_BUFFER), mType(_type)
    {}

    // ==================================================================================================== \/
    // ============================================================================================ GETTERS \/
    // ==================================================================================================== \/
public:
    inline GLenum getType(void) const { return mType; }

    // ==================================================================================================== \/
    // ============================================================================================ SETTERS \/
    // ==================================================================================================== \/
public:
    //! _type has to be one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT and indicates the
    //! datatype of the indices
Robert Menzel's avatar
Robert Menzel committed
60
    inline void setType (GLenum _type) { mType = _type; }
61

Robert Menzel's avatar
Robert Menzel committed
62
63
    //! Returns the number of indices:
    GLuint getElements() {
Robert Menzel's avatar
Robert Menzel committed
64
        return (GLuint)( getSize() / getGLTypeSize(mType));
Robert Menzel's avatar
Robert Menzel committed
65
66
    }

67
68
69
70
71
72
73
74
75
76
77
78
79
    //! Overloaded from the base class to _prevent_ redefining of the binding target! (see Buffer)
    inline void setTarget( GLenum ) {
        ACGL::Utils::error() << "DON'T redefine the target binding point of an ElementArrayBuffer" << std::endl;
    }

    // =================================================================================================== \/
    // ============================================================================================ FIELDS \/
    // =================================================================================================== \/
protected:
    //! index data type: GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT
    GLenum mType;
};

Robert Menzel's avatar
Robert Menzel committed
80
ACGL_SMARTPOINTER_TYPEDEFS(ElementArrayBuffer)
81
82


Robert Menzel's avatar
Robert Menzel committed
83
} // OpenGL
Robert Menzel's avatar
Robert Menzel committed
84
85
} // ACGL

86
#endif // ACGL_OPENGL_OBJECTS_ELEMENTBUFFERDATA_HH