Adding callbacks and viewports

This commit is contained in:
Dynamitos
2020-10-29 02:22:01 +01:00
parent b4fc5df74e
commit 84b3fa29bf
13 changed files with 230 additions and 25 deletions
+161 -15
View File
@@ -2,6 +2,151 @@
#include "MinimalEngine.h" #include "MinimalEngine.h"
namespace Seele namespace Seele
{ {
enum class KeyCode
{
/* Printable keys */
KEY_SPACE = 32,
KEY_APOSTROPHE = 39 /* ' */,
KEY_COMMA = 44 /* , */,
KEY_MINUS = 45 /* - */,
KEY_PERIOD = 46 /* . */,
KEY_SLASH = 47 /* / */,
KEY_0 = 48,
KEY_1 = 49,
KEY_2 = 50,
KEY_3 = 51,
KEY_4 = 52,
KEY_5 = 53,
KEY_6 = 54,
KEY_7 = 55,
KEY_8 = 56,
KEY_9 = 57,
KEY_SEMICOLON = 59 /* ; */,
KEY_EQUAL = 61 /* = */,
KEY_A = 65,
KEY_B = 66,
KEY_C = 67,
KEY_D = 68,
KEY_E = 69,
KEY_F = 70,
KEY_G = 71,
KEY_H = 72,
KEY_I = 73,
KEY_J = 74,
KEY_K = 75,
KEY_L = 76,
KEY_M = 77,
KEY_N = 78,
KEY_O = 79,
KEY_P = 80,
KEY_Q = 81,
KEY_R = 82,
KEY_S = 83,
KEY_T = 84,
KEY_U = 85,
KEY_V = 86,
KEY_W = 87,
KEY_X = 88,
KEY_Y = 89,
KEY_Z = 90,
KEY_LEFT_BRACKET = 91 /* [ */,
KEY_BACKSLASH = 92 /* \ */,
KEY_RIGHT_BRACKET = 93 /* ] */,
KEY_GRAVE_ACCENT = 96 /* ` */,
KEY_WORLD_1 = 161 /* non-US #1 */,
KEY_WORLD_2 = 162 /* non-US #2 */,
/* Function keys */
KEY_ESCAPE = 256,
KEY_ENTER = 257,
KEY_TAB = 258,
KEY_BACKSPACE = 259,
KEY_INSERT = 260,
KEY_DELETE = 261,
KEY_RIGHT = 262,
KEY_LEFT = 263,
KEY_DOWN = 264,
KEY_UP = 265,
KEY_PAGE_UP = 266,
KEY_PAGE_DOWN = 267,
KEY_HOME = 268,
KEY_END = 269,
KEY_CAPS_LOCK = 280,
KEY_SCROLL_LOCK = 281,
KEY_NUM_LOCK = 282,
KEY_PRINT_SCREEN = 283,
KEY_PAUSE = 284,
KEY_F1 = 290,
KEY_F2 = 291,
KEY_F3 = 292,
KEY_F4 = 293,
KEY_F5 = 294,
KEY_F6 = 295,
KEY_F7 = 296,
KEY_F8 = 297,
KEY_F9 = 298,
KEY_F10 = 299,
KEY_F11 = 300,
KEY_F12 = 301,
KEY_F13 = 302,
KEY_F14 = 303,
KEY_F15 = 304,
KEY_F16 = 305,
KEY_F17 = 306,
KEY_F18 = 307,
KEY_F19 = 308,
KEY_F20 = 309,
KEY_F21 = 310,
KEY_F22 = 311,
KEY_F23 = 312,
KEY_F24 = 313,
KEY_F25 = 314,
KEY_KP_0 = 320,
KEY_KP_1 = 321,
KEY_KP_2 = 322,
KEY_KP_3 = 323,
KEY_KP_4 = 324,
KEY_KP_5 = 325,
KEY_KP_6 = 326,
KEY_KP_7 = 327,
KEY_KP_8 = 328,
KEY_KP_9 = 329,
KEY_KP_DECIMAL = 330,
KEY_KP_DIVIDE = 331,
KEY_KP_MULTIPLY = 332,
KEY_KP_SUBTRACT = 333,
KEY_KP_ADD = 334,
KEY_KP_ENTER = 335,
KEY_KP_EQUAL = 336,
KEY_LEFT_SHIFT = 340,
KEY_LEFT_CONTROL = 341,
KEY_LEFT_ALT = 342,
KEY_LEFT_SUPER = 343,
KEY_RIGHT_SHIFT = 344,
KEY_RIGHT_CONTROL = 345,
KEY_RIGHT_ALT = 346,
KEY_RIGHT_SUPER = 347,
KEY_MENU = 348,
};
enum class KeyAction
{
RELEASE = 0,
PRESS = 1,
REPEAT = 2
};
enum class KeyModifier
{
MOD_SHIFT = 0x0001,
MOD_CONTROL = 0x0002,
MOD_ALT = 0x0004,
MOD_SUPER = 0x0008,
MOD_CAPS_LOCK = 0x0010,
MOD_NUM_LOCK = 0x0020
};
typedef uint32 KeyModifierFlags;
namespace Gfx namespace Gfx
{ {
static constexpr bool useAsyncCompute = true; static constexpr bool useAsyncCompute = true;
@@ -30,6 +175,22 @@ enum class RenderPassType : uint8
BasePass BasePass
}; };
enum class QueueType
{
GRAPHICS = 1,
COMPUTE = 2,
TRANSFER = 3,
DEDICATED_TRANSFER = 4
};
enum class VertexAttribute
{
POSITION,
TEXCOORD,
NORMAL,
TANGENT,
BITANGENT
};
typedef uint32_t SeFlags; typedef uint32_t SeFlags;
typedef uint32_t SeBool32; typedef uint32_t SeBool32;
typedef uint64_t SeDeviceSize; typedef uint64_t SeDeviceSize;
@@ -1885,20 +2046,5 @@ typedef union SeClearValue {
SeClearDepthStencilValue depthStencil; SeClearDepthStencilValue depthStencil;
} SeClearValue; } SeClearValue;
enum class QueueType
{
GRAPHICS = 1,
COMPUTE = 2,
TRANSFER = 3,
DEDICATED_TRANSFER = 4
};
enum class VertexAttribute
{
POSITION,
TEXCOORD,
NORMAL,
TANGENT,
BITANGENT
};
} // namespace Gfx } // namespace Gfx
} // namespace Seele } // namespace Seele
+2
View File
@@ -5,6 +5,7 @@
#include "GraphicsInitializer.h" #include "GraphicsInitializer.h"
#include "MeshBatch.h" #include "MeshBatch.h"
#include <boost/crc.hpp> #include <boost/crc.hpp>
#include <functional>
#ifndef ENABLE_VALIDATION #ifndef ENABLE_VALIDATION
@@ -499,6 +500,7 @@ public:
virtual void endFrame() = 0; virtual void endFrame() = 0;
virtual void onWindowCloseEvent() = 0; virtual void onWindowCloseEvent() = 0;
virtual PTexture2D getBackBuffer() = 0; virtual PTexture2D getBackBuffer() = 0;
virtual void setKeyCallback(std::function<void(KeyCode, KeyAction, KeyModifier)> callback) = 0;
SeFormat getSwapchainFormat() const SeFormat getSwapchainFormat() const
{ {
return pixelFormat; return pixelFormat;
+11 -3
View File
@@ -3,6 +3,8 @@
#include "Scene/Scene.h" #include "Scene/Scene.h"
#include "Window.h" #include "Window.h"
#include "Scene/Actor/CameraActor.h" #include "Scene/Actor/CameraActor.h"
#include "Scene/Components/CameraComponent.h"
#include <iostream>
using namespace Seele; using namespace Seele;
@@ -10,11 +12,17 @@ Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const Viewpo
: View(graphics, owner, createInfo) : View(graphics, owner, createInfo)
{ {
scene = new Scene(graphics); scene = new Scene(graphics);
PCameraActor camera = new CameraActor(); activeCamera = new CameraActor();
scene->addActor(camera); scene->addActor(activeCamera);
renderer = new SceneRenderPath(scene, graphics, viewport, camera); renderer = new SceneRenderPath(scene, graphics, viewport, activeCamera);
} }
Seele::SceneView::~SceneView() Seele::SceneView::~SceneView()
{ {
} }
void SceneView::keyCallback(KeyCode code, KeyAction action, KeyModifier modifier)
{
std::cout << "Key callback " << (uint32)code << std::endl;
activeCamera->getCameraComponent()->moveOrigin(1);
}
+3
View File
@@ -3,6 +3,7 @@
namespace Seele namespace Seele
{ {
DECLARE_REF(Scene); DECLARE_REF(Scene);
DECLARE_REF(CameraActor);
class SceneView : public View class SceneView : public View
{ {
public: public:
@@ -11,6 +12,8 @@ public:
PScene getScene() const { return scene; } PScene getScene() const { return scene; }
private: private:
PScene scene; PScene scene;
PCameraActor activeCamera;
virtual void keyCallback(KeyCode code, KeyAction action, KeyModifier modifier) override;
}; };
DEFINE_REF(SceneView); DEFINE_REF(SceneView);
} // namespace Seele } // namespace Seele
+5
View File
@@ -30,3 +30,8 @@ void Seele::View::applyArea(URect area)
{ {
renderer->applyArea(area); renderer->applyArea(area);
} }
void View::setFocused()
{
owner->setFocused(this);
}
+4
View File
@@ -13,12 +13,16 @@ public:
void render(); void render();
void endFrame(); void endFrame();
void applyArea(URect area); void applyArea(URect area);
void setFocused();
protected: protected:
Gfx::PGraphics graphics; Gfx::PGraphics graphics;
Gfx::PViewport viewport; Gfx::PViewport viewport;
PWindow owner; PWindow owner;
PRenderPath renderer; PRenderPath renderer;
virtual void keyCallback(KeyCode code, KeyAction action, KeyModifier modifier) = 0;
friend class Window;
}; };
DEFINE_REF(View) DEFINE_REF(View)
@@ -315,7 +315,9 @@ public:
virtual void endFrame() override; virtual void endFrame() override;
virtual Gfx::PTexture2D getBackBuffer() override; virtual Gfx::PTexture2D getBackBuffer() override;
virtual void onWindowCloseEvent() override; virtual void onWindowCloseEvent() override;
virtual void setKeyCallback(std::function<void(KeyCode, KeyAction, KeyModifier)> callback) override;
std::function<void(KeyCode, KeyAction, KeyModifier)> keyCallback;
protected: protected:
void advanceBackBuffer(); void advanceBackBuffer();
void recreateSwapchain(const WindowCreateInfo &createInfo); void recreateSwapchain(const WindowCreateInfo &createInfo);
@@ -324,6 +326,7 @@ protected:
void createSwapchain(); void createSwapchain();
void chooseSurfaceFormat(const Array<VkSurfaceFormatKHR> &available, Gfx::SeFormat preferred); void chooseSurfaceFormat(const Array<VkSurfaceFormatKHR> &available, Gfx::SeFormat preferred);
void choosePresentMode(const Array<VkPresentModeKHR> &modes); void choosePresentMode(const Array<VkPresentModeKHR> &modes);
PTexture2D backBufferImages[Gfx::numFramesBuffered]; PTexture2D backBufferImages[Gfx::numFramesBuffered];
PSemaphore renderFinished[Gfx::numFramesBuffered]; PSemaphore renderFinished[Gfx::numFramesBuffered];
PSemaphore imageAcquired[Gfx::numFramesBuffered]; PSemaphore imageAcquired[Gfx::numFramesBuffered];
@@ -768,9 +768,9 @@ VkPipelineShaderStageCreateInfo init::PipelineShaderStageCreateInfo(VkShaderStag
#pragma warning(disable : 4100) #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) 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_ERROR_BIT_EXT) if(flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT)
{ {
std::cerr << layerPrefix << ": " << msg << std::endl; //std::cerr << layerPrefix << ": " << msg << std::endl;
} }
else else
{ {
@@ -285,7 +285,7 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo
VK_CHECK(vkCreateGraphicsPipelines(graphics->getDevice(), cache, 1, &createInfo, nullptr, &pipelineHandle)); VK_CHECK(vkCreateGraphicsPipelines(graphics->getDevice(), cache, 1, &createInfo, nullptr, &pipelineHandle));
auto endTime = std::chrono::high_resolution_clock::now(); auto endTime = std::chrono::high_resolution_clock::now();
int64 delta = std::chrono::duration_cast<std::chrono::microseconds>(endTime - beginTime).count(); int64 delta = std::chrono::duration_cast<std::chrono::microseconds>(endTime - beginTime).count();
std::cout << "Gfx creation time: " << delta << std::endl; //std::cout << "Gfx creation time: " << delta << std::endl;
PGraphicsPipeline result = new GraphicsPipeline(graphics, pipelineHandle, layout, gfxInfo); PGraphicsPipeline result = new GraphicsPipeline(graphics, pipelineHandle, layout, gfxInfo);
return result; return result;
+25 -3
View File
@@ -8,14 +8,22 @@
using namespace Seele; using namespace Seele;
using namespace Seele::Vulkan; using namespace Seele::Vulkan;
void glfwKeyCallback(GLFWwindow* handle, int key, int scancode, int action, int modifier)
{
Window* window = (Window*)glfwGetWindowUserPointer(handle);
std::cout << "glfw callback: " << key << std::endl;
window->keyCallback((KeyCode)key, (KeyAction)action, (KeyModifier)modifier);
}
Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo) 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)) : Gfx::Window(createInfo), graphics(graphics), instance(graphics->getInstance()), swapchain(VK_NULL_HANDLE), numSamples(createInfo.numSamples), pixelFormat(cast(createInfo.pixelFormat))
{ {
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow *handle = glfwCreateWindow(createInfo.width, createInfo.height, createInfo.title, createInfo.bFullscreen ? glfwGetPrimaryMonitor() : nullptr, nullptr); GLFWwindow *handle = glfwCreateWindow(createInfo.width, createInfo.height, createInfo.title, createInfo.bFullscreen ? glfwGetPrimaryMonitor() : nullptr, nullptr);
windowHandle = handle; windowHandle = handle;
glfwSetWindowUserPointer(handle, this);
//TODO: callbacks glfwSetKeyCallback(handle, &glfwKeyCallback);
glfwCreateWindowSurface(instance, handle, nullptr, &surface); glfwCreateWindowSurface(instance, handle, nullptr, &surface);
@@ -69,6 +77,11 @@ Gfx::PTexture2D Window::getBackBuffer()
return backBufferImages[currentImageIndex]; return backBufferImages[currentImageIndex];
} }
void Window::setKeyCallback(std::function<void(KeyCode, KeyAction, KeyModifier)> callback)
{
keyCallback = callback;
}
void Window::advanceBackBuffer() void Window::advanceBackBuffer()
{ {
VkResult res = VK_ERROR_OUT_OF_DATE_KHR; VkResult res = VK_ERROR_OUT_OF_DATE_KHR;
@@ -258,9 +271,13 @@ void Window::choosePresentMode(const Array<VkPresentModeKHR> &modes)
Viewport::Viewport(PGraphics graphics, PWindow owner, const ViewportCreateInfo &viewportInfo) Viewport::Viewport(PGraphics graphics, PWindow owner, const ViewportCreateInfo &viewportInfo)
: Gfx::Viewport(owner, viewportInfo), graphics(graphics) : Gfx::Viewport(owner, viewportInfo), graphics(graphics)
{ {
handle = init::Viewport(static_cast<float>(viewportInfo.sizeX), static_cast<float>(viewportInfo.sizeY), 0.f, 1.f); handle.width = static_cast<float>(viewportInfo.sizeX);
handle.height = static_cast<float>(viewportInfo.sizeY);
handle.x = static_cast<float>(viewportInfo.offsetX); handle.x = static_cast<float>(viewportInfo.offsetX);
handle.y = static_cast<float>(viewportInfo.offsetY); handle.y = static_cast<float>(viewportInfo.offsetY) + handle.height;
handle.height = -handle.height;
handle.minDepth = 0.f;
handle.maxDepth = 1.f;
} }
Viewport::~Viewport() Viewport::~Viewport()
@@ -271,10 +288,15 @@ void Viewport::resize(uint32 newX, uint32 newY)
{ {
sizeX = newX; sizeX = newX;
sizeY = newY; sizeY = newY;
handle.width = static_cast<float>(sizeX);
handle.y = static_cast<float>(sizeY + offsetX);
handle.height = -static_cast<float>(sizeY);
} }
void Viewport::move(uint32 newOffsetX, uint32 newOffsetY) void Viewport::move(uint32 newOffsetX, uint32 newOffsetY)
{ {
offsetX = newOffsetX; offsetX = newOffsetX;
offsetY = newOffsetY; offsetY = newOffsetY;
handle.x = static_cast<float>(offsetX);
handle.y = static_cast<float>(offsetY + sizeY);
} }
+9 -1
View File
@@ -1,4 +1,5 @@
#include "Window.h" #include "Window.h"
#include <functional>
Seele::Window::Window(Gfx::PWindow handle) Seele::Window::Window(Gfx::PWindow handle)
: gfxHandle(handle) : gfxHandle(handle)
@@ -43,4 +44,11 @@ void Seele::Window::endFrame()
Gfx::PWindow Seele::Window::getGfxHandle() Gfx::PWindow Seele::Window::getGfxHandle()
{ {
return gfxHandle; 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);
}
+2
View File
@@ -15,9 +15,11 @@ public:
void render(); void render();
void endFrame(); void endFrame();
Gfx::PWindow getGfxHandle(); Gfx::PWindow getGfxHandle();
void setFocused(PView view);
private: private:
Array<PView> viewports; Array<PView> viewports;
PView focusedView;
Gfx::PWindow gfxHandle; Gfx::PWindow gfxHandle;
}; };
DEFINE_REF(Window); DEFINE_REF(Window);
+2
View File
@@ -20,7 +20,9 @@ int main()
sceneViewInfo.offsetX = 0; sceneViewInfo.offsetX = 0;
sceneViewInfo.offsetY = 0; sceneViewInfo.offsetY = 0;
PSceneView sceneView = new SceneView(core.getWindowManager()->getGraphics(), window, sceneViewInfo); PSceneView sceneView = new SceneView(core.getWindowManager()->getGraphics(), window, sceneViewInfo);
sceneView->applyArea(URect(1280/2, 720/2, 10, 10));
window->addView(sceneView); window->addView(sceneView);
sceneView->setFocused();
AssetRegistry::init("D:\\Private\\Programming\\C++\\TestSeeleProject"); AssetRegistry::init("D:\\Private\\Programming\\C++\\TestSeeleProject");
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Arissa\\Arissa.fbx"); AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Arissa\\Arissa.fbx");
PPrimitiveComponent arissa = new PrimitiveComponent(AssetRegistry::findMesh("Arissa")); PPrimitiveComponent arissa = new PrimitiveComponent(AssetRegistry::findMesh("Arissa"));