diff options
author | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2015-04-28 18:35:38 +0200 |
---|---|---|
committer | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2015-04-30 09:02:20 +0000 |
commit | fe13f5bb05ef278eb5109a9518118dda7ddb0b9d (patch) | |
tree | 167e3b090efb82e41dac6fd2cd8fd5504a72a60b /src/qtmultimediaquicktools/qsgvideonode_texture.cpp | |
parent | 61033aa420b4d34107e3cc67e8751506bc4ab745 (diff) |
Minor refactor of built-in QSGVideoNodes.v5.5.0-beta1
- Load shader source from resource files.
- Correctly report material types: each material can use different
shaders depending on the video pixel format but it was reporting
a unique material type. This was causing the node to keep using
the same shader even if its pixel format changed.
Change-Id: Ib903ecd6e7dd1dd56d7cefe255ab7049933df17d
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'src/qtmultimediaquicktools/qsgvideonode_texture.cpp')
-rw-r--r-- | src/qtmultimediaquicktools/qsgvideonode_texture.cpp | 82 |
1 files changed, 25 insertions, 57 deletions
diff --git a/src/qtmultimediaquicktools/qsgvideonode_texture.cpp b/src/qtmultimediaquicktools/qsgvideonode_texture.cpp index 3dc845c88..fd8d8719c 100644 --- a/src/qtmultimediaquicktools/qsgvideonode_texture.cpp +++ b/src/qtmultimediaquicktools/qsgvideonode_texture.cpp @@ -69,10 +69,11 @@ QSGVideoNode *QSGVideoNodeFactory_Texture::createNode(const QVideoSurfaceFormat class QSGVideoMaterialShader_Texture : public QSGMaterialShader { public: - QSGVideoMaterialShader_Texture(QVideoFrame::PixelFormat pixelFormat) - : QSGMaterialShader(), - m_pixelFormat(pixelFormat) + QSGVideoMaterialShader_Texture() + : QSGMaterialShader() { + setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qtmultimediaquicktools/shaders/rgbvideo.vert")); + setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qtmultimediaquicktools/shaders/rgbvideo.frag")); } void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial); @@ -87,56 +88,6 @@ public: } protected: - - virtual const char *vertexShader() const { - const char *shader = - "uniform highp mat4 qt_Matrix; \n" - "attribute highp vec4 qt_VertexPosition; \n" - "attribute highp vec2 qt_VertexTexCoord; \n" - "varying highp vec2 qt_TexCoord; \n" - "void main() { \n" - " qt_TexCoord = qt_VertexTexCoord; \n" - " gl_Position = qt_Matrix * qt_VertexPosition; \n" - "}"; - return shader; - } - - virtual const char *fragmentShader() const { - static const char *shader = - "uniform sampler2D rgbTexture;" - "uniform lowp float opacity;" - "" - "varying highp vec2 qt_TexCoord;" - "" - "void main()" - "{" - " gl_FragColor = texture2D(rgbTexture, qt_TexCoord) * opacity;" - "}"; - - static const char *colorsSwapShader = - "uniform sampler2D rgbTexture;" - "uniform lowp float opacity;" - "" - "varying highp vec2 qt_TexCoord;" - "" - "void main()" - "{" - " gl_FragColor = vec4(texture2D(rgbTexture, qt_TexCoord).bgr, 1.0) * opacity;" - "}"; - - if (!QMediaOpenGLHelper::isANGLE()) { - switch (m_pixelFormat) { - case QVideoFrame::Format_RGB32: - case QVideoFrame::Format_ARGB32: - return colorsSwapShader; - default: - break; - } - } - - return shader; - } - virtual void initialize() { m_id_matrix = program()->uniformLocation("qt_Matrix"); m_id_Texture = program()->uniformLocation("rgbTexture"); @@ -146,7 +97,16 @@ protected: int m_id_matrix; int m_id_Texture; int m_id_opacity; - QVideoFrame::PixelFormat m_pixelFormat; +}; + +class QSGVideoMaterialShader_Texture_swizzle : public QSGVideoMaterialShader_Texture +{ +public: + QSGVideoMaterialShader_Texture_swizzle() + : QSGVideoMaterialShader_Texture() + { + setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qtmultimediaquicktools/shaders/rgbvideo_swizzle.frag")); + } }; @@ -167,12 +127,13 @@ public: } virtual QSGMaterialType *type() const { - static QSGMaterialType theType; - return &theType; + static QSGMaterialType normalType, swizzleType; + return needsSwizzling() ? &swizzleType : &normalType; } virtual QSGMaterialShader *createShader() const { - return new QSGVideoMaterialShader_Texture(m_format.pixelFormat()); + return needsSwizzling() ? new QSGVideoMaterialShader_Texture_swizzle + : new QSGVideoMaterialShader_Texture; } virtual int compare(const QSGMaterial *other) const { @@ -220,6 +181,13 @@ public: QVideoSurfaceFormat m_format; GLuint m_textureId; qreal m_opacity; + +private: + bool needsSwizzling() const { + return !QMediaOpenGLHelper::isANGLE() + && (m_format.pixelFormat() == QVideoFrame::Format_RGB32 + || m_format.pixelFormat() == QVideoFrame::Format_ARGB32); + } }; |