def deleteImage(self): """ Deletes a texture. """ if self.tex_image: glDeleteTextures(self.tex_image) self.tex_image = None
def init_back_texture(self, width, height): if self.fbo is None: self.fbo = glGenFramebuffers(1) glActiveTexture(GL_TEXTURE0 + 1) if self.bfTex is not None: glDeleteTextures([self.bfTex]) self.bfTex = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, self.bfTex) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) w = int(width) h = int(height) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, w, h, 0, GL_RGBA, GL_FLOAT, None) glBindFramebuffer(GL_FRAMEBUFFER, self.fbo) glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, self.bfTex, 0) glBindFramebuffer(GL_FRAMEBUFFER, 0) glBindTexture(GL_TEXTURE_2D, 0)
def get_gl_info_string(glpane): # grantham 20051129 """Return a string containing some useful information about the OpenGL implementation. Use the GL context from the given QGLWidget glpane (by calling glpane.makeCurrent()). """ glpane.makeCurrent() #bruce 070308 added glpane arg and makeCurrent call gl_info_string = '' gl_info_string += 'GL_VENDOR : "%s"\n' % glGetString(GL_VENDOR) gl_info_string += 'GL_VERSION : "%s"\n' % glGetString(GL_VERSION) gl_info_string += 'GL_RENDERER : "%s"\n' % glGetString(GL_RENDERER) gl_info_string += 'GL_EXTENSIONS : "%s"\n' % glGetString(GL_EXTENSIONS) from utilities.debug_prefs import debug_pref, Choice_boolean_False if debug_pref("get_gl_info_string call glAreTexturesResident?", Choice_boolean_False): # Give a practical indication of how much video memory is available. # Should also do this with VBOs. # I'm pretty sure this code is right, but PyOpenGL seg faults in # glAreTexturesResident, so it's disabled until I can figure that # out. [grantham] [bruce 070308 added the debug_pref] all_tex_in = True tex_bytes = '\0' * (512 * 512 * 4) tex_names = [] tex_count = 0 tex_names = glGenTextures(1024) glEnable(GL_TEXTURE_2D) while all_tex_in: glBindTexture(GL_TEXTURE_2D, tex_names[tex_count]) gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 512, 512, GL_RGBA, GL_UNSIGNED_BYTE, tex_bytes) tex_count += 1 glTexCoord2f(0.0, 0.0) glBegin(GL_QUADS) glVertex2f(0.0, 0.0) glVertex2f(1.0, 0.0) glVertex2f(1.0, 1.0) glVertex2f(0.0, 1.0) glEnd() glFinish() residences = glAreTexturesResident(tex_names[:tex_count]) all_tex_in = reduce(lambda a,b: a and b, residences) # bruce 070308 sees this exception from this line: # TypeError: reduce() arg 2 must support iteration glDisable(GL_TEXTURE_2D) glDeleteTextures(tex_names) gl_info_string += "Could create %d 512x512 RGBA resident textures\n" \ % tex_count return gl_info_string
def get_gl_info_string(glpane): # grantham 20051129 """Return a string containing some useful information about the OpenGL implementation. Use the GL context from the given QGLWidget glpane (by calling glpane.makeCurrent()). """ glpane.makeCurrent() #bruce 070308 added glpane arg and makeCurrent call gl_info_string = '' gl_info_string += 'GL_VENDOR : "%s"\n' % glGetString(GL_VENDOR) gl_info_string += 'GL_VERSION : "%s"\n' % glGetString(GL_VERSION) gl_info_string += 'GL_RENDERER : "%s"\n' % glGetString(GL_RENDERER) gl_info_string += 'GL_EXTENSIONS : "%s"\n' % glGetString(GL_EXTENSIONS) from utilities.debug_prefs import debug_pref, Choice_boolean_False if debug_pref("get_gl_info_string call glAreTexturesResident?", Choice_boolean_False): # Give a practical indication of how much video memory is available. # Should also do this with VBOs. # I'm pretty sure this code is right, but PyOpenGL seg faults in # glAreTexturesResident, so it's disabled until I can figure that # out. [grantham] [bruce 070308 added the debug_pref] all_tex_in = True tex_bytes = '\0' * (512 * 512 * 4) tex_names = [] tex_count = 0 tex_names = glGenTextures(1024) glEnable(GL_TEXTURE_2D) while all_tex_in: glBindTexture(GL_TEXTURE_2D, tex_names[tex_count]) gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 512, 512, GL_RGBA, GL_UNSIGNED_BYTE, tex_bytes) tex_count += 1 glTexCoord2f(0.0, 0.0) glBegin(GL_QUADS) glVertex2f(0.0, 0.0) glVertex2f(1.0, 0.0) glVertex2f(1.0, 1.0) glVertex2f(0.0, 1.0) glEnd() glFinish() residences = glAreTexturesResident(tex_names[:tex_count]) all_tex_in = reduce(lambda a, b: a and b, residences) # bruce 070308 sees this exception from this line: # TypeError: reduce() arg 2 must support iteration glDisable(GL_TEXTURE_2D) glDeleteTextures(tex_names) gl_info_string += "Could create %d 512x512 RGBA resident textures\n" \ % tex_count return gl_info_string
def __del__(self): """Destructor. Destroys texture and sampler objects associated with the instance. """ glDeleteTextures(self.tex_id) glDeleteSamplers(1, [self.sampler]) self.tex_id = self.sampler = 0
def release(self) -> None: """Delete associated textures. We need to use this instead of ``__del__`` because by the time the finaliser is called the GLContext might already have been destroyed. """ glDeleteTextures([self._texture_id])
def deleteImages(self, imageArray): ''' Decreases the reference count of the texture of each image by one, and deletes it if nothing is using it anymore ''' for image in imageArray: self.qimages[image.imagepath][2] -= 1 if self.qimages[image.imagepath][2] <= 0: #print("deleting texture", image.textureId) glDeleteTextures(image.textureId) del self.qimages[image.imagepath] self.images[image.layer].remove(image) self.allimgs.remove(image)
def _texture_release(*largs): global _texture_release_list for texture_id in _texture_release_list: # try/except are here to prevent an error like this : # Exception TypeError: "'NoneType' object is not callable" # in <bound method Texture.__del__ of <pymt.texture.Texture # object at 0x3a1acb0>> ignored # # It occured only when leaving the application. # So, maybe numpy or pyopengl is unloaded, and have weird things happen. # try: if OpenGLversion < (3, 0, 1) and have_numpy: glDeleteTextures(numpy.array(texture_id)) else: glDeleteTextures(texture_id) except: pass # let the list to 0 _texture_release_list = []
def __del__(self): if hasattr(self, 'textureID'): # This may be set by MeshViewer from OpenGL.GL import glDeleteTextures glDeleteTextures([self.textureID])
def __del__(self): if hasattr(self, 'textureID'): from OpenGL.GL import glDeleteTextures glDeleteTextures([self.textureID])
def wipe(self): glDeleteTextures([self.texture])
def __del__(self): glDeleteTextures([self.texid])
def __del__(self): glDeleteTextures(1, self.m_RendererID)
def __del__(self): glDeleteTextures([self._texture_id])
def get_gl_info_string(glpane): # grantham 20051129 """ Return a string containing some useful information about the OpenGL implementation. Use the GL context from the given QGLWidget glpane (by calling glpane.makeCurrent()). """ glpane.makeCurrent() #bruce 070308 added glpane arg and makeCurrent call gl_info_string = '' gl_info_string += 'GL_VENDOR : "%s"\n' % glGetString(GL_VENDOR) gl_info_string += 'GL_VERSION : "%s"\n' % glGetString(GL_VERSION) gl_info_string += 'GL_RENDERER : "%s"\n' % glGetString(GL_RENDERER) gl_extensions = glGetString(GL_EXTENSIONS) gl_extensions = gl_extensions.strip() gl_extensions = gl_extensions.replace(" ", "\n* ") gl_info_string += 'GL_EXTENSIONS : \n* %s\n' % gl_extensions if debug_pref("Graphics Card Info: call glAreTexturesResident?", Choice_boolean_False): # Give a practical indication of how much video memory is available. # Should also do this with VBOs. # I'm pretty sure this code is right, but PyOpenGL seg faults in # glAreTexturesResident, so it's disabled until I can figure that # out. [grantham] [bruce 070308 added the debug_pref] all_tex_in = True tex_bytes = '\0' * (512 * 512 * 4) tex_names = [] tex_count = 0 tex_names = glGenTextures(1024) glEnable(GL_TEXTURE_2D) while all_tex_in: glBindTexture(GL_TEXTURE_2D, tex_names[tex_count]) gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 512, 512, GL_RGBA, GL_UNSIGNED_BYTE, tex_bytes) tex_count += 1 glTexCoord2f(0.0, 0.0) glBegin(GL_QUADS) glVertex2f(0.0, 0.0) glVertex2f(1.0, 0.0) glVertex2f(1.0, 1.0) glVertex2f(0.0, 1.0) glEnd() glFinish() residences = glAreTexturesResident(tex_names[:tex_count]) all_tex_in = reduce(lambda a, b: a and b, residences) # bruce 070308 sees this exception from this line: # TypeError: reduce() arg 2 must support iteration glDisable(GL_TEXTURE_2D) glDeleteTextures(tex_names) gl_info_string += "Could create %d 512x512 RGBA resident textures\n" \ % tex_count pass if True: ## or could be a debug_pref("Graphics Card Info: get all GL_MAX symbols?") #bruce 090314 new feature import OpenGL.GL symbols = [x for x in dir(OpenGL.GL) if x.startswith('GL_MAX_')] symbols.sort() gl_info_string += '\n' for symbol in symbols: try: numeric_symbol = getattr(OpenGL.GL, symbol) intval = glGetInteger(numeric_symbol) except: # this happens to most symbols, not sure why if debug_flags.atom_debug: print_compact_traceback("%s = ??: " % symbol) # overkill, only the exception itself matters # typical output (on Bruce's MacBookPro, 090314): ## GL_MAX_4D_TEXTURE_SIZE_SGIS = ??: ## <type 'exceptions.KeyError'>: ## ('Unknown specifier GL_MAX_4D_TEXTURE_SIZE_SGIS (33080)', ## 'Failure in cConverter <OpenGL.converters.SizedOutput object at 0x1457fab0>', ## [GL_MAX_4D_TEXTURE_SIZE_SGIS], 1, <OpenGL.wrapper.glGetIntegerv object at 0x1458aa30>) ## [graphics_card_info.py:122] [wrapper.py:676] [converters.py:195] [converters.py:234] pass pass ## gl_info_string += "%s = ??\n" % symbol else: gl_info_string += "%s = %r\n" % (symbol, intval) continue pass return gl_info_string
def get_gl_info_string(glpane): # grantham 20051129 """ Return a string containing some useful information about the OpenGL implementation. Use the GL context from the given QGLWidget glpane (by calling glpane.makeCurrent()). """ glpane.makeCurrent() #bruce 070308 added glpane arg and makeCurrent call gl_info_string = '' gl_info_string += 'GL_VENDOR : "%s"\n' % glGetString(GL_VENDOR) gl_info_string += 'GL_VERSION : "%s"\n' % glGetString(GL_VERSION) gl_info_string += 'GL_RENDERER : "%s"\n' % glGetString(GL_RENDERER) gl_extensions = glGetString(GL_EXTENSIONS) gl_extensions = gl_extensions.strip() gl_extensions = gl_extensions.replace(" ", "\n* ") gl_info_string += 'GL_EXTENSIONS : \n* %s\n' % gl_extensions if debug_pref("Graphics Card Info: call glAreTexturesResident?", Choice_boolean_False): # Give a practical indication of how much video memory is available. # Should also do this with VBOs. # I'm pretty sure this code is right, but PyOpenGL seg faults in # glAreTexturesResident, so it's disabled until I can figure that # out. [grantham] [bruce 070308 added the debug_pref] all_tex_in = True tex_bytes = '\0' * (512 * 512 * 4) tex_names = [] tex_count = 0 tex_names = glGenTextures(1024) glEnable(GL_TEXTURE_2D) while all_tex_in: glBindTexture(GL_TEXTURE_2D, tex_names[tex_count]) gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 512, 512, GL_RGBA, GL_UNSIGNED_BYTE, tex_bytes) tex_count += 1 glTexCoord2f(0.0, 0.0) glBegin(GL_QUADS) glVertex2f(0.0, 0.0) glVertex2f(1.0, 0.0) glVertex2f(1.0, 1.0) glVertex2f(0.0, 1.0) glEnd() glFinish() residences = glAreTexturesResident(tex_names[:tex_count]) all_tex_in = reduce(lambda a,b: a and b, residences) # bruce 070308 sees this exception from this line: # TypeError: reduce() arg 2 must support iteration glDisable(GL_TEXTURE_2D) glDeleteTextures(tex_names) gl_info_string += "Could create %d 512x512 RGBA resident textures\n" \ % tex_count pass if True: ## or could be a debug_pref("Graphics Card Info: get all GL_MAX symbols?") #bruce 090314 new feature import OpenGL.GL symbols = [x for x in dir(OpenGL.GL) if x.startswith('GL_MAX_')] symbols.sort() gl_info_string += '\n' for symbol in symbols: try: numeric_symbol = getattr(OpenGL.GL, symbol) intval = glGetInteger(numeric_symbol) except: # this happens to most symbols, not sure why if debug_flags.atom_debug: print_compact_traceback( "%s = ??: " % symbol ) # overkill, only the exception itself matters # typical output (on Bruce's MacBookPro, 090314): ## GL_MAX_4D_TEXTURE_SIZE_SGIS = ??: ## <type 'exceptions.KeyError'>: ## ('Unknown specifier GL_MAX_4D_TEXTURE_SIZE_SGIS (33080)', ## 'Failure in cConverter <OpenGL.converters.SizedOutput object at 0x1457fab0>', ## [GL_MAX_4D_TEXTURE_SIZE_SGIS], 1, <OpenGL.wrapper.glGetIntegerv object at 0x1458aa30>) ## [graphics_card_info.py:122] [wrapper.py:676] [converters.py:195] [converters.py:234] pass pass ## gl_info_string += "%s = ??\n" % symbol else: gl_info_string += "%s = %r\n" % (symbol, intval) continue pass return gl_info_string
def _close(self): glDeleteTextures([self._gl_texture_atlas])
def free_texture(): glDeleteTextures([gl_id])