update build script
[carveJwlIkooP6JGAAIwe30JlM.git] / render.h
index 41aeef241ef529b7bc33522f8cb1dea880b3d067..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
 
+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,
-               *fb_workshop_preview;
+               *fb_workshop_preview,
+               *fb_network_status;
    int ready;
-
-   float view_render_scale,
-         water_render_scale;
 }
-gpipeline = { .view_render_scale = 1.0f };
+gpipeline;
 
 struct framebuffer{
    const char *display_name;
@@ -181,7 +176,7 @@ framebuffers[] =
       "workshop_preview",
       .link = &gpipeline.fb_workshop_preview,
       .resolution_div = 0,
-      .fixed_w = 504, .fixed_h = 336,
+      .fixed_w = WORKSHOP_PREVIEW_WIDTH, .fixed_h = WORKSHOP_PREVIEW_HEIGHT,
       .attachments = 
       {
          {
@@ -197,13 +192,29 @@ framebuffers[] =
             .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 ){
@@ -216,7 +227,7 @@ VG_STATIC void render_fb_get_current_res( struct framebuffer *fb,
    }
 }
 
-VG_STATIC void render_fb_inverse_ratio( framebuffer *fb, v2f inverse )
+static void render_fb_inverse_ratio( framebuffer *fb, v2f inverse )
 {
    if( fb ){
       int x, y;
@@ -235,14 +246,14 @@ VG_STATIC void render_fb_inverse_ratio( framebuffer *fb, v2f inverse )
 /*
  * Bind framebuffer for drawing to
  */
-VG_STATIC void render_fb_bind( framebuffer *fb, int use_scaling )
+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 = gpipeline.view_render_scale*(float)x;
-      y = gpipeline.view_render_scale*(float)y;
+      x = k_render_scale*(float)x;
+      y = k_render_scale*(float)y;
 
       x = VG_MAX( 16, x );
       y = VG_MAX( 16, y );
@@ -258,7 +269,7 @@ VG_STATIC void render_fb_bind( framebuffer *fb, int use_scaling )
 /*
  * 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];
@@ -284,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[] =
@@ -308,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[] =
@@ -403,7 +414,7 @@ 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;
@@ -425,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 );
@@ -509,10 +520,9 @@ VG_STATIC void render_fb_allocate( struct framebuffer *fb )
 /*
  * 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++ ){
       struct framebuffer *fb = &framebuffers[i];
@@ -523,10 +533,10 @@ VG_STATIC void render_fb_resize(void)
    }
 }
 
-VG_STATIC int render_framebuffer_control( int argc, char const *argv[] );
-VG_STATIC void render_framebuffer_poll( int argc, char const *argv[] );
+static int render_framebuffer_control( int argc, char const *argv[] );
+static void render_framebuffer_poll( int argc, char const *argv[] );
 
-VG_STATIC void async_render_init( void *payload, u32 size )
+static void async_render_init( void *payload, u32 size )
 {
    /* 
     * Complete Framebuffers
@@ -536,12 +546,14 @@ VG_STATIC void async_render_init( void *payload, u32 size )
       render_fb_allocate( fb );
    }
 
+   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.00f,0.00f, 1.00f,0x1p-4f,0.00f,0x1p-4f,    /* fsquad1 */
-      0.00f,0.00f, 1.00f,0.00f,  1.00f,0x1p-4f,
+      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 */
@@ -565,11 +577,13 @@ VG_STATIC void async_render_init( void *payload, u32 size )
       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,
+
+      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 );
@@ -586,11 +600,22 @@ VG_STATIC void async_render_init( void *payload, u32 size )
    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_async_call( async_render_init, NULL, 0 );
 }
@@ -598,22 +623,28 @@ VG_STATIC void render_init(void)
 /*
  * 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;
@@ -669,7 +700,7 @@ VG_STATIC void render_view_framebuffer_ui(void)
 #endif
 }
 
-VG_STATIC void render_framebuffer_show( struct framebuffer *fb,
+static void render_framebuffer_show( struct framebuffer *fb,
                                         struct framebuffer_attachment *at,
                                         int operation )
 {
@@ -683,7 +714,7 @@ 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 ){
       vg_error( "Usage: fb \"show/hide\" <name>/\"all\" <name>/none\n" );
@@ -731,7 +762,7 @@ 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];