The Pyramid Engine's Render System provides a high-level rendering abstraction that manages the complete rendering pipeline. It implements modern rendering techniques including command buffers, render passes, and efficient resource management.
The main rendering system class that orchestrates all rendering operations.
RenderSystem();void Initialize(IGraphicsDevice* device);Initializes the render system with the specified graphics device.
Parameters:
device: Pointer to the graphics device to use for rendering
void BeginFrame();Begins a new rendering frame. Must be called before any rendering operations.
void EndFrame();Ends the current rendering frame and presents the results to the screen.
void Render(const Scene& scene, const Camera& camera);Renders a scene from the specified camera's perspective.
Parameters:
scene: The scene to rendercamera: The camera to render from
void SetRenderPass(RenderPassType type);Sets the current render pass for subsequent rendering operations.
Parameters:
type: The type of render pass (Forward, Deferred, Shadow, etc.)
void InitializeCommandBuffers();Initializes the command buffer system for efficient GPU command submission.
void InitializeRenderPasses();Sets up the various render passes used by the system.
The render system supports multiple render pass types:
enum class RenderPassType {
Forward, // Forward rendering pass
Deferred, // Deferred rendering pass
Shadow, // Shadow mapping pass
PostProcess, // Post-processing pass
UI // User interface rendering pass
};- Traditional immediate-mode rendering
- Suitable for transparent objects and simple scenes
- Lower memory usage but higher fill rate requirements
- Geometry buffer (G-buffer) based rendering
- Efficient for complex lighting scenarios
- Higher memory usage but consistent performance
- Generates shadow maps for dynamic lighting
- Supports multiple shadow map resolutions
- Cascade shadow mapping for directional lights
- Screen-space effects and tone mapping
- Bloom, SSAO, and other effects
- Frame buffer manipulation
#include <Pyramid/Graphics/Renderer/RenderSystem.hpp>
// Initialize render system
auto renderSystem = std::make_unique<RenderSystem>();
renderSystem->Initialize(graphicsDevice);
// Setup camera
Camera camera(Math::Radians(60.0f), 16.0f/9.0f, 0.1f, 1000.0f);
camera.SetPosition(Math::Vec3(0.0f, 5.0f, 10.0f));
camera.LookAt(Math::Vec3::Zero);
// Create scene
auto scene = SceneUtils::CreateTestScene();
// Render loop
while (running) {
renderSystem->BeginFrame();
renderSystem->Render(*scene, camera);
renderSystem->EndFrame();
}// Shadow pass
renderSystem->BeginFrame();
renderSystem->SetRenderPass(RenderPassType::Shadow);
renderSystem->Render(*scene, shadowCamera);
// Main rendering pass
renderSystem->SetRenderPass(RenderPassType::Forward);
renderSystem->Render(*scene, mainCamera);
// Post-processing pass
renderSystem->SetRenderPass(RenderPassType::PostProcess);
renderSystem->ApplyPostProcessing();
renderSystem->EndFrame();// The render system automatically manages command buffers
// for efficient GPU command submission
renderSystem->BeginFrame(); // Starts command recording
// ... rendering operations are batched into command buffers
renderSystem->EndFrame(); // Submits all recorded commands- Commands are automatically batched for optimal GPU utilization
- State changes are minimized through intelligent sorting
- Draw calls are merged when possible
- Efficient resource pooling for temporary rendering resources
- Automatic garbage collection of unused resources
- Smart caching of frequently used render states
- Minimal CPU-GPU synchronization points
- Efficient use of GPU memory bandwidth
- Optimized for modern graphics APIs
The render system seamlessly integrates with other graphics components:
// Works with the camera system
Camera camera = scene.GetActiveCamera();
renderSystem->Render(*scene, camera);
// Integrates with the material system
Material material = object.GetMaterial();
renderSystem->ApplyMaterial(material);
// Uses the scene management system
auto visibleObjects = scene.GetVisibleObjects(camera);
renderSystem->RenderObjects(visibleObjects);The render system provides comprehensive error checking:
if (!renderSystem->Initialize(device)) {
PYRAMID_LOG_ERROR("Failed to initialize render system");
return false;
}
// Automatic validation of render state
renderSystem->ValidateRenderState(); // Debug builds onlyThe render system is designed for extensibility:
- Custom Render Passes: Add application-specific rendering passes
- Plugin Architecture: Load rendering plugins at runtime
- Multi-API Support: Abstract rendering across different graphics APIs
- Compute Shaders: Integration with compute-based rendering techniques
- Graphics Device API - Low-level graphics operations
- Camera API - Camera system documentation
- Scene Management - Scene organization and culling
- Shader System - Shader management and compilation