3#include <Common/HashedString.hpp>
4#include <Common/Rendering/GeometryRenderingStats.hpp>
5#include <Grindstone.Renderables.3D/include/Assets/Mesh3dAsset.hpp>
6#include <Grindstone.Renderables.3D/include/FrustumCulling.hpp>
7#include <Grindstone.Renderables.3D/include/Components/MeshRendererComponent.hpp>
15 template<
typename MeshComponentType,
typename RenderTask>
16 std::vector<RenderTask> GenerateTaskList(
18 entt::registry& registry,
20 const glm::mat4& viewMatrix,
23 std::vector<RenderTask>&,
27 const MeshComponentType&,
31 std::vector<RenderTask> renderTasks;
32 renderTasks.reserve(1000);
36 [&submeshCallback, &renderingStats, ®istry, &renderTasks, &viewMatrix, frustum, renderQueueHash](
39 const MeshComponentType& meshComponent,
42 const Mesh3dAsset* meshAsset = meshComponent.mesh.Get();
44 if (meshAsset ==
nullptr) {
48 Math::Matrix4 transform = TransformComponent::GetWorldTransformMatrix(entity, registry);
49 glm::mat4 viewTransformTransform = viewMatrix * transform;
52 if (!IsInFrustum(frustum, viewTransformTransform, aabb)) {
53 renderingStats.objectsCulled += 1;
57 renderingStats.objectsRendered += 1;
61 .entityId =
static_cast<uint32_t
>(entity)
63 meshRenderComponent.perDrawUniformBuffer->UploadData(&renderableData);
65 std::vector<Grindstone::AssetReference<Grindstone::MaterialAsset>>& materials = meshRenderComponent.materials;
66 for (
const Grindstone::Mesh3dAsset::Submesh& submesh : meshAsset->submeshes) {
82 template<
typename RenderTask>
84 Grindstone::Rendering::GeometryRenderStats& renderingStats,
85 GraphicsAPI::DescriptorSet* engineDescriptorSet,
86 GraphicsAPI::CommandBuffer* commandBuffer,
87 const std::vector<RenderTask>& renderTasks
89 const GraphicsAPI::PipelineLayout* pipelineLayout =
nullptr;
90 const GraphicsAPI::GraphicsPipeline* graphicsPipeline =
nullptr;
91 const GraphicsAPI::DescriptorSet* materialDescriptorSet =
nullptr;
93 for (
const RenderTask& renderTask : renderTasks) {
94 if (graphicsPipeline != renderTask.pipeline) {
95 graphicsPipeline = renderTask.pipeline;
96 pipelineLayout = graphicsPipeline->pipelineLayout;
97 commandBuffer->BindGraphicsPipeline(renderTask.pipeline);
98 renderingStats.pipelineBinds += 1;
101 commandBuffer->BindVertexArrayObject(renderTask.vertexArrayObject);
103 if (renderTask.materialDescriptorSet != materialDescriptorSet) {
104 std::array<GraphicsAPI::DescriptorSet*, 3> descriptors = {
106 renderTask.materialDescriptorSet,
107 renderTask.perDrawDescriptorSet,
109 commandBuffer->BindGraphicsDescriptorSet(
113 static_cast<uint32_t
>(descriptors.size())
115 renderingStats.materialBinds += 1;
118 renderingStats.drawCalls += 1;
119 renderingStats.vertices += renderTask.indexCount;
120 renderingStats.triangles += renderTask.indexCount / 3;
122 commandBuffer->DrawIndices(
123 renderTask.baseIndex,
124 renderTask.indexCount,
127 renderTask.baseVertex
Definition HashedString.hpp:9
Definition AttachmentInfo.hpp:15
Definition Mesh3dAsset.hpp:28
Definition Mesh3dAsset.hpp:26
Definition MeshRendererComponent.hpp:16
Definition FrustumCulling.hpp:14
Definition FrustumCulling.hpp:6
Definition RenderTasks.hpp:10
Definition GeometryRenderingStats.hpp:6