Fixing render layout split
This commit is contained in:
1 parent
28a76ed404
commit
c57ca4efe6
27 files changed
+230
-57
No files matched your search
@@ -59,7 +59,6 @@ int main(int argc, char** argv) {
|
||||
},
|
||||
};
|
||||
OGameView sceneView = new PlayView(graphics, window, application->scene(), sceneViewInfo, useDepthCulling);
|
||||
sceneView->setFocused();
|
||||
|
||||
while (application->isActive()) {
|
||||
application->render();
|
||||
|
||||
@@ -184,9 +184,14 @@ void InspectorView::mouseButtonCallback(MouseButton button, InputAction action,
|
||||
}
|
||||
}
|
||||
|
||||
void InspectorView::scrollCallback(double xOffset, double yOffset) {
|
||||
void InspectorView::scrollCallback(double xPos, double yPos, double xScroll, double yScroll) {
|
||||
// The UI system's scroll() currently takes only the delta (no cursor position);
|
||||
// xPos/yPos are the view-local cursor coords, carried for the future the UI system
|
||||
// needs per-element scroll targeting.
|
||||
(void)xPos;
|
||||
(void)yPos;
|
||||
if (uiPass != nullptr) {
|
||||
uiPass->scroll(Vector2(xOffset, yOffset));
|
||||
uiPass->scroll(Vector2(xScroll, yScroll));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class InspectorView : public View {
|
||||
virtual void keyCallback(KeyCode code, InputAction action, uint32_t modifier) override;
|
||||
virtual void mouseMoveCallback(double xPos, double yPos) override;
|
||||
virtual void mouseButtonCallback(MouseButton button, InputAction action, uint32_t modifier) override;
|
||||
virtual void scrollCallback(double xOffset, double yOffset) override;
|
||||
virtual void scrollCallback(double xPos, double yPos, double xScroll, double yScroll) override;
|
||||
virtual void fileCallback(int count, const char** paths) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -50,6 +50,6 @@ void SceneView::mouseButtonCallback(MouseButton button, InputAction action, KeyM
|
||||
cameraSystem.mouseButtonCallback(button, action);
|
||||
}
|
||||
|
||||
void SceneView::scrollCallback(double, double) {}
|
||||
void SceneView::scrollCallback(double, double, double, double) {}
|
||||
|
||||
void SceneView::fileCallback(int, const char**) {}
|
||||
@@ -32,7 +32,7 @@ class SceneView : public View {
|
||||
virtual void keyCallback(KeyCode code, InputAction action, KeyModifierFlags modifier) override;
|
||||
virtual void mouseMoveCallback(double xPos, double yPos) override;
|
||||
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifierFlags modifier) override;
|
||||
virtual void scrollCallback(double xOffset, double yOffset) override;
|
||||
virtual void scrollCallback(double xPos, double yPos, double xScroll, double yScroll) override;
|
||||
virtual void fileCallback(int count, const char** paths) override;
|
||||
};
|
||||
DEFINE_REF(SceneView)
|
||||
|
||||
@@ -190,7 +190,6 @@ int main(int argc, char** argv) {
|
||||
},
|
||||
};
|
||||
OGameView sceneView = new Editor::PlayView(graphics, window, application->scene(), sceneViewInfo);
|
||||
sceneView->setFocused();
|
||||
OInspectorView inspectorView = new Editor::InspectorView(graphics, window,
|
||||
ViewportCreateInfo{
|
||||
.dimensions =
|
||||
@@ -201,7 +200,6 @@ int main(int argc, char** argv) {
|
||||
},
|
||||
/* scene = */ application->scene());
|
||||
|
||||
inspectorView->setFocused();
|
||||
window->show();
|
||||
while (application->isActive() && getGlobals().running) {
|
||||
application->render();
|
||||
|
||||
@@ -61,6 +61,10 @@ class Graphics {
|
||||
virtual void endRenderPass() = 0;
|
||||
virtual void waitDeviceIdle() = 0;
|
||||
|
||||
// Invalidate per-render-pass framebuffers cached on resize (their attachments are
|
||||
// recreated each resize). Default no-op; the Vulkan backend overrides it.
|
||||
virtual void invalidateFramebuffers() {}
|
||||
|
||||
virtual void executeCommands(ORenderCommand commands) = 0;
|
||||
virtual void executeCommands(Array<ORenderCommand> commands) = 0;
|
||||
virtual void executeCommands(OComputeCommand commands) = 0;
|
||||
|
||||
@@ -29,7 +29,7 @@ class Window : public Gfx::Window {
|
||||
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) override;
|
||||
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) override;
|
||||
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) override;
|
||||
virtual void setScrollCallback(std::function<void(double, double)> callback) override;
|
||||
virtual void setScrollCallback(std::function<void(double x, double y, double xScroll, double yScroll)> callback) override;
|
||||
virtual void setFileCallback(std::function<void(int, const char**)> callback) override;
|
||||
virtual void setCloseCallback(std::function<void()> callback) override;
|
||||
virtual void setResizeCallback(std::function<void(uint32, uint32)> callback) override;
|
||||
@@ -37,7 +37,7 @@ class Window : public Gfx::Window {
|
||||
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 scroll(double x, double y, double xScroll, double yScroll);
|
||||
void fileDrop(int num, const char** files);
|
||||
void close();
|
||||
void resize(int width, int height);
|
||||
@@ -57,7 +57,7 @@ class Window : public Gfx::Window {
|
||||
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(double x, double y, double xScroll, double yScroll)> scrollCallback;
|
||||
std::function<void(int, const char**)> fileCallback;
|
||||
std::function<void()> closeCallback;
|
||||
std::function<void(uint32, uint32)> resizeCallback;
|
||||
|
||||
@@ -44,7 +44,9 @@ void glfwMouseButtonCallback(GLFWwindow* handle, int button, int action, int mod
|
||||
|
||||
void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset) {
|
||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||
window->scroll(xoffset, yoffset);
|
||||
double x = 0.0, y = 0.0;
|
||||
glfwGetCursorPos(handle, &x, &y);
|
||||
window->scroll(x, y, xoffset, yoffset);
|
||||
}
|
||||
|
||||
void glfwFileCallback(GLFWwindow* handle, int count, const char** paths) {
|
||||
@@ -127,7 +129,7 @@ void Window::setMouseMoveCallback(std::function<void(double, double)> callback)
|
||||
|
||||
void Window::setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) { mouseButtonCallback = callback; }
|
||||
|
||||
void Window::setScrollCallback(std::function<void(double, double)> callback) { scrollCallback = callback; }
|
||||
void Window::setScrollCallback(std::function<void(double x, double y, double xScroll, double yScroll)> callback) { scrollCallback = callback; }
|
||||
|
||||
void Window::setFileCallback(std::function<void(int, const char**)> callback) { fileCallback = callback; }
|
||||
|
||||
@@ -141,7 +143,7 @@ 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::scroll(double x, double y, double xScroll, double yScroll) { scrollCallback(x, y, xScroll, yScroll); }
|
||||
|
||||
void Window::fileDrop(int num, const char** files) { fileCallback(num, files); }
|
||||
|
||||
|
||||
@@ -475,32 +475,39 @@ void BasePass::render() {
|
||||
void BasePass::endFrame() {}
|
||||
|
||||
void BasePass::publishOutputs() {
|
||||
// Size intermediates to the *view* (viewport), not the full window framebuffer. A split
|
||||
// window (e.g. the editor's 50/50 game/inspector layout) renders each view into its own
|
||||
// half-width slice; the shared framebuffers must match that slice or the renderArea (the
|
||||
// view's half) ends up a window into an over-wide attachment, clipping the image.
|
||||
uint32 viewWidth = viewport->getWidth();
|
||||
uint32 viewHeight = viewport->getHeight();
|
||||
|
||||
basePassDepth = graphics->createTexture2D(TextureCreateInfo{
|
||||
.format = Gfx::SE_FORMAT_D32_SFLOAT,
|
||||
.width = viewport->getOwner()->getFramebufferWidth(),
|
||||
.height = viewport->getOwner()->getFramebufferHeight(),
|
||||
.width = viewWidth,
|
||||
.height = viewHeight,
|
||||
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
|
||||
});
|
||||
|
||||
basePassColor = graphics->createTexture2D(TextureCreateInfo{
|
||||
.format = Gfx::SE_FORMAT_R32G32B32A32_SFLOAT,
|
||||
.width = viewport->getOwner()->getFramebufferWidth(),
|
||||
.height = viewport->getOwner()->getFramebufferHeight(),
|
||||
.width = viewWidth,
|
||||
.height = viewHeight,
|
||||
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
|
||||
});
|
||||
|
||||
msBasePassDepth = graphics->createTexture2D(TextureCreateInfo{
|
||||
.format = Gfx::SE_FORMAT_D32_SFLOAT,
|
||||
.width = viewport->getOwner()->getFramebufferWidth(),
|
||||
.height = viewport->getOwner()->getFramebufferHeight(),
|
||||
.width = viewWidth,
|
||||
.height = viewHeight,
|
||||
.samples = Gfx::SE_SAMPLE_COUNT_4_BIT,
|
||||
.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | Gfx::SE_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT,
|
||||
});
|
||||
|
||||
msBasePassColor = graphics->createTexture2D(TextureCreateInfo{
|
||||
.format = Gfx::SE_FORMAT_R32G32B32A32_SFLOAT,
|
||||
.width = viewport->getOwner()->getFramebufferWidth(),
|
||||
.height = viewport->getOwner()->getFramebufferHeight(),
|
||||
.width = viewWidth,
|
||||
.height = viewHeight,
|
||||
.samples = Gfx::SE_SAMPLE_COUNT_4_BIT, // todo: configure
|
||||
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | Gfx::SE_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT,
|
||||
});
|
||||
|
||||
@@ -61,7 +61,7 @@ void Command::beginRenderPass(PRenderPass renderPass, PFramebuffer framebuffer)
|
||||
.pNext = nullptr,
|
||||
.renderPass = renderPass->getHandle(),
|
||||
.framebuffer = framebuffer->getHandle(),
|
||||
.renderArea = framebuffer->getRenderArea(),
|
||||
.renderArea = renderPass->getRenderArea(),
|
||||
.clearValueCount = (uint32)renderPass->getClearValueCount(),
|
||||
.pClearValues = renderPass->getClearValues(),
|
||||
};
|
||||
|
||||
@@ -68,7 +68,6 @@ Framebuffer::Framebuffer(PGraphics graphics, PRenderPass renderPass, Gfx::Render
|
||||
.layers = 1,
|
||||
};
|
||||
VK_CHECK(vkCreateFramebuffer(graphics->getDevice(), &createInfo, nullptr, &handle));
|
||||
renderArea = renderPass->getRenderArea();
|
||||
hash = CRC::Calculate(&description, sizeof(FramebufferDescription), CRC::CRC_32());
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,9 @@ class Framebuffer {
|
||||
virtual ~Framebuffer();
|
||||
constexpr VkFramebuffer getHandle() const { return handle; }
|
||||
constexpr uint32 getHash() const { return hash; }
|
||||
constexpr VkRect2D getRenderArea() const { return renderArea; }
|
||||
|
||||
private:
|
||||
uint32 hash;
|
||||
VkRect2D renderArea;
|
||||
PGraphics graphics;
|
||||
VkFramebuffer handle;
|
||||
Gfx::RenderTargetLayout layout;
|
||||
|
||||
@@ -262,6 +262,10 @@ void Graphics::waitDeviceIdle() {
|
||||
getGraphicsCommands()->refreshCommands();
|
||||
}
|
||||
|
||||
void Graphics::invalidateFramebuffers() {
|
||||
allocatedFramebuffers.clear();
|
||||
}
|
||||
|
||||
void Graphics::executeCommands(Gfx::ORenderCommand commands) {
|
||||
Array<Gfx::ORenderCommand> commandArray;
|
||||
commandArray.add(std::move(commands));
|
||||
|
||||
@@ -106,6 +106,7 @@ class Graphics : public Gfx::Graphics {
|
||||
virtual void beginRenderPass(Gfx::PRenderPass renderPass) override;
|
||||
virtual void endRenderPass() override;
|
||||
virtual void waitDeviceIdle() override;
|
||||
virtual void invalidateFramebuffers() override;
|
||||
|
||||
virtual void executeCommands(Gfx::ORenderCommand commands) override;
|
||||
virtual void executeCommands(Array<Gfx::ORenderCommand> commands) override;
|
||||
|
||||
@@ -107,7 +107,12 @@ void glfwMouseButtonCallback(GLFWwindow* handle, int button, int action, int mod
|
||||
|
||||
void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset) {
|
||||
auto* window = static_cast<Seele::Vulkan::Window*>(glfwGetWindowUserPointer(handle));
|
||||
window->scroll(xoffset, yoffset);
|
||||
// GLFW's scroll callback does NOT give the cursor position, but per-view routing
|
||||
// needs it (scroll is spatial, like a mouse move). Query the current cursor pos
|
||||
// synchronously — it is stable between events and this is the only source we have.
|
||||
double x = 0.0, y = 0.0;
|
||||
glfwGetCursorPos(handle, &x, &y);
|
||||
window->scroll(x, y, xoffset, yoffset);
|
||||
}
|
||||
|
||||
void glfwFileCallback(GLFWwindow* handle, int count, const char** paths) {
|
||||
@@ -257,7 +262,7 @@ void Seele::Vulkan::Window::setMouseMoveCallback(std::function<void(double, doub
|
||||
|
||||
void Seele::Vulkan::Window::setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifierFlags)> callback) { mouseButtonCallback = callback; }
|
||||
|
||||
void Seele::Vulkan::Window::setScrollCallback(std::function<void(double, double)> callback) { scrollCallback = callback; }
|
||||
void Seele::Vulkan::Window::setScrollCallback(std::function<void(double x, double y, double xScroll, double yScroll)> callback) { scrollCallback = callback; }
|
||||
|
||||
void Seele::Vulkan::Window::setFileCallback(std::function<void(int, const char**)> callback) { fileCallback = callback; }
|
||||
|
||||
@@ -271,7 +276,7 @@ void Seele::Vulkan::Window::mouseMove(double x, double y) { mouseMoveCallback(x,
|
||||
|
||||
void Seele::Vulkan::Window::mouseButton(MouseButton button, InputAction action, KeyModifierFlags modifier) { mouseButtonCallback(button, action, modifier); }
|
||||
|
||||
void Seele::Vulkan::Window::scroll(double x, double y) { scrollCallback(x, y); }
|
||||
void Seele::Vulkan::Window::scroll(double x, double y, double xScroll, double yScroll) { scrollCallback(x, y, xScroll, yScroll); }
|
||||
|
||||
void Seele::Vulkan::Window::fileDrop(int num, const char** files) { fileCallback(num, files); }
|
||||
|
||||
@@ -291,6 +296,12 @@ void Seele::Vulkan::Window::resize(int width, int height) {
|
||||
framebufferWidth = extent.width;
|
||||
framebufferHeight = extent.height;
|
||||
createSwapChain();
|
||||
// The swapchain size changed and the views will be re-laid-out by resizeCallback below,
|
||||
// which rebuilds each pass's intermediate textures at the new (view) size. Any cached
|
||||
// framebuffers from the previous size are now stale (their handle-only hash also changed)
|
||||
// and must be dropped before the next render, or the pass would bind an over-wide
|
||||
// framebuffer whose renderArea is a sub-slice of it.
|
||||
graphics->invalidateFramebuffers();
|
||||
resizeCallback(width, height);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class Window : public Gfx::Window {
|
||||
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifierFlags)> callback) override;
|
||||
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) override;
|
||||
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifierFlags)> callback) override;
|
||||
virtual void setScrollCallback(std::function<void(double, double)> callback) override;
|
||||
virtual void setScrollCallback(std::function<void(double x, double y, double xScroll, double yScroll)> callback) override;
|
||||
virtual void setFileCallback(std::function<void(int, const char**)> callback) override;
|
||||
virtual void setCloseCallback(std::function<void()> callback) override;
|
||||
virtual void setResizeCallback(std::function<void(uint32, uint32)> callback) override;
|
||||
@@ -28,7 +28,7 @@ class Window : public Gfx::Window {
|
||||
void keyPress(KeyCode code, InputAction action, KeyModifierFlags modifier);
|
||||
void mouseMove(double x, double y);
|
||||
void mouseButton(MouseButton button, InputAction action, KeyModifierFlags modifier);
|
||||
void scroll(double x, double y);
|
||||
void scroll(double x, double y, double xScroll, double yScroll);
|
||||
void fileDrop(int num, const char** files);
|
||||
void close();
|
||||
void resize(int width, int height);
|
||||
@@ -64,7 +64,7 @@ class Window : public Gfx::Window {
|
||||
std::function<void(KeyCode, InputAction, KeyModifierFlags)> keyCallback;
|
||||
std::function<void(double, double)> mouseMoveCallback;
|
||||
std::function<void(MouseButton, InputAction, KeyModifierFlags)> mouseButtonCallback;
|
||||
std::function<void(double, double)> scrollCallback;
|
||||
std::function<void(double x, double y, double xScroll, double yScroll)> scrollCallback;
|
||||
std::function<void(int, const char**)> fileCallback;
|
||||
std::function<void()> closeCallback;
|
||||
std::function<void(uint32, uint32)> resizeCallback;
|
||||
|
||||
@@ -18,7 +18,10 @@ class Window {
|
||||
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifierFlags)> callback) = 0;
|
||||
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) = 0;
|
||||
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifierFlags)> callback) = 0;
|
||||
virtual void setScrollCallback(std::function<void(double, double)> callback) = 0;
|
||||
// The scroll callback carries the cursor POSITION (x, y) in addition to the scroll
|
||||
// deltas. Position is required for per-view routing (a scroll is a spatial event,
|
||||
// exactly like a mouse move).
|
||||
virtual void setScrollCallback(std::function<void(double x, double y, double xScroll, double yScroll)> 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;
|
||||
|
||||
@@ -13,6 +13,13 @@ struct Rect {
|
||||
struct URect {
|
||||
UVector2 size = UVector2(0);
|
||||
UVector2 offset = UVector2(0);
|
||||
// Half-open containment test for a window/client-space point (used for per-view input
|
||||
// hit-testing). Right/bottom edges are exclusive, matching how the column layout in
|
||||
// Window::onResize tiles the window without seams or double-hits at shared edges.
|
||||
bool contains(double x, double y) const {
|
||||
return x >= static_cast<double>(offset.x) && x < static_cast<double>(offset.x + size.x) &&
|
||||
y >= static_cast<double>(offset.y) && y < static_cast<double>(offset.y + size.y);
|
||||
}
|
||||
};
|
||||
struct Rect3D {
|
||||
Vector size = Vector(0);
|
||||
|
||||
@@ -59,7 +59,12 @@ void Application::loadGame(Gfx::PGraphics graphics, const std::filesystem::path&
|
||||
// editor's own systems. This used to live in the editor's main.cpp; it now
|
||||
// lives here so the world has a single owner and a single setup point.
|
||||
interface->getGame()->setupScene(scene_, graph_);
|
||||
graph_->addSystem(new System::KeyboardInput(scene_));
|
||||
// Keep a non-owning handle to the input sink so the focused game view can forward
|
||||
// keyboard/pointer events into it (which then feed Component::KeyboardInput entities).
|
||||
// Ownership stays with graph_ (the OSystemBase in its Array owns the real object).
|
||||
System::OSystemBase sink = new System::KeyboardInput(scene_); // graph_'s Array owns it
|
||||
keyboardInput_ = PKeyboardInput(static_cast<System::KeyboardInput*>(*sink)); // non-owning: graph_'s Array owns it
|
||||
graph_->addSystem(std::move(sink));
|
||||
graph_->addSystem(new System::FluidUpdater(scene_));
|
||||
graph_->addSystem(new System::LightGather(scene_));
|
||||
graph_->addSystem(new System::MeshUpdater(scene_));
|
||||
|
||||
@@ -9,6 +9,10 @@ DECLARE_NAME_REF(Gfx, Graphics)
|
||||
DECLARE_REF(Scene)
|
||||
class Game;
|
||||
class GameInterface;
|
||||
namespace System {
|
||||
class KeyboardInput;
|
||||
}
|
||||
typedef ::Seele::RefPtr<Seele::System::KeyboardInput> PKeyboardInput;
|
||||
|
||||
// The long-lived top-level application object.
|
||||
//
|
||||
@@ -43,6 +47,11 @@ class Application {
|
||||
PScene scene() const { return scene_; }
|
||||
PSystemGraph systemGraph() const { return graph_; }
|
||||
|
||||
// The world's input sink: the System::KeyboardInput that the focused game
|
||||
// view forwards keyboard/pointer events into (which then feed Component::
|
||||
// KeyboardInput entities, e.g. the FlyCam). Null until loadGame() has run.
|
||||
PKeyboardInput keyboardInput() const { return keyboardInput_; }
|
||||
|
||||
// Worldless hosts (e.g. the GPU-timing benchmark, which has no game binary)
|
||||
// build their own world and hand ownership in; the owning members take it via
|
||||
// move so the frame loop can step `graph_` and views can render `scene_`.
|
||||
@@ -53,6 +62,7 @@ class Application {
|
||||
Gfx::PGraphics graphics;
|
||||
OScene scene_;
|
||||
OSystemGraph graph_;
|
||||
PKeyboardInput keyboardInput_ = nullptr; // non-owning: the OSystemBase in graph_ owns it
|
||||
GameInterface* gameInterface = nullptr; // owned by Application (dlclose'd in dtor)
|
||||
};
|
||||
DEFINE_REF(Application)
|
||||
|
||||
@@ -16,6 +16,9 @@ using namespace Seele;
|
||||
|
||||
GameView::GameView(Gfx::PGraphics graphics, PWindow window, PScene scene, const ViewportCreateInfo& createInfo)
|
||||
: View(graphics, window, createInfo, "Game"), graphics(graphics), scene(scene) {
|
||||
// The Application (which owns the world) is reached via the Window that owns this View.
|
||||
// The input sink is null until loadGame() runs; the callbacks above null-guard for that.
|
||||
keyboardSystem = window->app()->keyboardInput();
|
||||
reloadGame();
|
||||
renderGraph.addPass(new CachedDepthPass(graphics, scene));
|
||||
renderGraph.addPass(new DepthCullingPass(graphics, scene));
|
||||
@@ -89,13 +92,28 @@ void GameView::reloadGame() {
|
||||
}
|
||||
|
||||
void GameView::keyCallback(KeyCode code, InputAction action, KeyModifierFlags modifier) {
|
||||
if (keyboardSystem != nullptr) {
|
||||
keyboardSystem->keyCallback(code, action, modifier);
|
||||
}
|
||||
}
|
||||
|
||||
void GameView::mouseMoveCallback(double xPos, double yPos) { }
|
||||
void GameView::mouseMoveCallback(double xPos, double yPos) {
|
||||
if (keyboardSystem != nullptr) {
|
||||
keyboardSystem->mouseCallback(xPos, yPos);
|
||||
}
|
||||
}
|
||||
|
||||
void GameView::mouseButtonCallback(MouseButton button, InputAction action, KeyModifierFlags modifier) {
|
||||
if (keyboardSystem != nullptr) {
|
||||
keyboardSystem->mouseButtonCallback(button, action, modifier);
|
||||
}
|
||||
}
|
||||
|
||||
void GameView::scrollCallback(double xScroll, double yScroll) { }
|
||||
void GameView::scrollCallback(double xPos, double yPos, double xScroll, double yScroll) {
|
||||
// The input sink has no cursor-position concept; it only consumes the deltas.
|
||||
if (keyboardSystem != nullptr) {
|
||||
keyboardSystem->scrollCallback(xScroll, yScroll);
|
||||
}
|
||||
}
|
||||
|
||||
void GameView::fileCallback(int, const char**) {}
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "Scene/Scene.h"
|
||||
#include "System/KeyboardInput.h"
|
||||
#include "Window/View.h"
|
||||
#include "Window/Application.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include "Platform/Windows/GameInterface.h" // TODO
|
||||
@@ -36,7 +37,7 @@ class GameView : public View {
|
||||
virtual void keyCallback(KeyCode code, InputAction action, KeyModifierFlags modifier) override;
|
||||
virtual void mouseMoveCallback(double xPos, double yPos) override;
|
||||
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifierFlags modifier) override;
|
||||
virtual void scrollCallback(double xOffset, double yOffset) override;
|
||||
virtual void scrollCallback(double xPos, double yPos, double xScroll, double yScroll) override;
|
||||
virtual void fileCallback(int count, const char** paths) override;
|
||||
};
|
||||
DEFINE_REF(GameView)
|
||||
|
||||
@@ -8,7 +8,6 @@ View::View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& vi
|
||||
: graphics(graphics), createInfo(viewportInfo), owner(window), name(name) {
|
||||
viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo);
|
||||
owner->addView(this);
|
||||
setFocused();
|
||||
}
|
||||
|
||||
View::~View() {}
|
||||
@@ -20,6 +19,4 @@ void View::resize(URect area) {
|
||||
applyArea(area);
|
||||
}
|
||||
|
||||
void View::setFocused() { owner->setFocused(this); }
|
||||
|
||||
const std::string& View::getName() { return name; }
|
||||
@@ -16,7 +16,6 @@ class View {
|
||||
virtual void prepareRender() = 0;
|
||||
virtual void render() = 0;
|
||||
void resize(URect area);
|
||||
void setFocused();
|
||||
|
||||
const std::string& getName();
|
||||
|
||||
@@ -31,7 +30,7 @@ class View {
|
||||
virtual void keyCallback(KeyCode code, InputAction action, uint32_t modifier) = 0;
|
||||
virtual void mouseMoveCallback(double xPos, double yPos) = 0;
|
||||
virtual void mouseButtonCallback(MouseButton button, InputAction action, uint32_t modifier) = 0;
|
||||
virtual void scrollCallback(double xOffset, double yOffset) = 0;
|
||||
virtual void scrollCallback(double xPos, double yPos, double xScroll, double yScroll) = 0;
|
||||
virtual void fileCallback(int count, const char** paths) = 0;
|
||||
friend class Window;
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ using namespace Seele;
|
||||
|
||||
Window::Window(PApplication owner, Gfx::OWindow handle) : owner(owner), gfxHandle(std::move(handle)) {
|
||||
gfxHandle->setResizeCallback([this](uint32 w, uint32 h) { onResize(w, h); });
|
||||
installInputCallbacks();
|
||||
}
|
||||
|
||||
Window::~Window() {}
|
||||
@@ -28,21 +29,93 @@ void Window::render() {
|
||||
|
||||
Gfx::PWindow Window::getGfxHandle() { return gfxHandle; }
|
||||
|
||||
void Window::setFocused(PView view) {
|
||||
auto keyFunction = std::bind(&View::keyCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
auto mouseMoveFunction = std::bind(&View::mouseMoveCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2);
|
||||
auto mouseButtonFunction =
|
||||
std::bind(&View::mouseButtonCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
auto scrollFunction = std::bind(&View::scrollCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2);
|
||||
auto fileFunction = std::bind(&View::fileCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2);
|
||||
gfxHandle->setKeyCallback(keyFunction);
|
||||
gfxHandle->setMouseMoveCallback(mouseMoveFunction);
|
||||
gfxHandle->setMouseButtonCallback(mouseButtonFunction);
|
||||
gfxHandle->setScrollCallback(scrollFunction);
|
||||
gfxHandle->setFileCallback(fileFunction);
|
||||
gfxHandle->setCloseCallback([this]() {
|
||||
owner->notifyWindowClosed(this);
|
||||
// The one-shot input dispatchers. Bound ONCE in the ctor (not per focus change), so the
|
||||
// GLFW layer always talks to a stable `Window::on*` that routes per-event. This is the
|
||||
// replacement for the old setFocused rebind, which silently made the last-constructed view
|
||||
// the sole input target.
|
||||
void Window::installInputCallbacks() {
|
||||
gfxHandle->setKeyCallback([this](KeyCode code, InputAction action, KeyModifierFlags modifier) { onKeyPress(code, action, modifier); });
|
||||
gfxHandle->setMouseMoveCallback([this](double x, double y) { onMouseMove(x, y); });
|
||||
gfxHandle->setMouseButtonCallback([this](MouseButton button, InputAction action, KeyModifierFlags modifier) { onMouseButton(button, action, modifier); });
|
||||
gfxHandle->setScrollCallback([this](double x, double y, double xScroll, double yScroll) { onScroll(x, y, xScroll, yScroll); });
|
||||
gfxHandle->setFileCallback([this](int count, const char** paths) {
|
||||
// File drops have no cursor-position meaning for per-view routing; deliver to the
|
||||
// keyboard-focus owner (or the first view as a fallback) -- a drop is a user action
|
||||
// aimed at "the app", not a specific pane.
|
||||
if (keyboardFocus != nullptr) {
|
||||
keyboardFocus->fileCallback(count, paths);
|
||||
} else if (views.size() > 0) {
|
||||
views[0]->fileCallback(count, paths);
|
||||
}
|
||||
});
|
||||
gfxHandle->setCloseCallback([this]() {
|
||||
owner->notifyWindowClosed(this);
|
||||
});
|
||||
}
|
||||
|
||||
// SPATIAL pointer routing. `x`/`y` are window/client coords (GLFW gives these). We hit-test
|
||||
// every view's on-screen rect and deliver to the view(s) under the cursor, in view-local
|
||||
// coords (window pos minus the rect origin). The layout is a flat, non-overlapping column
|
||||
// split (see onResize), so at most ONE view can be under the cursor -- but we loop anyway so
|
||||
// a future overlapping layout (dockable panes) keeps working without changes here.
|
||||
//
|
||||
// Coordinate offset is the crux: GLFW hands us window-absolute coords, but views (the UI
|
||||
// system, the 3D camera rig) consume VIEW-LOCAL coords. The old code passed raw window
|
||||
// coords, which only "worked" for the left-anchored (x=0) inspector. The offset below is
|
||||
// what makes per-view input correct for ANY rect origin.
|
||||
void Window::onMouseMove(double x, double y) {
|
||||
lastPointerX = x;
|
||||
lastPointerY = y;
|
||||
for (auto& view : views) {
|
||||
URect rect = view->viewport->getRenderArea();
|
||||
if (rect.contains(x, y)) {
|
||||
view->mouseMoveCallback(x - static_cast<double>(rect.offset.x), y - static_cast<double>(rect.offset.y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Window::onMouseButton(MouseButton button, InputAction action, KeyModifierFlags modifier) {
|
||||
// GLFW gives us the button+action but NOT the cursor position, so we hit-test using the
|
||||
// last known pointer location (kept in sync by onMouseMove). For a column layout the
|
||||
// pointer is effectively static between a move and the next press, so this is accurate.
|
||||
lastClickedView = nullptr;
|
||||
for (auto& view : views) {
|
||||
URect rect = view->viewport->getRenderArea();
|
||||
if (rect.contains(lastPointerX, lastPointerY)) {
|
||||
lastClickedView = view;
|
||||
view->mouseButtonCallback(button, action, modifier);
|
||||
}
|
||||
}
|
||||
// CLICK-TO-FOCUS: a press (not a hover, not a release) inside a view gives that view
|
||||
// the keyboard. This is the only sane keyboard-ownership rule -- the keyboard has no
|
||||
// position, so focus must be an explicit user gesture, never construction order.
|
||||
if (action == InputAction::PRESS && lastClickedView != nullptr) {
|
||||
keyboardFocus = lastClickedView;
|
||||
}
|
||||
}
|
||||
|
||||
void Window::onScroll(double x, double y, double xScroll, double yScroll) {
|
||||
// The scroll callback now carries the cursor position (x, y) — see the Gfx::Window
|
||||
// signature. Scroll is a spatial event, so route it exactly like a mouse move.
|
||||
for (auto& view : views) {
|
||||
URect rect = view->viewport->getRenderArea();
|
||||
if (rect.contains(x, y)) {
|
||||
view->scrollCallback(x - static_cast<double>(rect.offset.x), y - static_cast<double>(rect.offset.y), xScroll, yScroll);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FOCUS-based keyboard routing: a key event has no position, so it goes to exactly one
|
||||
// owner (keyboardFocus) -- the view last clicked into. With no focus, the event is dropped
|
||||
// (better than sending it to an arbitrary view).
|
||||
void Window::onKeyPress(KeyCode code, InputAction action, KeyModifierFlags modifier) {
|
||||
if (keyboardFocus != nullptr) {
|
||||
keyboardFocus->keyCallback(code, action, static_cast<uint32_t>(modifier));
|
||||
}
|
||||
}
|
||||
|
||||
void Window::setKeyboardFocus(PView view) {
|
||||
keyboardFocus = view;
|
||||
}
|
||||
|
||||
void Window::onResize(uint32 width, uint32 height) {
|
||||
|
||||
@@ -14,12 +14,44 @@ class Window {
|
||||
void pollInputs();
|
||||
void render();
|
||||
Gfx::PWindow getGfxHandle();
|
||||
void setFocused(PView view);
|
||||
// The Application that owns this window (non-owning). Views use this to reach
|
||||
// the world's services (e.g. the input sink) without a global lookup.
|
||||
PApplication app() const { return owner; }
|
||||
void setKeyboardFocus(PView view);
|
||||
void onResize(uint32 width, uint32 height);
|
||||
constexpr bool isPaused() const { return gfxHandle->isPaused(); }
|
||||
constexpr bool shouldClose() const { return gfxHandle->shouldClose(); }
|
||||
|
||||
protected:
|
||||
// Install the one-shot per-event dispatchers. `gfxHandle->pollInput()` fires the
|
||||
// GLFW callbacks into these; they route each event to the right view(s). Bound ONCE
|
||||
// here (not per setFocused) so the "last view wins" rebind bug is gone for good.
|
||||
void installInputCallbacks();
|
||||
|
||||
// Pointer (mouse/scroll) routing: SPATIAL. The position is window/client coords; we
|
||||
// hit-test every view's on-screen rect (already valid via onResize) and deliver to the
|
||||
// view(s) under the cursor, in VIEW-LOCAL coords (window pos minus the rect origin).
|
||||
// This is what makes the game viewport and the inspector independently usable.
|
||||
void onMouseMove(double x, double y);
|
||||
void onMouseButton(MouseButton button, InputAction action, KeyModifierFlags modifier);
|
||||
void onScroll(double x, double y, double xScroll, double yScroll);
|
||||
|
||||
// Keyboard routing: FOCUS. A key event has no position, so it goes to exactly one
|
||||
// owner -- keyboardFocus -- which is set by clicking into a view (see onMouseButton).
|
||||
void onKeyPress(KeyCode code, InputAction action, KeyModifierFlags modifier);
|
||||
|
||||
// The window's keyboard focus owner (click-to-focus). Null until the user clicks a
|
||||
// view; a key event with no focus is dropped.
|
||||
PView keyboardFocus = nullptr;
|
||||
|
||||
// GLFW's mouse-button callback does not carry a cursor position, so pointer hit-testing
|
||||
// for press/release uses the last known pointer location (kept fresh by onMouseMove).
|
||||
// For a static column layout the pointer does not move between a move event and the
|
||||
// following press, so this is accurate in practice.
|
||||
double lastPointerX = 0.0;
|
||||
double lastPointerY = 0.0;
|
||||
PView lastClickedView = nullptr;
|
||||
|
||||
PApplication owner;
|
||||
Array<PView> views;
|
||||
Gfx::OWindow gfxHandle;
|
||||
|
||||
Reference in new issue
Block a user