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(); } }
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(); } }
void MipMapGenerator::generateMipMapDesktop (gdx_cpp::graphics::Pixmap::ptr pixmap,int textureWidth,int textureHeight,bool disposePixmap) { if (Gdx::graphics->isGL20Available() && (Gdx::graphics->supportsExtension("GL_ARB_framebuffer_object") || Gdx::graphics ->supportsExtension("GL_EXT_framebuffer_object"))) { Gdx::gl->glTexImage2D(GL_TEXTURE_2D, 0, pixmap->getGLInternalFormat(), pixmap->getWidth(), pixmap->getHeight(), 0, pixmap->getGLFormat(), pixmap->getGLType(), pixmap->getPixels()); Gdx::gl20->glGenerateMipmap(GL_TEXTURE_2D); if (disposePixmap) pixmap->dispose(); } else if (Gdx::graphics->supportsExtension("GL_SGIS_generate_mipmap")) { if ((Gdx::gl20 == NULL) && textureWidth != textureHeight) { throw std::runtime_error("texture width and height must be square when using mipmapping in OpenGL ES 1.x"); } Gdx::gl->glTexParameterf(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); Gdx::gl->glTexImage2D(GL_TEXTURE_2D, 0, pixmap->getGLInternalFormat(), pixmap->getWidth(), pixmap->getHeight(), 0, pixmap->getGLFormat(), pixmap->getGLType(), pixmap->getPixels()); if (disposePixmap) pixmap->dispose(); } else { generateMipMapCPU(pixmap, textureWidth, textureHeight, disposePixmap); } }
void MipMapGenerator::generateMipMapGLES20 (gdx_cpp::graphics::Pixmap::ptr pixmap,bool disposePixmap) { Gdx::gl->glTexImage2D(GL_TEXTURE_2D, 0, pixmap->getGLInternalFormat(), pixmap->getWidth(), pixmap->getHeight(), 0, pixmap->getGLFormat(), pixmap->getGLType(), pixmap->getPixels()); Gdx::gl20->glGenerateMipmap(GL_TEXTURE_2D); if (disposePixmap) pixmap->dispose(); }