def delete_context(self):
     from OpenGL.EGL import eglDestroyContext, eglTerminate
     if self._egl_display is not None:
         if self._egl_context is not None:
             eglDestroyContext(self._egl_display, self._egl_context)
             self._egl_context = None
         eglTerminate(self._egl_display)
         self._egl_display = None
Example #2
0
    def close(self):
        """Destroy the OpenGL context attached to this renderer.

        Warning
        -------
        Once this has been called, the OpenGLRenderer object should be discarded.
        """
        # Delete shaders
        if self._full_shader:
            glDeleteProgram(self._full_shader)
            self._full_shader = None
        if self._depth_shader:
            glDeleteProgram(self._depth_shader)
            self._depth_shader = None

        # Delete all mesh geometry
        if self._buffers:
            glDeleteBuffers(len(self._buffers), self._buffers)
            self._buffers = None

        # Delete framebuffers and renderbuffers
        if self._colorbuf and self._depthbuf:
            glDeleteRenderbuffers(2, [self._colorbuf, self._depthbuf])
            self._colorbuf = None
            self._depthbuf = None

        if self._framebuf:
            glDeleteFramebuffers(1, [self._framebuf])
            self._framebuf = None

        OpenGL.contextdata.cleanupContext()
        if _USE_EGL_OFFSCREEN:
            from OpenGL.EGL import eglDestroySurface, eglDestroyContext, eglTerminate
            if self._egl_display is not None:
                if self._egl_context is not None:
                    eglDestroyContext(self._egl_display, self._egl_context)
                    self._egl_context = None
                if self._egl_surface:
                    eglDestroySurface(self._egl_display, self._egl_surface)
                    self._egl_surface = None
                eglTerminate(self._egl_display)
                self._egl_display = None
        else:
            if self._window is not None:
                try:
                    self._window.context.destroy()
                    self._window.close()
                except:
                    pass
                self._window = None