예제 #1
0
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
예제 #2
0
파일: vao.py 프로젝트: alexjdw/ping
    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)
예제 #3
0
 def size(self):
     return 2 * sizeof(GLfloat)
예제 #4
0
 def size(self):
     return len(self._fields) * sizeof(GLfloat)
예제 #5
0
def prepare_float_buffer_data(float_array):

    buffer_data_type = GLfloat * len(float_array)
    return sizeof(buffer_data_type), buffer_data_type(*float_array)
예제 #6
0
def prepare_uint_buffer_data(int_array):

    buffer_data_type = GLuint * len(int_array)
    return sizeof(buffer_data_type), buffer_data_type(*int_array)