shader vacuuming
[carveJwlIkooP6JGAAIwe30JlM.git] / render.h
1 /*
2 * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
3 */
4
5 #include "common.h"
6 #include "model.h"
7 #include "camera.h"
8 #include "world.h"
9
10 #include "shaders/blit.h"
11 #include "shaders/blitblur.h"
12 #include "shaders/blitcolour.h"
13
14 #if 0
15 #include "shaders/standard.h"
16 #include "shaders/vblend.h"
17 #endif
18
19 VG_STATIC void render_water_texture( world_instance *world, camera *cam );
20 VG_STATIC void render_water_surface( world_instance *world, camera *cam );
21 VG_STATIC void render_world( world_instance *world, camera *cam );
22 VG_STATIC void render_world_depth( world_instance *world, camera *cam );
23
24 #ifndef RENDER_H
25 #define RENDER_H
26
27 typedef struct framebuffer framebuffer;
28
29
30 /*
31 * All standard buffers used in rendering
32 */
33 VG_STATIC struct pipeline
34 {
35 glmesh fsquad;
36
37 framebuffer *fb_main,
38 *fb_water_reflection,
39 *fb_water_beneath;
40
41 struct light_widget
42 {
43 int enabled;
44 v2f dir;
45 v3f colour;
46 }
47 widgets[3];
48
49 float shadow_spread, shadow_length;
50
51 int ready;
52 }
53 gpipeline =
54 {
55 .widgets =
56 {
57 {
58 .enabled = 1,
59 .colour = { 1.36f, 1.35f, 1.01f },
60 .dir = { 0.63f, -0.08f }
61 },
62 {
63 .enabled = 1,
64 .colour = { 0.33f, 0.56f, 0.64f },
65 .dir = { -2.60f, -0.13f }
66 },
67 {
68 .enabled = 1,
69 .colour = { 0.05f, 0.05f, 0.23f },
70 .dir = { 2.60f, -0.84f }
71 }
72 },
73 .shadow_spread = 0.65f,
74 .shadow_length = 9.50f,
75 };
76
77 struct framebuffer
78 {
79 const char *display_name;
80 int resolution_div,
81 fixed_w,
82 fixed_h;
83
84 struct framebuffer_attachment
85 {
86 const char *display_name;
87
88 enum framebuffer_attachment_type
89 {
90 k_framebuffer_attachment_type_none,
91 k_framebuffer_attachment_type_colour,
92 k_framebuffer_attachment_type_renderbuffer
93 }
94 purpose;
95
96 enum framebuffer_quality_profile
97 {
98 k_framebuffer_quality_all,
99 k_framebuffer_quality_high_only
100 }
101 quality;
102
103 GLenum internalformat,
104 format,
105 type,
106 attachment;
107
108 GLuint id;
109
110 /* Runtime */
111 int debug_view;
112 }
113 attachments[5];
114 GLuint fb;
115 framebuffer **link;
116 }
117 framebuffers[] =
118 {
119 {
120 /*
121 * The primary draw target
122 */
123 "main",
124 .link = &gpipeline.fb_main,
125 .resolution_div = 1,
126 .attachments =
127 {
128 {
129 "colour", k_framebuffer_attachment_type_colour,
130
131 .internalformat = GL_RGB,
132 .format = GL_RGB,
133 .type = GL_UNSIGNED_BYTE,
134 .attachment = GL_COLOR_ATTACHMENT0
135 },
136 {
137 "motion", k_framebuffer_attachment_type_colour,
138
139 .quality = k_framebuffer_quality_high_only,
140 .internalformat = GL_RG16F,
141 .format = GL_RG,
142 .type = GL_FLOAT,
143 .attachment = GL_COLOR_ATTACHMENT1
144 },
145 {
146 "depth_stencil", k_framebuffer_attachment_type_renderbuffer,
147
148 .internalformat = GL_DEPTH24_STENCIL8,
149 .attachment = GL_DEPTH_STENCIL_ATTACHMENT
150 }
151 }
152 },
153 {
154 /*
155 * Second rendered view from the perspective of the water reflection
156 */
157 "water_reflection",
158 .link = &gpipeline.fb_water_reflection,
159 .resolution_div = 3,
160 .attachments =
161 {
162 {
163 "colour", k_framebuffer_attachment_type_colour,
164 .internalformat = GL_RGB,
165 .format = GL_RGB,
166 .type = GL_UNSIGNED_BYTE,
167 .attachment = GL_COLOR_ATTACHMENT0
168 },
169 {
170 "depth_stencil", k_framebuffer_attachment_type_renderbuffer,
171
172 .internalformat = GL_DEPTH24_STENCIL8,
173 .attachment = GL_DEPTH_STENCIL_ATTACHMENT
174 }
175 }
176 },
177 {
178 /*
179 * Thid rendered view from the perspective of the camera, but just
180 * captures stuff thats under the water
181 */
182 "water_beneath",
183 .link = &gpipeline.fb_water_beneath,
184 .resolution_div = 4,
185 .attachments =
186 {
187 {
188 "colour", k_framebuffer_attachment_type_colour,
189 .internalformat = GL_RED,
190 .format = GL_RED,
191 .type = GL_UNSIGNED_BYTE,
192 .attachment = GL_COLOR_ATTACHMENT0
193 },
194 {
195 "depth_stencil", k_framebuffer_attachment_type_renderbuffer,
196
197 .internalformat = GL_DEPTH24_STENCIL8,
198 .attachment = GL_DEPTH_STENCIL_ATTACHMENT
199 }
200 }
201 }
202 };
203
204 /*
205 * Get the current (automatically scaled or fixed) resolution of framebuffer
206 */
207 VG_STATIC void render_fb_get_current_res( struct framebuffer *fb,
208 int *x, int *y )
209 {
210 if( fb->resolution_div )
211 {
212 *x = vg.window_x / fb->resolution_div;
213 *y = vg.window_y / fb->resolution_div;
214 }
215 else
216 {
217 *x = fb->fixed_w;
218 *y = fb->fixed_h;
219 }
220 }
221
222 /*
223 * Bind framebuffer for drawing to
224 */
225 VG_STATIC void render_fb_bind( framebuffer *fb )
226 {
227 int x, y;
228 render_fb_get_current_res( fb, &x, &y );
229 glBindFramebuffer( GL_FRAMEBUFFER, fb->fb );
230 glViewport( 0, 0, x, y );
231 }
232
233 /*
234 * Bind framebuffer attachment's texture
235 */
236 VG_STATIC void render_fb_bind_texture( framebuffer *fb,
237 int attachment, int slot )
238 {
239 struct framebuffer_attachment *at = &fb->attachments[attachment];
240
241 if( at->purpose != k_framebuffer_attachment_type_colour )
242 {
243 vg_fatal_exit_loop( "illegal operation: bind non-colour framebuffer"
244 " attachment to texture slot" );
245 }
246
247 glActiveTexture( GL_TEXTURE0 + slot );
248 glBindTexture( GL_TEXTURE_2D, fb->attachments[attachment].id );
249 }
250
251
252 /*
253 * Shaders
254 */
255
256 #define FB_FORMAT_STR( E ) { E, #E },
257
258 /*
259 * Convert OpenGL attachment ID enum to string
260 */
261 VG_STATIC const char *render_fb_attachment_str( GLenum e )
262 {
263 struct { GLenum e; const char *str; }
264 formats[] =
265 {
266 FB_FORMAT_STR(GL_COLOR_ATTACHMENT0)
267 FB_FORMAT_STR(GL_COLOR_ATTACHMENT1)
268 FB_FORMAT_STR(GL_COLOR_ATTACHMENT2)
269 FB_FORMAT_STR(GL_COLOR_ATTACHMENT3)
270 FB_FORMAT_STR(GL_COLOR_ATTACHMENT4)
271 FB_FORMAT_STR(GL_DEPTH_STENCIL_ATTACHMENT)
272 };
273
274 for( int i=0; i<vg_list_size(formats); i++ )
275 if( formats[i].e == e )
276 return formats[i].str;
277
278 return "UNDEFINED";
279 }
280
281 /*
282 * Convert OpenGL texture format enums from TexImage2D table 1,2 &
283 * RenderBufferStorage Table 1, into strings
284 */
285 VG_STATIC const char *render_fb_format_str( GLenum format )
286 {
287 struct { GLenum e; const char *str; }
288 formats[] =
289 {
290 /* Table 1 */
291 FB_FORMAT_STR(GL_DEPTH_COMPONENT)
292 FB_FORMAT_STR(GL_DEPTH_STENCIL)
293 FB_FORMAT_STR(GL_RED)
294 FB_FORMAT_STR(GL_RG)
295 FB_FORMAT_STR(GL_RGB)
296 FB_FORMAT_STR(GL_RGBA)
297
298 /* Render buffer formats */
299 FB_FORMAT_STR(GL_DEPTH_COMPONENT16)
300 FB_FORMAT_STR(GL_DEPTH_COMPONENT24)
301 FB_FORMAT_STR(GL_DEPTH_COMPONENT32F)
302 FB_FORMAT_STR(GL_DEPTH24_STENCIL8)
303 FB_FORMAT_STR(GL_DEPTH32F_STENCIL8)
304 FB_FORMAT_STR(GL_STENCIL_INDEX8)
305
306 /* Table 2 */
307 FB_FORMAT_STR(GL_R8)
308 FB_FORMAT_STR(GL_R8_SNORM)
309 FB_FORMAT_STR(GL_R16)
310 FB_FORMAT_STR(GL_R16_SNORM)
311 FB_FORMAT_STR(GL_RG8)
312 FB_FORMAT_STR(GL_RG8_SNORM)
313 FB_FORMAT_STR(GL_RG16)
314 FB_FORMAT_STR(GL_RG16_SNORM)
315 FB_FORMAT_STR(GL_R3_G3_B2)
316 FB_FORMAT_STR(GL_RGB4)
317 FB_FORMAT_STR(GL_RGB5)
318 FB_FORMAT_STR(GL_RGB8)
319 FB_FORMAT_STR(GL_RGB8_SNORM)
320 FB_FORMAT_STR(GL_RGB10)
321 FB_FORMAT_STR(GL_RGB12)
322 FB_FORMAT_STR(GL_RGB16_SNORM)
323 FB_FORMAT_STR(GL_RGBA2)
324 FB_FORMAT_STR(GL_RGBA4)
325 FB_FORMAT_STR(GL_RGB5_A1)
326 FB_FORMAT_STR(GL_RGBA8)
327 FB_FORMAT_STR(GL_RGBA8_SNORM)
328 FB_FORMAT_STR(GL_RGB10_A2)
329 FB_FORMAT_STR(GL_RGB10_A2UI)
330 FB_FORMAT_STR(GL_RGBA12)
331 FB_FORMAT_STR(GL_RGBA16)
332 FB_FORMAT_STR(GL_SRGB8)
333 FB_FORMAT_STR(GL_SRGB8_ALPHA8)
334 FB_FORMAT_STR(GL_R16F)
335 FB_FORMAT_STR(GL_RG16F)
336 FB_FORMAT_STR(GL_RGB16F)
337 FB_FORMAT_STR(GL_RGBA16F)
338 FB_FORMAT_STR(GL_R32F)
339 FB_FORMAT_STR(GL_RG32F)
340 FB_FORMAT_STR(GL_RGB32F)
341 FB_FORMAT_STR(GL_RGBA32F)
342 FB_FORMAT_STR(GL_R11F_G11F_B10F)
343 FB_FORMAT_STR(GL_RGB9_E5)
344 FB_FORMAT_STR(GL_R8I)
345 FB_FORMAT_STR(GL_R8UI)
346 FB_FORMAT_STR(GL_R16I)
347 FB_FORMAT_STR(GL_R16UI)
348 FB_FORMAT_STR(GL_R32I)
349 FB_FORMAT_STR(GL_R32UI)
350 FB_FORMAT_STR(GL_RG8I)
351 FB_FORMAT_STR(GL_RG8UI)
352 FB_FORMAT_STR(GL_RG16I)
353 FB_FORMAT_STR(GL_RG16UI)
354 FB_FORMAT_STR(GL_RG32I)
355 FB_FORMAT_STR(GL_RG32UI)
356 FB_FORMAT_STR(GL_RGB8I)
357 FB_FORMAT_STR(GL_RGB8UI)
358 FB_FORMAT_STR(GL_RGB16I)
359 FB_FORMAT_STR(GL_RGB16UI)
360 FB_FORMAT_STR(GL_RGB32I)
361 FB_FORMAT_STR(GL_RGB32UI)
362 FB_FORMAT_STR(GL_RGBA8I)
363 FB_FORMAT_STR(GL_RGBA8UI)
364 FB_FORMAT_STR(GL_RGBA16I)
365 FB_FORMAT_STR(GL_RGBA16UI)
366 FB_FORMAT_STR(GL_RGBA32I)
367 FB_FORMAT_STR(GL_RGBA32UI)
368 };
369
370 for( int i=0; i<vg_list_size(formats); i++ )
371 if( formats[i].e == format )
372 return formats[i].str;
373
374 return "UNDEFINED";
375 }
376
377 /*
378 * Bind and allocate texture for framebuffer attachment
379 */
380 VG_STATIC void render_fb_allocate_texture( struct framebuffer *fb,
381 struct framebuffer_attachment *a )
382 {
383 int rx, ry;
384 render_fb_get_current_res( fb, &rx, &ry );
385
386 if( a->purpose == k_framebuffer_attachment_type_renderbuffer )
387 {
388 glBindRenderbuffer( GL_RENDERBUFFER, a->id );
389 glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, rx, ry );
390 }
391 else if( a->purpose == k_framebuffer_attachment_type_colour )
392 {
393 glBindTexture( GL_TEXTURE_2D, a->id );
394 glTexImage2D( GL_TEXTURE_2D, 0, a->internalformat, rx, ry,
395 0, a->format, a->type, NULL );
396 }
397 }
398
399 /*
400 * Full allocation of a framebuffer
401 */
402 VG_STATIC void render_fb_allocate( struct framebuffer *fb )
403 {
404 glGenFramebuffers( 1, &fb->fb );
405 glBindFramebuffer( GL_FRAMEBUFFER, fb->fb );
406
407 int rx, ry;
408 render_fb_get_current_res( fb, &rx, &ry );
409
410 vg_info( "allocate_framebuffer( %s, %dx%d )\n", fb->display_name, rx, ry );
411 vg_info( "{\n" );
412
413 GLenum colour_attachments[4];
414 u32 colour_count = 0;
415
416 for( int j=0; j<vg_list_size(fb->attachments); j++ )
417 {
418 struct framebuffer_attachment *attachment = &fb->attachments[j];
419
420 if( attachment->purpose == k_framebuffer_attachment_type_none )
421 continue;
422
423 vg_info( " %s: %s\n",
424 render_fb_attachment_str( attachment->attachment ),
425 render_fb_format_str( attachment->internalformat ) );
426
427 if( attachment->purpose == k_framebuffer_attachment_type_renderbuffer )
428 {
429 glGenRenderbuffers( 1, &attachment->id );
430 render_fb_allocate_texture( fb, attachment );
431 glFramebufferRenderbuffer( GL_FRAMEBUFFER,
432 GL_DEPTH_STENCIL_ATTACHMENT,
433 GL_RENDERBUFFER, attachment->id );
434 }
435 else if( attachment->purpose == k_framebuffer_attachment_type_colour )
436 {
437 glGenTextures( 1, &attachment->id );
438 render_fb_allocate_texture( fb, attachment );
439 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
440 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
441 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
442 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
443
444 glFramebufferTexture2D( GL_FRAMEBUFFER, attachment->attachment,
445 GL_TEXTURE_2D, attachment->id, 0 );
446
447 colour_attachments[ colour_count ++ ] = attachment->attachment;
448 }
449 }
450
451 glDrawBuffers( colour_count, colour_attachments );
452
453 /*
454 * Check result
455 */
456 GLenum result = glCheckFramebufferStatus( GL_FRAMEBUFFER );
457
458 if( result == GL_FRAMEBUFFER_COMPLETE )
459 {
460 /*
461 * Attatch to gpipeline
462 */
463 if( fb->link )
464 *fb->link = fb;
465
466 vg_success( " status: complete\n" );
467 vg_info( "}\n" );
468 }
469 else
470 {
471 if( result == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT )
472 vg_error( " status: Incomplete attachment" );
473 else if( result == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT )
474 vg_error( " status: Missing attachment" );
475 else if( result == GL_FRAMEBUFFER_UNSUPPORTED )
476 vg_error( " status: Unsupported framebuffer format" );
477 else
478 vg_error( " status: Generic Error" );
479
480 vg_info( "}\n" );
481 vg_fatal_exit_loop( "Incomplete framebuffer (see logs)" );
482 }
483 }
484
485 /*
486 * Resize/Update all framebuffers(we know about)
487 */
488 VG_STATIC void render_fb_resize(void)
489 {
490 if( !gpipeline.ready )
491 return;
492
493 for( int i=0; i<vg_list_size(framebuffers); i++ )
494 {
495 struct framebuffer *fb = &framebuffers[i];
496 for( int j=0; j<vg_list_size(fb->attachments); j++ )
497 {
498 struct framebuffer_attachment *attachment = &fb->attachments[j];
499 render_fb_allocate_texture( fb, attachment );
500 }
501 }
502 }
503
504 VG_STATIC int render_framebuffer_control( int argc, char const *argv[] );
505 VG_STATIC void render_framebuffer_poll( int argc, char const *argv[] );
506 VG_STATIC void render_init_fs_quad(void)
507 {
508 vg_info( "[render] Allocate quad\n" );
509
510 float quad[] =
511 {
512 0.00f,0.00f, 1.00f,1.00f, 0.00f,1.00f,
513 0.00f,0.00f, 1.00f,0.00f, 1.00f,1.00f,
514
515 0.20f,0.00f, 0.80f,1.00f, 0.20f,1.00f,
516 0.20f,0.00f, 0.80f,0.00f, 0.80f,1.00f,
517
518 /* 9x9 debug grid */
519 /* row0 */
520 0.00f,0.00f, 0.30f,0.30f, 0.00f,0.30f,
521 0.00f,0.00f, 0.30f,0.00f, 0.30f,0.30f,
522 0.30f,0.00f, 0.60f,0.30f, 0.30f,0.30f,
523 0.30f,0.00f, 0.60f,0.00f, 0.60f,0.30f,
524 0.60f,0.00f, 0.90f,0.30f, 0.60f,0.30f,
525 0.60f,0.00f, 0.90f,0.00f, 0.90f,0.30f,
526 /* row1 */
527 0.00f,0.30f, 0.30f,0.60f, 0.00f,0.60f,
528 0.00f,0.30f, 0.30f,0.30f, 0.30f,0.60f,
529 0.30f,0.30f, 0.60f,0.60f, 0.30f,0.60f,
530 0.30f,0.30f, 0.60f,0.30f, 0.60f,0.60f,
531 0.60f,0.30f, 0.90f,0.60f, 0.60f,0.60f,
532 0.60f,0.30f, 0.90f,0.30f, 0.90f,0.60f,
533 /* row2 */
534 0.00f,0.60f, 0.30f,0.90f, 0.00f,0.90f,
535 0.00f,0.60f, 0.30f,0.60f, 0.30f,0.90f,
536 0.30f,0.60f, 0.60f,0.90f, 0.30f,0.90f,
537 0.30f,0.60f, 0.60f,0.60f, 0.60f,0.90f,
538 0.60f,0.60f, 0.90f,0.90f, 0.60f,0.90f,
539 0.60f,0.60f, 0.90f,0.60f, 0.90f,0.90f,
540 };
541
542 vg_function_push( (struct vg_cmd)
543 {
544 .name = "fb",
545 .function = render_framebuffer_control,
546 .poll_suggest = render_framebuffer_poll
547 });
548
549 glGenVertexArrays( 1, &gpipeline.fsquad.vao );
550 glGenBuffers( 1, &gpipeline.fsquad.vbo );
551 glBindVertexArray( gpipeline.fsquad.vao );
552 glBindBuffer( GL_ARRAY_BUFFER, gpipeline.fsquad.vbo );
553 glBufferData( GL_ARRAY_BUFFER, sizeof(quad), quad, GL_STATIC_DRAW );
554 glBindVertexArray( gpipeline.fsquad.vao );
555 glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE,
556 sizeof(float)*2, (void*)0 );
557 glEnableVertexAttribArray( 0 );
558
559 VG_CHECK_GL_ERR();
560 }
561
562 VG_STATIC void render_init(void)
563 {
564 shader_blit_register();
565 shader_blitblur_register();
566 shader_blitcolour_register();
567
568 vg_acquire_thread_sync();
569 {
570 /*
571 * Complete Framebuffers
572 */
573 for( int i=0; i<vg_list_size(framebuffers); i++ )
574 {
575 struct framebuffer *fb = &framebuffers[i];
576 render_fb_allocate( fb );
577 }
578
579 render_init_fs_quad();
580
581 glBindFramebuffer( GL_FRAMEBUFFER, 0 );
582 gpipeline.ready = 1;
583 }
584
585 vg_release_thread_sync();
586 }
587
588 /*
589 * Utility
590 */
591 VG_STATIC void render_fsquad(void)
592 {
593 glBindVertexArray( gpipeline.fsquad.vao );
594 glDrawArrays( GL_TRIANGLES, 0, 6 );
595 }
596
597 VG_STATIC void render_fsquad1(void)
598 {
599 glBindVertexArray( gpipeline.fsquad.vao );
600 glDrawArrays( GL_TRIANGLES, 6, 6 );
601 }
602
603 /*
604 * Call this inside the UI function
605 */
606 VG_STATIC void render_view_framebuffer_ui(void)
607 {
608 int viewing_count = 0;
609
610 glBindVertexArray( gpipeline.fsquad.vao );
611 shader_blit_use();
612 shader_blit_uTexMain( 0 );
613
614 for( int i=0; i<vg_list_size(framebuffers); i++ )
615 {
616 struct framebuffer *fb = &framebuffers[i];
617
618 for( int j=0; j<vg_list_size(fb->attachments); j++ )
619 {
620 struct framebuffer_attachment *at = &fb->attachments[j];
621
622 if( !at->debug_view )
623 continue;
624
625 v2f corner,
626 window = { vg.window_x, vg.window_y };
627
628 corner[0] = viewing_count % 3;
629 corner[1] = 1 + (viewing_count / 3);
630 v2_mul( corner, window, corner );
631 v2_muls( corner, 0.3f, corner );
632 corner[1] = vg.window_y - corner[1];
633
634 ui_text( (ui_rect){ corner[0], corner[1], 0.0f, 0.0f },
635 fb->display_name, 2, k_text_align_left );
636 ui_text( (ui_rect){ corner[0], corner[1] + 32, 0.0f, 0.0f, },
637 at->display_name, 1, k_text_align_left );
638
639 if( at->purpose == k_framebuffer_attachment_type_renderbuffer )
640 {
641 v2f center;
642 v2_muladds( corner, window, 0.15f, center );
643
644 ui_text( (ui_rect){ center[0], center[1], 0.0f, 0.0f },
645 "<hardware texture>", 1, k_text_align_center );
646 }
647 else
648 {
649 render_fb_bind_texture( fb, j, 0 );
650
651 int start = (viewing_count+2) * 6,
652 count = 6;
653 glDrawArrays( GL_TRIANGLES, start, count );
654 }
655
656 viewing_count ++;
657 }
658 }
659 }
660
661 VG_STATIC void render_framebuffer_show( struct framebuffer *fb,
662 struct framebuffer_attachment *at,
663 int operation )
664 {
665 at->debug_view = operation;
666 vg_info( "%s %s:%s\n", (operation?"shown": "hidden"),
667 fb->display_name, at->display_name );
668 }
669
670 /*
671 * arg0: command "show"/"hide"
672 * arg1: framebuffer name <name>/"all"
673 * arg2: subname <name>/none
674 */
675 VG_STATIC int render_framebuffer_control( int argc, char const *argv[] )
676 {
677 if( argc < 2 )
678 {
679 vg_error( "Usage: fb \"show/hide\" <name>/\"all\" <name>/none\n" );
680 return 0;
681 }
682
683 int modify_all = 0,
684 operation = 0;
685
686 if( !strcmp( argv[0], "show" ) )
687 operation = 1;
688 else if( !strcmp( argv[0], "hide" ) )
689 operation = 0;
690 else
691 {
692 vg_error( "Unknown framebuffer operation: '%s'\n", argv[0] );
693 return 0;
694 }
695
696 if( !strcmp( argv[1], "all" ) )
697 modify_all = 1;
698
699 for( int i=0; i<vg_list_size(framebuffers); i++ )
700 {
701 struct framebuffer *fb = &framebuffers[i];
702
703 for( int j=0; j<vg_list_size(fb->attachments); j++ )
704 {
705 struct framebuffer_attachment *at = &fb->attachments[j];
706
707 if( at->purpose == k_framebuffer_attachment_type_none )
708 continue;
709
710 if( modify_all )
711 {
712 render_framebuffer_show( fb, at, operation );
713 }
714 else
715 {
716 if( !strcmp( fb->display_name, argv[1] ) )
717 {
718 if( argc == 2 )
719 render_framebuffer_show( fb, at, operation );
720 else if( !strcmp( at->display_name, argv[2] ) )
721 render_framebuffer_show( fb, at, operation );
722 }
723 }
724 }
725 }
726
727 return 0;
728 }
729
730 VG_STATIC void render_framebuffer_poll( int argc, char const *argv[] )
731 {
732 const char *term = argv[argc-1];
733
734 if( argc == 1 )
735 {
736 console_suggest_score_text( "show", term, 0 );
737 console_suggest_score_text( "hide", term, 0 );
738 }
739 else if( argc == 2 )
740 {
741 console_suggest_score_text( "all", term, 0 );
742
743 for( int i=0; i<vg_list_size(framebuffers); i++ )
744 {
745 struct framebuffer *fb = &framebuffers[i];
746 console_suggest_score_text( fb->display_name, term, 0 );
747 }
748 }
749 else if( argc == 3 )
750 {
751 int modify_all = 0;
752
753 if( !strcmp( argv[1], "all" ) )
754 modify_all = 1;
755
756 for( int i=0; i<vg_list_size(framebuffers); i++ )
757 {
758 struct framebuffer *fb = &framebuffers[i];
759
760 for( int j=0; j<vg_list_size(fb->attachments); j++ )
761 {
762 struct framebuffer_attachment *at = &fb->attachments[j];
763
764 if( at->purpose == k_framebuffer_attachment_type_none )
765 continue;
766
767 if( modify_all )
768 {
769 console_suggest_score_text( at->display_name, term, 0 );
770 }
771 else if( !strcmp( fb->display_name, argv[1] ) )
772 {
773 console_suggest_score_text( at->display_name, term, 0 );
774 }
775 }
776 }
777 }
778 }
779
780 #endif /* RENDER_H */