-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertexObjectFactory.py
More file actions
84 lines (48 loc) · 1.6 KB
/
VertexObjectFactory.py
File metadata and controls
84 lines (48 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'''
* VertexObjectFactory.py
*
* Created on: 16.12.2018
* Author: Andrew Jason Bishop
*
* General description:
* creates VertexArrayObjects (VAOs) and VertexArrayBuffers (VBOs)
'''
import OpenGL.GL as GL
import ctypes as ct
class VertexObjectFactory:
def __init__(self):
self.VERT_COMPONENT_COUNT = 3
self.ctype = ct.c_void_p(0)
self.vaos = []
self.vbos = []
def eval_vert_count_from_verts(self, _verts):
return int( _verts.size / self.VERT_COMPONENT_COUNT )
def eval_vert_count_from_indices(self, _indices):
return _indices.size
def create_and_bind_VAO(self):
vaoID = GL.glGenVertexArrays( 1 )
self.vaos.append(vaoID)
GL.glBindVertexArray( vaoID )
return vaoID
def unbind_VAO(self):
GL.glBindVertexArray( 0 )
def create_and_bind_VBO(self, _glBufferType, _name = "default"):
vboID = GL.glGenBuffers( 1 )
self.vbos.append( vboID )
#self.vbos.update({_name : vboID})
GL.glBindBuffer( _glBufferType, vboID )
return vboID
def determine_vertexArray_byteCount(self, _verts):
return GL.ArrayDatatype.arrayByteCount( _verts )
def unbind_VBO(self, _glBufferType):
GL.glBindBuffer( _glBufferType, 0 )
def cleanUp(self):
self.cleanUp_VAOs()
self.cleanUp_VBOs()
def cleanUp_VAOs(self):
for vao in self.vaos:
GL.glDeleteVertexArrays(vao)
def cleanUp_VBOs(self):
for vbo in self.vbos:
GL.glDeleteBuffers(vbo)
''' END '''