Search
lxdream.org :: lxdream :: r1159:580436b01b6c
lxdream 0.9.1
released Jun 29
Download Now
changeset1159:580436b01b6c
parent1158:2b237e3417dd
child1160:219d05b638de
authornkeynes
dateWed Jan 19 17:50:09 2011 +1000 (8 years ago)
Implement vertex array range support, and move buffer operations to gl_vbo.c
src/Makefile.am
src/Makefile.in
src/display.h
src/drivers/video_gl.h
src/drivers/video_glx.c
src/drivers/video_nsgl.m
src/drivers/video_null.c
src/lxdream.h
src/pvr2/glrender.c
src/pvr2/glutil.c
src/pvr2/glutil.h
src/pvr2/scene.c
src/pvr2/scene.h
1.1 --- a/src/Makefile.am Wed Jan 19 12:51:19 2011 +1000
1.2 +++ b/src/Makefile.am Wed Jan 19 17:50:09 2011 +1000
1.3 @@ -65,7 +65,7 @@
1.4 vmu/vmuvol.c vmu/vmuvol.h vmu/vmulist.c vmu/vmulist.h \
1.5 display.c display.h dckeysyms.h \
1.6 drivers/audio_null.c drivers/video_null.c \
1.7 - drivers/video_gl.c drivers/video_gl.h drivers/gl_fbo.c \
1.8 + drivers/video_gl.c drivers/video_gl.h drivers/gl_fbo.c drivers/gl_vbo.c \
1.9 drivers/serial_unix.c \
1.10 drivers/cdrom/cdrom.h drivers/cdrom/cdrom.c drivers/cdrom/drive.h \
1.11 drivers/cdrom/sector.h drivers/cdrom/sector.c drivers/cdrom/defs.h \
2.1 --- a/src/Makefile.in Wed Jan 19 12:51:19 2011 +1000
2.2 +++ b/src/Makefile.in Wed Jan 19 17:50:09 2011 +1000
2.3 @@ -166,7 +166,7 @@
2.4 vmu/vmuvol.h vmu/vmulist.c vmu/vmulist.h display.c display.h \
2.5 dckeysyms.h drivers/audio_null.c drivers/video_null.c \
2.6 drivers/video_gl.c drivers/video_gl.h drivers/gl_fbo.c \
2.7 - drivers/serial_unix.c drivers/cdrom/cdrom.h \
2.8 + drivers/gl_vbo.c drivers/serial_unix.c drivers/cdrom/cdrom.h \
2.9 drivers/cdrom/cdrom.c drivers/cdrom/drive.h \
2.10 drivers/cdrom/sector.h drivers/cdrom/sector.c \
2.11 drivers/cdrom/defs.h drivers/cdrom/cd_nrg.c \
2.12 @@ -276,18 +276,19 @@
2.13 lxdream-vmulist.$(OBJEXT) lxdream-display.$(OBJEXT) \
2.14 lxdream-audio_null.$(OBJEXT) lxdream-video_null.$(OBJEXT) \
2.15 lxdream-video_gl.$(OBJEXT) lxdream-gl_fbo.$(OBJEXT) \
2.16 - lxdream-serial_unix.$(OBJEXT) lxdream-cdrom.$(OBJEXT) \
2.17 - lxdream-sector.$(OBJEXT) lxdream-cd_nrg.$(OBJEXT) \
2.18 - lxdream-cd_cdi.$(OBJEXT) lxdream-cd_gdi.$(OBJEXT) \
2.19 - lxdream-edc_ecc.$(OBJEXT) lxdream-drive.$(OBJEXT) \
2.20 - lxdream-cd_mmc.$(OBJEXT) lxdream-isofs.$(OBJEXT) \
2.21 - lxdream-isomem.$(OBJEXT) lxdream-hotkeys.$(OBJEXT) \
2.22 - $(am__objects_1) $(am__objects_2) $(am__objects_3) \
2.23 - $(am__objects_4) $(am__objects_5) $(am__objects_6) \
2.24 - $(am__objects_7) $(am__objects_8) $(am__objects_9) \
2.25 - $(am__objects_10) $(am__objects_11) $(am__objects_12) \
2.26 - $(am__objects_13) $(am__objects_14) $(am__objects_15) \
2.27 - $(am__objects_16) $(am__objects_17) $(am__objects_18)
2.28 + lxdream-gl_vbo.$(OBJEXT) lxdream-serial_unix.$(OBJEXT) \
2.29 + lxdream-cdrom.$(OBJEXT) lxdream-sector.$(OBJEXT) \
2.30 + lxdream-cd_nrg.$(OBJEXT) lxdream-cd_cdi.$(OBJEXT) \
2.31 + lxdream-cd_gdi.$(OBJEXT) lxdream-edc_ecc.$(OBJEXT) \
2.32 + lxdream-drive.$(OBJEXT) lxdream-cd_mmc.$(OBJEXT) \
2.33 + lxdream-isofs.$(OBJEXT) lxdream-isomem.$(OBJEXT) \
2.34 + lxdream-hotkeys.$(OBJEXT) $(am__objects_1) $(am__objects_2) \
2.35 + $(am__objects_3) $(am__objects_4) $(am__objects_5) \
2.36 + $(am__objects_6) $(am__objects_7) $(am__objects_8) \
2.37 + $(am__objects_9) $(am__objects_10) $(am__objects_11) \
2.38 + $(am__objects_12) $(am__objects_13) $(am__objects_14) \
2.39 + $(am__objects_15) $(am__objects_16) $(am__objects_17) \
2.40 + $(am__objects_18)
2.41 lxdream_OBJECTS = $(am_lxdream_OBJECTS)
2.42 lxdream_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
2.43 $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
2.44 @@ -455,6 +456,7 @@
2.45 PACKAGE_NAME = @PACKAGE_NAME@
2.46 PACKAGE_STRING = @PACKAGE_STRING@
2.47 PACKAGE_TARNAME = @PACKAGE_TARNAME@
2.48 +PACKAGE_URL = @PACKAGE_URL@
2.49 PACKAGE_VERSION = @PACKAGE_VERSION@
2.50 PATH_SEPARATOR = @PATH_SEPARATOR@
2.51 PKG_CONFIG = @PKG_CONFIG@
2.52 @@ -586,25 +588,25 @@
2.53 gdlist.c gdlist.h vmu/vmuvol.c vmu/vmuvol.h vmu/vmulist.c \
2.54 vmu/vmulist.h display.c display.h dckeysyms.h \
2.55 drivers/audio_null.c drivers/video_null.c drivers/video_gl.c \
2.56 - drivers/video_gl.h drivers/gl_fbo.c drivers/serial_unix.c \
2.57 - drivers/cdrom/cdrom.h drivers/cdrom/cdrom.c \
2.58 - drivers/cdrom/drive.h drivers/cdrom/sector.h \
2.59 - drivers/cdrom/sector.c drivers/cdrom/defs.h \
2.60 - drivers/cdrom/cd_nrg.c drivers/cdrom/cd_cdi.c \
2.61 - drivers/cdrom/cd_gdi.c drivers/cdrom/edc_ecc.c \
2.62 - drivers/cdrom/ecc.h drivers/cdrom/drive.c \
2.63 - drivers/cdrom/edc_crctable.h drivers/cdrom/edc_encoder.h \
2.64 - drivers/cdrom/edc_l2sq.h drivers/cdrom/edc_scramble.h \
2.65 - drivers/cdrom/cd_mmc.c drivers/cdrom/isofs.h \
2.66 - drivers/cdrom/isofs.c drivers/cdrom/isomem.c sh4/sh4.def \
2.67 - sh4/sh4core.in sh4/sh4x86.in sh4/sh4dasm.in sh4/sh4stat.in \
2.68 - hotkeys.c hotkeys.h $(am__append_1) $(am__append_2) \
2.69 - $(am__append_4) $(am__append_5) $(am__append_6) \
2.70 - $(am__append_7) $(am__append_8) $(am__append_9) \
2.71 - $(am__append_10) $(am__append_17) $(am__append_19) \
2.72 - $(am__append_21) $(am__append_23) $(am__append_25) \
2.73 - $(am__append_27) $(am__append_28) $(am__append_29) \
2.74 - $(am__append_30)
2.75 + drivers/video_gl.h drivers/gl_fbo.c drivers/gl_vbo.c \
2.76 + drivers/serial_unix.c drivers/cdrom/cdrom.h \
2.77 + drivers/cdrom/cdrom.c drivers/cdrom/drive.h \
2.78 + drivers/cdrom/sector.h drivers/cdrom/sector.c \
2.79 + drivers/cdrom/defs.h drivers/cdrom/cd_nrg.c \
2.80 + drivers/cdrom/cd_cdi.c drivers/cdrom/cd_gdi.c \
2.81 + drivers/cdrom/edc_ecc.c drivers/cdrom/ecc.h \
2.82 + drivers/cdrom/drive.c drivers/cdrom/edc_crctable.h \
2.83 + drivers/cdrom/edc_encoder.h drivers/cdrom/edc_l2sq.h \
2.84 + drivers/cdrom/edc_scramble.h drivers/cdrom/cd_mmc.c \
2.85 + drivers/cdrom/isofs.h drivers/cdrom/isofs.c \
2.86 + drivers/cdrom/isomem.c sh4/sh4.def sh4/sh4core.in \
2.87 + sh4/sh4x86.in sh4/sh4dasm.in sh4/sh4stat.in hotkeys.c \
2.88 + hotkeys.h $(am__append_1) $(am__append_2) $(am__append_4) \
2.89 + $(am__append_5) $(am__append_6) $(am__append_7) \
2.90 + $(am__append_8) $(am__append_9) $(am__append_10) \
2.91 + $(am__append_17) $(am__append_19) $(am__append_21) \
2.92 + $(am__append_23) $(am__append_25) $(am__append_27) \
2.93 + $(am__append_28) $(am__append_29) $(am__append_30)
2.94 lxdream_CPPFLAGS = @LXDREAMCPPFLAGS@
2.95 @BUILD_SH4X86_TRUE@test_testsh4x86_LDADD = @LXDREAM_LIBS@ @GLIB_LIBS@ @GTK_LIBS@ @LIBPNG_LIBS@
2.96 @BUILD_SH4X86_TRUE@test_testsh4x86_CPPFLAGS = @LXDREAMCPPFLAGS@
2.97 @@ -819,6 +821,7 @@
2.98 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-gdrom.Po@am__quote@
2.99 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-gl_fbo.Po@am__quote@
2.100 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-gl_sl.Po@am__quote@
2.101 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-gl_vbo.Po@am__quote@
2.102 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-glrender.Po@am__quote@
2.103 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-glutil.Po@am__quote@
2.104 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-gtk_cfg.Po@am__quote@
2.105 @@ -1932,6 +1935,20 @@
2.106 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
2.107 @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-gl_fbo.obj `if test -f 'drivers/gl_fbo.c'; then $(CYGPATH_W) 'drivers/gl_fbo.c'; else $(CYGPATH_W) '$(srcdir)/drivers/gl_fbo.c'; fi`
2.108
2.109 +lxdream-gl_vbo.o: drivers/gl_vbo.c
2.110 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-gl_vbo.o -MD -MP -MF "$(DEPDIR)/lxdream-gl_vbo.Tpo" -c -o lxdream-gl_vbo.o `test -f 'drivers/gl_vbo.c' || echo '$(srcdir)/'`drivers/gl_vbo.c; \
2.111 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lxdream-gl_vbo.Tpo" "$(DEPDIR)/lxdream-gl_vbo.Po"; else rm -f "$(DEPDIR)/lxdream-gl_vbo.Tpo"; exit 1; fi
2.112 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='drivers/gl_vbo.c' object='lxdream-gl_vbo.o' libtool=no @AMDEPBACKSLASH@
2.113 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
2.114 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-gl_vbo.o `test -f 'drivers/gl_vbo.c' || echo '$(srcdir)/'`drivers/gl_vbo.c
2.115 +
2.116 +lxdream-gl_vbo.obj: drivers/gl_vbo.c
2.117 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-gl_vbo.obj -MD -MP -MF "$(DEPDIR)/lxdream-gl_vbo.Tpo" -c -o lxdream-gl_vbo.obj `if test -f 'drivers/gl_vbo.c'; then $(CYGPATH_W) 'drivers/gl_vbo.c'; else $(CYGPATH_W) '$(srcdir)/drivers/gl_vbo.c'; fi`; \
2.118 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lxdream-gl_vbo.Tpo" "$(DEPDIR)/lxdream-gl_vbo.Po"; else rm -f "$(DEPDIR)/lxdream-gl_vbo.Tpo"; exit 1; fi
2.119 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='drivers/gl_vbo.c' object='lxdream-gl_vbo.obj' libtool=no @AMDEPBACKSLASH@
2.120 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
2.121 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-gl_vbo.obj `if test -f 'drivers/gl_vbo.c'; then $(CYGPATH_W) 'drivers/gl_vbo.c'; else $(CYGPATH_W) '$(srcdir)/drivers/gl_vbo.c'; fi`
2.122 +
2.123 lxdream-serial_unix.o: drivers/serial_unix.c
2.124 @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-serial_unix.o -MD -MP -MF "$(DEPDIR)/lxdream-serial_unix.Tpo" -c -o lxdream-serial_unix.o `test -f 'drivers/serial_unix.c' || echo '$(srcdir)/'`drivers/serial_unix.c; \
2.125 @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lxdream-serial_unix.Tpo" "$(DEPDIR)/lxdream-serial_unix.Po"; else rm -f "$(DEPDIR)/lxdream-serial_unix.Tpo"; exit 1; fi
3.1 --- a/src/display.h Wed Jan 19 12:51:19 2011 +1000
3.2 +++ b/src/display.h Wed Jan 19 17:50:09 2011 +1000
3.3 @@ -108,6 +108,43 @@
3.4 int stencil_bits; /* 0 = no stencil buffer */
3.5 };
3.6
3.7 +struct vertex_buffer {
3.8 + /**
3.9 + * Map the buffer into the host address space (if necessary) in preparation
3.10 + * for filling the buffer. This also implies a fence operation.
3.11 + * @param buf previously allocated buffer
3.12 + * @param size number of bytes of the buffer actually to be used. The buffer
3.13 + * will be resized if necessary.
3.14 + * @return a pointer to the start of the buffer.
3.15 + */
3.16 + void *(*map)(vertex_buffer_t buf, uint32_t size);
3.17 +
3.18 + /**
3.19 + * Unmap the buffer, after the vertex data is written.
3.20 + * @return the buffer base to use for gl*Pointer calls
3.21 + */
3.22 + void *(*unmap)(vertex_buffer_t buf);
3.23 +
3.24 + /**
3.25 + * Mark the buffer as finished, indicating that the vertex data is no
3.26 + * longer required (ie rendering is complete).
3.27 + */
3.28 + void (*finished)(vertex_buffer_t buf);
3.29 +
3.30 + /**
3.31 + * Delete the buffer and all associated resources.
3.32 + */
3.33 + void (*destroy)(vertex_buffer_t buf);
3.34 +
3.35 + /* Private data */
3.36 + void *data;
3.37 + GLuint id;
3.38 + uint32_t capacity;
3.39 + uint32_t mapped_size;
3.40 + GLuint fence;
3.41 +};
3.42 +
3.43 +
3.44 /**
3.45 * Core video driver - exports function to setup a GL context, as well as handle
3.46 * keyboard input and display resultant output.
3.47 @@ -213,11 +250,17 @@
3.48 int rowstride, int format );
3.49
3.50 /**
3.51 + * Create a new vertex buffer
3.52 + */
3.53 + vertex_buffer_t (*create_vertex_buffer)( );
3.54 +
3.55 + /**
3.56 * Dump driver-specific information about the implementation to the given stream
3.57 */
3.58 void (*print_info)( FILE *out );
3.59
3.60 struct display_capabilities capabilities;
3.61 +
3.62 } *display_driver_t;
3.63
3.64 /**
4.1 --- a/src/drivers/video_gl.h Wed Jan 19 12:51:19 2011 +1000
4.2 +++ b/src/drivers/video_gl.h Wed Jan 19 17:50:09 2011 +1000
4.3 @@ -70,6 +70,12 @@
4.4 void gl_fbo_init( display_driver_t driver );
4.5 void gl_fbo_detach();
4.6
4.7 +/** VBO/VAR handling (gl_vbo.c) ******/
4.8 +void gl_vbo_init( display_driver_t driver );
4.9 +
4.10 +/* Set the fallback vertex buffer handling, for drivers with no GL */
4.11 +void gl_vbo_fallback_init( display_driver_t driver );
4.12 +
4.13 #ifdef __cplusplus
4.14 }
4.15 #endif
5.1 --- a/src/drivers/video_glx.c Wed Jan 19 12:51:19 2011 +1000
5.2 +++ b/src/drivers/video_glx.c Wed Jan 19 17:50:09 2011 +1000
5.3 @@ -243,6 +243,7 @@
5.4 video_glx_shutdown();
5.5 return FALSE;
5.6 }
5.7 + gl_vbo_init(driver);
5.8 return TRUE;
5.9 }
5.10
6.1 --- a/src/drivers/video_nsgl.m Wed Jan 19 12:51:19 2011 +1000
6.2 +++ b/src/drivers/video_nsgl.m Wed Jan 19 17:50:09 2011 +1000
6.3 @@ -52,6 +52,7 @@
6.4 ERROR( "FBO not supported" );
6.5 return FALSE;
6.6 }
6.7 + gl_vbo_init(driver);
6.8
6.9 return TRUE;
6.10 }
7.1 --- a/src/drivers/video_null.c Wed Jan 19 12:51:19 2011 +1000
7.2 +++ b/src/drivers/video_null.c Wed Jan 19 17:50:09 2011 +1000
7.3 @@ -17,6 +17,9 @@
7.4 */
7.5
7.6 #include "display.h"
7.7 +#include "drivers/video_gl.h"
7.8 +
7.9 +static gboolean video_null_init( void );
7.10
7.11 static render_buffer_t video_null_create_render_buffer( uint32_t hres, uint32_t vres, GLuint tex_id )
7.12 {
7.13 @@ -63,7 +66,7 @@
7.14 struct display_driver display_null_driver = {
7.15 "null",
7.16 N_("Null (no video) driver"),
7.17 - NULL,
7.18 + video_null_init,
7.19 NULL,
7.20 NULL,
7.21 NULL,
7.22 @@ -78,3 +81,9 @@
7.23 video_null_swap_buffers,
7.24 video_null_read_render_buffer,
7.25 NULL };
7.26 +
7.27 +static gboolean video_null_init( void )
7.28 +{
7.29 + gl_vbo_fallback_init(&display_null_driver);
7.30 + return TRUE;
7.31 +}
8.1 --- a/src/lxdream.h Wed Jan 19 12:51:19 2011 +1000
8.2 +++ b/src/lxdream.h Wed Jan 19 17:50:09 2011 +1000
8.3 @@ -61,6 +61,7 @@
8.4
8.5 typedef struct render_buffer *render_buffer_t;
8.6 typedef struct frame_buffer *frame_buffer_t;
8.7 +typedef struct vertex_buffer *vertex_buffer_t;
8.8
8.9 /*************************** Logging ****************************/
8.10
9.1 --- a/src/pvr2/glrender.c Wed Jan 19 12:51:19 2011 +1000
9.2 +++ b/src/pvr2/glrender.c Wed Jan 19 17:50:09 2011 +1000
9.3 @@ -518,6 +518,8 @@
9.4 glDisable( GL_FOG );
9.5 glsl_clear_shader();
9.6
9.7 + pvr2_scene_finished();
9.8 +
9.9 gettimeofday( &end_tv, NULL );
9.10 ms = (end_tv.tv_sec - tex_tv.tv_sec) * 1000 +
9.11 (end_tv.tv_usec - tex_tv.tv_usec)/1000;
10.1 --- a/src/pvr2/glutil.c Wed Jan 19 12:51:19 2011 +1000
10.2 +++ b/src/pvr2/glutil.c Wed Jan 19 17:50:09 2011 +1000
10.3 @@ -187,7 +187,7 @@
10.4 } else {
10.5 WARN( "GL error: %x (%s)\n", err, s );
10.6 }
10.7 - return TRUE;
10.8 + return FALSE;
10.9 }
10.10 - return FALSE;
10.11 + return TRUE;
10.12 }
11.1 --- a/src/pvr2/glutil.h Wed Jan 19 12:51:19 2011 +1000
11.2 +++ b/src/pvr2/glutil.h Wed Jan 19 17:50:09 2011 +1000
11.3 @@ -42,7 +42,7 @@
11.4 /**
11.5 * Check for a GL error and print a message if there is one
11.6 * @param context If not null, a string to be printed along side an error message
11.7 - * @return TRUE if there was an error, otherwise FALSE
11.8 + * @return FALSE if there was an error, otherwise TRUE
11.9 */
11.10 gboolean gl_check_error( const char *context );
11.11 /**
12.1 --- a/src/pvr2/scene.c Wed Jan 19 12:51:19 2011 +1000
12.2 +++ b/src/pvr2/scene.c Wed Jan 19 17:50:09 2011 +1000
12.3 @@ -2,7 +2,6 @@
12.4 * $Id$
12.5 *
12.6 * Manage the internal vertex/polygon buffers and scene data structure.
12.7 - * Where possible this uses VBOs for the vertex + index data.
12.8 *
12.9 * Copyright (c) 2005 Nathan Keynes.
12.10 *
12.11 @@ -69,33 +68,33 @@
12.12 }
12.13
12.14 struct pvr2_scene_struct pvr2_scene;
12.15 +static float scene_shadow_intensity = 0.0;
12.16 +static vertex_buffer_t vbuf = NULL;
12.17
12.18 -static gboolean vbo_init = FALSE;
12.19 -static float scene_shadow_intensity = 0.0;
12.20 +static void vertex_buffer_map()
12.21 +{
12.22 + // Allow 8 vertexes for the background (4+4)
12.23 + uint32_t size = (pvr2_scene.vertex_count + 8) * sizeof(struct vertex_struct);
12.24 + pvr2_scene.vertex_array = vbuf->map(vbuf, size);
12.25 +}
12.26
12.27 -#ifdef ENABLE_VERTEX_BUFFER
12.28 -static gboolean vbo_supported = FALSE;
12.29 -#endif
12.30 +static void vertex_buffer_unmap()
12.31 +{
12.32 + pvr2_scene.vertex_array = vbuf->unmap(vbuf);
12.33 +}
12.34
12.35 /**
12.36 - * Test for VBO support, and allocate all the system memory needed for the
12.37 - * temporary structures. GL context must have been initialized before this
12.38 + * Allocate vertex buffer + temporary structures. GL context must have been initialized before this
12.39 * point.
12.40 */
12.41 void pvr2_scene_init()
12.42 {
12.43 - if( !vbo_init ) {
12.44 -#ifdef ENABLE_VERTEX_BUFFER
12.45 - if( isGLVertexBufferSupported() ) {
12.46 - vbo_supported = TRUE;
12.47 - pvr2_scene.vbo_id = 1;
12.48 - }
12.49 -#endif
12.50 + if( vbuf == NULL ) {
12.51 + vbuf = display_driver->create_vertex_buffer();
12.52 pvr2_scene.vertex_array = NULL;
12.53 pvr2_scene.vertex_array_size = 0;
12.54 pvr2_scene.poly_array = g_malloc( MAX_POLY_BUFFER_SIZE );
12.55 pvr2_scene.buf_to_poly_map = g_malloc0( BUF_POLY_MAP_SIZE );
12.56 - vbo_init = TRUE;
12.57 }
12.58 }
12.59
12.60 @@ -110,72 +109,16 @@
12.61 }
12.62 pvr2_scene.poly_count = 0;
12.63 pvr2_scene.vertex_count = 0;
12.64 -}
12.65 + }
12.66
12.67 void pvr2_scene_shutdown()
12.68 {
12.69 -#ifdef ENABLE_VERTEX_BUFFER
12.70 - if( vbo_supported ) {
12.71 - glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );
12.72 - glDeleteBuffersARB( 1, &pvr2_scene.vbo_id );
12.73 - pvr2_scene.vbo_id = 0;
12.74 - } else {
12.75 -#endif
12.76 - g_free( pvr2_scene.vertex_array );
12.77 - pvr2_scene.vertex_array = NULL;
12.78 -#ifdef ENABLE_VERTEX_BUFFER
12.79 - }
12.80 -#endif
12.81 -
12.82 + vbuf->destroy(vbuf);
12.83 + vbuf = NULL;
12.84 g_free( pvr2_scene.poly_array );
12.85 pvr2_scene.poly_array = NULL;
12.86 g_free( pvr2_scene.buf_to_poly_map );
12.87 pvr2_scene.buf_to_poly_map = NULL;
12.88 - vbo_init = FALSE;
12.89 -}
12.90 -
12.91 -void *vertex_buffer_map()
12.92 -{
12.93 - // Allow 8 vertexes for the background (4+4)
12.94 - uint32_t size = (pvr2_scene.vertex_count + 8) * sizeof(struct vertex_struct);
12.95 -#ifdef ENABLE_VERTEX_BUFFER
12.96 - if( vbo_supported ) {
12.97 - glGetError();
12.98 - glBindBufferARB( GL_ARRAY_BUFFER_ARB, pvr2_scene.vbo_id );
12.99 - if( size > pvr2_scene.vertex_array_size ) {
12.100 - glBufferDataARB( GL_ARRAY_BUFFER_ARB, size, NULL, GL_DYNAMIC_DRAW_ARB );
12.101 - int status = glGetError();
12.102 - if( status != 0 ) {
12.103 - fprintf( stderr, "Error %08X allocating vertex buffer\n", status );
12.104 - abort();
12.105 - }
12.106 - pvr2_scene.vertex_array_size = size;
12.107 - }
12.108 - pvr2_scene.vertex_array = glMapBufferARB( GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB );
12.109 - assert(pvr2_scene.vertex_array != NULL );
12.110 - } else {
12.111 -#endif
12.112 - if( size > pvr2_scene.vertex_array_size ) {
12.113 - pvr2_scene.vertex_array = g_realloc( pvr2_scene.vertex_array, size );
12.114 - }
12.115 -#ifdef ENABLE_VERTEX_BUFFER
12.116 - }
12.117 -#endif
12.118 - return pvr2_scene.vertex_array;
12.119 -}
12.120 -
12.121 -gboolean vertex_buffer_unmap()
12.122 -{
12.123 -#ifdef ENABLE_VERTEX_BUFFER
12.124 - if( vbo_supported ) {
12.125 - pvr2_scene.vertex_array = NULL;
12.126 - return glUnmapBufferARB( GL_ARRAY_BUFFER_ARB );
12.127 - } else {
12.128 - return TRUE;
12.129 - }
12.130 -#else
12.131 - return TRUE;
12.132 -#endif
12.133 }
12.134
12.135 static struct polygon_struct *scene_add_polygon( pvraddr_t poly_idx, int vertex_count,
12.136 @@ -252,7 +195,7 @@
12.137 * @param modify_offset Offset in 32-bit words to the tex/color data. 0 for
12.138 * the normal vertex, half the vertex length for the modified vertex.
12.139 */
12.140 -static void pvr2_decode_render_vertex( struct vertex_struct *vert, uint32_t poly1,
12.141 +static void scene_decode_vertex( struct vertex_struct *vert, uint32_t poly1,
12.142 uint32_t poly2, uint32_t tex, uint32_t *pvr2_data,
12.143 int modify_offset )
12.144 {
12.145 @@ -560,7 +503,7 @@
12.146 assert( poly != NULL );
12.147 assert( pvr2_scene.vertex_index + poly->vertex_count <= pvr2_scene.vertex_count );
12.148 for( i=0; i<poly->vertex_count; i++ ) {
12.149 - pvr2_decode_render_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[1], context[2], ptr, 0 );
12.150 + scene_decode_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[1], context[2], ptr, 0 );
12.151 ptr += vertex_length;
12.152 }
12.153 if( is_modified ) {
12.154 @@ -570,7 +513,7 @@
12.155 int mod_offset = (vertex_length - 3)>>1;
12.156 ptr = &pvr2_scene.pvr2_pbuf[poly_idx] + 5;
12.157 for( i=0; i<poly->vertex_count; i++ ) {
12.158 - pvr2_decode_render_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[3], context[4], ptr, mod_offset );
12.159 + scene_decode_vertex( &pvr2_scene.vertex_array[pvr2_scene.vertex_index++], context[0], context[3], context[4], ptr, mod_offset );
12.160 ptr += vertex_length;
12.161 }
12.162 } else {
12.163 @@ -601,7 +544,7 @@
12.164 ptr += (is_modified == SHADOW_FULL ? 5 : 3 );
12.165 poly->vertex_index = pvr2_scene.vertex_index;
12.166 for( i=0; i<4; i++ ) {
12.167 - pvr2_decode_render_vertex( &quad[i], context[0], context[1], context[2], ptr, 0 );
12.168 + scene_decode_vertex( &quad[i], context[0], context[1], context[2], ptr, 0 );
12.169 ptr += vertex_length;
12.170 }
12.171 scene_compute_vertexes( &quad[3], 1, &quad[0], !POLY1_GOURAUD_SHADED(context[0]) );
12.172 @@ -618,7 +561,7 @@
12.173 int mod_offset = (vertex_length - 3)>>1;
12.174 ptr = &pvr2_scene.pvr2_pbuf[poly_idx] + 5;
12.175 for( i=0; i<4; i++ ) {
12.176 - pvr2_decode_render_vertex( &quad[4], context[0], context[3], context[4], ptr, mod_offset );
12.177 + scene_decode_vertex( &quad[4], context[0], context[3], context[4], ptr, mod_offset );
12.178 ptr += vertex_length;
12.179 }
12.180 scene_compute_vertexes( &quad[3], 1, &quad[0], !POLY1_GOURAUD_SHADED(context[0]) );
12.181 @@ -788,7 +731,7 @@
12.182 struct vertex_struct base_vertexes[3];
12.183 uint32_t *ptr = context + context_length;
12.184 for( i=0; i<3; i++ ) {
12.185 - pvr2_decode_render_vertex( &base_vertexes[i], context[0], context[1], context[2],
12.186 + scene_decode_vertex( &base_vertexes[i], context[0], context[1], context[2],
12.187 ptr, 0 );
12.188 ptr += vertex_length;
12.189 }
12.190 @@ -803,7 +746,7 @@
12.191 int mod_offset = (vertex_length - 3)>>1;
12.192 ptr = context + context_length;
12.193 for( i=0; i<3; i++ ) {
12.194 - pvr2_decode_render_vertex( &base_vertexes[i], context[0], context[3], context[4],
12.195 + scene_decode_vertex( &base_vertexes[i], context[0], context[3], context[4],
12.196 ptr, mod_offset );
12.197 ptr += vertex_length;
12.198 }
12.199 @@ -937,6 +880,11 @@
12.200 vertex_buffer_unmap();
12.201 }
12.202
12.203 +void pvr2_scene_finished( )
12.204 +{
12.205 + vbuf->finished(vbuf);
12.206 +}
12.207 +
12.208 /**
12.209 * Dump the current scene to file in a (mostly) human readable form
12.210 */
13.1 --- a/src/pvr2/scene.h Wed Jan 19 12:51:19 2011 +1000
13.2 +++ b/src/pvr2/scene.h Wed Jan 19 17:50:09 2011 +1000
13.3 @@ -36,7 +36,7 @@
13.4
13.5 struct vertex_struct {
13.6 float u,v,r,tex_mode; /* tex-coord quad */
13.7 - float x,y,z;
13.8 + float x,y,z,w;
13.9 float rgba[4];
13.10 float offset_rgba[4];
13.11 };
13.12 @@ -54,6 +54,7 @@
13.13
13.14 void pvr2_scene_init(void);
13.15 void pvr2_scene_read(void);
13.16 +void pvr2_scene_finished(void);
13.17 void pvr2_scene_shutdown();
13.18
13.19 uint32_t pvr2_scene_buffer_width();
13.20 @@ -72,6 +73,7 @@
13.21 */
13.22 #define MAX_VERTEXES 262144
13.23 #define MAX_VERTEX_BUFFER_SIZE (MAX_VERTEXES*sizeof(struct vertex_struct))
13.24 +#define MIN_VERTEX_BUFFER_SIZE (2024*1024)
13.25
13.26 /**
13.27 * Maximum polygons - smallest is 1 polygon in 48 bytes, giving
.