diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp index 15f6fc7498..d4af4b7759 100644 --- a/lib/kwinglutils.cpp +++ b/lib/kwinglutils.cpp @@ -863,6 +863,13 @@ void GLShader::initStatic() #endif } +GLShader::GLShader() + : mValid(false) + , mProgram(0) + , mTextureWidth(-1.0f) + , mTextureHeight(-1.0f) +{ +} GLShader::GLShader(const QString& vertexfile, const QString& fragmentfile) { @@ -1296,6 +1303,13 @@ GLShader *ShaderManager::loadFragmentShader(ShaderType vertex, const QString &fr return shader; } +GLShader *ShaderManager::loadShaderFromCode(const QString &vertexSource, const QString &fragmentSource) +{ + GLShader *shader = new GLShader(); + shader->load(vertexSource, fragmentSource); + return shader; +} + void ShaderManager::initShaders() { m_orthoShader = new GLShader(":/resources/scene-vertex.glsl", ":/resources/scene-fragment.glsl"); diff --git a/lib/kwinglutils.h b/lib/kwinglutils.h index 9e11372bb0..4884a7e64d 100644 --- a/lib/kwinglutils.h +++ b/lib/kwinglutils.h @@ -308,6 +308,7 @@ class KWIN_EXPORT GLShader protected: + GLShader(); bool loadFromFiles(const QString& vertexfile, const QString& fragmentfile); bool load(const QString& vertexsource, const QString& fragmentsource); @@ -319,6 +320,7 @@ class KWIN_EXPORT GLShader static bool mVertexShaderSupported; float mTextureWidth; float mTextureHeight; + friend class ShaderManager; }; /** @@ -420,6 +422,14 @@ class KWIN_EXPORT ShaderManager * @return The created shader **/ GLShader *loadFragmentShader(ShaderType vertex, const QString &fragmentFile); + /** + * Creates a GLShader with the specified sources. + * The difference to GLShader is that it does not need to be loaded from files. + * @param vertexSource The source code of the vertex shader + * @param fragmentSource The source code of the fragment shader. + * @return The created shader + **/ + GLShader *loadShaderFromCode(const QString &vertexSource, const QString &fragmentSource); /** * @return a pointer to the ShaderManager instance