Search
lxdream.org :: lxdream :: r1154:5225c7c059ce
lxdream 0.9.1
released Jun 29
Download Now
changeset1154:5225c7c059ce
parent1153:00e507e4025c
child1155:f9aefb4613e5
authornkeynes
dateMon Jan 17 21:22:06 2011 +1000 (8 years ago)
Avoid rebinding textures unnecessarily (actually saves a surprising amount
of runtime)
src/pvr2/glrender.c
src/pvr2/pvr2.h
src/pvr2/rendsort.c
1.1 --- a/src/pvr2/glrender.c Thu Dec 23 18:14:29 2010 +1000
1.2 +++ b/src/pvr2/glrender.c Mon Jan 17 21:22:06 2011 +1000
1.3 @@ -46,6 +46,15 @@
1.4 };
1.5
1.6 static gboolean have_shaders = FALSE;
1.7 +static int currentTexId = -1;
1.8 +
1.9 +static inline void bind_texture(int texid)
1.10 +{
1.11 + if( currentTexId != texid ) {
1.12 + currentTexId = texid;
1.13 + glBindTexture(GL_TEXTURE_2D, texid);
1.14 + }
1.15 +}
1.16
1.17 /**
1.18 * Clip the tile bounds to the clipping plane.
1.19 @@ -70,7 +79,7 @@
1.20 glEnd();
1.21 }
1.22
1.23 -void pvr2_scene_load_textures()
1.24 +static void pvr2_scene_load_textures()
1.25 {
1.26 int i;
1.27
1.28 @@ -164,7 +173,7 @@
1.29 /**
1.30 * Setup the texture/shading settings (TSP) which vary between mod/unmod modes.
1.31 */
1.32 -void render_set_tsp_context( uint32_t poly1, uint32_t poly2 )
1.33 +static void render_set_tsp_context( uint32_t poly1, uint32_t poly2 )
1.34 {
1.35 glShadeModel( POLY1_SHADE_MODEL(poly1) );
1.36
1.37 @@ -200,7 +209,7 @@
1.38 * @param depth_mode force depth mode, or 0 to use the polygon's
1.39 * depth mode.
1.40 */
1.41 -void render_set_context( uint32_t *context, gboolean set_depth )
1.42 +static void render_set_context( uint32_t *context, gboolean set_depth )
1.43 {
1.44 render_set_base_context(context[0], set_depth);
1.45 render_set_tsp_context(context[0],context[1]);
1.46 @@ -227,7 +236,7 @@
1.47 if( poly->vertex_count == 0 )
1.48 return; /* Culled */
1.49
1.50 - glBindTexture(GL_TEXTURE_2D, poly->tex_id);
1.51 + bind_texture(poly->tex_id);
1.52 if( poly->mod_vertex_index == -1 ) {
1.53 render_set_context( poly->context, set_depth );
1.54 gl_draw_vertexes(poly);
1.55 @@ -239,9 +248,7 @@
1.56 gl_draw_vertexes(poly);
1.57
1.58 if( pvr2_scene.shadow_mode == SHADOW_FULL ) {
1.59 - if( poly->mod_tex_id != poly->tex_id ) {
1.60 - glBindTexture(GL_TEXTURE_2D, poly->mod_tex_id);
1.61 - }
1.62 + bind_texture(poly->mod_tex_id);
1.63 render_set_tsp_context( poly->context[0], poly->context[3] );
1.64 }
1.65 glStencilFunc(GL_EQUAL, 2, 2);
1.66 @@ -319,7 +326,7 @@
1.67
1.68 static void gl_render_bkgnd( struct polygon_struct *poly )
1.69 {
1.70 - glBindTexture(GL_TEXTURE_2D, poly->tex_id);
1.71 + bind_texture(poly->tex_id);
1.72 render_set_tsp_context( poly->context[0], poly->context[1] );
1.73 glDisable( GL_DEPTH_TEST );
1.74 glBlendFunc( GL_ONE, GL_ZERO );
1.75 @@ -327,6 +334,14 @@
1.76 glEnable( GL_DEPTH_TEST );
1.77 }
1.78
1.79 +void gl_render_triangle( struct polygon_struct *poly, int index )
1.80 +{
1.81 + bind_texture(poly->tex_id);
1.82 + render_set_tsp_context( poly->context[0], poly->context[1] );
1.83 + glDrawArrays(GL_TRIANGLE_STRIP, poly->vertex_index + index, 3 );
1.84 +
1.85 +}
1.86 +
1.87 void gl_render_tilelist( pvraddr_t tile_entry, gboolean set_depth )
1.88 {
1.89 tileentryiter list;
1.90 @@ -402,6 +417,7 @@
1.91 display_driver->set_render_target(buffer);
1.92 pvr2_check_palette_changed();
1.93 pvr2_scene_load_textures();
1.94 + currentTexId = -1;
1.95
1.96 gettimeofday( &tex_tv, NULL );
1.97 uint32_t ms = (tex_tv.tv_sec - start_tv.tv_sec) * 1000 +
2.1 --- a/src/pvr2/pvr2.h Thu Dec 23 18:14:29 2010 +1000
2.2 +++ b/src/pvr2/pvr2.h Mon Jan 17 21:22:06 2011 +1000
2.3 @@ -283,8 +283,8 @@
2.4
2.5 void render_autosort_tile( pvraddr_t tile_entry, int render_mode );
2.6
2.7 -void render_set_context( uint32_t *context, gboolean set_depth );
2.8 -void render_set_tsp_context( uint32_t poly1, uint32_t poly2 );
2.9 +struct polygon_struct;
2.10 +void gl_render_triangle( struct polygon_struct *poly, int index );
2.11
2.12 void gl_render_tilelist( pvraddr_t tile_entry, gboolean set_depth );
2.13
3.1 --- a/src/pvr2/rendsort.c Thu Dec 23 18:14:29 2010 +1000
3.2 +++ b/src/pvr2/rendsort.c Mon Jan 17 21:22:06 2011 +1000
3.3 @@ -172,9 +172,7 @@
3.4 int i;
3.5 for( i=0; i<num_triangles; i++ ) {
3.6 struct polygon_struct *poly = triangles[i]->poly;
3.7 - glBindTexture(GL_TEXTURE_2D, poly->tex_id);
3.8 - render_set_tsp_context( poly->context[0], poly->context[1] );
3.9 - glDrawArrays(GL_TRIANGLE_STRIP, poly->vertex_index + triangles[i]->triangle_num, 3 );
3.10 + gl_render_triangle(triangles[i]->poly, triangles[i]->triangle_num);
3.11 }
3.12 }
3.13
.