Allow creating shaders from code directly.

This commit is contained in:
Martin Gräßlin 2011-01-08 19:53:11 +01:00
parent bf56d17aee
commit a478fc7ff3
2 changed files with 24 additions and 0 deletions

View file

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

View file

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