2022-08-19 02:40:34 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-10-12 03:16:52 +00:00
|
|
|
#include "../camera.h"
|
2022-08-19 02:40:34 +00:00
|
|
|
#include "shader.h"
|
2022-10-12 03:16:52 +00:00
|
|
|
#include "../renderable.h"
|
|
|
|
#include "rendering_type.h"
|
2022-08-19 02:40:34 +00:00
|
|
|
|
2022-08-30 23:39:24 +00:00
|
|
|
#include <unordered_map>
|
2022-08-19 02:40:34 +00:00
|
|
|
#include <vector>
|
2022-09-23 04:44:07 +00:00
|
|
|
#include <queue>
|
2022-10-12 03:16:52 +00:00
|
|
|
#include <map>
|
2022-08-19 02:40:34 +00:00
|
|
|
|
|
|
|
namespace simpleengine::gfx {
|
2022-10-12 03:16:52 +00:00
|
|
|
class Mesh;
|
|
|
|
|
2022-09-23 04:44:07 +00:00
|
|
|
class RenderingJob {
|
2022-08-19 02:40:34 +00:00
|
|
|
public:
|
2022-10-12 03:16:52 +00:00
|
|
|
RenderingType rendering_type;
|
|
|
|
gfx::Mesh* rendering_mesh;
|
2022-10-15 03:17:22 +00:00
|
|
|
glm::mat4 last_transform_mat;
|
2022-09-23 04:44:07 +00:00
|
|
|
glm::mat4 transform_mat;
|
2022-08-30 23:39:24 +00:00
|
|
|
|
2022-10-15 03:17:22 +00:00
|
|
|
RenderingJob(RenderingType rendering_type, gfx::Mesh& mesh, glm::mat4 last_pos, glm::mat4 position);
|
2022-09-23 04:44:07 +00:00
|
|
|
};
|
2022-08-19 02:40:34 +00:00
|
|
|
|
2022-09-23 04:44:07 +00:00
|
|
|
class Renderer : public simpleengine::Renderable {
|
|
|
|
private:
|
|
|
|
GLFWwindow* window;
|
2022-10-12 03:16:52 +00:00
|
|
|
protected:
|
2022-10-13 03:01:31 +00:00
|
|
|
bool is_initialized = false;
|
|
|
|
|
|
|
|
void check_if_initialized();
|
|
|
|
|
2022-09-23 04:44:07 +00:00
|
|
|
public:
|
2022-10-12 03:16:52 +00:00
|
|
|
std::queue<RenderingJob> transparent_render_queue;
|
|
|
|
std::queue<RenderingJob> other_render_queue;
|
2022-08-19 02:40:34 +00:00
|
|
|
|
2022-09-10 22:39:39 +00:00
|
|
|
gfx::Shader shader;
|
2022-10-12 03:16:52 +00:00
|
|
|
std::shared_ptr<Camera> camera;
|
2022-08-19 02:40:34 +00:00
|
|
|
|
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);
|
2022-09-10 22:39:39 +00:00
|
|
|
|
|
|
|
void enable_debug();
|
|
|
|
|
2022-10-12 03:16:52 +00:00
|
|
|
virtual void sort_jobs();
|
2022-10-15 03:17:22 +00:00
|
|
|
virtual void queue_job(RenderingType rendering_type, gfx::Mesh& mesh, glm::mat4 last_position, glm::mat4 position);
|
2022-09-23 04:44:07 +00:00
|
|
|
virtual void queue_job(RenderingJob job);
|
|
|
|
virtual void create_job_buffers(RenderingJob& job);
|
2022-08-19 02:40:34 +00:00
|
|
|
|
|
|
|
virtual void initialize();
|
2022-09-10 22:39:39 +00:00
|
|
|
virtual void destroy() override;
|
2022-08-19 02:40:34 +00:00
|
|
|
|
2022-08-30 23:39:24 +00:00
|
|
|
virtual void update(const float& delta_time) override;
|
2022-08-19 02:40:34 +00:00
|
|
|
|
2022-10-15 03:17:22 +00:00
|
|
|
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.
|
|
|
|
*/
|
2022-10-15 03:17:22 +00:00
|
|
|
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);
|
2022-08-19 02:40:34 +00:00
|
|
|
};
|
|
|
|
}
|