light.cpp 1.11 KB
Newer Older
1
2
3
4
5
6
#include "light.h"

// --------------- STDLIB ---------------


// --------------- EXTERN ---------------
7
#include <core/objects/light.h>
8
9
10
11

// --------------- INTERN ---------------
#include <raytrace/data/global_collector.h>

12
namespace glare::raytrace
13
{
14
15
16
17
18
	void LightCollector::clear(const math::Flags &flags)
	{
		if (flags & DirtyFlags::eLight)
		{
			m_lights.clear();
19
		}
20
	}
21

Johannes Braun's avatar
Johannes Braun committed
22
	void LightCollector::collect(const math::Flags &flags, const core::SceneNode &node)
23
24
	{
		if (flags & DirtyFlags::eLight)
25
		{
26
27
			if (const auto& light = node.getComponent<core::LightComponent>()) {
				m_lights.push_back(convert::light(*light));
28
29
			}
		}
30
	}
31

32
33
34
35
	void LightCollector::build(const math::Flags &flags)
	{
		if (flags & DirtyFlags::eLight) {
			m_light_buffer.upload(m_lights, gl::BufferUsage::eDynamicRead);
36
37
		}
	}
38

Johannes Braun's avatar
Johannes Braun committed
39
	void LightCollector::apply(core::Program &program, const std::string& uniform_name)
40
	{
Johannes Braun's avatar
Johannes Braun committed
41
42
		program.uniform(uniform_name + ".lights", m_lights.empty() ? 0 : m_light_buffer.makeResident(gl::Access::eReadOnly));
		program.uniform(uniform_name + ".num_lights", static_cast<int>(m_lights.size()));
43
44
	}
}