Cogs.Core
Public Member Functions | Protected Member Functions | Private Attributes | Friends | List of all members
Cogs::Core::Renderer Class Reference

Core renderer system. More...

#include <Renderer.h>

Inheritance diagram for Cogs::Core::Renderer:
Cogs::Core::IRenderer

Public Member Functions

 Renderer (Context *context)
 
void initialize (IGraphicsDevice *device) override
 
void cleanup () override
 Cleanup the renderer, releasing all resources held.
 
void setMode (RenderMode mode) override
 Set the rendering mode the renderer should use.
 
RenderMode getMode () const override
 Get the Rendering mode used by the renderer.
 
void setBackgroundColor (const glm::vec4 &backgroundColor) override
 Set the background color applied to the output surface before rendering.
 
glm::vec4 getBackgroundColor () const override
 Get the reference to the background color.
 
glm::vec2 getSize () const override
 Get the output surface size of the renderer.
 
IGraphicsDevicegetDevice () override
 Get the graphics device used by the renderer.
 
const RenderSettingsgetSettings () const override
 Get the settings of the renderer.
 
void beginFrame () override
 Signals the beginning of a new frame.
 
void endFrame (uint32_t syncInterval=0, uint32_t presentFlags=PresentFlags::None) override
 Signals the end of the current frame.
 
void render () override
 Kick off the actual rendering, allowing the renderer to produce its output.
 
glm::mat4 getProjectionMatrix (const glm::mat4 projectionMatrix) override
 Get an adjusted projection matrix used to render.
 
glm::mat4 getViewFromViewportMatrix (glm::mat4 inverseProjectionMatrix) override
 Get an adjusted inverse projection matrix mainly used in post processing.
 
float getClearDepth () override
 Get adjusted clear depth used to render.
 
float getNearDepth () override
 Get adjusted near plane depth.
 
IRenderResourcesgetResources () override
 Get the render resources interface.
 
void registerExtension (IRendererExtension *extension) override
 Registers the given extension with the renderer. Doesn not take ownership of pointer.
 
void unregisterExtension (IRendererExtension *extension) override
 Unregister an extension with the renderer.
 
std::span< IRendererExtension * > getExtensions () override
 Get the list of all extensions.
 
void renderScreenshot (const ScreenshotSettings &settings, std::vector< uint8_t > &bytes, uint32_t *stride=nullptr) override
 Render screenshot.
 
EngineBuffersgetEngineBuffers () override
 Get the reference to the EngineBuffers structure.
 
RenderStatesgetRenderStates () override
 Get the reference to the RenderStates structure.
 
EffectFlags::EEffectFlags getEffectFlags () const override
 Get the EffectFlags.
 
EffectCachegetEffectCache () override
 Get the reference to the EffectCache structure.
 
EffectBindingsgetEffectBindings () override
 Get the reference to the EffectBindings structure.
 
ActiveLightsgetActiveLights () override
 Get the reference to the ActiveLights structure.
 
unsigned getMaxLights () const override
 Get the maximum number of lights.
 
void updatePermutation (EnginePermutation *permutation) override
 Updates the EnginePermutation.
 
EnginePermutationsgetEnginePermutations () override
 Get the reference to the EnginePermutations structure.
 
COGSCORE_DLL_API class ImguiRenderergetGuiRenderer () override
 
COGSCORE_DLL_API class InspectorGuiRenderergetInspectorGuiRenderer () override
 
COGSCORE_DLL_API class InspectorGuiRenderergetEngineInspectorGuiRenderer () override
 
class RenderResourcesgetRenderResources ()
 
class RenderPipelineManagergetPipelineManager ()
 
RenderTaskContextgetRenderContext ()
 
- Public Member Functions inherited from Cogs::Core::IRenderer
virtual ~IRenderer ()=default
 Provided for destruction via pointer to base.
 
virtual void initialize (IGraphicsDevice *device)=0
 
virtual void cleanup ()=0
 Cleanup the renderer, releasing all resources held.
 
virtual glm::vec2 getSize () const =0
 Get the output surface size of the renderer.
 
virtual IGraphicsDevicegetDevice ()=0
 Get the graphics device used by the renderer.
 
virtual void setMode (RenderMode mode)=0
 Set the rendering mode the renderer should use.
 
virtual RenderMode getMode () const =0
 Get the Rendering mode used by the renderer.
 
virtual void setBackgroundColor (const glm::vec4 &color)=0
 Set the background color applied to the output surface before rendering.
 
virtual glm::vec4 getBackgroundColor () const =0
 Get the reference to the background color.
 
virtual void beginFrame ()=0
 Signals the beginning of a new frame.
 
virtual void endFrame (uint32_t syncInterval=0, uint32_t presentFlags=Cogs::PresentFlags::None)=0
 Signals the end of the current frame.
 
virtual void render ()=0
 Kick off the actual rendering, allowing the renderer to produce its output.
 
virtual glm::mat4 getProjectionMatrix (const glm::mat4 projectionMatrix)=0
 Get an adjusted projection matrix used to render.
 
virtual glm::mat4 getViewFromViewportMatrix (const glm::mat4 inverseProjectionMatrix)=0
 Get an adjusted inverse projection matrix mainly used in post processing.
 
virtual float getClearDepth ()=0
 Get adjusted clear depth used to render.
 
virtual float getNearDepth ()=0
 Get adjusted near plane depth.
 
virtual IRenderResourcesgetResources ()=0
 Get the render resources interface.
 
virtual const RenderSettingsgetSettings () const =0
 Get the settings of the renderer.
 
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 std::span< IRendererExtension * > getExtensions ()=0
 Get the list of all extensions.
 
virtual void renderScreenshot (const ScreenshotSettings &settings, std::vector< uint8_t > &bytes, uint32_t *stride)=0
 Render screenshot.
 
virtual unsigned getMaxLights () const =0
 Get the maximum number of lights.
 
virtual EngineBuffersgetEngineBuffers ()=0
 Get the reference to the EngineBuffers structure.
 
virtual RenderStatesgetRenderStates ()=0
 Get the reference to the RenderStates structure.
 
virtual EffectCachegetEffectCache ()=0
 Get the reference to the EffectCache structure.
 
virtual EffectFlags::EEffectFlags getEffectFlags () const =0
 Get the EffectFlags.
 
virtual EffectBindingsgetEffectBindings ()=0
 Get the reference to the EffectBindings structure.
 
virtual ActiveLightsgetActiveLights ()=0
 Get the reference to the ActiveLights structure.
 
virtual void updatePermutation (EnginePermutation *permutation)=0
 Updates the EnginePermutation.
 
virtual EnginePermutationsgetEnginePermutations ()=0
 Get the reference to the EnginePermutations structure.
 
virtual COGSCORE_DLL_API class ImguiRenderergetGuiRenderer ()=0
 
virtual COGSCORE_DLL_API class InspectorGuiRenderergetInspectorGuiRenderer ()=0
 
virtual COGSCORE_DLL_API class InspectorGuiRenderergetEngineInspectorGuiRenderer ()=0
 

Protected Member Functions

void updateSettings ()
 
void updateEffectFlags ()
 
void emitEvent (uint32_t eventId, const DrawContext *renderingContext)
 Emits the given render event to all registered extensions.
 

Private Attributes

Contextcontext = nullptr
 
IGraphicsDevicedevice = nullptr
 
RenderSettings settings
 
RenderMode mode = RenderMode::Normal
 
EngineBuffers engineBuffers = {}
 
RenderStates renderStates
 
struct RenderTargetdefaultTarget = nullptr
 
EffectCache effectCache
 
EffectFlags::EEffectFlags effectFlags = EffectFlags::None
 
RenderResources resources
 
EnginePermutations enginePermutations
 
EffectBindings effectBindings
 
std::unique_ptr< struct Renderersrenderers
 
std::unique_ptr< class RenderPipelineManagerpipelineManager
 
ActiveLights activeLights
 
unsigned maxLights = static_cast<unsigned>(kMaxLights)
 
glm::vec4 backgroundColor
 
std::vector< IRendererExtension * > extensions
 
RenderTaskContext renderContext
 

Friends

Cogs::Core::RenderTaskContext getRenderTaskContext (Renderer *renderer)
 

Detailed Description

Core renderer system.

Implements the IRenderer interface and provides a basic renderer for Cogs.Core.

Definition at line 27 of file Renderer.h.

Constructor & Destructor Documentation

◆ Renderer()

Cogs::Core::Renderer::Renderer ( Context context)

Definition at line 146 of file Renderer.cpp.

◆ ~Renderer()

Cogs::Core::Renderer::~Renderer ( )

Definition at line 157 of file Renderer.cpp.

Member Function Documentation

◆ beginFrame()

void Cogs::Core::Renderer::beginFrame ( )
overridevirtual

Signals the beginning of a new frame.

Implements Cogs::Core::IRenderer.

Definition at line 607 of file Renderer.cpp.

References Cogs::IGraphicsDevice::beginFrame().

◆ cleanup()

void Cogs::Core::Renderer::cleanup ( )
overridevirtual

Cleanup the renderer, releasing all resources held.

Implements Cogs::Core::IRenderer.

Definition at line 210 of file Renderer.cpp.

References Cogs::Core::Context::variables.

◆ emitEvent()

void Cogs::Core::Renderer::emitEvent ( uint32_t  eventId,
const DrawContext renderingContext 
)
protected

Emits the given render event to all registered extensions.

Definition at line 750 of file Renderer.cpp.

◆ endFrame()

void Cogs::Core::Renderer::endFrame ( uint32_t  syncInterval = 0,
uint32_t  presentFlags = PresentFlags::None 
)
overridevirtual

Signals the end of the current frame.

Implements Cogs::Core::IRenderer.

Definition at line 614 of file Renderer.cpp.

References Cogs::IGraphicsDevice::endFrame().

◆ getActiveLights()

ActiveLights & Cogs::Core::Renderer::getActiveLights ( )
inlineoverridevirtual

Get the reference to the ActiveLights structure.

Implements Cogs::Core::IRenderer.

Definition at line 72 of file Renderer.h.

◆ getBackgroundColor()

glm::vec4 Cogs::Core::Renderer::getBackgroundColor ( ) const
inlineoverridevirtual

Get the reference to the background color.

Implements Cogs::Core::IRenderer.

Definition at line 42 of file Renderer.h.

◆ getClearDepth()

float Cogs::Core::Renderer::getClearDepth ( )
overridevirtual

Get adjusted clear depth used to render.

The depth value is accounting for device coordinate system differences.

Implements Cogs::Core::IRenderer.

Definition at line 582 of file Renderer.cpp.

References Cogs::GraphicsDeviceCapabilities::DepthNegativeOneToOne, Cogs::IGraphicsDevice::getCapabilities(), Cogs::ICapabilities::getDeviceCapabilities(), and Cogs::Core::Context::variables.

◆ getDevice()

IGraphicsDevice * Cogs::Core::Renderer::getDevice ( )
inlineoverridevirtual

Get the graphics device used by the renderer.

Implements Cogs::Core::IRenderer.

Definition at line 45 of file Renderer.h.

◆ getEffectBindings()

EffectBindings & Cogs::Core::Renderer::getEffectBindings ( )
inlineoverridevirtual

Get the reference to the EffectBindings structure.

Implements Cogs::Core::IRenderer.

Definition at line 71 of file Renderer.h.

Referenced by Cogs::Core::RenderMaterial::getBinding().

◆ getEffectCache()

EffectCache & Cogs::Core::Renderer::getEffectCache ( )
inlineoverridevirtual

Get the reference to the EffectCache structure.

Implements Cogs::Core::IRenderer.

Definition at line 70 of file Renderer.h.

◆ getEffectFlags()

EffectFlags::EEffectFlags Cogs::Core::Renderer::getEffectFlags ( ) const
inlineoverridevirtual

Get the EffectFlags.

Implements Cogs::Core::IRenderer.

Definition at line 69 of file Renderer.h.

◆ getEngineBuffers()

EngineBuffers & Cogs::Core::Renderer::getEngineBuffers ( )
inlineoverridevirtual

Get the reference to the EngineBuffers structure.

Implements Cogs::Core::IRenderer.

Definition at line 67 of file Renderer.h.

◆ getEngineInspectorGuiRenderer()

Cogs::Core::InspectorGuiRenderer * Cogs::Core::Renderer::getEngineInspectorGuiRenderer ( )
overridevirtual

Implements Cogs::Core::IRenderer.

Definition at line 838 of file Renderer.cpp.

◆ getEnginePermutations()

EnginePermutations & Cogs::Core::Renderer::getEnginePermutations ( )
inlineoverridevirtual

Get the reference to the EnginePermutations structure.

Implements Cogs::Core::IRenderer.

Definition at line 76 of file Renderer.h.

◆ getExtensions()

std::span< IRendererExtension * > Cogs::Core::Renderer::getExtensions ( )
inlineoverridevirtual

Get the list of all extensions.

Implements Cogs::Core::IRenderer.

Definition at line 63 of file Renderer.h.

◆ getGuiRenderer()

Cogs::Core::ImguiRenderer * Cogs::Core::Renderer::getGuiRenderer ( )
overridevirtual

Implements Cogs::Core::IRenderer.

Definition at line 829 of file Renderer.cpp.

◆ getInspectorGuiRenderer()

Cogs::Core::InspectorGuiRenderer * Cogs::Core::Renderer::getInspectorGuiRenderer ( )
overridevirtual

Implements Cogs::Core::IRenderer.

Definition at line 833 of file Renderer.cpp.

◆ getMaxLights()

unsigned Cogs::Core::Renderer::getMaxLights ( ) const
inlineoverridevirtual

Get the maximum number of lights.

Implements Cogs::Core::IRenderer.

Definition at line 73 of file Renderer.h.

◆ getMode()

RenderMode Cogs::Core::Renderer::getMode ( ) const
inlineoverridevirtual

Get the Rendering mode used by the renderer.

Implements Cogs::Core::IRenderer.

Definition at line 39 of file Renderer.h.

◆ getNearDepth()

float Cogs::Core::Renderer::getNearDepth ( )
overridevirtual

Get adjusted near plane depth.

The depth value is accounting for device coordinate system differences.

Implements Cogs::Core::IRenderer.

Definition at line 594 of file Renderer.cpp.

References Cogs::GraphicsDeviceCapabilities::DepthNegativeOneToOne, Cogs::IGraphicsDevice::getCapabilities(), Cogs::ICapabilities::getDeviceCapabilities(), and Cogs::Core::Context::variables.

◆ getPipelineManager()

class RenderPipelineManager * Cogs::Core::Renderer::getPipelineManager ( )
inline

Definition at line 85 of file Renderer.h.

◆ getProjectionMatrix()

glm::mat4 Cogs::Core::Renderer::getProjectionMatrix ( const glm::mat4  projectionMatrix)
overridevirtual

Get an adjusted projection matrix used to render.

The matrix is accounting for device coordinate system differences.

Parameters
projectionMatrixGL-convention projection matrix used as base for the conversion.
Returns
A converted matrix, suitable for rendering on the current graphics device.

Implements Cogs::Core::IRenderer.

Definition at line 453 of file Renderer.cpp.

References Cogs::GraphicsDeviceCapabilities::DepthNegativeOneToOne, Cogs::Direct3D11, Cogs::Direct3D12, Cogs::IGraphicsDevice::getCapabilities(), Cogs::ICapabilities::getDeviceCapabilities(), Cogs::IGraphicsDevice::getType(), Cogs::Null, Cogs::OpenGL20, Cogs::OpenGLES30, Cogs::Core::Context::variables, Cogs::Vulkan, and Cogs::WebGPU.

◆ getRenderContext()

RenderTaskContext & Cogs::Core::Renderer::getRenderContext ( )
inline

Definition at line 86 of file Renderer.h.

◆ getRenderResources()

class RenderResources & Cogs::Core::Renderer::getRenderResources ( )
inline

Definition at line 84 of file Renderer.h.

◆ getRenderStates()

RenderStates & Cogs::Core::Renderer::getRenderStates ( )
inlineoverridevirtual

Get the reference to the RenderStates structure.

Implements Cogs::Core::IRenderer.

Definition at line 68 of file Renderer.h.

◆ getResources()

Cogs::Core::IRenderResources * Cogs::Core::Renderer::getResources ( )
overridevirtual

Get the render resources interface.

Returns
A pointer to the render resource store used by this renderer.

Implements Cogs::Core::IRenderer.

Definition at line 621 of file Renderer.cpp.

◆ getSettings()

const RenderSettings & Cogs::Core::Renderer::getSettings ( ) const
inlineoverridevirtual

Get the settings of the renderer.

Implements Cogs::Core::IRenderer.

Definition at line 46 of file Renderer.h.

◆ getSize()

glm::vec2 Cogs::Core::Renderer::getSize ( ) const
inlineoverridevirtual

Get the output surface size of the renderer.

Returns
A two-component floating point vector containing the width and height in pixels.

Implements Cogs::Core::IRenderer.

Definition at line 44 of file Renderer.h.

◆ getViewFromViewportMatrix()

glm::mat4 Cogs::Core::Renderer::getViewFromViewportMatrix ( glm::mat4  inverseProjectionMatrix)
overridevirtual

Get an adjusted inverse projection matrix mainly used in post processing.

The matrix is accounting for how depth values are converted from clip space to viewport coordinates.

Parameters
inverseProjectionMatrixinverse of the actual projection matrix used for rendering.
Returns
A converted matrix, suitable for determining view space coordinates in post processing.

Implements Cogs::Core::IRenderer.

Definition at line 527 of file Renderer.cpp.

References Cogs::GraphicsDeviceCapabilities::DepthNegativeOneToOne, Cogs::Direct3D11, Cogs::Direct3D12, Cogs::IGraphicsDevice::getCapabilities(), Cogs::ICapabilities::getDeviceCapabilities(), Cogs::IGraphicsDevice::getType(), Cogs::Null, Cogs::OpenGL20, Cogs::OpenGLES30, Cogs::Vulkan, and Cogs::WebGPU.

◆ initialize()

void Cogs::Core::Renderer::initialize ( IGraphicsDevice device)
overridevirtual

Implements Cogs::Core::IRenderer.

Definition at line 161 of file Renderer.cpp.

◆ registerExtension()

void Cogs::Core::Renderer::registerExtension ( IRendererExtension extension)
overridevirtual

Registers the given extension with the renderer. Doesn not take ownership of pointer.

Implements Cogs::Core::IRenderer.

Definition at line 626 of file Renderer.cpp.

◆ render()

void Cogs::Core::Renderer::render ( )
overridevirtual

◆ renderScreenshot()

void Cogs::Core::Renderer::renderScreenshot ( const ScreenshotSettings settings,
std::vector< uint8_t > &  bytes,
uint32_t *  stride = nullptr 
)
overridevirtual

◆ setBackgroundColor()

void Cogs::Core::Renderer::setBackgroundColor ( const glm::vec4 &  color)
overridevirtual

Set the background color applied to the output surface before rendering.

Parameters
colorA four-component RGBA color to clear the surface to.

Implements Cogs::Core::IRenderer.

Definition at line 330 of file Renderer.cpp.

◆ setMode()

void Cogs::Core::Renderer::setMode ( RenderMode  mode)
inlineoverridevirtual

Set the rendering mode the renderer should use.

Parameters
modeRendering mode to use.
See also
RenderMode

Implements Cogs::Core::IRenderer.

Definition at line 38 of file Renderer.h.

◆ unregisterExtension()

void Cogs::Core::Renderer::unregisterExtension ( IRendererExtension extension)
overridevirtual

Unregister an extension with the renderer.

Parameters
extensionPointer to a class implementing the IRendererExtension interface.
See also
IRendererExtension

Implements Cogs::Core::IRenderer.

Definition at line 635 of file Renderer.cpp.

◆ updateEffectFlags()

void Cogs::Core::Renderer::updateEffectFlags ( )
protected

Definition at line 337 of file Renderer.cpp.

◆ updatePermutation()

void Cogs::Core::Renderer::updatePermutation ( EnginePermutation permutation)
overridevirtual

◆ updateSettings()

void Cogs::Core::Renderer::updateSettings ( )
protected

Definition at line 349 of file Renderer.cpp.

Friends And Related Function Documentation

◆ getRenderTaskContext

Cogs::Core::RenderTaskContext getRenderTaskContext ( Renderer renderer)
friend

Definition at line 112 of file Renderer.cpp.

Member Data Documentation

◆ activeLights

ActiveLights Cogs::Core::Renderer::activeLights
private

Definition at line 113 of file Renderer.h.

◆ backgroundColor

glm::vec4 Cogs::Core::Renderer::backgroundColor
private

Definition at line 116 of file Renderer.h.

◆ context

Context* Cogs::Core::Renderer::context = nullptr
private

Definition at line 97 of file Renderer.h.

◆ defaultTarget

struct RenderTarget* Cogs::Core::Renderer::defaultTarget = nullptr
private

Definition at line 103 of file Renderer.h.

◆ device

IGraphicsDevice* Cogs::Core::Renderer::device = nullptr
private

Definition at line 98 of file Renderer.h.

◆ effectBindings

EffectBindings Cogs::Core::Renderer::effectBindings
private

Definition at line 109 of file Renderer.h.

◆ effectCache

EffectCache Cogs::Core::Renderer::effectCache
private

Definition at line 104 of file Renderer.h.

◆ effectFlags

EffectFlags::EEffectFlags Cogs::Core::Renderer::effectFlags = EffectFlags::None
private

Definition at line 105 of file Renderer.h.

◆ engineBuffers

EngineBuffers Cogs::Core::Renderer::engineBuffers = {}
private

Definition at line 101 of file Renderer.h.

◆ enginePermutations

EnginePermutations Cogs::Core::Renderer::enginePermutations
private

Definition at line 108 of file Renderer.h.

◆ extensions

std::vector<IRendererExtension*> Cogs::Core::Renderer::extensions
private

Definition at line 117 of file Renderer.h.

◆ maxLights

unsigned Cogs::Core::Renderer::maxLights = static_cast<unsigned>(kMaxLights)
private

Definition at line 115 of file Renderer.h.

◆ mode

RenderMode Cogs::Core::Renderer::mode = RenderMode::Normal
private

Definition at line 100 of file Renderer.h.

◆ pipelineManager

std::unique_ptr<class RenderPipelineManager> Cogs::Core::Renderer::pipelineManager
private

Definition at line 111 of file Renderer.h.

◆ renderContext

RenderTaskContext Cogs::Core::Renderer::renderContext
private

Definition at line 119 of file Renderer.h.

◆ renderers

std::unique_ptr<struct Renderers> Cogs::Core::Renderer::renderers
private

Definition at line 110 of file Renderer.h.

◆ renderStates

RenderStates Cogs::Core::Renderer::renderStates
private

Definition at line 102 of file Renderer.h.

◆ resources

RenderResources Cogs::Core::Renderer::resources
private

Definition at line 107 of file Renderer.h.

◆ settings

RenderSettings Cogs::Core::Renderer::settings
private

Definition at line 99 of file Renderer.h.


The documentation for this class was generated from the following files: