Пример #1
0
    def createImage(self, qimagepath, layer, textureRect, drawRect, hidden = False, dynamicity = GL_STATIC_DRAW_ARB):
        '''
        FILL IN LATER PLOX
        '''

        qimg = None
        layer = int(layer)

        if textureRect[2] == -1:
            if qimg == None:
                qimg = QImage(qimagepath)
            textureRect[2] = qimg.width()

        if textureRect[3] == -1:
            if qimg == None:
                qimg = QImage(qimagepath)
            textureRect[3] = qimg.height()

        if drawRect[2] == -1:
            if qimg == None:
                qimg = QImage(qimagepath)
            drawRect[2] = qimg.width()

        if drawRect[3] == -1:
            if qimg == None:
                qimg = QImage(qimagepath)
            drawRect[3] = qimg.height()

        image = Image(qimagepath, qimg, textureRect, drawRect, layer, hidden, dynamicity)

        texture = None
        found = False

        for qimgpath in self.qimages:
            if qimgpath == qimagepath and self.qimages[qimgpath][1] > 0:
                texture = self.qimages[qimgpath][0]
                found = True

        if found == False:
            if qimg == None:
                qimg = QImage(qimagepath)
                
            if self.texext == GL_TEXTURE_2D:
                w = nextPowerOfTwo(qimg.width())
                h = nextPowerOfTwo(qimg.height())
                if w != qimg.width() or h != qimg.height():
                    qimg = qimg.scaled(w, h)
                
            img = self.convertToGLFormat(qimg)
            texture = glGenTextures(1)
            imgdata = img.bits().asstring(img.numBytes())

            glBindTexture(self.texext, texture)

            glTexParameteri(self.texext, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
            glTexParameteri(self.texext, GL_TEXTURE_MAG_FILTER, GL_NEAREST)

            glTexImage2D(self.texext, 0, GL_RGBA, img.width(), img.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, imgdata);

            self.qimages[qimagepath] = [texture, 1] #texture, reference count
        else:
            self.qimages[qimagepath][1] += 1

        image.textureId = texture

        if layer not in self.images:
            self.images[layer] = []
            self.layers = self.images.keys()
            self.layers.sort()

        self.images[layer].append(image)

        if Globals.vbos:
            image.VBO = self.VBO

            self.fillBuffers(image)
            if len(self.qimages[qimagepath]) == 2:
                self.qimages[qimagepath].append(image.offset)

            self.calculateVBOList(image)

        return image
Пример #2
0
    def createImage(self, qimagepath, layer, textureRect, drawRect, hidden = False, dynamicity = GL_STATIC_DRAW_ARB):
        '''
        Creates an rggTile instance, uploads the correct image to GPU if not in cache, and some other helpful things.
        '''
        #print "requested to create", qimagepath, layer, textureRect, drawRect, hidden
        layer = int(layer)
        texture = None
        found = False

        if qimagepath in self.qimages:
            qimg = self.qimages[qimagepath][0]
            if self.qimages[qimagepath][2] > 0:
                texture = self.qimages[qimagepath][1]
                found = True
        else:
            qimg = QImage(qimagepath)
            print "created", qimagepath

        if textureRect[2] == -1:
            textureRect[2] = qimg.width() - 1

        if textureRect[3] == -1:
            textureRect[3] = qimg.height() - 1

        if drawRect[2] == -1:
            drawRect[2] = qimg.width()

        if drawRect[3] == -1:
            drawRect[3] = qimg.height()

        image = Image(qimagepath, qimg, textureRect, drawRect, layer, hidden, dynamicity, self)

        if found == False:
            if self.npot == 0:
                w = nextPowerOfTwo(qimg.width())
                h = nextPowerOfTwo(qimg.height())
                if w != qimg.width() or h != qimg.height():
                    qimg = qimg.scaled(w, h)
     
            img = self.convertToGLFormat(qimg)
            texture = int(glGenTextures(1))
            try:
                imgdata = img.bits().asstring(img.numBytes())
            except:
                import sys
                print "requested to create", qimagepath, layer, textureRect, drawRect, hidden
                for x in [0, 1, 2, 3]:
                    f_code = sys._getframe(x).f_code #really bad hack to get the filename and number
                    print "Doing it wrong in " + f_code.co_filename + ":" + str(f_code.co_firstlineno)
            
            print "created texture", texture

            glBindTexture(self.texext, texture)

            if self.anifilt > 1.0:
                glTexParameterf(self.texext, GL_TEXTURE_MAX_ANISOTROPY_EXT, self.anifilt)
            if self.npot == 3 and self.mipminfilter != -1:
                glTexParameteri(self.texext, GL_TEXTURE_MIN_FILTER, self.mipminfilter)
                glTexParameteri(self.texext, GL_TEXTURE_MAG_FILTER, self.magfilter)
            elif self.npot == 2 and self.mipminfilter != -1:
                glTexParameteri(self.texext, GL_TEXTURE_MIN_FILTER, self.mipminfilter)
                glTexParameteri(self.texext, GL_TEXTURE_MAG_FILTER, self.magfilter)
                glTexParameteri(self.texext, GL_GENERATE_MIPMAP, GL_TRUE)
            else:
                glTexParameteri(self.texext, GL_TEXTURE_MIN_FILTER, self.minfilter)
                glTexParameteri(self.texext, GL_TEXTURE_MAG_FILTER, self.magfilter)

            format = GL_RGBA
            if self.compress:
                format = self.compress

            glTexImage2D(self.texext, 0, GL_RGBA, img.width(), img.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, imgdata);

            if self.npot == 3 and self.mipminfilter != -1:
                glEnable(GL_TEXTURE_2D)
                glGenerateMipmap(GL_TEXTURE_2D)
            
            self.qimages[qimagepath] = [qimg, texture, 1] #texture, reference count
        else:
            self.qimages[qimagepath][2] += 1

        image.textureId = texture

        if layer not in self.images:
            self.images[layer] = []
            self.layers = self.images.keys()
            self.layers.sort()
            image.createLayer = True

        self.images[layer].append(image)

        if self.vbos:
            image.VBO = self.VBO
            if not self.fillBuffers(image):
                self.calculateVBOList(image)

        return image