revision 639:162ee7614b60
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 639:162ee7614b60 |
parent | 636:2ccf94f966fc |
child | 645:a7392098299c |
author | nkeynes |
date | Mon Feb 18 09:21:43 2008 +0000 (16 years ago) |
branch | lxdream-render |
More render WIP - initial glrender.c
1.1 --- a/src/Makefile.am Thu Feb 14 14:06:41 2008 +00001.2 +++ b/src/Makefile.am Mon Feb 18 09:21:43 2008 +00001.3 @@ -35,7 +35,7 @@1.4 pvr2/pvr2.c pvr2/pvr2.h pvr2/pvr2mem.c \1.5 pvr2/tacore.c pvr2/render.c pvr2/rendcore.c pvr2/rendbkg.c pvr2/rendsort.c \1.6 pvr2/texcache.c pvr2/yuv.c pvr2/rendsave.c pvr2/scene.c pvr2/scene.h \1.7 - pvr2/gl_sl.c pvr2/gl_slsrc.c pvr2/glutil.c pvr2/glutil.h \1.8 + pvr2/gl_sl.c pvr2/gl_slsrc.c pvr2/glutil.c pvr2/glutil.h pvr2/glrender.c \1.9 maple/maple.c maple/maple.h \1.10 maple/controller.c maple/controller.h maple/kbd.c maple/mouse.c \1.11 loader.c bootstrap.c util.c \
2.1 --- a/src/Makefile.in Thu Feb 14 14:06:41 2008 +00002.2 +++ b/src/Makefile.in Mon Feb 18 09:21:43 2008 +00002.3 @@ -236,7 +236,7 @@2.4 pvr2/pvr2.c pvr2/pvr2.h pvr2/pvr2mem.c \2.5 pvr2/tacore.c pvr2/render.c pvr2/rendcore.c pvr2/rendbkg.c pvr2/rendsort.c \2.6 pvr2/texcache.c pvr2/yuv.c pvr2/rendsave.c pvr2/scene.c pvr2/scene.h \2.7 - pvr2/gl_sl.c pvr2/gl_slsrc.c pvr2/glutil.c pvr2/glutil.h \2.8 + pvr2/gl_sl.c pvr2/gl_slsrc.c pvr2/glutil.c pvr2/glutil.h pvr2/glrender.c \2.9 maple/maple.c maple/maple.h \2.10 maple/controller.c maple/controller.h maple/kbd.c maple/mouse.c \2.11 loader.c bootstrap.c util.c \2.12 @@ -295,7 +295,7 @@2.13 pvr2/rendcore.c pvr2/rendbkg.c pvr2/rendsort.c pvr2/texcache.c \2.14 pvr2/yuv.c pvr2/rendsave.c pvr2/scene.c pvr2/scene.h \2.15 pvr2/gl_sl.c pvr2/gl_slsrc.c pvr2/glutil.c pvr2/glutil.h \2.16 - maple/maple.c maple/maple.h maple/controller.c \2.17 + pvr2/glrender.c maple/maple.c maple/maple.h maple/controller.c \2.18 maple/controller.h maple/kbd.c maple/mouse.c loader.c \2.19 bootstrap.c util.c display.c display.h dckeysyms.h \2.20 drivers/audio_null.c drivers/video_null.c drivers/video_gl.c \2.21 @@ -353,13 +353,13 @@2.22 rendcore.$(OBJEXT) rendbkg.$(OBJEXT) rendsort.$(OBJEXT) \2.23 texcache.$(OBJEXT) yuv.$(OBJEXT) rendsave.$(OBJEXT) \2.24 scene.$(OBJEXT) gl_sl.$(OBJEXT) gl_slsrc.$(OBJEXT) \2.25 - glutil.$(OBJEXT) maple.$(OBJEXT) controller.$(OBJEXT) \2.26 - kbd.$(OBJEXT) mouse.$(OBJEXT) loader.$(OBJEXT) \2.27 - bootstrap.$(OBJEXT) util.$(OBJEXT) display.$(OBJEXT) \2.28 - audio_null.$(OBJEXT) video_null.$(OBJEXT) video_gl.$(OBJEXT) \2.29 - gl_fbo.$(OBJEXT) $(am__objects_1) $(am__objects_2) \2.30 - $(am__objects_3) $(am__objects_4) $(am__objects_5) \2.31 - $(am__objects_6) $(am__objects_7)2.32 + glutil.$(OBJEXT) glrender.$(OBJEXT) maple.$(OBJEXT) \2.33 + controller.$(OBJEXT) kbd.$(OBJEXT) mouse.$(OBJEXT) \2.34 + loader.$(OBJEXT) bootstrap.$(OBJEXT) util.$(OBJEXT) \2.35 + display.$(OBJEXT) audio_null.$(OBJEXT) video_null.$(OBJEXT) \2.36 + video_gl.$(OBJEXT) gl_fbo.$(OBJEXT) $(am__objects_1) \2.37 + $(am__objects_2) $(am__objects_3) $(am__objects_4) \2.38 + $(am__objects_5) $(am__objects_6) $(am__objects_7)2.39 lxdream_OBJECTS = $(am_lxdream_OBJECTS)2.40 lxdream_DEPENDENCIES =2.41 lxdream_LDFLAGS =2.42 @@ -404,33 +404,33 @@2.43 @AMDEP_TRUE@ ./$(DEPDIR)/gdrom.Po ./$(DEPDIR)/gdrom_menu.Po \2.44 @AMDEP_TRUE@ ./$(DEPDIR)/gendec.Po ./$(DEPDIR)/genglsl.Po \2.45 @AMDEP_TRUE@ ./$(DEPDIR)/gl_fbo.Po ./$(DEPDIR)/gl_sl.Po \2.46 -@AMDEP_TRUE@ ./$(DEPDIR)/gl_slsrc.Po ./$(DEPDIR)/glutil.Po \2.47 -@AMDEP_TRUE@ ./$(DEPDIR)/gtkcb.Po ./$(DEPDIR)/gtkui.Po \2.48 -@AMDEP_TRUE@ ./$(DEPDIR)/i386-dis.Po ./$(DEPDIR)/ide.Po \2.49 -@AMDEP_TRUE@ ./$(DEPDIR)/insparse.Po ./$(DEPDIR)/intc.Po \2.50 -@AMDEP_TRUE@ ./$(DEPDIR)/joy_linux.Po ./$(DEPDIR)/kbd.Po \2.51 -@AMDEP_TRUE@ ./$(DEPDIR)/loader.Po ./$(DEPDIR)/main.Po \2.52 -@AMDEP_TRUE@ ./$(DEPDIR)/main_win.Po ./$(DEPDIR)/maple.Po \2.53 -@AMDEP_TRUE@ ./$(DEPDIR)/mem.Po ./$(DEPDIR)/mmio_win.Po \2.54 -@AMDEP_TRUE@ ./$(DEPDIR)/mmu.Po ./$(DEPDIR)/mouse.Po \2.55 -@AMDEP_TRUE@ ./$(DEPDIR)/nrg.Po ./$(DEPDIR)/path_dlg.Po \2.56 -@AMDEP_TRUE@ ./$(DEPDIR)/pvr2.Po ./$(DEPDIR)/pvr2mem.Po \2.57 -@AMDEP_TRUE@ ./$(DEPDIR)/rendbkg.Po ./$(DEPDIR)/rendcore.Po \2.58 -@AMDEP_TRUE@ ./$(DEPDIR)/render.Po ./$(DEPDIR)/rendsave.Po \2.59 -@AMDEP_TRUE@ ./$(DEPDIR)/rendsort.Po ./$(DEPDIR)/scene.Po \2.60 -@AMDEP_TRUE@ ./$(DEPDIR)/scif.Po ./$(DEPDIR)/sh4.Po \2.61 -@AMDEP_TRUE@ ./$(DEPDIR)/sh4core.Po ./$(DEPDIR)/sh4dasm.Po \2.62 -@AMDEP_TRUE@ ./$(DEPDIR)/sh4mem.Po ./$(DEPDIR)/sh4mmio.Po \2.63 -@AMDEP_TRUE@ ./$(DEPDIR)/sh4stat.Po ./$(DEPDIR)/sh4trans.Po \2.64 -@AMDEP_TRUE@ ./$(DEPDIR)/sh4x86.Po ./$(DEPDIR)/syscall.Po \2.65 -@AMDEP_TRUE@ ./$(DEPDIR)/tacore.Po ./$(DEPDIR)/testsh4x86.Po \2.66 -@AMDEP_TRUE@ ./$(DEPDIR)/testxlt.Po ./$(DEPDIR)/texcache.Po \2.67 -@AMDEP_TRUE@ ./$(DEPDIR)/timer.Po ./$(DEPDIR)/util.Po \2.68 -@AMDEP_TRUE@ ./$(DEPDIR)/video_gdk.Po ./$(DEPDIR)/video_gl.Po \2.69 -@AMDEP_TRUE@ ./$(DEPDIR)/video_glx.Po ./$(DEPDIR)/video_gtk.Po \2.70 -@AMDEP_TRUE@ ./$(DEPDIR)/video_null.Po ./$(DEPDIR)/watch.Po \2.71 -@AMDEP_TRUE@ ./$(DEPDIR)/x86dasm.Po ./$(DEPDIR)/xltcache.Po \2.72 -@AMDEP_TRUE@ ./$(DEPDIR)/yuv.Po2.73 +@AMDEP_TRUE@ ./$(DEPDIR)/gl_slsrc.Po ./$(DEPDIR)/glrender.Po \2.74 +@AMDEP_TRUE@ ./$(DEPDIR)/glutil.Po ./$(DEPDIR)/gtkcb.Po \2.75 +@AMDEP_TRUE@ ./$(DEPDIR)/gtkui.Po ./$(DEPDIR)/i386-dis.Po \2.76 +@AMDEP_TRUE@ ./$(DEPDIR)/ide.Po ./$(DEPDIR)/insparse.Po \2.77 +@AMDEP_TRUE@ ./$(DEPDIR)/intc.Po ./$(DEPDIR)/joy_linux.Po \2.78 +@AMDEP_TRUE@ ./$(DEPDIR)/kbd.Po ./$(DEPDIR)/loader.Po \2.79 +@AMDEP_TRUE@ ./$(DEPDIR)/main.Po ./$(DEPDIR)/main_win.Po \2.80 +@AMDEP_TRUE@ ./$(DEPDIR)/maple.Po ./$(DEPDIR)/mem.Po \2.81 +@AMDEP_TRUE@ ./$(DEPDIR)/mmio_win.Po ./$(DEPDIR)/mmu.Po \2.82 +@AMDEP_TRUE@ ./$(DEPDIR)/mouse.Po ./$(DEPDIR)/nrg.Po \2.83 +@AMDEP_TRUE@ ./$(DEPDIR)/path_dlg.Po ./$(DEPDIR)/pvr2.Po \2.84 +@AMDEP_TRUE@ ./$(DEPDIR)/pvr2mem.Po ./$(DEPDIR)/rendbkg.Po \2.85 +@AMDEP_TRUE@ ./$(DEPDIR)/rendcore.Po ./$(DEPDIR)/render.Po \2.86 +@AMDEP_TRUE@ ./$(DEPDIR)/rendsave.Po ./$(DEPDIR)/rendsort.Po \2.87 +@AMDEP_TRUE@ ./$(DEPDIR)/scene.Po ./$(DEPDIR)/scif.Po \2.88 +@AMDEP_TRUE@ ./$(DEPDIR)/sh4.Po ./$(DEPDIR)/sh4core.Po \2.89 +@AMDEP_TRUE@ ./$(DEPDIR)/sh4dasm.Po ./$(DEPDIR)/sh4mem.Po \2.90 +@AMDEP_TRUE@ ./$(DEPDIR)/sh4mmio.Po ./$(DEPDIR)/sh4stat.Po \2.91 +@AMDEP_TRUE@ ./$(DEPDIR)/sh4trans.Po ./$(DEPDIR)/sh4x86.Po \2.92 +@AMDEP_TRUE@ ./$(DEPDIR)/syscall.Po ./$(DEPDIR)/tacore.Po \2.93 +@AMDEP_TRUE@ ./$(DEPDIR)/testsh4x86.Po ./$(DEPDIR)/testxlt.Po \2.94 +@AMDEP_TRUE@ ./$(DEPDIR)/texcache.Po ./$(DEPDIR)/timer.Po \2.95 +@AMDEP_TRUE@ ./$(DEPDIR)/util.Po ./$(DEPDIR)/video_gdk.Po \2.96 +@AMDEP_TRUE@ ./$(DEPDIR)/video_gl.Po ./$(DEPDIR)/video_glx.Po \2.97 +@AMDEP_TRUE@ ./$(DEPDIR)/video_gtk.Po ./$(DEPDIR)/video_null.Po \2.98 +@AMDEP_TRUE@ ./$(DEPDIR)/watch.Po ./$(DEPDIR)/x86dasm.Po \2.99 +@AMDEP_TRUE@ ./$(DEPDIR)/xltcache.Po ./$(DEPDIR)/yuv.Po2.100 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \2.101 $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)2.102 CCLD = $(CC)2.103 @@ -541,6 +541,7 @@2.104 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gl_fbo.Po@am__quote@2.105 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gl_sl.Po@am__quote@2.106 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gl_slsrc.Po@am__quote@2.107 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/glrender.Po@am__quote@2.108 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/glutil.Po@am__quote@2.109 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gtkcb.Po@am__quote@2.110 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gtkui.Po@am__quote@2.111 @@ -1518,6 +1519,28 @@2.112 @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@2.113 @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o glutil.obj `if test -f 'pvr2/glutil.c'; then $(CYGPATH_W) 'pvr2/glutil.c'; else $(CYGPATH_W) '$(srcdir)/pvr2/glutil.c'; fi`2.115 +glrender.o: pvr2/glrender.c2.116 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT glrender.o -MD -MP -MF "$(DEPDIR)/glrender.Tpo" \2.117 +@am__fastdepCC_TRUE@ -c -o glrender.o `test -f 'pvr2/glrender.c' || echo '$(srcdir)/'`pvr2/glrender.c; \2.118 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/glrender.Tpo" "$(DEPDIR)/glrender.Po"; \2.119 +@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/glrender.Tpo"; exit 1; \2.120 +@am__fastdepCC_TRUE@ fi2.121 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pvr2/glrender.c' object='glrender.o' libtool=no @AMDEPBACKSLASH@2.122 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/glrender.Po' tmpdepfile='$(DEPDIR)/glrender.TPo' @AMDEPBACKSLASH@2.123 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@2.124 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o glrender.o `test -f 'pvr2/glrender.c' || echo '$(srcdir)/'`pvr2/glrender.c2.125 +2.126 +glrender.obj: pvr2/glrender.c2.127 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT glrender.obj -MD -MP -MF "$(DEPDIR)/glrender.Tpo" \2.128 +@am__fastdepCC_TRUE@ -c -o glrender.obj `if test -f 'pvr2/glrender.c'; then $(CYGPATH_W) 'pvr2/glrender.c'; else $(CYGPATH_W) '$(srcdir)/pvr2/glrender.c'; fi`; \2.129 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/glrender.Tpo" "$(DEPDIR)/glrender.Po"; \2.130 +@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/glrender.Tpo"; exit 1; \2.131 +@am__fastdepCC_TRUE@ fi2.132 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pvr2/glrender.c' object='glrender.obj' libtool=no @AMDEPBACKSLASH@2.133 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/glrender.Po' tmpdepfile='$(DEPDIR)/glrender.TPo' @AMDEPBACKSLASH@2.134 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@2.135 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o glrender.obj `if test -f 'pvr2/glrender.c'; then $(CYGPATH_W) 'pvr2/glrender.c'; else $(CYGPATH_W) '$(srcdir)/pvr2/glrender.c'; fi`2.136 +2.137 maple.o: maple/maple.c2.138 @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT maple.o -MD -MP -MF "$(DEPDIR)/maple.Tpo" \2.139 @am__fastdepCC_TRUE@ -c -o maple.o `test -f 'maple/maple.c' || echo '$(srcdir)/'`maple/maple.c; \
3.1 --- a/src/drivers/video_gdk.c Thu Feb 14 14:06:41 2008 +00003.2 +++ b/src/drivers/video_gdk.c Mon Feb 18 09:21:43 2008 +00003.3 @@ -55,7 +55,7 @@3.5 osmesa_context = OSMesaCreateContextExt( OSMESA_RGBA, 32, 0, 0, 0 );3.6 OSMesaMakeCurrent( osmesa_context, NULL, GL_UNSIGNED_BYTE, 640, 480 );3.7 - texcache_gl_init();3.8 + pvr2_setup_gl_context();3.9 }3.11 int video_gdk_find_free()
4.1 --- a/src/drivers/video_glx.c Thu Feb 14 14:06:41 2008 +00004.2 +++ b/src/drivers/video_glx.c Mon Feb 18 09:21:43 2008 +00004.3 @@ -177,7 +177,7 @@4.4 }4.5 }4.7 - texcache_gl_init();4.8 + pvr2_setup_gl_context();4.9 video_x11_display = display;4.10 video_x11_window = window;
5.1 --- a/src/pvr2/gl_slsrc.c Thu Feb 14 14:06:41 2008 +00005.2 +++ b/src/pvr2/gl_slsrc.c Mon Feb 18 09:21:43 2008 +00005.3 @@ -8,7 +8,6 @@5.4 {\n\5.5 gl_Position.xy = ftransform().xy;\n\5.6 gl_Position.z = gl_Vertex.z;\n\5.7 - gl_Position.w = 1;\n\5.8 gl_FrontColor = gl_Color;\n\5.9 gl_FrontSecondaryColor = gl_SecondaryColor;\n\5.10 gl_TexCoord[0] = gl_MultiTexCoord0;\n\
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00006.2 +++ b/src/pvr2/glrender.c Mon Feb 18 09:21:43 2008 +00006.3 @@ -0,0 +1,159 @@6.4 +/**6.5 + * $Id$6.6 + *6.7 + * Standard OpenGL rendering engine.6.8 + *6.9 + * Copyright (c) 2005 Nathan Keynes.6.10 + *6.11 + * This program is free software; you can redistribute it and/or modify6.12 + * it under the terms of the GNU General Public License as published by6.13 + * the Free Software Foundation; either version 2 of the License, or6.14 + * (at your option) any later version.6.15 + *6.16 + * This program is distributed in the hope that it will be useful,6.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of6.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the6.19 + * GNU General Public License for more details.6.20 + */6.21 +6.22 +#include "display.h"6.23 +#include "pvr2/pvr2.h"6.24 +#include "pvr2/scene.h"6.25 +6.26 +/**6.27 + * Clip the tile bounds to the clipping plane.6.28 + * @return TRUE if the tile was not clipped completely.6.29 + */6.30 +static gboolean clip_tile_bounds( uint32_t *tile, float *clip )6.31 +{6.32 + if( tile[0] < clip[0] ) tile[0] = clip[0];6.33 + if( tile[1] > clip[1] ) tile[1] = clip[1];6.34 + if( tile[2] < clip[2] ) tile[2] = clip[2];6.35 + if( tile[3] > clip[3] ) tile[3] = clip[3];6.36 + return tile[0] < tile[1] && tile[2] < tile[3];6.37 +}6.38 +6.39 +/**6.40 + * Once-off call to setup the OpenGL context.6.41 + */6.42 +void pvr2_setup_gl_context()6.43 +{6.44 + texcache_gl_init(); // Allocate texture IDs6.45 + glShadeModel(GL_SMOOTH);6.46 + glCullFace( GL_BACK );6.47 + glEnable( GL_BLEND );6.48 + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);6.49 + glMatrixMode(GL_MODELVIEW);6.50 + glLoadIdentity();6.51 +6.52 + glEnableClientState( GL_COLOR_ARRAY );6.53 + glEnableClientState( GL_VERTEX_ARRAY );6.54 + glEnableClientState( GL_TEXTURE_COORD_ARRAY );6.55 + glEnableClientState( GL_SECONDARY_COLOR_ARRAY );6.56 +6.57 + glClearColor(0.0f, 0.0f, 0.0f, 0.0f);6.58 + glClearDepth(0);6.59 + glClearStencil(0);6.60 +}6.61 +6.62 +static void gl_render_poly( struct polygon_struct *poly )6.63 +{6.64 + render_set_context( poly->context, RENDER_NORMAL );6.65 + glDrawArrays(GL_TRIANGLE_STRIP, poly->vertex_index, poly->vertex_count );6.66 +}6.67 +6.68 +static void gl_render_tilelist( pvraddr_t tile_entry )6.69 +{6.70 + uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);6.71 + int strip_count;6.72 + struct polygon_struct *poly;6.73 +6.74 + while(1) {6.75 + uint32_t entry = *tile_list++;6.76 + switch( entry >> 28 ) {6.77 + case 0x0F:6.78 + return; // End-of-list6.79 + case 0x0E:6.80 + tile_list = (uint32_t *)(video_base + (entry&0x007FFFFF));6.81 + break;6.82 + case 0x08:6.83 + case 0x09:6.84 + case 0x0A:6.85 + case 0x0B:6.86 + strip_count = ((entry >> 25) & 0x0F)+1;6.87 + poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];6.88 + while( strip_count > 0 ) {6.89 + gl_render_poly( poly );6.90 + poly = poly->next;6.91 + strip_count--;6.92 + }6.93 + break;6.94 + default:6.95 + poly = pvr2_scene.buf_to_poly_map[entry&0x000FFFFF];6.96 + gl_render_poly( poly );6.97 + }6.98 + }6.99 +}6.100 +6.101 +6.102 +/**6.103 + * Render the currently defined scene in pvr2_scene6.104 + */6.105 +void pvr2_scene_render( render_buffer_t buffer )6.106 +{6.107 + /* Scene setup */6.108 + display_driver->set_render_target(buffer);6.109 + pvr2_check_palette_changed();6.110 +6.111 + /* Setup view projection matrix */6.112 + glMatrixMode(GL_PROJECTION);6.113 + glLoadIdentity();6.114 + float nearz = pvr2_scene.bounds[4];6.115 + float farz = pvr2_scene.bounds[5];6.116 + if( nearz == farz ) {6.117 + farz*= 2.0;6.118 + }6.119 + glOrtho( 0, pvr2_scene.buffer_width, pvr2_scene.buffer_height, 0,6.120 + -nearz, -farz );6.121 +6.122 + /* Clear the buffer (FIXME: May not want always want to do this) */6.123 + glDisable( GL_SCISSOR_TEST );6.124 + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );6.125 +6.126 + /* Setup vertex array pointers */6.127 + glInterleavedArrays(GL_T2F_C4UB_V3F, sizeof(struct vertex_struct), pvr2_scene.vertex_array);6.128 + glSecondaryColorPointerEXT(4, GL_UNSIGNED_BYTE, sizeof(struct vertex_struct), &pvr2_scene.vertex_array[0].offset_rgba );6.129 +6.130 + uint32_t bgplane_mode = MMIO_READ(PVR2, RENDER_BGPLANE);6.131 + uint32_t *bgplane = pvr2_scene.pvr2_pbuf + (((bgplane_mode & 0x00FFFFFF)) >> 3) ;6.132 + render_backplane( bgplane, pvr2_scene.buffer_width, pvr2_scene.buffer_height, bgplane_mode );6.133 +6.134 + glEnable( GL_SCISSOR_TEST );6.135 +6.136 + /* Process the segment list */6.137 + struct tile_segment *segment = pvr2_scene.segment_list;6.138 + do {6.139 + int tilex = SEGMENT_X(segment->control);6.140 + int tiley = SEGMENT_Y(segment->control);6.141 +6.142 + int tile_bounds[4] = { tilex << 5, (tilex+1)<<5, tiley<<5, (tiley+1)<<5 };6.143 + if( !clip_tile_bounds(tile_bounds, pvr2_scene.bounds) ) {6.144 + continue; // fully clipped, skip tile6.145 + }6.146 +6.147 + /* Clip to the visible part of the tile */6.148 + glScissor( tile_bounds[0], pvr2_scene.buffer_height-tile_bounds[3],6.149 + tile_bounds[1]-tile_bounds[0], tile_bounds[3] - tile_bounds[2] );6.150 + if( IS_TILE_PTR(segment->opaque_ptr) ) {6.151 + gl_render_tilelist(segment->opaque_ptr);6.152 + }6.153 + if( IS_TILE_PTR(segment->trans_ptr) ) {6.154 + gl_render_tilelist(segment->trans_ptr);6.155 + }6.156 + if( IS_TILE_PTR(segment->punchout_ptr) ) {6.157 + gl_render_tilelist(segment->punchout_ptr);6.158 + }6.159 + } while( !IS_LAST_SEGMENT(segment++) );6.160 + glDisable( GL_SCISSOR_TEST );6.161 +6.162 +}
7.1 --- a/src/pvr2/pvr2.c Thu Feb 14 14:06:41 2008 +00007.2 +++ b/src/pvr2/pvr2.c Mon Feb 18 09:21:43 2008 +00007.3 @@ -454,9 +454,10 @@7.4 g_free( pvr2_state.save_next_render_filename );7.5 pvr2_state.save_next_render_filename = NULL;7.6 }7.7 + pvr2_scene_read();7.8 render_buffer_t buffer = pvr2_next_render_buffer();7.9 if( buffer != NULL ) {7.10 - pvr2_render_scene( buffer );7.11 + pvr2_scene_render( buffer );7.12 }7.13 asic_event( EVENT_PVR_RENDER_DONE );7.14 break;7.15 @@ -940,9 +941,9 @@7.16 render_addr = (render_addr & 0x00FFFFFF) + PVR2_RAM_BASE;7.17 }7.19 - int width, height;7.20 + int width = pvr2_scene_buffer_width();7.21 + int height = pvr2_scene_buffer_height();7.22 int colour_format = pvr2_render_colour_format[render_mode&0x07];7.23 - pvr2_render_getsize( &width, &height );7.25 result = pvr2_alloc_render_buffer( render_addr, width, height );7.26 /* Setup the buffer */
8.1 --- a/src/pvr2/render.c Thu Feb 14 14:06:41 2008 +00008.2 +++ b/src/pvr2/render.c Mon Feb 18 09:21:43 2008 +00008.3 @@ -106,7 +106,7 @@8.4 glDisable( GL_SCISSOR_TEST );8.5 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);8.6 glClearDepth(0);8.7 - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );8.8 + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );8.9 glEnableClientState( GL_COLOR_ARRAY );8.10 glEnableClientState( GL_VERTEX_ARRAY );8.11 }
9.1 --- a/src/pvr2/scene.c Thu Feb 14 14:06:41 2008 +00009.2 +++ b/src/pvr2/scene.c Mon Feb 18 09:21:43 2008 +00009.3 @@ -28,6 +28,11 @@9.4 #define VBO_EXT_STRING "GL_ARB_vertex_buffer_object"9.5 #define PBO_EXT_STRING "GL_ARB_pixel_buffer_object"9.7 +static inline uint32_t bgra_to_rgba(uint32_t bgra)9.8 +{9.9 + return (bgra&0xFF00FF00) | ((bgra&0x00FF0000)>>16) | ((bgra&0x000000FF)<<16);9.10 +}9.11 +9.12 struct pvr2_scene_struct pvr2_scene;9.14 static gboolean vbo_init = FALSE;9.15 @@ -53,6 +58,16 @@9.16 }9.17 }9.19 +/**9.20 + * Clear the scene data structures in preparation for fresh data9.21 + */9.22 +void pvr2_scene_reset()9.23 +{9.24 + pvr2_scene.poly_count = 0;9.25 + pvr2_scene.vertex_count = 0;9.26 + memset( pvr2_scene.buf_to_poly_map, 0, BUF_POLY_MAP_SIZE );9.27 +}9.28 +9.29 void pvr2_scene_shutdown()9.30 {9.31 if( vbo_supported ) {9.32 @@ -70,13 +85,19 @@9.34 void *vertex_buffer_map()9.35 {9.36 + glGetError();9.37 uint32_t size = pvr2_scene.vertex_count * sizeof(struct vertex_struct);9.38 if( vbo_supported ) {9.39 glBindBufferARB( GL_ARRAY_BUFFER_ARB, pvr2_scene.vbo_id );9.40 -9.41 + assert( glGetError() == 0 );9.42 if( size > pvr2_scene.vertex_array_size ) {9.43 glBufferDataARB( GL_ARRAY_BUFFER_ARB, size, NULL, GL_DYNAMIC_DRAW_ARB );9.44 - assert( glGetError() == 0 );9.45 + int status = glGetError();9.46 + if( status != 0 ) {9.47 + fprintf( stderr, "Error %08X allocating vertex buffer\n", status );9.48 + abort();9.49 + }9.50 + pvr2_scene.vertex_array_size = size;9.51 }9.52 pvr2_scene.vertex_array = glMapBufferARB( GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB );9.53 assert(pvr2_scene.vertex_array != NULL );9.54 @@ -98,7 +119,7 @@9.55 }9.56 }9.58 -static struct polygon_struct *vertex_buffer_add_polygon( pvraddr_t poly_idx, int vertex_count,9.59 +static struct polygon_struct *scene_add_polygon( pvraddr_t poly_idx, int vertex_count,9.60 gboolean is_modified )9.61 {9.62 int vert_mul = is_modified ? 2 : 1;9.63 @@ -114,6 +135,7 @@9.64 poly->context = (uint32_t *)(video_base + MMIO_READ(PVR2,RENDER_POLYBASE) + (poly_idx<<2));9.65 poly->vertex_count = vertex_count;9.66 poly->vertex_index = -1;9.67 + poly->next = NULL;9.68 pvr2_scene.buf_to_poly_map[poly_idx] = poly;9.69 pvr2_scene.vertex_count += (vertex_count * vert_mul);9.70 return poly;9.71 @@ -125,13 +147,16 @@9.72 * volume)9.73 * @param vert Pointer to output vertex structure9.74 * @param poly1 First word of polygon context (needed to understand vertex)9.75 + * @param poly2 Second word of polygon context9.76 * @param pvr2_data Pointer to raw pvr2 vertex data (in VRAM)9.77 * @param modify_offset Offset in 32-bit words to the tex/color data. 0 for9.78 * the normal vertex, half the vertex length for the modified vertex.9.79 */9.80 static void pvr2_decode_render_vertex( struct vertex_struct *vert, uint32_t poly1,9.81 - uint32_t *pvr2_data, int modify_offset )9.82 + uint32_t poly2, uint32_t *pvr2_data,9.83 + int modify_offset )9.84 {9.85 + gboolean force_alpha = !POLY2_ALPHA_ENABLE(poly2);9.86 union pvr2_data_type {9.87 uint32_t *ival;9.88 float *fval;9.89 @@ -161,10 +186,20 @@9.90 vert->u = *data.fval++;9.91 vert->v = *data.fval++;9.92 }9.93 + if( POLY2_TEX_BLEND(poly2) == 1 ) {9.94 + force_alpha = TRUE;9.95 + }9.96 }9.97 - vert->rgba = *data.ival++;9.98 - if( POLY1_SPECULAR(poly1) ) {9.99 - vert->offset_rgba = *data.ival++;9.100 + if( force_alpha ) {9.101 + vert->rgba = bgra_to_rgba((*data.ival++) | 0xFF000000);9.102 + if( POLY1_SPECULAR(poly1) ) {9.103 + vert->offset_rgba = bgra_to_rgba((*data.ival++) | 0xFF000000);9.104 + }9.105 + } else {9.106 + vert->rgba = bgra_to_rgba(*data.ival++);9.107 + if( POLY1_SPECULAR(poly1) ) {9.108 + vert->offset_rgba = bgra_to_rgba(*data.ival++);9.109 + }9.110 }9.111 }9.113 @@ -172,7 +207,7 @@9.114 * Compute texture, colour, and z values for a result point by interpolating from9.115 * a set of 3 input points. The result point must define its x,y.9.116 */9.117 -static void vertex_buffer_compute_vertex( struct vertex_struct *result,9.118 +static void scene_compute_vertex( struct vertex_struct *result,9.119 struct vertex_struct *input,9.120 gboolean is_solid_shaded )9.121 {9.122 @@ -236,7 +271,7 @@9.124 }9.126 -static void vertex_buffer_add_vertexes( pvraddr_t poly_idx, int vertex_length,9.127 +static void scene_add_vertexes( pvraddr_t poly_idx, int vertex_length,9.128 gboolean is_modified )9.129 {9.130 struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[poly_idx];9.131 @@ -248,9 +283,10 @@9.132 if( poly->vertex_index == -1 ) {9.133 ptr += (is_modified ? 5 : 3 );9.134 poly->vertex_index = pvr2_scene.vertex_index;9.135 +9.136 assert( pvr2_scene.vertex_index + poly->vertex_count <= pvr2_scene.vertex_count );9.137 for( i=0; i<poly->vertex_count; i++ ) {9.138 - pvr2_decode_render_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], ptr, 0 );9.139 + pvr2_decode_render_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[1], ptr, 0 );9.140 ptr += vertex_length;9.141 }9.142 if( is_modified ) {9.143 @@ -258,14 +294,14 @@9.144 ptr = &pvr2_scene.pvr2_pbuf[poly_idx] + 5;9.145 poly->mod_vertex_index = pvr2_scene.vertex_index;9.146 for( i=0; i<poly->vertex_count; i++ ) {9.147 - pvr2_decode_render_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], ptr, mod_offset );9.148 + pvr2_decode_render_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[3], ptr, mod_offset );9.149 ptr += vertex_length;9.150 }9.151 }9.152 }9.153 }9.155 -static void vertex_buffer_add_quad_vertexes( pvraddr_t poly_idx, int vertex_length,9.156 +static void scene_add_quad_vertexes( pvraddr_t poly_idx, int vertex_length,9.157 gboolean is_modified )9.158 {9.159 struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[poly_idx];9.160 @@ -283,11 +319,14 @@9.161 ptr += (is_modified ? 5 : 3 );9.162 poly->vertex_index = pvr2_scene.vertex_index;9.163 for( i=0; i<4; i++ ) {9.164 - pvr2_decode_render_vertex( &quad[i], context[0], ptr, 0 );9.165 + pvr2_decode_render_vertex( &quad[i], context[0], context[1], ptr, 0 );9.166 ptr += vertex_length;9.167 }9.168 - vertex_buffer_compute_vertex( &quad[3], &quad[0], !POLY1_GOURAUD_SHADED(context[0]) );9.169 - memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index], quad, sizeof(quad) );9.170 + scene_compute_vertex( &quad[3], &quad[0], !POLY1_GOURAUD_SHADED(context[0]) );9.171 + // Swap last two vertexes (quad arrangement => tri strip arrangement)9.172 + memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index], quad, sizeof(struct vertex_struct)*2 );9.173 + memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+2], &quad[3], sizeof(struct vertex_struct) );9.174 + memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+3], &quad[2], sizeof(struct vertex_struct) );9.175 pvr2_scene.vertex_index += 4;9.177 if( is_modified ) {9.178 @@ -295,17 +334,19 @@9.179 ptr = &pvr2_scene.pvr2_pbuf[poly_idx] + 5;9.180 poly->mod_vertex_index = pvr2_scene.vertex_index;9.181 for( i=0; i<4; i++ ) {9.182 - pvr2_decode_render_vertex( &quad[4], context[0], ptr, mod_offset );9.183 + pvr2_decode_render_vertex( &quad[4], context[0], context[3], ptr, mod_offset );9.184 ptr += vertex_length;9.185 }9.186 - vertex_buffer_compute_vertex( &quad[3], &quad[0], !POLY1_GOURAUD_SHADED(context[0]) );9.187 - memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index], quad, sizeof(quad) );9.188 + scene_compute_vertex( &quad[3], &quad[0], !POLY1_GOURAUD_SHADED(context[0]) );9.189 + memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index], quad, sizeof(struct vertex_struct)*2 );9.190 + memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+2], &quad[3], sizeof(struct vertex_struct) );9.191 + memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+3], &quad[2], sizeof(struct vertex_struct) );9.192 pvr2_scene.vertex_index += 4;9.193 }9.194 }9.195 }9.197 -static void vertex_buffer_extract_polygons( pvraddr_t tile_entry )9.198 +static void scene_extract_polygons( pvraddr_t tile_entry )9.199 {9.200 uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);9.201 do {9.202 @@ -332,7 +373,7 @@9.203 int i;9.204 struct polygon_struct *last_poly = NULL;9.205 for( i=0; i<strip_count; i++ ) {9.206 - struct polygon_struct *poly = vertex_buffer_add_polygon( polyaddr, 3, is_modified );9.207 + struct polygon_struct *poly = scene_add_polygon( polyaddr, 3, is_modified );9.208 polyaddr += polygon_length;9.209 if( last_poly != NULL && last_poly->next == NULL ) {9.210 last_poly->next = poly;9.211 @@ -346,7 +387,7 @@9.212 int i;9.213 struct polygon_struct *last_poly = NULL;9.214 for( i=0; i<strip_count; i++ ) {9.215 - struct polygon_struct *poly = vertex_buffer_add_polygon( polyaddr, 4, is_modified );9.216 + struct polygon_struct *poly = scene_add_polygon( polyaddr, 4, is_modified );9.217 polyaddr += polygon_length;9.218 if( last_poly != NULL && last_poly->next == NULL ) {9.219 last_poly->next = poly;9.220 @@ -363,14 +404,14 @@9.221 }9.222 }9.223 if( last != -1 ) {9.224 - vertex_buffer_add_polygon( polyaddr, last+3, is_modified );9.225 + scene_add_polygon( polyaddr, last+3, is_modified );9.226 }9.227 }9.228 }9.229 } while( 1 );9.230 }9.232 -static void vertex_buffer_extract_vertexes( pvraddr_t tile_entry )9.233 +static void scene_extract_vertexes( pvraddr_t tile_entry )9.234 {9.235 uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);9.236 do {9.237 @@ -396,7 +437,7 @@9.238 int polygon_length = 3 * vertex_length + context_length;9.239 int i;9.240 for( i=0; i<strip_count; i++ ) {9.241 - vertex_buffer_add_vertexes( polyaddr, vertex_length, is_modified );9.242 + scene_add_vertexes( polyaddr, vertex_length, is_modified );9.243 polyaddr += polygon_length;9.244 }9.245 } else if( (entry & 0xE0000000) == 0xA0000000 ) {9.246 @@ -405,7 +446,7 @@9.247 int polygon_length = 4 * vertex_length + context_length;9.248 int i;9.249 for( i=0; i<strip_count; i++ ) {9.250 - vertex_buffer_add_quad_vertexes( polyaddr, vertex_length, is_modified );9.251 + scene_add_quad_vertexes( polyaddr, vertex_length, is_modified );9.252 polyaddr += polygon_length;9.253 }9.254 } else {9.255 @@ -418,13 +459,23 @@9.256 }9.257 }9.258 if( last != -1 ) {9.259 - vertex_buffer_add_vertexes( polyaddr, vertex_length, is_modified );9.260 + scene_add_vertexes( polyaddr, vertex_length, is_modified );9.261 }9.262 }9.263 }9.264 } while( 1 );9.265 }9.267 +uint32_t pvr2_scene_buffer_width()9.268 +{9.269 + return pvr2_scene.buffer_width;9.270 +}9.271 +9.272 +uint32_t pvr2_scene_buffer_height()9.273 +{9.274 + return pvr2_scene.buffer_height;9.275 +}9.276 +9.277 /**9.278 * Extract the current scene into the rendering structures. We run two passes9.279 * - first pass extracts the polygons into pvr2_scene.poly_array (finding vertex counts),9.280 @@ -439,9 +490,8 @@9.281 void pvr2_scene_read( void )9.282 {9.283 pvr2_scene_init();9.284 + pvr2_scene_reset();9.286 - pvr2_scene.poly_count = 0;9.287 - pvr2_scene.vertex_count = 0;9.288 pvr2_scene.bounds[0] = MMIO_READ( PVR2, RENDER_HCLIP ) & 0x03FF;9.289 pvr2_scene.bounds[1] = ((MMIO_READ( PVR2, RENDER_HCLIP ) >> 16) & 0x03FF) + 1;9.290 pvr2_scene.bounds[2] = MMIO_READ( PVR2, RENDER_VCLIP ) & 0x03FF;9.291 @@ -484,7 +534,7 @@9.292 }9.293 for( i=0; i<5; i++ ) {9.294 if( (*segment & NO_POINTER) == 0 ) {9.295 - vertex_buffer_extract_polygons( *segment );9.296 + scene_extract_polygons( *segment );9.297 }9.298 segment++;9.299 }9.300 @@ -502,7 +552,7 @@9.301 control = *segment++;9.302 for( i=0; i<5; i++ ) {9.303 if( (*segment & NO_POINTER) == 0 ) {9.304 - vertex_buffer_extract_vertexes( *segment );9.305 + scene_extract_vertexes( *segment );9.306 }9.307 segment++;9.308 }9.309 @@ -511,22 +561,3 @@9.310 vertex_buffer_unmap();9.311 }9.312 }9.313 -9.314 -/**9.315 - * Render the data in the scene structure. The GL target should already be setup.9.316 - * Note: thar be GL code here.9.317 - */9.318 -void vertex_buffer_render()9.319 -{9.320 - /* Scene setup */9.321 -9.322 - glEnable( GL_SCISSOR_TEST );9.323 -9.324 - /* Scene render */9.325 - struct tile_segment *segment = pvr2_scene.segment_list;9.326 - do {9.327 -9.328 -9.329 - } while( !IS_LAST_SEGMENT(segment) );9.330 - glDisable( GL_SCISSOR_TEST );9.331 -}
10.1 --- a/src/pvr2/scene.h Thu Feb 14 14:06:41 2008 +000010.2 +++ b/src/pvr2/scene.h Mon Feb 18 09:21:43 2008 +000010.3 @@ -28,9 +28,9 @@10.4 } tile_sort_mode_t;10.6 struct vertex_struct {10.7 - float x,y,z;10.8 float u,v;10.9 uint32_t rgba;10.10 + float x,y,z;10.11 uint32_t offset_rgba;10.12 };10.14 @@ -117,8 +117,7 @@10.16 /** Pointer to the start of the tile segment list in PVR2 VRAM (32-bit) */10.17 struct tile_segment *segment_list;10.18 - /** Map from PVR2 polygon address to an element of poly_array. Temporary,10.19 - * used only during poly buffer parsing */10.20 + /** Map from PVR2 polygon address to an element of poly_array. */10.21 struct polygon_struct **buf_to_poly_map;10.22 /** Pointer to the start of the raw polygon buffer in PVR2 VRAM (32-bit).10.23 * Also only used during parsing */
11.1 --- a/src/pvr2/vertex.glsl Thu Feb 14 14:06:41 2008 +000011.2 +++ b/src/pvr2/vertex.glsl Mon Feb 18 09:21:43 2008 +000011.3 @@ -4,7 +4,6 @@11.4 {11.5 gl_Position.xy = ftransform().xy;11.6 gl_Position.z = gl_Vertex.z;11.7 - gl_Position.w = 1;11.8 gl_FrontColor = gl_Color;11.9 gl_FrontSecondaryColor = gl_SecondaryColor;11.10 gl_TexCoord[0] = gl_MultiTexCoord0;
.