blob: bf6ccb963c5a944e4958073d0cd79c1292ae311d (
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
|
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
//============================================================
//
// effect.cpp - BGFX shader material to be applied to a mesh
//
//============================================================
#include "effect.h"
bgfx_effect::bgfx_effect(uint64_t state, bgfx::ShaderHandle vertex_shader, bgfx::ShaderHandle fragment_shader, std::vector<bgfx_uniform*> uniforms)
: m_state(state)
{
m_program_handle = bgfx::createProgram(vertex_shader, fragment_shader, false);
for (int i = 0; i < uniforms.size(); i++)
{
m_uniforms[uniforms[i]->name()] = uniforms[i];
}
}
bgfx_effect::~bgfx_effect()
{
for (std::pair<std::string, bgfx_uniform*> uniform : m_uniforms)
{
delete uniform.second;
}
m_uniforms.clear();
bgfx::destroyProgram(m_program_handle);
}
void bgfx_effect::submit(int view)
{
for (std::pair<std::string, bgfx_uniform*> uniform_pair : m_uniforms)
{
(uniform_pair.second)->upload();
}
bgfx::setState(m_state);
bgfx::submit(view, m_program_handle);
}
bgfx_uniform* bgfx_effect::uniform(std::string name)
{
std::map<std::string, bgfx_uniform*>::iterator iter = m_uniforms.find(name);
if (iter != m_uniforms.end())
{
return iter->second;
}
return nullptr;
}
|