def do_gl_start(self): frag_stage = GstGL.GLSLStage.new_default_fragment(self.context) vert_stage = GstGL.GLSLStage.new_with_string(self.context, GL_VERTEX_SHADER, GstGL.GLSLVersion.NONE, GstGL.GLSLProfile.COMPATIBILITY | GstGL.GLSLProfile.ES, VERTEX_SHADER) self.shader = GstGL.GLShader.new(self.context) self.shader.compile_attach_stage(vert_stage) self.shader.compile_attach_stage(frag_stage) self.shader.link() a_position = self.shader.get_attribute_location('a_position') a_texcoord = self.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.wrappedOperation(a_position, 2, GL_FLOAT, GL_FALSE, 0, None) glBindBuffer(GL_ARRAY_BUFFER, self.texcoords_buffer); glVertexAttribPointer.wrappedOperation(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) return True
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
def init_gl(self, glcontext): assert not self.shader assert glcontext == self.glcontext frag_stage = GstGL.GLSLStage.new_default_fragment(self.glcontext) vert_stage = GstGL.GLSLStage.new_with_string( self.glcontext, GL_VERTEX_SHADER, GstGL.GLSLVersion.NONE, GstGL.GLSLProfile.COMPATIBILITY | GstGL.GLSLProfile.ES, VERTEX_SHADER_SRC) self.shader = GstGL.GLShader.new(self.glcontext) self.shader.compile_attach_stage(vert_stage) self.shader.compile_attach_stage(frag_stage) self.shader.link() self.u_transformation = glGetUniformLocation.wrappedOperation( self.shader.get_program_handle(), 'u_transformation') a_position = self.shader.get_attribute_location('a_position') a_texcoord = self.shader.get_attribute_location('a_texcoord') self.vao = glGenVertexArrays(1) glBindVertexArray(self.vao) 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 = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, self.vbo_indices) glBufferData(GL_ARRAY_BUFFER, ArrayDatatype.arrayByteCount(INDICES), INDICES, GL_STATIC_DRAW) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, self.vbo_indices) glBindBuffer(GL_ARRAY_BUFFER, self.positions_buffer) glVertexAttribPointer.wrappedOperation(a_position, 2, GL_FLOAT, GL_FALSE, 0, None) glBindBuffer(GL_ARRAY_BUFFER, self.texcoords_buffer) glVertexAttribPointer.wrappedOperation(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)