Cogs.Core
IRenderer.h
1#pragma once
2
3#include <glm/vec2.hpp>
4#include <glm/vec4.hpp>
5#include <glm/mat4x4.hpp>
6
7#include "Rendering/Common.h"
8#include "Rendering/IGraphicsDevice.h"
9
10#include "Resources/Resources.h"
11#include "Resources/ResourceBase.h"
12#include "Rendering/IEffects.h"
13
14#include "Services/Variables.h"
15#include <span>
16
17namespace Cogs
18{
19 class IGraphicsDevice;
20
21 namespace Core
22 {
23 class Context;
24 class LightComponent;
25
28 {
29 int width;
30 int height;
31 int numSamples;
32 int flags;
33 };
34
36 enum class RenderMode
37 {
39 Normal = 0,
41 Wireframe = 1,
43 Box = 3,
44 };
45
47 struct ActiveLights {
48 std::vector<const LightComponent*> lights;
49 uint32_t numDirectionalShadowLights = 0;
50 uint32_t numDirectionalLights = 0;
51 uint32_t numPointShadowLights = 0;
52 uint32_t numPointLights = 0;
53 };
54
64 {
65 public:
66 virtual ~IRenderResources() = default;
67
68 virtual ActivationResult updateResource(const TextureHandle & texture) = 0;
69 virtual ActivationResult updateResource(const MeshHandle & mesh) = 0;
70 virtual ActivationResult updateResource(const EffectHandle & effect) = 0;
71 virtual ActivationResult updateResource(const MaterialHandle & material) = 0;
72 virtual ActivationResult updateResource(const MaterialInstanceHandle & materialInstance) = 0;
73
74 virtual void releaseResource(Texture * texture) = 0;
75 virtual void releaseResource(Mesh * mesh) = 0;
76 virtual void releaseResource(Effect * effect) = 0;
77 virtual void releaseResource(Material * material) = 0;
78 virtual void releaseResource(MaterialInstance * materialInstance) = 0;
79
80 virtual std::string getReport() const = 0;
81
82 };
83
86 {
88 enum ERenderingEvent : uint32_t
89 {
91 None = 0,
102 };
103 };
104
105 struct DrawContext;
106 struct RenderTaskContext;
107 struct RenderList;
108 struct EnginePermutation;
109 struct EnginePermutations;
110 struct RenderSettings;
111 struct RenderStates;
112 struct EffectCache;
113 struct EffectBindings;
114 struct EngineBuffers;
115
123 {
124 public:
126 virtual ~IRendererExtension() = default;
127
134 virtual void initialize(class Context * context, IGraphicsDevice * device) = 0;
135
143 virtual void handleEvent(uint32_t eventId, const DrawContext * renderingContext) = 0;
144
145 virtual void generateCommands(const RenderTaskContext * renderingContext, RenderList * renderList) = 0;
146 };
147
154 {
155 public:
157 virtual ~IRenderer() = default;
158
159 virtual void initialize(IGraphicsDevice * device) = 0;
160
164 virtual void cleanup() = 0;
165
171 virtual glm::vec2 getSize() const = 0;
172
177
185 virtual void setMode(RenderMode mode) = 0;
186
190 virtual RenderMode getMode() const = 0;
191
197 virtual void setBackgroundColor(const glm::vec4 & color) = 0;
198
202 virtual glm::vec4 getBackgroundColor() const = 0;
203
207 virtual void beginFrame() = 0;
208
212 virtual void endFrame(uint32_t syncInterval = 0, uint32_t presentFlags = Cogs::PresentFlags::None) = 0;
213
217 virtual void render() = 0;
218
228 virtual glm::mat4 getProjectionMatrix(const glm::mat4 projectionMatrix) = 0;
229
239 virtual glm::mat4 getViewFromViewportMatrix(const glm::mat4 inverseProjectionMatrix) = 0;
240
241
247 virtual float getClearDepth() = 0;
248
254 virtual float getNearDepth() = 0;
255
262
266 virtual const RenderSettings & getSettings() const = 0;
267
277 virtual void registerExtension(IRendererExtension * extension) = 0;
278
285 virtual void unregisterExtension(IRendererExtension* extension) = 0;
286
290 virtual std::span<IRendererExtension*> getExtensions() = 0;
291
295 virtual void renderScreenshot(const ScreenshotSettings & settings, std::vector<uint8_t> & bytes, uint32_t * stride) = 0;
296
300 virtual unsigned getMaxLights() const = 0;
301
306
311
316
321
326
331
338 virtual void updatePermutation(EnginePermutation* permutation) = 0;
339
344
345 virtual COGSCORE_DLL_API class ImguiRenderer* getGuiRenderer() = 0;
346 virtual COGSCORE_DLL_API class InspectorGuiRenderer* getInspectorGuiRenderer() = 0;
347 virtual COGSCORE_DLL_API class InspectorGuiRenderer* getEngineInspectorGuiRenderer() = 0;
348 };
349 }
350}
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
Interface to the render resources.
Definition: IRenderer.h:64
Defines an extension to the renderer, capable of doing custom rendering.
Definition: IRenderer.h:123
virtual ~IRendererExtension()=default
Provided for destruction via pointer to base.
virtual void handleEvent(uint32_t eventId, const DrawContext *renderingContext)=0
Called when rendering events occur.
virtual void initialize(class Context *context, IGraphicsDevice *device)=0
Initialize the extension using the given context and device.
Renderer interface used by the engine to control registered renderer instances.
Definition: IRenderer.h:154
virtual RenderStates & getRenderStates()=0
Get the reference to the RenderStates structure.
virtual float getClearDepth()=0
Get adjusted clear depth used to render.
virtual void endFrame(uint32_t syncInterval=0, uint32_t presentFlags=Cogs::PresentFlags::None)=0
Signals the end of the current frame.
virtual glm::vec4 getBackgroundColor() const =0
Get the reference to the background color.
virtual EffectCache & getEffectCache()=0
Get the reference to the EffectCache structure.
virtual glm::mat4 getViewFromViewportMatrix(const glm::mat4 inverseProjectionMatrix)=0
Get an adjusted inverse projection matrix mainly used in post processing.
virtual unsigned getMaxLights() const =0
Get the maximum number of lights.
virtual EffectFlags::EEffectFlags getEffectFlags() const =0
Get the EffectFlags.
virtual void renderScreenshot(const ScreenshotSettings &settings, std::vector< uint8_t > &bytes, uint32_t *stride)=0
Render screenshot.
virtual void setMode(RenderMode mode)=0
Set the rendering mode the renderer should use.
virtual std::span< IRendererExtension * > getExtensions()=0
Get the list of all extensions.
virtual IGraphicsDevice * getDevice()=0
Get the graphics device used by the renderer.
virtual void beginFrame()=0
Signals the beginning of a new frame.
virtual glm::mat4 getProjectionMatrix(const glm::mat4 projectionMatrix)=0
Get an adjusted projection matrix used to render.
virtual EffectBindings & getEffectBindings()=0
Get the reference to the EffectBindings structure.
virtual EnginePermutations & getEnginePermutations()=0
Get the reference to the EnginePermutations structure.
virtual RenderMode getMode() const =0
Get the Rendering mode used by the renderer.
virtual glm::vec2 getSize() const =0
Get the output surface size of the renderer.
virtual void updatePermutation(EnginePermutation *permutation)=0
Updates the EnginePermutation.
virtual IRenderResources * getResources()=0
Get the render resources interface.
virtual float getNearDepth()=0
Get adjusted near plane depth.
virtual void render()=0
Kick off the actual rendering, allowing the renderer to produce its output.
virtual void cleanup()=0
Cleanup the renderer, releasing all resources held.
virtual EngineBuffers & getEngineBuffers()=0
Get the reference to the EngineBuffers structure.
virtual ActiveLights & getActiveLights()=0
Get the reference to the ActiveLights structure.
virtual void setBackgroundColor(const glm::vec4 &color)=0
Set the background color applied to the output surface before rendering.
virtual void registerExtension(IRendererExtension *extension)=0
Register an extension with the renderer.
virtual void unregisterExtension(IRendererExtension *extension)=0
Unregister an extension with the renderer.
virtual const RenderSettings & getSettings() const =0
Get the settings of the renderer.
virtual ~IRenderer()=default
Provided for destruction via pointer to base.
Represents a graphics device used to manage graphics resources and issue drawing commands.
RenderMode
Defines global rendering modes that can be supported by the renderer.
Definition: IRenderer.h:37
@ Wireframe
Wireframe rendering.
@ Box
Bounding-box rendering over regular rendering.
@ Normal
Regular shaded rendering.
ActivationResult
Defines results for resource activation.
Definition: ResourceBase.h:14
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
Active lights settings.
Definition: IRenderer.h:47
Effect resources contain data to control the shader stages of the GPU pipeline.
Definition: Effect.h:24
Material instances represent a specialized Material combined with state for all its buffers and prope...
Material resources define the how of geometry rendering (the what is defined by Mesh and Texture reso...
Definition: Material.h:82
Meshes contain streams of vertex data in addition to index data and options defining geometry used fo...
Definition: Mesh.h:265
Render settings variables.
Defines rendering events.
Definition: IRenderer.h:86
ERenderingEvent
Rendering event enum.
Definition: IRenderer.h:89
@ RenderGui
Rendering GUI elements.
Definition: IRenderer.h:99
@ None
No event occurred.
Definition: IRenderer.h:91
@ PostRender
Rendering has finished for a given rendering context.
Definition: IRenderer.h:101
@ PreRender
Pre rendering happening for a given rendering context.
Definition: IRenderer.h:93
@ RenderTransparent
Rendering transparent shapes for a given context.
Definition: IRenderer.h:97
@ RenderSolid
Rendering solid shapes for a given context.
Definition: IRenderer.h:95
Screenshot render settings.
Definition: IRenderer.h:28
Texture resources contain raster bitmap data to use for texturing.
Definition: Texture.h:91
EEffectFlags
Effect source flags.
Definition: IEffects.h:20
@ None
No flags.
Definition: Common.h:177