Merge all features from glider feature branch
[carveJwlIkooP6JGAAIwe30JlM.git] / render.h
index f17018bb2e767006dbd6701c355a7f5e9dd5b33b..22c05726ddd0222a7b567e6b47c1c87ddea18540 100644 (file)
--- a/render.h
+++ b/render.h
 #include "shaders/blit.h"
 #include "shaders/blitblur.h"
 #include "shaders/blitcolour.h"
+#include "shaders/blit_transition.h"
 
-#if 0
-#include "shaders/standard.h"
-#include "shaders/vblend.h"
-#endif
-
-VG_STATIC void render_water_texture( world_instance *world, camera *cam,
-                                     int layer_depth );
-VG_STATIC void render_water_surface( world_instance *world, camera *cam );
-VG_STATIC void render_world( world_instance *world, camera *cam,
-                             int layer_depth );
-VG_STATIC void render_world_depth( world_instance *world, camera *cam );
-
+#define WORKSHOP_PREVIEW_WIDTH  504
+#define WORKSHOP_PREVIEW_HEIGHT 336
 #ifndef RENDER_H
 #define RENDER_H
 
-typedef struct framebuffer framebuffer;
+static f32 k_render_scale  = 1.0f;
+static i32 k_blur_effect   = 1;
+static f32 k_blur_strength = 0.3f;
+static f32 k_fov           = 0.86f;
+static f32 k_cam_height    = 0.8f;
 
+typedef struct framebuffer framebuffer;
 
 /* 
  * All standard buffers used in rendering
  */
-VG_STATIC struct pipeline
-{
+static struct pipeline{
    glmesh fsquad;
 
    framebuffer *fb_main,
                *fb_water_reflection,
-               *fb_water_beneath;
-
-   struct light_widget
-   {
-      int enabled;
-      v2f dir;
-      v3f colour;
-   } 
-   widgets[3];
-
-   float shadow_spread, shadow_length;
-
+               *fb_water_beneath,
+               *fb_workshop_preview,
+               *fb_network_status;
    int ready;
 }
-gpipeline =
-{
-   .widgets =
-   {
-      {
-         .enabled = 1,
-         .colour = { 1.36f, 1.35f, 1.01f },
-         .dir = { 0.63f, -0.08f }
-      },
-      {
-         .enabled = 1,
-         .colour = { 0.33f, 0.56f, 0.64f },
-         .dir = { -2.60f, -0.13f }
-      },
-      {
-         .enabled = 1,
-         .colour = { 0.05f, 0.05f, 0.23f },
-         .dir = { 2.60f, -0.84f }
-      }
-   },
-   .shadow_spread = 0.65f,
-   .shadow_length = 9.50f,
-};
+gpipeline;
 
-struct framebuffer
-{
+struct framebuffer{
    const char *display_name;
-   int         resolution_div,
+   int         resolution_div,   /* definition */
                fixed_w,
-               fixed_h;
+               fixed_h,
 
-   struct framebuffer_attachment
-   {
+               render_w,         /* runtime */
+               render_h;
+
+   struct framebuffer_attachment{
       const char *display_name;
       
-      enum framebuffer_attachment_type
-      {
+      enum framebuffer_attachment_type{
          k_framebuffer_attachment_type_none,
-         k_framebuffer_attachment_type_colour,
-         k_framebuffer_attachment_type_renderbuffer
+         k_framebuffer_attachment_type_texture,
+         k_framebuffer_attachment_type_renderbuffer,
+         k_framebuffer_attachment_type_texture_depth
       }
       purpose;
 
-      enum framebuffer_quality_profile
-      {
+      enum framebuffer_quality_profile{
          k_framebuffer_quality_all,
          k_framebuffer_quality_high_only
       }
@@ -128,7 +92,7 @@ framebuffers[] =
       .attachments = 
       {
          {
-            "colour", k_framebuffer_attachment_type_colour,
+            "colour", k_framebuffer_attachment_type_texture,
 
             .internalformat = GL_RGB,
             .format         = GL_RGB,
@@ -136,7 +100,7 @@ framebuffers[] =
             .attachment     = GL_COLOR_ATTACHMENT0
          },
          {
-            "motion", k_framebuffer_attachment_type_colour,
+            "motion", k_framebuffer_attachment_type_texture,
 
             .quality        = k_framebuffer_quality_high_only,
             .internalformat = GL_RG16F,
@@ -145,9 +109,16 @@ framebuffers[] =
             .attachment     = GL_COLOR_ATTACHMENT1
          },
          {
+#if 0
             "depth_stencil", k_framebuffer_attachment_type_renderbuffer,
 
             .internalformat = GL_DEPTH24_STENCIL8,
+#else
+            "depth_stencil", k_framebuffer_attachment_type_texture_depth,
+            .internalformat = GL_DEPTH24_STENCIL8,
+            .format         = GL_DEPTH_STENCIL,
+            .type           = GL_UNSIGNED_INT_24_8,
+#endif
             .attachment     = GL_DEPTH_STENCIL_ATTACHMENT
          }
       }
@@ -158,11 +129,11 @@ framebuffers[] =
        */
       "water_reflection",
       .link = &gpipeline.fb_water_reflection,
-      .resolution_div = 3,
+      .resolution_div = 2,
       .attachments = 
       {
          {
-            "colour", k_framebuffer_attachment_type_colour,
+            "colour", k_framebuffer_attachment_type_texture,
             .internalformat = GL_RGB,
             .format         = GL_RGB,
             .type           = GL_UNSIGNED_BYTE,
@@ -183,11 +154,11 @@ framebuffers[] =
        */
       "water_beneath",
       .link = &gpipeline.fb_water_beneath,
-      .resolution_div = 4,
+      .resolution_div = 2,
       .attachments = 
       {
          {
-            "colour", k_framebuffer_attachment_type_colour,
+            "colour", k_framebuffer_attachment_type_texture,
             .internalformat = GL_RED,
             .format         = GL_RED,
             .type           = GL_UNSIGNED_BYTE,
@@ -200,34 +171,97 @@ framebuffers[] =
             .attachment     = GL_DEPTH_STENCIL_ATTACHMENT
          }
       }
+   },
+   {
+      "workshop_preview",
+      .link = &gpipeline.fb_workshop_preview,
+      .resolution_div = 0,
+      .fixed_w = WORKSHOP_PREVIEW_WIDTH, .fixed_h = WORKSHOP_PREVIEW_HEIGHT,
+      .attachments = 
+      {
+         {
+            "colour", k_framebuffer_attachment_type_texture,
+            .internalformat = GL_RGB,
+            .format         = GL_RGB,
+            .type           = GL_UNSIGNED_BYTE,
+            .attachment     = GL_COLOR_ATTACHMENT0
+         },
+         {
+            "depth_stencil", k_framebuffer_attachment_type_renderbuffer,
+            .internalformat = GL_DEPTH24_STENCIL8,
+            .attachment = GL_DEPTH_STENCIL_ATTACHMENT
+         }
+      }
+   },
+   {
+      "network_status_ui",
+      .link = &gpipeline.fb_network_status,
+      .resolution_div = 0,
+      .fixed_w = 128, .fixed_h = 48,
+      .attachments = 
+      {
+         {
+            "colour", k_framebuffer_attachment_type_texture,
+            .internalformat = GL_RGB,
+            .format         = GL_RGB,
+            .type           = GL_UNSIGNED_BYTE,
+            .attachment     = GL_COLOR_ATTACHMENT0
+         }
+      }
    }
 };
 
 /* 
  * Get the current (automatically scaled or fixed) resolution of framebuffer
  */
-VG_STATIC void render_fb_get_current_res( struct framebuffer *fb, 
+static void render_fb_get_current_res( struct framebuffer *fb, 
                                           int *x, int *y )
 {
-   if( fb->resolution_div )
-   {
+   if( fb->resolution_div ){
       *x = vg.window_x / fb->resolution_div;
       *y = vg.window_y / fb->resolution_div;
    }
-   else
-   {
+   else{
       *x = fb->fixed_w;
       *y = fb->fixed_h;
    }
 }
 
+static void render_fb_inverse_ratio( framebuffer *fb, v2f inverse )
+{
+   if( fb ){
+      int x, y;
+      render_fb_get_current_res( fb, &x, &y );
+
+      v2f render   = { fb->render_w, fb->render_h },
+          original = { x, y };
+
+      v2_div( render, original, inverse );
+   }
+   else{
+      v2_div( (v2f){1.0f,1.0f}, (v2f){ vg.window_x, vg.window_y }, inverse );
+   }
+}
+
 /*
  * Bind framebuffer for drawing to
  */
-VG_STATIC void render_fb_bind( framebuffer *fb )
+static void render_fb_bind( framebuffer *fb, int use_scaling )
 {
    int x, y;
    render_fb_get_current_res( fb, &x, &y );
+
+   if( use_scaling ){
+      x = k_render_scale*(float)x;
+      y = k_render_scale*(float)y;
+
+      x = VG_MAX( 16, x );
+      y = VG_MAX( 16, y );
+
+      fb->render_w = x;
+      fb->render_h = y;
+   }
+
    glBindFramebuffer( GL_FRAMEBUFFER, fb->fb );
    glViewport( 0, 0, x, y );
 }
@@ -235,14 +269,15 @@ VG_STATIC void render_fb_bind( framebuffer *fb )
 /*
  * Bind framebuffer attachment's texture
  */
-VG_STATIC void render_fb_bind_texture( framebuffer *fb, 
+static void render_fb_bind_texture( framebuffer *fb, 
                                        int attachment, int slot )
 {
    struct framebuffer_attachment *at = &fb->attachments[attachment];
 
-   if( at->purpose != k_framebuffer_attachment_type_colour )
+   if( (at->purpose != k_framebuffer_attachment_type_texture) &&
+       (at->purpose != k_framebuffer_attachment_type_texture_depth) )
    {
-      vg_fatal_exit_loop( "illegal operation: bind non-colour framebuffer"
+      vg_fatal_error( "illegal operation: bind non-texture framebuffer"
                           " attachment to texture slot" );
    }
 
@@ -260,7 +295,7 @@ VG_STATIC void render_fb_bind_texture( framebuffer *fb,
 /* 
  * Convert OpenGL attachment ID enum to string
  */
-VG_STATIC const char *render_fb_attachment_str( GLenum e )
+static const char *render_fb_attachment_str( GLenum e )
 {
    struct { GLenum e; const char *str; }
    formats[] =
@@ -284,7 +319,7 @@ VG_STATIC const char *render_fb_attachment_str( GLenum e )
  * Convert OpenGL texture format enums from TexImage2D table 1,2 &
  * RenderBufferStorage Table 1, into strings
  */
-VG_STATIC const char *render_fb_format_str( GLenum format )
+static const char *render_fb_format_str( GLenum format )
 {
    struct { GLenum e; const char *str; }
    formats[] =
@@ -379,18 +414,18 @@ VG_STATIC const char *render_fb_format_str( GLenum format )
 /*
  * Bind and allocate texture for framebuffer attachment
  */
-VG_STATIC void render_fb_allocate_texture( struct framebuffer *fb, 
+static void render_fb_allocate_texture( struct framebuffer *fb, 
                                            struct framebuffer_attachment *a )
 {
    int rx, ry;
    render_fb_get_current_res( fb, &rx, &ry );
 
-   if( a->purpose == k_framebuffer_attachment_type_renderbuffer )
-   {
+   if( a->purpose == k_framebuffer_attachment_type_renderbuffer ){
       glBindRenderbuffer( GL_RENDERBUFFER, a->id );
-      glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, rx, ry );
+      glRenderbufferStorage( GL_RENDERBUFFER, a->internalformat, rx, ry );
    }
-   else if( a->purpose == k_framebuffer_attachment_type_colour )
+   else if( a->purpose == k_framebuffer_attachment_type_texture ||
+            a->purpose == k_framebuffer_attachment_type_texture_depth )
    {
       glBindTexture( GL_TEXTURE_2D, a->id );
       glTexImage2D( GL_TEXTURE_2D, 0, a->internalformat, rx, ry,
@@ -401,7 +436,7 @@ VG_STATIC void render_fb_allocate_texture( struct framebuffer *fb,
 /* 
  * Full allocation of a framebuffer
  */
-VG_STATIC void render_fb_allocate( struct framebuffer *fb )
+static void render_fb_allocate( struct framebuffer *fb )
 {
    glGenFramebuffers( 1, &fb->fb );
    glBindFramebuffer( GL_FRAMEBUFFER, fb->fb );
@@ -415,8 +450,7 @@ VG_STATIC void render_fb_allocate( struct framebuffer *fb )
    GLenum colour_attachments[4];
    u32    colour_count = 0;
 
-   for( int j=0; j<vg_list_size(fb->attachments); j++ )
-   {
+   for( int j=0; j<vg_list_size(fb->attachments); j++ ){
       struct framebuffer_attachment *attachment = &fb->attachments[j];
 
       if( attachment->purpose == k_framebuffer_attachment_type_none )
@@ -426,15 +460,15 @@ VG_STATIC void render_fb_allocate( struct framebuffer *fb )
                   render_fb_attachment_str( attachment->attachment ),
                   render_fb_format_str( attachment->internalformat ) );
 
-      if( attachment->purpose == k_framebuffer_attachment_type_renderbuffer )
-      {
+      if( attachment->purpose == k_framebuffer_attachment_type_renderbuffer ){
          glGenRenderbuffers( 1, &attachment->id );
          render_fb_allocate_texture( fb, attachment );
          glFramebufferRenderbuffer( GL_FRAMEBUFFER, 
                                     GL_DEPTH_STENCIL_ATTACHMENT,
                                     GL_RENDERBUFFER, attachment->id );
       }
-      else if( attachment->purpose == k_framebuffer_attachment_type_colour )
+      else if( attachment->purpose == k_framebuffer_attachment_type_texture || 
+         attachment->purpose == k_framebuffer_attachment_type_texture_depth )
       {
          glGenTextures( 1, &attachment->id );
          render_fb_allocate_texture( fb, attachment );
@@ -446,7 +480,8 @@ VG_STATIC void render_fb_allocate( struct framebuffer *fb )
          glFramebufferTexture2D( GL_FRAMEBUFFER, attachment->attachment,
                                  GL_TEXTURE_2D,  attachment->id, 0 );
 
-         colour_attachments[ colour_count ++ ] = attachment->attachment;
+         if( attachment->purpose == k_framebuffer_attachment_type_texture )
+            colour_attachments[ colour_count ++ ] = attachment->attachment;
       }
    }
 
@@ -457,8 +492,7 @@ VG_STATIC void render_fb_allocate( struct framebuffer *fb )
     */
    GLenum result = glCheckFramebufferStatus( GL_FRAMEBUFFER );
 
-   if( result == GL_FRAMEBUFFER_COMPLETE )
-   {
+   if( result == GL_FRAMEBUFFER_COMPLETE ){
       /* 
        * Attatch to gpipeline
        */
@@ -468,8 +502,7 @@ VG_STATIC void render_fb_allocate( struct framebuffer *fb )
       vg_success( "  status: complete\n" );
       vg_info( "}\n" );
    }
-   else
-   {
+   else{
       if( result == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT )
          vg_error( "  status: Incomplete attachment" );
       else if( result == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT )
@@ -480,42 +513,47 @@ VG_STATIC void render_fb_allocate( struct framebuffer *fb )
          vg_error( "  status: Generic Error" );
 
       vg_info( "}\n" );
-      vg_fatal_exit_loop( "Incomplete framebuffer (see logs)" );
+      vg_fatal_error( "Incomplete framebuffer (see logs)" );
    }
 }
 
 /*
  * Resize/Update all framebuffers(we know about)
  */
-VG_STATIC void render_fb_resize(void)
+static void render_fb_resize(void)
 {
-   if( !gpipeline.ready )
-      return;
+   if( !gpipeline.ready ) return;
 
-   for( int i=0; i<vg_list_size(framebuffers); i++ )
-   {
+   for( int i=0; i<vg_list_size(framebuffers); i++ ){
       struct framebuffer *fb = &framebuffers[i];
-      for( int j=0; j<vg_list_size(fb->attachments); j++ )
-      {
+      for( int j=0; j<vg_list_size(fb->attachments); j++ ){
          struct framebuffer_attachment *attachment = &fb->attachments[j];
          render_fb_allocate_texture( fb, attachment );
       }
    }
 }
 
-VG_STATIC int render_framebuffer_control( int argc, char const *argv[] );
-VG_STATIC void render_framebuffer_poll( int argc, char const *argv[] );
-VG_STATIC void render_init_fs_quad(void)
+static int render_framebuffer_control( int argc, char const *argv[] );
+static void render_framebuffer_poll( int argc, char const *argv[] );
+
+static void async_render_init( void *payload, u32 size )
 {
-   vg_info( "[render] Allocate quad\n" );
+   /* 
+    * Complete Framebuffers
+    */
+   for( int i=0; i<vg_list_size(framebuffers); i++ ){
+      struct framebuffer *fb = &framebuffers[i];
+      render_fb_allocate( fb );
+   }
 
-   float quad[] = 
-   { 
-      0.00f,0.00f, 1.00f,1.00f, 0.00f,1.00f,
-      0.00f,0.00f, 1.00f,0.00f, 1.00f,1.00f,
+   f32 rh = 0x1p-4f, ih = 0.3f;
+
+   float quad[] = { 
+      0.00f,0.00f, 1.00f,1.00f, 0.00f,1.00f,    /* fsquad */
+      0.00f,0.00f, 1.00f,0.00f, 1.00f,1.00f,    
 
-      0.20f,0.00f, 0.80f,1.00f, 0.20f,1.00f,
-      0.20f,0.00f, 0.80f,0.00f, 0.80f,1.00f,
+      0.00f,0.00f, 1.00f,rh,     0.00f,rh,    /* fsquad1 */
+      0.00f,0.00f, 1.00f,0.00f,  1.00f,rh,
 
       /* 9x9 debug grid */
       /* row0 */
@@ -539,15 +577,13 @@ VG_STATIC void render_init_fs_quad(void)
       0.30f,0.60f, 0.60f,0.60f, 0.60f,0.90f,
       0.60f,0.60f, 0.90f,0.90f, 0.60f,0.90f,
       0.60f,0.60f, 0.90f,0.60f, 0.90f,0.90f,
-   };
 
-       vg_function_push( (struct vg_cmd)
-   {
-               .name = "fb",
-               .function = render_framebuffer_control,
-      .poll_suggest = render_framebuffer_poll
-       });
+      0.00f,ih, 1.00f,ih+rh, 0.00f,ih+rh,    /* fsquad2 */
+      0.00f,ih, 1.00f,ih,    1.00f,ih+rh,
+   };
 
+   vg_console_reg_cmd( "fb", render_framebuffer_control, 
+                             render_framebuffer_poll );
    glGenVertexArrays( 1, &gpipeline.fsquad.vao );
    glGenBuffers( 1, &gpipeline.fsquad.vbo );
    glBindVertexArray( gpipeline.fsquad.vao );
@@ -559,66 +595,71 @@ VG_STATIC void render_init_fs_quad(void)
    glEnableVertexAttribArray( 0 );
 
    VG_CHECK_GL_ERR();
+
+   glBindFramebuffer( GL_FRAMEBUFFER, 0 );
+   gpipeline.ready = 1;
 }
 
-VG_STATIC void render_init(void)
+static void render_init(void)
 {
+   vg_console_reg_var( "blur_strength", &k_blur_strength, k_var_dtype_f32, 0 );
+   vg_console_reg_var( "render_scale", &k_render_scale,
+                       k_var_dtype_f32, VG_VAR_PERSISTENT );
+   vg_console_reg_var( "fov", &k_fov, k_var_dtype_f32, VG_VAR_PERSISTENT );
+   vg_console_reg_var( "cam_height", &k_cam_height, 
+                        k_var_dtype_f32, VG_VAR_PERSISTENT );
+   vg_console_reg_var( "blur_effect", &k_blur_effect, 
+                        k_var_dtype_i32, VG_VAR_PERSISTENT );
+
+
    shader_blit_register();
    shader_blitblur_register();
    shader_blitcolour_register();
+   shader_blit_transition_register();
 
-   vg_acquire_thread_sync();
-   {
-      /* 
-       * Complete Framebuffers
-       */
-      for( int i=0; i<vg_list_size(framebuffers); i++ )
-      {
-         struct framebuffer *fb = &framebuffers[i];
-         render_fb_allocate( fb );
-      }
-
-      render_init_fs_quad();
-
-      glBindFramebuffer( GL_FRAMEBUFFER, 0 );
-      gpipeline.ready = 1;
-   }
-
-   vg_release_thread_sync();
+   vg_async_call( async_render_init, NULL, 0 );
 }
 
 /*
  * Utility
  */
-VG_STATIC void render_fsquad(void)
+static void render_fsquad(void)
 {
    glBindVertexArray( gpipeline.fsquad.vao );
    glDrawArrays( GL_TRIANGLES, 0, 6 );
 }
 
-VG_STATIC void render_fsquad1(void)
+static void render_fsquad1(void)
 {
    glBindVertexArray( gpipeline.fsquad.vao );
    glDrawArrays( GL_TRIANGLES, 6, 6 );
 }
 
+static void render_fsquad2(void)
+{
+   glBindVertexArray( gpipeline.fsquad.vao );
+   glDrawArrays( GL_TRIANGLES, 66,6 );
+}
+
 /*
  * Call this inside the UI function
  */
-VG_STATIC void render_view_framebuffer_ui(void)
+static void render_view_framebuffer_ui(void)
 {
+#if 0
    int viewing_count = 0;
 
    glBindVertexArray( gpipeline.fsquad.vao );
    shader_blit_use();
    shader_blit_uTexMain( 0 );
+   
+   v2f identity = { 1.0f, 1.0f };
+   shader_blit_uInverseRatio( identity );
 
-   for( int i=0; i<vg_list_size(framebuffers); i++ )
-   {
+   for( int i=0; i<vg_list_size(framebuffers); i++ ){
       struct framebuffer *fb = &framebuffers[i];
 
-      for( int j=0; j<vg_list_size(fb->attachments); j++ )
-      {
+      for( int j=0; j<vg_list_size(fb->attachments); j++ ){
          struct framebuffer_attachment *at = &fb->attachments[j];
 
          if( !at->debug_view )
@@ -638,16 +679,14 @@ VG_STATIC void render_view_framebuffer_ui(void)
          ui_text( (ui_rect){ corner[0], corner[1] + 32, 0.0f, 0.0f, },
                   at->display_name, 1, k_text_align_left );
 
-         if( at->purpose == k_framebuffer_attachment_type_renderbuffer )
-         {
+         if( at->purpose == k_framebuffer_attachment_type_renderbuffer ){
             v2f center;
             v2_muladds( corner, window, 0.15f, center );
 
             ui_text( (ui_rect){ center[0], center[1], 0.0f, 0.0f },
                      "<hardware texture>", 1, k_text_align_center );
          }
-         else
-         {
+         else{
             render_fb_bind_texture( fb, j, 0 );
             
             int start = (viewing_count+2) * 6,
@@ -658,9 +697,10 @@ VG_STATIC void render_view_framebuffer_ui(void)
          viewing_count ++;
       }
    }
+#endif
 }
 
-VG_STATIC void render_framebuffer_show( struct framebuffer *fb,
+static void render_framebuffer_show( struct framebuffer *fb,
                                         struct framebuffer_attachment *at,
                                         int operation )
 {
@@ -674,10 +714,9 @@ VG_STATIC void render_framebuffer_show( struct framebuffer *fb,
  * arg1: framebuffer name  <name>/"all"
  * arg2: subname           <name>/none
  */
-VG_STATIC int render_framebuffer_control( int argc, char const *argv[] )
+static int render_framebuffer_control( int argc, char const *argv[] )
 {
-   if( argc < 2 )
-   {
+   if( argc < 2 ){
       vg_error( "Usage: fb \"show/hide\" <name>/\"all\" <name>/none\n" );
       return 0;
    }
@@ -689,8 +728,7 @@ VG_STATIC int render_framebuffer_control( int argc, char const *argv[] )
       operation = 1;
    else if( !strcmp( argv[0], "hide" ) )
       operation = 0;
-   else
-   {
+   else{
       vg_error( "Unknown framebuffer operation: '%s'\n", argv[0] );
       return 0;
    }
@@ -698,25 +736,20 @@ VG_STATIC int render_framebuffer_control( int argc, char const *argv[] )
    if( !strcmp( argv[1], "all" ) )
       modify_all = 1;
 
-   for( int i=0; i<vg_list_size(framebuffers); i++ )
-   {
+   for( int i=0; i<vg_list_size(framebuffers); i++ ){
       struct framebuffer *fb = &framebuffers[i];
       
-      for( int j=0; j<vg_list_size(fb->attachments); j++ )
-      {
+      for( int j=0; j<vg_list_size(fb->attachments); j++ ){
          struct framebuffer_attachment *at = &fb->attachments[j];
 
          if( at->purpose == k_framebuffer_attachment_type_none )
             continue;
 
-         if( modify_all )
-         {
+         if( modify_all ){
             render_framebuffer_show( fb, at, operation );
          }
-         else
-         {
-            if( !strcmp( fb->display_name, argv[1] ) )
-            {
+         else{
+            if( !strcmp( fb->display_name, argv[1] ) ){
                if( argc == 2 )
                   render_framebuffer_show( fb, at, operation );
                else if( !strcmp( at->display_name, argv[2] ) )
@@ -729,49 +762,41 @@ VG_STATIC int render_framebuffer_control( int argc, char const *argv[] )
    return 0;
 }
 
-VG_STATIC void render_framebuffer_poll( int argc, char const *argv[] )
+static void render_framebuffer_poll( int argc, char const *argv[] )
 {
    const char *term = argv[argc-1];
 
-   if( argc == 1 )
-   {
+   if( argc == 1 ){
       console_suggest_score_text( "show", term, 0 );
       console_suggest_score_text( "hide", term, 0 );
    }
-   else if( argc == 2 )
-   {
+   else if( argc == 2 ){
       console_suggest_score_text( "all", term, 0 );
 
-      for( int i=0; i<vg_list_size(framebuffers); i++ )
-      {
+      for( int i=0; i<vg_list_size(framebuffers); i++ ){
          struct framebuffer *fb = &framebuffers[i];
          console_suggest_score_text( fb->display_name, term, 0 );
       }
    }
-   else if( argc == 3 )
-   {
+   else if( argc == 3 ){
       int modify_all = 0;
 
       if( !strcmp( argv[1], "all" ) )
          modify_all = 1;
 
-      for( int i=0; i<vg_list_size(framebuffers); i++ )
-      {
+      for( int i=0; i<vg_list_size(framebuffers); i++ ){
          struct framebuffer *fb = &framebuffers[i];
          
-         for( int j=0; j<vg_list_size(fb->attachments); j++ )
-         {
+         for( int j=0; j<vg_list_size(fb->attachments); j++ ){
             struct framebuffer_attachment *at = &fb->attachments[j];
 
             if( at->purpose == k_framebuffer_attachment_type_none )
                continue;
 
-            if( modify_all )
-            {
+            if( modify_all ){
                console_suggest_score_text( at->display_name, term, 0 );
             }
-            else if( !strcmp( fb->display_name, argv[1] ) )
-            {
+            else if( !strcmp( fb->display_name, argv[1] ) ){
                console_suggest_score_text( at->display_name, term, 0 );
             }
          }