medfall

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

commit b0a761dbe44c9c0db56e7158af94f9f5901e539e
parent 49f25a2e4dd4bd10fdb38b1fda826e14da4856e6
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Thu Nov  3 22:19:23 +0200

Partially move the terrain renderer to the new renderer API

Diffstat:
terrain_manager.cc | 20+++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/terrain_manager.cc b/terrain_manager.cc @@ -1,7 +1,6 @@ #include <stdio.h> #include "glad.h" -#include "glsl.h" #include <glm/glm.hpp> #include <glm/gtc/type_ptr.hpp> #include <GLFW/glfw3.h> @@ -253,7 +252,7 @@ void terrain_init( } } - tm->shader = compile_shader( vert_src, frag_src, "colour" ); + tm->shader = renderer_new_shader( vert_src, frag_src ); tm->at_position = glGetAttribLocation( tm->shader, "position" ); tm->un_V = glGetUniformLocation( tm->shader, "v" ); @@ -404,8 +403,7 @@ void terrain_render( TerrainManager * tm, glm::mat4 V, glm::mat4 VP, float sun ) gpu_tile_data.btt, &ohm, ( v3 * ) tm->decompressed_tiles[ tx ][ ty ].normalmap, - gpu_tile_data.horizonmap, - tm->at_position + gpu_tile_data.horizonmap ); free( gpu_tile_data.btt_memory ); free( gpu_tile_data.horizonmap ); @@ -421,6 +419,8 @@ void terrain_render( TerrainManager * tm, glm::mat4 V, glm::mat4 VP, float sun ) glUniformMatrix4fv( tm->un_VP, 1, GL_FALSE, glm::value_ptr( VP ) ); glUniform1f( tm->un_sun, sun ); glUniform2f( tm->un_dimensions, TILE_SIZE, TILE_SIZE ); + glUniform1i( tm->un_normals, 0 ); + glUniform1i( tm->un_horizons, 1 ); /* start lighting */ float tbo1[ 15 ] = { @@ -433,10 +433,10 @@ void terrain_render( TerrainManager * tm, glm::mat4 V, glm::mat4 VP, float sun ) glBindBuffer( GL_TEXTURE_BUFFER, tm->tbo_point_light_origins ); glBufferData( GL_TEXTURE_BUFFER, sizeof( tbo1 ), tbo1, GL_DYNAMIC_DRAW ); glBindBuffer( GL_TEXTURE_BUFFER, 0 ); - glActiveTexture( GL_TEXTURE0 + 1 ); + glActiveTexture( GL_TEXTURE0 + 2 ); glBindTexture( GL_TEXTURE_BUFFER, tm->tex_point_light_origins ); glTexBuffer( GL_TEXTURE_BUFFER, GL_RGB32UI, tm->tbo_point_light_origins ); - glUniform1i( tm->un_point_light_origins, 1 ); + glUniform1i( tm->un_point_light_origins, 2 ); float tbo2[ 15 ] = { 15, 0, 0, @@ -448,12 +448,14 @@ void terrain_render( TerrainManager * tm, glm::mat4 V, glm::mat4 VP, float sun ) glBindBuffer( GL_TEXTURE_BUFFER, tm->tbo_point_light_colours ); glBufferData( GL_TEXTURE_BUFFER, sizeof( tbo2 ), tbo2, GL_DYNAMIC_DRAW ); glBindBuffer( GL_TEXTURE_BUFFER, 0 ); - glActiveTexture( GL_TEXTURE0 + 2 ); + glActiveTexture( GL_TEXTURE0 + 3 ); glBindTexture( GL_TEXTURE_BUFFER, tm->tex_point_light_colours ); glTexBuffer( GL_TEXTURE_BUFFER, GL_RGB32F, tm->tbo_point_light_colours ); - glUniform1i( tm->un_point_light_colours, 2 ); + glUniform1i( tm->un_point_light_colours, 3 ); /* end lighting */ + RenderState render_state = { }; + render_state.shader = tm->shader; for( u16 vy = 0; vy < VIEW_SIZE; vy++ ) { for( u16 vx = 0; vx < VIEW_SIZE; vx++ ) { s32 tx = vx + tm->tile_x - VIEW_HALF; @@ -463,7 +465,7 @@ void terrain_render( TerrainManager * tm, glm::mat4 V, glm::mat4 VP, float sun ) u32 state = load_acquire( &tm->tile_states[ tx ][ ty ] ); if( state == TILE_ON_GPU ) { - gpubtt_render( &tm->gpubtts[ tx ][ ty ], tm->un_normals, tm->un_horizons ); + gpubtt_render( &tm->gpubtts[ tx ][ ty ], render_state ); } } }