ソースを参照

Make things public.
Add error printing for shader_program errors.

Sam Jaffe 6 年 前
コミット
8c26d2fcad

+ 4 - 3
graphics/include/game/graphics/shader.hpp

@@ -16,13 +16,14 @@ namespace graphics {
     enum class type : unsigned int;
   }
   class shader : public identity<shader> {
+  public:
+    shaders::type type;
+    std::string path;
+
   public:
     static flyweight<shader> create(shaders::type tp, std::string const & path);
 
   private:
     shader(unsigned int, shaders::type, std::string const &);
-
-    shaders::type type;
-    std::string path;
   };
 }

+ 4 - 1
graphics/include/game/graphics/shader_program.hpp

@@ -15,6 +15,10 @@
 
 namespace graphics {
   class shader_program : public identity<shader_program> {
+  public:
+    flyweight<shader> fragment_shader;
+    flyweight<shader> vertex_shader;
+
   public:
     static flyweight<shader_program> create(std::string const & frag,
                                             std::string const & vert);
@@ -22,6 +26,5 @@ namespace graphics {
 
   private:
     shader_program(unsigned int, flyweight<shader>, flyweight<shader>);
-    flyweight<shader> fragment_shader, vertex_shader;
   };
 }

+ 3 - 3
graphics/include/game/graphics/texture.hpp

@@ -14,14 +14,14 @@
 namespace graphics {
   class texture : public identity<texture> {
   public:
-    static flyweight<texture> create(std::string const & imagefile);
-
     static texture const WHITE;
     static texture const DARK_YELLOW;
     static texture const LIGHT_BLUE;
-
     math::vec2i const size;
 
+  public:
+    static flyweight<texture> create(std::string const & imagefile);
+
   private:
     static texture create(char const *, math::vec2i);
     texture(unsigned int, math::vec2i = math::vec2i{{0, 0}});

+ 19 - 1
graphics/src/opengl_helper.cxx

@@ -28,6 +28,8 @@ namespace {
   struct error_formatter {
     void operator()() const;
     static void shader_error(GLuint id, std::string const & path);
+    static void shader_program_error(GLuint id, std::string const & frag_path,
+                                     std::string const & vert_path);
 
     GLuint obj;
     std::string fileName, path, eNoticeMessage, eFileMessage, eWindowTitle;
@@ -102,6 +104,21 @@ namespace {
                     glGetShaderiv,
                     glGetShaderInfoLog}();
   }
+
+  void error_formatter::shader_program_error(GLuint id,
+                                             std::string const & frag_path,
+                                             std::string const & vert_path) {
+    std::string fileName = frag_path.substr(frag_path.find_last_of("/"));
+    error_formatter{id,
+                    fileName,
+                    frag_path,
+                    "GLSL program link error!",
+                    "File location of vertex shader: " + vert_path +
+                        "\nFile location of fragment shader: " + frag_path,
+                    "GLSL Link Error",
+                    glGetProgramiv,
+                    glGetProgramInfoLog}();
+  }
 }
 
 namespace graphics { namespace textures {
@@ -259,7 +276,8 @@ namespace graphics { namespace shaders {
     glGetProgramiv(id, GL_LINK_STATUS, &return_code);
 
     if (return_code != GL_TRUE) {
-      //      LogShaderProgramError(*id, vertPath, fragPath);
+      error_formatter::shader_program_error(id, fragmentShader.actual().path,
+                                            vertexShader.actual().path);
       throw linker_error("Could not link shader program");
     }
     return id;