Commit 6faee50f authored by Martin Flöser's avatar Martin Flöser

Allow creating shaders from code directly.

parent 41b4be09
......@@ -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");
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment