diff --git a/src/Engine/Graphics/RenderTarget.h b/src/Engine/Graphics/RenderTarget.h index 114ce15..e74365d 100644 --- a/src/Engine/Graphics/RenderTarget.h +++ b/src/Engine/Graphics/RenderTarget.h @@ -95,6 +95,7 @@ public: RenderTargetLayout(Array inputAttachments, Array colorAttachments, PRenderTargetAttachment depthAttachment); Array inputAttachments; Array colorAttachments; + Array resolveAttachments; PRenderTargetAttachment depthAttachment; uint32 width; uint32 height; diff --git a/src/Engine/Graphics/Vulkan/Graphics.cpp b/src/Engine/Graphics/Vulkan/Graphics.cpp index 7d8721f..5fbd3f4 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.cpp +++ b/src/Engine/Graphics/Vulkan/Graphics.cpp @@ -387,9 +387,9 @@ void Graphics::pickPhysicalDevice() if (Gfx::useMeshShading) { uint32 count = 0; - vkEnumerateDeviceExtensionProperties(physicalDevice, VK_EXT_MESH_SHADER_EXTENSION_NAME, &count, nullptr); + vkEnumerateDeviceExtensionProperties(physicalDevice, NULL, &count, nullptr); Array extensionProps(count); - vkEnumerateDeviceExtensionProperties(physicalDevice, VK_EXT_MESH_SHADER_EXTENSION_NAME, &count, extensionProps.data()); + vkEnumerateDeviceExtensionProperties(physicalDevice, NULL, &count, extensionProps.data()); for (size_t i = 0; i < count; ++i) { if (std::strcmp(VK_EXT_MESH_SHADER_EXTENSION_NAME, extensionProps[i].extensionName) == 0) @@ -515,7 +515,7 @@ void Graphics::createDevice(GraphicsInitializer initializer) if (supportMeshShading()) { descriptorIndexing.pNext = &enabledMeshShaderFeatures; - initializer.deviceExtensions.add("VK_EXT_mesh_shader"); + initializer.deviceExtensions.add(VK_EXT_MESH_SHADER_EXTENSION_NAME); } VkDeviceCreateInfo deviceInfo = { .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, diff --git a/src/Engine/Graphics/Vulkan/Window.cpp b/src/Engine/Graphics/Vulkan/Window.cpp index dbd85cb..61ab2db 100644 --- a/src/Engine/Graphics/Vulkan/Window.cpp +++ b/src/Engine/Graphics/Vulkan/Window.cpp @@ -17,37 +17,37 @@ double Gfx::getCurrentFrameDelta() void glfwKeyCallback(GLFWwindow* handle, int key, int, int action, int modifier) { Window* window = (Window*)glfwGetWindowUserPointer(handle); - window->keyCallback((KeyCode)key, (InputAction)action, (KeyModifier)modifier); + window->keyPress((KeyCode)key, (InputAction)action, (KeyModifier)modifier); } void glfwMouseMoveCallback(GLFWwindow* handle, double xpos, double ypos) { Window* window = (Window*)glfwGetWindowUserPointer(handle); - window->mouseMoveCallback(xpos, ypos); + window->mouseMove(xpos, ypos); } void glfwMouseButtonCallback(GLFWwindow* handle, int button, int action, int modifier) { Window* window = (Window*)glfwGetWindowUserPointer(handle); - window->mouseButtonCallback((MouseButton)button, (InputAction)action, (KeyModifier)modifier); + window->mouseButton((MouseButton)button, (InputAction)action, (KeyModifier)modifier); } void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset) { Window* window = (Window*)glfwGetWindowUserPointer(handle); - window->scrollCallback(xoffset, yoffset); + window->scroll(xoffset, yoffset); } void glfwFileCallback(GLFWwindow* handle, int count, const char** paths) { Window* window = (Window*)glfwGetWindowUserPointer(handle); - window->fileCallback(count, paths); + window->fileDrop(count, paths); } void glfwCloseCallback(GLFWwindow* handle) { Window* window = (Window*)glfwGetWindowUserPointer(handle); - window->closeCallback(); + window->close(); } void glfwResizeCallback(GLFWwindow* handle, int width, int height) { @@ -171,6 +171,41 @@ void Window::setCloseCallback(std::function callback) closeCallback = callback; } +void Seele::Vulkan::Window::setResizeCallback(std::function callback) +{ + resizeCallback = callback; +} + +void Window::keyPress(KeyCode code, InputAction action, KeyModifier modifier) +{ + keyCallback(code, action, modifier); +} + +void Window::mouseMove(double x, double y) +{ + mouseMoveCallback(x, y); +} + +void Window::mouseButton(MouseButton button, InputAction action, KeyModifier modifier) +{ + mouseButtonCallback(button, action, modifier); +} + +void Window::scroll(double x, double y) +{ + scrollCallback(x, y); +} + +void Window::fileDrop(int num, const char** files) +{ + fileCallback(num, files); +} + +void Window::close() +{ + closeCallback(); +} + void Window::resize(int width, int height) { querySurface(); @@ -181,6 +216,7 @@ void Window::resize(int width, int height) framebufferWidth = extent.width; framebufferHeight = extent.height; createSwapChain(); + resizeCallback(width, height); } void Window::querySurface() diff --git a/src/Engine/Graphics/Vulkan/Window.h b/src/Engine/Graphics/Vulkan/Window.h index 198abfb..8b24376 100644 --- a/src/Engine/Graphics/Vulkan/Window.h +++ b/src/Engine/Graphics/Vulkan/Window.h @@ -23,14 +23,15 @@ public: virtual void setScrollCallback(std::function callback) override; virtual void setFileCallback(std::function callback) override; virtual void setCloseCallback(std::function callback); + virtual void setResizeCallback(std::function callback) override; + + void keyPress(KeyCode code, InputAction action, KeyModifier modifier); + void mouseMove(double x, double y); + void mouseButton(MouseButton button, InputAction action, KeyModifier modifier); + void scroll(double x, double y); + void fileDrop(int num, const char** files); + void close(); void resize(int width, int height); - - std::function keyCallback; - std::function mouseMoveCallback; - std::function mouseButtonCallback; - std::function scrollCallback; - std::function fileCallback; - std::function closeCallback; protected: void querySurface(); void chooseSwapSurfaceFormat(); @@ -57,6 +58,14 @@ protected: StaticArray renderingDoneSemaphores; uint32 currentImageIndex = 0; uint32 currentSemaphoreIndex = 0; + + std::function keyCallback; + std::function mouseMoveCallback; + std::function mouseButtonCallback; + std::function scrollCallback; + std::function fileCallback; + std::function closeCallback; + std::function resizeCallback; }; DEFINE_REF(Window) diff --git a/src/Engine/Graphics/Window.h b/src/Engine/Graphics/Window.h index 32e7faa..b5272d7 100644 --- a/src/Engine/Graphics/Window.h +++ b/src/Engine/Graphics/Window.h @@ -21,6 +21,7 @@ public: virtual void setScrollCallback(std::function callback) = 0; virtual void setFileCallback(std::function callback) = 0; virtual void setCloseCallback(std::function callback) = 0; + virtual void setResizeCallback(std::function callback) = 0; constexpr SeFormat getSwapchainFormat() const { return framebufferFormat; @@ -46,7 +47,7 @@ protected: }; DEFINE_REF(Window) - class Viewport +class Viewport { public: Viewport(PWindow owner, const ViewportCreateInfo& createInfo); diff --git a/src/Engine/Math/Math.h b/src/Engine/Math/Math.h index 885473c..722f326 100644 --- a/src/Engine/Math/Math.h +++ b/src/Engine/Math/Math.h @@ -29,28 +29,12 @@ struct Rect //Unsigned int struct URect { - URect() - : size(0, 0), offset(0, 0) - { - } - URect(uint32 sizeX, uint32 sizeY, uint32 offsetX, uint32 offsetY) - : size(sizeX, sizeY), offset(offsetX, offsetY) - { - } - URect(UVector2 size, UVector2 offset) - : size(size), offset(offset) - { - } - bool isEmpty() const - { - return size.x == 0 || size.y == 0; - } - UVector2 size; - UVector2 offset; + UVector2 size = UVector2(0); + UVector2 offset = UVector2(0); }; struct Rect3D { - Vector size; - Vector offset; + Vector size = Vector(0); + Vector offset = Vector(0); }; } // namespace Seele \ No newline at end of file diff --git a/src/Engine/Window/GameView.cpp b/src/Engine/Window/GameView.cpp index 3f4b930..0336786 100644 --- a/src/Engine/Window/GameView.cpp +++ b/src/Engine/Window/GameView.cpp @@ -72,6 +72,14 @@ void GameView::render() renderGraph.render(cam); } +void GameView::applyArea(URect rect) +{ + viewport = graphics->createViewport(owner->getGfxHandle(), ViewportCreateInfo{ + .dimensions = rect, + }); + renderGraph.updateViewport(viewport); +} + void GameView::reloadGame() { gameInterface.reload(AssetRegistry::getInstance()); diff --git a/src/Engine/Window/GameView.h b/src/Engine/Window/GameView.h index 51a79f0..9d88635 100644 --- a/src/Engine/Window/GameView.h +++ b/src/Engine/Window/GameView.h @@ -25,6 +25,7 @@ public: virtual void prepareRender() override; virtual void render() override; + virtual void applyArea(URect rect) override; void reloadGame(); private: diff --git a/src/Engine/Window/View.cpp b/src/Engine/Window/View.cpp index 8a26b0e..ae15c10 100644 --- a/src/Engine/Window/View.cpp +++ b/src/Engine/Window/View.cpp @@ -18,11 +18,6 @@ View::~View() { } -void View::applyArea(URect) -{ - -} - void View::setFocused() { owner->setFocused(this); diff --git a/src/Engine/Window/View.h b/src/Engine/Window/View.h index 81e5a31..207e0ed 100644 --- a/src/Engine/Window/View.h +++ b/src/Engine/Window/View.h @@ -11,17 +11,13 @@ public: View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo, std::string name); virtual ~View(); - // These are called from the view thread, and handle updating game data virtual void beginUpdate() = 0; virtual void update() = 0; - // End frame is called with a lock, so it is safe to write to shared memory virtual void commitUpdate() = 0; - // These are called from the render thread - // prepare render is also locked, so reading from shared memory is also safe virtual void prepareRender() = 0; virtual void render() = 0; - void applyArea(URect area); + virtual void applyArea(URect area) = 0; void setFocused(); const std::string& getName(); diff --git a/src/Engine/Window/Window.cpp b/src/Engine/Window/Window.cpp index bf01e3d..7471abf 100644 --- a/src/Engine/Window/Window.cpp +++ b/src/Engine/Window/Window.cpp @@ -8,6 +8,7 @@ Window::Window(PWindowManager owner, Gfx::OWindow handle) : owner(owner) , gfxHandle(std::move(handle)) { + gfxHandle->setResizeCallback([this](uint32 w, uint32 h) {onResize(w, h); }); } Window::~Window() @@ -57,3 +58,15 @@ void Window::setFocused(PView view) owner->notifyWindowClosed(this); }); } + +void Window::onResize(uint32 width, uint32 height) +{ + for (auto& view : views) + { + // TODO: some sort of layouting algorithm should do this + view->applyArea(URect{ + .size = UVector2(width, height), + .offset = UVector2(0, 0), + }); + } +} diff --git a/src/Engine/Window/Window.h b/src/Engine/Window/Window.h index cd8db50..85a9246 100644 --- a/src/Engine/Window/Window.h +++ b/src/Engine/Window/Window.h @@ -15,13 +15,11 @@ public: void render(); Gfx::PWindow getGfxHandle(); void setFocused(PView view); - + void onResize(uint32 width, uint32 height); protected: PWindowManager owner; Array views; Gfx::OWindow gfxHandle; - - //void viewWorker(size_t viewIndex); }; DEFINE_REF(Window) } // namespace Seele \ No newline at end of file