]> git.sesse.net Git - movit/blobdiff - resource_pool.cpp
Check GLSL program link status, for better error reporting.
[movit] / resource_pool.cpp
index b074247e8d772bc6f4b00bbb817f1363e15baaf0..04b1aa9754b4a51bb5fe54a875047db414700777 100644 (file)
@@ -1,18 +1,21 @@
-#include "resource_pool.h"
-
-#include <stdio.h>
+#include <assert.h>
 #include <pthread.h>
-
+#include <stdio.h>
+#include <stdlib.h>
 #include <algorithm>
 #include <map>
 #include <string>
 #include <utility>
 
+#include "glew.h"
 #include "init.h"
+#include "resource_pool.h"
 #include "util.h"
 
 using namespace std;
 
+namespace movit {
+
 ResourcePool::ResourcePool(size_t program_freelist_max_length,
                            size_t texture_freelist_max_bytes)
        : program_freelist_max_length(program_freelist_max_length),
@@ -102,6 +105,15 @@ GLuint ResourcePool::compile_glsl_program(const string& vertex_shader, const str
                glLinkProgram(glsl_program_num);
                check_error();
 
+               GLint success;
+               glGetProgramiv(glsl_program_num, GL_LINK_STATUS, &success);
+               if (success == GL_FALSE) {
+                       GLchar error_log[1024] = {0};
+                       glGetProgramInfoLog(glsl_program_num, 1024, NULL, error_log);
+                       fprintf(stderr, "Error linking program: %s\n", error_log);
+                       exit(1);
+               }
+
                if (movit_debug_level == MOVIT_DEBUG_ON) {
                        // Output shader to a temporary file, for easier debugging.
                        static int compiled_shader_num = 0;
@@ -257,3 +269,5 @@ size_t ResourcePool::estimate_texture_size(const Texture2D &texture_format)
 
        return texture_format.width * texture_format.height * bytes_per_pixel;
 }
+
+}  // namespace movit