SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
RenderContext.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <string>
5#include <Memory/RefPtr.hpp>
8#include <Runtime/Texture.hpp>
10
11namespace Sleak {
12 class Material;
13 namespace RenderEngine {
14
15 /// Rasterizer fill style for a draw.
23
24/// Which triangle winding gets culled.
25enum class RenderFace {
29};
30
31/// Depth test comparison function.
42
43 /**
44 * @class RenderContext
45 * @brief Abstract interface for high-level graphics command execution and resource management.
46 * * The RenderContext acts as the primary bridge between the Sleak Engine's logic and the
47 * underlying Graphics API (Vulkan, DX11, etc.). It provides a unified set of commands for:
48 * - **Command Dispatch:** Executing non-indexed, indexed, and instanced draw calls.
49 * - **State Management:** Configuring the pipeline state (Viewports, Culling, Rasterization).
50 * - **Resource Creation:** Serving as a Factory for API-specific buffers, shaders, and textures.
51 * - **Resource Binding:** Mapping hardware buffers to specific pipeline slots.
52 * * @note This is a pure virtual interface. Implementations (e.g., VulkanRenderContext)
53 * must handle the specific synchronization and driver-level requirements of their respective APIs.
54 */
56 public:
57 // Rendering commands
58 /// Non-indexed draw from the currently bound vertex buffer.
59 virtual void Draw(uint32_t vertexCount) = 0;
60 /// Indexed draw from the currently bound vertex/index buffers.
61 virtual void DrawIndexed(uint32_t indexCount) = 0;
62 /// Non-indexed instanced draw.
63 virtual void DrawInstance(uint32_t instanceCount, uint32_t vertexPerInstance) = 0;
64 /// Indexed instanced draw.
65 virtual void DrawIndexedInstance(uint32_t instanceCount, uint32_t indexPerInstance) = 0;
66
67 // State management
68 virtual void SetRenderFace(RenderFace face) = 0;
69 virtual void SetRenderMode(RenderMode mode) = 0;
70 /// Sets the active viewport rect and depth range in pixel/NDC units.
71 virtual void SetViewport(float x, float y, float width, float height, float minDepth = 0.0f, float maxDepth = 1.0f) = 0;
72 virtual void ClearRenderTarget(float r, float g, float b, float a) = 0;
73 virtual void ClearDepthStencil(bool clearDepth, bool clearStencil, float depth, uint8_t stencil) = 0;
74
75 // Depth/cull state (for skybox and other special rendering)
76 virtual void SetDepthWrite(bool enabled) { (void)enabled; }
77 virtual void SetDepthCompare(DepthCompare compare) { (void)compare; }
78 virtual void SetCullEnabled(bool enabled) { (void)enabled; }
79 virtual void BindTexture(RefPtr<Sleak::Texture> texture, uint32_t slot = 0) { (void)texture; (void)slot; }
80 virtual void BindTextureRaw(Sleak::Texture* texture, uint32_t slot = 0) { (void)texture; (void)slot; }
81
82 // Skybox pipeline support (Vulkan needs separate pipeline for cubemap)
83 virtual void BeginSkyboxPass() {}
84 virtual void EndSkyboxPass() {}
85
86 // Bone buffer support (Vulkan needs UBO path — push constants too small)
87 virtual void BindBoneBuffer(RefPtr<BufferBase> buffer) { (void)buffer; }
88
89 // Skinned pipeline support (Vulkan needs separate pipeline for skinned shaders)
90 virtual void BeginSkinnedPass() {}
91 virtual void EndSkinnedPass() {}
92
93 // Custom vertex format pipeline support (registered via VertexFormatRegistry)
94 /// Binds the pipeline built for a registered vertex layout in the active render pass.
95 virtual void BeginCustomFormatPass(VertexFormatHandle format) { (void)format; }
96 /// Restores the pipeline that was active before the custom format draws.
97 virtual void EndCustomFormatPass() {}
98
99 // Debug line rendering pipeline support
100 virtual void BeginDebugLinePass() {}
101 virtual void EndDebugLinePass() {}
102
103 // Shadow pass support
104 virtual void BeginShadowPass() {}
105 virtual void EndShadowPass() {}
106 virtual bool IsShadowPassActive() const { return false; }
107
108 // Deferred rendering support
109 // Returns true when a geometry pass (GBuffer) is active this frame.
110 virtual bool IsInGeometryPass() const { return false; }
111 // Returns true when deferred lighting is enabled for this renderer.
112 virtual bool IsDeferredEnabled() const { return false; }
113 // Bind the GBuffer geometry-pass shader (overrides material shader in geometry pass).
114 virtual void BindGBufferShader() {}
115 // Bind all PBR material resources (textures + UBO) for the GBuffer geometry pass.
116 // Replaces BindGBufferShader + BindTexturesAndCB for the deferred path.
117 virtual void BindPBRMaterial(Sleak::Material* material) { (void)material; }
118 // Transition from geometry pass → lighting pass → bind final RT.
119 // Called by RenderCommandQueue after all opaque draws.
121 // Begin the forward transparent sub-pass (renders on top of deferred result).
123 // End the forward transparent sub-pass.
125 // Update the per-frame deferred CB (InvViewProj + screen size + near/far).
126 virtual void UpdateDeferredCB(const void* data, uint32_t size) { (void)data; (void)size; }
127
128 // Buffer binding
129 virtual void BindVertexBuffer(RefPtr<BufferBase> buffer, uint32_t slot = 0) = 0;
130 virtual void BindIndexBuffer(RefPtr<BufferBase> buffer, uint32_t slot = 0) = 0;
131 virtual void BindConstantBuffer(RefPtr<BufferBase> buffer, uint32_t slot = 0) = 0;
132
133 // Resource creation
134 /// Allocates a backend buffer, optionally seeded with initial data.
135 virtual BufferBase* CreateBuffer(BufferType Type, uint32_t size, void* data) = 0;
136 /// Compiles a shader program from source or a source-file path.
137 virtual Shader* CreateShader(const std::string& shaderSource) = 0;
138 /// Loads a texture from disk.
139 virtual Texture* CreateTexture(const std::string& TexturePath) = 0;
140 /// Creates a texture from an in-memory pixel buffer.
141 virtual Texture* CreateTextureFromData(uint32_t width, uint32_t height, void* data) = 0;
142
143 };
144 };
145};
int width
int height
Backend-agnostic GPU buffer: vertex, index, constant, or resource view target.
Abstract interface for high-level graphics command execution and resource management.
virtual void BindBoneBuffer(RefPtr< BufferBase > buffer)
virtual void BindTexture(RefPtr< Sleak::Texture > texture, uint32_t slot=0)
virtual void SetViewport(float x, float y, float width, float height, float minDepth=0.0f, float maxDepth=1.0f)=0
Sets the active viewport rect and depth range in pixel/NDC units.
virtual Shader * CreateShader(const std::string &shaderSource)=0
Compiles a shader program from source or a source-file path.
virtual void SetCullEnabled(bool enabled)
virtual void Draw(uint32_t vertexCount)=0
Non-indexed draw from the currently bound vertex buffer.
virtual void SetDepthCompare(DepthCompare compare)
virtual void DrawIndexedInstance(uint32_t instanceCount, uint32_t indexPerInstance)=0
Indexed instanced draw.
virtual void ClearRenderTarget(float r, float g, float b, float a)=0
virtual void DrawInstance(uint32_t instanceCount, uint32_t vertexPerInstance)=0
Non-indexed instanced draw.
virtual void SetRenderMode(RenderMode mode)=0
virtual void UpdateDeferredCB(const void *data, uint32_t size)
virtual void BindVertexBuffer(RefPtr< BufferBase > buffer, uint32_t slot=0)=0
virtual void BeginCustomFormatPass(VertexFormatHandle format)
Binds the pipeline built for a registered vertex layout in the active render pass.
virtual void ClearDepthStencil(bool clearDepth, bool clearStencil, float depth, uint8_t stencil)=0
virtual bool IsShadowPassActive() const
virtual void BindIndexBuffer(RefPtr< BufferBase > buffer, uint32_t slot=0)=0
virtual Texture * CreateTextureFromData(uint32_t width, uint32_t height, void *data)=0
Creates a texture from an in-memory pixel buffer.
virtual void BindTextureRaw(Sleak::Texture *texture, uint32_t slot=0)
virtual void SetDepthWrite(bool enabled)
virtual BufferBase * CreateBuffer(BufferType Type, uint32_t size, void *data)=0
Allocates a backend buffer, optionally seeded with initial data.
virtual void EndCustomFormatPass()
Restores the pipeline that was active before the custom format draws.
virtual void BindPBRMaterial(Sleak::Material *material)
virtual void SetRenderFace(RenderFace face)=0
virtual Texture * CreateTexture(const std::string &TexturePath)=0
Loads a texture from disk.
virtual void BindConstantBuffer(RefPtr< BufferBase > buffer, uint32_t slot=0)=0
virtual void DrawIndexed(uint32_t indexCount)=0
Indexed draw from the currently bound vertex/index buffers.
Backend-agnostic compiled shader program.
Definition Shader.hpp:11
Backend-facing rendering layer shared by the four graphics backends.
DepthCompare
Depth test comparison function.
RenderMode
Rasterizer fill style for a draw.
BufferType
GPU buffer usage kind, drives backend binding flags and layout.
RenderFace
Which triangle winding gets culled.
Root namespace for everything the engine exposes.
Definition Camera.hpp:10
uint32_t VertexFormatHandle