-
Notifications
You must be signed in to change notification settings - Fork 0
/
GLLayout.py
44 lines (32 loc) · 1.03 KB
/
GLLayout.py
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
from OpenGL.GL import *
from ctypes import *
import numpy as np
class vertAttrib:
def __init__(self, typeGL, typeC, size = 1, needNormalisation = GL_FALSE):
self.typeGL = typeGL
self.typeC = typeC
self.size = size
self.needNormalisation = needNormalisation
self.pointerOffset = 0
self.width = 0
def update(self):
self.width = sizeof(self.typeC) * self.size
class Layout:
def __init__(self, attribs = []):
self.attribs = list(attribs)
self.stride = 0
def addAttribF(self, size, needNormalisation = GL_FALSE):
newAttrib = vertAttrib(GL_FLOAT, c_float, size, needNormalisation)
self.attribs.append(newAttrib)
def update(self):
offset = 0
for attrib in self.attribs:
attrib.update()
attrib.pointerOffset = offset
offset += attrib.width
self.stride = offset
def bind(self, vBuffer):
self.update()
for i, attrib in enumerate(self.attribs):
glEnableVertexAttribArray(i)
glVertexAttribPointer(i, attrib.size, attrib.typeGL, attrib.needNormalisation, self.stride, vBuffer + attrib.pointerOffset)