示例#1
0
    def destroy(self, display=None):
        if self.active:
            ###### brute force tidying experiment TODO find nicer way ########
            if display:
                func_list = [
                    [
                        opengles.glIsBuffer, opengles.glDeleteBuffers,
                        dict(display.vbufs_dict.items() +
                             display.ebufs_dict.items())
                    ],
                    [
                        opengles.glIsTexture, opengles.glDeleteTextures,
                        display.textures_dict
                    ], [opengles.glIsProgram, opengles.glDeleteProgram, 0],
                    [opengles.glIsShader, opengles.glDeleteShader, 0]
                ]
                i_ct = (ctypes.c_int * 1)(0)  #convoluted 0
                for func in func_list:
                    max_streak = 100
                    streak_start = 0
                    if func[2]:  # list to work through
                        for i in func[2]:
                            if func[0](func[2][i]
                                       [0]) == 1:  #check if i exists as a name
                                func[1](1, ctypes.byref(func[2][i][0]))
                    else:  # just do sequential numbers
                        for i in xrange(10000):
                            if func[0](i) == 1:  #check if i exists as a name
                                i_ct[0] = i  #convoluted 1
                                func[1](ctypes.byref(i_ct))
                                streak_start = i
                            elif i > (streak_start + 100):
                                break
            ##################################################################
            openegl.eglSwapBuffers(self.display, self.surface)
            openegl.eglMakeCurrent(self.display, EGL_NO_SURFACE,
                                   EGL_NO_SURFACE, EGL_NO_CONTEXT)
            openegl.eglDestroySurface(self.display, self.surface)
            openegl.eglDestroyContext(self.display, self.context)
            openegl.eglTerminate(self.display)
            if PLATFORM == PLATFORM_PI:
                self.dispman_update = bcm.vc_dispmanx_update_start(0)
                bcm.vc_dispmanx_element_remove(self.dispman_update,
                                               self.dispman_element)
                bcm.vc_dispmanx_update_submit_sync(self.dispman_update)
                bcm.vc_dispmanx_display_close(self.dispman_display)

            self.active = False
            if pi3d.USE_PYGAME:
                import pygame
                pygame.display.quit()
            elif PLATFORM != PLATFORM_PI and PLATFORM != PLATFORM_ANDROID:
                xlib.XCloseDisplay(self.d)
示例#2
0
    def destroy(self, display=None):
        if self.active:
            ###### brute force tidying experiment TODO find nicer way ########
            if display:

                func_list = [
                    [
                        opengles.glIsBuffer, opengles.glDeleteBuffers,
                        display.vbufs_dict.update(display.ebufs_dict)
                    ],  # merge two dictionaries with update()
                    [
                        opengles.glIsTexture, opengles.glDeleteTextures,
                        display.textures_dict
                    ],
                    [opengles.glIsProgram, opengles.glDeleteProgram, 0],
                    [opengles.glIsShader, opengles.glDeleteShader, 0]
                ]

                i_ct = (ctypes.c_int * 1)(0)  #convoluted 0
                for fi, func in enumerate(func_list):
                    streak_start = 0
                    if func[2]:  # list to work through
                        for i in func[2]:
                            if func[0](func[2][i]
                                       [0]) == 1:  #check if i exists as a name
                                try:
                                    func[1](1, byref(func[2][i][0]))
                                except:
                                    pass  # TODO find why this might fail (maybe race condition)
                    else:  # just do sequential numbers
                        for i in range(1, 10000):  # name 0 not to be deleted
                            if func[0](i) == 1:  #check if i exists as a name
                                if fi < 2:  # buffers or textures needs number to delete
                                    i_ct[
                                        0] = i  # pass as pointer to array of uint
                                    try:
                                        func[1](1, byref(i_ct))
                                    except:
                                        pass  # TODO not sure why this silently fails and prevents the rest of the tidy up
                                else:  # program and shader just one arg
                                    try:
                                        func[1](i)
                                    except:
                                        pass  # TODO see above
                                streak_start = i
                            elif i > (streak_start + 100):
                                break
            ##################################################################
            openegl.eglSwapBuffers(self.display, self.surface)
            openegl.eglMakeCurrent(self.display, EGL_NO_SURFACE,
                                   EGL_NO_SURFACE, EGL_NO_CONTEXT)
            openegl.eglDestroySurface(self.display, self.surface)
            openegl.eglDestroyContext(self.display, self.context)
            openegl.eglTerminate(self.display)
            if PLATFORM == PLATFORM_PI:
                self.dispman_update = bcm.vc_dispmanx_update_start(0)
                bcm.vc_dispmanx_element_remove(self.dispman_update,
                                               self.dispman_element)
                bcm.vc_dispmanx_update_submit_sync(self.dispman_update)
                bcm.vc_dispmanx_display_close(self.dispman_display)

            self.active = False
            if pi3d.USE_PYGAME:
                import pygame
                pygame.display.quit()
            elif PLATFORM != PLATFORM_PI and PLATFORM != PLATFORM_ANDROID:
                xlib.XCloseDisplay(self.d)