summaryrefslogtreecommitdiff
path: root/renderer.hpp
blob: 46f53318771e85085166006e41e80fa6a15d1978 (plain) (blame)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef renderer_hpp
#define renderer_hpp

#include "camera.hpp"
#include "hashmap.hpp"
#include "lighting.hpp"
#include "video.hpp"

enum {
	FORWARD,
	SHADOW_MAP_START,
	SHADOW_MAP_END = SHADOW_MAP_START + Lighting::max_shadows,
	drawlist_count = SHADOW_MAP_END };

struct Asset_Arena;
struct Model_Instance;
struct Renderer;

struct Drawlist {
	Model_Instance** models;
	int count;
	int cap;
	Camera_Id camera;
	Staged_Buffer vp;

	void render(
		const Renderer& r,
		Device* dev,
		Arena* a,
		const Lighting* l,
		Render_Pass& pass,
		void (*overrider)(Pipeline_Builder&)
	);
};

struct Fullscreen_Quad {
	Buffer_Id vb;

	void init(Device* d);
	void destroy(Device* d);
	void render(
		Context& ctx,
		Pipeline& pip,
		Render_Pass& pass,
		int bind
	);
};

struct Renderer {
	static constexpr int max_cameras = 16;
	Hash_Map<Camera_Id, Camera, max_cameras> cameras;
	Drawlist drawlists[drawlist_count];
	Staged_Buffer globals;
	Fullscreen_Quad quad;
	int camera_count;
	int frame;

	Shader* ts_shader;
	int ts_shadowmap_binding;
	int ts_depthmap_binding;
	int ts_prev_binding;
	int ts_vert_binding;
	int ts_config_binding;
	int ts_caster_config_binding;
	int ts_casters_binding;
	int ts_globals_binding;
	Sampler_Id ts_sampler;
	Staged_Buffer ts_config, ts_config2;

	Sampler_Id clamped_linear;
	Texture_Id env_cubemap;

	void init(Arena* arena, Device* d, Asset_Arena& assets);
	void destroy(Device* d);
	void set_camera(Camera_Id cam, int drawlist);
	void make_ts_sampler(Device* d);
	void render(
		Device* dev,
		Arena* a,
		Texture_Id hdr_target,
		const Lighting* l
	);
	void temporal_shadows(
		Device* dev,
		Context& ctx,
		const Lighting* l,
		Pipeline_Builder& pb
	);

	void add_model(int drawlist, Model_Instance* m);
	void rem_model(int drawlist, Model_Instance* m);
	void default_model(Model_Instance* m);

	Camera_Id create_camera();
	Camera& get_camera(Camera_Id cam);
	const Camera& get_camera(Camera_Id cam) const;
	void destroy_camera(Camera_Id cam);
	void setcam(int did, Camera_Id cam);

	void update_globals(const Lighting* l, Device* d, Context& ctx);
};

#endif