forked from hugoam/two
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GfxSystem.h
160 lines (119 loc) · 4.25 KB
/
GfxSystem.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
// Copyright (c) 2019 Hugo Amiard [email protected]
// This software is provided 'as-is' under the zlib License, see the LICENSE.txt file.
// This notice and the license may not be removed or altered from any source distribution.
#pragma once
#ifndef TWO_MODULES
#include <stl/vector.h>
#include <stl/string.h>
#include <stl/function.h>
#include <stl/span.h>
#include <type/Unique.h>
#endif
#include <geom/Primitive.h>
#include <geom/Symbol.h>
#include <gfx/Forward.h>
#include <gfx/Renderer.h>
#ifndef TWO_BGFX_EXPORT
#define TWO_BGFX_EXPORT TWO_GFX_EXPORT
#endif
#include <bgfx/BgfxSystem.h>
namespace bx
{
struct FileReaderI;
struct FileWriterI;
}
namespace bgfx
{
struct Encoder;
}
namespace two
{
class Vg;
export_ class refl_ TWO_GFX_EXPORT GfxWindow : public BgfxContext
{
public:
GfxWindow(GfxSystem& gfx, const string& name, const uvec2& size, bool fullscreen, bool main = true);
~GfxWindow();
virtual void reset_fb(const uvec2& size) override;
GfxSystem& m_gfx;
Vg* m_vg = nullptr;
object<RenderTarget> m_target;
uint16_t m_vg_handle = UINT16_MAX;
using ResetVg = uint16_t(*)(GfxWindow&, Vg&); ResetVg m_reset_vg;
vector<Viewport*> m_viewports;
};
template <class T_Asset>
class TPool;
template <class T_Asset>
class AssetStore;
export_ struct LocatedFile
{
LocatedFile() {}
LocatedFile(string location, string name, string extension, size_t extension_index)
: m_located(true), m_location(location), m_name(name), m_extension(extension), m_extension_index(extension_index)
{}
bool m_located = false;
string m_location;
string m_name;
string m_extension;
size_t m_extension_index = 0;
string path(bool ext) { return m_location + "/" + m_name + (ext ? m_extension : ""); }
explicit operator bool() { return m_located; }
};
export_ class refl_ TWO_GFX_EXPORT GfxSystem : public BgfxSystem
{
public:
constr_ GfxSystem(const string& resource_path);
~GfxSystem();
JobSystem* m_job_system = nullptr;
bgfx::Encoder* m_encoders[8] = {};
size_t m_num_encoders = 0;
attr_ Renderer m_renderer;
attr_ BlockCopy* m_copy = nullptr;
attr_ BlockFilter* m_filter = nullptr;
attr_ bool m_flip_y = false;
attr_ RenderFrame m_render_frame;
meth_ RenderTarget& main_target();
virtual bool begin_frame() final;
virtual void end_frame() final;
void render_contexts();
void init(GfxWindow& context);
using PipelineDecl = void(*)(GfxSystem& gfx, Renderer& pipeline, bool deferred);
void init_pipeline(PipelineDecl pipeline);
meth_ void default_pipeline();
meth_ void add_resource_path(const string& path, bool relative = true);
void set_renderer(Shading shading, const RenderFunc& renderer);
RenderFunc renderer(Shading shading);
void render(Shading shading, RenderFunc renderer, RenderTarget& target, Viewport& viewport);
RenderFrame render_frame();
GfxWindow& context(size_t index = 0);
bx::FileReaderI& file_reader();
bx::FileWriterI& file_writer();
LocatedFile locate_file(const string& file);
LocatedFile locate_file(const string& file, span<string> extensions);
TPool<Mesh>& meshes();
TPool<Rig>& rigs();
TPool<Animation>& animations();
attr_ AssetStore<Texture>& textures();
attr_ AssetStore<Program>& programs();
attr_ AssetStore<Material>& materials();
attr_ AssetStore<Model>& models();
attr_ AssetStore<Flow>& flows();
attr_ AssetStore<Prefab>& prefabs();
void add_importer(ModelFormat format, Importer& importer);
Importer* importer(ModelFormat format);
Texture& default_texture(TextureHint hint);
meth_ Material& debug_material();
meth_ Model& create_model(const string& name);
meth_ Model& create_model_geo(const string& name, const MeshPacker& geometry, bool readback = false, bool optimize = false);
meth_ Model& create_model_gpu(const string& name, const GpuMesh& gpu_mesh, bool readback = false, bool optimize = false);
meth_ Material& fetch_material(const string& name, const string& shader, bool builtin = true);
meth_ Material& fetch_image256_material(const Image256& image);
meth_ Model& shape(const Shape& shape, const Symbol& symbol = {}, DrawMode draw_mode = PLAIN);
meth_ Material& symbol_material(const Symbol& symbol, DrawMode draw_mode = PLAIN);
void create_debug_materials();
public:
struct Impl;
unique<Impl> m_impl;
};
}