Move Drawable draw call recording logic out of renderer
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "Renderer.hpp"
|
||||
#include "VulkanDrawContext.hpp"
|
||||
#include "Scene/Shader.hpp"
|
||||
#include "Scene/Geometry.hpp"
|
||||
#include "Scene/VulkanGeometry.hpp"
|
||||
@@ -154,27 +155,11 @@ namespace openVulkanoCpp::Vulkan
|
||||
|
||||
shader->Record(cmdHelper->cmdBuffer, currentImageId);
|
||||
Scene::Drawable** drawablePointer;
|
||||
VulkanDrawContext drawContext { poolId, currentImageId, cmdHelper->cmdBuffer, this };
|
||||
while((drawablePointer = jobQueue->Pop()) != nullptr)
|
||||
{
|
||||
Scene::Drawable* drawable = *drawablePointer;
|
||||
Scene::Geometry* mesh = drawable->mesh;
|
||||
VulkanGeometry* renderGeo = dynamic_cast<VulkanGeometry*>(mesh->renderGeo);
|
||||
if (mesh != lastGeo)
|
||||
{
|
||||
if (!mesh->renderGeo) renderGeo = resourceManager.PrepareGeometry(mesh);
|
||||
renderGeo->RecordBind(cmdHelper->cmdBuffer);
|
||||
lastGeo = mesh;
|
||||
}
|
||||
for(Scene::Node* node : drawable->nodes)
|
||||
{
|
||||
if (node != lastNode)
|
||||
{
|
||||
if (!node->renderNode) resourceManager.PrepareNode(node);
|
||||
dynamic_cast<VulkanNode*>(node->renderNode)->Record(cmdHelper->cmdBuffer, currentImageId);
|
||||
lastNode = node;
|
||||
}
|
||||
renderGeo->RecordDraw(cmdHelper->cmdBuffer);
|
||||
}
|
||||
drawable->GetEncoder().vulkan(drawable, &drawContext);
|
||||
}
|
||||
cmdHelper->cmdBuffer.end();
|
||||
}
|
||||
|
||||
@@ -74,5 +74,7 @@ namespace openVulkanoCpp::Vulkan
|
||||
void Render();
|
||||
|
||||
void RecordSecondaryBuffer(Data::ReadOnlyAtomicArrayQueue<Scene::Drawable*>* jobQueue, uint32_t poolId);
|
||||
|
||||
ResourceManager& GetResourceManager() { return resourceManager; }
|
||||
};
|
||||
}
|
||||
|
||||
34
openVulkanoCpp/Vulkan/Scene/SimpleDrawableVulkanEncoder.cpp
Normal file
34
openVulkanoCpp/Vulkan/Scene/SimpleDrawableVulkanEncoder.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "Scene/SimpleDrawable.hpp"
|
||||
#include "VulkanGeometry.hpp"
|
||||
#include "VulkanNode.hpp"
|
||||
#include "Vulkan/VulkanDrawContext.hpp"
|
||||
|
||||
using namespace openVulkanoCpp::Scene;
|
||||
|
||||
namespace openVulkanoCpp::Vulkan
|
||||
{
|
||||
void EncodeSimpleDrawable(Drawable* instance, Vulkan::VulkanDrawContext* drawContext)
|
||||
{
|
||||
Geometry* mesh = dynamic_cast<SimpleDrawable*>(instance)->GetMesh();
|
||||
VulkanGeometry* renderGeo = dynamic_cast<VulkanGeometry*>(mesh->renderGeo);
|
||||
if (!mesh->renderGeo) renderGeo = drawContext->renderer->GetResourceManager().PrepareGeometry(mesh);
|
||||
renderGeo->RecordBind(drawContext->commandBuffer);
|
||||
for(Node* node : instance->GetNodes())
|
||||
{
|
||||
if (!node->renderNode) drawContext->renderer->GetResourceManager().PrepareNode(node);
|
||||
dynamic_cast<VulkanNode*>(node->renderNode)->Record(drawContext->commandBuffer, drawContext->currentImageId);
|
||||
renderGeo->RecordDraw(drawContext->commandBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
void* simpleDrawableVulkanEncoderReg = DrawEncoder::RegisterVulkanEncodeFunction<SimpleDrawable>(&openVulkanoCpp::Vulkan::EncodeSimpleDrawable);
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "IRecordable.hpp"
|
||||
#include "Scene/Scene.hpp"
|
||||
#include "Scene/Geometry.hpp"
|
||||
#include "Vulkan/Resources/ManagedResource.hpp"
|
||||
|
||||
namespace openVulkanoCpp::Vulkan
|
||||
{
|
||||
|
||||
19
openVulkanoCpp/Vulkan/VulkanDrawContext.hpp
Normal file
19
openVulkanoCpp/Vulkan/VulkanDrawContext.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "Renderer.hpp"
|
||||
|
||||
namespace openVulkanoCpp::Vulkan
|
||||
{
|
||||
class VulkanDrawContext
|
||||
{
|
||||
public:
|
||||
size_t encoderThreadId;
|
||||
size_t currentImageId;
|
||||
vk::CommandBuffer& commandBuffer;
|
||||
Renderer* renderer;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user