Golias Engine
A C++ 20 'game engine' built with SDL3 with wide platform support.
base_struct.h
Go to the documentation of this file.
1 #pragma once
2 #include "core/io/file_system.h"
3 
4 enum class CubemapOrientation {
5  DEFAULT,
6  TOP,
7  BOTTOM,
8  FLIP_X,
9  FLIP_Y
10 };
11 
12 
13 // TODO: implement
14 class Texture2D {
15 public:
16 };
17 
18 
29 enum class GpuBufferType {
30  VERTEX,
31  INDEX,
32  UNIFORM,
33  STORAGE
34 };
35 
46 class GpuBuffer {
47 public:
48  virtual ~GpuBuffer() = default;
49 
50  virtual void bind() const = 0;
51 
52  virtual void upload(const void* data, size_t size) = 0;
53 
54  virtual size_t size() const = 0;
55 
56  virtual GpuBufferType type() const = 0;
57 
58 };
59 
60 enum class DataType {
61  USHORT,
62  FLOAT,
63  INT,
65 };
66 
67 
69  uint32_t location;
70  uint32_t components;
72  bool normalized;
73  uint32_t offset;
74 };
75 
77 public:
78  virtual ~GpuVertexLayout() = default;
79  virtual void bind() const = 0;
80  virtual void unbind() const = 0;
81 };
82 
83 
85  None = 0,
86  RGBA8,
90 };
91 
94 };
95 
97  std::vector<FramebufferTextureSpecification> attachments;
99 
100  FramebufferAttachmentSpecification(const std::initializer_list<FramebufferTextureSpecification> list)
101  : attachments(list) {
102  }
103 };
104 
106  unsigned int width = 0;
107  unsigned int height = 0;
109  bool swap_chain_target = false;
110 };
111 
112 
113 class Framebuffer {
114 public:
115  virtual ~Framebuffer() = default;
116 
117  virtual void bind() = 0;
118  virtual void unbind() = 0;
119  virtual void invalidate() = 0;
120 
121  virtual void resize(unsigned int width, unsigned int height) = 0;
122  virtual uint32_t get_color_attachment_id(size_t index = 0) const = 0;
123  virtual uint32_t get_depth_attachment_id() const = 0;
124 
125  virtual const FramebufferSpecification& get_specification() const = 0;
126 };
127 
128 
129 
140 struct Vertex {
141  glm::vec3 position;
142  glm::vec3 normal;
143  glm::vec2 uv;
144 };
145 
146 constexpr int MAX_BONES = 250;
147 
148 
160 class Shader {
161 public:
162  Shader() = default;
163 
164  virtual ~Shader() = default;
165 
166  virtual void activate() const = 0;
167 
168  virtual void set_value(const std::string& name, float value) = 0;
169 
170  virtual void set_value(const std::string& name, int value) = 0;
171 
172  virtual void set_value(const std::string& name, Uint32 value) = 0;
173 
174  virtual void set_value(const std::string& name, glm::mat4 value, Uint32 count = 1) =0;
175 
176  virtual void set_value(const std::string& name, const int* value, Uint32 count = 1) =0;
177 
178  virtual void set_value(const std::string& name, const float* value, Uint32 count = 1) =0;
179 
180  virtual void set_value(const std::string& name, glm::vec2 value, Uint32 count = 1) =0;
181 
182  virtual void set_value(const std::string& name, glm::vec3 value, Uint32 count = 1) =0;
183 
184  virtual void set_value(const std::string& name, glm::vec4 value, Uint32 count = 1) =0;
185 
186  virtual void set_value(const std::string& name, const glm::mat4* values, Uint32 count = 1) =0;
187 
188 
189  virtual void destroy() = 0;
190 
191  virtual Uint32 get_id() const = 0;
192 
193  virtual bool is_valid() const = 0;
194 
195 protected:
196  Uint32 id = 0;
197 
198  std::unordered_map<std::string, Uint32> _uniforms;
199 };
200 
202  Uint32 texture = 0;
203 
204  glm::vec3 color = glm::vec3(0.2,0.3,0.3);
205  std::shared_ptr<GpuBuffer> vertex_buffer = nullptr;
206  std::shared_ptr<GpuBuffer> index_buffer = nullptr;
207  std::shared_ptr<GpuVertexLayout> vertex_layout = nullptr;
208 
209  float brightness = 1.0f;
210 };
211 
212 // Forward declaration
213 class Renderer;
constexpr int MAX_BONES
Definition: base_struct.h:146
FramebufferTextureFormat
Definition: base_struct.h:84
GpuBufferType
GpuBuffer Abstract class.
Definition: base_struct.h:29
@ STORAGE
For Uniform Buffer Objects (UBOs)
@ UNIFORM
For Element Buffer Objects (EBOs)
@ INDEX
For Vertex Buffer Objects (VBOs)
CubemapOrientation
Definition: base_struct.h:4
DataType
Definition: base_struct.h:60
Definition: base_struct.h:113
virtual ~Framebuffer()=default
virtual const FramebufferSpecification & get_specification() const =0
virtual uint32_t get_color_attachment_id(size_t index=0) const =0
virtual uint32_t get_depth_attachment_id() const =0
virtual void unbind()=0
virtual void bind()=0
virtual void resize(unsigned int width, unsigned int height)=0
virtual void invalidate()=0
GpuBuffer Abstract class.
Definition: base_struct.h:46
virtual void bind() const =0
virtual ~GpuBuffer()=default
virtual size_t size() const =0
virtual void upload(const void *data, size_t size)=0
virtual GpuBufferType type() const =0
Definition: base_struct.h:76
virtual ~GpuVertexLayout()=default
virtual void unbind() const =0
virtual void bind() const =0
Definition: renderer.h:33
Shader Abstract class.
Definition: base_struct.h:160
virtual Uint32 get_id() const =0
virtual void set_value(const std::string &name, int value)=0
virtual void set_value(const std::string &name, glm::mat4 value, Uint32 count=1)=0
virtual void set_value(const std::string &name, const glm::mat4 *values, Uint32 count=1)=0
virtual ~Shader()=default
virtual void set_value(const std::string &name, const float *value, Uint32 count=1)=0
virtual void set_value(const std::string &name, glm::vec4 value, Uint32 count=1)=0
std::unordered_map< std::string, Uint32 > _uniforms
Definition: base_struct.h:198
virtual void set_value(const std::string &name, glm::vec3 value, Uint32 count=1)=0
virtual void set_value(const std::string &name, const int *value, Uint32 count=1)=0
virtual void set_value(const std::string &name, Uint32 value)=0
virtual bool is_valid() const =0
virtual void destroy()=0
virtual void set_value(const std::string &name, glm::vec2 value, Uint32 count=1)=0
Shader()=default
virtual void activate() const =0
virtual void set_value(const std::string &name, float value)=0
Definition: base_struct.h:14
Definition: base_struct.h:96
FramebufferAttachmentSpecification(const std::initializer_list< FramebufferTextureSpecification > list)
Definition: base_struct.h:100
std::vector< FramebufferTextureSpecification > attachments
Definition: base_struct.h:97
Definition: base_struct.h:105
bool swap_chain_target
Definition: base_struct.h:109
unsigned int height
Definition: base_struct.h:107
FramebufferAttachmentSpecification attachments
Definition: base_struct.h:108
unsigned int width
Definition: base_struct.h:106
Definition: base_struct.h:92
FramebufferTextureFormat format
Definition: base_struct.h:93
Definition: base_struct.h:68
uint32_t components
Definition: base_struct.h:70
bool normalized
Definition: base_struct.h:72
uint32_t location
Definition: base_struct.h:69
DataType type
Definition: base_struct.h:71
uint32_t offset
Definition: base_struct.h:73
Vertex structure.
Definition: base_struct.h:140
glm::vec3 position
Definition: base_struct.h:141
glm::vec3 normal
3D position
Definition: base_struct.h:142
glm::vec2 uv
3D normal
Definition: base_struct.h:143
Definition: base_struct.h:201
float brightness
Definition: base_struct.h:209
Uint32 texture
Definition: base_struct.h:202
std::shared_ptr< GpuBuffer > index_buffer
Definition: base_struct.h:206
glm::vec3 color
Definition: base_struct.h:204
std::shared_ptr< GpuVertexLayout > vertex_layout
Definition: base_struct.h:207
std::shared_ptr< GpuBuffer > vertex_buffer
Definition: base_struct.h:205