Пример #1
0
void MipMapGenerator::generateMipMapCPU (Pixmap::ptr pixmap,int textureWidth,int textureHeight,bool disposePixmap) {
    Gdx::gl->glTexImage2D(GL_TEXTURE_2D, 0, pixmap->getGLInternalFormat(), pixmap->getWidth(), pixmap->getHeight(), 0,
                        pixmap->getGLFormat(), pixmap->getGLType(), pixmap->getPixels());
    if ((Gdx::gl20 == NULL) && textureWidth != textureHeight) { 
        throw std::runtime_error("texture width and height must be square when using mipmapping.");
    }
    
    int width = pixmap->getWidth() / 2;
    int height = pixmap->getHeight() / 2;
    int level = 1;
    
    while (width > 0 && height > 0) {
        Pixmap::ptr tmp(Pixmap::newFromRect(width, height, pixmap->getFormat(), pixmap->getType()));
        tmp->drawPixmap(*pixmap, 0, 0, pixmap->getWidth(), pixmap->getHeight(), 0, 0, width, height);
        if (level > 1 || disposePixmap) pixmap->dispose();

        pixmap.swap(tmp);

        Gdx::gl->glTexImage2D(GL_TEXTURE_2D, level, pixmap->getGLInternalFormat(), pixmap->getWidth(), pixmap->getHeight(), 0,
                            pixmap->getGLFormat(), pixmap->getGLType(), pixmap->getPixels());

        width = pixmap->getWidth() / 2;
        height = pixmap->getHeight() / 2;
        level++;
    }
    
    pixmap->dispose();
}
Пример #2
0
PixmapTextureData::PixmapTextureData(Pixmap::ptr _pixmap,
                                     const Pixmap::Format* format,
                                     bool useMipMaps, bool disposePixmap)
: pixmap(_pixmap),
format(format == NULL ? _pixmap->getFormat() : *format),
_useMipMaps(useMipMaps),
_disposePixmap(disposePixmap)
{
}