Ver código fonte

Moving error helping code to its own file.
Rename opengl_*.cxx files to openGL/*.cxx

Sam Jaffe 6 anos atrás
pai
commit
559b5f6e12

+ 24 - 12
graphics/graphics.xcodeproj/project.pbxproj

@@ -7,20 +7,21 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
-		CD1C82BD22988EC700825C4E /* matrix.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD1C82BC22988EC700825C4E /* matrix.cxx */; settings = {COMPILER_FLAGS = "-fvisibility=default"; }; };
+		CD1C82BD22988EC700825C4E /* matrix.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD1C82BC22988EC700825C4E /* matrix.cxx */; };
 		CD1C83E922998E2600825C4E /* manager.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD1C83E722998E2600825C4E /* manager.cxx */; settings = {COMPILER_FLAGS = "-fvisibility=default"; }; };
+		CD1C840F2299B81500825C4E /* error_formatter.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD1C840D2299B81500825C4E /* error_formatter.cxx */; };
 		CD3AC6F21D2C03B7002B4BB0 /* material.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD3AC6F01D2C03B7002B4BB0 /* material.cpp */; };
 		CD3AC6F81D2C0518002B4BB0 /* texture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD3AC6F61D2C0518002B4BB0 /* texture.cpp */; };
 		CD3AC6FD1D2C06B5002B4BB0 /* shader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD3AC6FB1D2C06B5002B4BB0 /* shader.cpp */; };
 		CD3AC7191D2C0950002B4BB0 /* shader_program.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD3AC7171D2C0950002B4BB0 /* shader_program.cpp */; };
 		CD3AC7261D2C0C63002B4BB0 /* object.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD3AC7241D2C0C63002B4BB0 /* object.cpp */; settings = {COMPILER_FLAGS = "-fvisibility=default"; }; };
 		CD62FCF72290DC9000376440 /* helper.hpp in Headers */ = {isa = PBXBuildFile; fileRef = CD62FCF52290DC9000376440 /* helper.hpp */; };
-		CD62FCF82290DC9000376440 /* opengl_helper.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD62FCF62290DC9000376440 /* opengl_helper.cxx */; };
+		CD62FCF82290DC9000376440 /* helper.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD62FCF62290DC9000376440 /* helper.cxx */; };
 		CD62FCFA2290E2E500376440 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD62FCF92290E2E500376440 /* OpenGL.framework */; };
 		CD62FD062291970F00376440 /* libgameutils.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CD62FD052291970F00376440 /* libgameutils.dylib */; };
 		CD62FD1E2292412900376440 /* renderer.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD62FD1C2292412900376440 /* renderer.cxx */; settings = {COMPILER_FLAGS = "-fvisibility=default"; }; };
 		CD62FD222292C76B00376440 /* renderer_impl.hpp in Headers */ = {isa = PBXBuildFile; fileRef = CD62FD202292C76B00376440 /* renderer_impl.hpp */; };
-		CD62FD232292C76B00376440 /* opengl_renderer.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD62FD212292C76B00376440 /* opengl_renderer.cxx */; };
+		CD62FD232292C76B00376440 /* renderer_impl.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD62FD212292C76B00376440 /* renderer_impl.cxx */; };
 		CDA34D9A22517A3D008036A7 /* libmath.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA34D9922517A3D008036A7 /* libmath.dylib */; };
 /* End PBXBuildFile section */
 
@@ -59,6 +60,7 @@
 		CD1C82B722988E4E00825C4E /* matrix.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = matrix.hpp; sourceTree = "<group>"; };
 		CD1C82BC22988EC700825C4E /* matrix.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = matrix.cxx; sourceTree = "<group>"; };
 		CD1C83E722998E2600825C4E /* manager.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = manager.cxx; sourceTree = "<group>"; };
+		CD1C840D2299B81500825C4E /* error_formatter.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = error_formatter.cxx; sourceTree = "<group>"; };
 		CD3AC6E21D2C0364002B4BB0 /* libgraphics.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libgraphics.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
 		CD3AC6F01D2C03B7002B4BB0 /* material.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = material.cpp; sourceTree = "<group>"; };
 		CD3AC6F61D2C0518002B4BB0 /* texture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = texture.cpp; sourceTree = "<group>"; };
@@ -67,12 +69,12 @@
 		CD3AC7241D2C0C63002B4BB0 /* object.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = object.cpp; sourceTree = "<group>"; };
 		CD62FCD722904AD100376440 /* GoogleMock.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = GoogleMock.xcodeproj; path = "../../gmock-xcode-master/GoogleMock.xcodeproj"; sourceTree = "<group>"; };
 		CD62FCF52290DC9000376440 /* helper.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = helper.hpp; sourceTree = "<group>"; };
-		CD62FCF62290DC9000376440 /* opengl_helper.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = opengl_helper.cxx; sourceTree = "<group>"; };
+		CD62FCF62290DC9000376440 /* helper.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = helper.cxx; sourceTree = "<group>"; };
 		CD62FCF92290E2E500376440 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; };
 		CD62FD052291970F00376440 /* libgameutils.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; path = libgameutils.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
 		CD62FD1C2292412900376440 /* renderer.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = renderer.cxx; sourceTree = "<group>"; };
 		CD62FD202292C76B00376440 /* renderer_impl.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = renderer_impl.hpp; sourceTree = "<group>"; };
-		CD62FD212292C76B00376440 /* opengl_renderer.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = opengl_renderer.cxx; sourceTree = "<group>"; };
+		CD62FD212292C76B00376440 /* renderer_impl.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = renderer_impl.cxx; sourceTree = "<group>"; };
 		CDA34D86225171AA008036A7 /* game */ = {isa = PBXFileReference; lastKnownFileType = folder; name = game; path = include/game; sourceTree = "<group>"; };
 		CDA34D9922517A3D008036A7 /* libmath.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; path = libmath.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
 /* End PBXFileReference section */
@@ -91,6 +93,16 @@
 /* End PBXFrameworksBuildPhase section */
 
 /* Begin PBXGroup section */
+		CD1C84052299B72C00825C4E /* openGL */ = {
+			isa = PBXGroup;
+			children = (
+				CD62FD212292C76B00376440 /* renderer_impl.cxx */,
+				CD62FCF62290DC9000376440 /* helper.cxx */,
+				CD1C840D2299B81500825C4E /* error_formatter.cxx */,
+			);
+			path = openGL;
+			sourceTree = "<group>";
+		};
 		CD3AC6D91D2C0364002B4BB0 = {
 			isa = PBXGroup;
 			children = (
@@ -113,10 +125,9 @@
 		CD3AC6E41D2C0364002B4BB0 /* src */ = {
 			isa = PBXGroup;
 			children = (
+				CD1C84052299B72C00825C4E /* openGL */,
 				CD62FD1A22923B8E00376440 /* renderer */,
 				CD62FD1822923B8100376440 /* model */,
-				CD62FCF52290DC9000376440 /* helper.hpp */,
-				CD62FCF62290DC9000376440 /* opengl_helper.cxx */,
 			);
 			path = src;
 			sourceTree = "<group>";
@@ -135,12 +146,13 @@
 		CD62FD1822923B8100376440 /* model */ = {
 			isa = PBXGroup;
 			children = (
+				CD62FCF52290DC9000376440 /* helper.hpp */,
+				CD1C83E722998E2600825C4E /* manager.cxx */,
 				CD3AC7241D2C0C63002B4BB0 /* object.cpp */,
 				CD3AC6F01D2C03B7002B4BB0 /* material.cpp */,
 				CD3AC6FB1D2C06B5002B4BB0 /* shader.cpp */,
 				CD3AC7171D2C0950002B4BB0 /* shader_program.cpp */,
 				CD3AC6F61D2C0518002B4BB0 /* texture.cpp */,
-				CD1C83E722998E2600825C4E /* manager.cxx */,
 			);
 			name = model;
 			sourceTree = "<group>";
@@ -148,11 +160,10 @@
 		CD62FD1A22923B8E00376440 /* renderer */ = {
 			isa = PBXGroup;
 			children = (
-				CD62FD1C2292412900376440 /* renderer.cxx */,
 				CD62FD202292C76B00376440 /* renderer_impl.hpp */,
+				CD62FD1C2292412900376440 /* renderer.cxx */,
 				CD1C82B722988E4E00825C4E /* matrix.hpp */,
 				CD1C82BC22988EC700825C4E /* matrix.cxx */,
-				CD62FD212292C76B00376440 /* opengl_renderer.cxx */,
 			);
 			name = renderer;
 			sourceTree = "<group>";
@@ -297,12 +308,13 @@
 				CD3AC7191D2C0950002B4BB0 /* shader_program.cpp in Sources */,
 				CD1C82BD22988EC700825C4E /* matrix.cxx in Sources */,
 				CD3AC6F21D2C03B7002B4BB0 /* material.cpp in Sources */,
+				CD1C840F2299B81500825C4E /* error_formatter.cxx in Sources */,
 				CD62FD1E2292412900376440 /* renderer.cxx in Sources */,
 				CD3AC6F81D2C0518002B4BB0 /* texture.cpp in Sources */,
 				CD3AC7261D2C0C63002B4BB0 /* object.cpp in Sources */,
 				CD1C83E922998E2600825C4E /* manager.cxx in Sources */,
-				CD62FCF82290DC9000376440 /* opengl_helper.cxx in Sources */,
-				CD62FD232292C76B00376440 /* opengl_renderer.cxx in Sources */,
+				CD62FCF82290DC9000376440 /* helper.cxx in Sources */,
+				CD62FD232292C76B00376440 /* renderer_impl.cxx in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

+ 107 - 0
graphics/src/openGL/error_formatter.cxx

@@ -0,0 +1,107 @@
+//
+//  error_formatter.cxx
+//  graphics
+//
+//  Created by Sam Jaffe on 5/25/19.
+//  Copyright © 2019 Sam Jaffe. All rights reserved.
+//
+
+#include <iostream>
+#include <sstream>
+#include <string>
+#ifdef __APPLE__
+#include <OpenGL/gl3.h>
+#endif
+
+struct error_formatter {
+  typedef void (*GLGetIntFor)(GLuint, GLenum, GLint *);
+  typedef void (*GLGetLog)(GLuint, GLsizei, GLsizei *, GLchar *);
+
+  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);
+
+  unsigned int obj;
+  std::string fileName, path, eNoticeMessage, eFileMessage, eWindowTitle;
+  GLGetIntFor getIntv;
+  GLGetLog getInfoLog;
+};
+
+void error_formatter::operator()() const {
+  std::stringstream errorString;
+  std::string errorLineNumber;
+
+  int infologLength = 0;
+  int maxLength = 0;
+
+  getIntv(obj, GL_INFO_LOG_LENGTH, &maxLength);
+  errorString << eNoticeMessage << "\n";
+
+  std::unique_ptr<char[]> infoLog(new char[maxLength + 1]);
+  getInfoLog(obj, maxLength, &infologLength, infoLog.get());
+
+  std::string errorLog(infoLog.get());
+  infoLog.reset();
+  if (infologLength <= 0) return;
+
+  std::size_t openParen = errorLog.find('(');
+  std::size_t closeParen = errorLog.find(')');
+  errorLineNumber = errorLog.substr(openParen + 1, closeParen - openParen - 1);
+
+  std::string errorStart = errorLog.find("error") != std::string::npos
+                               ? errorLog.substr(errorLog.find("error"))
+                               : errorLog;
+
+  errorString << errorLog << "\n";
+
+  errorString << "OpenGL Version: " << glGetString(GL_VERSION) << "\n";
+  errorString << "GLSL Shading Version: "
+              << glGetString(GL_SHADING_LANGUAGE_VERSION) << "\n";
+
+  errorString << eFileMessage << "\n";
+  errorString << "RAW ERROR LOG: " << errorLog;
+
+  std::stringstream consoleOutput;
+
+  consoleOutput << "1>" << path << '(' << errorLineNumber << ')' << ": "
+                << errorStart
+                << "in OpenGL version: " << glGetString(GL_VERSION) << " and "
+                << "GLSL Shading Version: "
+                << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
+
+#ifdef _WIN32
+  OutputDebugStringA(consoleOutput.str().c_str());
+  MessageBoxA(nullptr, errorString.str().c_str(), eWindowTitle.c_str(), MB_OK);
+#else
+  std::cerr << errorString.str() << std::endl;
+#endif
+}
+
+namespace graphics {
+  void print_shader_error(GLuint id, std::string const & path) {
+    std::string fileName = path.substr(path.find_last_of("/") + 1);
+    error_formatter{id,
+                    fileName,
+                    path,
+                    "GLSL shader compile error!",
+                    "File location: " + path,
+                    "GLSL Compile Error in " + fileName,
+                    glGetShaderiv,
+                    glGetShaderInfoLog}();
+  }
+
+  void print_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("/") + 1);
+    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}();
+  }
+}

+ 7 - 97
graphics/src/opengl_helper.cxx

@@ -24,99 +24,10 @@
 #include "game/util/files.hpp"
 #include "game/util/time.hpp"
 
-namespace {
-  typedef void (*GLGetIntFor)(GLuint, GLenum, GLint *);
-  typedef void (*GLGetLog)(GLuint, GLsizei, GLsizei *, GLchar *);
-  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;
-    GLGetIntFor getIntv;
-    GLGetLog getInfoLog;
-  };
-
-  void error_formatter::operator()() const {
-    std::stringstream errorString;
-    std::string errorLineNumber;
-
-    int infologLength = 0;
-    int maxLength = 0;
-
-    getIntv(obj, GL_INFO_LOG_LENGTH, &maxLength);
-    errorString << eNoticeMessage << "\n";
-
-    std::unique_ptr<char[]> infoLog(new char[maxLength + 1]);
-    getInfoLog(obj, maxLength, &infologLength, infoLog.get());
-
-    std::string errorLog(infoLog.get());
-    infoLog.reset();
-    if (infologLength <= 0) return;
-
-    std::size_t openParen = errorLog.find('(');
-    std::size_t closeParen = errorLog.find(')');
-    errorLineNumber =
-        errorLog.substr(openParen + 1, closeParen - openParen - 1);
-
-    std::string errorStart = errorLog.find("error") != std::string::npos
-                                 ? errorLog.substr(errorLog.find("error"))
-                                 : errorLog;
-
-    errorString << errorLog << "\n";
-
-    errorString << "OpenGL Version: " << glGetString(GL_VERSION) << "\n";
-    errorString << "GLSL Shading Version: "
-                << glGetString(GL_SHADING_LANGUAGE_VERSION) << "\n";
-
-    errorString << eFileMessage << "\n";
-    errorString << "RAW ERROR LOG: " << errorLog;
-
-    std::stringstream consoleOutput;
-
-    consoleOutput << "1>" << path << '(' << errorLineNumber << ')' << ": "
-                  << errorStart
-                  << "in OpenGL version: " << glGetString(GL_VERSION) << " and "
-                  << "GLSL Shading Version: "
-                  << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
-
-#ifdef _WIN32
-    OutputDebugStringA(consoleOutput.str().c_str());
-    MessageBoxA(nullptr, errorString.str().c_str(), eWindowTitle.c_str(),
-                MB_OK);
-#else
-    std::cerr << errorString.str() << std::endl;
-#endif
-  }
-
-  void error_formatter::shader_error(GLuint id, std::string const & path) {
-    std::string fileName = path.substr(path.find_last_of("/") + 1);
-    error_formatter{id,
-                    fileName,
-                    path,
-                    "GLSL shader compile error!",
-                    "File location: " + path,
-                    "GLSL Compile Error in " + fileName,
-                    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("/") + 1);
-    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 {
+  extern void print_shader_error(GLuint, std::string const &);
+  extern void print_shader_program_error(GLuint, std::string const &,
+                                         std::string const &);
 }
 
 namespace graphics { namespace textures {
@@ -244,7 +155,7 @@ namespace graphics { namespace shaders {
     glGetShaderiv(id, GL_COMPILE_STATUS, &return_code);
 
     if (return_code != GL_TRUE) {
-      error_formatter::shader_error(id, abs_path);
+      print_shader_error(id, abs_path);
       throw compilation_error("Could not compile the shader file");
     }
     return id;
@@ -274,9 +185,8 @@ namespace graphics { namespace shaders {
     glGetProgramiv(id, GL_LINK_STATUS, &return_code);
 
     if (return_code != GL_TRUE) {
-      //      error_formatter::shader_program_error(id,
-      //      fragmentShader.actual().path,
-      //                                            vertexShader.actual().path);
+      //      print_shader_program_error(id, fragmentShader.actual().path,
+      //                                 vertexShader.actual().path);
       throw linker_error("Could not link shader program");
     }
     return id;

graphics/src/opengl_renderer.cxx → graphics/src/openGL/renderer_impl.cxx