Search
lxdream.org :: lxdream/src/pvr2/scene.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/scene.c
changeset 1159:580436b01b6c
prev1155:f9aefb4613e5
next1240:190df8a791ca
author nkeynes
date Sun Feb 12 16:30:26 2012 +1000 (12 years ago)
permissions -rw-r--r--
last change Add -Werror for mregparm check, so it actually fails if mregparm isn't
accepted
file annotate diff log raw
1.1 --- a/src/pvr2/scene.c Tue Jan 18 17:48:48 2011 +1000
1.2 +++ b/src/pvr2/scene.c Sun Feb 12 16:30:26 2012 +1000
1.3 @@ -2,7 +2,6 @@
1.4 * $Id$
1.5 *
1.6 * Manage the internal vertex/polygon buffers and scene data structure.
1.7 - * Where possible this uses VBOs for the vertex + index data.
1.8 *
1.9 * Copyright (c) 2005 Nathan Keynes.
1.10 *
1.11 @@ -69,33 +68,33 @@
1.12 }
1.13
1.14 struct pvr2_scene_struct pvr2_scene;
1.15 +static float scene_shadow_intensity = 0.0;
1.16 +static vertex_buffer_t vbuf = NULL;
1.17
1.18 -static gboolean vbo_init = FALSE;
1.19 -static float scene_shadow_intensity = 0.0;
1.20 +static void vertex_buffer_map()
1.21 +{
1.22 + // Allow 8 vertexes for the background (4+4)
1.23 + uint32_t size = (pvr2_scene.vertex_count + 8) * sizeof(struct vertex_struct);
1.24 + pvr2_scene.vertex_array = vbuf->map(vbuf, size);
1.25 +}
1.26
1.27 -#ifdef ENABLE_VERTEX_BUFFER
1.28 -static gboolean vbo_supported = FALSE;
1.29 -#endif
1.30 +static void vertex_buffer_unmap()
1.31 +{
1.32 + pvr2_scene.vertex_array = vbuf->unmap(vbuf);
1.33 +}
1.34
1.35 /**
1.36 - * Test for VBO support, and allocate all the system memory needed for the
1.37 - * temporary structures. GL context must have been initialized before this
1.38 + * Allocate vertex buffer + temporary structures. GL context must have been initialized before this
1.39 * point.
1.40 */
1.41 void pvr2_scene_init()
1.42 {
1.43 - if( !vbo_init ) {
1.44 -#ifdef ENABLE_VERTEX_BUFFER
1.45 - if( isGLVertexBufferSupported() ) {
1.46 - vbo_supported = TRUE;
1.47 - pvr2_scene.vbo_id = 1;
1.48 - }
1.49 -#endif
1.50 + if( vbuf == NULL ) {
1.51 + vbuf = display_driver->create_vertex_buffer();
1.52 pvr2_scene.vertex_array = NULL;
1.53 pvr2_scene.vertex_array_size = 0;
1.54 pvr2_scene.poly_array = g_malloc( MAX_POLY_BUFFER_SIZE );
1.55 pvr2_scene.buf_to_poly_map = g_malloc0( BUF_POLY_MAP_SIZE );
1.56 - vbo_init = TRUE;
1.57 }
1.58 }
1.59
1.60 @@ -110,72 +109,16 @@
1.61 }
1.62 pvr2_scene.poly_count = 0;
1.63 pvr2_scene.vertex_count = 0;
1.64 -}
1.65 + }
1.66
1.67 void pvr2_scene_shutdown()
1.68 {
1.69 -#ifdef ENABLE_VERTEX_BUFFER
1.70 - if( vbo_supported ) {
1.71 - glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
1.72 - glDeleteBuffersARB( 1, &pvr2_scene.vbo_id );
1.73 - pvr2_scene.vbo_id = 0;
1.74 - } else {
1.75 -#endif
1.76 - g_free( pvr2_scene.vertex_array );
1.77 - pvr2_scene.vertex_array = NULL;
1.78 -#ifdef ENABLE_VERTEX_BUFFER
1.79 - }
1.80 -#endif
1.81 -
1.82 + vbuf->destroy(vbuf);
1.83 + vbuf = NULL;
1.84 g_free( pvr2_scene.poly_array );
1.85 pvr2_scene.poly_array = NULL;
1.86 g_free( pvr2_scene.buf_to_poly_map );
1.87 pvr2_scene.buf_to_poly_map = NULL;
1.88 - vbo_init = FALSE;
1.89 -}
1.90 -
1.91 -void *vertex_buffer_map()
1.92 -{
1.93 - // Allow 8 vertexes for the background (4+4)
1.94 - uint32_t size = (pvr2_scene.vertex_count + 8) * sizeof(struct vertex_struct);
1.95 -#ifdef ENABLE_VERTEX_BUFFER
1.96 - if( vbo_supported ) {
1.97 - glGetError();
1.98 - glBindBufferARB( GL_ARRAY_BUFFER_ARB, pvr2_scene.vbo_id );
1.99 - if( size > pvr2_scene.vertex_array_size ) {
1.100 - glBufferDataARB( GL_ARRAY_BUFFER_ARB, size, NULL, GL_DYNAMIC_DRAW_ARB );
1.101 - int status = glGetError();
1.102 - if( status != 0 ) {
1.103 - fprintf( stderr, "Error %08X allocating vertex buffer\n", status );
1.104 - abort();
1.105 - }
1.106 - pvr2_scene.vertex_array_size = size;
1.107 - }
1.108 - pvr2_scene.vertex_array = glMapBufferARB( GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB );
1.109 - assert(pvr2_scene.vertex_array != NULL );
1.110 - } else {
1.111 -#endif
1.112 - if( size > pvr2_scene.vertex_array_size ) {
1.113 - pvr2_scene.vertex_array = g_realloc( pvr2_scene.vertex_array, size );
1.114 - }
1.115 -#ifdef ENABLE_VERTEX_BUFFER
1.116 - }
1.117 -#endif
1.118 - return pvr2_scene.vertex_array;
1.119 -}
1.120 -
1.121 -gboolean vertex_buffer_unmap()
1.122 -{
1.123 -#ifdef ENABLE_VERTEX_BUFFER
1.124 - if( vbo_supported ) {
1.125 - pvr2_scene.vertex_array = NULL;
1.126 - return glUnmapBufferARB( GL_ARRAY_BUFFER_ARB );
1.127 - } else {
1.128 - return TRUE;
1.129 - }
1.130 -#else
1.131 - return TRUE;
1.132 -#endif
1.133 }
1.134
1.135 static struct polygon_struct *scene_add_polygon( pvraddr_t poly_idx, int vertex_count,
1.136 @@ -252,7 +195,7 @@
1.137 * @param modify_offset Offset in 32-bit words to the tex/color data. 0 for
1.138 * the normal vertex, half the vertex length for the modified vertex.
1.139 */
1.140 -static void pvr2_decode_render_vertex( struct vertex_struct *vert, uint32_t poly1,
1.141 +static void scene_decode_vertex( struct vertex_struct *vert, uint32_t poly1,
1.142 uint32_t poly2, uint32_t tex, uint32_t *pvr2_data,
1.143 int modify_offset )
1.144 {
1.145 @@ -560,7 +503,7 @@
1.146 assert( poly != NULL );
1.147 assert( pvr2_scene.vertex_index + poly->vertex_count <= pvr2_scene.vertex_count );
1.148 for( i=0; i<poly->vertex_count; i++ ) {
1.149 - pvr2_decode_render_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[1], context[2], ptr, 0 );
1.150 + scene_decode_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[1], context[2], ptr, 0 );
1.151 ptr += vertex_length;
1.152 }
1.153 if( is_modified ) {
1.154 @@ -570,7 +513,7 @@
1.155 int mod_offset = (vertex_length - 3)>>1;
1.156 ptr = &pvr2_scene.pvr2_pbuf[poly_idx] + 5;
1.157 for( i=0; i<poly->vertex_count; i++ ) {
1.158 - pvr2_decode_render_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[3], context[4], ptr, mod_offset );
1.159 + scene_decode_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[3], context[4], ptr, mod_offset );
1.160 ptr += vertex_length;
1.161 }
1.162 } else {
1.163 @@ -601,7 +544,7 @@
1.164 ptr += (is_modified == SHADOW_FULL ? 5 : 3 );
1.165 poly->vertex_index = pvr2_scene.vertex_index;
1.166 for( i=0; i<4; i++ ) {
1.167 - pvr2_decode_render_vertex( &quad[i], context[0], context[1], context[2], ptr, 0 );
1.168 + scene_decode_vertex( &quad[i], context[0], context[1], context[2], ptr, 0 );
1.169 ptr += vertex_length;
1.170 }
1.171 scene_compute_vertexes( &quad[3], 1, &quad[0], !POLY1_GOURAUD_SHADED(context[0]) );
1.172 @@ -618,7 +561,7 @@
1.173 int mod_offset = (vertex_length - 3)>>1;
1.174 ptr = &pvr2_scene.pvr2_pbuf[poly_idx] + 5;
1.175 for( i=0; i<4; i++ ) {
1.176 - pvr2_decode_render_vertex( &quad[4], context[0], context[3], context[4], ptr, mod_offset );
1.177 + scene_decode_vertex( &quad[4], context[0], context[3], context[4], ptr, mod_offset );
1.178 ptr += vertex_length;
1.179 }
1.180 scene_compute_vertexes( &quad[3], 1, &quad[0], !POLY1_GOURAUD_SHADED(context[0]) );
1.181 @@ -788,7 +731,7 @@
1.182 struct vertex_struct base_vertexes[3];
1.183 uint32_t *ptr = context + context_length;
1.184 for( i=0; i<3; i++ ) {
1.185 - pvr2_decode_render_vertex( &base_vertexes[i], context[0], context[1], context[2],
1.186 + scene_decode_vertex( &base_vertexes[i], context[0], context[1], context[2],
1.187 ptr, 0 );
1.188 ptr += vertex_length;
1.189 }
1.190 @@ -803,7 +746,7 @@
1.191 int mod_offset = (vertex_length - 3)>>1;
1.192 ptr = context + context_length;
1.193 for( i=0; i<3; i++ ) {
1.194 - pvr2_decode_render_vertex( &base_vertexes[i], context[0], context[3], context[4],
1.195 + scene_decode_vertex( &base_vertexes[i], context[0], context[3], context[4],
1.196 ptr, mod_offset );
1.197 ptr += vertex_length;
1.198 }
1.199 @@ -937,6 +880,11 @@
1.200 vertex_buffer_unmap();
1.201 }
1.202
1.203 +void pvr2_scene_finished( )
1.204 +{
1.205 + vbuf->finished(vbuf);
1.206 +}
1.207 +
1.208 /**
1.209 * Dump the current scene to file in a (mostly) human readable form
1.210 */
.