1#ifndef NNGN_RENDER_GEN_H
2#define NNGN_RENDER_GEN_H
32 u32 tex,
const std::array<vec4, 6> &uv);
50 const Font &
font,
const Text &txt,
bool mono,
float left,
51 vec2 *pos_p,
float *color_p,
u64 *i_p,
u64 *n_visible_p);
61 static constexpr std::array<vec2, 2>
67 constexpr std::size_t n_verts = 4, log2 = std::countr_zero(n_verts);
68 auto i =
static_cast<u32>(i_64) << log2;
69 for(
const auto e =
i + (
n << log2);
i !=
e;
i += n_verts) {
70 *p++ =
i ; *(p++) =
i + 1; *(p++) =
i + 2;
71 *p++ =
i + 2; *(p++) =
i + 1; *(p++) =
i + 3;
79 *p++ = {{
bl, z}, norm, color};
80 *p++ = {{
tr.
x,
bl.
y, z}, norm, color};
81 *p++ = {{
bl.
x,
tr.
y, z}, norm, color};
82 *p++ = {{
tr, z}, norm, color};
90 const auto tex_f =
static_cast<float>(tex);
92 *p++ = {{
bl, z}, norm, {uv0.
x, uv0.
y, tex_f}};
93 *p++ = {{
tr.
x,
bl.
y, z}, norm, {uv1.
x, uv0.
y, tex_f}};
94 *p++ = {{
bl.
x,
tr.
y, z}, norm, {uv0.
x, uv1.
y, tex_f}};
95 *p++ = {{
tr, z}, norm, {uv1.
x, uv1.
y, tex_f}};
103 const auto tex_f =
static_cast<float>(tex);
105 *p++ = {{
bl.
x, y,
bl.
y}, norm, {uv0.
x, uv0.
y, tex_f}};
106 *p++ = {{
tr.
x, y,
bl.
y}, norm, {uv1.
x, uv0.
y, tex_f}};
107 *p++ = {{
bl.
x, y,
tr.
y}, norm, {uv0.
x, uv1.
y, tex_f}};
108 *p++ = {{
tr.
x, y,
tr.
y}, norm, {uv1.
x, uv1.
y, tex_f}};
116 const auto tex_f =
static_cast<float>(tex);
118 *p++ = {{
bl.
x,
bl.
y, z}, norm, {uv0.
x, uv0.
y, tex_f}};
119 *p++ = {{
tr.
x,
bl.
y, z}, norm, {uv1.
x, uv0.
y, tex_f}};
120 *p++ = {{
bl.
x,
tr.
y, z +
tr.
y -
bl.
y}, norm, {uv0.
x, uv1.
y, tex_f}};
121 *p++ = {{
tr.
x,
tr.
y, z +
tr.
y -
bl.
y}, norm, {uv1.
x, uv1.
y, tex_f}};
126 const auto s = size / 2.0f;
129 *p++ = {
bl , { 0, 0, -1}, color};
130 *p++ = {{
bl.
x,
tr.
y,
bl.z}, { 0, 0, -1}, color};
131 *p++ = {{
tr.
x,
bl.
y,
bl.z}, { 0, 0, -1}, color};
132 *p++ = {{
tr.
x,
tr.
y,
bl.z}, { 0, 0, -1}, color};
133 *p++ = {{
bl.
x,
bl.
y,
tr.z}, { 0, 0, 1}, color};
134 *p++ = {{
tr.
x,
bl.
y,
tr.z}, { 0, 0, 1}, color};
135 *p++ = {{
bl.
x,
tr.
y,
tr.z}, { 0, 0, 1}, color};
136 *p++ = {
tr , { 0, 0, 1}, color};
137 *p++ = {
bl , {-1, 0, 0}, color};
138 *p++ = {{
bl.
x,
bl.
y,
tr.z}, {-1, 0, 0}, color};
139 *p++ = {{
bl.
x,
tr.
y,
bl.z}, {-1, 0, 0}, color};
140 *p++ = {{
bl.
x,
tr.
y,
tr.z}, {-1, 0, 0}, color};
141 *p++ = {{
tr.
x,
bl.
y,
bl.z}, { 1, 0, 0}, color};
142 *p++ = {{
tr.
x,
tr.
y,
bl.z}, { 1, 0, 0}, color};
143 *p++ = {{
tr.
x,
bl.
y,
tr.z}, { 1, 0, 0}, color};
144 *p++ = {
tr , { 1, 0, 0}, color};
145 *p++ = {
bl , { 0, -1, 0}, color};
146 *p++ = {{
tr.
x,
bl.
y,
bl.z}, { 0, -1, 0}, color};
147 *p++ = {{
bl.
x,
bl.
y,
tr.z}, { 0, -1, 0}, color};
148 *p++ = {{
tr.
x,
bl.
y,
tr.z}, { 0, -1, 0}, color};
149 *p++ = {{
bl.
x,
tr.
y,
bl.z}, { 0, 1, 0}, color};
150 *p++ = {{
bl.
x,
tr.
y,
tr.z}, { 0, 1, 0}, color};
151 *p++ = {{
tr.
x,
tr.
y,
bl.z}, { 0, 1, 0}, color};
152 *p++ = {
tr , { 0, 1, 0}, color};
158 u32 tex,
const std::array<vec4, 6> &uv
160 const auto ftex =
static_cast<float>(tex);
161 const auto s = size / 2.0f;
164 *((*p)++) = {
bl , { 0, 0, -1}, {uv_.
xy(), ftex}};
165 *((*p)++) = {{
bl.
x,
tr.
y,
bl.z}, { 0, 0, -1}, {uv_.xw(), ftex}};
166 *((*p)++) = {{
tr.
x,
bl.
y,
bl.z}, { 0, 0, -1}, {uv_.zy(), ftex}};
167 *((*p)++) = {{
tr.
x,
tr.
y,
bl.z}, { 0, 0, -1}, {uv_.zw(), ftex}};
169 *((*p)++) = {{
bl.
x,
bl.
y,
tr.z}, { 0, 0, 1}, {uv_.
xy(), ftex}};
170 *((*p)++) = {{
tr.
x,
bl.
y,
tr.z}, { 0, 0, 1}, {uv_.zy(), ftex}};
171 *((*p)++) = {{
bl.
x,
tr.
y,
tr.z}, { 0, 0, 1}, {uv_.xw(), ftex}};
172 *((*p)++) = {
tr , { 0, 0, 1}, {uv_.zw(), ftex}};
174 *((*p)++) = {
bl , {-1, 0, 0}, {uv_.
xy(), ftex}};
175 *((*p)++) = {{
bl.
x,
bl.
y,
tr.z}, {-1, 0, 0}, {uv_.xw(), ftex}};
176 *((*p)++) = {{
bl.
x,
tr.
y,
bl.z}, {-1, 0, 0}, {uv_.zy(), ftex}};
177 *((*p)++) = {{
bl.
x,
tr.
y,
tr.z}, {-1, 0, 0}, {uv_.zw(), ftex}};
179 *((*p)++) = {{
tr.
x,
bl.
y,
bl.z}, { 1, 0, 0}, {uv_.
xy(), ftex}};
180 *((*p)++) = {{
tr.
x,
tr.
y,
bl.z}, { 1, 0, 0}, {uv_.zy(), ftex}};
181 *((*p)++) = {{
tr.
x,
bl.
y,
tr.z}, { 1, 0, 0}, {uv_.xw(), ftex}};
182 *((*p)++) = {
tr , { 1, 0, 0}, {uv_.zw(), ftex}};
184 *((*p)++) = {
bl , { 0, -1, 0}, {uv_.
xy(), ftex}};
185 *((*p)++) = {{
tr.
x,
bl.
y,
bl.z}, { 0, -1, 0}, {uv_.zy(), ftex}};
186 *((*p)++) = {{
bl.
x,
bl.
y,
tr.z}, { 0, -1, 0}, {uv_.xw(), ftex}};
187 *((*p)++) = {{
tr.
x,
bl.
y,
tr.z}, { 0, -1, 0}, {uv_.zw(), ftex}};
189 *((*p)++) = {{
bl.
x,
tr.
y,
bl.z}, { 0, 1, 0}, {uv_.
xy(), ftex}};
190 *((*p)++) = {{
bl.
x,
tr.
y,
tr.z}, { 0, 1, 0}, {uv_.xw(), ftex}};
191 *((*p)++) = {{
tr.
x,
tr.
y,
bl.z}, { 0, 1, 0}, {uv_.zy(), ftex}};
192 *((*p)++) = {
tr , { 0, 1, 0}, {uv_.zw(), ftex}};
197 | (
static_cast<u32>(
g) << 8)
198 |
static_cast<u32>(b));
203 static_assert(
sizeof(ret) ==
sizeof(
c));
204 std::memcpy(&ret, &
c,
sizeof(ret));
211 const auto s = x->
size / 2.0f;
214 {0, 0, 1}, x->
tex, x->
uv[0], x->
uv[1]);
221 const auto s = x->
size / 2.0f;
224 {0, -nl, nl}, x->
tex, x->
uv[0], x->
uv[1]);
229 const auto s = x->
size / 2.0f;
239 const auto s = x->
size / 2.0f;
242 {0, 0, 1}, x->
tex, x->
uv[0], x->
uv[1]);
270 constexpr vec3 norm = {0, 0, 1};
272 auto s = x->
size / 2.0f;
294 const Font &
font,
const Text &txt,
bool mono,
float left,
295 vec2 *pos_p,
float *color_p,
u64 *i_p,
u64 *n_visible_p
298 auto color = *color_p;
299 auto i =
static_cast<std::size_t
>(*i_p);
300 auto n_visible = *n_visible_p;
301 const auto font_size =
static_cast<float>(
font.size);
304 const auto c =
static_cast<unsigned char>(txt.
str[
i++]);
306 case '\n':
pos = {left,
pos.y - font_size - txt.
spacing};
continue;
312 const auto fc =
font.chars[
static_cast<std::size_t
>(
c)];
313 const auto size =
static_cast<vec2>(fc.size);
314 const auto cpos =
pos
315 +
vec2(font_size / 2, txt.
size.
y - font_size / 2)
316 +
static_cast<vec2>(fc.bearing);
318 p, cpos, cpos + size, color,
319 {0, 0, 1},
static_cast<u32>(
c),
320 {0, size.y / font_size}, {size.x / font_size, 0});
321 pos.
x += mono ? font_size : fc.advance;
326 *i_p =
static_cast<u64>(
i);
327 *n_visible_p = n_visible;
331 constexpr vec3 norm = {0, 0, 1};
332 constexpr vec3 title_color = {0, 0, 1};
333 constexpr vec3 box_color = {1, 1, 1};
340 const auto s = x.
size / 2.0f;
356 constexpr vec3 norm = {0, 0, 1};
357 std::array<vec2, 4> rot = {{
363 const auto pos = x.
bl + (x.
tr - x.
bl) / 2.0f;
373 *p++ = {{rot[0], 0}, norm, color};
374 *p++ = {{rot[1], 0}, norm, color};
375 *p++ = {{rot[2], 0}, norm, color};
376 *p++ = {{rot[3], 0}, norm, color};
static constexpr T sq2_2(void)
Definition math.h:178
vec2 str_tr
Definition textbox.h:37
vec2 title_bl
Definition textbox.h:36
vec2 str_bl
Definition textbox.h:37
vec2 title_tr
Definition textbox.h:36
local textbox
Definition demo0.lua:2
local light
Definition demo1.lua:3
for i
Definition font.lua:5
local n
Definition dump_lights.lua:5
local c
Definition gamma.lua:11
local r
Definition gamma.lua:7
local g
Definition gamma.lua:7
pos
Definition lua_audio.cpp:17
vec2_base< float > vec2
Definition vec2.h:29
std::uint32_t u32
Definition def.h:14
std::uint8_t u8
Definition def.h:12
std::uint64_t u64
Definition def.h:15
local font
Definition repl.lua:1
Definition colliders.h:34
vec2 tr
Definition colliders.h:36
vec2 center
Definition colliders.h:36
vec2 bl
Definition colliders.h:36
float radius
Definition colliders.h:37
Definition colliders.h:44
float cos
Definition colliders.h:45
float sin
Definition colliders.h:45
vec3 pos
Definition colliders.h:25
Definition renderers.h:44
float size
Definition renderers.h:46
vec3 color
Definition renderers.h:45
constexpr Flags & clear(AT a)
Definition flags.h:49
static void quad_vertices_zsprite(Vertex **p, vec2 bl, vec2 tr, float z, vec3 norm, u32 tex, vec2 uv0, vec2 uv1)
Definition gen.h:112
static void quad_vertices_persp(Vertex **p, vec2 bl, vec2 tr, float y, vec3 norm, u32 tex, vec2 uv0, vec2 uv1)
Definition gen.h:99
static void light(Vertex **p, const Light &x, vec3 pos)
Definition gen.h:386
static void cube_persp(Vertex **p, CubeRenderer *x)
Definition gen.h:252
static void quad_vertices(Vertex **p, vec2 bl, vec2 tr, float z, vec3 norm, u32 tex, vec2 uv0, vec2 uv1)
Definition gen.h:86
static void text(Vertex **p, u64 n, const Font &font, const Text &txt, bool mono, float left, vec2 *pos_p, float *color_p, u64 *i_p, u64 *n_visible_p)
Definition gen.h:292
static void sprite_persp(Vertex **p, SpriteRenderer *x)
Definition gen.h:227
static void voxel_debug(Vertex **p, VoxelRenderer *x)
Definition gen.h:288
static constexpr std::array< vec2, 2 > CIRCLE_UV_64
Definition gen.h:63
static void screen_sprite(Vertex **p, SpriteRenderer *x)
Definition gen.h:236
static void textbox(Vertex **p, const Textbox &x)
Definition gen.h:330
static void sprite_orthoz(Vertex **p, SpriteRenderer *x)
Definition gen.h:217
static void cube_vertices(Vertex **p, vec3 pos, vec3 size, vec3 color)
Definition gen.h:125
static void cube_ortho(Vertex **p, CubeRenderer *x)
Definition gen.h:245
static void voxel_ortho(Vertex **p, VoxelRenderer *x)
Definition gen.h:257
static float text_color(u8 r, u8 g, u8 b)
Definition gen.h:195
static void coll_sphere(Vertex **p, const SphereCollider &x)
Definition gen.h:380
static void sprite_debug(Vertex **p, SpriteRenderer *x)
Definition gen.h:269
static void voxel_persp(Vertex **p, VoxelRenderer *x)
Definition gen.h:264
static void aabb(Vertex **p, const AABBCollider &x, vec3 color)
Definition gen.h:344
static void quad_indices(u64 i, u64 n, u32 *p)
Definition gen.h:66
static void sprite_ortho(Vertex **p, SpriteRenderer *x)
Definition gen.h:208
static void aabb_circle(Vertex **p, const AABBCollider &x)
Definition gen.h:348
static void selection(Vertex **p, const SpriteRenderer &x)
Definition gen.h:338
static void bb(Vertex **p, const BBCollider &x, vec3 color)
Definition gen.h:355
static void light_range(Vertex **p, const Light &x)
Definition gen.h:390
static constexpr std::array< vec2, 2 > CIRCLE_UV_32
Definition gen.h:62
static void cube_debug(Vertex **p, CubeRenderer *x)
Definition gen.h:284
vec3 pos
Definition light.h:29
vec4 color
Definition light.h:30
float z_off
Definition renderers.h:27
Flags< Flag > flags
Definition renderers.h:28
vec3 pos
Definition renderers.h:26
Definition colliders.h:53
float r
Definition colliders.h:54
Definition renderers.h:33
std::array< vec2, 2 > uv
Definition renderers.h:35
vec2 size
Definition renderers.h:34
u32 tex
Definition renderers.h:36
float spacing
Definition text.h:15
std::string str
Definition text.h:13
vec2 size
Definition text.h:16
Definition graphics.h:136
Definition renderers.h:50
u32 tex
Definition renderers.h:53
std::array< vec4, 6 > uv
Definition renderers.h:51
vec3 size
Definition renderers.h:52
constexpr vec2_base< T > xy() const
Definition vec2.h:18
constexpr vec2_base< T > xy() const
Definition vec3.h:26
constexpr vec3_base< T > xyz() const
Definition vec4.h:43
static constexpr nngn::vec2 tr
Definition collision.cpp:8
static constexpr nngn::vec2 bl
Definition collision.cpp:8
local e
Definition math.lua:4
std::chrono::seconds s
Definition timing.cpp:6