SparrowRenderer/src/deferredpipeline.h

105 lines
2.7 KiB
C++

#ifndef DEFERREDPIPELINE_H
#define DEFERREDPIPELINE_H
#include "pipeline.h"
#include "framebuffer.h"
#include <unordered_map>
#include <glm/mat4x4.hpp>
class Shader;
class Camera;
class Skybox;
class GuiMesh;
class GBuffer : public FrameBuffer
{
public:
enum Buffers { POSITION, ALBEDO, NORMAL, EMISSION, NB_BUFFERS };
GBuffer(int width, int height, GLuint renderBuffer);
void bindTextures();
void unbindTextures();
};
class LightingBuffer : public FrameBuffer
{
public:
LightingBuffer(int width, int height, GLuint renderBuffer);
};
class DeferredPipeline : public Pipeline
{
Camera *m_camera;
Skybox* m_skybox;
int m_width;
int m_height;
glm::mat4 m_orthoMatrix;
// shaders
std::vector<unsigned int> m_meshTypes;
std::vector<unsigned int> m_lightTypes;
std::unordered_map<unsigned int, Shader*> m_mesh3DShaders;
std::unordered_map<unsigned int, Shader*> m_lightShaders;
std::unordered_map<unsigned int, Shader*> m_mesh2DShaders;
Shader *m_postEffectsShader;
ShaderSource *m_gBufferSource;
ShaderSource *m_lightingSource;
ShaderSource *m_mesh2DSource;
ShaderSource *m_postEffectsShaders;
ShaderSource *m_debugShaders;
GuiMesh * m_guiMesh;
float m_imguiDepth;
glm::vec3 m_fogBe;
glm::vec3 m_fogBi;
glm::vec3 m_fogColor;
// framebuffers
GLuint m_depth_stencil_renderBuffer;
GBuffer *m_gBuffer;
LightingBuffer *m_lightingBuffer;
const FrameBuffer *m_renderTarget;
// debug gui
bool m_debugGuiEnabled;
bool m_gammaCorrectEnabled;
bool m_hdrTonemappingEnabled;
void gui();
void recompilePostEffectsShader();
public:
DeferredPipeline();
void setCamera(Camera *camera) { m_camera = camera; }
Camera* getCamera() { return m_camera;}
void setSources(ShaderSource *gBufferSource, ShaderSource *lightingSource, ShaderSource *guiSource, Shader *postEffectsShader);
void setRenderTarget(const FrameBuffer *fbo) { m_renderTarget = fbo; }
void setSkybox(Texture* texture);
void refreshScene(Scene *scene);
float getIMGuiDepth() { return m_imguiDepth; }
void setIMGuiDepth(float depth) { m_imguiDepth = depth; }
virtual void renderGL(Scene *scene);
virtual void resizeGL(int w, int h);
/**
* @brief pick allows picking directly in the GPU buffer, this is a very heavy operation though,
* and can only be performed in the position buffer
* @param x in screen space
* @param y in screen space
* @return the position of the fragment
*/
glm::vec4 pick(int x, int y);
void toggleDebugGui() { m_debugGuiEnabled = !m_debugGuiEnabled; }
bool isDebugGuiVisible() { return m_debugGuiEnabled; }
};
#endif // DEFERREDPIPELINE_H