Esempio n. 1
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();
    }
}
Esempio n. 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())))
    {
        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();
    }
}