Adding basic keyboard input
This commit is contained in:
@@ -468,6 +468,13 @@ CommandPool::CommandPool(PGraphics graphics, PQueue queue)
|
||||
|
||||
CommandPool::~CommandPool()
|
||||
{
|
||||
for (auto& command : allocatedBuffers)
|
||||
{
|
||||
command->waitForCommand();
|
||||
}
|
||||
allocatedRenderCommands.clear();
|
||||
allocatedComputeCommands.clear();
|
||||
allocatedBuffers.clear();
|
||||
vkDestroyCommandPool(graphics->getDevice(), commandPool, nullptr);
|
||||
graphics = nullptr;
|
||||
queue = nullptr;
|
||||
|
||||
@@ -522,8 +522,6 @@ void Graphics::createDevice(GraphicsInitializer initializer)
|
||||
.pNext = &descriptorIndexing,
|
||||
.queueCreateInfoCount = (uint32)queueInfos.size(),
|
||||
.pQueueCreateInfos = queueInfos.data(),
|
||||
.enabledLayerCount = (uint32_t)initializer.layers.size(),
|
||||
.ppEnabledLayerNames = initializer.layers.data(),
|
||||
.enabledExtensionCount = (uint32)initializer.deviceExtensions.size(),
|
||||
.ppEnabledExtensionNames = initializer.deviceExtensions.data(),
|
||||
.pEnabledFeatures = &features,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "Resources.h"
|
||||
#include "Enums.h"
|
||||
#include "Graphics.h"
|
||||
#include "Command.h"
|
||||
#include "Window.h"
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
@@ -18,17 +20,7 @@ Semaphore::Semaphore(PGraphics graphics)
|
||||
|
||||
Semaphore::~Semaphore()
|
||||
{
|
||||
uint64 value = 0;
|
||||
VkSemaphoreWaitInfo waitInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO,
|
||||
.pNext = nullptr,
|
||||
.flags = 0,
|
||||
.semaphoreCount = 1,
|
||||
.pSemaphores = &handle,
|
||||
.pValues = &value,
|
||||
};
|
||||
VK_CHECK(vkWaitSemaphores(graphics->getDevice(), &waitInfo, 10000));
|
||||
vkDestroySemaphore(graphics->getDevice(), handle, nullptr);
|
||||
graphics->getDestructionManager()->queueSemaphore(graphics->getGraphicsCommands()->getCommands(), handle);
|
||||
}
|
||||
|
||||
Fence::Fence(PGraphics graphics)
|
||||
|
||||
@@ -41,9 +41,11 @@ TextureBase::TextureBase(PGraphics graphics, VkImageViewType viewType,
|
||||
, image(existingImage)
|
||||
, aspect(getAspectFromFormat(createInfo.format))
|
||||
, layout(Gfx::SE_IMAGE_LAYOUT_UNDEFINED)
|
||||
, ownsImage(false)
|
||||
{
|
||||
if (existingImage == VK_NULL_HANDLE)
|
||||
{
|
||||
ownsImage = true;
|
||||
PAllocator pool = graphics->getAllocator();
|
||||
VkImageType type = VK_IMAGE_TYPE_MAX_ENUM;
|
||||
VkImageCreateFlags flags = 0;
|
||||
@@ -175,13 +177,16 @@ TextureBase::TextureBase(PGraphics graphics, VkImageViewType viewType,
|
||||
},
|
||||
};
|
||||
|
||||
VK_CHECK(vkCreateImageView(graphics->getDevice(), &viewInfo, nullptr, &defaultView));
|
||||
VK_CHECK(vkCreateImageView(graphics->getDevice(), &viewInfo, nullptr, &imageView));
|
||||
}
|
||||
|
||||
TextureBase::~TextureBase()
|
||||
{
|
||||
graphics->getDestructionManager()->queueImage(graphics->getQueueCommands(currentOwner)->getCommands(), image);
|
||||
graphics->getDestructionManager()->queueImageView(graphics->getQueueCommands(currentOwner)->getCommands(), defaultView);
|
||||
if (ownsImage)
|
||||
{
|
||||
graphics->getDestructionManager()->queueImage(graphics->getQueueCommands(currentOwner)->getCommands(), image);
|
||||
}
|
||||
graphics->getDestructionManager()->queueImageView(graphics->getQueueCommands(currentOwner)->getCommands(), imageView);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
}
|
||||
constexpr VkImageView getView() const
|
||||
{
|
||||
return defaultView;
|
||||
return imageView;
|
||||
}
|
||||
constexpr Gfx::SeImageLayout getLayout() const
|
||||
{
|
||||
@@ -72,9 +72,10 @@ protected:
|
||||
Gfx::SeFormat format;
|
||||
Gfx::SeImageUsageFlags usage;
|
||||
VkImage image;
|
||||
VkImageView defaultView;
|
||||
VkImageView imageView;
|
||||
VkImageAspectFlags aspect;
|
||||
Gfx::SeImageLayout layout;
|
||||
uint8 ownsImage;
|
||||
friend class Graphics;
|
||||
};
|
||||
|
||||
|
||||
@@ -49,6 +49,11 @@ void glfwCloseCallback(GLFWwindow* handle)
|
||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||
window->closeCallback();
|
||||
}
|
||||
void glfwResizeCallback(GLFWwindow* handle, int width, int height)
|
||||
{
|
||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||
window->resize(width, height);
|
||||
}
|
||||
|
||||
Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo)
|
||||
: graphics(graphics)
|
||||
@@ -68,20 +73,11 @@ Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo)
|
||||
glfwSetScrollCallback(handle, &glfwScrollCallback);
|
||||
glfwSetDropCallback(handle, &glfwFileCallback);
|
||||
glfwSetWindowCloseCallback(handle, &glfwCloseCallback);
|
||||
glfwSetWindowSizeCallback(handle, &glfwResizeCallback);
|
||||
|
||||
glfwCreateWindowSurface(instance, handle, nullptr, &surface);
|
||||
|
||||
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(graphics->getPhysicalDevice(), surface, &capabilities);
|
||||
|
||||
uint32 numFormats;
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(graphics->getPhysicalDevice(), surface, &numFormats, nullptr);
|
||||
supportedFormats.resize(numFormats);
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(graphics->getPhysicalDevice(), surface, &numFormats, supportedFormats.data());
|
||||
|
||||
uint32 numPresentModes;
|
||||
vkGetPhysicalDeviceSurfacePresentModesKHR(graphics->getPhysicalDevice(), surface, &numPresentModes, nullptr);
|
||||
supportedPresentModes.resize(numFormats);
|
||||
vkGetPhysicalDeviceSurfacePresentModesKHR(graphics->getPhysicalDevice(), surface, &numPresentModes, supportedPresentModes.data());
|
||||
querySurface();
|
||||
chooseSwapSurfaceFormat();
|
||||
framebufferFormat = cast(format.format);
|
||||
chooseSwapPresentMode();
|
||||
@@ -175,6 +171,33 @@ void Window::setCloseCallback(std::function<void()> callback)
|
||||
closeCallback = callback;
|
||||
}
|
||||
|
||||
void Window::resize(int width, int height)
|
||||
{
|
||||
querySurface();
|
||||
chooseSwapSurfaceFormat();
|
||||
framebufferFormat = cast(format.format);
|
||||
chooseSwapPresentMode();
|
||||
chooseSwapExtent();
|
||||
framebufferWidth = extent.width;
|
||||
framebufferHeight = extent.height;
|
||||
createSwapChain();
|
||||
}
|
||||
|
||||
void Window::querySurface()
|
||||
{
|
||||
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(graphics->getPhysicalDevice(), surface, &capabilities);
|
||||
|
||||
uint32 numFormats;
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(graphics->getPhysicalDevice(), surface, &numFormats, nullptr);
|
||||
supportedFormats.resize(numFormats);
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(graphics->getPhysicalDevice(), surface, &numFormats, supportedFormats.data());
|
||||
|
||||
uint32 numPresentModes;
|
||||
vkGetPhysicalDeviceSurfacePresentModesKHR(graphics->getPhysicalDevice(), surface, &numPresentModes, nullptr);
|
||||
supportedPresentModes.resize(numFormats);
|
||||
vkGetPhysicalDeviceSurfacePresentModesKHR(graphics->getPhysicalDevice(), surface, &numPresentModes, supportedPresentModes.data());
|
||||
}
|
||||
|
||||
void Window::chooseSwapSurfaceFormat()
|
||||
{
|
||||
for (const auto& supportedFormat : supportedFormats)
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
virtual void setScrollCallback(std::function<void(double, double)> callback) override;
|
||||
virtual void setFileCallback(std::function<void(int, const char**)> callback) override;
|
||||
virtual void setCloseCallback(std::function<void()> callback);
|
||||
void resize(int width, int height);
|
||||
|
||||
std::function<void(KeyCode, InputAction, KeyModifier)> keyCallback;
|
||||
std::function<void(double, double)> mouseMoveCallback;
|
||||
@@ -31,6 +32,7 @@ public:
|
||||
std::function<void(int, const char**)> fileCallback;
|
||||
std::function<void()> closeCallback;
|
||||
protected:
|
||||
void querySurface();
|
||||
void chooseSwapSurfaceFormat();
|
||||
void chooseSwapPresentMode();
|
||||
void chooseSwapExtent();
|
||||
|
||||
Reference in New Issue
Block a user