diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index c80b674..e3af6fd 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -24,8 +24,11 @@ target_link_libraries(${PROJECT_EXECUTABLE_NAME} PRIVATE spdlog::spdlog imgui::imgui open_engine + dl + nethost ) target_link_directories(${PROJECT_EXECUTABLE_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/lib + /usr/share/dotnet/packs/Microsoft.NETCore.App.Host.arch-x64/10.0.0/runtimes/arch-x64/native ) diff --git a/application/include/modding.hpp b/application/include/modding.hpp index 7385a70..faf35c4 100644 --- a/application/include/modding.hpp +++ b/application/include/modding.hpp @@ -3,10 +3,13 @@ #include #include +#include #include "/usr/share/dotnet/packs/Microsoft.NETCore.App.Host.arch-x64/10.0.0/runtimes/arch-x64/native/nethost.h" #include "/usr/share/dotnet/packs/Microsoft.NETCore.App.Host.arch-x64/10.0.0/runtimes/arch-x64/native/hostfxr.h" #include "/usr/share/dotnet/packs/Microsoft.NETCore.App.Host.arch-x64/10.0.0/runtimes/arch-x64/native/coreclr_delegates.h" +#include "open_engine/core/time.hpp" +#include "open_engine/logging.hpp" class Modding : public OpenEngine::Layer { @@ -74,6 +77,7 @@ class Modding : public OpenEngine::Layer void OnAttach() override { load_hostfxr(); + auto load_assembly_and_get_function_pointer = get_dotnet_load_assembly("assets/scripts/mod_loader.runtimeconfig.json"); component_entry_point_fn init = nullptr; int rc = load_assembly_and_get_function_pointer( @@ -85,6 +89,14 @@ class Modding : public OpenEngine::Layer (void**)&init); init(nullptr, 1); + + rc = load_assembly_and_get_function_pointer( + dotnet_lib_path, + dotnet_type, + "Hello", + UNMANAGEDCALLERSONLY_METHOD /*delegate_type_name*/, + nullptr, + (void**)&hello); } void OnDetach() override @@ -93,6 +105,14 @@ class Modding : public OpenEngine::Layer void OnUpdate() override { + static float time = 0; + + time += OpenEngine::Time::Get().DeltaTime(); + + if (time >= 1) { + hello(nullptr, 1); + time = 0; + } } void OnEvent(OpenEngine::Event& event) override @@ -111,6 +131,8 @@ class Modding : public OpenEngine::Layer hostfxr_get_runtime_delegate_fn get_delegate_fptr; hostfxr_close_fn close_fptr; + component_entry_point_fn hello = nullptr; + const char_t* dotnet_lib_path = "assets/scripts/mod_loader.dll"; const char_t* dotnet_type = "OpenEngine.ModLoader, mod_loader"; const char_t* dotnet_type_method = "Init"; diff --git a/application/include/sandbox.hpp b/application/include/sandbox.hpp index d257f58..24dc89b 100755 --- a/application/include/sandbox.hpp +++ b/application/include/sandbox.hpp @@ -47,8 +47,15 @@ class SandboxLayer : public OpenEngine::Layer return square_vertex_array; } + void OnDetach() override + { + OE_DEBUG("OnDetach {}", __PRETTY_FUNCTION__); + } + SandboxLayer() - : Layer("Sandbox") + : Layer("sandbox"), + camera((float)OpenEngine::Application::Get().GetWindow().GetWidth() / + OpenEngine::Application::Get().GetWindow().GetHeight(), 1.0f) { //vertex_array.reset(OpenEngine::VertexArray::Create()); square = CreateSquare(); @@ -82,11 +89,11 @@ class SandboxLayer : public OpenEngine::Layer texture = OpenEngine::Texture2D::Create("./assets/textures/container.jpg"); face = OpenEngine::Texture2D::Create("./assets/textures/awesomeface.png"); - std::dynamic_pointer_cast(texture_shader)->Bind(); - std::dynamic_pointer_cast(texture_shader)->SetInt("u_Texture", 0); + texture_shader->Bind(); + texture_shader->SetInt("u_Texture", 0); for (auto joystick : OpenEngine::Input::GetJoystickList()) - OE_TRACE("Joystick {}: {}", joystick.first, joystick.second); + OE_DEBUG("Joystick {}: {}", joystick.first, joystick.second); bindings = { {"fwd/bckwd", 1}, @@ -155,9 +162,9 @@ class SandboxLayer : public OpenEngine::Layer auto texture_shader = shader_library.Get("texture"); texture_shader->Bind(); - texture->Bind(); + //texture->Bind(); glm::mat4 square_transform = glm::translate(glm::mat4(1.0f), square_pos) * scale; - OpenEngine::Renderer::Submit(texture_shader, square, square_transform); + //OpenEngine::Renderer::Submit(texture_shader, square, square_transform); moveSquare(square_pos); moveSquareF(square_pos); @@ -174,21 +181,10 @@ class SandboxLayer : public OpenEngine::Layer void OnEvent(OpenEngine::Event& event) override { OpenEngine::EventDispatcher dispatcher(event); - dispatcher.Dispatch(BIND_EVENT_FN(SandboxLayer::QuitRunning)); camera.OnEvent(event); } - bool QuitRunning(OpenEngine::KeyPressedEvent& event) - { - if (event.GetKeyCode() == OE_KEY_ESCAPE) { - OpenEngine::Application::Get().StopRunning(); - return true; - } - - return false; - } - void OnImGuiRender() override { static std::vector axis_labels; diff --git a/application/src/control_layer.cpp b/application/src/control_layer.cpp index acbf22b..e7a328c 100644 --- a/application/src/control_layer.cpp +++ b/application/src/control_layer.cpp @@ -21,8 +21,8 @@ bool ControlLayer::SwitchLayer(OpenEngine::KeyPressedEvent& event) OE_DEBUG("Sandbox2D Layer"); layer = OpenEngine::CreateRef(); - app.PushLayer(layer); - app.PopLayer(active_layer); + app.QueueLayerPush(layer); + app.QueueLayerPop(active_layer); active_layer = layer; return true; @@ -30,8 +30,8 @@ bool ControlLayer::SwitchLayer(OpenEngine::KeyPressedEvent& event) OE_DEBUG("Sandbox Layer"); layer = OpenEngine::CreateRef(); - app.PushLayer(layer); - app.PopLayer(active_layer); + app.QueueLayerPush(layer); + app.QueueLayerPop(active_layer); active_layer = layer; return true; diff --git a/application/src/sandbox.cpp b/application/src/sandbox.cpp index 6f26339..55ae25f 100644 --- a/application/src/sandbox.cpp +++ b/application/src/sandbox.cpp @@ -1,8 +1,20 @@ +#include +#include #include +#include +#include + +#include Sandbox::Sandbox() { - PushLayer(new SandboxLayer()); + OpenEngine::Ref initial_layer = std::make_shared(); + OpenEngine::Ref control_layer = std::make_shared(initial_layer); + OpenEngine::Ref modding_layer = std::make_shared(); + + QueueLayerPush(modding_layer); + QueueLayerPush(control_layer); + QueueLayerPush(initial_layer); } Sandbox::~Sandbox() diff --git a/open_engine/include/open_engine.hpp b/open_engine/include/open_engine.hpp index 678fe70..a4b03e3 100644 --- a/open_engine/include/open_engine.hpp +++ b/open_engine/include/open_engine.hpp @@ -12,12 +12,8 @@ #include "open_engine/input/keycodes.hpp" #include "open_engine/renderer/buffer.hpp" #include "open_engine/renderer/shader.hpp" -#include "open_engine/opengl/opengl_shader.hpp" #include "open_engine/renderer/texture.hpp" #include "open_engine/orthographic_camera_controller.hpp" - -// Entry Point ------------------------- -#include "open_engine/entry_point.hpp" -// ------------------------------------- +#include "open_engine/renderer/renderer2d.hpp" #endif // OPEN_ENGINE_HPP diff --git a/open_engine/include/open_engine/application.hpp b/open_engine/include/open_engine/application.hpp index 38baefb..64d4030 100644 --- a/open_engine/include/open_engine/application.hpp +++ b/open_engine/include/open_engine/application.hpp @@ -15,14 +15,21 @@ namespace OpenEngine { { public: Application(); - virtual ~Application() = default; + ~Application(); void Run(); virtual void OnEvent(Event& event); - void PushLayer(Layer* layer); - void PushOverlay(Layer* overlay); + //void PushOverlay(Ref overlay); + //void PopOverlay(Ref overlay); + + //void PushLayer(Ref layer); + //void PopLayer(); + void QueueLayerPush(Ref layer); + void QueueLayerPop(Ref layer); + void QueueOverlayPush(Ref layer); + void QueueOverlayPop(Ref layer); inline static Application& Get() { return *instance; } @@ -38,7 +45,7 @@ namespace OpenEngine { bool running = true; std::unique_ptr window; - ImGuiLayer* imgui_layer; + Ref imgui_layer; LayerStack layer_stack; }; diff --git a/open_engine/include/open_engine/core.hpp b/open_engine/include/open_engine/core.hpp index 65caf9b..8f1a83c 100644 --- a/open_engine/include/open_engine/core.hpp +++ b/open_engine/include/open_engine/core.hpp @@ -28,9 +28,19 @@ namespace OpenEngine { template using Scope = std::unique_ptr; + template + constexpr Scope CreateScope(Args&& ... args) + { + return std::make_unique(std::forward(args)...); + } template using Ref = std::shared_ptr; + template + constexpr Ref CreateRef(Args&& ... args) + { + return std::make_shared(std::forward(args)...); + } } #endif // CORE_HPP diff --git a/open_engine/include/open_engine/entry_point.hpp b/open_engine/include/open_engine/entry_point.hpp index 2cb90b5..f8bbb9d 100644 --- a/open_engine/include/open_engine/entry_point.hpp +++ b/open_engine/include/open_engine/entry_point.hpp @@ -11,6 +11,7 @@ int main(int argc, char** argv) auto app = OpenEngine::CreateApplication(); app->Run(); + delete app; } diff --git a/open_engine/include/open_engine/imgui/imgui_layer.hpp b/open_engine/include/open_engine/imgui/imgui_layer.hpp index 9fea08b..33b29c9 100644 --- a/open_engine/include/open_engine/imgui/imgui_layer.hpp +++ b/open_engine/include/open_engine/imgui/imgui_layer.hpp @@ -9,7 +9,7 @@ namespace OpenEngine { { public: ImGuiLayer(); - ~ImGuiLayer() = default; + ~ImGuiLayer(); virtual void OnAttach() override; virtual void OnDetach() override; diff --git a/open_engine/include/open_engine/input/input_system.hpp b/open_engine/include/open_engine/input/input_system.hpp index 6abcad2..68bdbae 100644 --- a/open_engine/include/open_engine/input/input_system.hpp +++ b/open_engine/include/open_engine/input/input_system.hpp @@ -54,7 +54,7 @@ namespace OpenEngine { private: inline static const std::string GetJoystickName(unsigned int joystick) { return instance->GetJoystickNameImpl(joystick); }; - static Input* instance; + static Scope instance; }; } diff --git a/open_engine/include/open_engine/input/linux_input.hpp b/open_engine/include/open_engine/input/linux_input.hpp index a3ab377..2cf1100 100644 --- a/open_engine/include/open_engine/input/linux_input.hpp +++ b/open_engine/include/open_engine/input/linux_input.hpp @@ -25,8 +25,6 @@ namespace OpenEngine { virtual unsigned int GetJoystickAxesCountImpl(unsigned int joystick) override; virtual bool IsJoystickButtonPressedImpl(unsigned int joystick, unsigned int button) override; - - private: }; } diff --git a/open_engine/include/open_engine/layer.hpp b/open_engine/include/open_engine/layer.hpp index 8e9a237..b1ba227 100644 --- a/open_engine/include/open_engine/layer.hpp +++ b/open_engine/include/open_engine/layer.hpp @@ -3,6 +3,7 @@ #include "events/event.hpp" #include "core.hpp" +#include "open_engine/logging.hpp" namespace OpenEngine { class OE_API Layer diff --git a/open_engine/include/open_engine/layer_stack.hpp b/open_engine/include/open_engine/layer_stack.hpp index 91ea181..9a883b6 100644 --- a/open_engine/include/open_engine/layer_stack.hpp +++ b/open_engine/include/open_engine/layer_stack.hpp @@ -13,15 +13,23 @@ namespace OpenEngine { LayerStack(); ~LayerStack(); - void PushLayer(Layer* layer); - void PopLayer(Layer* layer); - void PushOverlay(Layer* overlay); - void PopOverlay(Layer* overlay); + void QueueLayerPush(Ref layer); + void QueueLayerPop(Ref layer); + void QueueOverlayPush(Ref layer); + void QueueOverlayPop(Ref layer); + void UpdateLayers(); + + std::vector>::iterator begin() { return layers.begin(); } + std::vector>::iterator end() { return layers.end(); } - std::vector::iterator begin() { return layers.begin(); } - std::vector::iterator end() { return layers.end(); } private: - std::vector layers; + std::vector> layers; + std::vector> layers_to_pop; + std::vector> layers_to_push; + + std::vector> overlay_to_pop; + std::vector> overlay_to_push; + unsigned int layer_insert_index = 0; }; } diff --git a/open_engine/include/open_engine/opengl/opengl_shader.hpp b/open_engine/include/open_engine/opengl/opengl_shader.hpp index 0090af3..1f936d4 100755 --- a/open_engine/include/open_engine/opengl/opengl_shader.hpp +++ b/open_engine/include/open_engine/opengl/opengl_shader.hpp @@ -22,12 +22,19 @@ namespace OpenEngine { virtual void Unbind() const override; // utility uniform functions - virtual void SetBool(const std::string &name, bool value) const; - virtual void SetInt(const std::string &name, int value) const; - virtual void SetFloat(const std::string &name, float value) const; - virtual void SetMat4(const std::string &name, const glm::mat4& value) const; - virtual void SetVec3(const std::string &name, const glm::vec3& value) const; + void UploadBool(const std::string &name, bool value) const; + void UploadInt(const std::string &name, int value) const; + void UploadFloat(const std::string &name, float value) const; + void UploadMat4(const std::string &name, const glm::mat4& value) const; + void UploadVec3(const std::string &name, const glm::vec3& value) const; + void UploadVec4(const std::string &name, const glm::vec4& value) const; + virtual void SetBool(const std::string &name, bool value) const override; + virtual void SetInt(const std::string &name, int value) const override; + virtual void SetFloat(const std::string &name, float value) const override; + virtual void SetMat4(const std::string &name, const glm::mat4& value) const override; + virtual void SetVec3(const std::string &name, const glm::vec3& value) const override; + virtual void SetVec4(const std::string &name, const glm::vec4& value) const override; private: std::string ReadFile(const std::string& shader_path); diff --git a/open_engine/include/open_engine/renderer/graphics_context.hpp b/open_engine/include/open_engine/renderer/graphics_context.hpp index 6d0a9ab..c284266 100644 --- a/open_engine/include/open_engine/renderer/graphics_context.hpp +++ b/open_engine/include/open_engine/renderer/graphics_context.hpp @@ -5,6 +5,8 @@ namespace OpenEngine { class GraphicsContext { public: + // TODO: Check this! + virtual ~GraphicsContext() = default; virtual void Init() = 0; virtual void SwapBuffers() = 0; }; diff --git a/open_engine/include/open_engine/renderer/render_command.hpp b/open_engine/include/open_engine/renderer/render_command.hpp index 577df2c..1fa6a38 100644 --- a/open_engine/include/open_engine/renderer/render_command.hpp +++ b/open_engine/include/open_engine/renderer/render_command.hpp @@ -3,6 +3,7 @@ #include "../renderer/renderer_api.hpp" #include "../opengl/opengl_renderer_api.hpp" +#include "open_engine/core.hpp" #include namespace OpenEngine { @@ -35,7 +36,7 @@ namespace OpenEngine { } private: - static inline RendererAPI* api = new OpenGLRendererAPI(); + static inline Scope api = CreateScope(); }; } diff --git a/open_engine/include/open_engine/renderer/renderer.hpp b/open_engine/include/open_engine/renderer/renderer.hpp index 992d5d7..3673b51 100644 --- a/open_engine/include/open_engine/renderer/renderer.hpp +++ b/open_engine/include/open_engine/renderer/renderer.hpp @@ -1,9 +1,10 @@ #ifndef RENDERER_HPP #define RENDERER_HPP -#include "../renderer/renderer_api.hpp" -#include "../renderer/vertex_array.hpp" -#include "../orthographic_camera.hpp" +#include "open_engine/renderer/renderer_api.hpp" +#include "open_engine/renderer/vertex_array.hpp" +#include "open_engine/orthographic_camera.hpp" +#include "open_engine/core.hpp" #include #include @@ -32,7 +33,7 @@ namespace OpenEngine { glm::mat4 view_projection_matrix; }; - inline static SceneData* scene_data = new SceneData; + inline static Scope scene_data = CreateScope(); }; } diff --git a/open_engine/include/open_engine/renderer/renderer_api.hpp b/open_engine/include/open_engine/renderer/renderer_api.hpp index 56be066..6b96541 100644 --- a/open_engine/include/open_engine/renderer/renderer_api.hpp +++ b/open_engine/include/open_engine/renderer/renderer_api.hpp @@ -16,6 +16,7 @@ namespace OpenEngine { }; virtual void Init() = 0; + virtual ~RendererAPI() = default; virtual void SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) = 0; diff --git a/open_engine/include/open_engine/renderer/shader.hpp b/open_engine/include/open_engine/renderer/shader.hpp index bcae923..b5ff056 100644 --- a/open_engine/include/open_engine/renderer/shader.hpp +++ b/open_engine/include/open_engine/renderer/shader.hpp @@ -19,6 +19,13 @@ namespace OpenEngine { virtual void Bind() const = 0; virtual void Unbind() const = 0; + + virtual void SetBool(const std::string &name, bool value) const = 0; + virtual void SetInt(const std::string &name, int value) const = 0; + virtual void SetFloat(const std::string &name, float value) const = 0; + virtual void SetMat4(const std::string &name, const glm::mat4& value) const = 0; + virtual void SetVec3(const std::string &name, const glm::vec3& value) const = 0; + virtual void SetVec4(const std::string &name, const glm::vec4& value) const = 0; }; class ShaderLibrary diff --git a/open_engine/include/open_engine/renderer/vertex_array.hpp b/open_engine/include/open_engine/renderer/vertex_array.hpp index 111cf96..90fa80e 100644 --- a/open_engine/include/open_engine/renderer/vertex_array.hpp +++ b/open_engine/include/open_engine/renderer/vertex_array.hpp @@ -1,7 +1,8 @@ #ifndef VERTEX_ARRAY_HPP #define VERTEX_ARRAY_HPP -#include "../renderer/buffer.hpp" +#include "open_engine/core.hpp" +#include "open_engine/renderer/buffer.hpp" #include @@ -20,7 +21,7 @@ namespace OpenEngine { virtual const std::vector>& GetVertexBuffers() const = 0; virtual const std::shared_ptr& GetIndexBuffer() const = 0; - static VertexArray* Create(); + static Ref Create(); }; } diff --git a/open_engine/include/open_engine/window/linux_window.hpp b/open_engine/include/open_engine/window/linux_window.hpp index 9bcb1f0..8d03c80 100644 --- a/open_engine/include/open_engine/window/linux_window.hpp +++ b/open_engine/include/open_engine/window/linux_window.hpp @@ -35,7 +35,7 @@ namespace OpenEngine { WindowData data; GLFWwindow* gl_window; - GraphicsContext* context; + Scope context; }; } diff --git a/open_engine/include/open_engine/window/window.hpp b/open_engine/include/open_engine/window/window.hpp index 910833b..dffdaf9 100644 --- a/open_engine/include/open_engine/window/window.hpp +++ b/open_engine/include/open_engine/window/window.hpp @@ -49,7 +49,7 @@ namespace OpenEngine { virtual void* GetNativeWindow() const = 0; - static Window* Create(const WindowProps& props = WindowProps()); + static std::unique_ptr Create(const WindowProps& props = WindowProps()); }; } diff --git a/open_engine/src/open_engine/application.cpp b/open_engine/src/open_engine/application.cpp index 46c0a6b..bf84583 100755 --- a/open_engine/src/open_engine/application.cpp +++ b/open_engine/src/open_engine/application.cpp @@ -1,42 +1,51 @@ #include -#include -#include -#include -#include -#include #include -#include +#include +#include +#include +#include +#include +#include +#include + +#include #include namespace OpenEngine { - Application::Application() { OE_CORE_ASSERT(!instance, "Application already exists!"); instance = this; - window = std::unique_ptr(Window::Create()); + window = Window::Create(); window->SetEventCallback(BIND_EVENT_FN(Application::OnEvent)); Renderer::Init(); + Renderer2D::Init(); - imgui_layer = new ImGuiLayer(); - PushOverlay(imgui_layer); + imgui_layer = std::make_shared(); + QueueOverlayPush(imgui_layer); + } + + Application::~Application() + { + Renderer2D::Shutdown(); } void Application::Run() { while(running) { Time::Get().Update(); + layer_stack.UpdateLayers(); - for (Layer* layer : layer_stack) + for (auto layer : layer_stack) layer->OnUpdate(); imgui_layer->Begin(); - for (Layer* layer : layer_stack) + for (auto layer : layer_stack) layer->OnImGuiRender(); imgui_layer->End(); @@ -72,13 +81,23 @@ namespace OpenEngine { return false; } - void Application::PushLayer(Layer* layer) + void Application::QueueLayerPush(Ref layer) { - layer_stack.PushLayer(layer); + layer_stack.QueueLayerPush(layer); } - void Application::PushOverlay(Layer* overlay) + void Application::QueueLayerPop(Ref layer) { - layer_stack.PushOverlay(overlay); + layer_stack.QueueLayerPop(layer); + } + + void Application::QueueOverlayPush(Ref overlay) + { + layer_stack.QueueOverlayPush(overlay); + } + + void Application::QueueOverlayPop(Ref overlay) + { + layer_stack.QueueOverlayPop(overlay); } } diff --git a/open_engine/src/open_engine/imgui/imgui_layer.cpp b/open_engine/src/open_engine/imgui/imgui_layer.cpp index 08d4878..788ab1b 100644 --- a/open_engine/src/open_engine/imgui/imgui_layer.cpp +++ b/open_engine/src/open_engine/imgui/imgui_layer.cpp @@ -253,6 +253,10 @@ namespace OpenEngine { { } + ImGuiLayer::~ImGuiLayer() + { + } + void ImGuiLayer::OnAttach() { IMGUI_CHECKVERSION(); diff --git a/open_engine/src/open_engine/input/linux_input.cpp b/open_engine/src/open_engine/input/linux_input.cpp index 6092ca8..d00a1d6 100644 --- a/open_engine/src/open_engine/input/linux_input.cpp +++ b/open_engine/src/open_engine/input/linux_input.cpp @@ -1,14 +1,15 @@ #include #include "application.hpp" +#include "core.hpp" #include "logging.hpp" #include #include namespace OpenEngine { - - Input* Input::instance = new LinuxInput(); + + Scope Input::instance = CreateScope(); bool LinuxInput::IsKeyPressedImpl(int keycode) { diff --git a/open_engine/src/open_engine/layer_stack.cpp b/open_engine/src/open_engine/layer_stack.cpp index f03f857..bb5cc1f 100644 --- a/open_engine/src/open_engine/layer_stack.cpp +++ b/open_engine/src/open_engine/layer_stack.cpp @@ -1,3 +1,4 @@ +#include "logging.hpp" #include namespace OpenEngine { @@ -7,39 +8,71 @@ namespace OpenEngine { LayerStack::~LayerStack() { - for (Layer* layer : layers) - delete layer; - } - - void LayerStack::PushLayer(Layer* layer) - { - layers.emplace(layers.begin() + layer_insert_index, layer); - layer_insert_index++; - layer->OnAttach(); - } - - void LayerStack::PushOverlay(Layer* overlay) - { - layers.emplace_back(overlay); - overlay->OnAttach(); - } - - void LayerStack::PopLayer(Layer* layer) - { - auto it = std::find(layers.begin(), layers.begin() + layer_insert_index, layer); - if (it != layers.end()) { + for (auto& layer : layers) layer->OnDetach(); - layers.erase(it); - layer_insert_index--; - } } - void LayerStack::PopOverlay(Layer* overlay) + void LayerStack::QueueLayerPush(Ref layer) { - auto it = std::find(layers.begin() + layer_insert_index, layers.end(), overlay); - if (it != layers.end()) { - overlay->OnDetach(); - layers.erase(it); + layers_to_push.emplace_back(layer); + } + + void LayerStack::QueueLayerPop(Ref layer) + { + layers_to_pop.emplace_back(layer); + } + + void LayerStack::QueueOverlayPush(Ref overlay) + { + overlay_to_push.emplace_back(overlay); + } + + void LayerStack::QueueOverlayPop(Ref overlay) + { + overlay_to_pop.emplace_back(overlay); + } + + void LayerStack::UpdateLayers() + { + // processing pop queue layers + for (auto& layer : layers_to_pop) { + auto it = std::find(layers.begin(), layers.begin() + layer_insert_index, layer); + if (it != layers.end()) { + layer->OnDetach(); + layers.erase(it); + layer_insert_index--; + } } + + layers_to_pop.clear(); + + // processing pop queue overlays + for (auto& overlay : overlay_to_pop) { + auto it = std::find(layers.begin() + layer_insert_index, layers.end(), overlay); + if (it != layers.end()) { + overlay->OnDetach(); + layers.erase(it); + } + } + + overlay_to_pop.clear(); + + // processing push queue layers + for (auto& layer : layers_to_push) { + layers.emplace(layers.begin() + layer_insert_index, layer); + layer_insert_index++; + layer->OnAttach(); + OE_CORE_DEBUG("Added layer: {}", layer->GetName()); + } + + layers_to_push.clear(); + + // processing push queue overlays + for (auto& overlay : overlay_to_push) { + layers.emplace_back(overlay); + overlay->OnAttach(); + } + + overlay_to_push.clear(); } } diff --git a/open_engine/src/open_engine/opengl/opengl_renderer_api.cpp b/open_engine/src/open_engine/opengl/opengl_renderer_api.cpp index 90c2895..ae7bb3b 100644 --- a/open_engine/src/open_engine/opengl/opengl_renderer_api.cpp +++ b/open_engine/src/open_engine/opengl/opengl_renderer_api.cpp @@ -10,6 +10,8 @@ namespace OpenEngine { { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glEnable(GL_DEPTH_TEST); } void OpenGLRendererAPI::SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) diff --git a/open_engine/src/open_engine/opengl/opengl_shader.cpp b/open_engine/src/open_engine/opengl/opengl_shader.cpp index 6969780..a6b110e 100644 --- a/open_engine/src/open_engine/opengl/opengl_shader.cpp +++ b/open_engine/src/open_engine/opengl/opengl_shader.cpp @@ -114,8 +114,10 @@ namespace OpenEngine { return; } - for (int i = 0; i < sources.size(); i++) + for (int i = 0; i < sources.size(); i++) { glDetachShader(program, gl_shader_ids[i]); + glDeleteShader(gl_shader_ids[i]); + } } std::unordered_map OpenGLShader::PreProcess(const std::string& shader_source) @@ -173,27 +175,54 @@ namespace OpenEngine { } void OpenGLShader::SetBool(const std::string &name, bool value) const - { - glUniform1i(glGetUniformLocation(id, name.c_str()), (int)value); + { + UploadBool(name, value); } - void OpenGLShader::SetInt(const std::string &name, int value) const - { - glUniform1i(glGetUniformLocation(id, name.c_str()), value); + { + UploadInt(name, value); } - void OpenGLShader::SetFloat(const std::string &name, float value) const - { - glUniform1f(glGetUniformLocation(id, name.c_str()), value); + { + UploadFloat(name, value); } void OpenGLShader::SetMat4(const std::string &name, const glm::mat4& value) const { - glUniformMatrix4fv(glGetUniformLocation(id, name.c_str()), 1, GL_FALSE, glm::value_ptr(value)); + UploadMat4(name, value); } void OpenGLShader::SetVec3(const std::string &name, const glm::vec3& value) const + { + UploadVec3(name, value); + } + void OpenGLShader::SetVec4(const std::string &name, const glm::vec4& value) const + { + UploadVec4(name, value); + } + + void OpenGLShader::UploadBool(const std::string &name, bool value) const + { + glUniform1i(glGetUniformLocation(id, name.c_str()), (int)value); + } + void OpenGLShader::UploadInt(const std::string &name, int value) const + { + glUniform1i(glGetUniformLocation(id, name.c_str()), value); + } + void OpenGLShader::UploadFloat(const std::string &name, float value) const + { + glUniform1f(glGetUniformLocation(id, name.c_str()), value); + } + void OpenGLShader::UploadMat4(const std::string &name, const glm::mat4& value) const + { + glUniformMatrix4fv(glGetUniformLocation(id, name.c_str()), 1, GL_FALSE, glm::value_ptr(value)); + } + void OpenGLShader::UploadVec3(const std::string &name, const glm::vec3& value) const { glUniform3fv(glGetUniformLocation(id, name.c_str()), 1, glm::value_ptr(value)); } + void OpenGLShader::UploadVec4(const std::string &name, const glm::vec4& value) const + { + glUniform4fv(glGetUniformLocation(id, name.c_str()), 1, glm::value_ptr(value)); + } void OpenGLShader::CheckCompileErrors(unsigned int shader, const std::string& type) { diff --git a/open_engine/src/open_engine/opengl/opengl_texture.cpp b/open_engine/src/open_engine/opengl/opengl_texture.cpp index 386c986..e0f1e6c 100644 --- a/open_engine/src/open_engine/opengl/opengl_texture.cpp +++ b/open_engine/src/open_engine/opengl/opengl_texture.cpp @@ -14,8 +14,8 @@ namespace OpenEngine { : path(path) { int image_width, image_height, channels; - stbi_uc* data = stbi_load(path.c_str(), &image_width, &image_height, &channels, 0); stbi_set_flip_vertically_on_load(1); + stbi_uc* data = stbi_load(path.c_str(), &image_width, &image_height, &channels, 0); OE_CORE_ASSERT(data, "Image could not be loaded!"); width = image_width; diff --git a/open_engine/src/open_engine/renderer/renderer.cpp b/open_engine/src/open_engine/renderer/renderer.cpp index b5d812d..c67aec0 100644 --- a/open_engine/src/open_engine/renderer/renderer.cpp +++ b/open_engine/src/open_engine/renderer/renderer.cpp @@ -1,9 +1,9 @@ -#include #include -#include -#include "opengl/opengl_shader.hpp" -#include "renderer/render_command.hpp" +#include "open_engine/renderer/renderer.hpp" +#include "open_engine/renderer/render_command.hpp" + +#include #include #include @@ -32,8 +32,8 @@ namespace OpenEngine { const glm::mat4& transform) { shader->Bind(); - std::dynamic_pointer_cast(shader)->SetMat4("u_ViewProjection", scene_data->view_projection_matrix); - std::dynamic_pointer_cast(shader)->SetMat4("u_Transform", transform); + shader->SetMat4("u_ViewProjection", scene_data->view_projection_matrix); + shader->SetMat4("u_Transform", transform); vertex_array->Bind(); RenderCommand::DrawIndexed(vertex_array); diff --git a/open_engine/src/open_engine/renderer/vertex_array.cpp b/open_engine/src/open_engine/renderer/vertex_array.cpp index fc5d506..3ced06a 100644 --- a/open_engine/src/open_engine/renderer/vertex_array.cpp +++ b/open_engine/src/open_engine/renderer/vertex_array.cpp @@ -2,15 +2,16 @@ #include "opengl/opengl_vertex_array.hpp" #include "renderer/renderer.hpp" - #include +#include + namespace OpenEngine { - VertexArray* VertexArray::Create() + Ref VertexArray::Create() { switch (Renderer::GetApi()) { case RendererAPI::API::None : OE_CORE_ASSERT(false, "No render API selected!"); return nullptr; - case RendererAPI::API::OpenGL : return new OpenGLVertexArray(); + case RendererAPI::API::OpenGL : return std::make_shared(); } OE_CORE_ASSERT(false, "Selected API not supported"); diff --git a/open_engine/src/open_engine/window/linux_window.cpp b/open_engine/src/open_engine/window/linux_window.cpp index 1722e4a..b6f8df5 100644 --- a/open_engine/src/open_engine/window/linux_window.cpp +++ b/open_engine/src/open_engine/window/linux_window.cpp @@ -5,6 +5,7 @@ #include "logging.hpp" #include +#include #include #include #include "renderer/graphics_context.hpp" @@ -17,9 +18,9 @@ namespace OpenEngine { OE_CORE_ERROR("GLFW Error {}: {}", error, description); } - Window* Window::Create(const WindowProps& props) + std::unique_ptr Window::Create(const WindowProps& props) { - return new LinuxWindow(props); + return std::make_unique(props); } LinuxWindow::LinuxWindow(const WindowProps& props) @@ -56,7 +57,7 @@ namespace OpenEngine { gl_window = glfwCreateWindow((int)props.width, (int)props.height, props.title.c_str(), nullptr, nullptr); - context = new OpenGLContext(gl_window); + context = CreateScope(gl_window); context->Init(); glfwSetWindowUserPointer(gl_window, &data); @@ -156,6 +157,7 @@ namespace OpenEngine { void LinuxWindow::Shutdown() { glfwDestroyWindow(gl_window); + gl_window = nullptr; } void LinuxWindow::OnUpdate() diff --git a/project_config.json b/project_config.json new file mode 100644 index 0000000..2a38d1d --- /dev/null +++ b/project_config.json @@ -0,0 +1,47 @@ +{ + "project_name": "solution name", + "sub_projects": [ + { + "project_name": "exec_proj2", + "binary_name": "hello_world", + "binary_type": "exec", + "include_directories": [ + "./include/test" + ], + "libraries": [ + { + "name" : "nlohmann_json", + "org" : "nlohmann_json", + "find" : true + }, + { + "name" : "shared_proj", + "find" : false + } + ] + }, + { + "project_name": "shared_proj", + "binary_name": "hello_shared", + "binary_type": "shared", + "include_directories": [ + "./include/test2" + ] + }, + { + "project_name": "static_proj", + "binary_name": "hello_static", + "binary_type": "static", + "include_directories": [ + "./include/test2" + ], + "libraries": [ + { + "name" : "nlohmann_json", + "org" : "nlohmann_json", + "find" : true + } + ] + } + ] +}