changeset 24:c1897cfc8463

Add shader compilation error handling.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 22 Nov 2019 05:49:14 +0200
parents f080349584b8
children 2403030a0352
files gldragon.cpp
diffstat 1 files changed, 18 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/gldragon.cpp	Fri Nov 22 05:29:34 2019 +0200
+++ b/gldragon.cpp	Fri Nov 22 05:49:14 2019 +0200
@@ -254,15 +254,26 @@
 }
 
 
-GLuint dmCompileShader(const GLenum stype, const std::string &src)
+bool dmCompileShader(const GLenum stype, const std::string &src, GLuint &shader)
 {
-    GLuint shader = glCreateShader(stype);
+    GLint status;
     const char *tmp = src.c_str();
 
+    shader = glCreateShader(stype);
     glShaderSource(shader, 1, &tmp, 0);
     glCompileShader(shader);
 
-    return shader;
+    glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
+    if (status == GL_TRUE)
+        return true;
+    else
+    {
+        char err[512];
+        glGetShaderInfoLog(shader, sizeof(err), NULL, err);
+        printf("ERROR: %s\n",
+            err);
+        return false;
+    }
 }
 
 
@@ -420,8 +431,10 @@
     {
         for (DMModel &model : scene.models)
         {
-            model.id_fs = dmCompileShader(GL_FRAGMENT_SHADER, model.fragShaderStr);
-            model.id_vs = dmCompileShader(GL_VERTEX_SHADER, model.vertShaderStr);
+            if (!dmCompileShader(GL_FRAGMENT_SHADER, model.fragShaderStr, model.id_fs) ||
+                !dmCompileShader(GL_VERTEX_SHADER, model.vertShaderStr, model.id_vs))
+                goto exit;
+
             dmLinkModelShaders(model);
         }
     }