summaryrefslogtreecommitdiffstats
path: root/src/opengl
diff options
context:
space:
mode:
Diffstat (limited to 'src/opengl')
-rw-r--r--src/opengl/gl2paintengineex/qglengineshadermanager.cpp3
-rw-r--r--src/opengl/gl2paintengineex/qglengineshadersource_p.h14
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp420
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h26
-rw-r--r--src/opengl/qegl.cpp10
-rw-r--r--src/opengl/qgl.cpp15
-rw-r--r--src/opengl/qgl_p.h3
-rw-r--r--src/opengl/qglextensions.cpp3
-rw-r--r--src/opengl/qglframebufferobject.cpp2
-rw-r--r--src/opengl/qglpixelbuffer.cpp4
-rw-r--r--src/opengl/qpixmapdata_gl.cpp5
11 files changed, 292 insertions, 213 deletions
diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
index ea57fdf..5c541d0 100644
--- a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
+++ b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
@@ -157,6 +157,7 @@ QGLEngineShaderManager::QGLEngineShaderManager(QGLContext* context)
simpleShaderProg->addShader(compiledShaders[PositionOnlyVertexShader]);
simpleShaderProg->addShader(compiledShaders[MainFragmentShader]);
simpleShaderProg->addShader(compiledShaders[ShockingPinkSrcFragmentShader]);
+ simpleShaderProg->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR);
simpleShaderProg->link();
if (!simpleShaderProg->isLinked()) {
qCritical() << "Errors linking simple shader:"
@@ -444,7 +445,7 @@ bool QGLEngineShaderManager::useCorrectShaderProg()
requiredProgram.program->addShader(requiredProgram.compositionFragShader);
// We have to bind the vertex attribute names before the program is linked:
- requiredProgram.program->bindAttributeLocation("inputVertex", QT_VERTEX_COORDS_ATTR);
+ requiredProgram.program->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR);
if (useTextureCoords)
requiredProgram.program->bindAttributeLocation("textureCoordArray", QT_TEXTURE_COORDS_ATTR);
diff --git a/src/opengl/gl2paintengineex/qglengineshadersource_p.h b/src/opengl/gl2paintengineex/qglengineshadersource_p.h
index 920d0bc..70cc67e 100644
--- a/src/opengl/gl2paintengineex/qglengineshadersource_p.h
+++ b/src/opengl/gl2paintengineex/qglengineshadersource_p.h
@@ -84,16 +84,20 @@ static const char* const qglslMainWithTexCoordsVertexShader = "\
static const char* const qglslPositionOnlyVertexShader = "\
attribute highp vec4 vertexCoordsArray;\
uniform highp mat4 pmvMatrix;\
+ uniform highp float depth;\
void setPosition(void)\
{\
gl_Position = pmvMatrix * vertexCoordsArray;\
+ gl_Position.z = depth;\
}";
static const char* const qglslUntransformedPositionVertexShader = "\
attribute highp vec4 vertexCoordsArray;\
+ uniform highp float depth;\
void setPosition(void)\
{\
gl_Position = vertexCoordsArray;\
+ gl_Position.z = depth;\
}";
// Pattern Brush - This assumes the texture size is 8x8 and thus, the inverted size is 0.125
@@ -104,9 +108,11 @@ static const char* const qglslPositionWithPatternBrushVertexShader = "\
uniform mediump vec2 invertedTextureSize; \
uniform mediump mat3 brushTransform; \
varying mediump vec2 patternTexCoords; \
+ uniform highp float depth;\
void setPosition(void) { \
gl_Position = pmvMatrix * vertexCoordsArray;\
gl_Position.xy = gl_Position.xy / gl_Position.w; \
+ gl_Position.z = depth;\
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
@@ -136,9 +142,11 @@ static const char* const qglslPositionWithLinearGradientBrushVertexShader = "\
uniform highp vec3 linearData; \
uniform highp mat3 brushTransform; \
varying mediump float index ; \
+ uniform highp float depth;\
void setPosition() { \
gl_Position = pmvMatrix * vertexCoordsArray;\
gl_Position.xy = gl_Position.xy / gl_Position.w; \
+ gl_Position.z = depth;\
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
@@ -166,10 +174,12 @@ static const char* const qglslPositionWithConicalGradientBrushVertexShader = "\
uniform mediump vec2 halfViewportSize; \
uniform highp mat3 brushTransform; \
varying highp vec2 A; \
+ uniform highp float depth;\
void setPosition(void)\
{\
gl_Position = pmvMatrix * vertexCoordsArray;\
gl_Position.xy = gl_Position.xy / gl_Position.w; \
+ gl_Position.z = depth; \
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
@@ -205,10 +215,12 @@ static const char* const qglslPositionWithRadialGradientBrushVertexShader = "\
uniform highp vec2 fmp; \
varying highp float b; \
varying highp vec2 A; \
+ uniform highp float depth;\
void setPosition(void) \
{\
gl_Position = pmvMatrix * vertexCoordsArray;\
gl_Position.xy = gl_Position.xy / gl_Position.w; \
+ gl_Position.z = depth; \
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
@@ -242,9 +254,11 @@ static const char* const qglslPositionWithTextureBrushVertexShader = "\
uniform mediump vec2 invertedTextureSize; \
uniform mediump mat3 brushTransform; \
varying mediump vec2 brushTextureCoords; \
+ uniform highp float depth;\
void setPosition(void) { \
gl_Position = pmvMatrix * vertexCoordsArray;\
gl_Position.xy = gl_Position.xy / gl_Position.w; \
+ gl_Position.z = depth; \
mediump vec2 viewportCoords = (gl_Position.xy + 1.0) * halfViewportSize; \
mediump vec3 hTexCoords = brushTransform * vec3(viewportCoords, 1); \
mediump float invertedHTexCoordsZ = 1.0 / hTexCoords.z; \
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
index 868adcf..bdea187 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
@@ -183,8 +183,8 @@ void QGLTextureGlyphCache::resizeTextureData(int width, int height)
pex->transferMode(BrushDrawingMode);
- glDisable(GL_SCISSOR_TEST);
glDisable(GL_DEPTH_TEST);
+ glDisable(GL_SCISSOR_TEST);
glViewport(0, 0, oldWidth, oldHeight);
@@ -217,7 +217,7 @@ void QGLTextureGlyphCache::resizeTextureData(int width, int height)
glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->current_fbo);
glViewport(0, 0, pex->width, pex->height);
- pex->updateDepthClip();
+ pex->updateDepthScissorTest();
}
void QGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph)
@@ -297,6 +297,11 @@ void QGL2PaintEngineExPrivate::useSimpleShader()
shaderManager->simpleProgram()->setUniformValue("pmvMatrix", pmvMatrix);
simpleShaderMatrixUniformDirty = false;
}
+
+ if (simpleShaderDepthUniformDirty) {
+ shaderManager->simpleProgram()->setUniformValue("depth", (GLfloat)q->state()->currentDepth);
+ simpleShaderDepthUniformDirty = false;
+ }
}
@@ -709,6 +714,7 @@ void QGL2PaintEngineExPrivate::fill(const QVectorPath& path)
if (path.shape() == QVectorPath::RectangleHint) {
QGLRect rect(points[0].x(), points[0].y(), points[2].x(), points[2].y());
prepareForDraw(currentBrush->isOpaque());
+
composite(rect);
}
else if (path.shape() == QVectorPath::EllipseHint) {
@@ -726,12 +732,14 @@ void QGL2PaintEngineExPrivate::fill(const QVectorPath& path)
// Stencil the brush onto the dest buffer
glStencilFunc(GL_NOTEQUAL, 0, 0xFFFF); // Pass if stencil buff value != 0
+ glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
+
glEnable(GL_STENCIL_TEST);
prepareForDraw(currentBrush->isOpaque());
composite(vertexCoordinateArray.boundingRect());
glDisable(GL_STENCIL_TEST);
- cleanStencilBuffer(vertexCoordinateArray.boundingRect());
+ glStencilMask(0);
}
}
@@ -739,17 +747,17 @@ void QGL2PaintEngineExPrivate::fill(const QVectorPath& path)
void QGL2PaintEngineExPrivate::fillStencilWithVertexArray(QGL2PEXVertexArray& vertexArray, bool useWindingFill)
{
// qDebug("QGL2PaintEngineExPrivate::fillStencilWithVertexArray()");
- if (stencilBuferDirty) {
+ glStencilMask(0xFFFF); // Enable stencil writes
+
+ if (stencilBufferDirty) {
// Clear the stencil buffer to zeros
glDisable(GL_STENCIL_TEST);
- glStencilMask(0xFFFF); // Enable writing to stencil buffer, otherwise glClear wont do anything.
glClearStencil(0); // Clear to zero
glClear(GL_STENCIL_BUFFER_BIT);
- stencilBuferDirty = false;
+ stencilBufferDirty = false;
}
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // Disable color writes
- glStencilMask(0xFFFF); // Enable stencil writes
glStencilFunc(GL_ALWAYS, 0, 0xFFFF); // Always pass the stencil test
// Setup the stencil op:
@@ -759,7 +767,7 @@ void QGL2PaintEngineExPrivate::fillStencilWithVertexArray(QGL2PEXVertexArray& ve
} else
glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT); // Simply invert the stencil bit
- // No point in using a fancy gradiant shader for writing into the stencil buffer!
+ // No point in using a fancy gradient shader for writing into the stencil buffer!
useSimpleShader();
glEnable(GL_STENCIL_TEST); // For some reason, this has to happen _after_ the simple shader is use()'d
@@ -770,41 +778,6 @@ void QGL2PaintEngineExPrivate::fillStencilWithVertexArray(QGL2PEXVertexArray& ve
// Enable color writes & disable stencil writes
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glStencilMask(0);
-}
-
-void QGL2PaintEngineExPrivate::cleanStencilBuffer(const QGLRect& area)
-{
-// qDebug("QGL2PaintEngineExPrivate::cleanStencilBuffer()");
- useSimpleShader();
-
- GLfloat rectVerts[] = {
- area.left, area.top,
- area.left, area.bottom,
- area.right, area.bottom,
- area.right, area.top
- };
-
- glEnableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
- glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, rectVerts);
-
- glEnable(GL_STENCIL_TEST);
- glStencilFunc(GL_ALWAYS, 0, 0xFFFF); // Always pass the stencil test
-
- glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // Disable color writes
- glStencilMask(0xFFFF); // Enable writing to stencil buffer
- glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); // Write 0's to stencil buffer
-
- glDisable(GL_BLEND);
-
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
- glDisableVertexAttribArray(QT_VERTEX_COORDS_ATTR);
-
- // Enable color writes & disable stencil writes
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glStencilMask(0);
- glDisable(GL_STENCIL_TEST);
}
void QGL2PaintEngineExPrivate::prepareForDraw(bool srcPixelsAreOpaque)
@@ -843,6 +816,7 @@ void QGL2PaintEngineExPrivate::prepareForDraw(bool srcPixelsAreOpaque)
// The shader program has changed so mark all uniforms as dirty:
brushUniformsDirty = true;
shaderMatrixUniformDirty = true;
+ depthUniformDirty = true;
}
if (brushUniformsDirty && mode != ImageDrawingMode)
@@ -853,6 +827,11 @@ void QGL2PaintEngineExPrivate::prepareForDraw(bool srcPixelsAreOpaque)
shaderMatrixUniformDirty = false;
}
+ if (depthUniformDirty) {
+ shaderManager->currentProgram()->setUniformValue("depth", (GLfloat)q->state()->currentDepth);
+ depthUniformDirty = false;
+ }
+
if (useGlobalOpacityUniform)
shaderManager->currentProgram()->setUniformValue("globalOpacity", (GLfloat)q->state()->opacity);
}
@@ -1062,7 +1041,6 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(const QPointF &p, const QTextIte
matrix.translate(p.x(), p.y());
ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
-
QFontEngineGlyphCache::Type glyphType = ti.fontEngine->glyphFormat >= 0
? QFontEngineGlyphCache::Type(ti.fontEngine->glyphFormat)
: QFontEngineGlyphCache::Raster_A8;
@@ -1146,6 +1124,7 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev)
}
d->ctx->d_ptr->active_engine = this;
+ d->last_created_state = 0;
d->drawable.makeCurrent();
QSize sz = d->drawable.size();
@@ -1172,12 +1151,16 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev)
d->brushUniformsDirty = true;
d->matrixDirty = true;
d->compositionModeDirty = true;
- d->stencilBuferDirty = true;
+ d->stencilBufferDirty = true;
+ d->simpleShaderDepthUniformDirty = true;
+ d->depthUniformDirty = true;
d->use_system_clip = !systemClip().isEmpty();
glDisable(GL_DEPTH_TEST);
glDisable(GL_SCISSOR_TEST);
+ glDepthFunc(GL_LEQUAL);
+ glDepthMask(false);
QGLPixmapData *source = d->drawable.copyOnBegin();
if (d->drawable.context()->d_func()->clear_on_painter_begin && d->drawable.autoFillBackground()) {
@@ -1201,7 +1184,7 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev)
d->drawTexture(QRectF(rect), QRectF(rect), rect.size(), true);
}
- updateClipRegion(QRegion(), Qt::NoClip);
+ d->systemStateChanged();
return true;
}
@@ -1245,260 +1228,297 @@ void QGL2PaintEngineEx::ensureActive()
ctx->d_ptr->active_engine = this;
glDisable(GL_DEPTH_TEST);
- glDisable(GL_SCISSOR_TEST);
glViewport(0, 0, d->width, d->height);
+
setState(state());
- d->updateDepthClip();
}
}
+void QGL2PaintEngineExPrivate::updateDepthScissorTest()
+{
+ Q_Q(QGL2PaintEngineEx);
+ if (q->state()->depthTestEnabled)
+ glEnable(GL_DEPTH_TEST);
+ else
+ glDisable(GL_DEPTH_TEST);
-/////////////////////////////////// State/Clipping stolen from QOpenGLPaintEngine //////////////////////////////////////////
+ if (q->state()->scissorTestEnabled)
+ glEnable(GL_SCISSOR_TEST);
+ else
+ glDisable(GL_SCISSOR_TEST);
+}
void QGL2PaintEngineEx::clipEnabledChanged()
{
Q_D(QGL2PaintEngineEx);
- d->updateDepthClip();
+ d->simpleShaderDepthUniformDirty = true;
+ d->depthUniformDirty = true;
+
+ if (painter()->hasClipping()) {
+ d->regenerateDepthClip();
+ } else {
+ if (d->use_system_clip) {
+ state()->currentDepth = -0.5f;
+ } else {
+ glDisable(GL_DEPTH_TEST);
+ state()->depthTestEnabled = false;
+ }
+ }
}
-void QGL2PaintEngineEx::clip(const QVectorPath &path, Qt::ClipOperation op)
+void QGL2PaintEngineExPrivate::writeClip(const QVectorPath &path, float depth)
{
-// qDebug("QGL2PaintEngineEx::clip()");
- const qreal *points = path.points();
- const QPainterPath::ElementType *types = path.elements();
- if (!types && path.shape() == QVectorPath::RectangleHint) {
- QRectF r(points[0], points[1], points[4]-points[0], points[5]-points[1]);
- updateClipRegion(QRegion(r.toRect()), op);
- return;
- }
+ transferMode(BrushDrawingMode);
- QPainterPath p;
- if (types) {
- int id = 0;
- for (int i=0; i<path.elementCount(); ++i) {
- switch(types[i]) {
- case QPainterPath::MoveToElement:
- p.moveTo(QPointF(points[id], points[id+1]));
- id+=2;
- break;
- case QPainterPath::LineToElement:
- p.lineTo(QPointF(points[id], points[id+1]));
- id+=2;
- break;
- case QPainterPath::CurveToElement: {
- QPointF p1(points[id], points[id+1]);
- QPointF p2(points[id+2], points[id+3]);
- QPointF p3(points[id+4], points[id+5]);
- p.cubicTo(p1, p2, p3);
- id+=6;
- break;
- }
- case QPainterPath::CurveToDataElement:
- ;
- break;
- }
- }
- } else if (!path.isEmpty()) {
- p.moveTo(QPointF(points[0], points[1]));
- int id = 2;
- for (int i=1; i<path.elementCount(); ++i) {
- p.lineTo(QPointF(points[id], points[id+1]));
- id+=2;
- }
+ if (matrixDirty)
+ updateMatrix();
+
+ if (q->state()->needsDepthBufferClear) {
+ glDepthMask(true);
+ glClearDepth(0.5);
+ glClear(GL_DEPTH_BUFFER_BIT);
+ q->state()->needsDepthBufferClear = false;
+ glDepthMask(false);
}
- if (path.hints() & QVectorPath::WindingFill)
- p.setFillRule(Qt::WindingFill);
- updateClipRegion(QRegion(p.toFillPolygon().toPolygon(), p.fillRule()), op);
- return;
+ if (path.isEmpty())
+ return;
+
+ glDisable(GL_BLEND);
+ glDepthMask(false);
+
+ vertexCoordinateArray.clear();
+ vertexCoordinateArray.addPath(path, inverseScale);
+
+ glDepthMask(GL_FALSE);
+ fillStencilWithVertexArray(vertexCoordinateArray, path.hasWindingFill());
+
+ // Stencil the clip onto the clip buffer
+ glColorMask(false, false, false, false);
+ glDepthMask(true);
+
+ shaderManager->simpleProgram()->setUniformValue("depth", depth);
+ simpleShaderDepthUniformDirty = true;
+
+ glEnable(GL_DEPTH_TEST);
+ glDepthFunc(GL_ALWAYS);
+
+ glStencilFunc(GL_NOTEQUAL, 0, 0xFFFF); // Pass if stencil buff value != 0
+ glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
+
+ glEnable(GL_STENCIL_TEST);
+ composite(vertexCoordinateArray.boundingRect());
+ glDisable(GL_STENCIL_TEST);
+
+ glStencilMask(0);
+
+ glColorMask(true, true, true, true);
+ glDepthMask(false);
}
-void QGL2PaintEngineEx::updateClipRegion(const QRegion &clipRegion, Qt::ClipOperation op)
+void QGL2PaintEngineEx::clip(const QVectorPath &path, Qt::ClipOperation op)
{
-// qDebug("QGL2PaintEngineEx::updateClipRegion()");
+// qDebug("QGL2PaintEngineEx::clip()");
Q_D(QGL2PaintEngineEx);
- QRegion sysClip = systemClip();
- if (op == Qt::NoClip && !d->use_system_clip) {
- state()->hasClipping = false;
- state()->clipRegion = QRegion();
- d->updateDepthClip();
- return;
- }
+ if (op == Qt::ReplaceClip && !d->hasClipOperations())
+ op = Qt::IntersectClip;
- bool isScreenClip = false;
- if (!d->use_system_clip) {
- QVector<QRect> untransformedRects = clipRegion.rects();
+ if (!path.isEmpty() && op == Qt::IntersectClip && (path.hints() & QVectorPath::RectangleHint)) {
+ const QPointF* const points = reinterpret_cast<const QPointF*>(path.points());
+ QRectF rect(points[0], points[2]);
- if (untransformedRects.size() == 1) {
- QPainterPath path;
- path.addRect(untransformedRects[0]);
- //path = d->matrix.map(path);
- path = state()->matrix.map(path);
-
-// if (path.contains(QRectF(QPointF(), d->drawable.size())))
-// isScreenClip = true;
- if (path.contains(QRectF(0.0, 0.0, d->width, d->height)))
- isScreenClip = true;
+ if (state()->matrix.type() <= QTransform::TxScale) {
+ rect = state()->matrix.mapRect(rect);
+
+ if (d->use_system_clip && rect.contains(d->systemClip.boundingRect())
+ || rect.contains(QRect(0, 0, d->width, d->height)))
+ return;
}
}
-// QRegion region = isScreenClip ? QRegion() : clipRegion * d->matrix;
- QRegion region = isScreenClip ? QRegion() : clipRegion * state()->matrix;
switch (op) {
case Qt::NoClip:
- if (!d->use_system_clip)
- break;
- state()->clipRegion = sysClip;
+ if (d->use_system_clip) {
+ glEnable(GL_DEPTH_TEST);
+ state()->depthTestEnabled = true;
+ state()->currentDepth = -0.5;
+ } else {
+ glDisable(GL_DEPTH_TEST);
+ state()->depthTestEnabled = false;
+ }
+ state()->canRestoreClip = false;
break;
case Qt::IntersectClip:
- if (isScreenClip)
- return;
- if (state()->hasClipping) {
- state()->clipRegion &= region;
- break;
- }
- // fall through
+ state()->maxDepth = (1.0f + state()->maxDepth) * 0.5;
+ d->writeClip(path, state()->maxDepth);
+ state()->currentDepth = 1.5 * state()->maxDepth - 0.5f;
+ state()->depthTestEnabled = true;
+ break;
case Qt::ReplaceClip:
- if (d->use_system_clip && !sysClip.isEmpty())
- state()->clipRegion = region & sysClip;
- else
- state()->clipRegion = region;
+ d->systemStateChanged();
+ state()->maxDepth = 0.5f;
+ glDepthFunc(GL_ALWAYS);
+ d->writeClip(path, state()->maxDepth);
+ state()->currentDepth = 0.25f;
+ state()->canRestoreClip = false;
+ state()->depthTestEnabled = true;
break;
case Qt::UniteClip:
- state()->clipRegion |= region;
- if (d->use_system_clip && !sysClip.isEmpty())
- state()->clipRegion &= sysClip;
- break;
- default:
+ glDepthFunc(GL_ALWAYS);
+ d->writeClip(path, state()->maxDepth);
+ state()->canRestoreClip = false;
+ state()->depthTestEnabled = true;
break;
}
- if (isScreenClip) {
- state()->hasClipping = false;
- state()->clipRegion = QRegion();
- } else {
- state()->hasClipping = op != Qt::NoClip || d->use_system_clip;
+ glDepthFunc(GL_LEQUAL);
+ if (state()->depthTestEnabled) {
+ glEnable(GL_DEPTH_TEST);
+ d->simpleShaderDepthUniformDirty = true;
+ d->depthUniformDirty = true;
}
-
- d->updateDepthClip();
}
-void QGL2PaintEngineExPrivate::systemStateChanged()
+void QGL2PaintEngineExPrivate::regenerateDepthClip()
{
- Q_Q(QGL2PaintEngineEx);
- use_system_clip = !systemClip.isEmpty();
-
- if (q->painter()->hasClipping())
- q->updateClipRegion(q->painter()->clipRegion(), Qt::ReplaceClip);
- else
- q->updateClipRegion(QRegion(), Qt::NoClip);
+ systemStateChanged();
+ replayClipOperations();
}
-void QGL2PaintEngineExPrivate::updateDepthClip()
+void QGL2PaintEngineExPrivate::systemStateChanged()
{
-// qDebug("QGL2PaintEngineExPrivate::updateDepthClip()");
-
Q_Q(QGL2PaintEngineEx);
+ use_system_clip = !systemClip.isEmpty();
- q->ensureActive();
glDisable(GL_DEPTH_TEST);
+ q->state()->depthTestEnabled = false;
+ q->state()->scissorTestEnabled = false;
+ q->state()->needsDepthBufferClear = true;
+
glDisable(GL_SCISSOR_TEST);
- if (!q->state()->hasClipping)
- return;
+ q->state()->currentDepth = -0.5f;
+ q->state()->maxDepth = 0.5f;
- const QVector<QRect> rects = q->state()->clipEnabled ? q->state()->clipRegion.rects() : q->systemClip().rects();
- if (rects.size() == 1) {
- QRect fastClip = rects.at(0);
+ if (use_system_clip) {
+ QRect bounds = systemClip.boundingRect();
+ if (systemClip.numRects() == 1
+ && bounds == QRect(0, 0, width, height))
+ {
+ q->state()->needsDepthBufferClear = true;
+ } else {
+ glEnable(GL_SCISSOR_TEST);
- glEnable(GL_SCISSOR_TEST);
+ const int left = bounds.left();
+ const int width = bounds.width();
+ const int bottom = height - (bounds.top() + bounds.height());
+ const int height = bounds.height();
- const int left = fastClip.left();
- const int width = fastClip.width();
- const int bottom = height - (fastClip.bottom() + 1);
- const int height = fastClip.height();
+ glScissor(left, bottom, width, height);
- glScissor(left, bottom, width, height);
- return;
- }
+ QTransform transform = q->state()->matrix;
+ q->state()->matrix = QTransform();
+ q->transformChanged();
- glClearDepth(0x0);
- glDepthMask(true);
- glClear(GL_DEPTH_BUFFER_BIT);
- glClearDepth(0x1);
+ q->state()->needsDepthBufferClear = false;
- glEnable(GL_SCISSOR_TEST);
- for (int i = 0; i < rects.size(); ++i) {
- QRect rect = rects.at(i);
+ glDepthMask(true);
- const int left = rect.left();
- const int width = rect.width();
- const int bottom = height - (rect.bottom() + 1);
- const int height = rect.height();
+ glClearDepth(0);
+ glClear(GL_DEPTH_BUFFER_BIT);
- glScissor(left, bottom, width, height);
+ QPainterPath path;
+ path.addRegion(systemClip);
- glClear(GL_DEPTH_BUFFER_BIT);
- }
- glDisable(GL_SCISSOR_TEST);
+ glDepthFunc(GL_ALWAYS);
+ writeClip(qtVectorPathForPath(path), 0.0f);
+ glDepthFunc(GL_LEQUAL);
- glDepthMask(false);
- glDepthFunc(GL_LEQUAL);
- glEnable(GL_DEPTH_TEST);
-}
+ glEnable(GL_DEPTH_TEST);
+ q->state()->depthTestEnabled = true;
+ q->state()->scissorTestEnabled = true;
+ q->state()->matrix = transform;
+ q->transformChanged();
+ }
+ q->state()->currentDepth = -0.5f;
+ simpleShaderDepthUniformDirty = true;
+ depthUniformDirty = true;
+ }
+}
void QGL2PaintEngineEx::setState(QPainterState *new_state)
{
-// qDebug("QGL2PaintEngineEx::setState()");
+ // qDebug("QGL2PaintEngineEx::setState()");
Q_D(QGL2PaintEngineEx);
QOpenGL2PaintEngineState *s = static_cast<QOpenGL2PaintEngineState *>(new_state);
-
QOpenGL2PaintEngineState *old_state = state();
- const bool needsDepthClipUpdate = !old_state
- || s->clipEnabled != old_state->clipEnabled
- || (s->clipEnabled && s->clipRegion != old_state->clipRegion);
QPaintEngineEx::setState(s);
- if (needsDepthClipUpdate)
- d->updateDepthClip();
+ if (s == d->last_created_state) {
+ d->last_created_state = 0;
+ return;
+ }
d->matrixDirty = true;
d->compositionModeDirty = true;
d->brushTextureDirty = true;
d->brushUniformsDirty = true;
+ d->simpleShaderDepthUniformDirty = true;
+ d->depthUniformDirty = true;
d->simpleShaderMatrixUniformDirty = true;
d->shaderMatrixUniformDirty = true;
+
+ if (old_state && old_state != s && old_state->canRestoreClip) {
+ d->updateDepthScissorTest();
+ glDepthMask(false);
+ glDepthFunc(GL_LEQUAL);
+ s->maxDepth = old_state->maxDepth;
+ } else {
+ d->regenerateDepthClip();
+ }
}
QPainterState *QGL2PaintEngineEx::createState(QPainterState *orig) const
{
+ Q_D(const QGL2PaintEngineEx);
+
QOpenGL2PaintEngineState *s;
if (!orig)
s = new QOpenGL2PaintEngineState();
else
s = new QOpenGL2PaintEngineState(*static_cast<QOpenGL2PaintEngineState *>(orig));
+ d->last_created_state = s;
return s;
}
QOpenGL2PaintEngineState::QOpenGL2PaintEngineState(QOpenGL2PaintEngineState &other)
: QPainterState(other)
{
- clipRegion = other.clipRegion;
- hasClipping = other.hasClipping;
+ needsDepthBufferClear = other.needsDepthBufferClear;
+ depthTestEnabled = other.depthTestEnabled;
+ scissorTestEnabled = other.scissorTestEnabled;
+ currentDepth = other.currentDepth;
+ maxDepth = other.maxDepth;
+ canRestoreClip = other.canRestoreClip;
}
QOpenGL2PaintEngineState::QOpenGL2PaintEngineState()
{
- hasClipping = false;
+ needsDepthBufferClear = true;
+ depthTestEnabled = false;
+ scissorTestEnabled = false;
+ currentDepth = -0.5f;
+ maxDepth = 0.5f;
+ canRestoreClip = true;
}
QOpenGL2PaintEngineState::~QOpenGL2PaintEngineState()
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
index 7213474..db39ced 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
@@ -77,8 +77,15 @@ public:
QOpenGL2PaintEngineState();
~QOpenGL2PaintEngineState();
- QRegion clipRegion;
- bool hasClipping;
+ bool needsDepthBufferClear;
+ qreal depthBufferClearValue;
+
+ bool depthTestEnabled;
+ bool scissorTestEnabled;
+ qreal currentDepth;
+ qreal maxDepth;
+
+ bool canRestoreClip;
};
@@ -116,7 +123,6 @@ public:
Type type() const { return OpenGL; }
- // State stuff is just for clipping and ripped off from QGLPaintEngine
void setState(QPainterState *s);
QPainterState *createState(QPainterState *orig) const;
inline QOpenGL2PaintEngineState *state() {
@@ -125,7 +131,6 @@ public:
inline const QOpenGL2PaintEngineState *state() const {
return static_cast<const QOpenGL2PaintEngineState *>(QPaintEngineEx::state());
}
- void updateClipRegion(const QRegion &clipRegion, Qt::ClipOperation op);
virtual void sync();
private:
@@ -169,7 +174,6 @@ public:
// ^ Composites the bounding rect onto dest buffer
void fillStencilWithVertexArray(QGL2PEXVertexArray& vertexArray, bool useWindingFill);
// ^ Calls drawVertexArrays to render into stencil buffer
- void cleanStencilBuffer(const QGLRect& area);
void prepareForDraw(bool srcPixelsAreOpaque);
@@ -180,9 +184,10 @@ public:
QGLDrawable drawable;
int width, height;
QGLContext *ctx;
-
EngineMode mode;
+ mutable QOpenGL2PaintEngineState *last_created_state;
+
// Dirty flags
bool matrixDirty; // Implies matrix uniforms are also dirty
bool compositionModeDirty;
@@ -190,7 +195,9 @@ public:
bool brushUniformsDirty;
bool simpleShaderMatrixUniformDirty;
bool shaderMatrixUniformDirty;
- bool stencilBuferDirty;
+ bool stencilBufferDirty;
+ bool depthUniformDirty;
+ bool simpleShaderDepthUniformDirty;
const QBrush* currentBrush; // May not be the state's brush!
@@ -206,8 +213,9 @@ public:
QGLEngineShaderManager* shaderManager;
- // Clipping & state stuff stolen from QOpenGLPaintEngine:
- void updateDepthClip();
+ void writeClip(const QVectorPath &path, float depth);
+ void updateDepthScissorTest();
+ void regenerateDepthClip();
void systemStateChanged();
uint use_system_clip : 1;
};
diff --git a/src/opengl/qegl.cpp b/src/opengl/qegl.cpp
index f1ae4ed..290f77c 100644
--- a/src/opengl/qegl.cpp
+++ b/src/opengl/qegl.cpp
@@ -413,12 +413,18 @@ int QEglProperties::value(int name) const
case EGL_RED_SIZE: return 0;
case EGL_GREEN_SIZE: return 0;
case EGL_BLUE_SIZE: return 0;
- case EGL_LUMINANCE_SIZE: return 0;
case EGL_ALPHA_SIZE: return 0;
+#if defined(EGL_LUMINANCE_SIZE)
+ case EGL_LUMINANCE_SIZE: return 0;
+#endif
+#if defined(EGL_ALPHA_MASK_SIZE)
case EGL_ALPHA_MASK_SIZE: return 0;
+#endif
case EGL_BIND_TO_TEXTURE_RGB: return EGL_DONT_CARE;
case EGL_BIND_TO_TEXTURE_RGBA: return EGL_DONT_CARE;
+#if defined(EGL_COLOR_BUFFER_TYPE)
case EGL_COLOR_BUFFER_TYPE: return EGL_RGB_BUFFER;
+#endif
case EGL_CONFIG_CAVEAT: return EGL_DONT_CARE;
case EGL_CONFIG_ID: return EGL_DONT_CARE;
case EGL_DEPTH_SIZE: return 0;
@@ -427,7 +433,9 @@ int QEglProperties::value(int name) const
case EGL_NATIVE_VISUAL_TYPE: return EGL_DONT_CARE;
case EGL_MAX_SWAP_INTERVAL: return EGL_DONT_CARE;
case EGL_MIN_SWAP_INTERVAL: return EGL_DONT_CARE;
+#if defined(EGL_RENDERABLE_TYPE)
case EGL_RENDERABLE_TYPE: return EGL_OPENGL_ES_BIT;
+#endif
case EGL_SAMPLE_BUFFERS: return 0;
case EGL_SAMPLES: return 0;
case EGL_STENCIL_SIZE: return 0;
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index 2e72851..146d088 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -65,12 +65,19 @@
#include "qimage.h"
#include "qgl_p.h"
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
#include "gl2paintengineex/qpaintengineex_opengl2_p.h"
+#endif
#ifndef QT_OPENGL_ES_2
#include <private/qpaintengine_opengl_p.h>
#endif
+#ifdef Q_WS_QWS
+#include <private/qglpaintdevice_qws_p.h>
+#include <private/qglwindowsurface_qws_p.h>
+#endif
+
#include <qglpixelbuffer.h>
#include <qglframebufferobject.h>
@@ -4428,7 +4435,11 @@ void QGLDrawable::swapBuffers()
void QGLDrawable::makeCurrent()
{
previous_fbo = 0;
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
if (!pixmapData && !fbo) {
+#else
+ if (!fbo) {
+#endif
QGLContext *ctx = context();
previous_fbo = ctx->d_ptr->current_fbo;
ctx->d_ptr->current_fbo = 0;
@@ -4561,8 +4572,10 @@ QColor QGLDrawable::backgroundColor() const
{
if (widget)
return widget->palette().brush(widget->backgroundRole()).color();
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
else if (pixmapData)
return pixmapData->fillColor();
+#endif
return QApplication::palette().brush(QPalette::Background).color();
}
@@ -4590,8 +4603,10 @@ bool QGLDrawable::autoFillBackground() const
{
if (widget)
return widget->autoFillBackground();
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
else if (pixmapData)
return pixmapData->needsFill();
+#endif
else
return false;
}
diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h
index b3523d4..4af8598 100644
--- a/src/opengl/qgl_p.h
+++ b/src/opengl/qgl_p.h
@@ -428,8 +428,7 @@ private:
extern Q_OPENGL_EXPORT QGLShareRegister* qgl_share_reg();
#ifdef Q_WS_QWS
-class QOpenGLPaintEngine;
-extern QOpenGLPaintEngine* qt_qgl_paint_engine();
+extern QPaintEngine* qt_qgl_paint_engine();
extern EGLDisplay qt_qgl_egl_display();
#endif
diff --git a/src/opengl/qglextensions.cpp b/src/opengl/qglextensions.cpp
index 3c198fb..10ca613 100644
--- a/src/opengl/qglextensions.cpp
+++ b/src/opengl/qglextensions.cpp
@@ -337,6 +337,9 @@ bool qt_resolve_version_2_0_functions(QGLContext *ctx)
if (!qt_resolve_version_1_3_functions(ctx))
gl2supported = false;
+ if (!qt_resolve_framebufferobject_extensions(ctx))
+ gl2supported = false;
+
if (glStencilOpSeparate)
return gl2supported;
diff --git a/src/opengl/qglframebufferobject.cpp b/src/opengl/qglframebufferobject.cpp
index 3e7ca0a..fb16107 100644
--- a/src/opengl/qglframebufferobject.cpp
+++ b/src/opengl/qglframebufferobject.cpp
@@ -43,7 +43,9 @@
#include <qdebug.h>
#include <private/qgl_p.h>
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
#include <private/qpaintengineex_opengl2_p.h>
+#endif
#ifndef QT_OPENGL_ES_2
#include <private/qpaintengine_opengl_p.h>
diff --git a/src/opengl/qglpixelbuffer.cpp b/src/opengl/qglpixelbuffer.cpp
index 483856a..9b7a506 100644
--- a/src/opengl/qglpixelbuffer.cpp
+++ b/src/opengl/qglpixelbuffer.cpp
@@ -76,7 +76,11 @@
\sa {opengl/pbuffers}{Pbuffers Example}
*/
+#include <QtCore/qglobal.h>
+
+#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
#include <private/qpaintengineex_opengl2_p.h>
+#endif
#include <qglpixelbuffer.h>
#include <private/qglpixelbuffer_p.h>
diff --git a/src/opengl/qpixmapdata_gl.cpp b/src/opengl/qpixmapdata_gl.cpp
index 8d94c8b..98c406b 100644
--- a/src/opengl/qpixmapdata_gl.cpp
+++ b/src/opengl/qpixmapdata_gl.cpp
@@ -389,6 +389,11 @@ QPaintEngine* QGLPixmapData::paintEngine() const
sz.setWidth(qMax(m_width, qRound(sz.width() * 1.5)));
if (sz.height() < m_height)
sz.setHeight(qMax(m_height, qRound(sz.height() * 1.5)));
+
+ // wasting too much space?
+ if (sz.width() * sz.height() > m_width * m_height * 2.5)
+ sz = QSize(m_width, m_height);
+
delete textureBufferStack.at(currentTextureBuffer).fbo;
textureBufferStack[currentTextureBuffer] =
createTextureBuffer(sz, textureBufferStack.at(currentTextureBuffer).engine);