Window resizing works
This commit is contained in:
@@ -95,6 +95,7 @@ public:
|
||||
RenderTargetLayout(Array<PRenderTargetAttachment> inputAttachments, Array<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachment);
|
||||
Array<PRenderTargetAttachment> inputAttachments;
|
||||
Array<PRenderTargetAttachment> colorAttachments;
|
||||
Array<PRenderTargetAttachment> resolveAttachments;
|
||||
PRenderTargetAttachment depthAttachment;
|
||||
uint32 width;
|
||||
uint32 height;
|
||||
|
||||
@@ -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<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)
|
||||
{
|
||||
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,
|
||||
|
||||
@@ -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<void()> 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)
|
||||
{
|
||||
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()
|
||||
|
||||
@@ -23,14 +23,15 @@ public:
|
||||
virtual void setScrollCallback(std::function<void(double, double)> callback) override;
|
||||
virtual void setFileCallback(std::function<void(int, const char**)> callback) override;
|
||||
virtual void setCloseCallback(std::function<void()> callback);
|
||||
void resize(int width, int height);
|
||||
virtual void setResizeCallback(std::function<void(uint32, uint32)> callback) override;
|
||||
|
||||
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;
|
||||
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);
|
||||
protected:
|
||||
void querySurface();
|
||||
void chooseSwapSurfaceFormat();
|
||||
@@ -57,6 +58,14 @@ protected:
|
||||
StaticArray<OSemaphore, Gfx::numFramesBuffered> renderingDoneSemaphores;
|
||||
uint32 currentImageIndex = 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)
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
virtual void setScrollCallback(std::function<void(double, double)> callback) = 0;
|
||||
virtual void setFileCallback(std::function<void(int, const char**)> callback) = 0;
|
||||
virtual void setCloseCallback(std::function<void()> callback) = 0;
|
||||
virtual void setResizeCallback(std::function<void(uint32, uint32)> callback) = 0;
|
||||
constexpr SeFormat getSwapchainFormat() const
|
||||
{
|
||||
return framebufferFormat;
|
||||
|
||||
+4
-20
@@ -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
|
||||
@@ -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());
|
||||
|
||||
@@ -25,6 +25,7 @@ public:
|
||||
|
||||
virtual void prepareRender() override;
|
||||
virtual void render() override;
|
||||
virtual void applyArea(URect rect) override;
|
||||
|
||||
void reloadGame();
|
||||
private:
|
||||
|
||||
@@ -18,11 +18,6 @@ View::~View()
|
||||
{
|
||||
}
|
||||
|
||||
void View::applyArea(URect)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void View::setFocused()
|
||||
{
|
||||
owner->setFocused(this);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,11 @@ public:
|
||||
void render();
|
||||
Gfx::PWindow getGfxHandle();
|
||||
void setFocused(PView view);
|
||||
|
||||
void onResize(uint32 width, uint32 height);
|
||||
protected:
|
||||
PWindowManager owner;
|
||||
Array<PView> views;
|
||||
Gfx::OWindow gfxHandle;
|
||||
|
||||
//void viewWorker(size_t viewIndex);
|
||||
};
|
||||
DEFINE_REF(Window)
|
||||
} // namespace Seele
|
||||
Reference in New Issue
Block a user