Search
lxdream.org :: lxdream/src/pvr2/render.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/render.c
changeset 315:2d8ba198d62c
prev308:10a5b5475fb0
next322:354407942957
author nkeynes
date Tue Jan 23 11:19:32 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Refactor render buffer read/write to pvr2mem.c
Implement 4-bit indexed textures (tentatively)
Fix RGB24 support
file annotate diff log raw
1.1 --- a/src/pvr2/render.c Sun Jan 21 11:28:43 2007 +0000
1.2 +++ b/src/pvr2/render.c Tue Jan 23 11:19:32 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: render.c,v 1.17 2007-01-21 11:28:43 nkeynes Exp $
1.6 + * $Id: render.c,v 1.18 2007-01-23 11:19:32 nkeynes Exp $
1.7 *
1.8 * PVR2 Renderer support. This part is primarily
1.9 *
1.10 @@ -19,16 +19,6 @@
1.11 #include "pvr2/pvr2.h"
1.12 #include "asic.h"
1.13
1.14 -/**
1.15 - * Describes a rendering buffer that's actually held in GL, for when we need
1.16 - * to fetch the bits back to vram.
1.17 - */
1.18 -typedef struct pvr2_render_buffer {
1.19 - sh4addr_t render_addr; /* The actual address rendered to in pvr ram */
1.20 - uint32_t size; /* Length of rendering region in bytes */
1.21 - int width, height;
1.22 - int colour_format;
1.23 -} *pvr2_render_buffer_t;
1.24
1.25 struct pvr2_render_buffer front_buffer;
1.26 struct pvr2_render_buffer back_buffer;
1.27 @@ -44,11 +34,6 @@
1.28 uint32_t colour3;
1.29 } *pvr2_bgplane_packed_t;
1.30
1.31 -
1.32 -
1.33 -void pvr2_render_copy_to_sh4( pvr2_render_buffer_t buffer,
1.34 - gboolean backBuffer );
1.35 -
1.36 int pvr2_render_font_list = -1;
1.37 int pvr2_render_trace = 0;
1.38
1.39 @@ -113,19 +98,19 @@
1.40 * PVR2 ram (note that front buffer flush may be corrupt under some
1.41 * circumstances).
1.42 */
1.43 -gboolean pvr2_render_invalidate( sh4addr_t address )
1.44 +gboolean pvr2_render_buffer_invalidate( sh4addr_t address )
1.45 {
1.46 address = address & 0x1FFFFFFF;
1.47 if( front_buffer.render_addr != -1 &&
1.48 front_buffer.render_addr <= address &&
1.49 (front_buffer.render_addr + front_buffer.size) > address ) {
1.50 - pvr2_render_copy_to_sh4( &front_buffer, FALSE );
1.51 + pvr2_render_buffer_copy_to_sh4( &front_buffer, FALSE );
1.52 front_buffer.render_addr = -1;
1.53 return TRUE;
1.54 } else if( back_buffer.render_addr != -1 &&
1.55 back_buffer.render_addr <= address &&
1.56 (back_buffer.render_addr + back_buffer.size) > address ) {
1.57 - pvr2_render_copy_to_sh4( &back_buffer, TRUE );
1.58 + pvr2_render_buffer_copy_to_sh4( &back_buffer, TRUE );
1.59 back_buffer.render_addr = -1;
1.60 return TRUE;
1.61 }
1.62 @@ -178,7 +163,7 @@
1.63 /* There's a current back buffer, and we're rendering somewhere else -
1.64 * flush the back buffer back to vram and start a new back buffer
1.65 */
1.66 - pvr2_render_copy_to_sh4( &back_buffer, TRUE );
1.67 + pvr2_render_buffer_copy_to_sh4( &back_buffer, TRUE );
1.68 }
1.69
1.70 if( front_buffer.render_addr == render_addr ) {
1.71 @@ -275,130 +260,3 @@
1.72 asic_event( EVENT_PVR_RENDER_DONE );
1.73 DEBUG( "Rendered frame %d", pvr2_get_frame_count() );
1.74 }
1.75 -
1.76 -
1.77 -/**
1.78 - * Flush the indicated render buffer back to PVR. Caller is responsible for
1.79 - * tracking whether there is actually anything in the buffer.
1.80 - *
1.81 - * @param buffer A render buffer indicating the address to store to, and the
1.82 - * format the data needs to be in.
1.83 - * @param backBuffer TRUE to flush the back buffer, FALSE for
1.84 - * the front buffer.
1.85 - */
1.86 -void pvr2_render_copy_to_sh4( pvr2_render_buffer_t buffer,
1.87 - gboolean backBuffer )
1.88 -{
1.89 - if( buffer->render_addr == -1 )
1.90 - return;
1.91 - GLenum type, format = GL_RGBA;
1.92 - int line_size = buffer->width, size;
1.93 -
1.94 - switch( buffer->colour_format ) {
1.95 - case COLFMT_RGB565:
1.96 - type = GL_UNSIGNED_SHORT_5_6_5;
1.97 - format = GL_RGB;
1.98 - line_size <<= 1;
1.99 - break;
1.100 - case COLFMT_RGB888:
1.101 - type = GL_UNSIGNED_INT;
1.102 - format = GL_RGB;
1.103 - line_size = (line_size<<1)+line_size;
1.104 - break;
1.105 - case COLFMT_ARGB1555:
1.106 - type = GL_UNSIGNED_SHORT_5_5_5_1;
1.107 - line_size <<= 1;
1.108 - break;
1.109 - case COLFMT_ARGB4444:
1.110 - type = GL_UNSIGNED_SHORT_4_4_4_4;
1.111 - line_size <<= 1;
1.112 - break;
1.113 - case COLFMT_ARGB8888:
1.114 - type = GL_UNSIGNED_INT_8_8_8_8;
1.115 - line_size <<= 2;
1.116 - break;
1.117 - }
1.118 - size = line_size * buffer->height;
1.119 -
1.120 - if( backBuffer ) {
1.121 - glFinish();
1.122 - glReadBuffer( GL_BACK );
1.123 - } else {
1.124 - glReadBuffer( GL_FRONT );
1.125 - }
1.126 -
1.127 - if( buffer->render_addr & 0xFF000000 == 0x04000000 ) {
1.128 - /* Interlaced buffer. Go the double copy... :( */
1.129 - char target[size];
1.130 - glReadPixels( 0, 0, buffer->width, buffer->height, format, type, target );
1.131 - pvr2_vram64_write( buffer->render_addr, target, size );
1.132 - } else {
1.133 - /* Regular buffer */
1.134 - char target[size];
1.135 - glReadPixels( 0, 0, buffer->width, buffer->height, format, type, target );
1.136 - pvr2_vram_write_invert( buffer->render_addr, target, size, line_size );
1.137 - }
1.138 -}
1.139 -
1.140 -
1.141 -/**
1.142 - * Copy data from PVR ram into the GL render buffer.
1.143 - *
1.144 - * @param buffer A render buffer indicating the address to read from, and the
1.145 - * format the data is in.
1.146 - * @param backBuffer TRUE to write the back buffer, FALSE for
1.147 - * the front buffer.
1.148 - */
1.149 -void pvr2_render_copy_from_sh4( pvr2_render_buffer_t buffer,
1.150 - gboolean backBuffer )
1.151 -{
1.152 - if( buffer->render_addr == -1 )
1.153 - return;
1.154 - GLenum type, format = GL_RGBA;
1.155 - int size = buffer->width * buffer->height;
1.156 -
1.157 - switch( buffer->colour_format ) {
1.158 - case COLFMT_RGB565:
1.159 - type = GL_UNSIGNED_SHORT_5_6_5;
1.160 - format = GL_RGB;
1.161 - size <<= 1;
1.162 - break;
1.163 - case COLFMT_RGB888:
1.164 - type = GL_UNSIGNED_INT;
1.165 - format = GL_RGB;
1.166 - size = (size<<1)+size;
1.167 - break;
1.168 - case COLFMT_ARGB1555:
1.169 - type = GL_UNSIGNED_SHORT_5_5_5_1;
1.170 - size <<= 1;
1.171 - break;
1.172 - case COLFMT_ARGB4444:
1.173 - type = GL_UNSIGNED_SHORT_4_4_4_4;
1.174 - size <<= 1;
1.175 - break;
1.176 - case COLFMT_ARGB8888:
1.177 - type = GL_UNSIGNED_INT_8_8_8_8;
1.178 - size <<= 2;
1.179 - break;
1.180 - }
1.181 -
1.182 - if( backBuffer ) {
1.183 - glDrawBuffer( GL_BACK );
1.184 - } else {
1.185 - glDrawBuffer( GL_FRONT );
1.186 - }
1.187 -
1.188 - glRasterPos2i( 0, 0 );
1.189 - if( buffer->render_addr & 0xFF000000 == 0x04000000 ) {
1.190 - /* Interlaced buffer. Go the double copy... :( */
1.191 - char target[size];
1.192 - pvr2_vram64_read( target, buffer->render_addr, size );
1.193 - glDrawPixels( buffer->width, buffer->height,
1.194 - format, type, target );
1.195 - } else {
1.196 - /* Regular buffer - go direct */
1.197 - char *target = mem_get_region( buffer->render_addr );
1.198 - glDrawPixels( buffer->width, buffer->height,
1.199 - format, type, target );
1.200 - }
1.201 -}
.