Esempio n. 1
0
    def _loadTexture(self):
        """
        Load texture data from current image object
        """
        ix, iy, image = self.image_obj.getTextureData()

        # allocate texture object if never yet done [bruce 060207 revised all related code, to fix bug 1059]
        if self.tex_name is None:
            self.tex_name = glGenTextures(1)
            # note: by experiment (iMac G5 Panther), this returns a single number (1L, 2L, ...), not a list or tuple,
            # but for an argument >1 it returns a list of longs. We depend on this behavior here. [bruce 060207]

        # initialize texture data
        glBindTexture(GL_TEXTURE_2D,
                      self.tex_name)  # 2d texture (x and y size)

        glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
        self.have_mipmaps = False
        if debug_pref("smoother tiny textures",
                      Choice_boolean_False,
                      prefs_key=True):
            #bruce 060212 new feature; only takes effect when image is reloaded for some reason (like "load image" button)
            gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, ix, iy, GL_RGBA,
                              GL_UNSIGNED_BYTE, image)
            self.have_mipmaps = True
        else:
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ix, iy, 0, GL_RGBA,
                         GL_UNSIGNED_BYTE, image)
            # 0 is mipmap level, GL_RGBA is internal format, ix, iy is size, 0 is borderwidth,
            # and (GL_RGBA, GL_UNSIGNED_BYTE, image) describe the external image data. [bruce 060212 comment]

        ## self._initTextureEnv() #bruce 060207 do this in draw method, not here
        self.assy.o.gl_update()
        return
Esempio n. 2
0
    def gl_tex_image_2d(self, image, target=GL_TEXTURE_2D, internal_format=GL_RGBA, border=False, with_mipmaps=False):
        """Load the currently bound texture with data from an image, with automatic
        scaling to power-of-2 size and optional mipmap generation."""
        border = bool(border)
        if border and with_mipmaps:
            raise ValueError("Bordered texture cannot have mipmaps")
        b2 = 2 * border
        width, height = image.size
        twidth = pow2up(width - b2) + b2
        theight = pow2up(height - b2) + b2
        # print "GUI.GGLTextures.Texture.gl_tex_image_2d: before scaling: size =", (width, height) ###
        if width <> twidth or height <> theight:
            # print "GUI.GGLTextures.Texture.gl_tex_image_2d: scaling image to size", (twidth, theight) ###
            from Pixmaps import Pixmap

            image2 = Pixmap(twidth, theight)

            def scale(canvas):
                image.draw(canvas, (0, 0, width, height), (0, 0, twidth, theight))

            image2.with_canvas(scale)
            image = image2
        format, type, data = self._gl_get_texture_data(image)
        if with_mipmaps:
            # print "GUI.GGLTextures.Texture.gl_tex_image_2d: loading mipmaps" ###
            gluBuild2DMipmaps(target, internal_format, twidth, theight, format, type, data)
        else:
            # print "GUI.GGLTextures.Texture.gl_tex_image_2d: loading texture" ###
            glTexImage2D(target, 0, internal_format, twidth, theight, border, format, type, data)
Esempio n. 3
0
def make_texture(filename, mipmaps=False):
    image = pygame.image.load(filename)
    pixels = pygame.image.tostring(image, "RGBA", True)
    texture=glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, texture)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
        GL_LINEAR_MIPMAP_LINEAR if mipmaps else GL_LINEAR)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,     GL_CLAMP_TO_EDGE)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,     GL_CLAMP_TO_EDGE)
    if mipmaps:
        gluBuild2DMipmaps(
            GL_TEXTURE_2D,
            GL_RGBA8,
            image.get_width(),
            image.get_height(),
            GL_RGBA, GL_UNSIGNED_BYTE,
            pixels)
    else:
        glTexImage2D(
            GL_TEXTURE_2D, 0,
            GL_RGBA8,
            image.get_width(), image.get_height(), 0,
            GL_RGBA, GL_UNSIGNED_BYTE,
            pixels)
    return texture
Esempio n. 4
0
    def _loadTexture(self):
        """
        Load texture data from current image object
        """
        ix, iy, image = self.image_obj.getTextureData() 

        # allocate texture object if never yet done [bruce 060207 revised all related code, to fix bug 1059]
        if self.tex_name is None:
            self.tex_name = glGenTextures(1)
            # note: by experiment (iMac G5 Panther), this returns a single number (1L, 2L, ...), not a list or tuple,
            # but for an argument >1 it returns a list of longs. We depend on this behavior here. [bruce 060207]

        # initialize texture data
        glBindTexture(GL_TEXTURE_2D, self.tex_name)   # 2d texture (x and y size)

        glPixelStorei(GL_UNPACK_ALIGNMENT,1)
        self.have_mipmaps = False
        if debug_pref("smoother tiny textures", Choice_boolean_False, prefs_key = True):
            #bruce 060212 new feature; only takes effect when image is reloaded for some reason (like "load image" button)
            gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, ix, iy, GL_RGBA, GL_UNSIGNED_BYTE, image)
            self.have_mipmaps = True
        else:
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
                # 0 is mipmap level, GL_RGBA is internal format, ix, iy is size, 0 is borderwidth,
                # and (GL_RGBA, GL_UNSIGNED_BYTE, image) describe the external image data. [bruce 060212 comment]

        ## self._initTextureEnv() #bruce 060207 do this in draw method, not here
        self.assy.o.gl_update()
        return
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
0
 def loadTexture(self, nomFichier):
     """ Charge la texture de la facette """
     # On charge l'image dans pygame
     textureSurface = pygame.image.load(os.path.join('res', nomFichier))
     textureData = pygame.image.tostring(textureSurface, "RGBA", True)
     # Puis on l'associe à la texture dans OpenGL
     self.texID = glGenTextures(1)
     glBindTexture(GL_TEXTURE_2D, self.texID)
     gluBuild2DMipmaps(GL_TEXTURE_2D, 4, textureSurface.get_width(),
                       textureSurface.get_height(), GL_BGRA, GL_UNSIGNED_BYTE, textureData)
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
     return
Esempio n. 8
0
def MakeTexture(path):
	image = wx.Image(path)
	if image.HasAlpha():
		colorData = array.array('B', image.GetData()).tolist()
		alphaData = array.array('B', image.GetAlphaData()).tolist()
		data = array.array('B', itertools.chain(*zip(
			colorData[::3], colorData[1::3], colorData[2::3], alphaData))).tostring()
		format = GL_RGBA
	else:
		data = image.GetData()
		format = GL_RGB
	handle = glGenTextures(1)
	glBindTexture(GL_TEXTURE_2D, handle)
	gluBuild2DMipmaps(GL_TEXTURE_2D, format, image.GetWidth(), image.GetHeight(), format, GL_UNSIGNED_BYTE, data)
	glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
	return handle
Esempio n. 9
0
    def load_texture(filename="../texture.bmp"):
        img = Image.open(filename)
        img_data = numpy.array(list(img.getdata()), numpy.uint8)
        texture = glGenTextures(1)

        glBindTexture(GL_TEXTURE_2D, texture)
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                        GL_LINEAR_MIPMAP_NEAREST)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)

        gluBuild2DMipmaps(GL_TEXTURE_2D, 3, img.size[0], img.size[1], GL_RGB,
                          GL_UNSIGNED_BYTE, img_data)
        return texture
Esempio n. 10
0
    def load_texture(self, image_ref):
        textureSurface = image_ref
        colorkey = textureSurface.get_at((0, 0))
        textureSurface.set_colorkey(colorkey)

        rect = textureSurface.get_rect()
        textureData = pygame.image.tostring(textureSurface, "RGBA", 1)

        self.texture = glGenTextures(1)

        glBindTexture(GL_TEXTURE_2D, self.texture)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                        GL_LINEAR_MIPMAP_LINEAR)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, textureSurface.get_width(),
                          textureSurface.get_height(), GL_RGBA,
                          GL_UNSIGNED_BYTE, textureData)

        return rect.width, rect.height
Esempio n. 11
0
def loadTexture(image_obj, tex_name=0):  #e arg want_mipmaps
    """
    Load texture data from current image object;
    return have_mipmaps, tex_name
    (also leave that texture bound, BTW)
    """
    # note: some of this code has been copied into exprs/images.py, class
    # texture_holder [bruce 061125]
    ix, iy, image = image_obj.getTextureData()

    # allocate texture object if necessary
    if not tex_name:
        tex_name = glGenTextures(1)
        # It's deprecated to let this happen much. [070308]
        print "debug fyi: texture_helpers.loadTexture allocated tex_name %r" %\
              (tex_name,)
        # note: by experiment (iMac G5 Panther), this returns a single number
        # (1L, 2L, ...), not a list or tuple, but for an argument >1 it returns
        # a list of longs. We depend on this behavior here. [bruce 060207]
        tex_name = int(tex_name)  # make sure it worked as expected
        assert tex_name != 0

    # initialize texture data
    glBindTexture(GL_TEXTURE_2D, tex_name)  # 2d texture (x and y size)

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1)  ###k what's this?
    have_mipmaps = False
    ##want_mipmaps = debug_pref("smoother tiny textures",
    ##                          Choice_boolean_False, prefs_key = True)
    want_mipmaps = True
    if want_mipmaps:
        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, ix, iy, GL_RGBA,
                          GL_UNSIGNED_BYTE, image)
        have_mipmaps = True
    else:
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ix, iy, 0, GL_RGBA,
                     GL_UNSIGNED_BYTE, image)
        # 0 is mipmap level, GL_RGBA is internal format, ix, iy is size, 0
        # is borderwidth, and (GL_RGBA, GL_UNSIGNED_BYTE, image) describe
        # the external image data. [bruce 060212 comment]
    return have_mipmaps, tex_name
Esempio n. 12
0
def loadTexture(image_obj, tex_name = 0): #e arg want_mipmaps
    """
    Load texture data from current image object;
    return have_mipmaps, tex_name
    (also leave that texture bound, BTW)
    """
    # note: some of this code has been copied into exprs/images.py, class
    # texture_holder [bruce 061125]
    ix, iy, image = image_obj.getTextureData() 

    # allocate texture object if necessary
    if not tex_name:
        tex_name = glGenTextures(1)
        # It's deprecated to let this happen much. [070308]
        print "debug fyi: texture_helpers.loadTexture allocated tex_name %r" %\
              (tex_name,)
        # note: by experiment (iMac G5 Panther), this returns a single number
        # (1L, 2L, ...), not a list or tuple, but for an argument >1 it returns
        # a list of longs. We depend on this behavior here. [bruce 060207]
        tex_name = int(tex_name) # make sure it worked as expected
        assert tex_name != 0
    
    # initialize texture data
    glBindTexture(GL_TEXTURE_2D, tex_name)   # 2d texture (x and y size)

    glPixelStorei(GL_UNPACK_ALIGNMENT,1) ###k what's this?
    have_mipmaps = False
    ##want_mipmaps = debug_pref("smoother tiny textures",
    ##                          Choice_boolean_False, prefs_key = True)
    want_mipmaps = True
    if want_mipmaps: 
        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, ix, iy, GL_RGBA,
                          GL_UNSIGNED_BYTE, image)
        have_mipmaps = True
    else:
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ix, iy, 0, GL_RGBA,
                     GL_UNSIGNED_BYTE, image)
            # 0 is mipmap level, GL_RGBA is internal format, ix, iy is size, 0
            # is borderwidth, and (GL_RGBA, GL_UNSIGNED_BYTE, image) describe
            # the external image data. [bruce 060212 comment]
    return have_mipmaps, tex_name
Esempio n. 13
0
 def load(self):
     if self.loaded: return
     self._size, self._data, self.__id, mode = self.pool.load_image(
         self.name)
     glBindTexture(self._id)
     get_screen().bind_texture(self._id)
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                     GL_LINEAR_MIPMAP_NEAREST)
     if mode == GL_RGB:
         # Only this function works...
         gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, self._size[0],
                           self._size[1], GL_RGBA, GL_UNSIGNED_BYTE,
                           self.data)
         # glTexImage2D(GL_TEXTURE_2D, 1, 1, size[0], size[1], 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, data)
         # gluBuild2DMipmaps(GL_TEXTURE_2D, 4, size[0], size[1], GL_COLOR_INDEX, GL_UNSIGNED_BYTE, data)
     else:
         gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, size[0], size[1],
                           GL_RGBA, GL_UNSIGNED_BYTE, self.data)
     self.frame_width = self._size[0] / self.nbframes
     self.loaded = True
     for i in xrange(self.nbframes):
         self.frames.append((self.size, self.data, self._id))
Esempio n. 14
0
    def build(self):
        if self.loaded: return
        frames = []
        for i in self.filenames:
            size, data, _id, mode = self.pool.load_image(i)
            frames.append((size, data, _id))
            get_screen().bind_texture(_id)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                            GL_LINEAR_MIPMAP_NEAREST)
            if mode == GL_RGB:
                gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, size[0], size[1],
                                  GL_RGBA, GL_UNSIGNED_BYTE, data)
                #glTexImage2D(GL_TEXTURE_2D, 1, 1, size[0], size[1], 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, data)
                #gluBuild2DMipmaps(GL_TEXTURE_2D, 4, size[0], size[1], GL_COLOR_INDEX, GL_UNSIGNED_BYTE, data)
            else:
                gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, size[0], size[1],
                                  GL_RGBA, GL_UNSIGNED_BYTE, data)
        self.loaded = True
        self.frames = frames
        self.nbframes = len(self.filenames)
        self.nb_frames = len(self.filenames)

        for i in xrange(self.virtual_frames - len(self.orders)):
            if self.nb_frames:
                self.orders.append(i % self.nb_frames)
            else:
                self.orders.append(0)

        for i in xrange(self.virtual_frames - len(self.delays)):
            self.delays.append(100)

        for i in xrange(self.virtual_frames - len(self.hotspots)):
            self.hotspots.append(Point(0, 0))

        for i in xrange(self.virtual_frames - len(self.move_offsets)):
            self.move_offsets.append(Point(0, 0))
Esempio n. 15
0
    def gl_tex_image_2d(self,
                        image,
                        target=GL_TEXTURE_2D,
                        internal_format=GL_RGBA,
                        border=False,
                        with_mipmaps=False):
        """Load the currently bound texture with data from an image, with automatic
        scaling to power-of-2 size and optional mipmap generation."""
        border = bool(border)
        if border and with_mipmaps:
            raise ValueError("Bordered texture cannot have mipmaps")
        b2 = 2 * border
        width, height = image.size
        twidth = pow2up(width - b2) + b2
        theight = pow2up(height - b2) + b2
        #print "GUI.GGLTextures.Texture.gl_tex_image_2d: before scaling: size =", (width, height) ###
        if width <> twidth or height <> theight:
            #print "GUI.GGLTextures.Texture.gl_tex_image_2d: scaling image to size", (twidth, theight) ###
            from Pixmaps import Pixmap
            image2 = Pixmap(twidth, theight)

            def scale(canvas):
                image.draw(canvas, (0, 0, width, height),
                           (0, 0, twidth, theight))

            image2.with_canvas(scale)
            image = image2
        format, type, data = self._gl_get_texture_data(image)
        if with_mipmaps:
            #print "GUI.GGLTextures.Texture.gl_tex_image_2d: loading mipmaps" ###
            gluBuild2DMipmaps(target, internal_format, twidth, theight, format,
                              type, data)
        else:
            #print "GUI.GGLTextures.Texture.gl_tex_image_2d: loading texture" ###
            glTexImage2D(target, 0, internal_format, twidth, theight, border,
                         format, type, data)
Esempio n. 16
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_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
Esempio n. 17
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_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