diff options
author | Tomi Korpipää <tomi.korpipaa@digia.com> | 2013-10-03 13:40:02 +0300 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@digia.com> | 2013-10-03 13:46:02 +0300 |
commit | 56d71710d5c87047815c2f2a3686ecb01332da7c (patch) | |
tree | 4ba14151b6b0f321b1eea2a84371ce3399140679 /src/datavisualization/utils/texturehelper.cpp | |
parent | eca4f57c854874ec6e4f616e663b43675d76cff4 (diff) |
Selection fixed for Android surface
Task-number: QTRD-2368
Change-Id: I7b6bf5f16111a7dfdb49cb391b29872bf12ac8fd
Change-Id: I7b6bf5f16111a7dfdb49cb391b29872bf12ac8fd
Reviewed-by: Mika Salmela <mika.salmela@digia.com>
Diffstat (limited to 'src/datavisualization/utils/texturehelper.cpp')
-rw-r--r-- | src/datavisualization/utils/texturehelper.cpp | 54 |
1 files changed, 18 insertions, 36 deletions
diff --git a/src/datavisualization/utils/texturehelper.cpp b/src/datavisualization/utils/texturehelper.cpp index 4c7d71a5..25fe17ac 100644 --- a/src/datavisualization/utils/texturehelper.cpp +++ b/src/datavisualization/utils/texturehelper.cpp @@ -34,66 +34,49 @@ TextureHelper::~TextureHelper() { } -GLuint TextureHelper::create2DTexture(const QImage &image, bool useTrilinearFiltering, bool convert) +GLuint TextureHelper::create2DTexture(const QImage &image, bool useTrilinearFiltering, + bool convert, bool smoothScale) { if (image.isNull()) return 0; - QImage texImage; + QImage texImage = image; #if defined(Q_OS_ANDROID) GLuint temp; //qDebug() << "old size" << image.size(); GLuint imageWidth = Utils::getNearestPowerOfTwo(image.width(), temp); - //qDebug() << "new width" << imageWidth << "padding" << temp; GLuint imageHeight = Utils::getNearestPowerOfTwo(image.height(), temp); - //qDebug() << "new height" << imageHeight << "padding" << temp; - texImage = image.scaled(imageWidth, imageHeight, Qt::IgnoreAspectRatio, - Qt::SmoothTransformation); + if (smoothScale) { + texImage = image.scaled(imageWidth, imageHeight, Qt::IgnoreAspectRatio, + Qt::SmoothTransformation); + } else { + texImage = image.scaled(imageWidth, imageHeight, Qt::IgnoreAspectRatio); + } //qDebug() << "new size" << texImage.size(); -#else - texImage = image; #endif GLuint textureId; glGenTextures(1, &textureId); glBindTexture(GL_TEXTURE_2D, textureId); - if (convert) { - QImage glTexture = convertToGLFormat(texImage); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, glTexture.width(), glTexture.height(), - 0, GL_RGBA, GL_UNSIGNED_BYTE, glTexture.bits()); - } else { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texImage.width(), texImage.height(), - 0, GL_RGBA, GL_UNSIGNED_BYTE, texImage.bits()); - } - if (useTrilinearFiltering) { + if (convert) + texImage = convertToGLFormat(texImage); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texImage.width(), texImage.height(), + 0, GL_RGBA, GL_UNSIGNED_BYTE, texImage.bits()); + if (smoothScale) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + else + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + if (useTrilinearFiltering) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glGenerateMipmap(GL_TEXTURE_2D); } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } glBindTexture(GL_TEXTURE_2D, 0); return textureId; } -GLuint TextureHelper::create2DTexture(const uchar *image, int width, int height) -{ - GLuint textureId; - glGenTextures(1, &textureId); - glBindTexture(GL_TEXTURE_2D, textureId); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, - 0, GL_RGBA, GL_UNSIGNED_BYTE, image); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - glBindTexture(GL_TEXTURE_2D, 0); - return textureId; -} - GLuint TextureHelper::createCubeMapTexture(const QImage &image, bool useTrilinearFiltering) { if (image.isNull()) @@ -105,13 +88,12 @@ GLuint TextureHelper::createCubeMapTexture(const QImage &image, bool useTrilinea QImage glTexture = convertToGLFormat(image); glTexImage2D(GL_TEXTURE_CUBE_MAP, 0, GL_RGBA, glTexture.width(), glTexture.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, glTexture.bits()); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if (useTrilinearFiltering) { - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glGenerateMipmap(GL_TEXTURE_CUBE_MAP); } else { glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } glBindTexture(GL_TEXTURE_2D, 0); return textureId; |