SimpleEngine/include/simpleengine/gfx/renderer.h

70 lines
2.2 KiB
C
Raw Normal View History

#pragma once
2022-10-12 03:16:52 +00:00
#include "../camera.h"
#include "shader.h"
2022-10-12 03:16:52 +00:00
#include "../renderable.h"
#include "rendering_type.h"
#include <unordered_map>
#include <vector>
#include <queue>
2022-10-12 03:16:52 +00:00
#include <map>
namespace simpleengine::gfx {
2022-10-12 03:16:52 +00:00
class Mesh;
class RenderingJob {
public:
2022-10-12 03:16:52 +00:00
RenderingType rendering_type;
gfx::Mesh* rendering_mesh;
glm::mat4 last_transform_mat;
glm::mat4 transform_mat;
RenderingJob(RenderingType rendering_type, gfx::Mesh& mesh, glm::mat4 last_pos, glm::mat4 position);
};
class Renderer : public simpleengine::Renderable {
private:
GLFWwindow* window;
2022-10-12 03:16:52 +00:00
protected:
bool is_initialized = false;
void check_if_initialized();
public:
2022-10-12 03:16:52 +00:00
std::queue<RenderingJob> transparent_render_queue;
std::queue<RenderingJob> other_render_queue;
gfx::Shader shader;
2022-10-12 03:16:52 +00:00
std::shared_ptr<Camera> camera;
2022-10-12 03:16:52 +00:00
Renderer(GLFWwindow* window, gfx::Shader shader, std::shared_ptr<Camera> camera);
Renderer(GLFWwindow* window, GLuint shader_program, std::shared_ptr<Camera> camera);
void enable_debug();
void enable_gl_option(GLenum option) const;
2022-10-12 03:16:52 +00:00
virtual void sort_jobs();
virtual void queue_job(RenderingType rendering_type, gfx::Mesh& mesh, glm::mat4 last_position, glm::mat4 position);
virtual void queue_job(RenderingJob job);
virtual void create_job_buffers(RenderingJob& job);
virtual void initialize();
virtual void destroy() override;
virtual void update(const float& delta_time) override;
virtual void render(const float& interpolate_alpha, const float& frame_time) override;
2022-10-12 03:16:52 +00:00
/**
* @brief Renders a single job.
*
* @param job The job that will be rendered.
* @return true if the job was rendered successfully.
* @return false if there was an error when trying to render the job.
*/
virtual bool render_job(const float& interpolate_alpha, const RenderingJob& job);
virtual void render_job_queue(const float& interpolate_alpha, std::queue<RenderingJob>& queue);
virtual void render_job_queue(const float& interpolate_alpha, std::map<float, RenderingJob, std::greater<>>& queue);
};
}