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
@@ -315,7 +315,9 @@ public:
virtual void endFrame() override;
virtual Gfx::PTexture2D getBackBuffer() override;
virtual void onWindowCloseEvent() override;
virtual void setKeyCallback(std::function<void(KeyCode, KeyAction, KeyModifier)> callback) override;
std::function<void(KeyCode, KeyAction, KeyModifier)> keyCallback;
protected:
void advanceBackBuffer();
void recreateSwapchain(const WindowCreateInfo &createInfo);
@@ -324,6 +326,7 @@ protected:
void createSwapchain();
void chooseSurfaceFormat(const Array<VkSurfaceFormatKHR> &available, Gfx::SeFormat preferred);
void choosePresentMode(const Array<VkPresentModeKHR> &modes);
PTexture2D backBufferImages[Gfx::numFramesBuffered];
PSemaphore renderFinished[Gfx::numFramesBuffered];
PSemaphore imageAcquired[Gfx::numFramesBuffered];
@@ -768,9 +768,9 @@ 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_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
{
@@ -285,7 +285,7 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo
VK_CHECK(vkCreateGraphicsPipelines(graphics->getDevice(), cache, 1, &createInfo, nullptr, &pipelineHandle));
auto endTime = std::chrono::high_resolution_clock::now();
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);
return result;
+25 -3
View File
@@ -8,14 +8,22 @@
using namespace Seele;
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)
: 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);
GLFWwindow *handle = glfwCreateWindow(createInfo.width, createInfo.height, createInfo.title, createInfo.bFullscreen ? glfwGetPrimaryMonitor() : nullptr, nullptr);
windowHandle = handle;
glfwSetWindowUserPointer(handle, this);
//TODO: callbacks
glfwSetKeyCallback(handle, &glfwKeyCallback);
glfwCreateWindowSurface(instance, handle, nullptr, &surface);
@@ -69,6 +77,11 @@ Gfx::PTexture2D Window::getBackBuffer()
return backBufferImages[currentImageIndex];
}
void Window::setKeyCallback(std::function<void(KeyCode, KeyAction, KeyModifier)> callback)
{
keyCallback = callback;
}
void Window::advanceBackBuffer()
{
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)
: 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.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()
@@ -271,10 +288,15 @@ void Viewport::resize(uint32 newX, uint32 newY)
{
sizeX = newX;
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)
{
offsetX = newOffsetX;
offsetY = newOffsetY;
handle.x = static_cast<float>(offsetX);
handle.y = static_cast<float>(offsetY + sizeY);
}