X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world_gate.h;h=b57c799fd33b68f31eb9a513fb8fc5f009253a52;hb=47941822dae18a018c985847b052e70214a3ccc6;hp=39a1e78d39dffdf8b2ff6f6034afd24aa039f910;hpb=4f96bd0040e35ecb21d353ee2b895129682d22c1;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world_gate.h b/world_gate.h index 39a1e78..b57c799 100644 --- a/world_gate.h +++ b/world_gate.h @@ -5,35 +5,15 @@ #ifndef WORLD_GATE_H #define WORLD_GATE_H -#define GATE_RENDER_PERFORMANCE - #include "common.h" #include "model.h" #include "render.h" -#ifndef GATE_RENDER_PERFORMANCE - #include "shaders/gate.h" -#else - #include "shaders/gatelq.h" -#endif - +#include "shaders/gatelq.h" #include "world_water.h" -static struct -{ - struct framebuffer fb; - glmesh mdl; -} -grender = -{ - .fb = { - .format = GL_RGB, - .div = 1 - } -}; - -static void gate_transform_update( teleport_gate *gate ) +VG_STATIC void gate_transform_update( teleport_gate *gate ) { m4x3f to_local; @@ -47,37 +27,23 @@ static void gate_transform_update( teleport_gate *gate ) m4x3_mul( gate->recv_to_world, to_local, gate->transport ); } -static void world_gates_init(void) +VG_STATIC void world_gates_init(void) { vg_info( "world_gates_init\n" ); -#ifndef GATE_RENDER_PERFORMANCE - shader_gate_register(); -#else shader_gatelq_register(); -#endif - mdl_header *mgate = mdl_load( "models/rs_gate.mdl" ); + vg_linear_clear( vg_mem.scratch ); + mdl_context *mgate = mdl_load_full( vg_mem.scratch, "models/rs_gate.mdl" ); vg_acquire_thread_sync(); { - fb_init( &grender.fb ); - mdl_unpack_glmesh( mgate, &grender.mdl ); + mdl_unpack_glmesh( mgate, &world.mesh_gate_surface ); } vg_release_thread_sync(); } -static void world_gates_free(void*_) -{ - fb_free( &grender.fb ); -} - -static void gate_fb_resize(void) -{ - fb_resize( &grender.fb ); -} - -static int render_gate( teleport_gate *gate, v3f viewpos, m4x3f camera ) +VG_STATIC int render_gate( teleport_gate *gate, v3f viewpos, m4x3f camera ) { v3f viewdir, gatedir; m3x3_mulv( camera, (v3f){0.0f,0.0f,-1.0f}, viewdir ); @@ -135,11 +101,7 @@ static int render_gate( teleport_gate *gate, v3f viewpos, m4x3f camera ) m4x4_mul( projection, view, projection ); -#ifndef GATE_RENDER_PERFORMANCE - fb_use( &grender.fb ); - glClearColor( 0.11f, 0.35f, 0.37f, 1.0f ); - glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT ); -#else + { shader_gatelq_use(); shader_gatelq_uPv( vg.pv ); shader_gatelq_uMdl( gate_xform ); @@ -154,53 +116,17 @@ static int render_gate( teleport_gate *gate, v3f viewpos, m4x3f camera ) glStencilFunc( GL_ALWAYS, 1, 0xFF ); glStencilMask( 0xFF ); - mesh_bind( &grender.mdl ); - mesh_draw( &grender.mdl ); + mesh_bind( &world.mesh_gate_surface ); + mesh_draw( &world.mesh_gate_surface ); glClear( GL_DEPTH_BUFFER_BIT ); glStencilFunc( GL_EQUAL, 1, 0xFF ); glStencilMask( 0x00 ); -#endif + } render_world( projection, cam_new ); -#ifndef GATE_RENDER_PERFORMANCE - - /* - * NOTE: Need to find a way to draw a stencil buffer into the water - * rendering - */ - - render_water_texture( cam_new ); - fb_use( &grender.fb ); - - render_water_surface( projection, cam_new ); - fb_use( NULL ); - - shader_gate_use(); - - shader_gate_uPv( vg_pv ); - shader_gate_uMdl( gate_xform ); - - fb_bindtex( &grender.fb, 0 ); - - shader_gate_uCam( viewpos ); - shader_gate_uTexMain( 0 ); - shader_gate_uTexWater( 1 ); - shader_gate_uTime( vg_time*0.25f ); - shader_gate_uInvRes( (v2f){ - 1.0f / (float)vg_window_x, - 1.0f / (float)vg_window_y }); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - glBlendEquation(GL_FUNC_ADD); - - mesh_bind( &grender.mdl ); - mesh_draw( &grender.mdl ); - - glDisable(GL_BLEND); -#else + { glDisable( GL_STENCIL_TEST ); render_water_texture( cam_new ); @@ -212,12 +138,12 @@ static int render_gate( teleport_gate *gate, v3f viewpos, m4x3f camera ) glStencilMask( 0xFF ); glStencilFunc( GL_ALWAYS, 1, 0xFF ); glDisable( GL_STENCIL_TEST ); -#endif + } return 1; } -static int gate_intersect( teleport_gate *gate, v3f pos, v3f last ) +VG_STATIC int gate_intersect( teleport_gate *gate, v3f pos, v3f last ) { v4f surface; m3x3_mulv( gate->to_world, (v3f){0.0f,0.0f,-1.0f}, surface );