move location of main camera to g_render
[carveJwlIkooP6JGAAIwe30JlM.git] / world_render.c
index e1a30886b8de504afacda8052fbef4e9eba4c2ef..7d93920e558014a1aac6562153e19a266d2075de 100644 (file)
@@ -24,9 +24,11 @@ static int ccmd_set_time( int argc, const char *argv[] ){
    return 0;
 }
 
-static void async_world_render_init( void *payload, u32 size ){
+static void async_world_render_init( void *payload, u32 size )
+{
    vg_info( "Allocate uniform buffers\n" );
-   for( int i=0; i<k_world_max; i++ ){
+   for( int i=0; i<k_world_max; i++ )
+   {
       world_instance *world = &world_static.instances[i];
       world->ubo_bind_point = i;
 
@@ -38,32 +40,6 @@ static void async_world_render_init( void *payload, u32 size ){
       glBindBufferBase( GL_UNIFORM_BUFFER, i, world->ubo_lighting );
       VG_CHECK_GL_ERR();
    }
-
-   vg_info( "Allocate frame buffers\n" );
-   for( int i=0; i<k_world_max; i++ ){
-      world_instance *world = &world_static.instances[i];
-      struct framebuffer *fb = &world->heightmap;
-
-      fb->display_name = NULL;
-      fb->link = NULL;
-      fb->fixed_w = 1024;
-      fb->fixed_h = 1024;
-      fb->resolution_div = 0;
-
-      fb->attachments[0].display_name     = NULL;
-      fb->attachments[0].purpose = k_framebuffer_attachment_type_texture;
-      fb->attachments[0].internalformat   = GL_RG16F;
-      fb->attachments[0].format           = GL_RG;
-      fb->attachments[0].type             = GL_FLOAT;
-      fb->attachments[0].attachment       = GL_COLOR_ATTACHMENT0;
-
-      fb->attachments[1].purpose = k_framebuffer_attachment_type_none;
-      fb->attachments[2].purpose = k_framebuffer_attachment_type_none;
-      fb->attachments[3].purpose = k_framebuffer_attachment_type_none;
-      fb->attachments[4].purpose = k_framebuffer_attachment_type_none;
-
-      render_fb_allocate( fb );
-   }
 }
 
 void world_render_init(void)
@@ -92,6 +68,26 @@ void world_render_init(void)
                                  VG_TEX2D_NEAREST|VG_TEX2D_REPEAT, 
                                  &world_render.tex_terrain_noise );
 
+   vg_info( "Allocate frame buffers\n" );
+   for( int i=0; i<k_world_max; i++ )
+   {
+      world_instance *world = &world_static.instances[i];
+      world->heightmap = vg_framebuffer_allocate( vg_mem.rtmemory, 1, 0 );
+      world->heightmap->display_name = NULL;
+      world->heightmap->fixed_w = 1024;
+      world->heightmap->fixed_h = 1024;
+      world->heightmap->resolution_div = 0;
+      world->heightmap->attachments[0] = (vg_framebuffer_attachment)
+      {
+         NULL, k_framebuffer_attachment_type_texture,
+         .internalformat = GL_RG16F,
+         .format         = GL_RG,
+         .type           = GL_FLOAT,
+         .attachment     = GL_COLOR_ATTACHMENT0
+      };
+      vg_framebuffer_create( world->heightmap );
+   }
+
    vg_async_call( async_world_render_init, NULL, 0 );
 }
 
@@ -109,7 +105,7 @@ void world_bind_position_texture( world_instance *world,
                                   GLuint shader, GLuint location,
                                   int slot )
 {
-   render_fb_bind_texture( &world->heightmap, 0, slot );
+   vg_framebuffer_bind_texture( world->heightmap, 0, slot );
    glUniform1i( location, slot );
 }
 
@@ -145,15 +141,6 @@ static GLuint world_get_texture( world_instance *world, u32 id ){
    else                  return world->textures[ id ];
 }
 
-#if 0
-static void bindpoint_diffuse_texture1( world_instance *world,
-                                        struct world_surface *mat ){
-   glActiveTexture( GL_TEXTURE1 );
-   glBindTexture( GL_TEXTURE_2D, 
-                  world_get_texture(world,mat->info.tex_diffuse) );
-}
-#endif
-
 /*
  * Passes Rendering
  * ----------------------------------------------------------------------------
@@ -626,7 +613,7 @@ static void world_render_challenges( world_instance *world,
    }
 
    /* render texts */
-   font3d_bind( &gui.font, k_font_shader_world, 0, world, &skaterift.cam );
+   font3d_bind( &gui.font, k_font_shader_world, 0, world, &g_render.cam );
 
    u32 count = 0;
 
@@ -669,7 +656,7 @@ static void world_render_challenges( world_instance *world,
 
       shader_scene_font_uOpacity( scale );
       shader_scene_font_uColourize( colour );
-      font3d_simple_draw( 1, buf, &skaterift.cam, mmdl );
+      font3d_simple_draw( 1, buf, &g_render.cam, mmdl );
    }
 }
 
@@ -1114,19 +1101,22 @@ void render_world( world_instance *world, vg_camera *cam,
       render_world_fxglow( world, world, cam, NULL, 1, 1, 0 );
    }
    
-   if( with_water ){
+   if( with_water )
+   {
       render_water_texture( world, cam );
-      render_fb_bind( gpipeline.fb_main, 1 );
+      vg_framebuffer_bind( g_render.fb_main, k_render_scale );
    }
 
-   if( stenciled ){
+   if( stenciled )
+   {
       glStencilFunc( GL_EQUAL, 1, 0xFF );
       glStencilMask( 0x00 ); 
       glEnable( GL_CULL_FACE );
       glEnable( GL_STENCIL_TEST );
    }
 
-   if( with_water ){
+   if( with_water )
+   {
       render_water_surface( world, cam );
    }
 
@@ -1134,7 +1124,8 @@ void render_world( world_instance *world, vg_camera *cam,
    render_other_entities( world, cam );
    ent_miniworld_render( world, cam );
 
-   if( stenciled ){
+   if( stenciled )
+   {
       glStencilMask( 0xFF );
       glStencilFunc( GL_ALWAYS, 1, 0xFF );
       glDisable( GL_STENCIL_TEST );
@@ -1210,7 +1201,6 @@ void render_world_override( world_instance *world,
    v4f uPlayerPos, uSpawnPos;
    v4_zero( uPlayerPos );
    v4_zero( uSpawnPos );
-
    v3_copy( world->player_co, uPlayerPos );
    
    if( dest_spawn && (v3_dist2(dest_spawn->transform.co,uPlayerPos) > 0.1f) )
@@ -1360,20 +1350,21 @@ static f32 *skybox_prop_location( world_instance *world, i32 index ){
    }
 }
 
-void imgui_world_light_edit( world_instance *world )
+void imgui_world_light_edit( ui_context *ctx, world_instance *world )
 {
    ui_rect panel = { vg.window_x-400, 0, 400, vg.window_y };
-   ui_fill( panel, ui_colour( k_ui_bg+1 ) );
-   ui_outline( panel, 1, ui_colour( k_ui_bg+7 ), 0 );
+   ui_fill( ctx, panel, ui_colour( ctx, k_ui_bg+1 ) );
+   ui_outline( ctx, panel, 1, ui_colour( ctx, k_ui_bg+7 ), 0 );
    ui_rect_pad( panel, (ui_px[2]){ 8, 8 } );
-   vg_ui.wants_mouse = 1;
+   ui_capture_mouse(ctx, 1);
 
    static i32 option_to_edit = 0;
-   ui_enum( panel, "option", skybox_setting_options, 5, &option_to_edit );
-   ui_colourpicker( panel, "colour", 
+   ui_enum( ctx, panel, "option", skybox_setting_options, 5, &option_to_edit );
+   ui_colourpicker( ctx, panel, "colour", 
                     skybox_prop_location( world, option_to_edit ) );
 
-   if( ui_button( panel, "save tweaker file ('/tmp/tweaker.txt')\n" ) == 1 ){
+   if( ui_button( ctx, panel, "save tweaker file ('/tmp/tweaker.txt')\n" ) == 1 )
+   {
       FILE *fp = fopen( "/tmp/tweaker.txt", "w" );
       
       for( i32 i=0; i<5; i ++ ){