nngn
Loading...
Searching...
No Matches
render.h
Go to the documentation of this file.
1
5#ifndef NNGN_RENDER_RENDER_H
6#define NNGN_RENDER_RENDER_H
7
8#include <unordered_set>
9#include <vector>
10
11#include "lua/table.h"
12#include "utils/flags.h"
13
14#include "model.h"
15#include "renderers.h"
16
17namespace nngn {
18
19struct Colliders;
20struct Graphics;
21class Fonts;
22class Grid;
23class Lighting;
24class Map;
25class Textures;
26class Textbox;
27
38class Renderers {
39public:
41 enum Debug : u8 {
42 DEBUG_RENDERERS = 1u << 0,
43 DEBUG_CIRCLE = 1u << 1,
44 DEBUG_BB = 1u << 2,
45 DEBUG_LIGHT = 1u << 3,
46 DEBUG_DEPTH = 1u << 4,
47 DEBUG_ALL = (1u << 5) - 1,
48 };
49 // Initialization
51 void init(
52 Textures *t, const Fonts *f, const Textbox *tb, const Grid *g,
53 const Colliders *c, const Lighting *l, const Map *map);
54 // Configuration
55 auto debug(void) const { return *this->m_debug; }
56 bool perspective(void) const;
57 bool zsprites(void) const { return this->flags.is_set(Flag::ZSPRITES); }
58 auto max_sprites(void) const { return this->sprites.capacity(); }
59 auto max_screen_sprites(void) const;
60 auto max_translucent(void) const { return this->translucent.capacity(); }
61 auto max_cubes(void) const { return this->cubes.capacity(); }
62 auto max_voxels(void) const { return this->voxels.capacity(); }
64 std::size_t n(void) const;
66 std::size_t n_sprites(void) const { return this->sprites.size(); }
68 std::size_t n_screen_sprites(void) const { return this->sprites.size(); }
70 std::size_t n_translucent(void) const { return this->translucent.size(); }
72 std::size_t n_cubes(void) const { return this->cubes.size(); }
74 std::size_t n_voxels(void) const { return this->voxels.size(); }
75 bool selected(const Renderer *p) const;
77 void set_perspective(bool p);
78 void set_zsprites(bool z);
79 bool set_max_sprites(std::size_t n);
80 bool set_max_screen_sprites(std::size_t n);
81 bool set_max_translucent(std::size_t n);
82 bool set_max_cubes(std::size_t n);
83 bool set_max_voxels(std::size_t n);
84 bool set_max_text(std::size_t n);
85 bool set_max_colliders(std::size_t n);
93 // Operations
99 void add_selection(const Renderer *p);
101 bool update(void);
102private:
103 bool update_renderers(
104 bool sprites_updated, bool screen_sprites_updated,
105 bool translucent_updated, bool models_updated, bool cubes_updated,
106 bool voxels_updated);
108 bool sprites_updated, bool screen_sprites_updated, bool cubes_updated,
109 bool voxels_updated);
110 enum Flag : u16 {
111 SPRITES_UPDATED = 1u << 0,
112 SCREEN_SPRITES_UPDATED = 1u << 1,
113 TRANSLUCENT_UPDATED = 1u << 2,
114 CUBES_UPDATED = 1u << 3,
115 VOXELS_UPDATED = 1u << 4,
116 MODELS_UPDATED = 1u << 5,
117 DEBUG_UPDATED = 1u << 6,
118 SELECTION_UPDATED = 1u << 7,
119 PERSPECTIVE = 1u << 8,
120 ZSPRITES = 1u << 9,
121 };
122 Flags<Flag> flags = {};
123 Flags<Debug> m_debug = {};
124 Textures *textures = nullptr;
125 Graphics *graphics = nullptr;
126 const Fonts *fonts = nullptr;
127 const Textbox *textbox = nullptr;
128 const Grid *grid = nullptr;
129 const Colliders *colliders = nullptr;
130 const Lighting *lighting = nullptr;
131 const Map *map = nullptr;
132 std::vector<SpriteRenderer> sprites = {};
133 std::vector<SpriteRenderer> screen_sprites = {};
134 std::vector<SpriteRenderer> translucent = {};
135 std::vector<CubeRenderer> cubes = {};
136 std::vector<VoxelRenderer> voxels = {};
137 std::vector<ModelRenderer> models = {};
138 std::unordered_set<const Renderer*> selections = {};
139 u32
141 sprite_vbo = {}, sprite_ebo = {},
146 cube_vbo = {}, cube_ebo = {},
148 voxel_vbo = {}, voxel_ebo = {},
150 text_vbo = {}, text_ebo = {},
151 textbox_vbo = {}, textbox_ebo = {},
152 selection_vbo = {}, selection_ebo = {},
153 aabb_vbo = {}, aabb_ebo = {},
155 bb_vbo = {}, bb_ebo = {},
156 bb_circle_vbo = {}, bb_circle_ebo = {},
157 sphere_vbo = {}, sphere_ebo = {},
158 lights_vbo = {}, lights_ebo = {},
159 range_vbo = {}, range_ebo = {},
160 depth_vbo = {}, depth_ebo = {},
162};
163
164inline bool Renderers::perspective(void) const {
165 return this->flags.is_set(Flag::PERSPECTIVE);
166}
167
168inline auto Renderers::max_screen_sprites(void) const {
169 return this->screen_sprites.capacity();
170}
171
172inline bool Renderers::selected(const Renderer *p) const {
173 return this->selections.find(p) != cend(this->selections);
174}
175
176}
177
178#endif
Definition: font.h:30
Definition: grid.h:11
Definition: light.h:53
Definition: map.h:17
u32 voxel_vbo
Definition: render.h:143
bool set_max_cubes(std::size_t n)
u32 translucent_ebo
Definition: render.h:136
auto max_screen_sprites(void) const
void init(Textures *t, const Fonts *f, const Textbox *tb, const Grid *g, const Colliders *c, const Lighting *l, const Map *map)
Partially initializes this system.
u32 screen_sprite_debug_ebo
Definition: render.h:140
u32 model_vbo
Definition: render.h:145
bool update_debug(bool sprites_updated, bool screen_sprites_updated, bool cubes_updated, bool voxels_updated)
Renderer * load(nngn::lua::table_view t)
Adds a new renderer object according to a description in a Lua table.
u32 cube_debug_vbo
Definition: render.h:142
u32 sprite_vbo
Definition: render.h:137
u32 aabb_vbo
Definition: render.h:148
bool set_max_sprites(std::size_t n)
u32 selection_vbo
Definition: render.h:147
const Textbox * textbox
Definition: render.h:124
Debug
Enabled debugging features.
Definition: render.h:41
@ DEBUG_RENDERERS
Definition: render.h:41
@ DEBUG_LIGHT
Definition: render.h:44
@ DEBUG_BB
Definition: render.h:43
@ DEBUG_CIRCLE
Definition: render.h:42
@ DEBUG_DEPTH
Definition: render.h:45
@ DEBUG_ALL
Definition: render.h:46
u32 sphere_ebo
Definition: render.h:152
u32 selection_ebo
Definition: render.h:147
bool set_max_text(std::size_t n)
const Lighting * lighting
Definition: render.h:127
u32 textbox_vbo
Definition: render.h:146
u32 lights_vbo
Definition: render.h:153
void remove(Renderer *p)
Removes a renderer.
Flags< Debug > m_debug
Definition: render.h:120
void set_perspective(bool p)
auto max_cubes(void) const
Definition: render.h:61
std::size_t n(void) const
Total number of active renderers.
std::size_t n_translucent(void) const
Number of active translucent sprite renderers.
Definition: render.h:70
auto debug(void) const
Definition: render.h:55
u32 sprite_debug_ebo
Definition: render.h:138
Graphics * graphics
Definition: render.h:122
std::vector< ModelRenderer > models
Definition: render.h:137
std::size_t n_cubes(void) const
Number of active cube renderers.
Definition: render.h:72
auto max_sprites(void) const
Definition: render.h:58
void set_debug(Debug d)
u32 textbox_ebo
Definition: render.h:146
bool set_max_translucent(std::size_t n)
u32 screen_sprite_debug_vbo
Definition: render.h:140
bool set_max_screen_sprites(std::size_t n)
u32 sphere_vbo
Definition: render.h:152
void remove_selection(const Renderer *p)
const Fonts * fonts
Definition: render.h:123
bool update_renderers(bool sprites_updated, bool screen_sprites_updated, bool translucent_updated, bool cubes_updated, bool voxels_updated)
Definition: render.cpp:745
u32 lights_ebo
Definition: render.h:153
u32 bb_circle_vbo
Definition: render.h:151
bool set_max_colliders(std::size_t n)
std::unordered_set< const Renderer * > selections
Definition: render.h:134
bool selected(const Renderer *p) const
u32 cube_debug_ebo
Definition: render.h:142
u32 aabb_ebo
Definition: render.h:148
std::vector< CubeRenderer > cubes
Definition: render.h:132
bool update(void)
u32 screen_sprite_vbo
Definition: render.h:139
u32 screen_sprite_ebo
Definition: render.h:139
bool perspective(void) const
u32 translucent_vbo
Definition: render.h:136
bool set_max_voxels(std::size_t n)
u32 voxel_debug_ebo
Definition: render.h:144
u32 depth_cube_ebo
Definition: render.h:156
auto max_translucent(void) const
Definition: render.h:60
u32 text_ebo
Definition: render.h:145
u32 depth_vbo
Definition: render.h:155
u32 depth_ebo
Definition: render.h:155
u32 aabb_circle_ebo
Definition: render.h:149
u32 text_vbo
Definition: render.h:145
void set_zsprites(bool z)
auto max_voxels(void) const
Definition: render.h:62
u32 bb_circle_ebo
Definition: render.h:151
bool zsprites(void) const
Definition: render.h:57
std::size_t n_screen_sprites(void) const
Number of active screen sprite renderers.
Definition: render.h:68
const Colliders * colliders
Definition: render.h:126
u32 sprite_ebo
Definition: render.h:137
u32 range_ebo
Definition: render.h:154
u32 depth_cube_vbo
Definition: render.h:156
void add_selection(const Renderer *p)
Processes changed renderers/configuration and updates graphics.
std::vector< SpriteRenderer > translucent
Definition: render.h:131
const Grid * grid
Definition: render.h:125
bool set_graphics(Graphics *g)
Associates this system with a graphics back end.
u32 voxel_ebo
Definition: render.h:143
u32 bb_ebo
Definition: render.h:150
std::size_t n_sprites(void) const
Number of active sprite renderers.
Definition: render.h:66
Flags< Flag > flags
Definition: render.h:119
Textures * textures
Definition: render.h:121
std::vector< VoxelRenderer > voxels
Definition: render.h:133
std::vector< SpriteRenderer > sprites
Definition: render.h:129
u32 sprite_debug_vbo
Definition: render.h:138
u32 voxel_debug_vbo
Definition: render.h:144
std::vector< SpriteRenderer > screen_sprites
Definition: render.h:130
u32 bb_vbo
Definition: render.h:150
Flag
Definition: render.h:110
@ SELECTION_UPDATED
Definition: render.h:115
@ ZSPRITES
Definition: render.h:117
@ PERSPECTIVE
Definition: render.h:116
@ CUBES_UPDATED
Definition: render.h:112
@ VOXELS_UPDATED
Definition: render.h:113
@ TRANSLUCENT_UPDATED
Definition: render.h:111
@ SCREEN_SPRITES_UPDATED
Definition: render.h:110
@ DEBUG_UPDATED
Definition: render.h:114
@ MODELS_UPDATED
Definition: render.h:116
@ SPRITES_UPDATED
Definition: render.h:109
u32 aabb_circle_vbo
Definition: render.h:149
u32 cube_vbo
Definition: render.h:141
const Map * map
Definition: render.h:128
u32 range_vbo
Definition: render.h:154
u32 model_ebo
Definition: render.h:145
u32 cube_ebo
Definition: render.h:141
std::size_t n_voxels(void) const
Number of active voxel renderers.
Definition: render.h:74
Definition: textbox.h:18
Texture manager, loads and caches image data from files/buffers.
Definition: texture.h:34
g
Definition: gamma.lua:7
c
Definition: gamma.lua:11
l
Definition: light.lua:23
z
Definition: input.lua:25
p
Definition: input.lua:29
function f()) end
Definition: audio.cpp:7
std::uint32_t u32
Definition: def.h:14
std::uint16_t u16
Definition: def.h:13
std::uint8_t u8
Definition: def.h:12
Definition: collision.h:72
Wrapper for an unsigned integral representing flags.
Definition: flags.h:18
constexpr bool is_set(AT a) const
Definition: flags.h:26
Definition: graphics.h:138
Definition: renderers.h:15
Non-owning reference to a table on the stack.
Definition: table.h:166