summaryrefslogtreecommitdiff
path: root/gfx/gl/sceneRenderer.h
blob: 7f72d7645f33af4ab09a3e66b610273b239488d8 (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
56
#pragma once

#include "camera.h"
#include "glArrays.h"
#include "program.h"
#include "sceneProvider.h"
#include "sceneShader.h"
#include "shadowMapper.h"
#include <functional>
#include <glm/fwd.hpp>

class SceneRenderer {
public:
	explicit SceneRenderer(ScreenAbsCoord size, GLuint output);

	void render(const SceneProvider &) const;
	void setAmbientLight(const RGB & colour) const;
	void setDirectionalLight(const RGB & colour, const Direction3D & direction, const SceneProvider &) const;

	Camera camera;

protected:
	void renderQuad() const;

	ScreenAbsCoord 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 RGB &, const Direction3D &, const std::span<const glm::mat4x4>,
				const std::span<const TextureRelRegion>, std::size_t maps) const;

	private:
		RequiredUniformLocation directionLoc, colourLoc, lightViewProjectionLoc, lightViewProjectionCountLoc,
				lightViewShadowMapRegionLoc;
	};

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