update helpers/location to 'frosted' ui
[carveJwlIkooP6JGAAIwe30JlM.git] / render.h
index 493ed3b6d4520c8954bc7860e4702c28fb9b9893..a0bde7e024bf3c46e92ebe91d82641c5ccc49833 100644 (file)
--- a/render.h
+++ b/render.h
@@ -1,82 +1,94 @@
-#ifndef RENDER_H
-#define RENDER_H
-#define VG_3D
-#include "vg/vg.h"
+/*
+ * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
+ */
+#pragma once
+#include "common.h"
+#include "model.h"
+#include "camera.h"
+#include "shader_props.h"
 
-static struct pipeline
-{
-   float fov;
-}
-gpipeline;
+#include "shaders/blit.h"
+#include "shaders/blitblur.h"
+#include "shaders/blitcolour.h"
+#include "shaders/blit_transition.h"
 
-static void render_water_texture( m4x3f camera );
-static void render_water_surface( m4x4f pv );
-static void render_world( m4x4f projection, m4x3f camera );
+#define WORKSHOP_PREVIEW_WIDTH  504
+#define WORKSHOP_PREVIEW_HEIGHT 336
 
-/* 
- * http://www.terathon.com/lengyel/Lengyel-Oblique.pdf 
- */
-static void plane_clip_projection( m4x4f mat, v4f plane )
-{
-   v4f c = 
-   {
-      (vg_signf(plane[0]) + mat[2][0]) / mat[0][0],
-      (vg_signf(plane[1]) + mat[2][1]) / mat[1][1],
-      -1.0f,
-      (1.0f + mat[2][2]) / mat[3][2]
-   };
+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;
 
-   v4_muls( plane, 2.0f / v4_dot(plane,c), c );
+typedef struct framebuffer framebuffer;
 
-   mat[0][2] = c[0];
-   mat[1][2] = c[1];
-   mat[2][2] = c[2] + 1.0f;
-   mat[3][2] = c[3];
-}
+/* 
+ * All standard buffers used in rendering
+ */
+static struct pipeline{
+   glmesh fsquad;
 
-static void pipeline_projection( m4x4f mat, float nearz, float farz )
-{
-   m4x4_projection( mat,
-         gpipeline.fov,
-         (float)vg_window_x / (float)vg_window_y, 
-         nearz, farz );
+   framebuffer *fb_main,
+               *fb_water_reflection,
+               *fb_water_beneath,
+               *fb_workshop_preview,
+               *fb_network_status;
+   int ready;
 }
+gpipeline;
 
-static void create_renderbuffer_std( GLuint *fb, GLuint *rgb, GLuint *rb )
-{
-   glGenFramebuffers( 1, fb );
-   glBindFramebuffer( GL_FRAMEBUFFER, *fb );
-
-   glGenTextures( 1, rgb );
-   glBindTexture( GL_TEXTURE_2D, *rgb );
-   glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, vg_window_x, vg_window_y, 
-         0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
-
-   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
-   glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-   glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 
-         GL_TEXTURE_2D, *rgb, 0);
+struct framebuffer{
+   const char *display_name;
+   int         resolution_div,   /* definition */
+               fixed_w,
+               fixed_h,
 
-   /* TODO: Check for DEPTH32f availiblity and use if possible */
+               render_w,         /* runtime */
+               render_h;
 
-   glGenRenderbuffers( 1, rb );
-   glBindRenderbuffer( GL_RENDERBUFFER, *rb );
-   glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 
-         vg_window_x, vg_window_y );
+   struct framebuffer_attachment{
+      const char *display_name;
+      
+      enum framebuffer_attachment_type{
+         k_framebuffer_attachment_type_none,
+         k_framebuffer_attachment_type_texture,
+         k_framebuffer_attachment_type_renderbuffer,
+         k_framebuffer_attachment_type_texture_depth
+      }
+      purpose;
 
-   glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
-         GL_RENDERBUFFER, *rb );
-}
+      enum framebuffer_quality_profile{
+         k_framebuffer_quality_all,
+         k_framebuffer_quality_high_only
+      }
+      quality;
+      
+      GLenum internalformat,
+             format,
+             type,
+             attachment;
 
-static void resize_renderbuffer_std( GLuint *fb, GLuint *rgb, GLuint *rb )
-{
-   glBindTexture( GL_TEXTURE_2D, *rgb );
-   glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, vg_window_x, vg_window_y, 0,
-         GL_RGB, GL_UNSIGNED_BYTE, NULL );
+      GLuint id;
 
-   glBindRenderbuffer( GL_RENDERBUFFER, *rb );
-   glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 
-         vg_window_x, vg_window_y );
+      /* Runtime */
+      int debug_view;
+   }
+   attachments[5];
+   GLuint fb;
+   framebuffer **link;
 }
+extern framebuffers[];
 
-#endif /* RENDER_H */
+void render_init(void);
+void render_fsquad(void);
+void render_fsquad1(void);
+void render_fsquad2(void);
+void render_view_framebuffer_ui(void);
+void render_fb_bind_texture( framebuffer *fb, int attachment, int slot );
+void render_fb_inverse_ratio( framebuffer *fb, v2f inverse );
+void render_fb_get_current_res( struct framebuffer *fb, int *x, int *y );
+void render_fb_bind( framebuffer *fb, int use_scaling );
+void render_fb_bind_texture( framebuffer *fb, int attachment, int slot );
+void render_fb_allocate( struct framebuffer *fb );
+void render_fb_resize(void);