2 * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
9 #include "shaders/blit.h"
10 #include "shaders/blitblur.h"
11 #include "shaders/standard.h"
12 #include "shaders/vblend.h"
14 VG_STATIC
void render_water_texture( camera
*cam
);
15 VG_STATIC
void render_water_surface( camera
*cam
);
16 VG_STATIC
void render_world( camera
*cam
);
17 VG_STATIC
void shader_link_standard_ub( GLuint shader
, int texture_id
);
18 VG_STATIC
void render_world_depth( camera
*cam
);
23 typedef struct framebuffer framebuffer
;
27 * All standard buffers used in rendering
29 VG_STATIC
struct pipeline
39 struct ub_world_lighting
42 v4f g_light_colours
[3],
43 g_light_directions
[3],
64 float shadow_spread
, shadow_length
;
65 GLuint ubo_world_lighting
,
76 .colour
= { 1.36f
, 1.35f
, 1.01f
},
77 .dir
= { 0.63f
, -0.08f
}
81 .colour
= { 0.33f
, 0.56f
, 0.64f
},
82 .dir
= { -2.60f
, -0.13f
}
86 .colour
= { 0.05f
, 0.05f
, 0.23f
},
87 .dir
= { 2.60f
, -0.84f
}
90 .shadow_spread
= 0.65f
,
91 .shadow_length
= 9.50f
,
95 .g_ambient_colour
= { 0.09f
, 0.03f
, 0.07f
}
101 const char *display_name
;
106 struct framebuffer_attachment
108 const char *display_name
;
110 enum framebuffer_attachment_type
112 k_framebuffer_attachment_type_none
,
113 k_framebuffer_attachment_type_colour
,
114 k_framebuffer_attachment_type_renderbuffer
118 enum framebuffer_quality_profile
120 k_framebuffer_quality_all
,
121 k_framebuffer_quality_high_only
125 GLenum internalformat
,
143 * The primary draw target
146 .link
= &gpipeline
.fb_main
,
151 "colour", k_framebuffer_attachment_type_colour
,
153 .internalformat
= GL_RGB
,
155 .type
= GL_UNSIGNED_BYTE
,
156 .attachment
= GL_COLOR_ATTACHMENT0
159 "motion", k_framebuffer_attachment_type_colour
,
161 .quality
= k_framebuffer_quality_high_only
,
162 .internalformat
= GL_RG16F
,
165 .attachment
= GL_COLOR_ATTACHMENT1
168 "depth_stencil", k_framebuffer_attachment_type_renderbuffer
,
170 .internalformat
= GL_DEPTH24_STENCIL8
,
171 .attachment
= GL_DEPTH_STENCIL_ATTACHMENT
177 * A ortho projection of the world, used for shadows and ocean colouring.
178 * Note: it does not have a render buffer attachement because it's
179 * intended to be drawn to in a MAX blending mode
182 .link
= &gpipeline
.fb_heightmap
,
189 "depth", k_framebuffer_attachment_type_colour
,
191 .internalformat
= GL_R32F
,
194 .attachment
= GL_COLOR_ATTACHMENT0
200 * Second rendered view from the perspective of the water reflection
203 .link
= &gpipeline
.fb_water_reflection
,
208 "colour", k_framebuffer_attachment_type_colour
,
209 .internalformat
= GL_RGB
,
211 .type
= GL_UNSIGNED_BYTE
,
212 .attachment
= GL_COLOR_ATTACHMENT0
215 "depth_stencil", k_framebuffer_attachment_type_renderbuffer
,
217 .internalformat
= GL_DEPTH24_STENCIL8
,
218 .attachment
= GL_DEPTH_STENCIL_ATTACHMENT
224 * Thid rendered view from the perspective of the camera, but just
225 * captures stuff thats under the water
228 .link
= &gpipeline
.fb_water_beneath
,
233 "colour", k_framebuffer_attachment_type_colour
,
234 .internalformat
= GL_RGBA
,
236 .type
= GL_UNSIGNED_BYTE
,
237 .attachment
= GL_COLOR_ATTACHMENT0
240 "depth_stencil", k_framebuffer_attachment_type_renderbuffer
,
242 .internalformat
= GL_DEPTH24_STENCIL8
,
243 .attachment
= GL_DEPTH_STENCIL_ATTACHMENT
250 * Get the current (automatically scaled or fixed) resolution of framebuffer
252 VG_STATIC
void render_fb_get_current_res( struct framebuffer
*fb
,
255 if( fb
->resolution_div
)
257 *x
= vg
.window_x
/ fb
->resolution_div
;
258 *y
= vg
.window_y
/ fb
->resolution_div
;
268 * Bind framebuffer for drawing to
270 VG_STATIC
void render_fb_bind( framebuffer
*fb
)
273 render_fb_get_current_res( fb
, &x
, &y
);
274 glBindFramebuffer( GL_FRAMEBUFFER
, fb
->fb
);
275 glViewport( 0, 0, x
, y
);
279 * Bind framebuffer attachment's texture
281 VG_STATIC
void render_fb_bind_texture( framebuffer
*fb
,
282 int attachment
, int slot
)
284 struct framebuffer_attachment
*at
= &fb
->attachments
[attachment
];
286 if( at
->purpose
!= k_framebuffer_attachment_type_colour
)
288 vg_fatal_exit_loop( "illegal operation: bind non-colour framebuffer"
289 " attachment to texture slot" );
292 glActiveTexture( GL_TEXTURE0
+ slot
);
293 glBindTexture( GL_TEXTURE_2D
, fb
->attachments
[attachment
].id
);
300 VG_STATIC
void shader_link_standard_ub( GLuint shader
, int texture_id
)
302 GLuint idx
= glGetUniformBlockIndex( shader
, "ub_world_lighting" );
303 glUniformBlockBinding( shader
, idx
, 0 );
305 render_fb_bind_texture( gpipeline
.fb_heightmap
, 0, texture_id
);
306 glUniform1i( glGetUniformLocation( shader
, "g_world_depth" ), texture_id
);
309 VG_STATIC
void render_update_lighting_ub(void)
311 struct ub_world_lighting
*winf
= &gpipeline
.ub_world_lighting
;
314 for( int i
=0; i
<3; i
++ )
316 struct light_widget
*lw
= &gpipeline
.widgets
[i
];
320 float pitch
= lw
->dir
[0],
324 v3_copy( (v3f
){ xz
*cosf(yaw
), sinf(pitch
), xz
*sinf(yaw
) },
325 winf
->g_light_directions
[c
] );
326 v3_copy( lw
->colour
, winf
->g_light_colours
[c
] );
332 winf
->g_light_count
= c
;
333 winf
->g_light_directions
[0][3] = gpipeline
.shadow_length
;
334 winf
->g_light_colours
[0][3] = gpipeline
.shadow_spread
;
336 if( vg
.quality_profile
== k_quality_profile_low
)
337 winf
->g_shadow_samples
= 0;
339 winf
->g_shadow_samples
= 8;
341 glBindBuffer( GL_UNIFORM_BUFFER
, gpipeline
.ubo_world_lighting
);
342 glBufferSubData( GL_UNIFORM_BUFFER
, 0, sizeof(struct ub_world_lighting
),
343 &gpipeline
.ub_world_lighting
);
346 #define FB_FORMAT_STR( E ) { E, #E },
349 * Convert OpenGL attachment ID enum to string
351 VG_STATIC
const char *render_fb_attachment_str( GLenum e
)
353 struct { GLenum e
; const char *str
; }
356 FB_FORMAT_STR(GL_COLOR_ATTACHMENT0
)
357 FB_FORMAT_STR(GL_COLOR_ATTACHMENT1
)
358 FB_FORMAT_STR(GL_COLOR_ATTACHMENT2
)
359 FB_FORMAT_STR(GL_COLOR_ATTACHMENT3
)
360 FB_FORMAT_STR(GL_COLOR_ATTACHMENT4
)
361 FB_FORMAT_STR(GL_DEPTH_STENCIL_ATTACHMENT
)
364 for( int i
=0; i
<vg_list_size(formats
); i
++ )
365 if( formats
[i
].e
== e
)
366 return formats
[i
].str
;
372 * Convert OpenGL texture format enums from TexImage2D table 1,2 &
373 * RenderBufferStorage Table 1, into strings
375 VG_STATIC
const char *render_fb_format_str( GLenum format
)
377 struct { GLenum e
; const char *str
; }
381 FB_FORMAT_STR(GL_DEPTH_COMPONENT
)
382 FB_FORMAT_STR(GL_DEPTH_STENCIL
)
383 FB_FORMAT_STR(GL_RED
)
385 FB_FORMAT_STR(GL_RGB
)
386 FB_FORMAT_STR(GL_RGBA
)
388 /* Render buffer formats */
389 FB_FORMAT_STR(GL_DEPTH_COMPONENT16
)
390 FB_FORMAT_STR(GL_DEPTH_COMPONENT24
)
391 FB_FORMAT_STR(GL_DEPTH_COMPONENT32F
)
392 FB_FORMAT_STR(GL_DEPTH24_STENCIL8
)
393 FB_FORMAT_STR(GL_DEPTH32F_STENCIL8
)
394 FB_FORMAT_STR(GL_STENCIL_INDEX8
)
398 FB_FORMAT_STR(GL_R8_SNORM
)
399 FB_FORMAT_STR(GL_R16
)
400 FB_FORMAT_STR(GL_R16_SNORM
)
401 FB_FORMAT_STR(GL_RG8
)
402 FB_FORMAT_STR(GL_RG8_SNORM
)
403 FB_FORMAT_STR(GL_RG16
)
404 FB_FORMAT_STR(GL_RG16_SNORM
)
405 FB_FORMAT_STR(GL_R3_G3_B2
)
406 FB_FORMAT_STR(GL_RGB4
)
407 FB_FORMAT_STR(GL_RGB5
)
408 FB_FORMAT_STR(GL_RGB8
)
409 FB_FORMAT_STR(GL_RGB8_SNORM
)
410 FB_FORMAT_STR(GL_RGB10
)
411 FB_FORMAT_STR(GL_RGB12
)
412 FB_FORMAT_STR(GL_RGB16_SNORM
)
413 FB_FORMAT_STR(GL_RGBA2
)
414 FB_FORMAT_STR(GL_RGBA4
)
415 FB_FORMAT_STR(GL_RGB5_A1
)
416 FB_FORMAT_STR(GL_RGBA8
)
417 FB_FORMAT_STR(GL_RGBA8_SNORM
)
418 FB_FORMAT_STR(GL_RGB10_A2
)
419 FB_FORMAT_STR(GL_RGB10_A2UI
)
420 FB_FORMAT_STR(GL_RGBA12
)
421 FB_FORMAT_STR(GL_RGBA16
)
422 FB_FORMAT_STR(GL_SRGB8
)
423 FB_FORMAT_STR(GL_SRGB8_ALPHA8
)
424 FB_FORMAT_STR(GL_R16F
)
425 FB_FORMAT_STR(GL_RG16F
)
426 FB_FORMAT_STR(GL_RGB16F
)
427 FB_FORMAT_STR(GL_RGBA16F
)
428 FB_FORMAT_STR(GL_R32F
)
429 FB_FORMAT_STR(GL_RG32F
)
430 FB_FORMAT_STR(GL_RGB32F
)
431 FB_FORMAT_STR(GL_RGBA32F
)
432 FB_FORMAT_STR(GL_R11F_G11F_B10F
)
433 FB_FORMAT_STR(GL_RGB9_E5
)
434 FB_FORMAT_STR(GL_R8I
)
435 FB_FORMAT_STR(GL_R8UI
)
436 FB_FORMAT_STR(GL_R16I
)
437 FB_FORMAT_STR(GL_R16UI
)
438 FB_FORMAT_STR(GL_R32I
)
439 FB_FORMAT_STR(GL_R32UI
)
440 FB_FORMAT_STR(GL_RG8I
)
441 FB_FORMAT_STR(GL_RG8UI
)
442 FB_FORMAT_STR(GL_RG16I
)
443 FB_FORMAT_STR(GL_RG16UI
)
444 FB_FORMAT_STR(GL_RG32I
)
445 FB_FORMAT_STR(GL_RG32UI
)
446 FB_FORMAT_STR(GL_RGB8I
)
447 FB_FORMAT_STR(GL_RGB8UI
)
448 FB_FORMAT_STR(GL_RGB16I
)
449 FB_FORMAT_STR(GL_RGB16UI
)
450 FB_FORMAT_STR(GL_RGB32I
)
451 FB_FORMAT_STR(GL_RGB32UI
)
452 FB_FORMAT_STR(GL_RGBA8I
)
453 FB_FORMAT_STR(GL_RGBA8UI
)
454 FB_FORMAT_STR(GL_RGBA16I
)
455 FB_FORMAT_STR(GL_RGBA16UI
)
456 FB_FORMAT_STR(GL_RGBA32I
)
457 FB_FORMAT_STR(GL_RGBA32UI
)
460 for( int i
=0; i
<vg_list_size(formats
); i
++ )
461 if( formats
[i
].e
== format
)
462 return formats
[i
].str
;
468 * Bind and allocate texture for framebuffer attachment
470 VG_STATIC
void render_fb_allocate_texture( struct framebuffer
*fb
,
471 struct framebuffer_attachment
*a
)
474 render_fb_get_current_res( fb
, &rx
, &ry
);
476 if( a
->purpose
== k_framebuffer_attachment_type_renderbuffer
)
478 glBindRenderbuffer( GL_RENDERBUFFER
, a
->id
);
479 glRenderbufferStorage( GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, rx
, ry
);
481 else if( a
->purpose
== k_framebuffer_attachment_type_colour
)
483 glBindTexture( GL_TEXTURE_2D
, a
->id
);
484 glTexImage2D( GL_TEXTURE_2D
, 0, a
->internalformat
, rx
, ry
,
485 0, a
->format
, a
->type
, NULL
);
490 * Full allocation of a framebuffer
492 VG_STATIC
void render_fb_allocate( struct framebuffer
*fb
)
494 glGenFramebuffers( 1, &fb
->fb
);
495 glBindFramebuffer( GL_FRAMEBUFFER
, fb
->fb
);
498 render_fb_get_current_res( fb
, &rx
, &ry
);
500 vg_info( "allocate_framebuffer( %s, %dx%d )\n", fb
->display_name
, rx
, ry
);
503 GLenum colour_attachments
[4];
504 u32 colour_count
= 0;
506 for( int j
=0; j
<vg_list_size(fb
->attachments
); j
++ )
508 struct framebuffer_attachment
*attachment
= &fb
->attachments
[j
];
510 if( attachment
->purpose
== k_framebuffer_attachment_type_none
)
513 vg_info( " %s: %s\n",
514 render_fb_attachment_str( attachment
->attachment
),
515 render_fb_format_str( attachment
->internalformat
) );
517 if( attachment
->purpose
== k_framebuffer_attachment_type_renderbuffer
)
519 glGenRenderbuffers( 1, &attachment
->id
);
520 render_fb_allocate_texture( fb
, attachment
);
521 glFramebufferRenderbuffer( GL_FRAMEBUFFER
,
522 GL_DEPTH_STENCIL_ATTACHMENT
,
523 GL_RENDERBUFFER
, attachment
->id
);
525 else if( attachment
->purpose
== k_framebuffer_attachment_type_colour
)
527 glGenTextures( 1, &attachment
->id
);
528 render_fb_allocate_texture( fb
, attachment
);
529 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
530 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
531 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
532 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
534 glFramebufferTexture2D( GL_FRAMEBUFFER
, attachment
->attachment
,
535 GL_TEXTURE_2D
, attachment
->id
, 0 );
537 colour_attachments
[ colour_count
++ ] = attachment
->attachment
;
541 glDrawBuffers( colour_count
, colour_attachments
);
546 GLenum result
= glCheckFramebufferStatus( GL_FRAMEBUFFER
);
548 if( result
== GL_FRAMEBUFFER_COMPLETE
)
551 * Attatch to gpipeline
556 vg_success( " status: complete\n" );
561 if( result
== GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
)
562 vg_error( " status: Incomplete attachment" );
563 else if( result
== GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
)
564 vg_error( " status: Missing attachment" );
565 else if( result
== GL_FRAMEBUFFER_UNSUPPORTED
)
566 vg_error( " status: Unsupported framebuffer format" );
568 vg_error( " status: Generic Error" );
571 vg_fatal_exit_loop( "Incomplete framebuffer (see logs)" );
576 * Resize/Update all framebuffers(we know about)
578 VG_STATIC
void render_fb_resize(void)
580 if( !gpipeline
.ready
)
583 for( int i
=0; i
<vg_list_size(framebuffers
); i
++ )
585 struct framebuffer
*fb
= &framebuffers
[i
];
586 for( int j
=0; j
<vg_list_size(fb
->attachments
); j
++ )
588 struct framebuffer_attachment
*attachment
= &fb
->attachments
[j
];
589 render_fb_allocate_texture( fb
, attachment
);
594 VG_STATIC
int render_framebuffer_control( int argc
, char const *argv
[] );
595 VG_STATIC
void render_framebuffer_poll( int argc
, char const *argv
[] );
596 VG_STATIC
void render_init_fs_quad(void)
598 vg_info( "[render] Allocate quad\n" );
602 0.00f
,0.00f
, 1.00f
,1.00f
, 0.00f
,1.00f
,
603 0.00f
,0.00f
, 1.00f
,0.00f
, 1.00f
,1.00f
,
605 0.20f
,0.00f
, 0.80f
,1.00f
, 0.20f
,1.00f
,
606 0.20f
,0.00f
, 0.80f
,0.00f
, 0.80f
,1.00f
,
610 0.00f
,0.00f
, 0.30f
,0.30f
, 0.00f
,0.30f
,
611 0.00f
,0.00f
, 0.30f
,0.00f
, 0.30f
,0.30f
,
612 0.30f
,0.00f
, 0.60f
,0.30f
, 0.30f
,0.30f
,
613 0.30f
,0.00f
, 0.60f
,0.00f
, 0.60f
,0.30f
,
614 0.60f
,0.00f
, 0.90f
,0.30f
, 0.60f
,0.30f
,
615 0.60f
,0.00f
, 0.90f
,0.00f
, 0.90f
,0.30f
,
617 0.00f
,0.30f
, 0.30f
,0.60f
, 0.00f
,0.60f
,
618 0.00f
,0.30f
, 0.30f
,0.30f
, 0.30f
,0.60f
,
619 0.30f
,0.30f
, 0.60f
,0.60f
, 0.30f
,0.60f
,
620 0.30f
,0.30f
, 0.60f
,0.30f
, 0.60f
,0.60f
,
621 0.60f
,0.30f
, 0.90f
,0.60f
, 0.60f
,0.60f
,
622 0.60f
,0.30f
, 0.90f
,0.30f
, 0.90f
,0.60f
,
624 0.00f
,0.60f
, 0.30f
,0.90f
, 0.00f
,0.90f
,
625 0.00f
,0.60f
, 0.30f
,0.60f
, 0.30f
,0.90f
,
626 0.30f
,0.60f
, 0.60f
,0.90f
, 0.30f
,0.90f
,
627 0.30f
,0.60f
, 0.60f
,0.60f
, 0.60f
,0.90f
,
628 0.60f
,0.60f
, 0.90f
,0.90f
, 0.60f
,0.90f
,
629 0.60f
,0.60f
, 0.90f
,0.60f
, 0.90f
,0.90f
,
632 vg_function_push( (struct vg_cmd
)
635 .function
= render_framebuffer_control
,
636 .poll_suggest
= render_framebuffer_poll
639 glGenVertexArrays( 1, &gpipeline
.fsquad
.vao
);
640 glGenBuffers( 1, &gpipeline
.fsquad
.vbo
);
641 glBindVertexArray( gpipeline
.fsquad
.vao
);
642 glBindBuffer( GL_ARRAY_BUFFER
, gpipeline
.fsquad
.vbo
);
643 glBufferData( GL_ARRAY_BUFFER
, sizeof(quad
), quad
, GL_STATIC_DRAW
);
644 glBindVertexArray( gpipeline
.fsquad
.vao
);
645 glVertexAttribPointer( 0, 2, GL_FLOAT
, GL_FALSE
,
646 sizeof(float)*2, (void*)0 );
647 glEnableVertexAttribArray( 0 );
652 VG_STATIC
void render_init_uniform_buffers(void)
654 vg_info( "[render] Allocate uniform buffer\n" );
656 glGenBuffers( 1, &gpipeline
.ubo_world_lighting
);
657 glBindBuffer( GL_UNIFORM_BUFFER
, gpipeline
.ubo_world_lighting
);
658 glBufferData( GL_UNIFORM_BUFFER
, sizeof(struct ub_world_lighting
),
659 NULL
, GL_DYNAMIC_DRAW
);
661 render_update_lighting_ub();
662 glBindBufferBase( GL_UNIFORM_BUFFER
, 0, gpipeline
.ubo_world_lighting
);
667 VG_STATIC
void render_init(void)
669 shader_blit_register();
670 shader_blitblur_register();
671 shader_standard_register();
672 shader_vblend_register();
674 vg_acquire_thread_sync();
677 * Complete Framebuffers
679 for( int i
=0; i
<vg_list_size(framebuffers
); i
++ )
681 struct framebuffer
*fb
= &framebuffers
[i
];
682 render_fb_allocate( fb
);
685 render_init_fs_quad();
686 render_init_uniform_buffers();
688 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
692 vg_release_thread_sync();
698 VG_STATIC
void render_fsquad(void)
700 glBindVertexArray( gpipeline
.fsquad
.vao
);
701 glDrawArrays( GL_TRIANGLES
, 0, 6 );
704 VG_STATIC
void render_fsquad1(void)
706 glBindVertexArray( gpipeline
.fsquad
.vao
);
707 glDrawArrays( GL_TRIANGLES
, 6, 6 );
711 * Call this inside the UI function
713 VG_STATIC
void render_view_framebuffer_ui(void)
715 int viewing_count
= 0;
717 glBindVertexArray( gpipeline
.fsquad
.vao
);
719 shader_blit_uTexMain( 0 );
721 for( int i
=0; i
<vg_list_size(framebuffers
); i
++ )
723 struct framebuffer
*fb
= &framebuffers
[i
];
725 for( int j
=0; j
<vg_list_size(fb
->attachments
); j
++ )
727 struct framebuffer_attachment
*at
= &fb
->attachments
[j
];
729 if( !at
->debug_view
)
733 window
= { vg
.window_x
, vg
.window_y
};
735 corner
[0] = viewing_count
% 3;
736 corner
[1] = 1 + (viewing_count
/ 3);
737 v2_mul( corner
, window
, corner
);
738 v2_muls( corner
, 0.3f
, corner
);
739 corner
[1] = vg
.window_y
- corner
[1];
741 ui_text( (ui_rect
){ corner
[0], corner
[1], 0.0f
, 0.0f
},
742 fb
->display_name
, 2, k_text_align_left
);
743 ui_text( (ui_rect
){ corner
[0], corner
[1] + 32, 0.0f
, 0.0f
, },
744 at
->display_name
, 1, k_text_align_left
);
746 if( at
->purpose
== k_framebuffer_attachment_type_renderbuffer
)
749 v2_muladds( corner
, window
, 0.15f
, center
);
751 ui_text( (ui_rect
){ center
[0], center
[1], 0.0f
, 0.0f
},
752 "<hardware texture>", 1, k_text_align_center
);
756 render_fb_bind_texture( fb
, j
, 0 );
758 int start
= (viewing_count
+2) * 6,
760 glDrawArrays( GL_TRIANGLES
, start
, count
);
768 VG_STATIC
void render_framebuffer_show( struct framebuffer
*fb
,
769 struct framebuffer_attachment
*at
,
772 at
->debug_view
= operation
;
773 vg_info( "%s %s:%s\n", (operation
?"shown": "hidden"),
774 fb
->display_name
, at
->display_name
);
778 * arg0: command "show"/"hide"
779 * arg1: framebuffer name <name>/"all"
780 * arg2: subname <name>/none
782 VG_STATIC
int render_framebuffer_control( int argc
, char const *argv
[] )
786 vg_error( "Usage: fb \"show/hide\" <name>/\"all\" <name>/none\n" );
793 if( !strcmp( argv
[0], "show" ) )
795 else if( !strcmp( argv
[0], "hide" ) )
799 vg_error( "Unknown framebuffer operation: '%s'\n", argv
[0] );
803 if( !strcmp( argv
[1], "all" ) )
806 for( int i
=0; i
<vg_list_size(framebuffers
); i
++ )
808 struct framebuffer
*fb
= &framebuffers
[i
];
810 for( int j
=0; j
<vg_list_size(fb
->attachments
); j
++ )
812 struct framebuffer_attachment
*at
= &fb
->attachments
[j
];
814 if( at
->purpose
== k_framebuffer_attachment_type_none
)
819 render_framebuffer_show( fb
, at
, operation
);
823 if( !strcmp( fb
->display_name
, argv
[1] ) )
826 render_framebuffer_show( fb
, at
, operation
);
827 else if( !strcmp( at
->display_name
, argv
[2] ) )
828 render_framebuffer_show( fb
, at
, operation
);
837 VG_STATIC
void render_framebuffer_poll( int argc
, char const *argv
[] )
839 const char *term
= argv
[argc
-1];
843 console_suggest_score_text( "show", term
, 0 );
844 console_suggest_score_text( "hide", term
, 0 );
848 console_suggest_score_text( "all", term
, 0 );
850 for( int i
=0; i
<vg_list_size(framebuffers
); i
++ )
852 struct framebuffer
*fb
= &framebuffers
[i
];
853 console_suggest_score_text( fb
->display_name
, term
, 0 );
860 if( !strcmp( argv
[1], "all" ) )
863 for( int i
=0; i
<vg_list_size(framebuffers
); i
++ )
865 struct framebuffer
*fb
= &framebuffers
[i
];
867 for( int j
=0; j
<vg_list_size(fb
->attachments
); j
++ )
869 struct framebuffer_attachment
*at
= &fb
->attachments
[j
];
871 if( at
->purpose
== k_framebuffer_attachment_type_none
)
876 console_suggest_score_text( at
->display_name
, term
, 0 );
878 else if( !strcmp( fb
->display_name
, argv
[1] ) )
880 console_suggest_score_text( at
->display_name
, term
, 0 );
887 #endif /* RENDER_H */