diff --git a/src/Makefile b/src/Makefile
index 61e9905d6..54ec34a80 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,826 +1,826 @@
-
-# GNU Make makefile for SRB2
-#############################################################################
-# Copyright (C) 1998-2000 by DooM Legacy Team.
-# Copyright (C) 2003-2018 by Sonic Team Junior.
-#
-# This program is free software distributed under the
-# terms of the GNU General Public License, version 2.
-# See the 'LICENSE' file for more details.
-#
-# -DLINUX -> use for the GNU/Linux specific
-# -DHAVE_SDL -> use for the SDL interface
-#
-# Sets:
-# Compile the Mingw version with 'make MINGW=1'
-# Compile the SDL/Mingw version with 'make MINGW=1 SDL=1'
-# Compile the SDL/Linux version with 'make LINUX=1'
-# Compile the SDL/Solaris version with 'make SOLARIS=1'
-# Compile the SDL/FreeBSD version with 'gmake FREEBSD=1'
-# Compile the SDL/Cygwin version with 'make CYGWIN32=1'
-# Compile the SDL/other version try with 'make SDL=1'
-#
-# 'Targets':
-# clean
-# Remove all object files
-# cleandep
-# Remove depend.dep
-# dll
-# compile primary HW render DLL/SO
-# all_dll
-# compile all HW render and 3D sound DLLs for the set
-# opengl_dll
-# Pure Mingw only, compile OpenGL HW render DLL
-# minigl_dll
-# Pure Mingw only, compile MiniGL HW render DLL
-# ds3d_dll
-# Pure Mingw only, compile DirectX DirectSound HW sound DLL
-# fmod_dll
-# Pure Mingw only, compile FMOD HW sound DLL
-# openal_dll
-# Pure Mingw only, compile OpenAL HW sound DLL
-# fmod_so
-# Non-Mingw, compile FMOD HW sound SO
-# openal_so
-# Non-Mingw, compile OpenAL HW sound SO
-#
-#
-# Addon:
-# To Cross-Compile, CC=gcc-version make * PREFIX=
-# Compile with GCC 2.97 version, add 'GCC29=1'
-# Compile with GCC 4.0x version, add 'GCC40=1'
-# Compile with GCC 4.1x version, add 'GCC41=1'
-# Compile with GCC 4.2x version, add 'GCC42=1'
-# Compile with GCC 4.3x version, add 'GCC43=1'
-# Compile with GCC 4.4x version, add 'GCC44=1'
-# Compile with GCC 4.5x version, add 'GCC45=1'
-# Compile with GCC 4.6x version, add 'GCC46=1'
-# Compile a profile version, add 'PROFILEMODE=1'
-# Compile a debug version, add 'DEBUGMODE=1'
-# Compile with less warnings, add 'RELAXWARNINGS=1'
-# Generate compiler errors for most compiler warnings, add 'ERRORMODE=1'
-# Compile without 3D hardware support, add 'NOHW=1'
-# Compile with GDBstubs, add 'RDB=1'
-# Compile without PNG, add 'NOPNG=1'
-# Compile without zlib, add 'NOZLIB=1'
-#
-# Addon for SDL:
-# To Cross-Compile, add 'SDL_CONFIG=/usr/*/bin/sdl-config'
-# Compile without SDL_Mixer, add 'NOMIXER=1'
-# Compile without BSD API, add 'NONET=1'
-# Compile without IPX/SPX, add 'NOIPX=1'
-# Compile Mingw/SDL with S_DS3S, add 'DS3D=1'
-# Compile without libopenmpt, add 'NOOPENMPT=1'
-# Compile with S_FMOD3D, add 'FMOD=1' (WIP)
-# Compile with S_OPENAL, add 'OPENAL=1' (WIP)
-# To link with the whole SDL_Image lib to load Icons, add 'SDL_IMAGE=1' but it isn't not realy needed
-# To link with SDLMain to hide console or make on a console-less binary, add 'SDLMAIN=1'
-#
-#############################################################################
-
-ALL_SYSTEMS=\
- PANDORA\
- LINUX64\
- MINGW64\
- HAIKU\
- DUMMY\
- MINGW\
- UNIX\
- LINUX\
- SOLARIS\
- FREEBSD\
- MACOSX\
- SDL\
-
-# check for user specified system
-ifeq (,$(filter $(ALL_SYSTEMS),$(.VARIABLES)))
-ifeq ($(OS),Windows_NT) # all windows are Windows_NT...
-
- $(info Detected a Windows system, compiling for 32-bit MinGW SDL2...)
-
- # go for a 32-bit sdl mingw exe by default
- MINGW=1
- SDL=1
- WINDOWSHELL=1
- HAVE_DISCORDRPC=0
- NOUPX=1
-
-else # if you on the *nix
-
- system:=$(shell uname -s)
-
- ifeq ($(system),Linux)
- new_system=LINUX
- else
-
- $(error \
- Could not automatically detect your system,\
- try specifying a system manually)
-
- endif
-
- ifeq ($(shell getconf LONG_BIT),64)
- system+=64-bit
- new_system:=$(new_system)64
- endif
-
- $(info Detected $(system) ($(new_system))...)
- $(new_system)=1
-
-endif
-endif
-
-
-# SRB2 data files
-D_DIR?=../bin/Resources
-D_FILES=$(D_DIR)/srb2.srb \
- $(D_DIR)/patch.dta \
- #$(D_DIR)/music.dta \
- $(D_DIR)/gfx.kart \
- $(D_DIR)/textures.kart \
- $(D_DIR)/chars.kart \
- $(D_DIR)/maps.kart \
- $(D_DIR)/sounds.kart \
- $(D_DIR)/patch.kart \
- $(D_DIR)/music.kart \
-
-PKG_CONFIG?=pkg-config
-
-ifdef PANDORA
-LINUX=1
-endif
-
-ifdef LINUX64
-LINUX=1
-NONX86=1
-# LINUX64 does not imply X86_64=1; could mean ARM64 or Itanium
-endif
-
-ifdef MINGW64
-MINGW=1
-NONX86=1
-# MINGW64 should not necessarily imply X86_64=1, but we make that assumption elsewhere
-# Once that changes, remove this
-X86_64=1
-endif #ifdef MINGW64
-
-ifdef HAIKU
-SDL=1
-endif
-
-include Makefile.cfg
-
-ifdef DUMMY
-NOPNG=1
-NOZLIB=1
-NONET=1
-NOHW=1
-NOIPX=1
-EXENAME?=srb2dummy
-OBJS=$(OBJDIR)/i_video.o
-LIBS=-lm
-endif
-
-ifdef HAIKU
-NOIPX=1
-ifndef NONET
-LIBS=-lnetwork
-endif
-CFLAGS+=-DUNIXCOMMON
-PNG_CFLAGS?=
-PNG_LDFLAGS?=-lpng
-endif
-
-ifdef PANDORA
-NONX86=1
-NOHW=1
-endif
-
-ifndef NOOPENMPT
-HAVE_OPENMPT=1
-endif
-
-ifdef MINGW
-include win32/Makefile.cfg
-endif #ifdef MINGW
-
-ifdef UNIX
-UNIXCOMMON=1
-endif
-
-ifdef LINUX
-UNIXCOMMON=1
-ifndef NOGME
-HAVE_LIBGME=1
-endif
-endif
-
-ifdef SOLARIS
-UNIXCOMMON=1
-endif
-
-ifdef FREEBSD
-UNIXCOMMON=1
-endif
-
-ifdef MACOSX
-UNIXCOMMON=1
-endif
-
-ifdef SDL
- include sdl/Makefile.cfg
-endif #ifdef SDL
-
-ifdef DISTCC
- CC:=distcc $(CC)
-endif
-
-ifdef CCACHE
- CC:=ccache $(CC)
-endif
-
-MSGFMT?=msgfmt
-
-ifndef ECHO
- REMOVE:=@$(REMOVE)
- CC:=@$(CC)
- CXX:=@$(CXX)
- OBJCOPY:=@$(OBJCOPY)
- OBJDUMP:=@$(OBJDUMP)
- STRIP:=@$(STRIP)
- WINDRES:=@$(WINDRES)
- CP:=@$(CP)
- MKDIR:=@$(MKDIR)
- MKISOFS:=@$(MKISOFS)
- DD:=@$(DD)
- NDSTOOL:=@$(NDSTOOL)
- GZIP:=@$(GZIP)
- MSGFMT:=@$(MSGFMT)
- UPX:=@$(UPX)
- UPX_OPTS+=-q
-endif
-
-ifdef NONET
- OPTS+=-DNONET
- NOCURL=1
-else
-ifdef NO_IPV6
- OPTS+=-DNO_IPV6
-endif
-endif
-
-ifdef NOHW
- OPTS+=-DNOHW
-else
- #Hurdler: not really supported and not tested recently
- #OPTS+=-DUSE_PALETTED_TEXTURE
- OPTS+=-DHWRENDER
- OBJS+=$(OBJDIR)/hw_bsp.o $(OBJDIR)/hw_draw.o $(OBJDIR)/hw_light.o \
- $(OBJDIR)/hw_main.o $(OBJDIR)/hw_clip.o $(OBJDIR)/hw_md2.o $(OBJDIR)/hw_cache.o $(OBJDIR)/hw_trick.o \
- $(OBJDIR)/hw_md2load.o $(OBJDIR)/hw_md3load.o $(OBJDIR)/hw_model.o $(OBJDIR)/u_list.o
-endif
-
-OPTS += -DCOMPVERSION
-
-ifndef NONX86
-ifndef GCC29
- ARCHOPTS?=-msse3 -mfpmath=sse
-else
- ARCHOPTS?=-mpentium
-endif
-else
-ifdef X86_64
- ARCHOPTS?=-march=native -O3 -mfpmath=both -funroll-loops -finline-functions -funswitch-loops -fpeel-loops -fipa-pta -fprefetch-loop-arrays -ftree-loop-linear -ftree-vectorize -floop-strip-mine -fgraphite-identity -falign-functions -falign-loops -ftree-loop-distribution -floop-nest-optimize
-endif
-endif
-
-
-ifndef NOPNG
-OPTS+=-DHAVE_PNG
-
-ifdef PNG_PKGCONFIG
-PNG_CFLAGS?=$(shell $(PKG_CONFIG) $(PNG_PKGCONFIG) --cflags)
-PNG_LDFLAGS?=$(shell $(PKG_CONFIG) $(PNG_PKGCONFIG) --libs)
-else
-ifdef PREFIX
-PNG_CONFIG?=$(PREFIX)-libpng-config
-else
-PNG_CONFIG?=libpng-config
-endif
-
-ifdef PNG_STATIC
-PNG_CFLAGS?=$(shell $(PNG_CONFIG) --static --cflags)
-PNG_LDFLAGS?=$(shell $(PNG_CONFIG) --static --ldflags)
-else
-PNG_CFLAGS?=$(shell $(PNG_CONFIG) --cflags)
-PNG_LDFLAGS?=$(shell $(PNG_CONFIG) --ldflags)
-endif
-endif
-
-ifdef LINUX
-PNG_CFLAGS+=-D_LARGEFILE64_SOURCE
-endif
-
-LIBS+=$(PNG_LDFLAGS)
-CFLAGS+=$(PNG_CFLAGS)
-
-OBJS+=$(OBJDIR)/apng.o
-endif
-
-ifdef HAVE_LIBGME
-OPTS+=-DHAVE_LIBGME
-
-LIBGME_PKGCONFIG?=libgme
-LIBGME_CFLAGS?=$(shell $(PKG_CONFIG) $(LIBGME_PKGCONFIG) --cflags)
-LIBGME_LDFLAGS?=$(shell $(PKG_CONFIG) $(LIBGME_PKGCONFIG) --libs)
-
-LIBS+=$(LIBGME_LDFLAGS)
-CFLAGS+=$(LIBGME_CFLAGS)
-endif
-
-ifdef HAVE_OPENMPT
-OPTS+=-DHAVE_OPENMPT
-
-LIBOPENMPT_PKGCONFIG?=libopenmpt
-LIBOPENMPT_CFLAGS?=$(shell $(PKG_CONFIG) $(LIBOPENMPT_PKGCONFIG) --cflags)
-LIBOPENMPT_LDFLAGS?=$(shell $(PKG_CONFIG) $(LIBOPENMPT_PKGCONFIG) --libs)
-
-LIBS+=$(LIBOPENMPT_LDFLAGS)
-CFLAGS+=$(LIBOPENMPT_CFLAGS)
-endif
-
-ifndef NOZLIB
-OPTS+=-DHAVE_ZLIB
-ZLIB_PKGCONFIG?=zlib
-ZLIB_CFLAGS?=$(shell $(PKG_CONFIG) $(ZLIB_PKGCONFIG) --cflags)
-ZLIB_LDFLAGS?=$(shell $(PKG_CONFIG) $(ZLIB_PKGCONFIG) --libs)
-
-LIBS+=$(ZLIB_LDFLAGS)
-CFLAGS+=$(ZLIB_CFLAGS)
-else
-NOPNG=1
-endif
-
-ifndef NOCURL
-OPTS+=-DHAVE_CURL
-CURLCONFIG?=curl-config
-CURL_CFLAGS?=$(shell $(CURLCONFIG) --cflags)
-CURL_LDFLAGS?=$(shell $(CURLCONFIG) --libs)
-
-LIBS+=$(CURL_LDFLAGS)
-CFLAGS+=$(CURL_CFLAGS)
-endif
-
-ifdef STATIC
-LIBS:=-static $(LIBS)
-endif
-
-ifdef HAVE_MINIUPNPC
-ifdef NONET
-HAVE_MINIUPNPC=''
-else
-LIBS+=-lminiupnpc
-ifdef MINGW
-LIBS+=-lws2_32 -liphlpapi
-endif
-CFLAGS+=-DHAVE_MINIUPNPC
-endif
-endif
-
-ifdef HAVE_DISCORDRPC
-LIBS+=-ldiscord-rpc
-CFLAGS+=-DHAVE_DISCORDRPC -DUSE_STUN
-OBJS+=$(OBJDIR)/discord.o $(OBJDIR)/stun.o
-endif
-
-ifndef NO_LUA
- include blua/Makefile.cfg
-endif
-
-ifdef NOMD5
- OPTS+=-DNOMD5
-else
- OBJS:=$(OBJDIR)/md5.o $(OBJS)
-endif
-
-ifdef NOPOSTPROCESSING
- OPTS+=-DNOPOSTPROCESSING
-endif
-
- OPTS:=-fno-exceptions $(OPTS)
-
-ifdef MOBJCONSISTANCY
- OPTS+=-DMOBJCONSISTANCY
-endif
-
-ifdef PACKETDROP
- OPTS+=-DPACKETDROP
-endif
-
-ifdef DEBUGMODE
-
- # build with debugging information
- WINDRESFLAGS = -D_DEBUG
-ifdef GCC48
- CFLAGS+=-Og
-else
- CFLAGS+=-O0
-endif
- CFLAGS+= -Wall -DPARANOIA -DRANGECHECK -DPACKETDROP -DMOBJCONSISTANCY
-else
-
-
- # build a normal optimised version
- WINDRESFLAGS = -DNDEBUG
- CFLAGS+=-O3
-endif
- CFLAGS+=-g $(OPTS) $(ARCHOPTS) $(WINDRESFLAGS)
-
-ifdef PROFILEMODE
- # build with profiling information
- CFLAGS+=-pg
- LDFLAGS+=-pg
-endif
-
-ifdef ZDEBUG
- CPPFLAGS+=-DZDEBUG
-endif
-
-ifdef DUMPCONSISTENCY
- CPPFLAGS+=-DDUMPCONSISTENCY
-endif
-
-ifdef DEVELOP
- CPPFLAGS+=-DDEVELOP
-endif
-
-OPTS+=$(CPPFLAGS)
-
-# default EXENAME if all else fails
-EXENAME?=srb2
-DBGNAME?=$(EXENAME).debug
-
-# $(OBJDIR)/dstrings.o \
-
-# not too sophisticated dependency
-# SRB2kart kart.o on line 433 below
-OBJS:=$(i_main_o) \
- $(OBJDIR)/comptime.o \
- $(OBJDIR)/string.o \
- $(OBJDIR)/d_async.o \
- $(OBJDIR)/d_main.o \
- $(OBJDIR)/d_protocol.o \
- $(OBJDIR)/d_clisrv.o \
- $(OBJDIR)/d_net.o \
- $(OBJDIR)/d_netfil.o \
- $(OBJDIR)/d_netcmd.o \
- $(OBJDIR)/dehacked.o \
- $(OBJDIR)/z_zone.o \
- $(OBJDIR)/f_finale.o \
- $(OBJDIR)/f_wipe.o \
- $(OBJDIR)/g_game.o \
- $(OBJDIR)/g_input.o \
- $(OBJDIR)/am_map.o \
- $(OBJDIR)/command.o \
- $(OBJDIR)/console.o \
- $(OBJDIR)/hu_stuff.o \
- $(OBJDIR)/y_inter.o \
- $(OBJDIR)/st_stuff.o \
- $(OBJDIR)/k_kart.o \
- $(OBJDIR)/m_aatree.o \
- $(OBJDIR)/m_anigif.o \
- $(OBJDIR)/m_argv.o \
- $(OBJDIR)/m_bbox.o \
- $(OBJDIR)/m_cheat.o \
- $(OBJDIR)/m_cond.o \
- $(OBJDIR)/m_fixed.o \
- $(OBJDIR)/m_menu.o \
- $(OBJDIR)/m_misc.o \
- $(OBJDIR)/m_perfstats.o \
- $(OBJDIR)/m_random.o \
- $(OBJDIR)/m_queue.o \
- $(OBJDIR)/info.o \
- $(OBJDIR)/p_ceilng.o \
- $(OBJDIR)/p_enemy.o \
- $(OBJDIR)/p_floor.o \
- $(OBJDIR)/p_inter.o \
- $(OBJDIR)/p_lights.o \
- $(OBJDIR)/p_map.o \
- $(OBJDIR)/p_maputl.o \
- $(OBJDIR)/p_mobj.o \
- $(OBJDIR)/p_polyobj.o\
- $(OBJDIR)/p_saveg.o \
- $(OBJDIR)/p_setup.o \
- $(OBJDIR)/p_sight.o \
- $(OBJDIR)/p_spec.o \
- $(OBJDIR)/p_telept.o \
- $(OBJDIR)/p_tick.o \
- $(OBJDIR)/p_user.o \
- $(OBJDIR)/p_slopes.o \
- $(OBJDIR)/tables.o \
- $(OBJDIR)/r_bsp.o \
- $(OBJDIR)/r_data.o \
- $(OBJDIR)/r_draw.o \
- $(OBJDIR)/r_fps.o \
- $(OBJDIR)/r_main.o \
- $(OBJDIR)/r_plane.o \
- $(OBJDIR)/r_segs.o \
- $(OBJDIR)/r_sky.o \
- $(OBJDIR)/r_splats.o \
- $(OBJDIR)/r_patch.o \
- $(OBJDIR)/r_things.o \
- $(OBJDIR)/screen.o \
- $(OBJDIR)/v_video.o \
- $(OBJDIR)/s_sound.o \
- $(OBJDIR)/sounds.o \
- $(OBJDIR)/w_wad.o \
- $(OBJDIR)/filesrch.o \
- $(OBJDIR)/mserv.o \
- $(OBJDIR)/http-mserv.o\
- $(OBJDIR)/i_tcp.o \
- $(OBJDIR)/i_time.o \
- $(OBJDIR)/lzf.o \
- $(OBJDIR)/b_bot.o \
- $(i_net_o) \
- $(i_system_o) \
- $(i_sound_o) \
- $(OBJS)
-
-# List of languages to compile.
-# For reference, this is the command I use to build a srb2.pot file from the source code.
-# (The listed source files are the ones containing translated strings).
-# FILES=""; for file in `find ./ | grep "\.c" | grep -v svn`; do [ "`grep "M_GetText(" $file`" ] && FILES="$FILES $file"; done; xgettext -d srb2 -o locale/srb2.pot -kM_GetText -F --no-wrap $FILES
-ifdef GETTEXT
-POS:=$(BIN)/en.mo
-
-OPTS+=-DGETTEXT
-endif
-
-ifdef PANDORA
-all: pre-build $(BIN)/$(PNDNAME)
-endif
-
-ifdef MINGW
-ifndef SDL
-all: pre-build $(BIN)/$(EXENAME) dll
-endif
-endif
-
-ifdef SDL
-all: pre-build $(BIN)/$(EXENAME)
-endif
-
-ifdef DUMMY
-all: $(BIN)/$(EXENAME)
-endif
-
-cleandep:
- $(REMOVE) $(OBJDIR)/depend.dep
- $(REMOVE) comptime.h
-
-pre-build:
-ifdef WINDOWSHELL
- -$(.)..\comptime.bat .
-else
- -$(.)../comptime.sh .
-endif
-
-clean:
- $(REMOVE) *~ *.flc
- $(REMOVE) $(OBJDIR)/*.o
-
-ifdef MINGW
- $(REMOVE) $(OBJDIR)/*.res
-endif
-
-ifdef CYGWIN32
- $(REMOVE) $(OBJDIR)/*.res
-endif
-
-
-# executable
-
-$(BIN)/$(EXENAME): $(POS) $(OBJS)
- -$(MKDIR) $(BIN)
- @echo Linking $(EXENAME)...
- $(LD) $(LDFLAGS) $(OBJS) -o $(BIN)/$(EXENAME) $(LIBS)
-ifndef VALGRIND
-ifndef NOOBJDUMP
- @echo Dumping debugging info
- $(OBJDUMP) $(OBJDUMP_OPTS) $(BIN)/$(EXENAME) > $(BIN)/$(DBGNAME).txt
- -$(GZIP) $(GZIP_OPTS) $(BIN)/$(DBGNAME).txt
-ifndef WINDOWSHELL
- -$(GZIP) $(GZIP_OPT2) $(BIN)/$(DBGNAME).txt
-endif
-endif
-
-# mac os x lsdlsrb2 does not like objcopy
-ifndef MACOSX
- $(OBJCOPY) $(BIN)/$(EXENAME) $(BIN)/$(DBGNAME)
- $(OBJCOPY) --strip-debug $(BIN)/$(EXENAME)
- -$(OBJCOPY) --add-gnu-debuglink=$(BIN)/$(DBGNAME) $(BIN)/$(EXENAME)
-endif
-ifndef NOUPX
- -$(UPX) $(UPX_OPTS) $(BIN)/$(EXENAME)
-endif
-endif
- @echo Build is done, please look for $(EXENAME) in $(BIN), \(checking for post steps\)
-
-reobjdump:
- @echo Redumping debugging info
- $(OBJDUMP) $(OBJDUMP_OPTS) $(BIN)/$(DBGNAME) > $(BIN)/$(DBGNAME).txt
- -$(GZIP) $(GZIP_OPTS) $(BIN)/$(DBGNAME).txt
-ifndef WINDOWSHELL
- -$(GZIP) $(GZIP_OPT2) $(BIN)/$(DBGNAME).txt
-endif
-
-$(OBJDIR):
- -$(MKDIR) $(OBJDIR)
-
-ifndef SDL
-ifdef NOHW
-dll :
-else
-dll : opengl_dll
-endif
-ifdef MINGW
-all_dll: opengl_dll ds3d_dll fmod_dll openal_dll
-
-opengl_dll: $(BIN)/r_opengl.dll
-$(BIN)/r_opengl.dll: $(OBJDIR)/ogl_win.o $(OBJDIR)/r_opengl.o
- -$(MKDIR) $(BIN)
- @echo Linking R_OpenGL.dll...
- $(CC) --shared $^ -o $@ -g -Wl,--add-stdcall-alias -lgdi32 -static-libgcc
-ifndef NOUPX
- -$(UPX) $(UPX_OPTS) $@
-endif
-
-ds3d_dll: $(BIN)/s_ds3d.dll
-$(BIN)/s_ds3d.dll: $(OBJDIR)/s_ds3d.o
- @echo Linking S_DS3d.dll...
- $(CC) --shared $^ -o $@ -g -Wl,--add-stdcall-alias -ldsound -luuid
-
-fmod_dll: $(BIN)/s_fmod.dll
-$(BIN)/s_fmod.dll: $(OBJDIR)/s_fmod.o
- -$(MKDIR) $(BIN)
- @echo Linking S_FMOD.dll...
- $(CC) --shared $^ -o $@ -g -Wl,--add-stdcall-alias -lfmod
-
-openal_dll: $(BIN)/s_openal.dll
-$(BIN)/s_openal.dll: $(OBJDIR)/s_openal.o
- -$(MKDIR) $(BIN)
- @echo Linking S_OpenAL.dll...
- $(CC) --shared $^ -o $@ -g -Wl,--add-stdcall-alias -lopenal32
-else
-all_dll: fmod_so openal_so
-
-fmod_so: $(BIN)/s_fmod.so
-$(BIN)/s_fmod.so: $(OBJDIR)/s_fmod.o
- -$(MKDIR) $(BIN)
- @echo Linking S_FMOD.so...
- $(CC) --shared $^ -o $@ -g --nostartfiles -lm -lfmod
-
-openal_so: $(BIN)/s_openal.so
-$(BIN)/s_openal.so: $(OBJDIR)/s_openal.o
- -$(MKDIR) $(BIN)
- @echo Linking S_OpenAL.so...
- $(CC) --shared $^ -o $@ -g --nostartfiles -lm -lopenal
-endif
-
-else
-ifdef SDL
-ifdef MINGW
-$(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \
- doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \
- command.h hardware/hw_data.h hardware/hw_defs.h hardware/hw_md2.h \
- hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h \
- hardware/hw_md2load.h hardware/hw_md3load.h hardware/hw_model.h hardware/u_list.h \
- am_map.h d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \
- p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-else
-$(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \
- doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \
- command.h hardware/hw_data.h hardware/hw_defs.h hardware/hw_md2.h \
- hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h \
- hardware/hw_md2load.h hardware/hw_md3load.h hardware/hw_model.h hardware/u_list.h \
- am_map.h d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \
- p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h
- $(CC) $(CFLAGS) $(WFLAGS) -I/usr/X11R6/include -c $< -o $@
-endif
-endif
-
-endif
-
-#dependecy made by gcc itself !
-$(OBJS):
-ifndef DUMMY
--include $(OBJDIR)/depend.dep
-endif
-
-$(OBJDIR)/depend.dep:
- @echo "Creating dependency file, depend.dep"
- @echo > comptime.h
- -$(MKDIR) $(OBJDIR)
- $(CC) $(CFLAGS) -MM *.c > $(OBJDIR)/depend.ped
- $(CC) $(CFLAGS) -MM $(INTERFACE)/*.c >> $(OBJDIR)/depend.ped
-ifndef NOHW
- $(CC) $(CFLAGS) -MM hardware/*.c >> $(OBJDIR)/depend.ped
-endif
-ifndef NO_LUA
- $(CC) $(CFLAGS) -MM blua/*.c >> $(OBJDIR)/depend.ped
-endif
- @sed -e 's,\(.*\)\.o: ,$(subst /,\/,$(OBJDIR))\/&,g' < $(OBJDIR)/depend.ped > $(OBJDIR)/depend.dep
- $(REMOVE) $(OBJDIR)/depend.ped
- @echo "Created dependency file, depend.dep"
-
-ifdef VALGRIND
-$(OBJDIR)/z_zone.o: z_zone.c
- $(CC) $(CFLAGS) $(WFLAGS) -DHAVE_VALGRIND $(VALGRIND_CFLAGS) -c $< -o $@
-endif
-
-$(OBJDIR)/comptime.o: comptime.c pre-build
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-
-$(BIN)/%.mo: locale/%.po
- -$(MKDIR) $(BIN)
- $(MSGFMT) -f -o $@ $<
-
-$(OBJDIR)/%.o: %.c
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-
-$(OBJDIR)/%.o: $(INTERFACE)/%.c
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-
-ifdef MACOSX
-$(OBJDIR)/%.o: sdl/macosx/%.c
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-endif
-
-$(OBJDIR)/%.o: hardware/%.c
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-
-$(OBJDIR)/%.o: blua/%.c
- $(CC) $(CFLAGS) $(LUA_CFLAGS) $(WFLAGS) -c $< -o $@
-
-$(OBJDIR)/%.o: %.s
- $(CC) $(OPTS) -x assembler-with-cpp -c $< -o $@
-
-$(OBJDIR)/SRB2.res: win32/Srb2win.rc win32/afxres.h win32/resource.h
- $(WINDRES) -i $< -O rc $(WINDRESFLAGS) --include-dir=win32 -o $@ -O coff
-
-ifdef SDL
-
-ifdef MINGW
-$(OBJDIR)/win_dbg.o: win32/win_dbg.c
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-endif
-
-ifdef STATICHS
-$(OBJDIR)/s_openal.o: hardware/s_openal/s_openal.c hardware/hw3dsdrv.h \
- hardware/hw_dll.h
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-
-$(OBJDIR)/s_fmod.o: hardware/s_fmod/s_fmod.c hardware/hw3dsdrv.h \
- hardware/hw_dll.h
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-
-ifdef MINGW
-$(OBJDIR)/s_ds3d.o: hardware/s_ds3d/s_ds3d.c hardware/hw3dsdrv.h \
- hardware/hw_dll.h
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-endif
-else
-
-$(OBJDIR)/s_fmod.o: hardware/s_fmod/s_fmod.c hardware/hw3dsdrv.h \
- hardware/hw_dll.h
- $(CC) $(ARCHOPTS) -Os -o $(OBJDIR)/s_fmod.o -DHW3SOUND -DUNIXCOMMON -shared -nostartfiles -c hardware/s_fmod/s_fmod.c
-
-$(OBJDIR)/s_openal.o: hardware/s_openal/s_openal.c hardware/hw3dsdrv.h \
- hardware/hw_dll.h
- $(CC) $(ARCHOPTS) -Os -o $(OBJDIR)/s_openal.o -DHW3SOUND -DUNIXCOMMON -shared -nostartfiles -c hardware/s_openal/s_openal.c
-endif
-
-ifdef FILTERS
-$(OBJDIR)/%.o: $(INTERFACE)/filter/%.c
- @echo $< needs deps
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-
-$(OBJDIR)/filters.o: $(INTERFACE)/filter/filters.c $(INTERFACE)/filter/filters.c \
- $(INTERFACE)/filter/filters.h
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-
-$(OBJDIR)/hq2x.o: $(INTERFACE)/filter/hq2x.c $(INTERFACE)/filter/hq2x.c \
- $(INTERFACE)/filter/filters.h
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-
-$(OBJDIR)/lq2x.o: $(INTERFACE)/filter/lq2x.c $(INTERFACE)/filter/lq2x.c \
- $(INTERFACE)/filter/filters.h $(INTERFACE)/filter/interp.h \
- $(INTERFACE)/filter/hq2x.h $(INTERFACE)/filter/lq2x.h
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-endif
-endif
-
-#############################################################
-#
-#############################################################
+
+# GNU Make makefile for SRB2
+#############################################################################
+# Copyright (C) 1998-2000 by DooM Legacy Team.
+# Copyright (C) 2003-2018 by Sonic Team Junior.
+#
+# This program is free software distributed under the
+# terms of the GNU General Public License, version 2.
+# See the 'LICENSE' file for more details.
+#
+# -DLINUX -> use for the GNU/Linux specific
+# -DHAVE_SDL -> use for the SDL interface
+#
+# Sets:
+# Compile the Mingw version with 'make MINGW=1'
+# Compile the SDL/Mingw version with 'make MINGW=1 SDL=1'
+# Compile the SDL/Linux version with 'make LINUX=1'
+# Compile the SDL/Solaris version with 'make SOLARIS=1'
+# Compile the SDL/FreeBSD version with 'gmake FREEBSD=1'
+# Compile the SDL/Cygwin version with 'make CYGWIN32=1'
+# Compile the SDL/other version try with 'make SDL=1'
+#
+# 'Targets':
+# clean
+# Remove all object files
+# cleandep
+# Remove depend.dep
+# dll
+# compile primary HW render DLL/SO
+# all_dll
+# compile all HW render and 3D sound DLLs for the set
+# opengl_dll
+# Pure Mingw only, compile OpenGL HW render DLL
+# minigl_dll
+# Pure Mingw only, compile MiniGL HW render DLL
+# ds3d_dll
+# Pure Mingw only, compile DirectX DirectSound HW sound DLL
+# fmod_dll
+# Pure Mingw only, compile FMOD HW sound DLL
+# openal_dll
+# Pure Mingw only, compile OpenAL HW sound DLL
+# fmod_so
+# Non-Mingw, compile FMOD HW sound SO
+# openal_so
+# Non-Mingw, compile OpenAL HW sound SO
+#
+#
+# Addon:
+# To Cross-Compile, CC=gcc-version make * PREFIX=
+# Compile with GCC 2.97 version, add 'GCC29=1'
+# Compile with GCC 4.0x version, add 'GCC40=1'
+# Compile with GCC 4.1x version, add 'GCC41=1'
+# Compile with GCC 4.2x version, add 'GCC42=1'
+# Compile with GCC 4.3x version, add 'GCC43=1'
+# Compile with GCC 4.4x version, add 'GCC44=1'
+# Compile with GCC 4.5x version, add 'GCC45=1'
+# Compile with GCC 4.6x version, add 'GCC46=1'
+# Compile a profile version, add 'PROFILEMODE=1'
+# Compile a debug version, add 'DEBUGMODE=1'
+# Compile with less warnings, add 'RELAXWARNINGS=1'
+# Generate compiler errors for most compiler warnings, add 'ERRORMODE=1'
+# Compile without 3D hardware support, add 'NOHW=1'
+# Compile with GDBstubs, add 'RDB=1'
+# Compile without PNG, add 'NOPNG=1'
+# Compile without zlib, add 'NOZLIB=1'
+#
+# Addon for SDL:
+# To Cross-Compile, add 'SDL_CONFIG=/usr/*/bin/sdl-config'
+# Compile without SDL_Mixer, add 'NOMIXER=1'
+# Compile without BSD API, add 'NONET=1'
+# Compile without IPX/SPX, add 'NOIPX=1'
+# Compile Mingw/SDL with S_DS3S, add 'DS3D=1'
+# Compile without libopenmpt, add 'NOOPENMPT=1'
+# Compile with S_FMOD3D, add 'FMOD=1' (WIP)
+# Compile with S_OPENAL, add 'OPENAL=1' (WIP)
+# To link with the whole SDL_Image lib to load Icons, add 'SDL_IMAGE=1' but it isn't not realy needed
+# To link with SDLMain to hide console or make on a console-less binary, add 'SDLMAIN=1'
+#
+#############################################################################
+
+ALL_SYSTEMS=\
+ PANDORA\
+ LINUX64\
+ MINGW64\
+ HAIKU\
+ DUMMY\
+ MINGW\
+ UNIX\
+ LINUX\
+ SOLARIS\
+ FREEBSD\
+ MACOSX\
+ SDL\
+
+# check for user specified system
+ifeq (,$(filter $(ALL_SYSTEMS),$(.VARIABLES)))
+ifeq ($(OS),Windows_NT) # all windows are Windows_NT...
+
+ $(info Detected a Windows system, compiling for 32-bit MinGW SDL2...)
+
+ # go for a 32-bit sdl mingw exe by default
+ MINGW=1
+ SDL=1
+ WINDOWSHELL=1
+ HAVE_DISCORDRPC=0
+ NOUPX=1
+
+else # if you on the *nix
+
+ system:=$(shell uname -s)
+
+ ifeq ($(system),Linux)
+ new_system=LINUX
+ else
+
+ $(error \
+ Could not automatically detect your system,\
+ try specifying a system manually)
+
+ endif
+
+ ifeq ($(shell getconf LONG_BIT),64)
+ system+=64-bit
+ new_system:=$(new_system)64
+ endif
+
+ $(info Detected $(system) ($(new_system))...)
+ $(new_system)=1
+
+endif
+endif
+
+
+# SRB2 data files
+D_DIR?=../bin/Resources
+D_FILES=$(D_DIR)/srb2.srb \
+ $(D_DIR)/patch.dta \
+ #$(D_DIR)/music.dta \
+ $(D_DIR)/gfx.kart \
+ $(D_DIR)/textures.kart \
+ $(D_DIR)/chars.kart \
+ $(D_DIR)/maps.kart \
+ $(D_DIR)/sounds.kart \
+ $(D_DIR)/patch.kart \
+ $(D_DIR)/music.kart \
+
+PKG_CONFIG?=pkg-config
+
+ifdef PANDORA
+LINUX=1
+endif
+
+ifdef LINUX64
+LINUX=1
+NONX86=1
+# LINUX64 does not imply X86_64=1; could mean ARM64 or Itanium
+endif
+
+ifdef MINGW64
+MINGW=1
+NONX86=1
+# MINGW64 should not necessarily imply X86_64=1, but we make that assumption elsewhere
+# Once that changes, remove this
+X86_64=1
+endif #ifdef MINGW64
+
+ifdef HAIKU
+SDL=1
+endif
+
+include Makefile.cfg
+
+ifdef DUMMY
+NOPNG=1
+NOZLIB=1
+NONET=1
+NOHW=1
+NOIPX=1
+EXENAME?=srb2dummy
+OBJS=$(OBJDIR)/i_video.o
+LIBS=-lm
+endif
+
+ifdef HAIKU
+NOIPX=1
+ifndef NONET
+LIBS=-lnetwork
+endif
+CFLAGS+=-DUNIXCOMMON
+PNG_CFLAGS?=
+PNG_LDFLAGS?=-lpng
+endif
+
+ifdef PANDORA
+NONX86=1
+NOHW=1
+endif
+
+ifndef NOOPENMPT
+HAVE_OPENMPT=1
+endif
+
+ifdef MINGW
+include win32/Makefile.cfg
+endif #ifdef MINGW
+
+ifdef UNIX
+UNIXCOMMON=1
+endif
+
+ifdef LINUX
+UNIXCOMMON=1
+ifndef NOGME
+HAVE_LIBGME=1
+endif
+endif
+
+ifdef SOLARIS
+UNIXCOMMON=1
+endif
+
+ifdef FREEBSD
+UNIXCOMMON=1
+endif
+
+ifdef MACOSX
+UNIXCOMMON=1
+endif
+
+ifdef SDL
+ include sdl/Makefile.cfg
+endif #ifdef SDL
+
+ifdef DISTCC
+ CC:=distcc $(CC)
+endif
+
+ifdef CCACHE
+ CC:=ccache $(CC)
+endif
+
+MSGFMT?=msgfmt
+
+ifndef ECHO
+ REMOVE:=@$(REMOVE)
+ CC:=@$(CC)
+ CXX:=@$(CXX)
+ OBJCOPY:=@$(OBJCOPY)
+ OBJDUMP:=@$(OBJDUMP)
+ STRIP:=@$(STRIP)
+ WINDRES:=@$(WINDRES)
+ CP:=@$(CP)
+ MKDIR:=@$(MKDIR)
+ MKISOFS:=@$(MKISOFS)
+ DD:=@$(DD)
+ NDSTOOL:=@$(NDSTOOL)
+ GZIP:=@$(GZIP)
+ MSGFMT:=@$(MSGFMT)
+ UPX:=@$(UPX)
+ UPX_OPTS+=-q
+endif
+
+ifdef NONET
+ OPTS+=-DNONET
+ NOCURL=1
+else
+ifdef NO_IPV6
+ OPTS+=-DNO_IPV6
+endif
+endif
+
+ifdef NOHW
+ OPTS+=-DNOHW
+else
+ #Hurdler: not really supported and not tested recently
+ #OPTS+=-DUSE_PALETTED_TEXTURE
+ OPTS+=-DHWRENDER
+ OBJS+=$(OBJDIR)/hw_bsp.o $(OBJDIR)/hw_draw.o $(OBJDIR)/hw_light.o \
+ $(OBJDIR)/hw_main.o $(OBJDIR)/hw_clip.o $(OBJDIR)/hw_md2.o $(OBJDIR)/hw_cache.o $(OBJDIR)/hw_trick.o \
+ $(OBJDIR)/hw_md2load.o $(OBJDIR)/hw_md3load.o $(OBJDIR)/hw_model.o $(OBJDIR)/u_list.o $(OBJDIR)/hw_batching.o
+endif
+
+OPTS += -DCOMPVERSION
+
+ifndef NONX86
+ifndef GCC29
+ ARCHOPTS?=-msse3 -mfpmath=sse
+else
+ ARCHOPTS?=-mpentium
+endif
+else
+ifdef X86_64
+ ARCHOPTS?=-march=native -O3 -mfpmath=both -funroll-loops -finline-functions -funswitch-loops -fpeel-loops -fipa-pta -fprefetch-loop-arrays -ftree-loop-linear -ftree-vectorize -floop-strip-mine -fgraphite-identity -falign-functions -falign-loops -ftree-loop-distribution -floop-nest-optimize
+endif
+endif
+
+
+ifndef NOPNG
+OPTS+=-DHAVE_PNG
+
+ifdef PNG_PKGCONFIG
+PNG_CFLAGS?=$(shell $(PKG_CONFIG) $(PNG_PKGCONFIG) --cflags)
+PNG_LDFLAGS?=$(shell $(PKG_CONFIG) $(PNG_PKGCONFIG) --libs)
+else
+ifdef PREFIX
+PNG_CONFIG?=$(PREFIX)-libpng-config
+else
+PNG_CONFIG?=libpng-config
+endif
+
+ifdef PNG_STATIC
+PNG_CFLAGS?=$(shell $(PNG_CONFIG) --static --cflags)
+PNG_LDFLAGS?=$(shell $(PNG_CONFIG) --static --ldflags)
+else
+PNG_CFLAGS?=$(shell $(PNG_CONFIG) --cflags)
+PNG_LDFLAGS?=$(shell $(PNG_CONFIG) --ldflags)
+endif
+endif
+
+ifdef LINUX
+PNG_CFLAGS+=-D_LARGEFILE64_SOURCE
+endif
+
+LIBS+=$(PNG_LDFLAGS)
+CFLAGS+=$(PNG_CFLAGS)
+
+OBJS+=$(OBJDIR)/apng.o
+endif
+
+ifdef HAVE_LIBGME
+OPTS+=-DHAVE_LIBGME
+
+LIBGME_PKGCONFIG?=libgme
+LIBGME_CFLAGS?=$(shell $(PKG_CONFIG) $(LIBGME_PKGCONFIG) --cflags)
+LIBGME_LDFLAGS?=$(shell $(PKG_CONFIG) $(LIBGME_PKGCONFIG) --libs)
+
+LIBS+=$(LIBGME_LDFLAGS)
+CFLAGS+=$(LIBGME_CFLAGS)
+endif
+
+ifdef HAVE_OPENMPT
+OPTS+=-DHAVE_OPENMPT
+
+LIBOPENMPT_PKGCONFIG?=libopenmpt
+LIBOPENMPT_CFLAGS?=$(shell $(PKG_CONFIG) $(LIBOPENMPT_PKGCONFIG) --cflags)
+LIBOPENMPT_LDFLAGS?=$(shell $(PKG_CONFIG) $(LIBOPENMPT_PKGCONFIG) --libs)
+
+LIBS+=$(LIBOPENMPT_LDFLAGS)
+CFLAGS+=$(LIBOPENMPT_CFLAGS)
+endif
+
+ifndef NOZLIB
+OPTS+=-DHAVE_ZLIB
+ZLIB_PKGCONFIG?=zlib
+ZLIB_CFLAGS?=$(shell $(PKG_CONFIG) $(ZLIB_PKGCONFIG) --cflags)
+ZLIB_LDFLAGS?=$(shell $(PKG_CONFIG) $(ZLIB_PKGCONFIG) --libs)
+
+LIBS+=$(ZLIB_LDFLAGS)
+CFLAGS+=$(ZLIB_CFLAGS)
+else
+NOPNG=1
+endif
+
+ifndef NOCURL
+OPTS+=-DHAVE_CURL
+CURLCONFIG?=curl-config
+CURL_CFLAGS?=$(shell $(CURLCONFIG) --cflags)
+CURL_LDFLAGS?=$(shell $(CURLCONFIG) --libs)
+
+LIBS+=$(CURL_LDFLAGS)
+CFLAGS+=$(CURL_CFLAGS)
+endif
+
+ifdef STATIC
+LIBS:=-static $(LIBS)
+endif
+
+ifdef HAVE_MINIUPNPC
+ifdef NONET
+HAVE_MINIUPNPC=''
+else
+LIBS+=-lminiupnpc
+ifdef MINGW
+LIBS+=-lws2_32 -liphlpapi
+endif
+CFLAGS+=-DHAVE_MINIUPNPC
+endif
+endif
+
+ifdef HAVE_DISCORDRPC
+LIBS+=-ldiscord-rpc
+CFLAGS+=-DHAVE_DISCORDRPC -DUSE_STUN
+OBJS+=$(OBJDIR)/discord.o $(OBJDIR)/stun.o
+endif
+
+ifndef NO_LUA
+ include blua/Makefile.cfg
+endif
+
+ifdef NOMD5
+ OPTS+=-DNOMD5
+else
+ OBJS:=$(OBJDIR)/md5.o $(OBJS)
+endif
+
+ifdef NOPOSTPROCESSING
+ OPTS+=-DNOPOSTPROCESSING
+endif
+
+ OPTS:=-fno-exceptions $(OPTS)
+
+ifdef MOBJCONSISTANCY
+ OPTS+=-DMOBJCONSISTANCY
+endif
+
+ifdef PACKETDROP
+ OPTS+=-DPACKETDROP
+endif
+
+ifdef DEBUGMODE
+
+ # build with debugging information
+ WINDRESFLAGS = -D_DEBUG
+ifdef GCC48
+ CFLAGS+=-Og
+else
+ CFLAGS+=-O0
+endif
+ CFLAGS+= -Wall -DPARANOIA -DRANGECHECK -DPACKETDROP -DMOBJCONSISTANCY
+else
+
+
+ # build a normal optimised version
+ WINDRESFLAGS = -DNDEBUG
+ CFLAGS+=-O3
+endif
+ CFLAGS+=-g $(OPTS) $(ARCHOPTS) $(WINDRESFLAGS)
+
+ifdef PROFILEMODE
+ # build with profiling information
+ CFLAGS+=-pg
+ LDFLAGS+=-pg
+endif
+
+ifdef ZDEBUG
+ CPPFLAGS+=-DZDEBUG
+endif
+
+ifdef DUMPCONSISTENCY
+ CPPFLAGS+=-DDUMPCONSISTENCY
+endif
+
+ifdef DEVELOP
+ CPPFLAGS+=-DDEVELOP
+endif
+
+OPTS+=$(CPPFLAGS)
+
+# default EXENAME if all else fails
+EXENAME?=srb2
+DBGNAME?=$(EXENAME).debug
+
+# $(OBJDIR)/dstrings.o \
+
+# not too sophisticated dependency
+# SRB2kart kart.o on line 433 below
+OBJS:=$(i_main_o) \
+ $(OBJDIR)/comptime.o \
+ $(OBJDIR)/string.o \
+ $(OBJDIR)/d_async.o \
+ $(OBJDIR)/d_main.o \
+ $(OBJDIR)/d_protocol.o \
+ $(OBJDIR)/d_clisrv.o \
+ $(OBJDIR)/d_net.o \
+ $(OBJDIR)/d_netfil.o \
+ $(OBJDIR)/d_netcmd.o \
+ $(OBJDIR)/dehacked.o \
+ $(OBJDIR)/z_zone.o \
+ $(OBJDIR)/f_finale.o \
+ $(OBJDIR)/f_wipe.o \
+ $(OBJDIR)/g_game.o \
+ $(OBJDIR)/g_input.o \
+ $(OBJDIR)/am_map.o \
+ $(OBJDIR)/command.o \
+ $(OBJDIR)/console.o \
+ $(OBJDIR)/hu_stuff.o \
+ $(OBJDIR)/y_inter.o \
+ $(OBJDIR)/st_stuff.o \
+ $(OBJDIR)/k_kart.o \
+ $(OBJDIR)/m_aatree.o \
+ $(OBJDIR)/m_anigif.o \
+ $(OBJDIR)/m_argv.o \
+ $(OBJDIR)/m_bbox.o \
+ $(OBJDIR)/m_cheat.o \
+ $(OBJDIR)/m_cond.o \
+ $(OBJDIR)/m_fixed.o \
+ $(OBJDIR)/m_menu.o \
+ $(OBJDIR)/m_misc.o \
+ $(OBJDIR)/m_perfstats.o \
+ $(OBJDIR)/m_random.o \
+ $(OBJDIR)/m_queue.o \
+ $(OBJDIR)/info.o \
+ $(OBJDIR)/p_ceilng.o \
+ $(OBJDIR)/p_enemy.o \
+ $(OBJDIR)/p_floor.o \
+ $(OBJDIR)/p_inter.o \
+ $(OBJDIR)/p_lights.o \
+ $(OBJDIR)/p_map.o \
+ $(OBJDIR)/p_maputl.o \
+ $(OBJDIR)/p_mobj.o \
+ $(OBJDIR)/p_polyobj.o\
+ $(OBJDIR)/p_saveg.o \
+ $(OBJDIR)/p_setup.o \
+ $(OBJDIR)/p_sight.o \
+ $(OBJDIR)/p_spec.o \
+ $(OBJDIR)/p_telept.o \
+ $(OBJDIR)/p_tick.o \
+ $(OBJDIR)/p_user.o \
+ $(OBJDIR)/p_slopes.o \
+ $(OBJDIR)/tables.o \
+ $(OBJDIR)/r_bsp.o \
+ $(OBJDIR)/r_data.o \
+ $(OBJDIR)/r_draw.o \
+ $(OBJDIR)/r_fps.o \
+ $(OBJDIR)/r_main.o \
+ $(OBJDIR)/r_plane.o \
+ $(OBJDIR)/r_segs.o \
+ $(OBJDIR)/r_sky.o \
+ $(OBJDIR)/r_splats.o \
+ $(OBJDIR)/r_patch.o \
+ $(OBJDIR)/r_things.o \
+ $(OBJDIR)/screen.o \
+ $(OBJDIR)/v_video.o \
+ $(OBJDIR)/s_sound.o \
+ $(OBJDIR)/sounds.o \
+ $(OBJDIR)/w_wad.o \
+ $(OBJDIR)/filesrch.o \
+ $(OBJDIR)/mserv.o \
+ $(OBJDIR)/http-mserv.o\
+ $(OBJDIR)/i_tcp.o \
+ $(OBJDIR)/i_time.o \
+ $(OBJDIR)/lzf.o \
+ $(OBJDIR)/b_bot.o \
+ $(i_net_o) \
+ $(i_system_o) \
+ $(i_sound_o) \
+ $(OBJS)
+
+# List of languages to compile.
+# For reference, this is the command I use to build a srb2.pot file from the source code.
+# (The listed source files are the ones containing translated strings).
+# FILES=""; for file in `find ./ | grep "\.c" | grep -v svn`; do [ "`grep "M_GetText(" $file`" ] && FILES="$FILES $file"; done; xgettext -d srb2 -o locale/srb2.pot -kM_GetText -F --no-wrap $FILES
+ifdef GETTEXT
+POS:=$(BIN)/en.mo
+
+OPTS+=-DGETTEXT
+endif
+
+ifdef PANDORA
+all: pre-build $(BIN)/$(PNDNAME)
+endif
+
+ifdef MINGW
+ifndef SDL
+all: pre-build $(BIN)/$(EXENAME) dll
+endif
+endif
+
+ifdef SDL
+all: pre-build $(BIN)/$(EXENAME)
+endif
+
+ifdef DUMMY
+all: $(BIN)/$(EXENAME)
+endif
+
+cleandep:
+ $(REMOVE) $(OBJDIR)/depend.dep
+ $(REMOVE) comptime.h
+
+pre-build:
+ifdef WINDOWSHELL
+ -$(.)..\comptime.bat .
+else
+ -$(.)../comptime.sh .
+endif
+
+clean:
+ $(REMOVE) *~ *.flc
+ $(REMOVE) $(OBJDIR)/*.o
+
+ifdef MINGW
+ $(REMOVE) $(OBJDIR)/*.res
+endif
+
+ifdef CYGWIN32
+ $(REMOVE) $(OBJDIR)/*.res
+endif
+
+
+# executable
+
+$(BIN)/$(EXENAME): $(POS) $(OBJS)
+ -$(MKDIR) $(BIN)
+ @echo Linking $(EXENAME)...
+ $(LD) $(LDFLAGS) $(OBJS) -o $(BIN)/$(EXENAME) $(LIBS)
+ifndef VALGRIND
+ifndef NOOBJDUMP
+ @echo Dumping debugging info
+ $(OBJDUMP) $(OBJDUMP_OPTS) $(BIN)/$(EXENAME) > $(BIN)/$(DBGNAME).txt
+ -$(GZIP) $(GZIP_OPTS) $(BIN)/$(DBGNAME).txt
+ifndef WINDOWSHELL
+ -$(GZIP) $(GZIP_OPT2) $(BIN)/$(DBGNAME).txt
+endif
+endif
+
+# mac os x lsdlsrb2 does not like objcopy
+ifndef MACOSX
+ $(OBJCOPY) $(BIN)/$(EXENAME) $(BIN)/$(DBGNAME)
+ $(OBJCOPY) --strip-debug $(BIN)/$(EXENAME)
+ -$(OBJCOPY) --add-gnu-debuglink=$(BIN)/$(DBGNAME) $(BIN)/$(EXENAME)
+endif
+ifndef NOUPX
+ -$(UPX) $(UPX_OPTS) $(BIN)/$(EXENAME)
+endif
+endif
+ @echo Build is done, please look for $(EXENAME) in $(BIN), \(checking for post steps\)
+
+reobjdump:
+ @echo Redumping debugging info
+ $(OBJDUMP) $(OBJDUMP_OPTS) $(BIN)/$(DBGNAME) > $(BIN)/$(DBGNAME).txt
+ -$(GZIP) $(GZIP_OPTS) $(BIN)/$(DBGNAME).txt
+ifndef WINDOWSHELL
+ -$(GZIP) $(GZIP_OPT2) $(BIN)/$(DBGNAME).txt
+endif
+
+$(OBJDIR):
+ -$(MKDIR) $(OBJDIR)
+
+ifndef SDL
+ifdef NOHW
+dll :
+else
+dll : opengl_dll
+endif
+ifdef MINGW
+all_dll: opengl_dll ds3d_dll fmod_dll openal_dll
+
+opengl_dll: $(BIN)/r_opengl.dll
+$(BIN)/r_opengl.dll: $(OBJDIR)/ogl_win.o $(OBJDIR)/r_opengl.o
+ -$(MKDIR) $(BIN)
+ @echo Linking R_OpenGL.dll...
+ $(CC) --shared $^ -o $@ -g -Wl,--add-stdcall-alias -lgdi32 -static-libgcc
+ifndef NOUPX
+ -$(UPX) $(UPX_OPTS) $@
+endif
+
+ds3d_dll: $(BIN)/s_ds3d.dll
+$(BIN)/s_ds3d.dll: $(OBJDIR)/s_ds3d.o
+ @echo Linking S_DS3d.dll...
+ $(CC) --shared $^ -o $@ -g -Wl,--add-stdcall-alias -ldsound -luuid
+
+fmod_dll: $(BIN)/s_fmod.dll
+$(BIN)/s_fmod.dll: $(OBJDIR)/s_fmod.o
+ -$(MKDIR) $(BIN)
+ @echo Linking S_FMOD.dll...
+ $(CC) --shared $^ -o $@ -g -Wl,--add-stdcall-alias -lfmod
+
+openal_dll: $(BIN)/s_openal.dll
+$(BIN)/s_openal.dll: $(OBJDIR)/s_openal.o
+ -$(MKDIR) $(BIN)
+ @echo Linking S_OpenAL.dll...
+ $(CC) --shared $^ -o $@ -g -Wl,--add-stdcall-alias -lopenal32
+else
+all_dll: fmod_so openal_so
+
+fmod_so: $(BIN)/s_fmod.so
+$(BIN)/s_fmod.so: $(OBJDIR)/s_fmod.o
+ -$(MKDIR) $(BIN)
+ @echo Linking S_FMOD.so...
+ $(CC) --shared $^ -o $@ -g --nostartfiles -lm -lfmod
+
+openal_so: $(BIN)/s_openal.so
+$(BIN)/s_openal.so: $(OBJDIR)/s_openal.o
+ -$(MKDIR) $(BIN)
+ @echo Linking S_OpenAL.so...
+ $(CC) --shared $^ -o $@ -g --nostartfiles -lm -lopenal
+endif
+
+else
+ifdef SDL
+ifdef MINGW
+$(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \
+ doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \
+ command.h hardware/hw_data.h hardware/hw_defs.h hardware/hw_md2.h \
+ hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h \
+ hardware/hw_md2load.h hardware/hw_md3load.h hardware/hw_model.h hardware/u_list.h \
+ am_map.h d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \
+ p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h
+ $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
+else
+$(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \
+ doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \
+ command.h hardware/hw_data.h hardware/hw_defs.h hardware/hw_md2.h \
+ hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h \
+ hardware/hw_md2load.h hardware/hw_md3load.h hardware/hw_model.h hardware/u_list.h \
+ am_map.h d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \
+ p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h
+ $(CC) $(CFLAGS) $(WFLAGS) -I/usr/X11R6/include -c $< -o $@
+endif
+endif
+
+endif
+
+#dependecy made by gcc itself !
+$(OBJS):
+ifndef DUMMY
+-include $(OBJDIR)/depend.dep
+endif
+
+$(OBJDIR)/depend.dep:
+ @echo "Creating dependency file, depend.dep"
+ @echo > comptime.h
+ -$(MKDIR) $(OBJDIR)
+ $(CC) $(CFLAGS) -MM *.c > $(OBJDIR)/depend.ped
+ $(CC) $(CFLAGS) -MM $(INTERFACE)/*.c >> $(OBJDIR)/depend.ped
+ifndef NOHW
+ $(CC) $(CFLAGS) -MM hardware/*.c >> $(OBJDIR)/depend.ped
+endif
+ifndef NO_LUA
+ $(CC) $(CFLAGS) -MM blua/*.c >> $(OBJDIR)/depend.ped
+endif
+ @sed -e 's,\(.*\)\.o: ,$(subst /,\/,$(OBJDIR))\/&,g' < $(OBJDIR)/depend.ped > $(OBJDIR)/depend.dep
+ $(REMOVE) $(OBJDIR)/depend.ped
+ @echo "Created dependency file, depend.dep"
+
+ifdef VALGRIND
+$(OBJDIR)/z_zone.o: z_zone.c
+ $(CC) $(CFLAGS) $(WFLAGS) -DHAVE_VALGRIND $(VALGRIND_CFLAGS) -c $< -o $@
+endif
+
+$(OBJDIR)/comptime.o: comptime.c pre-build
+ $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
+
+$(BIN)/%.mo: locale/%.po
+ -$(MKDIR) $(BIN)
+ $(MSGFMT) -f -o $@ $<
+
+$(OBJDIR)/%.o: %.c
+ $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
+
+$(OBJDIR)/%.o: $(INTERFACE)/%.c
+ $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
+
+ifdef MACOSX
+$(OBJDIR)/%.o: sdl/macosx/%.c
+ $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
+endif
+
+$(OBJDIR)/%.o: hardware/%.c
+ $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
+
+$(OBJDIR)/%.o: blua/%.c
+ $(CC) $(CFLAGS) $(LUA_CFLAGS) $(WFLAGS) -c $< -o $@
+
+$(OBJDIR)/%.o: %.s
+ $(CC) $(OPTS) -x assembler-with-cpp -c $< -o $@
+
+$(OBJDIR)/SRB2.res: win32/Srb2win.rc win32/afxres.h win32/resource.h
+ $(WINDRES) -i $< -O rc $(WINDRESFLAGS) --include-dir=win32 -o $@ -O coff
+
+ifdef SDL
+
+ifdef MINGW
+$(OBJDIR)/win_dbg.o: win32/win_dbg.c
+ $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
+endif
+
+ifdef STATICHS
+$(OBJDIR)/s_openal.o: hardware/s_openal/s_openal.c hardware/hw3dsdrv.h \
+ hardware/hw_dll.h
+ $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
+
+$(OBJDIR)/s_fmod.o: hardware/s_fmod/s_fmod.c hardware/hw3dsdrv.h \
+ hardware/hw_dll.h
+ $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
+
+ifdef MINGW
+$(OBJDIR)/s_ds3d.o: hardware/s_ds3d/s_ds3d.c hardware/hw3dsdrv.h \
+ hardware/hw_dll.h
+ $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
+endif
+else
+
+$(OBJDIR)/s_fmod.o: hardware/s_fmod/s_fmod.c hardware/hw3dsdrv.h \
+ hardware/hw_dll.h
+ $(CC) $(ARCHOPTS) -Os -o $(OBJDIR)/s_fmod.o -DHW3SOUND -DUNIXCOMMON -shared -nostartfiles -c hardware/s_fmod/s_fmod.c
+
+$(OBJDIR)/s_openal.o: hardware/s_openal/s_openal.c hardware/hw3dsdrv.h \
+ hardware/hw_dll.h
+ $(CC) $(ARCHOPTS) -Os -o $(OBJDIR)/s_openal.o -DHW3SOUND -DUNIXCOMMON -shared -nostartfiles -c hardware/s_openal/s_openal.c
+endif
+
+ifdef FILTERS
+$(OBJDIR)/%.o: $(INTERFACE)/filter/%.c
+ @echo $< needs deps
+ $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
+
+$(OBJDIR)/filters.o: $(INTERFACE)/filter/filters.c $(INTERFACE)/filter/filters.c \
+ $(INTERFACE)/filter/filters.h
+ $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
+
+$(OBJDIR)/hq2x.o: $(INTERFACE)/filter/hq2x.c $(INTERFACE)/filter/hq2x.c \
+ $(INTERFACE)/filter/filters.h
+ $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
+
+$(OBJDIR)/lq2x.o: $(INTERFACE)/filter/lq2x.c $(INTERFACE)/filter/lq2x.c \
+ $(INTERFACE)/filter/filters.h $(INTERFACE)/filter/interp.h \
+ $(INTERFACE)/filter/hq2x.h $(INTERFACE)/filter/lq2x.h
+ $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
+endif
+endif
+
+#############################################################
+#
+#############################################################
diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c
new file mode 100644
index 000000000..b56278c7d
--- /dev/null
+++ b/src/hardware/hw_batching.c
@@ -0,0 +1,488 @@
+// SONIC ROBO BLAST 2
+//-----------------------------------------------------------------------------
+// Copyright (C) 2020-2023 by Sonic Team Junior.
+//
+// This program is free software distributed under the
+// terms of the GNU General Public License, version 2.
+// See the 'LICENSE' file for more details.
+//-----------------------------------------------------------------------------
+/// \file hw_batching.c
+/// \brief Draw call batching and related things.
+
+#ifdef HWRENDER
+#include "hw_glob.h"
+#include "hw_batching.h"
+#include "hw_main.h"
+#include "../i_system.h"
+
+// The texture for the next polygon given to HWR_ProcessPolygon.
+// Set with HWR_SetCurrentTexture.
+GLMipmap_t *current_texture = NULL;
+
+boolean currently_batching = false;
+
+FOutVector* finalVertexArray = NULL;// contains subset of sorted vertices and texture coordinates to be sent to gpu
+UINT32* finalVertexIndexArray = NULL;// contains indexes for glDrawElements, taking into account fan->triangles conversion
+// NOTE have this alloced as 3x finalVertexArray size
+int finalVertexArrayAllocSize = 65536;
+//GLubyte* colorArray = NULL;// contains color data to be sent to gpu, if needed
+//int colorArrayAllocSize = 65536;
+// not gonna use this for now, just sort by color and change state when it changes
+// later maybe when using vertex attributes if it's needed
+
+PolygonArrayEntry* polygonArray = NULL;// contains the polygon data from DrawPolygon, waiting to be processed
+int polygonArraySize = 0;
+UINT32* polygonIndexArray = NULL;// contains sorting pointers for polygonArray
+int polygonArrayAllocSize = 65536;
+
+FOutVector* unsortedVertexArray = NULL;// contains unsorted vertices and texture coordinates from DrawPolygon
+int unsortedVertexArraySize = 0;
+int unsortedVertexArrayAllocSize = 65536;
+
+// Enables batching mode. HWR_ProcessPolygon will collect polygons instead of passing them directly to the rendering backend.
+// Call HWR_RenderBatches to render all the collected geometry.
+void HWR_StartBatching(void)
+{
+ if (currently_batching)
+ I_Error("Repeat call to HWR_StartBatching without HWR_RenderBatches");
+
+ // init arrays if that has not been done yet
+ if (!finalVertexArray)
+ {
+ finalVertexArray = malloc(finalVertexArrayAllocSize * sizeof(FOutVector));
+ finalVertexIndexArray = malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32));
+ polygonArray = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry));
+ polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(UINT32));
+ unsortedVertexArray = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector));
+ }
+
+ currently_batching = true;
+}
+
+// This replaces the direct calls to pfnSetTexture in cases where batching is available.
+// The texture selection is saved for the next HWR_ProcessPolygon call.
+// Doing this was easier than getting a texture pointer to HWR_ProcessPolygon.
+void HWR_SetCurrentTexture(GLMipmap_t *texture)
+{
+ if (currently_batching)
+ {
+ current_texture = texture;
+ }
+ else
+ {
+ HWD.pfnSetTexture(texture);
+ }
+}
+
+// If batching is enabled, this function collects the polygon data and the chosen texture
+// for later use in HWR_RenderBatches. Otherwise the rendering backend is used to
+// render the polygon immediately.
+void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, int shader, boolean horizonSpecial)
+{
+ if (currently_batching)
+ {
+ if (!pSurf)
+ I_Error("Got a null FSurfaceInfo in batching");// nulls should not come in the stuff that batching currently applies to
+ if (polygonArraySize == polygonArrayAllocSize)
+ {
+ PolygonArrayEntry* new_array;
+ // ran out of space, make new array double the size
+ polygonArrayAllocSize *= 2;
+ new_array = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry));
+ memcpy(new_array, polygonArray, polygonArraySize * sizeof(PolygonArrayEntry));
+ free(polygonArray);
+ polygonArray = new_array;
+ // also need to redo the index array, dont need to copy it though
+ free(polygonIndexArray);
+ polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(UINT32));
+ }
+
+ while (unsortedVertexArraySize + (int)iNumPts > unsortedVertexArrayAllocSize)
+ {
+ FOutVector* new_array;
+ // need more space for vertices in unsortedVertexArray
+ unsortedVertexArrayAllocSize *= 2;
+ new_array = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector));
+ memcpy(new_array, unsortedVertexArray, unsortedVertexArraySize * sizeof(FOutVector));
+ free(unsortedVertexArray);
+ unsortedVertexArray = new_array;
+ }
+
+ // add the polygon data to the arrays
+
+ polygonArray[polygonArraySize].surf = *pSurf;
+ polygonArray[polygonArraySize].vertsIndex = unsortedVertexArraySize;
+ polygonArray[polygonArraySize].numVerts = iNumPts;
+ polygonArray[polygonArraySize].polyFlags = PolyFlags;
+ polygonArray[polygonArraySize].texture = current_texture;
+ polygonArray[polygonArraySize].shader = shader;
+ polygonArray[polygonArraySize].horizonSpecial = horizonSpecial;
+ polygonArraySize++;
+
+ memcpy(&unsortedVertexArray[unsortedVertexArraySize], pOutVerts, iNumPts * sizeof(FOutVector));
+ unsortedVertexArraySize += iNumPts;
+ }
+ else
+ {
+ if (shader)
+ HWD.pfnSetShader(shader);
+ HWD.pfnDrawPolygon(pSurf, pOutVerts, iNumPts, PolyFlags);
+ }
+}
+
+static int comparePolygons(const void *p1, const void *p2)
+{
+ unsigned int index1 = *(const unsigned int*)p1;
+ unsigned int index2 = *(const unsigned int*)p2;
+ PolygonArrayEntry* poly1 = &polygonArray[index1];
+ PolygonArrayEntry* poly2 = &polygonArray[index2];
+ int diff;
+ INT64 diff64;
+ UINT32 downloaded1 = 0;
+ UINT32 downloaded2 = 0;
+
+ int shader1 = poly1->shader;
+ int shader2 = poly2->shader;
+ // make skywalls and horizon lines first in order
+ if (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial)
+ shader1 = -1;
+ if (poly2->polyFlags & PF_NoTexture || poly2->horizonSpecial)
+ shader2 = -1;
+ diff = shader1 - shader2;
+ if (diff != 0) return diff;
+
+ // skywalls and horizon lines must retain their order for horizon lines to work
+ if (shader1 == -1 && shader2 == -1)
+ return index1 - index2;
+
+ if (poly1->texture)
+ downloaded1 = poly1->texture->downloaded; // there should be a opengl texture name here, usable for comparisons
+ if (poly2->texture)
+ downloaded2 = poly2->texture->downloaded;
+ diff64 = downloaded1 - downloaded2;
+ if (diff64 != 0) return diff64;
+
+ if (HWR_ShouldUsePaletteRendering())
+ {
+ diff = poly1->surf.LightTableId - poly2->surf.LightTableId;
+ if (diff != 0) return diff;
+ }
+
+ diff = poly1->polyFlags - poly2->polyFlags;
+ if (diff != 0) return diff;
+
+ diff64 = poly1->surf.PolyColor.rgba - poly2->surf.PolyColor.rgba;
+ if (diff64 < 0) return -1; else if (diff64 > 0) return 1;
+ diff64 = poly1->surf.TintColor.rgba - poly2->surf.TintColor.rgba;
+ if (diff64 < 0) return -1; else if (diff64 > 0) return 1;
+ diff64 = poly1->surf.FadeColor.rgba - poly2->surf.FadeColor.rgba;
+ if (diff64 < 0) return -1; else if (diff64 > 0) return 1;
+
+ diff = poly1->surf.LightInfo.light_level - poly2->surf.LightInfo.light_level;
+ if (diff != 0) return diff;
+ diff = poly1->surf.LightInfo.fade_start - poly2->surf.LightInfo.fade_start;
+ if (diff != 0) return diff;
+ diff = poly1->surf.LightInfo.fade_end - poly2->surf.LightInfo.fade_end;
+ return diff;
+}
+
+static int comparePolygonsNoShaders(const void *p1, const void *p2)
+{
+ unsigned int index1 = *(const unsigned int*)p1;
+ unsigned int index2 = *(const unsigned int*)p2;
+ PolygonArrayEntry* poly1 = &polygonArray[index1];
+ PolygonArrayEntry* poly2 = &polygonArray[index2];
+ int diff;
+ INT64 diff64;
+
+ GLMipmap_t *texture1 = poly1->texture;
+ GLMipmap_t *texture2 = poly2->texture;
+ UINT32 downloaded1 = 0;
+ UINT32 downloaded2 = 0;
+ if (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial)
+ texture1 = NULL;
+ if (poly2->polyFlags & PF_NoTexture || poly2->horizonSpecial)
+ texture2 = NULL;
+ if (texture1)
+ downloaded1 = texture1->downloaded; // there should be a opengl texture name here, usable for comparisons
+ if (texture2)
+ downloaded2 = texture2->downloaded;
+ // skywalls and horizon lines must retain their order for horizon lines to work
+ if (!texture1 && !texture2)
+ return index1 - index2;
+ diff64 = downloaded1 - downloaded2;
+ if (diff64 != 0) return diff64;
+
+ diff = poly1->polyFlags - poly2->polyFlags;
+ if (diff != 0) return diff;
+
+ diff64 = poly1->surf.PolyColor.rgba - poly2->surf.PolyColor.rgba;
+ if (diff64 < 0) return -1; else if (diff64 > 0) return 1;
+
+ return 0;
+}
+
+// This function organizes the geometry collected by HWR_ProcessPolygon calls into batches and uses
+// the rendering backend to draw them.
+void HWR_RenderBatches(void)
+{
+ int finalVertexWritePos = 0;// position in finalVertexArray
+ int finalIndexWritePos = 0;// position in finalVertexIndexArray
+
+ int polygonReadPos = 0;// position in polygonIndexArray
+
+ int currentShader;
+ int nextShader = 0;
+ GLMipmap_t *currentTexture;
+ GLMipmap_t *nextTexture = NULL;
+ FBITFIELD currentPolyFlags = 0;
+ FBITFIELD nextPolyFlags = 0;
+ FSurfaceInfo currentSurfaceInfo;
+ FSurfaceInfo nextSurfaceInfo;
+
+ int i;
+
+ if (!currently_batching)
+ I_Error("HWR_RenderBatches called without starting batching");
+
+ nextSurfaceInfo.LightInfo.fade_end = 0;
+ nextSurfaceInfo.LightInfo.fade_start = 0;
+ nextSurfaceInfo.LightInfo.light_level = 0;
+
+ currently_batching = false;// no longer collecting batches
+ if (!polygonArraySize)
+ {
+ ps_hw_numpolys.value.i = ps_hw_numcalls.value.i = ps_hw_numshaders.value.i
+ = ps_hw_numtextures.value.i = ps_hw_numpolyflags.value.i
+ = ps_hw_numcolors.value.i = 0;
+ return;// nothing to draw
+ }
+ // init stats vars
+ ps_hw_numpolys.value.i = polygonArraySize;
+ ps_hw_numcalls.value.i = ps_hw_numverts.value.i = 0;
+ ps_hw_numshaders.value.i = ps_hw_numtextures.value.i
+ = ps_hw_numpolyflags.value.i = ps_hw_numcolors.value.i = 1;
+ // init polygonIndexArray
+ for (i = 0; i < polygonArraySize; i++)
+ {
+ polygonIndexArray[i] = i;
+ }
+
+ // sort polygons
+ PS_START_TIMING(ps_hw_batchsorttime);
+ if (cv_grshaders.value && gr_shadersavailable)
+ qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygons);
+ else
+ qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygonsNoShaders);
+ PS_STOP_TIMING(ps_hw_batchsorttime);
+ // sort order
+ // 1. shader
+ // 2. texture
+ // 3. polyflags
+ // 4. colors + light level
+ // not sure about what order of the last 2 should be, or if it even matters
+
+ PS_START_TIMING(ps_hw_batchdrawtime);
+
+ currentShader = polygonArray[polygonIndexArray[0]].shader;
+ currentTexture = polygonArray[polygonIndexArray[0]].texture;
+ currentPolyFlags = polygonArray[polygonIndexArray[0]].polyFlags;
+ currentSurfaceInfo = polygonArray[polygonIndexArray[0]].surf;
+ // For now, will sort and track the colors. Vertex attributes could be used instead of uniforms
+ // and a color array could replace the color calls.
+
+ // set state for first batch
+
+ if (cv_grshaders.value && gr_shadersavailable)
+ {
+ HWD.pfnSetShader(currentShader);
+ }
+
+ if (currentPolyFlags & PF_NoTexture)
+ currentTexture = NULL;
+ else
+ HWD.pfnSetTexture(currentTexture);
+
+ while (1)// note: remember handling notexture polyflag as having texture number 0 (also in comparePolygons)
+ {
+ int firstIndex;
+ int lastIndex;
+
+ boolean stopFlag = false;
+ boolean changeState = false;
+ boolean changeShader = false;
+ boolean changeTexture = false;
+ boolean changePolyFlags = false;
+ boolean changeSurfaceInfo = false;
+
+ // steps:
+ // write vertices
+ // check for changes or end, otherwise go back to writing
+ // changes will affect the next vars and the change bools
+ // end could set flag for stopping
+ // execute draw call
+ // could check ending flag here
+ // change states according to next vars and change bools, updating the current vars and reseting the bools
+ // reset write pos
+ // repeat loop
+
+ int index = polygonIndexArray[polygonReadPos++];
+ int numVerts = polygonArray[index].numVerts;
+ // before writing, check if there is enough room
+ // using 'while' instead of 'if' here makes sure that there will *always* be enough room.
+ // probably never will this loop run more than once though
+ while (finalVertexWritePos + numVerts > finalVertexArrayAllocSize)
+ {
+ FOutVector* new_array;
+ unsigned int* new_index_array;
+ finalVertexArrayAllocSize *= 2;
+ new_array = malloc(finalVertexArrayAllocSize * sizeof(FOutVector));
+ memcpy(new_array, finalVertexArray, finalVertexWritePos * sizeof(FOutVector));
+ free(finalVertexArray);
+ finalVertexArray = new_array;
+ // also increase size of index array, 3x of vertex array since
+ // going from fans to triangles increases vertex count to 3x
+ new_index_array = malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32));
+ memcpy(new_index_array, finalVertexIndexArray, finalIndexWritePos * sizeof(UINT32));
+ free(finalVertexIndexArray);
+ finalVertexIndexArray = new_index_array;
+ }
+ // write the vertices of the polygon
+ memcpy(&finalVertexArray[finalVertexWritePos], &unsortedVertexArray[polygonArray[index].vertsIndex],
+ numVerts * sizeof(FOutVector));
+ // write the indexes, pointing to the fan vertexes but in triangles format
+ firstIndex = finalVertexWritePos;
+ lastIndex = finalVertexWritePos + numVerts;
+ finalVertexWritePos += 2;
+ while (finalVertexWritePos < lastIndex)
+ {
+ finalVertexIndexArray[finalIndexWritePos++] = firstIndex;
+ finalVertexIndexArray[finalIndexWritePos++] = finalVertexWritePos - 1;
+ finalVertexIndexArray[finalIndexWritePos++] = finalVertexWritePos++;
+ }
+
+ if (polygonReadPos >= polygonArraySize)
+ {
+ stopFlag = true;
+ }
+ else
+ {
+ // check if a state change is required, set the change bools and next vars
+ int nextIndex = polygonIndexArray[polygonReadPos];
+ nextShader = polygonArray[nextIndex].shader;
+ nextTexture = polygonArray[nextIndex].texture;
+ nextPolyFlags = polygonArray[nextIndex].polyFlags;
+ nextSurfaceInfo = polygonArray[nextIndex].surf;
+ if (nextPolyFlags & PF_NoTexture)
+ nextTexture = 0;
+ if (currentShader != nextShader && cv_grshaders.value && gr_shadersavailable)
+ {
+ changeState = true;
+ changeShader = true;
+ }
+ if (currentTexture != nextTexture)
+ {
+ changeState = true;
+ changeTexture = true;
+ }
+ if (currentPolyFlags != nextPolyFlags)
+ {
+ changeState = true;
+ changePolyFlags = true;
+ }
+ if ((cv_grshaders.value && gr_shadersavailable) && (HWR_ShouldUsePaletteRendering()))
+ {
+ if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba ||
+ currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba ||
+ currentSurfaceInfo.FadeColor.rgba != nextSurfaceInfo.FadeColor.rgba ||
+ currentSurfaceInfo.LightInfo.light_level != nextSurfaceInfo.LightInfo.light_level ||
+ currentSurfaceInfo.LightInfo.fade_start != nextSurfaceInfo.LightInfo.fade_start ||
+ currentSurfaceInfo.LightInfo.fade_end != nextSurfaceInfo.LightInfo.fade_end ||
+ currentSurfaceInfo.LightTableId != nextSurfaceInfo.LightTableId)
+ {
+ changeState = true;
+ changeSurfaceInfo = true;
+ }
+ }
+ else if (cv_grshaders.value && gr_shadersavailable)
+ {
+ if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba ||
+ currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba ||
+ currentSurfaceInfo.FadeColor.rgba != nextSurfaceInfo.FadeColor.rgba ||
+ currentSurfaceInfo.LightInfo.light_level != nextSurfaceInfo.LightInfo.light_level ||
+ currentSurfaceInfo.LightInfo.fade_start != nextSurfaceInfo.LightInfo.fade_start ||
+ currentSurfaceInfo.LightInfo.fade_end != nextSurfaceInfo.LightInfo.fade_end)
+ {
+ changeState = true;
+ changeSurfaceInfo = true;
+ }
+ }
+ else
+ {
+ if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba)
+ {
+ changeState = true;
+ changeSurfaceInfo = true;
+ }
+ }
+ }
+
+ if (changeState || stopFlag)
+ {
+ // execute draw call
+ HWD.pfnDrawIndexedTriangles(¤tSurfaceInfo, finalVertexArray, finalIndexWritePos, currentPolyFlags, finalVertexIndexArray);
+ // update stats
+ ps_hw_numcalls.value.i++;
+ ps_hw_numverts.value.i += finalIndexWritePos;
+ // reset write positions
+ finalVertexWritePos = 0;
+ finalIndexWritePos = 0;
+ }
+ else continue;
+
+ // if we're here then either its time to stop or time to change state
+ if (stopFlag) break;
+
+ // change state according to change bools and next vars, update current vars and reset bools
+ if (changeShader)
+ {
+ HWD.pfnSetShader(nextShader);
+ currentShader = nextShader;
+ changeShader = false;
+
+ ps_hw_numshaders.value.i++;
+ }
+ if (changeTexture)
+ {
+ // texture should be already ready for use from calls to SetTexture during batch collection
+ HWD.pfnSetTexture(nextTexture);
+ currentTexture = nextTexture;
+ changeTexture = false;
+
+ ps_hw_numtextures.value.i++;
+ }
+ if (changePolyFlags)
+ {
+ currentPolyFlags = nextPolyFlags;
+ changePolyFlags = false;
+
+ ps_hw_numpolyflags.value.i++;
+ }
+ if (changeSurfaceInfo)
+ {
+ currentSurfaceInfo = nextSurfaceInfo;
+ changeSurfaceInfo = false;
+
+ ps_hw_numcolors.value.i++;
+ }
+ // and that should be it?
+ }
+ // reset the arrays (set sizes to 0)
+ polygonArraySize = 0;
+ unsortedVertexArraySize = 0;
+
+ PS_STOP_TIMING(ps_hw_batchdrawtime);
+}
+
+
+#endif // HWRENDER
diff --git a/src/hardware/hw_batching.h b/src/hardware/hw_batching.h
new file mode 100644
index 000000000..bf0b7fc94
--- /dev/null
+++ b/src/hardware/hw_batching.h
@@ -0,0 +1,39 @@
+// SONIC ROBO BLAST 2
+//-----------------------------------------------------------------------------
+// Copyright (C) 1998-2000 by DooM Legacy Team.
+// Copyright (C) 1999-2020 by Sonic Team Junior.
+//
+// This program is free software distributed under the
+// terms of the GNU General Public License, version 2.
+// See the 'LICENSE' file for more details.
+//-----------------------------------------------------------------------------
+/// \file hw_batching.h
+/// \brief Draw call batching and related things.
+
+#ifndef __HWR_BATCHING_H__
+#define __HWR_BATCHING_H__
+
+#include "hw_defs.h"
+#include "hw_data.h"
+#include "hw_drv.h"
+
+typedef struct
+{
+ FSurfaceInfo surf;// surf also has its own polyflags for some reason, but it seems unused
+ unsigned int vertsIndex;// location of verts in unsortedVertexArray
+ FUINT numVerts;
+ FBITFIELD polyFlags;
+ GLMipmap_t *texture;
+ int shader;
+ // this tells batching that the plane belongs to a horizon line and must be drawn in correct order with the skywalls
+ boolean horizonSpecial;
+} PolygonArrayEntry;
+
+void HWR_StartBatching(void);
+void HWR_SetCurrentTexture(GLMipmap_t *texture);
+void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, int shader, boolean horizonSpecial);
+void HWR_RenderBatches(void);
+
+extern boolean currently_batching;
+
+#endif
diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c
index 53547f37e..44d2763cf 100644
--- a/src/hardware/hw_cache.c
+++ b/src/hardware/hw_cache.c
@@ -17,6 +17,7 @@
#include "hw_main.h"
#include "hw_glob.h"
#include "hw_drv.h"
+#include "hw_batching.h"
#include "../doomstat.h" //gamemode
#include "../i_video.h" //rendermode
@@ -592,7 +593,11 @@ GLTexture_t *HWR_GetTexture(INT32 tex, boolean noencore)
if (!grtex->mipmap.grInfo.data && !grtex->mipmap.downloaded)
HWR_GenerateTexture(tex, grtex, noencore);
- HWD.pfnSetTexture(&grtex->mipmap);
+ // If hardware does not have the texture, then call pfnSetTexture to upload it
+ if (!grtex->mipmap.downloaded)
+ HWD.pfnSetTexture(&grtex->mipmap);
+
+ HWR_SetCurrentTexture(&grtex->mipmap);
// The system-memory data can be purged now.
Z_ChangeTag(grtex->mipmap.grInfo.data, PU_HWRCACHE_UNLOCKED);
@@ -676,7 +681,11 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap)
if (!grmip->downloaded && !grmip->grInfo.data)
HWR_CacheFlat(grmip, flatlumpnum);
- HWD.pfnSetTexture(grmip);
+ // If hardware does not have the texture, then call pfnSetTexture to upload it
+ if (!grmip->downloaded)
+ HWD.pfnSetTexture(grmip);
+
+ HWR_SetCurrentTexture(grmip);
// The system-memory data can be purged now.
Z_ChangeTag(grmip->grInfo.data, PU_HWRCACHE_UNLOCKED);
@@ -702,8 +711,11 @@ static void HWR_LoadMappedPatch(GLMipmap_t *grmip, GLPatch_t *gpatch)
Z_Free(patch);
}
-
- HWD.pfnSetTexture(grmip);
+ // If hardware does not have the texture, then call pfnSetTexture to upload it
+ if (!grmip->downloaded)
+ HWD.pfnSetTexture(grmip);
+
+ HWR_SetCurrentTexture(grmip);
// The system-memory data can be purged now.
Z_ChangeTag(grmip->grInfo.data, PU_HWRCACHE_UNLOCKED);
@@ -733,7 +745,11 @@ void HWR_GetPatch(GLPatch_t *gpatch)
Z_Free(ptr);
}
- HWD.pfnSetTexture(gpatch->mipmap);
+ // If hardware does not have the texture, then call pfnSetTexture to upload it
+ if (!gpatch->mipmap->downloaded)
+ HWD.pfnSetTexture(gpatch->mipmap);
+
+ HWR_SetCurrentTexture(gpatch->mipmap);
// The system-memory patch data can be purged now.
Z_ChangeTag(gpatch->mipmap->grInfo.data, PU_HWRCACHE_UNLOCKED);
diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c
index 71af8172f..f7725e08d 100644
--- a/src/hardware/hw_draw.c
+++ b/src/hardware/hw_draw.c
@@ -122,7 +122,7 @@ void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option)
flags |= PF_ForceWrapY;
// clip it since it is used for bunny scroll in doom I
- HWD.pfnDrawPolygon(NULL, v, 4, flags, false);
+ HWD.pfnDrawPolygon(NULL, v, 4, flags);
}
void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap)
@@ -300,10 +300,10 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t
else if (alphalevel == 15) Surf.PolyColor.s.alpha = softwaretranstogl_hi[hudtrans];
else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel];
flags |= PF_Modulated;
- HWD.pfnDrawPolygon(&Surf, v, 4, flags, false);
+ HWD.pfnDrawPolygon(&Surf, v, 4, flags);
}
else
- HWD.pfnDrawPolygon(NULL, v, 4, flags, false);
+ HWD.pfnDrawPolygon(NULL, v, 4, flags);
}
void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h)
@@ -454,10 +454,10 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal
else if (alphalevel == 15) Surf.PolyColor.s.alpha = softwaretranstogl_hi[cv_translucenthud.value];
else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel];
flags |= PF_Modulated;
- HWD.pfnDrawPolygon(&Surf, v, 4, flags, false);
+ HWD.pfnDrawPolygon(&Surf, v, 4, flags);
}
else
- HWD.pfnDrawPolygon(NULL, v, 4, flags, false);
+ HWD.pfnDrawPolygon(NULL, v, 4, flags);
}
// ==========================================================================
@@ -533,7 +533,7 @@ void HWR_DrawFlatFill (INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum
// BTW, I see we put 0 for PFs, and If I'm right, that
// means we take the previous PFs as default
// how can we be sure they are ok?
- HWD.pfnDrawPolygon(NULL, v, 4, PF_NoDepthTest, false); //PF_Translucent);
+ HWD.pfnDrawPolygon(NULL, v, 4, PF_NoDepthTest); //PF_Translucent);
}
@@ -576,7 +576,7 @@ void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength)
Surf.PolyColor.s.alpha = (UINT8)(strength*25.5f);
}
- HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false);
+ HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest);
}
// Draw the console background with translucency support
@@ -603,7 +603,7 @@ void HWR_DrawConsoleBack(UINT32 color, INT32 height)
Surf.PolyColor.rgba = UINT2RGBA(color);
Surf.PolyColor.s.alpha = 0x80;
- HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false);
+ HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest);
}
@@ -854,7 +854,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color)
Surf.PolyColor = palette[color&0xFF];
HWD.pfnDrawPolygon(&Surf, v, 4,
- PF_Modulated|PF_NoTexture|PF_NoDepthTest, false);
+ PF_Modulated|PF_NoTexture|PF_NoDepthTest);
}
// -------------------+
@@ -963,7 +963,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32
Surf.PolyColor.rgba = UINT2RGBA(color);
Surf.PolyColor.s.alpha = 0x80;
- HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false);
+ HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest);
}
// -----------------+
@@ -1081,7 +1081,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color)
else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel];
}
- HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false);
+ HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest);
}
#ifdef HAVE_PNG
diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h
index 60ea552b2..66ddf3a33 100644
--- a/src/hardware/hw_drv.h
+++ b/src/hardware/hw_drv.h
@@ -32,7 +32,8 @@ EXPORT void HWRAPI(SetupGLInfo) (void);
EXPORT void HWRAPI(SetTexturePalette) (RGBA_t *ppal);
EXPORT void HWRAPI(FinishUpdate) (INT32 waitvbl);
EXPORT void HWRAPI(Draw2DLine) (F2DCoord *v1, F2DCoord *v2, RGBA_t Color);
-EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, boolean horizonSpecial);
+EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags);
+EXPORT void HWRAPI(DrawIndexedTriangles) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, unsigned int *IndexArray);
EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags);
EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, FBOOLEAN DepthMask, FBOOLEAN StencilMask, FRGBAFloat *ClearColor);
EXPORT void HWRAPI(SetTexture) (FTextureInfo *TexInfo);
@@ -77,9 +78,6 @@ EXPORT void HWRAPI(SetShaderInfo) (hwdshaderinfo_t info, INT32 value);
EXPORT void HWRAPI(LoadCustomShader) (int number, char *shader, size_t size, boolean fragment);
EXPORT boolean HWRAPI(InitCustomShaders) (void);
-EXPORT void HWRAPI(StartBatching) (void);
-EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, int *sNumPolys, int *sNumVerts, int *sNumCalls, int *sNumShaders, int *sNumTextures, int *sNumPolyFlags, int *sNumColors);
-
EXPORT void HWRAPI(SetPaletteLookup)(UINT8 *lut);
EXPORT UINT32 HWRAPI(CreateLightTable)(RGBA_t *hw_lighttable);
EXPORT void HWRAPI(ClearLightTables)(void);
@@ -99,6 +97,7 @@ struct hwdriver_s
FinishUpdate pfnFinishUpdate;
Draw2DLine pfnDraw2DLine;
DrawPolygon pfnDrawPolygon;
+ DrawIndexedTriangles pfnDrawIndexedTriangles;
SetBlend pfnSetBlend;
ClearBuffer pfnClearBuffer;
SetTexture pfnSetTexture;
@@ -133,9 +132,6 @@ struct hwdriver_s
LoadCustomShader pfnLoadCustomShader;
InitCustomShaders pfnInitCustomShaders;
- StartBatching pfnStartBatching;
- RenderBatches pfnRenderBatches;
-
SetPaletteLookup pfnSetPaletteLookup;
CreateLightTable pfnCreateLightTable;
ClearLightTables pfnClearLightTables;
diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c
index 2c463ee9a..07e692a46 100644
--- a/src/hardware/hw_main.c
+++ b/src/hardware/hw_main.c
@@ -19,6 +19,7 @@
#include "hw_main.h"
#include "hw_glob.h"
#include "hw_drv.h"
+#include "hw_batching.h"
#include "hw_md2.h"
#include "hw_clip.h"
#include "hw_light.h"
@@ -649,6 +650,8 @@ void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isc
static FOutVector *planeVerts = NULL;
static UINT16 numAllocedPlaneVerts = 0;
+
+ INT32 shader = 0;
// no convex poly were generated for this subsector
if (!xsub->planepoly)
@@ -825,16 +828,16 @@ void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isc
if (HWR_UseShader())
{
if (PolyFlags & PF_Fog)
- HWD.pfnSetShader(6); // fog shader
+ shader = 6; // fog shader
else if (PolyFlags & PF_Ripple)
- HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 11 : 5); // water shader
+ shader = (HWR_ShouldUsePaletteRendering() ? 11 : 5); // water shader
else
- HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 9 : 1); // floor shader
+ shader = (HWR_ShouldUsePaletteRendering() ? 9 : 1); // floor shader
PolyFlags |= PF_ColorMapped;
}
- HWD.pfnDrawPolygon(&Surf, planeVerts, nrPlaneVerts, PolyFlags, false);
+ HWR_ProcessPolygon(&Surf, planeVerts, nrPlaneVerts, PolyFlags, shader, false);
if (subsector)
{
@@ -919,7 +922,7 @@ void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isc
horizonpts[4].y = gr_viewz;
// Draw
- HWD.pfnDrawPolygon(&Surf, horizonpts, 6, PolyFlags, true);
+ HWR_ProcessPolygon(&Surf, horizonpts, 6, PolyFlags, shader, true);
}
}
}
@@ -935,6 +938,8 @@ static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf)
fixed_t i;
// seg bbox
fixed_t segbbox[4];
+
+ INT32 shader = 0;
M_ClearBox(segbbox);
M_AddToBox(segbbox,
@@ -988,10 +993,10 @@ static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf)
if (HWR_UseShader())
{
- HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 2); // wall shader
+ shader = (HWR_ShouldUsePaletteRendering() ? 10 : 2); // wall shader
}
- HWD.pfnDrawPolygon(&pSurf, wallVerts, 4, i|PF_Modulated|PF_Decal, false);
+ HWD.HWR_ProcessPolygon(&pSurf, wallVerts, 4, i|PF_Modulated|PF_Decal, shader, false);
}
}
#endif
@@ -1022,11 +1027,13 @@ FBITFIELD HWR_TranstableToAlpha(INT32 transtablenum, FSurfaceInfo *pSurf)
//
void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blendmode, INT32 lightlevel, extracolormap_t *wallcolormap)
{
+ INT32 shader = 0;
+
HWR_Lighting(pSurf, lightlevel, wallcolormap);
if (HWR_UseShader())
{
- HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 2); // wall shader
+ shader = (HWR_ShouldUsePaletteRendering() ? 10 : 2); // wall shader
blendmode |= PF_ColorMapped;
}
@@ -1037,7 +1044,7 @@ void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend
blendmode &= ~PF_Masked;
}
- HWD.pfnDrawPolygon(pSurf, wallVerts, 4, blendmode|PF_Modulated|PF_Occlude, false);
+ HWR_ProcessPolygon(pSurf, wallVerts, 4, blendmode|PF_Modulated|PF_Occlude, shader, false); // wall shader
#ifdef WALLSPLATS
if (gr_curline->linedef->splats && cv_splats.value)
@@ -1393,11 +1400,11 @@ static void HWR_DrawSkyWallList(void)
surf.PolyColor.rgba = 0xFFFFFFFF;
- HWD.pfnSetTexture(NULL);
+ HWR_SetCurrentTexture(NULL);
HWD.pfnUnSetShader();
for (i = 0; i < skyWallVertexArraySize; i++)
{
- HWD.pfnDrawPolygon(&surf, skyWallVertexArray + i * 4, 4, PF_Occlude|PF_Invisible|PF_NoTexture, false);
+ HWD.pfnDrawPolygon(&surf, skyWallVertexArray + i * 4, 4, PF_Occlude|PF_Invisible|PF_NoTexture);
}
}
@@ -1418,7 +1425,7 @@ void HWR_DrawSkyWall(FOutVector *wallVerts, FSurfaceInfo *Surf)
}
else
{
- HWD.pfnSetTexture(NULL);
+ HWR_SetCurrentTexture(NULL);
HWR_ProjectWall(wallVerts, Surf, PF_Invisible|PF_NoTexture, 255, NULL);
}
// PF_Invisible so it's not drawn into the colour buffer
@@ -2862,8 +2869,8 @@ void HWR_AddLine(seg_t *line)
}
// OPTIMIZE: quickly reject orthogonal back sides.
- angle1 = R_PointToAngleEx64(viewx, viewy, v1x, v1y);
- angle2 = R_PointToAngleEx64(viewx, viewy, v2x, v2y);
+ angle1 = R_PointToAngle64(v1x, v1y);
+ angle2 = R_PointToAngle64(v2x, v2y);
// do an extra culling check when rendering portals
// check if any line vertex is on the viewable side of the portal target line
@@ -3056,8 +3063,8 @@ boolean HWR_CheckBBox(fixed_t *bspcoord)
if (mindist > current_bsp_culling_distance) return false;
}
- angle1 = R_PointToAngleEx64(viewx, viewy, px1, py1);
- angle2 = R_PointToAngleEx64(viewx, viewy, px2, py2);
+ angle1 = R_PointToAngle64(px1, py1);
+ angle2 = R_PointToAngle64(px2, py2);
return gld_clipper_SafeCheckRange(angle2, angle1);
}
@@ -3118,6 +3125,8 @@ void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, fixed_t
static FOutVector *planeVerts = NULL;
static UINT16 numAllocedPlaneVerts = 0;
+
+ INT32 shader = 0;
nrPlaneVerts = polysector->numVertices;
@@ -3263,11 +3272,11 @@ void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, fixed_t
if (HWR_UseShader())
{
- HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 9 : 1); // floor shader
+ shader = (HWR_ShouldUsePaletteRendering() ? 9 : 1); // floor shader
blendmode |= PF_ColorMapped;
}
- HWD.pfnDrawPolygon(&Surf, planeVerts, nrPlaneVerts, blendmode, false);
+ HWR_ProcessPolygon(&Surf, planeVerts, nrPlaneVerts, blendmode, shader, false); // floor shader
}
void HWR_AddPolyObjectPlanes(void)
@@ -3923,6 +3932,8 @@ static void HWR_DrawSpriteShadow(gr_vissprite_t *spr, GLPatch_t *gpatch, float t
fixed_t slopez;
float offset = 0;
+ INT32 shader = 0;
+
R_GetShadowZ(spr->mobj, &floorslope);
mobjfloor = HWR_OpaqueFloorAtPos(
@@ -4072,10 +4083,10 @@ static void HWR_DrawSpriteShadow(gr_vissprite_t *spr, GLPatch_t *gpatch, float t
if (HWR_UseShader())
{
- HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 9 : 1); // floor shader
+ shader = (HWR_ShouldUsePaletteRendering() ? 9 : 1); // floor shader
}
-
- HWD.pfnDrawPolygon(&sSurf, swallVerts, 4, PF_Translucent|PF_Modulated, false);
+
+ HWR_ProcessPolygon(&sSurf, swallVerts, 4, PF_Translucent|PF_Modulated, shader, false);
}
}
@@ -4171,6 +4182,8 @@ static void HWR_SplitSprite(gr_vissprite_t *spr)
fixed_t v1x, v1y, v2x, v2y;
#endif
+ INT32 shader = 0;
+
this_scale = FIXED_TO_FLOAT(spr->mobj->scale);
if (hires)
@@ -4444,11 +4457,11 @@ static void HWR_SplitSprite(gr_vissprite_t *spr)
if (HWR_UseShader())
{
- HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader
+ shader = (HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader
blend |= PF_ColorMapped;
}
- HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, false);
+ HWR_ProcessPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, shader, false); // sprite shader
top = bot;
#ifdef ESLOPE
@@ -4489,11 +4502,11 @@ static void HWR_SplitSprite(gr_vissprite_t *spr)
if (HWR_UseShader())
{
- HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader
+ shader = (HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader
blend |= PF_ColorMapped;
}
- HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, false);
+ HWR_ProcessPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, shader, false); // sprite shader
}
// -----------------+
@@ -4507,6 +4520,9 @@ static void HWR_DrawSprite(gr_vissprite_t *spr)
FOutVector wallVerts[4];
GLPatch_t *gpatch; // sprite patch converted to hardware
FSurfaceInfo Surf;
+
+ INT32 shader = 0;
+
const boolean hires = (spr->mobj && spr->mobj->skin && ((skin_t *)( (spr->mobj->localskin) ? spr->mobj->localskin : spr->mobj->skin ))->flags & SF_HIRES);
if (spr->mobj)
this_scale = FIXED_TO_FLOAT(spr->mobj->scale);
@@ -4647,11 +4663,11 @@ static void HWR_DrawSprite(gr_vissprite_t *spr)
if (HWR_UseShader())
{
- HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader
+ shader = (HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader
blend |= PF_ColorMapped;
}
- HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, false);
+ HWR_ProcessPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, shader, false);
}
}
@@ -4662,6 +4678,8 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr)
FOutVector wallVerts[4];
GLPatch_t *gpatch; // sprite patch converted to hardware
FSurfaceInfo Surf;
+
+ INT32 shader = 0;
if (!spr->mobj)
return;
@@ -4746,11 +4764,11 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr)
if (HWR_UseShader())
{
- HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader
+ shader = (HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader
blend |= PF_ColorMapped;
}
- HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, false);
+ HWR_ProcessPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, shader, false);
}
// --------------------------------------------------------------------------
@@ -5920,8 +5938,8 @@ static void HWR_PortalClipping(gl_portal_t *portal)
line_t *line = &lines[portal->clipline];
- angle1 = R_PointToAngleEx64(viewx, viewy, line->v1->x, line->v1->y);
- angle2 = R_PointToAngleEx64(viewx, viewy, line->v2->x, line->v2->y);
+ angle1 = R_PointToAngleEx(viewx, viewy, line->v1->x, line->v1->y);
+ angle2 = R_PointToAngleEx(viewx, viewy, line->v2->x, line->v2->y);
// clip things that are not inside the portal window from our viewpoint
gld_clipper_SafeAddClipRange(angle2, angle1);
@@ -6051,8 +6069,9 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe
}
//drawcount = 0;
validcount++;
+
if (cv_grbatching.value)
- HWD.pfnStartBatching();
+ HWR_StartBatching();
ps_numbspcalls.value.i = 0;
ps_numpolyobjects.value.i = 0;
@@ -6073,14 +6092,10 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, playe
gr_portal = oldgl_portal_state;
PS_STOP_TIMING(ps_bsptime);
-
+
if (cv_grbatching.value)
- {
- HWD.pfnRenderBatches(&ps_hw_batchsorttime.value.p, &ps_hw_batchdrawtime.value.p,
- &ps_hw_numpolys.value.i, &ps_hw_numverts.value.i, &ps_hw_numcalls.value.i,
- &ps_hw_numshaders.value.i, &ps_hw_numtextures.value.i, &ps_hw_numpolyflags.value.i,
- &ps_hw_numcolors.value.i);
- }
+ HWR_RenderBatches();
+
if (skyWallVertexArraySize)// if there are skywalls to draw using the alternate method
{
HWR_SetStencilState(HWR_STENCIL_SKY, -1);
@@ -6370,7 +6385,7 @@ void HWR_AddCommands(void)
CV_RegisterVar(&cv_granisotropicmode);
CV_RegisterVar(&cv_grcorrecttricks);
CV_RegisterVar(&cv_grsolvetjoin);
-
+
CV_RegisterVar(&cv_grbatching);
CV_RegisterVar(&cv_grfofcut);
CV_RegisterVar(&cv_fofzfightfix);
@@ -6460,6 +6475,8 @@ void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend,
{
FBITFIELD blendmode = blend;
UINT8 alpha = pSurf->PolyColor.s.alpha; // retain the alpha
+
+ INT32 shader = 0;
// Lighting is done here instead so that fog isn't drawn incorrectly on transparent walls after sorting
HWR_Lighting(pSurf, lightlevel, wallcolormap);
@@ -6472,7 +6489,7 @@ void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend,
if (fogwall)
{
blendmode |= PF_Fog;
- HWD.pfnSetShader(6); // fog shader
+ shader = 6; // fog shader
}
blendmode |= PF_Modulated; // No PF_Occlude means overlapping (incorrect) transparency
@@ -6481,12 +6498,12 @@ void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend,
{
if (HWR_UseShader())
{
- HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 2); // wall shader
+ shader = (HWR_ShouldUsePaletteRendering() ? 10 : 2); // wall shader
blendmode |= PF_ColorMapped;
}
}
- HWD.pfnDrawPolygon(pSurf, wallVerts, 4, blendmode, false);
+ HWR_ProcessPolygon(pSurf, wallVerts, 4, blendmode, shader, false);
#ifdef WALLSPLATS
if (gr_curline->linedef->splats && cv_splats.value)
@@ -6537,7 +6554,7 @@ void HWR_DoPostProcessor(player_t *player)
Surf.PolyColor.s.alpha = 0xc0; // match software mode
- HWD.pfnDrawPolygon(&Surf, v, 4, PF_Modulated|PF_Translucent|PF_NoTexture|PF_NoDepthTest, false);
+ HWD.pfnDrawPolygon(&Surf, v, 4, PF_Modulated|PF_Translucent|PF_NoTexture|PF_NoDepthTest);
}
if (!cv_grscreentextures.value) // screen textures are needed for the rest of the effects
diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h
index dd77a41da..2d19ec1c4 100644
--- a/src/hardware/hw_main.h
+++ b/src/hardware/hw_main.h
@@ -64,6 +64,8 @@ extern ps_metric_t ps_hw_numcolors;
extern ps_metric_t ps_hw_batchsorttime;
extern ps_metric_t ps_hw_batchdrawtime;
+extern boolean gr_shadersavailable;
+
// hw_draw.c
void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option);
void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap);
diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c
index 8b630844a..6f8ba7eea 100644
--- a/src/hardware/r_opengl/r_opengl.c
+++ b/src/hardware/r_opengl/r_opengl.c
@@ -31,6 +31,7 @@
#include "../../i_system.h" // for I_GetPreciseTime (batching time measurements)
#include "../hw_main.h"
+#include "../hw_batching.h"
// Eeeeh not sure is this right way, but it works < sry :c
extern consvar_t cv_grusecustomshaders;
@@ -639,7 +640,6 @@ static boolean gl_shadersenabled = false;
static GLuint gl_currentshaderprogram = 0;
static boolean gl_shaderprogramchanged = true;
-static boolean gl_batching = false;// are we currently collecting batches?
static INT32 gl_enable_screen_textures = 1;
@@ -1335,7 +1335,7 @@ EXPORT void HWRAPI(KillShaders) (void)
static void SetNoTexture(void)
{
// Disable texture.
- if (tex_downloaded != NOTEXTURE_NUM && !gl_batching)
+ if (tex_downloaded != NOTEXTURE_NUM)
{
pglBindTexture(GL_TEXTURE_2D, NOTEXTURE_NUM);
tex_downloaded = NOTEXTURE_NUM;
@@ -2141,674 +2141,84 @@ static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAF
#endif
}
-
-// unfinished draw call batching
-
-// Note: could use realloc in the array reallocation code
-
-typedef struct
+// code that is common between DrawPolygon and DrawIndexedTriangles
+// the corona thing is there too, i have no idea if that stuff works with DrawIndexedTriangles and batching
+static void PreparePolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FBITFIELD PolyFlags)
{
- FSurfaceInfo surf;// surf also has its own polyflags for some reason, but it seems unused
- unsigned int vertsIndex;// location of verts in unsortedVertexArray
- FUINT numVerts;
- FBITFIELD polyFlags;
- GLuint texNum;
- GLuint shader;
- // this tells batching that the plane belongs to a horizon line and must be drawn in correct order with the skywalls
- boolean horizonSpecial;
- INT32 hash;
-} PolygonArrayEntry;
+ static GLRGBAFloat poly = {0,0,0,0};
+ static GLRGBAFloat tint = {0,0,0,0};
+ static GLRGBAFloat fade = {0,0,0,0};
-FOutVector* finalVertexArray = NULL;// contains subset of sorted vertices and texture coordinates to be sent to gpu
-UINT32* finalVertexIndexArray = NULL;// contains indexes for glDrawElements, taking into account fan->triangles conversion
-// NOTE have this alloced as 3x finalVertexArray size
-int finalVertexArrayAllocSize = 65536;
-//GLubyte* colorArray = NULL;// contains color data to be sent to gpu, if needed
-//int colorArrayAllocSize = 65536;
-// not gonna use this for now, just sort by color and change state when it changes
-// later maybe when using vertex attributes if it's needed
+ SetBlend(PolyFlags); //TODO: inline (#pragma..)
-PolygonArrayEntry* polygonArray = NULL;// contains the polygon data from DrawPolygon, waiting to be processed
-int polygonArraySize = 0;
-PolygonArrayEntry **polygonArraySorted = NULL;// contains sorted pointers to polygonArray
-int polygonArrayAllocSize = 65536;
-
-FOutVector* unsortedVertexArray = NULL;// contains unsorted vertices and texture coordinates from DrawPolygon
-int unsortedVertexArraySize = 0;
-int unsortedVertexArrayAllocSize = 65536;
-
-EXPORT void HWRAPI(StartBatching) (void)
-{
- //CONS_Printf("StartBatching begin\n");
- // init arrays if that has not been done yet
- if (!finalVertexArray)
+ // PolyColor
+ if (pSurf)
{
- finalVertexArray = malloc(finalVertexArrayAllocSize * sizeof(FOutVector));
- finalVertexIndexArray = malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32));
- polygonArray = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry));
- polygonArraySorted = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry *));
- unsortedVertexArray = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector));
- }
- // drawing functions will now collect the drawing data instead of passing it to opengl
- gl_batching = true;
- //CONS_Printf("StartBatching end\n");
-}
+ // If Modulated, mix the surface colour to the texture
+ if (CurrentPolyFlags & PF_Modulated)
+ {
+ // Poly color
+ poly.red = byte2float[pSurf->PolyColor.s.red];
+ poly.green = byte2float[pSurf->PolyColor.s.green];
+ poly.blue = byte2float[pSurf->PolyColor.s.blue];
+ poly.alpha = byte2float[pSurf->PolyColor.s.alpha];
-static int comparePolygons(const void *p1, const void *p2)
-{
- PolygonArrayEntry *poly1 = *(PolygonArrayEntry *const *)p1;
- PolygonArrayEntry *poly2 = *(PolygonArrayEntry *const *)p2;
- int diff;
- INT64 diff64;
+ pglColor4ubv((GLubyte*)&pSurf->PolyColor.s);
+ }
- int shader1 = poly1->shader;
- int shader2 = poly2->shader;
- // make skywalls and horizon lines first in order
- if (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial)
- shader1 = -1;
- if (poly2->polyFlags & PF_NoTexture || poly2->horizonSpecial)
- shader2 = -1;
- diff = shader1 - shader2;
- if (diff != 0) return diff;
+ // Tint color
+ tint.red = byte2float[pSurf->TintColor.s.red];
+ tint.green = byte2float[pSurf->TintColor.s.green];
+ tint.blue = byte2float[pSurf->TintColor.s.blue];
+ tint.alpha = byte2float[pSurf->TintColor.s.alpha];
- // skywalls and horizon lines must retain their order for horizon lines to work
- if (shader1 == -1 && shader2 == -1)
- return poly1 - poly2;
-
- diff = poly1->texNum - poly2->texNum;
- if (diff != 0) return diff;
-
- if (gl_palshader)
- {
- diff = poly1->surf.LightTableId - poly2->surf.LightTableId;
- if (diff != 0) return diff;
- }
-
- diff = poly1->polyFlags - poly2->polyFlags;
- if (diff != 0) return diff;
-
- diff64 = poly1->surf.PolyColor.rgba - poly2->surf.PolyColor.rgba;
- if (diff64 < 0) return -1; else if (diff64 > 0) return 1;
- diff64 = poly1->surf.TintColor.rgba - poly2->surf.TintColor.rgba;
- if (diff64 < 0) return -1; else if (diff64 > 0) return 1;
- diff64 = poly1->surf.FadeColor.rgba - poly2->surf.FadeColor.rgba;
- if (diff64 < 0) return -1; else if (diff64 > 0) return 1;
-
- diff = poly1->surf.LightInfo.light_level - poly2->surf.LightInfo.light_level;
- if (diff != 0) return diff;
- diff = poly1->surf.LightInfo.fade_start - poly2->surf.LightInfo.fade_start;
- if (diff != 0) return diff;
- diff = poly1->surf.LightInfo.fade_end - poly2->surf.LightInfo.fade_end;
- return diff;
-}
-
-static int comparePolygonsNoShaders(const void *p1, const void *p2)
-{
- PolygonArrayEntry *poly1 = *(PolygonArrayEntry *const *)p1;
- PolygonArrayEntry *poly2 = *(PolygonArrayEntry *const *)p2;
- int diff;
- INT64 diff64;
-
- GLuint texNum1 = poly1->texNum;
- GLuint texNum2 = poly2->texNum;
- if (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial)
- texNum1 = 0;
- if (poly2->polyFlags & PF_NoTexture || poly2->horizonSpecial)
- texNum2 = 0;
- diff = texNum1 - texNum2;
- if (diff != 0) return diff;
-
- // skywalls and horizon lines must retain their order for horizon lines to work
- if (texNum1 == 0 && texNum2 == 0)
- return poly1 - poly2;
-
- diff = poly1->polyFlags - poly2->polyFlags;
- if (diff != 0) return diff;
-
- diff64 = poly1->surf.PolyColor.rgba - poly2->surf.PolyColor.rgba;
- if (diff64 < 0) return -1; else if (diff64 > 0) return 1;
-
- return 0;
-}
-
-// the parameters for this functions (numPolys etc.) are used to return rendering stats
-EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, int *sNumPolys, int *sNumVerts, int *sNumCalls, int *sNumShaders, int *sNumTextures, int *sNumPolyFlags, int *sNumColors)
-{
- int finalVertexWritePos = 0;// position in finalVertexArray
- int finalIndexWritePos = 0;// position in finalVertexIndexArray
-
- int polygonReadPos = 0;// position in polygonArraySorted
-
- GLuint currentShader;
- GLuint currentTexture;
- FBITFIELD currentPolyFlags;
- FSurfaceInfo currentSurfaceInfo;
-
- GLRGBAFloat firstPoly = {0,0,0,0}; // may be misleading but this means first PolyColor
- GLRGBAFloat firstTint = {0,0,0,0};
- GLRGBAFloat firstFade = {0,0,0,0};
-
- boolean needRebind = false;
-
- int i;
-
- //CONS_Printf("RenderBatches\n");
- gl_batching = false;// no longer collecting batches
- if (!polygonArraySize)
- {
- *sSortTime = *sDrawTime = *sNumPolys = *sNumCalls = *sNumShaders = *sNumTextures = *sNumPolyFlags = *sNumColors = 0;
- return;// nothing to draw
- }
- // init stats vars
- *sNumPolys = polygonArraySize;
- *sNumCalls = *sNumVerts = 0;
- *sNumShaders = *sNumTextures = *sNumPolyFlags = *sNumColors = 1;
- // init polygonArraySorted
- for (i = 0; i < polygonArraySize; i++)
- {
- polygonArraySorted[i] = &polygonArray[i];
- }
-
- // sort polygons
- //CONS_Printf("qsort polys\n");
- *sSortTime = I_GetPreciseTime();
- if (gl_allowshaders)
- qsort(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), comparePolygons);
- else
- qsort(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), comparePolygonsNoShaders);
- *sSortTime = I_GetPreciseTime() - *sSortTime;
- //CONS_Printf("sort done\n");
- // sort order
- // 1. shader
- // 2. texture
- // 3. polyflags
- // 4. colors + light level
- // not sure about order of last 2, or if it even matters
-
- *sDrawTime = I_GetPreciseTime();
-
- currentShader = polygonArraySorted[0]->shader;
- currentTexture = polygonArraySorted[0]->texNum;
- currentPolyFlags = polygonArraySorted[0]->polyFlags;
- currentSurfaceInfo = polygonArraySorted[0]->surf;
- // For now, will sort and track the colors. Vertex attributes could be used instead of uniforms
- // and a color array could replace the color calls.
-
- // set state for first batch
- //CONS_Printf("set first state\n");
- gl_currentshaderprogram = currentShader;
- gl_shaderprogramchanged = true;
- if (currentPolyFlags & PF_Modulated)
- {
- // Poly color
- firstPoly.red = byte2float[currentSurfaceInfo.PolyColor.s.red];
- firstPoly.green = byte2float[currentSurfaceInfo.PolyColor.s.green];
- firstPoly.blue = byte2float[currentSurfaceInfo.PolyColor.s.blue];
- firstPoly.alpha = byte2float[currentSurfaceInfo.PolyColor.s.alpha];
- pglColor4ubv((GLubyte*)¤tSurfaceInfo.PolyColor.s);
- }
- // Tint color
- firstTint.red = byte2float[currentSurfaceInfo.TintColor.s.red];
- firstTint.green = byte2float[currentSurfaceInfo.TintColor.s.green];
- firstTint.blue = byte2float[currentSurfaceInfo.TintColor.s.blue];
- firstTint.alpha = byte2float[currentSurfaceInfo.TintColor.s.alpha];
- // Fade color
- firstFade.red = byte2float[currentSurfaceInfo.FadeColor.s.red];
- firstFade.green = byte2float[currentSurfaceInfo.FadeColor.s.green];
- firstFade.blue = byte2float[currentSurfaceInfo.FadeColor.s.blue];
- firstFade.alpha = byte2float[currentSurfaceInfo.FadeColor.s.alpha];
-
- if (gl_allowshaders)
- {
- Shader_Load(¤tSurfaceInfo, &firstPoly, &firstTint, &firstFade);
+ // Fade color
+ fade.red = byte2float[pSurf->FadeColor.s.red];
+ fade.green = byte2float[pSurf->FadeColor.s.green];
+ fade.blue = byte2float[pSurf->FadeColor.s.blue];
+ fade.alpha = byte2float[pSurf->FadeColor.s.alpha];
- //if (currentSurfaceInfo.LightTableId && currentSurfaceInfo.LightTableId != lt_downloaded)
- if (HWR_ShouldUsePaletteRendering())
+ if (HWR_ShouldUsePaletteRendering && gl_allowshaders)
{
pglActiveTexture(GL_TEXTURE2);
- pglBindTexture(GL_TEXTURE_2D, currentSurfaceInfo.LightTableId);
+ pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId);
pglActiveTexture(GL_TEXTURE0);
- //lt_downloaded = currentSurfaceInfo.LightTableId;
}
}
- if (currentPolyFlags & PF_NoTexture)
- currentTexture = 0;
- pglBindTexture(GL_TEXTURE_2D, currentTexture);
- tex_downloaded = currentTexture;
-
- SetBlend(currentPolyFlags);
-
- //CONS_Printf("first pointers to ogl\n");
- pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &finalVertexArray[0].x);
- pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &finalVertexArray[0].s);
-
- while (1)// note: remember handling notexture polyflag as having texture number 0 (also in comparePolygons)
- {
- int firstIndex;
- int lastIndex;
-
- boolean stopFlag = false;
- boolean changeState = false;
- boolean changeShader = false;
- GLuint nextShader = 0U;
- boolean changeTexture = false;
- GLuint nextTexture = 0U;
- boolean changePolyFlags = false;
- FBITFIELD nextPolyFlags = 0U;
- boolean changeSurfaceInfo = false;
- FSurfaceInfo nextSurfaceInfo;
-
- //CONS_Printf("loop iter start\n");
- // new try:
- // write vertices
- // check for changes or end, otherwise go back to writing
- // changes will affect the next vars and the change bools
- // end could set flag for stopping
- // execute draw call
- // could check ending flag here
- // change states according to next vars and change bools, updating the current vars and reseting the bools
- // reset write pos
- // repeat loop
-
- PolygonArrayEntry *entry = polygonArraySorted[polygonReadPos++];
- int numVerts = entry->numVerts;
- // before writing, check if there is enough room
- // using 'while' instead of 'if' here makes sure that there will *always* be enough room.
- // probably never will this loop run more than once though
- while (finalVertexWritePos + numVerts > finalVertexArrayAllocSize)
- {
- FOutVector* new_array;
- unsigned int* new_index_array;
- //CONS_Printf("final vert realloc\n");
- finalVertexArrayAllocSize *= 2;
- new_array = malloc(finalVertexArrayAllocSize * sizeof(FOutVector));
- memcpy(new_array, finalVertexArray, finalVertexWritePos * sizeof(FOutVector));
- free(finalVertexArray);
- finalVertexArray = new_array;
- // also increase size of index array, 3x of vertex array since
- // going from fans to triangles increases vertex count to 3x
- new_index_array = malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32));
- memcpy(new_index_array, finalVertexIndexArray, finalIndexWritePos * sizeof(UINT32));
- free(finalVertexIndexArray);
- finalVertexIndexArray = new_index_array;
- // if vertex buffers are reallocated then opengl needs to know too
- needRebind = true;
- }
- //CONS_Printf("write verts to final\n");
- // write the vertices of the polygon
- memcpy(&finalVertexArray[finalVertexWritePos], &unsortedVertexArray[entry->vertsIndex],
- numVerts * sizeof(FOutVector));
- // write the indexes, pointing to the fan vertexes but in triangles format
- firstIndex = finalVertexWritePos;
- lastIndex = finalVertexWritePos + numVerts;
- finalVertexWritePos += 2;
- //CONS_Printf("write final vert indices\n");
- while (finalVertexWritePos < lastIndex)
- {
- finalVertexIndexArray[finalIndexWritePos++] = firstIndex;
- finalVertexIndexArray[finalIndexWritePos++] = finalVertexWritePos - 1;
- finalVertexIndexArray[finalIndexWritePos++] = finalVertexWritePos++;
- }
-
- if (polygonReadPos >= polygonArraySize)
- {
- stopFlag = true;
- }
- else
- {
- //CONS_Printf("state change check\n");
- // check if a state change is required, set the change bools and next vars
- PolygonArrayEntry *nextEntry = polygonArraySorted[polygonReadPos];
- nextShader = nextEntry->shader;
- nextTexture = nextEntry->texNum;
- nextPolyFlags = nextEntry->polyFlags;
- nextSurfaceInfo = nextEntry->surf;
- if (nextPolyFlags & PF_NoTexture)
- nextTexture = 0;
- if (currentShader != nextShader)
- {
- changeState = true;
- nextShader = polygonArray[nextIndex].shader;
- nextTexture = polygonArray[nextIndex].texNum;
- nextPolyFlags = polygonArray[nextIndex].polyFlags;
- nextSurfaceInfo = polygonArray[nextIndex].surf;
-
- if (nextPolyFlags & PF_NoTexture)
- nextTexture = 0;
- if (currentShader != nextShader)
- {
- changeShader = true;
- }
- if (currentTexture != nextTexture)
- {
- changeTexture = true;
- }
- if (currentPolyFlags != nextPolyFlags)
- {
- changePolyFlags = true;
- }
- if (gl_allowshaders && HWR_ShouldUsePaletteRendering())
- {
- if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba ||
- currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba ||
- currentSurfaceInfo.FadeColor.rgba != nextSurfaceInfo.FadeColor.rgba ||
- currentSurfaceInfo.LightInfo.light_level != nextSurfaceInfo.LightInfo.light_level ||
- currentSurfaceInfo.LightInfo.fade_start != nextSurfaceInfo.LightInfo.fade_start ||
- currentSurfaceInfo.LightInfo.fade_end != nextSurfaceInfo.LightInfo.fade_end ||
- currentSurfaceInfo.LightTableId != nextSurfaceInfo.LightTableId)
- {
- changeSurfaceInfo = true;
- }
- }
- else if ((gl_allowshaders) && (!HWR_ShouldUsePaletteRendering()))
- {
- if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba ||
- currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba ||
- currentSurfaceInfo.FadeColor.rgba != nextSurfaceInfo.FadeColor.rgba ||
- currentSurfaceInfo.LightInfo.light_level != nextSurfaceInfo.LightInfo.light_level ||
- currentSurfaceInfo.LightInfo.fade_start != nextSurfaceInfo.LightInfo.fade_start ||
- currentSurfaceInfo.LightInfo.fade_end != nextSurfaceInfo.LightInfo.fade_end)
- {
- changeSurfaceInfo = true;
- }
- }
- else
- {
- if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba)
- {
- changeSurfaceInfo = true;
- }
- }
- }
- }
-
- if (changeState || stopFlag)
- {
- if (needRebind)
- {
- //CONS_Printf("rebind\n");
- pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &finalVertexArray[0].x);
- pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &finalVertexArray[0].s);
- needRebind = false;
- }
- //CONS_Printf("exec draw call\n");
- // execute draw call
- pglDrawElements(GL_TRIANGLES, finalIndexWritePos, GL_UNSIGNED_INT, finalVertexIndexArray);
- //CONS_Printf("draw call done\n");
- // update stats
- (*sNumCalls)++;
- *sNumVerts += finalIndexWritePos;
- // reset write positions
- finalVertexWritePos = 0;
- finalIndexWritePos = 0;
- }
- else continue;
-
- // if we're here then either its time to stop or time to change state
- if (stopFlag) break;
-
- //CONS_Printf("state change\n");
-
- // change state according to change bools and next vars, update current vars and reset bools
- if (changeState)
- {
- if (changeShader)
- {
- GLRGBAFloat poly = {0,0,0,0};
- GLRGBAFloat tint = {0,0,0,0};
- GLRGBAFloat fade = {0,0,0,0};
- gl_currentshaderprogram = nextShader;
- gl_shaderprogramchanged = true;
- if (nextPolyFlags & PF_Modulated)
- {
- // Poly color
- poly.red = byte2float[nextSurfaceInfo.PolyColor.s.red];
- poly.green = byte2float[nextSurfaceInfo.PolyColor.s.green];
- poly.blue = byte2float[nextSurfaceInfo.PolyColor.s.blue];
- poly.alpha = byte2float[nextSurfaceInfo.PolyColor.s.alpha];
- }
- // Tint color
- tint.red = byte2float[nextSurfaceInfo.TintColor.s.red];
- tint.green = byte2float[nextSurfaceInfo.TintColor.s.green];
- tint.blue = byte2float[nextSurfaceInfo.TintColor.s.blue];
- tint.alpha = byte2float[nextSurfaceInfo.TintColor.s.alpha];
- // Fade color
- fade.red = byte2float[nextSurfaceInfo.FadeColor.s.red];
- fade.green = byte2float[nextSurfaceInfo.FadeColor.s.green];
- fade.blue = byte2float[nextSurfaceInfo.FadeColor.s.blue];
- fade.alpha = byte2float[nextSurfaceInfo.FadeColor.s.alpha];
-
- Shader_Load(&nextSurfaceInfo, &poly, &tint, &fade);
-
- currentShader = nextShader;
- changeShader = false;
-
- (*sNumShaders)++;
- }
- if (changeTexture)
- {
- // texture should be already ready for use from calls to SetTexture during batch collection
- pglBindTexture(GL_TEXTURE_2D, nextTexture);
- tex_downloaded = nextTexture;
- currentTexture = nextTexture;
- changeTexture = false;
-
- (*sNumTextures)++;
- }
- if (changePolyFlags)
- {
- SetBlend(nextPolyFlags);
- currentPolyFlags = nextPolyFlags;
- changePolyFlags = false;
-
- (*sNumPolyFlags)++;
- }
- if (changeSurfaceInfo)
- {
- GLRGBAFloat poly = {0,0,0,0};
- GLRGBAFloat tint = {0,0,0,0};
- GLRGBAFloat fade = {0,0,0,0};
- gl_shaderprogramchanged = false;
- if (nextPolyFlags & PF_Modulated)
- {
- // Poly color
- poly.red = byte2float[nextSurfaceInfo.PolyColor.s.red];
- poly.green = byte2float[nextSurfaceInfo.PolyColor.s.green];
- poly.blue = byte2float[nextSurfaceInfo.PolyColor.s.blue];
- poly.alpha = byte2float[nextSurfaceInfo.PolyColor.s.alpha];
- pglColor4ubv((GLubyte*)&nextSurfaceInfo.PolyColor.s);
- }
- if (gl_allowshaders)
- {
- // Tint color
- tint.red = byte2float[nextSurfaceInfo.TintColor.s.red];
- tint.green = byte2float[nextSurfaceInfo.TintColor.s.green];
- tint.blue = byte2float[nextSurfaceInfo.TintColor.s.blue];
- tint.alpha = byte2float[nextSurfaceInfo.TintColor.s.alpha];
- // Fade color
- fade.red = byte2float[nextSurfaceInfo.FadeColor.s.red];
- fade.green = byte2float[nextSurfaceInfo.FadeColor.s.green];
- fade.blue = byte2float[nextSurfaceInfo.FadeColor.s.blue];
- fade.alpha = byte2float[nextSurfaceInfo.FadeColor.s.alpha];
-
- Shader_Load(&nextSurfaceInfo, &poly, &tint, &fade);
-
- //if (nextSurfaceInfo.LightTableId && nextSurfaceInfo.LightTableId != lt_downloaded2)
- if (HWR_ShouldUsePaletteRendering())
- {
- pglActiveTexture(GL_TEXTURE2);
- pglBindTexture(GL_TEXTURE_2D, nextSurfaceInfo.LightTableId);
- pglActiveTexture(GL_TEXTURE0);
- //lt_downloaded2 = nextSurfaceInfo.LightTableId;
- }
- }
-
- currentSurfaceInfo = nextSurfaceInfo;
- changeSurfaceInfo = false;
-
- (*sNumColors)++;
- }
- }
- // and that should be it?
- }
- // reset the arrays (set sizes to 0)
- polygonArraySize = 0;
- unsortedVertexArraySize = 0;
-
- *sDrawTime = I_GetPreciseTime() - *sDrawTime;
+ Shader_Load(pSurf, &poly, &tint, &fade);
}
// -----------------+
// DrawPolygon : Render a polygon, set the texture, set render mode
// -----------------+
-EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, boolean horizonSpecial)
+EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags)
{
- if (gl_batching)
- {
- //CONS_Printf("Batched DrawPolygon\n");
- if (!pSurf)
- I_Error("Got a null FSurfaceInfo in batching");// nulls should only come in sky background pic drawing
- if (polygonArraySize == polygonArrayAllocSize)
- {
- PolygonArrayEntry* new_array;
- // ran out of space, make new array double the size
- polygonArrayAllocSize *= 2;
- new_array = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry));
- memcpy(new_array, polygonArray, polygonArraySize * sizeof(PolygonArrayEntry));
- free(polygonArray);
- polygonArray = new_array;
- // also need to redo the index array, dont need to copy it though
- free(polygonArraySorted);
- polygonArraySorted = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry *));
- }
+ PreparePolygon(pSurf, pOutVerts, PolyFlags);
- while (unsortedVertexArraySize + (int)iNumPts > unsortedVertexArrayAllocSize)
- {
- FOutVector* new_array;
- // need more space for vertices in unsortedVertexArray
- unsortedVertexArrayAllocSize *= 2;
- new_array = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector));
- memcpy(new_array, unsortedVertexArray, unsortedVertexArraySize * sizeof(FOutVector));
- free(unsortedVertexArray);
- unsortedVertexArray = new_array;
- }
+ pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x);
+ pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].s);
+ pglDrawArrays(GL_TRIANGLE_FAN, 0, iNumPts);
- // add the polygon data to the arrays
+ if (PolyFlags & PF_RemoveYWrap)
+ pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- polygonArray[polygonArraySize].surf = *pSurf;
- polygonArray[polygonArraySize].vertsIndex = unsortedVertexArraySize;
- polygonArray[polygonArraySize].numVerts = iNumPts;
- polygonArray[polygonArraySize].polyFlags = PolyFlags;
- polygonArray[polygonArraySize].texNum = tex_downloaded;
- polygonArray[polygonArraySize].shader = gl_currentshaderprogram;
- polygonArray[polygonArraySize].horizonSpecial = horizonSpecial;
- // default to polygonArraySize so we don't lose order on horizon lines
- // (yes, it's supposed to be negative, since we're sorting in that direction)
- polygonArray[polygonArraySize].hash = polygonArraySize;
- polygonArraySize++;
-
- if (!(PolyFlags & PF_NoTexture) && !horizonSpecial)
- {
- // use FNV-1a to hash polygons for later sorting.
- INT32 hash = 0x811c9dc5;
-#define DIGEST(h, x) h ^= (x); h *= 0x01000193
- if (tex_downloaded)
- {
- DIGEST(hash, tex_downloaded);
- }
- DIGEST(hash, PolyFlags);
- DIGEST(hash, pSurf->PolyColor.rgba);
- if (cv_grshaders.value && gl_allowshaders)
- {
- DIGEST(hash, gl_currentshaderprogram);
- DIGEST(hash, pSurf->TintColor.rgba);
- DIGEST(hash, pSurf->FadeColor.rgba);
- DIGEST(hash, pSurf->LightInfo.light_level);
- DIGEST(hash, pSurf->LightInfo.fade_start);
- DIGEST(hash, pSurf->LightInfo.fade_end);
+ if (PolyFlags & PF_ForceWrapX)
+ Clamp2D(GL_TEXTURE_WRAP_S);
- if (HWR_ShouldUsePaletteRendering())
- {
- DIGEST(hash, pSurf->LightTableId);
- }
- }
-#undef DIGEST
- // remove the sign bit to ensure that skybox and horizon line comes first.
- polygonArray[polygonArraySize-1].hash = (hash & INT32_MAX);
- }
+ if (PolyFlags & PF_ForceWrapY)
+ Clamp2D(GL_TEXTURE_WRAP_T);
+}
- memcpy(&unsortedVertexArray[unsortedVertexArraySize], pOutVerts, iNumPts * sizeof(FOutVector));
- unsortedVertexArraySize += iNumPts;
- }
- else
- {
- static GLRGBAFloat poly = {0,0,0,0};
- static GLRGBAFloat tint = {0,0,0,0};
- static GLRGBAFloat fade = {0,0,0,0};
+EXPORT void HWRAPI(DrawIndexedTriangles) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, unsigned int *IndexArray)
+{
+ PreparePolygon(pSurf, pOutVerts, PolyFlags);
- SetBlend(PolyFlags); //TODO: inline (#pragma..)
+ pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x);
+ pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].s);
+ pglDrawElements(GL_TRIANGLES, iNumPts, GL_UNSIGNED_INT, IndexArray);
- if (gl_portal_mode == HWD_PORTAL_NORMAL)
- {
- // PolyColor
- if (pSurf)
- {
- // If modulated, mix the surface colour to the texture
- if (CurrentPolyFlags & PF_Modulated)
- pglColor4ubv((GLubyte*)&pSurf->PolyColor.s);
-
- // If the surface is either modulated or colormapped, or both
- if (CurrentPolyFlags & (PF_Modulated | PF_ColorMapped))
- {
- poly.red = byte2float[pSurf->PolyColor.s.red];
- poly.green = byte2float[pSurf->PolyColor.s.green];
- poly.blue = byte2float[pSurf->PolyColor.s.blue];
- poly.alpha = byte2float[pSurf->PolyColor.s.alpha];
- }
-
- // Only if the surface is colormapped
- if (CurrentPolyFlags & PF_ColorMapped)
- {
- tint.red = byte2float[pSurf->TintColor.s.red];
- tint.green = byte2float[pSurf->TintColor.s.green];
- tint.blue = byte2float[pSurf->TintColor.s.blue];
- tint.alpha = byte2float[pSurf->TintColor.s.alpha];
-
- fade.red = byte2float[pSurf->FadeColor.s.red];
- fade.green = byte2float[pSurf->FadeColor.s.green];
- fade.blue = byte2float[pSurf->FadeColor.s.blue];
- fade.alpha = byte2float[pSurf->FadeColor.s.alpha];
-
- //if (pSurf->LightTableId && pSurf->LightTableId != lt_downloaded3)
- if (HWR_ShouldUsePaletteRendering())
- {
- pglActiveTexture(GL_TEXTURE2);
- pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId);
- pglActiveTexture(GL_TEXTURE0);
- //lt_downloaded3 = pSurf->LightTableId;
- }
- }
- }
-
- Shader_Load(pSurf, &poly, &tint, &fade);
- }
- else
- UnSetShader();
-
- pglVertexPointer(3, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].x);
- pglTexCoordPointer(2, GL_FLOAT, sizeof(FOutVector), &pOutVerts[0].s);
- pglDrawArrays(GL_TRIANGLE_FAN, 0, iNumPts);
-
- if (PolyFlags & PF_RemoveYWrap)
- pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-
- if (PolyFlags & PF_ForceWrapX)
- Clamp2D(GL_TEXTURE_WRAP_S);
-
- if (PolyFlags & PF_ForceWrapY)
- Clamp2D(GL_TEXTURE_WRAP_T);
- }
+ // the DrawPolygon variant of this has some code about polyflags and wrapping here but havent noticed any problems from omitting it?
}
// Sky dome code, taken/backported from SRB2
diff --git a/src/r_bsp.c b/src/r_bsp.c
index 795ef459c..8750c2ee3 100644
--- a/src/r_bsp.c
+++ b/src/r_bsp.c
@@ -410,8 +410,8 @@ static void R_AddLine(seg_t *line)
return;
// big room fix
- angle1 = R_PointToAngleEx64(viewx, viewy, line->v1->x, line->v1->y);
- angle2 = R_PointToAngleEx64(viewx, viewy, line->v2->x, line->v2->y);
+ angle1 = R_PointToAngle64(line->v1->x, line->v1->y);
+ angle2 = R_PointToAngle64(line->v2->x, line->v2->y);
curline = line;
// Clip to view edges.
@@ -613,8 +613,8 @@ static boolean R_CheckBBox(const fixed_t *bspcoord)
check = checkcoord[boxpos];
// big room fix
- angle1 = R_PointToAngleEx64(viewx, viewy, bspcoord[check[0]], bspcoord[check[1]]) - viewangle;
- angle2 = R_PointToAngleEx64(viewx, viewy, bspcoord[check[2]], bspcoord[check[3]]) - viewangle;
+ angle1 = R_PointToAngle64(bspcoord[check[0]], bspcoord[check[1]]) - viewangle;
+ angle2 = R_PointToAngle64(bspcoord[check[2]], bspcoord[check[3]]) - viewangle;
if ((signed)angle1 < (signed)angle2)
{
diff --git a/src/r_main.c b/src/r_main.c
index a0085d12f..4104c24d8 100644
--- a/src/r_main.c
+++ b/src/r_main.c
@@ -396,7 +396,24 @@ FUNCINLINE ATTRINLINE angle_t R_PointToAngle(fixed_t x, fixed_t y)
0;
}
-FUNCINLINE ATTRINLINE angle_t R_PointToAngle2(fixed_t pviewx, fixed_t pviewy, fixed_t x, fixed_t y)
+// This version uses 64-bit variables to avoid overflows with large values.
+angle_t R_PointToAngle64(INT64 x, INT64 y)
+{
+ return (y -= viewy, (x -= viewx) || y) ?
+ x >= 0 ?
+ y >= 0 ?
+ (x > y) ? tantoangle[SlopeDivEx(y,x)] : // octant 0
+ ANGLE_90-tantoangle[SlopeDivEx(x,y)] : // octant 1
+ x > (y = -y) ? 0-tantoangle[SlopeDivEx(y,x)] : // octant 8
+ ANGLE_270+tantoangle[SlopeDivEx(x,y)] : // octant 7
+ y >= 0 ? (x = -x) > y ? ANGLE_180-tantoangle[SlopeDivEx(y,x)] : // octant 3
+ ANGLE_90 + tantoangle[SlopeDivEx(x,y)] : // octant 2
+ (x = -x) > (y = -y) ? ANGLE_180+tantoangle[SlopeDivEx(y,x)] : // octant 4
+ ANGLE_270-tantoangle[SlopeDivEx(x,y)] : // octant 5
+ 0;
+}
+
+angle_t R_PointToAngle2(fixed_t pviewx, fixed_t pviewy, fixed_t x, fixed_t y)
{
return (y -= pviewy, (x -= pviewx) || y) ?
x >= 0 ?
@@ -490,32 +507,6 @@ FUNCINLINE ATTRINLINE angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT
0;
}
-FUNCINLINE ATTRINLINE angle_t R_PointToAngleEx64(INT64 x2, INT64 y2, INT64 x1, INT64 y1)
-{
- INT64 dx = x1 - x2;
- INT64 dy = y1 - y2;
-
- // Check for potential overflow or underflow
- if (dx < INT64_MIN || dx > INT64_MAX || dy < INT64_MIN || dy > INT64_MAX)
- {
- x1 = (INT64)(dx / 2 + x2);
- y1 = (INT64)(dy / 2 + y2);
- }
-
- return (y1 -= y2, (x1 -= x2) || y1) ?
- x1 >= 0 ?
- y1 >= 0 ?
- (x1 > y1) ? tantoangle[SlopeDivEx(y1, x1)] : // octant 0
- ANGLE_90 - tantoangle[SlopeDivEx(x1, y1)] : // octant 1
- x1 > (y1 = -y1) ? 0 - tantoangle[SlopeDivEx(y1, x1)] : // octant 8
- ANGLE_270 + tantoangle[SlopeDivEx(x1, y1)] : // octant 7
- y1 >= 0 ? (x1 = -x1) > y1 ? ANGLE_180 - tantoangle[SlopeDivEx(y1, x1)] : // octant 3
- ANGLE_90 + tantoangle[SlopeDivEx(x1, y1)] : // octant 2
- (x1 = -x1) > (y1 = -y1) ? ANGLE_180 + tantoangle[SlopeDivEx(y1, x1)] : // octant 4
- ANGLE_270 - tantoangle[SlopeDivEx(x1, y1)] : // octant 5
- 0;
-}
-
//
// R_ScaleFromGlobalAngle
// Returns the texture mapping scale for the current line (horizontal span)
diff --git a/src/r_main.h b/src/r_main.h
index c8a8aa535..3df5bd088 100644
--- a/src/r_main.h
+++ b/src/r_main.h
@@ -68,9 +68,9 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ];
INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *node);
INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line);
angle_t R_PointToAngle(fixed_t x, fixed_t y);
+angle_t R_PointToAngle64(INT64 x, INT64 y);
angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1);
angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT32 y1);
-angle_t R_PointToAngleEx64(INT64 x2, INT64 y2, INT64 x1, INT64 y1);
fixed_t R_PointToDist(fixed_t x, fixed_t y);
fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1);
angle_t R_PlayerSliptideAngle(player_t *player);
diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c
index bbb5d9df3..55b47a15e 100644
--- a/src/sdl/hwsym_sdl.c
+++ b/src/sdl/hwsym_sdl.c
@@ -81,6 +81,7 @@ void *hwSym(const char *funcName,void *handle)
GETFUNC(SetupGLInfo);
GETFUNC(Draw2DLine);
GETFUNC(DrawPolygon);
+ GETFUNC(DrawIndexedTriangles);
GETFUNC(SetBlend);
GETFUNC(ClearBuffer);
GETFUNC(SetTexture);
@@ -114,10 +115,6 @@ void *hwSym(const char *funcName,void *handle)
GETFUNC(SetShaderInfo);
GETFUNC(LoadCustomShader);
GETFUNC(InitCustomShaders);
-
- GETFUNC(StartBatching);
- GETFUNC(RenderBatches);
-
GETFUNC(SetPaletteLookup);
GETFUNC(CreateLightTable);
GETFUNC(ClearLightTables);
diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c
index d3a7c8ae3..4e9a98433 100644
--- a/src/sdl/i_video.c
+++ b/src/sdl/i_video.c
@@ -2125,6 +2125,7 @@ void I_StartupGraphics(void)
HWD.pfnFinishUpdate = NULL;
HWD.pfnDraw2DLine = hwSym("Draw2DLine",NULL);
HWD.pfnDrawPolygon = hwSym("DrawPolygon",NULL);
+ HWD.pfnDrawIndexedTriangles = hwSym("DrawIndexedTriangles",NULL);
HWD.pfnSetBlend = hwSym("SetBlend",NULL);
HWD.pfnClearBuffer = hwSym("ClearBuffer",NULL);
HWD.pfnSetTexture = hwSym("SetTexture",NULL);
@@ -2160,9 +2161,6 @@ void I_StartupGraphics(void)
HWD.pfnLoadCustomShader = hwSym("LoadCustomShader",NULL);
HWD.pfnInitCustomShaders = hwSym("InitCustomShaders",NULL);
- HWD.pfnStartBatching = hwSym("StartBatching",NULL);
- HWD.pfnRenderBatches = hwSym("RenderBatches",NULL);
-
HWD.pfnSetPaletteLookup = hwSym("SetPaletteLookup",NULL);
HWD.pfnCreateLightTable = hwSym("CreateLightTable",NULL);
HWD.pfnClearLightTables = hwSym("ClearLightTables",NULL);