Elevate Engine 1
Loading...
Searching...
No Matches
Elevate::Renderer Class Reference

#include <Renderer.h>

Static Public Member Functions

static RendererAPI::GraphicAPI GetAPI ()
 
static void BeginFrame (const ScenePtr scene, const Camera &cam)
 
static bool BindShader (const std::shared_ptr< Shader > &shader)
 
static void ApplySystemUniforms (const std::shared_ptr< Shader > &shader)
 
static void SetClearColor (const glm::vec4 &color)
 
static void Clear ()
 
static void FlushBuffers ()
 
static void SetViewport (int x, int y, int width, int height)
 
static void DrawArray (const VertexArray *vao, DrawPrimitiveType primitive=DrawPrimitiveType::Triangles)
 
static void DrawArray (const std::shared_ptr< VertexArray > &vao, DrawPrimitiveType primitive=DrawPrimitiveType::Triangles)
 
static void DrawStack ()
 
static void PushRenderState (const RenderState &newState)
 
static void Dispatch (const RenderCommand &command)
 Immediatly process a RenderCommand. Do not use directly unless you know what you are donig.
 
static void Submit (RenderBucket::Type type, const RenderCommand &command)
 
static void SubmitMesh (const std::shared_ptr< VertexArray > &vao, const std::shared_ptr< Material > &material, const glm::mat4 &transform, RenderBucket::Type bucketType=RenderBucket::Opaque)
 
static void BindTexture (const std::shared_ptr< Texture > &texture, uint8_t slot=0)
 
static void InvalidateStateCache ()
 

Detailed Description

Definition at line 21 of file Renderer.h.

Member Function Documentation

◆ ApplySystemUniforms()

void Elevate::Renderer::ApplySystemUniforms ( const std::shared_ptr< Shader > &  shader)
static

Definition at line 42 of file Renderer.cpp.

43 {
44 // If the binded shader changed
45 if (BindShader(shader))
46 {
47 shader->SetProjectionViewMatrix(s_data.ViewProj);
48 shader->SetCameraPosition(s_data.CameraPosition);
49 }
50 }
static bool BindShader(const std::shared_ptr< Shader > &shader)
Definition Renderer.cpp:30

◆ BeginFrame()

void Elevate::Renderer::BeginFrame ( const ScenePtr  scene,
const Camera cam 
)
static

Definition at line 21 of file Renderer.cpp.

22 {
23 s_API->ClearTextureBindings();
24 s_currentShaderID = 0;
25 s_data.CameraPosition = cam.gameObject->GetPosition();
26 s_data.ViewProj = cam.GenViewProjectionMatrix();
27 s_data.ActiveLighting = scene->GetSceneLighting();
28 }
virtual void ClearTextureBindings() const =0

◆ BindShader()

bool Elevate::Renderer::BindShader ( const std::shared_ptr< Shader > &  shader)
static

Definition at line 30 of file Renderer.cpp.

31 {
32 uint32_t id = shader->GetID();
33 if (s_currentShaderID != id)
34 {
35 shader->Bind();
36 s_currentShaderID = id;
37 return true;
38 }
39 return false;
40 }

◆ BindTexture()

void Elevate::Renderer::BindTexture ( const std::shared_ptr< Texture > &  texture,
uint8_t  slot = 0 
)
static

Definition at line 160 of file Renderer.cpp.

161 {
162 // todo optimize and make sure EVERY texture uses this
163 uintptr_t textureID = texture ? reinterpret_cast<uintptr_t>(texture->GetNativeHandle()) : 0;
164 if (s_textures[slot] != textureID)
165 {
166 if (texture)
167 {
168 texture->Bind(slot);
169 }
170 s_textures[slot] = textureID;
171 }
172 }

◆ Clear()

void Elevate::Renderer::Clear ( )
static

Definition at line 58 of file Renderer.cpp.

59 {
60 s_API->Clear();
61 }
virtual void Clear() const =0

◆ Dispatch()

void Elevate::Renderer::Dispatch ( const RenderCommand command)
static

Immediatly process a RenderCommand. Do not use directly unless you know what you are donig.

Parameters
commandThe RenderCommand to process at this exact instant.

Definition at line 112 of file Renderer.cpp.

113 {
114 // Update the renderer state if necessary
115 PushRenderState(command.m_State);
116
117 // Setup the Material and Shader
118 uint32_t prevshader = s_currentShaderID;
119 if (command.m_MaterialInstance)
120 {
121 auto shader = command.m_MaterialInstance->GetShader();
122 if (shader)
123 {
124 ApplySystemUniforms(shader);
125 shader->SetModelMatrix(command.Transform);
126 s_data.ActiveLighting->UploadToShader(shader);
127 command.m_MaterialInstance->Apply();
128 }
129 }
130 // Actually render the vertex array
131 Renderer::DrawArray(command.m_VertexArray);
132 }
static void PushRenderState(const RenderState &newState)
Definition Renderer.cpp:91
static void DrawArray(const VertexArray *vao, DrawPrimitiveType primitive=DrawPrimitiveType::Triangles)
Definition Renderer.cpp:73
static void ApplySystemUniforms(const std::shared_ptr< Shader > &shader)
Definition Renderer.cpp:42

◆ DrawArray() [1/2]

void Elevate::Renderer::DrawArray ( const std::shared_ptr< VertexArray > &  vao,
DrawPrimitiveType  primitive = DrawPrimitiveType::Triangles 
)
static

Definition at line 81 of file Renderer.cpp.

82 {
83 DrawArray(vao.get(), primitive);
84 }

◆ DrawArray() [2/2]

void Elevate::Renderer::DrawArray ( const VertexArray vao,
DrawPrimitiveType  primitive = DrawPrimitiveType::Triangles 
)
static

Definition at line 73 of file Renderer.cpp.

74 {
75 if (vao)
76 {
77 s_API->DrawArray(vao, primitive);
78 }
79 }
virtual void DrawArray(const VertexArray *vao, DrawPrimitiveType primitive=DrawPrimitiveType::Triangles) const =0

◆ DrawStack()

void Elevate::Renderer::DrawStack ( )
static

Definition at line 86 of file Renderer.cpp.

87 {
88 s_commands.FlushAll();
89 }

◆ FlushBuffers()

void Elevate::Renderer::FlushBuffers ( )
static

Definition at line 63 of file Renderer.cpp.

64 {
65 s_API->FlushBuffers();
66 }
virtual void FlushBuffers() const =0

◆ GetAPI()

static RendererAPI::GraphicAPI Elevate::Renderer::GetAPI ( )
inlinestatic

Definition at line 24 of file Renderer.h.

24{ return RendererAPI::GetAPI(); }
static GraphicAPI GetAPI()
Definition RendererAPI.h:49

◆ InvalidateStateCache()

void Elevate::Renderer::InvalidateStateCache ( )
static

Definition at line 174 of file Renderer.cpp.

175 {
176 // Make each texture ptr to an impossible value to make sure we bind each frame.
177 for (int i = 0; i < std::size(s_textures); i++) {
178 s_textures[i] = (uintptr_t)-1;
179 }
180 }

◆ PushRenderState()

void Elevate::Renderer::PushRenderState ( const RenderState newState)
static

Definition at line 91 of file Renderer.cpp.

92 {
93 // todo make a first invalid call to make sure the GPU is synced with this cache before the user does anything
94 if (newState.Cullface != s_currentState.Cullface)
95 {
96 s_API->SetCullingState(newState.Cullface);
97 }
98
99 if (newState.DepthWrite != s_currentState.DepthWrite)
100 {
101 s_API->SetDepthWrittingState(newState.DepthWrite);
102 }
103
104 if (newState.DepthTest != s_currentState.DepthTest)
105 {
106 s_API->SetDepthTestingState(newState.DepthTest);
107 }
108
109 s_currentState = newState;
110 }
virtual void SetCullingState(bool enabled) const =0
virtual void SetDepthWrittingState(bool enabled) const =0
virtual void SetDepthTestingState(bool enabled) const =0

◆ SetClearColor()

void Elevate::Renderer::SetClearColor ( const glm::vec4 &  color)
static

Definition at line 53 of file Renderer.cpp.

54 {
55 s_API->SetClearColor(color);
56 }
virtual void SetClearColor(const glm::vec4 &color) const =0

◆ SetViewport()

void Elevate::Renderer::SetViewport ( int  x,
int  y,
int  width,
int  height 
)
static

Definition at line 68 of file Renderer.cpp.

69 {
70 s_API->SetViewport(x, y, width, height);
71 }
virtual void SetViewport(int x, int y, int width, int height) const =0

◆ Submit()

void Elevate::Renderer::Submit ( RenderBucket::Type  type,
const RenderCommand command 
)
static

Definition at line 134 of file Renderer.cpp.

135 {
136 s_commands.Submit(type, command);
137 }
void Submit(RenderBucket::Type type, const RenderCommand &command)

◆ SubmitMesh()

void Elevate::Renderer::SubmitMesh ( const std::shared_ptr< VertexArray > &  vao,
const std::shared_ptr< Material > &  material,
const glm::mat4 &  transform,
RenderBucket::Type  bucketType = RenderBucket::Opaque 
)
static

Definition at line 139 of file Renderer.cpp.

140 {
141 RenderCommand command;
142 command.m_VertexArray = vao.get();
143 command.m_MaterialInstance = material.get();
144 command.Transform = transform;
145
146 if (bucketType == RenderBucket::Transparent)
147 {
148 command.m_State.BlendEnable = true;
149 command.m_State.DepthWrite = false; // Transparents usually don't write to depth
150 }
151 else
152 {
153 command.m_State.BlendEnable = false;
154 command.m_State.DepthWrite = true;
155 }
156
157 Submit(bucketType, command);
158 }
static void Submit(RenderBucket::Type type, const RenderCommand &command)
Definition Renderer.cpp:134

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