Skip to content

Commit ca1978c

Browse files
committed
Add support for static generic vertex attributes
1 parent 384094d commit ca1978c

File tree

2 files changed

+137
-4
lines changed

2 files changed

+137
-4
lines changed

source/globjects/include/globjects/VertexAttributeBinding.h

+36-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <glm/fwd.hpp>
4+
35
#include <glbinding/gl/types.h>
46
#include <glbinding/gl/boolean.h>
57

@@ -29,7 +31,15 @@ class GLOBJECTS_API VertexAttributeBinding : public Referenced
2931
void setDivisor(gl::GLint divisor);
3032

3133
void setAttribute(gl::GLint attributeIndex);
32-
void setBuffer(
34+
35+
gl::GLint attributeIndex() const;
36+
gl::GLint bindingIndex() const;
37+
38+
/**
39+
* For VertexAttribPointer
40+
*/
41+
const Buffer * buffer() const;
42+
void setBuffer(
3343
const Buffer * vbo
3444
, gl::GLint baseoffset
3545
, gl::GLint stride);
@@ -48,9 +58,31 @@ class GLOBJECTS_API VertexAttributeBinding : public Referenced
4858
, gl::GLenum type
4959
, gl::GLuint relativeoffset = 0);
5060

51-
gl::GLint attributeIndex() const;
52-
gl::GLint bindingIndex() const;
53-
const Buffer * buffer() const;
61+
/**
62+
* For VertexAttrib
63+
*/
64+
void setValue(gl::GLboolean value);
65+
void setValue(gl::GLbyte value);
66+
void setValue(gl::GLshort value);
67+
void setValue(gl::GLint value);
68+
void setValue(gl::GLint64 value);
69+
void setValue(gl::GLfloat value);
70+
void setValue(gl::GLdouble value);
71+
72+
void setValue(const glm::bvec2 value);
73+
void setValue(const glm::ivec2 value);
74+
void setValue(const glm::vec2 value);
75+
void setValue(const glm::dvec2 value);
76+
77+
void setValue(const glm::bvec3 value);
78+
void setValue(const glm::ivec3 value);
79+
void setValue(const glm::vec3 value);
80+
void setValue(const glm::dvec3 value);
81+
82+
void setValue(const glm::bvec4 value);
83+
void setValue(const glm::ivec4 value);
84+
void setValue(const glm::vec4 value);
85+
void setValue(const glm::dvec4 value);
5486

5587
protected:
5688
virtual ~VertexAttributeBinding();

source/globjects/source/VertexAttributeBinding.cpp

+101
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
#include <cassert>
44

5+
#include <glm/vec2.hpp>
6+
#include <glm/vec3.hpp>
7+
#include <glm/vec4.hpp>
8+
59
#include <globjects/VertexArray.h>
610
#include <globjects/globjects.h>
711

@@ -97,4 +101,101 @@ void VertexAttributeBinding::setLFormat(const GLint size, const GLenum type, con
97101
attributeImplementation().setLFormat(this, size, type, relativeoffset);
98102
}
99103

104+
void VertexAttributeBinding::setValue(gl::GLboolean value)
105+
{
106+
glVertexAttribI1i(bindingIndex(), static_cast<GLint>(value));
107+
}
108+
109+
void VertexAttributeBinding::setValue(gl::GLbyte value)
110+
{
111+
glVertexAttribI1i(bindingIndex(), static_cast<GLint>(value));
112+
}
113+
114+
void VertexAttributeBinding::setValue(gl::GLshort value)
115+
{
116+
glVertexAttribI1i(bindingIndex(), static_cast<GLint>(value));
117+
}
118+
119+
void VertexAttributeBinding::setValue(gl::GLint value)
120+
{
121+
glVertexAttribI1i(bindingIndex(), value);
122+
}
123+
124+
void VertexAttributeBinding::setValue(gl::GLint64 value)
125+
{
126+
glVertexAttribL1i64NV(bindingIndex(), value);
127+
}
128+
129+
void VertexAttributeBinding::setValue(gl::GLfloat value)
130+
{
131+
glVertexAttrib1f(bindingIndex(), value);
132+
}
133+
134+
void VertexAttributeBinding::setValue(gl::GLdouble value)
135+
{
136+
glVertexAttrib1d(bindingIndex(), value);
137+
glVertexAttribL1d(bindingIndex(), value);
138+
}
139+
140+
void VertexAttributeBinding::setValue(const glm::bvec2 value)
141+
{
142+
glVertexAttribI2i(bindingIndex(), static_cast<GLint>(value.x), static_cast<GLint>(value.y));
143+
}
144+
145+
void VertexAttributeBinding::setValue(const glm::ivec2 value)
146+
{
147+
glVertexAttribI2i(bindingIndex(), value.x, value.y);
148+
}
149+
150+
void VertexAttributeBinding::setValue(const glm::vec2 value)
151+
{
152+
glVertexAttrib2f(bindingIndex(), value.x, value.y);
153+
}
154+
155+
void VertexAttributeBinding::setValue(const glm::dvec2 value)
156+
{
157+
glVertexAttribL2d(bindingIndex(), value.x, value.y);
158+
}
159+
160+
void VertexAttributeBinding::setValue(const glm::bvec3 value)
161+
{
162+
glVertexAttribI3i(bindingIndex(), static_cast<GLint>(value.x), static_cast<GLint>(value.y), static_cast<GLint>(value.z));
163+
}
164+
165+
void VertexAttributeBinding::setValue(const glm::ivec3 value)
166+
{
167+
glVertexAttribI3i(bindingIndex(), value.x, value.y, value.z);
168+
}
169+
170+
void VertexAttributeBinding::setValue(const glm::vec3 value)
171+
{
172+
glVertexAttrib3f(bindingIndex(), value.x, value.y, value.z);
173+
}
174+
175+
void VertexAttributeBinding::setValue(const glm::dvec3 value)
176+
{
177+
glVertexAttribL3d(bindingIndex(), value.x, value.y, value.z);
178+
}
179+
180+
void VertexAttributeBinding::setValue(const glm::bvec4 value)
181+
{
182+
glVertexAttribI4i(bindingIndex(), static_cast<GLint>(value.x), static_cast<GLint>(value.y), static_cast<GLint>(value.z), static_cast<GLint>(value.w));
183+
}
184+
185+
void VertexAttributeBinding::setValue(const glm::ivec4 value)
186+
{
187+
glVertexAttribI4i(bindingIndex(), value.x, value.y, value.z, value.w);
188+
}
189+
190+
void VertexAttributeBinding::setValue(const glm::vec4 value)
191+
{
192+
glVertexAttrib4f(bindingIndex(), value.x, value.y, value.z, value.w);
193+
}
194+
195+
void VertexAttributeBinding::setValue(const glm::dvec4 value)
196+
{
197+
glVertexAttribL4d(bindingIndex(), value.x, value.y, value.z, value.w);
198+
}
199+
200+
100201
} // namespace globjects

0 commit comments

Comments
 (0)