kwin: Change the shader source code parameters from QStrings to QByteArrays.

This eliminates the QByteArray -> QString -> QByteArray conversions.
This commit is contained in:
Fredrik Höglund 2011-02-04 16:41:55 +01:00
parent f95b82a907
commit 9f41472085
2 changed files with 13 additions and 13 deletions

View file

@ -860,23 +860,23 @@ bool GLShader::loadFromFiles(const QString& vertexfile, const QString& fragmentf
kError(1212) << "Couldn't open '" << vertexfile << "' for reading!" << endl; kError(1212) << "Couldn't open '" << vertexfile << "' for reading!" << endl;
return false; return false;
} }
QString vertexsource(vf.readAll()); const QByteArray vertexSource = vf.readAll();
QFile ff(fragmentfile); QFile ff(fragmentfile);
if (!ff.open(QIODevice::ReadOnly)) { if (!ff.open(QIODevice::ReadOnly)) {
kError(1212) << "Couldn't open '" << fragmentfile << "' for reading!" << endl; kError(1212) << "Couldn't open '" << fragmentfile << "' for reading!" << endl;
return false; return false;
} }
QString fragsource(ff.readAll()); const QByteArray fragmentSource = ff.readAll();
return load(vertexsource, fragsource); return load(vertexSource, fragmentSource);
} }
bool GLShader::load(const QString& vertexsource, const QString& fragmentsource) bool GLShader::load(const QByteArray &vertexSource, const QByteArray &fragmentSource)
{ {
// Make sure shaders are actually supported // Make sure shaders are actually supported
if ((!vertexsource.isEmpty() && !vertexShaderSupported()) || if ((!vertexSource.isEmpty() && !vertexShaderSupported()) ||
(!fragmentsource.isEmpty() && !fragmentShaderSupported())) { (!fragmentSource.isEmpty() && !fragmentShaderSupported())) {
kDebug(1212) << "Shaders not supported"; kDebug(1212) << "Shaders not supported";
return false; return false;
} }
@ -889,7 +889,7 @@ bool GLShader::load(const QString& vertexsource, const QString& fragmentsource)
// Create program object // Create program object
mProgram = glCreateProgram(); mProgram = glCreateProgram();
if (!vertexsource.isEmpty()) { if (!vertexSource.isEmpty()) {
// Create shader object // Create shader object
vertexshader = glCreateShader(GL_VERTEX_SHADER); vertexshader = glCreateShader(GL_VERTEX_SHADER);
// Load it // Load it
@ -897,7 +897,7 @@ bool GLShader::load(const QString& vertexsource, const QString& fragmentsource)
#ifdef KWIN_HAVE_OPENGLES #ifdef KWIN_HAVE_OPENGLES
srcba.append("#ifdef GL_ES\nprecision highp float;\n#endif\n"); srcba.append("#ifdef GL_ES\nprecision highp float;\n#endif\n");
#endif #endif
srcba.append(vertexsource.toLatin1()); srcba.append(vertexSource);
const char* src = srcba.data(); const char* src = srcba.data();
glShaderSource(vertexshader, 1, &src, NULL); glShaderSource(vertexshader, 1, &src, NULL);
// Compile the shader // Compile the shader
@ -923,14 +923,14 @@ bool GLShader::load(const QString& vertexsource, const QString& fragmentsource)
} }
if (!fragmentsource.isEmpty()) { if (!fragmentSource.isEmpty()) {
fragmentshader = glCreateShader(GL_FRAGMENT_SHADER); fragmentshader = glCreateShader(GL_FRAGMENT_SHADER);
// Load it // Load it
QByteArray srcba; QByteArray srcba;
#ifdef KWIN_HAVE_OPENGLES #ifdef KWIN_HAVE_OPENGLES
srcba.append("#ifdef GL_ES\nprecision highp float;\n#endif\n"); srcba.append("#ifdef GL_ES\nprecision highp float;\n#endif\n");
#endif #endif
srcba.append(fragmentsource.toLatin1()); srcba.append(fragmentSource);
const char* src = srcba.data(); const char* src = srcba.data();
glShaderSource(fragmentshader, 1, &src, NULL); glShaderSource(fragmentshader, 1, &src, NULL);
//glShaderSource(fragmentshader, 1, &fragmentsrc.latin1(), NULL); //glShaderSource(fragmentshader, 1, &fragmentsrc.latin1(), NULL);
@ -1272,7 +1272,7 @@ GLShader *ShaderManager::loadVertexShader(ShaderType fragment, const QString &ve
return shader; return shader;
} }
GLShader *ShaderManager::loadShaderFromCode(const QString &vertexSource, const QString &fragmentSource) GLShader *ShaderManager::loadShaderFromCode(const QByteArray &vertexSource, const QByteArray &fragmentSource)
{ {
GLShader *shader = new GLShader(); GLShader *shader = new GLShader();
shader->load(vertexSource, fragmentSource); shader->load(vertexSource, fragmentSource);

View file

@ -327,7 +327,7 @@ public:
protected: protected:
GLShader(); GLShader();
bool loadFromFiles(const QString& vertexfile, const QString& fragmentfile); bool loadFromFiles(const QString& vertexfile, const QString& fragmentfile);
bool load(const QString& vertexsource, const QString& fragmentsource); bool load(const QByteArray &vertexSource, const QByteArray &fragmentSource);
void bind(); void bind();
void unbind(); void unbind();
@ -455,7 +455,7 @@ public:
* @param fragmentSource The source code of the fragment shader. * @param fragmentSource The source code of the fragment shader.
* @return The created shader * @return The created shader
**/ **/
GLShader *loadShaderFromCode(const QString &vertexSource, const QString &fragmentSource); GLShader *loadShaderFromCode(const QByteArray &vertexSource, const QByteArray &fragmentSource);
/** /**
* @return a pointer to the ShaderManager instance * @return a pointer to the ShaderManager instance