From c280fa59cb0065addfb441bd05e5f6fae584a316 Mon Sep 17 00:00:00 2001 From: Jani Uusi-Rantala Date: Sun, 9 Oct 2011 21:06:49 +0300 Subject: Easier shader debugging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Dumps out also the source code of the failed shader if available Change-Id: I9ae80e6a6749446c5ff54db1bc324cc7411a81a7 Signed-off-by: Jani Uusi-Rantala Reviewed-on: http://codereview.qt-project.org/6269 Sanity-Review: Qt Sanity Bot Reviewed-by: Samuel Rødal --- src/gui/opengl/qopenglshaderprogram.cpp | 56 ++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 8 deletions(-) (limited to 'src/gui/opengl') diff --git a/src/gui/opengl/qopenglshaderprogram.cpp b/src/gui/opengl/qopenglshaderprogram.cpp index aa7767a7eb..3c93b127ef 100644 --- a/src/gui/opengl/qopenglshaderprogram.cpp +++ b/src/gui/opengl/qopenglshaderprogram.cpp @@ -213,17 +213,17 @@ bool QOpenGLShaderPrivate::compile(QOpenGLShader *q) GLuint shader = shaderGuard ? shaderGuard->id() : 0; if (!shader) return false; + + // Try to compile shader glfuncs->glCompileShader(shader); GLint value = 0; + + // Get compilation status glfuncs->glGetShaderiv(shader, GL_COMPILE_STATUS, &value); compiled = (value != 0); - value = 0; - glfuncs->glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &value); - if (!compiled && value > 1) { - char *logbuf = new char [value]; - GLint len; - glfuncs->glGetShaderInfoLog(shader, value, &len, logbuf); - log = QString::fromLatin1(logbuf); + + if (!compiled) { + // Compilation failed, try to provide some information about the failure QString name = q->objectName(); const char *types[] = { @@ -241,13 +241,53 @@ bool QOpenGLShaderPrivate::compile(QOpenGLShader *q) else if (shaderType == QOpenGLShader::Geometry) type = types[2]; + // Get info and source code lengths + GLint infoLogLength = 0; + GLint sourceCodeLength = 0; + char *logBuffer = 0; + char *sourceCodeBuffer = 0; + + // Get the compilation info log + glfuncs->glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength); + + if (infoLogLength > 1) { + GLint temp; + logBuffer = new char [infoLogLength]; + glfuncs->glGetShaderInfoLog(shader, infoLogLength, &temp, logBuffer); + } + + // Get the source code + glfuncs->glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &sourceCodeLength); + + if (sourceCodeLength > 1) { + GLint temp; + sourceCodeBuffer = new char [sourceCodeLength]; + glfuncs->glGetShaderSource(shader, sourceCodeLength, &temp, sourceCodeBuffer); + } + + QString log; + if (logBuffer) + log = QString::fromLatin1(logBuffer); + else + log = QLatin1String("failed"); + if (name.isEmpty()) qWarning("QOpenGLShader::compile(%s): %s", type, qPrintable(log)); else qWarning("QOpenGLShader::compile(%s)[%s]: %s", type, qPrintable(name), qPrintable(log)); - delete [] logbuf; + // Dump the source code if we got it + if (sourceCodeBuffer) { + qWarning("*** Problematic %s shader source code ***", type); + qWarning() << qPrintable(QString::fromLatin1(sourceCodeBuffer)); + qWarning("***"); + } + + // Cleanup + delete [] logBuffer; + delete [] sourceCodeBuffer; } + return compiled; } -- cgit v1.2.3