Handling window minimizing

This commit is contained in:
Dynamitos
2023-12-28 21:42:18 +01:00
parent e18254ec29
commit 4b58ab84be
21 changed files with 109 additions and 76 deletions
+1 -1
View File
@@ -51,7 +51,7 @@ void taskMain(
{ {
uint m = mesh.meshletOffset + i; uint m = mesh.meshletOffset + i;
MeshletDescription meshlet = pScene.meshletInfos[m]; MeshletDescription meshlet = pScene.meshletInfos[m];
//if(meshlet.boundingBox.insideFrustum(localToClip, viewFrustum)) if(meshlet.boundingBox.insideFrustum(localToClip, viewFrustum))
{ {
uint index; uint index;
InterlockedAdd(head, 1, index); InterlockedAdd(head, 1, index);
+1 -1
View File
@@ -10,7 +10,7 @@
#ifndef ENABLE_VALIDATION #ifndef ENABLE_VALIDATION
#define ENABLE_VALIDATION 0 #define ENABLE_VALIDATION 1
#endif #endif
namespace Seele namespace Seele
+3 -2
View File
@@ -100,11 +100,11 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
{ {
uint32 numMeshlets = std::min<uint32>(512, loadedMeshlets.size() - currentMesh); uint32 numMeshlets = std::min<uint32>(512, loadedMeshlets.size() - currentMesh);
uint32 meshletOffset = meshlets.size(); uint32 meshletOffset = meshlets.size();
//AABB meshAABB; AABB meshAABB;
for (uint32 i = 0; i < numMeshlets; ++i) for (uint32 i = 0; i < numMeshlets; ++i)
{ {
Meshlet& m = loadedMeshlets[currentMesh + i]; Meshlet& m = loadedMeshlets[currentMesh + i];
//meshAABB = meshAABB.combine(m.boundingBox); meshAABB = meshAABB.combine(m.boundingBox);
uint32 vertexOffset = vertexIndices.size(); uint32 vertexOffset = vertexIndices.size();
vertexIndices.resize(vertexOffset + m.numVertices); vertexIndices.resize(vertexOffset + m.numVertices);
std::memcpy(vertexIndices.data() + vertexOffset, m.uniqueVertices, m.numVertices * sizeof(uint32)); std::memcpy(vertexIndices.data() + vertexOffset, m.uniqueVertices, m.numVertices * sizeof(uint32));
@@ -121,6 +121,7 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
}); });
} }
meshData[id].add(MeshData{ meshData[id].add(MeshData{
.boundingBox = meshAABB,
.numMeshlets = numMeshlets, .numMeshlets = numMeshlets,
.meshletOffset = meshletOffset, .meshletOffset = meshletOffset,
.indicesOffset = (uint32)meshOffsets[id], .indicesOffset = (uint32)meshOffsets[id],
+26 -32
View File
@@ -134,6 +134,10 @@ void Allocation::markFree(PSubAllocation allocation)
} }
activeAllocations.remove(allocation, false); activeAllocations.remove(allocation, false);
bytesUsed -= allocation->allocatedSize; bytesUsed -= allocation->allocatedSize;
//if (activeAllocations.size() == 0)
//{
// pool->free(this);
//}
} }
void Allocation::flushMemory() void Allocation::flushMemory()
@@ -203,7 +207,7 @@ OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2
OSubAllocation suballoc = alloc->getSuballocation(requirements.size, requirements.alignment); OSubAllocation suballoc = alloc->getSuballocation(requirements.size, requirements.alignment);
if (suballoc != nullptr) if (suballoc != nullptr)
{ {
return std::move(suballoc); return suballoc;
} }
} }
} }
@@ -216,18 +220,15 @@ OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2
return heaps[heapIndex].allocations.back()->getSuballocation(requirements.size, requirements.alignment); return heaps[heapIndex].allocations.back()->getSuballocation(requirements.size, requirements.alignment);
} }
void Allocator::free() void Allocator::free(PAllocation allocation)
{ {
for (uint32 heapIndex = 0; heapIndex < heaps.size(); ++heapIndex) for (uint32 heapIndex = 0; heapIndex < heaps.size(); ++heapIndex)
{ {
for (uint32 alloc = 0; alloc < heaps[heapIndex].allocations.size(); ++alloc) for (uint32 alloc = 0; alloc < heaps[heapIndex].allocations.size(); ++alloc)
{ {
if (heaps[heapIndex].allocations[alloc]->bytesUsed == 0) if (heaps[heapIndex].allocations[alloc] == allocation)
{ {
heaps[heapIndex].inUse -= heaps[heapIndex].allocations[alloc]->bytesAllocated;
std::cout << "Heap " << heapIndex << ": " << (float)heaps[heapIndex].inUse / heaps[heapIndex].maxSize * 100 << "%" << std::endl;
heaps[heapIndex].allocations.removeAt(alloc, false); heaps[heapIndex].allocations.removeAt(alloc, false);
alloc--;
} }
} }
} }
@@ -259,7 +260,7 @@ uint32 Allocator::findMemoryType(uint32 typeFilter, VkMemoryPropertyFlags proper
} }
StagingBuffer::StagingBuffer(PGraphics graphics, OSubAllocation allocation, VkBuffer buffer, VkDeviceSize size, Gfx::QueueType owner) StagingBuffer::StagingBuffer(PGraphics graphics, OSubAllocation allocation, VkBuffer buffer, VkDeviceSize size, Gfx::QueueType owner)
: QueueOwnedResource(graphics->getFamilyMapping(), owner) : owner(owner)
, graphics(graphics) , graphics(graphics)
, allocation(std::move(allocation)) , allocation(std::move(allocation))
, buffer(buffer) , buffer(buffer)
@@ -270,9 +271,9 @@ StagingBuffer::StagingBuffer(PGraphics graphics, OSubAllocation allocation, VkBu
StagingBuffer::~StagingBuffer() StagingBuffer::~StagingBuffer()
{ {
graphics->getDestructionManager()->queueBuffer( graphics->getDestructionManager()->queueBuffer(
graphics->getQueueCommands(currentOwner)->getCommands(), buffer); graphics->getQueueCommands(owner)->getCommands(), buffer);
graphics->getDestructionManager()->queueAllocation( graphics->getDestructionManager()->queueAllocation(
graphics->getQueueCommands(currentOwner)->getCommands(), std::move(allocation)); graphics->getQueueCommands(owner)->getCommands(), std::move(allocation));
} }
void* StagingBuffer::map() void* StagingBuffer::map()
@@ -300,28 +301,6 @@ VkDeviceSize StagingBuffer::getOffset() const
return allocation->getOffset(); return allocation->getOffset();
} }
void StagingBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner)
{
assert(false);
}
void StagingBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage)
{
PCommand commandBuffer = graphics->getQueueCommands(currentOwner)->getCommands();
VkBufferMemoryBarrier barrier = {
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
.pNext = nullptr,
.srcAccessMask = srcAccess,
.dstAccessMask = dstAccess,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.buffer = buffer,
.offset = 0,
.size = size,
};
vkCmdPipelineBarrier(commandBuffer->getHandle(), srcStage, dstStage, 0, 0, nullptr, 1, &barrier, 0, nullptr);
}
StagingManager::StagingManager(PGraphics graphics, PAllocator pool) StagingManager::StagingManager(PGraphics graphics, PAllocator pool)
: graphics(graphics), pool(pool) : graphics(graphics), pool(pool)
{ {
@@ -333,8 +312,18 @@ StagingManager::~StagingManager()
OStagingBuffer StagingManager::create(uint64 size, Gfx::QueueType owner) OStagingBuffer StagingManager::create(uint64 size, Gfx::QueueType owner)
{ {
//vkDeviceWaitIdle(graphics->getDevice());
//std::cout << "Creating new stagingbuffer" << std::endl; //std::cout << "Creating new stagingbuffer" << std::endl;
uint32 queueIndex = graphics->getFamilyMapping().getQueueTypeFamilyIndex(Gfx::QueueType::DEDICATED_TRANSFER); for (uint32 i = 0; i < freeBuffers.size(); ++i)
{
if (size <= freeBuffers[i]->getSize() && owner == freeBuffers[i]->getOwner())
{
OStagingBuffer result = std::move(freeBuffers[i]);
freeBuffers.removeAt(i);
return result;
}
}
uint32 queueIndex = graphics->getFamilyMapping().getQueueTypeFamilyIndex(owner);
VkBufferCreateInfo stagingBufferCreateInfo = { VkBufferCreateInfo stagingBufferCreateInfo = {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.pNext = nullptr, .pNext = nullptr,
@@ -375,3 +364,8 @@ OStagingBuffer StagingManager::create(uint64 size, Gfx::QueueType owner)
return stagingBuffer; return stagingBuffer;
} }
void StagingManager::release(OStagingBuffer buffer)
{
freeBuffers.add(std::move(buffer));
}
+11 -6
View File
@@ -49,6 +49,8 @@ class Allocation
public: public:
Allocation(PGraphics graphics, PAllocator pool, VkDeviceSize size, uint8 memoryTypeIndex, Allocation(PGraphics graphics, PAllocator pool, VkDeviceSize size, uint8 memoryTypeIndex,
VkMemoryPropertyFlags properties, VkMemoryDedicatedAllocateInfo *dedicatedInfo = nullptr); VkMemoryPropertyFlags properties, VkMemoryDedicatedAllocateInfo *dedicatedInfo = nullptr);
Allocation(const Allocation& other) = delete;
Allocation& operator=(const Allocation& other) = delete;
~Allocation(); ~Allocation();
OSubAllocation getSuballocation(VkDeviceSize size, VkDeviceSize alignment); OSubAllocation getSuballocation(VkDeviceSize size, VkDeviceSize alignment);
void markFree(PSubAllocation alloc); void markFree(PSubAllocation alloc);
@@ -122,7 +124,7 @@ public:
return allocate(requirements, props, &allocInfo); return allocate(requirements, props, &allocInfo);
} }
void free(); void free(PAllocation allocation);
void print(); void print();
private: private:
static constexpr VkDeviceSize DEFAULT_ALLOCATION = 16 * 1024 * 1024; // 16MB static constexpr VkDeviceSize DEFAULT_ALLOCATION = 16 * 1024 * 1024; // 16MB
@@ -143,7 +145,7 @@ private:
VkPhysicalDeviceMemoryProperties memProperties; VkPhysicalDeviceMemoryProperties memProperties;
}; };
DEFINE_REF(Allocator) DEFINE_REF(Allocator)
class StagingBuffer : public Gfx::QueueOwnedResource class StagingBuffer
{ {
public: public:
StagingBuffer(PGraphics graphics, OSubAllocation allocation, VkBuffer buffer, VkDeviceSize size, Gfx::QueueType owner); StagingBuffer(PGraphics graphics, OSubAllocation allocation, VkBuffer buffer, VkDeviceSize size, Gfx::QueueType owner);
@@ -161,10 +163,12 @@ public:
{ {
return size; return size;
} }
constexpr Gfx::QueueType getOwner() const
{
return owner;
}
private: private:
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override; Gfx::QueueType owner;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override;
OSubAllocation allocation; OSubAllocation allocation;
PGraphics graphics; PGraphics graphics;
VkBuffer buffer; VkBuffer buffer;
@@ -178,10 +182,11 @@ public:
StagingManager(PGraphics graphics, PAllocator pool); StagingManager(PGraphics graphics, PAllocator pool);
~StagingManager(); ~StagingManager();
OStagingBuffer create(uint64 size, Gfx::QueueType owner); OStagingBuffer create(uint64 size, Gfx::QueueType owner);
void release(OStagingBuffer buffer);
private: private:
PGraphics graphics; PGraphics graphics;
PAllocator pool; PAllocator pool;
Array<OStagingBuffer> freeBuffers;
}; };
DEFINE_REF(StagingManager) DEFINE_REF(StagingManager)
} // namespace Vulkan } // namespace Vulkan
+9
View File
@@ -255,6 +255,7 @@ void Buffer::unmap()
vkCmdCopyBuffer(cmdHandle, stagingBuffer->getHandle(), buffers[currentBuffer].buffer, 1, &region); vkCmdCopyBuffer(cmdHandle, stagingBuffer->getHandle(), buffers[currentBuffer].buffer, 1, &region);
} }
//requestOwnershipTransfer(pending.prevQueue); //requestOwnershipTransfer(pending.prevQueue);
graphics->getStagingManager()->release(std::move(pending.stagingBuffer));
pendingBuffers.erase(this); pendingBuffers.erase(this);
} }
} }
@@ -278,6 +279,10 @@ UniformBuffer::UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo &
UniformBuffer::~UniformBuffer() UniformBuffer::~UniformBuffer()
{ {
if (dedicatedStagingBuffer != nullptr)
{
graphics->getStagingManager()->release(std::move(dedicatedStagingBuffer));
}
} }
bool UniformBuffer::updateContents(const DataSource &sourceData) bool UniformBuffer::updateContents(const DataSource &sourceData)
@@ -365,6 +370,10 @@ ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo &sou
ShaderBuffer::~ShaderBuffer() ShaderBuffer::~ShaderBuffer()
{ {
if (dedicatedStagingBuffer != nullptr)
{
graphics->getStagingManager()->release(std::move(dedicatedStagingBuffer));
}
} }
bool ShaderBuffer::updateContents(const DataSource &sourceData) bool ShaderBuffer::updateContents(const DataSource &sourceData)
@@ -346,13 +346,6 @@ DescriptorPool::DescriptorPool(PGraphics graphics, DescriptorLayout &layout)
DescriptorPool::~DescriptorPool() DescriptorPool::~DescriptorPool()
{ {
for (uint32 setIndex = 0; setIndex < cachedHandles.size(); ++setIndex)
{
if (cachedHandles[setIndex] != nullptr && cachedHandles[setIndex]->setHandle != VK_NULL_HANDLE)
{
graphics->getDestructionManager()->queueDescriptorSet(graphics->getGraphicsCommands()->getCommands(), Pair<VkDescriptorSet, VkDescriptorPool>(cachedHandles[setIndex]->setHandle, poolHandle));
}
}
graphics->getDestructionManager()->queueDescriptorPool(graphics->getGraphicsCommands()->getCommands(), poolHandle); graphics->getDestructionManager()->queueDescriptorPool(graphics->getGraphicsCommands()->getCommands(), poolHandle);
if(nextAlloc) if(nextAlloc)
{ {
+9 -13
View File
@@ -46,16 +46,21 @@ bool Fence::isSignaled()
{ {
return true; return true;
} }
VkResult res = vkGetFenceStatus(graphics->getDevice(), fence); VkResult r = vkGetFenceStatus(graphics->getDevice(), fence);
if (res == VK_SUCCESS) if (r == VK_SUCCESS)
{ {
signaled = true; signaled = true;
return true; return true;
} }
if (res == VK_NOT_READY) if (r == VK_NOT_READY)
{ {
return false; return false;
} }
else
{
VK_CHECK(r);
return false;
}
} }
void Fence::reset() void Fence::reset()
@@ -124,11 +129,6 @@ void DestructionManager::queueDescriptorPool(PCommand cmd, VkDescriptorPool pool
pools[cmd].add(pool); pools[cmd].add(pool);
} }
void DestructionManager::queueDescriptorSet(PCommand cmd, Pair<VkDescriptorSet, VkDescriptorPool> set)
{
sets[cmd].add(set);
}
void DestructionManager::queueAllocation(PCommand cmd, OSubAllocation alloc) void DestructionManager::queueAllocation(PCommand cmd, OSubAllocation alloc)
{ {
allocs[cmd].add(std::move(alloc)); allocs[cmd].add(std::move(alloc));
@@ -152,10 +152,6 @@ void DestructionManager::notifyCmdComplete(PCommand cmd)
{ {
vkDestroySemaphore(graphics->getDevice(), sem, nullptr); vkDestroySemaphore(graphics->getDevice(), sem, nullptr);
} }
for (auto [set, pool] : sets[cmd])
{
vkFreeDescriptorSets(graphics->getDevice(), pool, 1, &set);
}
for (auto pool : pools[cmd]) for (auto pool : pools[cmd])
{ {
vkDestroyDescriptorPool(graphics->getDevice(), pool, nullptr); vkDestroyDescriptorPool(graphics->getDevice(), pool, nullptr);
@@ -168,7 +164,7 @@ void DestructionManager::notifyCmdComplete(PCommand cmd)
images[cmd].clear(); images[cmd].clear();
views[cmd].clear(); views[cmd].clear();
sems[cmd].clear(); sems[cmd].clear();
pools[cmd].clear();
renderPasses[cmd].clear(); renderPasses[cmd].clear();
allocs[cmd].clear(); allocs[cmd].clear();
//graphics->getAllocator()->free();
} }
-2
View File
@@ -63,7 +63,6 @@ public:
void queueSemaphore(PCommand cmd, VkSemaphore sem); void queueSemaphore(PCommand cmd, VkSemaphore sem);
void queueRenderPass(PCommand cmd, VkRenderPass renderPass); void queueRenderPass(PCommand cmd, VkRenderPass renderPass);
void queueDescriptorPool(PCommand cmd, VkDescriptorPool pool); void queueDescriptorPool(PCommand cmd, VkDescriptorPool pool);
void queueDescriptorSet(PCommand cmd, Pair<VkDescriptorSet, VkDescriptorPool> set);
void queueAllocation(PCommand cmd, OSubAllocation alloc); void queueAllocation(PCommand cmd, OSubAllocation alloc);
void notifyCmdComplete(PCommand cmdbuffer); void notifyCmdComplete(PCommand cmdbuffer);
private: private:
@@ -74,7 +73,6 @@ private:
Map<PCommand, List<VkSemaphore>> sems; Map<PCommand, List<VkSemaphore>> sems;
Map<PCommand, List<VkRenderPass>> renderPasses; Map<PCommand, List<VkRenderPass>> renderPasses;
Map<PCommand, List<VkDescriptorPool>> pools; Map<PCommand, List<VkDescriptorPool>> pools;
Map<PCommand, List<Pair<VkDescriptorSet, VkDescriptorPool>>> sets;
Map<PCommand, List<OSubAllocation>> allocs; Map<PCommand, List<OSubAllocation>> allocs;
}; };
DEFINE_REF(DestructionManager) DEFINE_REF(DestructionManager)
+1
View File
@@ -157,6 +157,7 @@ TextureBase::TextureBase(PGraphics graphics, VkImageViewType viewType,
// When loading a texture from a file, we will almost always use it as a texture map for fragment shaders // When loading a texture from a file, we will almost always use it as a texture map for fragment shaders
changeLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); changeLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
graphics->getStagingManager()->release(std::move(staging));
} }
else if(usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) else if(usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
{ {
+11 -1
View File
@@ -97,9 +97,13 @@ Window::~Window()
glfwDestroyWindow(static_cast<GLFWwindow *>(windowHandle)); glfwDestroyWindow(static_cast<GLFWwindow *>(windowHandle));
} }
void Window::beginFrame() void Window::pollInput()
{ {
glfwPollEvents(); glfwPollEvents();
}
void Window::beginFrame()
{
vkAcquireNextImageKHR(graphics->getDevice(), swapchain, std::numeric_limits<uint64>::max(), imageAvailableSemaphores[currentSemaphoreIndex]->getHandle(), VK_NULL_HANDLE, &currentImageIndex); vkAcquireNextImageKHR(graphics->getDevice(), swapchain, std::numeric_limits<uint64>::max(), imageAvailableSemaphores[currentSemaphoreIndex]->getHandle(), VK_NULL_HANDLE, &currentImageIndex);
swapChainTextures[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); swapChainTextures[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
graphics->getGraphicsCommands()->getCommands()->waitForSemaphore(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, imageAvailableSemaphores[currentSemaphoreIndex]); graphics->getGraphicsCommands()->getCommands()->waitForSemaphore(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, imageAvailableSemaphores[currentSemaphoreIndex]);
@@ -210,6 +214,12 @@ void Window::close()
void Window::resize(int width, int height) void Window::resize(int width, int height)
{ {
if (width == 0 || height == 0)
{
paused = true;
return;
}
paused = false;
querySurface(); querySurface();
chooseSwapSurfaceFormat(); chooseSwapSurfaceFormat();
framebufferFormat = cast(format.format); framebufferFormat = cast(format.format);
+1
View File
@@ -13,6 +13,7 @@ class Window : public Gfx::Window
public: public:
Window(PGraphics graphics, const WindowCreateInfo &createInfo); Window(PGraphics graphics, const WindowCreateInfo &createInfo);
virtual ~Window(); virtual ~Window();
virtual void pollInput() override;
virtual void beginFrame() override; virtual void beginFrame() override;
virtual void endFrame() override; virtual void endFrame() override;
virtual Gfx::PTexture2D getBackBuffer() override; virtual Gfx::PTexture2D getBackBuffer() override;
+1 -1
View File
@@ -31,7 +31,7 @@ Matrix4 Viewport::getProjectionMatrix() const
{ {
if (fieldOfView > 0.0f) if (fieldOfView > 0.0f)
{ {
return glm::perspective(fieldOfView, sizeX / static_cast<float>(sizeY), 0.1f, 1000.0f); return glm::perspective(fieldOfView, sizeX / static_cast<float>(sizeY), 0.1f, 10000.0f);
} }
else else
{ {
+6 -1
View File
@@ -11,6 +11,7 @@ class Window
public: public:
Window(); Window();
virtual ~Window(); virtual ~Window();
virtual void pollInput() = 0;
virtual void beginFrame() = 0; virtual void beginFrame() = 0;
virtual void endFrame() = 0; virtual void endFrame() = 0;
virtual void onWindowCloseEvent() = 0; virtual void onWindowCloseEvent() = 0;
@@ -34,11 +35,15 @@ public:
{ {
return framebufferHeight; return framebufferHeight;
} }
constexpr bool isPaused() const
{
return paused;
}
protected: protected:
SeFormat framebufferFormat; SeFormat framebufferFormat;
uint32 framebufferWidth; uint32 framebufferWidth;
uint32 framebufferHeight; uint32 framebufferHeight;
bool paused = false;
}; };
DEFINE_REF(Window) DEFINE_REF(Window)
-3
View File
@@ -76,9 +76,6 @@ void GameView::render()
void GameView::applyArea(URect rect) void GameView::applyArea(URect rect)
{ {
viewport = graphics->createViewport(owner->getGfxHandle(), ViewportCreateInfo{
.dimensions = rect,
});
renderGraph.updateViewport(viewport); renderGraph.updateViewport(viewport);
} }
+2 -2
View File
@@ -25,10 +25,10 @@ public:
virtual void prepareRender() override; virtual void prepareRender() override;
virtual void render() override; virtual void render() override;
virtual void applyArea(URect rect) override;
void reloadGame(); void reloadGame();
private: protected:
virtual void applyArea(URect rect) override;
OScene scene; OScene scene;
GameInterface gameInterface; GameInterface gameInterface;
RenderGraph< RenderGraph<
+8
View File
@@ -7,6 +7,7 @@ using namespace Seele;
View::View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &viewportInfo, std::string name) View::View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &viewportInfo, std::string name)
: graphics(graphics) : graphics(graphics)
, owner(window) , owner(window)
, createInfo(viewportInfo)
, name(name) , name(name)
{ {
viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo); viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo);
@@ -18,6 +19,13 @@ View::~View()
{ {
} }
void View::resize(URect area)
{
createInfo.dimensions = area;
viewport = graphics->createViewport(owner->getGfxHandle(), createInfo);
applyArea(area);
}
void View::setFocused() void View::setFocused()
{ {
owner->setFocused(this); owner->setFocused(this);
+3 -1
View File
@@ -17,14 +17,16 @@ public:
virtual void prepareRender() = 0; virtual void prepareRender() = 0;
virtual void render() = 0; virtual void render() = 0;
virtual void applyArea(URect area) = 0; void resize(URect area);
void setFocused(); void setFocused();
const std::string& getName(); const std::string& getName();
protected: protected:
virtual void applyArea(URect area) = 0;
Gfx::PGraphics graphics; Gfx::PGraphics graphics;
Gfx::OViewport viewport; Gfx::OViewport viewport;
ViewportCreateInfo createInfo;
PWindow owner; PWindow owner;
std::string name; std::string name;
+6 -1
View File
@@ -20,6 +20,11 @@ void Window::addView(PView view)
views.add(view); views.add(view);
} }
void Window::pollInputs()
{
gfxHandle->pollInput();
}
void Window::render() void Window::render()
{ {
gfxHandle->beginFrame(); gfxHandle->beginFrame();
@@ -61,7 +66,7 @@ void Window::onResize(uint32 width, uint32 height)
for (auto& view : views) for (auto& view : views)
{ {
// TODO: some sort of layouting algorithm should do this // TODO: some sort of layouting algorithm should do this
view->applyArea(URect{ view->resize(URect{
.size = UVector2(width, height), .size = UVector2(width, height),
.offset = UVector2(0, 0), .offset = UVector2(0, 0),
}); });
+5
View File
@@ -12,10 +12,15 @@ public:
Window(PWindowManager owner, Gfx::OWindow handle); Window(PWindowManager owner, Gfx::OWindow handle);
~Window(); ~Window();
void addView(PView view); void addView(PView view);
void pollInputs();
void render(); void render();
Gfx::PWindow getGfxHandle(); Gfx::PWindow getGfxHandle();
void setFocused(PView view); void setFocused(PView view);
void onResize(uint32 width, uint32 height); void onResize(uint32 width, uint32 height);
constexpr bool isPaused() const
{
return gfxHandle->isPaused();
}
protected: protected:
PWindowManager owner; PWindowManager owner;
Array<PView> views; Array<PView> views;
+3
View File
@@ -22,6 +22,9 @@ void WindowManager::render()
{ {
for (auto& window : windows) for (auto& window : windows)
{ {
window->pollInputs();
if (window->isPaused())
continue;
window->render(); window->render();
} }
} }