示例#1
0
    def _delete(shaders_id, prog_id):
        # Check to see if the context was already cleaned up from program
        # shut down. If so, we don't need to delete the shaders.
        if gl.current_context is None:
            return

        for shader_id in shaders_id:
            gl.glDetachShader(prog_id, shader_id)

        gl.glDeleteProgram(prog_id)
示例#2
0
    def delete_shader_program(self, program_id):
        """Safely delete a Shader Program belonging to this context.

        This method behaves similarly to `delete_texture`, though for
        ``glDeleteProgram`` instead of ``glDeleteTextures``.

        :Parameters:
            `program_id` : int
                The OpenGL name of the Shader Program to delete.

        .. versionadded:: 2.0
        """
        if gl.current_context is self:
            gl.glDeleteProgram(program_id)
        else:
            self.object_space.doomed_shader_programs.append(program_id)
示例#3
0
    def compile(self):
        if self.handle is not None:
            glDeleteProgram(self.handle)
        self.handle = glCreateProgram()

        if len(self.vertex_shader_name) > 0:
            with open(self.vertex_shader_name) as f:
                vertex_source = f.readlines()
            self.create_shader(vertex_source, GL_VERTEX_SHADER)

        if len(self.fragment_shader_name) > 0:
            with open(self.fragment_shader_name) as f:
                fragment_source = f.readlines()
            self.create_shader(fragment_source, GL_FRAGMENT_SHADER)

        self.link()
示例#4
0
    def _invalidate_device_objects(self):
        if self._vao_handle.value > -1:
            gl.glDeleteVertexArrays(1, byref(self._vao_handle))
        if self._vbo_handle.value > -1:
            gl.glDeleteBuffers(1, byref(self._vbo_handle))
        if self._elements_handle.value > -1:
            gl.glDeleteBuffers(1, byref(self._elements_handle))
        self._vao_handle = self._vbo_handle = self._elements_handle = 0

        gl.glDeleteProgram(self._shader_handle)
        self._shader_handle = 0

        if self._font_texture.value > -1:
            gl.glDeleteTextures(1, byref(self._font_texture))
        self.io.fonts.texture_id = 0
        self._font_texture = 0
示例#5
0
文件: test.py 项目: gabdube/pyshaders
 def test_freeing(self):
     " Test if programs are freed correctly "
     prog = ShaderProgram.new_program()
     vert, frag = self.get_objects()
     prog.attach(vert, frag)
     
     # Warning, borrowed_obj do not own the underlying shader so it will not be freed automatically
     borrowed_prog = ShaderProgram(glCreateProgram(), owned=False)
     
     pid = prog.pid
     pid2 = borrowed_prog.pid
     del prog
     del borrowed_prog
     gc.collect()
     
     self.assertEqual(glIsProgram(pid), GL_FALSE, 'Program was not freed')
     self.assertEqual(glIsProgram(pid2), GL_TRUE, 'Program was freed')
     self.assertFalse(vert.valid(), 'vert was not freed')
     self.assertFalse(frag.valid(), 'frag was not freed')
     
     # Free the program object
     glDeleteProgram(pid2)        
示例#6
0
    def set_current(self):
        if not self.canvas:
            raise RuntimeError('Canvas has not been attached')

        # XXX not per-thread
        gl.current_context = self

        # XXX
        gl_info.set_active_context()

        if not self._info:
            self._info = gl_info.GLInfo()
            self._info.set_active_context()

        # Release Textures, Buffers, and VAOs on this context scheduled for
        # deletion. Note that the garbage collector may introduce a race
        # condition, so operate on a copy, and clear the list afterwards.
        if self.object_space.doomed_textures:
            textures = self.object_space.doomed_textures[:]
            textures = (gl.GLuint * len(textures))(*textures)
            gl.glDeleteTextures(len(textures), textures)
            self.object_space.doomed_textures.clear()
        if self.object_space.doomed_buffers:
            buffers = self.object_space.doomed_buffers[:]
            buffers = (gl.GLuint * len(buffers))(*buffers)
            gl.glDeleteBuffers(len(buffers), buffers)
            self.object_space.doomed_buffers.clear()
        if self.object_space.doomed_vaos:
            vaos = self.object_space.doomed_vaos[:]
            vaos = (gl.GLuint * len(vaos))(*vaos)
            gl.glDeleteVertexArrays(len(vaos), vaos)
            self.object_space.doomed_vaos.clear()
        if self.object_space.doomed_shader_programs:
            for program_id in self.object_space.doomed_shader_programs:
                gl.glDeleteProgram(program_id)
            self.object_space.doomed_shader_programs.clear()
	def __del__(self): # don't forget to delete the program when the Shader object is deleted!
		gl.glDeleteProgram(self.program)
示例#8
0
 def __del__(self):
     if self.owned and self.valid():
         self.detach(*self.shaders(
         ))  # Detach and mark for deletion all attahed shader object
         glDeleteProgram(self.pid)
示例#9
0
 def release(self):
     if self.prog_id != 0:
         gl.glDeleteProgram(self.prog_id)
         self.prog_id = 0
示例#10
0
 def __del__(self):
     self.disable()
     gl.glDeleteProgram(self.handle)
示例#11
0
 def __del__(self):
     gl.glDeleteProgram(self.program)
示例#12
0
文件: shader.py 项目: artyprog/p5
 def delete(self):
     """Delete the current shader."""
     gl.glDeleteProgram(self._pid)
     gl.glDeleteShader(self._fid)
     gl.glDeleteShader(self._vid)
示例#13
0
 def __del__(self):
     gl.glDeleteProgram(self.__value)