Polymorphic Map and threadpool
This commit is contained in:
@@ -8,49 +8,49 @@
|
||||
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))
|
||||
: 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);
|
||||
scene->addActor(activeCamera);
|
||||
/*AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Diffuse.png");
|
||||
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Lightmap.png");
|
||||
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Face_Diffuse.png");
|
||||
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Hair_Diffuse.png");
|
||||
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Hair_Lightmap.png");
|
||||
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Tex_FaceLightmap.png");
|
||||
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Ayaka.fbx");
|
||||
PPrimitiveComponent ayaka = new PrimitiveComponent(AssetRegistry::findMesh("Ayaka"));
|
||||
ayaka->addWorldTranslation(Vector(0, 0, 100));
|
||||
ayaka->setWorldScale(Vector(0.1f, 0.1f, 0.1f));
|
||||
scene->addPrimitiveComponent(ayaka);*/
|
||||
scene = new Scene(graphics);
|
||||
scene->addActor(activeCamera);
|
||||
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Diffuse.png");
|
||||
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Lightmap.png");
|
||||
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Face_Diffuse.png");
|
||||
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Hair_Diffuse.png");
|
||||
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Hair_Lightmap.png");
|
||||
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Tex_FaceLightmap.png");
|
||||
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Ayaka.fbx");
|
||||
PPrimitiveComponent ayaka = new PrimitiveComponent(AssetRegistry::findMesh("Ayaka"));
|
||||
ayaka->addWorldTranslation(Vector(0, 0, 0));
|
||||
ayaka->setWorldScale(Vector(10, 10, 10));
|
||||
scene->addPrimitiveComponent(ayaka);
|
||||
|
||||
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Ely\\Ely.fbx");
|
||||
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Cube\\cube.obj");
|
||||
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Plane\\plane.fbx");
|
||||
PPrimitiveComponent plane = new PrimitiveComponent(AssetRegistry::findMesh("plane"));
|
||||
plane->setWorldScale(Vector(100, 100, 100));
|
||||
PPrimitiveComponent arissa = new PrimitiveComponent(AssetRegistry::findMesh("Ely"));
|
||||
arissa->addWorldTranslation(Vector(0, 0, 100));
|
||||
arissa->setWorldScale(Vector(0.1f, 0.1f, 0.1f));
|
||||
scene->addPrimitiveComponent(plane);
|
||||
scene->addPrimitiveComponent(arissa);
|
||||
/*AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Ely\\Ely.fbx");
|
||||
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Cube\\cube.obj");
|
||||
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Plane\\plane.fbx");
|
||||
PPrimitiveComponent plane = new PrimitiveComponent(AssetRegistry::findMesh("plane"));
|
||||
plane->setWorldScale(Vector(100, 100, 100));
|
||||
PPrimitiveComponent arissa = new PrimitiveComponent(AssetRegistry::findMesh("Ely"));
|
||||
arissa->addWorldTranslation(Vector(0, 0, 100));
|
||||
arissa->setWorldScale(Vector(0.1f, 0.1f, 0.1f));
|
||||
scene->addPrimitiveComponent(plane);
|
||||
scene->addPrimitiveComponent(arissa);*/
|
||||
|
||||
PRenderGraphResources resources = new RenderGraphResources();
|
||||
depthPrepass.setResources(resources);
|
||||
lightCullingPass.setResources(resources);
|
||||
basePass.setResources(resources);
|
||||
PRenderGraphResources resources = new RenderGraphResources();
|
||||
depthPrepass.setResources(resources);
|
||||
lightCullingPass.setResources(resources);
|
||||
basePass.setResources(resources);
|
||||
|
||||
depthPrepass.publishOutputs();
|
||||
lightCullingPass.publishOutputs();
|
||||
basePass.publishOutputs();
|
||||
depthPrepass.publishOutputs();
|
||||
lightCullingPass.publishOutputs();
|
||||
basePass.publishOutputs();
|
||||
|
||||
depthPrepass.createRenderPass();
|
||||
lightCullingPass.createRenderPass();
|
||||
basePass.createRenderPass();
|
||||
depthPrepass.createRenderPass();
|
||||
lightCullingPass.createRenderPass();
|
||||
basePass.createRenderPass();
|
||||
}
|
||||
|
||||
Seele::SceneView::~SceneView()
|
||||
@@ -59,8 +59,8 @@ Seele::SceneView::~SceneView()
|
||||
|
||||
void SceneView::beginUpdate()
|
||||
{
|
||||
View::beginUpdate();
|
||||
scene->tick(Gfx::currentFrameDelta);
|
||||
View::beginUpdate();
|
||||
scene->tick(Gfx::currentFrameDelta);
|
||||
}
|
||||
|
||||
void SceneView::update()
|
||||
@@ -69,81 +69,81 @@ void SceneView::update()
|
||||
|
||||
void SceneView::commitUpdate()
|
||||
{
|
||||
depthPrepassData.staticDrawList = scene->getStaticMeshes();
|
||||
lightCullingPassData.lightEnv = scene->getLightBuffer();
|
||||
basePassData.staticDrawList = scene->getStaticMeshes();
|
||||
depthPrepassData.staticDrawList = scene->getStaticMeshes();
|
||||
lightCullingPassData.lightEnv = scene->getLightBuffer();
|
||||
basePassData.staticDrawList = scene->getStaticMeshes();
|
||||
}
|
||||
|
||||
void SceneView::prepareRender()
|
||||
{
|
||||
depthPrepass.updateViewFrame(depthPrepassData);
|
||||
lightCullingPass.updateViewFrame(lightCullingPassData);
|
||||
basePass.updateViewFrame(basePassData);
|
||||
depthPrepass.updateViewFrame(depthPrepassData);
|
||||
lightCullingPass.updateViewFrame(lightCullingPassData);
|
||||
basePass.updateViewFrame(basePassData);
|
||||
}
|
||||
|
||||
void SceneView::render()
|
||||
{
|
||||
depthPrepass.beginFrame();
|
||||
lightCullingPass.beginFrame();
|
||||
basePass.beginFrame();
|
||||
depthPrepass.beginFrame();
|
||||
lightCullingPass.beginFrame();
|
||||
basePass.beginFrame();
|
||||
|
||||
depthPrepass.render();
|
||||
lightCullingPass.render();
|
||||
basePass.render();
|
||||
depthPrepass.render();
|
||||
lightCullingPass.render();
|
||||
basePass.render();
|
||||
|
||||
depthPrepass.endFrame();
|
||||
lightCullingPass.endFrame();
|
||||
basePass.endFrame();
|
||||
depthPrepass.endFrame();
|
||||
lightCullingPass.endFrame();
|
||||
basePass.endFrame();
|
||||
}
|
||||
|
||||
void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier)
|
||||
{
|
||||
if(action != InputAction::RELEASE)
|
||||
{
|
||||
if(code == KeyCode::KEY_W)
|
||||
{
|
||||
activeCamera->getCameraComponent()->moveOrigin(1);
|
||||
}
|
||||
if(code == KeyCode::KEY_S)
|
||||
{
|
||||
activeCamera->getCameraComponent()->moveOrigin(-1);
|
||||
}
|
||||
}
|
||||
if(action != InputAction::RELEASE)
|
||||
{
|
||||
if(code == KeyCode::KEY_W)
|
||||
{
|
||||
activeCamera->getCameraComponent()->moveOrigin(1);
|
||||
}
|
||||
if(code == KeyCode::KEY_S)
|
||||
{
|
||||
activeCamera->getCameraComponent()->moveOrigin(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool mouseDown = false;
|
||||
|
||||
void SceneView::mouseMoveCallback(double xPos, double yPos)
|
||||
{
|
||||
static double prevXPos = 0.0f, prevYPos = 0.0f;
|
||||
double deltaX = prevXPos - xPos;
|
||||
double deltaY = prevYPos - yPos;
|
||||
prevXPos = xPos;
|
||||
prevYPos = yPos;
|
||||
if(mouseDown)
|
||||
{
|
||||
activeCamera->getCameraComponent()->mouseMove((float)deltaX, (float)deltaY);
|
||||
}
|
||||
static double prevXPos = 0.0f, prevYPos = 0.0f;
|
||||
double deltaX = prevXPos - xPos;
|
||||
double deltaY = prevYPos - yPos;
|
||||
prevXPos = xPos;
|
||||
prevYPos = yPos;
|
||||
if(mouseDown)
|
||||
{
|
||||
activeCamera->getCameraComponent()->mouseMove((float)deltaX, (float)deltaY);
|
||||
}
|
||||
}
|
||||
|
||||
void SceneView::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier)
|
||||
{
|
||||
if(button == MouseButton::MOUSE_BUTTON_1 && action != InputAction::RELEASE)
|
||||
{
|
||||
mouseDown = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mouseDown = false;
|
||||
}
|
||||
if(button == MouseButton::MOUSE_BUTTON_1 && action != InputAction::RELEASE)
|
||||
{
|
||||
mouseDown = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mouseDown = false;
|
||||
}
|
||||
}
|
||||
|
||||
void SceneView::scrollCallback(double, double yOffset)
|
||||
{
|
||||
activeCamera->getCameraComponent()->mouseScroll(yOffset);
|
||||
activeCamera->getCameraComponent()->mouseScroll(yOffset);
|
||||
}
|
||||
|
||||
void SceneView::fileCallback(int, const char**)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#include "Window.h"
|
||||
#include "WindowManager.h"
|
||||
#include <functional>
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
Window::Window(Gfx::PWindow handle)
|
||||
: gfxHandle(handle)
|
||||
Window::Window(PWindowManager owner, Gfx::PWindow handle)
|
||||
: owner(owner)
|
||||
, gfxHandle(handle)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -20,23 +22,17 @@ void Window::addView(PView view)
|
||||
views.add(windowView);
|
||||
}
|
||||
|
||||
void Window::render()
|
||||
MainJob Window::render()
|
||||
{
|
||||
gfxHandle->beginFrame();
|
||||
for(auto& windowView : views)
|
||||
{
|
||||
windowView->view->beginUpdate();
|
||||
windowView->view->update();
|
||||
{
|
||||
std::unique_lock lock(windowView->workerMutex);
|
||||
windowView->view->commitUpdate();
|
||||
}
|
||||
windowView->updateFinished.raise();
|
||||
{
|
||||
viewWorker(windowView);
|
||||
co_await windowView->updateFinished;
|
||||
{
|
||||
std::unique_lock lock(windowView->workerMutex);
|
||||
windowView->view->prepareRender();
|
||||
}
|
||||
windowView->updateFinished.reset();
|
||||
windowView->view->render();
|
||||
}
|
||||
gfxHandle->endFrame();
|
||||
@@ -59,12 +55,22 @@ void Window::setFocused(PView view)
|
||||
gfxHandle->setMouseButtonCallback(mouseButtonFunction);
|
||||
gfxHandle->setScrollCallback(scrollFunction);
|
||||
gfxHandle->setFileCallback(fileFunction);
|
||||
gfxHandle->setCloseCallback([this](){
|
||||
owner->notifyWindowClosed(this);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void Window::viewWorker(WindowView* windowView)
|
||||
Job Window::viewWorker(WindowView* windowView)
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
windowView->view->beginUpdate();
|
||||
windowView->view->update();
|
||||
{
|
||||
std::unique_lock lock(windowView->workerMutex);
|
||||
windowView->view->commitUpdate();
|
||||
}
|
||||
windowView->updateFinished.raise();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,26 +9,27 @@ struct WindowView
|
||||
{
|
||||
PView view;
|
||||
Event updateFinished;
|
||||
std::thread worker;
|
||||
std::mutex workerMutex;
|
||||
};
|
||||
DEFINE_REF(WindowView)
|
||||
DECLARE_REF(WindowManager)
|
||||
// The logical window, with the graphics proxy
|
||||
class Window
|
||||
{
|
||||
public:
|
||||
Window(Gfx::PWindow handle);
|
||||
Window(PWindowManager owner, Gfx::PWindow handle);
|
||||
~Window();
|
||||
void addView(PView view);
|
||||
void render();
|
||||
MainJob render();
|
||||
Gfx::PWindow getGfxHandle();
|
||||
void setFocused(PView view);
|
||||
|
||||
protected:
|
||||
PWindowManager owner;
|
||||
Array<WindowView*> views;
|
||||
Gfx::PWindow gfxHandle;
|
||||
|
||||
void viewWorker(WindowView* view);
|
||||
Job viewWorker(WindowView* view);
|
||||
};
|
||||
DEFINE_REF(Window)
|
||||
} // namespace Seele
|
||||
@@ -7,21 +7,21 @@ Gfx::PGraphics WindowManager::graphics;
|
||||
|
||||
WindowManager::WindowManager()
|
||||
{
|
||||
graphics = new Vulkan::Graphics();
|
||||
GraphicsInitializer initializer;
|
||||
graphics->init(initializer);
|
||||
TextureCreateInfo info;
|
||||
info.width = 4096;
|
||||
info.height = 4096;
|
||||
Gfx::PTexture2D testTexture = graphics->createTexture2D(info);
|
||||
UniformBufferCreateInfo uniformInitializer;
|
||||
uniformInitializer.resourceData.size = 4096;
|
||||
uniformInitializer.resourceData.data = new uint8[4096];
|
||||
for (int i = 0; i < 4096; ++i)
|
||||
{
|
||||
uniformInitializer.resourceData.data[i] = (uint8)i;
|
||||
}
|
||||
Gfx::PUniformBuffer testUniform = graphics->createUniformBuffer(uniformInitializer);
|
||||
graphics = new Vulkan::Graphics();
|
||||
GraphicsInitializer initializer;
|
||||
graphics->init(initializer);
|
||||
TextureCreateInfo info;
|
||||
info.width = 4096;
|
||||
info.height = 4096;
|
||||
Gfx::PTexture2D testTexture = graphics->createTexture2D(info);
|
||||
UniformBufferCreateInfo uniformInitializer;
|
||||
uniformInitializer.resourceData.size = 4096;
|
||||
uniformInitializer.resourceData.data = new uint8[4096];
|
||||
for (int i = 0; i < 4096; ++i)
|
||||
{
|
||||
uniformInitializer.resourceData.data[i] = (uint8)i;
|
||||
}
|
||||
Gfx::PUniformBuffer testUniform = graphics->createUniformBuffer(uniformInitializer);
|
||||
}
|
||||
|
||||
WindowManager::~WindowManager()
|
||||
@@ -30,8 +30,13 @@ WindowManager::~WindowManager()
|
||||
|
||||
PWindow WindowManager::addWindow(const WindowCreateInfo &createInfo)
|
||||
{
|
||||
Gfx::PWindow handle = graphics->createWindow(createInfo);
|
||||
PWindow window = new Window(handle);
|
||||
windows.add(window);
|
||||
return window;
|
||||
Gfx::PWindow handle = graphics->createWindow(createInfo);
|
||||
PWindow window = new Window(this, handle);
|
||||
windows.add(window);
|
||||
return window;
|
||||
}
|
||||
|
||||
void WindowManager::notifyWindowClosed(PWindow window)
|
||||
{
|
||||
windows.remove(windows.find(window));
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ public:
|
||||
WindowManager();
|
||||
~WindowManager();
|
||||
PWindow addWindow(const WindowCreateInfo &createInfo);
|
||||
void notifyWindowClosed(PWindow window);
|
||||
static Gfx::PGraphics getGraphics()
|
||||
{
|
||||
return graphics;
|
||||
|
||||
Reference in New Issue
Block a user