Starting implementation of UI framework

This commit is contained in:
Dynamitos
2021-01-19 15:30:00 +01:00
parent 65caae9e21
commit fb3c66cc4c
57 changed files with 381 additions and 186 deletions
+1 -13
View File
@@ -13,24 +13,12 @@ target_sources(SeeleEngine
RenderCore.cpp
RenderMaterial.h
RenderMaterial.cpp
RenderPath.h
RenderPath.cpp
SceneView.h
SceneView.cpp
SceneRenderPath.h
SceneRenderPath.cpp
ShaderCompiler.h
ShaderCompiler.cpp
View.h
View.cpp
VertexShaderInput.h
VertexShaderInput.cpp
StaticMeshVertexInput.h
StaticMeshVertexInput.cpp
Window.cpp
Window.h
WindowManager.h
WindowManager.cpp)
StaticMeshVertexInput.cpp)
add_subdirectory(RenderPass/)
add_subdirectory(Vulkan/)
+2
View File
@@ -502,6 +502,8 @@ public:
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) = 0;
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) = 0;
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) = 0;
virtual void setScrollCallback(std::function<void(double, double)> callback) = 0;
virtual void setFileCallback(std::function<void(int, const char**)> callback) = 0;
SeFormat getSwapchainFormat() const
{
return pixelFormat;
+1 -1
View File
@@ -1,5 +1,5 @@
#include "RenderCore.h"
#include "SceneView.h"
#include "Window/SceneView.h"
Seele::RenderCore::RenderCore()
{
+1 -1
View File
@@ -1,5 +1,5 @@
#pragma once
#include "WindowManager.h"
#include "Window/WindowManager.h"
#include "Scene/Scene.h"
namespace Seele
{
+3 -2
View File
@@ -1,8 +1,9 @@
#include "BasePass.h"
#include "Graphics/Graphics.h"
#include "Graphics/Window.h"
#include "Window/Window.h"
#include "Scene/Components/CameraComponent.h"
#include "Scene/Actor/CameraActor.h"
#include "Math/Vector.h"
using namespace Seele;
@@ -162,7 +163,7 @@ void BasePass::beginFrame()
viewParams.viewMatrix = source->getViewMatrix();
viewParams.projectionMatrix = source->getProjectionMatrix();
viewParams.cameraPosition = Vector4(source->getTransform().getPosition(), 0);
viewParams.cameraPosition = Vector4(source->getCameraPosition(), 0);
screenToViewParams.inverseProjectionMatrix = glm::inverse(viewParams.projectionMatrix);
screenToViewParams.screenDimensions = Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
uniformUpdate.size = sizeof(ViewParameter);
-17
View File
@@ -1,17 +0,0 @@
#include "RenderPath.h"
#include "GraphicsResources.h"
Seele::RenderPath::RenderPath(Gfx::PGraphics graphics, Gfx::PViewport target)
: graphics(graphics), target(target)
{
}
Seele::RenderPath::~RenderPath()
{
}
void Seele::RenderPath::applyArea(URect newArea)
{
target->resize(newArea.size.x, newArea.size.y);
target->move(newArea.offset.x, newArea.offset.y);
}
-22
View File
@@ -1,22 +0,0 @@
#pragma once
#include "Graphics.h"
namespace Seele
{
//A renderpath is a general Renderer for a view.
class RenderPath
{
public:
RenderPath(Gfx::PGraphics graphics, Gfx::PViewport target);
virtual ~RenderPath();
virtual void applyArea(URect area);
virtual void init() = 0;
virtual void beginFrame() = 0;
virtual void render() = 0;
virtual void endFrame() = 0;
protected:
Gfx::PGraphics graphics;
Gfx::PViewport target;
};
DEFINE_REF(RenderPath);
} // namespace Seele
-42
View File
@@ -1,42 +0,0 @@
#include "SceneRenderPath.h"
#include "Scene/Scene.h"
#include "Material/Material.h"
#include "Asset/AssetRegistry.h"
using namespace Seele;
SceneRenderPath::SceneRenderPath(PScene scene, Gfx::PGraphics graphics, Gfx::PViewport target, PCameraActor source)
: RenderPath(graphics, target)
, scene(scene)
{
basePass = new BasePass(scene, graphics, target, source);
}
SceneRenderPath::~SceneRenderPath()
{
}
void SceneRenderPath::setTargetScene(PScene newScene)
{
scene = newScene;
}
void SceneRenderPath::init()
{
}
void SceneRenderPath::beginFrame()
{
basePass->beginFrame();
}
void SceneRenderPath::render()
{
basePass->render();
}
void SceneRenderPath::endFrame()
{
basePass->endFrame();
}
-24
View File
@@ -1,24 +0,0 @@
#pragma once
#include "RenderPath.h"
#include "Graphics/RenderPass/BasePass.h"
namespace Seele
{
DECLARE_REF(Scene);
DECLARE_REF(CameraActor);
class SceneRenderPath : public RenderPath
{
public:
SceneRenderPath(PScene scene, Gfx::PGraphics graphics, Gfx::PViewport target, PCameraActor source);
virtual ~SceneRenderPath();
void setTargetScene(PScene scene);
virtual void init();
virtual void beginFrame();
virtual void render();
virtual void endFrame();
protected:
PScene scene;
UPBasePass basePass;
};
} // namespace Seele
-40
View File
@@ -1,40 +0,0 @@
#include "SceneView.h"
#include "SceneRenderPath.h"
#include "Scene/Scene.h"
#include "Window.h"
#include "Scene/Actor/CameraActor.h"
#include "Scene/Components/CameraComponent.h"
#include <iostream>
using namespace Seele;
Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo)
: View(graphics, owner, createInfo)
{
scene = new Scene(graphics);
activeCamera = new CameraActor();
scene->addActor(activeCamera);
renderer = new SceneRenderPath(scene, graphics, viewport, activeCamera);
}
Seele::SceneView::~SceneView()
{
}
void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier modifier)
{
}
void SceneView::mouseMoveCallback(double xPos, double yPos)
{
static double prevXPos = 0.0f, prevYPos = 0.0f;
double deltaX = xPos - prevXPos;
double deltaY = yPos - prevYPos;
prevXPos = xPos;
prevYPos = yPos;
activeCamera->getCameraComponent()->mouseMove(deltaX, deltaY);
}
void SceneView::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier)
{
}
-21
View File
@@ -1,21 +0,0 @@
#pragma once
#include "View.h"
namespace Seele
{
DECLARE_REF(Scene);
DECLARE_REF(CameraActor);
class SceneView : public View
{
public:
SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo);
~SceneView();
PScene getScene() const { return scene; }
private:
PScene scene;
PCameraActor activeCamera;
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) override;
virtual void mouseMoveCallback(double xPos, double yPos) override;
virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier) override;
};
DEFINE_REF(SceneView);
} // namespace Seele
-37
View File
@@ -1,37 +0,0 @@
#include "View.h"
#include "Window.h"
Seele::View::View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &viewportInfo)
: graphics(graphics), owner(window)
{
viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo);
}
Seele::View::~View()
{
}
void Seele::View::beginFrame()
{
renderer->beginFrame();
}
void Seele::View::render()
{
renderer->render();
}
void Seele::View::endFrame()
{
renderer->endFrame();
}
void Seele::View::applyArea(URect area)
{
renderer->applyArea(area);
}
void View::setFocused()
{
owner->setFocused(this);
}
-31
View File
@@ -1,31 +0,0 @@
#pragma once
#include "RenderPath.h"
namespace Seele
{
DECLARE_REF(Window);
// A view is a part of the window, which can be anything from a viewport to an editor
class View
{
public:
View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo);
virtual ~View();
void beginFrame();
void render();
void endFrame();
void applyArea(URect area);
void setFocused();
protected:
Gfx::PGraphics graphics;
Gfx::PViewport viewport;
PWindow owner;
PRenderPath renderer;
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;
friend class Window;
};
DEFINE_REF(View)
} // namespace Seele
@@ -89,6 +89,10 @@ void CmdBuffer::executeCommands(Array<Gfx::PRenderCommand> commands)
auto command = commands[i].cast<SecondaryCmdBuffer>();
command->end();
executingCommands.add(command);
for(PDescriptorSet set : command->boundDescriptors)
{
set->setCurrentlyBound(this);
}
cmdBuffers[i] = command->getHandle();
}
vkCmdExecuteCommands(handle, cmdBuffers.size(), cmdBuffers.data());
@@ -112,7 +116,7 @@ void CmdBuffer::refreshFence()
{
command->reset();
}
executingCommands.clear();
fence->reset();
}
}
@@ -92,6 +92,7 @@ public:
private:
PGraphicsPipeline pipeline;
Array<PDescriptorSet> boundDescriptors;
friend class CmdBuffer;
};
DEFINE_REF(SecondaryCmdBuffer);
@@ -208,6 +208,7 @@ void DescriptorSet::writeChanges()
if(currentlyBound != nullptr)
{
currentlyBound->getManager()->waitForCommands(currentlyBound);
currentlyBound = nullptr;
}
vkUpdateDescriptorSets(graphics->getDevice(), writeDescriptors.size(), writeDescriptors.data(), 0, nullptr);
writeDescriptors.clear();
@@ -324,10 +324,14 @@ public:
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 setFileCallback(std::function<void(int, const char**)> 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;
protected:
void advanceBackBuffer();
void recreateSwapchain(const WindowCreateInfo &createInfo);
@@ -768,15 +768,7 @@ VkPipelineShaderStageCreateInfo init::PipelineShaderStageCreateInfo(VkShaderStag
#pragma warning(disable : 4100)
VkBool32 Seele::Vulkan::debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char *layerPrefix, const char *msg, void *userDataManager)
{
if(flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT)
{
//std::cerr << layerPrefix << ": " << msg << std::endl;
}
else
{
std::cerr << layerPrefix << ": " << msg << std::endl;
return VK_FALSE;
}
std::cerr << layerPrefix << ": " << msg << std::endl;
return VK_FALSE;
}
#pragma warning(default : 4100)
@@ -14,6 +14,30 @@ void glfwKeyCallback(GLFWwindow* handle, int key, int scancode, int action, int
window->keyCallback((KeyCode)key, (InputAction)action, (KeyModifier)modifier);
}
void glfwMouseMoveCallback(GLFWwindow* handle, double xpos, double ypos)
{
Window* window = (Window*)glfwGetWindowUserPointer(handle);
window->mouseMoveCallback(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);
}
void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset)
{
Window* window = (Window*)glfwGetWindowUserPointer(handle);
window->scrollCallback(xoffset, yoffset);
}
void glfwFileCallback(GLFWwindow* handle, int count, const char** paths)
{
Window* window = (Window*)glfwGetWindowUserPointer(handle);
window->fileCallback(count, paths);
}
Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo)
: Gfx::Window(createInfo), graphics(graphics), instance(graphics->getInstance()), swapchain(VK_NULL_HANDLE), numSamples(createInfo.numSamples), pixelFormat(cast(createInfo.pixelFormat))
{
@@ -23,6 +47,10 @@ Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo)
glfwSetWindowUserPointer(handle, this);
glfwSetKeyCallback(handle, &glfwKeyCallback);
glfwSetCursorPosCallback(handle, &glfwMouseMoveCallback);
glfwSetMouseButtonCallback(handle, &glfwMouseButtonCallback);
glfwSetScrollCallback(handle, &glfwScrollCallback);
glfwSetDropCallback(handle, &glfwFileCallback);
glfwCreateWindowSurface(instance, handle, nullptr, &surface);
@@ -91,6 +119,16 @@ void Window::setMouseButtonCallback(std::function<void(MouseButton, InputAction,
mouseButtonCallback = callback;
}
void Window::setScrollCallback(std::function<void(double, double)> callback)
{
scrollCallback = callback;
}
void Window::setFileCallback(std::function<void(int, const char**)> callback)
{
fileCallback = callback;
}
void Window::advanceBackBuffer()
{
VkResult res = VK_ERROR_OUT_OF_DATE_KHR;
-54
View File
@@ -1,54 +0,0 @@
#include "Window.h"
#include <functional>
Seele::Window::Window(Gfx::PWindow handle)
: gfxHandle(handle)
{
}
Seele::Window::~Window()
{
}
void Seele::Window::addView(PView view)
{
viewports.add(view);
}
void Seele::Window::beginFrame()
{
gfxHandle->beginFrame();
for (auto view : viewports)
{
view->beginFrame();
}
}
void Seele::Window::render()
{
for (auto view : viewports)
{
view->render();
}
}
void Seele::Window::endFrame()
{
gfxHandle->endFrame();
for (auto view : viewports)
{
view->endFrame();
}
}
Gfx::PWindow Seele::Window::getGfxHandle()
{
return gfxHandle;
}
void Window::setFocused(PView view)
{
focusedView = view;
auto boundFunction = std::bind(&View::keyCallback, view.getHandle(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
gfxHandle->setKeyCallback(boundFunction);
}
-26
View File
@@ -1,26 +0,0 @@
#pragma once
#include "GraphicsResources.h"
#include "View.h"
namespace Seele
{
// The logical window, with the graphics proxy
class Window
{
public:
Window(Gfx::PWindow handle);
~Window();
void addView(PView view);
void beginFrame();
void render();
void endFrame();
Gfx::PWindow getGfxHandle();
void setFocused(PView view);
private:
Array<PView> viewports;
PView focusedView;
Gfx::PWindow gfxHandle;
};
DEFINE_REF(Window);
} // namespace Seele
-59
View File
@@ -1,59 +0,0 @@
#include "WindowManager.h"
#include "Vulkan/VulkanGraphics.h"
Gfx::PGraphics WindowManager::graphics;
Seele::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);
}
Seele::WindowManager::~WindowManager()
{
}
PWindow Seele::WindowManager::addWindow(const WindowCreateInfo &createInfo)
{
Gfx::PWindow handle = graphics->createWindow(createInfo);
PWindow window = new Window(handle);
windows.add(window);
return window;
}
void Seele::WindowManager::beginFrame()
{
for (auto window : windows)
{
window->beginFrame();
}
}
void WindowManager::render()
{
for(auto window : windows)
{
window->render();
}
}
void Seele::WindowManager::endFrame()
{
for (auto window : windows)
{
window->endFrame();
}
}
-32
View File
@@ -1,32 +0,0 @@
#pragma once
#include "GraphicsResources.h"
#include "Graphics.h"
#include "Containers/Array.h"
#include "Window.h"
namespace Seele
{
class WindowManager
{
public:
WindowManager();
~WindowManager();
PWindow addWindow(const WindowCreateInfo &createInfo);
void beginFrame();
void render();
void endFrame();
static Gfx::PGraphics getGraphics()
{
return graphics;
}
inline bool isActive() const
{
return windows.size();
}
private:
Array<PWindow> windows;
static Gfx::PGraphics graphics;
};
DEFINE_REF(WindowManager);
} // namespace Seele