class HMultiColorVertex2D: size = 6 * sizeof(GLfloat) posOffset = 0 colorOffset = 2 * sizeof(GLfloat) def __init__(self): self.pos = HVertexPos2D() self.rgba = HColorRGBA() def __add__(self, other): if isinstance(other, HMultiColorVertex2D): return self.pos + self.rgba + other.pos + other.rgba elif isinstance(other, bytes): return self.pos + self.rgba + other def __radd__(self, other): if isinstance(other, HMultiColorVertex2D): return other.pos + other.rgba + self.pos + self.rgba elif isinstance(other, bytes): return other + self.pos + self.rgba
def __init__(self, locations): self.locations = locations self.VBOs = [] self.vptr_args = [] # VAO index or 'name' in OpenGL self._index = GLuint(0) glGenVertexArrays(1, self._index) # Plan: Store the arguments for a glVertex call, # then, when a buffer is added, activate the VBO # and call glVertexAttribPointer with stored arguments. offset = 0 count = 0 stride = 0 for loc, attribs in self.locations.items(): if 'vec' in attribs.type: size = int(attribs.type[3]) elif 'mat' in attribs.type: size = int(attribs.type[3])**2 elif 'float' in attribs.type: size = 1 else: raise TypeError("Unsupported type for VAO: " + attribs.type) self.vptr_args.append([ loc, size, GL_FLOAT, GL_FALSE, 0, # mulitply by stride later ctypes.c_void_p(offset) ]) offset += size * sizeof(ctypes.c_float) stride += size for arg in self.vptr_args: arg[4] = stride * sizeof(ctypes.c_float)
def size(self): return 2 * sizeof(GLfloat)
def size(self): return len(self._fields) * sizeof(GLfloat)
def prepare_float_buffer_data(float_array): buffer_data_type = GLfloat * len(float_array) return sizeof(buffer_data_type), buffer_data_type(*float_array)
def prepare_uint_buffer_data(int_array): buffer_data_type = GLuint * len(int_array) return sizeof(buffer_data_type), buffer_data_type(*int_array)