From 1a99c86c9872728638405f3048116da92cd55c32 Mon Sep 17 00:00:00 2001 From: Aaron <56617292+SpinnerX@users.noreply.github.com> Date: Wed, 9 Oct 2024 11:22:47 -0700 Subject: [PATCH] added event system into this commit (#52) Added clear comments on specific aspects of Vulkan abstraction layers, modified header extensions to hpp, including adding in the event-system --- CMakeLists.txt | 1 - Editor/CMakeLists.txt | 2 +- Editor/Editor/Editor.cpp | 8 +- Editor/Editor/{Editor.h => Editor.hpp} | 2 +- conanfile.py | 2 +- ...tionInstance.h => ApplicationInstance.hpp} | 6 +- engine3d/Core/{Core.h => Core.hpp} | 0 .../Core/{EngineLogger.h => EngineLogger.hpp} | 2 +- engine3d/Core/Event/Event.hpp | 104 +++++++ engine3d/Core/Event/InputPoll.hpp | 22 ++ engine3d/Core/Event/KeyCodes.hpp | 265 ++++++++++++++++++ engine3d/Core/Event/KeyEvent.hpp | 84 ++++++ engine3d/Core/Event/MouseCodes.hpp | 40 +++ engine3d/Core/Event/MouseEvent.hpp | 112 ++++++++ engine3d/Core/{Timestep.h => Timestep.hpp} | 0 engine3d/Core/{Window.h => Window.hpp} | 2 +- engine3d/Core/internal/{API.h => API.hpp} | 0 .../{CoreInternal.h => CoreInternal.hpp} | 0 .../internal/{FrameTimer.h => FrameTimer.hpp} | 0 engine3d/Core/internal/VulkanCpp/Vulkan.h | 14 - engine3d/Core/internal/VulkanCpp/Vulkan.hpp | 21 ++ .../{VulkanDevice.h => VulkanDevice.hpp} | 2 +- ...ogicalDevice.h => VulkanLogicalDevice.hpp} | 10 +- ...sicalDevice.h => VulkanPhysicalDevice.hpp} | 26 +- ...{VulkanSwapchain.h => VulkanSwapchain.hpp} | 0 .../{VulkanWindow.h => VulkanWindow.hpp} | 4 +- src/CMakeLists.txt | 18 +- src/engine3d/Core/ApplicationInstance.cpp | 14 +- src/engine3d/Core/EngineLogger.cpp | 2 +- src/engine3d/Core/Window.cpp | 8 +- src/engine3d/Core/internal/CoreInternal.cpp | 4 +- src/engine3d/Core/internal/FrameTimer.cpp | 2 +- .../Core/internal/VulkanCpp/Vulkan.cpp | 21 +- .../Core/internal/VulkanCpp/VulkanDevice.cpp | 2 +- .../VulkanCpp/VulkanLogicalDevice.cpp | 2 +- .../VulkanCpp/VulkanPhysicalDevice.cpp | 37 +-- .../internal/VulkanCpp/VulkanSwapchain.cpp | 23 +- .../Core/internal/VulkanCpp/VulkanWindow.cpp | 10 +- src/engine3d/Core/platforms/win32.cpp | 10 +- test_package/Application.cpp | 2 +- .../{Application.h => Application.hpp} | 2 +- test_package/CMakeLists.txt | 2 +- 42 files changed, 775 insertions(+), 113 deletions(-) rename Editor/Editor/{Editor.h => Editor.hpp} (95%) rename engine3d/Core/{ApplicationInstance.h => ApplicationInstance.hpp} (98%) rename engine3d/Core/{Core.h => Core.hpp} (100%) rename engine3d/Core/{EngineLogger.h => EngineLogger.hpp} (98%) create mode 100644 engine3d/Core/Event/Event.hpp create mode 100644 engine3d/Core/Event/InputPoll.hpp create mode 100644 engine3d/Core/Event/KeyCodes.hpp create mode 100644 engine3d/Core/Event/KeyEvent.hpp create mode 100644 engine3d/Core/Event/MouseCodes.hpp create mode 100644 engine3d/Core/Event/MouseEvent.hpp rename engine3d/Core/{Timestep.h => Timestep.hpp} (100%) rename engine3d/Core/{Window.h => Window.hpp} (98%) rename engine3d/Core/internal/{API.h => API.hpp} (100%) rename engine3d/Core/internal/{CoreInternal.h => CoreInternal.hpp} (100%) rename engine3d/Core/internal/{FrameTimer.h => FrameTimer.hpp} (100%) delete mode 100644 engine3d/Core/internal/VulkanCpp/Vulkan.h create mode 100644 engine3d/Core/internal/VulkanCpp/Vulkan.hpp rename engine3d/Core/internal/VulkanCpp/{VulkanDevice.h => VulkanDevice.hpp} (84%) rename engine3d/Core/internal/VulkanCpp/{VulkanLogicalDevice.h => VulkanLogicalDevice.hpp} (63%) rename engine3d/Core/internal/VulkanCpp/{VulkanPhysicalDevice.h => VulkanPhysicalDevice.hpp} (63%) rename engine3d/Core/internal/VulkanCpp/{VulkanSwapchain.h => VulkanSwapchain.hpp} (100%) rename engine3d/Core/internal/VulkanCpp/{VulkanWindow.h => VulkanWindow.hpp} (89%) rename test_package/{Application.h => Application.hpp} (84%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 95da0fa..a33309e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,6 @@ endif(LINUX) if(APPLE) find_package(Vulkan REQUIRED) -# find_package(VulkanHeaders REQUIRED) endif(APPLE) find_package(glm REQUIRED) diff --git a/Editor/CMakeLists.txt b/Editor/CMakeLists.txt index 2d3da56..cc66ddf 100644 --- a/Editor/CMakeLists.txt +++ b/Editor/CMakeLists.txt @@ -3,7 +3,7 @@ project(Editor CXX) set( all_src - Editor/Editor.h + Editor/Editor.hpp Editor/Editor.cpp ) diff --git a/Editor/Editor/Editor.cpp b/Editor/Editor/Editor.cpp index 4e50a9a..3b46d92 100644 --- a/Editor/Editor/Editor.cpp +++ b/Editor/Editor/Editor.cpp @@ -1,8 +1,6 @@ -#include "Editor.h" -// #include -#include "engine3d/Core/EngineLogger.h" -// #include "engine3d/Core/Renderer/Renderer.h" -#include +#include "Editor.hpp" +#include +#include namespace engine3d{ EditorApplication::EditorApplication(const std::string& p_DebugName) : ApplicationInstance(p_DebugName) { diff --git a/Editor/Editor/Editor.h b/Editor/Editor/Editor.hpp similarity index 95% rename from Editor/Editor/Editor.h rename to Editor/Editor/Editor.hpp index b221cf2..7f23388 100644 --- a/Editor/Editor/Editor.h +++ b/Editor/Editor/Editor.hpp @@ -1,5 +1,5 @@ #pragma once -#include +#include namespace engine3d{ diff --git a/conanfile.py b/conanfile.py index a9e224c..f110ce7 100644 --- a/conanfile.py +++ b/conanfile.py @@ -86,7 +86,7 @@ def build(self): def package(self): copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) - copy(self, pattern="*.h", src=os.path.join(self.source_folder, "engine3d"), dst=os.path.join(self.package_folder, "engine3d")) + copy(self, pattern="*.hpp", src=os.path.join(self.source_folder, "engine3d"), dst=os.path.join(self.package_folder, "engine3d")) copy(self, pattern="*.a", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False) copy(self, pattern="*.so", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False) copy(self, pattern="*.lib", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False) diff --git a/engine3d/Core/ApplicationInstance.h b/engine3d/Core/ApplicationInstance.hpp similarity index 98% rename from engine3d/Core/ApplicationInstance.h rename to engine3d/Core/ApplicationInstance.hpp index ec7b8a8..01c8a07 100644 --- a/engine3d/Core/ApplicationInstance.h +++ b/engine3d/Core/ApplicationInstance.hpp @@ -1,8 +1,8 @@ #pragma once #include -#include -#include "internal/API.h" -#include +#include +#include "internal/API.hpp" +#include namespace engine3d{ /** diff --git a/engine3d/Core/Core.h b/engine3d/Core/Core.hpp similarity index 100% rename from engine3d/Core/Core.h rename to engine3d/Core/Core.hpp diff --git a/engine3d/Core/EngineLogger.h b/engine3d/Core/EngineLogger.hpp similarity index 98% rename from engine3d/Core/EngineLogger.h rename to engine3d/Core/EngineLogger.hpp index 8dc4d81..b81d838 100644 --- a/engine3d/Core/EngineLogger.h +++ b/engine3d/Core/EngineLogger.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include +#include #include #include #include diff --git a/engine3d/Core/Event/Event.hpp b/engine3d/Core/Event/Event.hpp new file mode 100644 index 0000000..cae5937 --- /dev/null +++ b/engine3d/Core/Event/Event.hpp @@ -0,0 +1,104 @@ +#pragma once +// #include +#include +#include + +namespace engine3d{ + enum class EventType{ + None=0, + WindowClose, WindowResize, WindowFocus, WindowLostFocus, WindowMoved, + KeyPressed, KeyReleased, KeyTyped, + MouseButtonPressed, MouseButtonReleased, MouseMoved, MouseScrolled + }; + + // EventCategories + // May want to filter out certain events + // In other words,receiving all events from application into some kind of + // receiving events from my application into some event class. + // Only carying about the keyboard events + // Example Scenario - If I wanted to log in mouse events, and do we really + // want to check to see if the event type is pressed, released, or scrolled + // So, instead we can just say "give me all the mouse events" + // Hence why we have EventCategoryEnum + enum EventCategory{ + None = 0, + EventCategoryApplication = bit(0), + EventCategoryInput = bit(1), + EventCategoryKeyboard = bit(2), + EventCategoryMouse = bit(3), + EventCategoryMouseButton = bit(4) + }; + + class ENGINE_API Event{ + friend class EventDispatcher; //! @note EventDispatcher accessing Event private variables + public: + + std::string toString() const{ + return str(); + } + + //! @note Checking if the type of category we are searching have been set. + inline bool InCategory(EventCategory category) { + return GetCategoryFlags() & category; + } + + inline bool IsEventHandled() const { return isEventHandled; } + + bool operator|=(bool value) { + isEventHandled |= value; + return isEventHandled; + } + + private: + //! @note Type of Events that are going to be handled + //! @note Name of Event being handled + virtual EventType GetEventType() const = 0; + // virtual const char* GetName() const = 0; + virtual int GetCategoryFlags() const = 0; + + //! @note Will be overrided by different types of Event + //! @note Returns the name as a string (or any other information related to those events) + virtual std::string str() const{ return "Event Default str()"; } + + private: + bool isEventHandled = false; + }; + + class EventDispatcher{ + public: + EventDispatcher(Event& e) : event(e) {} + + //! @note Instead of passing in std::function + //! @note Lets just assume the type being passed in is going to be a lambda + /**@note Used like + + EventDispatcher([](WindowResizedEvent& event){ + }); + + void onWindowResize(WindowResizedEvent& event){} + + EventDispatcher.Dispatch(onWindowResized); + + */ + + //! @param T is the type of event we accept + //! @param EventFunction is the function that we are submitting to our event dispatcher + //! @example dispatcher.Dispatch([](){}); + //! @example dispatcher.Dispatch(bind(this, &Instance::onKeyPressed)) + //! @note Using bind(...) to bind our member function to dispatch based on that given event type + template + bool Dispatch(EventFunction func){ + //! @note Assuming that the type of given by user is an event + //! @note TODO - We should have this function know whether to infer function is a kind of event or not. + if(event.GetEventType() == T::GetStaticType()){ + event.isEventHandled = func(*(T *)&event); + return true; + } + return false; + } + + private: + Event& event; + }; + +}; \ No newline at end of file diff --git a/engine3d/Core/Event/InputPoll.hpp b/engine3d/Core/Event/InputPoll.hpp new file mode 100644 index 0000000..63b4863 --- /dev/null +++ b/engine3d/Core/Event/InputPoll.hpp @@ -0,0 +1,22 @@ +#pragma once +#include +#include +#include + +namespace engine3d{ + class InputPoll{ + public: + + //! @note Key/Mouse event pressed! + static bool IsKeyPressed(KeyCode keycode); + + static bool IsMousePressed(MouseCode mouseCode); + + //! @note Mouse Position + static glm::vec2 GetMousePos(); + + static float GetMouseX(); + + static float GetMouseY(); + }; +}; \ No newline at end of file diff --git a/engine3d/Core/Event/KeyCodes.hpp b/engine3d/Core/Event/KeyCodes.hpp new file mode 100644 index 0000000..d08f63c --- /dev/null +++ b/engine3d/Core/Event/KeyCodes.hpp @@ -0,0 +1,265 @@ +#pragma once +#include + +namespace engine3d{ + typedef enum class KeyCode : uint16_t { + // From glfw3.h + Space = 32, + Apostrophe = 39, /* ' */ + Comma = 44, /* , */ + Minus = 45, /* - */ + Period = 46, /* . */ + Slash = 47, /* / */ + + D0 = 48, /* 0 */ + D1 = 49, /* 1 */ + D2 = 50, /* 2 */ + D3 = 51, /* 3 */ + D4 = 52, /* 4 */ + D5 = 53, /* 5 */ + D6 = 54, /* 6 */ + D7 = 55, /* 7 */ + D8 = 56, /* 8 */ + D9 = 57, /* 9 */ + + Semicolon = 59, /* ; */ + Equal = 61, /* = */ + + A = 65, + B = 66, + C = 67, + D = 68, + E = 69, + F = 70, + G = 71, + H = 72, + I = 73, + J = 74, + K = 75, + L = 76, + M = 77, + N = 78, + O = 79, + P = 80, + Q = 81, + R = 82, + S = 83, + T = 84, + U = 85, + V = 86, + W = 87, + X = 88, + Y = 89, + Z = 90, + + LeftBracket = 91, /* [ */ + Backslash = 92, /* \ */ + RightBracket = 93, /* ] */ + GraveAccent = 96, /* ` */ + + World1 = 161, /* non-US #1 */ + World2 = 162, /* non-US #2 */ + + /* Function keys */ + Escape = 256, + Enter = 257, + Tab = 258, + Backspace = 259, + Insert = 260, + Delete = 261, + Right = 262, + Left = 263, + Down = 264, + Up = 265, + PageUp = 266, + PageDown = 267, + Home = 268, + End = 269, + CapsLock = 280, + ScrollLock = 281, + NumLock = 282, + PrintScreen = 283, + Pause = 284, + F1 = 290, + F2 = 291, + F3 = 292, + F4 = 293, + F5 = 294, + F6 = 295, + F7 = 296, + F8 = 297, + F9 = 298, + F10 = 299, + F11 = 300, + F12 = 301, + F13 = 302, + F14 = 303, + F15 = 304, + F16 = 305, + F17 = 306, + F18 = 307, + F19 = 308, + F20 = 309, + F21 = 310, + F22 = 311, + F23 = 312, + F24 = 313, + F25 = 314, + + /* Keypad */ + KP0 = 320, + KP1 = 321, + KP2 = 322, + KP3 = 323, + KP4 = 324, + KP5 = 325, + KP6 = 326, + KP7 = 327, + KP8 = 328, + KP9 = 329, + KPDecimal = 330, + KPDivide = 331, + KPMultiply = 332, + KPSubtract = 333, + KPAdd = 334, + KPEnter = 335, + KPEqual = 336, + + LeftShift = 340, + LeftControl = 341, + LeftAlt = 342, + LeftSuper = 343, + RightShift = 344, + RightControl = 345, + RightAlt = 346, + RightSuper = 347, + Menu = 348 + } Key; +} + +// From glfw3.h +#define ENGINE_KEY_SPACE ::engine3d::Key::Space +#define ENGINE_KEY_APOSTROPHE ::engine3d::Key::Apostrophe /* ' */ +#define ENGINE_KEY_COMMA ::engine3d::Key::Comma /* , */ +#define ENGINE_KEY_MINUS ::engine3d::Key::Minus /* - */ +#define ENGINE_KEY_PERIOD ::engine3d::Key::Period /* . */ +#define ENGINE_KEY_SLASH ::engine3d::Key::Slash /* / */ +#define ENGINE_KEY_0 ::engine3d::Key::D0 +#define ENGINE_KEY_1 ::engine3d::Key::D1 +#define ENGINE_KEY_2 ::engine3d::Key::D2 +#define ENGINE_KEY_3 ::engine3d::Key::D3 +#define ENGINE_KEY_4 ::engine3d::Key::D4 +#define ENGINE_KEY_5 ::engine3d::Key::D5 +#define ENGINE_KEY_6 ::engine3d::Key::D6 +#define ENGINE_KEY_7 ::engine3d::Key::D7 +#define ENGINE_KEY_8 ::engine3d::Key::D8 +#define ENGINE_KEY_9 ::engine3d::Key::D9 +#define ENGINE_KEY_SEMICOLON ::engine3d::Key::Semicolon /* ; */ +#define ENGINE_KEY_EQUAL ::engine3d::Key::Equal /* = */ +#define ENGINE_KEY_A ::engine3d::Key::A +#define ENGINE_KEY_B ::engine3d::Key::B +#define ENGINE_KEY_C ::engine3d::Key::C +#define ENGINE_KEY_D ::engine3d::Key::D +#define ENGINE_KEY_E ::engine3d::Key::E +#define ENGINE_KEY_F ::engine3d::Key::F +#define ENGINE_KEY_G ::engine3d::Key::G +#define ENGINE_KEY_H ::engine3d::Key::H +#define ENGINE_KEY_I ::engine3d::Key::I +#define ENGINE_KEY_J ::engine3d::Key::J +#define ENGINE_KEY_K ::engine3d::Key::K +#define ENGINE_KEY_L ::engine3d::Key::L +#define ENGINE_KEY_M ::engine3d::Key::M +#define ENGINE_KEY_N ::engine3d::Key::N +#define ENGINE_KEY_O ::engine3d::Key::O +#define ENGINE_KEY_P ::engine3d::Key::P +#define ENGINE_KEY_Q ::engine3d::Key::Q +#define ENGINE_KEY_R ::engine3d::Key::R +#define ENGINE_KEY_S ::engine3d::Key::S +#define ENGINE_KEY_T ::engine3d::Key::T +#define ENGINE_KEY_U ::engine3d::Key::U +#define ENGINE_KEY_V ::engine3d::Key::V +#define ENGINE_KEY_W ::engine3d::Key::W +#define ENGINE_KEY_X ::engine3d::Key::X +#define ENGINE_KEY_Y ::engine3d::Key::Y +#define ENGINE_KEY_Z ::engine3d::Key::Z +#define ENGINE_KEY_LEFT_BRACKET ::engine3d::Key::LeftBracket /* [ */ +#define ENGINE_KEY_BACKSLASH ::engine3d::Key::Backslash /* \ */ +#define ENGINE_KEY_RIGHT_BRACKET ::engine3d::Key::RightBracket /* ] */ +#define ENGINE_KEY_GRAVE_ACCENT ::engine3d::Key::GraveAccent /* ` */ +#define ENGINE_KEY_WORLD_1 ::engine3d::Key::World1 /* non-US #1 */ +#define ENGINE_KEY_WORLD_2 ::engine3d::Key::World2 /* non-US #2 */ + +/* Function keys */ +#define ENGINE_KEY_ESCAPE ::engine3d::Key::Escape +#define ENGINE_KEY_ENTER ::engine3d::Key::Enter +#define ENGINE_KEY_TAB ::engine3d::Key::Tab +#define ENGINE_KEY_BACKSPACE ::engine3d::Key::Backspace +#define ENGINE_KEY_INSERT ::engine3d::Key::Insert +#define ENGINE_KEY_DELETE ::engine3d::Key::Delete +#define ENGINE_KEY_RIGHT ::engine3d::Key::Right +#define ENGINE_KEY_LEFT ::engine3d::Key::Left +#define ENGINE_KEY_DOWN ::engine3d::Key::Down +#define ENGINE_KEY_UP ::engine3d::Key::Up +#define ENGINE_KEY_PAGE_UP ::engine3d::Key::PageUp +#define ENGINE_KEY_PAGE_DOWN ::engine3d::Key::PageDown +#define ENGINE_KEY_HOME ::engine3d::Key::Home +#define ENGINE_KEY_END ::engine3d::Key::End +#define ENGINE_KEY_CAPS_LOCK ::engine3d::Key::CapsLock +#define ENGINE_KEY_SCROLL_LOCK ::engine3d::Key::ScrollLock +#define ENGINE_KEY_NUM_LOCK ::engine3d::Key::NumLock +#define ENGINE_KEY_PRINT_SCREEN ::engine3d::Key::PrintScreen +#define ENGINE_KEY_PAUSE ::engine3d::Key::Pause +#define ENGINE_KEY_F1 ::engine3d::Key::F1 +#define ENGINE_KEY_F2 ::engine3d::Key::F2 +#define ENGINE_KEY_F3 ::engine3d::Key::F3 +#define ENGINE_KEY_F4 ::engine3d::Key::F4 +#define ENGINE_KEY_F5 ::engine3d::Key::F5 +#define ENGINE_KEY_F6 ::engine3d::Key::F6 +#define ENGINE_KEY_F7 ::engine3d::Key::F7 +#define ENGINE_KEY_F8 ::engine3d::Key::F8 +#define ENGINE_KEY_F9 ::engine3d::Key::F9 +#define ENGINE_KEY_F10 ::engine3d::Key::F10 +#define ENGINE_KEY_F11 ::engine3d::Key::F11 +#define ENGINE_KEY_F12 ::engine3d::Key::F12 +#define ENGINE_KEY_F13 ::engine3d::Key::F13 +#define ENGINE_KEY_F14 ::engine3d::Key::F14 +#define ENGINE_KEY_F15 ::engine3d::Key::F15 +#define ENGINE_KEY_F16 ::engine3d::Key::F16 +#define ENGINE_KEY_F17 ::engine3d::Key::F17 +#define ENGINE_KEY_F18 ::engine3d::Key::F18 +#define ENGINE_KEY_F19 ::engine3d::Key::F19 +#define ENGINE_KEY_F20 ::engine3d::Key::F20 +#define ENGINE_KEY_F21 ::engine3d::Key::F21 +#define ENGINE_KEY_F22 ::engine3d::Key::F22 +#define ENGINE_KEY_F23 ::engine3d::Key::F23 +#define ENGINE_KEY_F24 ::engine3d::Key::F24 +#define ENGINE_KEY_F25 ::engine3d::Key::F25 + +/* Keypad */ +#define ENGINE_KEY_KP_0 ::engine3d::Key::KP0 +#define ENGINE_KEY_KP_1 ::engine3d::Key::KP1 +#define ENGINE_KEY_KP_2 ::engine3d::Key::KP2 +#define ENGINE_KEY_KP_3 ::engine3d::Key::KP3 +#define ENGINE_KEY_KP_4 ::engine3d::Key::KP4 +#define ENGINE_KEY_KP_5 ::engine3d::Key::KP5 +#define ENGINE_KEY_KP_6 ::engine3d::Key::KP6 +#define ENGINE_KEY_KP_7 ::engine3d::Key::KP7 +#define ENGINE_KEY_KP_8 ::engine3d::Key::KP8 +#define ENGINE_KEY_KP_9 ::engine3d::Key::KP9 +#define ENGINE_KEY_KP_DECIMAL ::engine3d::Key::KPDecimal +#define ENGINE_KEY_KP_DIVIDE ::engine3d::Key::KPDivide +#define ENGINE_KEY_KP_MULTIPLY ::engine3d::Key::KPMultiply +#define ENGINE_KEY_KP_SUBTRACT ::engine3d::Key::KPSubtract +#define ENGINE_KEY_KP_ADD ::engine3d::Key::KPAdd +#define ENGINE_KEY_KP_ENTER ::engine3d::Key::KPEnter +#define ENGINE_KEY_KP_EQUAL ::engine3d::Key::KPEqual + +#define ENGINE_KEY_LEFT_SHIFT ::engine3d::Key::LeftShift +#define ENGINE_KEY_LEFT_CONTROL ::engine3d::Key::LeftControl +#define ENGINE_KEY_LEFT_ALT ::engine3d::Key::LeftAlt +#define ENGINE_KEY_LEFT_SUPER ::engine3d::Key::LeftSuper +#define ENGINE_KEY_RIGHT_SHIFT ::engine3d::Key::RightShift +#define ENGINE_KEY_RIGHT_CONTROL ::engine3d::Key::RightControl +#define ENGINE_KEY_RIGHT_ALT ::engine3d::Key::RightAlt +#define ENGINE_KEY_RIGHT_SUPER ::engine3d::Key::RightSuper +#define ENGINE_KEY_MENU ::engine3d::Key::Menu \ No newline at end of file diff --git a/engine3d/Core/Event/KeyEvent.hpp b/engine3d/Core/Event/KeyEvent.hpp new file mode 100644 index 0000000..4e9b7c7 --- /dev/null +++ b/engine3d/Core/Event/KeyEvent.hpp @@ -0,0 +1,84 @@ +#pragma once +#include +#include +#include +#include + +namespace engine3d{ + + class ENGINE_API KeyEvent : public Event{ + public: + + inline KeyCode GetKeyCode() const { return keycode; } + + int GetCategoryFlags() const override{ + return EventCategoryKeyboard | EventCategoryInput; + } + + protected: + KeyEvent(KeyCode code) : keycode(code) {} + + KeyCode keycode; + }; + + class ENGINE_API KeyPressedEvent : public KeyEvent { + public: + KeyPressedEvent(KeyCode code, int countRepeated) : KeyEvent(code), repeated(countRepeated) {} + + inline int GetRepeatedCount() const { return repeated; } + + static EventType GetStaticType() { return EventType::KeyPressed; } + + private: + std::string str() const override{ + std::stringstream ss; + ss << "KeyPressedEvent(Key) = " << static_cast(keycode); + ss << "EventType::KeyPressedEvent"; + return ss.str(); + } + + // const char* GetName() const override { return "EventType::KeyPressedEvent"; } + + EventType GetEventType() const override { return GetStaticType(); } + + private: + int repeated; + }; + + class ENGINE_API KeyReleasedEvent : public KeyEvent { + public: + KeyReleasedEvent(KeyCode code) : KeyEvent(code){} + + static EventType GetStaticType() { return EventType::KeyReleased; } + + private: + std::string str() const override { + std::stringstream ss; + ss << "KeyReleasedEvent(Key) = " << static_cast(keycode); + return ss.str(); + } + + EventType GetEventType() const override { return GetStaticType(); } + + // const char* GetName() const override { return "EventType::KeyReleasedEvent"; } + }; + + class ENGINE_API KeyTypedEvent : public KeyEvent { + public: + KeyTypedEvent(KeyCode code) : KeyEvent(code) {} + + static EventType GetStaticType() { return EventType::KeyTyped; } + + private: + std::string str() const override{ + std::stringstream ss; + ss << "KeyTypedEvent(key) = " << static_cast(keycode); + return ss.str(); + } + + EventType GetEventType() const override { return GetStaticType(); } + // const char* GetName() const override { return "EventType::KeyTypedEvent"; } + }; + + +}; \ No newline at end of file diff --git a/engine3d/Core/Event/MouseCodes.hpp b/engine3d/Core/Event/MouseCodes.hpp new file mode 100644 index 0000000..fd2dae2 --- /dev/null +++ b/engine3d/Core/Event/MouseCodes.hpp @@ -0,0 +1,40 @@ +#pragma once +#include + +namespace engine3d{ + typedef enum class MouseCode : uint16_t{ + // From glfw3.h + Button0 = 0, + Button1 = 1, + Button2 = 2, + Button3 = 3, + Button4 = 4, + Button5 = 5, + Button6 = 6, + Button7 = 7, + + ButtonLast = Button7, + ButtonLeft = Button0, + ButtonRight = Button1, + ButtonMiddle = Button2 + } Mouse; + + // inline std::ostream& operator<<(std::ostream& os, MouseCode mouseCode) + // { + // os << static_cast(mouseCode); + // return os; + // } +} + +#define ENGINE_MOUSE_BUTTON_0 ::engine3d::Mouse::Button0 +#define ENGINE_MOUSE_BUTTON_1 ::engine3d::Mouse::Button1 +#define ENGINE_MOUSE_BUTTON_2 ::engine3d::Mouse::Button2 +#define ENGINE_MOUSE_BUTTON_3 ::engine3d::Mouse::Button3 +#define ENGINE_MOUSE_BUTTON_4 ::engine3d::Mouse::Button4 +#define ENGINE_MOUSE_BUTTON_5 ::engine3d::Mouse::Button5 +#define ENGINE_MOUSE_BUTTON_6 ::engine3d::Mouse::Button6 +#define ENGINE_MOUSE_BUTTON_7 ::engine3d::Mouse::Button7 +#define ENGINE_MOUSE_BUTTON_LAST ::engine3d::Mouse::ButtonLast +#define ENGINE_MOUSE_BUTTON_LEFT ::engine3d::Mouse::ButtonLeft +#define ENGINE_MOUSE_BUTTON_RIGHT ::engine3d::Mouse::ButtonRight +#define ENGINE_MOUSE_BUTTON_MIDDLE ::engine3d::Mouse::ButtonMiddle \ No newline at end of file diff --git a/engine3d/Core/Event/MouseEvent.hpp b/engine3d/Core/Event/MouseEvent.hpp new file mode 100644 index 0000000..e643cfe --- /dev/null +++ b/engine3d/Core/Event/MouseEvent.hpp @@ -0,0 +1,112 @@ +#pragma once +#include +#include +#include + +namespace engine3d{ + class ENGINE_API MouseMovedEvent : public Event{ + public: + MouseMovedEvent(float x, float y) : mouseX(x), mouseY(y) {}; + + static EventType GetStaticType() { return EventType::MouseMoved; } + + inline float GetX() const { return mouseX; } + + inline float GetY() const { return mouseY; } + + private: + std::string str() const override{ + std::stringstream ss; + ss << "MouseMovedEvent(Mouse) = (" << mouseX << ", " << mouseY << ")"; + return ss.str(); + } + + virtual EventType GetEventType() const override { return GetStaticType(); } + + int GetCategoryFlags() const override{ + return EventCategoryMouse | EventCategoryInput; + } + + private: + float mouseX, mouseY; + }; + + class ENGINE_API MouseScrolledEvent: public Event{ + public: + MouseScrolledEvent(float x, float y) : xOffset(x), yOffset(y) {} + + inline float GetXOffset() const { return xOffset; } + + inline float GetYOffset() const { return yOffset; } + + static EventType GetStaticType() { return EventType::MouseScrolled; } + + private: + std::string str() const override{ + std::stringstream ss; + ss << "MouseScrolledEvent(mouse) = (" << xOffset << ", " << yOffset <<")"; + return ss.str(); + } + + virtual EventType GetEventType() const override { return GetStaticType(); } + + int GetCategoryFlags() const override{ + return EventCategoryMouse | EventCategoryInput; + } + + private: + float xOffset, yOffset; + }; + + class MouseButtonEvent : public Event{ + public: + inline MouseCode GetMouseCode() const { return mouseCode; } + + int GetCategoryFlags() const override{ + return EventCategoryMouse | EventCategoryInput; + } + + protected: + MouseButtonEvent(MouseCode code) : mouseCode(code) {} + MouseCode mouseCode; + }; + + class ENGINE_API MouseButtonPressedEvent : public MouseButtonEvent { + public: + MouseButtonPressedEvent(MouseCode code) : MouseButtonEvent(code) {} + + static EventType GetStaticType() { return EventType::MouseButtonPressed; } + + private: + //! @note Returns the name as a string (or any other information) + std::string str() const override { + std::stringstream ss; + ss << "MouseButtonPressedEvent(mouse) = " << static_cast(mouseCode); + ss << "EventType::MouseButtonPressed"; + return ss.str(); + } + + virtual EventType GetEventType() const override { return GetStaticType(); } + + // virtual const char* GetName() const override { return "EventType::MouseButtonPressed"; } + }; + + class ENGINE_API MouseButtonReleasedEvent : public MouseButtonEvent { + public: + MouseButtonReleasedEvent(MouseCode code) : MouseButtonEvent(code) {} + + static EventType GetStaticType() { return EventType::MouseButtonReleased; } + + private: + std::string str() const override { + std::stringstream ss; + ss << "MouseButtonReleasedEvent(Mouse) = " << static_cast(mouseCode); + ss << "Event::MouseButtonReleased"; + return ss.str(); + } + + virtual EventType GetEventType() const override { return GetStaticType(); } + }; + + +}; \ No newline at end of file diff --git a/engine3d/Core/Timestep.h b/engine3d/Core/Timestep.hpp similarity index 100% rename from engine3d/Core/Timestep.h rename to engine3d/Core/Timestep.hpp diff --git a/engine3d/Core/Window.h b/engine3d/Core/Window.hpp similarity index 98% rename from engine3d/Core/Window.h rename to engine3d/Core/Window.hpp index d852644..24b3f02 100644 --- a/engine3d/Core/Window.h +++ b/engine3d/Core/Window.hpp @@ -1,5 +1,5 @@ #pragma once -#include +#include #include #include diff --git a/engine3d/Core/internal/API.h b/engine3d/Core/internal/API.hpp similarity index 100% rename from engine3d/Core/internal/API.h rename to engine3d/Core/internal/API.hpp diff --git a/engine3d/Core/internal/CoreInternal.h b/engine3d/Core/internal/CoreInternal.hpp similarity index 100% rename from engine3d/Core/internal/CoreInternal.h rename to engine3d/Core/internal/CoreInternal.hpp diff --git a/engine3d/Core/internal/FrameTimer.h b/engine3d/Core/internal/FrameTimer.hpp similarity index 100% rename from engine3d/Core/internal/FrameTimer.h rename to engine3d/Core/internal/FrameTimer.hpp diff --git a/engine3d/Core/internal/VulkanCpp/Vulkan.h b/engine3d/Core/internal/VulkanCpp/Vulkan.h deleted file mode 100644 index a95bae5..0000000 --- a/engine3d/Core/internal/VulkanCpp/Vulkan.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include -namespace engine3d{ - namespace vk{ - class Vulkan{ - public: - static void InitializeVulkanCore(); - static void CleanupVulkanCore(); - - static VkInstance& GetVkInstance(); - }; - }; -}; \ No newline at end of file diff --git a/engine3d/Core/internal/VulkanCpp/Vulkan.hpp b/engine3d/Core/internal/VulkanCpp/Vulkan.hpp new file mode 100644 index 0000000..8e0deac --- /dev/null +++ b/engine3d/Core/internal/VulkanCpp/Vulkan.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include +namespace engine3d{ + namespace vk{ + /* + * @name Vulkan + * @note Used to instantiate the vulkan's application information. + * @note Essentially setting Vulkan's global state that contains information about the application + * @note Which includes extensions and validation layers used for debugging information. + * @note VKInstance used to instantiate vulkan and allows the application to pass information about itself. + */ + class Vulkan{ + public: + static void InitializeVulkanCore(); + static void CleanupVulkanCore(); + + static VkInstance& GetVkInstance(); + }; + }; +}; diff --git a/engine3d/Core/internal/VulkanCpp/VulkanDevice.h b/engine3d/Core/internal/VulkanCpp/VulkanDevice.hpp similarity index 84% rename from engine3d/Core/internal/VulkanCpp/VulkanDevice.h rename to engine3d/Core/internal/VulkanCpp/VulkanDevice.hpp index 3e425d4..baef831 100644 --- a/engine3d/Core/internal/VulkanCpp/VulkanDevice.h +++ b/engine3d/Core/internal/VulkanCpp/VulkanDevice.hpp @@ -1,5 +1,5 @@ #pragma once -#include "internal/VulkanCpp/VulkanLogicalDevice.h" +#include "internal/VulkanCpp/VulkanLogicalDevice.hpp" namespace engine3d::vk{ class VulkanDevice{ diff --git a/engine3d/Core/internal/VulkanCpp/VulkanLogicalDevice.h b/engine3d/Core/internal/VulkanCpp/VulkanLogicalDevice.hpp similarity index 63% rename from engine3d/Core/internal/VulkanCpp/VulkanLogicalDevice.h rename to engine3d/Core/internal/VulkanCpp/VulkanLogicalDevice.hpp index 9e620a6..642f717 100644 --- a/engine3d/Core/internal/VulkanCpp/VulkanLogicalDevice.h +++ b/engine3d/Core/internal/VulkanCpp/VulkanLogicalDevice.hpp @@ -1,10 +1,16 @@ #pragma once -#include +#include #include #include namespace engine3d{ namespace vk{ + /* + * @name VulkanLogicalDevice + * @note Represent our vulkan interface to the physical device. + * @note Using this logical device allows for multiple application accessing the physical devices on our machine. + * @note Utilizing our selected physical device (VulkanPhysicalDevice), using this logical device to specify features/extensions with our selected physical device. + */ class VulkanLogicalDevice{ public: VulkanLogicalDevice() {} @@ -28,4 +34,4 @@ namespace engine3d{ VkQueue m_ComputeQueue; }; }; -}; \ No newline at end of file +}; diff --git a/engine3d/Core/internal/VulkanCpp/VulkanPhysicalDevice.h b/engine3d/Core/internal/VulkanCpp/VulkanPhysicalDevice.hpp similarity index 63% rename from engine3d/Core/internal/VulkanCpp/VulkanPhysicalDevice.h rename to engine3d/Core/internal/VulkanCpp/VulkanPhysicalDevice.hpp index e6b33c9..9b84000 100644 --- a/engine3d/Core/internal/VulkanCpp/VulkanPhysicalDevice.h +++ b/engine3d/Core/internal/VulkanCpp/VulkanPhysicalDevice.hpp @@ -6,6 +6,12 @@ namespace engine3d{ namespace vk{ + /* + * @name VulkanPhysicalDevice + * @note Abstracted physical device layer for validating compatbility with our current platform's GPU. + * @note In other words represent actual physical GPU that is available on our current machine. + * @note Allows with workloads from vulkan logical devices and exposing to various queue families the GPU supports. + */ class VulkanPhysicalDevice{ struct QueueFamilyIndices{ int Graphics = -1; @@ -16,15 +22,27 @@ namespace engine3d{ VulkanPhysicalDevice(); VkPhysicalDevice& GetVkPhysicalDevice(); - VkFormat GetDepthFormat(); + /* + * @name GetDepthFormat() + * @note Returns the depth format we need for image depth usage. + * @note By returning the depth format we also describe how our memory is laid out. + */ + VkFormat GetDepthFormat(); + + //! @note Returns boolean if we pass a valid extension name. bool IsExtensionSupported(const std::string& ext_name); private: + //! @note Returns the queue family indices to which queue family indices are supported and valid. VulkanPhysicalDevice::QueueFamilyIndices GetQueueFamilyIndices(int flag); - + + //! @note Used for validating if depth format is available or valid on our current machine. VkFormat SearchAvailableDepthFormat(); - + + //! @note print debugging information of our physical device properties. void print_physical_device_property(VkPhysicalDeviceProperties properties); + + //! @note Fetching our devices that are compatible to use. std::vector get_available_devices(); @@ -44,4 +62,4 @@ namespace engine3d{ std::unordered_set m_SupportedExtensions; }; }; -}; \ No newline at end of file +}; diff --git a/engine3d/Core/internal/VulkanCpp/VulkanSwapchain.h b/engine3d/Core/internal/VulkanCpp/VulkanSwapchain.hpp similarity index 100% rename from engine3d/Core/internal/VulkanCpp/VulkanSwapchain.h rename to engine3d/Core/internal/VulkanCpp/VulkanSwapchain.hpp diff --git a/engine3d/Core/internal/VulkanCpp/VulkanWindow.h b/engine3d/Core/internal/VulkanCpp/VulkanWindow.hpp similarity index 89% rename from engine3d/Core/internal/VulkanCpp/VulkanWindow.h rename to engine3d/Core/internal/VulkanCpp/VulkanWindow.hpp index e0bf380..3db086c 100644 --- a/engine3d/Core/internal/VulkanCpp/VulkanWindow.h +++ b/engine3d/Core/internal/VulkanCpp/VulkanWindow.hpp @@ -1,6 +1,5 @@ #pragma once -#include "Window.h" -#include "internal/VulkanCpp/VulkanSwapchain.h" +#include "Window.hpp" #include #include #include @@ -32,7 +31,6 @@ namespace engine3d{ private: GLFWwindow* m_Window; VkSurfaceKHR m_Surface; - VulkanSwapchain* m_CurrentWindowSwapchain; bool m_IsCurrentWindowActive = false; uint32_t m_Width, m_Height; std::string m_Title; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8c4c4e1..523c910 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,17 +6,17 @@ set(VULKAN_SRC_DIR ${ENGINE_SRC_DIR}/Core/internal/VulkanCpp) set( all_headers - ${ENGINE_INCLUDE_NAME}/Core/ApplicationInstance.h + ${ENGINE_INCLUDE_NAME}/Core/ApplicationInstance.hpp - ${ENGINE_INCLUDE_NAME}/Core/EngineLogger.h - ${ENGINE_INCLUDE_NAME}/Core/Window.h + ${ENGINE_INCLUDE_NAME}/Core/EngineLogger.hpp + ${ENGINE_INCLUDE_NAME}/Core/Window.hpp - ${VULKAN_INCLUDE_DIR}/Vulkan.h - ${VULKAN_INCLUDE_DIR}/VulkanWindow.h - ${VULKAN_INCLUDE_DIR}/VulkanDevice.h - ${VULKAN_INCLUDE_DIR}/VulkanPhysicalDevice.h - ${VULKAN_INCLUDE_DIR}/VulkanLogicalDevice.h - ${VULKAN_INCLUDE_DIR}/VulkanSwapchain.h + ${VULKAN_INCLUDE_DIR}/Vulkan.hpp + ${VULKAN_INCLUDE_DIR}/VulkanWindow.hpp + ${VULKAN_INCLUDE_DIR}/VulkanDevice.hpp + ${VULKAN_INCLUDE_DIR}/VulkanPhysicalDevice.hpp + ${VULKAN_INCLUDE_DIR}/VulkanLogicalDevice.hpp + ${VULKAN_INCLUDE_DIR}/VulkanSwapchain.hpp # Renderer Includes ${ENGINE_INCLUDE_NAME}/Core/Renderer/Renderer.hpp diff --git a/src/engine3d/Core/ApplicationInstance.cpp b/src/engine3d/Core/ApplicationInstance.cpp index acf1b32..c00a5f3 100644 --- a/src/engine3d/Core/ApplicationInstance.cpp +++ b/src/engine3d/Core/ApplicationInstance.cpp @@ -1,8 +1,8 @@ -// #include -#include -#include -// #include -#include +// #include +#include +#include +// #include +#include namespace engine3d{ static float m_LastFrameTime = 0.0f; @@ -14,7 +14,7 @@ namespace engine3d{ g_ThisInstance = this; g_DebugName = p_DebugName; SetCurrentAPI(VULKAN); - m_Window = Window::Create(); + m_Window = Window::Create(900, 600, p_DebugName); } void ApplicationInstance::ExecuteApplicationMainloop(){ @@ -54,4 +54,4 @@ namespace engine3d{ } Window& ApplicationInstance::GetWindow() { return *g_ThisInstance->m_Window; } -}; \ No newline at end of file +}; diff --git a/src/engine3d/Core/EngineLogger.cpp b/src/engine3d/Core/EngineLogger.cpp index 7c69105..d91915d 100644 --- a/src/engine3d/Core/EngineLogger.cpp +++ b/src/engine3d/Core/EngineLogger.cpp @@ -1,4 +1,4 @@ -#include +#include #include namespace engine3d{ diff --git a/src/engine3d/Core/Window.cpp b/src/engine3d/Core/Window.cpp index 02c5625..221a4e6 100644 --- a/src/engine3d/Core/Window.cpp +++ b/src/engine3d/Core/Window.cpp @@ -1,7 +1,7 @@ -// #include -#include -#include "ApplicationInstance.h" -#include +// #include +#include +#include "ApplicationInstance.hpp" +#include #include #include diff --git a/src/engine3d/Core/internal/CoreInternal.cpp b/src/engine3d/Core/internal/CoreInternal.cpp index d001808..e7a609d 100644 --- a/src/engine3d/Core/internal/CoreInternal.cpp +++ b/src/engine3d/Core/internal/CoreInternal.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include namespace engine3d{ //! @note TODO -- Move this somewhere within the vulkan directory diff --git a/src/engine3d/Core/internal/FrameTimer.cpp b/src/engine3d/Core/internal/FrameTimer.cpp index ec4ddfb..0e516aa 100644 --- a/src/engine3d/Core/internal/FrameTimer.cpp +++ b/src/engine3d/Core/internal/FrameTimer.cpp @@ -1,4 +1,4 @@ -#include +#include #include namespace engine3d{ diff --git a/src/engine3d/Core/internal/VulkanCpp/Vulkan.cpp b/src/engine3d/Core/internal/VulkanCpp/Vulkan.cpp index cf76630..d8e0989 100644 --- a/src/engine3d/Core/internal/VulkanCpp/Vulkan.cpp +++ b/src/engine3d/Core/internal/VulkanCpp/Vulkan.cpp @@ -1,13 +1,14 @@ -#include "EngineLogger.h" -#include +#include "EngineLogger.hpp" +#include #include #include #include #include -#include +#include namespace engine3d::vk{ + //! @note These are different extensions we need to check are available as required for the vulkan API. #if defined(_WIN32) static std::vector extensions = { VK_KHR_SURFACE_EXTENSION_NAME, @@ -35,10 +36,10 @@ namespace engine3d::vk{ static std::vector validationLayers = { "VK_LAYER_KHRONOS_validation", - // "VK_LAYER_LUNARG_api_dump", - // "VK_LAYER_KHRONOS_profiles", - // "VK_LAYER_KHRONOS_synchronization2", - // "VK_LAYER_KHRONOS_shader_object", + /* "VK_LAYER_LUNARG_api_dump", */ + /* "VK_LAYER_KHRONOS_profiles", */ + /* "VK_LAYER_KHRONOS_synchronization2", */ + /* "VK_LAYER_KHRONOS_shader_object", */ }; static VkInstance g_Instance; @@ -66,6 +67,7 @@ namespace engine3d::vk{ }; #if defined(__APPLE__) + //! @note enabling this flags allow vulkan non-conformant vulkan implementation to be built on top of another non-vulkan graphics API sucha as Metal, DX12, and etc. createInfo.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; #endif @@ -75,7 +77,7 @@ namespace engine3d::vk{ } if(g_Instance == VK_NULL_HANDLE){ - printf("Vulkan VkInstance::g_Instance === nullptr\n"); + throw std::runtime_error("Vulkan VkInstance::g_Instance === nullptr"); } //! @note Setting the debug callback @@ -85,9 +87,6 @@ namespace engine3d::vk{ } VkInstance& Vulkan::GetVkInstance(){ - if(g_Instance == VK_NULL_HANDLE){ - printf("Vulkan VkInstance::g_Instance (from GetVkInstance)=== nullptr\n"); - } return g_Instance; } diff --git a/src/engine3d/Core/internal/VulkanCpp/VulkanDevice.cpp b/src/engine3d/Core/internal/VulkanCpp/VulkanDevice.cpp index 9c1eb39..9cdb811 100644 --- a/src/engine3d/Core/internal/VulkanCpp/VulkanDevice.cpp +++ b/src/engine3d/Core/internal/VulkanCpp/VulkanDevice.cpp @@ -1,4 +1,4 @@ -#include +#include namespace engine3d::vk{ /** diff --git a/src/engine3d/Core/internal/VulkanCpp/VulkanLogicalDevice.cpp b/src/engine3d/Core/internal/VulkanCpp/VulkanLogicalDevice.cpp index 44ce2b6..7feaa24 100644 --- a/src/engine3d/Core/internal/VulkanCpp/VulkanLogicalDevice.cpp +++ b/src/engine3d/Core/internal/VulkanCpp/VulkanLogicalDevice.cpp @@ -1,4 +1,4 @@ -#include +#include #include namespace engine3d::vk{ diff --git a/src/engine3d/Core/internal/VulkanCpp/VulkanPhysicalDevice.cpp b/src/engine3d/Core/internal/VulkanCpp/VulkanPhysicalDevice.cpp index 3cece88..278aa62 100644 --- a/src/engine3d/Core/internal/VulkanCpp/VulkanPhysicalDevice.cpp +++ b/src/engine3d/Core/internal/VulkanCpp/VulkanPhysicalDevice.cpp @@ -1,5 +1,6 @@ -#include -#include +#include "EngineLogger.hpp" +#include +#include #include #include @@ -19,20 +20,15 @@ namespace engine3d::vk{ VulkanPhysicalDevice::VulkanPhysicalDevice(){ - // printf("==================================================\n"); - // printf("==================================================\n"); - // printf("==================================================\n"); - // printf("VULKAN PHYSICAL DEVICE CONSTRUCTED\n"); - // printf("At before get_available_devices()\n"); - - // printf("After before get_available_devices()\n"); - // ConsoleLogError("VULKAN PHYSICAL DEVICE CONSTRUCTED!\n"); auto& instance = Vulkan::GetVkInstance(); std::vector devices = get_available_devices(); // printf("available devices size() = %zu\n", devices.size()); uint32_t gpu_count = devices.size(); - + + //! @note Validating our physical device is a discrete GPU. + //! @note Using our discrete GPU that has been found on our machine. + //! @note vkGetPhysicalDeviceProperties is how we get information about our physical device. for(VkPhysicalDevice device : devices){ vkGetPhysicalDeviceProperties(device, &m_PhysicalDeviceProperties); @@ -47,18 +43,21 @@ namespace engine3d::vk{ } m_PhysicalDeviceHandler = m_SelectedPhysicalDevice; - + vkGetPhysicalDeviceFeatures(m_PhysicalDeviceHandler, &m_PhysicalDeviceFeatures); vkGetPhysicalDeviceMemoryProperties(m_PhysicalDeviceHandler, &m_PhysicalMemoryProperties); - + + //! @note This is how we know what queue families are available to us by checking through our physical devices. uint32_t queue_family_count = 0; vkGetPhysicalDeviceQueueFamilyProperties(m_PhysicalDeviceHandler, &queue_family_count, nullptr); + /* printf("queue_family_count === %i\n", queue_family_count); */ // assert(queue_family_count > 0); if(queue_family_count <= 0) throw std::runtime_error("queue_family_count === 0"); m_QueueFamilyProperties.resize(queue_family_count); vkGetPhysicalDeviceQueueFamilyProperties(m_PhysicalDeviceHandler, &queue_family_count, m_QueueFamilyProperties.data()); // reads in the queue family properties from our physical devices - + + //! @note Validating our extensions and getting the extensinos that we support. uint32_t extension_count = 0; vkEnumerateDeviceExtensionProperties(m_PhysicalDeviceHandler, nullptr, &extension_count, nullptr); // just used to read how many extensions are available. @@ -87,6 +86,7 @@ namespace engine3d::vk{ m_QueueIndices = GetQueueFamilyIndices(requested_queue_t); // VK_QUEUE_GRAPHICS_BIT + //! @note Checking queue family for graphics operations. ( Such as vkCmdDraw*(...) ) if(requested_queue_t & VK_QUEUE_GRAPHICS_BIT){ VkDeviceQueueCreateInfo createInfo{ .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, @@ -98,6 +98,7 @@ namespace engine3d::vk{ } // VK_QUEUE_COMPUTE_BIT + //! @note Specifies queues in this queue family support compute operations. if(requested_queue_t & VK_QUEUE_COMPUTE_BIT){ if (m_QueueIndices.Compute != m_QueueIndices.Graphics){ // If compute family index differs, we need an additional queue create info for the compute queue @@ -110,7 +111,9 @@ namespace engine3d::vk{ m_DeviceQueueCreateInfos.push_back(createInfo); } } - + + // VK_QUEUE_TRANSFER_BIT + //! @note specifies queues in this family only has support for transfer operations. if(requested_queue_t & VK_QUEUE_TRANSFER_BIT){ if((m_QueueIndices.Transfer != m_QueueIndices.Graphics) && (m_QueueIndices.Transfer != m_QueueIndices.Compute)){ // If compute family index differs, we need an additional queue create info for the compute queue @@ -208,7 +211,7 @@ namespace engine3d::vk{ bool VulkanPhysicalDevice::IsExtensionSupported(const std::string& ext_name){ return m_SupportedExtensions.find(ext_name) != m_SupportedExtensions.end(); } - + std::vector VulkanPhysicalDevice::get_available_devices(){ uint32_t gpu_devices_count = 0; printf("Before enumerating physical devices\n"); @@ -240,4 +243,4 @@ namespace engine3d::vk{ VkPhysicalDevice& VulkanPhysicalDevice::GetVkPhysicalDevice(){ return m_PhysicalDeviceHandler; } VkFormat VulkanPhysicalDevice::GetDepthFormat(){ return SearchAvailableDepthFormat(); } -}; \ No newline at end of file +}; diff --git a/src/engine3d/Core/internal/VulkanCpp/VulkanSwapchain.cpp b/src/engine3d/Core/internal/VulkanCpp/VulkanSwapchain.cpp index 471c2de..562207e 100644 --- a/src/engine3d/Core/internal/VulkanCpp/VulkanSwapchain.cpp +++ b/src/engine3d/Core/internal/VulkanCpp/VulkanSwapchain.cpp @@ -1,8 +1,8 @@ -#include "EngineLogger.h" +#include "EngineLogger.hpp" #include "Renderer/Renderer.hpp" -#include "internal/VulkanCpp/Vulkan.h" -#include "internal/VulkanCpp/VulkanDevice.h" -#include +#include "internal/VulkanCpp/Vulkan.hpp" +#include "internal/VulkanCpp/VulkanDevice.hpp" +#include #include @@ -22,6 +22,7 @@ #include #endif +#include static PFN_vkGetPhysicalDeviceSurfaceSupportKHR fpGetPhysicalDeviceSurfaceSupportKHR; static PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR fpGetPhysicalDeviceSurfaceCapabilitiesKHR; @@ -29,13 +30,21 @@ static PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR fpGetPhysicalDeviceSurfaceC namespace engine3d::vk{ VulkanSwapchain::VulkanSwapchain(GLFWwindow* p_WindowHandler, bool p_VSync){ + ConsoleLogInfo("Initializing VulkanSwapchain!!!!"); m_VSync = p_VSync; glfwCreateWindowSurface(Vulkan::GetVkInstance(), p_WindowHandler, nullptr, &m_Surface); - auto physical_device = VulkanDevice::GetPhysicalDevice().GetVkPhysicalDevice(); + auto& physical_device = VulkanDevice::GetPhysicalDevice().GetVkPhysicalDevice(); + if(physical_device == VK_NULL_HANDLE){ + /* printf("physical_device === nullptr~\n"); */ + ConsoleLogWarn("physical_device === VK_NULL_HANDLE\n"); + } + uint32_t queue_count = 0; - // vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &queue_count, nullptr); + vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &queue_count, nullptr); + /* printf("queue_count = %i\n", queue_count); */ + // assert(queue_count >= 1); // if(queue_count >= 1){ // ConsoleLogWarn("Queue Count >= 1"); @@ -450,4 +459,4 @@ namespace engine3d::vk{ // m_GraphicsMutex.unlock(); // } } -}; \ No newline at end of file +}; diff --git a/src/engine3d/Core/internal/VulkanCpp/VulkanWindow.cpp b/src/engine3d/Core/internal/VulkanCpp/VulkanWindow.cpp index 3cdb15e..39e19d4 100644 --- a/src/engine3d/Core/internal/VulkanCpp/VulkanWindow.cpp +++ b/src/engine3d/Core/internal/VulkanCpp/VulkanWindow.cpp @@ -1,6 +1,6 @@ -#include "internal/VulkanCpp/VulkanDevice.h" -#include -#include +#include +#include +#include #include #include @@ -36,8 +36,6 @@ namespace engine3d::vk{ if(res != VK_SUCCESS){ throw std::runtime_error("glfwCreateWindowSurface() failed error number: =====> " + std::to_string(res)); } - - m_CurrentWindowSwapchain = new VulkanSwapchain(m_Window, false); m_IsCurrentWindowActive = true; } @@ -59,4 +57,4 @@ namespace engine3d::vk{ uint32_t VulkanWindow::Height() const{ return m_Height; } std::string VulkanWindow::Title() const{ return m_Title; } -}; \ No newline at end of file +}; diff --git a/src/engine3d/Core/platforms/win32.cpp b/src/engine3d/Core/platforms/win32.cpp index 418f26e..5cbef26 100644 --- a/src/engine3d/Core/platforms/win32.cpp +++ b/src/engine3d/Core/platforms/win32.cpp @@ -1,8 +1,8 @@ -#include "Core/EngineLogger.h" -#include -#include +#include +#include +#include -#include +#include extern engine3d::ApplicationInstance* engine3d::InitializeApplication(); @@ -14,4 +14,4 @@ int Main(int argc, char** argv){ engine3d::ApplicationInstance* app = engine3d::InitializeApplication(); app->ExecuteApplicationMainloop(); return 0; -} \ No newline at end of file +} diff --git a/test_package/Application.cpp b/test_package/Application.cpp index 20b974c..eea3926 100644 --- a/test_package/Application.cpp +++ b/test_package/Application.cpp @@ -1,4 +1,4 @@ -#include "Application.h" +#include "Application.hpp" namespace engine3d{ TestbedApplication::TestbedApplication(const std::string& p_DebugName) : ApplicationInstance(p_DebugName){ diff --git a/test_package/Application.h b/test_package/Application.hpp similarity index 84% rename from test_package/Application.h rename to test_package/Application.hpp index 33b4d00..cab0f36 100644 --- a/test_package/Application.h +++ b/test_package/Application.hpp @@ -1,4 +1,4 @@ -#include +#include #include namespace engine3d{ diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt index c911fae..9eafbe9 100644 --- a/test_package/CMakeLists.txt +++ b/test_package/CMakeLists.txt @@ -4,7 +4,7 @@ project(example CXX) find_package(Vulkan REQUIRED) find_package(engine3d CONFIG REQUIRED) -add_executable(example Application.h Application.cpp) +add_executable(example Application.hpp Application.cpp) target_link_libraries(${PROJECT_NAME} Vulkan::Vulkan