summaryrefslogtreecommitdiffstats
path: root/src/gui/opengl
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/opengl')
-rw-r--r--src/gui/opengl/qopengldebug.cpp14
-rw-r--r--src/gui/opengl/qopenglfunctions.cpp6
-rw-r--r--src/gui/opengl/qopenglpaintengine.cpp53
-rw-r--r--src/gui/opengl/qopenglpaintengine_p.h4
-rw-r--r--src/gui/opengl/qopenglproxy_win.cpp3
-rw-r--r--src/gui/opengl/qopenglshaderprogram.cpp23
-rw-r--r--src/gui/opengl/qopenglshaderprogram.h2
-rw-r--r--src/gui/opengl/qopengltextureglyphcache.cpp78
-rw-r--r--src/gui/opengl/qopengltextureglyphcache_p.h9
-rw-r--r--src/gui/opengl/qopenglversionfunctions.cpp2
-rw-r--r--src/gui/opengl/qopenglvertexarrayobject.cpp149
11 files changed, 211 insertions, 132 deletions
diff --git a/src/gui/opengl/qopengldebug.cpp b/src/gui/opengl/qopengldebug.cpp
index 90d062f4dd..2355d0a8a7 100644
--- a/src/gui/opengl/qopengldebug.cpp
+++ b/src/gui/opengl/qopengldebug.cpp
@@ -43,6 +43,7 @@
#include <QtCore/qglobal.h>
#include <QtCore/qvarlengtharray.h>
#include <QtGui/qopengl.h>
+#include <QtGui/qopenglfunctions.h>
#include "qopengldebug.h"
@@ -1364,7 +1365,20 @@ bool QOpenGLDebugLogger::initialize()
GET_DEBUG_PROC_ADDRESS(glGetDebugMessageLog);
GET_DEBUG_PROC_ADDRESS(glPushDebugGroup);
GET_DEBUG_PROC_ADDRESS(glPopDebugGroup);
+
+ // Windows' Desktop GL doesn't allow resolution of "basic GL entry points"
+ // through wglGetProcAddress
+#if defined(Q_OS_WIN) && !defined(QT_OPENGL_ES_2)
+ {
+ HMODULE handle = static_cast<HMODULE>(QOpenGLFunctions::platformGLHandle());
+ if (!handle)
+ handle = GetModuleHandleA("opengl32.dll");
+ d->glGetPointerv = reinterpret_cast<qt_glGetPointerv_t>(GetProcAddress(handle, QByteArrayLiteral("glGetPointerv")));
+ }
+#else
GET_DEBUG_PROC_ADDRESS(glGetPointerv)
+#endif
+
#undef GET_DEBUG_PROC_ADDRESS
glGetIntegerv(GL_MAX_DEBUG_MESSAGE_LENGTH, &d->maxMessageLength);
diff --git a/src/gui/opengl/qopenglfunctions.cpp b/src/gui/opengl/qopenglfunctions.cpp
index 150e7dcb32..60743b3a27 100644
--- a/src/gui/opengl/qopenglfunctions.cpp
+++ b/src/gui/opengl/qopenglfunctions.cpp
@@ -314,7 +314,8 @@ static int qt_gl_resolve_features()
if (extensions.match("GL_ARB_multisample"))
features |= QOpenGLFunctions::Multisample;
if (extensions.match("GL_ARB_texture_non_power_of_two"))
- features |= QOpenGLFunctions::NPOTTextures;
+ features |= QOpenGLFunctions::NPOTTextures |
+ QOpenGLFunctions::NPOTTextureRepeat;
// assume version 2.0 or higher
features |= QOpenGLFunctions::BlendColor |
@@ -327,7 +328,8 @@ static int qt_gl_resolve_features()
QOpenGLFunctions::Shaders |
QOpenGLFunctions::StencilSeparate |
QOpenGLFunctions::BlendEquationSeparate |
- QOpenGLFunctions::NPOTTextures;
+ QOpenGLFunctions::NPOTTextures |
+ QOpenGLFunctions::NPOTTextureRepeat;
if (format.majorVersion() >= 3)
features |= QOpenGLFunctions::Framebuffers;
diff --git a/src/gui/opengl/qopenglpaintengine.cpp b/src/gui/opengl/qopenglpaintengine.cpp
index e91ada7b3a..63127668a5 100644
--- a/src/gui/opengl/qopenglpaintengine.cpp
+++ b/src/gui/opengl/qopenglpaintengine.cpp
@@ -1434,19 +1434,18 @@ void QOpenGL2PaintEngineEx::drawStaticTextItem(QStaticTextItem *textItem)
QFontEngine *fontEngine = textItem->fontEngine();
if (shouldDrawCachedGlyphs(fontEngine, s->matrix)) {
- QFontEngineGlyphCache::Type glyphType = fontEngine->glyphFormat >= 0
- ? QFontEngineGlyphCache::Type(textItem->fontEngine()->glyphFormat)
- : d->glyphCacheType;
- if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) {
+ QFontEngine::GlyphFormat glyphFormat = fontEngine->glyphFormat != QFontEngine::Format_None
+ ? fontEngine->glyphFormat : d->glyphCacheFormat;
+ if (glyphFormat == QFontEngine::Format_A32) {
if (d->device->context()->format().alphaBufferSize() > 0 || s->matrix.type() > QTransform::TxTranslate
|| (s->composition_mode != QPainter::CompositionMode_Source
&& s->composition_mode != QPainter::CompositionMode_SourceOver))
{
- glyphType = QFontEngineGlyphCache::Raster_A8;
+ glyphFormat = QFontEngine::Format_A8;
}
}
- d->drawCachedGlyphs(glyphType, textItem);
+ d->drawCachedGlyphs(glyphFormat, textItem);
} else {
QPaintEngineEx::drawStaticTextItem(textItem);
}
@@ -1483,17 +1482,15 @@ void QOpenGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &text
QTransform::TransformationType txtype = s->matrix.type();
- QFontEngineGlyphCache::Type glyphType = ti.fontEngine->glyphFormat >= 0
- ? QFontEngineGlyphCache::Type(ti.fontEngine->glyphFormat)
- : d->glyphCacheType;
+ QFontEngine::GlyphFormat glyphFormat = ti.fontEngine->glyphFormat != QFontEngine::Format_None
+ ? ti.fontEngine->glyphFormat : d->glyphCacheFormat;
-
- if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) {
+ if (glyphFormat == QFontEngine::Format_A32) {
if (d->device->context()->format().alphaBufferSize() > 0 || txtype > QTransform::TxTranslate
|| (state()->composition_mode != QPainter::CompositionMode_Source
&& state()->composition_mode != QPainter::CompositionMode_SourceOver))
{
- glyphType = QFontEngineGlyphCache::Raster_A8;
+ glyphFormat = QFontEngine::Format_A8;
}
}
@@ -1512,7 +1509,7 @@ void QOpenGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &text
staticTextItem.numGlyphs = glyphs.size();
staticTextItem.glyphPositions = positions.data();
- d->drawCachedGlyphs(glyphType, &staticTextItem);
+ d->drawCachedGlyphs(glyphFormat, &staticTextItem);
}
return;
}
@@ -1537,7 +1534,7 @@ namespace {
QSize cacheSize;
QOpenGL2PEXVertexArray vertexCoordinateArray;
QOpenGL2PEXVertexArray textureCoordinateArray;
- QFontEngineGlyphCache::Type glyphType;
+ QFontEngine::GlyphFormat glyphFormat;
int cacheSerialNumber;
};
@@ -1572,7 +1569,7 @@ bool QOpenGL2PaintEngineEx::shouldDrawCachedGlyphs(QFontEngine *fontEngine, cons
return QPaintEngineEx::shouldDrawCachedGlyphs(fontEngine, t);
}
-void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType,
+void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngine::GlyphFormat glyphFormat,
QStaticTextItem *staticTextItem)
{
Q_Q(QOpenGL2PaintEngineEx);
@@ -1596,9 +1593,9 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type
}
QOpenGLTextureGlyphCache *cache =
- (QOpenGLTextureGlyphCache *) fe->glyphCache(cacheKey, glyphType, glyphCacheTransform);
- if (!cache || cache->cacheType() != glyphType || cache->contextGroup() == 0) {
- cache = new QOpenGLTextureGlyphCache(glyphType, glyphCacheTransform);
+ (QOpenGLTextureGlyphCache *) fe->glyphCache(cacheKey, glyphFormat, glyphCacheTransform);
+ if (!cache || cache->glyphFormat() != glyphFormat || cache->contextGroup() == 0) {
+ cache = new QOpenGLTextureGlyphCache(glyphFormat, glyphCacheTransform);
fe->setGlyphCache(cacheKey, cache);
recreateVertexArrays = true;
}
@@ -1611,7 +1608,7 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type
recreateVertexArrays = true;
} else {
QOpenGLStaticTextUserData *userData = static_cast<QOpenGLStaticTextUserData *>(staticTextItem->userData());
- if (userData->glyphType != glyphType) {
+ if (userData->glyphFormat != glyphFormat) {
recreateVertexArrays = true;
} else if (userData->cacheSerialNumber != cache->serialNumber()) {
recreateVertexArrays = true;
@@ -1636,12 +1633,12 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type
if (cache->width() == 0 || cache->height() == 0)
return;
- if (glyphType == QFontEngineGlyphCache::Raster_ARGB)
+ if (glyphFormat == QFontEngine::Format_ARGB)
transferMode(ImageArrayDrawingMode);
else
transferMode(TextDrawingMode);
- int margin = fe->glyphMargin(glyphType);
+ int margin = fe->glyphMargin(glyphFormat);
GLfloat dx = 1.0 / cache->width();
GLfloat dy = 1.0 / cache->height();
@@ -1663,7 +1660,7 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type
userData = static_cast<QOpenGLStaticTextUserData*>(staticTextItem->userData());
}
- userData->glyphType = glyphType;
+ userData->glyphFormat = glyphFormat;
userData->cacheSerialNumber = cache->serialNumber();
// Use cache if backend optimizations is turned on
@@ -1735,7 +1732,7 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type
#endif
}
- if (glyphType != QFontEngineGlyphCache::Raster_ARGB || recreateVertexArrays) {
+ if (glyphFormat != QFontEngine::Format_ARGB || recreateVertexArrays) {
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinates->data());
setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinates->data());
}
@@ -1748,7 +1745,7 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type
QBrush pensBrush = q->state()->pen.brush();
setBrush(pensBrush);
- if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) {
+ if (glyphFormat == QFontEngine::Format_A32) {
// Subpixel antialiasing without gamma correction
@@ -1821,7 +1818,7 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type
glBlendFunc(GL_ONE, GL_ONE);
}
compositionModeDirty = true;
- } else if (glyphType == QFontEngineGlyphCache::Raster_ARGB) {
+ } else if (glyphFormat == QFontEngine::Format_ARGB) {
currentBrush = noBrush;
shaderManager->setSrcPixelType(QOpenGLEngineShaderManager::ImageSrc);
if (prepareForCachedGlyphDraw(*cache))
@@ -1836,7 +1833,7 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type
QOpenGLTextureGlyphCache::FilterMode filterMode = (s->matrix.type() > QTransform::TxTranslate)?QOpenGLTextureGlyphCache::Linear:QOpenGLTextureGlyphCache::Nearest;
if (lastMaskTextureUsed != cache->texture() || cache->filterMode() != filterMode) {
- if (glyphType == QFontEngineGlyphCache::Raster_ARGB)
+ if (glyphFormat == QFontEngine::Format_ARGB)
funcs.glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT);
else
funcs.glActiveTexture(GL_TEXTURE0 + QT_MASK_TEXTURE_UNIT);
@@ -2012,12 +2009,12 @@ bool QOpenGL2PaintEngineEx::begin(QPaintDevice *pdev)
glDisable(GL_DEPTH_TEST);
glDisable(GL_SCISSOR_TEST);
- d->glyphCacheType = QFontEngineGlyphCache::Raster_A8;
+ d->glyphCacheFormat = QFontEngine::Format_A8;
#ifndef QT_OPENGL_ES_2
if (!QOpenGLFunctions::isES()) {
glDisable(GL_MULTISAMPLE);
- d->glyphCacheType = QFontEngineGlyphCache::Raster_RGBMask;
+ d->glyphCacheFormat = QFontEngine::Format_A32;
d->multisamplingAlwaysEnabled = false;
} else
#endif // QT_OPENGL_ES_2
diff --git a/src/gui/opengl/qopenglpaintengine_p.h b/src/gui/opengl/qopenglpaintengine_p.h
index d51f0e5256..4f0e2e52a4 100644
--- a/src/gui/opengl/qopenglpaintengine_p.h
+++ b/src/gui/opengl/qopenglpaintengine_p.h
@@ -212,7 +212,7 @@ public:
void drawTexture(const QOpenGLRect& dest, const QOpenGLRect& src, const QSize &textureSize, bool opaque, bool pattern = false);
void drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap,
QPainter::PixmapFragmentHints hints);
- void drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType, QStaticTextItem *staticTextItem);
+ void drawCachedGlyphs(QFontEngine::GlyphFormat glyphFormat, QStaticTextItem *staticTextItem);
// Calls glVertexAttributePointer if the pointer has changed
inline void setVertexAttributePointer(unsigned int arrayIndex, const GLfloat *pointer);
@@ -267,7 +267,7 @@ public:
int width, height;
QOpenGLContext *ctx;
EngineMode mode;
- QFontEngineGlyphCache::Type glyphCacheType;
+ QFontEngine::GlyphFormat glyphCacheFormat;
bool vertexAttributeArraysEnabledState[QT_GL_VERTEX_ARRAY_TRACKED_COUNT];
diff --git a/src/gui/opengl/qopenglproxy_win.cpp b/src/gui/opengl/qopenglproxy_win.cpp
index 83c3073f63..88f3a1d11d 100644
--- a/src/gui/opengl/qopenglproxy_win.cpp
+++ b/src/gui/opengl/qopenglproxy_win.cpp
@@ -680,9 +680,6 @@ static HMODULE qgl_loadLib(const char *name, bool warnOnFail = true)
QWindowsOpenGL::QWindowsOpenGL()
: m_eglLib(0)
{
- if (qEnvironmentVariableIsSet("QT_OPENGLPROXY_DEBUG"))
- QLoggingCategory::setFilterRules(QStringLiteral("qt.gui.openglproxy=true"));
-
enum RequestedLib {
Unknown,
Desktop,
diff --git a/src/gui/opengl/qopenglshaderprogram.cpp b/src/gui/opengl/qopenglshaderprogram.cpp
index 06f40eafd0..164e5e6925 100644
--- a/src/gui/opengl/qopenglshaderprogram.cpp
+++ b/src/gui/opengl/qopenglshaderprogram.cpp
@@ -123,7 +123,8 @@ QT_BEGIN_NAMESPACE
on the return value from programId(). Then the application should
call link(), which will notice that the program has already been
specified and linked, allowing other operations to be performed
- on the shader program.
+ on the shader program. The shader program's id can be explicitly
+ created using the create() function.
\sa QOpenGLShader
*/
@@ -639,6 +640,26 @@ QOpenGLShaderProgram::~QOpenGLShaderProgram()
{
}
+/*!
+ Requests the shader program's id to be created immediately. Returns \c true
+ if successful; \c false otherwise.
+
+ This function is primarily useful when combining QOpenGLShaderProgram
+ with other OpenGL functions that operate directly on the shader
+ program id, like \c {GL_OES_get_program_binary}.
+
+ When the shader program is used normally, the shader program's id will
+ be created on demand.
+
+ \sa programId()
+
+ \since 5.3
+ */
+bool QOpenGLShaderProgram::create()
+{
+ return init();
+}
+
bool QOpenGLShaderProgram::init()
{
Q_D(QOpenGLShaderProgram);
diff --git a/src/gui/opengl/qopenglshaderprogram.h b/src/gui/opengl/qopenglshaderprogram.h
index b894ae3af8..91754842e6 100644
--- a/src/gui/opengl/qopenglshaderprogram.h
+++ b/src/gui/opengl/qopenglshaderprogram.h
@@ -130,6 +130,8 @@ public:
bool bind();
void release();
+ bool create();
+
GLuint programId() const;
int maxGeometryOutputVertices() const;
diff --git a/src/gui/opengl/qopengltextureglyphcache.cpp b/src/gui/opengl/qopengltextureglyphcache.cpp
index 0d9a2359bd..3524c1cb1a 100644
--- a/src/gui/opengl/qopengltextureglyphcache.cpp
+++ b/src/gui/opengl/qopengltextureglyphcache.cpp
@@ -51,13 +51,14 @@ QT_BEGIN_NAMESPACE
QBasicAtomicInt qopengltextureglyphcache_serial_number = Q_BASIC_ATOMIC_INITIALIZER(1);
-QOpenGLTextureGlyphCache::QOpenGLTextureGlyphCache(QFontEngineGlyphCache::Type type, const QTransform &matrix)
- : QImageTextureGlyphCache(type, matrix)
+QOpenGLTextureGlyphCache::QOpenGLTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix)
+ : QImageTextureGlyphCache(format, matrix)
, m_textureResource(0)
, pex(0)
, 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());
@@ -88,6 +89,11 @@ QOpenGLTextureGlyphCache::~QOpenGLTextureGlyphCache()
#endif
}
+static inline bool isCoreProfile()
+{
+ return QOpenGLContext::currentContext()->format().profile() == QSurfaceFormat::CoreProfile;
+}
+
void QOpenGLTextureGlyphCache::createTextureData(int width, int height)
{
QOpenGLContext *ctx = const_cast<QOpenGLContext *>(QOpenGLContext::currentContext());
@@ -122,7 +128,7 @@ void QOpenGLTextureGlyphCache::createTextureData(int width, int height)
m_textureResource->m_width = width;
m_textureResource->m_height = height;
- if (m_type == QFontEngineGlyphCache::Raster_RGBMask || m_type == QFontEngineGlyphCache::Raster_ARGB) {
+ if (m_format == QFontEngine::Format_A32 || m_format == QFontEngine::Format_ARGB) {
QVarLengthArray<uchar> data(width * height * 4);
for (int i = 0; i < data.size(); ++i)
data[i] = 0;
@@ -131,7 +137,14 @@ void QOpenGLTextureGlyphCache::createTextureData(int width, int height)
QVarLengthArray<uchar> data(width * height);
for (int i = 0; i < data.size(); ++i)
data[i] = 0;
- glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, &data[0]);
+#if !defined(QT_OPENGL_ES_2)
+ const GLint internalFormat = isCoreProfile() ? GL_R8 : GL_ALPHA;
+ const GLenum format = isCoreProfile() ? GL_RED : GL_ALPHA;
+#else
+ const GLint internalFormat = GL_ALPHA;
+ const GLenum format = GL_ALPHA;
+#endif
+ glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, GL_UNSIGNED_BYTE, &data[0]);
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -139,6 +152,31 @@ 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();
+ }
+
+ if (!m_vao.isCreated())
+ m_vao.create();
+}
+
+void QOpenGLTextureGlyphCache::setupVertexAttribs()
+{
+ m_buffer.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_buffer.release();
}
void QOpenGLTextureGlyphCache::resizeTextureData(int width, int height)
@@ -237,16 +275,19 @@ void QOpenGLTextureGlyphCache::resizeTextureData(int width, int height)
m_blitProgram->bindAttributeLocation("textureCoordArray", QT_TEXTURE_COORDS_ATTR);
m_blitProgram->link();
+
+ if (m_vao.isCreated()) {
+ m_vao.bind();
+ setupVertexAttribs();
+ }
}
- 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);
+ if (m_vao.isCreated())
+ m_vao.bind();
+ else
+ setupVertexAttribs();
m_blitProgram->bind();
- m_blitProgram->enableAttributeArray(int(QT_VERTEX_COORDS_ATTR));
- m_blitProgram->enableAttributeArray(int(QT_TEXTURE_COORDS_ATTR));
- m_blitProgram->disableAttributeArray(int(QT_OPACITY_ATTR));
-
blitProgram = m_blitProgram;
} else {
@@ -276,8 +317,12 @@ void QOpenGLTextureGlyphCache::resizeTextureData(int width, int height)
glViewport(0, 0, pex->width, pex->height);
pex->updateClipScissorTest();
} else {
- m_blitProgram->disableAttributeArray(int(QT_VERTEX_COORDS_ATTR));
- m_blitProgram->disableAttributeArray(int(QT_TEXTURE_COORDS_ATTR));
+ if (m_vao.isCreated()) {
+ m_vao.release();
+ } else {
+ m_blitProgram->disableAttributeArray(int(QT_VERTEX_COORDS_ATTR));
+ m_blitProgram->disableAttributeArray(int(QT_TEXTURE_COORDS_ATTR));
+ }
}
}
@@ -395,7 +440,14 @@ void QOpenGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph, QFixed
glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y + i, maskWidth, 1, GL_ALPHA, GL_UNSIGNED_BYTE, mask.scanLine(i));
} else {
#endif
- glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, GL_ALPHA, GL_UNSIGNED_BYTE, mask.bits());
+
+#if !defined(QT_OPENGL_ES_2)
+ const GLenum format = isCoreProfile() ? GL_RED : GL_ALPHA;
+#else
+ const GLenum format = GL_ALPHA;
+#endif
+ glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, format, GL_UNSIGNED_BYTE, mask.bits());
+
#if 0
}
#endif
diff --git a/src/gui/opengl/qopengltextureglyphcache_p.h b/src/gui/opengl/qopengltextureglyphcache_p.h
index d9456db6ed..1e2c031018 100644
--- a/src/gui/opengl/qopengltextureglyphcache_p.h
+++ b/src/gui/opengl/qopengltextureglyphcache_p.h
@@ -57,6 +57,8 @@
#include <private/qopenglcontext_p.h>
#include <qopenglshaderprogram.h>
#include <qopenglfunctions.h>
+#include <qopenglbuffer.h>
+#include <qopenglvertexarrayobject.h>
// #define QT_GL_TEXTURE_GLYPH_CACHE_DEBUG
@@ -109,7 +111,7 @@ public:
class Q_GUI_EXPORT QOpenGLTextureGlyphCache : public QImageTextureGlyphCache
{
public:
- QOpenGLTextureGlyphCache(QFontEngineGlyphCache::Type type, const QTransform &matrix);
+ QOpenGLTextureGlyphCache(QFontEngine::GlyphFormat glyphFormat, const QTransform &matrix);
~QOpenGLTextureGlyphCache();
virtual void createTextureData(int width, int height);
@@ -152,6 +154,8 @@ public:
void clear();
private:
+ void setupVertexAttribs();
+
QOpenGLGlyphTexture *m_textureResource;
QOpenGL2PaintEngineExPrivate *pex;
@@ -162,6 +166,9 @@ private:
GLfloat m_textureCoordinateArray[8];
int m_serialNumber;
+
+ QOpenGLBuffer m_buffer;
+ QOpenGLVertexArrayObject m_vao;
};
QT_END_NAMESPACE
diff --git a/src/gui/opengl/qopenglversionfunctions.cpp b/src/gui/opengl/qopenglversionfunctions.cpp
index 428f6e8a8b..5df7463e8a 100644
--- a/src/gui/opengl/qopenglversionfunctions.cpp
+++ b/src/gui/opengl/qopenglversionfunctions.cpp
@@ -191,6 +191,8 @@ QAbstractOpenGLFunctions::~QAbstractOpenGLFunctions()
delete d_ptr;
}
+/*! \internal
+ */
bool QAbstractOpenGLFunctions::initializeOpenGLFunctions()
{
Q_D(QAbstractOpenGLFunctions);
diff --git a/src/gui/opengl/qopenglvertexarrayobject.cpp b/src/gui/opengl/qopenglvertexarrayobject.cpp
index e26c6ec25a..52fd482b53 100644
--- a/src/gui/opengl/qopenglvertexarrayobject.cpp
+++ b/src/gui/opengl/qopenglvertexarrayobject.cpp
@@ -45,34 +45,35 @@
#include <QtGui/qopenglcontext.h>
#include <QtGui/qopenglfunctions.h>
-#if !defined(QT_OPENGL_ES_2)
#include <QtGui/qopenglfunctions_3_0.h>
#include <QtGui/qopenglfunctions_3_2_core.h>
-#endif
QT_BEGIN_NAMESPACE
+class QOpenGLFunctions_3_0;
+class QOpenGLFunctions_3_2_Core;
+
class QVertexArrayObjectHelper
{
public:
QVertexArrayObjectHelper(QOpenGLContext *context)
{
Q_ASSERT(context);
-#if !defined(QT_OPENGL_ES_2)
- if (context->hasExtension(QByteArrayLiteral("GL_APPLE_vertex_array_object"))) {
- GenVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , GLuint *)>(context->getProcAddress(QByteArrayLiteral("glGenVertexArraysAPPLE")));
- DeleteVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , const GLuint *)>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArraysAPPLE")));
- BindVertexArray = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint )>(context->getProcAddress(QByteArrayLiteral("glBindVertexArrayAPPLE")));
+ if (QOpenGLFunctions::isES()) {
+ GenVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , GLuint *)>(context->getProcAddress(QByteArrayLiteral("glGenVertexArraysOES")));
+ DeleteVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , const GLuint *)>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArraysOES")));
+ BindVertexArray = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint )>(context->getProcAddress(QByteArrayLiteral("glBindVertexArrayOES")));
} else {
- GenVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , GLuint *)>(context->getProcAddress(QByteArrayLiteral("glGenVertexArrays")));
- DeleteVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , const GLuint *)>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArrays")));
- BindVertexArray = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint )>(context->getProcAddress(QByteArrayLiteral("glBindVertexArray")));
+ if (context->hasExtension(QByteArrayLiteral("GL_APPLE_vertex_array_object"))) {
+ GenVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , GLuint *)>(context->getProcAddress(QByteArrayLiteral("glGenVertexArraysAPPLE")));
+ DeleteVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , const GLuint *)>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArraysAPPLE")));
+ BindVertexArray = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint )>(context->getProcAddress(QByteArrayLiteral("glBindVertexArrayAPPLE")));
+ } else {
+ GenVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , GLuint *)>(context->getProcAddress(QByteArrayLiteral("glGenVertexArrays")));
+ DeleteVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , const GLuint *)>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArrays")));
+ BindVertexArray = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint )>(context->getProcAddress(QByteArrayLiteral("glBindVertexArray")));
+ }
}
-#else
- GenVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , GLuint *)>(context->getProcAddress(QByteArrayLiteral("glGenVertexArraysOES")));
- DeleteVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , const GLuint *)>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArraysOES")));
- BindVertexArray = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint )>(context->getProcAddress(QByteArrayLiteral("glBindVertexArrayOES")));
-#endif
}
inline void glGenVertexArrays(GLsizei n, GLuint *arrays)
@@ -102,23 +103,15 @@ class QOpenGLVertexArrayObjectPrivate : public QObjectPrivate
public:
QOpenGLVertexArrayObjectPrivate()
: vao(0)
-#if defined(QT_OPENGL_ES_2)
- , vaoFuncs(0)
-#else
, vaoFuncsType(NotSupported)
-#endif
, context(0)
{
}
~QOpenGLVertexArrayObjectPrivate()
{
-#if defined(QT_OPENGL_ES_2)
- delete vaoFuncs;
-#else
- if ((vaoFuncsType == ARB) || (vaoFuncsType == APPLE))
+ if (vaoFuncsType == ARB || vaoFuncsType == APPLE || vaoFuncsType == OES)
delete vaoFuncs.helper;
-#endif
}
bool create();
@@ -131,9 +124,6 @@ public:
GLuint vao;
-#if defined(QT_OPENGL_ES_2)
- QVertexArrayObjectHelper *vaoFuncs;
-#else
union {
QOpenGLFunctions_3_0 *core_3_0;
QOpenGLFunctions_3_2_Core *core_3_2;
@@ -144,9 +134,10 @@ public:
Core_3_0,
Core_3_2,
ARB,
- APPLE
+ APPLE,
+ OES
} vaoFuncsType;
-#endif
+
QOpenGLContext *context;
};
@@ -157,13 +148,6 @@ bool QOpenGLVertexArrayObjectPrivate::create()
return false;
}
-#if !defined(QT_OPENGL_ES_2)
- if (QOpenGLFunctions::isES()) {
- qWarning("QOpenGLVertexArrayObject: Not supported on dynamic GL ES");
- return false;
- }
-#endif
-
Q_Q(QOpenGLVertexArrayObject);
if (context)
QObject::disconnect(context, SIGNAL(aboutToBeDestroyed()), q, SLOT(_q_contextAboutToBeDestroyed()));
@@ -176,35 +160,40 @@ bool QOpenGLVertexArrayObjectPrivate::create()
context = ctx;
QObject::connect(context, SIGNAL(aboutToBeDestroyed()), q, SLOT(_q_contextAboutToBeDestroyed()));
-#if defined(QT_OPENGL_ES_2)
- if (ctx->hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) {
- vaoFuncs = new QVertexArrayObjectHelper(ctx);
- vaoFuncs->glGenVertexArrays(1, &vao);
- }
-#else
- vaoFuncs.core_3_0 = 0;
- vaoFuncsType = NotSupported;
- QSurfaceFormat format = ctx->format();
- if (format.version() >= qMakePair<int, int>(3,2)) {
- vaoFuncs.core_3_2 = ctx->versionFunctions<QOpenGLFunctions_3_2_Core>();
- vaoFuncsType = Core_3_2;
- vaoFuncs.core_3_2->initializeOpenGLFunctions();
- vaoFuncs.core_3_2->glGenVertexArrays(1, &vao);
- } else if (format.majorVersion() >= 3) {
- vaoFuncs.core_3_0 = ctx->versionFunctions<QOpenGLFunctions_3_0>();
- vaoFuncsType = Core_3_0;
- vaoFuncs.core_3_0->initializeOpenGLFunctions();
- vaoFuncs.core_3_0->glGenVertexArrays(1, &vao);
- } else if (ctx->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) {
- vaoFuncs.helper = new QVertexArrayObjectHelper(ctx);
- vaoFuncsType = ARB;
- vaoFuncs.helper->glGenVertexArrays(1, &vao);
- } else if (ctx->hasExtension(QByteArrayLiteral("GL_APPLE_vertex_array_object"))) {
- vaoFuncs.helper = new QVertexArrayObjectHelper(ctx);
- vaoFuncsType = APPLE;
- vaoFuncs.helper->glGenVertexArrays(1, &vao);
- }
+ if (QOpenGLFunctions::isES()) {
+ if (ctx->hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) {
+ vaoFuncs.helper = new QVertexArrayObjectHelper(ctx);
+ vaoFuncsType = OES;
+ vaoFuncs.helper->glGenVertexArrays(1, &vao);
+ }
+ } else {
+ vaoFuncs.core_3_0 = 0;
+ vaoFuncsType = NotSupported;
+ QSurfaceFormat format = ctx->format();
+#ifndef QT_OPENGL_ES_2
+ if (format.version() >= qMakePair<int, int>(3,2)) {
+ vaoFuncs.core_3_2 = ctx->versionFunctions<QOpenGLFunctions_3_2_Core>();
+ vaoFuncsType = Core_3_2;
+ vaoFuncs.core_3_2->initializeOpenGLFunctions();
+ vaoFuncs.core_3_2->glGenVertexArrays(1, &vao);
+ } else if (format.majorVersion() >= 3) {
+ vaoFuncs.core_3_0 = ctx->versionFunctions<QOpenGLFunctions_3_0>();
+ vaoFuncsType = Core_3_0;
+ vaoFuncs.core_3_0->initializeOpenGLFunctions();
+ vaoFuncs.core_3_0->glGenVertexArrays(1, &vao);
+ } else
#endif
+ if (ctx->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) {
+ vaoFuncs.helper = new QVertexArrayObjectHelper(ctx);
+ vaoFuncsType = ARB;
+ vaoFuncs.helper->glGenVertexArrays(1, &vao);
+ } else if (ctx->hasExtension(QByteArrayLiteral("GL_APPLE_vertex_array_object"))) {
+ vaoFuncs.helper = new QVertexArrayObjectHelper(ctx);
+ vaoFuncsType = APPLE;
+ vaoFuncs.helper->glGenVertexArrays(1, &vao);
+ }
+ }
+
return (vao != 0);
}
@@ -212,25 +201,25 @@ void QOpenGLVertexArrayObjectPrivate::destroy()
{
if (!vao)
return;
-#if defined(QT_OPENGL_ES_2)
- if (vaoFuncs)
- vaoFuncs->glDeleteVertexArrays(1, &vao);
-#else
+
switch (vaoFuncsType) {
+#ifndef QT_OPENGL_ES_2
case Core_3_2:
vaoFuncs.core_3_2->glDeleteVertexArrays(1, &vao);
break;
case Core_3_0:
vaoFuncs.core_3_0->glDeleteVertexArrays(1, &vao);
break;
+#endif
case ARB:
case APPLE:
+ case OES:
vaoFuncs.helper->glDeleteVertexArrays(1, &vao);
break;
- case NotSupported:
+ default:
break;
}
-#endif
+
vao = 0;
}
@@ -244,48 +233,44 @@ void QOpenGLVertexArrayObjectPrivate::_q_contextAboutToBeDestroyed()
void QOpenGLVertexArrayObjectPrivate::bind()
{
-#if defined(QT_OPENGL_ES_2)
- if (vaoFuncs)
- vaoFuncs->glBindVertexArray(vao);
-#else
switch (vaoFuncsType) {
+#ifndef QT_OPENGL_ES_2
case Core_3_2:
vaoFuncs.core_3_2->glBindVertexArray(vao);
break;
case Core_3_0:
vaoFuncs.core_3_0->glBindVertexArray(vao);
break;
+#endif
case ARB:
case APPLE:
+ case OES:
vaoFuncs.helper->glBindVertexArray(vao);
break;
- case NotSupported:
+ default:
break;
}
-#endif
}
void QOpenGLVertexArrayObjectPrivate::release()
{
-#if defined(QT_OPENGL_ES_2)
- if (vaoFuncs)
- vaoFuncs->glBindVertexArray(0);
-#else
switch (vaoFuncsType) {
+#ifndef QT_OPENGL_ES_2
case Core_3_2:
vaoFuncs.core_3_2->glBindVertexArray(0);
break;
case Core_3_0:
vaoFuncs.core_3_0->glBindVertexArray(0);
break;
+#endif
case ARB:
case APPLE:
+ case OES:
vaoFuncs.helper->glBindVertexArray(0);
break;
- case NotSupported:
+ default:
break;
}
-#endif
}