From 1fe4e0c239423644f1562d4aadc374495dce81c9 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 12 May 2013 16:56:56 +0100 Subject: [PATCH 01/28] Add USE_INTERNAL_LIBS, a default for USE_INTERNAL_* Linux distributions that want to link dependencies externally will generally want to link (almost) every dependency externally; similarly, minimal-dependency builds that want to use the embedded copies of dependencies will generally want to do so for (almost) every dependency. Make it easier to choose one of those by setting USE_INTERNAL_LIBS=0 or USE_INTERNAL_LIBS=1, respectively. The default can still be overridden per-dependency; for instance, "make USE_INTERNAL_LIBS=0 USE_INTERNAL_OPUS=1" will use the system version of everything except Opus. --- Makefile | 16 ++++++++++------ README | 4 ++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index f7ae1159..b4d9be64 100644 --- a/Makefile +++ b/Makefile @@ -187,28 +187,32 @@ ifndef USE_FREETYPE USE_FREETYPE=0 endif +ifndef USE_INTERNAL_LIBS +USE_INTERNAL_LIBS=1 +endif + ifndef USE_INTERNAL_SPEEX -USE_INTERNAL_SPEEX=1 +USE_INTERNAL_SPEEX=$(USE_INTERNAL_LIBS) endif ifndef USE_INTERNAL_OGG -USE_INTERNAL_OGG=1 +USE_INTERNAL_OGG=$(USE_INTERNAL_LIBS) endif ifndef USE_INTERNAL_OPUS -USE_INTERNAL_OPUS=1 +USE_INTERNAL_OPUS=$(USE_INTERNAL_LIBS) endif ifndef USE_INTERNAL_ZLIB -USE_INTERNAL_ZLIB=1 +USE_INTERNAL_ZLIB=$(USE_INTERNAL_LIBS) endif ifndef USE_INTERNAL_JPEG -USE_INTERNAL_JPEG=1 +USE_INTERNAL_JPEG=$(USE_INTERNAL_LIBS) endif ifndef USE_LOCAL_HEADERS -USE_LOCAL_HEADERS=1 +USE_LOCAL_HEADERS=$(USE_INTERNAL_LIBS) endif ifndef USE_RENDERER_DLOPEN diff --git a/README b/README index 1f4cf49c..9f10163b 100644 --- a/README +++ b/README @@ -97,6 +97,10 @@ Makefile.local: USE_CODEC_OPUS - enable Ogg Opus support USE_MUMBLE - enable Mumble support USE_VOIP - enable built-in VoIP support + USE_INTERNAL_LIBS - build internal libraries instead of dynamically + linking against system libraries; this just sets + the default for USE_INTERNAL_SPEEX etc. + and USE_LOCAL_HEADERS USE_INTERNAL_SPEEX - build internal speex library instead of dynamically linking against system libspeex USE_FREETYPE - enable FreeType support for rendering fonts From 608347c84d94052311992ed6eca8163f19043c7a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 19 May 2013 20:52:23 +0100 Subject: [PATCH 02/28] Centralize checks for Freetype, with a user override This lets us find a library in a non-standard library directory (via -L in the pkg-config metadata), and allows overrides similar to the Autoconf convention, e.g. make FREETYPE_CFLAGS=-I/opt/freetype/include \ FREETYPE_LIBS="-L/opt/freetype/lib -lfreetype" If pkg-config didn't work, assume that Freetype is in the default location. --- Makefile | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index b4d9be64..9d8d0f26 100644 --- a/Makefile +++ b/Makefile @@ -271,7 +271,6 @@ ifneq ($(BUILD_CLIENT),0) OPENAL_LIBS=$(shell pkg-config --silence-errors --libs openal) SDL_CFLAGS=$(shell pkg-config --silence-errors --cflags sdl|sed 's/-Dmain=SDL_main//') SDL_LIBS=$(shell pkg-config --silence-errors --libs sdl) - FREETYPE_CFLAGS=$(shell pkg-config --silence-errors --cflags freetype2) endif # Use sdl-config if all else fails ifeq ($(SDL_CFLAGS),) @@ -385,10 +384,6 @@ ifneq (,$(findstring "$(PLATFORM)", "linux" "gnu_kfreebsd" "kfreebsd-gnu")) CLIENT_LIBS += -lrt endif - ifeq ($(USE_FREETYPE),1) - BASE_CFLAGS += $(FREETYPE_CFLAGS) - endif - ifeq ($(ARCH),x86) # linux32 make ... BASE_CFLAGS += -m32 @@ -466,10 +461,6 @@ ifeq ($(PLATFORM),darwin) endif endif - ifeq ($(USE_FREETYPE),1) - BASE_CFLAGS += $(FREETYPE_CFLAGS) - endif - BASE_CFLAGS += -D_THREAD_SAFE=1 ifeq ($(USE_LOCAL_HEADERS),1) @@ -584,7 +575,7 @@ ifeq ($(PLATFORM),mingw32) RENDERER_LIBS = -lgdi32 -lole32 -lopengl32 ifeq ($(USE_FREETYPE),1) - BASE_CFLAGS += -Ifreetype2 + FREETYPE_CFLAGS = -Ifreetype2 endif ifeq ($(USE_CURL),1) @@ -913,10 +904,6 @@ endif TARGETS = -ifeq ($(USE_FREETYPE),1) - BASE_CFLAGS += -DBUILD_FREETYPE -endif - ifndef FULLBINEXT FULLBINEXT=.$(ARCH)$(BINEXT) endif @@ -1048,7 +1035,11 @@ else endif ifeq ($(USE_FREETYPE),1) - RENDERER_LIBS += -lfreetype + FREETYPE_CFLAGS ?= $(shell pkg-config --silence-errors --cflags freetype2 || true) + FREETYPE_LIBS ?= $(shell pkg-config --silence-errors --libs freetype2 || echo -lfreetype) + + BASE_CFLAGS += -DBUILD_FREETYPE $(FREETYPE_CFLAGS) + RENDERER_LIBS += $(FREETYPE_LIBS) endif ifeq ("$(CC)", $(findstring "$(CC)", "clang" "clang++")) From b1da3556444ae4413e4c078b6226c25f0a6afe7d Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 19 May 2013 20:57:04 +0100 Subject: [PATCH 03/28] Allow libcurl to be in a non-standard location on all platforms We didn't add CURL_CFLAGS to CLIENT_CFLAGS on all platforms, and didn't use CURL_LIBS at all, so if "pkg-config --libs" returned "-L... -lcurl" or even "/.../libcurl.a", it wouldn't work. --- Makefile | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 9d8d0f26..4f8ac039 100644 --- a/Makefile +++ b/Makefile @@ -271,6 +271,9 @@ ifneq ($(BUILD_CLIENT),0) OPENAL_LIBS=$(shell pkg-config --silence-errors --libs openal) SDL_CFLAGS=$(shell pkg-config --silence-errors --cflags sdl|sed 's/-Dmain=SDL_main//') SDL_LIBS=$(shell pkg-config --silence-errors --libs sdl) + else + # assume they're in the system default paths (no -I or -L needed) + CURL_LIBS=-lcurl endif # Use sdl-config if all else fails ifeq ($(SDL_CFLAGS),) @@ -375,8 +378,9 @@ ifneq (,$(findstring "$(PLATFORM)", "linux" "gnu_kfreebsd" "kfreebsd-gnu")) endif ifeq ($(USE_CURL),1) + CLIENT_CFLAGS += $(CURL_CFLAGS) ifneq ($(USE_CURL_DLOPEN),1) - CLIENT_LIBS += -lcurl + CLIENT_LIBS += $(CURL_LIBS) endif endif @@ -456,8 +460,9 @@ ifeq ($(PLATFORM),darwin) endif ifeq ($(USE_CURL),1) + CLIENT_CFLAGS += $(CURL_CFLAGS) ifneq ($(USE_CURL_DLOPEN),1) - CLIENT_LIBS += -lcurl + CLIENT_LIBS += $(CURL_LIBS) endif endif @@ -666,8 +671,9 @@ ifeq ($(PLATFORM),freebsd) endif ifeq ($(USE_CURL),1) + CLIENT_CFLAGS += $(CURL_CFLAGS) ifeq ($(USE_CURL_DLOPEN),1) - CLIENT_LIBS += -lcurl + CLIENT_LIBS += $(CURL_LIBS) endif endif @@ -760,7 +766,7 @@ ifeq ($(PLATFORM),openbsd) ifeq ($(USE_CURL),1) ifneq ($(USE_CURL_DLOPEN),1) - CLIENT_LIBS += -lcurl + CLIENT_LIBS += $(CURL_LIBS) endif endif else # ifeq openbsd From 2821aa41d781a7ff15b425ef5cc96b523a796d68 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 19 May 2013 21:06:16 +0100 Subject: [PATCH 04/28] Allow OpenAL to be in a non-standard location on all platforms Similar to libcurl, we didn't use OPENAL_LIBS and assumed it was always "-lopenal". --- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 4f8ac039..35c1fc96 100644 --- a/Makefile +++ b/Makefile @@ -274,6 +274,7 @@ ifneq ($(BUILD_CLIENT),0) else # assume they're in the system default paths (no -I or -L needed) CURL_LIBS=-lcurl + OPENAL_LIBS=-lopenal endif # Use sdl-config if all else fails ifeq ($(SDL_CFLAGS),) @@ -373,7 +374,7 @@ ifneq (,$(findstring "$(PLATFORM)", "linux" "gnu_kfreebsd" "kfreebsd-gnu")) ifeq ($(USE_OPENAL),1) ifneq ($(USE_OPENAL_DLOPEN),1) - CLIENT_LIBS += -lopenal + CLIENT_LIBS += $(OPENAL_LIBS) endif endif @@ -666,7 +667,7 @@ ifeq ($(PLATFORM),freebsd) # optional features/libraries ifeq ($(USE_OPENAL),1) ifeq ($(USE_OPENAL_DLOPEN),1) - CLIENT_LIBS += $(THREAD_LIBS) -lopenal + CLIENT_LIBS += $(THREAD_LIBS) $(OPENAL_LIBS) endif endif @@ -760,7 +761,7 @@ ifeq ($(PLATFORM),openbsd) ifeq ($(USE_OPENAL),1) ifneq ($(USE_OPENAL_DLOPEN),1) - CLIENT_LIBS += $(THREAD_LIBS) -lopenal + CLIENT_LIBS += $(THREAD_LIBS) $(OPENAL_LIBS) endif endif From 9ff2fc3324503a95f1220521b8d063fca15a5db3 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 19 May 2013 20:58:42 +0100 Subject: [PATCH 05/28] Allow system libjpeg to be in a non-standard location It doesn't have pkg-config metadata (at least on Debian), so if the user doesn't override it, assume normal system paths. --- Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 35c1fc96..416d1f17 100644 --- a/Makefile +++ b/Makefile @@ -1038,7 +1038,13 @@ ifeq ($(USE_INTERNAL_JPEG),1) BASE_CFLAGS += -DUSE_INTERNAL_JPEG BASE_CFLAGS += -I$(JPDIR) else - RENDERER_LIBS += -ljpeg + # libjpeg doesn't have pkg-config yet, but let users override with + # "make JPEG_CFLAGS=-I/opt/jpeg/include JPEG_LIBS='-L/opt/jpeg/lib -ljpeg'" + # if they need to + JPEG_CFLAGS ?= + JPEG_LIBS ?= -ljpeg + BASE_CFLAGS += $(JPEG_CFLAGS) + RENDERER_LIBS += $(JPEG_LIBS) endif ifeq ($(USE_FREETYPE),1) From c817ab5ae0601a9bbdce6c36f7cdccff9fe7474b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 19 May 2013 21:31:12 +0100 Subject: [PATCH 06/28] Find system zlib via user override, pkg-config or in standard locations --- Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 416d1f17..1563d703 100644 --- a/Makefile +++ b/Makefile @@ -1028,11 +1028,13 @@ ifeq ($(USE_VOIP),1) endif ifeq ($(USE_INTERNAL_ZLIB),1) - BASE_CFLAGS += -DNO_GZIP - BASE_CFLAGS += -I$(ZDIR) + ZLIB_CFLAGS = -DNO_GZIP -I$(ZDIR) else - LIBS += -lz + ZLIB_CFLAGS ?= $(shell pkg-config --silence-errors --cflags zlib || true) + ZLIB_LIBS ?= $(shell pkg-config --silence-errors --libs zlib || echo -lz) endif +BASE_CFLAGS += $(ZLIB_CFLAGS) +LIBS += $(ZLIB_LIBS) ifeq ($(USE_INTERNAL_JPEG),1) BASE_CFLAGS += -DUSE_INTERNAL_JPEG From cff1fcd658fe1805791ed9658d2822ab356fffeb Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 19 May 2013 21:02:31 +0100 Subject: [PATCH 07/28] Look for system Vorbis, Opus and Ogg via pkg-config As usual, the order of precedence is: user override, pkg-config, or assume they're in standard locations. In particular, Opus isn't in the default search path on Debian. --- Makefile | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 1563d703..086048dc 100644 --- a/Makefile +++ b/Makefile @@ -982,31 +982,37 @@ ifeq ($(USE_CURL),1) endif ifeq ($(USE_CODEC_VORBIS),1) - CLIENT_CFLAGS += -DUSE_CODEC_VORBIS - CLIENT_LIBS += -lvorbisfile -lvorbis + VORBIS_CFLAGS ?= $(shell pkg-config --silence-errors --cflags vorbisfile vorbis || true) + VORBIS_LIBS ?= $(shell pkg-config --silence-errors --libs vorbisfile vorbis || echo -lvorbisfile -lvorbis) + CLIENT_CFLAGS += -DUSE_CODEC_VORBIS $(VORBIS_CFLAGS) + CLIENT_LIBS += $(VORBIS_LIBS) NEED_OGG=1 endif ifeq ($(USE_CODEC_OPUS),1) CLIENT_CFLAGS += -DUSE_CODEC_OPUS ifeq ($(USE_INTERNAL_OPUS),1) - CLIENT_CFLAGS += -DOPUS_BUILD -DHAVE_LRINTF -DFLOATING_POINT -DUSE_ALLOCA \ + OPUS_CFLAGS = -DOPUS_BUILD -DHAVE_LRINTF -DFLOATING_POINT -DUSE_ALLOCA \ -I$(OPUSDIR)/include -I$(OPUSDIR)/celt -I$(OPUSDIR)/silk \ - -I$(OPUSDIR)/silk/float - - CLIENT_CFLAGS += -I$(OPUSFILEDIR)/include + -I$(OPUSDIR)/silk/float -I$(OPUSFILEDIR)/include else - CLIENT_LIBS += -lopusfile -lopus + OPUS_CFLAGS=$(shell pkg-config --silence-errors --cflags opusfile opus || true) + OPUS_LIBS=$(shell pkg-config --silence-errors --libs opusfile opus || echo -lopusfile -lopus) endif + CLIENT_CFLAGS += $(OPUS_CFLAGS) + CLIENT_LIBS += $(OPUS_LIBS) NEED_OGG=1 endif ifeq ($(NEED_OGG),1) ifeq ($(USE_INTERNAL_OGG),1) - CLIENT_CFLAGS += -I$(OGGDIR)/include + OGG_CFLAGS = -I$(OGGDIR)/include else - CLIENT_LIBS += -logg + OGG_CFLAGS ?= $(shell pkg-config --silence-errors --cflags ogg || true) + OGG_LIBS ?= $(shell pkg-config --silence-errors --libs ogg || echo -logg) endif + CLIENT_CFLAGS += $(OGG_CFLAGS) + CLIENT_LIBS += $(OGG_LIBS) endif ifeq ($(USE_RENDERER_DLOPEN),1) From 69999280c6645998a497dd80c87e9c3c0f0f83a4 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 19 May 2013 21:19:36 +0100 Subject: [PATCH 08/28] Find Speex via user override, pkg-config or default search path --- Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 086048dc..6173dc74 100644 --- a/Makefile +++ b/Makefile @@ -1027,10 +1027,13 @@ ifeq ($(USE_VOIP),1) CLIENT_CFLAGS += -DUSE_VOIP SERVER_CFLAGS += -DUSE_VOIP ifeq ($(USE_INTERNAL_SPEEX),1) - CLIENT_CFLAGS += -DFLOATING_POINT -DUSE_ALLOCA -I$(SPEEXDIR)/include + SPEEX_CFLAGS += -DFLOATING_POINT -DUSE_ALLOCA -I$(SPEEXDIR)/include else - CLIENT_LIBS += -lspeex -lspeexdsp + SPEEX_CFLAGS ?= $(shell pkg-config --silence-errors --cflags speex speexdsp || true) + SPEEX_LIBS ?= $(shell pkg-config --silence-errors --libs speex speexdsp || echo -lspeex -lspeexdsp) endif + CLIENT_CFLAGS += $(SPEEX_CFLAGS) + CLIENT_LIBS += $(SPEEX_LIBS) endif ifeq ($(USE_INTERNAL_ZLIB),1) From 95b241b8ba3d7eacf5e8a9dfbab45aab907b4b6c Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Tue, 10 Jun 2014 21:21:32 -0500 Subject: [PATCH 09/28] OpenGL2 don't try to dlight surfaces that had all dlights culled In the renderers, dlightbits are never cleared from world surfaces. The dlight image does not repeat, so if it draws on extra surfaces it's not visible. However if using a repeating image (tr.defaultImage instead of tr.dlightImage); * In OpenGL1 image is only drawn on surfaces close to dlight origin. * In OpenGL2 image is draw on surfaces clearly outside the dlight radius, including past non-dlighted surfaces. It seems there was a similar issue with pshadowBits. So update surface dlightBits even if 0, like already done for pshadowBits. This causes only surfaces close to origin to be affected. (Though it is a little farther than in OpenGL1.) I have no idea why this isn't a problem in OpenGL1. --- code/renderergl2/tr_world.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/renderergl2/tr_world.c b/code/renderergl2/tr_world.c index f4edbb03..8bd6fae9 100644 --- a/code/renderergl2/tr_world.c +++ b/code/renderergl2/tr_world.c @@ -330,7 +330,7 @@ static void R_AddWorldSurface( msurface_t *surf, int dlightBits, int pshadowBits } // check for dlighting - if ( dlightBits ) { + /*if ( dlightBits ) */{ dlightBits = R_DlightSurface( surf, dlightBits ); dlightBits = ( dlightBits != 0 ); } From 5c1091b41453594735d23096b5ddc727ad963602 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Tue, 17 Jun 2014 21:28:22 -0500 Subject: [PATCH 10/28] Fix SkipRestOfLine going past end of string If string data starts with a 0 (string terminator), don't skip over it at p++. Not causing any problems in ioq3 as far as I know. --- code/qcommon/q_shared.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code/qcommon/q_shared.c b/code/qcommon/q_shared.c index 690838cc..a771c829 100644 --- a/code/qcommon/q_shared.c +++ b/code/qcommon/q_shared.c @@ -600,6 +600,10 @@ void SkipRestOfLine ( char **data ) { int c; p = *data; + + if ( !*p ) + return; + while ( (c = *p++) != 0 ) { if ( c == '\n' ) { com_lines++; From 599456453786acd021e4e702ff0075116536eb79 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Thu, 19 Jun 2014 20:48:54 -0500 Subject: [PATCH 11/28] Remove unused array joy_pressed --- code/sdl/sdl_input.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/code/sdl/sdl_input.c b/code/sdl/sdl_input.c index 88c0ef58..5035285b 100644 --- a/code/sdl/sdl_input.c +++ b/code/sdl/sdl_input.c @@ -658,7 +658,6 @@ IN_JoyMove */ static void IN_JoyMove( void ) { - qboolean joy_pressed[ARRAY_LEN(joy_keys)]; unsigned int axes = 0; unsigned int hats = 0; int total = 0; @@ -669,8 +668,6 @@ static void IN_JoyMove( void ) SDL_JoystickUpdate(); - memset(joy_pressed, '\0', sizeof (joy_pressed)); - // update the ball state. total = SDL_JoystickNumBalls(stick); if (total > 0) From 1d664a3a10d6edbf97ee9f6d9f45f48e1d22b112 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Thu, 3 Jul 2014 20:59:54 -0500 Subject: [PATCH 12/28] Remove unused cvar in_joystickDebug --- code/sdl/sdl_input.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/code/sdl/sdl_input.c b/code/sdl/sdl_input.c index 5035285b..6cefc5e3 100644 --- a/code/sdl/sdl_input.c +++ b/code/sdl/sdl_input.c @@ -63,7 +63,6 @@ static double originalMouseSpeed = -1.0; static cvar_t *in_nograb; static cvar_t *in_joystick = NULL; -static cvar_t *in_joystickDebug = NULL; static cvar_t *in_joystickThreshold = NULL; static cvar_t *in_joystickNo = NULL; static cvar_t *in_joystickUseAnalog = NULL; @@ -1038,7 +1037,6 @@ void IN_Init( void ) in_nograb = Cvar_Get( "in_nograb", "0", CVAR_ARCHIVE ); in_joystick = Cvar_Get( "in_joystick", "0", CVAR_ARCHIVE|CVAR_LATCH ); - in_joystickDebug = Cvar_Get( "in_joystickDebug", "0", CVAR_TEMP ); in_joystickThreshold = Cvar_Get( "joy_threshold", "0.15", CVAR_ARCHIVE ); #ifdef MACOS_X_ACCELERATION_HACK From d9309ac6db0dbd4e0b424bbf98d9e4c64f538f10 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Thu, 3 Jul 2014 21:06:05 -0500 Subject: [PATCH 13/28] Fix overstrike/insert logic being reversed in q3_ui --- code/q3_ui/ui_mfield.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/q3_ui/ui_mfield.c b/code/q3_ui/ui_mfield.c index d2862ff4..9eae7e01 100644 --- a/code/q3_ui/ui_mfield.c +++ b/code/q3_ui/ui_mfield.c @@ -253,7 +253,7 @@ void MField_CharEvent( mfield_t *edit, int ch ) { return; } - if ( !trap_Key_GetOverstrikeMode() ) { + if ( trap_Key_GetOverstrikeMode() ) { if ((edit->cursor == MAX_EDIT_LINE - 1) || (edit->maxchars && edit->cursor >= edit->maxchars)) return; } else { From b9e0398244bb93433daa57133b1a08fd031b9f52 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sat, 12 Jul 2014 21:49:40 -0500 Subject: [PATCH 14/28] Don't draw client console buffer past top of screen Thanks @Pan7. --- code/client/cl_console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/client/cl_console.c b/code/client/cl_console.c index d1b9fec1..dee9d0cb 100644 --- a/code/client/cl_console.c +++ b/code/client/cl_console.c @@ -677,7 +677,7 @@ void Con_DrawSolidConsole( float frac ) { // draw the text con.vislines = lines; - rows = (lines-SMALLCHAR_WIDTH)/SMALLCHAR_WIDTH; // rows of text to draw + rows = (lines-SMALLCHAR_HEIGHT*2)/SMALLCHAR_HEIGHT; // rows of text to draw y = lines - (SMALLCHAR_HEIGHT*3); From 0fe2e8d2249deb0ea4a07c3a0284f185f8b62628 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sun, 13 Jul 2014 01:56:50 -0500 Subject: [PATCH 15/28] Restore drawing a cut off client console line in 1920x1080 The text lines don't meet at top of the sceen in 1920x1080, restore drawing a cut off line across the top. In 640x480 this line isn't seen at all. This is still better then trying to draw twice as many lines than are actually seen (the way it was before the last commit). --- code/client/cl_console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/client/cl_console.c b/code/client/cl_console.c index dee9d0cb..a3d4d322 100644 --- a/code/client/cl_console.c +++ b/code/client/cl_console.c @@ -677,7 +677,7 @@ void Con_DrawSolidConsole( float frac ) { // draw the text con.vislines = lines; - rows = (lines-SMALLCHAR_HEIGHT*2)/SMALLCHAR_HEIGHT; // rows of text to draw + rows = (lines-SMALLCHAR_HEIGHT)/SMALLCHAR_HEIGHT; // rows of text to draw y = lines - (SMALLCHAR_HEIGHT*3); From 7afb433e2045a65e139e48a3744027543552fd1a Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Tue, 15 Jul 2014 00:19:48 -0500 Subject: [PATCH 16/28] Fix fast-math optimize flag for MinGW x86_64 build Found by /dev/humancontroller. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4c939122..e2fe1d13 100644 --- a/Makefile +++ b/Makefile @@ -558,7 +558,7 @@ ifeq ($(PLATFORM),mingw32) ifeq ($(ARCH),x86_64) OPTIMIZEVM = -O3 -fno-omit-frame-pointer \ -funroll-loops -falign-functions=2 -fstrength-reduce - OPTIMIZE = $(OPTIMIZEVM) --fast-math + OPTIMIZE = $(OPTIMIZEVM) -ffast-math HAVE_VM_COMPILED = true endif ifeq ($(ARCH),x86) From 16b48b50dd9be097a88757f955afd702322a1dfc Mon Sep 17 00:00:00 2001 From: Pan7 Date: Mon, 14 Jul 2014 03:43:03 +0200 Subject: [PATCH 17/28] -ffast-math for msvc --- misc/msvc/opengl1.vcproj | 4 ++++ misc/msvc/opengl2.vcproj | 4 ++++ misc/msvc/quake3.vcproj | 4 ++++ misc/msvc10/quake3.vcxproj | 8 ++++++++ misc/msvc11/quake3.vcxproj | 8 ++++++++ 5 files changed, 28 insertions(+) diff --git a/misc/msvc/opengl1.vcproj b/misc/msvc/opengl1.vcproj index 6dc6973f..a1daff6b 100644 --- a/misc/msvc/opengl1.vcproj +++ b/misc/msvc/opengl1.vcproj @@ -61,6 +61,7 @@ WarningLevel="4" SuppressStartupBanner="true" CompileAs="1" + FloatingPointModel="2" /> Level4 true CompileAsC + Fast NDEBUG;%(PreprocessorDefinitions) @@ -220,6 +221,7 @@ Level4 true CompileAsC + Fast NDEBUG;%(PreprocessorDefinitions) @@ -273,6 +275,7 @@ true EditAndContinue CompileAsC + Fast _DEBUG;%(PreprocessorDefinitions) @@ -327,6 +330,7 @@ true ProgramDatabase CompileAsC + Fast FastCall @@ -382,6 +386,7 @@ Level4 true CompileAsC + Fast NDEBUG;%(PreprocessorDefinitions) @@ -430,6 +435,7 @@ Level4 true CompileAsC + Fast NDEBUG;%(PreprocessorDefinitions) @@ -478,6 +484,7 @@ true EditAndContinue CompileAsC + Fast _DEBUG;%(PreprocessorDefinitions) @@ -532,6 +539,7 @@ true ProgramDatabase CompileAsC + Fast _DEBUG;%(PreprocessorDefinitions) diff --git a/misc/msvc11/quake3.vcxproj b/misc/msvc11/quake3.vcxproj index 4f203d9e..1c26fda8 100644 --- a/misc/msvc11/quake3.vcxproj +++ b/misc/msvc11/quake3.vcxproj @@ -188,6 +188,7 @@ Level4 true CompileAsC + Fast NDEBUG;%(PreprocessorDefinitions) @@ -241,6 +242,7 @@ Level4 true CompileAsC + Fast NDEBUG;%(PreprocessorDefinitions) @@ -294,6 +296,7 @@ true EditAndContinue CompileAsC + Fast _DEBUG;%(PreprocessorDefinitions) @@ -349,6 +352,7 @@ true ProgramDatabase CompileAsC + Fast FastCall @@ -404,6 +408,7 @@ Level4 true CompileAsC + Fast NDEBUG;%(PreprocessorDefinitions) @@ -453,6 +458,7 @@ Level4 true CompileAsC + Fast NDEBUG;%(PreprocessorDefinitions) @@ -501,6 +507,7 @@ true EditAndContinue CompileAsC + Fast _DEBUG;%(PreprocessorDefinitions) @@ -556,6 +563,7 @@ true ProgramDatabase CompileAsC + Fast _DEBUG;%(PreprocessorDefinitions) From b02b54883b49faa6b5c12f9743b8c4d6ed44e909 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sun, 20 Jul 2014 05:58:38 -0500 Subject: [PATCH 18/28] Fix up vorbis handling in Makefile --- Makefile | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 1e09a30c..d3183497 100644 --- a/Makefile +++ b/Makefile @@ -200,7 +200,7 @@ USE_INTERNAL_OGG=$(USE_INTERNAL_LIBS) endif ifndef USE_INTERNAL_VORBIS -USE_INTERNAL_VORBIS=1 +USE_INTERNAL_VORBIS=$(USE_INTERNAL_LIBS) endif ifndef USE_INTERNAL_OPUS @@ -982,14 +982,6 @@ ifeq ($(USE_CURL),1) endif endif -ifeq ($(USE_CODEC_VORBIS),1) - VORBIS_CFLAGS ?= $(shell pkg-config --silence-errors --cflags vorbisfile vorbis || true) - VORBIS_LIBS ?= $(shell pkg-config --silence-errors --libs vorbisfile vorbis || echo -lvorbisfile -lvorbis) - CLIENT_CFLAGS += -DUSE_CODEC_VORBIS $(VORBIS_CFLAGS) - CLIENT_LIBS += $(VORBIS_LIBS) - NEED_OGG=1 -endif - ifeq ($(USE_CODEC_OPUS),1) CLIENT_CFLAGS += -DUSE_CODEC_OPUS ifeq ($(USE_INTERNAL_OPUS),1) @@ -1005,6 +997,19 @@ ifeq ($(USE_CODEC_OPUS),1) NEED_OGG=1 endif +ifeq ($(USE_CODEC_VORBIS),1) + CLIENT_CFLAGS += -DUSE_CODEC_VORBIS + ifeq ($(USE_INTERNAL_VORBIS),1) + CLIENT_CFLAGS += -I$(VORBISDIR)/include -I$(VORBISDIR)/lib + else + VORBIS_CFLAGS ?= $(shell pkg-config --silence-errors --cflags vorbisfile vorbis || true) + VORBIS_LIBS ?= $(shell pkg-config --silence-errors --libs vorbisfile vorbis || echo -lvorbisfile -lvorbis) + endif + CLIENT_CFLAGS += $(VORBIS_CFLAGS) + CLIENT_LIBS += $(VORBIS_LIBS) + NEED_OGG=1 +endif + ifeq ($(NEED_OGG),1) ifeq ($(USE_INTERNAL_OGG),1) OGG_CFLAGS = -I$(OGGDIR)/include @@ -1016,15 +1021,6 @@ ifeq ($(NEED_OGG),1) CLIENT_LIBS += $(OGG_LIBS) endif -ifeq ($(USE_CODEC_VORBIS),1) - ifeq ($(USE_INTERNAL_VORBIS),1) - CLIENT_CFLAGS += -I$(VORBISDIR)/include -I$(VORBISDIR)/lib - - else - CLIENT_LIBS += -lvorbisfile -lvorbis - endif -endif - ifeq ($(USE_RENDERER_DLOPEN),1) CLIENT_CFLAGS += -DUSE_RENDERER_DLOPEN endif From 574f6d1f31fcdc699462d8546cbdce0f13b7edea Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sun, 20 Jul 2014 16:55:41 -0500 Subject: [PATCH 19/28] Allow overriding external opus libs/cflags in Makefile Pointed out by @MAN-AT-ARMS. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d3183497..f606736b 100644 --- a/Makefile +++ b/Makefile @@ -989,8 +989,8 @@ ifeq ($(USE_CODEC_OPUS),1) -I$(OPUSDIR)/include -I$(OPUSDIR)/celt -I$(OPUSDIR)/silk \ -I$(OPUSDIR)/silk/float -I$(OPUSFILEDIR)/include else - OPUS_CFLAGS=$(shell pkg-config --silence-errors --cflags opusfile opus || true) - OPUS_LIBS=$(shell pkg-config --silence-errors --libs opusfile opus || echo -lopusfile -lopus) + OPUS_CFLAGS ?= $(shell pkg-config --silence-errors --cflags opusfile opus || true) + OPUS_LIBS ?= $(shell pkg-config --silence-errors --libs opusfile opus || echo -lopusfile -lopus) endif CLIENT_CFLAGS += $(OPUS_CFLAGS) CLIENT_LIBS += $(OPUS_LIBS) From a8dcf60b761f3c08991f42d473e17c7708a5e6fa Mon Sep 17 00:00:00 2001 From: MAN-AT-ARMS Date: Sun, 20 Jul 2014 17:31:37 -0500 Subject: [PATCH 20/28] Fix compiling on Linux Mint --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f606736b..aba44499 100644 --- a/Makefile +++ b/Makefile @@ -377,7 +377,7 @@ ifneq (,$(findstring "$(PLATFORM)", "linux" "gnu_kfreebsd" "kfreebsd-gnu")) ifeq ($(USE_OPENAL),1) ifneq ($(USE_OPENAL_DLOPEN),1) - CLIENT_LIBS += $(OPENAL_LIBS) + CLIENT_LIBS += $(THREAD_LIBS) $(OPENAL_LIBS) endif endif From 48738599a089e8f28d5f460bed47f21d63bae04a Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sun, 20 Jul 2014 17:39:27 -0500 Subject: [PATCH 21/28] Allow user override of cURL, OpenAL, and SDL libs/cflags --- Makefile | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index aba44499..2e97e12b 100644 --- a/Makefile +++ b/Makefile @@ -270,22 +270,22 @@ ifneq ($(BUILD_CLIENT),0) # set PKG_CONFIG_PATH to influence this, e.g. # PKG_CONFIG_PATH=/opt/cross/i386-mingw32msvc/lib/pkgconfig ifneq ($(call bin_path, pkg-config),) - CURL_CFLAGS=$(shell pkg-config --silence-errors --cflags libcurl) - CURL_LIBS=$(shell pkg-config --silence-errors --libs libcurl) - OPENAL_CFLAGS=$(shell pkg-config --silence-errors --cflags openal) - OPENAL_LIBS=$(shell pkg-config --silence-errors --libs openal) - SDL_CFLAGS=$(shell pkg-config --silence-errors --cflags sdl|sed 's/-Dmain=SDL_main//') - SDL_LIBS=$(shell pkg-config --silence-errors --libs sdl) + CURL_CFLAGS ?= $(shell pkg-config --silence-errors --cflags libcurl) + CURL_LIBS ?= $(shell pkg-config --silence-errors --libs libcurl) + OPENAL_CFLAGS ?= $(shell pkg-config --silence-errors --cflags openal) + OPENAL_LIBS ?= $(shell pkg-config --silence-errors --libs openal) + SDL_CFLAGS ?= $(shell pkg-config --silence-errors --cflags sdl|sed 's/-Dmain=SDL_main//') + SDL_LIBS ?= $(shell pkg-config --silence-errors --libs sdl) else # assume they're in the system default paths (no -I or -L needed) - CURL_LIBS=-lcurl - OPENAL_LIBS=-lopenal + CURL_LIBS ?= -lcurl + OPENAL_LIBS ?= -lopenal endif # Use sdl-config if all else fails ifeq ($(SDL_CFLAGS),) ifneq ($(call bin_path, sdl-config),) - SDL_CFLAGS=$(shell sdl-config --cflags) - SDL_LIBS=$(shell sdl-config --libs) + SDL_CFLAGS ?= $(shell sdl-config --cflags) + SDL_LIBS ?= $(shell sdl-config --libs) endif endif endif From 3d01543e2c48cdaa5b5d7f5a1c2c96ef07c13a69 Mon Sep 17 00:00:00 2001 From: SmileTheory Date: Tue, 22 Jul 2014 11:43:19 -0700 Subject: [PATCH 22/28] OpenGL2: Replace R_MipMapsRGB() with faster version. --- code/renderergl2/tr_extramath.h | 3 -- code/renderergl2/tr_image.c | 76 ++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/code/renderergl2/tr_extramath.h b/code/renderergl2/tr_extramath.h index 0223c640..93271537 100644 --- a/code/renderergl2/tr_extramath.h +++ b/code/renderergl2/tr_extramath.h @@ -56,9 +56,6 @@ void Mat4SimpleInverse( const mat4_t in, mat4_t out); #define ByteToFloat(a) ((float)(a) * 1.0f/255.0f) #define FloatToByte(a) (byte)((a) * 255.0f) -#define RGBtosRGB(a) (((a) < 0.0031308f) ? (12.92f * (a)) : (1.055f * pow((a), 0.41666f) - 0.055f)) -#define sRGBtoRGB(a) (((a) <= 0.04045f) ? ((a) / 12.92f) : (pow((((a) + 0.055f) / 1.055f), 2.4)) ) - static ID_INLINE int VectorCompare4(const vec4_t v1, const vec4_t v2) { if(v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2] || v1[3] != v2[3]) diff --git a/code/renderergl2/tr_image.c b/code/renderergl2/tr_image.c index ffee673d..ac0054a2 100644 --- a/code/renderergl2/tr_image.c +++ b/code/renderergl2/tr_image.c @@ -1332,43 +1332,51 @@ static void R_MipMap2( byte *in, int inWidth, int inHeight ) { static void R_MipMapsRGB( byte *in, int inWidth, int inHeight) { - int i, j, k; - int outWidth, outHeight; - byte *temp; + int x, y, c, stride; + const byte *in2; + float total; + static float downmipSrgbLookup[256]; + static int downmipSrgbLookupSet = 0; + byte *out = in; - outWidth = inWidth >> 1; - outHeight = inHeight >> 1; - temp = ri.Hunk_AllocateTempMemory( outWidth * outHeight * 4 ); - - for ( i = 0 ; i < outHeight ; i++ ) { - byte *outbyte = temp + ( i * outWidth ) * 4; - byte *inbyte1 = in + ( i * 2 * inWidth ) * 4; - byte *inbyte2 = in + ( (i * 2 + 1) * inWidth ) * 4; - for ( j = 0 ; j < outWidth ; j++ ) { - for ( k = 0 ; k < 3 ; k++ ) { - float total, current; - - current = ByteToFloat(inbyte1[0]); total = sRGBtoRGB(current); - current = ByteToFloat(inbyte1[4]); total += sRGBtoRGB(current); - current = ByteToFloat(inbyte2[0]); total += sRGBtoRGB(current); - current = ByteToFloat(inbyte2[4]); total += sRGBtoRGB(current); - - total *= 0.25f; - - inbyte1++; - inbyte2++; - - current = RGBtosRGB(total); - *outbyte++ = FloatToByte(current); - } - *outbyte++ = (inbyte1[0] + inbyte1[4] + inbyte2[0] + inbyte2[4]) >> 2; - inbyte1 += 5; - inbyte2 += 5; - } + if (!downmipSrgbLookupSet) { + for (x = 0; x < 256; x++) + downmipSrgbLookup[x] = ((x < 10) ? x / 3294.6f : powf((x / 255.0f + 0.055f) / 1.055f, 2.4f)) * 0.25f; + downmipSrgbLookupSet = 1; } - Com_Memcpy( in, temp, outWidth * outHeight * 4 ); - ri.Hunk_FreeTempMemory( temp ); + if (inWidth == 1 && inHeight == 1) + return; + + if (inWidth == 1 || inHeight == 1) { + for (x = (inWidth * inHeight) >> 1; x; x--) { + for (c = 3; c; c--, in++) { + total = (downmipSrgbLookup[*(in)] + downmipSrgbLookup[*(in + 4)]) * 2.0f; + + *out++ = (byte)(powf(total, 1.0f / 2.2f) * 255.0f); + } + *out++ = (*(in) + *(in + 4)) >> 1; in += 5; + } + + return; + } + + stride = inWidth * 4; + inWidth >>= 1; inHeight >>= 1; + + in2 = in + stride; + for (y = inHeight; y; y--, in += stride, in2 += stride) { + for (x = inWidth; x; x--) { + for (c = 3; c; c--, in++, in2++) { + total = downmipSrgbLookup[*(in)] + downmipSrgbLookup[*(in + 4)] + + downmipSrgbLookup[*(in2)] + downmipSrgbLookup[*(in2 + 4)]; + + *out++ = (byte)(powf(total, 1.0f / 2.2f) * 255.0f); + } + + *out++ = (*(in) + *(in + 4) + *(in2) + *(in2 + 4)) >> 2; in += 5, in2 += 5; + } + } } /* From 75cce50a9ca5a606f271ef18bd27f27ac46dfd0f Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Fri, 25 Jul 2014 23:34:29 -0500 Subject: [PATCH 23/28] Don't load external GLSL files by default External GLSL should probably only be used for development testing, not released products. The GLSL files are tied to the code, and the code changes some what often. Fixes using OpenArena 0.8.8 which has incompatible GLSL files in a pk3. --- code/renderergl2/tr_glsl.c | 14 ++++++++++---- code/renderergl2/tr_init.c | 4 ++++ code/renderergl2/tr_local.h | 2 ++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/code/renderergl2/tr_glsl.c b/code/renderergl2/tr_glsl.c index 58a00e6e..ed078ddf 100644 --- a/code/renderergl2/tr_glsl.c +++ b/code/renderergl2/tr_glsl.c @@ -400,24 +400,30 @@ static int GLSL_LoadGPUShaderText(const char *name, const char *fallback, Com_sprintf(filename, sizeof(filename), "glsl/%s_fp.glsl", name); } - ri.Printf(PRINT_DEVELOPER, "...loading '%s'\n", filename); - size = ri.FS_ReadFile(filename, (void **)&buffer); + if ( r_externalGLSL->integer ) { + size = ri.FS_ReadFile(filename, (void **)&buffer); + } else { + size = 0; + buffer = NULL; + } + if(!buffer) { if (fallback) { - ri.Printf(PRINT_DEVELOPER, "couldn't load, using fallback\n"); + ri.Printf(PRINT_DEVELOPER, "...loading built-in '%s'\n", filename); shaderText = fallback; size = strlen(shaderText); } else { - ri.Printf(PRINT_DEVELOPER, "couldn't load!\n"); + ri.Printf(PRINT_DEVELOPER, "couldn't load '%s'\n", filename); return 0; } } else { + ri.Printf(PRINT_DEVELOPER, "...loading '%s'\n", filename); shaderText = buffer; } diff --git a/code/renderergl2/tr_init.c b/code/renderergl2/tr_init.c index 2a681007..045cd85a 100644 --- a/code/renderergl2/tr_init.c +++ b/code/renderergl2/tr_init.c @@ -108,6 +108,8 @@ cvar_t *r_mergeLeafSurfaces; cvar_t *r_cameraExposure; +cvar_t *r_externalGLSL; + cvar_t *r_hdr; cvar_t *r_floatLightmap; cvar_t *r_postProcess; @@ -1164,6 +1166,8 @@ void R_Register( void ) r_greyscale = ri.Cvar_Get("r_greyscale", "0", CVAR_ARCHIVE | CVAR_LATCH); ri.Cvar_CheckRange(r_greyscale, 0, 1, qfalse); + r_externalGLSL = ri.Cvar_Get( "r_externalGLSL", "0", CVAR_LATCH ); + r_hdr = ri.Cvar_Get( "r_hdr", "1", CVAR_ARCHIVE | CVAR_LATCH ); r_floatLightmap = ri.Cvar_Get( "r_floatLightmap", "0", CVAR_ARCHIVE | CVAR_LATCH ); r_postProcess = ri.Cvar_Get( "r_postProcess", "1", CVAR_ARCHIVE ); diff --git a/code/renderergl2/tr_local.h b/code/renderergl2/tr_local.h index 7bfa8769..7736b954 100644 --- a/code/renderergl2/tr_local.h +++ b/code/renderergl2/tr_local.h @@ -1765,6 +1765,8 @@ extern cvar_t *r_anaglyphMode; extern cvar_t *r_mergeMultidraws; extern cvar_t *r_mergeLeafSurfaces; +extern cvar_t *r_externalGLSL; + extern cvar_t *r_hdr; extern cvar_t *r_floatLightmap; extern cvar_t *r_postProcess; From 3c52f2dccc68aab3e0446cf531f844c9bd711fe6 Mon Sep 17 00:00:00 2001 From: hairball Date: Fri, 14 Feb 2014 04:34:17 +0000 Subject: [PATCH 24/28] Don't use -mwindows with Clang on Windows Thanks to stigmha for pointing out this doesn't work in Windows. --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2e97e12b..162120ac 100644 --- a/Makefile +++ b/Makefile @@ -580,7 +580,10 @@ ifeq ($(PLATFORM),mingw32) endif LIBS= -lws2_32 -lwinmm -lpsapi - CLIENT_LDFLAGS += -mwindows + # clang 3.4 doesn't support this + ifneq ("$(CC)", $(findstring "$(CC)", "clang" "clang++")) + CLIENT_LDFLAGS += -mwindows + endif CLIENT_LIBS = -lgdi32 -lole32 RENDERER_LIBS = -lgdi32 -lole32 -lopengl32 From 7b866ae96d97d876f5b5ca134c6533d10565782e Mon Sep 17 00:00:00 2001 From: /dev/humancontroller Date: Mon, 21 Jul 2014 17:43:53 +0200 Subject: [PATCH 25/28] guard against out-of-bounds jump table targets --- code/qcommon/vm_x86.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/qcommon/vm_x86.c b/code/qcommon/vm_x86.c index b896883d..77aba05b 100644 --- a/code/qcommon/vm_x86.c +++ b/code/qcommon/vm_x86.c @@ -1087,8 +1087,9 @@ void VM_Compile(vm_t *vm, vmHeader_t *header) // ensure that the optimisation pass knows about all the jump // table targets + pc = -1; // a bogus value to be printed in out-of-bounds error messages for( i = 0; i < vm->numJumpTableTargets; i++ ) { - jused[ *(int *)(vm->jumpTableTargets + ( i * sizeof( int ) ) ) ] = 1; + JUSED( *(int *)(vm->jumpTableTargets + ( i * sizeof( int ) ) ) ); } // Start buffer with x86-VM specific procedures From 2b2d696f1243b8810ab5ef26b84118a6c2389c70 Mon Sep 17 00:00:00 2001 From: SmileTheory Date: Thu, 31 Jul 2014 21:01:57 -0700 Subject: [PATCH 26/28] OpenGL2: Add fourth cascade for sun shadows, and adjust sun shadow cvar defaults. --- code/renderergl2/glsl/shadowmask_fp.glsl | 97 ++++++++------ code/renderergl2/tr_backend.c | 25 +++- code/renderergl2/tr_bsp.c | 3 + code/renderergl2/tr_fbo.c | 2 +- code/renderergl2/tr_glsl.c | 6 +- code/renderergl2/tr_image.c | 7 +- code/renderergl2/tr_init.c | 6 +- code/renderergl2/tr_local.h | 11 +- code/renderergl2/tr_main.c | 161 ++++++++++++++++------- code/renderergl2/tr_scene.c | 27 +++- 10 files changed, 235 insertions(+), 110 deletions(-) diff --git a/code/renderergl2/glsl/shadowmask_fp.glsl b/code/renderergl2/glsl/shadowmask_fp.glsl index b489fef5..8a5597a9 100644 --- a/code/renderergl2/glsl/shadowmask_fp.glsl +++ b/code/renderergl2/glsl/shadowmask_fp.glsl @@ -1,15 +1,17 @@ uniform sampler2D u_ScreenDepthMap; -uniform sampler2D u_ShadowMap; +uniform sampler2DShadow u_ShadowMap; #if defined(USE_SHADOW_CASCADE) -uniform sampler2D u_ShadowMap2; -uniform sampler2D u_ShadowMap3; +uniform sampler2DShadow u_ShadowMap2; +uniform sampler2DShadow u_ShadowMap3; +uniform sampler2DShadow u_ShadowMap4; #endif uniform mat4 u_ShadowMvp; #if defined(USE_SHADOW_CASCADE) uniform mat4 u_ShadowMvp2; uniform mat4 u_ShadowMvp3; +uniform mat4 u_ShadowMvp4; #endif uniform vec3 u_ViewOrigin; @@ -39,94 +41,103 @@ float random( const vec2 p ) return mod( 123456789., 1e-7 + 256. * dot(p,r) ); } -float PCF(const sampler2D shadowmap, const vec2 st, const float dist) +float PCF(const sampler2DShadow shadowmap, const vec2 st, const float dist) { float mult; float scale = 2.0 / r_shadowMapSize; +#if 0 + // from http://http.developer.nvidia.com/GPUGems/gpugems_ch11.html + vec2 offset = vec2(greaterThan(fract(var_DepthTex.xy * r_FBufScale * 0.5), vec2(0.25))); + offset.y += offset.x; + if (offset.y > 1.1) offset.y = 0.0; + + mult = shadow2D(shadowmap, vec3(st + (offset + vec2(-1.5, 0.5)) * scale, dist)).r + + shadow2D(shadowmap, vec3(st + (offset + vec2( 0.5, 0.5)) * scale, dist)).r + + shadow2D(shadowmap, vec3(st + (offset + vec2(-1.5, -1.5)) * scale, dist)).r + + shadow2D(shadowmap, vec3(st + (offset + vec2( 0.5, -1.5)) * scale, dist)).r; + + mult *= 0.25; +#endif + #if defined(USE_SHADOW_FILTER) float r = random(var_DepthTex.xy); float sinr = sin(r) * scale; float cosr = cos(r) * scale; mat2 rmat = mat2(cosr, sinr, -sinr, cosr); - mult = step(dist, texture2D(shadowmap, st + rmat * vec2(-0.7055767, 0.196515)).r); - mult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.3524343, -0.7791386)).r); - mult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.2391056, 0.9189604)).r); + mult = shadow2D(shadowmap, vec3(st + rmat * vec2(-0.7055767, 0.196515), dist)).r; + mult += shadow2D(shadowmap, vec3(st + rmat * vec2(0.3524343, -0.7791386), dist)).r; + mult += shadow2D(shadowmap, vec3(st + rmat * vec2(0.2391056, 0.9189604), dist)).r; #if defined(USE_SHADOW_FILTER2) - mult += step(dist, texture2D(shadowmap, st + rmat * vec2(-0.07580382, -0.09224417)).r); - mult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.5784913, -0.002528916)).r); - mult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.192888, 0.4064181)).r); - mult += step(dist, texture2D(shadowmap, st + rmat * vec2(-0.6335801, -0.5247476)).r); - mult += step(dist, texture2D(shadowmap, st + rmat * vec2(-0.5579782, 0.7491854)).r); - mult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.7320465, 0.6317794)).r); + mult += shadow2D(shadowmap, vec3(st + rmat * vec2(-0.07580382, -0.09224417), dist)).r; + mult += shadow2D(shadowmap, vec3(st + rmat * vec2(0.5784913, -0.002528916), dist)).r; + mult += shadow2D(shadowmap, vec3(st + rmat * vec2(0.192888, 0.4064181), dist)).r; + mult += shadow2D(shadowmap, vec3(st + rmat * vec2(-0.6335801, -0.5247476), dist)).r; + mult += shadow2D(shadowmap, vec3(st + rmat * vec2(-0.5579782, 0.7491854), dist)).r; + mult += shadow2D(shadowmap, vec3(st + rmat * vec2(0.7320465, 0.6317794), dist)).r; mult *= 0.11111; #else mult *= 0.33333; #endif #else - mult = step(dist, texture2D(shadowmap, st).r); + mult = shadow2D(shadowmap, vec3(st, dist)); #endif - + return mult; } float getLinearDepth(sampler2D depthMap, vec2 tex, float zFarDivZNear) { - float sampleZDivW = texture2D(depthMap, tex).r; - sampleZDivW -= DEPTH_MAX_ERROR; - return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW); + float sampleZDivW = texture2D(depthMap, tex).r - DEPTH_MAX_ERROR; + return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW); } void main() { float result; - + float depth = getLinearDepth(u_ScreenDepthMap, var_DepthTex, u_ViewInfo.x); - float sampleZ = u_ViewInfo.y * depth; - vec4 biasPos = vec4(u_ViewOrigin + var_ViewDir * (depth - 0.5 / u_ViewInfo.x), 1.0); - - vec4 shadowpos = u_ShadowMvp * biasPos; - -#if defined(USE_SHADOW_CASCADE) - const float fadeTo = 1.0; - result = fadeTo; -#else - result = 0.0; -#endif - if (all(lessThanEqual(abs(shadowpos.xyz), vec3(abs(shadowpos.w))))) - { - shadowpos.xyz = shadowpos.xyz / shadowpos.w * 0.5 + 0.5; - result = PCF(u_ShadowMap, shadowpos.xy, shadowpos.z); - } + vec4 shadowpos = u_ShadowMvp * biasPos; + #if defined(USE_SHADOW_CASCADE) + if (all(lessThan(abs(shadowpos.xyz), vec3(abs(shadowpos.w))))) + { +#endif + shadowpos.xyz = shadowpos.xyz * (0.5 / shadowpos.w) + vec3(0.5); + result = PCF(u_ShadowMap, shadowpos.xy, shadowpos.z); +#if defined(USE_SHADOW_CASCADE) + } else { shadowpos = u_ShadowMvp2 * biasPos; - if (all(lessThanEqual(abs(shadowpos.xyz), vec3(abs(shadowpos.w))))) + if (all(lessThan(abs(shadowpos.xyz), vec3(abs(shadowpos.w))))) { - shadowpos.xyz = shadowpos.xyz / shadowpos.w * 0.5 + 0.5; + shadowpos.xyz = shadowpos.xyz * (0.5 / shadowpos.w) + vec3(0.5); result = PCF(u_ShadowMap2, shadowpos.xy, shadowpos.z); } else { shadowpos = u_ShadowMvp3 * biasPos; - if (all(lessThanEqual(abs(shadowpos.xyz), vec3(abs(shadowpos.w))))) + if (all(lessThan(abs(shadowpos.xyz), vec3(abs(shadowpos.w))))) { - shadowpos.xyz = shadowpos.xyz / shadowpos.w * 0.5 + 0.5; + shadowpos.xyz = shadowpos.xyz * (0.5 / shadowpos.w) + vec3(0.5); result = PCF(u_ShadowMap3, shadowpos.xy, shadowpos.z); - - float fade = clamp(sampleZ / r_shadowCascadeZFar * 10.0 - 9.0, 0.0, 1.0); - result = mix(result, fadeTo, fade); + } + else + { + shadowpos = u_ShadowMvp4 * biasPos; + shadowpos.xyz = shadowpos.xyz * (0.5 / shadowpos.w) + vec3(0.5); + result = PCF(u_ShadowMap4, shadowpos.xy, shadowpos.z); } } } #endif - + gl_FragColor = vec4(vec3(result), 1.0); } diff --git a/code/renderergl2/tr_backend.c b/code/renderergl2/tr_backend.c index e4431cf5..b8314039 100644 --- a/code/renderergl2/tr_backend.c +++ b/code/renderergl2/tr_backend.c @@ -1122,13 +1122,24 @@ const void *RB_DrawSurfs( const void *data ) { GLSL_BindProgram(&tr.shadowmaskShader); GL_BindToTMU(tr.renderDepthImage, TB_COLORMAP); - GL_BindToTMU(tr.sunShadowDepthImage[0], TB_SHADOWMAP); - GL_BindToTMU(tr.sunShadowDepthImage[1], TB_SHADOWMAP2); - GL_BindToTMU(tr.sunShadowDepthImage[2], TB_SHADOWMAP3); + + if (r_shadowCascadeZFar->integer != 0) + { + GL_BindToTMU(tr.sunShadowDepthImage[0], TB_SHADOWMAP); + GL_BindToTMU(tr.sunShadowDepthImage[1], TB_SHADOWMAP2); + GL_BindToTMU(tr.sunShadowDepthImage[2], TB_SHADOWMAP3); + GL_BindToTMU(tr.sunShadowDepthImage[3], TB_SHADOWMAP4); - GLSL_SetUniformMat4(&tr.shadowmaskShader, UNIFORM_SHADOWMVP, backEnd.refdef.sunShadowMvp[0]); - GLSL_SetUniformMat4(&tr.shadowmaskShader, UNIFORM_SHADOWMVP2, backEnd.refdef.sunShadowMvp[1]); - GLSL_SetUniformMat4(&tr.shadowmaskShader, UNIFORM_SHADOWMVP3, backEnd.refdef.sunShadowMvp[2]); + GLSL_SetUniformMat4(&tr.shadowmaskShader, UNIFORM_SHADOWMVP, backEnd.refdef.sunShadowMvp[0]); + GLSL_SetUniformMat4(&tr.shadowmaskShader, UNIFORM_SHADOWMVP2, backEnd.refdef.sunShadowMvp[1]); + GLSL_SetUniformMat4(&tr.shadowmaskShader, UNIFORM_SHADOWMVP3, backEnd.refdef.sunShadowMvp[2]); + GLSL_SetUniformMat4(&tr.shadowmaskShader, UNIFORM_SHADOWMVP4, backEnd.refdef.sunShadowMvp[3]); + } + else + { + GL_BindToTMU(tr.sunShadowDepthImage[3], TB_SHADOWMAP); + GLSL_SetUniformMat4(&tr.shadowmaskShader, UNIFORM_SHADOWMVP, backEnd.refdef.sunShadowMvp[3]); + } GLSL_SetUniformVec3(&tr.shadowmaskShader, UNIFORM_VIEWORIGIN, backEnd.refdef.vieworg); { @@ -1681,6 +1692,8 @@ const void *RB_PostProcess(const void *data) FBO_BlitFromTexture(tr.sunShadowDepthImage[1], NULL, NULL, NULL, dstBox, NULL, NULL, 0); VectorSet4(dstBox, 256, 0, 128, 128); FBO_BlitFromTexture(tr.sunShadowDepthImage[2], NULL, NULL, NULL, dstBox, NULL, NULL, 0); + VectorSet4(dstBox, 384, 0, 128, 128); + FBO_BlitFromTexture(tr.sunShadowDepthImage[3], NULL, NULL, NULL, dstBox, NULL, NULL, 0); } if (0) diff --git a/code/renderergl2/tr_bsp.c b/code/renderergl2/tr_bsp.c index 63824284..25603af3 100644 --- a/code/renderergl2/tr_bsp.c +++ b/code/renderergl2/tr_bsp.c @@ -3313,6 +3313,9 @@ void RE_LoadWorldMap( const char *name ) { tr.toneMinAvgMaxLevel[1] = -2.0f; tr.toneMinAvgMaxLevel[2] = 0.0f; + // reset last cascade sun direction so last shadow cascade is rerendered + VectorClear(tr.lastCascadeSunDirection); + tr.worldMapLoaded = qtrue; // load it diff --git a/code/renderergl2/tr_fbo.c b/code/renderergl2/tr_fbo.c index c642b732..4070c6ef 100644 --- a/code/renderergl2/tr_fbo.c +++ b/code/renderergl2/tr_fbo.c @@ -484,7 +484,7 @@ void FBO_Init(void) if (tr.sunShadowDepthImage[0]) { - for ( i = 0; i < 3; i++) + for ( i = 0; i < 4; i++) { tr.sunShadowFbo[i] = FBO_Create("_sunshadowmap", tr.sunShadowDepthImage[i]->width, tr.sunShadowDepthImage[i]->height); FBO_Bind(tr.sunShadowFbo[i]); diff --git a/code/renderergl2/tr_glsl.c b/code/renderergl2/tr_glsl.c index ed078ddf..cb00e91c 100644 --- a/code/renderergl2/tr_glsl.c +++ b/code/renderergl2/tr_glsl.c @@ -79,10 +79,12 @@ static uniformInfo_t uniformsInfo[] = { "u_ShadowMap", GLSL_INT }, { "u_ShadowMap2", GLSL_INT }, { "u_ShadowMap3", GLSL_INT }, + { "u_ShadowMap4", GLSL_INT }, { "u_ShadowMvp", GLSL_MAT16 }, { "u_ShadowMvp2", GLSL_MAT16 }, { "u_ShadowMvp3", GLSL_MAT16 }, + { "u_ShadowMvp4", GLSL_MAT16 }, { "u_EnableTextures", GLSL_VEC4 }, @@ -1302,7 +1304,8 @@ void GLSL_InitGPUShaders(void) if (r_shadowFilter->integer >= 2) Q_strcat(extradefines, 1024, "#define USE_SHADOW_FILTER2\n"); - Q_strcat(extradefines, 1024, "#define USE_SHADOW_CASCADE\n"); + if (r_shadowCascadeZFar->integer != 0) + Q_strcat(extradefines, 1024, "#define USE_SHADOW_CASCADE\n"); Q_strcat(extradefines, 1024, va("#define r_shadowMapSize %d\n", r_shadowMapSize->integer)); Q_strcat(extradefines, 1024, va("#define r_shadowCascadeZFar %f\n", r_shadowCascadeZFar->value)); @@ -1320,6 +1323,7 @@ void GLSL_InitGPUShaders(void) GLSL_SetUniformInt(&tr.shadowmaskShader, UNIFORM_SHADOWMAP, TB_SHADOWMAP); GLSL_SetUniformInt(&tr.shadowmaskShader, UNIFORM_SHADOWMAP2, TB_SHADOWMAP2); GLSL_SetUniformInt(&tr.shadowmaskShader, UNIFORM_SHADOWMAP3, TB_SHADOWMAP3); + GLSL_SetUniformInt(&tr.shadowmaskShader, UNIFORM_SHADOWMAP4, TB_SHADOWMAP4); qglUseProgramObjectARB(0); GLSL_FinishGPUShader(&tr.shadowmaskShader); diff --git a/code/renderergl2/tr_image.c b/code/renderergl2/tr_image.c index ac0054a2..eff21988 100644 --- a/code/renderergl2/tr_image.c +++ b/code/renderergl2/tr_image.c @@ -2930,9 +2930,14 @@ void R_CreateBuiltinImages( void ) { if (r_sunlightMode->integer) { - for ( x = 0; x < 3; x++) + for ( x = 0; x < 4; x++) { tr.sunShadowDepthImage[x] = R_CreateImage(va("*sunshadowdepth%i", x), NULL, r_shadowMapSize->integer, r_shadowMapSize->integer, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_DEPTH_COMPONENT24_ARB); + GL_Bind(tr.sunShadowDepthImage[x]); + qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); + qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); } tr.screenShadowImage = R_CreateImage("*screenShadow", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8); diff --git a/code/renderergl2/tr_init.c b/code/renderergl2/tr_init.c index 045cd85a..2b66a6fd 100644 --- a/code/renderergl2/tr_init.c +++ b/code/renderergl2/tr_init.c @@ -1223,9 +1223,9 @@ void R_Register( void ) r_sunShadows = ri.Cvar_Get( "r_sunShadows", "1", CVAR_ARCHIVE | CVAR_LATCH ); r_shadowFilter = ri.Cvar_Get( "r_shadowFilter", "1", CVAR_ARCHIVE | CVAR_LATCH ); r_shadowMapSize = ri.Cvar_Get( "r_shadowMapSize", "1024", CVAR_ARCHIVE | CVAR_LATCH ); - r_shadowCascadeZNear = ri.Cvar_Get( "r_shadowCascadeZNear", "4", CVAR_ARCHIVE | CVAR_LATCH ); - r_shadowCascadeZFar = ri.Cvar_Get( "r_shadowCascadeZFar", "3072", CVAR_ARCHIVE | CVAR_LATCH ); - r_shadowCascadeZBias = ri.Cvar_Get( "r_shadowCascadeZBias", "-320", CVAR_ARCHIVE | CVAR_LATCH ); + r_shadowCascadeZNear = ri.Cvar_Get( "r_shadowCascadeZNear", "8", CVAR_ARCHIVE | CVAR_LATCH ); + r_shadowCascadeZFar = ri.Cvar_Get( "r_shadowCascadeZFar", "1024", CVAR_ARCHIVE | CVAR_LATCH ); + r_shadowCascadeZBias = ri.Cvar_Get( "r_shadowCascadeZBias", "0", CVAR_ARCHIVE | CVAR_LATCH ); r_ignoreDstAlpha = ri.Cvar_Get( "r_ignoreDstAlpha", "1", CVAR_ARCHIVE | CVAR_LATCH ); // diff --git a/code/renderergl2/tr_local.h b/code/renderergl2/tr_local.h index 7736b954..7af9ac19 100644 --- a/code/renderergl2/tr_local.h +++ b/code/renderergl2/tr_local.h @@ -364,6 +364,7 @@ enum TB_SPECULARMAP = 4, TB_SHADOWMAP = 5, TB_CUBEMAP = 6, + TB_SHADOWMAP4 = 6, NUM_TEXTURE_BUNDLES = 7 }; @@ -633,10 +634,12 @@ typedef enum UNIFORM_SHADOWMAP, UNIFORM_SHADOWMAP2, UNIFORM_SHADOWMAP3, + UNIFORM_SHADOWMAP4, UNIFORM_SHADOWMVP, UNIFORM_SHADOWMVP2, UNIFORM_SHADOWMVP3, + UNIFORM_SHADOWMVP4, UNIFORM_ENABLETEXTURES, @@ -760,7 +763,7 @@ typedef struct { int num_pshadows; struct pshadow_s *pshadows; - float sunShadowMvp[3][16]; + float sunShadowMvp[4][16]; float sunDir[4]; float sunCol[4]; float sunAmbCol[4]; @@ -1534,7 +1537,7 @@ typedef struct { image_t *calcLevelsImage; image_t *targetLevelsImage; image_t *fixedLevelsImage; - image_t *sunShadowDepthImage[3]; + image_t *sunShadowDepthImage[4]; image_t *screenShadowImage; image_t *screenSsaoImage; image_t *hdrDepthImage; @@ -1551,7 +1554,7 @@ typedef struct { FBO_t *quarterFbo[2]; FBO_t *calcLevelsFbo; FBO_t *targetLevelsFbo; - FBO_t *sunShadowFbo[3]; + FBO_t *sunShadowFbo[4]; FBO_t *screenShadowFbo; FBO_t *screenSsaoFbo; FBO_t *hdrDepthFbo; @@ -1623,6 +1626,8 @@ typedef struct { qboolean sunShadows; vec3_t sunLight; // from the sky shader for this level vec3_t sunDirection; + vec3_t lastCascadeSunDirection; + float lastCascadeSunMvp[16]; frontEndCounters_t pc; int frontEndMsec; // not in pc due to clearing issue diff --git a/code/renderergl2/tr_main.c b/code/renderergl2/tr_main.c index 7ea837ae..cc9c6cb8 100644 --- a/code/renderergl2/tr_main.c +++ b/code/renderergl2/tr_main.c @@ -2572,14 +2572,16 @@ void R_RenderSunShadowMaps(const refdef_t *fd, int level) //splitZFar = 3072; break; } - - VectorCopy(fd->vieworg, lightOrigin); - + + if (level != 3) + VectorCopy(fd->vieworg, lightOrigin); + else + VectorCopy(tr.world->lightGridOrigin, lightOrigin); // Make up a projection VectorScale(lightDir, -1.0f, lightViewAxis[0]); - if (lightViewIndependentOfCameraView) + if (level == 3 || lightViewIndependentOfCameraView) { // Use world up as light view up VectorSet(lightViewAxis[2], 0, 0, 1); @@ -2599,7 +2601,7 @@ void R_RenderSunShadowMaps(const refdef_t *fd, int level) // Check if too close to parallel to light direction if (abs(DotProduct(lightViewAxis[2], lightViewAxis[0])) > 0.9f) { - if (lightViewIndependentOfCameraView) + if (level == 3 || lightViewIndependentOfCameraView) { // Use world left as light view up VectorSet(lightViewAxis[2], 0, 1, 0); @@ -2636,56 +2638,117 @@ void R_RenderSunShadowMaps(const refdef_t *fd, int level) ClearBounds(lightviewBounds[0], lightviewBounds[1]); - // add view near plane - lx = splitZNear * tan(fd->fov_x * M_PI / 360.0f); - ly = splitZNear * tan(fd->fov_y * M_PI / 360.0f); - VectorMA(fd->vieworg, splitZNear, fd->viewaxis[0], base); + if (level != 3) + { + // add view near plane + lx = splitZNear * tan(fd->fov_x * M_PI / 360.0f); + ly = splitZNear * tan(fd->fov_y * M_PI / 360.0f); + VectorMA(fd->vieworg, splitZNear, fd->viewaxis[0], base); - VectorMA(base, lx, fd->viewaxis[1], point); - VectorMA(point, ly, fd->viewaxis[2], point); - Mat4Transform(lightViewMatrix, point, lightViewPoint); - AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); + VectorMA(base, lx, fd->viewaxis[1], point); + VectorMA(point, ly, fd->viewaxis[2], point); + Mat4Transform(lightViewMatrix, point, lightViewPoint); + AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); - VectorMA(base, -lx, fd->viewaxis[1], point); - VectorMA(point, ly, fd->viewaxis[2], point); - Mat4Transform(lightViewMatrix, point, lightViewPoint); - AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); + VectorMA(base, -lx, fd->viewaxis[1], point); + VectorMA(point, ly, fd->viewaxis[2], point); + Mat4Transform(lightViewMatrix, point, lightViewPoint); + AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); - VectorMA(base, lx, fd->viewaxis[1], point); - VectorMA(point, -ly, fd->viewaxis[2], point); - Mat4Transform(lightViewMatrix, point, lightViewPoint); - AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); + VectorMA(base, lx, fd->viewaxis[1], point); + VectorMA(point, -ly, fd->viewaxis[2], point); + Mat4Transform(lightViewMatrix, point, lightViewPoint); + AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); - VectorMA(base, -lx, fd->viewaxis[1], point); - VectorMA(point, -ly, fd->viewaxis[2], point); - Mat4Transform(lightViewMatrix, point, lightViewPoint); - AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); - + VectorMA(base, -lx, fd->viewaxis[1], point); + VectorMA(point, -ly, fd->viewaxis[2], point); + Mat4Transform(lightViewMatrix, point, lightViewPoint); + AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); + - // add view far plane - lx = splitZFar * tan(fd->fov_x * M_PI / 360.0f); - ly = splitZFar * tan(fd->fov_y * M_PI / 360.0f); - VectorMA(fd->vieworg, splitZFar, fd->viewaxis[0], base); + // add view far plane + lx = splitZFar * tan(fd->fov_x * M_PI / 360.0f); + ly = splitZFar * tan(fd->fov_y * M_PI / 360.0f); + VectorMA(fd->vieworg, splitZFar, fd->viewaxis[0], base); - VectorMA(base, lx, fd->viewaxis[1], point); - VectorMA(point, ly, fd->viewaxis[2], point); - Mat4Transform(lightViewMatrix, point, lightViewPoint); - AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); + VectorMA(base, lx, fd->viewaxis[1], point); + VectorMA(point, ly, fd->viewaxis[2], point); + Mat4Transform(lightViewMatrix, point, lightViewPoint); + AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); - VectorMA(base, -lx, fd->viewaxis[1], point); - VectorMA(point, ly, fd->viewaxis[2], point); - Mat4Transform(lightViewMatrix, point, lightViewPoint); - AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); + VectorMA(base, -lx, fd->viewaxis[1], point); + VectorMA(point, ly, fd->viewaxis[2], point); + Mat4Transform(lightViewMatrix, point, lightViewPoint); + AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); - VectorMA(base, lx, fd->viewaxis[1], point); - VectorMA(point, -ly, fd->viewaxis[2], point); - Mat4Transform(lightViewMatrix, point, lightViewPoint); - AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); + VectorMA(base, lx, fd->viewaxis[1], point); + VectorMA(point, -ly, fd->viewaxis[2], point); + Mat4Transform(lightViewMatrix, point, lightViewPoint); + AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); - VectorMA(base, -lx, fd->viewaxis[1], point); - VectorMA(point, -ly, fd->viewaxis[2], point); - Mat4Transform(lightViewMatrix, point, lightViewPoint); - AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); + VectorMA(base, -lx, fd->viewaxis[1], point); + VectorMA(point, -ly, fd->viewaxis[2], point); + Mat4Transform(lightViewMatrix, point, lightViewPoint); + AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); + } + else + { + // use light grid size as level size + // FIXME: could be tighter + vec3_t bounds; + + bounds[0] = tr.world->lightGridSize[0] * tr.world->lightGridBounds[0]; + bounds[1] = tr.world->lightGridSize[1] * tr.world->lightGridBounds[1]; + bounds[2] = tr.world->lightGridSize[2] * tr.world->lightGridBounds[2]; + + point[0] = tr.world->lightGridOrigin[0]; + point[1] = tr.world->lightGridOrigin[1]; + point[2] = tr.world->lightGridOrigin[2]; + Mat4Transform(lightViewMatrix, point, lightViewPoint); + AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); + + point[0] = tr.world->lightGridOrigin[0] + bounds[0]; + point[1] = tr.world->lightGridOrigin[1]; + point[2] = tr.world->lightGridOrigin[2]; + Mat4Transform(lightViewMatrix, point, lightViewPoint); + AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); + + point[0] = tr.world->lightGridOrigin[0]; + point[1] = tr.world->lightGridOrigin[1] + bounds[1]; + point[2] = tr.world->lightGridOrigin[2]; + Mat4Transform(lightViewMatrix, point, lightViewPoint); + AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); + + point[0] = tr.world->lightGridOrigin[0] + bounds[0]; + point[1] = tr.world->lightGridOrigin[1] + bounds[1]; + point[2] = tr.world->lightGridOrigin[2]; + Mat4Transform(lightViewMatrix, point, lightViewPoint); + AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); + + point[0] = tr.world->lightGridOrigin[0]; + point[1] = tr.world->lightGridOrigin[1]; + point[2] = tr.world->lightGridOrigin[2] + bounds[2]; + Mat4Transform(lightViewMatrix, point, lightViewPoint); + AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); + + point[0] = tr.world->lightGridOrigin[0] + bounds[0]; + point[1] = tr.world->lightGridOrigin[1]; + point[2] = tr.world->lightGridOrigin[2] + bounds[2]; + Mat4Transform(lightViewMatrix, point, lightViewPoint); + AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); + + point[0] = tr.world->lightGridOrigin[0]; + point[1] = tr.world->lightGridOrigin[1] + bounds[1]; + point[2] = tr.world->lightGridOrigin[2] + bounds[2]; + Mat4Transform(lightViewMatrix, point, lightViewPoint); + AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); + + point[0] = tr.world->lightGridOrigin[0] + bounds[0]; + point[1] = tr.world->lightGridOrigin[1] + bounds[1]; + point[2] = tr.world->lightGridOrigin[2] + bounds[2]; + Mat4Transform(lightViewMatrix, point, lightViewPoint); + AddPointToBounds(lightViewPoint, lightviewBounds[0], lightviewBounds[1]); + } if (!glRefConfig.depthClamp) lightviewBounds[0][0] = lightviewBounds[1][0] - 8192; @@ -2715,11 +2778,10 @@ void R_RenderSunShadowMaps(const refdef_t *fd, int level) VectorScale(lightviewBounds[1], worldUnitsPerTexel, lightviewBounds[1]); } - //ri.Printf(PRINT_ALL, "znear %f zfar %f\n", lightviewBounds[0][0], lightviewBounds[1][0]); - //ri.Printf(PRINT_ALL, "fovx %f fovy %f xmin %f xmax %f ymin %f ymax %f\n", fd->fov_x, fd->fov_y, xmin, xmax, ymin, ymax); + //ri.Printf(PRINT_ALL, "level %d znear %f zfar %f\n", level, lightviewBounds[0][0], lightviewBounds[1][0]); + //ri.Printf(PRINT_ALL, "xmin %f xmax %f ymin %f ymax %f\n", lightviewBounds[0][1], lightviewBounds[1][1], -lightviewBounds[1][2], -lightviewBounds[0][2]); } - { int firstDrawSurf; @@ -2857,6 +2919,7 @@ void R_RenderCubemapSide( int cubemapIndex, int cubemapSide, qboolean subscene ) R_RenderSunShadowMaps(&refdef, 0); R_RenderSunShadowMaps(&refdef, 1); R_RenderSunShadowMaps(&refdef, 2); + R_RenderSunShadowMaps(&refdef, 3); } } diff --git a/code/renderergl2/tr_scene.c b/code/renderergl2/tr_scene.c index db2d1386..88eda479 100644 --- a/code/renderergl2/tr_scene.c +++ b/code/renderergl2/tr_scene.c @@ -498,9 +498,30 @@ void RE_RenderScene( const refdef_t *fd ) { // playing with even more shadows if(glRefConfig.framebufferObject && r_sunlightMode->integer && !( fd->rdflags & RDF_NOWORLDMODEL ) && (r_forceSun->integer || tr.sunShadows)) { - R_RenderSunShadowMaps(fd, 0); - R_RenderSunShadowMaps(fd, 1); - R_RenderSunShadowMaps(fd, 2); + if (r_shadowCascadeZFar != 0) + { + R_RenderSunShadowMaps(fd, 0); + R_RenderSunShadowMaps(fd, 1); + R_RenderSunShadowMaps(fd, 2); + } + else + { + Mat4Zero(tr.refdef.sunShadowMvp[0]); + Mat4Zero(tr.refdef.sunShadowMvp[1]); + Mat4Zero(tr.refdef.sunShadowMvp[2]); + } + + // only rerender last cascade if sun has changed position + if (r_forceSun->integer == 2 || !VectorCompare(tr.refdef.sunDir, tr.lastCascadeSunDirection)) + { + VectorCopy(tr.refdef.sunDir, tr.lastCascadeSunDirection); + R_RenderSunShadowMaps(fd, 3); + Mat4Copy(tr.refdef.sunShadowMvp[3], tr.lastCascadeSunMvp); + } + else + { + Mat4Copy(tr.lastCascadeSunMvp, tr.refdef.sunShadowMvp[3]); + } } // playing with cube maps From ff1f093a0bab87bc08f4bc2a8fef6a5a8878f861 Mon Sep 17 00:00:00 2001 From: SmileTheory Date: Fri, 1 Aug 2014 23:57:26 -0700 Subject: [PATCH 27/28] OpenGL2: Remove R_MipMap() and R_MipMap2(), and fix gamma conversion in R_MipMapsRGB() --- code/renderergl2/tr_image.c | 102 ++---------------------------------- 1 file changed, 3 insertions(+), 99 deletions(-) diff --git a/code/renderergl2/tr_image.c b/code/renderergl2/tr_image.c index eff21988..6c8dc456 100644 --- a/code/renderergl2/tr_image.c +++ b/code/renderergl2/tr_image.c @@ -1275,61 +1275,12 @@ void R_LightScaleTexture (byte *in, int inwidth, int inheight, qboolean only_gam /* ================ -R_MipMap2 +R_MipMapsRGB Operates in place, quartering the size of the texture -Proper linear filter +Colors are gamma correct ================ */ -static void R_MipMap2( byte *in, int inWidth, int inHeight ) { - int i, j, k; - byte *outpix; - int inWidthMask, inHeightMask; - int total; - int outWidth, outHeight; - unsigned *temp; - - outWidth = inWidth >> 1; - outHeight = inHeight >> 1; - temp = ri.Hunk_AllocateTempMemory( outWidth * outHeight * 4 ); - - inWidthMask = inWidth - 1; - inHeightMask = inHeight - 1; - - for ( i = 0 ; i < outHeight ; i++ ) { - for ( j = 0 ; j < outWidth ; j++ ) { - outpix = (byte *) ( temp + i * outWidth + j ); - for ( k = 0 ; k < 4 ; k++ ) { - total = - 1 * (&in[ 4*(((i*2-1)&inHeightMask)*inWidth + ((j*2-1)&inWidthMask)) ])[k] + - 2 * (&in[ 4*(((i*2-1)&inHeightMask)*inWidth + ((j*2 )&inWidthMask)) ])[k] + - 2 * (&in[ 4*(((i*2-1)&inHeightMask)*inWidth + ((j*2+1)&inWidthMask)) ])[k] + - 1 * (&in[ 4*(((i*2-1)&inHeightMask)*inWidth + ((j*2+2)&inWidthMask)) ])[k] + - - 2 * (&in[ 4*(((i*2 )&inHeightMask)*inWidth + ((j*2-1)&inWidthMask)) ])[k] + - 4 * (&in[ 4*(((i*2 )&inHeightMask)*inWidth + ((j*2 )&inWidthMask)) ])[k] + - 4 * (&in[ 4*(((i*2 )&inHeightMask)*inWidth + ((j*2+1)&inWidthMask)) ])[k] + - 2 * (&in[ 4*(((i*2 )&inHeightMask)*inWidth + ((j*2+2)&inWidthMask)) ])[k] + - - 2 * (&in[ 4*(((i*2+1)&inHeightMask)*inWidth + ((j*2-1)&inWidthMask)) ])[k] + - 4 * (&in[ 4*(((i*2+1)&inHeightMask)*inWidth + ((j*2 )&inWidthMask)) ])[k] + - 4 * (&in[ 4*(((i*2+1)&inHeightMask)*inWidth + ((j*2+1)&inWidthMask)) ])[k] + - 2 * (&in[ 4*(((i*2+1)&inHeightMask)*inWidth + ((j*2+2)&inWidthMask)) ])[k] + - - 1 * (&in[ 4*(((i*2+2)&inHeightMask)*inWidth + ((j*2-1)&inWidthMask)) ])[k] + - 2 * (&in[ 4*(((i*2+2)&inHeightMask)*inWidth + ((j*2 )&inWidthMask)) ])[k] + - 2 * (&in[ 4*(((i*2+2)&inHeightMask)*inWidth + ((j*2+1)&inWidthMask)) ])[k] + - 1 * (&in[ 4*(((i*2+2)&inHeightMask)*inWidth + ((j*2+2)&inWidthMask)) ])[k]; - outpix[k] = total / 36; - } - } - } - - Com_Memcpy( in, temp, outWidth * outHeight * 4 ); - ri.Hunk_FreeTempMemory( temp ); -} - - static void R_MipMapsRGB( byte *in, int inWidth, int inHeight) { int x, y, c, stride; @@ -1341,7 +1292,7 @@ static void R_MipMapsRGB( byte *in, int inWidth, int inHeight) if (!downmipSrgbLookupSet) { for (x = 0; x < 256; x++) - downmipSrgbLookup[x] = ((x < 10) ? x / 3294.6f : powf((x / 255.0f + 0.055f) / 1.055f, 2.4f)) * 0.25f; + downmipSrgbLookup[x] = powf(x / 255.0f, 2.2f) * 0.25f; downmipSrgbLookupSet = 1; } @@ -1379,53 +1330,6 @@ static void R_MipMapsRGB( byte *in, int inWidth, int inHeight) } } -/* -================ -R_MipMap - -Operates in place, quartering the size of the texture -================ -*/ -static void R_MipMap (byte *in, int width, int height) { - int i, j; - byte *out; - int row; - - if ( !r_simpleMipMaps->integer ) { - R_MipMap2( in, width, height ); - return; - } - - if ( width == 1 && height == 1 ) { - return; - } - - row = width * 4; - out = in; - width >>= 1; - height >>= 1; - - if ( width == 0 || height == 0 ) { - width += height; // get largest - for (i=0 ; i>1; - out[1] = ( in[1] + in[5] )>>1; - out[2] = ( in[2] + in[6] )>>1; - out[3] = ( in[3] + in[7] )>>1; - } - return; - } - - for (i=0 ; i>2; - out[1] = (in[1] + in[5] + in[row+1] + in[row+5])>>2; - out[2] = (in[2] + in[6] + in[row+2] + in[row+6])>>2; - out[3] = (in[3] + in[7] + in[row+3] + in[row+7])>>2; - } - } -} - static void R_MipMapLuminanceAlpha (const byte *in, byte *out, int width, int height) { From ca9eebb125458b65a0cc705bfd9d26ac683c3bab Mon Sep 17 00:00:00 2001 From: SmileTheory Date: Sat, 2 Aug 2014 00:02:46 -0700 Subject: [PATCH 28/28] OpenGL2: Fix a glsl compile error on old hardware with r_shadowFilter 0. --- code/renderergl2/glsl/shadowmask_fp.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/renderergl2/glsl/shadowmask_fp.glsl b/code/renderergl2/glsl/shadowmask_fp.glsl index 8a5597a9..053907cf 100644 --- a/code/renderergl2/glsl/shadowmask_fp.glsl +++ b/code/renderergl2/glsl/shadowmask_fp.glsl @@ -82,7 +82,7 @@ float PCF(const sampler2DShadow shadowmap, const vec2 st, const float dist) mult *= 0.33333; #endif #else - mult = shadow2D(shadowmap, vec3(st, dist)); + mult = shadow2D(shadowmap, vec3(st, dist)).r; #endif return mult;