Exemplo n.º 1
0
 def update_heatmap(self, glcontext, heatmap):
     glActiveTexture(GL_TEXTURE0 + 1)
     glBindTexture(GL_TEXTURE_2D, self.hm_tex_id)
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
     glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
                     heatmap.shape[1], heatmap.shape[0],
                     GL_RGBA, GL_FLOAT, heatmap)
Exemplo n.º 2
0
 def update_heatmap(self, glcontext, hm_data):
     hm_w, hm_h = self.engine.heatmap_size
     glActiveTexture(GL_TEXTURE0 + 1)
     glBindTexture(GL_TEXTURE_2D, self.hm_tex_id)
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
     glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, hm_w, hm_h, GL_RED, GL_FLOAT,
                     hm_data)
Exemplo n.º 3
0
    def update_aggregate_heatmap(self, glcontext):
        # Since we're in a different thread, check if this is even ready yet.
        if self.heatmap_sum is None: return

        if self.ahm:
            agg_heatmap = self.heatmap_sum / np.max(self.heatmap_sum)
        else:
            agg_heatmap = np.zeros_like(self.heatmap_sum)
        hm_w, hm_h = self.engine.heatmap_size
        glActiveTexture(GL_TEXTURE0 + 3)
        glBindTexture(GL_TEXTURE_2D, self.agg_hm_tex_id)
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, hm_w, hm_h, GL_RED, GL_FLOAT,
                        agg_heatmap)
Exemplo n.º 4
0
    def init_gl(self, glcontext):
        #TODO deinit at some point
        assert not self.glcontext

        vert_stage = GstGL.GLSLStage.new_default_vertex(glcontext)
        frag_stage = GstGL.GLSLStage.new_with_string(
            glcontext, GL_FRAGMENT_SHADER, GstGL.GLSLVersion.NONE,
            GstGL.GLSLProfile.COMPATIBILITY | GstGL.GLSLProfile.ES,
            FRAGMENT_SHADER_SRC)
        self.hm_shader = GstGL.GLShader.new(glcontext)
        self.hm_shader.compile_attach_stage(vert_stage)
        self.hm_shader.compile_attach_stage(frag_stage)
        self.hm_shader.link()

        self.default_shader = GstGL.GLShader.new_default(glcontext)
        a_position = self.default_shader.get_attribute_location('a_position')
        a_texcoord = self.default_shader.get_attribute_location('a_texcoord')

        self.vao_id = glGenVertexArrays(1)
        glBindVertexArray(self.vao_id)

        self.positions_buffer = glGenBuffers(1)
        glBindBuffer(GL_ARRAY_BUFFER, self.positions_buffer)
        glBufferData(GL_ARRAY_BUFFER, ArrayDatatype.arrayByteCount(POSITIONS),
                     POSITIONS, GL_STATIC_DRAW)

        self.texcoords_buffer = glGenBuffers(1)
        glBindBuffer(GL_ARRAY_BUFFER, self.texcoords_buffer)
        glBufferData(GL_ARRAY_BUFFER, ArrayDatatype.arrayByteCount(TEXCOORDS),
                     TEXCOORDS, GL_STATIC_DRAW)

        self.vbo_indices_buffer = glGenBuffers(1)
        glBindBuffer(GL_ARRAY_BUFFER, self.vbo_indices_buffer)
        glBufferData(GL_ARRAY_BUFFER, ArrayDatatype.arrayByteCount(INDICES),
                     INDICES, GL_STATIC_DRAW)

        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.vbo_indices_buffer)
        glBindBuffer(GL_ARRAY_BUFFER, self.positions_buffer)
        glVertexAttribPointer.baseFunction(a_position, 2, GL_FLOAT, GL_FALSE,
                                           0, None)
        glBindBuffer(GL_ARRAY_BUFFER, self.texcoords_buffer)
        glVertexAttribPointer.baseFunction(a_texcoord, 2, GL_FLOAT, GL_FALSE,
                                           0, None)
        glEnableVertexAttribArray(a_position)
        glEnableVertexAttribArray(a_texcoord)

        glBindVertexArray(0)
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)
        glBindBuffer(GL_ARRAY_BUFFER, 0)

        hm_w, hm_h = self.get_heatmap_texture_size()

        texture_ids = glGenTextures(1)
        self.hm_tex_id = texture_ids

        glActiveTexture(GL_TEXTURE0 + 1)
        glBindTexture(GL_TEXTURE_2D, self.hm_tex_id)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, hm_w, hm_h, 0, GL_RGBA,
                     GL_FLOAT, None)

        self.glcontext = glcontext