[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.
This commit is contained in:
Martin Gräßlin 2015-11-27 15:37:08 +01:00
parent 3be6ff9f12
commit 4b11b7b6b8
2 changed files with 25 additions and 2 deletions

View file

@ -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) << "**************";

View file

@ -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.