summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-06-09 04:59:16 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-06-09 04:59:16 (GMT)
commitedd535defde42cf4b57c6144b6ba8a0607363d5e (patch)
treed77e95ab7335f3af8feb1b60a440df3b49504386 /src/declarative
parenta276e872e83e0c2f04a367299580ef787b6efc51 (diff)
downloadQt-edd535defde42cf4b57c6144b6ba8a0607363d5e.zip
Qt-edd535defde42cf4b57c6144b6ba8a0607363d5e.tar.gz
Qt-edd535defde42cf4b57c6144b6ba8a0607363d5e.tar.bz2
Fix OpenGL texture access issues
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/fx/qfximage.cpp100
-rw-r--r--src/declarative/fx/qfxtext.cpp19
-rw-r--r--src/declarative/opengl/gltexture.cpp8
-rw-r--r--src/declarative/opengl/gltexture.h1
4 files changed, 78 insertions, 50 deletions
diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp
index 03a674d..c5e7e89 100644
--- a/src/declarative/fx/qfximage.cpp
+++ b/src/declarative/fx/qfximage.cpp
@@ -500,6 +500,12 @@ void QFxImage::paintGLContents(GLPainter &p)
float glWidth = d->tex->glWidth();
float glHeight = d->tex->glHeight();
+ float deltaX = 0.5 / qreal(d->tex->glSize().width());
+ float deltaY = 0.5 / qreal(d->tex->glSize().height());
+ glWidth -= deltaX;
+ glHeight -= deltaY;
+
+
float vert[] = {
0, heightV,
widthV, heightV,
@@ -510,12 +516,12 @@ void QFxImage::paintGLContents(GLPainter &p)
widthV, 0 };
float tex[] = {
- 0, 0,
- glWidth, 0,
- 0, glHeight,
+ deltaX, deltaY,
+ glWidth, deltaY,
+ deltaX, glHeight,
- glWidth, 0,
- 0, glHeight,
+ glWidth, deltaY,
+ deltaX, glHeight,
glWidth, glHeight
};
@@ -551,11 +557,17 @@ void QFxImage::paintGLContents(GLPainter &p)
float widthV = width();
float heightV = height();
-
- float texleft = 0;
- float texright = d->tex->glWidth();
- float textop = d->tex->glHeight();
- float texbottom = 0;
+ float glWidth = d->tex->glWidth();
+ float glHeight = d->tex->glHeight();
+ float deltaX = 0.5 / qreal(d->tex->glSize().width());
+ float deltaY = 0.5 / qreal(d->tex->glSize().height());
+ glHeight -= deltaY;
+ glWidth -= deltaX;
+
+ float texleft = deltaX;
+ float texright = glWidth;
+ float textop = glHeight;
+ float texbottom = deltaY;
float imgleft = 0;
float imgright = widthV;
float imgtop = 0;
@@ -567,19 +579,19 @@ void QFxImage::paintGLContents(GLPainter &p)
const int sgb = d->scaleGrid->bottom();
if (sgl) {
- texleft = d->tex->glWidth() * float(sgl) / imgWidth;
+ texleft = deltaX + d->tex->glWidth() * float(sgl) / imgWidth;
imgleft = sgl;
}
if (sgr) {
- texright = d->tex->glWidth() - float(sgr) / imgWidth;
+ texright = d->tex->glWidth() - float(sgr) / imgWidth - deltaX;
imgright = widthV - sgr;
}
if (sgt) {
- textop = d->tex->glHeight() - float(sgb) / imgHeight;
+ textop = d->tex->glHeight() - float(sgb) / imgHeight - deltaY;
imgtop = sgt;
}
if (sgb) {
- texbottom = d->tex->glHeight() * float(sgt) / imgHeight;
+ texbottom = deltaY + d->tex->glHeight() * float(sgt) / imgHeight;
imgbottom = heightV - sgb;
}
@@ -655,35 +667,35 @@ void QFxImage::paintGLContents(GLPainter &p)
widthV, imgbottom,
widthV, heightV };
- float tex1[] = { 0, 1,
- 0, textop,
- texleft, 1,
+ float tex1[] = { deltaX, glHeight,
+ deltaX, textop,
+ texleft, glHeight,
- 0, textop,
- texleft, 1,
+ deltaX, textop,
+ texleft, glHeight,
texleft, textop,
- texleft, 1,
+ texleft, glHeight,
texleft, textop,
- texright, 1,
+ texright, glHeight,
texleft, textop,
- texright, 1,
+ texright, glHeight,
texright, textop,
- texright, 1,
+ texright, glHeight,
texright, textop,
- 1, 1,
+ glWidth, glHeight,
texright, textop,
- 1, 1,
- 1, textop,
+ glWidth, glHeight,
+ glWidth, textop,
- 0, textop,
- 0, texbottom,
+ deltaX, textop,
+ deltaX, texbottom,
texleft, textop,
- 0, texbottom,
+ deltaX, texbottom,
texleft, textop,
texleft, texbottom,
@@ -697,35 +709,35 @@ void QFxImage::paintGLContents(GLPainter &p)
texright, textop,
texright, texbottom,
- 1, textop,
+ glWidth, textop,
texright, texbottom,
- 1, textop,
- 1, texbottom,
+ glWidth, textop,
+ glWidth, texbottom,
- 0, texbottom,
- 0, 0,
+ deltaX, texbottom,
+ deltaX, deltaY,
texleft, texbottom,
- 0, 0,
+ deltaX, deltaY,
texleft, texbottom,
- texleft, 0,
+ texleft, deltaY,
texleft, texbottom,
- texleft, 0,
+ texleft, deltaY,
texright, texbottom,
- texleft, 0,
+ texleft, deltaY,
texright, texbottom,
- texright, 0,
+ texright, deltaY,
texright, texbottom,
- texright, 0,
- 1, texbottom,
+ texright, deltaY,
+ glWidth, texbottom,
- texright, 0,
- 1, texbottom,
- 1, 0 };
+ texright, deltaY,
+ glWidth, texbottom,
+ glWidth, deltaY };
glBindTexture(GL_TEXTURE_2D, d->tex->texture());
diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp
index 7a2dd8d..031c0f8 100644
--- a/src/declarative/fx/qfxtext.cpp
+++ b/src/declarative/fx/qfxtext.cpp
@@ -793,9 +793,16 @@ void QFxText::paintGLContents(GLPainter &p)
float widthV = d->imgCache.width();
float heightV = d->imgCache.height();
+ float glWidth = d->tex.glWidth();
+ float glHeight = d->tex.glHeight();
QGLShaderProgram *shader = p.useTextureShader();
+ float deltaX = 0.5 / qreal(d->tex.glSize().width());
+ float deltaY = 0.5 / qreal(d->tex.glSize().height());
+ glWidth -= deltaX;
+ glHeight -= deltaY;
+
GLfloat vertices[] = { x, y + heightV,
x + widthV, y + heightV,
x, y,
@@ -804,13 +811,13 @@ void QFxText::paintGLContents(GLPainter &p)
x, y,
x + widthV, y };
- GLfloat texVertices[] = { 0, 0,
- d->tex.glWidth(), 0,
- 0, d->tex.glHeight(),
+ GLfloat texVertices[] = { deltaX, deltaY,
+ glWidth, deltaY,
+ deltaX, glHeight,
- d->tex.glWidth(), 0,
- 0, d->tex.glHeight(),
- d->tex.glWidth(), d->tex.glHeight() };
+ glWidth, deltaY,
+ deltaX, glHeight,
+ glWidth, glHeight };
shader->setAttributeArray(SingleTextureShader::Vertices, vertices, 2);
shader->setAttributeArray(SingleTextureShader::TextureCoords, texVertices, 2);
diff --git a/src/declarative/opengl/gltexture.cpp b/src/declarative/opengl/gltexture.cpp
index cd9c406..c2a02df 100644
--- a/src/declarative/opengl/gltexture.cpp
+++ b/src/declarative/opengl/gltexture.cpp
@@ -95,6 +95,7 @@ public:
qreal glWidth;
qreal glHeight;
+ QSize glSize;
void genTexture();
};
@@ -199,6 +200,7 @@ void GLTexture::setImage(const QImage &img, ImageMode mode)
}
d->glWidth = 1.;
d->glHeight = 1.;
+ d->glSize = img.size();
} else {
// mode == PowerOfTwo
@@ -233,6 +235,7 @@ void GLTexture::setImage(const QImage &img, ImageMode mode)
d->glWidth = qreal(img.width()) / qreal(max);
d->glHeight = qreal(img.height()) / qreal(max);
+ d->glSize = QSize(max, max);
}
d->width = img.width();
@@ -273,6 +276,11 @@ qreal GLTexture::glHeight() const
return d->glHeight;
}
+QSize GLTexture::glSize() const
+{
+ return d->glSize;
+}
+
/*!
Sets the \a size of the texture. This will destroy the current contents of
the texture. If an image has been assigned, it will need to be reassigned
diff --git a/src/declarative/opengl/gltexture.h b/src/declarative/opengl/gltexture.h
index d301d8a..c08d68f 100644
--- a/src/declarative/opengl/gltexture.h
+++ b/src/declarative/opengl/gltexture.h
@@ -77,6 +77,7 @@ public:
int height() const;
qreal glWidth() const;
qreal glHeight() const;
+ QSize glSize() const;
QSize size() const;
void setSize(const QSize &);