-
Notifications
You must be signed in to change notification settings - Fork 47
/
LightInteractions.h
82 lines (64 loc) · 1.99 KB
/
LightInteractions.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
#pragma once
#include <map>
#include <vector>
#include <set>
#include "irender.h"
#include "isurfacerenderer.h"
#include "irenderableobject.h"
#include "irenderview.h"
namespace render
{
class OpenGLState;
class OpenGLShader;
class GLSLDepthFillAlphaProgram;
class GLSLBumpProgram;
/**
* Defines interactions between a light and one or more entity renderables
* It only lives through the course of a single render pass, therefore direct
* references without ref-counting are used.
*
* Objects are grouped by entity, then by shader.
*/
class LightInteractions
{
private:
RendererLight& _light;
IGeometryStore& _store;
AABB _lightBounds;
// A flat list of renderables
using ObjectList = std::vector<std::reference_wrapper<IRenderableObject>>;
// All objects, grouped by material
using ObjectsByMaterial = std::map<OpenGLShader*, ObjectList>;
// object mappings, grouped by entity
std::map<IRenderEntity*, ObjectsByMaterial> _objectsByEntity;
std::size_t _drawCalls;
std::size_t _objectCount;
public:
LightInteractions(RendererLight& light, IGeometryStore& store) :
_light(light),
_store(store),
_lightBounds(light.lightAABB()),
_drawCalls(0),
_objectCount(0)
{}
std::size_t getDrawCalls() const
{
return _drawCalls;
}
std::size_t getObjectCount() const
{
return _objectCount;
}
std::size_t getEntityCount() const
{
return _objectsByEntity.size();
}
void addObject(IRenderableObject& object, IRenderEntity& entity, OpenGLShader* shader);
bool isInView(const IRenderView& view);
void collectSurfaces(const std::set<IRenderEntityPtr>& entities);
void fillDepthBuffer(OpenGLState& state, GLSLDepthFillAlphaProgram& program,
const IRenderView& view, std::size_t renderTime);
void drawInteractions(OpenGLState& state, GLSLBumpProgram& program, RenderStateFlags globalFlagsMask,
const IRenderView& view, std::size_t renderTime);
};
}