def __del__(self): try: GL.glDeleteBuffers(2, self.vertex_buffer) GL.glDeleteVertexArrays(1, self.vertex_array) GL.glBindTexture(GL.GL_TEXTURE_2D, 0) except: #TODO: Make sure GL objects are deleted in the correct context pass
def view_draw(self, context, depsgraph): profiler = cProfile.Profile() global PROFILE if PROFILE: profiler.enable() if self.request_new_frame: self.profiling_data = io.StringIO() # Get viewport resolution resolution = context.region.width, context.region.height #Save FBO for later use fbo = GL.gl_buffer(GL.GL_INT, 1) GL.glGetIntegerv(GL.GL_FRAMEBUFFER_BINDING, fbo) # Generating a VAO before loading/rendering fixes an error where the viewport # freezes in edit mode. Why ??? I have no idea. ¯\_(ツ)_/¯ # TODO: try to load meshes the normal way, without lazy VAO generation. # (Would need a Pipeline refactor) VAO = GL.gl_buffer(GL.GL_INT, 1) GL.glGenVertexArrays(1, VAO) #render scene = self.get_scene(context, depsgraph, self.request_scene_update) self.request_scene_update = False render_texture = self.get_pipeline().render( resolution, scene, False, self.request_new_frame)['COLOR'] self.request_new_frame = False if MaltMaterial.INITIALIZED == False: #First viewport render can happen before initialization self.request_new_frame = True #Render to viewport self.bind_display_space_shader(depsgraph.scene_eval) if self.display_draw is None or self.display_draw.resolution != resolution: self.display_draw = DisplayDraw(resolution) self.display_draw.draw(fbo, render_texture) self.unbind_display_space_shader() if self.get_pipeline().needs_more_samples(): self.tag_redraw() reset_GL_state() GL.glDeleteVertexArrays(1, VAO) if PROFILE: profiler.disable() stats = pstats.Stats(profiler, stream=self.profiling_data) stats.strip_dirs() stats.sort_stats(pstats.SortKey.CUMULATIVE) stats.print_stats() if self.get_pipeline().needs_more_samples() == False: PROFILE = False with open(REPORT_PATH, 'w') as file: file.write(self.profiling_data.getvalue())
def gl_delete(self): GL.glDeleteBuffers(2, self.vertex_buffer) GL.glDeleteVertexArrays(1, self.vertex_array) GL.glBindTexture(GL.GL_TEXTURE_2D, 0)