Search
lxdream.org :: lxdream/src/pvr2/render.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/render.c
changeset 352:f0df7a6d4703
prev338:8c68d9097846
next429:e581b90c3fb3
author nkeynes
date Sun Feb 11 10:09:32 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Bug 27: Implement opengl framebuffer objects
Rewrite much of the final video output stage. Now uses generic "render
buffers", implemented on GL using framebuffer objects + textures.
file annotate diff log raw
1.1 --- a/src/pvr2/render.c Mon Jan 29 11:24:44 2007 +0000
1.2 +++ b/src/pvr2/render.c Sun Feb 11 10:09:32 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: render.c,v 1.23 2007-01-29 11:24:44 nkeynes Exp $
1.6 + * $Id: render.c,v 1.24 2007-02-11 10:09:32 nkeynes Exp $
1.7 *
1.8 * PVR2 Renderer support. This part is primarily
1.9 *
1.10 @@ -20,20 +20,6 @@
1.11 #include "asic.h"
1.12
1.13
1.14 -struct pvr2_render_buffer front_buffer;
1.15 -struct pvr2_render_buffer back_buffer;
1.16 -
1.17 -typedef struct pvr2_bgplane_packed {
1.18 - uint32_t poly_cfg, poly_mode;
1.19 - uint32_t texture_mode;
1.20 - float x1, y1, z1;
1.21 - uint32_t colour1;
1.22 - float x2, y2, z2;
1.23 - uint32_t colour2;
1.24 - float x3, y3, z3;
1.25 - uint32_t colour3;
1.26 -} *pvr2_bgplane_packed_t;
1.27 -
1.28 int pvr2_render_font_list = -1;
1.29 int pvr2_render_trace = 0;
1.30
1.31 @@ -85,111 +71,27 @@
1.32
1.33 }
1.34
1.35 -
1.36 -gboolean pvr2_render_init( void )
1.37 -{
1.38 - front_buffer.render_addr = -1;
1.39 - back_buffer.render_addr = -1;
1.40 -}
1.41 -
1.42 -/**
1.43 - * Invalidate any caching on the supplied address. Specifically, if it falls
1.44 - * within either the front buffer or back buffer, flush the buffer back to
1.45 - * PVR2 ram (note that front buffer flush may be corrupt under some
1.46 - * circumstances).
1.47 - */
1.48 -gboolean pvr2_render_buffer_invalidate( sh4addr_t address )
1.49 -{
1.50 - address = address & 0x1FFFFFFF;
1.51 - if( front_buffer.render_addr != -1 &&
1.52 - front_buffer.render_addr <= address &&
1.53 - (front_buffer.render_addr + front_buffer.size) > address ) {
1.54 - pvr2_render_buffer_copy_to_sh4( &front_buffer, FALSE );
1.55 - front_buffer.render_addr = -1;
1.56 - return TRUE;
1.57 - } else if( back_buffer.render_addr != -1 &&
1.58 - back_buffer.render_addr <= address &&
1.59 - (back_buffer.render_addr + back_buffer.size) > address ) {
1.60 - pvr2_render_buffer_copy_to_sh4( &back_buffer, TRUE );
1.61 - back_buffer.render_addr = -1;
1.62 - return TRUE;
1.63 - }
1.64 - return FALSE;
1.65 -}
1.66 -
1.67 -/**
1.68 - * Display a rendered frame if one is available.
1.69 - * @param address An address in PVR ram (0500000 range).
1.70 - * @return TRUE if a frame was available to be displayed, otherwise false.
1.71 - */
1.72 -gboolean pvr2_render_display_frame( uint32_t address )
1.73 -{
1.74 - if( front_buffer.render_addr == address ) {
1.75 - /* Current front buffer is already displayed, so do nothing
1.76 - * and tell the caller that all is well.
1.77 - */
1.78 - return TRUE;
1.79 - }
1.80 - if( back_buffer.render_addr == address ) {
1.81 - /* The more useful case - back buffer is to be displayed. Swap
1.82 - * the buffers
1.83 - */
1.84 - display_driver->display_back_buffer();
1.85 - front_buffer = back_buffer;
1.86 - back_buffer.render_addr = -1;
1.87 - return TRUE;
1.88 - }
1.89 - return FALSE;
1.90 -}
1.91 -
1.92 /**
1.93 * Prepare the OpenGL context to receive instructions for a new frame.
1.94 */
1.95 -static void pvr2_render_prepare_context( sh4addr_t render_addr,
1.96 - uint32_t width, uint32_t height,
1.97 - uint32_t colour_format,
1.98 - float bgplanez, float nearz,
1.99 - gboolean texture_target )
1.100 +static void pvr2_render_prepare_context( render_buffer_t buffer,
1.101 + float bgplanez, float nearz )
1.102 {
1.103 /* Select and initialize the render context */
1.104 - display_driver->set_render_format( width, height, colour_format, texture_target );
1.105 + display_driver->set_render_target(buffer);
1.106
1.107 if( pvr2_render_font_list == -1 ) {
1.108 pvr2_render_font_list = video_glx_load_font( "-*-helvetica-*-r-normal--16-*-*-*-p-*-iso8859-1");
1.109 }
1.110
1.111 - if( back_buffer.render_addr != -1 &&
1.112 - back_buffer.render_addr != render_addr ) {
1.113 - /* There's a current back buffer, and we're rendering somewhere else -
1.114 - * flush the back buffer back to vram and start a new back buffer
1.115 - */
1.116 - pvr2_render_buffer_copy_to_sh4( &back_buffer, TRUE );
1.117 - }
1.118 -
1.119 - if( front_buffer.render_addr == render_addr ) {
1.120 - /* In case we've been asked to render to the current front buffer -
1.121 - * invalidate the front buffer and render to the back buffer, ensuring
1.122 - * we swap at the next frame display.
1.123 - */
1.124 - front_buffer.render_addr = -1;
1.125 - }
1.126 - back_buffer.render_addr = render_addr;
1.127 - back_buffer.width = width;
1.128 - back_buffer.height = height;
1.129 - back_buffer.colour_format = colour_format;
1.130 - back_buffer.scale = MMIO_READ( PVR2, RENDER_SCALER );
1.131 - back_buffer.size = width * height * colour_format_bytes[colour_format];
1.132 -
1.133 pvr2_check_palette_changed();
1.134
1.135 /* Setup the display model */
1.136 - glDrawBuffer(GL_BACK);
1.137 glShadeModel(GL_SMOOTH);
1.138 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
1.139 - glViewport( 0, 0, width, height );
1.140 glMatrixMode(GL_PROJECTION);
1.141 glLoadIdentity();
1.142 - glOrtho( 0, width, height, 0, -bgplanez, -nearz );
1.143 + glOrtho( 0, buffer->width, buffer->height, 0, -bgplanez, -nearz );
1.144 glMatrixMode(GL_MODELVIEW);
1.145 glLoadIdentity();
1.146 glCullFace( GL_BACK );
1.147 @@ -200,7 +102,6 @@
1.148 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1.149 glClearDepth(0);
1.150 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1.151 -
1.152 }
1.153
1.154 /**
1.155 @@ -208,58 +109,32 @@
1.156 * Note: this will probably need to be broken up eventually once timings are
1.157 * determined.
1.158 */
1.159 -void pvr2_render_scene( )
1.160 +void pvr2_render_scene( render_buffer_t buffer )
1.161 {
1.162 struct tile_descriptor *tile_desc =
1.163 (struct tile_descriptor *)mem_get_region(PVR2_RAM_BASE + MMIO_READ( PVR2, RENDER_TILEBASE ));
1.164
1.165 - uint32_t render_addr = MMIO_READ( PVR2, RENDER_ADDR1 );
1.166 - gboolean render_to_tex;
1.167 - if( render_addr & 0x01000000 ) {
1.168 - render_addr = (render_addr & 0x00FFFFFF) + PVR2_RAM_BASE_INT;
1.169 - /* Heuristic - if we're rendering to the interlaced region we're
1.170 - * probably creating a texture rather than rendering actual output.
1.171 - * We can optimise for this case a little
1.172 - */
1.173 - render_to_tex = TRUE;
1.174 - WARN( "Render to texture not supported properly yet" );
1.175 - } else {
1.176 - render_addr = (render_addr & 0x00FFFFFF) + PVR2_RAM_BASE;
1.177 - render_to_tex = FALSE;
1.178 - }
1.179 -
1.180 float bgplanez = 1/MMIO_READF( PVR2, RENDER_FARCLIP );
1.181 - uint32_t render_mode = MMIO_READ( PVR2, RENDER_MODE );
1.182 - int width, height;
1.183 - pvr2_render_getsize( &width, &height );
1.184 - int colour_format = pvr2_render_colour_format[render_mode&0x07];
1.185 - pvr2_render_prepare_context( render_addr, width, height, colour_format,
1.186 - bgplanez, 0, render_to_tex );
1.187 + pvr2_render_prepare_context( buffer, bgplanez, 0 );
1.188
1.189 int clip_x = MMIO_READ( PVR2, RENDER_HCLIP ) & 0x03FF;
1.190 int clip_y = MMIO_READ( PVR2, RENDER_VCLIP ) & 0x03FF;
1.191 int clip_width = ((MMIO_READ( PVR2, RENDER_HCLIP ) >> 16) & 0x03FF) - clip_x + 1;
1.192 int clip_height= ((MMIO_READ( PVR2, RENDER_VCLIP ) >> 16) & 0x03FF) - clip_y + 1;
1.193
1.194 - /* Fog setup goes here */
1.195 + /* Fog setup goes here? */
1.196
1.197 /* Render the background plane */
1.198 +
1.199 uint32_t bgplane_mode = MMIO_READ(PVR2, RENDER_BGPLANE);
1.200 uint32_t *display_list =
1.201 (uint32_t *)mem_get_region(PVR2_RAM_BASE + MMIO_READ( PVR2, RENDER_POLYBASE ));
1.202
1.203 uint32_t *bgplane = display_list + (((bgplane_mode & 0x00FFFFFF)) >> 3) ;
1.204 - render_backplane( bgplane, width, height, bgplane_mode );
1.205 -
1.206 - pvr2_render_tilebuffer( width, height, clip_x, clip_y,
1.207 + render_backplane( bgplane, buffer->width, buffer->height, bgplane_mode );
1.208 +
1.209 + pvr2_render_tilebuffer( buffer->width, buffer->height, clip_x, clip_y,
1.210 clip_x + clip_width, clip_y + clip_height );
1.211 -
1.212 - /* Post-render cleanup and update */
1.213 -
1.214 - /* Add frame, fps, etc data */
1.215 - //glDrawGrid( width, height );
1.216 - glPrintf( 4, 16, "Frame %d", pvr2_get_frame_count() );
1.217 - /* Generate end of render event */
1.218 - asic_event( EVENT_PVR_RENDER_DONE );
1.219 - DEBUG( "Rendered frame %d to %08X", pvr2_get_frame_count(), render_addr );
1.220 +
1.221 + DEBUG( "Rendered frame %d to %08X", pvr2_get_frame_count(), buffer->address );
1.222 }
.