engine/include/renderer.h

100 lines
2.4 KiB
C
Raw Normal View History

#ifndef ENGINE_INCLUDE_RENDERER_H_
#define ENGINE_INCLUDE_RENDERER_H_
2023-08-29 17:06:04 +00:00
#include <memory>
#include <unordered_map>
#include <glm/mat4x4.hpp>
2023-08-29 21:10:05 +00:00
#include <glm/trigonometric.hpp>
2023-08-29 17:06:04 +00:00
#include "gfx_device.h"
2023-08-31 09:51:12 +00:00
#include "systems/mesh_render_system.h"
2023-08-29 17:06:04 +00:00
namespace engine {
2023-08-29 17:06:04 +00:00
// A uniform struct that holds data of type T
template <typename T>
struct UniformDescriptor {
const gfx::DescriptorSetLayout* layout;
const gfx::DescriptorSet* set;
struct UniformBufferData {
T data;
} uniform_buffer_data;
gfx::UniformBuffer* uniform_buffer;
};
class Renderer {
public:
Renderer(const char* app_name, const char* app_version, SDL_Window* window,
gfx::GraphicsSettings settings);
~Renderer();
2023-08-29 21:10:05 +00:00
void PreRender(bool window_is_resized, glm::mat4 camera_transform);
2023-08-31 09:51:12 +00:00
// staticList can be nullptr to render nothing
2023-09-02 18:14:12 +00:00
void Render(const RenderList& static_list, const RenderList& dynamic_list);
2023-08-29 21:10:05 +00:00
// getters
2023-08-29 17:06:04 +00:00
GFXDevice* GetDevice() { return device_.get(); }
const gfx::DescriptorSetLayout* GetGlobalSetLayout() {
return global_uniform.layout;
}
const gfx::DescriptorSetLayout* GetFrameSetLayout() {
return frame_uniform.layout;
}
const gfx::DescriptorSetLayout* GetMaterialSetLayout() {
return material_set_layout;
}
std::unordered_map<gfx::SamplerInfo, const gfx::Sampler*> samplers;
private:
std::unique_ptr<GFXDevice> device_;
2023-08-29 21:10:05 +00:00
struct CameraSettings {
float vertical_fov_radians = glm::radians(70.0f);
float clip_near = 0.5f;
float clip_far = 1000.0f;
} camera_settings_;
2023-08-29 17:06:04 +00:00
// ALL vertex shaders must begin with:
/*
layout(set = 0, binding = 0) uniform GlobalSetUniformBuffer {
mat4 proj;
} globalSetUniformBuffer;
layout(set = 1, binding = 0) uniform FrameSetUniformBuffer {
mat4 view;
} frameSetUniformBuffer;
layout( push_constant ) uniform Constants {
mat4 model;
} constants;
*/
// ALL fragment shaders must begin with:
/*
layout(set = 2, binding = 0) uniform sampler2D materialSetSampler;
*/
// in vertex shader
UniformDescriptor<glm::mat4> global_uniform; // rarely updates; set 0
UniformDescriptor<glm::mat4> frame_uniform; // updates once per frame; set 1
// in fragment shader
const gfx::DescriptorSetLayout* material_set_layout; // set 2
2023-08-29 21:10:05 +00:00
float viewport_aspect_ratio_ = 1.0f;
2023-08-31 13:18:42 +00:00
const gfx::Pipeline* last_bound_pipeline_ = nullptr;
void DrawRenderList(gfx::DrawBuffer* draw_buffer, const RenderList& render_list);
2023-08-29 17:06:04 +00:00
};
} // namespace engine
2023-09-02 18:14:12 +00:00
#endif