From 1ebc8096a0353451ddd2aa663c57f4fa8c0f14e4 Mon Sep 17 00:00:00 2001
From: Hannu Hanhi <hhanhipublic@gmail.com>
Date: Fri, 8 Oct 2021 22:07:58 +0300
Subject: [PATCH] Some cleanup I forgot to do

---
 src/hardware/hw_draw.c           |  4 +--
 src/hardware/hw_drv.h            |  6 ++--
 src/hardware/r_opengl/r_opengl.c | 55 +-------------------------------
 src/sdl/hwsym_sdl.c              |  3 +-
 src/sdl/i_video.c                |  3 +-
 5 files changed, 7 insertions(+), 64 deletions(-)

diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c
index 9e80e89549..b39c8bdacb 100644
--- a/src/hardware/hw_draw.c
+++ b/src/hardware/hw_draw.c
@@ -1489,7 +1489,7 @@ UINT8 *HWR_GetScreenshot(void)
 	if (!buf)
 		return NULL;
 	// returns 24bit 888 RGB
-	HWD.pfnReadRect(tex, (void *)buf);
+	HWD.pfnReadScreenTexture(tex, (void *)buf);
 	return buf;
 }
 
@@ -1506,7 +1506,7 @@ boolean HWR_Screenshot(const char *pathname)
 	}
 
 	// returns 24bit 888 RGB
-	HWD.pfnReadRect(tex, (void *)buf);
+	HWD.pfnReadScreenTexture(tex, (void *)buf);
 
 #ifdef USE_PNG
 	ret = M_SavePNG(pathname, buf, vid.width, vid.height, NULL);
diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h
index 82e2c285cb..aa3a9a613d 100644
--- a/src/hardware/hw_drv.h
+++ b/src/hardware/hw_drv.h
@@ -43,7 +43,7 @@ EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, FBOOLEAN DepthMask, FRGBAFl
 EXPORT void HWRAPI(SetTexture) (GLMipmap_t *TexInfo);
 EXPORT void HWRAPI(UpdateTexture) (GLMipmap_t *TexInfo);
 EXPORT void HWRAPI(DeleteTexture) (GLMipmap_t *TexInfo);
-EXPORT void HWRAPI(ReadRect) (int tex, UINT8 *dst_data);
+EXPORT void HWRAPI(ReadScreenTexture) (int tex, UINT8 *dst_data);
 EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip);
 EXPORT void HWRAPI(ClearMipMapCache) (void);
 
@@ -55,7 +55,6 @@ EXPORT void HWRAPI(SetTransform) (FTransform *ptransform);
 EXPORT INT32 HWRAPI(GetTextureUsed) (void);
 
 EXPORT void HWRAPI(FlushScreenTextures) (void);
-EXPORT void HWRAPI(SwapScreenTextures) (int tex1, int tex2);
 EXPORT void HWRAPI(DoScreenWipe) (int wipeStart, int wipeEnd);
 EXPORT void HWRAPI(DrawScreenTexture) (int tex);
 EXPORT void HWRAPI(MakeScreenTexture) (int tex);
@@ -97,7 +96,7 @@ struct hwdriver_s
 	SetTexture          pfnSetTexture;
 	UpdateTexture       pfnUpdateTexture;
 	DeleteTexture       pfnDeleteTexture;
-	ReadRect            pfnReadRect;
+	ReadScreenTexture   pfnReadScreenTexture;
 	GClipRect           pfnGClipRect;
 	ClearMipMapCache    pfnClearMipMapCache;
 	SetSpecialState     pfnSetSpecialState;
@@ -113,7 +112,6 @@ struct hwdriver_s
 #endif
 	PostImgRedraw       pfnPostImgRedraw;
 	FlushScreenTextures pfnFlushScreenTextures;
-	SwapScreenTextures  pfnSwapScreenTextures;
 	DoScreenWipe        pfnDoScreenWipe;
 	DrawScreenTexture   pfnDrawScreenTexture;
 	MakeScreenTexture   pfnMakeScreenTexture;
diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c
index 7c9a37131f..bacfea1d9e 100644
--- a/src/hardware/r_opengl/r_opengl.c
+++ b/src/hardware/r_opengl/r_opengl.c
@@ -1166,18 +1166,14 @@ EXPORT void HWRAPI(ClearMipMapCache) (void)
 // Writes screen texture tex into dst_data.
 // Pixel format is 24-bit RGB. Row order is top to bottom.
 // Dimensions are screen_width * screen_height.
-// TODO should rename to ReadScreenTexture
-EXPORT void HWRAPI(ReadRect) (int tex, UINT8 *dst_data)
+EXPORT void HWRAPI(ReadScreenTexture) (int tex, UINT8 *dst_data)
 {
 	INT32 i;
 	int dst_stride = screen_width * 3; // stride between rows of image data
 	GLubyte*top = (GLvoid*)dst_data, *bottom = top + dst_stride * (screen_height - 1);
-	//precise_t ts1, ts2, ts3, ts4, ts5, total_time, get_time, loop_time;
 	GLubyte *row;
-	//ts1 = I_GetPreciseTime();
 	row = malloc(dst_stride);
 	if (!row) return;
-	//ts2 = I_GetPreciseTime();
 	// at the time this function is called, generic2 can be found drawn on the framebuffer
 	// if some other screen texture is needed, draw it to the framebuffer
 	// and draw generic2 back after reading the framebuffer.
@@ -1188,7 +1184,6 @@ EXPORT void HWRAPI(ReadRect) (int tex, UINT8 *dst_data)
 	pglReadPixels(0, 0, screen_width, screen_height, GL_RGB, GL_UNSIGNED_BYTE, dst_data);
 	if (tex != HWD_SCREENTEXTURE_GENERIC2)
 		DrawScreenTexture(HWD_SCREENTEXTURE_GENERIC2);
-	//ts3 = I_GetPreciseTime();
 	// Flip image upside down.
 	// In other words, convert OpenGL's "bottom->top" row order into "top->bottom".
 	for(i = 0; i < screen_height/2; i++)
@@ -1199,47 +1194,7 @@ EXPORT void HWRAPI(ReadRect) (int tex, UINT8 *dst_data)
 		top += dst_stride;
 		bottom -= dst_stride;
 	}
-	//ts4 = I_GetPreciseTime();
 	free(row);
-	//ts5 = I_GetPreciseTime();
-	//total_time = I_PreciseToMicros(ts5 - ts1);
-	//get_time = I_PreciseToMicros(ts3 - ts2);
-	//loop_time = I_PreciseToMicros(ts4 - ts3);
-	//CONS_Printf("ReadRect: total time: %" PRIu64 ", read pixels thing: %" PRIu64 " memcpy loop: %" PRIu64 "\n", total_time, get_time, loop_time);
-
-	// the slow glGetTexImage based implementation. left in here in case i wanna test it more
-	// TODO remove this at some point
-
-	/*int texsize = 512;
-	GLsizei buffer_size;
-	GLubyte *buffer;
-	// GL_DBG_Printf ("ReadRect()\n");
-	precise_t ts1, ts2, ts3, ts4, ts5, total_time, get_time, loop_time;
-	ts1 = I_GetPreciseTime();
-	// look for power of two that is large enough for the screen
-	while (texsize < screen_width || texsize < screen_height)
-		texsize <<= 1;
-	buffer_size = texsize * texsize * 4;
-	buffer = malloc(buffer_size);
-	tex_downloaded = screenTextures[tex];
-	pglBindTexture(GL_TEXTURE_2D, tex_downloaded);
-	ts2 = I_GetPreciseTime();
-	pglGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_BYTE, buffer); // GL better not overwrite my buffer :v
-	ts3 = I_GetPreciseTime();
-	//for (i = 0; i < screen_height; i++) // i: pixel row index that we are writing
-	//{
-	//	// read the frame from the lower left corner of the GL screen texture
-	//	// flip it upside down so it's in correct format
-	//	memcpy(dst_data + (screen_height - i - 1) * screen_width * 3,
-	//		buffer + i * texsize * 3, screen_width * 3);
-	//}
-	ts4 = I_GetPreciseTime();
-	free(buffer);
-	ts5 = I_GetPreciseTime();
-	total_time = I_PreciseToMicros(ts5 - ts1);
-	get_time = I_PreciseToMicros(ts3 - ts2);
-	loop_time = I_PreciseToMicros(ts4 - ts3);
-	CONS_Printf("ReadRect: total time: %" PRIu64 ", glGetTexImage: %" PRIu64 " memcpy loop: %" PRIu64 "\n", total_time, get_time, loop_time);*/
 }
 
 
@@ -3016,14 +2971,6 @@ EXPORT void HWRAPI(FlushScreenTextures) (void)
 		screenTextures[i] = 0;
 }
 
-EXPORT void HWRAPI(SwapScreenTextures) (int tex1, int tex2)
-{
-	GLuint temp = screenTextures[tex1];
-	screenTextures[tex1] = screenTextures[tex2];
-	screenTextures[tex2] = temp;
-}
-
-
 EXPORT void HWRAPI(DrawScreenTexture)(int tex)
 {
 	float xfix, yfix;
diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c
index 8e48350fcb..ca87fcc795 100644
--- a/src/sdl/hwsym_sdl.c
+++ b/src/sdl/hwsym_sdl.c
@@ -87,7 +87,7 @@ void *hwSym(const char *funcName,void *handle)
 	GETFUNC(SetTexture);
 	GETFUNC(UpdateTexture);
 	GETFUNC(DeleteTexture);
-	GETFUNC(ReadRect);
+	GETFUNC(ReadScreenTexture);
 	GETFUNC(GClipRect);
 	GETFUNC(ClearMipMapCache);
 	GETFUNC(SetSpecialState);
@@ -97,7 +97,6 @@ void *hwSym(const char *funcName,void *handle)
 	GETFUNC(SetTransform);
 	GETFUNC(PostImgRedraw);
 	GETFUNC(FlushScreenTextures);
-	GETFUNC(SwapScreenTextures);
 	GETFUNC(DoScreenWipe);
 	GETFUNC(DrawScreenTexture);
 	GETFUNC(MakeScreenTexture);
diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c
index 763506b418..4b18407975 100644
--- a/src/sdl/i_video.c
+++ b/src/sdl/i_video.c
@@ -1869,7 +1869,7 @@ void VID_StartupOpenGL(void)
 		HWD.pfnSetTexture       = hwSym("SetTexture",NULL);
 		HWD.pfnUpdateTexture    = hwSym("UpdateTexture",NULL);
 		HWD.pfnDeleteTexture    = hwSym("DeleteTexture",NULL);
-		HWD.pfnReadRect         = hwSym("ReadRect",NULL);
+		HWD.pfnReadScreenTexture= hwSym("ReadScreenTexture",NULL);
 		HWD.pfnGClipRect        = hwSym("GClipRect",NULL);
 		HWD.pfnClearMipMapCache = hwSym("ClearMipMapCache",NULL);
 		HWD.pfnSetSpecialState  = hwSym("SetSpecialState",NULL);
@@ -1880,7 +1880,6 @@ void VID_StartupOpenGL(void)
 		HWD.pfnSetTransform     = hwSym("SetTransform",NULL);
 		HWD.pfnPostImgRedraw    = hwSym("PostImgRedraw",NULL);
 		HWD.pfnFlushScreenTextures=hwSym("FlushScreenTextures",NULL);
-		HWD.pfnSwapScreenTextures=hwSym("SwapScreenTextures",NULL);
 		HWD.pfnDoScreenWipe     = hwSym("DoScreenWipe",NULL);
 		HWD.pfnDrawScreenTexture= hwSym("DrawScreenTexture",NULL);
 		HWD.pfnMakeScreenTexture= hwSym("MakeScreenTexture",NULL);
-- 
GitLab