-
Notifications
You must be signed in to change notification settings - Fork 280
Open
Labels
GraphicsGraphical featureGraphical feature
Description
Problem this feature should fix
A lot of the code to draw the scene is redundant, as it requires to iterate over the scene to find drawables, filter them, and prepare them for rendering. The implementation is also very inconsistent.
Expected solution
We could implement some sort of "Frame builder" that would take a scene, and:
- Parse the scene
- Filter
- Prepare
- and Draw
We could also add an additional step for batching.
Model bounds culling could be added back here too (removed by #561)
Example
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
#include <span>
#include <typeinfo>
namespace Math {
struct Transform {};
}
namespace Rendering {
struct Material {};
struct Mesh {};
enum class EPrimitiveMode { TRIANGLE, QUAD, LINE };
struct Drawable {
Material material;
Mesh mesh;
EPrimitiveMode primitiveMode;
std::optional<std::string> pass;
};
}
namespace Engine {
enum class EVisibilityFlags {};
struct MaterialRenderer {
Rendering::Material material;
};
struct MeshRenderer {
Rendering::Mesh mesh;
};
struct Actor {
std::optional<MaterialRenderer> materialRenderer;
};
struct Scene {
std::vector<Actor> actors;
};
}
namespace FrameBuilder {
struct ParsedDrawable {
Rendering::Mesh mesh;
Rendering::Material material;
Math::Transform transform;
Engine::EVisibilityFlags visibilityFlags;
};
struct ParsingResult {
std::vector<ParsedDrawable> parsedDrawables;
};
struct FilteredDrawable {
Rendering::Mesh mesh;
Rendering::Material material;
Math::Transform transform;
};
struct FilteringResult {
std::vector<FilteredDrawable> filteredDrawables;
};
struct PreparationResult {
std::vector<Rendering::Drawable> preparedDrawables;
};
ParsingResult Parse(const Engine::Scene& scene) { return{}; }
FilteringResult Filter(const ParsingResult& parsingResult) { return{}; }
PreparationResult Prepare(const FilteringResult& filteringResult) { return{}; }
}
namespace {
void SubmitDrawable(const const Rendering::Drawable& drawble) {}
void SubmitDrawables(const std::span<const Rendering::Drawable> drawables) {}
}
int main()
{
// Created by the engine, accessible through the scene renderer.
Engine::Scene scene;
// From inside the scene renderer, we always parse the scene.
// Render pass can use that information for filtering and preparation.
auto sceneParsingResult = FrameBuilder::Parse(scene);
// Opaque Render Pass
{
auto sceneFilteringResult = FrameBuilder::Filter(sceneParsingResult);
auto preparationResult = FrameBuilder::Prepare(sceneFilteringResult);
// Add extra custom preparation logic here if needed.
for (auto& drawable : preparationResult.preparedDrawables)
{
// drawable.material.pass = "OpaquePass"; // Set the pass for opaque rendering.
}
SubmitDrawables(preparationResult.preparedDrawables);
}
return 0;
}Metadata
Metadata
Assignees
Labels
GraphicsGraphical featureGraphical feature