StevEngine
StevEngine is a customizable C++ game engine.
Loading...
Searching...
No Matches
RenderSystem.hpp
1#pragma once
2#ifdef StevEngine_RENDERER_GL
3#include "Object.hpp"
4#include "utilities/Color.hpp"
5#include "visuals/shaders/Shader.hpp"
6#include "visuals/shaders/ShaderProgram.hpp"
7
8#include <SDL.h>
9
10#include <vector>
11#include <array>
12#include <cstdint>
13
14#define OPENGL_MAJOR 4
15#define OPENGL_MINOR 4
16
17namespace StevEngine {
18 namespace Visuals {
19 class Light;
20 }
27 namespace Renderer {
28 //Object
33 struct RenderObject {
36
43
47 void Draw() {
48 object.Draw(transform);
49 }
50 };
51
61
69 public:
74 void Init(SDL_Window* window);
75
82 void DrawObject(const CustomObject& object, Utilities::Matrix4 transform, RenderQueue queue = STANDARD);
83
88 void SetBackground(const Utilities::Color& color);
89
95 void SetAmbientLight(float strength, const Utilities::Color& color = Utilities::Color(255,255,255,255));
96
101 void AddGlobalShader(ShaderProgram shader);
102
107 void ResetGlobalShader(ShaderType type);
108
109 // Engine interface functions
110 static const Uint32 WindowType();
111 void DrawFrame();
112 void SetViewSize(int WIDTH, int HEIGHT);
113 void SetVSync(bool vsync);
114 void SetFaceCulling(bool enable, GLenum face = GL_FRONT, bool clockwise = false);
115 void SetMSAA(bool enable, uint16_t amount = 4);
116
117 //Enable/disable
118 void SetEnabled(bool enabled);
119 private: bool enabled;
120 public:
121
122 // Getters
123 const ShaderProgram& GetDefaultVertexShaderProgram() const { return vertexShaderProgram; }
124 const ShaderProgram& GetDefaultFragmentShaderProgram() const { return fragmentShaderProgram; }
125 uint32_t GetShaderPipeline() const { return shaderPipeline; }
126 Utilities::Color GetAmbientLightColor() const { return ambientLightColor; }
127 float GetAmbientLightStrength() const { return ambientLightStrength; }
128
129 // Light management
135 uint32_t GetLightID(std::string type);
136
141 std::vector<Visuals::Light*> GetLights() const { return lights; }
142
147 void AddLight(Visuals::Light* light);
148
153 void RemoveLight(Visuals::Light* light);
154
158 void ResetGPUBuffers();
159
160 private:
161 SDL_GLContext context;
162
164 std::array<std::vector<RenderObject>, RenderQueue::MUST_BE_LAST> queues;
165
166 // Shader programs
167 ShaderProgram vertexShaderProgram;
168 ShaderProgram fragmentShaderProgram;
169 uint32_t shaderPipeline;
170
171 // GPU Buffers
172 uint32_t VBO;
173 uint32_t EBO;
174 uint32_t VAO;
175
176 // Scene properties
177 Utilities::Color backgroundColor = {0, 0, 0, 255};
178 std::vector<Visuals::Light*> lights;
179 Utilities::Color ambientLightColor;
180 float ambientLightStrength;
181 };
182
183 extern RenderSystem render;
184 }
185}
186#endif
Base interface for renderable objects.
Definition Object.hpp:21
Core rendering system.
Definition RenderSystem.hpp:68
void SetMSAA(bool enable, uint16_t amount=4)
Set anti-aliasing.
Definition RenderSystem.cpp:126
void DrawObject(const CustomObject &object, Utilities::Matrix4 transform, RenderQueue queue=STANDARD)
Queue object for rendering.
Definition RenderSystem.cpp:181
void ResetGlobalShader(ShaderType type)
Reset global shader to default.
Definition RenderSystem.cpp:141
static const Uint32 WindowType()
Get SDL window flags.
Definition RenderSystem.cpp:28
void AddGlobalShader(ShaderProgram shader)
Add global shader program.
Definition RenderSystem.cpp:158
void SetFaceCulling(bool enable, GLenum face=GL_FRONT, bool clockwise=false)
Set face culling.
Definition RenderSystem.cpp:116
void AddLight(Visuals::Light *light)
Add light to scene.
Definition RenderSystem.cpp:257
void SetVSync(bool vsync)
Set vertical sync.
Definition RenderSystem.cpp:112
void SetViewSize(int WIDTH, int HEIGHT)
Set viewport size.
Definition RenderSystem.cpp:108
void DrawFrame()
Draw a complete frame.
Definition RenderSystem.cpp:185
std::vector< Visuals::Light * > GetLights() const
Get all active lights.
Definition RenderSystem.hpp:141
void SetBackground(const Utilities::Color &color)
Set background clear color.
Definition RenderSystem.cpp:232
void SetAmbientLight(float strength, const Utilities::Color &color=Utilities::Color(255, 255, 255, 255))
Set ambient light properties.
Definition RenderSystem.cpp:236
uint32_t GetLightID(std::string type)
Get next available light ID for type.
Definition RenderSystem.cpp:243
void ResetGPUBuffers()
Rebinds the GPU buffers (VBO, EBO, VAO) to the renderers.
Definition RenderSystem.cpp:175
void RemoveLight(Visuals::Light *light)
Remove light from scene.
Definition RenderSystem.cpp:261
void Init(SDL_Window *window)
Initialize rendering system.
Definition RenderSystem.cpp:48
Compiled and linked shader program.
Definition ShaderProgram.hpp:22
4x4 matrix for 3D transformations
Definition Matrix4.hpp:12
Base class for light components.
Definition Lights.hpp:18
Core rendering system.
Definition Object.cpp:19
RenderQueue
Render queue types for sorting objects.
Definition RenderSystem.hpp:55
@ OVERLAY
UI and overlay objects.
Definition RenderSystem.hpp:58
@ STANDARD
Default opaque objects.
Definition RenderSystem.hpp:56
@ MUST_BE_LAST
Queue count marker.
Definition RenderSystem.hpp:59
@ TRANSPARENT
Transparent objects.
Definition RenderSystem.hpp:57
RenderSystem render
Global render system instance.
Definition RenderSystem.cpp:26
const CustomObject & object
Object to render.
Definition RenderSystem.hpp:34
const Utilities::Matrix4 transform
World transform matrix.
Definition RenderSystem.hpp:35
RenderObject(const CustomObject &object, const Utilities::Matrix4 &transform)
Create render object.
Definition RenderSystem.hpp:42
void Draw()
Draw the object.
Definition RenderSystem.hpp:47
RGBA color representation.
Definition Color.hpp:12