summaryrefslogtreecommitdiff
path: root/ui/sceneRenderer.h
blob: f40b894c6ccb49e893c9b3dc5c4c100f79704dff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once

#include "gfx/gl/camera.h"
#include "gfx/gl/program.h"
#include "gfx/gl/sceneShader.h"
#include "lib/glArrays.h"
#include <functional>
#include <glm/fwd.hpp>

class SceneRenderer {
public:
	class SceneProvider {
	public:
		virtual ~SceneProvider() = default;
		virtual void content(const SceneShader &) const = 0;
		virtual void environment(const SceneShader &, const SceneRenderer &) const;
		virtual void lights(const SceneShader &) const = 0;
	};

	explicit SceneRenderer(glm::ivec2 size, GLuint output);

	void render(const SceneProvider &) const;
	void setAmbientLight(const glm::vec3 & colour) const;
	void setDirectionalLight(const glm::vec3 & colour, const glm::vec3 & direction) const;

	Camera camera;

private:
	glm::ivec2 size;
	GLuint output;
	glFrameBuffer gBuffer;
	glTexture gPosition, gNormal, gAlbedoSpec, gIllumination;
	glRenderBuffer depth;
	class DeferredLightProgram : public Program {
	public:
		using Program::Program;
		using Program::use;
	};
	class DirectionalLightProgram : public Program {
	public:
		DirectionalLightProgram();
		using Program::use;

		void setDirectionalLight(const glm::vec3 &, const glm::vec3 &) const;

	private:
		RequiredUniformLocation directionLoc, colourLoc;
	};

	DeferredLightProgram lighting;
	DirectionalLightProgram dirLight;
	glVertexArray displayVAO;
	glBuffer displayVBO;
	SceneShader shader;
};