scene font rendering
[carveJwlIkooP6JGAAIwe30JlM.git] / world_routes.c
1 /*
2 * Copyright (C) 2021-2023 Mt.ZERO Software, Harry Godden - All Rights Reserved
3 */
4
5 #ifndef ROUTES_C
6 #define ROUTES_C
7
8 #include <time.h>
9 #include "entity.h"
10 #include "world_routes.h"
11 #include "world_gate.h"
12 #include "world_load.h"
13 #include "highscores.h"
14
15 #include "font.h"
16 #include "pointcloud.h"
17 #include "gui.h"
18 #include "steam.h"
19
20 #include "shaders/scene_route.h"
21 #include "shaders/routeui.h"
22
23
24 VG_STATIC
25 void world_routes_local_set_record( world_instance *world, ent_route *route,
26 f64 lap_time )
27 {
28 vg_success( " NEW LAP TIME: %f\n", lap_time );
29
30 if( route->official_track_id != 0xffffffff ){
31 double time_centiseconds = lap_time * 100.0;
32 if( time_centiseconds > (float)0xfffe ) /* skill issue */
33 return;
34
35 struct track_info *ti = &track_infos[ route->official_track_id ];
36 highscore_record *record = &ti->record;
37 record->trackid = route->official_track_id;
38 record->datetime = time(NULL);
39 record->playerid = 0;
40 record->points = 0;
41 record->time = time_centiseconds;
42 ti->push = 1;
43
44 if( ti->achievement_id ){
45 steam_set_achievement( ti->achievement_id );
46 steam_store_achievements();
47 }
48 }
49 else{
50 vg_warn( "There is no associated track for this record...\n" );
51 }
52 }
53
54
55 VG_STATIC void world_routes_clear( world_instance *world )
56 {
57 for( u32 i=0; i<mdl_arrcount( &world->ent_route ); i++ ){
58 ent_route *route = mdl_arritm( &world->ent_route, i );
59 route->active_checkpoint = 0xffff;
60 }
61
62 for( u32 i=0; i<mdl_arrcount( &world->ent_gate ); i++ ){
63 ent_gate *rg = mdl_arritm( &world->ent_gate, i );
64 rg->timing_version = 0;
65 rg->timing_time = 0.0;
66 }
67
68 world_static.current_run_version += 4;
69 world_static.last_use = 0.0;
70 }
71
72 VG_STATIC void world_routes_time_lap( world_instance *world, ent_route *route )
73 {
74 vg_info( "------- time lap %s -------\n",
75 mdl_pstr(&world->meta,route->pstr_name) );
76
77 double start_time = 0.0;
78 u32 last_version=0;
79
80 u32 valid_count=0;
81
82 for( u32 i=0; i<route->checkpoints_count; i++ ){
83 u32 cpid = (i+route->active_checkpoint) % route->checkpoints_count;
84 cpid += route->checkpoints_start;
85
86 ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint, cpid );
87 ent_gate *rg = mdl_arritm( &world->ent_gate, cp->gate_index );
88 rg = mdl_arritm( &world->ent_gate, rg->target );
89
90 if( i == 1 ){
91 route->timing_base = rg->timing_time;
92 }
93
94 if( i == 0 )
95 start_time = rg->timing_time;
96 else{
97 if( last_version+1 == rg->timing_version ) valid_count ++;
98 else valid_count = 0;
99 }
100
101 last_version = rg->timing_version;
102 vg_info( "%u %f\n", rg->timing_version, rg->timing_time );
103 }
104
105 if( world_static.current_run_version == last_version+1 ){
106 valid_count ++;
107
108 if( route->checkpoints_count == 1 ){
109 route->timing_base = world_static.time;
110 }
111 }
112 else valid_count = 0;
113
114 vg_info( "%u %f\n", world_static.current_run_version, world_static.time );
115
116 if( valid_count==route->checkpoints_count ){
117 double lap_time = world_static.time - start_time;
118 world_routes_local_set_record( world, route, lap_time );
119 }
120
121 route->valid_checkpoints = valid_count+1;
122
123 vg_info( "valid: %u\n", valid_count );
124 vg_info( "----------------------------\n" );
125 }
126
127 /*
128 * When going through a gate this is called for bookkeeping purposes
129 */
130 VG_STATIC void world_routes_activate_entry_gate( world_instance *world,
131 ent_gate *rg )
132 {
133 world_static.last_use = world_static.time;
134
135 /* disable all routes and leave the world */
136 if( rg->flags & k_ent_gate_nonlocal ){
137 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
138 ent_route *route = mdl_arritm( &world->ent_route, i );
139 route->active_checkpoint = 0xffff;
140 }
141 return;
142 }
143
144 ent_gate *dest = mdl_arritm( &world->ent_gate, rg->target );
145
146 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
147 ent_route *route = mdl_arritm( &world->ent_route, i );
148
149 u32 active_prev = route->active_checkpoint;
150 route->active_checkpoint = 0xffff;
151
152 for( u32 j=0; j<4; j++ ){
153 if( dest->routes[j] == i ){
154 for( u32 k=0; k<route->checkpoints_count; k++ ){
155 ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint,
156 route->checkpoints_start+k );
157
158 ent_gate *gk = mdl_arritm( &world->ent_gate, cp->gate_index );
159 gk = mdl_arritm( &world->ent_gate, gk->target );
160 if( gk == dest ){
161 route->active_checkpoint = k;
162 world_routes_time_lap( world, route );
163 break;
164 }
165 }
166 break;
167 }
168 }
169 }
170
171 dest->timing_version = world_static.current_run_version;
172 dest->timing_time = world_static.time;
173
174 world_static.current_run_version ++;
175 }
176
177 /* draw lines along the paths */
178 VG_STATIC void world_routes_debug( world_instance *world )
179 {
180 for( u32 i=0; i<mdl_arrcount(&world->ent_route_node); i++ ){
181 ent_route_node *rn = mdl_arritm(&world->ent_route_node,i);
182 vg_line_point( rn->co, 0.25f, VG__WHITE );
183 }
184
185 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
186 ent_route *route = mdl_arritm(&world->ent_route, i);
187
188 u32 colours[] = { 0xfff58142, 0xff42cbf5, 0xff42f56c, 0xfff542b3,
189 0xff5442f5 };
190
191 u32 cc = 0xffcccccc;
192 if( route->active_checkpoint != 0xffff ){
193 cc = colours[i%vg_list_size(colours)];
194 }
195
196 for( int i=0; i<route->checkpoints_count; i++ ){
197 int i0 = route->checkpoints_start+i,
198 i1 = route->checkpoints_start+((i+1)%route->checkpoints_count);
199
200 ent_checkpoint *c0 = mdl_arritm(&world->ent_checkpoint, i0),
201 *c1 = mdl_arritm(&world->ent_checkpoint, i1);
202
203 ent_gate *start_gate = mdl_arritm( &world->ent_gate, c0->gate_index );
204 ent_gate *end_gate = mdl_arritm( &world->ent_gate, c1->gate_index );
205
206 v3f p0, p1;
207 v3_copy( start_gate->co[1], p0 );
208
209 for( int j=0; j<c0->path_count; j ++ ){
210 ent_path_index *index = mdl_arritm( &world->ent_path_index,
211 c0->path_start+j );
212
213 ent_route_node *rn = mdl_arritm( &world->ent_route_node,
214 index->index );
215
216 v3_copy( rn->co, p1 );
217 vg_line( p0, p1, cc );
218 v3_copy( p1, p0 );
219 }
220
221 v3_copy( end_gate->co[0], p1 );
222 vg_line( p0, p1, cc );
223 }
224 }
225 }
226
227 VG_STATIC
228 void world_routes_pointcloud_spot( world_instance *world,
229 pointcloud_buffer *pcbuf,
230 v3f co, f32 radius, u32 samples, v4f colour )
231 {
232 v3f inv_ext;
233 v3_sub( pcbuf->boundary[1], pcbuf->boundary[0], inv_ext );
234 v3_div( (v3f){1.0f,1.0f,1.0f}, inv_ext, inv_ext );
235
236 for( u32 j=0; j<samples; j++ ){
237 if( pcbuf->count >= pcbuf->max )
238 return;
239
240 pointcloud_vert *vert = &pcbuf->buf[ pcbuf->count ++ ];
241
242 v3f sample, jitter, point;
243 vg_rand_sphere( jitter );
244 v3_muladds( co, jitter, radius, sample );
245
246 if( bh_closest_point( world->geo_bh, sample, point, radius*1.5f ) == -1 ){
247 v3_copy( sample, point );
248 }
249
250 v3f pos;
251 v3_sub( point, pcbuf->boundary[0], pos );
252 v3_mul( pos, inv_ext, pos );
253
254 float dist = 1.0f-(v3_length(jitter));
255
256 v4f final_colour;
257 v4_muls( colour, dist*dist, final_colour );
258
259 pointcloud_packvert( vert, pos, final_colour );
260 }
261 }
262
263 /*
264 * '
265 * .
266 * |
267 * |
268 * /#\
269 * -'###`-
270 */
271 VG_STATIC
272 void world_routes_pointcloud_tower( world_instance *world,
273 pointcloud_buffer *pcbuf,
274 v3f co, f32 radius, f32 height,
275 u32 samples, v4f colour )
276 {
277 v3f inv_ext;
278 v3_sub( pcbuf->boundary[1], pcbuf->boundary[0], inv_ext );
279 v3_div( (v3f){1.0f,1.0f,1.0f}, inv_ext, inv_ext );
280
281 for( u32 j=0; j<samples; j++ ){
282 if( pcbuf->count >= pcbuf->max )
283 return;
284
285 pointcloud_vert *vert = &pcbuf->buf[ pcbuf->count ++ ];
286
287 v3f point;
288 point[0] = vg_randf64()*2.0f-1.0f;
289 point[1] = 0.0f;
290 point[2] = vg_randf64()*2.0f-1.0f;
291 v3_normalize( point );
292 v3_muls( point, sqrtf(vg_randf64()), point );
293
294 f32 h = vg_randf64();
295 point[1] = h*h*h*height;
296 point[0] *= radius;
297 point[2] *= radius;
298
299 v3_add( point, co, point );
300 v3_sub( point, pcbuf->boundary[0], point );
301 v3_mul( point, inv_ext, point );
302
303 pointcloud_packvert( vert, point, colour );
304 }
305 }
306
307 VG_STATIC
308 void world_routes_place_curve( world_instance *world, ent_route *route,
309 v4f h[3], v3f n0, v3f n2, scene_context *scene,
310 pointcloud_buffer *pcbuf )
311 {
312 float t;
313 v3f p, pd;
314 int last_valid=0;
315
316 float total_length = 0.0f,
317 travel_length = 0.0;
318
319 v3f last;
320 v3_copy( h[0], last );
321 for( int it=0; it<128; it ++ ){
322 t = (float)(it+1) * (1.0f/128.0f);
323 eval_bezier3( h[0], h[1], h[2], t, p );
324 total_length += v3_dist( p, last );
325 v3_copy( p, last );
326 }
327
328 float patch_size = 4.0f,
329 patch_count = ceilf( total_length / patch_size );
330
331 t = 0.0f;
332 v3_copy( h[0], last );
333
334 for( int it=0; it<128; it ++ ){
335 float const k_sample_dist = 0.0025f,
336 k_line_width = 1.5f;
337
338 eval_bezier3( h[0], h[1], h[2], t, p );
339 eval_bezier3( h[0], h[1], h[2], t+k_sample_dist, pd );
340
341 travel_length += v3_dist( p, last );
342
343 float mod = k_sample_dist / v3_dist( p, pd );
344
345 v3f v0,up, right;
346
347 v3_muls( n0, -(1.0f-t), up );
348 v3_muladds( up, n2, -t, up );
349 v3_normalize( up );
350
351 v3_sub( pd,p,v0 );
352 v3_cross( up, v0, right );
353 v3_normalize( right );
354
355 float cur_x = (1.0f-t)*h[0][3] + t*h[2][3];
356
357 v3f sc, sa, sb, down;
358 v3_muladds( p, right, cur_x * k_line_width, sc );
359 v3_muladds( sc, up, 1.5f, sc );
360 v3_muladds( sc, right, k_line_width*0.95f, sa );
361 v3_muladds( sc, right, 0.0f, sb );
362 v3_muls( up, -1.0f, down );
363
364 ray_hit ha, hb;
365 ha.dist = 8.0f;
366 hb.dist = 8.0f;
367
368 int resa = ray_world( world, sa, down, &ha, k_material_flag_ghosts ),
369 resb = ray_world( world, sb, down, &hb, k_material_flag_ghosts );
370
371 if( pcbuf && resa ){
372 world_routes_pointcloud_spot( world, pcbuf, ha.pos,
373 12.0f, 10, route->colour );
374 }
375
376 if( resa && resb ){
377 struct world_surface *surfa = ray_hit_surface( world, &ha ),
378 *surfb = ray_hit_surface( world, &hb );
379
380 if( (surfa->info.flags & k_material_flag_skate_target) &&
381 (surfb->info.flags & k_material_flag_skate_target) )
382 {
383 scene_vert va, vb;
384
385 float gap = vg_fractf(cur_x*0.5f)*0.02f;
386
387 v3_muladds( ha.pos, up, 0.06f+gap, va.co );
388 v3_muladds( hb.pos, up, 0.06f+gap, vb.co );
389
390 scene_vert_pack_norm( &va, up );
391 scene_vert_pack_norm( &vb, up );
392
393 float t1 = (travel_length / total_length) * patch_count;
394 va.uv[0] = t1;
395 va.uv[1] = 0.0f;
396 vb.uv[0] = t1;
397 vb.uv[1] = 1.0f;
398
399 scene_push_vert( scene, &va );
400 scene_push_vert( scene, &vb );
401
402 if( last_valid ){
403 /* Connect them with triangles */
404 scene_push_tri( scene, (u32[3]){
405 last_valid+0-2, last_valid+1-2, last_valid+2-2} );
406 scene_push_tri( scene, (u32[3]){
407 last_valid+1-2, last_valid+3-2, last_valid+2-2} );
408 }
409
410 last_valid = scene->vertex_count;
411 }
412 else
413 last_valid = 0;
414 }
415 else
416 last_valid = 0;
417
418 if( t == 1.0f )
419 return;
420
421 t += 1.0f*mod;
422 if( t > 1.0f )
423 t = 1.0f;
424
425 v3_copy( p, last );
426 }
427 }
428
429 VG_STATIC void world_routes_gen_meshes( world_instance *world, u32 route_id,
430 scene_context *sc,
431 pointcloud_buffer *pcbuf )
432 {
433 ent_route *route = mdl_arritm( &world->ent_route, route_id );
434 u8 colour[4];
435 colour[0] = route->colour[0] * 255.0f;
436 colour[1] = route->colour[1] * 255.0f;
437 colour[2] = route->colour[2] * 255.0f;
438 colour[3] = route->colour[3] * 255.0f;
439
440 u32 last_valid = 0;
441
442 for( int i=0; i<route->checkpoints_count; i++ ){
443 int i0 = route->checkpoints_start+i,
444 i1 = route->checkpoints_start+((i+1)%route->checkpoints_count);
445
446 ent_checkpoint *c0 = mdl_arritm(&world->ent_checkpoint, i0),
447 *c1 = mdl_arritm(&world->ent_checkpoint, i1);
448
449 ent_gate *start_gate = mdl_arritm( &world->ent_gate, c0->gate_index );
450 start_gate = mdl_arritm( &world->ent_gate, start_gate->target );
451
452 ent_gate *end_gate = mdl_arritm( &world->ent_gate, c1->gate_index ),
453 *collector = mdl_arritm( &world->ent_gate, end_gate->target );
454
455 v4f p[3];
456
457 v3_add( (v3f){0.0f,0.1f,0.0f}, start_gate->co[0], p[0] );
458 p[0][3] = start_gate->ref_count;
459 p[0][3] -= (float)start_gate->route_count * 0.5f;
460 start_gate->ref_count ++;
461
462 if( !c0->path_count )
463 continue;
464
465 /* this is so that we get nice flow through the gates */
466 v3f temp_alignments[2];
467 ent_gate *both[] = { start_gate, end_gate };
468
469 for( int j=0; j<2; j++ ){
470 int pi = c0->path_start + ((j==1)? c0->path_count-1: 0);
471
472 ent_path_index *index = mdl_arritm( &world->ent_path_index, pi );
473 ent_route_node *rn = mdl_arritm( &world->ent_route_node,
474 index->index );
475 v3f v0;
476 v3_sub( rn->co, both[j]->co[0], v0 );
477 float d = v3_dot( v0, both[j]->to_world[2] );
478
479 v3_muladds( both[j]->co[0], both[j]->to_world[2], d,
480 temp_alignments[j] );
481 v3_add( (v3f){0.0f,0.1f,0.0f}, temp_alignments[j], temp_alignments[j]);
482 }
483
484
485 for( int j=0; j<c0->path_count; j ++ ){
486 ent_path_index *index = mdl_arritm( &world->ent_path_index,
487 c0->path_start+j );
488 ent_route_node *rn = mdl_arritm( &world->ent_route_node,
489 index->index );
490 if( j==0 || j==c0->path_count-1 )
491 if( j == 0 )
492 v3_copy( temp_alignments[0], p[1] );
493 else
494 v3_copy( temp_alignments[1], p[1] );
495 else
496 v3_copy( rn->co, p[1] );
497
498 p[1][3] = rn->ref_count;
499 p[1][3] -= (float)rn->ref_total * 0.5f;
500 rn->ref_count ++;
501
502 if( j+1 < c0->path_count ){
503 index = mdl_arritm( &world->ent_path_index,
504 c0->path_start+j+1 );
505 rn = mdl_arritm( &world->ent_route_node, index->index );
506
507 if( j+1 == c0->path_count-1 )
508 v3_lerp( p[1], temp_alignments[1], 0.5f, p[2] );
509 else
510 v3_lerp( p[1], rn->co, 0.5f, p[2] );
511
512 p[2][3] = rn->ref_count;
513 p[2][3] -= (float)rn->ref_total * 0.5f;
514 }
515 else{
516 v3_copy( end_gate->co[0], p[2] );
517 v3_add( (v3f){0.0f,0.1f,0.0f}, p[2], p[2] );
518 p[2][3] = collector->ref_count;
519
520 if( i == route->checkpoints_count-1)
521 p[2][3] -= 1.0f;
522
523 p[2][3] -= (float)collector->route_count * 0.5f;
524 //collector->ref_count ++;
525 }
526
527 /* p0,p1,p2 bezier patch is complete
528 * --------------------------------------*/
529 v3f surf0, surf2, n0, n2;
530
531 if( bh_closest_point( world->geo_bh, p[0], surf0, 5.0f ) == -1 )
532 v3_add( (v3f){0.0f,-0.1f,0.0f}, p[0], surf0 );
533
534 if( bh_closest_point( world->geo_bh, p[2], surf2, 5.0f ) == -1 )
535 v3_add( (v3f){0.0f,-0.1f,0.0f}, p[2], surf2 );
536
537 v3_sub( surf0, p[0], n0 );
538 v3_sub( surf2, p[2], n2 );
539 v3_normalize( n0 );
540 v3_normalize( n2 );
541
542 world_routes_place_curve( world, route, p, n0, n2, sc, pcbuf );
543
544 /* --- */
545 v4_copy( p[2], p[0] );
546 }
547 }
548
549 scene_copy_slice( sc, &route->sm );
550 }
551
552 VG_STATIC
553 struct world_surface *world_tri_index_surface( world_instance *world,
554 u32 index );
555
556 VG_STATIC f64 world_routes_scatter_surface_points( world_instance *world,
557 pointcloud_buffer *pcbuf,
558 f32 rate )
559 {
560 static f32 densities[] = {
561 [k_surface_prop_concrete] = 2.0f,
562 [k_surface_prop_grass] = 0.8f,
563 [k_surface_prop_metal] = 1.0f,
564 [k_surface_prop_wood] = 2.5f,
565 [k_surface_prop_tiles] = 4.0f
566 };
567
568 /* calculate total area */
569 f64 total_area = 0.0f;
570 for( u32 i=0; i<world->scene_geo.indice_count/3; i++ ){
571 u32 *tri = &world->scene_geo.arrindices[i*3];
572 struct world_surface *surf = world_tri_index_surface( world, tri[0] );
573
574 if( surf->info.shader == k_shader_boundary ||
575 surf->info.shader == k_shader_invisible ) continue;
576
577 if( !(surf->info.flags & k_material_flag_preview_visibile) ) continue;
578
579 scene_vert *va = &world->scene_geo.arrvertices[tri[0]],
580 *vb = &world->scene_geo.arrvertices[tri[1]],
581 *vc = &world->scene_geo.arrvertices[tri[2]];
582
583 v3f v0, v1, vn;
584 v3_sub( vb->co, va->co, v0 );
585 v3_sub( vc->co, va->co, v1 );
586 v3_cross( v0, v1, vn );
587 if( vn[1] < 0.0f ) continue;
588
589 f32 density = 1.0f;
590 if( surf->info.surface_prop < vg_list_size(densities) )
591 density = densities[surf->info.surface_prop];
592 total_area += v3_length(vn)*0.5f*density;
593 }
594
595 f32 accum = 0.0f;
596
597 u8 colour[] = { 80,80,80,255 };
598 v3f light_dir = {0.3f,0.8f,0.1f};
599 v3_normalize( light_dir );
600
601 v3f inv_ext;
602 v3_sub( pcbuf->boundary[1], pcbuf->boundary[0], inv_ext );
603 v3_div( (v3f){1.0f,1.0f,1.0f}, inv_ext, inv_ext );
604
605 for( u32 i=0; i<world->scene_geo.indice_count/3; i++ ){
606 u32 *tri = &world->scene_geo.arrindices[i*3];
607 struct world_surface *surf = world_tri_index_surface( world, tri[0] );
608
609 if( surf->info.shader == k_shader_boundary ||
610 surf->info.shader == k_shader_invisible ) continue;
611
612 if( !(surf->info.flags & k_material_flag_preview_visibile) ) continue;
613
614 scene_vert *va = &world->scene_geo.arrvertices[tri[0]],
615 *vb = &world->scene_geo.arrvertices[tri[1]],
616 *vc = &world->scene_geo.arrvertices[tri[2]];
617
618 v3f v0, v1, vn;
619 v3_sub( vb->co, va->co, v0 );
620 v3_sub( vc->co, va->co, v1 );
621 v3_cross( v0, v1, vn );
622 if( vn[1] < 0.0f ) continue;
623
624 f32 density = 1.0f;
625 if( surf->info.surface_prop < vg_list_size(densities) )
626 density = densities[surf->info.surface_prop];
627
628 f32 area = v3_length(vn)*0.5f*density;
629 accum += area;
630
631 v3_normalize( vn );
632
633 while( accum > rate ){
634 accum -= rate;
635
636 if( pcbuf->count >= pcbuf->max ) return total_area;
637
638 v2f co = { vg_randf64(), vg_randf64() };
639 if( v2_length2(co) > 0.5f ){
640 co[0] = 1.0f-co[0];
641 co[1] = 1.0f-co[1];
642 }
643
644 v3f pt;
645 v3_muls( v0, co[0], pt );
646 v3_muladds( pt, v1, co[1], pt );
647 v3_add( va->co, pt, pt );
648
649 if( pt[1] < world->water.height ) continue;
650 pointcloud_vert *vert = &pcbuf->buf[ pcbuf->count ++ ];
651
652 v3f pos;
653 v3_sub( pt, pcbuf->boundary[0], pos );
654 v3_mul( pos, inv_ext, pos );
655
656 static v4f colours[] = {
657 [k_surface_prop_concrete] = { 0.13, 0.15, 0.17, 1.0 },
658 [k_surface_prop_grass] = { 0.07, 0.1, 0.14, 1.0 },
659 [k_surface_prop_metal] = { 0.15, 0.19, 0.22, 1.0 },
660 [k_surface_prop_wood] = { 0.1, 0.13, 0.17, 1.0 },
661 [k_surface_prop_tiles] = { 0.05, 0.06, 0.07, 1.0 },
662 };
663
664 v4f col = {0.0f,0.0f,0.0f,0.0f};
665 if( surf->info.surface_prop < vg_list_size(colours) )
666 v4_copy( colours[surf->info.surface_prop], col );
667
668 f32 brightness = v3_dot(vn,light_dir)*0.5f+0.5f;
669 v3_muls( col, brightness, col );
670
671 pointcloud_packvert( vert, pos, col );
672 }
673 }
674
675 return total_area;
676 }
677
678 VG_STATIC void world_routes_surface_grid( world_instance *world,
679 pointcloud_buffer *pcbuf )
680 {
681 i32 const k_gridlines = 32,
682 k_gridres = 255;
683
684 v3f inv_ext;
685 v3_sub( pcbuf->boundary[1], pcbuf->boundary[0], inv_ext );
686 v3_div( (v3f){1.0f,1.0f,1.0f}, inv_ext, inv_ext );
687 v4f colour = {0.2f,0.2f,0.2f,1.0f};
688 v3f dir = {0.0f,-1.0f,0.0f};
689
690 for( u32 k=0; k<2; k++ ){
691 u32 a = k*2,
692 b = (k^0x1)*2;
693
694 for( i32 x=0; x<=k_gridlines; x++ ){
695 f32 t = (float)x / (float)k_gridlines,
696 px = vg_lerpf( pcbuf->boundary[0][a], pcbuf->boundary[1][a], t );
697
698 for( i32 z=0; z<=k_gridres; z++ ){
699 f32 tz = (float)z / (float)k_gridres,
700 pz = vg_lerpf(pcbuf->boundary[0][b],pcbuf->boundary[1][b], tz);
701
702 v3f ro, hit;
703 ro[a] = px;
704 ro[1] = 1000.0f;
705 ro[b] = pz;
706
707 bh_iter it;
708 bh_iter_init_ray( 0, &it, ro, dir, INFINITY );
709 i32 idx;
710
711 while( bh_next( world->geo_bh, &it, &idx ) ){
712 u32 *tri = &world->scene_geo.arrindices[ idx*3 ];
713 v3f vs[3];
714
715 u16 mask = k_material_flag_preview_visibile;
716 if( !(world->scene_geo.arrvertices[tri[0]].flags & mask) )
717 continue;
718
719 for( u32 i=0; i<3; i++ ){
720 v3_copy( world->scene_geo.arrvertices[tri[i]].co, vs[i] );
721 }
722
723 f32 t;
724 if( ray_tri( vs, ro, dir, &t ) ){
725 v3_muladds( ro, dir, t, hit );
726
727 if( world->water.enabled )
728 if( hit[1] < world->water.height )
729 continue;
730
731 if( pcbuf->count >= pcbuf->max ) return;
732
733 pointcloud_vert *vert = &pcbuf->buf[ pcbuf->count ++ ];
734
735 v3f co;
736 v3_sub( hit, pcbuf->boundary[0], co );
737 v3_mul( co, inv_ext, co );
738
739 pointcloud_packvert( vert, co, colour );
740 }
741 }
742 }
743 }
744 }
745 }
746
747 VG_STATIC void world_write_preview( addon_reg *reg, pointcloud_buffer *pcbuf ){
748 if( reg->alias.workshop_id ) return;
749
750 /*
751 * FIXME: BUG: cannot correctly handle workshop because there is a stalling
752 * call below, which deadlocks the scene upload. TODO: improve the async
753 * stack to handle out of order execution. MAYBE
754 */
755
756 char path_buf[4096];
757 vg_str path;
758 vg_strnull( &path, path_buf, 4096 );
759
760 addon_get_content_folder( reg, &path );
761 vg_strcat( &path, "/preview.bin" );
762
763 if( !vg_strgood( &path ) ) vg_fatal_error( "Path too long\n" );
764 FILE *fp = fopen( path_buf, "wb" );
765 if( !fp ) vg_fatal_error( "Cannot open '%s' for writing\n", path_buf );
766
767 fwrite( pcbuf, sizeof(struct pointcloud_buffer) +
768 sizeof(struct pointcloud_vert)*pcbuf->count, 1, fp );
769 fclose( fp );
770 vg_info( "written %s\n", path_buf );
771 }
772
773 /*
774 * Create the strips of colour that run through the world along course paths
775 */
776 VG_STATIC void world_gen_routes_generate( u32 instance_id ){
777 world_instance *world = &world_static.instances[ instance_id ];
778 vg_info( "Generating route meshes\n" );
779 vg_async_stall();
780
781 vg_rand_seed( 2000 );
782 vg_async_item *call_scene = scene_alloc_async( &world->scene_lines,
783 &world->mesh_route_lines,
784 200000, 300000 );
785
786 vg_async_item *call_pointcloud = NULL;
787 pointcloud_buffer *pcbuf = NULL;
788
789 if( instance_id <= 1 /*world_loader.generate_point_cloud*/ ){
790 call_pointcloud = vg_async_alloc(
791 sizeof(pointcloud_buffer) +
792 sizeof(pointcloud_vert)*POINTCLOUD_POINTS );
793 pcbuf = call_pointcloud->payload;
794 pcbuf->count = 0;
795 pcbuf->max = POINTCLOUD_POINTS;
796 pcbuf->op = k_pointcloud_op_clear;
797
798 v3f ext, mid, v0;
799 v3_sub( world->scene_geo.bbx[1], world->scene_geo.bbx[0], ext );
800 f32 maxe = v3_maxf( ext );
801 v3_fill( v0, maxe * 0.5f );
802 v3_muladds( world->scene_geo.bbx[0], ext, 0.5f, mid );
803 v3_add( mid, v0, pcbuf->boundary[1] );
804 v3_sub( mid, v0, pcbuf->boundary[0] );
805 }
806
807 for( u32 i=0; i<mdl_arrcount(&world->ent_gate); i++ ){
808 ent_gate *gate = mdl_arritm( &world->ent_gate, i );
809 gate->ref_count = 0;
810 gate->route_count = 0;
811 }
812
813 for( u32 i=0; i<mdl_arrcount(&world->ent_route_node); i++ ){
814 ent_route_node *rn = mdl_arritm( &world->ent_route_node, i );
815 rn->ref_count = 0;
816 rn->ref_total = 0;
817 }
818
819 for( u32 k=0; k<mdl_arrcount(&world->ent_route); k++ ){
820 ent_route *route = mdl_arritm( &world->ent_route, k );
821
822 for( int i=0; i<route->checkpoints_count; i++ ){
823 int i0 = route->checkpoints_start+i,
824 i1 = route->checkpoints_start+((i+1)%route->checkpoints_count);
825
826 ent_checkpoint *c0 = mdl_arritm(&world->ent_checkpoint, i0),
827 *c1 = mdl_arritm(&world->ent_checkpoint, i1);
828
829 ent_gate *start_gate = mdl_arritm( &world->ent_gate, c0->gate_index );
830 start_gate = mdl_arritm( &world->ent_gate, start_gate->target );
831 start_gate->route_count ++;
832
833 if( !c0->path_count )
834 continue;
835
836 for( int j=0; j<c0->path_count; j ++ ){
837 ent_path_index *index = mdl_arritm( &world->ent_path_index,
838 c0->path_start+j );
839 ent_route_node *rn = mdl_arritm( &world->ent_route_node,
840 index->index );
841 rn->ref_total ++;
842 }
843 }
844 }
845
846 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
847 world_routes_gen_meshes( world, i, &world->scene_lines, pcbuf );
848 }
849
850 if( instance_id <= 1 /*world_loader.generate_point_cloud*/ ){
851 f64 area = 0.0;
852 area = world_routes_scatter_surface_points( world, pcbuf, 16.0f );
853 world_routes_surface_grid( world, pcbuf );
854
855 for( u32 i=0; i<mdl_arrcount( &world->ent_gate ); i++ ){
856 ent_gate *gate = mdl_arritm( &world->ent_gate, i );
857
858 world_routes_pointcloud_tower( world, pcbuf, gate->co[0],
859 2.0f, 50.0f, 128,
860 (v4f){0.2f,0.2f,0.2f,1.0f} );
861 }
862
863 vg_info( "Distrubuted %u points over %fkm^2!\n",
864 pcbuf->count, area/1e6f );
865
866 world_write_preview( instance_id? world_static.addon_client:
867 world_static.addon_hub,
868 pcbuf );
869 vg_async_dispatch( call_pointcloud, async_pointcloud_sub );
870 }
871
872 vg_async_dispatch( call_scene, async_scene_upload );
873 world_routes_clear( world );
874 }
875
876 /* load all routes from model header */
877 VG_STATIC void world_gen_routes_ent_init( world_instance *world ){
878 vg_info( "Initializing routes\n" );
879
880 for( u32 i=0; i<mdl_arrcount(&world->ent_gate); i++ ){
881 ent_gate *gate = mdl_arritm( &world->ent_gate, i );
882 for( u32 j=0; j<4; j++ ){
883 gate->routes[j] = 0xffff;
884 }
885 }
886
887 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
888 ent_route *route = mdl_arritm(&world->ent_route,i);
889 mdl_transform_m4x3( &route->transform, route->board_transform );
890
891 route->official_track_id = 0xffffffff;
892 for( u32 j=0; j<vg_list_size(track_infos); j ++ ){
893 if( !strcmp(track_infos[j].name,
894 mdl_pstr(&world->meta,route->pstr_name))){
895 route->official_track_id = j;
896 }
897 }
898
899 for( u32 j=0; j<route->checkpoints_count; j++ ){
900 u32 id = route->checkpoints_start + j;
901 ent_checkpoint *cp = mdl_arritm(&world->ent_checkpoint,id);
902
903 ent_gate *gate = mdl_arritm( &world->ent_gate, cp->gate_index );
904
905 for( u32 k=0; k<4; k++ ){
906 if( gate->routes[k] == 0xffff ){
907 gate->routes[k] = i;
908 break;
909 }
910 }
911
912 if( (gate->flags & k_ent_gate_linked) &
913 !(gate->flags & k_ent_gate_nonlocal) ){
914 gate = mdl_arritm(&world->ent_gate, gate->target );
915
916 for( u32 k=0; k<4; k++ ){
917 if( gate->routes[k] == i ){
918 vg_error( "already assigned route to gate\n" );
919 break;
920 }
921 if( gate->routes[k] == 0xffff ){
922 gate->routes[k] = i;
923 break;
924 }
925 }
926 }
927 }
928 }
929
930 for( u32 i=0; i<mdl_arrcount(&world->ent_gate); i++ ){
931 ent_gate *gate = mdl_arritm( &world->ent_gate, i );
932 }
933
934 world_routes_clear( world );
935 }
936
937 /*
938 * -----------------------------------------------------------------------------
939 * Events
940 * -----------------------------------------------------------------------------
941 */
942
943 VG_STATIC void world_routes_init(void)
944 {
945 world_static.current_run_version = 200;
946 world_static.time = 300.0;
947 world_static.last_use = 0.0;
948
949 shader_scene_route_register();
950 shader_routeui_register();
951 }
952
953 VG_STATIC void world_routes_update( world_instance *world )
954 {
955 world_static.time += vg.time_delta;
956
957 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
958 ent_route *route = mdl_arritm( &world->ent_route, i );
959
960 int target = route->active_checkpoint == 0xffff? 0: 1;
961 route->factive = vg_lerpf( route->factive, target, 0.6f*vg.time_delta );
962 }
963
964 for( u32 i=0; i<world_render.text_particle_count; i++ ){
965 struct text_particle *particle = &world_render.text_particles[i];
966 rb_object_debug( &particle->obj, VG__RED );
967 }
968 }
969
970 VG_STATIC void world_routes_fixedupdate( world_instance *world )
971 {
972 rb_solver_reset();
973
974 for( u32 i=0; i<world_render.text_particle_count; i++ ){
975 struct text_particle *particle = &world_render.text_particles[i];
976
977 if( rb_global_has_space() ){
978 rb_ct *buf = rb_global_buffer();
979
980 int l = rb_sphere__scene( particle->obj.rb.to_world,
981 &particle->obj.inf.sphere,
982 NULL, &world->rb_geo.inf.scene, buf,
983 k_material_flag_ghosts );
984
985 for( int j=0; j<l; j++ ){
986 buf[j].rba = &particle->obj.rb;
987 buf[j].rbb = &world->rb_geo.rb;
988 }
989
990 rb_contact_count += l;
991 }
992 }
993
994 rb_presolve_contacts( rb_contact_buffer, rb_contact_count );
995
996 for( int i=0; i<rb_contact_count; i++ ){
997 rb_contact_restitution( rb_contact_buffer+i, vg_randf64() );
998 }
999
1000 for( int i=0; i<6; i++ ){
1001 rb_solve_contacts( rb_contact_buffer, rb_contact_count );
1002 }
1003
1004 for( u32 i=0; i<world_render.text_particle_count; i++ ){
1005 struct text_particle *particle = &world_render.text_particles[i];
1006 rb_iter( &particle->obj.rb );
1007 }
1008
1009 for( u32 i=0; i<world_render.text_particle_count; i++ ){
1010 struct text_particle *particle = &world_render.text_particles[i];
1011 rb_update_transform( &particle->obj.rb );
1012 }
1013 }
1014
1015 VG_STATIC void bind_terrain_noise(void);
1016 VG_STATIC void world_bind_light_array( world_instance *world,
1017 GLuint shader, GLuint location,
1018 int slot );
1019 VG_STATIC void world_bind_light_index( world_instance *world,
1020 GLuint shader, GLuint location,
1021 int slot );
1022
1023 VG_STATIC void world_routes_update_timer_texts( world_instance *world )
1024 {
1025 world_render.timer_text_count = 0;
1026
1027 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
1028 ent_route *route = mdl_arritm( &world->ent_route, i );
1029
1030 if( route->active_checkpoint != 0xffff ){
1031 u32 next = route->active_checkpoint+1;
1032 next = next % route->checkpoints_count;
1033 next += route->checkpoints_start;
1034
1035 ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint, next );
1036 ent_gate *gate = mdl_arritm( &world->ent_gate, cp->gate_index );
1037 ent_gate *dest = mdl_arritm( &world->ent_gate, gate->target );
1038
1039 u32 j=0;
1040 for( ; j<4; j++ ){
1041 if( dest->routes[j] == i ){
1042 break;
1043 }
1044 }
1045
1046 float h0 = 0.8f,
1047 h1 = 1.2f,
1048 depth = 0.4f,
1049 size = 0.4f;
1050
1051 struct timer_text *text =
1052 &world_render.timer_texts[ world_render.timer_text_count ++ ];
1053
1054 text->gate = gate;
1055 text->route = route;
1056
1057 if( route->valid_checkpoints >= route->checkpoints_count ){
1058 double lap_time = world_static.time - route->timing_base,
1059 time_centiseconds = lap_time * 100.0;
1060
1061 if( time_centiseconds > (float)0xfffe ) time_centiseconds = 0.0;
1062
1063 u16 centiseconds = time_centiseconds,
1064 seconds = centiseconds / 100,
1065 minutes = seconds / 60;
1066
1067 centiseconds %= 100;
1068 seconds %= 60;
1069 minutes %= 60;
1070
1071 if( minutes > 9 ) minutes = 9;
1072
1073 int j=0;
1074 if( minutes ){
1075 highscore_intr( text->text, minutes, 1, ' ' ); j++;
1076 text->text[j++] = ':';
1077 }
1078
1079 if( seconds >= 10 || minutes ){
1080 highscore_intr( text->text+j, seconds, 2, '0' ); j+=2;
1081 }
1082 else{
1083 highscore_intr( text->text+j, seconds, 1, '0' ); j++;
1084 }
1085
1086 text->text[j++] = '.';
1087 highscore_intr( text->text+j, centiseconds, 1, '0' ); j++;
1088 text->text[j] = '\0';
1089 }
1090 else{
1091 highscore_intr( text->text, route->valid_checkpoints, 1, ' ' );
1092 text->text[1] = '/';
1093 highscore_intr( text->text+2, route->checkpoints_count+1, 1, ' ' );
1094 text->text[3] = '\0';
1095 }
1096
1097 float align_r = font3d_string_width( &gui.font, 0, text->text );
1098 align_r *= size;
1099
1100 v3f positions[] = {
1101 { -0.92f, h0, depth },
1102 { 0.92f - align_r, h0, depth },
1103 { -0.92f, h1, depth },
1104 { 0.92f - align_r, h1, depth },
1105 };
1106
1107 if( dest->route_count == 1 ){
1108 positions[0][0] = -align_r*0.5f;
1109 positions[0][1] = h1;
1110 }
1111
1112 m4x3f mmdl;
1113 ent_gate_get_mdl_mtx( gate, mmdl );
1114
1115 m3x3_copy( mmdl, text->transform );
1116 float ratio = v3_length(text->transform[0]) /
1117 v3_length(text->transform[1]);
1118
1119 m3x3_scale( text->transform, (v3f){ size, size*ratio, 0.1f } );
1120 m4x3_mulv( mmdl, positions[j], text->transform[3] );
1121 }
1122 }
1123 }
1124
1125 VG_STATIC void world_routes_fracture( world_instance *world, ent_gate *gate,
1126 v3f imp_co, v3f imp_v )
1127 {
1128 world_render.text_particle_count = 0;
1129
1130 for( u32 i=0; i<world_render.timer_text_count; i++ ){
1131 struct timer_text *text = &world_render.timer_texts[i];
1132
1133 if( text->gate != gate ) continue;
1134
1135 m4x3f transform;
1136 m4x3_mul( gate->transport, text->transform, transform );
1137
1138 v3f co, s;
1139 v4f q;
1140 m4x3_decompose( transform, co, q, s );
1141
1142 v3f offset;
1143 v3_zero( offset );
1144
1145 v4f colour;
1146 float brightness = 0.3f + world->ub_lighting.g_day_phase;
1147 v3_muls( text->route->colour, brightness, colour );
1148 colour[3] = 1.0f-text->route->factive;
1149
1150 for( u32 j=0;; j++ ){
1151 char c = text->text[j];
1152 if( !c ) break;
1153
1154 ent_glyph *glyph = font3d_glyph( &gui.font, 0, c );
1155 if( !glyph ) continue;
1156
1157 if( c >= (u32)'0' && c <= (u32)'9' && glyph->indice_count ){
1158 struct text_particle *particle =
1159 &world_render.text_particles[world_render.text_particle_count++];
1160
1161 particle->glyph = glyph;
1162 v4_copy( colour, particle->colour );
1163
1164 v3f origin;
1165 v2_muls( glyph->size, 0.5f, origin );
1166 origin[2] = -0.5f;
1167
1168 v3f world_co;
1169
1170 v3_add( offset, origin, world_co );
1171 m4x3_mulv( transform, world_co, world_co );
1172
1173 float r = vg_maxf( s[0]*glyph->size[0], s[1]*glyph->size[1] )*0.5f;
1174
1175 m3x3_identity( particle->mlocal );
1176 m3x3_scale( particle->mlocal, s );
1177 origin[2] *= s[2];
1178 v3_muls( origin, -1.0f, particle->mlocal[3] );
1179
1180 v3_copy( world_co, particle->obj.rb.co );
1181 v3_muls( imp_v, 1.0f+vg_randf64(), particle->obj.rb.v );
1182 particle->obj.rb.v[1] += 2.0f;
1183
1184 v4_copy( q, particle->obj.rb.q );
1185 particle->obj.rb.w[0] = vg_randf64()*2.0f-1.0f;
1186 particle->obj.rb.w[1] = vg_randf64()*2.0f-1.0f;
1187 particle->obj.rb.w[2] = vg_randf64()*2.0f-1.0f;
1188
1189 particle->obj.type = k_rb_shape_sphere;
1190 particle->obj.inf.sphere.radius = r*0.6f;
1191
1192 rb_init_object( &particle->obj );
1193 }
1194 offset[0] += glyph->size[0];
1195 }
1196 }
1197 }
1198
1199 VG_STATIC void render_world_routes( world_instance *world, camera *cam,
1200 int layer_depth )
1201 {
1202 m4x3f identity_matrix;
1203 m4x3_identity( identity_matrix );
1204
1205 shader_scene_route_use();
1206 shader_scene_route_uTexGarbage(0);
1207 world_link_lighting_ub( world, _shader_scene_route.id );
1208 world_bind_position_texture( world, _shader_scene_route.id,
1209 _uniform_scene_route_g_world_depth, 2 );
1210 world_bind_light_array( world, _shader_scene_route.id,
1211 _uniform_scene_route_uLightsArray, 3 );
1212 world_bind_light_index( world, _shader_scene_route.id,
1213 _uniform_scene_route_uLightsIndex, 4 );
1214 bind_terrain_noise();
1215
1216 shader_scene_route_uPv( cam->mtx.pv );
1217 shader_scene_route_uPvmPrev( cam->mtx_prev.pv );
1218 shader_scene_route_uMdl( identity_matrix );
1219 shader_scene_route_uCamera( cam->transform[3] );
1220
1221 mesh_bind( &world->mesh_route_lines );
1222
1223 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
1224 ent_route *route = mdl_arritm( &world->ent_route, i );
1225
1226 v4f colour;
1227 v3_lerp( (v3f){0.7f,0.7f,0.7f}, route->colour, route->factive, colour );
1228 colour[3] = route->factive*0.2f;
1229
1230 shader_scene_route_uColour( colour );
1231 mdl_draw_submesh( &route->sm );
1232 }
1233
1234 /* timers
1235 * ---------------------------------------------------- */
1236 if( layer_depth == 0 ){
1237 font3d_bind( &gui.font, cam );
1238
1239 for( u32 i=0; i<world_render.timer_text_count; i++ ){
1240 struct timer_text *text = &world_render.timer_texts[i];
1241
1242 v4f colour;
1243 float brightness = 0.3f + world->ub_lighting.g_day_phase;
1244 v3_muls( text->route->colour, brightness, colour );
1245 colour[3] = 1.0f-text->route->factive;
1246
1247 shader_model_font_uColour( colour );
1248 font3d_simple_draw( &gui.font, 0, k_font_shader_default,
1249 text->text, cam, text->transform );
1250 }
1251
1252 shader_model_font_uOffset( (v4f){0.0f,0.0f,0.0f,1.0f} );
1253
1254 for( u32 i=0; i<world_render.text_particle_count; i++ ){
1255 struct text_particle *particle = &world_render.text_particles[i];
1256
1257 m4x4f prev_mtx;
1258
1259 m4x3_expand( particle->mdl, prev_mtx );
1260 m4x4_mul( cam->mtx_prev.pv, prev_mtx, prev_mtx );
1261
1262 shader_model_font_uPvmPrev( prev_mtx );
1263
1264 v4f q;
1265 m4x3f model;
1266 rb_extrapolate( &particle->obj.rb, model[3], q );
1267 q_m3x3( q, model );
1268
1269 m4x3_mul( model, particle->mlocal, particle->mdl );
1270 shader_model_font_uMdl( particle->mdl );
1271 shader_model_font_uColour( particle->colour );
1272
1273 mesh_drawn( particle->glyph->indice_start,
1274 particle->glyph->indice_count );
1275 }
1276 }
1277
1278 /* gate markers
1279 * ---------------------------------------------------- */
1280
1281 shader_model_gate_use();
1282 shader_model_gate_uPv( cam->mtx.pv );
1283 shader_model_gate_uCam( cam->pos );
1284 shader_model_gate_uTime( vg.time*0.25f );
1285 shader_model_gate_uInvRes( (v2f){
1286 1.0f / (float)vg.window_x,
1287 1.0f / (float)vg.window_y });
1288
1289 mesh_bind( &world_gates.mesh );
1290
1291 /* skip writing into the motion vectors for this */
1292 glDrawBuffers( 1, (GLenum[]){ GL_COLOR_ATTACHMENT0 } );
1293
1294 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
1295 ent_route *route = mdl_arritm( &world->ent_route, i );
1296
1297 if( route->active_checkpoint != 0xffff ){
1298 v4f colour;
1299 float brightness = 0.3f + world->ub_lighting.g_day_phase;
1300 v3_muls( route->colour, brightness, colour );
1301 colour[3] = 1.0f-route->factive;
1302
1303 shader_model_gate_uColour( colour );
1304
1305 u32 next = route->active_checkpoint+1+layer_depth;
1306 next = next % route->checkpoints_count;
1307 next += route->checkpoints_start;
1308
1309 ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint, next );
1310 ent_gate *gate = mdl_arritm( &world->ent_gate, cp->gate_index );
1311
1312 m4x3f mmdl;
1313 ent_gate_get_mdl_mtx( gate, mmdl );
1314 shader_model_gate_uMdl( mmdl );
1315
1316 for( u32 j=0; j<4; j++ ){
1317 if( gate->routes[j] == i ){
1318 mdl_draw_submesh( &world_gates.sm_marker[j] );
1319 break;
1320 }
1321 }
1322 }
1323 }
1324 glDrawBuffers( 2, (GLenum[]){ GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 } );
1325 }
1326
1327 #endif /* ROUTES_C */