Search
lxdream.org :: lxdream :: r1130:5f56fc931112
lxdream 0.9.1
released Jun 29
Download Now
changeset1130:5f56fc931112
parent1129:7b16bbd6209c
child1131:4727c2006e0f
authornkeynes
dateFri Sep 17 20:08:50 2010 +1000 (9 years ago)
Refactor shader management to support multiple programs, which are all
defined in the shaders.glsl, rather than split up into one file per
fragment.
src/Makefile.am
src/Makefile.in
src/pvr2/fragment.glsl
src/pvr2/gl_sl.c
src/pvr2/glrender.c
src/pvr2/glutil.h
src/pvr2/shaders.glsl
src/pvr2/vertex.glsl
src/tools/genglsl.c
1.1 --- a/src/Makefile.am Fri Sep 17 20:05:34 2010 +1000
1.2 +++ b/src/Makefile.am Fri Sep 17 20:08:50 2010 +1000
1.3 @@ -27,9 +27,9 @@
1.4
1.5 TESTS = test/testxlt
1.6 BUILT_SOURCES = sh4/sh4core.c sh4/sh4dasm.c sh4/sh4x86.c sh4/sh4stat.c \
1.7 - pvr2/gl_slsrc.c drivers/mac_keymap.h version.c
1.8 + pvr2/shaders.def pvr2/shaders.h drivers/mac_keymap.h version.c
1.9 CLEANFILES = sh4/sh4core.c sh4/sh4dasm.c sh4/sh4x86.c sh4/sh4stat.c \
1.10 - pvr2/gl_slsrc.c drivers/mac_keymap.h version.c \
1.11 + pvr2/shaders.def pvr2/shaders.h drivers/mac_keymap.h version.c \
1.12 audio_alsa.lo audio_sdl.lo audio_esd.lo audio_pulse.lo input_lirc.lo \
1.13 lxdream_dummy.lo
1.14
1.15 @@ -58,7 +58,7 @@
1.16 pvr2/pvr2.c pvr2/pvr2.h pvr2/pvr2mem.c pvr2/pvr2mmio.h \
1.17 pvr2/tacore.c pvr2/rendsort.c \
1.18 pvr2/texcache.c pvr2/yuv.c pvr2/rendsave.c pvr2/scene.c pvr2/scene.h \
1.19 - pvr2/gl_sl.c pvr2/gl_slsrc.c pvr2/glutil.c pvr2/glutil.h pvr2/glrender.c \
1.20 + pvr2/gl_sl.c pvr2/shaders.h pvr2/shaders.def pvr2/glutil.c pvr2/glutil.h pvr2/glrender.c \
1.21 pvr2/vertex.glsl pvr2/fragment.glsl \
1.22 maple/maple.c maple/maple.h \
1.23 maple/controller.c maple/kbd.c maple/mouse.c maple/lightgun.c maple/vmu.c \
1.24 @@ -254,9 +254,10 @@
1.25 sh4/sh4stat.c: gendec sh4/sh4.def sh4/sh4stat.in
1.26 $(mkdir_p) `dirname $@`
1.27 ./gendec $(srcdir)/sh4/sh4.def $(srcdir)/sh4/sh4stat.in -o $@
1.28 -pvr2/gl_slsrc.c: genglsl pvr2/vertex.glsl pvr2/fragment.glsl
1.29 +pvr2/shaders.def: genglsl pvr2/shaders.glsl
1.30 $(mkdir_p) `dirname $@`
1.31 - ./genglsl $(srcdir)/pvr2/vertex.glsl $(srcdir)/pvr2/fragment.glsl $@
1.32 + ./genglsl $(srcdir)/pvr2/shaders.glsl $@
1.33 +pvr2/shaders.h: pvr2/shaders.def
1.34 drivers/mac_keymap.h: drivers/mac_keymap.txt drivers/genkeymap.pl
1.35 $(mkdir_p) `dirname $@`
1.36 $(srcdir)/drivers/genkeymap.pl mac $(srcdir)/drivers/mac_keymap.txt > $@
2.1 --- a/src/Makefile.in Fri Sep 17 20:05:34 2010 +1000
2.2 +++ b/src/Makefile.in Fri Sep 17 20:08:50 2010 +1000
2.3 @@ -157,45 +157,46 @@
2.4 aica/aica.c aica/aica.h aica/audio.c aica/audio.h pvr2/pvr2.c \
2.5 pvr2/pvr2.h pvr2/pvr2mem.c pvr2/pvr2mmio.h pvr2/tacore.c \
2.6 pvr2/rendsort.c pvr2/texcache.c pvr2/yuv.c pvr2/rendsave.c \
2.7 - pvr2/scene.c pvr2/scene.h pvr2/gl_sl.c pvr2/gl_slsrc.c \
2.8 - pvr2/glutil.c pvr2/glutil.h pvr2/glrender.c pvr2/vertex.glsl \
2.9 - pvr2/fragment.glsl maple/maple.c maple/maple.h \
2.10 - maple/controller.c maple/kbd.c maple/mouse.c maple/lightgun.c \
2.11 - maple/vmu.c loader.c loader.h elf.h bootstrap.c bootstrap.h \
2.12 - util.c gdlist.c gdlist.h vmu/vmuvol.c vmu/vmuvol.h \
2.13 - vmu/vmulist.c vmu/vmulist.h display.c display.h dckeysyms.h \
2.14 - drivers/audio_null.c drivers/video_null.c drivers/video_gl.c \
2.15 - drivers/video_gl.h drivers/gl_fbo.c drivers/serial_unix.c \
2.16 - drivers/cdrom/cdrom.h drivers/cdrom/cdrom.c \
2.17 - drivers/cdrom/drive.h drivers/cdrom/sector.h \
2.18 - drivers/cdrom/sector.c drivers/cdrom/defs.h \
2.19 - drivers/cdrom/cd_nrg.c drivers/cdrom/cd_cdi.c \
2.20 - drivers/cdrom/cd_gdi.c drivers/cdrom/edc_ecc.c \
2.21 - drivers/cdrom/ecc.h drivers/cdrom/drive.c \
2.22 - drivers/cdrom/edc_crctable.h drivers/cdrom/edc_encoder.h \
2.23 - drivers/cdrom/edc_l2sq.h drivers/cdrom/edc_scramble.h \
2.24 - drivers/cdrom/cd_mmc.c drivers/cdrom/isofs.h \
2.25 - drivers/cdrom/isofs.c sh4/sh4.def sh4/sh4core.in sh4/sh4x86.in \
2.26 - sh4/sh4dasm.in sh4/sh4stat.in hotkeys.c hotkeys.h plugin.c \
2.27 - plugin.h sh4/sh4x86.c xlat/x86/x86op.h xlat/x86/ia32abi.h \
2.28 - xlat/x86/amd64abi.h sh4/sh4trans.c sh4/sh4trans.h sh4/mmux86.c \
2.29 - x86dasm/x86dasm.c x86dasm/x86dasm.h x86dasm/i386-dis.c \
2.30 - x86dasm/dis-init.c x86dasm/dis-buf.c x86dasm/ansidecl.h \
2.31 - x86dasm/bfd.h x86dasm/dis-asm.h x86dasm/symcat.h \
2.32 - x86dasm/sysdep.h gtkui/gtkui.c gtkui/gtkui.h gtkui/gtk_win.c \
2.33 - gtkui/gtkcb.c gtkui/gtk_cfg.c gtkui/gtk_mmio.c \
2.34 - gtkui/gtk_debug.c gtkui/gtk_dump.c gtkui/gtk_ctrl.c \
2.35 - gtkui/gtk_gd.c drivers/io_glib.c drivers/video_gtk.c \
2.36 - cocoaui/cocoaui.m cocoaui/cocoaui.h cocoaui/cocoa_cfg.m \
2.37 - cocoaui/cocoa_win.m cocoaui/cocoa_gd.m cocoaui/cocoa_prefs.m \
2.38 - cocoaui/cocoa_ctrl.m cocoaui/paths_osx.m drivers/io_osx.m \
2.39 - drivers/video_osx.m drivers/mac_keymap.h \
2.40 - drivers/mac_keymap.txt paths_unix.c drivers/video_gdk.c \
2.41 - drivers/video_glx.c drivers/video_glx.h drivers/video_nsgl.m \
2.42 - drivers/video_nsgl.h drivers/audio_osx.m drivers/audio_sdl.c \
2.43 - drivers/audio_pulse.c drivers/audio_esd.c drivers/audio_alsa.c \
2.44 - drivers/input_lirc.c drivers/cdrom/cd_linux.c \
2.45 - drivers/cdrom/cd_osx.c drivers/osx_iokit.m drivers/osx_iokit.h \
2.46 + pvr2/scene.c pvr2/scene.h pvr2/gl_sl.c pvr2/shaders.h \
2.47 + pvr2/shaders.def pvr2/glutil.c pvr2/glutil.h pvr2/glrender.c \
2.48 + pvr2/vertex.glsl pvr2/fragment.glsl maple/maple.c \
2.49 + maple/maple.h maple/controller.c maple/kbd.c maple/mouse.c \
2.50 + maple/lightgun.c maple/vmu.c loader.c loader.h elf.h \
2.51 + bootstrap.c bootstrap.h util.c gdlist.c gdlist.h vmu/vmuvol.c \
2.52 + vmu/vmuvol.h vmu/vmulist.c vmu/vmulist.h display.c display.h \
2.53 + dckeysyms.h drivers/audio_null.c drivers/video_null.c \
2.54 + drivers/video_gl.c drivers/video_gl.h drivers/gl_fbo.c \
2.55 + drivers/serial_unix.c drivers/cdrom/cdrom.h \
2.56 + drivers/cdrom/cdrom.c drivers/cdrom/drive.h \
2.57 + drivers/cdrom/sector.h drivers/cdrom/sector.c \
2.58 + drivers/cdrom/defs.h drivers/cdrom/cd_nrg.c \
2.59 + drivers/cdrom/cd_cdi.c drivers/cdrom/cd_gdi.c \
2.60 + drivers/cdrom/edc_ecc.c drivers/cdrom/ecc.h \
2.61 + drivers/cdrom/drive.c drivers/cdrom/edc_crctable.h \
2.62 + drivers/cdrom/edc_encoder.h drivers/cdrom/edc_l2sq.h \
2.63 + drivers/cdrom/edc_scramble.h drivers/cdrom/cd_mmc.c \
2.64 + drivers/cdrom/isofs.h drivers/cdrom/isofs.c sh4/sh4.def \
2.65 + sh4/sh4core.in sh4/sh4x86.in sh4/sh4dasm.in sh4/sh4stat.in \
2.66 + hotkeys.c hotkeys.h plugin.c plugin.h sh4/sh4x86.c \
2.67 + xlat/x86/x86op.h xlat/x86/ia32abi.h xlat/x86/amd64abi.h \
2.68 + sh4/sh4trans.c sh4/sh4trans.h sh4/mmux86.c x86dasm/x86dasm.c \
2.69 + x86dasm/x86dasm.h x86dasm/i386-dis.c x86dasm/dis-init.c \
2.70 + x86dasm/dis-buf.c x86dasm/ansidecl.h x86dasm/bfd.h \
2.71 + x86dasm/dis-asm.h x86dasm/symcat.h x86dasm/sysdep.h \
2.72 + gtkui/gtkui.c gtkui/gtkui.h gtkui/gtk_win.c gtkui/gtkcb.c \
2.73 + gtkui/gtk_cfg.c gtkui/gtk_mmio.c gtkui/gtk_debug.c \
2.74 + gtkui/gtk_dump.c gtkui/gtk_ctrl.c gtkui/gtk_gd.c \
2.75 + drivers/io_glib.c drivers/video_gtk.c cocoaui/cocoaui.m \
2.76 + cocoaui/cocoaui.h cocoaui/cocoa_cfg.m cocoaui/cocoa_win.m \
2.77 + cocoaui/cocoa_gd.m cocoaui/cocoa_prefs.m cocoaui/cocoa_ctrl.m \
2.78 + cocoaui/paths_osx.m drivers/io_osx.m drivers/video_osx.m \
2.79 + drivers/mac_keymap.h drivers/mac_keymap.txt paths_unix.c \
2.80 + drivers/video_gdk.c drivers/video_glx.c drivers/video_glx.h \
2.81 + drivers/video_nsgl.m drivers/video_nsgl.h drivers/audio_osx.m \
2.82 + drivers/audio_sdl.c drivers/audio_pulse.c drivers/audio_esd.c \
2.83 + drivers/audio_alsa.c drivers/input_lirc.c \
2.84 + drivers/cdrom/cd_linux.c drivers/cdrom/cd_osx.c \
2.85 + drivers/osx_iokit.m drivers/osx_iokit.h \
2.86 drivers/cdrom/cd_none.c drivers/joy_linux.c \
2.87 drivers/joy_linux.h
2.88 @BUILD_SHARED_TRUE@am__objects_1 = lxdream-plugin.$(OBJEXT)
2.89 @@ -264,28 +265,28 @@
2.90 lxdream-tacore.$(OBJEXT) lxdream-rendsort.$(OBJEXT) \
2.91 lxdream-texcache.$(OBJEXT) lxdream-yuv.$(OBJEXT) \
2.92 lxdream-rendsave.$(OBJEXT) lxdream-scene.$(OBJEXT) \
2.93 - lxdream-gl_sl.$(OBJEXT) lxdream-gl_slsrc.$(OBJEXT) \
2.94 - lxdream-glutil.$(OBJEXT) lxdream-glrender.$(OBJEXT) \
2.95 - lxdream-maple.$(OBJEXT) lxdream-controller.$(OBJEXT) \
2.96 - lxdream-kbd.$(OBJEXT) lxdream-mouse.$(OBJEXT) \
2.97 - lxdream-lightgun.$(OBJEXT) lxdream-vmu.$(OBJEXT) \
2.98 - lxdream-loader.$(OBJEXT) lxdream-bootstrap.$(OBJEXT) \
2.99 - lxdream-util.$(OBJEXT) lxdream-gdlist.$(OBJEXT) \
2.100 - lxdream-vmuvol.$(OBJEXT) lxdream-vmulist.$(OBJEXT) \
2.101 - lxdream-display.$(OBJEXT) lxdream-audio_null.$(OBJEXT) \
2.102 - lxdream-video_null.$(OBJEXT) lxdream-video_gl.$(OBJEXT) \
2.103 - lxdream-gl_fbo.$(OBJEXT) lxdream-serial_unix.$(OBJEXT) \
2.104 - lxdream-cdrom.$(OBJEXT) lxdream-sector.$(OBJEXT) \
2.105 - lxdream-cd_nrg.$(OBJEXT) lxdream-cd_cdi.$(OBJEXT) \
2.106 - lxdream-cd_gdi.$(OBJEXT) lxdream-edc_ecc.$(OBJEXT) \
2.107 - lxdream-drive.$(OBJEXT) lxdream-cd_mmc.$(OBJEXT) \
2.108 - lxdream-isofs.$(OBJEXT) lxdream-hotkeys.$(OBJEXT) \
2.109 - $(am__objects_1) $(am__objects_2) $(am__objects_3) \
2.110 - $(am__objects_4) $(am__objects_5) $(am__objects_6) \
2.111 - $(am__objects_7) $(am__objects_8) $(am__objects_9) \
2.112 - $(am__objects_10) $(am__objects_11) $(am__objects_12) \
2.113 - $(am__objects_13) $(am__objects_14) $(am__objects_15) \
2.114 - $(am__objects_16) $(am__objects_17) $(am__objects_18)
2.115 + lxdream-gl_sl.$(OBJEXT) lxdream-glutil.$(OBJEXT) \
2.116 + lxdream-glrender.$(OBJEXT) lxdream-maple.$(OBJEXT) \
2.117 + lxdream-controller.$(OBJEXT) lxdream-kbd.$(OBJEXT) \
2.118 + lxdream-mouse.$(OBJEXT) lxdream-lightgun.$(OBJEXT) \
2.119 + lxdream-vmu.$(OBJEXT) lxdream-loader.$(OBJEXT) \
2.120 + lxdream-bootstrap.$(OBJEXT) lxdream-util.$(OBJEXT) \
2.121 + lxdream-gdlist.$(OBJEXT) lxdream-vmuvol.$(OBJEXT) \
2.122 + lxdream-vmulist.$(OBJEXT) lxdream-display.$(OBJEXT) \
2.123 + lxdream-audio_null.$(OBJEXT) lxdream-video_null.$(OBJEXT) \
2.124 + lxdream-video_gl.$(OBJEXT) lxdream-gl_fbo.$(OBJEXT) \
2.125 + lxdream-serial_unix.$(OBJEXT) lxdream-cdrom.$(OBJEXT) \
2.126 + lxdream-sector.$(OBJEXT) lxdream-cd_nrg.$(OBJEXT) \
2.127 + lxdream-cd_cdi.$(OBJEXT) lxdream-cd_gdi.$(OBJEXT) \
2.128 + lxdream-edc_ecc.$(OBJEXT) lxdream-drive.$(OBJEXT) \
2.129 + lxdream-cd_mmc.$(OBJEXT) lxdream-isofs.$(OBJEXT) \
2.130 + lxdream-hotkeys.$(OBJEXT) $(am__objects_1) $(am__objects_2) \
2.131 + $(am__objects_3) $(am__objects_4) $(am__objects_5) \
2.132 + $(am__objects_6) $(am__objects_7) $(am__objects_8) \
2.133 + $(am__objects_9) $(am__objects_10) $(am__objects_11) \
2.134 + $(am__objects_12) $(am__objects_13) $(am__objects_14) \
2.135 + $(am__objects_15) $(am__objects_16) $(am__objects_17) \
2.136 + $(am__objects_18)
2.137 lxdream_OBJECTS = $(am_lxdream_OBJECTS)
2.138 lxdream_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
2.139 $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
2.140 @@ -544,10 +545,10 @@
2.141 AM_CFLAGS = -D__EXTENSIONS__ -D_BSD_SOURCE -D_GNU_SOURCE
2.142 TESTS = test/testxlt
2.143 BUILT_SOURCES = sh4/sh4core.c sh4/sh4dasm.c sh4/sh4x86.c sh4/sh4stat.c \
2.144 - pvr2/gl_slsrc.c drivers/mac_keymap.h version.c
2.145 + pvr2/shaders.def pvr2/shaders.h drivers/mac_keymap.h version.c
2.146
2.147 CLEANFILES = sh4/sh4core.c sh4/sh4dasm.c sh4/sh4x86.c sh4/sh4stat.c \
2.148 - pvr2/gl_slsrc.c drivers/mac_keymap.h version.c \
2.149 + pvr2/shaders.def pvr2/shaders.h drivers/mac_keymap.h version.c \
2.150 audio_alsa.lo audio_sdl.lo audio_esd.lo audio_pulse.lo input_lirc.lo \
2.151 lxdream_dummy.lo
2.152
2.153 @@ -576,8 +577,8 @@
2.154 aica/audio.c aica/audio.h pvr2/pvr2.c pvr2/pvr2.h \
2.155 pvr2/pvr2mem.c pvr2/pvr2mmio.h pvr2/tacore.c pvr2/rendsort.c \
2.156 pvr2/texcache.c pvr2/yuv.c pvr2/rendsave.c pvr2/scene.c \
2.157 - pvr2/scene.h pvr2/gl_sl.c pvr2/gl_slsrc.c pvr2/glutil.c \
2.158 - pvr2/glutil.h pvr2/glrender.c pvr2/vertex.glsl \
2.159 + pvr2/scene.h pvr2/gl_sl.c pvr2/shaders.h pvr2/shaders.def \
2.160 + pvr2/glutil.c pvr2/glutil.h pvr2/glrender.c pvr2/vertex.glsl \
2.161 pvr2/fragment.glsl maple/maple.c maple/maple.h \
2.162 maple/controller.c maple/kbd.c maple/mouse.c maple/lightgun.c \
2.163 maple/vmu.c loader.c loader.h elf.h bootstrap.c bootstrap.h \
2.164 @@ -816,7 +817,6 @@
2.165 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-gdrom.Po@am__quote@
2.166 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-gl_fbo.Po@am__quote@
2.167 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-gl_sl.Po@am__quote@
2.168 -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-gl_slsrc.Po@am__quote@
2.169 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-glrender.Po@am__quote@
2.170 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-glutil.Po@am__quote@
2.171 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lxdream-gtk_cfg.Po@am__quote@
2.172 @@ -1663,20 +1663,6 @@
2.173 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
2.174 @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-gl_sl.obj `if test -f 'pvr2/gl_sl.c'; then $(CYGPATH_W) 'pvr2/gl_sl.c'; else $(CYGPATH_W) '$(srcdir)/pvr2/gl_sl.c'; fi`
2.175
2.176 -lxdream-gl_slsrc.o: pvr2/gl_slsrc.c
2.177 -@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-gl_slsrc.o -MD -MP -MF "$(DEPDIR)/lxdream-gl_slsrc.Tpo" -c -o lxdream-gl_slsrc.o `test -f 'pvr2/gl_slsrc.c' || echo '$(srcdir)/'`pvr2/gl_slsrc.c; \
2.178 -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lxdream-gl_slsrc.Tpo" "$(DEPDIR)/lxdream-gl_slsrc.Po"; else rm -f "$(DEPDIR)/lxdream-gl_slsrc.Tpo"; exit 1; fi
2.179 -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pvr2/gl_slsrc.c' object='lxdream-gl_slsrc.o' libtool=no @AMDEPBACKSLASH@
2.180 -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
2.181 -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-gl_slsrc.o `test -f 'pvr2/gl_slsrc.c' || echo '$(srcdir)/'`pvr2/gl_slsrc.c
2.182 -
2.183 -lxdream-gl_slsrc.obj: pvr2/gl_slsrc.c
2.184 -@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-gl_slsrc.obj -MD -MP -MF "$(DEPDIR)/lxdream-gl_slsrc.Tpo" -c -o lxdream-gl_slsrc.obj `if test -f 'pvr2/gl_slsrc.c'; then $(CYGPATH_W) 'pvr2/gl_slsrc.c'; else $(CYGPATH_W) '$(srcdir)/pvr2/gl_slsrc.c'; fi`; \
2.185 -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lxdream-gl_slsrc.Tpo" "$(DEPDIR)/lxdream-gl_slsrc.Po"; else rm -f "$(DEPDIR)/lxdream-gl_slsrc.Tpo"; exit 1; fi
2.186 -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pvr2/gl_slsrc.c' object='lxdream-gl_slsrc.obj' libtool=no @AMDEPBACKSLASH@
2.187 -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
2.188 -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o lxdream-gl_slsrc.obj `if test -f 'pvr2/gl_slsrc.c'; then $(CYGPATH_W) 'pvr2/gl_slsrc.c'; else $(CYGPATH_W) '$(srcdir)/pvr2/gl_slsrc.c'; fi`
2.189 -
2.190 lxdream-glutil.o: pvr2/glutil.c
2.191 @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(lxdream_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lxdream-glutil.o -MD -MP -MF "$(DEPDIR)/lxdream-glutil.Tpo" -c -o lxdream-glutil.o `test -f 'pvr2/glutil.c' || echo '$(srcdir)/'`pvr2/glutil.c; \
2.192 @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lxdream-glutil.Tpo" "$(DEPDIR)/lxdream-glutil.Po"; else rm -f "$(DEPDIR)/lxdream-glutil.Tpo"; exit 1; fi
2.193 @@ -3193,9 +3179,10 @@
2.194 sh4/sh4stat.c: gendec sh4/sh4.def sh4/sh4stat.in
2.195 $(mkdir_p) `dirname $@`
2.196 ./gendec $(srcdir)/sh4/sh4.def $(srcdir)/sh4/sh4stat.in -o $@
2.197 -pvr2/gl_slsrc.c: genglsl pvr2/vertex.glsl pvr2/fragment.glsl
2.198 +pvr2/shaders.def: genglsl pvr2/shaders.glsl
2.199 $(mkdir_p) `dirname $@`
2.200 - ./genglsl $(srcdir)/pvr2/vertex.glsl $(srcdir)/pvr2/fragment.glsl $@
2.201 + ./genglsl $(srcdir)/pvr2/shaders.glsl $@
2.202 +pvr2/shaders.h: pvr2/shaders.def
2.203 drivers/mac_keymap.h: drivers/mac_keymap.txt drivers/genkeymap.pl
2.204 $(mkdir_p) `dirname $@`
2.205 $(srcdir)/drivers/genkeymap.pl mac $(srcdir)/drivers/mac_keymap.txt > $@
3.1 --- a/src/pvr2/fragment.glsl Fri Sep 17 20:05:34 2010 +1000
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,7 +0,0 @@
3.4 -// Standard PVR2 fragment shader
3.5 -
3.6 -void main()
3.7 -{
3.8 - gl_FragColor = gl_Color;
3.9 - gl_FragDepth = gl_FragCoord.z;
3.10 -}
3.11 \ No newline at end of file
4.1 --- a/src/pvr2/gl_sl.c Fri Sep 17 20:05:34 2010 +1000
4.2 +++ b/src/pvr2/gl_sl.c Fri Sep 17 20:08:50 2010 +1000
4.3 @@ -1,11 +1,9 @@
4.4 /**
4.5 * $Id$
4.6 *
4.7 - * GLSL shader loader/unloader. Current version assumes there's exactly
4.8 - * 1 shader program that's used globally. This may turn out not to be the
4.9 - * most efficient approach.
4.10 - *
4.11 - * Copyright (c) 2007 Nathan Keynes.
4.12 + * GLSL wrapper code to hide the differences between the different gl/sl APIs.
4.13 + *
4.14 + * Copyright (c) 2007-2010 Nathan Keynes.
4.15 *
4.16 * This program is free software; you can redistribute it and/or modify
4.17 * it under the terms of the GNU General Public License as published by
4.18 @@ -18,11 +16,33 @@
4.19 * GNU General Public License for more details.
4.20 */
4.21
4.22 +#include <assert.h>
4.23 +
4.24 #include "lxdream.h"
4.25 #include "display.h"
4.26 #include "pvr2/glutil.h"
4.27
4.28 #define MAX_ERROR_BUF 4096
4.29 +#define INVALID_SHADER 0
4.30 +#define INVALID_PROGRAM 0
4.31 +
4.32 +#ifdef HAVE_OPENGL_SHADER_ARB
4.33 +typedef GLhandleARB gl_program_t;
4.34 +typedef GLhandleARB gl_shader_t;
4.35 +#else
4.36 +typedef GLuint gl_program_t;
4.37 +typedef GLuint gl_shader_t;
4.38 +#endif
4.39 +
4.40 +gboolean glsl_is_supported();
4.41 +gl_shader_t glsl_create_vertex_shader( const char *source );
4.42 +gl_shader_t glsl_create_fragment_shader( const char *source );
4.43 +gl_program_t glsl_create_program( gl_shader_t *shaderv );
4.44 +void glsl_use_program(gl_program_t program);
4.45 +void glsl_destroy_shader(gl_shader_t shader);
4.46 +void glsl_destroy_program(gl_program_t program);
4.47 +
4.48 +#ifdef HAVE_OPENGL_SHADER_ARB
4.49
4.50 gboolean glsl_is_supported()
4.51 {
4.52 @@ -31,9 +51,6 @@
4.53 isGLExtensionSupported("GL_ARB_shading_language_100");
4.54 }
4.55
4.56 -#ifdef HAVE_OPENGL_SHADER_ARB
4.57 -static GLhandleARB glsl_program = 0, glsl_vert_shader = 0, glsl_frag_shader = 0;
4.58 -
4.59 void glsl_print_error( char *msg, GLhandleARB obj )
4.60 {
4.61 char buf[MAX_ERROR_BUF];
4.62 @@ -62,73 +79,82 @@
4.63 return TRUE;
4.64 }
4.65
4.66 +gl_shader_t glsl_create_vertex_shader( const char *source )
4.67 +{
4.68 + gboolean ok;
4.69 + gl_shader_t shader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
4.70
4.71 -gboolean glsl_load_shaders( const char *vertex_src, const char *fragment_src )
4.72 -{
4.73 - gboolean vsok = TRUE, fsok = TRUE, pok = FALSE;
4.74 -
4.75 - if( vertex_src == NULL && fragment_src == NULL ) {
4.76 - return TRUE; // nothing to do
4.77 - }
4.78 -
4.79 - glsl_program = glCreateProgramObjectARB();
4.80 -
4.81 - if( vertex_src != NULL ) {
4.82 - glsl_vert_shader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
4.83 - glShaderSourceARB( glsl_vert_shader, 1, &vertex_src, NULL );
4.84 - glCompileShaderARB(glsl_vert_shader);
4.85 - vsok = glsl_check_shader_error("Failed to compile vertex shader", glsl_vert_shader);
4.86 - }
4.87 - if( fragment_src != NULL ) {
4.88 - glsl_frag_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
4.89 - glShaderSourceARB( glsl_frag_shader, 1, &fragment_src, NULL );
4.90 - glCompileShaderARB(glsl_frag_shader);
4.91 - fsok = glsl_check_shader_error("Failed to compile fragment shader", glsl_frag_shader);
4.92 - }
4.93 -
4.94 - if( vsok && fsok ) {
4.95 - if( vertex_src != NULL ) {
4.96 - glAttachObjectARB(glsl_program, glsl_vert_shader);
4.97 - }
4.98 - if( fragment_src != NULL ) {
4.99 - glAttachObjectARB(glsl_program, glsl_frag_shader);
4.100 - }
4.101 - glLinkProgramARB(glsl_program);
4.102 - pok = glsl_check_program_error( "Failed to link shader program", glsl_program );
4.103 - }
4.104 - if( pok ) {
4.105 - glUseProgramObjectARB(glsl_program);
4.106 - pok = glsl_check_program_error( "Failed to apply shader program", glsl_program );
4.107 - glsl_enable_shaders(FALSE); // initially disabled
4.108 + glShaderSourceARB( shader, 1, &source, NULL );
4.109 + glCompileShaderARB(shader);
4.110 + ok = glsl_check_shader_error("Failed to compile vertex shader", shader);
4.111 + if( !ok ) {
4.112 + glDeleteObjectARB(shader);
4.113 + return INVALID_SHADER;
4.114 } else {
4.115 - glsl_unload_shaders();
4.116 - }
4.117 - return pok;
4.118 -}
4.119 -
4.120 -void glsl_enable_shaders(gboolean en)
4.121 -{
4.122 - if( glsl_program != 0 ) {
4.123 - if( en ) {
4.124 - glUseProgramObjectARB(glsl_program);
4.125 - } else {
4.126 - glUseProgramObjectARB(0);
4.127 - }
4.128 + return shader;
4.129 }
4.130 }
4.131
4.132 -void glsl_unload_shaders(void)
4.133 +gl_shader_t glsl_create_fragment_shader( const char *source )
4.134 {
4.135 - glUseProgramObjectARB(0);
4.136 - glDetachObjectARB(glsl_program, glsl_vert_shader);
4.137 - glDetachObjectARB(glsl_program, glsl_frag_shader);
4.138 - glDeleteObjectARB(glsl_program);
4.139 - glDeleteObjectARB(glsl_vert_shader);
4.140 - glDeleteObjectARB(glsl_frag_shader);
4.141 + gboolean ok;
4.142 + gl_shader_t shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
4.143 +
4.144 + glShaderSourceARB( shader, 1, &source, NULL );
4.145 + glCompileShaderARB(shader);
4.146 + ok = glsl_check_shader_error("Failed to compile fragment shader", shader);
4.147 + if( !ok ) {
4.148 + glDeleteObjectARB(shader);
4.149 + return INVALID_SHADER;
4.150 + } else {
4.151 + return shader;
4.152 + }
4.153 +}
4.154 +
4.155 +gl_program_t glsl_create_program( gl_shader_t *shaderv )
4.156 +{
4.157 + gboolean ok;
4.158 + unsigned i;
4.159 + gl_program_t program = glCreateProgramObjectARB();
4.160 +
4.161 + for( i=0; shaderv[i] != INVALID_SHADER; i++ ) {
4.162 + glAttachObjectARB(program, shaderv[i]);
4.163 + }
4.164 +
4.165 + glLinkProgramARB(program);
4.166 + ok = glsl_check_program_error( "Failed to link shader program", program );
4.167 + if( !ok ) {
4.168 + glDeleteObjectARB(program);
4.169 + return INVALID_PROGRAM;
4.170 + } else {
4.171 + return program;
4.172 + }
4.173 +}
4.174 +
4.175 +void glsl_use_program(gl_program_t program)
4.176 +{
4.177 + glUseProgramObjectARB(program);
4.178 + glsl_check_program_error( "Failed to activate shader program", program );
4.179 +}
4.180 +
4.181 +void glsl_destroy_shader(gl_shader_t shader)
4.182 +{
4.183 + glDeleteObjectARB(shader);
4.184 +}
4.185 +
4.186 +void glsl_destroy_program(gl_program_t program)
4.187 +{
4.188 + glDeleteObjectARB(program);
4.189 }
4.190
4.191 #elif HAVE_OPENGL_SHADER
4.192 -static GLuint glsl_program = 0, glsl_vert_shader = 0, glsl_frag_shader = 0;
4.193 +
4.194 +gboolean glsl_is_supported()
4.195 +{
4.196 + return isGLExtensionSupported("GL_ARB_fragment_shader") &&
4.197 + isGLExtensionSupported("GL_ARB_vertex_shader") &&
4.198 + isGLExtensionSupported("GL_ARB_shading_language_100");
4.199 +}
4.200
4.201 gboolean glsl_check_shader_error( char *msg, GLuint shader )
4.202 {
4.203 @@ -144,6 +170,7 @@
4.204 }
4.205 return TRUE;
4.206 }
4.207 +
4.208 gboolean glsl_check_program_error( char *msg, GLuint program )
4.209 {
4.210 if( glGetError() != GL_NO_ERROR ) {
4.211 @@ -156,83 +183,203 @@
4.212 return TRUE;
4.213 }
4.214
4.215 -gboolean glsl_load_shaders( const char *vertex_src, const char *fragment_src )
4.216 +gl_shader_t glsl_create_vertex_shader( const char *source )
4.217 {
4.218 - gboolean vsok = TRUE, fsok = TRUE, pok = FALSE;
4.219 + gboolean ok;
4.220 + gl_shader_t shader = glCreateShader(GL_VERTEX_SHADER);
4.221
4.222 - if( vertex_src == NULL && fragment_src == NULL ) {
4.223 - return TRUE;
4.224 + glShaderSource( shader, 1, &source, NULL );
4.225 + glCompileShader(shader);
4.226 + ok = glsl_check_shader_error( "Failed to compile vertex shader", glsl_vert_shader );
4.227 + if( !ok ) {
4.228 + glDeleteShader(shader);
4.229 + return INVALID_SHADER;
4.230 + } else {
4.231 + return shader;
4.232 }
4.233
4.234 - glsl_program = glCreateProgram();
4.235 +}
4.236
4.237 - if( vertex_src != NULL ) {
4.238 - glsl_vert_shader = glCreateShader(GL_VERTEX_SHADER);
4.239 - glShaderSource( glsl_vert_shader, 1, &vertex_src, NULL );
4.240 - glCompileShader(glsl_vert_shader);
4.241 - vsok = glsl_check_shader_error( "Failed to compile vertex shader", glsl_vert_shader );
4.242 +gl_shader_t glsl_create_fragment_shader( const char *source )
4.243 +{
4.244 + gboolean ok;
4.245 + gl_shader_t shader = glCreateShader(GL_FRAGMENT_SHADER);
4.246 +
4.247 + glShaderSource( shader, 1, &source, NULL );
4.248 + glCompileShader(shader);
4.249 + ok = glsl_check_shader_error( "Failed to compile fragment shader", glsl_frag_shader );
4.250 + if( !ok ) {
4.251 + glDeleteShader(shader);
4.252 + return INVALID_SHADER;
4.253 + } else {
4.254 + return shader;
4.255 }
4.256 - if( fragment_src != NULL ) {
4.257 - glsl_frag_shader = glCreateShader(GL_FRAGMENT_SHADER);
4.258 - glShaderSource( glsl_frag_shader, 1, &fragment_src, NULL );
4.259 - glCompileShader(glsl_frag_shader);
4.260 - fsok = glsl_check_shader_error( "Failed to compile fragment shader", glsl_frag_shader );
4.261 +}
4.262 +
4.263 +gl_program_t glsl_create_program( gl_shader_t *shaderv )
4.264 +{
4.265 + gboolean ok;
4.266 + unsigned i;
4.267 + gl_program_t program = glCreateProgram();
4.268 +
4.269 + for( i=0; shaderv[i] != INVALID_SHADER; i++ ) {
4.270 + glAttachShader(program, shaderv[i]);
4.271 + }
4.272 + glLinkProgram(program);
4.273 + ok = glsl_check_program_error( "Failed to link shader program", program );
4.274 + if( !ok ) {
4.275 + glDeleteProgram(program);
4.276 + return INVALID_PROGRAM;
4.277 + } else {
4.278 + return program;
4.279 + }
4.280 +}
4.281 +
4.282 +void glsl_use_program(gl_program_t program)
4.283 +{
4.284 + glUseProgram(program);
4.285 +}
4.286 +
4.287 +void glsl_destroy_shader(gl_shader_t shader)
4.288 +{
4.289 + glDeleteShader(shader);
4.290 +}
4.291 +
4.292 +void glsl_destroy_program(gl_program_t program)
4.293 +{
4.294 + glDeleteProgram(program);
4.295 +}
4.296 +
4.297 +#else
4.298 +gboolean glsl_is_supported()
4.299 +{
4.300 + return FALSE;
4.301 +}
4.302 +
4.303 +gl_shader_t glsl_create_vertex_shader( const char *source )
4.304 +{
4.305 + return 0;
4.306 +}
4.307 +
4.308 +gl_shader_t glsl_create_fragment_shader( const char *source )
4.309 +{
4.310 + return 0;
4.311 +}
4.312 +
4.313 +gl_program_t glsl_create_program( gl_shader_t vertex, gl_shader_t fragment )
4.314 +{
4.315 + return 0;
4.316 +}
4.317 +
4.318 +void glsl_use_program(gl_program_t program)
4.319 +{
4.320 +}
4.321 +
4.322 +void glsl_destroy_shader(gl_shader_t shader)
4.323 +{
4.324 +}
4.325 +
4.326 +void glsl_destroy_program(gl_program_t program)
4.327 +{
4.328 +}
4.329 +#endif
4.330 +
4.331 +/****************************************************************************/
4.332 +
4.333 +/* Pull in the auto-generated shader definitions */
4.334 +
4.335 +#include "pvr2/shaders.def"
4.336 +
4.337 +static gl_program_t program_array[GLSL_NUM_PROGRAMS];
4.338 +
4.339 +gboolean glsl_load_shaders()
4.340 +{
4.341 + gl_shader_t shader_array[GLSL_NUM_SHADERS];
4.342 + gboolean ok = TRUE;
4.343 + unsigned i, j;
4.344 + for( i=0; i<GLSL_NUM_SHADERS; i++ )
4.345 + shader_array[i] = INVALID_SHADER;
4.346 + for( i=0; i<GLSL_NUM_PROGRAMS; i++ )
4.347 + program_array[i] = INVALID_PROGRAM;
4.348 +
4.349 + /* Compile the shader fragments */
4.350 + for( i=0; shader_source[i].type != GLSL_NO_SHADER; i++ ) {
4.351 + gl_shader_t shader = INVALID_SHADER;
4.352 + switch(shader_source[i].type) {
4.353 + case GLSL_VERTEX_SHADER:
4.354 + shader = glsl_create_vertex_shader(shader_source[i].source);
4.355 + break;
4.356 + case GLSL_FRAGMENT_SHADER:
4.357 + shader = glsl_create_fragment_shader(shader_source[i].source);
4.358 + break;
4.359 + }
4.360 + if( shader == INVALID_SHADER ) {
4.361 + ok = FALSE;
4.362 + break;
4.363 + } else {
4.364 + shader_array[i] = shader;
4.365 + }
4.366 }
4.367
4.368 - if( vsok && fsok ) {
4.369 - if( vertex_src != NULL ) {
4.370 - glAttachShader(glsl_program, glsl_vert_shader);
4.371 + /* Link the programs */
4.372 + if(ok) for( i=0; program_list[i][0] != GLSL_NO_SHADER; i++ ) {
4.373 + gl_shader_t shaderv[GLSL_NUM_SHADERS+1];
4.374 + for( j=0; program_list[i][j] != GLSL_NO_SHADER; j++ ) {
4.375 + shaderv[j] = shader_array[program_list[i][j]];
4.376 }
4.377 - if( fragment_src != NULL ) {
4.378 - glAttachShader(glsl_program, glsl_frag_shader);
4.379 + shaderv[j] = INVALID_SHADER;
4.380 + gl_program_t program = glsl_create_program(shaderv);
4.381 + if( program == INVALID_PROGRAM ) {
4.382 + ok = FALSE;
4.383 + break;
4.384 + } else {
4.385 + program_array[i] = program;
4.386 }
4.387 - glLinkProgram(glsl_program);
4.388 - pok = glsl_check_program_error( "Failed to link shader program", glsl_program );
4.389 }
4.390
4.391 - if( pok ) {
4.392 - glUseProgram(glsl_program);
4.393 - pok = glsl_check_program_error( "Failed to apply shader program", glsl_program );
4.394 - glsl_enable_shaders(FALSE); // initially disabled
4.395 - } else {
4.396 + /**
4.397 + * Destroy the compiled fragments (the linked programs don't need them
4.398 + * anymore)
4.399 + */
4.400 + for( i=0; i<GLSL_NUM_SHADERS; i++ ) {
4.401 + if( shader_array[i] != INVALID_SHADER )
4.402 + glsl_destroy_shader(shader_array[i]);
4.403 + }
4.404 +
4.405 + /**
4.406 + * If we errored, delete the programs. It's all or nothing.
4.407 + */
4.408 + if( !ok ) {
4.409 glsl_unload_shaders();
4.410 + return FALSE;
4.411 }
4.412 - return pok;
4.413 + return TRUE;
4.414 }
4.415
4.416 -
4.417 -void glsl_enable_shaders(gboolean en)
4.418 +void glsl_unload_shaders()
4.419 {
4.420 - if( glsl_program != 0 ) {
4.421 - if( en ) {
4.422 - glUseProgram(glsl_program);
4.423 - } else {
4.424 - glUseProgram(0);
4.425 + unsigned i;
4.426 + for( i=0; i<GLSL_NUM_PROGRAMS; i++ ) {
4.427 + if( program_array[i] != INVALID_PROGRAM ) {
4.428 + glsl_destroy_program(program_array[i]);
4.429 + program_array[i] = INVALID_PROGRAM;
4.430 }
4.431 }
4.432 }
4.433
4.434 -void glsl_unload_shaders(void)
4.435 +gboolean glsl_set_shader(unsigned i)
4.436 {
4.437 - glUseProgram(0);
4.438 - glDetachShader(glsl_program, glsl_vert_shader);
4.439 - glDetachShader(glsl_program, glsl_frag_shader);
4.440 - glDeleteProgram(glsl_program);
4.441 - glDeleteShader(glsl_vert_shader);
4.442 - glDeleteShader(glsl_frag_shader);
4.443 + assert( i >= 0 && i <= GLSL_LAST_PROGRAM );
4.444 +
4.445 + if( program_array[i] != INVALID_PROGRAM ) {
4.446 + glsl_use_program(program_array[i]);
4.447 + return TRUE;
4.448 + } else {
4.449 + return FALSE;
4.450 + }
4.451 }
4.452
4.453 -#else
4.454 -gboolean glsl_load_shaders( const char *vertex_src, const char *fragment_src )
4.455 +void glsl_clear_shader()
4.456 {
4.457 - return FALSE;
4.458 + glsl_use_program(0);
4.459 }
4.460 -
4.461 -void glsl_unload_shaders()
4.462 -{
4.463 -}
4.464 -
4.465 -void glsl_enable_shaders( gboolean enable )
4.466 -{
4.467 -}
4.468 -#endif
5.1 --- a/src/pvr2/glrender.c Fri Sep 17 20:05:34 2010 +1000
5.2 +++ b/src/pvr2/glrender.c Fri Sep 17 20:08:50 2010 +1000
5.3 @@ -95,7 +95,7 @@
5.4 {
5.5
5.6 if( glsl_is_supported() ) {
5.7 - if( !glsl_load_shaders( glsl_vertex_shader_src, NULL ) ) {
5.8 + if( !glsl_load_shaders( ) ) {
5.9 WARN( "Unable to load GL shaders" );
5.10 }
5.11 }
5.12 @@ -526,7 +526,7 @@
5.13 glFogf(GL_FOG_START, 0.0);
5.14 glFogf(GL_FOG_END, 1.0);
5.15 /* Turn on the shaders (if available) */
5.16 - glsl_enable_shaders(TRUE);
5.17 + glsl_set_shader(DEFAULT_PROGRAM);
5.18
5.19 /* Render the background */
5.20 gl_render_bkgnd( pvr2_scene.bkgnd_poly );
5.21 @@ -580,7 +580,7 @@
5.22 } while( !IS_LAST_SEGMENT(segment++) );
5.23 glDisable( GL_SCISSOR_TEST );
5.24
5.25 - glsl_enable_shaders(FALSE);
5.26 + glsl_clear_shader();
5.27
5.28 gettimeofday( &end_tv, NULL );
5.29 ms = (end_tv.tv_sec - tex_tv.tv_sec) * 1000 +
6.1 --- a/src/pvr2/glutil.h Fri Sep 17 20:05:34 2010 +1000
6.2 +++ b/src/pvr2/glutil.h Fri Sep 17 20:08:50 2010 +1000
6.3 @@ -21,6 +21,7 @@
6.4
6.5 #include <stdio.h>
6.6 #include "display.h"
6.7 +#include "pvr2/shaders.h"
6.8
6.9 #ifdef __cplusplus
6.10 extern "C" {
6.11 @@ -49,12 +50,10 @@
6.12
6.13 /****** Shader handling (gl_sl.c) *****/
6.14 gboolean glsl_is_supported(void);
6.15 -gboolean glsl_load_shaders( const char *vert_shader, const char *frag_shader );
6.16 +gboolean glsl_load_shaders( );
6.17 void glsl_unload_shaders(void);
6.18 -void glsl_enable_shaders( gboolean enable );
6.19 -
6.20 -extern const char *glsl_vertex_shader_src;
6.21 -extern const char *glsl_fragment_shader_src;
6.22 +gboolean glsl_set_shader( unsigned program_id );
6.23 +void glsl_clear_shader();
6.24
6.25 #ifdef __cplusplus
6.26 }
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/src/pvr2/shaders.glsl Fri Sep 17 20:08:50 2010 +1000
7.3 @@ -0,0 +1,42 @@
7.4 +/**
7.5 + * $Id$
7.6 + *
7.7 + * Assorted shader definitions (optionally) used by the PVR2 rendering
7.8 + * engine.
7.9 + *
7.10 + * This file is preprocessed by genglsl to produce shaders.c and shaders.h.
7.11 + *
7.12 + * Copyright (c) 2007-2010 Nathan Keynes.
7.13 + *
7.14 + * This program is free software; you can redistribute it and/or modify
7.15 + * it under the terms of the GNU General Public License as published by
7.16 + * the Free Software Foundation; either version 2 of the License, or
7.17 + * (at your option) any later version.
7.18 + *
7.19 + * This program is distributed in the hope that it will be useful,
7.20 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.21 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.22 + * GNU General Public License for more details.
7.23 + */
7.24 +
7.25 +#vertex DEFAULT_VERTEX_SHADER
7.26 +void main()
7.27 +{
7.28 + vec4 tmp = ftransform();
7.29 + float w = gl_Vertex.z;
7.30 + gl_Position = tmp * w;
7.31 + gl_FrontColor = gl_Color;
7.32 + gl_FrontSecondaryColor = gl_SecondaryColor;
7.33 + gl_TexCoord[0] = gl_MultiTexCoord0;
7.34 + gl_FogFragCoord = gl_FogCoord;
7.35 +}
7.36 +
7.37 +#fragment DEFAULT_FRAGMENT_SHADER
7.38 +void main()
7.39 +{
7.40 + gl_FragColor = gl_Color;
7.41 + gl_FragDepth = gl_FragCoord.z;
7.42 +}
7.43 +
7.44 +#program DEFAULT_PROGRAM = DEFAULT_VERTEX_SHADER
7.45 +
8.1 --- a/src/pvr2/vertex.glsl Fri Sep 17 20:05:34 2010 +1000
8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
8.3 @@ -1,12 +0,0 @@
8.4 -// Standard PVR2 vertex shader
8.5 -
8.6 -void main()
8.7 -{
8.8 - vec4 tmp = ftransform();
8.9 - float w = gl_Vertex.z;
8.10 - gl_Position = tmp * w;
8.11 - gl_FrontColor = gl_Color;
8.12 - gl_FrontSecondaryColor = gl_SecondaryColor;
8.13 - gl_TexCoord[0] = gl_MultiTexCoord0;
8.14 - gl_FogFragCoord = gl_FogCoord;
8.15 -}
9.1 --- a/src/tools/genglsl.c Fri Sep 17 20:05:34 2010 +1000
9.2 +++ b/src/tools/genglsl.c Fri Sep 17 20:08:50 2010 +1000
9.3 @@ -1,10 +1,13 @@
9.4 /**
9.5 * $Id$
9.6 *
9.7 - * Trivial tool to take two shader source files and dump them out in
9.8 - * a C file with appropriate escaping.
9.9 + * Tool to take an input .glsl file and write out a corresponding .c and .h
9.10 + * file based on the content. The .glsl file contains a number of shaders
9.11 + * marked with either #fragment <name> or #vertex <name>
9.12 + * a C file with appropriate escaping, as well as program definitions
9.13 + * written as #program <name> = <shader1> <shader2> ... <shaderN>
9.14 *
9.15 - * Copyright (c) 2007 Nathan Keynes.
9.16 + * Copyright (c) 2007-2010 Nathan Keynes.
9.17 *
9.18 * This program is free software; you can redistribute it and/or modify
9.19 * it under the terms of the GNU General Public License as published by
9.20 @@ -17,62 +20,267 @@
9.21 * GNU General Public License for more details.
9.22 */
9.23
9.24 +#include <assert.h>
9.25 +#include <errno.h>
9.26 #include <stdio.h>
9.27 #include <stdlib.h>
9.28 +#include <string.h>
9.29 +#include <glib/gstrfuncs.h>
9.30 +#include <glib/glist.h>
9.31 +
9.32 +#define MAX_LINE 4096
9.33 +#define DEF_ALLOC_SIZE 4096
9.34 +#define MAX_SHADERS 128
9.35 +
9.36 +typedef enum {
9.37 + VERTEX_SHADER = 0,
9.38 + FRAGMENT_SHADER = 1
9.39 +} shader_type_t;
9.40 +
9.41 +typedef struct shader {
9.42 + shader_type_t type;
9.43 + const char *name;
9.44 + char *body;
9.45 +} *shader_t;
9.46 +
9.47 +typedef struct program {
9.48 + const char *name;
9.49 + gchar **shader_names;
9.50 +} *program_t;
9.51 +
9.52 +typedef struct glsldata {
9.53 + const char *filename;
9.54 + unsigned max_shaders;
9.55 + GList *shaders;
9.56 + GList *programs;
9.57 +} *glsldata_t;
9.58 +
9.59 +static struct glsldata *readInput( const char *filename )
9.60 +{
9.61 + char buf[MAX_LINE];
9.62 + size_t current_size = 0, current_posn = 0;
9.63 + unsigned i;
9.64 +
9.65 + FILE *f = fopen( filename, "ro" );
9.66 + if( f == NULL ) {
9.67 + fprintf( stderr, "Error: unable to open input file '%s': %s\n", filename, strerror(errno) );
9.68 + exit(1);
9.69 + }
9.70 +
9.71 + shader_t shader = NULL;
9.72 + glsldata_t result = malloc(sizeof(struct glsldata));
9.73 + assert( result != NULL );
9.74 + result->filename = strdup(filename);
9.75 + result->shaders = NULL;
9.76 + result->programs = NULL;
9.77 + result->max_shaders = 0;
9.78 +
9.79 + while( fgets(buf, sizeof(buf), f) != NULL ) {
9.80 + if( strlen(buf) == 0 )
9.81 + continue;
9.82 +
9.83 + if( strncmp(buf, "#vertex ", 8) == 0 ) {
9.84 + shader = malloc(sizeof(struct shader));
9.85 + assert( shader != NULL );
9.86 + shader->type = VERTEX_SHADER;
9.87 + shader->name = strdup(g_strstrip(buf+8));
9.88 + shader->body = malloc(DEF_ALLOC_SIZE);
9.89 + shader->body[0] = '\0';
9.90 + current_size = DEF_ALLOC_SIZE;
9.91 + current_posn = 0;
9.92 + result->shaders = g_list_append(result->shaders, shader);
9.93 + } else if( strncmp( buf, "#fragment ", 10 ) == 0 ) {
9.94 + shader = malloc(sizeof(struct shader));
9.95 + assert( shader != NULL );
9.96 + shader->type = FRAGMENT_SHADER;
9.97 + shader->name = strdup(g_strstrip(buf+10));
9.98 + shader->body = malloc(DEF_ALLOC_SIZE);
9.99 + shader->body[0] = '\0';
9.100 + current_size = DEF_ALLOC_SIZE;
9.101 + current_posn = 0;
9.102 + result->shaders = g_list_append(result->shaders, shader);
9.103 + } else if( strncmp( buf, "#program ", 9 ) == 0 ) {
9.104 + shader = NULL;
9.105 + program_t program = malloc(sizeof(struct program));
9.106 + char *rest = buf+9;
9.107 + char *equals = strchr(rest, '=');
9.108 + if( equals == NULL ) {
9.109 + fprintf( stderr, "Error: invalid program line %s\n", buf );
9.110 + exit(2);
9.111 + }
9.112 + *equals = '\0';
9.113 + program->name = g_strdup(g_strstrip(rest));
9.114 + program->shader_names = g_strsplit_set(g_strstrip(equals+1), " \t\r,", 0);
9.115 + result->programs = g_list_append(result->programs, program);
9.116 + for(i=0;program->shader_names[i] != NULL; i++ );
9.117 + if( i > result->max_shaders )
9.118 + result->max_shaders = i;
9.119 + } else if( shader != NULL ) {
9.120 + size_t len = strlen(buf);
9.121 + if( current_posn + len > current_size ) {
9.122 + shader->body = realloc(shader->body, current_size*2);
9.123 + assert( shader->body != NULL );
9.124 + current_size *= 2;
9.125 + }
9.126 + strcpy( shader->body + current_posn, buf );
9.127 + current_posn += len;
9.128 + }
9.129 + }
9.130 +
9.131 + fclose(f);
9.132 + return result;
9.133 +}
9.134
9.135 /**
9.136 * Copy input to output, quoting " characters as we go.
9.137 */
9.138 -static void writeShader( FILE *out, FILE *in )
9.139 +static void writeCString( FILE *out, const char *str )
9.140 {
9.141 - int ch;
9.142 + const char *p = str;
9.143
9.144 - while( (ch = fgetc(in)) != EOF ) {
9.145 - if( ch == '\"' ) {
9.146 + while( *p != 0 ) {
9.147 + if( *p == '\"' ) {
9.148 fputc( '\\', out );
9.149 - } else if( ch == '\n') {
9.150 + } else if( *p == '\n' ) {
9.151 fputs( "\\n\\", out );
9.152 }
9.153 - fputc( ch, out );
9.154 + fputc( *p, out );
9.155 + p++;
9.156 + }
9.157 +}
9.158 +
9.159 +static void writeHeader( FILE *out, glsldata_t data )
9.160 +{
9.161 + fprintf( out, "/*\n * This file automatically generated by genglsl from %s\n */\n", data->filename );
9.162 +}
9.163 +
9.164 +static void writeInterface( const char *filename, glsldata_t data )
9.165 +{
9.166 + FILE *f = fopen(filename, "wo");
9.167 + if( f == NULL ) {
9.168 + fprintf( stderr, "Error: Unable to write interface file '%s': %s\n", filename, strerror(errno) );
9.169 + exit(1);
9.170 + }
9.171 +
9.172 + writeHeader( f, data );
9.173 + fprintf( f, "#ifndef lxdream_glsl_H\n#define lxdream_glsl_H 1\n\n" );
9.174 +
9.175 + fprintf( f, "typedef enum {\n" );
9.176 + const char *last_name = NULL;
9.177 + int count = 0;
9.178 + GList *shader_ptr;
9.179 + for( shader_ptr = data->shaders; shader_ptr != NULL; shader_ptr = shader_ptr->next ) {
9.180 + count++;
9.181 + shader_t shader = (shader_t)shader_ptr->data;
9.182 + fprintf( f, " %s,\n", shader->name );
9.183 + last_name = shader->name;
9.184 + }
9.185 + fprintf( f, "} shader_id;\n\n" );
9.186 +
9.187 + if( last_name == NULL )
9.188 + last_name = "NULL";
9.189 + fprintf( f, "#define GLSL_LAST_SHADER %s\n", last_name );
9.190 + fprintf( f, "#define GLSL_NUM_SHADERS %d\n", count );
9.191 + fprintf( f, "#define GLSL_NO_SHADER -1\n\n" );
9.192 + fprintf( f, "#define GLSL_VERTEX_SHADER 1\n" );
9.193 + fprintf( f, "#define GLSL_FRAGMENT_SHADER 2\n" );
9.194 +
9.195 + fprintf( f, "typedef enum {\n" );
9.196 + last_name = NULL;
9.197 + count = 0;
9.198 + GList *program_ptr;
9.199 + for( program_ptr = data->programs; program_ptr != NULL; program_ptr = program_ptr->next ) {
9.200 + count++;
9.201 + program_t program = (program_t)program_ptr->data;
9.202 + fprintf( f, " %s,\n", program->name );
9.203 + last_name = program->name;
9.204 + }
9.205 + fprintf( f, "} program_id;\n\n" );
9.206 +
9.207 + if( last_name == NULL )
9.208 + last_name = "NULL";
9.209 + fprintf( f, "#define GLSL_LAST_PROGRAM %s\n", last_name );
9.210 + fprintf( f, "#define GLSL_NUM_PROGRAMS %d\n", count );
9.211 + fprintf( f, "#define GLSL_NO_PROGRAM -1\n\n" );
9.212 +
9.213 + fprintf( f, "int glsl_load_programs();\n" );
9.214 + fprintf( f, "void glsl_use_program_id( program_id );\n" );
9.215 +
9.216 + fprintf( f, "#endif /* !lxdream_glsl_H */\n" );
9.217 +
9.218 + fclose(f);
9.219 +}
9.220 +
9.221 +static void writeSource( const char *filename, glsldata_t data )
9.222 +{
9.223 + FILE *f = fopen(filename, "wo");
9.224 + if( f == NULL ) {
9.225 + fprintf( stderr, "Error: Unable to write interface file '%s': %s\n", filename, strerror(errno) );
9.226 + exit(1);
9.227 + }
9.228 +
9.229 + writeHeader( f, data );
9.230 + fprintf( f, "struct shader_def {\n int type;\n const char *source;\n};\n" );
9.231 +
9.232 + fprintf( f, "const struct shader_def shader_source[] = {\n" );
9.233 + GList *shader_ptr;
9.234 + for( shader_ptr = data->shaders; shader_ptr != NULL; shader_ptr = shader_ptr->next ) {
9.235 + shader_t shader = (shader_t)shader_ptr->data;
9.236 + fprintf( f, " {%s,\"", (shader->type == VERTEX_SHADER ? "GLSL_VERTEX_SHADER" : "GLSL_FRAGMENT_SHADER") );
9.237 + writeCString( f, shader->body );
9.238 + fprintf( f, "\"},\n" );
9.239 + }
9.240 + fprintf( f, " {GLSL_NO_SHADER,NULL}};\n\n" );
9.241 +
9.242 + fprintf( f, "const int program_list[][%d] = {\n", data->max_shaders+1 );
9.243 + GList *program_ptr;
9.244 + unsigned i;
9.245 + for( program_ptr = data->programs; program_ptr != NULL; program_ptr = program_ptr->next ) {
9.246 + program_t program = (program_t)program_ptr->data;
9.247 + fprintf( f, " {" );
9.248 + for( i=0; program->shader_names[i] != NULL; i++ ) {
9.249 + fprintf(f, "%s,", program->shader_names[i] );
9.250 + }
9.251 + fprintf( f, "GLSL_NO_SHADER},\n" );
9.252 + }
9.253 + fprintf( f, " {GLSL_NO_SHADER}};\n" );
9.254 +
9.255 + fclose(f);
9.256 +}
9.257 +
9.258 +const char *makeExtension(const char *basename, const char *ext)
9.259 +{
9.260 + const char *oldext = strrchr(basename, '.');
9.261 + if( oldext == NULL ) {
9.262 + return g_strdup_printf("%s%s", basename, ext);
9.263 + } else {
9.264 + return g_strdup_printf("%.*s%s", oldext-basename, basename, ext);
9.265 }
9.266 }
9.267
9.268 int main( int argc, char *argv[] )
9.269 {
9.270 - if( argc != 4 ) {
9.271 - fprintf( stderr, "Usage: genglsl <vertex-shader-file> <fragment-shader-file> <output-file>\n");
9.272 + if( argc < 2 ) {
9.273 + fprintf( stderr, "Usage: genglsl <glsl-source-file> [output.c [output.h]]\n");
9.274 exit(1);
9.275 }
9.276
9.277 - FILE *vsin = fopen( argv[1], "ro" );
9.278 - if( vsin == NULL ) {
9.279 - perror( "Unable to open vertex shader source" );
9.280 - exit(2);
9.281 + glsldata_t data = readInput(argv[1]);
9.282 +
9.283 + const char *sourcefile, *ifacefile;
9.284 + if( argc > 2 ) {
9.285 + sourcefile = argv[2];
9.286 + } else {
9.287 + sourcefile = makeExtension(argv[1], ".def");
9.288 }
9.289
9.290 - FILE *fsin = fopen( argv[2], "ro" );
9.291 - if( fsin == NULL ) {
9.292 - perror( "Unable to open fragment shader source" );
9.293 - exit(2);
9.294 + if( argc > 3 ) {
9.295 + ifacefile = argv[3];
9.296 + } else {
9.297 + ifacefile = makeExtension(sourcefile, ".h");
9.298 }
9.299
9.300 - FILE *out = fopen( argv[3], "wo" );
9.301 - if( out == NULL ) {
9.302 - perror( "Unable to open output file" );
9.303 - exit(2);
9.304 - }
9.305 -
9.306 - fprintf( out, "/**\n * This file is automatically generated - do not edit\n */\n\n" );
9.307 - fprintf( out, "const char *glsl_vertex_shader_src = \"" );
9.308 -
9.309 - writeShader( out, vsin );
9.310 -
9.311 - fprintf( out, "\";\n\n" );
9.312 - fprintf( out, "const char *glsl_fragment_shader_src = \"" );
9.313 - writeShader( out, fsin );
9.314 - fprintf( out, "\";\n\n" );
9.315 - fclose( fsin );
9.316 - fclose( vsin );
9.317 - fclose( out );
9.318 + writeSource( sourcefile, data );
9.319 + writeInterface( ifacefile, data );
9.320 return 0;
9.321 }
.