Search
lxdream.org :: lxdream/src/pvr2/glrender.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/glrender.c
changeset 736:a02d1475ccfd
prev687:6bdc2b7032ea
next847:2089244671d2
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
1.1 --- a/src/pvr2/glrender.c Sat Jun 14 11:54:15 2008 +0000
1.2 +++ b/src/pvr2/glrender.c Mon Jul 14 07:44:42 2008 +0000
1.3 @@ -25,25 +25,25 @@
1.4 #include "pvr2/glutil.h"
1.5
1.6 int pvr2_poly_depthmode[8] = { GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL,
1.7 - GL_GREATER, GL_NOTEQUAL, GL_GEQUAL,
1.8 - GL_ALWAYS };
1.9 + GL_GREATER, GL_NOTEQUAL, GL_GEQUAL,
1.10 + GL_ALWAYS };
1.11 int pvr2_poly_srcblend[8] = {
1.12 - GL_ZERO, GL_ONE, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
1.13 - GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
1.14 - GL_ONE_MINUS_DST_ALPHA };
1.15 + GL_ZERO, GL_ONE, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
1.16 + GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
1.17 + GL_ONE_MINUS_DST_ALPHA };
1.18 int pvr2_poly_dstblend[8] = {
1.19 - GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
1.20 - GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
1.21 - GL_ONE_MINUS_DST_ALPHA };
1.22 + GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
1.23 + GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
1.24 + GL_ONE_MINUS_DST_ALPHA };
1.25 int pvr2_poly_texblend[4] = {
1.26 - GL_REPLACE,
1.27 - GL_MODULATE,
1.28 - GL_DECAL,
1.29 - GL_MODULATE
1.30 + GL_REPLACE,
1.31 + GL_MODULATE,
1.32 + GL_DECAL,
1.33 + GL_MODULATE
1.34 };
1.35 int pvr2_render_colour_format[8] = {
1.36 - COLFMT_BGRA1555, COLFMT_RGB565, COLFMT_BGRA4444, COLFMT_BGRA1555,
1.37 - COLFMT_BGR888, COLFMT_BGRA8888, COLFMT_BGRA8888, COLFMT_BGRA4444 };
1.38 + COLFMT_BGRA1555, COLFMT_RGB565, COLFMT_BGRA4444, COLFMT_BGRA1555,
1.39 + COLFMT_BGR888, COLFMT_BGRA8888, COLFMT_BGRA8888, COLFMT_BGRA4444 };
1.40
1.41
1.42 /**
1.43 @@ -63,20 +63,20 @@
1.44 {
1.45 int i;
1.46 for( i=0; i < pvr2_scene.poly_count; i++ ) {
1.47 - struct polygon_struct *poly = &pvr2_scene.poly_array[i];
1.48 - if( POLY1_TEXTURED(poly->context[0]) ) {
1.49 - poly->tex_id = texcache_get_texture( poly->context[2],
1.50 - POLY2_TEX_WIDTH(poly->context[1]),
1.51 - POLY2_TEX_HEIGHT(poly->context[1]) );
1.52 - if( poly->mod_vertex_index != -1 ) {
1.53 - poly->mod_tex_id = texcache_get_texture( poly->context[4],
1.54 - POLY2_TEX_WIDTH(poly->context[3]),
1.55 - POLY2_TEX_HEIGHT(poly->context[3]) );
1.56 - }
1.57 - } else {
1.58 - poly->tex_id = -1;
1.59 - poly->mod_tex_id = -1;
1.60 - }
1.61 + struct polygon_struct *poly = &pvr2_scene.poly_array[i];
1.62 + if( POLY1_TEXTURED(poly->context[0]) ) {
1.63 + poly->tex_id = texcache_get_texture( poly->context[2],
1.64 + POLY2_TEX_WIDTH(poly->context[1]),
1.65 + POLY2_TEX_HEIGHT(poly->context[1]) );
1.66 + if( poly->mod_vertex_index != -1 ) {
1.67 + poly->mod_tex_id = texcache_get_texture( poly->context[4],
1.68 + POLY2_TEX_WIDTH(poly->context[3]),
1.69 + POLY2_TEX_HEIGHT(poly->context[3]) );
1.70 + }
1.71 + } else {
1.72 + poly->tex_id = -1;
1.73 + poly->mod_tex_id = -1;
1.74 + }
1.75 }
1.76 }
1.77
1.78 @@ -89,11 +89,11 @@
1.79 {
1.80
1.81 if( glsl_is_supported() ) {
1.82 - if( !glsl_load_shaders( glsl_vertex_shader_src, NULL ) ) {
1.83 + if( !glsl_load_shaders( glsl_vertex_shader_src, NULL ) ) {
1.84 WARN( "Unable to load GL shaders" );
1.85 }
1.86 }
1.87 -
1.88 +
1.89 texcache_gl_init(); // Allocate texture IDs
1.90 glCullFace( GL_BACK );
1.91 glEnable( GL_BLEND );
1.92 @@ -101,7 +101,7 @@
1.93 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
1.94 glMatrixMode(GL_MODELVIEW);
1.95 glLoadIdentity();
1.96 -
1.97 +
1.98 #ifdef HAVE_OPENGL_CLAMP_COLOR
1.99 if( isGLExtensionSupported("GL_ARB_color_buffer_float") ) {
1.100 glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, GL_FALSE );
1.101 @@ -129,57 +129,57 @@
1.102 {
1.103 uint32_t poly1 = context[0], poly2, texture;
1.104 if( render_mode == RENDER_FULLMOD ) {
1.105 - poly2 = context[3];
1.106 - texture = context[4];
1.107 + poly2 = context[3];
1.108 + texture = context[4];
1.109 } else {
1.110 - poly2 = context[1];
1.111 - texture = context[2];
1.112 + poly2 = context[1];
1.113 + texture = context[2];
1.114 }
1.115 -
1.116 +
1.117 glDepthFunc( POLY1_DEPTH_MODE(poly1) );
1.118 glDepthMask( POLY1_DEPTH_WRITE(poly1) ? GL_TRUE : GL_FALSE );
1.119 -
1.120 +
1.121 switch( POLY1_CULL_MODE(poly1) ) {
1.122 case CULL_NONE:
1.123 case CULL_SMALL:
1.124 - glDisable( GL_CULL_FACE );
1.125 - break;
1.126 + glDisable( GL_CULL_FACE );
1.127 + break;
1.128 case CULL_CCW:
1.129 - glEnable( GL_CULL_FACE );
1.130 - glFrontFace( GL_CW );
1.131 - break;
1.132 + glEnable( GL_CULL_FACE );
1.133 + glFrontFace( GL_CW );
1.134 + break;
1.135 case CULL_CW:
1.136 - glEnable( GL_CULL_FACE );
1.137 - glFrontFace( GL_CCW );
1.138 - break;
1.139 + glEnable( GL_CULL_FACE );
1.140 + glFrontFace( GL_CCW );
1.141 + break;
1.142 }
1.143
1.144 if( POLY1_SPECULAR(poly1) ) {
1.145 - glEnable(GL_COLOR_SUM);
1.146 + glEnable(GL_COLOR_SUM);
1.147 } else {
1.148 - glDisable(GL_COLOR_SUM);
1.149 + glDisable(GL_COLOR_SUM);
1.150 }
1.151
1.152
1.153 if( POLY1_TEXTURED(poly1) ) {
1.154 - glEnable(GL_TEXTURE_2D);
1.155 - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, pvr2_poly_texblend[POLY2_TEX_BLEND(poly2)] );
1.156 - if( POLY2_TEX_CLAMP_U(poly2) ) {
1.157 - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1.158 - } else if( POLY2_TEX_MIRROR_U(poly2) ) {
1.159 - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT_ARB );
1.160 - } else {
1.161 - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
1.162 - }
1.163 - if( POLY2_TEX_CLAMP_V(poly2) ) {
1.164 - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1.165 - } else if( POLY2_TEX_MIRROR_V(poly2) ) {
1.166 - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT_ARB );
1.167 - } else {
1.168 - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
1.169 - }
1.170 + glEnable(GL_TEXTURE_2D);
1.171 + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, pvr2_poly_texblend[POLY2_TEX_BLEND(poly2)] );
1.172 + if( POLY2_TEX_CLAMP_U(poly2) ) {
1.173 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1.174 + } else if( POLY2_TEX_MIRROR_U(poly2) ) {
1.175 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT_ARB );
1.176 + } else {
1.177 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
1.178 + }
1.179 + if( POLY2_TEX_CLAMP_V(poly2) ) {
1.180 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1.181 + } else if( POLY2_TEX_MIRROR_V(poly2) ) {
1.182 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT_ARB );
1.183 + } else {
1.184 + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
1.185 + }
1.186 } else {
1.187 - glDisable( GL_TEXTURE_2D );
1.188 + glDisable( GL_TEXTURE_2D );
1.189 }
1.190
1.191 glShadeModel( POLY1_SHADE_MODEL(poly1) );
1.192 @@ -189,7 +189,7 @@
1.193 glBlendFunc( srcblend, destblend );
1.194
1.195 if( POLY2_SRC_BLEND_TARGET(poly2) || POLY2_DEST_BLEND_TARGET(poly2) ) {
1.196 - ERROR( "Accumulation buffer not supported" );
1.197 + ERROR( "Accumulation buffer not supported" );
1.198 }
1.199
1.200 }
1.201 @@ -198,7 +198,7 @@
1.202 static void gl_render_poly( struct polygon_struct *poly )
1.203 {
1.204 if( poly->tex_id != -1 ) {
1.205 - glBindTexture(GL_TEXTURE_2D, poly->tex_id);
1.206 + glBindTexture(GL_TEXTURE_2D, poly->tex_id);
1.207 }
1.208 render_set_context( poly->context, RENDER_NORMAL );
1.209 glDrawArrays(GL_TRIANGLE_STRIP, poly->vertex_index, poly->vertex_count );
1.210 @@ -228,29 +228,29 @@
1.211 struct polygon_struct *poly;
1.212
1.213 while(1) {
1.214 - uint32_t entry = *tile_list++;
1.215 - switch( entry >> 28 ) {
1.216 - case 0x0F:
1.217 - return; // End-of-list
1.218 - case 0x0E:
1.219 - tile_list = (uint32_t *)(video_base + (entry&0x007FFFFF));
1.220 - break;
1.221 - case 0x08: case 0x09: case 0x0A: case 0x0B:
1.222 - strip_count = ((entry >> 25) & 0x0F)+1;
1.223 - poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];
1.224 - while( strip_count > 0 ) {
1.225 - assert( poly != NULL );
1.226 - gl_render_poly( poly );
1.227 - poly = poly->next;
1.228 - strip_count--;
1.229 - }
1.230 - break;
1.231 - default:
1.232 - if( entry & 0x7E000000 ) {
1.233 - poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];
1.234 - gl_render_poly( poly );
1.235 - }
1.236 - }
1.237 + uint32_t entry = *tile_list++;
1.238 + switch( entry >> 28 ) {
1.239 + case 0x0F:
1.240 + return; // End-of-list
1.241 + case 0x0E:
1.242 + tile_list = (uint32_t *)(video_base + (entry&0x007FFFFF));
1.243 + break;
1.244 + case 0x08: case 0x09: case 0x0A: case 0x0B:
1.245 + strip_count = ((entry >> 25) & 0x0F)+1;
1.246 + poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];
1.247 + while( strip_count > 0 ) {
1.248 + assert( poly != NULL );
1.249 + gl_render_poly( poly );
1.250 + poly = poly->next;
1.251 + strip_count--;
1.252 + }
1.253 + break;
1.254 + default:
1.255 + if( entry & 0x7E000000 ) {
1.256 + poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];
1.257 + gl_render_poly( poly );
1.258 + }
1.259 + }
1.260 }
1.261 }
1.262
1.263 @@ -267,10 +267,10 @@
1.264 display_driver->set_render_target(buffer);
1.265 pvr2_check_palette_changed();
1.266 pvr2_scene_load_textures();
1.267 -
1.268 +
1.269 gettimeofday( &tex_tv, NULL );
1.270 uint32_t ms = (tex_tv.tv_sec - start_tv.tv_sec) * 1000 +
1.271 - (tex_tv.tv_usec - start_tv.tv_usec)/1000;
1.272 + (tex_tv.tv_usec - start_tv.tv_usec)/1000;
1.273 DEBUG( "Scene setup in %dms", ms );
1.274
1.275 /* Setup view projection matrix */
1.276 @@ -282,7 +282,7 @@
1.277 farz*= 4.0;
1.278 }
1.279 glOrtho( 0, pvr2_scene.buffer_width, pvr2_scene.buffer_height, 0,
1.280 - -farz, -nearz );
1.281 + -farz, -nearz );
1.282 float alphaRef = ((float)(MMIO_READ(PVR2, RENDER_ALPHA_REF)&0xFF)+1)/256.0;
1.283 glAlphaFunc( GL_GEQUAL, alphaRef );
1.284
1.285 @@ -302,39 +302,39 @@
1.286
1.287 /* Render the background */
1.288 gl_render_bkgnd( pvr2_scene.bkgnd_poly );
1.289 -
1.290 +
1.291 glEnable( GL_SCISSOR_TEST );
1.292
1.293 /* Process the segment list */
1.294 struct tile_segment *segment = pvr2_scene.segment_list;
1.295 do {
1.296 - int tilex = SEGMENT_X(segment->control);
1.297 - int tiley = SEGMENT_Y(segment->control);
1.298 -
1.299 - uint32_t tile_bounds[4] = { tilex << 5, (tilex+1)<<5, tiley<<5, (tiley+1)<<5 };
1.300 - if( !clip_tile_bounds(tile_bounds, pvr2_scene.bounds) ) {
1.301 - continue; // fully clipped, skip tile
1.302 - }
1.303 + int tilex = SEGMENT_X(segment->control);
1.304 + int tiley = SEGMENT_Y(segment->control);
1.305
1.306 - /* Clip to the visible part of the tile */
1.307 - glScissor( tile_bounds[0], pvr2_scene.buffer_height-tile_bounds[3],
1.308 - tile_bounds[1]-tile_bounds[0], tile_bounds[3] - tile_bounds[2] );
1.309 - if( IS_TILE_PTR(segment->opaque_ptr) ) {
1.310 - gl_render_tilelist(segment->opaque_ptr);
1.311 - }
1.312 - if( IS_TILE_PTR(segment->trans_ptr) ) {
1.313 - if( pvr2_scene.sort_mode == SORT_NEVER ||
1.314 - (pvr2_scene.sort_mode == SORT_TILEFLAG && (segment->control&SEGMENT_SORT_TRANS))) {
1.315 - gl_render_tilelist(segment->trans_ptr);
1.316 - } else {
1.317 - render_autosort_tile(segment->trans_ptr, RENDER_NORMAL );
1.318 - }
1.319 - }
1.320 - if( IS_TILE_PTR(segment->punchout_ptr) ) {
1.321 - glEnable(GL_ALPHA_TEST );
1.322 - render_autosort_tile(segment->punchout_ptr, RENDER_NORMAL );
1.323 - glDisable(GL_ALPHA_TEST );
1.324 - }
1.325 + uint32_t tile_bounds[4] = { tilex << 5, (tilex+1)<<5, tiley<<5, (tiley+1)<<5 };
1.326 + if( !clip_tile_bounds(tile_bounds, pvr2_scene.bounds) ) {
1.327 + continue; // fully clipped, skip tile
1.328 + }
1.329 +
1.330 + /* Clip to the visible part of the tile */
1.331 + glScissor( tile_bounds[0], pvr2_scene.buffer_height-tile_bounds[3],
1.332 + tile_bounds[1]-tile_bounds[0], tile_bounds[3] - tile_bounds[2] );
1.333 + if( IS_TILE_PTR(segment->opaque_ptr) ) {
1.334 + gl_render_tilelist(segment->opaque_ptr);
1.335 + }
1.336 + if( IS_TILE_PTR(segment->trans_ptr) ) {
1.337 + if( pvr2_scene.sort_mode == SORT_NEVER ||
1.338 + (pvr2_scene.sort_mode == SORT_TILEFLAG && (segment->control&SEGMENT_SORT_TRANS))) {
1.339 + gl_render_tilelist(segment->trans_ptr);
1.340 + } else {
1.341 + render_autosort_tile(segment->trans_ptr, RENDER_NORMAL );
1.342 + }
1.343 + }
1.344 + if( IS_TILE_PTR(segment->punchout_ptr) ) {
1.345 + glEnable(GL_ALPHA_TEST );
1.346 + render_autosort_tile(segment->punchout_ptr, RENDER_NORMAL );
1.347 + glDisable(GL_ALPHA_TEST );
1.348 + }
1.349 } while( !IS_LAST_SEGMENT(segment++) );
1.350 glDisable( GL_SCISSOR_TEST );
1.351
1.352 @@ -342,6 +342,6 @@
1.353
1.354 gettimeofday( &end_tv, NULL );
1.355 ms = (end_tv.tv_sec - tex_tv.tv_sec) * 1000 +
1.356 - (end_tv.tv_usec - tex_tv.tv_usec)/1000;
1.357 + (end_tv.tv_usec - tex_tv.tv_usec)/1000;
1.358 DEBUG( "Scene render in %dms", ms );
1.359 }
.