Search
lxdream.org :: lxdream :: r847:2089244671d2
lxdream 0.9.1
released Jun 29
Download Now
changeset847:2089244671d2
parent846:32ab6b592a8a
child848:34dc33c05106
authornkeynes
dateSun Sep 07 04:23:49 2008 +0000 (12 years ago)
Fog work-in-progress
src/pvr2/glrender.c
src/pvr2/pvr2mmio.h
src/pvr2/scene.c
src/pvr2/scene.h
src/pvr2/vertex.glsl
1.1 --- a/src/pvr2/glrender.c Sat Sep 06 08:16:39 2008 +0000
1.2 +++ b/src/pvr2/glrender.c Sun Sep 07 04:23:49 2008 +0000
1.3 @@ -113,6 +113,7 @@
1.4 glEnableClientState( GL_VERTEX_ARRAY );
1.5 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
1.6 glEnableClientState( GL_SECONDARY_COLOR_ARRAY );
1.7 + glEnableClientState( GL_FOG_COORDINATE_ARRAY_EXT );
1.8
1.9 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1.10 glClearDepth(0);
1.11 @@ -181,6 +182,22 @@
1.12 } else {
1.13 glDisable( GL_TEXTURE_2D );
1.14 }
1.15 +
1.16 + switch( POLY2_FOG_MODE(poly2) ) {
1.17 + case PVR2_POLY_FOG_LOOKUP:
1.18 + glFogfv( GL_FOG_COLOR, pvr2_scene.fog_lut_colour );
1.19 + glEnable( GL_FOG );
1.20 + break;
1.21 + case PVR2_POLY_FOG_VERTEX:
1.22 + if( POLY1_SPECULAR(poly1) ) {
1.23 + glFogfv( GL_FOG_COLOR, pvr2_scene.fog_vert_colour );
1.24 + glEnable( GL_FOG );
1.25 + break;
1.26 + } /* else fallthrough */
1.27 + default:
1.28 + glDisable( GL_FOG );
1.29 + }
1.30 +
1.31
1.32 glShadeModel( POLY1_SHADE_MODEL(poly1) );
1.33
1.34 @@ -296,7 +313,11 @@
1.35 glColorPointer(4, GL_FLOAT, sizeof(struct vertex_struct), &pvr2_scene.vertex_array[0].rgba[0]);
1.36 glTexCoordPointer(2, GL_FLOAT, sizeof(struct vertex_struct), &pvr2_scene.vertex_array[0].u);
1.37 glSecondaryColorPointerEXT(3, GL_FLOAT, sizeof(struct vertex_struct), pvr2_scene.vertex_array[0].offset_rgba );
1.38 -
1.39 + glFogCoordPointerEXT(GL_FLOAT, sizeof(struct vertex_struct), &pvr2_scene.vertex_array[0].offset_rgba[3] );
1.40 + glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
1.41 + glFogi(GL_FOG_MODE, GL_LINEAR);
1.42 + glFogf(GL_FOG_START, 0.0);
1.43 + glFogf(GL_FOG_END, 1.0);
1.44 /* Turn on the shaders (if available) */
1.45 glsl_enable_shaders(TRUE);
1.46
2.1 --- a/src/pvr2/pvr2mmio.h Sat Sep 06 08:16:39 2008 +0000
2.2 +++ b/src/pvr2/pvr2mmio.h Sun Sep 07 04:23:49 2008 +0000
2.3 @@ -89,6 +89,7 @@
2.4 LONG_PORT( 0x164, TA_LISTBASE, PORT_MRW, 0, "TA Tile list start" )
2.5 LONG_PORT( 0x1A8, PVRUNK7, PORT_MRW, 0, "PVR2 unknown register 7" )
2.6 LONG_PORT( 0x1AC, PVRUNK8, PORT_MRW, 0, "PVR2 unknown register 8" )
2.7 + LONG_PORT( 0x200, RENDER_FOGTABLE, PORT_MRW, 0, "Start of fog table" )
2.8 MMIO_REGION_END
2.9
2.10 MMIO_REGION_BEGIN( 0x005F9000, PVR2PAL, "Power VR/2 CLUT Palettes" )
3.1 --- a/src/pvr2/scene.c Sat Sep 06 08:16:39 2008 +0000
3.2 +++ b/src/pvr2/scene.c Sun Sep 07 04:23:49 2008 +0000
3.3 @@ -55,8 +55,15 @@
3.4 return temp.f;
3.5 }
3.6
3.7 -
3.8 -
3.9 +static float parse_fog_density( uint32_t value )
3.10 +{
3.11 + union {
3.12 + uint32_t i;
3.13 + float f;
3.14 + } u;
3.15 + u.i = (((value+127)&0xFF)<<23)|((value & 0xFF00)<<7);
3.16 + return u.f;
3.17 +}
3.18
3.19
3.20 struct pvr2_scene_struct pvr2_scene;
3.21 @@ -245,7 +252,6 @@
3.22 unpack_bgra(*data.ival++, vert->rgba);
3.23 if( POLY1_SPECULAR(poly1) ) {
3.24 unpack_bgra(*data.ival++, vert->offset_rgba);
3.25 - vert->offset_rgba[3] = 1.0;
3.26 } else {
3.27 vert->offset_rgba[0] = 0.0;
3.28 vert->offset_rgba[1] = 0.0;
3.29 @@ -255,7 +261,6 @@
3.30
3.31 if( force_alpha ) {
3.32 vert->rgba[3] = 1.0;
3.33 - vert->offset_rgba[3] = 1.0;
3.34 }
3.35 }
3.36
3.37 @@ -329,6 +334,61 @@
3.38 }
3.39 }
3.40
3.41 +static float scene_compute_lut_fog_vertex( float z, float fog_density, float fog_table[][2] )
3.42 +{
3.43 + union {
3.44 + uint32_t i;
3.45 + float f;
3.46 + } v;
3.47 + v.f = z * fog_density;
3.48 + if( v.f < 1.0 ) v.f = 1.0;
3.49 + else if( v.f > 255.9999 ) v.f = 255.9999;
3.50 +
3.51 + uint32_t index = ((v.i >> 18) & 0x0F)|((v.i>>19)&0x70);
3.52 + return fog_table[index][0];
3.53 +}
3.54 +
3.55 +/**
3.56 + * Compute the fog coefficients for all polygons using lookup-table fog. It's
3.57 + * a little more convenient to do this as a separate pass, since we don't have
3.58 + * to worry about computed vertexes.
3.59 + */
3.60 +static void scene_compute_lut_fog( )
3.61 +{
3.62 + int i,j;
3.63 +
3.64 + float fog_density = parse_fog_density(MMIO_READ( PVR2, RENDER_FOGCOEFF ));
3.65 + float fog_table[128][2];
3.66 +
3.67 + /* Parse fog table out into floating-point format */
3.68 + for( i=0; i<128; i++ ) {
3.69 + uint32_t ent = MMIO_READ( PVR2, RENDER_FOGTABLE + (i<<2) );
3.70 + fog_table[i][0] = ((float)(((ent&0x0000FF00)>>8) + 1)) / 256.0;
3.71 + fog_table[i][1] = ((float)((ent&0x000000FF) + 1)) / 256.0;
3.72 + }
3.73 +
3.74 +
3.75 + for( i=0; i<pvr2_scene.poly_count; i++ ) {
3.76 + int mode = POLY2_FOG_MODE(pvr2_scene.poly_array[i].context[1]);
3.77 + if( mode == PVR2_POLY_FOG_LOOKUP ) {
3.78 + uint32_t index = pvr2_scene.poly_array[i].vertex_index;
3.79 + for( j=0; j<=pvr2_scene.poly_array[i].vertex_count; j++ ) {
3.80 + pvr2_scene.vertex_array[index+j].offset_rgba[3] =
3.81 + scene_compute_lut_fog_vertex( pvr2_scene.vertex_array[index+j].z, fog_density, fog_table );
3.82 + }
3.83 + } else if( mode == PVR2_POLY_FOG_LOOKUP2 ) {
3.84 + uint32_t index = pvr2_scene.poly_array[i].vertex_index;
3.85 + for( j=0; j<=pvr2_scene.poly_array[i].vertex_count; j++ ) {
3.86 + pvr2_scene.vertex_array[index+j].rgba[0] = pvr2_scene.fog_lut_colour[0];
3.87 + pvr2_scene.vertex_array[index+j].rgba[1] = pvr2_scene.fog_lut_colour[1];
3.88 + pvr2_scene.vertex_array[index+j].rgba[2] = pvr2_scene.fog_lut_colour[2];
3.89 + pvr2_scene.vertex_array[index+j].rgba[3] =
3.90 + scene_compute_lut_fog_vertex( pvr2_scene.vertex_array[index+j].z, fog_density, fog_table );
3.91 + }
3.92 + }
3.93 + }
3.94 +}
3.95 +
3.96 static void scene_add_vertexes( pvraddr_t poly_idx, int vertex_length,
3.97 gboolean is_modified )
3.98 {
3.99 @@ -628,6 +688,12 @@
3.100 */
3.101 pvr2_scene.bounds[1] *= 2;
3.102 }
3.103 +
3.104 + uint32_t fog_col = MMIO_READ( PVR2, RENDER_FOGTBLCOL );
3.105 + unpack_bgra( fog_col, pvr2_scene.fog_lut_colour );
3.106 + fog_col = MMIO_READ( PVR2, RENDER_FOGVRTCOL );
3.107 + unpack_bgra( fog_col, pvr2_scene.fog_vert_colour );
3.108 +
3.109 uint32_t *tilebuffer = (uint32_t *)(video_base + MMIO_READ( PVR2, RENDER_TILEBASE ));
3.110 uint32_t *segment = tilebuffer;
3.111 pvr2_scene.segment_list = (struct tile_segment *)tilebuffer;
3.112 @@ -688,6 +754,7 @@
3.113 } while( (control & SEGMENT_END) == 0 );
3.114
3.115 scene_extract_background();
3.116 + scene_compute_lut_fog();
3.117
3.118 vertex_buffer_unmap();
3.119 }
4.1 --- a/src/pvr2/scene.h Sat Sep 06 08:16:39 2008 +0000
4.2 +++ b/src/pvr2/scene.h Sun Sep 07 04:23:49 2008 +0000
4.3 @@ -127,6 +127,9 @@
4.4 /** Specifies the translucency auto-sort mode for the scene */
4.5 tile_sort_mode_t sort_mode;
4.6
4.7 + float fog_lut_colour[4];
4.8 + float fog_vert_colour[4];
4.9 +
4.10 /** Pointer to the start of the tile segment list in PVR2 VRAM (32-bit) */
4.11 struct tile_segment *segment_list;
4.12 /** Map from PVR2 polygon address to an element of poly_array. */
5.1 --- a/src/pvr2/vertex.glsl Sat Sep 06 08:16:39 2008 +0000
5.2 +++ b/src/pvr2/vertex.glsl Sun Sep 07 04:23:49 2008 +0000
5.3 @@ -8,4 +8,5 @@
5.4 gl_FrontColor = gl_Color;
5.5 gl_FrontSecondaryColor = gl_SecondaryColor;
5.6 gl_TexCoord[0] = gl_MultiTexCoord0;
5.7 + gl_FogFragCoord = gl_FogCoord;
5.8 }
.