Search
lxdream.org :: lxdream/src/pvr2/glrender.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/glrender.c
changeset 1145:45674791c6ad
prev1140:7dc1c71ece76
next1151:e1848ca9b5b1
author nkeynes
date Mon Nov 08 14:33:38 2010 +1000 (10 years ago)
permissions -rw-r--r--
last change Introduce tile iterators to simplify processing of the tile lists
file annotate diff log raw
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.3 @@ -21,8 +21,9 @@
1.4 #include "display.h"
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.11
1.12 #define IS_EMPTY_TILE_LIST(p) ((*((uint32_t *)(pvr2_main_ram+(p))) >> 28) == 0x0F)
1.13
1.14 @@ -59,6 +60,16 @@
1.15 return tile[0] < tile[1] && tile[2] < tile[3];
1.16 }
1.17
1.18 +static void drawrect2d( uint32_t tile_bounds[], float z )
1.19 +{
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.25 + glEnd();
1.26 +}
1.27 +
1.28 void pvr2_scene_load_textures()
1.29 {
1.30 int i;
1.31 @@ -239,107 +250,8 @@
1.32 }
1.33 }
1.34
1.35 -static void gl_render_bkgnd( struct polygon_struct *poly )
1.36 -{
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.43 -}
1.44
1.45 -void gl_render_tilelist( pvraddr_t tile_entry, gboolean set_depth )
1.46 -{
1.47 - uint32_t *tile_list = (uint32_t *)(pvr2_main_ram+tile_entry);
1.48 - int strip_count;
1.49 - struct polygon_struct *poly;
1.50 -
1.51 - if( !IS_TILE_PTR(tile_entry) )
1.52 - return;
1.53 -
1.54 - while(1) {
1.55 - uint32_t entry = *tile_list++;
1.56 - switch( entry >> 28 ) {
1.57 - case 0x0F:
1.58 - return; // End-of-list
1.59 - case 0x0E:
1.60 - tile_list = (uint32_t *)(pvr2_main_ram + (entry&0x007FFFFF));
1.61 - break;
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.69 - strip_count--;
1.70 - }
1.71 - break;
1.72 - default:
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.76 - }
1.77 - }
1.78 - }
1.79 -}
1.80 -
1.81 -/**
1.82 - * Render the tilelist with depthbuffer updates only.
1.83 - */
1.84 -void gl_render_tilelist_depthonly( pvraddr_t tile_entry )
1.85 -{
1.86 - uint32_t *tile_list = (uint32_t *)(pvr2_main_ram+tile_entry);
1.87 - int strip_count;
1.88 - struct polygon_struct *poly;
1.89 -
1.90 - if( !IS_TILE_PTR(tile_entry) )
1.91 - return;
1.92 -
1.93 - while(1) {
1.94 - uint32_t entry = *tile_list++;
1.95 - switch( entry >> 28 ) {
1.96 - case 0x0F:
1.97 - return; // End-of-list
1.98 - case 0x0E:
1.99 - tile_list = (uint32_t *)(pvr2_main_ram + (entry&0x007FFFFF));
1.100 - break;
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.108 - }
1.109 - poly = poly->next;
1.110 - strip_count--;
1.111 - }
1.112 - break;
1.113 - default:
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.119 - }
1.120 - }
1.121 - }
1.122 - }
1.123 -}
1.124 -
1.125 -static void drawrect2d( uint32_t tile_bounds[], float z )
1.126 -{
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.132 - glEnd();
1.133 -}
1.134 -
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.137 {
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.141 }
1.142 }
1.143
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.146 {
1.147 - uint32_t *tile_list = (uint32_t *)(pvr2_main_ram+tile_entry);
1.148 - int strip_count;
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.156 +}
1.157 +
1.158 +void gl_render_tilelist( pvraddr_t tile_entry, gboolean set_depth )
1.159 +{
1.160 + tileentryiter list;
1.161 +
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.165 + do {
1.166 + gl_render_poly(poly, set_depth);
1.167 + poly = poly->next;
1.168 + } while( list.strip_count-- > 0 );
1.169 + }
1.170 + }
1.171 +}
1.172 +
1.173 +/**
1.174 + * Render the tilelist with depthbuffer updates only.
1.175 + */
1.176 +static void gl_render_tilelist_depthonly( pvraddr_t tile_entry )
1.177 +{
1.178 + tileentryiter list;
1.179 +
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.183 + do {
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.188 + }
1.189 + }
1.190 +}
1.191 +
1.192 +static void gl_render_modifier_tilelist( pvraddr_t tile_entry, uint32_t tile_bounds[] )
1.193 +{
1.194 + tileentryiter list;
1.195
1.196 if( !IS_TILE_PTR(tile_entry) )
1.197 return;
1.198
1.199 glEnable( GL_STENCIL_TEST );
1.200 glEnable( GL_DEPTH_TEST );
1.201 - glDepthFunc( GL_LEQUAL );
1.202 -
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.208
1.209 - while(1) {
1.210 - uint32_t entry = *tile_list++;
1.211 - switch( entry >> 28 ) {
1.212 - case 0x0F:
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.217 - case 0x0E:
1.218 - tile_list = (uint32_t *)(pvr2_main_ram + (entry&0x007FFFFF));
1.219 - break;
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.227 + do {
1.228 gl_render_modifier_polygon( poly, tile_bounds );
1.229 poly = poly->next;
1.230 - strip_count--;
1.231 - }
1.232 - break;
1.233 - default:
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.237 - }
1.238 + } while( list.strip_count-- > 0 );
1.239 }
1.240 }
1.241 -
1.242 + glDepthMask( GL_TRUE );
1.243 + glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
1.244 + glDisable( GL_STENCIL_TEST );
1.245 }
1.246
1.247 -
1.248 /**
1.249 * Render the currently defined scene in pvr2_scene
1.250 */
.