wip: renderer rewrite

This commit is contained in:
light7734 2025-09-18 19:24:27 +03:30
parent 3c1193eedc
commit 3a713b6af7
Signed by: light7734
GPG key ID: 8C30176798F1A6BA
28 changed files with 283 additions and 186 deletions

View file

@ -0,0 +1,248 @@
---
Checks: "-*,
performance-unnecessary-value-param,
performance-unnecessary-copy-initialization,
performance-type-promotion-in-math-fn,
performance-trivially-destructible,
performance-noexcept-swap,
performance-noexcept-move-constructor,
performance-noexcept-destructor,
performance-no-int-to-ptr,
performance-no-automatic-move,
performance-move-constructor-init,
performance-move-const-arg,
performance-inefficient-vector-operation,
performance-inefficient-string-concatenation,
performance-inefficient-algorithm,
performance-implicit-conversion-in-loop,
performance-for-range-copy,
performance-faster-string-find,
performance-enum-size,
performance-avoid-endl,
readability-avoid-const-params-in-decls,
readability-avoid-nested-conditional-operator,
readability-avoid-return-with-void-value,
readability-avoid-unconditional-preprocessor-if,
readability-braces-around-statements,
readability-const-return-type,
readability-container-contains,
readability-container-data-pointdr,
readability-container-size-empty,
readability-delete-null-pointer,
readability-duplicate-include,
readability-else-after-return,
readability-inconsistent-declaration-parameter-name,
readability-isolate-declaration,
readability-make-member-function-const,
readability-misleading-indentation,
readability-misplaced-array-index,
readability-named-parameter,
readability-non-const-parameter,
readability-qualified-auto,
readability-redundant-access-specifiers,
readability-redundant-casting,
readability-redundant-control-flow,
readability-redundant-declaration,
readability-redundant-function-ptr-dereference,
readability-redundant-inline-specifier,
readability-redundant-member-init,
readability-redundant-preprocessor,
readability-redundant-smartptr-get,
readability-redundant-string-cstr,
readability-reference-to-constructed-temporary,
readability-simplify-boolean-expr,
readability-simplify-subscript-expr,
readability-static-accessed-through-instance,
readability-static-definition-in-anonymous-namespace,
readability-string-compare,
readability-suspicious-call-argument,
readability-uniqueptr-delete-release,
readability-use-anyofallof
readability-use-std-min-max,
readability-function-cognitive-complexity
readability-function-size
readability-identifier-naming
readability-identifier-length
readability-magic-numbers
modernize-avoid-bind,
modernize-avoid-c-arrays,
modernize-concat-nested-namespaces,
modernize-deprecated-headers,
modernize-deprecated-ios-base-aliases,
modernize-loop-convert,
modernize-macro-to-enum,
modernize-make-shared,
modernize-make-unique,
modernize-pass-by-value,
modernize-raw-string-literal,
modernize-redundant-void-arg,
modernize-replace-auto-ptr,
modernize-replace-disallow-copy-and-assign-macro,
modernize-replace-random-shuffle,
modernize-return-braced-init-list,
modernize-shrink-to-fit,
modernize-type-traits,
modernize-unary-static-assert,
modernize-use-auto,
modernize-use-bool-literals,
modernize-use-constraints,
modernize-use-default-member-init,
modernize-use-designated-initializers,
modernize-use-emplace,
modernize-use-equals-default,
modernize-use-equals-delete,
modernize-use-nodiscard,
modernize-use-noexcept,
modernize-use-nullptr,
modernize-use-override,
modernize-use-starts-ends-with,
modernize-use-std-numbers,
modernize-use-std-print,
modernize-use-transparent-functors,
modernize-use-uncaught-exceptions,
modernize-use-using
modernize-min-max-use-initializer-list,
cppcoreguidelines-avoid-capturing-lambda-coroutines,
cppcoreguidelines-avoid-const-or-ref-data-members,
cppcoreguidelines-avoid-do-while,
cppcoreguidelines-avoid-goto,
cppcoreguidelines-avoid-non-const-global-variables,
cppcoreguidelines-avoid-reference-coroutine-parameters,
cppcoreguidelines-init-variables,
cppcoreguidelines-interfaces-global-init,
cppcoreguidelines-macro-usage,
cppcoreguidelines-misleading-capture-default-by-value,
cppcoreguidelines-missing-std-forward,
cppcoreguidelines-narrowing-conversions,
cppcoreguidelines-no-malloc,
cppcoreguidelines-no-suspend-with-lock,
cppcoreguidelines-owning-memory,
cppcoreguidelines-prefer-member-initializer,
cppcoreguidelines-pro-bounds-array-to-pointer-decay,
cppcoreguidelines-pro-bounds-pointer-arithmetic,
cppcoreguidelines-pro-type-const-cast,
cppcoreguidelines-pro-type-cstyle-cast,
cppcoreguidelines-pro-type-member-init,
cppcoreguidelines-pro-type-reinterpret-cast,
cppcoreguidelines-pro-type-static-cast-downcast,
cppcoreguidelines-pro-type-vararg,
cppcoreguidelines-rvalue-reference-param-not-moved,
cppcoreguidelines-slicing,
cppcoreguidelines-special-member-functions,
cppcoreguidelines-virtual-class-destructor,
bugprone-argument-comment,
bugprone-assert-side-effect,
bugprone-assignment-in-if-condition,
bugprone-bad-signal-to-kill-thread,
bugprone-bool-pointer-implicit-conversion,
bugprone-branch-clone,
bugprone-casting-through-void,
bugprone-chained-comparison,
bugprone-compare-pointer-to-member-virtual-function,
bugprone-copy-constructor-init,
bugprone-crtp-constructor-accessibility,
bugprone-dangling-handle,
bugprone-empty-catch,
bugprone-exception-escape,
bugprone-fold-init-type,
bugprone-forward-declaration-namespace,
bugprone-forwarding-reference-overload,
bugprone-implicit-widening-of-multiplication-result,
bugprone-inaccurate-erase,
bugprone-inc-dec-in-conditions,
bugprone-incorrect-enable-if,
bugprone-incorrect-roundings,
bugprone-infinite-loop,
bugprone-integer-division,
bugprone-lambda-function-name,
bugprone-macro-parentheses,
bugprone-macro-repeated-side-effects,
bugprone-misplaced-operator-in-strlen-in-alloc,
bugprone-misplaced-pointer-arithmetic-in-alloc,
bugprone-misplaced-widening-cast,
bugprone-move-forwarding-reference,
bugprone-multi-level-implicit-pointer-conversion,
bugprone-multiple-new-in-one-expression,
bugprone-multiple-statement-macro,
bugprone-no-escape,
bugprone-non-zero-enum-to-bool-conversion,
bugprone-not-null-terminated-result,
bugprone-optional-value-conversion,
bugprone-parent-virtual-call,
bugprone-posix-return,
bugprone-redundant-branch-condition,
bugprone-reserved-identifier,
bugprone-return-const-ref-from-parameter,
bugprone-shared-ptr-array-mismatch,
bugprone-signal-handler,
bugprone-signed-char-misuse,
bugprone-sizeof-container,
bugprone-sizeof-expression,
bugprone-spuriously-wake-up-functions,
bugprone-standalone-empty,
bugprone-string-constructor,
bugprone-string-integer-assignment,
bugprone-string-literal-with-embedded-nul,
bugprone-stringview-nullptr,
bugprone-suspicious-enum-usage,
bugprone-suspicious-include,
bugprone-suspicious-memory-comparison,
bugprone-suspicious-memset-usage,
bugprone-suspicious-missing-comma,
bugprone-suspicious-realloc-usage,
bugprone-suspicious-semicolon,
bugprone-suspicious-string-compare,
bugprone-suspicious-stringview-data-usage,
bugprone-swapped-arguments,
bugprone-switch-missing-default-case,
bugprone-terminating-continue,
bugprone-throw-keyword-missing,
bugprone-too-small-loop-variable,
bugprone-unchecked-optional-access,
bugprone-undefined-memory-manipulation,
bugprone-undelegated-constructor,
bugprone-unhandled-exception-at-new,
bugprone-unhandled-self-assignment,
bugprone-unique-ptr-array-mismatch,
bugprone-unsafe-functions,
bugprone-unused-local-non-trivial-variable,
bugprone-unused-raii,
bugprone-unused-return-value,
bugprone-use-after-move,
bugprone-virtual-near-miss,
concurrency-mt-unsafe,
concurrency-thread-canceltype-asynchronous,
misc-use-anonymous-namespace,
misc-unused-using-decls,
misc-unused-parameters,
misc-unused-alias-decls,
misc-uniqueptr-reset-release,
misc-unconventional-assign-operator,
misc-throw-by-value-catch-by-reference,
misc-static-assert,
misc-redundant-expression,
misc-non-private-member-variables-in-classes,
misc-non-copyable-objects,
misc-no-recursion,
misc-new-delete-overloads,
misc-misplaced-const,
misc-misleading-identifier,
misc-misleading-bidirectional,
misc-header-include-cycle,
misc-definitions-in-headers,
misc-coroutine-hostile-raii,
misc-const-correctness,
-hicpp-signed-bitwise,
hicpp-no-assembler,
hicpp-multiway-paths-covered,
hicpp-ignored-remove-result,
hicpp-exception-baseclass,
"

View file

@ -27,10 +27,7 @@ target_link_libraries(
renderer
PUBLIC camera
PUBLIC input
PUBLIC glad
PUBLIC logger
PUBLIC opengl::opengl
PUBLIC glfw
PUBLIC imgui
PUBLIC asset_parser
PUBLIC yaml-cpp::yaml-cpp

View file

@ -0,0 +1,14 @@
#include <ranges>
#include <renderer/system.hpp>
#include <test/test.hpp>
using namespace lt;
#include <renderer/backend.hpp>
using lt::test::Case;
using lt::test::Suite;
Suite raii = [] {
Case { "happy path won't throw" } = [] {
};
};

View file

@ -7,15 +7,9 @@
#include <renderer/renderer.hpp> // required for forward declaratio>
#include <ui/ui.hpp> // required for forward declaratio>
#define GLFW_EXPOSE_NATIVE_WIN32
#include <glfw/glfw3.h>
#include <glfw/glfw3native.h>
namespace lt {
dxGraphicsContext::dxGraphicsContext(GLFWwindow *windowHandle)
: m_window_handle(windowHandle)
, m_debug_interface(nullptr)
dxGraphicsContext::dxGraphicsContext(): m_window_handle(windowHandle), m_debug_interface(nullptr)
{
// set 'GraphicsAPI';
m_graphics_api = GraphicsAPI::DirectX;
@ -28,7 +22,7 @@ dxGraphicsContext::dxGraphicsContext(GLFWwindow *windowHandle)
setup_debug_interface();
}
void dxGraphicsContext::setup_device_and_swap_chain(GLFWwindow *windowHandle)
void dxGraphicsContext::setup_device_and_swap_chain()
{
auto context = std::static_pointer_cast<dxSharedContext>(m_shared_context);
@ -52,8 +46,7 @@ void dxGraphicsContext::setup_device_and_swap_chain(GLFWwindow *windowHandle)
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.BufferCount = 1u;
// #todo: don't handle Windows's window with glfw, create it yourself
sd.OutputWindow = static_cast<HWND>(glfwGetWin32Window(windowHandle));
sd.OutputWindow = {}; // ...
sd.Windowed = true;
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

View file

@ -4,23 +4,19 @@
#include <renderer/graphics_context.hpp>
#include <wrl.h>
struct GLFWwindow;
namespace lt {
class dxGraphicsContext: public GraphicsContext
{
public:
dxGraphicsContext(GLFWwindow *windowHandle);
dxGraphicsContext();
virtual void log_debug_data() override;
private:
GLFWwindow *m_window_handle;
Microsoft::WRL::ComPtr<ID3D11Debug> m_debug_interface;
void setup_device_and_swap_chain(GLFWwindow *windowHandle);
void setup_device_and_swap_chain();
void setup_render_targets();

View file

@ -1,66 +0,0 @@
#include <input/key_codes.hpp>
#include <renderer/dx/shared_context.hpp>
#include <renderer/dx/user_interface.hpp>
#define GLFW_EXPOSE_NATIVE_WIN32
#include <backends/imgui_impl_dx11.h>
#include <backends/imgui_impl_win32.h>
#include <glfw/glfw3.h>
#include <glfw/glfw3native.h>
#include <imgui.h>
namespace lt {
void dxUserInterface::platform_implementation(
GLFWwindow *windowHandle,
Ref<SharedContext> sharedContext
)
{
auto &io = ImGui::GetIO();
auto context = std::dynamic_pointer_cast<dxSharedContext>(sharedContext);
ImGui_ImplWin32_Init(glfwGetWin32Window(windowHandle));
ImGui_ImplDX11_Init(context->get_device().Get(), context->get_device_context().Get());
}
dxUserInterface::~dxUserInterface()
{
// #todo: handle this in a better way
auto &io = ImGui::GetIO();
if (io.IniFilename == "default_gui_layout.ini")
io.IniFilename = "user_gui_layout.ini";
ImGui_ImplDX11_Shutdown();
ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext();
}
void dxUserInterface::begin()
{
ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
}
void dxUserInterface::end()
{
ImGui::Render();
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
}
void dxUserInterface::log_debug_data()
{
// #todo: improve
log_inf("________________________________________");
log_inf("UserInterface::");
log_inf(" API : ImGui");
log_inf(" Version: {}", ImGui::GetVersion());
log_inf(" GraphicsAPI : DirectX");
log_inf("________________________________________");
}
} // namespace lt

View file

@ -4,8 +4,6 @@
#include <ui/ui.hpp>
#include <wrl.h>
struct GLFWwindow;
namespace lt {
class dxSharedContext;
@ -17,10 +15,7 @@ public:
~dxUserInterface();
void platform_implementation(
GLFWwindow *windowHandle,
Ref<SharedContext> sharedContext
) override;
void platform_implementation(Ref<SharedContext> sharedContext) override;
void begin() override;

View file

@ -1,4 +1,3 @@
#include <glad/gl.h>
#include <renderer/gl/blender.hpp>
namespace lt {

View file

@ -1,5 +1,4 @@
#include <cstddef>
#include <glad/gl.h>
#include <logger/logger.hpp>
#include <renderer/gl/buffers.hpp>

View file

@ -1,4 +1,3 @@
#include <glad/gl.h>
#include <renderer/gl/framebuffers.hpp>
namespace lt {

View file

@ -1,4 +1,3 @@
#include <glad/gl.h>
#include <input/events/window.hpp>
#include <renderer/blender.hpp> // required for forward declaratio>
#include <renderer/buffers.hpp> // required for forward declaratio>
@ -6,18 +5,11 @@
#include <renderer/render_command.hpp> // required for forward declaratio>
#include <renderer/renderer.hpp> // required for forward declaratio>
#ifndef STOP_FUCKING_ORDERING_THESE_THE_WRONG_WAY_CLANG_FORMAT____
#include <GLFW/glfw3.h>
#endif
namespace lt {
glGraphicsContext::glGraphicsContext(GLFWwindow *windowHandle): m_window_handle(windowHandle)
glGraphicsContext::glGraphicsContext()
{
m_graphics_api = GraphicsAPI::OpenGL;
glfwMakeContextCurrent(windowHandle);
ensure(gladLoadGL(glfwGetProcAddress), "Failed to initialize opengl (glad)");
set_debug_message_callback();
}

View file

@ -3,20 +3,16 @@
#include <renderer/graphics_context.hpp>
struct GLFWwindow;
namespace lt {
class glGraphicsContext: public GraphicsContext
{
public:
glGraphicsContext(GLFWwindow *windowHandle);
glGraphicsContext();
void log_debug_data() override;
private:
GLFWwindow *m_window_handle;
void set_debug_message_callback();
};

View file

@ -1,18 +1,13 @@
#include <glad/gl.h>
#include <renderer/gl/render_command.hpp>
#ifndef DONT_FUCKING_ORDER_THESSE_PLEASE_FOR_THE_LOVE_OF_GOD_CLANG_FORMAT
#include <GLFW/glfw3.h>
#endif
namespace lt {
glRenderCommand::glRenderCommand(GLFWwindow *windowHandle): m_window_handle(windowHandle)
glRenderCommand::glRenderCommand(): m_window_handle(windowHandle)
{
}
void glRenderCommand::swap_buffers()
{
glfwSwapBuffers(m_window_handle);
}
void glRenderCommand::clear_back_buffer(const math::vec4 &clearColor)

View file

@ -3,14 +3,12 @@
#include <math/vec4.hpp>
#include <renderer/render_command.hpp>
struct GLFWwindow;
namespace lt {
class glRenderCommand: public RenderCommand
{
public:
glRenderCommand(GLFWwindow *windowHandle);
glRenderCommand();
void swap_buffers() override;
@ -28,9 +26,6 @@ public:
unsigned int width,
unsigned int height
) override;
private:
GLFWwindow *m_window_handle;
};
} // namespace lt

View file

@ -1,6 +1,4 @@
#include <asset_parser/assets/text.hpp>
#include <glad/gl.h>
#include <renderer/gl/shader.hpp>
namespace lt {

View file

@ -1,5 +1,4 @@
#include <asset_parser/assets/texture.hpp>
#include <glad/gl.h>
#include <lt_debug/assertions.hpp>
#include <renderer/gl/texture.hpp>

View file

@ -3,8 +3,6 @@
#include <ui/ui.hpp>
struct GLFWwindow;
namespace lt {
class glUserInterface: public UserInterface
@ -14,19 +12,13 @@ public:
~glUserInterface() override;
void platform_implementation(
GLFWwindow *windowHandle,
Ref<SharedContext> sharedContext
) override;
void platform_implementation(Ref<SharedContext> sharedContext) override;
void begin() override;
void end() override;
void log_debug_data() override;
private:
GLFWwindow *m_window_handle {};
};
} // namespace lt

View file

@ -1,4 +1,3 @@
#include <glad/gl.h>
#include <lt_debug/assertions.hpp>
#include <renderer/gl/buffers.hpp>
#include <renderer/gl/vertex_layout.hpp>

View file

@ -12,7 +12,7 @@ GraphicsContext *GraphicsContext::s_context = nullptr;
GraphicsContext::~GraphicsContext() = default;
auto GraphicsContext::create(GraphicsAPI api, GLFWwindow *window_handle) -> Scope<GraphicsContext>
auto GraphicsContext::create(GraphicsAPI api) -> Scope<GraphicsContext>
{
delete s_context;

View file

@ -11,12 +11,11 @@
namespace lt {
auto RenderCommand::create(GLFWwindow *windowHandle, const Ref<SharedContext> & /*sharedContext*/)
-> Scope<RenderCommand>
auto RenderCommand::create(const Ref<SharedContext> & /*sharedContext*/) -> Scope<RenderCommand>
{
switch (GraphicsContext::get_graphics_api())
{
case GraphicsAPI::OpenGL: return create_scope<glRenderCommand>(windowHandle);
case GraphicsAPI::OpenGL: return create_scope<glRenderCommand>();
case GraphicsAPI::DirectX:
lt_win(

View file

@ -16,11 +16,7 @@ namespace lt {
Renderer *Renderer::s_context = nullptr;
Renderer::Renderer(
GLFWwindow *window_handle,
const Ref<SharedContext> &shared_context,
CreateInfo create_info
)
Renderer::Renderer(const Ref<SharedContext> &shared_context, CreateInfo create_info)
: m_quad_renderer(
create_scope<QuadRendererProgram>(
LT_MAX_QUAD_RENDERER_VERTICES,
@ -66,15 +62,9 @@ Renderer::~Renderer() // NOLINT
{
}
auto Renderer::create(
GLFWwindow *windowHandle,
Ref<SharedContext> sharedContext,
CreateInfo create_info
) -> Scope<Renderer>
auto Renderer::create(Ref<SharedContext> sharedContext, CreateInfo create_info) -> Scope<Renderer>
{
return make_scope<Renderer>(
new Renderer(windowHandle, std::move(sharedContext), std::move(create_info))
);
return make_scope<Renderer>(new Renderer(std::move(sharedContext), std::move(create_info)));
}
void Renderer::on_window_resize(const WindowResizedEvent &event)

View file

@ -6,7 +6,6 @@ namespace lt::renderer {
System::System(InitRequirements requirements): m_registry(std::move(requirements.registry))
{
ensure(m_registry, "null registry");
ensure(requirements.glfw_window_handle, "null glfw handle");
}
System::~System() = default;

View file

@ -13,11 +13,8 @@ Suite raii = [] {
using lt::test::expect_throw;
using renderer::System;
auto *window = static_cast<GLFWwindow *>(lt::Window::create([](auto &&PH1) {})->get_handle());
Case { "happy" } = [=] {
std::ignore = System { {
.glfw_window_handle = window,
.registry = create_ref<ecs::Registry>(),
} };
};
@ -25,14 +22,12 @@ Suite raii = [] {
Case { "unhappy" } = [=] {
expect_throw([=] {
std::ignore = System { {
.glfw_window_handle = window,
.registry = {},
} };
});
expect_throw([=] {
std::ignore = System { {
.glfw_window_handle = {},
.registry = create_ref<ecs::Registry>(),
} };
});
@ -42,7 +37,6 @@ Suite raii = [] {
for (auto idx : std::views::iota(0, 100'001))
{
std::ignore = System { {
.glfw_window_handle = window,
.registry = create_ref<ecs::Registry>(),
} };
}

View file

@ -1,7 +1,5 @@
#pragma once
struct GLFWwindow;
namespace lt {
class SharedContext;
@ -19,12 +17,7 @@ enum class GraphicsAPI
class GraphicsContext
{
public:
static auto create(
GraphicsAPI api,
GLFWwindow *window_handle
) -> Scope<GraphicsContext>;
static auto create(GraphicsAPI api) -> Scope<GraphicsContext>;
GraphicsContext(const GraphicsContext &) = delete;
GraphicsContext &operator=(const GraphicsContext &) = delete;

View file

@ -2,8 +2,6 @@
#include <math/vec4.hpp>
struct GLFWwindow;
namespace lt {
class SharedContext;
@ -11,8 +9,7 @@ class SharedContext;
class RenderCommand
{
public:
static auto create(GLFWwindow *windowHandle, const Ref<SharedContext> &sharedContext)
-> Scope<RenderCommand>;
static auto create(const Ref<SharedContext> &sharedContext) -> Scope<RenderCommand>;
RenderCommand(const RenderCommand &) = delete;

View file

@ -13,8 +13,6 @@
#define LT_MAX_TEXTURE_RENDERER_VERTICES (1028u * 4u)
#define LT_MAX_TINTED_TEXTURE_RENDERER_VERTICES (1028u * 4u)
struct GLFWwindow;
namespace lt {
class ConstantBuffer;
@ -42,11 +40,7 @@ public:
Ref<Shader> tinted_texture_renderer_shader;
};
static auto create(
GLFWwindow *windowHandle,
Ref<SharedContext> sharedContext,
CreateInfo create_info
) -> Scope<Renderer>;
static auto create(Ref<SharedContext> sharedContext, CreateInfo create_info) -> Scope<Renderer>;
static void draw_quad(
const math::vec3 &position,
@ -134,11 +128,7 @@ private:
bool m_should_clear_backbuffer { false };
Renderer(
GLFWwindow *window_handle,
const Ref<SharedContext> &shared_context,
CreateInfo create_info
);
Renderer(const Ref<SharedContext> &shared_context, CreateInfo create_info);
void draw_quad_impl(
const math::vec3 &position,

View file

@ -3,8 +3,6 @@
#include <base/base.hpp>
#include <ecs/scene.hpp>
struct GLFWwindow;
namespace lt::renderer {
/** The system for putting gore on your display
@ -28,8 +26,6 @@ public:
/** The requirements for this system to initialize. */
struct InitRequirements
{
GLFWwindow *glfw_window_handle;
Ref<ecs::Registry> registry;
};

View file

@ -3,7 +3,6 @@
namespace Assets {
class TextureAsset;
}
namespace lt {