Ejemplo n.º 1
0
 def disableVertexAttribArray(self, varName):
     assert varName in self.shaderVars, 'Variable %s not found' % varName
     v = self.shaderVars[varName]
     q,l,t = v['qualifier'],v['location'],v['type']
     if l == -1:
         if not v['reported']:
             print('COULD NOT FIND %s' % (varName))
             v['reported'] = True
         return
     if DEBUG_PRINT:
         print('disable vertattrib array: %s (%s,%d,%s)' % (varName, q, l, t))
     bgl.glDisableVertexAttribArray(l)
     self.checkErrors(f'disableVertexAttribArray {varName}')
Ejemplo n.º 2
0
 def disableVertexAttribArray(self, varName):
     assert varName in self.shaderVars, 'Variable %s not found' % varName
     v = self.shaderVars[varName]
     q,l,t = v['qualifier'],v['location'],v['type']
     if l == -1:
         if not v['reported']:
             print('COULD NOT FIND %s' % (varName))
             v['reported'] = True
         return
     if DEBUG_PRINT:
         print('disable vertattrib array: %s (%s,%d,%s)' % (varName, q, l, t))
     bgl.glDisableVertexAttribArray(l)
     if self.checkErrors:
         self.drawing.glCheckError('disableVertexAttribArray %s' % varName)
Ejemplo n.º 3
0
Archivo: zu.py Proyecto: vktec/zu
    def prepare_viewport(self, ctx, dg):
        width, height = ctx.region.width, ctx.region.height
        self.dim = (width, height)

        buf = bgl.Buffer(bgl.GL_INT, 1)
        bgl.glGetIntegerv(bgl.GL_DRAW_FRAMEBUFFER_BINDING, buf)
        fb = buf[0]

        self.genfb(width, height)

        bgl.glGenVertexArrays(1, buf)
        self.vao = buf[0]
        bgl.glBindVertexArray(self.vao)

        quad = bgl.Buffer(bgl.GL_FLOAT, 2 * 4,
                          [0, 0, width, 0, width, height, 0, height])
        uv = bgl.Buffer(bgl.GL_FLOAT, 2 * 4, [0, 0, 1, 0, 1, 1, 0, 1])

        self.bind_display_space_shader(dg.scene)
        bgl.glGetIntegerv(bgl.GL_CURRENT_PROGRAM, buf)
        self.unbind_display_space_shader()
        self.quad_in = bgl.glGetAttribLocation(buf[0], "pos")
        self.uv_in = bgl.glGetAttribLocation(buf[0], "texCoord")

        bgl.glEnableVertexAttribArray(self.quad_in)
        bgl.glEnableVertexAttribArray(self.uv_in)

        self.vtx_buf = bgl.Buffer(bgl.GL_INT, 2)
        bgl.glGenBuffers(2, self.vtx_buf)
        bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vtx_buf[0])
        bgl.glBufferData(bgl.GL_ARRAY_BUFFER, 2 * 4 * 4, quad,
                         bgl.GL_STATIC_DRAW)
        bgl.glVertexAttribPointer(self.quad_in, 2, bgl.GL_FLOAT, bgl.GL_FALSE,
                                  0, None)

        bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vtx_buf[1])
        bgl.glBufferData(bgl.GL_ARRAY_BUFFER, 2 * 4 * 4, uv,
                         bgl.GL_STATIC_DRAW)
        bgl.glVertexAttribPointer(self.uv_in, 2, bgl.GL_FLOAT, bgl.GL_FALSE, 0,
                                  None)

        bgl.glDisableVertexAttribArray(self.quad_in)
        bgl.glDisableVertexAttribArray(self.uv_in)

        bgl.glBindFramebuffer(bgl.GL_FRAMEBUFFER, fb)
Ejemplo n.º 4
0
Archivo: zu.py Proyecto: vktec/zu
    def view_draw(self, ctx, dg):
        if self.scene is None:
            return

        buf = bgl.Buffer(bgl.GL_INT, 1)
        bgl.glGetIntegerv(bgl.GL_DRAW_FRAMEBUFFER_BINDING, buf)
        if buf[0] == 0:
            return

        width, height = ctx.region.width, ctx.region.height
        if self.dim != (width, height):
            self.delfb()
            self.prepare_viewport(ctx, dg)

        # Render the scene
        bgl.glViewport(0, 0, width, height)
        cam = ctx.region_data.perspective_matrix
        zu.scene_cam(self.scene, mat(cam))
        zu.scene_draw(self.scene, self.fb)

        # Copy the rendered scene to the viewport (through the color space adjustment shader)
        bgl.glBindFramebuffer(bgl.GL_FRAMEBUFFER, buf[0])
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)

        self.bind_display_space_shader(dg.scene)
        bgl.glBindVertexArray(self.vao)
        bgl.glEnableVertexAttribArray(self.quad_in)
        bgl.glEnableVertexAttribArray(self.uv_in)

        bgl.glActiveTexture(bgl.GL_TEXTURE0)
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.tex)
        bgl.glDrawArrays(bgl.GL_TRIANGLE_FAN, 0, 4)

        bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)
        bgl.glDisableVertexAttribArray(self.quad_in)
        bgl.glDisableVertexAttribArray(self.uv_in)
        bgl.glBindVertexArray(0)

        self.unbind_display_space_shader()
        bgl.glDisable(bgl.GL_BLEND)
Ejemplo n.º 5
0
def gpu_Indices_restore_state():
    bgl.glDisableVertexAttribArray(GPU_Indices.attr_pos)
    bgl.glDisableVertexAttribArray(GPU_Indices.attr_primitive_id)
    bgl.glBindVertexArray(0)
    _restore_shader_state(PreviousGLState)