Skip to content

Commit 63ce95e

Browse files
committed
Sanity check element buffers in VAO
1 parent aa8a95e commit 63ce95e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

demosys/opengl/geometry/plane.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def gen_index():
5757
normal_vbo = VBO(normal_data)
5858

5959
index_data = numpy.fromiter(gen_index(), dtype=numpy.uint32)
60-
index_vbo = VBO(index_data, target=GL.GL_ELEMENT_ARRAY_BUFFER)
60+
index_vbo = VBO(index_data, target="GL_ELEMENT_ARRAY_BUFFER")
6161

6262
vao = VAO("plane_xz", mode=GL.GL_TRIANGLES)
6363

demosys/opengl/vao.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,16 @@ def add_array_buffer(self, format, vbo):
132132
self.array_buffer_map[id(vbo)] = ArrayBuffer(format, vbo)
133133

134134
def set_element_buffer(self, format, vbo):
135-
# GL_ELEMENT_ARRAY_BUFFER, GL_UNSIGNED_INT
135+
"""Set the index buffer for this VAO"""
136+
if not isinstance(vbo, VBO):
137+
raise VAOError("vbo parameter must be an OpenGL.arrays.vbo.VBO instance")
138+
139+
if vbo.target not in ["GL_ELEMENT_ARRAY_BUFFER"]:
140+
raise VAOError("Element buffers must have target=GL_ELEMENT_ARRAY_BUFFER")
141+
142+
if format not in [GL.GL_UNSIGNED_INT]:
143+
raise VAOError("Format can currently only be GL_UNSIGNED_INT")
144+
136145
self.element_buffer = ArrayBuffer(format, vbo)
137146

138147
def map_buffer(self, vbo, attrib_name, components):
@@ -167,7 +176,7 @@ def build(self):
167176
if buff.stride == 0:
168177
raise VAOError("Buffer {} was never mapped in VAO {}".format(key, self.name))
169178

170-
# Check that all buffers have the same number of elements
179+
# Check that all buffers have the same number of units
171180
last_vertices = -1
172181
for name, buf in self.array_buffer_map.items():
173182
vertices = buf.vertices

0 commit comments

Comments
 (0)