From b3996b0a8da75210ea7611896325737c17afcf89 Mon Sep 17 00:00:00 2001 From: Ben Kyd Date: Mon, 24 Apr 2023 15:47:01 +0100 Subject: [PATCH] CLANG FORMAT LETS GOOO --- .clang-format | 192 ++++++++++++++++++++++++++++++ src/inferno.cpp | 49 ++++---- src/inferno.hpp | 1 - src/main.cpp | 1 - src/preview_renderer/renderer.cpp | 14 +-- src/preview_renderer/shader.cpp | 176 +++++++++++++++------------ src/preview_renderer/shader.hpp | 8 +- src/scene/material.cpp | 16 +-- src/scene/material.hpp | 8 +- src/window.cpp | 66 ++++++---- src/window.hpp | 6 +- 11 files changed, 376 insertions(+), 161 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..c8e7b33 --- /dev/null +++ b/.clang-format @@ -0,0 +1,192 @@ +--- +Language: Cpp +# BasedOnStyle: WebKit +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignArrayOfStructures: None +AlignConsecutiveMacros: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignEscapedNewlines: Right +AlignOperands: DontAlign +AlignTrailingComments: false +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: All +BreakBeforeConceptDeclarations: true +BreakBeforeBraces: WebKit +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 0 +CommentPragmas: '^ IWYU pragma:' +QualifierAlignment: Leave +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +PackConstructorInitializers: BinPack +BasedOnStyle: '' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +AllowAllConstructorInitializersOnNextLine: true +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseLabels: false +IndentCaseBlocks: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentExternBlock: AfterExternBlock +IndentRequires: false +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +LambdaBodyIndentation: Signature +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 4 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PenaltyIndentedWhitespace: 0 +PointerAlignment: Left +PPIndentWidth: -1 +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + BeforeNonEmptyParentheses: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME +... + diff --git a/src/inferno.cpp b/src/inferno.cpp index d7a55f7..1533c70 100644 --- a/src/inferno.cpp +++ b/src/inferno.cpp @@ -1,29 +1,29 @@ #include "inferno.hpp" #include -//#include "gui/layout.hpp" +// #include "gui/layout.hpp" #include "window.hpp" -//#include "hart_module.hpp" -//#include "hart_directory.hpp" +// #include "hart_module.hpp" +// #include "hart_directory.hpp" -//#include "preview_renderer/renderer.hpp" -//#include "preview_renderer/shader.hpp" -//#include "renderer/dispatcher.hpp" -//#include "renderer/renderer.hpp" -//#include "scene/camera.hpp" -//#include "scene/scene.hpp" -//#include "scene/material.hpp" -//#include "scene/mesh.hpp" +// #include "preview_renderer/renderer.hpp" +// #include "preview_renderer/shader.hpp" +// #include "renderer/dispatcher.hpp" +// #include "renderer/renderer.hpp" +// #include "scene/camera.hpp" +// #include "scene/scene.hpp" +// #include "scene/material.hpp" +// #include "scene/mesh.hpp" #include +#include #include #include -#include #include -using namespace inferno; +namespace inferno { InfernoApp* inferno_create() { @@ -44,8 +44,7 @@ void inferno_cleanup(InfernoApp* app) static void inferno_gui_help_marker(const char* desc) { ImGui::TextDisabled("(?)"); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayShort)) - { + if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayShort)) { ImGui::BeginTooltip(); ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); ImGui::TextUnformatted(desc); @@ -54,13 +53,13 @@ static void inferno_gui_help_marker(const char* desc) } } -void inferno_preset_gui(InfernoApp *app) +void inferno_preset_gui(InfernoApp* app) { ImGuiID dockspace_id = ImGui::GetID("main"); ImGui::DockBuilderRemoveNode(dockspace_id); // Clear out existing layout ImGui::DockBuilderAddNode(dockspace_id, ImGuiDockNodeFlags_DockSpace); // Add empty node - ImGui::DockBuilderSetNodeSize(dockspace_id, {1000, 1000}); + ImGui::DockBuilderSetNodeSize(dockspace_id, { 1000, 1000 }); ImGuiID dock_main_id = dockspace_id; // This variable will track the document node, however we are not using it here as we aren't docking anything into it. ImGuiID dock_left = ImGui::DockBuilderSplitNode(dock_main_id, ImGuiDir_Left, 0.5f, NULL, &dock_main_id); @@ -71,7 +70,7 @@ void inferno_preset_gui(InfernoApp *app) yolo::info("LAYOUT SET TO DEFAULT"); } -void inferno_move_input(InfernoApp *app) +void inferno_move_input(InfernoApp* app) { static GLFWcursor* cursor = glfwCreateStandardCursor(GLFW_HAND_CURSOR); glfwSetCursor(graphics::window_get_glfw_window(), cursor); @@ -80,19 +79,16 @@ void inferno_move_input(InfernoApp *app) // pan only get on hold static glm::dvec2 lastMousePos; static int firstClick = 0; - if (glfwGetMouseButton(graphics::window_get_glfw_window(), GLFW_MOUSE_BUTTON_1) == GLFW_PRESS) - { + if (glfwGetMouseButton(graphics::window_get_glfw_window(), GLFW_MOUSE_BUTTON_1) == GLFW_PRESS) { firstClick++; - if (firstClick == 1) - { + if (firstClick == 1) { glfwGetCursorPos(graphics::window_get_glfw_window(), &lastMousePos.x, &lastMousePos.y); } glm::dvec2 tempMousePos = { 0.0f, 0.0f }; glfwGetCursorPos(graphics::window_get_glfw_window(), &tempMousePos.x, &tempMousePos.y); app->Input->MouseDelta = lastMousePos - tempMousePos; lastMousePos = tempMousePos; - } else - { + } else { firstClick = 0; app->Input->MouseDelta = { 0.0f, 0.0f }; lastMousePos = { 0.0f, 0.0f }; @@ -113,14 +109,15 @@ void inferno_move_input(InfernoApp *app) app->Input->MovementDelta |= 0b00000100; } -void inferno_stop_move_input(InfernoApp *app) +void inferno_stop_move_input(InfernoApp* app) { app->Input->MovementDelta = 0x0; app->Input->MouseDelta = { 0.0f, 0.0f }; } -int inferno_run(InfernoApp *app) +int inferno_run(InfernoApp* app) { return 1; } +} // namespace inferno diff --git a/src/inferno.hpp b/src/inferno.hpp index 02bbc0b..1b49a03 100644 --- a/src/inferno.hpp +++ b/src/inferno.hpp @@ -26,4 +26,3 @@ void inferno_stop_move_input(InfernoApp* app); int inferno_run(InfernoApp* app); } - diff --git a/src/main.cpp b/src/main.cpp index 9ee8811..b082c79 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,4 +8,3 @@ int main(int argc, char** argv) auto* inferno = inferno::inferno_create(); return inferno::inferno_run(inferno); } - diff --git a/src/preview_renderer/renderer.cpp b/src/preview_renderer/renderer.cpp index 4fdacdc..73904b2 100644 --- a/src/preview_renderer/renderer.cpp +++ b/src/preview_renderer/renderer.cpp @@ -94,15 +94,15 @@ void RasterizeRenderer::draw() for (Mesh* m : mCurrentScene->getRenderables()) { - m->getMaterial()->getGlShader()->use(); - GLint uniTrans = glGetUniformLocation(m->getMaterial()->getGlShader()->getProgram(), "model"); - glUniformMatrix4fv(uniTrans, 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0f))); + //m->getMaterial()->getGlShader()->use(); + //GLint uniTrans = glGetUniformLocation(m->getMaterial()->getGlShader()->getProgram(), "model"); + //glUniformMatrix4fv(uniTrans, 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0f))); - GLint uniView = glGetUniformLocation(m->getMaterial()->getGlShader()->getProgram(), "view"); - glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(mCurrentScene->getCamera()->getViewMatrix())); + //GLint uniView = glGetUniformLocation(m->getMaterial()->getGlShader()->getProgram(), "view"); + //glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(mCurrentScene->getCamera()->getViewMatrix())); - GLint uniProj = glGetUniformLocation(m->getMaterial()->getGlShader()->getProgram(), "proj"); - glUniformMatrix4fv(uniProj, 1, GL_FALSE, glm::value_ptr(mCurrentScene->getCamera()->getProjectionMatrix())); + //GLint uniProj = glGetUniformLocation(m->getMaterial()->getGlShader()->getProgram(), "proj"); + //glUniformMatrix4fv(uniProj, 1, GL_FALSE, glm::value_ptr(mCurrentScene->getCamera()->getProjectionMatrix())); glBindVertexArray(m->getVAO()); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m->getEBO()); diff --git a/src/preview_renderer/shader.cpp b/src/preview_renderer/shader.cpp index c19160b..8565189 100644 --- a/src/preview_renderer/shader.cpp +++ b/src/preview_renderer/shader.cpp @@ -1,40 +1,44 @@ #include "shader.hpp" -#include #include +#include using namespace inferno::graphics; static std::unordered_map shader2Index = { - {GL_VERTEX_SHADER, 0}, - {GL_GEOMETRY_SHADER, 1}, - {GL_FRAGMENT_SHADER, 2} + { GL_VERTEX_SHADER, 0 }, + { GL_GEOMETRY_SHADER, 1 }, + { GL_FRAGMENT_SHADER, 2 } }; inline std::string trim(std::string& str) { - str.erase(str.find_last_not_of(' ')+1); //suffixing spaces - str.erase(0, str.find_first_not_of(' ')); //prefixing spaces + str.erase(str.find_last_not_of(' ') + 1); // suffixing spaces + str.erase(0, str.find_first_not_of(' ')); // prefixing spaces return str; } -std::string textFromFile(const std::filesystem::path& path) { +std::string textFromFile(const std::filesystem::path& path) +{ std::ifstream input(path); return std::string((std::istreambuf_iterator(input)), - std::istreambuf_iterator()); + std::istreambuf_iterator()); } -std::vector getKeys(std::unique_ptr& shader, std::string key) { - std::vector ret; - for (const auto& p : shader->PreprocessorDefinitions) if (p.key == key) ret.push_back(&p); - return ret; +std::vector getKeys(std::unique_ptr& shader, std::string key) +{ + std::vector ret; + for (const auto& p : shader->PreprocessorDefinitions) + if (p.key == key) + ret.push_back(&p); + return ret; } -bool checkShader(GLuint uid) { +bool checkShader(GLuint uid) +{ GLint isCompiled = 0; glGetShaderiv(uid, GL_COMPILE_STATUS, &isCompiled); - if(isCompiled == GL_FALSE) - { + if (isCompiled == GL_FALSE) { GLint maxLength = 0; glGetShaderiv(uid, GL_INFO_LOG_LENGTH, &maxLength); @@ -52,8 +56,8 @@ bool checkShader(GLuint uid) { return true; } - -std::unique_ptr shader_create() { +std::unique_ptr shader_create() +{ std::unique_ptr shader = std::make_unique(); shader->Program = 0; @@ -64,100 +68,114 @@ std::unique_ptr shader_create() { return shader; } -void shader_cleanup(std::unique_ptr& shader) { - for (int i = 0; i < 3; i++) { - if (shader->Shaders[i] == GL_NONE) continue; - glDeleteShader(shader->Shaders[i]); - } +void shader_cleanup(std::unique_ptr& shader) +{ + for (int i = 0; i < 3; i++) { + if (shader->Shaders[i] == GL_NONE) + continue; + glDeleteShader(shader->Shaders[i]); + } glDeleteProgram(shader->Program); } -void shader_load(std::unique_ptr& shader, std::filesystem::path path) { +void shader_load(std::unique_ptr& shader, std::filesystem::path path) +{ - assert(std::filesystem::exists(path)); + assert(std::filesystem::exists(path)); - std::string loadedShaderSource = textFromFile(path); + std::string loadedShaderSource = textFromFile(path); - for (int i = 0; i < loadedShaderSource.length(); i++) { - const char& c = loadedShaderSource[i]; - if (c == '#') { - ShaderPreprocessorDefinition def = { .start = i }; - int j; - for (j = ++i; loadedShaderSource[j] != ' '; j++) { - def.key += loadedShaderSource[j]; - } - for (j++; loadedShaderSource[j] != '\n'; j++) { - def.def += loadedShaderSource[j]; - } - def.end = j; i = j; // advance i - def.def = trim(def.def); - def.key = trim(def.key); - shader->PreprocessorDefinitions.push_back(def); - } - } + for (int i = 0; i < loadedShaderSource.length(); i++) { + const char& c = loadedShaderSource[i]; + if (c == '#') { + ShaderPreprocessorDefinition def = { .start = i }; + int j; + for (j = ++i; loadedShaderSource[j] != ' '; j++) { + def.key += loadedShaderSource[j]; + } + for (j++; loadedShaderSource[j] != '\n'; j++) { + def.def += loadedShaderSource[j]; + } + def.end = j; + i = j; // advance i + def.def = trim(def.def); + def.key = trim(def.key); + shader->PreprocessorDefinitions.push_back(def); + } + } - // now we have all of the key/value definitions - // we can extract the relavent ones, for example - // "type" - std::vector types = getKeys(shader, "type"); - int i = 0; - for (const ShaderPreprocessorDefinition* type : types) { - GLuint glType = GL_NONE; - if (type->def == "vertex") glType = GL_VERTEX_SHADER; - if (type->def == "geometry") glType = GL_GEOMETRY_SHADER; - if (type->def == "fragment") glType = GL_FRAGMENT_SHADER; + // now we have all of the key/value definitions + // we can extract the relavent ones, for example + // "type" + std::vector types = getKeys(shader, "type"); + int i = 0; + for (const ShaderPreprocessorDefinition* type : types) { + GLuint glType = GL_NONE; + if (type->def == "vertex") + glType = GL_VERTEX_SHADER; + if (type->def == "geometry") + glType = GL_GEOMETRY_SHADER; + if (type->def == "fragment") + glType = GL_FRAGMENT_SHADER; - assert(glType != GL_NONE); + assert(glType != GL_NONE); - shader->Shaders[shader2Index[glType]] = glCreateShader(glType); + shader->Shaders[shader2Index[glType]] = glCreateShader(glType); - const char* source = loadedShaderSource.c_str() + type->end; - int end = types.size() - 1 == i ? types.size(): types[i + 1]->start; - int length = end - type->end; + const char* source = loadedShaderSource.c_str() + type->end; + int end = types.size() - 1 == i ? types.size() : types[i + 1]->start; + int length = end - type->end; - glShaderSource(shader->Shaders[shader2Index[glType]], 1, &source, &length); - i++; - } + glShaderSource(shader->Shaders[shader2Index[glType]], 1, &source, &length); + i++; + } } -void shader_link(std::unique_ptr &shader) { - shader->Program = glCreateProgram(); +void shader_link(std::unique_ptr& shader) +{ + shader->Program = glCreateProgram(); - for (int i = 0; i < 3; i++) { - if (shader->Shaders[i] == GL_NONE) continue; + for (int i = 0; i < 3; i++) { + if (shader->Shaders[i] == GL_NONE) + continue; - glCompileShader(shader->Shaders[i]); - if (!checkShader(shader->Shaders[i])) continue; + glCompileShader(shader->Shaders[i]); + if (!checkShader(shader->Shaders[i])) + continue; - glAttachShader(shader->Program, shader->Shaders[i]); - } + glAttachShader(shader->Program, shader->Shaders[i]); + } - glLinkProgram(shader->Program); + glLinkProgram(shader->Program); } - -void shader_add_attribute(std::unique_ptr &shader, const std::string &attribute) { +void shader_add_attribute(std::unique_ptr& shader, const std::string& attribute) +{ shader->Attributes[attribute] = glGetAttribLocation(shader->Program, attribute.c_str()); } -void shader_add_uniform(std::unique_ptr &shader, const std::string &uniform) { +void shader_add_uniform(std::unique_ptr& shader, const std::string& uniform) +{ shader->Uniforms[uniform] = glGetUniformLocation(shader->Program, uniform.c_str()); } -GLuint shader_get_attribute(std::unique_ptr &shader, const std::string &attribute) { +GLuint shader_get_attribute(std::unique_ptr& shader, const std::string& attribute) +{ return shader->Attributes[attribute]; } -GLuint shader_get_uniform(std::unique_ptr &shader, const std::string &uniform) { +GLuint shader_get_uniform(std::unique_ptr& shader, const std::string& uniform) +{ return shader->Uniforms[uniform]; } -void shader_use(std::unique_ptr& shader) { - glUseProgram(shader->Program); +void shader_use(std::unique_ptr& shader) +{ + glUseProgram(shader->Program); } -void shader_unuse(std::unique_ptr& shader) { - glUseProgram(0); +void shader_unuse(std::unique_ptr& shader) +{ + glUseProgram(0); } - diff --git a/src/preview_renderer/shader.hpp b/src/preview_renderer/shader.hpp index 9d83457..766269a 100644 --- a/src/preview_renderer/shader.hpp +++ b/src/preview_renderer/shader.hpp @@ -2,11 +2,11 @@ #include "../graphics.hpp" -#include -#include -#include #include +#include +#include #include +#include namespace inferno::graphics { @@ -16,7 +16,6 @@ typedef struct ShaderPreprocessorDefinition { std::string def; } shaderpreprocessordefinition; - typedef struct Shader { GLuint Shaders[3]; GLuint Program; @@ -40,4 +39,3 @@ void shader_use(std::unique_ptr& shader); void shader_unuse(std::unique_ptr& shader); } - diff --git a/src/scene/material.cpp b/src/scene/material.cpp index 95918fc..bcdba1c 100644 --- a/src/scene/material.cpp +++ b/src/scene/material.cpp @@ -15,12 +15,12 @@ Material::~Material() } -void Material::setGlShader(Shader* shader) -{ - mGlShader = shader; -} +//void Material::setGlShader(Shader* shader) +//{ + //mGlShader = shader; +//} -Shader* Material::getGlShader() -{ - return mGlShader; -} +//Shader* Material::getGlShader() +//{ + //return mGlShader; +//} diff --git a/src/scene/material.hpp b/src/scene/material.hpp index 482a48e..05a0fff 100644 --- a/src/scene/material.hpp +++ b/src/scene/material.hpp @@ -6,7 +6,7 @@ namespace inferno { -class Shader; +//class Shader; class HitInfo; class Material { @@ -15,14 +15,14 @@ public: ~Material(); std::string getName(); - void setGlShader(Shader* shader); - Shader* getGlShader(); + //void setGlShader(Shader* shader); + //Shader* getGlShader(); glm::vec3 sample(HitInfo* hit); private: std::string mName; - Shader* mGlShader; + //Shader* mGlShader; }; } diff --git a/src/window.cpp b/src/window.cpp index a01100f..2be7262 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1,9 +1,9 @@ -#include "window.hpp" +#include "window.hpp" #include "gui/style.hpp" #include "yolo/yolo.hpp" -using namespace inferno::graphics; +namespace inferno::graphics { static WINDOW_MODE WinMode = WINDOW_MODE::WIN_MODE_DEFAULT; static KeyCallback UserKeyCallback = nullptr; @@ -11,23 +11,26 @@ static int Width, Height; static const char* GlslVersion; static GLFWwindow* Window; -void glfwKeyCallback(GLFWwindow *window, int key, int scancode, - int action, int mods) { +void glfwKeyCallback(GLFWwindow* window, int key, int scancode, + int action, int mods) +{ if (UserKeyCallback != nullptr) { UserKeyCallback(key, scancode, action, mods); } } -void glfwErrorCallback(int error, const char *description) { +void glfwErrorCallback(int error, const char* description) +{ yolo::error("[GLFW {}] {}", error, description); } -void setupGLFW(std::string title) { +void setupGLFW(std::string title) +{ glfwSetErrorCallback(glfwErrorCallback); if (!glfwInit()) throw std::runtime_error("Failed to initialize GLFW"); - // Decide GL+GLSL versions + // Decide GL+GLSL versions #if defined(IMGUI_IMPL_OPENGL_ES2) // GL ES 2.0 + GLSL 100 glslVersion = "#version 100"; @@ -40,14 +43,14 @@ void setupGLFW(std::string title) { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac #else // GL 4.5 + GLSL 450 GlslVersion = "#version 450"; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only #endif // Create window with graphics context @@ -59,7 +62,8 @@ void setupGLFW(std::string title) { glfwSwapInterval(1); // Enable vsync } -void setupImGui() { +void setupImGui() +{ // Setup Dear ImGui context IMGUI_CHECKVERSION(); ImGui::CreateContext(); @@ -67,37 +71,38 @@ void setupImGui() { // Setup Dear ImGui style ImGui::StyleColorsDark(); - ImGuiIO &io = ImGui::GetIO(); + ImGuiIO& io = ImGui::GetIO(); (void)io; io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking - io.ConfigFlags |= - ImGuiConfigFlags_DpiEnableScaleFonts; // FIXME-DPI: THIS CURRENTLY DOESN'T - // WORK AS EXPECTED. DON'T USE IN - // USER APP! + io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleFonts; // FIXME-DPI: THIS CURRENTLY DOESN'T + // WORK AS EXPECTED. DON'T USE IN + // USER APP! io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleViewports; // FIXME-DPI // io.ConfigDockingWithShift // = true; - // Setup Platform/Renderer backends + // Setup Platform/Renderer backends ImGui_ImplGlfw_InitForOpenGL(Window, true); ImGui_ImplOpenGL3_Init(GlslVersion); inferno::SetupImGuiStyle2(); } -void shutdownImGui() { +void shutdownImGui() +{ ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); } -void shutdownGLFW() { +void shutdownGLFW() +{ glfwDestroyWindow(Window); glfwTerminate(); } - -void window_create(std::string title, int width, int height) { +void window_create(std::string title, int width, int height) +{ Width = width; Height = height; setupGLFW(title); @@ -105,16 +110,19 @@ void window_create(std::string title, int width, int height) { setupImGui(); } -void window_cleanup() { +void window_cleanup() +{ shutdownImGui(); shutdownGLFW(); } -void window_set_title(std::string title) { +void window_set_title(std::string title) +{ glfwSetWindowTitle(Window, title.c_str()); } -void window_set_size(int w, int h) { +void window_set_size(int w, int h) +{ Width = w; Height = h; glfwSetWindowSize(Window, Width, Height); @@ -126,7 +134,10 @@ glm::vec2 window_get_size() { return { Width, Height }; } void window_get_pos(int& x, int& y) { glfwGetWindowPos(Window, &x, &y); } -void window_set_mode(WINDOW_MODE mode) { +GLFWwindow* window_get_glfw_window() { return Window; } + +void window_set_mode(WINDOW_MODE mode) +{ WinMode = mode; if (mode == WINDOW_MODE::WIN_MODE_FPS) { glfwSetInputMode(Window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); @@ -137,7 +148,8 @@ void window_set_key_callback(KeyCallback callback) { UserKeyCallback = callback; KeyCallback window_get_key_callback() { return UserKeyCallback; } -bool window_new_frame() { +bool window_new_frame() +{ glfwPollEvents(); if (WinMode == WIN_MODE_FPS) { glfwSetInputMode(Window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); @@ -163,7 +175,8 @@ bool window_new_frame() { return true; } -void window_render() { +void window_render() +{ ImGui::End(); ImGui::Render(); auto io = ImGui::GetIO(); @@ -173,3 +186,4 @@ void window_render() { ImGui::UpdatePlatformWindows(); } +} diff --git a/src/window.hpp b/src/window.hpp index 9ccc1f7..3f9e7fd 100644 --- a/src/window.hpp +++ b/src/window.hpp @@ -2,8 +2,8 @@ #include -#include "singleton.hpp" #include "graphics.hpp" +#include "singleton.hpp" #define WINDOW_FLAGS ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoCollapse @@ -12,8 +12,7 @@ namespace inferno::graphics { typedef void (*KeyCallback)(int key, int scan, int action, int mod); typedef void (*MouseCallback)(double x, double y); -enum WINDOW_MODE -{ +enum WINDOW_MODE { WIN_MODE_DEFAULT, WIN_MODE_FPS, }; @@ -38,4 +37,3 @@ bool window_new_frame(); void window_render(); } -