medfall

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

commit ce0d21eec3e45be8f658296daa7e5bbafc1871e0
parent e16ded4b1b4c5641c3c09e179b099705bb3d7766
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Fri Nov  4 19:42:23 +0200

Do the glUniform1i for textures in renderer_new_shader

Diffstat:
mod_btt.cc | 15+++++++--------
renderer.cc | 11+++++++++++
renderer.h | 1+
3 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/mod_btt.cc b/mod_btt.cc @@ -136,9 +136,12 @@ extern "C" GAME_INIT( game_init ) { game->test_sun = 0.3f; - game->test_shader = renderer_new_shader( vert_src, frag_src ); - game->test_un_normals = glGetUniformLocation( game->test_shader, "normals" ); - game->test_un_horizons = glGetUniformLocation( game->test_shader, "horizons" ); + ShaderConfig terrain_config = { }; + terrain_config.vertex_src = vert_src; + terrain_config.fragment_src = frag_src; + terrain_config.texture_uniform_names[ 0 ] = "normals"; + terrain_config.texture_uniform_names[ 1 ] = "horizons"; + game->test_shader = renderer_new_shader( terrain_config ); game->test_outline_shader = renderer_new_shader( vert_outline_src, frag_outline_src ); game->test_outline_at_position = glGetAttribLocation( game->test_outline_shader, "position" ); @@ -228,13 +231,9 @@ extern "C" GAME_FRAME( game_frame ) { -game->pos ); - glUseProgram( game->test_shader ); - 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 ); + fs_data.sun = game->test_sun; renderer_ub_data( ub_vs, &VP, sizeof( VP ) ); renderer_ub_data( ub_fs, &fs_data, sizeof( fs_data ) ); diff --git a/renderer.cc b/renderer.cc @@ -201,6 +201,17 @@ Shader renderer_new_shader( ShaderConfig config ) { } } + glUseProgram( program ); + for( size_t i = 0; i < RENDERER_MAX_TEXTURES; i++ ) { + if( config.texture_uniform_names[ i ] != NULL ) { + GLuint uniform = glGetUniformLocation( program, config.texture_uniform_names[ i ] ); + if( uniform != -1 ) { + glUniform1i( uniform, i ); + } + } + } + glUseProgram( 0 ); + return checked_cast< Shader >( program ); } diff --git a/renderer.h b/renderer.h @@ -83,6 +83,7 @@ struct ShaderConfig { const char * vertex_src; const char * fragment_src; const char * geometry_src; + const char * texture_uniform_names[ RENDERER_MAX_TEXTURES ]; }; enum TextureFormat {