3#include <Common/HashedString.hpp>
4#include <Common/Rendering/AssetRendererFilter.hpp>
5#include <Common/Rendering/GeometryRenderingStats.hpp>
6#include <Grindstone.Renderables.3D/include/Assets/Mesh3dAsset.hpp>
7#include <Grindstone.Renderables.3D/include/FrustumCulling.hpp>
8#include <Grindstone.Renderables.3D/include/Components/MeshRendererComponent.hpp>
16 template<
typename MeshComponentType,
typename RenderTask>
17 std::vector<RenderTask> GenerateTaskList(
20 entt::registry& registry,
23 const glm::mat4& viewMatrix,
25 std::vector<RenderTask>&,
29 const MeshComponentType&,
33 std::vector<RenderTask> renderTasks;
34 renderTasks.reserve(1000);
36 if (filter.useWhitelist) {
37 GS_ASSERT_ENGINE_WITH_MESSAGE(filter.blacklist.GetSize() == 0,
"You can only use the blacklist if the whitelist is empty");
39 for (entt::entity& entity : filter.whitelist) {
41 if (transformComponent ==
nullptr || meshComponent ==
nullptr || meshRendererComponent ==
nullptr) {
45 const Mesh3dAsset* meshAsset = meshComponent->mesh.Get();
47 if (meshAsset ==
nullptr) {
51 Math::Matrix4 transform = TransformComponent::GetWorldTransformMatrix(entity, registry);
52 glm::mat4 viewTransformTransform = viewMatrix * transform;
55 if (!IsInFrustum(frustum, viewTransformTransform, aabb)) {
56 renderingStats.objectsCulled += 1;
60 renderingStats.objectsRendered += 1;
64 .entityId =
static_cast<uint32_t
>(entity)
66 meshRendererComponent->perDrawUniformBuffer->UploadData(&renderableData);
68 std::vector<Grindstone::AssetReference<Grindstone::MaterialAsset>>& materials = meshRendererComponent->materials;
69 for (
const Grindstone::Mesh3dAsset::Submesh& submesh : meshAsset->submeshes) {
76 *meshRendererComponent
82 GS_ASSERT_ENGINE_WITH_MESSAGE(filter.blacklist.GetSize() == 0,
"Blacklist support not implemented yet!");
83 GS_ASSERT_ENGINE_WITH_MESSAGE(filter.whitelist.GetSize() == 0,
"You can only use the whitelist if useWhitelist is true");
85 auto view = registry.view<
const entt::entity,
const TransformComponent,
const MeshComponentType, MeshRendererComponent>();
87 [&submeshCallback, &renderingStats, ®istry, &renderTasks, &viewMatrix, frustum, renderQueueHash](
89 const TransformComponent& transformComponent,
90 const MeshComponentType& meshComponent,
91 MeshRendererComponent& meshRenderComponent
93 const Mesh3dAsset* meshAsset = meshComponent.mesh.Get();
95 if (meshAsset ==
nullptr) {
99 Math::Matrix4 transform = TransformComponent::GetWorldTransformMatrix(entity, registry);
100 glm::mat4 viewTransformTransform = viewMatrix * transform;
102 Grindstone::Renderer::AABB aabb{ meshAsset->boundingData.minAABB, meshAsset->boundingData.maxAABB };
103 if (!IsInFrustum(frustum, viewTransformTransform, aabb)) {
104 renderingStats.objectsCulled += 1;
108 renderingStats.objectsRendered += 1;
112 .entityId =
static_cast<uint32_t
>(entity)
114 meshRenderComponent.perDrawUniformBuffer->UploadData(&renderableData);
116 std::vector<Grindstone::AssetReference<Grindstone::MaterialAsset>>& materials = meshRenderComponent.materials;
117 for (
const Grindstone::Mesh3dAsset::Submesh& submesh : meshAsset->submeshes) {
134 template<
typename RenderTask>
136 Grindstone::Rendering::GeometryRenderStats& renderingStats,
137 GraphicsAPI::DescriptorSet* engineDescriptorSet,
138 GraphicsAPI::CommandBuffer* commandBuffer,
139 const std::vector<RenderTask>& renderTasks
141 const GraphicsAPI::PipelineLayout* pipelineLayout =
nullptr;
142 const GraphicsAPI::GraphicsPipeline* graphicsPipeline =
nullptr;
143 const GraphicsAPI::DescriptorSet* materialDescriptorSet =
nullptr;
145 for (
const RenderTask& renderTask : renderTasks) {
146 if (graphicsPipeline != renderTask.pipeline) {
147 graphicsPipeline = renderTask.pipeline;
148 pipelineLayout = graphicsPipeline->pipelineLayout;
149 commandBuffer->BindGraphicsPipeline(renderTask.pipeline);
150 renderingStats.pipelineBinds += 1;
153 commandBuffer->BindVertexArrayObject(renderTask.vertexArrayObject);
155 if (renderTask.materialDescriptorSet != materialDescriptorSet) {
156 std::array<GraphicsAPI::DescriptorSet*, 3> descriptors = {
158 renderTask.materialDescriptorSet,
159 renderTask.perDrawDescriptorSet,
161 commandBuffer->BindGraphicsDescriptorSet(
165 static_cast<uint32_t
>(descriptors.size())
167 renderingStats.materialBinds += 1;
170 renderingStats.drawCalls += 1;
171 renderingStats.vertices += renderTask.indexCount;
172 renderingStats.triangles += renderTask.indexCount / 3;
174 commandBuffer->DrawIndices(
175 renderTask.baseIndex,
176 renderTask.indexCount,
179 renderTask.baseVertex
Definition HashedString.hpp:10
Definition AttachmentInfo.hpp:17
Definition Mesh3dAsset.hpp:28
Definition Mesh3dAsset.hpp:26
Definition MeshRendererComponent.hpp:16
Definition FrustumCulling.hpp:14
Definition FrustumCulling.hpp:6
Definition RenderTasks.hpp:11
Definition AssetRendererFilter.hpp:8
Definition GeometryRenderingStats.hpp:6