medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit c463902a0cc268d385e577f420a1a22c86744de1
parent d7abbed49f3640991047eba1b90cc27eee1750dd
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Thu Nov  3 23:22:21 +0200

Use UBOs for some things in btt.so

Diffstat:
mod_btt.cc | 40+++++++++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 11 deletions(-)
diff --git a/mod_btt.cc b/mod_btt.cc @@ -14,13 +14,15 @@ static ImmediateTriangle triangles[ 512000 ]; static ImmediateContext imm; -static const GLchar * const vert_src = GLSL( +static const GLchar * vert_src = GLSL( in vec3 position; out vec3 smooth_position; out float depth; - uniform mat4 vp; + layout( std140 ) uniform v_hot { + mat4 vp; + }; void main() { gl_Position = vp * vec4( position, 1.0 ); @@ -35,10 +37,13 @@ static const GLchar * frag_src = GLSL( out vec4 colour; - uniform float sun; + layout( std140 ) uniform f_hot { + vec2 dimensions; + float sun; + }; + uniform sampler2D normals; uniform sampler2D horizons; - uniform vec2 dimensions; void main() { vec3 normal = normalize( texture( normals, smooth_position.xy / dimensions ).xyz ); @@ -66,7 +71,7 @@ static const GLchar * frag_src = GLSL( } ); -static const GLchar * const vert_outline_src = GLSL( +static const GLchar * vert_outline_src = GLSL( in vec3 position; in vec3 colour; @@ -123,6 +128,8 @@ static const glm::mat4 P( glm::perspective( glm::radians( 120.0f ), ( float ) WI static float * horizons; +static UB ub_fs, ub_vs; + extern "C" GAME_INIT( game_init ) { game->pos = glm::vec3( 100, 200, 100 ); game->angles = glm::radians( glm::vec3( -90, 45, 0 ) ); @@ -130,17 +137,17 @@ extern "C" GAME_INIT( game_init ) { game->test_sun = 0.3f; game->test_shader = renderer_new_shader( vert_src, frag_src ); - game->test_un_VP = glGetUniformLocation( game->test_shader, "vp" ); - game->test_un_sun = glGetUniformLocation( game->test_shader, "sun" ); game->test_un_normals = glGetUniformLocation( game->test_shader, "normals" ); game->test_un_horizons = glGetUniformLocation( game->test_shader, "horizons" ); - game->test_un_dimensions = glGetUniformLocation( game->test_shader, "dimensions" ); game->test_outline_shader = renderer_new_shader( vert_outline_src, frag_outline_src ); game->test_outline_at_position = glGetAttribLocation( game->test_outline_shader, "position" ); game->test_outline_at_colour = glGetAttribLocation( game->test_outline_shader, "colour" ); game->test_outline_un_vp = glGetUniformLocation( game->test_outline_shader, "vp" ); + ub_vs = renderer_new_ub(); + ub_fs = renderer_new_ub(); + int w, h; u8 * pixels = stbi_load( "terrains/mountains512.png", &w, &h, NULL, 1 ); heightmap_init( &game->hm, pixels, w, h ); @@ -179,6 +186,11 @@ extern "C" GAME_INIT( game_init ) { skybox_init( &game->skybox ); } +struct FSData { + v2 dimensions; + float sun; +}; + extern "C" GAME_FRAME( game_frame ) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); @@ -217,14 +229,20 @@ extern "C" GAME_FRAME( game_frame ) { ); glUseProgram( game->test_shader ); - glUniformMatrix4fv( game->test_un_VP, 1, GL_FALSE, glm::value_ptr( VP ) ); - glUniform1f( game->test_un_sun, game->test_sun ); - glUniform2f( game->test_un_dimensions, game->hm.width, game->hm.height ); glUniform1i( game->test_un_normals, 0 ); glUniform1i( game->test_un_horizons, 1 ); + FSData fs_data = { }; + fs_data.sun = game->test_sun; + fs_data.dimensions = v2( game->hm.width, game->hm.height ); + + renderer_ub_data( ub_vs, &VP, sizeof( VP ) ); + renderer_ub_data( ub_fs, &fs_data, sizeof( fs_data ) ); + RenderState render_state = { }; render_state.shader = game->test_shader; + render_state.ubs[ UB_VS_HOT ] = ub_vs; + render_state.ubs[ UB_FS_HOT ] = ub_fs; gpubtt_render( &game->gpubtt, render_state ); immediate_init( &imm, triangles, array_count( triangles ) );