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 "renderers.h"
15
16namespace nngn {
17
18struct Colliders;
19struct Graphics;
20class Fonts;
21class Grid;
22class Lighting;
23class Map;
24class Textures;
25class Textbox;
26
37class Renderers {
38public:
40 enum Debug : u8 {
41 DEBUG_RENDERERS = 1u << 0,
42 DEBUG_CIRCLE = 1u << 1,
43 DEBUG_BB = 1u << 2,
44 DEBUG_LIGHT = 1u << 3,
45 DEBUG_DEPTH = 1u << 4,
46 DEBUG_ALL = (1u << 5) - 1,
47 };
48 // Initialization
50 void init(
51 Textures *t, const Fonts *f, const Textbox *tb, const Grid *g,
52 const Colliders *c, const Lighting *l, const Map *map);
53 // Configuration
54 auto debug(void) const { return *this->m_debug; }
55 bool perspective(void) const;
56 bool zsprites(void) const { return this->flags.is_set(Flag::ZSPRITES); }
57 auto max_sprites(void) const { return this->sprites.capacity(); }
58 auto max_screen_sprites(void) const;
59 auto max_translucent(void) const { return this->translucent.capacity(); }
60 auto max_cubes(void) const { return this->cubes.capacity(); }
61 auto max_voxels(void) const { return this->voxels.capacity(); }
63 std::size_t n(void) const;
65 std::size_t n_sprites(void) const { return this->sprites.size(); }
67 std::size_t n_screen_sprites(void) const { return this->sprites.size(); }
69 std::size_t n_translucent(void) const { return this->translucent.size(); }
71 std::size_t n_cubes(void) const { return this->cubes.size(); }
73 std::size_t n_voxels(void) const { return this->voxels.size(); }
74 bool selected(const Renderer *p) const;
75 void set_debug(Debug d);
76 void set_perspective(bool p);
77 void set_zsprites(bool z);
78 bool set_max_sprites(std::size_t n);
79 bool set_max_screen_sprites(std::size_t n);
80 bool set_max_translucent(std::size_t n);
81 bool set_max_cubes(std::size_t n);
82 bool set_max_voxels(std::size_t n);
83 bool set_max_text(std::size_t n);
84 bool set_max_colliders(std::size_t n);
91 bool set_graphics(Graphics *g);
92 // Operations
96 void remove(Renderer *p);
98 void add_selection(const Renderer *p);
99 void remove_selection(const Renderer *p);
100 bool update(void);
101private:
102 bool update_renderers(
103 bool sprites_updated, bool screen_sprites_updated,
104 bool translucent_updated, bool cubes_updated, bool voxels_updated);
105 bool update_debug(
106 bool sprites_updated, bool screen_sprites_updated, bool cubes_updated,
107 bool voxels_updated);
108 enum Flag : u16 {
112 CUBES_UPDATED = 1u << 3,
113 VOXELS_UPDATED = 1u << 4,
114 DEBUG_UPDATED = 1u << 5,
116 PERSPECTIVE = 1u << 7,
117 ZSPRITES = 1u << 8,
118 };
121 Textures *textures = nullptr;
122 Graphics *graphics = nullptr;
123 const Fonts *fonts = nullptr;
124 const Textbox *textbox = nullptr;
125 const Grid *grid = nullptr;
126 const Colliders *colliders = nullptr;
127 const Lighting *lighting = nullptr;
128 const Map *map = nullptr;
129 std::vector<SpriteRenderer> sprites = {};
130 std::vector<SpriteRenderer> screen_sprites = {};
131 std::vector<SpriteRenderer> translucent = {};
132 std::vector<CubeRenderer> cubes = {};
133 std::vector<VoxelRenderer> voxels = {};
134 std::unordered_set<const Renderer*> selections = {};
135 u32
141 cube_vbo = {}, cube_ebo = {},
145 text_vbo = {}, text_ebo = {},
148 aabb_vbo = {}, aabb_ebo = {},
150 bb_vbo = {}, bb_ebo = {},
157};
158
159inline bool Renderers::perspective(void) const {
160 return this->flags.is_set(Flag::PERSPECTIVE);
161}
162
163inline auto Renderers::max_screen_sprites(void) const {
164 return this->screen_sprites.capacity();
165}
166
167inline bool Renderers::selected(const Renderer *p) const {
168 return this->selections.find(p) != cend(this->selections);
169}
170
171}
172
173#endif
Definition font.h:30
Definition grid.h:11
Definition light.h:53
Definition map.h:17
Rendering subsystem.
Definition render.h:37
u32 voxel_vbo
Definition render.h:143
bool set_max_cubes(std::size_t n)
Definition render.cpp:174
std::vector< VoxelRenderer > voxels
Definition render.h:133
std::vector< SpriteRenderer > screen_sprites
Definition render.h:130
std::unordered_set< const Renderer * > selections
Definition render.h:134
u32 translucent_ebo
Definition render.h:136
auto max_screen_sprites(void) const
Definition render.h:163
const Lighting * lighting
Definition render.h:127
u32 screen_sprite_debug_ebo
Definition render.h:140
bool update_debug(bool sprites_updated, bool screen_sprites_updated, bool cubes_updated, bool voxels_updated)
Definition render.cpp:911
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)
Definition render.cpp:152
u32 selection_vbo
Definition render.h:147
Debug
Enabled debugging features.
Definition render.h:40
@ DEBUG_RENDERERS
Definition render.h:41
@ DEBUG_DEPTH
Definition render.h:45
@ DEBUG_ALL
Definition render.h:46
@ DEBUG_LIGHT
Definition render.h:44
@ DEBUG_BB
Definition render.h:43
@ DEBUG_CIRCLE
Definition render.h:42
Flags< Debug > m_debug
Definition render.h:120
u32 sphere_ebo
Definition render.h:152
u32 selection_ebo
Definition render.h:147
bool set_max_text(std::size_t n)
Definition render.cpp:194
const Map * map
Definition render.h:128
u32 textbox_vbo
Definition render.h:146
u32 lights_vbo
Definition render.h:153
void remove(Renderer *p)
Removes a renderer.
Definition render.cpp:682
const Fonts * fonts
Definition render.h:123
const Textbox * textbox
Definition render.h:124
auto max_cubes(void) const
Definition render.h:60
std::size_t n(void) const
Total number of active renderers.
Definition render.cpp:144
std::size_t n_translucent(void) const
Number of active translucent sprite renderers.
Definition render.h:69
auto debug(void) const
Definition render.h:54
u32 sprite_debug_ebo
Definition render.h:138
std::vector< SpriteRenderer > sprites
Definition render.h:129
std::size_t n_cubes(void) const
Number of active cube renderers.
Definition render.h:71
Textures * textures
Definition render.h:121
auto max_sprites(void) const
Definition render.h:57
void set_debug(Debug d)
Definition render.cpp:218
u32 textbox_ebo
Definition render.h:146
bool set_max_translucent(std::size_t n)
Definition render.cpp:166
u32 screen_sprite_debug_vbo
Definition render.h:140
std::vector< SpriteRenderer > translucent
Definition render.h:131
bool set_max_screen_sprites(std::size_t n)
Definition render.cpp:159
u32 sphere_vbo
Definition render.h:152
void remove_selection(const Renderer *p)
Definition render.cpp:717
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
Flags< Flag > flags
Definition render.h:119
bool selected(const Renderer *p) const
Definition render.h:167
u32 cube_debug_ebo
Definition render.h:142
u32 aabb_ebo
Definition render.h:148
bool update(void)
Definition render.cpp:722
u32 screen_sprite_vbo
Definition render.h:139
u32 screen_sprite_ebo
Definition render.h:139
bool perspective(void) const
Definition render.h:159
u32 translucent_vbo
Definition render.h:136
bool set_max_voxels(std::size_t n)
Definition render.cpp:184
u32 voxel_debug_ebo
Definition render.h:144
u32 depth_cube_ebo
Definition render.h:156
auto max_translucent(void) const
Definition render.h:59
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)
Definition render.cpp:235
const Grid * grid
Definition render.h:125
auto max_voxels(void) const
Definition render.h:61
u32 bb_circle_ebo
Definition render.h:151
bool zsprites(void) const
Definition render.h:56
std::size_t n_screen_sprites(void) const
Number of active screen sprite renderers.
Definition render.h:67
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.
Definition render.cpp:712
std::vector< CubeRenderer > cubes
Definition render.h:132
bool set_graphics(Graphics *g)
Associates this system with a graphics back end.
Definition render.cpp:246
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:65
Graphics * graphics
Definition render.h:122
u32 sprite_debug_vbo
Definition render.h:138
u32 voxel_debug_vbo
Definition render.h:144
u32 bb_vbo
Definition render.h:150
Flag
Definition render.h:108
@ DEBUG_UPDATED
Definition render.h:114
@ ZSPRITES
Definition render.h:117
@ SCREEN_SPRITES_UPDATED
Definition render.h:110
@ SELECTION_UPDATED
Definition render.h:115
@ SPRITES_UPDATED
Definition render.h:109
@ VOXELS_UPDATED
Definition render.h:113
@ CUBES_UPDATED
Definition render.h:112
@ PERSPECTIVE
Definition render.h:116
@ TRANSLUCENT_UPDATED
Definition render.h:111
u32 aabb_circle_vbo
Definition render.h:149
const Colliders * colliders
Definition render.h:126
u32 cube_vbo
Definition render.h:141
u32 range_vbo
Definition render.h:154
u32 cube_ebo
Definition render.h:141
std::size_t n_voxels(void) const
Number of active voxel renderers.
Definition render.h:73
Definition textbox.h:18
Texture manager, loads and caches image data from files/buffers.
Definition texture.h:34
set_max_colliders
Definition collision.lua:14
local c
Definition gamma.lua:11
local g
Definition gamma.lua:7
init
Definition img_common.lua:34
local l
Definition light.lua:23
Definition audio.cpp:7
std::uint16_t u16
Definition def.h:13
std::uint32_t u32
Definition def.h:14
std::uint8_t u8
Definition def.h:12
set_perspective
Definition camera.lua:51
load
Definition entity.lua:7
local function f()) end
Definition collision.h:72
Wrapper for a small unsigned integral representing flags.
Definition flags.h:18
constexpr bool is_set(AT a) const
Definition flags.h:45
Definition graphics.h:138
Definition renderers.h:15
Non-owning reference to a table on the stack.
Definition table.h:166
Operations on table values.