def render_overlays(self, arg):
     self.setup_scene(0, bind_bg=False, bind_hm=True)
     self.hm_shader.set_uniform_1i('stage', 2)
     self.hm_shader.set_uniform_1f('heatmap_mul', 1.0 if self.hm else 0.0)
     glEnable(GL_BLEND)
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
     glBlendEquation(GL_FUNC_ADD)
     glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, None)
     glDisable(GL_BLEND)
     return True
示例#2
0
    def on_draw(self, sink, context, sample):
        assert context == self.glcontext
        self.draws += 1

        assert context == self.glcontext
        frame_texture = _get_gl_texture_id(sample.get_buffer())
        overlay_buffer = self.get_front_buffer()
        overlay_texture = overlay_buffer.texture_id if overlay_buffer else 0

        glDisable(GL_BLEND)

        glBindVertexArray(self.vao)
        glActiveTexture(GL_TEXTURE0)
        glBindTexture(GL_TEXTURE_2D, frame_texture)

        self.shader.use()
        self.shader.set_uniform_1i('frame', 0)
        glUniformMatrix4fv(self.u_transformation, 1, GL_FALSE, self.matrix)

        glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, None)

        if overlay_texture:
            glBindTexture(GL_TEXTURE_2D, overlay_texture)
            glEnable(GL_BLEND)
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
            glBlendEquation(GL_FUNC_ADD)
            glUniformMatrix4fv(self.u_transformation, 1, GL_FALSE,
                               IDENTITY_MATRIX)
            glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, None)

        glActiveTexture(GL_TEXTURE0)
        glBindTexture(GL_TEXTURE_2D, 0)
        glDisable(GL_BLEND)
        context.clear_shader()
        glBindVertexArray(0)

        if overlay_buffer:
            overlay_buffer.set_sync_point()

        self.emit('drawn')

        if not self.fps_start:
            self.fps_start = time.monotonic()
        elapsed = time.monotonic() - self.fps_start
        if self.print_fps and elapsed > self.print_fps:
            incoming_fps = self.incoming_frames / elapsed
            draw_fps = self.draws / elapsed
            incoming_overlay_fps = self.incoming_overlays / elapsed
            render_fps = self.rendered_overlays / elapsed
            print(
                'glsvgoverlaysink: in frames {} ({:.2f} fps) svg {} ({:.2f} fps), rendered {} ({:.2f} fps), draw {} ({:.2f} fps)'
                .format(self.incoming_frames, self.incoming_frames / elapsed,
                        self.incoming_overlays,
                        self.incoming_overlays / elapsed,
                        self.rendered_overlays,
                        self.rendered_overlays / elapsed, self.draws,
                        self.draws / elapsed))
            self.incoming_frames = 0
            self.incoming_overlays = 0
            self.rendered_overlays = 0
            self.draws = 0
            self.fps_start = time.monotonic()

        return True