示例#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();
    }
}
示例#4
0
    void create() {
        Texture::ptr texture = Texture::ptr(new Texture(1024,1024, Pixmap::Format::RGBA8888, Pixmap::Gdx2d));

        Pixmap::ptr pixmap = Pixmap::newFromRect(840, 480, Pixmap::Format::RGBA8888, Pixmap::Gdx2d);
        texture->setFilter(Texture::TextureFilter::Nearest, Texture::TextureFilter::Linear);
        texture->setWrap(Texture::TextureWrap::ClampToEdge, Texture::TextureWrap::ClampToEdge);
        pixmap->setColor(1.0f, 0.0f, 0.0f, 1.0f); // Red
        pixmap->drawLine(0, 0, 100, 100);
        
        pixmap->setColor(0.0f, 0.0f, 1.0f, 1.0f); // Blue
        pixmap->drawLine(100, 100, 200, 0);
        
        pixmap->setColor(0.0f, 1.0f, 0.0f, 1.0f); // Green
        pixmap->drawLine(100, 0, 100, 100);
        
        pixmap->setColor(1.0f, 1.0f, 1.0f, 1.0f); // White
        pixmap->drawCircle(400, 300, 100);

        texture->draw(*pixmap, 0, 0);
        region = new TextureRegion(texture, 0, 0, 800, 480);
        batch = new SpriteBatch();

        Pixmap::ptr px = Pixmap::newFromRect(512, 1024, Pixmap::Format::RGBA8888, Pixmap::Gdx2d);
        for (int y = 0; y < pixmap->getHeight(); y++) { // 1024
            for (int x = 0; x < pixmap->getWidth(); x++) { // 512
                                pixmap->getPixel(x, y);
                        }
        }
        px->dispose();
    }