From 4b11b7b6b8a9bdcdc2e2104fc06ba554d1c50074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 27 Nov 2015 15:37:08 +0100 Subject: [PATCH] [kwineffects] Add a generateCustomShader to ShaderManager This method allows to generate a shader with ShaderTraits but one part (e.g. vertex and/or fragment) to be replaced by custom shader code. Thus it can be used as a replacement for the load*(ShaderType) variants and allows more effects to transition to shaders using traits. --- libkwineffects/kwinglutils.cpp | 9 +++++++-- libkwineffects/kwinglutils.h | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/libkwineffects/kwinglutils.cpp b/libkwineffects/kwinglutils.cpp index b643333dbb..c0bc67bcfc 100644 --- a/libkwineffects/kwinglutils.cpp +++ b/libkwineffects/kwinglutils.cpp @@ -987,8 +987,13 @@ QByteArray ShaderManager::generateFragmentSource(ShaderTraits traits) const GLShader *ShaderManager::generateShader(ShaderTraits traits) { - const QByteArray vertex = generateVertexSource(traits); - const QByteArray fragment = generateFragmentSource(traits); + return generateCustomShader(traits); +} + +GLShader *ShaderManager::generateCustomShader(ShaderTraits traits, const QByteArray &vertexSource, const QByteArray &fragmentSource) +{ + const QByteArray vertex = vertexSource.isEmpty() ? generateVertexSource(traits) : vertexSource; + const QByteArray fragment = fragmentSource.isEmpty() ? generateFragmentSource(traits) : fragmentSource; #if 0 qCDebug(LIBKWINGLUTILS) << "**************"; diff --git a/libkwineffects/kwinglutils.h b/libkwineffects/kwinglutils.h index 553e713cff..1db702e6c9 100644 --- a/libkwineffects/kwinglutils.h +++ b/libkwineffects/kwinglutils.h @@ -361,6 +361,24 @@ public: **/ GLShader *loadShaderFromCode(const QByteArray &vertexSource, const QByteArray &fragmentSource); + /** + * Creates a custom shader with the given @p traits and custom @p vertexSource and or @p fragmentSource. + * If the @p vertexSource is empty a vertex shader with the given @p traits is generated. + * If it is not empty the @p vertexSource is used as the source for the vertex shader. + * + * The same applies for argument @p fragmentSource just for the fragment shader. + * + * So if both @p vertesSource and @p fragmentSource are provided the @p traits are ignored. + * If neither are provided a new shader following the @p traits is generated. + * + * @param traits The shader traits for generating the shader + * @param vertesSource optional vertex shader source code to be used instead of shader traits + * @param fragmentSource optional fragment shader source code to be used instead of shader traits + * @return new generated shader + * @since 5.6 + **/ + GLShader *generateCustomShader(ShaderTraits traits, const QByteArray &vertexSource = QByteArray(), const QByteArray &fragmentSource = QByteArray()); + /** * Compiles and tests the dynamically generated shaders. * Returns true if successful and false otherwise.