Пример #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
void Texture::uploadImageData (const gdx_cpp::graphics::Pixmap::ptr& pixmap) {
    if (enforcePotImages && Gdx::gl20 == NULL
            && (! gdx_cpp::math::utils::isPowerOfTwo(data->getWidth()) || !gdx_cpp::math::utils::isPowerOfTwo(data->getHeight())))
    {
        throw std::runtime_error("Texture.cpp: texture width and height must be powers of two");
    }

    bool disposePixmap = false;

    Pixmap::ptr tmp = pixmap;

    if (*data->getFormat() != pixmap->getFormat()) {
        tmp = Pixmap::newFromPixmap(*pixmap);
        tmp->drawPixmap(*pixmap, 0, 0, 0, 0, pixmap->getWidth(), pixmap->getHeight());
        disposePixmap = true;
    }

    Gdx::gl->glBindTexture(GL_TEXTURE_2D, glHandle);
    Gdx::gl->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    if (data->useMipMaps()) {
        glutils::MipMapGenerator::generateMipMap(tmp, tmp->getWidth(), tmp->getHeight(), disposePixmap);
    } else {
        Gdx::gl->glTexImage2D(GL_TEXTURE_2D, 0, tmp->getGLInternalFormat(), tmp->getWidth(), tmp->getHeight(), 0,
                              tmp->getGLFormat(), tmp->getGLType(), tmp->getPixels());

        if (disposePixmap) tmp->dispose();
    }
}
Пример #3
0
void Texture::uploadImageData (const gdx_cpp::graphics::Pixmap::ptr pixmap) {
    if (enforcePotImages && Gdx::gl20 == NULL
            && (! gdx_cpp::math::utils::isPowerOfTwo(data->getWidth()) || !gdx_cpp::math::utils::isPowerOfTwo(data->getHeight())))
    {
        Gdx::app->error("Texture.cpp", "texture width and height must be powers of two");
    }

    bool disposePixmap = false;

    Pixmap::ptr tmp = pixmap;
    
    if (*data->getFormat() != pixmap->getFormat()) {
        tmp = Pixmap::ptr(new Pixmap(pixmap->getWidth(), pixmap->getHeight(), *data->getFormat()));
        Pixmap::Blending blend = Pixmap::getBlending();
        Pixmap::setBlending(Pixmap::None);
        tmp->drawPixmap(*pixmap, 0, 0, 0, 0, pixmap->getWidth(), pixmap->getHeight());
        Pixmap::setBlending(blend);
        disposePixmap = true;
    }

    Gdx::gl->glBindTexture(GL10::GL_TEXTURE_2D, glHandle);
    if (data->useMipMaps()) {
        glutils::MipMapGenerator::generateMipMap(*tmp, tmp->getWidth(), tmp->getHeight(), disposePixmap);
    } else {
        Gdx::gl->glTexImage2D(GL10::GL_TEXTURE_2D, 0, tmp->getGLInternalFormat(), tmp->getWidth(), tmp->getHeight(), 0,
                            tmp->getGLFormat(), tmp->getGLType(), tmp->getPixels());
        if (disposePixmap) tmp->dispose();
    }
}