forked from graphitemaster/neothyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
r_world.h
161 lines (127 loc) · 3.49 KB
/
r_world.h
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#ifndef R_WORLD_HDR
#define R_WORLD_HDR
#include "kdmap.h"
#include "r_aa.h"
#include "r_ssao.h"
#include "r_skybox.h"
#include "r_billboard.h"
#include "r_particles.h"
#include "r_geom.h"
#include "r_grader.h"
#include "r_model.h"
#include "r_light.h"
#include "r_hoq.h"
#include "u_map.h"
struct world;
namespace r {
struct bboxMethod : method {
bboxMethod();
bool init();
void setWVP(const m::mat4 &wvp);
void setColor(const m::vec3 &color);
private:
GLint m_WVPLocation;
GLint m_colorLocation;
};
inline bboxMethod::bboxMethod()
: m_WVPLocation(-1)
, m_colorLocation(-1)
{
}
struct compositeMethod : method {
compositeMethod();
bool init(const u::vector<const char *> &defines = u::vector<const char *>());
void setWVP(const m::mat4 &wvp);
void setColorTextureUnit(int unit);
void setColorGradingTextureUnit(int unit);
void setPerspective(const m::perspective &perspective);
private:
GLint m_WVPLocation;
GLint m_colorMapLocation;
GLint m_colorGradingMapLocation;
GLint m_screenSizeLocation;
};
inline compositeMethod::compositeMethod()
: m_WVPLocation(-1)
, m_colorMapLocation(-1)
, m_colorGradingMapLocation(-1)
, m_screenSizeLocation(-1)
{
}
struct composite {
composite();
~composite();
bool init(const m::perspective &p, GLuint depth);
void update(const m::perspective &p);
void bindWriting();
GLuint texture() const;
private:
enum {
kBuffer,
kDepth
};
void destroy();
GLuint m_fbo;
GLuint m_texture;
size_t m_width;
size_t m_height;
};
struct renderTextureBatch {
int permute;
size_t start;
size_t count;
size_t index;
material mat; // Rendering material (world and models share this)
};
struct world : geom {
world();
~world();
bool load(const kdMap &map);
bool upload(const m::perspective &p, ::world *map);
void unload(bool destroy = true);
void render(const pipeline &pl, ::world *map);
private:
void occlusionPass(const pipeline &pl, ::world *map);
void geometryPass(const pipeline &pl, ::world *map);
void lightingPass(const pipeline &pl, ::world *map);
void forwardPass(const pipeline &pl, ::world *map);
void compositePass(const pipeline &pl, ::world *map);
void pointLightPass(const pipeline &pl, const ::world *const map);
void spotLightPass(const pipeline &pl, const ::world *const map);
// world shading methods and permutations
geomMethods *m_geomMethods;
u::vector<directionalLightMethod> m_directionalLightMethods;
compositeMethod m_compositeMethod;
pointLightMethod m_pointLightMethod;
spotLightMethod m_spotLightMethod;
ssaoMethod m_ssaoMethod;
bboxMethod m_bboxMethod;
aaMethod m_aaMethod;
defaultMethod m_defaultMethod;
// Other things in the world to render
skybox m_skybox;
quad m_quad;
sphere m_sphere;
bbox m_bbox;
u::map<u::string, model*> m_models;
u::map<u::string, billboard*> m_billboards;
u::vector<r::particleSystem*> m_particleSystems;
// HACK: Testing only
model m_gun;
// The world itself
u::vector<uint32_t> m_indices;
u::vector<kdBinVertex> m_vertices;
u::vector<renderTextureBatch> m_textureBatches;
u::map<u::string, texture2D*> m_textures2D;
aa m_aa;
gBuffer m_gBuffer;
ssao m_ssao;
composite m_final;
grader m_colorGrader;
m::mat4 m_identity;
m::frustum m_frustum;
occlusionQueries m_queries;
bool m_uploaded;
};
}
#endif