SleakEngine 0.1.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 /// Non-indexed draw starting at firstVertex.
61 virtual void Draw(uint32_t vertexCount, uint32_t firstVertex) = 0;
62 /// Indexed draw from the currently bound vertex/index buffers.
63 virtual void DrawIndexed(uint32_t indexCount) = 0;
64 /// Indexed draw from firstIndex, adding baseVertex to each index.
65 virtual void DrawIndexed(uint32_t indexCount, uint32_t firstIndex,
66 int32_t baseVertex) = 0;
67 /// Non-indexed instanced draw.
68 virtual void DrawInstance(uint32_t instanceCount, uint32_t vertexPerInstance) = 0;
69 /// Indexed instanced draw.
70 virtual void DrawIndexedInstance(uint32_t instanceCount, uint32_t indexPerInstance) = 0;
71 /// Indexed instanced draw from firstIndex, adding baseVertex.
72 virtual void DrawIndexedInstance(uint32_t instanceCount,
73 uint32_t indexPerInstance,
74 uint32_t firstIndex,
75 int32_t baseVertex) = 0;
76
77 // State management
78 virtual void SetRenderFace(RenderFace face) = 0;
79 virtual void SetRenderMode(RenderMode mode) = 0;
80 /// Sets the active viewport rect and depth range in pixel/NDC units.
81 virtual void SetViewport(float x, float y, float width, float height, float minDepth = 0.0f, float maxDepth = 1.0f) = 0;
82 virtual void ClearRenderTarget(float r, float g, float b, float a) = 0;
83 virtual void ClearDepthStencil(bool clearDepth, bool clearStencil, float depth, uint8_t stencil) = 0;
84
85 // Depth/cull state (for skybox and other special rendering)
86 virtual void SetDepthWrite(bool enabled) { (void)enabled; }
87 virtual void SetDepthCompare(DepthCompare compare) { (void)compare; }
88 virtual void SetCullEnabled(bool enabled) { (void)enabled; }
89 virtual void BindTexture(RefPtr<Sleak::Texture> texture, uint32_t slot = 0) { (void)texture; (void)slot; }
90 virtual void BindTextureRaw(Sleak::Texture* texture, uint32_t slot = 0) { (void)texture; (void)slot; }
91
92 // Skybox pipeline support (Vulkan needs separate pipeline for cubemap)
93 virtual void BeginSkyboxPass() {}
94 virtual void EndSkyboxPass() {}
95
96 // Bone buffer support (Vulkan needs UBO path — push constants too small)
97 virtual void BindBoneBuffer(RefPtr<BufferBase> buffer) { (void)buffer; }
98
99 // Skinned pipeline support (Vulkan needs separate pipeline for skinned shaders)
100 virtual void BeginSkinnedPass() {}
101 virtual void EndSkinnedPass() {}
102
103 // Custom vertex format pipeline support (registered via VertexFormatRegistry)
104 /// Binds the pipeline built for a registered vertex layout in the active render pass.
105 virtual void BeginCustomFormatPass(VertexFormatHandle format) { (void)format; }
106 /// Restores the pipeline that was active before the custom format draws.
107 virtual void EndCustomFormatPass() {}
108
109 // Debug line rendering pipeline support
110 virtual void BeginDebugLinePass() {}
111 virtual void EndDebugLinePass() {}
112
113 // Shadow pass support
114 virtual void BeginShadowPass() {}
115 virtual void EndShadowPass() {}
116 virtual bool IsShadowPassActive() const { return false; }
117
118 // Deferred rendering support
119 // Returns true when a geometry pass (GBuffer) is active this frame.
120 virtual bool IsInGeometryPass() const { return false; }
121 // Returns true when deferred lighting is enabled for this renderer.
122 virtual bool IsDeferredEnabled() const { return false; }
123 // Bind the GBuffer geometry-pass shader (overrides material shader in geometry pass).
124 virtual void BindGBufferShader() {}
125 // Bind all PBR material resources (textures + UBO) for the GBuffer geometry pass.
126 // Replaces BindGBufferShader + BindTexturesAndCB for the deferred path.
127 virtual void BindPBRMaterial(Sleak::Material* material) { (void)material; }
128 // Transition from geometry pass → lighting pass → bind final RT.
129 // Called by RenderCommandQueue after all opaque draws.
131 // Begin the forward transparent sub-pass (renders on top of deferred result).
133 // End the forward transparent sub-pass.
135 // Update the per-frame deferred CB (InvViewProj + screen size + near/far).
136 virtual void UpdateDeferredCB(const void* data, uint32_t size) { (void)data; (void)size; }
137
138 // Buffer binding
139 virtual void BindVertexBuffer(RefPtr<BufferBase> buffer, uint32_t slot = 0) = 0;
140 virtual void BindIndexBuffer(RefPtr<BufferBase> buffer, uint32_t slot = 0) = 0;
141 virtual void BindConstantBuffer(RefPtr<BufferBase> buffer, uint32_t slot = 0) = 0;
142
143 // Resource creation
144 /// Allocates a backend buffer, optionally seeded with initial data.
145 virtual BufferBase* CreateBuffer(BufferType Type, uint32_t size, void* data) = 0;
146 /// Compiles a shader program from source or a source-file path.
147 virtual Shader* CreateShader(const std::string& shaderSource) = 0;
148 /// Loads a texture from disk.
149 virtual Texture* CreateTexture(const std::string& TexturePath) = 0;
150 /// Creates a texture from an in-memory pixel buffer.
151 virtual Texture* CreateTextureFromData(uint32_t width, uint32_t height, void* data) = 0;
152
153 };
154 };
155};
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 Draw(uint32_t vertexCount, uint32_t firstVertex)=0
Non-indexed draw starting at firstVertex.
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 DrawIndexed(uint32_t indexCount, uint32_t firstIndex, int32_t baseVertex)=0
Indexed draw from firstIndex, adding baseVertex to each index.
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 void DrawIndexedInstance(uint32_t instanceCount, uint32_t indexPerInstance, uint32_t firstIndex, int32_t baseVertex)=0
Indexed instanced draw from firstIndex, adding baseVertex.
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