diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-06-03 09:07:45 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-06-03 09:07:45 (GMT) |
commit | e91dff94de4851b4b8ac48cadccd516893fe4661 (patch) | |
tree | c3dea50c87c5be7b467ae9ceb08ab618e98cba14 /src | |
parent | 694b270d78d99e94c8ab7543b7371edbe16ecaab (diff) | |
download | Qt-e91dff94de4851b4b8ac48cadccd516893fe4661.zip Qt-e91dff94de4851b4b8ac48cadccd516893fe4661.tar.gz Qt-e91dff94de4851b4b8ac48cadccd516893fe4661.tar.bz2 |
Use POT textures only
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/fx/qfximage.cpp | 14 | ||||
-rw-r--r-- | src/declarative/fx/qfxrect.cpp | 41 | ||||
-rw-r--r-- | src/declarative/fx/qfxtext.cpp | 13 | ||||
-rw-r--r-- | src/declarative/opengl/gltexture.cpp | 69 |
4 files changed, 86 insertions, 51 deletions
diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp index d28cf7d..d3ac38f 100644 --- a/src/declarative/fx/qfximage.cpp +++ b/src/declarative/fx/qfximage.cpp @@ -462,7 +462,7 @@ uint QFxImage::glSimpleItemData(float *vertices, float *texVertices, void QFxImagePrivate::checkDirty() { if (_texDirty && !_pix.isNull()) { - _tex.setImage(_pix.toImage()); + _tex.setImage(_pix.toImage(), GLTexture::PowerOfTwo); _tex.setHorizontalWrap(GLTexture::Repeat); _tex.setVerticalWrap(GLTexture::Repeat); } @@ -548,8 +548,8 @@ void QFxImage::paintGLContents(GLPainter &p) float heightV = height(); float texleft = 0; - float texright = 1; - float textop = 1; + float texright = d->_tex.glWidth(); + float textop = d->_tex.glHeight(); float texbottom = 0; float imgleft = 0; float imgright = widthV; @@ -562,19 +562,19 @@ void QFxImage::paintGLContents(GLPainter &p) const int sgb = d->_scaleGrid->bottom(); if (sgl) { - texleft = float(sgl) / imgWidth; + texleft = d->_tex.glWidth() * float(sgl) / imgWidth; imgleft = sgl; } if (sgr) { - texright = 1. - float(sgr) / imgWidth; + texright = d->_tex.glWidth() - float(sgr) / imgWidth; imgright = widthV - sgr; } if (sgt) { - textop = 1. - float(sgb) / imgHeight; + textop = d->_tex.glHeight() - float(sgb) / imgHeight; imgtop = sgt; } if (sgb) { - texbottom = float(sgt) / imgHeight; + texbottom = d->_tex.glHeight() * float(sgt) / imgHeight; imgbottom = heightV - sgb; } diff --git a/src/declarative/fx/qfxrect.cpp b/src/declarative/fx/qfxrect.cpp index 3d6897e..c053001 100644 --- a/src/declarative/fx/qfxrect.cpp +++ b/src/declarative/fx/qfxrect.cpp @@ -535,7 +535,7 @@ void QFxRect::generateRoundedRect() } p.setBrush(d->_color); p.drawRoundedRect((pw+1)/2, (pw+1)/2, roundRect.width()-(pw+1)/2*2, roundRect.height()-(pw+1)/2*2, d->_radius, d->_radius); - d->_rectTexture.setImage(roundRect); + d->_rectTexture.setImage(roundRect, GLTexture::PowerOfTwo); } } @@ -556,7 +556,7 @@ void QFxRect::generateBorderedRect() } p.setBrush(d->_color); p.drawRect(qreal(pw+1)/2, qreal(pw+1)/2, borderedRect.width()-(pw+1)/2*2, borderedRect.height()-(pw+1)/2*2); - d->_rectTexture.setImage(borderedRect); + d->_rectTexture.setImage(borderedRect, GLTexture::PowerOfTwo); } } #endif @@ -756,6 +756,11 @@ void QFxRect::paintGLContents(GLPainter &p) if (offset==1) texleft=texright=textop=texbottom=0.5; + texleft *= d->_rectTexture.glWidth(); + texright *= d->_rectTexture.glWidth(); + textop *= d->_rectTexture.glHeight(); + texbottom *= d->_rectTexture.glHeight(); + float vert1[] = { -pw/2, -pw/2, -pw/2, imgtop, imgleft, -pw/2, @@ -847,35 +852,35 @@ void QFxRect::paintGLContents(GLPainter &p) texright, 0, texright, textop, - 1, 0, + d->_rectTexture.glWidth(), 0, texright, textop, - 1, 0, - 1, textop, + d->_rectTexture.glWidth(), 0, + d->_rectTexture.glWidth(), textop, - 0, 1, + 0, d->_rectTexture.glHeight(), 0, texbottom, - texleft, 1, + texleft, d->_rectTexture.glHeight(), 0, texbottom, - texleft, 1, + texleft, d->_rectTexture.glHeight(), texleft, texbottom, - texleft, 1, + texleft, d->_rectTexture.glHeight(), texleft, texbottom, - texright, 1, + texright, d->_rectTexture.glHeight(), texleft, texbottom, - texright, 1, + texright, d->_rectTexture.glHeight(), texright, texbottom, - texright, 1, + texright, d->_rectTexture.glHeight(), texright, texbottom, - 1, 1, + d->_rectTexture.glWidth(), d->_rectTexture.glHeight(), texright, texbottom, - 1, 1, - 1, texbottom, + d->_rectTexture.glWidth(), d->_rectTexture.glHeight(), + d->_rectTexture.glWidth(), texbottom, 0, textop, 0, texbottom, @@ -895,11 +900,11 @@ void QFxRect::paintGLContents(GLPainter &p) texright, textop, texright, texbottom, - 1, textop, + d->_rectTexture.glWidth(), textop, texright, texbottom, - 1, textop, - 1, texbottom }; + d->_rectTexture.glWidth(), textop, + d->_rectTexture.glWidth(), texbottom }; diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp index 1b5c080..7a2dd8d 100644 --- a/src/declarative/fx/qfxtext.cpp +++ b/src/declarative/fx/qfxtext.cpp @@ -696,7 +696,7 @@ void QFxTextPrivate::checkImgCache() } #if defined(QFX_RENDER_OPENGL) - tex.setImage(imgCache.toImage()); + tex.setImage(imgCache.toImage(), GLTexture::PowerOfTwo); #endif imgDirty = false; @@ -755,6 +755,7 @@ void QFxText::paintContents(QPainter &p) #elif defined(QFX_RENDER_OPENGL2) void QFxText::paintGLContents(GLPainter &p) { + //return; Q_D(QFxText); d->checkImgCache(); if (d->imgCache.isNull()) @@ -804,12 +805,12 @@ void QFxText::paintGLContents(GLPainter &p) x + widthV, y }; GLfloat texVertices[] = { 0, 0, - 1, 0, - 0, 1, + d->tex.glWidth(), 0, + 0, d->tex.glHeight(), - 1, 0, - 0, 1, - 1, 1 }; + d->tex.glWidth(), 0, + 0, d->tex.glHeight(), + d->tex.glWidth(), d->tex.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 bebee08..cd9c406 100644 --- a/src/declarative/opengl/gltexture.cpp +++ b/src/declarative/opengl/gltexture.cpp @@ -180,30 +180,59 @@ void GLTexture::setImage(const QImage &img, ImageMode mode) glBindTexture(GL_TEXTURE_2D, d->texture); - // ### Need to respect mode - if (img.format() == QImage::Format_RGB16) { - QImage dataImage = img.mirrored(); + if (mode == NonPowerOfTwo) { + + if (img.format() == QImage::Format_RGB16) { + QImage dataImage = img.mirrored(); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, dataImage.width(), + dataImage.height(), 0, + GL_RGB, + GL_UNSIGNED_SHORT_5_6_5, dataImage.bits()); + } else { + QImage dataImage = QGLWidget_convertToGLFormat(img); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dataImage.width(), + dataImage.height(), 0, + (dataImage.format() == QImage::Format_ARGB32)?GL_RGBA:GL_RGB, + GL_UNSIGNED_BYTE, dataImage.bits()); + } + d->glWidth = 1.; + d->glHeight = 1.; + + } else { + // mode == PowerOfTwo int max = (img.width() > img.height())?img.width():img.height(); max = npot(max); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, max, - max, 0, - GL_RGB, - GL_UNSIGNED_SHORT_5_6_5, 0); - - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, dataImage.width(), - dataImage.height(), GL_RGB, GL_UNSIGNED_SHORT_5_6_5, - dataImage.bits()); - - d->glWidth = qreal(dataImage.width()) / qreal(max); - d->glHeight = qreal(dataImage.height()) / qreal(max); - } else { - QImage dataImage = QGLWidget_convertToGLFormat(img); + if (img.format() == QImage::Format_RGB16) { + QImage dataImage = img.mirrored(); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, max, + max, 0, + GL_RGB, + GL_UNSIGNED_SHORT_5_6_5, 0); + + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, dataImage.width(), + dataImage.height(), GL_RGB, GL_UNSIGNED_SHORT_5_6_5, + dataImage.bits()); + + } else { + QImage dataImage = QGLWidget_convertToGLFormat(img); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, max, + max, 0, + (dataImage.format() == QImage::Format_ARGB32)?GL_RGBA:GL_RGB, + GL_UNSIGNED_BYTE, 0); + + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, dataImage.width(), + dataImage.height(), + (dataImage.format() == QImage::Format_ARGB32)?GL_RGBA:GL_RGB, + GL_UNSIGNED_BYTE, dataImage.bits()); + } - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dataImage.width(), - dataImage.height(), 0, - (dataImage.format() == QImage::Format_ARGB32)?GL_RGBA:GL_RGB, - GL_UNSIGNED_BYTE, dataImage.bits()); + d->glWidth = qreal(img.width()) / qreal(max); + d->glHeight = qreal(img.height()) / qreal(max); } d->width = img.width(); |