def render_single_texture(self, tex): glBindVertexArray(self.vao_id) glActiveTexture(GL_TEXTURE0) glBindTexture(GL_TEXTURE_2D, get_gl_texture_id(tex)) self.default_shader.use() self.default_shader.set_uniform_1i('image_tex', 0) glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, None) return True
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
def do_render(self, filter, in_tex): # Black borders. glClearColor(0.0, 0.0, 0.0, 0.0) glClear(GL_COLOR_BUFFER_BIT) glBindVertexArray(self.vao_id) glActiveTexture(GL_TEXTURE0) glBindTexture(GL_TEXTURE_2D, in_tex.tex_id) self.shader.use() self.shader.set_uniform_1f('u_scale_x', self.scale_x) self.shader.set_uniform_1f('u_scale_y', self.scale_y) glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, None)
def render_background(self, args): vid_buf, new_bg_buf = args # This is the mixing ratio of the instantaneous background estimate and # the current aggregated background estimate. ratio = max(0.001, 1.0 / max(1.0, self.frames / 2.0)) self.setup_scene(get_gl_texture_id(vid_buf)) self.hm_shader.set_uniform_1i('stage', 0) self.hm_shader.set_uniform_1f('ratio', ratio) glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, None) # Drop the ref to old background here in the GL thread. self.bg_buf = new_bg_buf return True
def render_anon_background(self, arg): self.setup_scene(0, bind_hm=False) self.hm_shader.set_uniform_1i('stage', 1) glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, None) return True
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