From b4c01d2aa1afe176ed4c23a94fb76cc1c1efd9e6 Mon Sep 17 00:00:00 2001
From: Petr Babic <pbabic@redhat.com>
Date: Mon, 11 Mar 2024 19:51:50 +0100
Subject: [PATCH] use default material

---
 .clang-format     | 234 ++++++++++++++++++++++++++++++++++++++++++++++
 src/presenter.cpp |  87 +++++++----------
 2 files changed, 269 insertions(+), 52 deletions(-)
 create mode 100644 .clang-format

diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..42d7091
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,234 @@
+---
+BasedOnStyle: LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignArrayOfStructures: None
+AlignConsecutiveAssignments:
+  Enabled: false
+  AcrossEmptyLines: false
+  AcrossComments: false
+  AlignCompound: false
+  PadOperators: true
+AlignConsecutiveBitFields:
+  Enabled: false
+  AcrossEmptyLines: false
+  AcrossComments: false
+  AlignCompound: false
+  PadOperators: false
+AlignConsecutiveDeclarations:
+  Enabled: false
+  AcrossEmptyLines: false
+  AcrossComments: false
+  AlignCompound: false
+  PadOperators: false
+AlignConsecutiveMacros:
+  Enabled: false
+  AcrossEmptyLines: false
+  AcrossComments: false
+  AlignCompound: false
+  PadOperators: false
+AlignConsecutiveShortCaseStatements:
+  Enabled: false
+  AcrossEmptyLines: false
+  AcrossComments: false
+  AlignCaseColons: false
+AlignEscapedNewlines: Right
+AlignOperands: Align
+AlignTrailingComments:
+  Kind: Always
+  OverEmptyLines: 0
+AllowAllArgumentsOnNextLine: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: Never
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortEnumsOnASingleLine: true
+AllowShortFunctionsOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: Never
+AllowShortLambdasOnASingleLine: All
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: Yes
+AttributeMacros:
+  - __capability
+BinPackArguments: true
+BinPackParameters: true
+BitFieldColonSpacing: Both
+BraceWrapping:
+  AfterCaseLabel: false
+  AfterClass: false
+  AfterControlStatement: Never
+  AfterEnum: false
+  AfterFunction: false
+  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
+BreakAfterAttributes: Never
+BreakAfterJavaFieldAnnotations: false
+BreakArrays: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Attach
+BreakBeforeConceptDeclarations: Always
+BreakBeforeInlineASMColon: OnlyMultiline
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: BeforeColon
+BreakInheritanceList: BeforeColon
+BreakStringLiterals: true
+ColumnLimit: 120
+CommentPragmas: "^ IWYU pragma:"
+CompactNamespaces: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat: false
+EmptyLineAfterAccessModifier: Never
+EmptyLineBeforeAccessModifier: LogicalBlock
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+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
+IndentCaseBlocks: false
+IndentCaseLabels: false
+IndentExternBlock: AfterExternBlock
+IndentGotoLabels: true
+IndentPPDirectives: None
+IndentRequiresClause: true
+IndentWidth: 4
+IndentWrappedFunctionNames: false
+InsertBraces: false
+InsertNewlineAtEOF: false
+InsertTrailingCommas: None
+IntegerLiteralSeparator:
+  Binary: 0
+  BinaryMinDigits: 0
+  Decimal: 0
+  DecimalMinDigits: 0
+  Hex: 0
+  HexMinDigits: 0
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtEOF: false
+KeepEmptyLinesAtTheStartOfBlocks: true
+LambdaBodyIndentation: Signature
+Language: Cpp
+LineEnding: DeriveLF
+MacroBlockBegin: ""
+MacroBlockEnd: ""
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 2
+ObjCBreakBeforeNestedBlockParam: true
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PPIndentWidth: -1
+PackConstructorInitializers: BinPack
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakOpenParenthesis: 0
+PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 1000000
+PenaltyIndentedWhitespace: 0
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Right
+QualifierAlignment: Leave
+ReferenceAlignment: Pointer
+ReflowComments: true
+RemoveBracesLLVM: false
+RemoveParentheses: Leave
+RemoveSemicolon: false
+RequiresClausePosition: OwnLine
+RequiresExpressionIndentation: OuterScope
+SeparateDefinitionBlocks: Leave
+ShortNamespaceLines: 1
+SortIncludes: CaseSensitive
+SortJavaStaticImport: Before
+SortUsingDeclarations: LexicographicNumeric
+SpaceAfterCStyleCast: false
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: true
+SpaceAroundPointerQualifiers: Default
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCaseColon: false
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeJsonColon: false
+SpaceBeforeParens: ControlStatements
+SpaceBeforeParensOptions:
+  AfterControlStatements: true
+  AfterForeachMacros: true
+  AfterFunctionDeclarationName: false
+  AfterFunctionDefinitionName: false
+  AfterIfMacros: true
+  AfterOverloadedOperator: false
+  AfterRequiresInClause: false
+  AfterRequiresInExpression: false
+  BeforeNonEmptyParentheses: false
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceBeforeSquareBrackets: false
+SpaceInEmptyBlock: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: Never
+SpacesInContainerLiterals: true
+SpacesInLineCommentPrefix:
+  Minimum: 1
+  Maximum: -1
+SpacesInParens: Never
+SpacesInParensOptions:
+  InConditionalStatements: false
+  InCStyleCasts: false
+  InEmptyParentheses: false
+  Other: false
+SpacesInSquareBrackets: false
+Standard: Latest
+StatementAttributeLikeMacros:
+  - Q_EMIT
+StatementMacros:
+  - Q_UNUSED
+  - QT_REQUIRE_VERSION
+TabWidth: 8
+UseTab: Never
+VerilogBreakBetweenInstancePorts: true
+WhitespaceSensitiveMacros:
+  - BOOST_PP_STRINGIZE
+  - CF_SWIFT_NAME
+  - NS_SWIFT_NAME
+  - PP_STRINGIZE
+  - STRINGIZE
diff --git a/src/presenter.cpp b/src/presenter.cpp
index bc4fa5b..ac30734 100644
--- a/src/presenter.cpp
+++ b/src/presenter.cpp
@@ -1,39 +1,32 @@
-#include <maker/presenter.hpp>
-#include <maker/index.hpp>
+#include <com/math_files.hpp>
 #include <gfx/index.hpp>
+#include <maker/index.hpp>
+#include <maker/presenter.hpp>
 #include <osi/index.hpp>
-#include <com/math_files.hpp>
 
 namespace mak {
 
-Presenter::Presenter()
-    : com::Runner{ self_name() }
-{}
+Presenter::Presenter() : com::Runner{ self_name() } {}
 
-Presenter::~Presenter()
-{}
+Presenter::~Presenter() {}
 
 static com::Folder *generate_grid() {
-    auto shader = gfx::shader_system()->insert_shader("grid_shader", gfx::Shader::Pipeline::FORWARD, gfx::Shader::UNLIT, {"shaders"});
-    auto color = shader->insert<gfx::Shader::UniformNode>(gfx::Shader::Node::SlotDefinition{"color", "color", gfx::Shader::Node::DataType::ElementType::VEC3});
-    shader->connect(shader->root(), gfx::Shader::MasterNodeUnlit::inputs::color, color, 0);
-
-    auto material = gfx::material_system()->insert_material("grid_material", shader, {gfx::material_system()->materials()->name()});
+    auto material = gfx::material_system()->insert_default_material("grid_material", { "materials" }, vec3{ 0 });
 
-    auto grid = gfx::object_system()->insert_object(
-        { "grid" },
-        material,
-        gfx::buffer_generators()->insert_procedural_grid()
-    );
+    auto grid =
+        gfx::object_system()->insert_object({ "grid" }, material, gfx::buffer_generators()->insert_procedural_grid());
     gfx::object_system()->push_frame_back(grid, grid_frame());
 
     return grid;
 }
 
 static com::Folder *generate_box(vec3 position, vec3 half_sizes_along_axes) {
-    auto shader = gfx::shader_system()->insert_shader("box_shader", gfx::Shader::Pipeline::FORWARD, gfx::Shader::LIT, {"shaders"});
-    auto texture = shader->insert<gfx::Shader::TextureNode>("/home/pbabic/Repositories/age_app_template/data/age/texture/UV.jpeg");
-    auto container = shader->insert<gfx::Shader::TextureNode>("/home/pbabic/Repositories/age_app_template/data/age/texture/container.jpg");
+    auto shader = gfx::shader_system()->insert_shader("box_shader", gfx::Shader::Pipeline::FORWARD, gfx::Shader::LIT,
+                                                      { "shaders" });
+    auto texture =
+        shader->insert<gfx::Shader::TextureNode>("/home/pbabic/Repositories/age_app_template/data/age/texture/UV.jpeg");
+    auto container = shader->insert<gfx::Shader::TextureNode>(
+        "/home/pbabic/Repositories/age_app_template/data/age/texture/container.jpg");
 
     auto tex_coords = shader->insert<gfx::Shader::NodeVaryingTexcoord>();
     shader->connect(texture, gfx::Shader::TextureNode::inputs::tex_coord, tex_coords, 0);
@@ -47,14 +40,12 @@ static com::Folder *generate_box(vec3 position, vec3 half_sizes_along_axes) {
     shader->connect(shader->root(), gfx::Shader::MasterNodeLit::inputs::diffuse, add, 0);
     shader->connect(shader->root(), gfx::Shader::MasterNodeLit::inputs::specular, add, 0);
 
-
-    auto material = gfx::material_system()->insert_material("box_material", shader, {gfx::material_system()->materials()->name()});
+    auto material = gfx::material_system()->insert_material("box_material", shader,
+                                                            { gfx::material_system()->materials()->name() });
 
     auto box = gfx::object_system()->insert_object(
-        { "test_box" },
-        material,
-        gfx::buffer_generators()->insert_procedural_box_solid(half_sizes_along_axes , "test_box", { "maker" })
-    );
+        { "test_box" }, material,
+        gfx::buffer_generators()->insert_procedural_box_solid(half_sizes_along_axes, "test_box", { "maker" }));
     auto frame = root()->push_back<com::Folder>("test_box")->push_back<com::Frame>();
     frame->set_origin(position);
     gfx::object_system()->push_frame_back(box, frame);
@@ -65,62 +56,54 @@ static com::Folder *generate_box(vec3 position, vec3 half_sizes_along_axes) {
 static com::Folder *generate_point_light(vec3 position, vec3 color, float radius) {
     auto point_light_frame = root()->push_back<com::Folder>("point_light")->push_back<com::Frame>();
     point_light_frame->move_origin(position);
-    auto point_light = gfx::light_system()->insert_light<gfx::PointLight>({"point_light"}, point_light_frame, color, radius);
+    auto point_light =
+        gfx::light_system()->insert_light<gfx::PointLight>({ "point_light" }, point_light_frame, color, radius);
 
-    auto shader = gfx::shader_system()->insert_shader("point_light_shader", gfx::Shader::Pipeline::FORWARD, gfx::Shader::UNLIT, {"shaders"});
-    auto color_node = shader->insert<gfx::Shader::UniformNode>(gfx::Shader::Node::SlotDefinition{"color", "color", gfx::Shader::Node::DataType::ElementType::VEC3});
-    shader->connect(shader->root(), gfx::Shader::MasterNodeUnlit::inputs::color, color_node, 0);
-
-    auto material = gfx::material_system()->insert_material("point_light_material", shader, {gfx::material_system()->materials()->name()});
-    material->set_uniform(color_node->name(), color);
+    auto material = gfx::material_system()->insert_default_material("point_light_material", { "materials" }, color);
 
     // point light visualizer box
     gfx::object_system()->push_frame_back(
         gfx::object_system()->insert_object(
-            { "point_light_box" },
-            material,
-            gfx::buffer_generators()->insert_procedural_box_solid({0.1, 0.1, 0.1}, "point_light_box", {"maker"})
-            ),
-        point_light_frame
-        );
+            { "point_light_box" }, material,
+            gfx::buffer_generators()->insert_procedural_box_solid({ 0.1, 0.1, 0.1 }, "point_light_box", { "maker" })),
+        point_light_frame);
 
     return point_light;
 }
 
-void Presenter::initialize()
-{
+void Presenter::initialize() {
     osi::presenters()->push_back<com::Folder>("maker")->push_back<com::Link>(self_name() + ".link", this);
 
     auto grid = generate_grid();
-    auto box = generate_box(vec3{0}, vec3{0.5});
+    auto box = generate_box(vec3{ 0 }, vec3{ 0.5 });
 
-    auto point_light = generate_point_light({2, 1, 1}, {0, 1, 1}, 20);
+    auto point_light = generate_point_light({ 2, 1, 1 }, { 0, 1, 1 }, 20);
     gfx::object_system()->insert_light(box, point_light);
 
     // directional light
     auto light_frame = root()->push_back<com::Folder>("dir_light")->push_back<com::Frame>();
-    light_frame->set_rotation(quat{{1.2, 0.8, 0.3}});
-    auto light = gfx::light_system()->insert_light<gfx::DirectionalLight>({"dir_light"}, light_frame, vec3{0.75, 0.5, 0.5});
+    light_frame->set_rotation(quat{ { 1.2, 0.8, 0.3 } });
+    auto light =
+        gfx::light_system()->insert_light<gfx::DirectionalLight>({ "dir_light" }, light_frame, vec3{ 0.75, 0.5, 0.5 });
     gfx::object_system()->insert_light(box, light);
 
     // ambient light
-    gfx::object_system()->insert_light(box, gfx::light_system()->insert_light<gfx::AmbientLight>({"ambient_light"}, nullptr, vec3{0.1, 1, 0.5}));
+    gfx::object_system()->insert_light(
+        box, gfx::light_system()->insert_light<gfx::AmbientLight>({ "ambient_light" }, nullptr, vec3{ 0.1, 1, 0.5 }));
 
     print_tree(*root());
     print_tree(*gfx::material_system()->folder());
 }
 
-void Presenter::release()
-{
+void Presenter::release() {
     osi::presenters()->find<com::Folder>("maker")->erase(self_name() + ".link");
 
     root()->erase("test_box");
 }
 
-void Presenter::next_round()
-{
+void Presenter::next_round() {
     gfx::renderer()->clear_render_buffers();
     gfx::renderer()->present_collection(gfx::object_system()->objects());
 }
 
-}
+} // namespace mak
-- 
GitLab