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
|
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
//============================================================
//
// targetmanager.cpp - BGFX render target manager
//
// Maintains a string-to-entry mapping for any registered
// render targets.
//
//============================================================
#include <bgfx/bgfx.h>
#include <vector>
#include "targetmanager.h"
#include "target.h"
target_manager::~target_manager()
{
for (std::pair<std::string, bgfx_target*> target : m_targets)
{
delete target.second;
}
m_targets.clear();
}
bgfx_target* target_manager::create_target(std::string name, bgfx::TextureFormat::Enum format, uint32_t width, uint32_t height, bool filter)
{
bgfx_target* target = new bgfx_target(name, format, width, height, filter);
m_targets[name] = target;
m_textures.add_texture(name, target);
return target;
}
bgfx_target* target_manager::create_target(std::string name, void *handle, uint32_t width, uint32_t height)
{
bgfx_target* target = new bgfx_target(name, width, height, TARGET_STYLE_CUSTOM, handle);
m_targets[name] = target;
m_textures.add_texture(name, target);
return target;
}
bgfx_target* target_manager::target(std::string name)
{
std::map<std::string, bgfx_target*>::iterator iter = m_targets.find(name);
if (iter != m_targets.end())
{
return iter->second;
}
return nullptr;
}
void target_manager::update_guest_targets(uint16_t width, uint16_t height)
{
if (width != m_guest_width || height != m_guest_height)
{
m_guest_width = width;
m_guest_height = height;
std::vector<bgfx_target*> to_resize;
for (std::pair<std::string, bgfx_target*> target : m_targets)
{
if ((target.second)->style() == TARGET_STYLE_GUEST)
{
to_resize.push_back(target.second);
}
}
for (bgfx_target* target : to_resize)
{
m_targets[target->name()] = new bgfx_target(target->name(), target->format(), width, height, TARGET_STYLE_GUEST, target->filter());
delete target;
}
}
}
|