summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2013-10-03 13:40:02 +0300
committerTomi Korpipää <tomi.korpipaa@digia.com>2013-10-03 13:46:02 +0300
commit56d71710d5c87047815c2f2a3686ecb01332da7c (patch)
tree4ba14151b6b0f321b1eea2a84371ce3399140679 /src
parenteca4f57c854874ec6e4f616e663b43675d76cff4 (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')
-rw-r--r--src/datavisualization/engine/surface3drenderer.cpp14
-rw-r--r--src/datavisualization/utils/texturehelper.cpp54
-rw-r--r--src/datavisualization/utils/texturehelper_p.h3
3 files changed, 22 insertions, 49 deletions
diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp
index cebe906e..9f40e410 100644
--- a/src/datavisualization/engine/surface3drenderer.cpp
+++ b/src/datavisualization/engine/surface3drenderer.cpp
@@ -484,7 +484,7 @@ void Surface3DRenderer::drawSlicedScene()
GLfloat scaleX;
GLfloat scaleXBackground;
- GLfloat offset;
+ GLfloat offset = 0.0f;
if (m_cachedSelectionMode == QDataVis::SelectionModeSliceRow) {
scaleX = m_surfaceScaleX;
scaleXBackground = m_scaleXWithBackground;
@@ -1694,15 +1694,6 @@ void Surface3DRenderer::updateSelectionTexture()
// ID color so that each vertex (data point) has 4x4 pixel area of ID color
int idImageWidth = (m_sampleSpace.width() - 1) * 4;
int idImageHeight = (m_sampleSpace.height() - 1) * 4;
-
-#if defined(Q_OS_ANDROID)
- // Android requires power-of-two textures
- GLuint temp;
- idImageWidth = Utils::getNearestPowerOfTwo(idImageWidth, temp);
- idImageHeight = Utils::getNearestPowerOfTwo(idImageHeight, temp);
- // TODO: This is not enough, the selection texture itself needs to be modified for Android (colors?, scaling)
-#endif
-
int stride = idImageWidth * 4 * sizeof(uchar); // 4 = number of color components (rgba)
uchar *bits = new uchar[idImageWidth * idImageHeight * 4 * sizeof(uchar)];
@@ -1735,7 +1726,8 @@ void Surface3DRenderer::updateSelectionTexture()
}
// Move the ID image (bits) to the texture
- m_selectionTexture = m_textureHelper->create2DTexture(bits, idImageWidth, idImageHeight);
+ QImage image = QImage(bits, idImageWidth, idImageHeight, QImage::Format_RGB32);
+ m_selectionTexture = m_textureHelper->create2DTexture(image, false, false, false);
// Release the temp bits allocation
delete[] bits;
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;
diff --git a/src/datavisualization/utils/texturehelper_p.h b/src/datavisualization/utils/texturehelper_p.h
index e5f54d00..f7779b59 100644
--- a/src/datavisualization/utils/texturehelper_p.h
+++ b/src/datavisualization/utils/texturehelper_p.h
@@ -43,8 +43,7 @@ class TextureHelper : protected QOpenGLFunctions
// Ownership of created texture is transferred to caller
GLuint create2DTexture(const QImage &image, bool useTrilinearFiltering = false,
- bool convert = true);
- GLuint create2DTexture(const uchar *image, int width, int height);
+ bool convert = true, bool smoothScale = true);
GLuint createCubeMapTexture(const QImage &image, bool useTrilinearFiltering = false);
// Returns selection framebuffer and inserts generated texture id to texture parameters
GLuint createSelectionBuffer(const QSize &size, GLuint &texture, GLuint &depthTexture);