summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/opengl/qglpixmapfilter.cpp67
-rw-r--r--src/opengl/qpaintengine_opengl.cpp14
-rw-r--r--src/opengl/qpaintengine_opengl_p.h2
3 files changed, 22 insertions, 61 deletions
diff --git a/src/opengl/qglpixmapfilter.cpp b/src/opengl/qglpixmapfilter.cpp
index 6ebc397..7876661 100644
--- a/src/opengl/qglpixmapfilter.cpp
+++ b/src/opengl/qglpixmapfilter.cpp
@@ -68,17 +68,16 @@ void QGLPixmapFilterBase::drawImpl(QPainter *painter, const QPointF &pos, const
processGL(painter, pos, src, source);
}
-class QGLPixmapColorizeFilter: public QGLPixmapFilter<QPixmapColorizeFilter>
+class QGLPixmapColorizeFilter: public QGLCustomShaderStage, public QGLPixmapFilter<QPixmapColorizeFilter>
{
public:
- QGLPixmapColorizeFilter();
+ void setUniforms(QGLShaderProgram *program);
protected:
bool processGL(QPainter *painter, const QPointF &pos, const QPixmap &pixmap, const QRectF &srcRect) const;
private:
- mutable QGLShaderProgram m_program;
- int m_colorUniform;
+ mutable QGLShader *m_shader;
};
class QGLPixmapConvolutionFilter: public QGLPixmapFilter<QPixmapConvolutionFilter>
@@ -104,9 +103,6 @@ private:
class QGLPixmapBlurFilter : public QGLCustomShaderStage, public QGLPixmapFilter<QPixmapBlurFilter>
{
public:
- QGLPixmapBlurFilter();
- ~QGLPixmapBlurFilter();
-
void setUniforms(QGLShaderProgram *program);
protected:
@@ -120,8 +116,6 @@ private:
mutable QSize m_textureSize;
mutable bool m_horizontalBlur;
-
- QGLShaderProgram *m_program;
};
extern QGLWidget *qt_gl_share_widget();
@@ -183,41 +177,34 @@ static void qgl_drawTexture(const QRectF &rect, int tx_width, int tx_height, con
}
static const char *qt_gl_colorize_filter =
- "uniform sampler2D texture;"
- "uniform vec3 color;"
- "void main(void)"
+ "uniform lowp vec4 colorizeColor;"
+ "uniform lowp float colorizeStrength;"
+ "lowp vec4 customShader(lowp sampler2D src, highp vec2 srcCoords)"
"{"
- " vec2 coords = gl_TexCoord[0].st;"
- " vec4 src = texture2D(texture, coords);"
- " float gray = dot(src.rgb, vec3(0.212671, 0.715160, 0.072169));"
- " vec3 colorizeed = 1.0-((1.0-gray)*(1.0-color));"
- " gl_FragColor = vec4(colorizeed, src.a);"
+ " lowp vec4 srcPixel = texture2D(src, srcCoords);"
+ " lowp float gray = dot(srcPixel.rgb, vec3(0.212671, 0.715160, 0.072169));"
+ " lowp vec3 colorized = 1.0-((1.0-gray)*(1.0-colorizeColor.rgb));"
+ " return vec4(mix(srcPixel.rgb, colorized * srcPixel.a, colorizeStrength), srcPixel.a);"
"}";
-QGLPixmapColorizeFilter::QGLPixmapColorizeFilter()
+bool QGLPixmapColorizeFilter::processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &) const
{
- m_program.addShader(QGLShader::FragmentShader, qt_gl_colorize_filter);
- m_program.link();
- m_program.enable();
- m_program.setUniformValue(m_program.uniformLocation("texture"), GLint(0)); // GL_TEXTURE_0
- m_colorUniform = m_program.uniformLocation("color");
-}
+ QGLPixmapColorizeFilter *filter = const_cast<QGLPixmapColorizeFilter *>(this);
+ filter->setSource(qt_gl_colorize_filter);
-bool QGLPixmapColorizeFilter::processGL(QPainter *, const QPointF &pos, const QPixmap &src, const QRectF &srcRect) const
-{
- bindTexture(src);
-
- QColor col = color();
- m_program.enable();
- m_program.setUniformValue(m_colorUniform, col.redF(), col.greenF(), col.blueF());
-
- QRectF target = (srcRect.isNull() ? QRectF(src.rect()) : srcRect).translated(pos);
- qgl_drawTexture(target, src.width(), src.height(), srcRect);
- m_program.disable();
+ filter->setOnPainter(painter);
+ painter->drawPixmap(pos, src);
+ filter->removeFromPainter(painter);
return true;
}
+void QGLPixmapColorizeFilter::setUniforms(QGLShaderProgram *program)
+{
+ program->setUniformValue("colorizeColor", color());
+ program->setUniformValue("colorizeStrength", float(strength()));
+}
+
// generates convolution filter code for arbitrary sized kernel
QByteArray QGLPixmapConvolutionFilter::generateConvolutionShader() const {
QByteArray code;
@@ -310,14 +297,6 @@ bool QGLPixmapConvolutionFilter::processGL(QPainter *, const QPointF &pos, const
return true;
}
-QGLPixmapBlurFilter::QGLPixmapBlurFilter()
-{
-}
-
-QGLPixmapBlurFilter::~QGLPixmapBlurFilter()
-{
-}
-
bool QGLPixmapBlurFilter::processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &) const
{
QGLPixmapBlurFilter *filter = const_cast<QGLPixmapBlurFilter *>(this);
@@ -384,8 +363,6 @@ void QGLPixmapBlurFilter::setUniforms(QGLShaderProgram *program)
program->setUniformValue("delta", 1.0, 0.0);
else
program->setUniformValue("delta", 0.0, 1.0);
-
- m_program = program;
}
static inline qreal gaussian(qreal dx, qreal sigma)
diff --git a/src/opengl/qpaintengine_opengl.cpp b/src/opengl/qpaintengine_opengl.cpp
index ff00f29..bd3883a 100644
--- a/src/opengl/qpaintengine_opengl.cpp
+++ b/src/opengl/qpaintengine_opengl.cpp
@@ -5625,20 +5625,6 @@ void QOpenGLPaintEnginePrivate::ensureDrawableTexture()
#endif
}
-QPixmapFilter *QOpenGLPaintEngine::createPixmapFilter(int type) const
-{
-#if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL)
- if (QGLContext::currentContext())
- return QGLContext::currentContext()->d_func()->createPixmapFilter(type);
- else
- return 0;
-#else
- Q_UNUSED(type);
- return 0;
-#endif
-}
-
-
QT_END_NAMESPACE
#include "qpaintengine_opengl.moc"
diff --git a/src/opengl/qpaintengine_opengl_p.h b/src/opengl/qpaintengine_opengl_p.h
index c8f460a..4fea638 100644
--- a/src/opengl/qpaintengine_opengl_p.h
+++ b/src/opengl/qpaintengine_opengl_p.h
@@ -136,8 +136,6 @@ public:
void drawEllipse(const QRectF &rect);
- QPixmapFilter *createPixmapFilter(int type) const;
-
#ifdef Q_WS_WIN
HDC handle() const;
#else