dont remember
[carveJwlIkooP6JGAAIwe30JlM.git] / render.h
index cd41ec33e836d65ef02d690fc824d4505efee3a1..f17018bb2e767006dbd6701c355a7f5e9dd5b33b 100644 (file)
--- a/render.h
+++ b/render.h
@@ -5,17 +5,23 @@
 #include "common.h"
 #include "model.h"
 #include "camera.h"
+#include "world.h"
 
 #include "shaders/blit.h"
 #include "shaders/blitblur.h"
+#include "shaders/blitcolour.h"
+
+#if 0
 #include "shaders/standard.h"
 #include "shaders/vblend.h"
+#endif
 
-VG_STATIC void render_water_texture( camera *cam );
-VG_STATIC void render_water_surface( camera *cam );
-VG_STATIC void render_world( camera *cam );
-VG_STATIC void shader_link_standard_ub( GLuint shader, int texture_id );
-VG_STATIC void render_world_depth( camera *cam );
+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 );
 
 #ifndef RENDER_H
 #define RENDER_H
@@ -31,28 +37,9 @@ VG_STATIC struct pipeline
    glmesh fsquad;
 
    framebuffer *fb_main,
-               *fb_heightmap,
                *fb_water_reflection,
                *fb_water_beneath;
 
-   /* STD140 */
-   struct ub_world_lighting
-   {
-      /* v3f (padded) */
-      v4f g_light_colours[3],
-          g_light_directions[3],
-          g_ambient_colour;
-
-      v4f g_water_plane,
-          g_depth_bounds;
-
-      float g_water_fog;
-      int g_light_count;
-      int g_light_preview;
-      int g_shadow_samples;
-   }
-   ub_world_lighting;
-
    struct light_widget
    {
       int enabled;
@@ -62,8 +49,6 @@ VG_STATIC struct pipeline
    widgets[3];
 
    float shadow_spread, shadow_length;
-   GLuint ubo_world_lighting,
-          ubo_world;
 
    int ready;
 }
@@ -89,11 +74,6 @@ gpipeline =
    },
    .shadow_spread = 0.65f,
    .shadow_length = 9.50f,
-
-   .ub_world_lighting =
-   {
-      .g_ambient_colour = { 0.09f, 0.03f, 0.07f }
-   }
 };
 
 struct framebuffer
@@ -172,29 +152,6 @@ framebuffers[] =
          }
       }
    },
-   {
-      /*
-       * A ortho projection of the world, used for shadows and ocean colouring.
-       * Note: it does not have a render buffer attachement because it's
-       *       intended to be drawn to in a MAX blending mode
-       */
-      "heightmap", 
-      .link = &gpipeline.fb_heightmap,
-      .fixed_w = 1024,
-      .fixed_h = 1024,
-
-      .attachments =
-      {
-         {
-            "depth", k_framebuffer_attachment_type_colour,
-
-            .internalformat = GL_R32F,
-            .format         = GL_RED,
-            .type           = GL_FLOAT,
-            .attachment     = GL_COLOR_ATTACHMENT0
-         }
-      }
-   },
    {
       /*
        * Second rendered view from the perspective of the water reflection
@@ -231,8 +188,8 @@ framebuffers[] =
       {
          {
             "colour", k_framebuffer_attachment_type_colour,
-            .internalformat = GL_RGBA,
-            .format         = GL_RGBA,
+            .internalformat = GL_RED,
+            .format         = GL_RED,
             .type           = GL_UNSIGNED_BYTE,
             .attachment     = GL_COLOR_ATTACHMENT0
          },
@@ -297,51 +254,6 @@ VG_STATIC void render_fb_bind_texture( framebuffer *fb,
 /*
  * Shaders
  */
-VG_STATIC void shader_link_standard_ub( GLuint shader, int texture_id )
-{
-   GLuint idx = glGetUniformBlockIndex( shader, "ub_world_lighting" );   
-   glUniformBlockBinding( shader, idx, 0 );
-
-   render_fb_bind_texture( gpipeline.fb_heightmap, 0, texture_id );
-   glUniform1i( glGetUniformLocation( shader, "g_world_depth" ), texture_id );
-}
-
-VG_STATIC void render_update_lighting_ub(void)
-{
-   struct ub_world_lighting *winf = &gpipeline.ub_world_lighting;
-   int c = 0;
-
-   for( int i=0; i<3; i++ )
-   {
-      struct light_widget *lw = &gpipeline.widgets[i];
-
-      if( lw->enabled )
-      {
-         float pitch = lw->dir[0],
-               yaw = lw->dir[1],
-               xz = cosf( pitch );
-         
-         v3_copy( (v3f){ xz*cosf(yaw), sinf(pitch), xz*sinf(yaw) }, 
-               winf->g_light_directions[c] );
-         v3_copy( lw->colour, winf->g_light_colours[c] );
-
-         c ++;
-      }
-   }
-
-   winf->g_light_count = c;
-   winf->g_light_directions[0][3] = gpipeline.shadow_length;
-   winf->g_light_colours[0][3] = gpipeline.shadow_spread;
-
-   if( vg.quality_profile == k_quality_profile_low )
-      winf->g_shadow_samples = 0;
-   else
-      winf->g_shadow_samples = 8;
-
-   glBindBuffer( GL_UNIFORM_BUFFER, gpipeline.ubo_world_lighting );
-   glBufferSubData( GL_UNIFORM_BUFFER, 0, sizeof(struct ub_world_lighting),
-         &gpipeline.ub_world_lighting );
-}
 
 #define FB_FORMAT_STR( E ) { E, #E },
 
@@ -649,27 +561,11 @@ VG_STATIC void render_init_fs_quad(void)
    VG_CHECK_GL_ERR();
 }
 
-VG_STATIC void render_init_uniform_buffers(void)
-{
-   vg_info( "[render] Allocate uniform buffer\n" );
-
-   glGenBuffers( 1, &gpipeline.ubo_world_lighting );
-   glBindBuffer( GL_UNIFORM_BUFFER, gpipeline.ubo_world_lighting );
-   glBufferData( GL_UNIFORM_BUFFER, sizeof(struct ub_world_lighting), 
-         NULL, GL_DYNAMIC_DRAW );
-
-   render_update_lighting_ub();
-   glBindBufferBase( GL_UNIFORM_BUFFER, 0, gpipeline.ubo_world_lighting );
-
-   VG_CHECK_GL_ERR();
-}
-
 VG_STATIC void render_init(void)
 {
    shader_blit_register();
    shader_blitblur_register();
-   shader_standard_register();
-   shader_vblend_register();
+   shader_blitcolour_register();
 
    vg_acquire_thread_sync();
    {
@@ -683,7 +579,6 @@ VG_STATIC void render_init(void)
       }
 
       render_init_fs_quad();
-      render_init_uniform_buffers();
 
       glBindFramebuffer( GL_FRAMEBUFFER, 0 );
       gpipeline.ready = 1;