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

@@ -18,12 +18,12 @@
#include <yolo/yolo.hpp>
#include <chrono>
#include <iostream>
#include <memory>
#include <chrono>
#include <numeric>
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);
@@ -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 };
@@ -124,3 +120,4 @@ int inferno_run(InfernoApp *app)
return 1;
}
} // namespace inferno

View File

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

View File

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

View File

@@ -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());

View File

@@ -1,7 +1,7 @@
#include "shader.hpp"
#include <iostream>
#include <fstream>
#include <iostream>
using namespace inferno::graphics;
@@ -18,23 +18,27 @@ inline std::string trim(std::string& str)
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<char>(input)),
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);
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> shader_create() {
std::unique_ptr<Shader> shader_create()
{
std::unique_ptr<Shader> shader = std::make_unique<Shader>();
shader->Program = 0;
@@ -64,16 +68,19 @@ std::unique_ptr<Shader> shader_create() {
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;
if (shader->Shaders[i] == GL_NONE)
continue;
glDeleteShader(shader->Shaders[i]);
}
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));
@@ -90,7 +97,8 @@ void shader_load(std::unique_ptr<Shader>& shader, std::filesystem::path path) {
for (j++; loadedShaderSource[j] != '\n'; j++) {
def.def += loadedShaderSource[j];
}
def.end = j; i = j; // advance i
def.end = j;
i = j; // advance i
def.def = trim(def.def);
def.key = trim(def.key);
shader->PreprocessorDefinitions.push_back(def);
@@ -104,9 +112,12 @@ void shader_load(std::unique_ptr<Shader>& shader, std::filesystem::path path) {
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;
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);
@@ -121,14 +132,17 @@ void shader_load(std::unique_ptr<Shader>& shader, std::filesystem::path path) {
}
}
void shader_link(std::unique_ptr<Shader> &shader) {
void shader_link(std::unique_ptr<Shader>& shader)
{
shader->Program = glCreateProgram();
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]);
if (!checkShader(shader->Shaders[i])) continue;
if (!checkShader(shader->Shaders[i]))
continue;
glAttachShader(shader->Program, shader->Shaders[i]);
}
@@ -136,28 +150,32 @@ void shader_link(std::unique_ptr<Shader> &shader) {
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());
}
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());
}
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];
}
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];
}
void shader_use(std::unique_ptr<Shader>& shader) {
void shader_use(std::unique_ptr<Shader>& shader)
{
glUseProgram(shader->Program);
}
void shader_unuse(std::unique_ptr<Shader>& shader) {
void shader_unuse(std::unique_ptr<Shader>& shader)
{
glUseProgram(0);
}

View File

@@ -2,11 +2,11 @@
#include "../graphics.hpp"
#include <string>
#include <memory>
#include <vector>
#include <filesystem>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
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>& shader);
void shader_unuse(std::unique_ptr<Shader>& shader);
}

View File

@@ -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;
//}

View File

@@ -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;
};
}

View File

@@ -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;
@@ -12,17 +12,20 @@ static const char* GlslVersion;
static GLFWwindow* Window;
void glfwKeyCallback(GLFWwindow* window, int key, int scancode,
int action, int mods) {
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");
@@ -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();
@@ -70,8 +74,7 @@ void setupImGui() {
ImGuiIO& io = ImGui::GetIO();
(void)io;
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |=
ImGuiConfigFlags_DpiEnableScaleFonts; // FIXME-DPI: THIS CURRENTLY DOESN'T
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
@@ -85,19 +88,21 @@ void setupImGui() {
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();
}
}

View File

@@ -2,8 +2,8 @@
#include <string>
#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();
}