summaryrefslogtreecommitdiffstats
path: root/src/opengl
diff options
context:
space:
mode:
authorTrond Kjernåsen <trond@trolltech.com>2009-08-17 13:45:43 (GMT)
committerTrond Kjernåsen <trond@trolltech.com>2009-08-17 13:52:09 (GMT)
commit53807e58770f27d46ca8ecaa33a3d5f7b6925517 (patch)
treeafa7ccf8c1e635e41c0b1dc898077011573b8b89 /src/opengl
parentd0b0f7b5b44fbec26a67b4afb3a08143b5de4b57 (diff)
downloadQt-53807e58770f27d46ca8ecaa33a3d5f7b6925517.zip
Qt-53807e58770f27d46ca8ecaa33a3d5f7b6925517.tar.gz
Qt-53807e58770f27d46ca8ecaa33a3d5f7b6925517.tar.bz2
Fixed text rendering on GL ES 2 implementations.
Some GL ES 2 implementations seem to have problems with glCopyTexSubImage2D(), so we fall back and read the old font texture into system memory and re-upload the new font texture. Also, the precision used for texture coordinates in the fragment programs wasn't high enough, which could lead to rendering artifacts. Reviewed-by: Samuel
Diffstat (limited to 'src/opengl')
-rw-r--r--src/opengl/gl2paintengineex/qglengineshadersource_p.h6
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp37
2 files changed, 31 insertions, 12 deletions
diff --git a/src/opengl/gl2paintengineex/qglengineshadersource_p.h b/src/opengl/gl2paintengineex/qglengineshadersource_p.h
index b0b91ae..c80d6e1 100644
--- a/src/opengl/gl2paintengineex/qglengineshadersource_p.h
+++ b/src/opengl/gl2paintengineex/qglengineshadersource_p.h
@@ -73,8 +73,8 @@ static const char* const qglslMainVertexShader = "\
}";
static const char* const qglslMainWithTexCoordsVertexShader = "\
- attribute lowp vec2 textureCoordArray; \
- varying lowp vec2 textureCoords; \
+ attribute mediump vec2 textureCoordArray; \
+ varying mediump vec2 textureCoords; \
uniform highp float depth;\
void setPosition();\
void main(void) \
@@ -284,7 +284,7 @@ static const char* const qglslSolidBrushSrcFragmentShader = "\
}";
static const char* const qglslImageSrcFragmentShader = "\
- varying highp vec2 textureCoords; \
+ varying mediump vec2 textureCoords; \
uniform sampler2D imageTexture; \
lowp vec4 srcPixel() { \
return texture2D(imageTexture, textureCoords); \
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
index 5e1e892..34f7e7a 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
@@ -75,6 +75,7 @@
#include <private/qfontengine_p.h>
#include <private/qtextureglyphcache_p.h>
#include <private/qpixmapdata_gl_p.h>
+#include <private/qdatabuffer_p.h>
#include "qglgradientcache_p.h"
#include "qglengineshadermanager_p.h"
@@ -175,7 +176,7 @@ void QGLTextureGlyphCache::createTextureData(int width, int height)
m_height = height;
QVarLengthArray<uchar> data(width * height);
- for (int i = 0; i < width * height; ++i)
+ for (int i = 0; i < data.size(); ++i)
data[i] = 0;
if (m_type == QFontEngineGlyphCache::Raster_RGBMask)
@@ -200,13 +201,18 @@ void QGLTextureGlyphCache::resizeTextureData(int width, int height)
glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_fbo);
- GLuint colorBuffer;
- glGenRenderbuffers(1, &colorBuffer);
- glBindRenderbuffer(GL_RENDERBUFFER_EXT, colorBuffer);
- glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_RGBA, oldWidth, oldHeight);
- glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
- GL_RENDERBUFFER_EXT, colorBuffer);
- glBindRenderbuffer(GL_RENDERBUFFER_EXT, 0);
+ GLuint tmp_texture;
+ glGenTextures(1, &tmp_texture);
+ glBindTexture(GL_TEXTURE_2D, tmp_texture);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, oldWidth, oldHeight, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glBindTexture(GL_TEXTURE_2D, 0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
+ GL_TEXTURE_2D, tmp_texture, 0);
glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT);
glBindTexture(GL_TEXTURE_2D, oldTexture);
@@ -237,11 +243,24 @@ void QGLTextureGlyphCache::resizeTextureData(int width, int height)
glDisableVertexAttribArray(QT_TEXTURE_COORDS_ATTR);
glBindTexture(GL_TEXTURE_2D, m_texture);
+
+#ifdef QT_OPENGL_ES_2
+ QDataBuffer<uchar> buffer(4*oldWidth*oldHeight);
+ glReadPixels(0, 0, oldWidth, oldHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer.data());
+
+ // do an in-place conversion from GL_RGBA to GL_ALPHA
+ for (int i=0; i<oldWidth*oldHeight; ++i)
+ buffer.data()[i] = buffer.at(4*i + 3);
+
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, oldWidth, oldHeight,
+ GL_ALPHA, GL_UNSIGNED_BYTE, buffer.data());
+#else
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, oldWidth, oldHeight);
+#endif
glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_RENDERBUFFER_EXT, 0);
- glDeleteRenderbuffers(1, &colorBuffer);
+ glDeleteTextures(1, &tmp_texture);
glDeleteTextures(1, &oldTexture);
glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->current_fbo);