Screw rendergraphs (for now)

This commit is contained in:
Dynamitos
2021-10-01 19:55:04 +02:00
parent bd739068d6
commit 5dfc8300c5
25 changed files with 222 additions and 226 deletions
View File
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include "View.h"
namespace Seele
{
// A frame is the mutable data needed to
// process a time step for the game updates
// It contains all the game update relevant data
// and is handed over to the renderer for read only processing
// If the game loop runs faster than the renderer, the renderer
// simply discards old Frames and starts working on the more recent ones
// if the game loop runs slower than the renderer (bad), the renderer has to wait
struct Frame
{
uint64 frameNumber;
Array<PViewFrame> viewFrame;
};
} // namespace Seele
+13 -5
View File
@@ -5,11 +5,8 @@ using namespace Seele;
InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo)
: View(graphics, window, createInfo)
, renderGraph(UIPass(graphics, viewport, new Gfx::SwapchainAttachment(window->getGfxHandle())))
{
renderGraph = new RenderGraph();
Gfx::PRenderTargetAttachment attachment = new Gfx::SwapchainAttachment(window->getGfxHandle());
renderGraph->addRenderPass(new UIPass(renderGraph, graphics, viewport, attachment));
renderGraph->setup();
}
InspectorView::~InspectorView()
@@ -20,12 +17,23 @@ void InspectorView::beginFrame()
{
}
void InspectorView::render()
void InspectorView::update()
{
}
void InspectorView::endFrame()
{
}
void InspectorView::prepareRender()
{
}
void InspectorView::render()
{
}
void InspectorView::keyCallback(KeyCode code, InputAction action, KeyModifier modifier)
+11 -11
View File
@@ -7,24 +7,24 @@
namespace Seele
{
DECLARE_REF(Actor)
class InspectorViewFrame : public ViewFrame
{
public:
protected:
const UI::RenderHierarchy hierarchy;
};
class InspectorView : public View
{
public:
InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo);
virtual ~InspectorView();
virtual void beginFrame();
virtual void render();
virtual void endFrame();
void selectActor();
virtual void beginFrame() override;
virtual void update() override;
virtual void endFrame() override;
virtual void prepareRender() override;
virtual void render() override;
void selectActor();
protected:
UIPass renderGraph;
UIPassData uiPassData;
UI::PPanel rootPanel;
PActor selectedActor;
+29 -9
View File
@@ -3,23 +3,18 @@
#include "Window.h"
#include "Scene/Actor/CameraActor.h"
#include "Scene/Components/CameraComponent.h"
#include "Graphics/RenderPass/DepthPrepass.h"
#include "Graphics/RenderPass/LightCullingPass.h"
#include "Graphics/RenderPass/BasePass.h"
using namespace Seele;
Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo)
: View(graphics, owner, createInfo)
, activeCamera(new CameraActor())
, depthPrepass(DepthPrepass(graphics, viewport, activeCamera))
, lightCullingPass(LightCullingPass(graphics, viewport, activeCamera))
, basePass(BasePass(graphics, viewport, activeCamera))
{
scene = new Scene(graphics);
activeCamera = new CameraActor();
scene->addActor(activeCamera);
renderGraph = new RenderGraph();
renderGraph->addRenderPass(new DepthPrepass(renderGraph, scene, graphics, viewport, activeCamera));
renderGraph->addRenderPass(new LightCullingPass(renderGraph, scene, graphics, viewport, activeCamera));
renderGraph->addRenderPass(new BasePass(renderGraph, scene, graphics, viewport, activeCamera));
renderGraph->setup();
}
Seele::SceneView::~SceneView()
@@ -32,6 +27,31 @@ void SceneView::beginFrame()
scene->tick(Gfx::currentFrameDelta);
}
void SceneView::update()
{
}
void SceneView::endFrame()
{
depthPrepassData.staticDrawList = scene->getStaticMeshes();
lightCullingPassData.lightEnv = scene->getLightBuffer();
basePassData.staticDrawList = scene->getStaticMeshes();
}
void SceneView::prepareRender()
{
depthPrepass.updateViewFrame(depthPrepassData);
lightCullingPass.updateViewFrame(lightCullingPassData);
basePass.updateViewFrame(basePassData);
}
void SceneView::render()
{
depthPrepass.render();
lightCullingPass.render();
basePass.render();
}
void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier)
{
if(action != InputAction::RELEASE)
+17 -8
View File
@@ -1,28 +1,37 @@
#pragma once
#include "View.h"
#include "Graphics/RenderPass/DepthPrepass.h"
#include "Graphics/RenderPass/LightCullingPass.h"
#include "Graphics/RenderPass/BasePass.h"
namespace Seele
{
DECLARE_REF(Scene)
DECLARE_REF(CameraActor)
class SceneViewFrame : public ViewFrame
{
public:
protected:
const PScene scene;
};
DEFINE_REF(SceneViewFrame)
class SceneView : public View
{
public:
SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo);
~SceneView();
virtual void beginFrame() override;
virtual void update() override;
virtual void endFrame() override;
virtual void prepareRender() override;
virtual void render() override;
PScene getScene() const { return scene; }
private:
PScene scene;
PCameraActor activeCamera;
DepthPrepass depthPrepass;
LightCullingPass lightCullingPass;
BasePass basePass;
DepthPrepassData depthPrepassData;
LightCullingPassData lightCullingData;
BasePassData basePassData;
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) override;
virtual void mouseMoveCallback(double xPos, double yPos) override;
+5 -16
View File
@@ -2,30 +2,19 @@
#include "Window.h"
#include "Graphics/Graphics.h"
Seele::View::View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &viewportInfo)
using namespace Seele;
View::View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &viewportInfo)
: graphics(graphics), owner(window)
{
viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo);
}
Seele::View::~View()
View::~View()
{
}
void Seele::View::beginFrame()
{
}
void Seele::View::render()
{
}
void Seele::View::endFrame()
{
}
void Seele::View::applyArea(URect area)
void View::applyArea(URect area)
{
}
+12 -14
View File
@@ -5,33 +5,31 @@ namespace Seele
{
DECLARE_REF(Window)
// A ViewFrame is the render relevant data of a View
class ViewFrame
{
public:
protected:
};
DEFINE_REF(ViewFrame)
// A view is a part of the window, which can be anything from a scene viewport to an inspector
class View
{
public:
View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo);
virtual ~View();
virtual void beginFrame();
virtual void render();
virtual void endFrame();
// These are called from the view thread, and handle updating game data
virtual void beginFrame() {}
virtual void update() {}
// End frame is called with a lock, so it is safe to write to shared memory
virtual void endFrame() {}
// These are called from the render thread
// prepare render is also locked, so reading from shared memory is also safe
virtual void prepareRender() {}
virtual void render() {}
void applyArea(URect area);
void setFocused();
protected:
UPViewFrame currentFrame;
Gfx::PGraphics graphics;
Gfx::PViewport viewport;
PWindow owner;
PRenderGraph renderGraph;
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) = 0;
virtual void mouseMoveCallback(double xPos, double yPos) = 0;
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier) = 0;
+4 -10
View File
@@ -16,7 +16,6 @@ void Window::addView(PView view)
{
WindowView* windowView = new WindowView();
windowView->view = view;
windowView->renderGraph = view->renderGraph;
windowView->worker = std::thread(&Window::viewWorker, this, windowView);
views.add(windowView);
}
@@ -26,15 +25,11 @@ void Window::render()
gfxHandle->beginFrame();
for(auto& windowView : views)
{
UPViewFrame frame;
{
std::lock_guard lock(windowView->workerMutex);
frame = std::move(windowView->currentFrame);
}
if(frame != nullptr)
{
windowView->renderGraph->render(std::move(frame));
windowView->view->prepareRender();
}
windowView->view->render();
}
gfxHandle->endFrame();
}
@@ -64,9 +59,8 @@ void Window::viewWorker(WindowView* windowView)
while(true)
{
windowView->view->beginFrame();
windowView->view->render();
windowView->view->endFrame();
windowView->view->update();
std::lock_guard lock(windowView->workerMutex);
windowView->currentFrame = std::move(windowView->view->currentFrame);
windowView->view->endFrame();
}
}
-2
View File
@@ -7,8 +7,6 @@ namespace Seele
struct WindowView
{
PView view;
PRenderGraph renderGraph;
UPViewFrame currentFrame;
std::thread worker;
std::mutex workerMutex;
};