[SOLVED] Need help porting xBRZ scaler to old GL renderer

Discuss anything ZDoom-related that doesn't fall into one of the other categories.
Post Reply
User avatar
drfrag
Vintage GZDoom Developer
Posts: 3207
Joined: Fri Apr 23, 2004 3:51 am
Location: Spain
Contact:

[SOLVED] Need help porting xBRZ scaler to old GL renderer

Post by drfrag »

I'm trying to add the xBRZ texture scaler to GZDoom LE (not definitive name) from commit 03/09/16 * - added xBRZ texture scaler.
Compiles fine with gcc 4.6.1 but it doesn't work. It would be cool to get it working with this old renderer from GZDoom 1.8.04, this one works on OpenGL 1.2 hardware with ZDoom 2.8.1 feature support. I've tested it on a Geforce 2 MX with an ancient GL 1.2 driver and a 3dfx voodoo3 with MesaFX both on win98. Runs mostly fine and it's fast, there are minor glitches specially on the 3dfx (mainly during the wipe).
@_mental_ since you ported the code to C++ could you please help and have a look at it when you have time? Thanks.
Of course a also applied the next commit with the files.

Code: Select all

 docs/licenses/xBRZ.jpg          | Bin 0 -> 60099 bytes
 src/CMakeLists.txt              |   3 +++
 src/gl/textures/gl_hqresize.cpp |  50 +++++++++++++++++++++++++++++++++++++++-
 wadsrc/static/menudef.z         |   6 +++++
 4 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/docs/licenses/xBRZ.jpg b/docs/licenses/xBRZ.jpg
new file mode 100644
index 000000000..ab8335391
Binary files /dev/null and b/docs/licenses/xBRZ.jpg differ
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c5087af94..881bd47ca 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -820,6 +820,7 @@ file( GLOB HEADER_FILES
 	textures/*.h
 	thingdef/*.h
 	xlat/*.h
+	gl/xbr/*.h
 	*.h
 )
 
@@ -926,6 +927,8 @@ add_executable( zdoom WIN32 MACOSX_BUNDLE
 	${SYSTEM_SOURCES}
 	${X86_SOURCES}
 	x86.cpp
+	gl/xbr/xbrz.cpp
+	gl/xbr/xbrz_old.cpp
 	actorptrselect.cpp
 	am_map.cpp
 	b_bot.cpp
diff --git a/src/gl/textures/gl_hqresize.cpp b/src/gl/textures/gl_hqresize.cpp
index 232c1d6c1..a13f0aab4 100644
--- a/src/gl/textures/gl_hqresize.cpp
+++ b/src/gl/textures/gl_hqresize.cpp
@@ -39,10 +39,12 @@
 #include "gl/textures/gl_texture.h"
 #include "c_cvars.h"
 #include "gl/hqnx/hqx.h"
+#include "gl/xbr/xbrz.h"
+#include "gl/xbr/xbrz_old.h"
 
 CUSTOM_CVAR(Int, gl_texture_hqresize, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
 {
-	if (self < 0 || self > 6)
+	if (self < 0 || self > 12)
 		self = 0;
 	GLRenderer->FlushTextures();
 }
@@ -202,6 +204,42 @@ static unsigned char *hqNxHelper( void (*hqNxFunction) ( unsigned*, unsigned*, i
 	return newBuffer;
 }
 
+			
+static unsigned char *xbrzHelper( void (*xbrzFunction) ( size_t, const uint32_t*, uint32_t*, int, int, xbrz::ColorFormat, const xbrz::ScalerCfg&, int, int ),
+							  const int N,
+							  unsigned char *inputBuffer,
+							  const int inWidth,
+							  const int inHeight,
+							  int &outWidth,
+							  int &outHeight )
+{
+	outWidth = N * inWidth;
+	outHeight = N *inHeight;
+
+	unsigned char * newBuffer = new unsigned char[outWidth*outHeight*4];
+	xbrzFunction(N, reinterpret_cast<uint32_t*>(inputBuffer), reinterpret_cast<uint32_t*>(newBuffer), inWidth, inHeight, xbrz::ARGB, xbrz::ScalerCfg(), 0, std::numeric_limits<int>::max());
+	delete[] inputBuffer;
+	return newBuffer;
+}
+
+static unsigned char *xbrzoldHelper( void (*xbrzFunction) ( size_t factor, const uint32_t* src, uint32_t* trg, int srcWidth, int srcHeight, const xbrz_old::ScalerCfg& cfg, int yFirst, int yLast ),
+							  const int N,
+							  unsigned char *inputBuffer,
+							  const int inWidth,
+							  const int inHeight,
+							  int &outWidth,
+							  int &outHeight )
+{
+	outWidth = N * inWidth;
+	outHeight = N *inHeight;
+
+	unsigned char * newBuffer = new unsigned char[outWidth*outHeight*4];
+	xbrzFunction(N, reinterpret_cast<uint32_t*>(inputBuffer), reinterpret_cast<uint32_t*>(newBuffer), inWidth, inHeight, xbrz_old::ScalerCfg(), 0, std::numeric_limits<int>::max());
+	delete[] inputBuffer;
+	return newBuffer;
+}
+
+
 //===========================================================================
 // 
 // [BB] Upsamples the texture in inputBuffer, frees inputBuffer and returns
@@ -270,6 +308,16 @@ unsigned char *gl_CreateUpsampledTextureBuffer ( const FTexture *inputTexture, u
 			return hqNxHelper( &hq3x_32, 3, inputBuffer, inWidth, inHeight, outWidth, outHeight );
 		case 6:
 			return hqNxHelper( &hq4x_32, 4, inputBuffer, inWidth, inHeight, outWidth, outHeight );
+		case 7:
+		case 8:
+		case 9:
+			return xbrzHelper(xbrz::scale, type - 8, inputBuffer, inWidth, inHeight, outWidth, outHeight );
+			
+		case 10:
+		case 11:
+		case 12:
+			return xbrzoldHelper(xbrz_old::scale, type - 11, inputBuffer, inWidth, inHeight, outWidth, outHeight );
+			
 		}
 	}
 	return inputBuffer;
diff --git a/wadsrc/static/menudef.z b/wadsrc/static/menudef.z
index a7711873d..524a5312b 100644
--- a/wadsrc/static/menudef.z
+++ b/wadsrc/static/menudef.z
@@ -110,6 +110,12 @@ OptionValue "HqResizeModes"
    4, "hq2x"
    5, "hq3x"
    6, "hq4x"
+   7, "xBRZ 2x"
+   8, "xBRZ 3x"
+   9, "xBRZ 4x"
+   10, "xBRZ_old 2x"
+   11, "xBRZ_old 3x"
+   12, "xBRZ_old 4x"
 }
 
 OptionValue "HqResizeTargets"
My repo: https://github.com/drfrag666/gzdoom/commits/gzdoomle

BTW line distance culling for software is still not working and no idea why.

Edit: i've tried to debug with gdb but i get no useful information, the program exits with code 03 so i guess it's running out of memory. The game hangs when i try to set those modes and then exits to the desktop when pressing a key.
I'm using the google code hqx implementation but i don't think that matters.
Last edited by drfrag on Sat Aug 05, 2017 12:06 pm, edited 1 time in total.
_mental_
 
 
Posts: 3820
Joined: Sun Aug 07, 2011 4:32 am

Re: [Source] Need help porting xBRZ scaler to old GL rendere

Post by _mental_ »

Why don't you use branches for work-in-progress stuff? This makes collaboration much easier.
User avatar
drfrag
Vintage GZDoom Developer
Posts: 3207
Joined: Fri Apr 23, 2004 3:51 am
Location: Spain
Contact:

Re: [Source] Need help porting xBRZ scaler to old GL rendere

Post by drfrag »

Good idea, it's fixed now. It was a stupid bug on my part at the type substraction, thanks anyway.
Edit: i've just uploaded the changes.
Post Reply

Return to “General”