Window resizing works
This commit is contained in:
@@ -95,6 +95,7 @@ public:
|
|||||||
RenderTargetLayout(Array<PRenderTargetAttachment> inputAttachments, Array<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachment);
|
RenderTargetLayout(Array<PRenderTargetAttachment> inputAttachments, Array<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachment);
|
||||||
Array<PRenderTargetAttachment> inputAttachments;
|
Array<PRenderTargetAttachment> inputAttachments;
|
||||||
Array<PRenderTargetAttachment> colorAttachments;
|
Array<PRenderTargetAttachment> colorAttachments;
|
||||||
|
Array<PRenderTargetAttachment> resolveAttachments;
|
||||||
PRenderTargetAttachment depthAttachment;
|
PRenderTargetAttachment depthAttachment;
|
||||||
uint32 width;
|
uint32 width;
|
||||||
uint32 height;
|
uint32 height;
|
||||||
|
|||||||
@@ -387,9 +387,9 @@ void Graphics::pickPhysicalDevice()
|
|||||||
if (Gfx::useMeshShading)
|
if (Gfx::useMeshShading)
|
||||||
{
|
{
|
||||||
uint32 count = 0;
|
uint32 count = 0;
|
||||||
vkEnumerateDeviceExtensionProperties(physicalDevice, VK_EXT_MESH_SHADER_EXTENSION_NAME, &count, nullptr);
|
vkEnumerateDeviceExtensionProperties(physicalDevice, NULL, &count, nullptr);
|
||||||
Array<VkExtensionProperties> extensionProps(count);
|
Array<VkExtensionProperties> 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)
|
for (size_t i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
if (std::strcmp(VK_EXT_MESH_SHADER_EXTENSION_NAME, extensionProps[i].extensionName) == 0)
|
if (std::strcmp(VK_EXT_MESH_SHADER_EXTENSION_NAME, extensionProps[i].extensionName) == 0)
|
||||||
@@ -515,7 +515,7 @@ void Graphics::createDevice(GraphicsInitializer initializer)
|
|||||||
if (supportMeshShading())
|
if (supportMeshShading())
|
||||||
{
|
{
|
||||||
descriptorIndexing.pNext = &enabledMeshShaderFeatures;
|
descriptorIndexing.pNext = &enabledMeshShaderFeatures;
|
||||||
initializer.deviceExtensions.add("VK_EXT_mesh_shader");
|
initializer.deviceExtensions.add(VK_EXT_MESH_SHADER_EXTENSION_NAME);
|
||||||
}
|
}
|
||||||
VkDeviceCreateInfo deviceInfo = {
|
VkDeviceCreateInfo deviceInfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
||||||
|
|||||||
@@ -17,37 +17,37 @@ double Gfx::getCurrentFrameDelta()
|
|||||||
void glfwKeyCallback(GLFWwindow* handle, int key, int, int action, int modifier)
|
void glfwKeyCallback(GLFWwindow* handle, int key, int, int action, int modifier)
|
||||||
{
|
{
|
||||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
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)
|
void glfwMouseMoveCallback(GLFWwindow* handle, double xpos, double ypos)
|
||||||
{
|
{
|
||||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||||
window->mouseMoveCallback(xpos, ypos);
|
window->mouseMove(xpos, ypos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void glfwMouseButtonCallback(GLFWwindow* handle, int button, int action, int modifier)
|
void glfwMouseButtonCallback(GLFWwindow* handle, int button, int action, int modifier)
|
||||||
{
|
{
|
||||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
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)
|
void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset)
|
||||||
{
|
{
|
||||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||||
window->scrollCallback(xoffset, yoffset);
|
window->scroll(xoffset, yoffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void glfwFileCallback(GLFWwindow* handle, int count, const char** paths)
|
void glfwFileCallback(GLFWwindow* handle, int count, const char** paths)
|
||||||
{
|
{
|
||||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||||
window->fileCallback(count, paths);
|
window->fileDrop(count, paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
void glfwCloseCallback(GLFWwindow* handle)
|
void glfwCloseCallback(GLFWwindow* handle)
|
||||||
{
|
{
|
||||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||||
window->closeCallback();
|
window->close();
|
||||||
}
|
}
|
||||||
void glfwResizeCallback(GLFWwindow* handle, int width, int height)
|
void glfwResizeCallback(GLFWwindow* handle, int width, int height)
|
||||||
{
|
{
|
||||||
@@ -171,6 +171,41 @@ void Window::setCloseCallback(std::function<void()> callback)
|
|||||||
closeCallback = callback;
|
closeCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Seele::Vulkan::Window::setResizeCallback(std::function<void(uint32, uint32)> 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)
|
void Window::resize(int width, int height)
|
||||||
{
|
{
|
||||||
querySurface();
|
querySurface();
|
||||||
@@ -181,6 +216,7 @@ void Window::resize(int width, int height)
|
|||||||
framebufferWidth = extent.width;
|
framebufferWidth = extent.width;
|
||||||
framebufferHeight = extent.height;
|
framebufferHeight = extent.height;
|
||||||
createSwapChain();
|
createSwapChain();
|
||||||
|
resizeCallback(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::querySurface()
|
void Window::querySurface()
|
||||||
|
|||||||
@@ -23,14 +23,15 @@ public:
|
|||||||
virtual void setScrollCallback(std::function<void(double, double)> callback) override;
|
virtual void setScrollCallback(std::function<void(double, double)> callback) override;
|
||||||
virtual void setFileCallback(std::function<void(int, const char**)> callback) override;
|
virtual void setFileCallback(std::function<void(int, const char**)> callback) override;
|
||||||
virtual void setCloseCallback(std::function<void()> callback);
|
virtual void setCloseCallback(std::function<void()> callback);
|
||||||
|
virtual void setResizeCallback(std::function<void(uint32, uint32)> 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);
|
void resize(int width, int height);
|
||||||
|
|
||||||
std::function<void(KeyCode, InputAction, KeyModifier)> keyCallback;
|
|
||||||
std::function<void(double, double)> mouseMoveCallback;
|
|
||||||
std::function<void(MouseButton, InputAction, KeyModifier)> mouseButtonCallback;
|
|
||||||
std::function<void(double, double)> scrollCallback;
|
|
||||||
std::function<void(int, const char**)> fileCallback;
|
|
||||||
std::function<void()> closeCallback;
|
|
||||||
protected:
|
protected:
|
||||||
void querySurface();
|
void querySurface();
|
||||||
void chooseSwapSurfaceFormat();
|
void chooseSwapSurfaceFormat();
|
||||||
@@ -57,6 +58,14 @@ protected:
|
|||||||
StaticArray<OSemaphore, Gfx::numFramesBuffered> renderingDoneSemaphores;
|
StaticArray<OSemaphore, Gfx::numFramesBuffered> renderingDoneSemaphores;
|
||||||
uint32 currentImageIndex = 0;
|
uint32 currentImageIndex = 0;
|
||||||
uint32 currentSemaphoreIndex = 0;
|
uint32 currentSemaphoreIndex = 0;
|
||||||
|
|
||||||
|
std::function<void(KeyCode, InputAction, KeyModifier)> keyCallback;
|
||||||
|
std::function<void(double, double)> mouseMoveCallback;
|
||||||
|
std::function<void(MouseButton, InputAction, KeyModifier)> mouseButtonCallback;
|
||||||
|
std::function<void(double, double)> scrollCallback;
|
||||||
|
std::function<void(int, const char**)> fileCallback;
|
||||||
|
std::function<void()> closeCallback;
|
||||||
|
std::function<void(uint32, uint32)> resizeCallback;
|
||||||
};
|
};
|
||||||
DEFINE_REF(Window)
|
DEFINE_REF(Window)
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public:
|
|||||||
virtual void setScrollCallback(std::function<void(double, double)> callback) = 0;
|
virtual void setScrollCallback(std::function<void(double, double)> callback) = 0;
|
||||||
virtual void setFileCallback(std::function<void(int, const char**)> callback) = 0;
|
virtual void setFileCallback(std::function<void(int, const char**)> callback) = 0;
|
||||||
virtual void setCloseCallback(std::function<void()> callback) = 0;
|
virtual void setCloseCallback(std::function<void()> callback) = 0;
|
||||||
|
virtual void setResizeCallback(std::function<void(uint32, uint32)> callback) = 0;
|
||||||
constexpr SeFormat getSwapchainFormat() const
|
constexpr SeFormat getSwapchainFormat() const
|
||||||
{
|
{
|
||||||
return framebufferFormat;
|
return framebufferFormat;
|
||||||
@@ -46,7 +47,7 @@ protected:
|
|||||||
};
|
};
|
||||||
DEFINE_REF(Window)
|
DEFINE_REF(Window)
|
||||||
|
|
||||||
class Viewport
|
class Viewport
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Viewport(PWindow owner, const ViewportCreateInfo& createInfo);
|
Viewport(PWindow owner, const ViewportCreateInfo& createInfo);
|
||||||
|
|||||||
+4
-20
@@ -29,28 +29,12 @@ struct Rect
|
|||||||
//Unsigned int
|
//Unsigned int
|
||||||
struct URect
|
struct URect
|
||||||
{
|
{
|
||||||
URect()
|
UVector2 size = UVector2(0);
|
||||||
: size(0, 0), offset(0, 0)
|
UVector2 offset = UVector2(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;
|
|
||||||
};
|
};
|
||||||
struct Rect3D
|
struct Rect3D
|
||||||
{
|
{
|
||||||
Vector size;
|
Vector size = Vector(0);
|
||||||
Vector offset;
|
Vector offset = Vector(0);
|
||||||
};
|
};
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
@@ -72,6 +72,14 @@ void GameView::render()
|
|||||||
renderGraph.render(cam);
|
renderGraph.render(cam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameView::applyArea(URect rect)
|
||||||
|
{
|
||||||
|
viewport = graphics->createViewport(owner->getGfxHandle(), ViewportCreateInfo{
|
||||||
|
.dimensions = rect,
|
||||||
|
});
|
||||||
|
renderGraph.updateViewport(viewport);
|
||||||
|
}
|
||||||
|
|
||||||
void GameView::reloadGame()
|
void GameView::reloadGame()
|
||||||
{
|
{
|
||||||
gameInterface.reload(AssetRegistry::getInstance());
|
gameInterface.reload(AssetRegistry::getInstance());
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public:
|
|||||||
|
|
||||||
virtual void prepareRender() override;
|
virtual void prepareRender() override;
|
||||||
virtual void render() override;
|
virtual void render() override;
|
||||||
|
virtual void applyArea(URect rect) override;
|
||||||
|
|
||||||
void reloadGame();
|
void reloadGame();
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -18,11 +18,6 @@ View::~View()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::applyArea(URect)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::setFocused()
|
void View::setFocused()
|
||||||
{
|
{
|
||||||
owner->setFocused(this);
|
owner->setFocused(this);
|
||||||
|
|||||||
@@ -11,17 +11,13 @@ public:
|
|||||||
View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo, std::string name);
|
View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo, std::string name);
|
||||||
virtual ~View();
|
virtual ~View();
|
||||||
|
|
||||||
// These are called from the view thread, and handle updating game data
|
|
||||||
virtual void beginUpdate() = 0;
|
virtual void beginUpdate() = 0;
|
||||||
virtual void update() = 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;
|
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 prepareRender() = 0;
|
||||||
virtual void render() = 0;
|
virtual void render() = 0;
|
||||||
void applyArea(URect area);
|
virtual void applyArea(URect area) = 0;
|
||||||
void setFocused();
|
void setFocused();
|
||||||
|
|
||||||
const std::string& getName();
|
const std::string& getName();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ Window::Window(PWindowManager owner, Gfx::OWindow handle)
|
|||||||
: owner(owner)
|
: owner(owner)
|
||||||
, gfxHandle(std::move(handle))
|
, gfxHandle(std::move(handle))
|
||||||
{
|
{
|
||||||
|
gfxHandle->setResizeCallback([this](uint32 w, uint32 h) {onResize(w, h); });
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::~Window()
|
Window::~Window()
|
||||||
@@ -57,3 +58,15 @@ void Window::setFocused(PView view)
|
|||||||
owner->notifyWindowClosed(this);
|
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),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,13 +15,11 @@ public:
|
|||||||
void render();
|
void render();
|
||||||
Gfx::PWindow getGfxHandle();
|
Gfx::PWindow getGfxHandle();
|
||||||
void setFocused(PView view);
|
void setFocused(PView view);
|
||||||
|
void onResize(uint32 width, uint32 height);
|
||||||
protected:
|
protected:
|
||||||
PWindowManager owner;
|
PWindowManager owner;
|
||||||
Array<PView> views;
|
Array<PView> views;
|
||||||
Gfx::OWindow gfxHandle;
|
Gfx::OWindow gfxHandle;
|
||||||
|
|
||||||
//void viewWorker(size_t viewIndex);
|
|
||||||
};
|
};
|
||||||
DEFINE_REF(Window)
|
DEFINE_REF(Window)
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
Reference in New Issue
Block a user