67 uint64_t frameCount = 0;
68 decltype(frameCount) lastResizeFrameVB = 0, lastResizeFrameIB = 0;
73 RGLCommandQueuePtr mainCommandQueue;
74 RGLCommandBufferPtr mainCommandBuffer, transformSyncCommandBuffer, transientCommandBuffer;
75 bool transientSubmittedLastFrame =
false;
77 RGLTexturePtr dummyShadowmap, dummyCubemap;
78 RGLSamplerPtr textureSampler, textureClampSampler, shadowSampler, depthPyramidSampler;
79 RGLRenderPassPtr litRenderPass, unlitRenderPass, envSkyboxPass, depthPrepassRenderPass, depthPrepassRenderPassLit, postProcessRenderPass, postProcessRenderPassClear, finalRenderPass, finalRenderPassNoDepth, shadowRenderPass, lightingClearRenderPass, litClearRenderPass, finalClearRenderPass, depthPyramidCopyPass, litTransparentPass, unlitTransparentPass, transparentClearPass, transparencyApplyPass, ssaoPassClear, ssgiPassNoClear, ssgiAmbientApplyPass, ssgiPassClear;
81 RGLRenderPipelinePtr depthPyramidCopyPipeline,
82 im3dLineRenderPipeline, im3dPointRenderPipeline, im3dTriangleRenderPipeline, recastLinePipeline, recastPointPipeline, recastTrianglePipeline, guiRenderPipeline, transparencyApplyPipeline, ssgipipeline, gtaoPipeline, ssaoPipeline, ssgiDownsamplePipeline, ssgiUpsamplePipeline, ambientSSGIApplyPipeline, aoUpsamplePipeline, ssgiUpsamplePipleineFinalStep, environmentPreFilterPipeline, environmentIrradiancePipeline;
83 RGLComputePipelinePtr skinnedMeshComputePipeline, defaultCullingComputePipeline, skinningDrawCallPreparePipeline, depthPyramidPipeline, particleCreatePipeline, particleDispatchSetupPipeline, particleDispatchSetupPipelineIndexed, particleKillPipeline, clusterBuildGridPipeline, clusterPopulatePipeline, blurKernelX, blurKernelY;
84 RGLBufferPtr screenTriVerts,
85 sharedPositionBuffer,sharedNormalBuffer, sharedTangentBuffer, sharedBitangentBuffer, sharedUV0Buffer, sharedLightmapUVBuffer, sharedIndexBuffer, sharedSkeletonMatrixBuffer, sharedSkinnedPositionBuffer, sharedSkinnedNormalBuffer, sharedSkinnedTangentBuffer, sharedSkinnedBitangentBuffer, sharedSkinnedUV0Buffer, quadVertBuffer, lightClusterBuffer, debugRenderBufferUpload;
86 uint32_t debugRenderBufferSize = 0, debugRenderBufferOffset = 0;
88 constexpr static uint32_t initialVerts = 1024, initialIndices = 1536;
90 struct PyramidCopyUBO {
96 enum DefaultCullBindings : uint32_t{
102 depthPyramidSamplerBinding = 9,
106 struct GridBuildUBO {
115 struct GridAssignUBO {
117 uint32_t pointLightCount, spotLightCount;
120 struct DownsampleUBO {
129 struct SkyboxEnvPrefilterUBO {
133 struct AmbientSSGIApplyUBO {
135 uint32_t ambientLightCount = 0;
136 float ssaoStrength = 1;
137 uint32_t options = 0;
138 static constexpr uint32_t SSAOBIT = 1, SSGIBIT = 1 << 1;
141 RGLShaderLibraryPtr defaultPostEffectVSH;
145 static constexpr RGL::TextureFormat depthPyramidFormat = RGL::TextureFormat::R32_Float;
146 constexpr static uint32_t maxssgimips = 5;
148 auto GetDefaultPostEffectVSH()
const{
149 return defaultPostEffectVSH;
152 constexpr static RGL::TextureFormat
153 colorTexFormat = RGL::TextureFormat::RGBA16_Sfloat,
154 radianceFormat = RGL::TextureFormat::RGBA16_Sfloat,
155 albedoFormat = RGL::TextureFormat::RGBA16_Sfloat,
156 viewSpaceNormalTextureFormat = RGL::TextureFormat::RGBA16_Sfloat,
157 ssgiOutputFormat = RGL::TextureFormat::RGBA16_Sfloat,
158 ssaoOutputFormat = RGL::TextureFormat::R16_Float,
159 depthFormat = RGL::TextureFormat::D32SFloat;
179 uint32_t numObjects = 0;
180 uint32_t numVertices = 0;
181 uint32_t numBones = 0;
182 uint32_t boneReadOffset = 0;
183 uint32_t vertexWriteOffset = 0;
184 uint32_t vertexReadOffset = 0;
208 uint32_t joint_index;
213 uint32_t indirectBufferOffset = 0;
214 uint32_t numObjects = 0;
215 uint32_t cullingBufferOffset = 0;
217 uint32_t numLODs = 0;
218 uint32_t idOutputBufferBindlessHandle = 0;
219 uint32_t entityIDInputBufferBindlessHandle = 0;
220 uint32_t indirectOutputBufferBindlessHandle = 0;
221 uint32_t lodDistanceBufferBindlessHandle = 0;
228 renderlayer_t cameraRenderLayers = 0;
229 uint32_t singleInstanceModeAndShadowMode = 0;
233 uint32_t indexBufferOffset = 0;
234 uint32_t vertexBufferOffset = 0;
235 uint32_t nIndicesInThisMesh = 0;
236 uint32_t nVerticesInThisMesh = 0;
237 uint32_t nTotalObjects = 0;
238 uint32_t drawCallBufferOffset = 0;
239 uint32_t baseInstanceOffset = 0;
243 uint32_t particlesToSpawn;
244 uint32_t maxParticles;
248 uint32_t maxTotalParticles;
265 enum class AOMethod : uint8_t {
272 AOMethod aoMethod = AOMethod::SSAO;
275 void SyncVideoSettings();
278 double GetElapsedTime()
override;
279 void SetMouseCursor(
const Rml::String& cursor_name)
override;
280 void SetClipboardText(
const Rml::String& text)
override;
281 void GetClipboardText(Rml::String& text)
override;
284 void RenderGeometry(Rml::Vertex* vertices,
int num_vertices,
int* indices,
int num_indices, Rml::TextureHandle texture,
const Rml::Vector2f& translation)
override;
287 Rml::CompiledGeometryHandle
CompileGeometry(Rml::Vertex* vertices,
int num_vertices,
int* indices,
int num_indices, Rml::TextureHandle texture)
override;
290 void RenderCompiledGeometry(Rml::CompiledGeometryHandle geometry,
const Rml::Vector2f& translation)
override;
300 bool LoadTexture(Rml::TextureHandle& texture_handle, Rml::Vector2i& texture_dimensions,
const Rml::String& source)
override;
302 bool GenerateTexture(Rml::TextureHandle& texture_handle,
const Rml::byte* source,
const Rml::Vector2i& source_dimensions)
override;
307 void SetTransform(
const Rml::Matrix4f* transform)
override;
309 bool LogMessage(Rml::Log::Type type,
const Rml::String& message)
override;
312 static std::optional<GUIComponent> debuggerContext;
313 void InitDebugger()
const;
314 void DeactivateDebugger()
const;
315 static std::unique_ptr<InputManager> debuggerInput;
318 void depthMask(
bool state)
final;
319 void texture(
bool state)
final;
320 void begin(duDebugDrawPrimitives prim,
float size = 1.0f) final;
321 void vertex(const
float* pos,
unsigned int color) final;
322 void vertex(const
float x, const
float y, const
float z,
unsigned int color) final;
323 void vertex(const
float* pos,
unsigned int color, const
float* uv) final;
324 void vertex(const
float x, const
float y, const
float z,
unsigned int color, const
float u, const
float v) final;
327 void DebugRender(const Im3d::DrawList&);
329 size_t GetCurrentVRAMUse();
331 size_t GetTotalVRAM();
333 ConcurrentQueue<RGLBufferPtr> gcBuffers;
334 ConcurrentQueue<RGLTexturePtr> gcTextures;
335 ConcurrentQueue<RGLPipelineLayoutPtr> gcPipelineLayout;
336 ConcurrentQueue<RGLRenderPipelinePtr> gcRenderPipeline;
340 void DeallocateMesh(const MeshRange& range);
343 dim_t<
int> currentRenderSize;
344 matrix4 make_gui_matrix(Rml::Vector2f translation);
346 constexpr static uint32_t transientSizeBytes = 65536;
347 RGLBufferPtr transientBuffer, transientStagingBuffer;
348 uint32_t transientOffset = 0;
357 allocation_freelist_t vertexFreeList{ 1,
Range{.start = 0, .count = initialVerts}};
358 allocation_freelist_t indexFreeList{ 1,
Range{.start = 0, .count = initialIndices}};
359 allocation_allocatedlist_t vertexAllocatedList, indexAllocatedList;
360 uint32_t currentVertexSize = initialVerts, currentIndexSize = initialIndices;
362 void ReallocateVertexAllocationToSize(uint32_t newSize);
363 void ReallocateIndexAllocationToSize(uint32_t newSize);
364 void ReallocateGeneric(RGLBufferPtr& reallocBuffer, uint32_t& reallocBufferSize, uint32_t newSize, allocation_allocatedlist_t& allocatedList, allocation_freelist_t& freelist, uint32_t stride,
RGL::BufferConfig::Type bufferType,
decltype(frameCount)& lastResizeFrame,
const char* debugName =
nullptr);
366 SpinLock allocationLock;
368 void DestroyUnusedResources();
370 bool navDebugDepthEnabled =
false;
376 static Ref<GUIMaterialInstance> guiMaterial;
381 uint16_t x, y, width, height;
382 bool enabled =
false;