Exemple #1
0
    def ensurePow2(self, image):
        """Ensure that the PIL image is pow2 x pow2 dimensions

        Note:
            This method will create a _new_ PIL image if
            the image is not a valid size (It will use BICUBIC
            filtering (from PIL) to do the resizing). Otherwise
            just returns the same image object.
        """

        if self.NPOT_SUPPORT is None:
            self.__class__.NPOT_SUPPORT = texture_non_power_of_two.glInitTextureNonPowerOfTwoARB(
            )
            if not self.NPOT_SUPPORT:
                log.warn(
                    "Implementation requires Power-of-Two textures (very old device?)"
                )
        if not self.NPOT_SUPPORT:
            try:
                from PIL import Image
            except ImportError as err:
                # old style?
                import Image
            BICUBIC = Image.BICUBIC
            ### Now resize non-power-of-two images...
            # should check whether it needs it first!
            newSize = bestSize(image.size[0]), bestSize(image.size[1])
            if newSize != image.size:
                log.warn(
                    "Non-power-of-2 image %s found resizing: %s",
                    image.size,
                    image.info,
                )
                image = image.resize(newSize, BICUBIC)
        return image
Exemple #2
0
    def ensurePow2( self, image ):
        """Ensure that the PIL image is pow2 x pow2 dimensions

        Note:
            This method will create a _new_ PIL image if
            the image is not a valid size (It will use BICUBIC
            filtering (from PIL) to do the resizing). Otherwise
            just returns the same image object.
        """
        
        if self.NPOT_SUPPORT is None:
            self.__class__.NPOT_SUPPORT = texture_non_power_of_two.glInitTextureNonPowerOfTwoARB()
            if not self.NPOT_SUPPORT:
                log.warn( "Implementation requires Power-of-Two textures (very old device?)" )
        if not self.NPOT_SUPPORT:
            try:
                from PIL import Image
            except ImportError, err:
                # old style?
                import Image
            BICUBIC = Image.BICUBIC
            ### Now resize non-power-of-two images...
            # should check whether it needs it first!
            newSize = bestSize(image.size[0]),bestSize(image.size[1])
            if newSize != image.size:
                log.warn( 
                    "Non-power-of-2 image %s found resizing: %s", 
                    image.size, image.info,
                )
                image = image.resize( newSize, BICUBIC )
Exemple #3
0
 def __init__(self):
     self.blank=0	#self.get(join('Resources','blank.png'))
     self.texs={}
     self.terraintexs=[]	# terrain textures will not be reloaded
     self.stats={}
     # Must be after init
     self.maxtexsize = glGetString(GL_VENDOR)=='Humper' and 2048 or glGetIntegerv(GL_MAX_TEXTURE_SIZE)	# VirtualBox limitation - https://www.virtualbox.org/ticket/5720
     self.npot=glInitTextureNonPowerOfTwoARB()
     self.compress=glInitTextureCompressionARB()
     self.s3tc=self.compress and glInitTextureCompressionS3TcEXT()
     self.bgra=glInitBgraEXT()
     if self.compress: glHint(GL_TEXTURE_COMPRESSION_HINT, GL_NICEST)	# Texture compression appears severe on Mac, but this doesn't help
     glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST)	# prefer speed
     if glGetString(GL_VERSION) >= '1.2':
         self.clampmode=GL_CLAMP_TO_EDGE
     else:
         self.clampmode=GL_CLAMP
Exemple #4
0
 def __init__(self):
     self.blank = 0  #self.get(join('Resources','blank.png'))
     self.texs = {}
     self.terraintexs = []  # terrain textures will not be reloaded
     self.stats = {}
     # Must be after init
     self.maxtexsize = glGetString(
         GL_VENDOR) == 'Humper' and 2048 or glGetIntegerv(
             GL_MAX_TEXTURE_SIZE
         )  # VirtualBox limitation - https://www.virtualbox.org/ticket/5720
     self.npot = glInitTextureNonPowerOfTwoARB()
     self.compress = glInitTextureCompressionARB()
     self.s3tc = self.compress and glInitTextureCompressionS3TcEXT()
     self.bgra = glInitBgraEXT()
     if self.compress:
         glHint(
             GL_TEXTURE_COMPRESSION_HINT, GL_NICEST
         )  # Texture compression appears severe on Mac, but this doesn't help
     glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST)  # prefer speed
     if glGetString(GL_VERSION) >= '1.2':
         self.clampmode = GL_CLAMP_TO_EDGE
     else:
         self.clampmode = GL_CLAMP
Exemple #5
0
 def __init__(self):
     self.num = None
     self.supportsNpot = npot.glInitTextureNonPowerOfTwoARB()