framebuffer change
[carveJwlIkooP6JGAAIwe30JlM.git] / world_render.c
index 4cac23f6a2418446cdc4ceee2b8ac412bff78747..5db790a41192a11e26d5e62eaee061542ac3039e 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 );
 }
 
@@ -1105,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( gpipeline.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 );
    }
 
@@ -1125,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 );