CLANG FORMAT LETS GOOO

This commit is contained in:
Ben Kyd
2023-04-24 15:47:01 +01:00
parent 2ed5212b35
commit b3996b0a8d
11 changed files with 376 additions and 161 deletions

192
.clang-format Normal file
View File

@@ -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
...

View File

@@ -1,29 +1,29 @@
#include "inferno.hpp" #include "inferno.hpp"
#include <version.hpp> #include <version.hpp>
//#include "gui/layout.hpp" // #include "gui/layout.hpp"
#include "window.hpp" #include "window.hpp"
//#include "hart_module.hpp" // #include "hart_module.hpp"
//#include "hart_directory.hpp" // #include "hart_directory.hpp"
//#include "preview_renderer/renderer.hpp" // #include "preview_renderer/renderer.hpp"
//#include "preview_renderer/shader.hpp" // #include "preview_renderer/shader.hpp"
//#include "renderer/dispatcher.hpp" // #include "renderer/dispatcher.hpp"
//#include "renderer/renderer.hpp" // #include "renderer/renderer.hpp"
//#include "scene/camera.hpp" // #include "scene/camera.hpp"
//#include "scene/scene.hpp" // #include "scene/scene.hpp"
//#include "scene/material.hpp" // #include "scene/material.hpp"
//#include "scene/mesh.hpp" // #include "scene/mesh.hpp"
#include <yolo/yolo.hpp> #include <yolo/yolo.hpp>
#include <chrono>
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <chrono>
#include <numeric> #include <numeric>
using namespace inferno; namespace inferno {
InfernoApp* inferno_create() InfernoApp* inferno_create()
{ {
@@ -44,8 +44,7 @@ void inferno_cleanup(InfernoApp* app)
static void inferno_gui_help_marker(const char* desc) static void inferno_gui_help_marker(const char* desc)
{ {
ImGui::TextDisabled("(?)"); ImGui::TextDisabled("(?)");
if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayShort)) if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayShort)) {
{
ImGui::BeginTooltip(); ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
ImGui::TextUnformatted(desc); 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"); ImGuiID dockspace_id = ImGui::GetID("main");
ImGui::DockBuilderRemoveNode(dockspace_id); // Clear out existing layout ImGui::DockBuilderRemoveNode(dockspace_id); // Clear out existing layout
ImGui::DockBuilderAddNode(dockspace_id, ImGuiDockNodeFlags_DockSpace); // Add empty node 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_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); 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"); 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); static GLFWcursor* cursor = glfwCreateStandardCursor(GLFW_HAND_CURSOR);
glfwSetCursor(graphics::window_get_glfw_window(), cursor); glfwSetCursor(graphics::window_get_glfw_window(), cursor);
@@ -80,19 +79,16 @@ void inferno_move_input(InfernoApp *app)
// pan only get on hold // pan only get on hold
static glm::dvec2 lastMousePos; static glm::dvec2 lastMousePos;
static int firstClick = 0; 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++; firstClick++;
if (firstClick == 1) if (firstClick == 1) {
{
glfwGetCursorPos(graphics::window_get_glfw_window(), &lastMousePos.x, &lastMousePos.y); glfwGetCursorPos(graphics::window_get_glfw_window(), &lastMousePos.x, &lastMousePos.y);
} }
glm::dvec2 tempMousePos = { 0.0f, 0.0f }; glm::dvec2 tempMousePos = { 0.0f, 0.0f };
glfwGetCursorPos(graphics::window_get_glfw_window(), &tempMousePos.x, &tempMousePos.y); glfwGetCursorPos(graphics::window_get_glfw_window(), &tempMousePos.x, &tempMousePos.y);
app->Input->MouseDelta = lastMousePos - tempMousePos; app->Input->MouseDelta = lastMousePos - tempMousePos;
lastMousePos = tempMousePos; lastMousePos = tempMousePos;
} else } else {
{
firstClick = 0; firstClick = 0;
app->Input->MouseDelta = { 0.0f, 0.0f }; app->Input->MouseDelta = { 0.0f, 0.0f };
lastMousePos = { 0.0f, 0.0f }; lastMousePos = { 0.0f, 0.0f };
@@ -113,14 +109,15 @@ void inferno_move_input(InfernoApp *app)
app->Input->MovementDelta |= 0b00000100; app->Input->MovementDelta |= 0b00000100;
} }
void inferno_stop_move_input(InfernoApp *app) void inferno_stop_move_input(InfernoApp* app)
{ {
app->Input->MovementDelta = 0x0; app->Input->MovementDelta = 0x0;
app->Input->MouseDelta = { 0.0f, 0.0f }; app->Input->MouseDelta = { 0.0f, 0.0f };
} }
int inferno_run(InfernoApp *app) int inferno_run(InfernoApp* app)
{ {
return 1; return 1;
} }
} // namespace inferno

View File

@@ -26,4 +26,3 @@ void inferno_stop_move_input(InfernoApp* app);
int inferno_run(InfernoApp* app); int inferno_run(InfernoApp* app);
} }

View File

@@ -8,4 +8,3 @@ int main(int argc, char** argv)
auto* inferno = inferno::inferno_create(); auto* inferno = inferno::inferno_create();
return inferno::inferno_run(inferno); return inferno::inferno_run(inferno);
} }

View File

@@ -94,15 +94,15 @@ void RasterizeRenderer::draw()
for (Mesh* m : mCurrentScene->getRenderables()) for (Mesh* m : mCurrentScene->getRenderables())
{ {
m->getMaterial()->getGlShader()->use(); //m->getMaterial()->getGlShader()->use();
GLint uniTrans = glGetUniformLocation(m->getMaterial()->getGlShader()->getProgram(), "model"); //GLint uniTrans = glGetUniformLocation(m->getMaterial()->getGlShader()->getProgram(), "model");
glUniformMatrix4fv(uniTrans, 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0f))); //glUniformMatrix4fv(uniTrans, 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0f)));
GLint uniView = glGetUniformLocation(m->getMaterial()->getGlShader()->getProgram(), "view"); //GLint uniView = glGetUniformLocation(m->getMaterial()->getGlShader()->getProgram(), "view");
glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(mCurrentScene->getCamera()->getViewMatrix())); //glUniformMatrix4fv(uniView, 1, GL_FALSE, glm::value_ptr(mCurrentScene->getCamera()->getViewMatrix()));
GLint uniProj = glGetUniformLocation(m->getMaterial()->getGlShader()->getProgram(), "proj"); //GLint uniProj = glGetUniformLocation(m->getMaterial()->getGlShader()->getProgram(), "proj");
glUniformMatrix4fv(uniProj, 1, GL_FALSE, glm::value_ptr(mCurrentScene->getCamera()->getProjectionMatrix())); //glUniformMatrix4fv(uniProj, 1, GL_FALSE, glm::value_ptr(mCurrentScene->getCamera()->getProjectionMatrix()));
glBindVertexArray(m->getVAO()); glBindVertexArray(m->getVAO());
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m->getEBO()); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m->getEBO());

View File

@@ -1,40 +1,44 @@
#include "shader.hpp" #include "shader.hpp"
#include <iostream>
#include <fstream> #include <fstream>
#include <iostream>
using namespace inferno::graphics; using namespace inferno::graphics;
static std::unordered_map<GLuint, int> shader2Index = { static std::unordered_map<GLuint, int> shader2Index = {
{GL_VERTEX_SHADER, 0}, { GL_VERTEX_SHADER, 0 },
{GL_GEOMETRY_SHADER, 1}, { GL_GEOMETRY_SHADER, 1 },
{GL_FRAGMENT_SHADER, 2} { GL_FRAGMENT_SHADER, 2 }
}; };
inline std::string trim(std::string& str) inline std::string trim(std::string& str)
{ {
str.erase(str.find_last_not_of(' ')+1); //suffixing spaces str.erase(str.find_last_not_of(' ') + 1); // suffixing spaces
str.erase(0, str.find_first_not_of(' ')); //prefixing spaces str.erase(0, str.find_first_not_of(' ')); // prefixing spaces
return str; return str;
} }
std::string textFromFile(const std::filesystem::path& path) { std::string textFromFile(const std::filesystem::path& path)
{
std::ifstream input(path); std::ifstream input(path);
return std::string((std::istreambuf_iterator<char>(input)), return std::string((std::istreambuf_iterator<char>(input)),
std::istreambuf_iterator<char>()); std::istreambuf_iterator<char>());
} }
std::vector<const ShaderPreprocessorDefinition*> getKeys(std::unique_ptr<Shader>& shader, std::string key) { std::vector<const ShaderPreprocessorDefinition*> getKeys(std::unique_ptr<Shader>& shader, std::string key)
std::vector<const ShaderPreprocessorDefinition*> ret; {
for (const auto& p : shader->PreprocessorDefinitions) if (p.key == key) ret.push_back(&p); std::vector<const ShaderPreprocessorDefinition*> ret;
return 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; GLint isCompiled = 0;
glGetShaderiv(uid, GL_COMPILE_STATUS, &isCompiled); glGetShaderiv(uid, GL_COMPILE_STATUS, &isCompiled);
if(isCompiled == GL_FALSE) if (isCompiled == GL_FALSE) {
{
GLint maxLength = 0; GLint maxLength = 0;
glGetShaderiv(uid, GL_INFO_LOG_LENGTH, &maxLength); glGetShaderiv(uid, GL_INFO_LOG_LENGTH, &maxLength);
@@ -52,8 +56,8 @@ bool checkShader(GLuint uid) {
return true; return true;
} }
std::unique_ptr<Shader> shader_create()
std::unique_ptr<Shader> shader_create() { {
std::unique_ptr<Shader> shader = std::make_unique<Shader>(); std::unique_ptr<Shader> shader = std::make_unique<Shader>();
shader->Program = 0; shader->Program = 0;
@@ -64,100 +68,114 @@ std::unique_ptr<Shader> shader_create() {
return shader; return shader;
} }
void shader_cleanup(std::unique_ptr<Shader>& shader) { void shader_cleanup(std::unique_ptr<Shader>& shader)
for (int i = 0; i < 3; i++) { {
if (shader->Shaders[i] == GL_NONE) continue; for (int i = 0; i < 3; i++) {
glDeleteShader(shader->Shaders[i]); if (shader->Shaders[i] == GL_NONE)
} continue;
glDeleteShader(shader->Shaders[i]);
}
glDeleteProgram(shader->Program); glDeleteProgram(shader->Program);
} }
void shader_load(std::unique_ptr<Shader>& shader, std::filesystem::path path) { void shader_load(std::unique_ptr<Shader>& 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++) { for (int i = 0; i < loadedShaderSource.length(); i++) {
const char& c = loadedShaderSource[i]; const char& c = loadedShaderSource[i];
if (c == '#') { if (c == '#') {
ShaderPreprocessorDefinition def = { .start = i }; ShaderPreprocessorDefinition def = { .start = i };
int j; int j;
for (j = ++i; loadedShaderSource[j] != ' '; j++) { for (j = ++i; loadedShaderSource[j] != ' '; j++) {
def.key += loadedShaderSource[j]; def.key += loadedShaderSource[j];
} }
for (j++; loadedShaderSource[j] != '\n'; j++) { for (j++; loadedShaderSource[j] != '\n'; j++) {
def.def += loadedShaderSource[j]; def.def += loadedShaderSource[j];
} }
def.end = j; i = j; // advance i def.end = j;
def.def = trim(def.def); i = j; // advance i
def.key = trim(def.key); def.def = trim(def.def);
shader->PreprocessorDefinitions.push_back(def); def.key = trim(def.key);
} shader->PreprocessorDefinitions.push_back(def);
} }
}
// now we have all of the key/value definitions // now we have all of the key/value definitions
// we can extract the relavent ones, for example // we can extract the relavent ones, for example
// "type" // "type"
std::vector<const ShaderPreprocessorDefinition*> types = getKeys(shader, "type"); std::vector<const ShaderPreprocessorDefinition*> types = getKeys(shader, "type");
int i = 0; int i = 0;
for (const ShaderPreprocessorDefinition* type : types) { for (const ShaderPreprocessorDefinition* type : types) {
GLuint glType = GL_NONE; GLuint glType = GL_NONE;
if (type->def == "vertex") glType = GL_VERTEX_SHADER; if (type->def == "vertex")
if (type->def == "geometry") glType = GL_GEOMETRY_SHADER; glType = GL_VERTEX_SHADER;
if (type->def == "fragment") glType = GL_FRAGMENT_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; const char* source = loadedShaderSource.c_str() + type->end;
int end = types.size() - 1 == i ? types.size(): types[i + 1]->start; int end = types.size() - 1 == i ? types.size() : types[i + 1]->start;
int length = end - type->end; int length = end - type->end;
glShaderSource(shader->Shaders[shader2Index[glType]], 1, &source, &length); glShaderSource(shader->Shaders[shader2Index[glType]], 1, &source, &length);
i++; i++;
} }
} }
void shader_link(std::unique_ptr<Shader> &shader) { void shader_link(std::unique_ptr<Shader>& shader)
shader->Program = glCreateProgram(); {
shader->Program = glCreateProgram();
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
if (shader->Shaders[i] == GL_NONE) continue; if (shader->Shaders[i] == GL_NONE)
continue;
glCompileShader(shader->Shaders[i]); glCompileShader(shader->Shaders[i]);
if (!checkShader(shader->Shaders[i])) continue; 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>& shader, const std::string& attribute)
void shader_add_attribute(std::unique_ptr<Shader> &shader, const std::string &attribute) { {
shader->Attributes[attribute] = glGetAttribLocation(shader->Program, attribute.c_str()); shader->Attributes[attribute] = glGetAttribLocation(shader->Program, attribute.c_str());
} }
void shader_add_uniform(std::unique_ptr<Shader> &shader, const std::string &uniform) { void shader_add_uniform(std::unique_ptr<Shader>& shader, const std::string& uniform)
{
shader->Uniforms[uniform] = glGetUniformLocation(shader->Program, uniform.c_str()); shader->Uniforms[uniform] = glGetUniformLocation(shader->Program, uniform.c_str());
} }
GLuint shader_get_attribute(std::unique_ptr<Shader> &shader, const std::string &attribute) { GLuint shader_get_attribute(std::unique_ptr<Shader>& shader, const std::string& attribute)
{
return shader->Attributes[attribute]; return shader->Attributes[attribute];
} }
GLuint shader_get_uniform(std::unique_ptr<Shader> &shader, const std::string &uniform) { GLuint shader_get_uniform(std::unique_ptr<Shader>& shader, const std::string& uniform)
{
return shader->Uniforms[uniform]; return shader->Uniforms[uniform];
} }
void shader_use(std::unique_ptr<Shader>& shader) { void shader_use(std::unique_ptr<Shader>& shader)
glUseProgram(shader->Program); {
glUseProgram(shader->Program);
} }
void shader_unuse(std::unique_ptr<Shader>& shader) { void shader_unuse(std::unique_ptr<Shader>& shader)
glUseProgram(0); {
glUseProgram(0);
} }

View File

@@ -2,11 +2,11 @@
#include "../graphics.hpp" #include "../graphics.hpp"
#include <string>
#include <memory>
#include <vector>
#include <filesystem> #include <filesystem>
#include <memory>
#include <string>
#include <unordered_map> #include <unordered_map>
#include <vector>
namespace inferno::graphics { namespace inferno::graphics {
@@ -16,7 +16,6 @@ typedef struct ShaderPreprocessorDefinition {
std::string def; std::string def;
} shaderpreprocessordefinition; } shaderpreprocessordefinition;
typedef struct Shader { typedef struct Shader {
GLuint Shaders[3]; GLuint Shaders[3];
GLuint Program; GLuint Program;
@@ -40,4 +39,3 @@ void shader_use(std::unique_ptr<Shader>& shader);
void shader_unuse(std::unique_ptr<Shader>& shader); void shader_unuse(std::unique_ptr<Shader>& shader);
} }

View File

@@ -15,12 +15,12 @@ Material::~Material()
} }
void Material::setGlShader(Shader* shader) //void Material::setGlShader(Shader* shader)
{ //{
mGlShader = shader; //mGlShader = shader;
} //}
Shader* Material::getGlShader() //Shader* Material::getGlShader()
{ //{
return mGlShader; //return mGlShader;
} //}

View File

@@ -6,7 +6,7 @@
namespace inferno { namespace inferno {
class Shader; //class Shader;
class HitInfo; class HitInfo;
class Material { class Material {
@@ -15,14 +15,14 @@ public:
~Material(); ~Material();
std::string getName(); std::string getName();
void setGlShader(Shader* shader); //void setGlShader(Shader* shader);
Shader* getGlShader(); //Shader* getGlShader();
glm::vec3 sample(HitInfo* hit); glm::vec3 sample(HitInfo* hit);
private: private:
std::string mName; std::string mName;
Shader* mGlShader; //Shader* mGlShader;
}; };
} }

View File

@@ -1,9 +1,9 @@
#include "window.hpp"
#include "window.hpp"
#include "gui/style.hpp" #include "gui/style.hpp"
#include "yolo/yolo.hpp" #include "yolo/yolo.hpp"
using namespace inferno::graphics; namespace inferno::graphics {
static WINDOW_MODE WinMode = WINDOW_MODE::WIN_MODE_DEFAULT; static WINDOW_MODE WinMode = WINDOW_MODE::WIN_MODE_DEFAULT;
static KeyCallback UserKeyCallback = nullptr; static KeyCallback UserKeyCallback = nullptr;
@@ -11,23 +11,26 @@ static int Width, Height;
static const char* GlslVersion; static const char* GlslVersion;
static GLFWwindow* Window; static GLFWwindow* Window;
void glfwKeyCallback(GLFWwindow *window, int key, int scancode, void glfwKeyCallback(GLFWwindow* window, int key, int scancode,
int action, int mods) { int action, int mods)
{
if (UserKeyCallback != nullptr) { if (UserKeyCallback != nullptr) {
UserKeyCallback(key, scancode, action, mods); UserKeyCallback(key, scancode, action, mods);
} }
} }
void glfwErrorCallback(int error, const char *description) { void glfwErrorCallback(int error, const char* description)
{
yolo::error("[GLFW {}] {}", error, description); yolo::error("[GLFW {}] {}", error, description);
} }
void setupGLFW(std::string title) { void setupGLFW(std::string title)
{
glfwSetErrorCallback(glfwErrorCallback); glfwSetErrorCallback(glfwErrorCallback);
if (!glfwInit()) if (!glfwInit())
throw std::runtime_error("Failed to initialize GLFW"); throw std::runtime_error("Failed to initialize GLFW");
// Decide GL+GLSL versions // Decide GL+GLSL versions
#if defined(IMGUI_IMPL_OPENGL_ES2) #if defined(IMGUI_IMPL_OPENGL_ES2)
// GL ES 2.0 + GLSL 100 // GL ES 2.0 + GLSL 100
glslVersion = "#version 100"; glslVersion = "#version 100";
@@ -40,14 +43,14 @@ void setupGLFW(std::string title) {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only 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 #else
// GL 4.5 + GLSL 450 // GL 4.5 + GLSL 450
GlslVersion = "#version 450"; GlslVersion = "#version 450";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only 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 #endif
// Create window with graphics context // Create window with graphics context
@@ -59,7 +62,8 @@ void setupGLFW(std::string title) {
glfwSwapInterval(1); // Enable vsync glfwSwapInterval(1); // Enable vsync
} }
void setupImGui() { void setupImGui()
{
// Setup Dear ImGui context // Setup Dear ImGui context
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();
@@ -67,37 +71,38 @@ void setupImGui() {
// Setup Dear ImGui style // Setup Dear ImGui style
ImGui::StyleColorsDark(); ImGui::StyleColorsDark();
ImGuiIO &io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
(void)io; (void)io;
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleFonts; // FIXME-DPI: THIS CURRENTLY DOESN'T
ImGuiConfigFlags_DpiEnableScaleFonts; // FIXME-DPI: THIS CURRENTLY DOESN'T // WORK AS EXPECTED. DON'T USE IN
// WORK AS EXPECTED. DON'T USE IN // USER APP!
// USER APP!
io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleViewports; // FIXME-DPI io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleViewports; // FIXME-DPI
// io.ConfigDockingWithShift // io.ConfigDockingWithShift
// = true; // = true;
// Setup Platform/Renderer backends // Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(Window, true); ImGui_ImplGlfw_InitForOpenGL(Window, true);
ImGui_ImplOpenGL3_Init(GlslVersion); ImGui_ImplOpenGL3_Init(GlslVersion);
inferno::SetupImGuiStyle2(); inferno::SetupImGuiStyle2();
} }
void shutdownImGui() { void shutdownImGui()
{
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown(); ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext(); ImGui::DestroyContext();
} }
void shutdownGLFW() { void shutdownGLFW()
{
glfwDestroyWindow(Window); glfwDestroyWindow(Window);
glfwTerminate(); glfwTerminate();
} }
void window_create(std::string title, int width, int height)
void window_create(std::string title, int width, int height) { {
Width = width; Width = width;
Height = height; Height = height;
setupGLFW(title); setupGLFW(title);
@@ -105,16 +110,19 @@ void window_create(std::string title, int width, int height) {
setupImGui(); setupImGui();
} }
void window_cleanup() { void window_cleanup()
{
shutdownImGui(); shutdownImGui();
shutdownGLFW(); shutdownGLFW();
} }
void window_set_title(std::string title) { void window_set_title(std::string title)
{
glfwSetWindowTitle(Window, title.c_str()); glfwSetWindowTitle(Window, title.c_str());
} }
void window_set_size(int w, int h) { void window_set_size(int w, int h)
{
Width = w; Width = w;
Height = h; Height = h;
glfwSetWindowSize(Window, Width, Height); 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_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; WinMode = mode;
if (mode == WINDOW_MODE::WIN_MODE_FPS) { if (mode == WINDOW_MODE::WIN_MODE_FPS) {
glfwSetInputMode(Window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); 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; } KeyCallback window_get_key_callback() { return UserKeyCallback; }
bool window_new_frame() { bool window_new_frame()
{
glfwPollEvents(); glfwPollEvents();
if (WinMode == WIN_MODE_FPS) { if (WinMode == WIN_MODE_FPS) {
glfwSetInputMode(Window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); glfwSetInputMode(Window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
@@ -163,7 +175,8 @@ bool window_new_frame() {
return true; return true;
} }
void window_render() { void window_render()
{
ImGui::End(); ImGui::End();
ImGui::Render(); ImGui::Render();
auto io = ImGui::GetIO(); auto io = ImGui::GetIO();
@@ -173,3 +186,4 @@ void window_render() {
ImGui::UpdatePlatformWindows(); ImGui::UpdatePlatformWindows();
} }
}

View File

@@ -2,8 +2,8 @@
#include <string> #include <string>
#include "singleton.hpp"
#include "graphics.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 #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 (*KeyCallback)(int key, int scan, int action, int mod);
typedef void (*MouseCallback)(double x, double y); typedef void (*MouseCallback)(double x, double y);
enum WINDOW_MODE enum WINDOW_MODE {
{
WIN_MODE_DEFAULT, WIN_MODE_DEFAULT,
WIN_MODE_FPS, WIN_MODE_FPS,
}; };
@@ -38,4 +37,3 @@ bool window_new_frame();
void window_render(); void window_render();
} }