Exemplo n.º 1
0
    def _render(self, rect):
        gl.enable(gl.SCISSOR_TEST)
        gl.enable(gl.CULL_FACE)

        if (not self._render_to_texture and self._depth_n_stencil) or \
            (self._render_to_texture and self._fb_depth_n_stencil):
            gl.enable(gl.DEPTH_TEST)
            gl.enable(gl.DEPTH_STENCIL)
        
        gl.viewport(rect.x, rect.y, rect.width, rect.height)
        gl.scissor(rect.x, rect.y, rect.width, rect.height)

        for com in self._queue:
            com[0](*com[1:])

        self._queue = []
        gl.disable(gl.SCISSOR_TEST)
        gl.disable(gl.CULL_FACE)
        gl.disable(gl.DEPTH_TEST)

        gl.useProgram(0)
        gl.bindBuffer(gl.ARRAY_BUFFER, 0)
        gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, 0)
        gl.bindFramebuffer(gl.FRAMEBUFFER, 0)
        gl.viewport(0.0, 0.0, self.stage.stageWidth, self.stage.stageHeight)
Exemplo n.º 2
0
    def setVertexBufferAt(self, locname, vbuffer, offset=0, 
                                        format=VertexBuffer3DFormat.FLOAT_1):
        loc = gl.getAttribLocation(self._current_prog.gl_program, locname)
        gl.bindBuffer(gl.ARRAY_BUFFER, vbuffer.gl_buffer)

        tp = gl.FLOAT
        numbytes = 4
        dimension = 4
        try:
            dimension = {
                VertexBuffer3DFormat.BYTES_4: 4,
                VertexBuffer3DFormat.FLOAT_1: 1,
                VertexBuffer3DFormat.FLOAT_2: 2,
                VertexBuffer3DFormat.FLOAT_3: 3,
                VertexBuffer3DFormat.FLOAT_4: 4,
            }[format]
        except KeyError:
            raise ValueError('Buffer format "%s" is not supported' % \
                                                                str(format))

        self._do(gl.bindBuffer, gl.ARRAY_BUFFER, vbuffer.gl_buffer)
        self._do(gl.enableVertexAttribArray, loc)
        self._do(gl.vertexAttribPointer, loc, dimension, tp, False, 
                    vbuffer.data32_per_vertex * numbytes, offset * numbytes)
Exemplo n.º 3
0
 def upload(self, data):
     ndata = struct.pack('%sH' % len(data), *data)
     gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, self.gl_buffer)
     gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, ndata, gl.STATIC_DRAW)
     self.num_indeces = len(data)
Exemplo n.º 4
0
 def upload(self, data):
     gl.bindBuffer(gl.ARRAY_BUFFER, self.gl_buffer)
     gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW)