variable scale menu
[carveJwlIkooP6JGAAIwe30JlM.git] / render.h
index e7220b0935a92f3a105eb8382bb8cd9345bfc1ba..712961ea3f196dc6956aeefe0b3c5164e2aef45c 100644 (file)
--- a/render.h
+++ b/render.h
@@ -28,7 +28,6 @@ VG_STATIC void render_world_depth( world_instance *world, camera *cam );
 
 typedef struct framebuffer framebuffer;
 
-
 /* 
  * All standard buffers used in rendering
  */
@@ -39,49 +38,22 @@ VG_STATIC struct pipeline
    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;
-
    int ready;
+
+   float view_render_scale,
+         water_render_scale;
 }
-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 = { .view_render_scale = 1.0f };
 
 struct framebuffer
 {
    const char *display_name;
-   int         resolution_div,
+   int         resolution_div,   /* definition */
                fixed_w,
-               fixed_h;
+               fixed_h,
+
+               render_w,         /* runtime */
+               render_h;
 
    struct framebuffer_attachment
    {
@@ -209,25 +181,46 @@ framebuffers[] =
 VG_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;
    }
 }
 
+VG_STATIC void render_fb_inverse_ratio( framebuffer *fb, v2f inverse )
+{
+   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 );
+}
+
 /*
  * Bind framebuffer for drawing to
  */
-VG_STATIC void render_fb_bind( framebuffer *fb )
+VG_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 = 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 );
 }
@@ -612,13 +605,14 @@ VG_STATIC void render_view_framebuffer_ui(void)
    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 +632,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,