| globjects 1.0.0.000000000000 Strict OpenGL objects wrapper.

VertexArray.h
Go to the documentation of this file.
1
2 #pragma once
3
4 #include <map>
5 #include <vector>
6
7 #include <glbinding/gl/types.h>
8
9 #include <globjects/base/ref_ptr.h>
10
11 #include <globjects/globjects_api.h>
12 #include <globjects/Object.h>
13
14
15 namespace globjects
16 {
17
18
19 class VertexAttributeBinding;
20
21 // http://www.opengl.org/wiki/Vertex_Array_Object
22 class GLOBJECTS_API VertexArray : public Object
23 {
24 public:
25 enum class AttributeImplementation
26 {
27 DirectStateAccessARB
28 , VertexAttribBindingARB
29 , Legacy
30 };
31
32 static void hintAttributeImplementation(AttributeImplementation impl);
33
34 public:
35 VertexArray();
36
37 static VertexArray * fromId(gl::GLuint id);
38 static VertexArray * defaultVAO();
39
40 virtual void accept(ObjectVisitor & visitor) override;
41
42 void bind() const;
43 static void unbind();
44
45 VertexAttributeBinding * binding(gl::GLuint bindingIndex);
46 const VertexAttributeBinding * binding(gl::GLuint bindingIndex) const;
47
48 void enable(gl::GLint attributeIndex);
49 void disable(gl::GLint attributeIndex);
50
51 std::vector<VertexAttributeBinding *> bindings();
52 std::vector<const VertexAttributeBinding *> bindings() const;
53
54 // drawing
55
56 void drawArrays(gl::GLenum mode, gl::GLint first, gl::GLsizei count) const;
57 void drawArraysInstanced(gl::GLenum mode, gl::GLint first, gl::GLsizei count, gl::GLsizei instanceCount) const;
58 void drawArraysInstancedBaseInstance(gl::GLenum mode, gl::GLint first, gl::GLsizei count, gl::GLsizei instanceCount, gl::GLuint baseInstance) const;
59 void drawArraysIndirect(gl::GLenum mode, const void * indirect = nullptr) const;
60
61 void multiDrawArrays(gl::GLenum mode, gl::GLint * first, const gl::GLsizei * count, gl::GLsizei drawCount) const;
62 void multiDrawArraysIndirect(gl::GLenum mode, const void * indirect, gl::GLsizei drawCount, gl::GLsizei stride) const;
63
64 void drawElements(gl::GLenum mode, gl::GLsizei count, gl::GLenum type, const void * indices = nullptr) const;
65 void drawElementsBaseVertex(gl::GLenum mode, gl::GLsizei count, gl::GLenum type, const void * indices, gl::GLint baseVertex) const;
66 void drawElementsInstanced(gl::GLenum mode, gl::GLsizei count, gl::GLenum type, const void * indices, gl::GLsizei primitiveCount) const;
67 void drawElementsInstancedBaseInstance(gl::GLenum mode, gl::GLsizei count, gl::GLenum type, const void * indices, gl::GLsizei instanceCount, gl::GLuint baseInstance) const;
68 void drawElementsInstancedBaseVertex(gl::GLenum mode, gl::GLsizei count, gl::GLenum type, const void * indices, gl::GLsizei instanceCount, gl::GLint baseVertex) const;
69 void drawElementsInstancedBaseVertexBaseInstance(gl::GLenum mode, gl::GLsizei count, gl::GLenum type, const void * indices, gl::GLsizei instanceCount, gl::GLint baseVertex, gl::GLuint baseInstance) const;
70
71 void multiDrawElements(gl::GLenum mode, const gl::GLsizei * count, gl::GLenum type, const void ** indices, gl::GLsizei drawCount) const;
72 void multiDrawElementsBaseVertex(gl::GLenum mode, const gl::GLsizei * count, gl::GLenum type, const void ** indices, gl::GLsizei drawCount, gl::GLint * baseVertex) const;
73 void multiDrawElementsIndirect(gl::GLenum mode, gl::GLenum type, const void * indirect, gl::GLsizei drawCount, gl::GLsizei stride) const;
74
75 void drawRangeElements(gl::GLenum mode, gl::GLuint start, gl::GLuint end, gl::GLsizei count, gl::GLenum type, const void * indices = nullptr) const;
76 void drawRangeElementsBaseVertex(gl::GLenum mode, gl::GLuint start, gl::GLuint end, gl::GLsizei count, gl::GLenum type, const void * indices, gl::GLint baseVertex) const;
77
78 // convenience
79 struct MultiDrawArraysRange
80 {
81 gl::GLint first;
82 gl::GLsizei count;
83 };
84
85 struct MultiDrawElementsRange
86 {
87 gl::GLsizei count;
88 void * indices;
89 };
90
91 struct MultiDrawElementsBaseVertexRange
92 {
93 gl::GLsizei count;
94 void * indices;
95 gl::GLint baseVertex;
96 };
97
98 void multiDrawArrays(gl::GLenum mode, const std::vector<MultiDrawArraysRange> & ranges) const;
99 void multiDrawElements(gl::GLenum mode, gl::GLenum type, const std::vector<MultiDrawElementsRange> & ranges) const;
100 void multiDrawElementsBaseVertex(gl::GLenum mode, gl::GLenum type, const std::vector<MultiDrawElementsBaseVertexRange> & ranges) const;
101
102 virtual gl::GLenum objectType() const override;
103
104 protected:
105 VertexArray(IDResource * resource);
106 virtual ~VertexArray();
107
108 protected:
109 std::map<gl::GLuint, ref_ptr<VertexAttributeBinding>> m_bindings;
110
111 };
112
113
114 } // namespace globjects
globjects::VertexArray
Definition: VertexArray.h:22
globjects::disable
GLOBJECTS_API void disable(gl::GLenum capability)
globjects
Contains all the classes that wrap OpenGL functionality.
globjects::Object
Superclass of all wrapped OpenGL objects.
Definition: Object.h:26
globjects::VertexAttributeBinding
Definition: VertexAttributeBinding.h:21
globjects::VertexArray::MultiDrawArraysRange::count
gl::GLsizei count
Definition: VertexArray.h:82
globjects::VertexArray::MultiDrawElementsRange::count
gl::GLsizei count
Definition: VertexArray.h:87
ref_ptr.h
globjects::VertexArray::MultiDrawArraysRange
Definition: VertexArray.h:79
globjects::VertexArray::MultiDrawElementsBaseVertexRange::indices
void * indices
Definition: VertexArray.h:94
globjects::VertexArray::MultiDrawElementsBaseVertexRange::count
gl::GLsizei count
Definition: VertexArray.h:93
globjects::VertexArray::MultiDrawElementsRange::indices
void * indices
Definition: VertexArray.h:88
globjects::VertexArray::MultiDrawElementsRange
Definition: VertexArray.h:85
globjects::VertexArray::MultiDrawArraysRange::first
gl::GLint first
Definition: VertexArray.h:81
globjects::ObjectVisitor
Implements a Visitor Pattern to iterate over all tracked globjects objects.
Definition: ObjectVisitor.h:29
Object.h
globjects::VertexArray::m_bindings
std::map< gl::GLuint, ref_ptr< VertexAttributeBinding > > m_bindings
Definition: VertexArray.h:109
globjects::VertexArray::MultiDrawElementsBaseVertexRange
Definition: VertexArray.h:91
globjects::VertexArray::MultiDrawElementsBaseVertexRange::baseVertex
gl::GLint baseVertex
Definition: VertexArray.h:95
globjects::enable
GLOBJECTS_API void enable(gl::GLenum capability)
globjects::VertexArray::AttributeImplementation
AttributeImplementation
Definition: VertexArray.h:25