]> git.sesse.net Git - movit/blobdiff - resource_pool.cpp
.gitignore more unit tests.
[movit] / resource_pool.cpp
index 6eadd9069538a473a7e419f2b60a27f1df331743..72b309519062b728d7b1b6ae73d05c0cc5086c9d 100644 (file)
@@ -1,18 +1,21 @@
-#include "resource_pool.h"
-
-#include <stdio.h>
+#include <assert.h>
 #include <pthread.h>
 #include <pthread.h>
-
+#include <stdio.h>
+#include <stdlib.h>
 #include <algorithm>
 #include <map>
 #include <string>
 #include <utility>
 
 #include <algorithm>
 #include <map>
 #include <string>
 #include <utility>
 
+#include "glew.h"
 #include "init.h"
 #include "init.h"
+#include "resource_pool.h"
 #include "util.h"
 
 using namespace std;
 
 #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),
 ResourcePool::ResourcePool(size_t program_freelist_max_length,
                            size_t texture_freelist_max_bytes)
        : program_freelist_max_length(program_freelist_max_length),
@@ -50,7 +53,7 @@ ResourcePool::~ResourcePool()
 void ResourcePool::delete_program(GLuint glsl_program_num)
 {
        bool found_program = false;
 void ResourcePool::delete_program(GLuint glsl_program_num)
 {
        bool found_program = false;
-       for (std::map<std::pair<std::string, std::string>, GLuint>::iterator program_it = programs.begin();
+       for (map<pair<string, string>, GLuint>::iterator program_it = programs.begin();
             program_it != programs.end();
             ++program_it) {
                if (program_it->second == glsl_program_num) {
             program_it != programs.end();
             ++program_it) {
                if (program_it->second == glsl_program_num) {
@@ -62,7 +65,7 @@ void ResourcePool::delete_program(GLuint glsl_program_num)
        assert(found_program);
        glDeleteProgram(glsl_program_num);
 
        assert(found_program);
        glDeleteProgram(glsl_program_num);
 
-       std::map<GLuint, std::pair<GLuint, GLuint> >::iterator shader_it =
+       map<GLuint, pair<GLuint, GLuint> >::iterator shader_it =
                program_shaders.find(glsl_program_num);
        assert(shader_it != program_shaders.end());
 
                program_shaders.find(glsl_program_num);
        assert(shader_it != program_shaders.end());
 
@@ -102,6 +105,15 @@ GLuint ResourcePool::compile_glsl_program(const string& vertex_shader, const str
                glLinkProgram(glsl_program_num);
                check_error();
 
                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;
                if (movit_debug_level == MOVIT_DEBUG_ON) {
                        // Output shader to a temporary file, for easier debugging.
                        static int compiled_shader_num = 0;
@@ -178,8 +190,8 @@ GLuint ResourcePool::create_2d_texture(GLint internal_format, GLsizei width, GLs
        case GL_RG16F:
                format = GL_RG;
                break;
        case GL_RG16F:
                format = GL_RG;
                break;
-       case GL_LUMINANCE8:
-               format = GL_LUMINANCE;
+       case GL_R8:
+               format = GL_RED;
                break;
        default:
                // TODO: Add more here as needed.
                break;
        default:
                // TODO: Add more here as needed.
@@ -247,7 +259,7 @@ size_t ResourcePool::estimate_texture_size(const Texture2D &texture_format)
        case GL_RG16F:
                bytes_per_pixel = 4;
                break;
        case GL_RG16F:
                bytes_per_pixel = 4;
                break;
-       case GL_LUMINANCE8:
+       case GL_R8:
                bytes_per_pixel = 1;
                break;
        default:
                bytes_per_pixel = 1;
                break;
        default:
@@ -257,3 +269,5 @@ size_t ResourcePool::estimate_texture_size(const Texture2D &texture_format)
 
        return texture_format.width * texture_format.height * bytes_per_pixel;
 }
 
        return texture_format.width * texture_format.height * bytes_per_pixel;
 }
+
+}  // namespace movit