1.1 --- a/src/pvr2/glrender.c Tue Oct 26 08:39:02 2010 +1000
1.2 +++ b/src/pvr2/glrender.c Mon Nov 08 14:33:38 2010 +1000
1.5 #include "pvr2/pvr2.h"
1.6 #include "pvr2/pvr2mmio.h"
1.7 +#include "pvr2/glutil.h"
1.8 #include "pvr2/scene.h"
1.9 -#include "pvr2/glutil.h"
1.10 +#include "pvr2/tileiter.h"
1.12 #define IS_EMPTY_TILE_LIST(p) ((*((uint32_t *)(pvr2_main_ram+(p))) >> 28) == 0x0F)
1.15 return tile[0] < tile[1] && tile[2] < tile[3];
1.18 +static void drawrect2d( uint32_t tile_bounds[], float z )
1.20 + glBegin( GL_QUADS );
1.21 + glVertex3f( tile_bounds[0], tile_bounds[2], z );
1.22 + glVertex3f( tile_bounds[1], tile_bounds[2], z );
1.23 + glVertex3f( tile_bounds[1], tile_bounds[3], z );
1.24 + glVertex3f( tile_bounds[0], tile_bounds[3], z );
1.28 void pvr2_scene_load_textures()
1.31 @@ -239,107 +250,8 @@
1.35 -static void gl_render_bkgnd( struct polygon_struct *poly )
1.37 - glBindTexture(GL_TEXTURE_2D, poly->tex_id);
1.38 - render_set_tsp_context( poly->context[0], poly->context[1] );
1.39 - glDisable( GL_DEPTH_TEST );
1.40 - glBlendFunc( GL_ONE, GL_ZERO );
1.41 - gl_draw_vertexes(poly);
1.42 - glEnable( GL_DEPTH_TEST );
1.45 -void gl_render_tilelist( pvraddr_t tile_entry, gboolean set_depth )
1.47 - uint32_t *tile_list = (uint32_t *)(pvr2_main_ram+tile_entry);
1.49 - struct polygon_struct *poly;
1.51 - if( !IS_TILE_PTR(tile_entry) )
1.55 - uint32_t entry = *tile_list++;
1.56 - switch( entry >> 28 ) {
1.58 - return; // End-of-list
1.60 - tile_list = (uint32_t *)(pvr2_main_ram + (entry&0x007FFFFF));
1.62 - case 0x08: case 0x09: case 0x0A: case 0x0B:
1.63 - strip_count = ((entry >> 25) & 0x0F)+1;
1.64 - poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];
1.65 - while( strip_count > 0 ) {
1.66 - assert( poly != NULL );
1.67 - gl_render_poly( poly, set_depth );
1.68 - poly = poly->next;
1.73 - if( entry & 0x7E000000 ) {
1.74 - poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];
1.75 - gl_render_poly( poly, set_depth );
1.82 - * Render the tilelist with depthbuffer updates only.
1.84 -void gl_render_tilelist_depthonly( pvraddr_t tile_entry )
1.86 - uint32_t *tile_list = (uint32_t *)(pvr2_main_ram+tile_entry);
1.88 - struct polygon_struct *poly;
1.90 - if( !IS_TILE_PTR(tile_entry) )
1.94 - uint32_t entry = *tile_list++;
1.95 - switch( entry >> 28 ) {
1.97 - return; // End-of-list
1.99 - tile_list = (uint32_t *)(pvr2_main_ram + (entry&0x007FFFFF));
1.101 - case 0x08: case 0x09: case 0x0A: case 0x0B:
1.102 - strip_count = ((entry >> 25) & 0x0F)+1;
1.103 - poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];
1.104 - while( strip_count > 0 ) {
1.105 - if( poly->vertex_count != 0 ) {
1.106 - render_set_base_context(poly->context[0],TRUE);
1.107 - gl_draw_vertexes(poly);
1.109 - poly = poly->next;
1.114 - if( entry & 0x7E000000 ) {
1.115 - poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];
1.116 - if( poly->vertex_count != 0 ) {
1.117 - render_set_base_context(poly->context[0],TRUE);
1.118 - gl_draw_vertexes(poly);
1.125 -static void drawrect2d( uint32_t tile_bounds[], float z )
1.127 - glBegin( GL_QUADS );
1.128 - glVertex3f( tile_bounds[0], tile_bounds[2], z );
1.129 - glVertex3f( tile_bounds[1], tile_bounds[2], z );
1.130 - glVertex3f( tile_bounds[1], tile_bounds[3], z );
1.131 - glVertex3f( tile_bounds[0], tile_bounds[3], z );
1.135 -void gl_render_modifier_polygon( struct polygon_struct *poly, uint32_t tile_bounds[] )
1.136 +static void gl_render_modifier_polygon( struct polygon_struct *poly, uint32_t tile_bounds[] )
1.138 /* A bit of explanation:
1.139 * In theory it works like this: generate a 1-bit stencil for each polygon
1.140 @@ -405,55 +317,79 @@
1.144 -void gl_render_modifier_tilelist( pvraddr_t tile_entry, uint32_t tile_bounds[] )
1.145 +static void gl_render_bkgnd( struct polygon_struct *poly )
1.147 - uint32_t *tile_list = (uint32_t *)(pvr2_main_ram+tile_entry);
1.149 - struct polygon_struct *poly;
1.150 + glBindTexture(GL_TEXTURE_2D, poly->tex_id);
1.151 + render_set_tsp_context( poly->context[0], poly->context[1] );
1.152 + glDisable( GL_DEPTH_TEST );
1.153 + glBlendFunc( GL_ONE, GL_ZERO );
1.154 + gl_draw_vertexes(poly);
1.155 + glEnable( GL_DEPTH_TEST );
1.158 +void gl_render_tilelist( pvraddr_t tile_entry, gboolean set_depth )
1.160 + tileentryiter list;
1.162 + FOREACH_TILEENTRY(list, tile_entry) {
1.163 + struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[TILEENTRYITER_POLYADDR(list)];
1.164 + if( poly != NULL ) {
1.166 + gl_render_poly(poly, set_depth);
1.167 + poly = poly->next;
1.168 + } while( list.strip_count-- > 0 );
1.174 + * Render the tilelist with depthbuffer updates only.
1.176 +static void gl_render_tilelist_depthonly( pvraddr_t tile_entry )
1.178 + tileentryiter list;
1.180 + FOREACH_TILEENTRY(list, tile_entry) {
1.181 + struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[TILEENTRYITER_POLYADDR(list)];
1.182 + if( poly != NULL ) {
1.184 + render_set_base_context(poly->context[0],TRUE);
1.185 + gl_draw_vertexes(poly);
1.186 + poly = poly->next;
1.187 + } while( list.strip_count-- > 0 );
1.192 +static void gl_render_modifier_tilelist( pvraddr_t tile_entry, uint32_t tile_bounds[] )
1.194 + tileentryiter list;
1.196 if( !IS_TILE_PTR(tile_entry) )
1.199 glEnable( GL_STENCIL_TEST );
1.200 glEnable( GL_DEPTH_TEST );
1.201 - glDepthFunc( GL_LEQUAL );
1.203 glStencilFunc( GL_ALWAYS, 0, 1 );
1.204 glStencilOp( GL_KEEP,GL_INVERT, GL_KEEP );
1.205 glStencilMask( 0x01 );
1.206 + glDepthFunc( GL_LEQUAL );
1.207 glDepthMask( GL_FALSE );
1.210 - uint32_t entry = *tile_list++;
1.211 - switch( entry >> 28 ) {
1.213 - glDepthMask( GL_TRUE );
1.214 - glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
1.215 - glDisable( GL_STENCIL_TEST );
1.216 - return; // End-of-list
1.218 - tile_list = (uint32_t *)(pvr2_main_ram + (entry&0x007FFFFF));
1.220 - case 0x08: case 0x09: case 0x0A: case 0x0B:
1.221 - strip_count = ((entry >> 25) & 0x0F)+1;
1.222 - poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];
1.223 - while( strip_count > 0 ) {
1.224 + FOREACH_TILEENTRY(list, tile_entry ) {
1.225 + struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[TILEENTRYITER_POLYADDR(list)];
1.226 + if( poly != NULL ) {
1.228 gl_render_modifier_polygon( poly, tile_bounds );
1.234 - if( entry & 0x7E000000 ) {
1.235 - poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];
1.236 - gl_render_modifier_polygon( poly, tile_bounds );
1.238 + } while( list.strip_count-- > 0 );
1.242 + glDepthMask( GL_TRUE );
1.243 + glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
1.244 + glDisable( GL_STENCIL_TEST );
1.249 * Render the currently defined scene in pvr2_scene