X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world_water.h;h=a4f69672973a2676ce520756f7494e4158b7d7f1;hb=5ecf9cca8b5b9bf876d7e7c7fde03d5b187bb42b;hp=85f4b5debd4766d7ee81f1fb3f379d8454653347;hpb=86dbcd5796ed674ca9433cce1ace8bef322cd121;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world_water.h b/world_water.h index 85f4b5d..a4f6967 100644 --- a/world_water.h +++ b/world_water.h @@ -1,3 +1,7 @@ +/* + * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved + */ + #ifndef WATER_H #define WATER_H @@ -26,18 +30,27 @@ wrender = .fbdepth = { .format = GL_RGBA, .div = 4 } }; -static void world_water_register(void) +static void world_water_init(void) { + vg_info( "world_water_init\n" ); shader_water_register(); + + vg_acquire_thread_sync(); + { + fb_init( &wrender.fbreflect ); + fb_init( &wrender.fbdepth ); + + vg_tex2d_init( (vg_tex2d *[]){&tex_water_surf}, 1 ); + vg_success( "done\n" ); + } + vg_release_thread_sync(); } -static void world_water_init(void) +static void world_water_free(void *_) { - /* TODO: probably dont do this every time */ - wrender.enabled = 1; - - fb_init( &wrender.fbreflect ); - fb_init( &wrender.fbdepth ); + vg_tex2d_free( (vg_tex2d *[]){&tex_water_surf}, 1 ); + fb_free( &wrender.fbreflect ); + fb_free( &wrender.fbdepth ); } static void water_fb_resize(void) @@ -53,6 +66,7 @@ static void water_set_surface( glmesh *surf, float height ) { wrender.mdl = *surf; wrender.height = height; + wrender.enabled = 1; v4_copy( (v4f){ 0.0f, 1.0f, 0.0f, height }, wrender.plane ); } @@ -94,7 +108,7 @@ static void render_water_texture( m4x3f camera ) m4x4f projection; m4x4_projection( projection, gpipeline.fov, - (float)vg_window_x / (float)vg_window_y, + (float)vg.window_x / (float)vg.window_y, 0.1f, 900.0f ); plane_clip_projection( projection, clippa ); m4x4_mul( projection, view, projection ); @@ -118,14 +132,14 @@ static void render_water_texture( m4x3f camera ) m4x4_projection( projection, gpipeline.fov, - (float)vg_window_x / (float)vg_window_y, + (float)vg.window_x / (float)vg.window_y, 0.1f, 900.0f ); plane_clip_projection( projection, clippb ); m4x4_mul( projection, view, projection ); render_world_depth( projection, camera ); - glViewport( 0, 0, vg_window_x, vg_window_y ); + glViewport( 0, 0, vg.window_x, vg.window_y ); } static void render_water_surface( m4x4f pv, m4x3f camera ) @@ -142,14 +156,14 @@ static void render_water_surface( m4x4f pv, m4x3f camera ) vg_tex2d_bind( &tex_water_surf, 1 ); shader_water_uTexDudv( 1 ); shader_water_uInvRes( (v2f){ - 1.0f / (float)vg_window_x, - 1.0f / (float)vg_window_y }); + 1.0f / (float)vg.window_x, + 1.0f / (float)vg.window_y }); shader_link_standard_ub( _shader_water.id, 2 ); fb_bindtex( &wrender.fbdepth, 3 ); shader_water_uTexBack( 3 ); - shader_water_uTime( vg_time ); + shader_water_uTime( vg.time ); shader_water_uCamera( camera[3] ); shader_water_uSurfaceY( wrender.height );