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() glu_info.set_active_context() # Implement workarounds if not self._info: self._info = gl_info.GLInfo() self._info.set_active_context() for attr, check in self._workaround_checks: setattr(self, attr, check(self._info)) # Release textures on this context scheduled for deletion 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 = [] # Release buffers on this context scheduled for deletion 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 = []
def delete_texture(self, texture_id): '''Safely delete a texture belonging to this context. Usually, the texture is released immediately using ``glDeleteTextures``, however if another context that does not share this context's object space is currently active, the deletion will be deferred until an appropriate context is activated. :Parameters: `texture_id` : int The OpenGL name of the texture to delete. ''' if self.object_space is gl.current_context.object_space: id = gl.GLuint(texture_id) gl.glDeleteTextures(1, id) else: self.object_space._doomed_textures.append(texture_id)