From 357363dd51e885447202fc753792a49b5812539a Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 24 Feb 2014 16:40:00 +0100 Subject: Texture glyph cache: Use a vbo It is not going to work with core profile otherwise. This fixes one of the several problems that make native text rendering in Quick impossible with OpenGL core profile. The GL2 paint engine path is not changed, that continues to use client side pointers. Task-number: QTBUG-36993 Change-Id: Icfbd6efc894a79a3a84568fb792c1cb6692469cb Reviewed-by: Gunnar Sletta --- src/gui/opengl/qopengltextureglyphcache.cpp | 20 +++++++++++++++++--- src/gui/opengl/qopengltextureglyphcache_p.h | 3 +++ 2 files changed, 20 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/gui/opengl/qopengltextureglyphcache.cpp b/src/gui/opengl/qopengltextureglyphcache.cpp index ba1fa8f486..f1bf944d7b 100644 --- a/src/gui/opengl/qopengltextureglyphcache.cpp +++ b/src/gui/opengl/qopengltextureglyphcache.cpp @@ -58,6 +58,7 @@ QOpenGLTextureGlyphCache::QOpenGLTextureGlyphCache(QFontEngine::GlyphFormat form , m_blitProgram(0) , m_filterMode(Nearest) , m_serialNumber(qopengltextureglyphcache_serial_number.fetchAndAddRelaxed(1)) + , m_buffer(QOpenGLBuffer::VertexBuffer) { #ifdef QT_GL_TEXTURE_GLYPH_CACHE_DEBUG qDebug(" -> QOpenGLTextureGlyphCache() %p for context %p.", this, QOpenGLContext::currentContext()); @@ -139,6 +140,18 @@ void QOpenGLTextureGlyphCache::createTextureData(int width, int height) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); m_filterMode = Nearest; + + if (!m_buffer.isCreated()) { + m_buffer.create(); + m_buffer.bind(); + static GLfloat buf[sizeof(m_vertexCoordinateArray) + sizeof(m_textureCoordinateArray)]; + memcpy(buf, m_vertexCoordinateArray, sizeof(m_vertexCoordinateArray)); + memcpy(buf + (sizeof(m_vertexCoordinateArray) / sizeof(GLfloat)), + m_textureCoordinateArray, + sizeof(m_textureCoordinateArray)); + m_buffer.allocate(buf, sizeof(buf)); + m_buffer.release(); + } } void QOpenGLTextureGlyphCache::resizeTextureData(int width, int height) @@ -239,10 +252,10 @@ void QOpenGLTextureGlyphCache::resizeTextureData(int width, int height) m_blitProgram->link(); } - funcs.glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, m_vertexCoordinateArray); - funcs.glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, m_textureCoordinateArray); - + m_buffer.bind(); m_blitProgram->bind(); + m_blitProgram->setAttributeBuffer(int(QT_VERTEX_COORDS_ATTR), GL_FLOAT, 0, 2); + m_blitProgram->setAttributeBuffer(int(QT_TEXTURE_COORDS_ATTR), GL_FLOAT, sizeof(m_vertexCoordinateArray), 2); m_blitProgram->enableAttributeArray(int(QT_VERTEX_COORDS_ATTR)); m_blitProgram->enableAttributeArray(int(QT_TEXTURE_COORDS_ATTR)); m_blitProgram->disableAttributeArray(int(QT_OPACITY_ATTR)); @@ -278,6 +291,7 @@ void QOpenGLTextureGlyphCache::resizeTextureData(int width, int height) } else { m_blitProgram->disableAttributeArray(int(QT_VERTEX_COORDS_ATTR)); m_blitProgram->disableAttributeArray(int(QT_TEXTURE_COORDS_ATTR)); + m_buffer.release(); } } diff --git a/src/gui/opengl/qopengltextureglyphcache_p.h b/src/gui/opengl/qopengltextureglyphcache_p.h index a361a79de2..394c28f7ff 100644 --- a/src/gui/opengl/qopengltextureglyphcache_p.h +++ b/src/gui/opengl/qopengltextureglyphcache_p.h @@ -57,6 +57,7 @@ #include #include #include +#include // #define QT_GL_TEXTURE_GLYPH_CACHE_DEBUG @@ -162,6 +163,8 @@ private: GLfloat m_textureCoordinateArray[8]; int m_serialNumber; + + QOpenGLBuffer m_buffer; }; QT_END_NAMESPACE -- cgit v1.2.3