Search
lxdream.org :: lxdream :: r687:6bdc2b7032ea
lxdream 0.9.1
released Jun 29
Download Now
changeset687:6bdc2b7032ea
parent686:afd1bd3f1acc
child688:8a13dabbdced
authornkeynes
dateSat Jun 14 11:54:15 2008 +0000 (11 years ago)
Change colour params to float
Convert background processing over to scene structure (fixes some depth issues as well)
Add color unclamp when supported
config.h.in
configure.in
src/Makefile.am
src/Makefile.in
src/pvr2/glrender.c
src/pvr2/glutil.c
src/pvr2/glutil.h
src/pvr2/scene.c
src/pvr2/scene.h
1.1 --- a/config.h.in Sat Jun 14 10:19:35 2008 +0000
1.2 +++ b/config.h.in Sat Jun 14 11:54:15 2008 +0000
1.3 @@ -82,6 +82,9 @@
1.4 /* Have NSOpenGL support */
1.5 #undef HAVE_NSGL
1.6
1.7 +/* Have Color Clamp */
1.8 +#undef HAVE_OPENGL_CLAMP_COLOR
1.9 +
1.10 /* Have EXT_framebuffer_object support */
1.11 #undef HAVE_OPENGL_FBO
1.12
2.1 --- a/configure.in Sat Jun 14 10:19:35 2008 +0000
2.2 +++ b/configure.in Sat Jun 14 11:54:15 2008 +0000
2.3 @@ -139,6 +139,7 @@
2.4 AC_CHECK_FUNC(glGenFramebuffersEXT, [ AC_DEFINE([HAVE_OPENGL_FBO],1,[Have EXT_framebuffer_object support]) ], [])
2.5 AC_CHECK_FUNC(glCreateShader, [ AC_DEFINE([HAVE_OPENGL_SHADER],1,[Have 2.0 shader support]) ], [])
2.6 AC_CHECK_FUNC(glCreateShaderObjectARB, [ AC_DEFINE([HAVE_OPENGL_SHADER_ARB],1,[Have ARB shader support]) ], [])
2.7 +AC_CHECK_FUNC(glClampColorARB, [ AC_DEFINE([HAVE_OPENGL_CLAMP_COLOR],1,[Have Color Clamp]) ], [])
2.8
2.9
2.10 dnl Check for a supported cpu target for translation purposes
3.1 --- a/src/Makefile.am Sat Jun 14 10:19:35 2008 +0000
3.2 +++ b/src/Makefile.am Sat Jun 14 11:54:15 2008 +0000
3.3 @@ -35,7 +35,7 @@
3.4 aica/armcore.c aica/armcore.h aica/armdasm.c aica/armmem.c \
3.5 aica/aica.c aica/aica.h aica/audio.c aica/audio.h \
3.6 pvr2/pvr2.c pvr2/pvr2.h pvr2/pvr2mem.c \
3.7 - pvr2/tacore.c pvr2/rendbkg.c pvr2/rendsort.c \
3.8 + pvr2/tacore.c pvr2/rendsort.c \
3.9 pvr2/texcache.c pvr2/yuv.c pvr2/rendsave.c pvr2/scene.c pvr2/scene.h \
3.10 pvr2/gl_sl.c pvr2/gl_slsrc.c pvr2/glutil.c pvr2/glutil.h pvr2/glrender.c \
3.11 maple/maple.c maple/maple.h \
4.1 --- a/src/Makefile.in Sat Jun 14 10:19:35 2008 +0000
4.2 +++ b/src/Makefile.in Sat Jun 14 11:54:15 2008 +0000
4.3 @@ -98,25 +98,25 @@
4.4 sh4/sh4stat.h sh4/xltcache.c sh4/xltcache.h sh4/sh4.h \
4.5 aica/armcore.c aica/armcore.h aica/armdasm.c aica/armmem.c \
4.6 aica/aica.c aica/aica.h aica/audio.c aica/audio.h pvr2/pvr2.c \
4.7 - pvr2/pvr2.h pvr2/pvr2mem.c pvr2/tacore.c pvr2/rendbkg.c \
4.8 - pvr2/rendsort.c pvr2/texcache.c pvr2/yuv.c pvr2/rendsave.c \
4.9 - pvr2/scene.c pvr2/scene.h pvr2/gl_sl.c pvr2/gl_slsrc.c \
4.10 - pvr2/glutil.c pvr2/glutil.h pvr2/glrender.c maple/maple.c \
4.11 - maple/maple.h maple/controller.c maple/controller.h \
4.12 - maple/kbd.c maple/mouse.c loader.c bootstrap.c util.c \
4.13 - display.c display.h dckeysyms.h drivers/audio_null.c \
4.14 - drivers/video_null.c drivers/video_gl.c drivers/video_gl.h \
4.15 - drivers/gl_fbo.c sh4/sh4x86.c sh4/x86op.h sh4/ia32abi.h \
4.16 - sh4/ia32mac.h sh4/ia64abi.h sh4/sh4trans.c sh4/sh4trans.h \
4.17 - x86dasm/x86dasm.c x86dasm/x86dasm.h x86dasm/i386-dis.c \
4.18 - x86dasm/dis-init.c x86dasm/dis-buf.c gtkui/gtkui.c \
4.19 - gtkui/gtkui.h gtkui/main_win.c gtkui/gtkcb.c gtkui/mmio_win.c \
4.20 - gtkui/debug_win.c gtkui/dump_win.c gtkui/ctrl_dlg.c \
4.21 - gtkui/path_dlg.c gtkui/gdrom_menu.c drivers/video_gtk.c \
4.22 - drivers/video_gtk.h cocoaui/cocoaui.c cocoaui/cocoaui.h \
4.23 - cocoaui/cocoa_win.c drivers/video_osx.c drivers/mac_keymap.h \
4.24 - drivers/video_gdk.c drivers/video_gdk.h drivers/video_glx.c \
4.25 - drivers/video_glx.h drivers/video_nsgl.c drivers/video_nsgl.h \
4.26 + pvr2/pvr2.h pvr2/pvr2mem.c pvr2/tacore.c pvr2/rendsort.c \
4.27 + pvr2/texcache.c pvr2/yuv.c pvr2/rendsave.c pvr2/scene.c \
4.28 + pvr2/scene.h pvr2/gl_sl.c pvr2/gl_slsrc.c pvr2/glutil.c \
4.29 + pvr2/glutil.h pvr2/glrender.c maple/maple.c maple/maple.h \
4.30 + maple/controller.c maple/controller.h maple/kbd.c \
4.31 + maple/mouse.c loader.c bootstrap.c util.c display.c display.h \
4.32 + dckeysyms.h drivers/audio_null.c drivers/video_null.c \
4.33 + drivers/video_gl.c drivers/video_gl.h drivers/gl_fbo.c \
4.34 + sh4/sh4x86.c sh4/x86op.h sh4/ia32abi.h sh4/ia32mac.h \
4.35 + sh4/ia64abi.h sh4/sh4trans.c sh4/sh4trans.h x86dasm/x86dasm.c \
4.36 + x86dasm/x86dasm.h x86dasm/i386-dis.c x86dasm/dis-init.c \
4.37 + x86dasm/dis-buf.c gtkui/gtkui.c gtkui/gtkui.h gtkui/main_win.c \
4.38 + gtkui/gtkcb.c gtkui/mmio_win.c gtkui/debug_win.c \
4.39 + gtkui/dump_win.c gtkui/ctrl_dlg.c gtkui/path_dlg.c \
4.40 + gtkui/gdrom_menu.c drivers/video_gtk.c drivers/video_gtk.h \
4.41 + cocoaui/cocoaui.c cocoaui/cocoaui.h cocoaui/cocoa_win.c \
4.42 + drivers/video_osx.c drivers/mac_keymap.h drivers/video_gdk.c \
4.43 + drivers/video_gdk.h drivers/video_glx.c drivers/video_glx.h \
4.44 + drivers/video_nsgl.c drivers/video_nsgl.h \
4.45 drivers/audio_pulse.c drivers/audio_esd.c drivers/audio_alsa.c \
4.46 drivers/cd_linux.c drivers/cd_none.c drivers/joy_linux.c
4.47 @BUILD_SH4X86_TRUE@am__objects_1 = sh4x86.$(OBJEXT) sh4trans.$(OBJEXT) \
4.48 @@ -149,18 +149,18 @@
4.49 sh4stat.$(OBJEXT) xltcache.$(OBJEXT) armcore.$(OBJEXT) \
4.50 armdasm.$(OBJEXT) armmem.$(OBJEXT) aica.$(OBJEXT) \
4.51 audio.$(OBJEXT) pvr2.$(OBJEXT) pvr2mem.$(OBJEXT) \
4.52 - tacore.$(OBJEXT) rendbkg.$(OBJEXT) rendsort.$(OBJEXT) \
4.53 - texcache.$(OBJEXT) yuv.$(OBJEXT) rendsave.$(OBJEXT) \
4.54 - scene.$(OBJEXT) gl_sl.$(OBJEXT) gl_slsrc.$(OBJEXT) \
4.55 - glutil.$(OBJEXT) glrender.$(OBJEXT) maple.$(OBJEXT) \
4.56 - controller.$(OBJEXT) kbd.$(OBJEXT) mouse.$(OBJEXT) \
4.57 - loader.$(OBJEXT) bootstrap.$(OBJEXT) util.$(OBJEXT) \
4.58 - display.$(OBJEXT) audio_null.$(OBJEXT) video_null.$(OBJEXT) \
4.59 - video_gl.$(OBJEXT) gl_fbo.$(OBJEXT) $(am__objects_1) \
4.60 - $(am__objects_2) $(am__objects_3) $(am__objects_4) \
4.61 - $(am__objects_5) $(am__objects_6) $(am__objects_7) \
4.62 - $(am__objects_8) $(am__objects_9) $(am__objects_10) \
4.63 - $(am__objects_11) $(am__objects_12)
4.64 + tacore.$(OBJEXT) rendsort.$(OBJEXT) texcache.$(OBJEXT) \
4.65 + yuv.$(OBJEXT) rendsave.$(OBJEXT) scene.$(OBJEXT) \
4.66 + gl_sl.$(OBJEXT) gl_slsrc.$(OBJEXT) glutil.$(OBJEXT) \
4.67 + glrender.$(OBJEXT) maple.$(OBJEXT) controller.$(OBJEXT) \
4.68 + kbd.$(OBJEXT) mouse.$(OBJEXT) loader.$(OBJEXT) \
4.69 + bootstrap.$(OBJEXT) util.$(OBJEXT) display.$(OBJEXT) \
4.70 + audio_null.$(OBJEXT) video_null.$(OBJEXT) video_gl.$(OBJEXT) \
4.71 + gl_fbo.$(OBJEXT) $(am__objects_1) $(am__objects_2) \
4.72 + $(am__objects_3) $(am__objects_4) $(am__objects_5) \
4.73 + $(am__objects_6) $(am__objects_7) $(am__objects_8) \
4.74 + $(am__objects_9) $(am__objects_10) $(am__objects_11) \
4.75 + $(am__objects_12)
4.76 lxdream_OBJECTS = $(am_lxdream_OBJECTS)
4.77 lxdream_DEPENDENCIES = $(am__DEPENDENCIES_1)
4.78 am__test_testsh4x86_SOURCES_DIST = test/testsh4x86.c x86dasm/x86dasm.c \
4.79 @@ -374,19 +374,18 @@
4.80 sh4/sh4stat.h sh4/xltcache.c sh4/xltcache.h sh4/sh4.h \
4.81 aica/armcore.c aica/armcore.h aica/armdasm.c aica/armmem.c \
4.82 aica/aica.c aica/aica.h aica/audio.c aica/audio.h pvr2/pvr2.c \
4.83 - pvr2/pvr2.h pvr2/pvr2mem.c pvr2/tacore.c pvr2/rendbkg.c \
4.84 - pvr2/rendsort.c pvr2/texcache.c pvr2/yuv.c pvr2/rendsave.c \
4.85 - pvr2/scene.c pvr2/scene.h pvr2/gl_sl.c pvr2/gl_slsrc.c \
4.86 - pvr2/glutil.c pvr2/glutil.h pvr2/glrender.c maple/maple.c \
4.87 - maple/maple.h maple/controller.c maple/controller.h \
4.88 - maple/kbd.c maple/mouse.c loader.c bootstrap.c util.c \
4.89 - display.c display.h dckeysyms.h drivers/audio_null.c \
4.90 - drivers/video_null.c drivers/video_gl.c drivers/video_gl.h \
4.91 - drivers/gl_fbo.c $(am__append_1) $(am__append_3) \
4.92 - $(am__append_4) $(am__append_5) $(am__append_6) \
4.93 - $(am__append_7) $(am__append_8) $(am__append_9) \
4.94 - $(am__append_10) $(am__append_11) $(am__append_12) \
4.95 - $(am__append_13)
4.96 + pvr2/pvr2.h pvr2/pvr2mem.c pvr2/tacore.c pvr2/rendsort.c \
4.97 + pvr2/texcache.c pvr2/yuv.c pvr2/rendsave.c pvr2/scene.c \
4.98 + pvr2/scene.h pvr2/gl_sl.c pvr2/gl_slsrc.c pvr2/glutil.c \
4.99 + pvr2/glutil.h pvr2/glrender.c maple/maple.c maple/maple.h \
4.100 + maple/controller.c maple/controller.h maple/kbd.c \
4.101 + maple/mouse.c loader.c bootstrap.c util.c display.c display.h \
4.102 + dckeysyms.h drivers/audio_null.c drivers/video_null.c \
4.103 + drivers/video_gl.c drivers/video_gl.h drivers/gl_fbo.c \
4.104 + $(am__append_1) $(am__append_3) $(am__append_4) \
4.105 + $(am__append_5) $(am__append_6) $(am__append_7) \
4.106 + $(am__append_8) $(am__append_9) $(am__append_10) \
4.107 + $(am__append_11) $(am__append_12) $(am__append_13)
4.108 @BUILD_SH4X86_TRUE@test_testsh4x86_LDADD = @GLIB_LIBS@ @GTK_LIBS@ @LIBPNG_LIBS@
4.109 @BUILD_SH4X86_TRUE@test_testsh4x86_SOURCES = test/testsh4x86.c x86dasm/x86dasm.c \
4.110 @BUILD_SH4X86_TRUE@ x86dasm/x86dasm.h x86dasm/i386-dis.c x86dasm/dis-init.c \
4.111 @@ -548,7 +547,6 @@
4.112 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/path_dlg.Po@am__quote@
4.113 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pvr2.Po@am__quote@
4.114 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pvr2mem.Po@am__quote@
4.115 -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rendbkg.Po@am__quote@
4.116 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rendsave.Po@am__quote@
4.117 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rendsort.Po@am__quote@
4.118 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scene.Po@am__quote@
4.119 @@ -1028,20 +1026,6 @@
4.120 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
4.121 @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tacore.obj `if test -f 'pvr2/tacore.c'; then $(CYGPATH_W) 'pvr2/tacore.c'; else $(CYGPATH_W) '$(srcdir)/pvr2/tacore.c'; fi`
4.122
4.123 -rendbkg.o: pvr2/rendbkg.c
4.124 -@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT rendbkg.o -MD -MP -MF "$(DEPDIR)/rendbkg.Tpo" -c -o rendbkg.o `test -f 'pvr2/rendbkg.c' || echo '$(srcdir)/'`pvr2/rendbkg.c; \
4.125 -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/rendbkg.Tpo" "$(DEPDIR)/rendbkg.Po"; else rm -f "$(DEPDIR)/rendbkg.Tpo"; exit 1; fi
4.126 -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pvr2/rendbkg.c' object='rendbkg.o' libtool=no @AMDEPBACKSLASH@
4.127 -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
4.128 -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o rendbkg.o `test -f 'pvr2/rendbkg.c' || echo '$(srcdir)/'`pvr2/rendbkg.c
4.129 -
4.130 -rendbkg.obj: pvr2/rendbkg.c
4.131 -@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT rendbkg.obj -MD -MP -MF "$(DEPDIR)/rendbkg.Tpo" -c -o rendbkg.obj `if test -f 'pvr2/rendbkg.c'; then $(CYGPATH_W) 'pvr2/rendbkg.c'; else $(CYGPATH_W) '$(srcdir)/pvr2/rendbkg.c'; fi`; \
4.132 -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/rendbkg.Tpo" "$(DEPDIR)/rendbkg.Po"; else rm -f "$(DEPDIR)/rendbkg.Tpo"; exit 1; fi
4.133 -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pvr2/rendbkg.c' object='rendbkg.obj' libtool=no @AMDEPBACKSLASH@
4.134 -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
4.135 -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o rendbkg.obj `if test -f 'pvr2/rendbkg.c'; then $(CYGPATH_W) 'pvr2/rendbkg.c'; else $(CYGPATH_W) '$(srcdir)/pvr2/rendbkg.c'; fi`
4.136 -
4.137 rendsort.o: pvr2/rendsort.c
4.138 @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT rendsort.o -MD -MP -MF "$(DEPDIR)/rendsort.Tpo" -c -o rendsort.o `test -f 'pvr2/rendsort.c' || echo '$(srcdir)/'`pvr2/rendsort.c; \
4.139 @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/rendsort.Tpo" "$(DEPDIR)/rendsort.Po"; else rm -f "$(DEPDIR)/rendsort.Tpo"; exit 1; fi
5.1 --- a/src/pvr2/glrender.c Sat Jun 14 10:19:35 2008 +0000
5.2 +++ b/src/pvr2/glrender.c Sat Jun 14 11:54:15 2008 +0000
5.3 @@ -101,6 +101,13 @@
5.4 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
5.5 glMatrixMode(GL_MODELVIEW);
5.6 glLoadIdentity();
5.7 +
5.8 +#ifdef HAVE_OPENGL_CLAMP_COLOR
5.9 + if( isGLExtensionSupported("GL_ARB_color_buffer_float") ) {
5.10 + glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, GL_FALSE );
5.11 + glClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB, GL_FALSE );
5.12 + }
5.13 +#endif
5.14
5.15 glEnableClientState( GL_COLOR_ARRAY );
5.16 glEnableClientState( GL_VERTEX_ARRAY );
5.17 @@ -197,6 +204,23 @@
5.18 glDrawArrays(GL_TRIANGLE_STRIP, poly->vertex_index, poly->vertex_count );
5.19 }
5.20
5.21 +
5.22 +static void gl_render_bkgnd( struct polygon_struct *poly )
5.23 +{
5.24 + if( poly->tex_id != -1 ) {
5.25 + glBindTexture(GL_TEXTURE_2D, poly->tex_id);
5.26 + }
5.27 + render_set_context( poly->context, RENDER_NORMAL );
5.28 + glDisable( GL_DEPTH_TEST );
5.29 + glDisable( GL_CULL_FACE );
5.30 + glBlendFunc( GL_ONE, GL_ZERO );
5.31 + glDrawArrays(GL_TRIANGLE_STRIP, poly->vertex_index, poly->vertex_count );
5.32 + glEnable( GL_CULL_FACE );
5.33 + glEnable( GL_DEPTH_TEST );
5.34 +}
5.35 +
5.36 +
5.37 +
5.38 void gl_render_tilelist( pvraddr_t tile_entry )
5.39 {
5.40 uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);
5.41 @@ -255,10 +279,10 @@
5.42 float nearz = pvr2_scene.bounds[4];
5.43 float farz = pvr2_scene.bounds[5];
5.44 if( nearz == farz ) {
5.45 - farz*= 2.0;
5.46 + farz*= 4.0;
5.47 }
5.48 glOrtho( 0, pvr2_scene.buffer_width, pvr2_scene.buffer_height, 0,
5.49 - -farz-1, -nearz );
5.50 + -farz, -nearz );
5.51 float alphaRef = ((float)(MMIO_READ(PVR2, RENDER_ALPHA_REF)&0xFF)+1)/256.0;
5.52 glAlphaFunc( GL_GEQUAL, alphaRef );
5.53
5.54 @@ -268,15 +292,16 @@
5.55 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
5.56
5.57 /* Setup vertex array pointers */
5.58 - glInterleavedArrays(GL_T2F_C4UB_V3F, sizeof(struct vertex_struct), pvr2_scene.vertex_array);
5.59 - glSecondaryColorPointerEXT(3, GL_UNSIGNED_BYTE, sizeof(struct vertex_struct), &pvr2_scene.vertex_array[0].offset_rgba );
5.60 + glVertexPointer(3, GL_FLOAT, sizeof(struct vertex_struct), &pvr2_scene.vertex_array[0].x);
5.61 + glColorPointer(4, GL_FLOAT, sizeof(struct vertex_struct), &pvr2_scene.vertex_array[0].rgba[0]);
5.62 + glTexCoordPointer(2, GL_FLOAT, sizeof(struct vertex_struct), &pvr2_scene.vertex_array[0].u);
5.63 + glSecondaryColorPointerEXT(3, GL_FLOAT, sizeof(struct vertex_struct), pvr2_scene.vertex_array[0].offset_rgba );
5.64
5.65 /* Turn on the shaders (if available) */
5.66 glsl_enable_shaders(TRUE);
5.67
5.68 - uint32_t bgplane_mode = MMIO_READ(PVR2, RENDER_BGPLANE);
5.69 - uint32_t *bgplane = pvr2_scene.pvr2_pbuf + (((bgplane_mode & 0x00FFFFFF)) >> 3) ;
5.70 - render_backplane( bgplane, pvr2_scene.buffer_width, pvr2_scene.buffer_height, bgplane_mode );
5.71 + /* Render the background */
5.72 + gl_render_bkgnd( pvr2_scene.bkgnd_poly );
5.73
5.74 glEnable( GL_SCISSOR_TEST );
5.75
6.1 --- a/src/pvr2/glutil.c Sat Jun 14 10:19:35 2008 +0000
6.2 +++ b/src/pvr2/glutil.c Sat Jun 14 11:54:15 2008 +0000
6.3 @@ -16,6 +16,7 @@
6.4 * GNU General Public License for more details.
6.5 */
6.6 #include <string.h>
6.7 +#include <glib/gstrfuncs.h>
6.8 #include "pvr2/glutil.h"
6.9
6.10 gboolean isGLSecondaryColorSupported()
6.11 @@ -75,3 +76,20 @@
6.12 }
6.13 return FALSE;
6.14 }
6.15 +
6.16 +void glPrintInfo( FILE *out )
6.17 +{
6.18 + const GLubyte *extensions = glGetString(GL_EXTENSIONS);
6.19 + gchar **ext_split = g_strsplit(extensions, " ", 0);
6.20 + unsigned int i;
6.21 +
6.22 + fprintf( out, "GL Vendor: %s\n", glGetString(GL_VENDOR) );
6.23 + fprintf( out, "GL Renderer: %s\n", glGetString(GL_RENDERER) );
6.24 + fprintf( out, "GL Version: %s\n", glGetString(GL_VERSION) );
6.25 +
6.26 + fprintf( out, "Supported GL Extensions:\n" );
6.27 + for( i=0; ext_split[i] != NULL; i++ ) {
6.28 + fprintf( out, " %s\n", ext_split[i] );
6.29 + }
6.30 + g_strfreev(ext_split);
6.31 +}
7.1 --- a/src/pvr2/glutil.h Sat Jun 14 10:19:35 2008 +0000
7.2 +++ b/src/pvr2/glutil.h Sat Jun 14 11:54:15 2008 +0000
7.3 @@ -19,6 +19,7 @@
7.4 #ifndef lxdream_glutil_H
7.5 #define lxdream_glutil_H
7.6
7.7 +#include <stdio.h>
7.8 #include "display.h"
7.9
7.10 /**
7.11 @@ -29,6 +30,11 @@
7.12 gboolean isGLExtensionSupported( const char *extension );
7.13
7.14 /**
7.15 + * Dump GL information to the output stream, usually for debugging purposes
7.16 + */
7.17 +void glPrintInfo( FILE *out );
7.18 +
7.19 +/**
7.20 * Test if secondary color (GL_COLOR_SUM) is supported.
7.21 */
7.22 gboolean isGLSecondaryColorSupported();
8.1 --- a/src/pvr2/scene.c Sat Jun 14 10:19:35 2008 +0000
8.2 +++ b/src/pvr2/scene.c Sat Jun 14 11:54:15 2008 +0000
8.3 @@ -27,6 +27,13 @@
8.4 #include "pvr2/glutil.h"
8.5 #include "pvr2/scene.h"
8.6
8.7 +static void unpack_bgra(uint32_t bgra, float *rgba)
8.8 +{
8.9 + rgba[0] = ((float)(((bgra&0x00FF0000)>>16) + 1)) / 256.0;
8.10 + rgba[1] = ((float)(((bgra&0x0000FF00)>>8) + 1)) / 256.0;
8.11 + rgba[2] = ((float)((bgra&0x000000FF) + 1)) / 256.0;
8.12 + rgba[3] = ((float)(((bgra&0xFF000000)>>24) + 1)) / 256.0;
8.13 +}
8.14
8.15 static inline uint32_t bgra_to_rgba(uint32_t bgra)
8.16 {
8.17 @@ -117,7 +124,8 @@
8.18 void *vertex_buffer_map()
8.19 {
8.20 glGetError();
8.21 - uint32_t size = pvr2_scene.vertex_count * sizeof(struct vertex_struct);
8.22 + // Allow 8 vertexes for the background (4+4)
8.23 + uint32_t size = (pvr2_scene.vertex_count + 8) * sizeof(struct vertex_struct);
8.24 #ifdef ENABLE_VERTEX_BUFFER
8.25 if( vbo_supported ) {
8.26 glBindBufferARB( GL_ARRAY_BUFFER_ARB, pvr2_scene.vbo_id );
8.27 @@ -158,26 +166,26 @@
8.28 }
8.29
8.30 static struct polygon_struct *scene_add_polygon( pvraddr_t poly_idx, int vertex_count,
8.31 - gboolean is_modified )
8.32 + gboolean is_modified )
8.33 {
8.34 int vert_mul = is_modified ? 2 : 1;
8.35
8.36 if( pvr2_scene.buf_to_poly_map[poly_idx] != NULL ) {
8.37 - if( vertex_count > pvr2_scene.buf_to_poly_map[poly_idx]->vertex_count ) {
8.38 - pvr2_scene.vertex_count += (vertex_count - pvr2_scene.buf_to_poly_map[poly_idx]->vertex_count) * vert_mul;
8.39 - pvr2_scene.buf_to_poly_map[poly_idx]->vertex_count = vertex_count;
8.40 - }
8.41 - return pvr2_scene.buf_to_poly_map[poly_idx];
8.42 + if( vertex_count > pvr2_scene.buf_to_poly_map[poly_idx]->vertex_count ) {
8.43 + pvr2_scene.vertex_count += (vertex_count - pvr2_scene.buf_to_poly_map[poly_idx]->vertex_count) * vert_mul;
8.44 + pvr2_scene.buf_to_poly_map[poly_idx]->vertex_count = vertex_count;
8.45 + }
8.46 + return pvr2_scene.buf_to_poly_map[poly_idx];
8.47 } else {
8.48 - struct polygon_struct *poly = &pvr2_scene.poly_array[pvr2_scene.poly_count++];
8.49 - poly->context = (uint32_t *)(video_base + MMIO_READ(PVR2,RENDER_POLYBASE) + (poly_idx<<2));
8.50 - poly->vertex_count = vertex_count;
8.51 - poly->vertex_index = -1;
8.52 - poly->mod_vertex_index = -1;
8.53 - poly->next = NULL;
8.54 - pvr2_scene.buf_to_poly_map[poly_idx] = poly;
8.55 - pvr2_scene.vertex_count += (vertex_count * vert_mul);
8.56 - return poly;
8.57 + struct polygon_struct *poly = &pvr2_scene.poly_array[pvr2_scene.poly_count++];
8.58 + poly->context = &pvr2_scene.pvr2_pbuf[poly_idx];
8.59 + poly->vertex_count = vertex_count;
8.60 + poly->vertex_index = -1;
8.61 + poly->mod_vertex_index = -1;
8.62 + poly->next = NULL;
8.63 + pvr2_scene.buf_to_poly_map[poly_idx] = poly;
8.64 + pvr2_scene.vertex_count += (vertex_count * vert_mul);
8.65 + return poly;
8.66 }
8.67 }
8.68
8.69 @@ -197,69 +205,70 @@
8.70 {
8.71 gboolean force_alpha = !POLY2_ALPHA_ENABLE(poly2);
8.72 union pvr2_data_type {
8.73 - uint32_t *ival;
8.74 - float *fval;
8.75 + uint32_t *ival;
8.76 + float *fval;
8.77 } data;
8.78
8.79 data.ival = pvr2_data;
8.80 -
8.81 +
8.82 vert->x = *data.fval++;
8.83 vert->y = *data.fval++;
8.84
8.85 float z = *data.fval++;
8.86 if( !isfinite(z) ) {
8.87 - z = 0;
8.88 + z = 0;
8.89 } else if( z != 0 ) {
8.90 - z = 1/z;
8.91 + z = 1/z;
8.92 }
8.93 if( z > pvr2_scene.bounds[5] ) {
8.94 - pvr2_scene.bounds[5] = z;
8.95 + pvr2_scene.bounds[5] = z;
8.96 } else if( z < pvr2_scene.bounds[4] && z != 0 ) {
8.97 - pvr2_scene.bounds[4] = z;
8.98 + pvr2_scene.bounds[4] = z;
8.99 }
8.100 vert->z = z;
8.101 data.ival += modify_offset;
8.102
8.103 -
8.104 +
8.105 if( POLY1_TEXTURED(poly1) ) {
8.106 - if( POLY1_UV16(poly1) ) {
8.107 - vert->u = halftofloat( *data.ival>>16 );
8.108 - vert->v = halftofloat( *data.ival );
8.109 - data.ival++;
8.110 - } else {
8.111 - vert->u = *data.fval++;
8.112 - vert->v = *data.fval++;
8.113 - }
8.114 - if( POLY2_TEX_BLEND(poly2) == 1 ) {
8.115 - force_alpha = TRUE;
8.116 - }
8.117 + if( POLY1_UV16(poly1) ) {
8.118 + vert->u = halftofloat( *data.ival>>16 );
8.119 + vert->v = halftofloat( *data.ival );
8.120 + data.ival++;
8.121 + } else {
8.122 + vert->u = *data.fval++;
8.123 + vert->v = *data.fval++;
8.124 + }
8.125 + if( POLY2_TEX_BLEND(poly2) == 1 ) {
8.126 + force_alpha = TRUE;
8.127 + }
8.128 }
8.129 + unpack_bgra(*data.ival++, vert->rgba);
8.130 + if( POLY1_SPECULAR(poly1) ) {
8.131 + unpack_bgra(*data.ival++, vert->offset_rgba);
8.132 + vert->offset_rgba[3] = 1.0;
8.133 + } else {
8.134 + vert->offset_rgba[0] = 0.0;
8.135 + vert->offset_rgba[1] = 0.0;
8.136 + vert->offset_rgba[2] = 0.0;
8.137 + vert->offset_rgba[3] = 0.0;
8.138 + }
8.139 +
8.140 if( force_alpha ) {
8.141 - vert->rgba = bgra_to_rgba((*data.ival++) | 0xFF000000);
8.142 - if( POLY1_SPECULAR(poly1) ) {
8.143 - vert->offset_rgba = bgra_to_rgba((*data.ival++) | 0xFF000000);
8.144 - } else {
8.145 - vert->offset_rgba = 0;
8.146 - }
8.147 - } else {
8.148 - vert->rgba = bgra_to_rgba(*data.ival++);
8.149 - if( POLY1_SPECULAR(poly1) ) {
8.150 - vert->offset_rgba = bgra_to_rgba(*data.ival++);
8.151 - } else {
8.152 - vert->offset_rgba = 0;
8.153 - }
8.154 + vert->rgba[3] = 1.0;
8.155 + vert->offset_rgba[3] = 1.0;
8.156 }
8.157 }
8.158
8.159 /**
8.160 - * Compute texture, colour, and z values for a result point by interpolating from
8.161 - * a set of 3 input points. The result point must define its x,y.
8.162 + * Compute texture, colour, and z values for 1 or more result points by interpolating from
8.163 + * a set of 3 input points. The result point(s) must define their x,y.
8.164 */
8.165 -static void scene_compute_vertex( struct vertex_struct *result,
8.166 - struct vertex_struct *input,
8.167 - gboolean is_solid_shaded )
8.168 +static void scene_compute_vertexes( struct vertex_struct *result,
8.169 + int result_count,
8.170 + struct vertex_struct *input,
8.171 + gboolean is_solid_shaded )
8.172 {
8.173 - int i;
8.174 + int i,j;
8.175 float sx = input[2].x - input[1].x;
8.176 float sy = input[2].y - input[1].y;
8.177 float tx = input[0].x - input[1].x;
8.178 @@ -267,18 +276,18 @@
8.179
8.180 float detxy = ((sy) * (tx)) - ((ty) * (sx));
8.181 if( detxy == 0 ) {
8.182 - result->z = input[2].z;
8.183 - result->u = input[2].u;
8.184 - result->v = input[2].v;
8.185 - result->rgba = input[2].rgba;
8.186 - result->offset_rgba = input[2].offset_rgba;
8.187 - return;
8.188 + // If the input points fall on a line, they don't define a usable
8.189 + // polygon - the PVR2 takes the last input point as the result in
8.190 + // this case.
8.191 + for( i=0; i<result_count; i++ ) {
8.192 + float x = result[i].x;
8.193 + float y = result[i].y;
8.194 + memcpy( &result[i], &input[2], sizeof(struct vertex_struct) );
8.195 + result[i].x = x;
8.196 + result[i].y = y;
8.197 + }
8.198 + return;
8.199 }
8.200 - float t = ((result->x - input[1].x) * sy -
8.201 - (result->y - input[1].y) * sx) / detxy;
8.202 - float s = ((result->y - input[1].y) * tx -
8.203 - (result->x - input[1].x) * ty) / detxy;
8.204 -
8.205 float sz = input[2].z - input[1].z;
8.206 float tz = input[0].z - input[1].z;
8.207 float su = input[2].u - input[1].u;
8.208 @@ -286,41 +295,42 @@
8.209 float sv = input[2].v - input[1].v;
8.210 float tv = input[0].v - input[1].v;
8.211
8.212 - float rz = input[1].z + (t*tz) + (s*sz);
8.213 - if( rz > pvr2_scene.bounds[5] ) {
8.214 - pvr2_scene.bounds[5] = rz;
8.215 - } else if( rz < pvr2_scene.bounds[4] ) {
8.216 - pvr2_scene.bounds[4] = rz;
8.217 + for( i=0; i<result_count; i++ ) {
8.218 + float t = ((result[i].x - input[1].x) * sy -
8.219 + (result[i].y - input[1].y) * sx) / detxy;
8.220 + float s = ((result[i].y - input[1].y) * tx -
8.221 + (result[i].x - input[1].x) * ty) / detxy;
8.222 +
8.223 + float rz = input[1].z + (t*tz) + (s*sz);
8.224 + if( rz > pvr2_scene.bounds[5] ) {
8.225 + pvr2_scene.bounds[5] = rz;
8.226 + } else if( rz < pvr2_scene.bounds[4] ) {
8.227 + pvr2_scene.bounds[4] = rz;
8.228 + }
8.229 + result[i].z = rz;
8.230 + result[i].u = input[1].u + (t*tu) + (s*su);
8.231 + result[i].v = input[1].v + (t*tv) + (s*sv);
8.232 +
8.233 + if( is_solid_shaded ) {
8.234 + memcpy( result->rgba, input[2].rgba, sizeof(result->rgba) );
8.235 + memcpy( result->offset_rgba, input[2].offset_rgba, sizeof(result->offset_rgba) );
8.236 + } else {
8.237 + float *rgba0 = input[0].rgba;
8.238 + float *rgba1 = input[1].rgba;
8.239 + float *rgba2 = input[2].rgba;
8.240 + float *rgba3 = result[i].rgba;
8.241 + for( j=0; j<8; j++ ) {
8.242 + float tc = *rgba0++ - *rgba1;
8.243 + float sc = *rgba2++ - *rgba1;
8.244 + float rc = *rgba1++ + (t*tc) + (s*sc);
8.245 + *rgba3++ = rc;
8.246 + }
8.247 + }
8.248 }
8.249 - result->z = rz;
8.250 - result->u = input[1].u + (t*tu) + (s*su);
8.251 - result->v = input[1].v + (t*tv) + (s*sv);
8.252 -
8.253 - if( is_solid_shaded ) {
8.254 - result->rgba = input[2].rgba;
8.255 - result->offset_rgba = input[2].offset_rgba;
8.256 - } else {
8.257 - uint8_t *rgba0 = (uint8_t *)&input[0].rgba;
8.258 - uint8_t *rgba1 = (uint8_t *)&input[1].rgba;
8.259 - uint8_t *rgba2 = (uint8_t *)&input[2].rgba;
8.260 - uint8_t *rgba3 = (uint8_t *)&result->rgba;
8.261 - for( i=0; i<8; i++ ) { // note: depends on rgba & offset_rgba being adjacent
8.262 - float tc = *rgba0++ - *rgba1;
8.263 - float sc = *rgba2++ - *rgba1;
8.264 - float rc = *rgba1++ + (t*tc) + (s*sc);
8.265 - if( rc < 0 ) {
8.266 - rc = 0;
8.267 - } else if( rc > 255 ) {
8.268 - rc = 255;
8.269 - }
8.270 - *rgba3++ = rc;
8.271 - }
8.272 - }
8.273 -
8.274 }
8.275
8.276 static void scene_add_vertexes( pvraddr_t poly_idx, int vertex_length,
8.277 - gboolean is_modified )
8.278 + gboolean is_modified )
8.279 {
8.280 struct polygon_struct *poly = pvr2_scene.buf_to_poly_map[poly_idx];
8.281 uint32_t *ptr = &pvr2_scene.pvr2_pbuf[poly_idx];
8.282 @@ -328,25 +338,25 @@
8.283 unsigned int i;
8.284
8.285 if( poly->vertex_index == -1 ) {
8.286 - ptr += (is_modified ? 5 : 3 );
8.287 - poly->vertex_index = pvr2_scene.vertex_index;
8.288 -
8.289 - assert( poly != NULL );
8.290 - assert( pvr2_scene.vertex_index + poly->vertex_count <= pvr2_scene.vertex_count );
8.291 - for( i=0; i<poly->vertex_count; i++ ) {
8.292 - pvr2_decode_render_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[1], ptr, 0 );
8.293 - ptr += vertex_length;
8.294 - }
8.295 - if( is_modified ) {
8.296 - int mod_offset = (vertex_length - 3)>>1;
8.297 - assert( pvr2_scene.vertex_index + poly->vertex_count <= pvr2_scene.vertex_count );
8.298 - ptr = &pvr2_scene.pvr2_pbuf[poly_idx] + 5;
8.299 - poly->mod_vertex_index = pvr2_scene.vertex_index;
8.300 - for( i=0; i<poly->vertex_count; i++ ) {
8.301 - pvr2_decode_render_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[3], ptr, mod_offset );
8.302 - ptr += vertex_length;
8.303 - }
8.304 - }
8.305 + ptr += (is_modified ? 5 : 3 );
8.306 + poly->vertex_index = pvr2_scene.vertex_index;
8.307 +
8.308 + assert( poly != NULL );
8.309 + assert( pvr2_scene.vertex_index + poly->vertex_count <= pvr2_scene.vertex_count );
8.310 + for( i=0; i<poly->vertex_count; i++ ) {
8.311 + pvr2_decode_render_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[1], ptr, 0 );
8.312 + ptr += vertex_length;
8.313 + }
8.314 + if( is_modified ) {
8.315 + int mod_offset = (vertex_length - 3)>>1;
8.316 + assert( pvr2_scene.vertex_index + poly->vertex_count <= pvr2_scene.vertex_count );
8.317 + ptr = &pvr2_scene.pvr2_pbuf[poly_idx] + 5;
8.318 + poly->mod_vertex_index = pvr2_scene.vertex_index;
8.319 + for( i=0; i<poly->vertex_count; i++ ) {
8.320 + pvr2_decode_render_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[3], ptr, mod_offset );
8.321 + ptr += vertex_length;
8.322 + }
8.323 + }
8.324 }
8.325 }
8.326
8.327 @@ -372,7 +382,7 @@
8.328 pvr2_decode_render_vertex( &quad[i], context[0], context[1], ptr, 0 );
8.329 ptr += vertex_length;
8.330 }
8.331 - scene_compute_vertex( &quad[3], &quad[0], !POLY1_GOURAUD_SHADED(context[0]) );
8.332 + scene_compute_vertexes( &quad[3], 1, &quad[0], !POLY1_GOURAUD_SHADED(context[0]) );
8.333 // Swap last two vertexes (quad arrangement => tri strip arrangement)
8.334 memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index], quad, sizeof(struct vertex_struct)*2 );
8.335 memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+2], &quad[3], sizeof(struct vertex_struct) );
8.336 @@ -380,7 +390,7 @@
8.337 pvr2_scene.vertex_index += 4;
8.338
8.339 if( is_modified ) {
8.340 - int mod_offset = (vertex_length - 3)>>1;
8.341 + int mod_offset = (vertex_length - 3)>>1;
8.342 assert( pvr2_scene.vertex_index + poly->vertex_count <= pvr2_scene.vertex_count );
8.343 ptr = &pvr2_scene.pvr2_pbuf[poly_idx] + 5;
8.344 poly->mod_vertex_index = pvr2_scene.vertex_index;
8.345 @@ -388,7 +398,7 @@
8.346 pvr2_decode_render_vertex( &quad[4], context[0], context[3], ptr, mod_offset );
8.347 ptr += vertex_length;
8.348 }
8.349 - scene_compute_vertex( &quad[3], &quad[0], !POLY1_GOURAUD_SHADED(context[0]) );
8.350 + scene_compute_vertexes( &quad[3], 1, &quad[0], !POLY1_GOURAUD_SHADED(context[0]) );
8.351 memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index], quad, sizeof(struct vertex_struct)*2 );
8.352 memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+2], &quad[3], sizeof(struct vertex_struct) );
8.353 memcpy( &pvr2_scene.vertex_array[pvr2_scene.vertex_index+3], &quad[2], sizeof(struct vertex_struct) );
8.354 @@ -401,64 +411,64 @@
8.355 {
8.356 uint32_t *tile_list = (uint32_t *)(video_base+tile_entry);
8.357 do {
8.358 - uint32_t entry = *tile_list++;
8.359 - if( entry >> 28 == 0x0F ) {
8.360 - break;
8.361 - } else if( entry >> 28 == 0x0E ) {
8.362 - tile_list = (uint32_t *)(video_base + (entry&0x007FFFFF));
8.363 - } else {
8.364 - pvraddr_t polyaddr = entry&0x000FFFFF;
8.365 - int is_modified = (entry & 0x01000000) && pvr2_scene.full_shadow;
8.366 - int vertex_length = (entry >> 21) & 0x07;
8.367 - int context_length = 3;
8.368 - if( is_modified ) {
8.369 - context_length = 5;
8.370 - vertex_length <<= 1 ;
8.371 - }
8.372 - vertex_length += 3;
8.373 -
8.374 - if( (entry & 0xE0000000) == 0x80000000 ) {
8.375 - /* Triangle(s) */
8.376 - int strip_count = ((entry >> 25) & 0x0F)+1;
8.377 - int polygon_length = 3 * vertex_length + context_length;
8.378 - int i;
8.379 - struct polygon_struct *last_poly = NULL;
8.380 - for( i=0; i<strip_count; i++ ) {
8.381 - struct polygon_struct *poly = scene_add_polygon( polyaddr, 3, is_modified );
8.382 - polyaddr += polygon_length;
8.383 - if( last_poly != NULL && last_poly->next == NULL ) {
8.384 - last_poly->next = poly;
8.385 - }
8.386 - last_poly = poly;
8.387 - }
8.388 - } else if( (entry & 0xE0000000) == 0xA0000000 ) {
8.389 - /* Sprite(s) */
8.390 - int strip_count = ((entry >> 25) & 0x0F)+1;
8.391 - int polygon_length = 4 * vertex_length + context_length;
8.392 - int i;
8.393 - struct polygon_struct *last_poly = NULL;
8.394 - for( i=0; i<strip_count; i++ ) {
8.395 - struct polygon_struct *poly = scene_add_polygon( polyaddr, 4, is_modified );
8.396 - polyaddr += polygon_length;
8.397 - if( last_poly != NULL && last_poly->next == NULL ) {
8.398 - last_poly->next = poly;
8.399 - }
8.400 - last_poly = poly;
8.401 - }
8.402 - } else {
8.403 - /* Polygon */
8.404 - int i, last = -1;
8.405 - for( i=5; i>=0; i-- ) {
8.406 - if( entry & (0x40000000>>i) ) {
8.407 - last = i;
8.408 - break;
8.409 - }
8.410 - }
8.411 - if( last != -1 ) {
8.412 - scene_add_polygon( polyaddr, last+3, is_modified );
8.413 - }
8.414 - }
8.415 - }
8.416 + uint32_t entry = *tile_list++;
8.417 + if( entry >> 28 == 0x0F ) {
8.418 + break;
8.419 + } else if( entry >> 28 == 0x0E ) {
8.420 + tile_list = (uint32_t *)(video_base + (entry&0x007FFFFF));
8.421 + } else {
8.422 + pvraddr_t polyaddr = entry&0x000FFFFF;
8.423 + int is_modified = (entry & 0x01000000) && pvr2_scene.full_shadow;
8.424 + int vertex_length = (entry >> 21) & 0x07;
8.425 + int context_length = 3;
8.426 + if( is_modified ) {
8.427 + context_length = 5;
8.428 + vertex_length <<= 1 ;
8.429 + }
8.430 + vertex_length += 3;
8.431 +
8.432 + if( (entry & 0xE0000000) == 0x80000000 ) {
8.433 + /* Triangle(s) */
8.434 + int strip_count = ((entry >> 25) & 0x0F)+1;
8.435 + int polygon_length = 3 * vertex_length + context_length;
8.436 + int i;
8.437 + struct polygon_struct *last_poly = NULL;
8.438 + for( i=0; i<strip_count; i++ ) {
8.439 + struct polygon_struct *poly = scene_add_polygon( polyaddr, 3, is_modified );
8.440 + polyaddr += polygon_length;
8.441 + if( last_poly != NULL && last_poly->next == NULL ) {
8.442 + last_poly->next = poly;
8.443 + }
8.444 + last_poly = poly;
8.445 + }
8.446 + } else if( (entry & 0xE0000000) == 0xA0000000 ) {
8.447 + /* Sprite(s) */
8.448 + int strip_count = ((entry >> 25) & 0x0F)+1;
8.449 + int polygon_length = 4 * vertex_length + context_length;
8.450 + int i;
8.451 + struct polygon_struct *last_poly = NULL;
8.452 + for( i=0; i<strip_count; i++ ) {
8.453 + struct polygon_struct *poly = scene_add_polygon( polyaddr, 4, is_modified );
8.454 + polyaddr += polygon_length;
8.455 + if( last_poly != NULL && last_poly->next == NULL ) {
8.456 + last_poly->next = poly;
8.457 + }
8.458 + last_poly = poly;
8.459 + }
8.460 + } else {
8.461 + /* Polygon */
8.462 + int i, last = -1;
8.463 + for( i=5; i>=0; i-- ) {
8.464 + if( entry & (0x40000000>>i) ) {
8.465 + last = i;
8.466 + break;
8.467 + }
8.468 + }
8.469 + if( last != -1 ) {
8.470 + scene_add_polygon( polyaddr, last+3, is_modified );
8.471 + }
8.472 + }
8.473 + }
8.474 } while( 1 );
8.475 }
8.476
8.477 @@ -517,6 +527,66 @@
8.478 } while( 1 );
8.479 }
8.480
8.481 +static void scene_extract_background( void )
8.482 +{
8.483 + uint32_t bgplane = MMIO_READ(PVR2, RENDER_BGPLANE);
8.484 + int vertex_length = (bgplane >> 24) & 0x07;
8.485 + int context_length = 3, i;
8.486 + int is_modified = (bgplane & 0x08000000) && pvr2_scene.full_shadow;
8.487 +
8.488 + struct polygon_struct *poly = &pvr2_scene.poly_array[pvr2_scene.poly_count++];
8.489 + uint32_t *context = &pvr2_scene.pvr2_pbuf[(bgplane & 0x00FFFFFF)>>3];
8.490 + poly->context = context;
8.491 + poly->vertex_count = 4;
8.492 + poly->vertex_index = pvr2_scene.vertex_count;
8.493 + if( is_modified ) {
8.494 + context_length = 5;
8.495 + vertex_length <<= 1;
8.496 + poly->mod_vertex_index = pvr2_scene.vertex_count + 4;
8.497 + pvr2_scene.vertex_count += 8;
8.498 + } else {
8.499 + poly->mod_vertex_index = -1;
8.500 + pvr2_scene.vertex_count += 4;
8.501 + }
8.502 + vertex_length += 3;
8.503 + context_length += (bgplane & 0x07) * vertex_length;
8.504 +
8.505 + poly->next = NULL;
8.506 + pvr2_scene.bkgnd_poly = poly;
8.507 +
8.508 + struct vertex_struct base_vertexes[3];
8.509 + uint32_t *ptr = context + context_length;
8.510 + for( i=0; i<3; i++ ) {
8.511 + pvr2_decode_render_vertex( &base_vertexes[i], context[0], context[1],
8.512 + ptr, 0 );
8.513 + ptr += vertex_length;
8.514 + }
8.515 + struct vertex_struct *result_vertexes = &pvr2_scene.vertex_array[poly->vertex_index];
8.516 + result_vertexes[0].x = result_vertexes[0].y = 0;
8.517 + result_vertexes[1].x = result_vertexes[3].x = pvr2_scene.buffer_width;
8.518 + result_vertexes[1].y = result_vertexes[2].x = 0;
8.519 + result_vertexes[2].y = result_vertexes[3].y = pvr2_scene.buffer_height;
8.520 + scene_compute_vertexes( result_vertexes, 4, base_vertexes, !POLY1_GOURAUD_SHADED(context[0]) );
8.521 +
8.522 + if( is_modified ) {
8.523 + int mod_offset = (vertex_length - 3)>>1;
8.524 + ptr = context + context_length;
8.525 + for( i=0; i<3; i++ ) {
8.526 + pvr2_decode_render_vertex( &base_vertexes[i], context[0], context[3],
8.527 + ptr, mod_offset );
8.528 + ptr += vertex_length;
8.529 + }
8.530 + result_vertexes = &pvr2_scene.vertex_array[poly->mod_vertex_index];
8.531 + result_vertexes[0].x = result_vertexes[0].y = 0;
8.532 + result_vertexes[1].x = result_vertexes[3].x = pvr2_scene.buffer_width;
8.533 + result_vertexes[1].y = result_vertexes[2].x = 0;
8.534 + result_vertexes[2].y = result_vertexes[3].y = pvr2_scene.buffer_height;
8.535 + scene_compute_vertexes( result_vertexes, 4, base_vertexes, !POLY1_GOURAUD_SHADED(context[0]) );
8.536 + }
8.537 +
8.538 +}
8.539 +
8.540 +
8.541 uint32_t pvr2_scene_buffer_width()
8.542 {
8.543 return pvr2_scene.buffer_width;
8.544 @@ -554,62 +624,63 @@
8.545 pvr2_scene.segment_list = (struct tile_segment *)tilebuffer;
8.546 pvr2_scene.pvr2_pbuf = (uint32_t *)(video_base + MMIO_READ(PVR2,RENDER_POLYBASE));
8.547 pvr2_scene.full_shadow = MMIO_READ( PVR2, RENDER_SHADOW ) & 0x100 ? FALSE : TRUE;
8.548 -
8.549 +
8.550 int max_tile_x = 0;
8.551 int max_tile_y = 0;
8.552 int obj_config = MMIO_READ( PVR2, RENDER_OBJCFG );
8.553 int isp_config = MMIO_READ( PVR2, RENDER_ISPCFG );
8.554
8.555 if( (obj_config & 0x00200000) == 0 ) {
8.556 - if( isp_config & 1 ) {
8.557 - pvr2_scene.sort_mode = SORT_NEVER;
8.558 - } else {
8.559 - pvr2_scene.sort_mode = SORT_ALWAYS;
8.560 - }
8.561 + if( isp_config & 1 ) {
8.562 + pvr2_scene.sort_mode = SORT_NEVER;
8.563 + } else {
8.564 + pvr2_scene.sort_mode = SORT_ALWAYS;
8.565 + }
8.566 } else {
8.567 - pvr2_scene.sort_mode = SORT_TILEFLAG;
8.568 + pvr2_scene.sort_mode = SORT_TILEFLAG;
8.569 }
8.570
8.571 // Pass 1: Extract polygon list
8.572 uint32_t control;
8.573 int i;
8.574 do {
8.575 - control = *segment++;
8.576 - int tile_x = SEGMENT_X(control);
8.577 - int tile_y = SEGMENT_Y(control);
8.578 - if( tile_x > max_tile_x ) {
8.579 - max_tile_x = tile_x;
8.580 - }
8.581 - if( tile_y > max_tile_y ) {
8.582 - max_tile_y = tile_y;
8.583 - }
8.584 - for( i=0; i<5; i++ ) {
8.585 - if( (*segment & NO_POINTER) == 0 ) {
8.586 - scene_extract_polygons( *segment );
8.587 - }
8.588 - segment++;
8.589 - }
8.590 + control = *segment++;
8.591 + int tile_x = SEGMENT_X(control);
8.592 + int tile_y = SEGMENT_Y(control);
8.593 + if( tile_x > max_tile_x ) {
8.594 + max_tile_x = tile_x;
8.595 + }
8.596 + if( tile_y > max_tile_y ) {
8.597 + max_tile_y = tile_y;
8.598 + }
8.599 + for( i=0; i<5; i++ ) {
8.600 + if( (*segment & NO_POINTER) == 0 ) {
8.601 + scene_extract_polygons( *segment );
8.602 + }
8.603 + segment++;
8.604 + }
8.605 } while( (control & SEGMENT_END) == 0 );
8.606
8.607 pvr2_scene.buffer_width = (max_tile_x+1)<<5;
8.608 pvr2_scene.buffer_height = (max_tile_y+1)<<5;
8.609
8.610 - if( pvr2_scene.vertex_count > 0 ) {
8.611 - // Pass 2: Extract vertex data
8.612 - vertex_buffer_map();
8.613 - pvr2_scene.vertex_index = 0;
8.614 - segment = tilebuffer;
8.615 - do {
8.616 - control = *segment++;
8.617 - for( i=0; i<5; i++ ) {
8.618 - if( (*segment & NO_POINTER) == 0 ) {
8.619 - scene_extract_vertexes( *segment );
8.620 - }
8.621 - segment++;
8.622 - }
8.623 - } while( (control & SEGMENT_END) == 0 );
8.624 - vertex_buffer_unmap();
8.625 - }
8.626 + // Pass 2: Extract vertex data
8.627 + vertex_buffer_map();
8.628 + pvr2_scene.vertex_index = 0;
8.629 + segment = tilebuffer;
8.630 + do {
8.631 + control = *segment++;
8.632 + for( i=0; i<5; i++ ) {
8.633 + if( (*segment & NO_POINTER) == 0 ) {
8.634 + scene_extract_vertexes( *segment );
8.635 + }
8.636 + segment++;
8.637 + }
8.638 + } while( (control & SEGMENT_END) == 0 );
8.639 +
8.640 + scene_extract_background();
8.641 +
8.642 + vertex_buffer_unmap();
8.643 }
8.644
8.645 /**
9.1 --- a/src/pvr2/scene.h Sat Jun 14 10:19:35 2008 +0000
9.2 +++ b/src/pvr2/scene.h Sat Jun 14 11:54:15 2008 +0000
9.3 @@ -29,9 +29,9 @@
9.4
9.5 struct vertex_struct {
9.6 float u,v;
9.7 - uint32_t rgba;
9.8 float x,y,z;
9.9 - uint32_t offset_rgba;
9.10 + float rgba[4];
9.11 + float offset_rgba[4];
9.12 };
9.13
9.14 struct polygon_struct {
9.15 @@ -69,7 +69,7 @@
9.16
9.17 /**
9.18 * Maximum polygons - smallest is 1 polygon in 48 bytes, giving
9.19 - * 87381
9.20 + * 87381, plus 1 for the background
9.21 *
9.22 */
9.23 #define MAX_POLYGONS 87382
9.24 @@ -100,6 +100,9 @@
9.25 /** Pointer to the polygon data for the scene (main ram).
9.26 * This will always have room for at least MAX_POLYGONS */
9.27 struct polygon_struct *poly_array;
9.28 + /** Pointer to the background polygon. This is always a quad, and
9.29 + * normally the last member of poly_array */
9.30 + struct polygon_struct *bkgnd_poly;
9.31 /** Total number of polygons in the scene */
9.32 uint32_t poly_count;
9.33
.