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