From 795406b8e4c6ddda7738e58d46f304c31a8a33b5 Mon Sep 17 00:00:00 2001
From: TimeServ <timeserv@users.sourceforge.net>
Date: Thu, 31 Mar 2011 11:00:23 +0000
Subject: [PATCH] gldraw_transpictranslate -> r2d_transpictranslate, removed
 old unused code

git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3764 fc73d0e0-1445-4013-8a0c-d673dee63da5
---
 engine/client/cl_screen.c | 38 --------------------------
 engine/client/client.h    |  2 --
 engine/client/m_items.c   |  1 -
 engine/client/m_multi.c   |  2 +-
 engine/client/menu.c      |  6 -----
 engine/client/menu.h      |  1 -
 engine/client/merged.h    |  3 +--
 engine/client/r_2d.c      | 51 ++++++++++++++++++++++++++++++++++-
 engine/client/renderer.c  |  3 ---
 engine/d3d/vid_d3d.c      |  4 ---
 engine/gl/gl_draw.c       | 56 ---------------------------------------
 engine/gl/gl_draw.h       |  2 --
 engine/gl/gl_vidcommon.c  |  1 -
 13 files changed, 52 insertions(+), 118 deletions(-)

diff --git a/engine/client/cl_screen.c b/engine/client/cl_screen.c
index 376fe5405..3e2470210 100644
--- a/engine/client/cl_screen.c
+++ b/engine/client/cl_screen.c
@@ -299,43 +299,6 @@ void SCR_StringToRGB (char *rgbstring, float *rgb, float rgbinputscale)
 	} // i contains the crosshair color
 }
 
-// SCR_StringToPalIndex: takes in "<index>" or "<r> <g> <b>" and converts to a
-// Quake palette index
-int SCR_StringToPalIndex (char *rgbstring, float rgbinputscale)
-{
-	int i;
-	char *t;
-
-	rgbinputscale = 255/rgbinputscale;
-	t = strstr(rgbstring, " ");
-
-	if (t)
-	{
-		int r, g, b;
-
-		t++;
-		r = atof(rgbstring) * rgbinputscale;
-		g = atof(t) * rgbinputscale;
-		t = strstr(t, " ");
-		if (t)
-			b = atof(t) * rgbinputscale;
-		else
-			b = 0;
-
-		r = bound(0, r, 255);
-		g = bound(0, g, 255);
-		b = bound(0, b, 255);
-		i = GetPaletteIndex(r, g, b);
-	}
-	else
-	{
-		i = atoi(rgbstring);
-		i = bound(0, i, 255);
-	}
-
-	return i;
-}
-
 /*
 ==============
 SCR_CenterPrint
@@ -584,7 +547,6 @@ void SCR_DrawCursor(int prydoncursornum)
 	{
 		R2D_ImageColours(1, 1, 1, 1);
 		R2D_Image(mousecursor_x-cl_cursorbias.value, mousecursor_y-cl_cursorbias.value, cl_cursorsize.value, cl_cursorsize.value, 0, 0, 1, 1, p);
-//		Draw_TransPic(mousecursor_x-4, mousecursor_y-4, p);
 	}
 	else
 	{
diff --git a/engine/client/client.h b/engine/client/client.h
index 7f854559b..69979b08b 100644
--- a/engine/client/client.h
+++ b/engine/client/client.h
@@ -1209,8 +1209,6 @@ void Editor_Init(void);
 #endif
 
 void SCR_StringToRGB (char *rgbstring, float *rgb, float rgbinputscale);
-int SCR_StringToPalIndex (char *rgbstring, float rgbinputscale);
-
 
 struct model_s;
 void CL_AddVWeapModel(entity_t *player, struct model_s *model);
diff --git a/engine/client/m_items.c b/engine/client/m_items.c
index 8f89e2f4a..3752d6593 100644
--- a/engine/client/m_items.c
+++ b/engine/client/m_items.c
@@ -1460,7 +1460,6 @@ void DrawCursor(int prydoncursornum)
 	{
 		R2D_ImageColours(1, 1, 1, 1);
 		R2D_Image(mousecursor_x-cl_cursorbias.value, mousecursor_y-cl_cursorbias.value, cl_cursorsize.value, cl_cursorsize.value, 0, 0, 1, 1, p);
-//		Draw_TransPic(mousecursor_x-4, mousecursor_y-4, p);
 	}
 	else
 	{
diff --git a/engine/client/m_multi.c b/engine/client/m_multi.c
index 382f8b55e..81246bc00 100644
--- a/engine/client/m_multi.c
+++ b/engine/client/m_multi.c
@@ -317,7 +317,7 @@ void MSetup_TransDraw (int x, int y, menucustom_t *option, menu_t *menu)
 		R2D_ScalePic (x-12, y-8, 72, 72, p);
 
 	M_BuildTranslationTable(info->topcolour, info->lowercolour);
-	Draw_TransPicTranslate (x, y, info->tiwidth, info->tiheight, info->translationimage, translationTable);	
+	R2D_TransPicTranslate (x, y, info->tiwidth, info->tiheight, info->translationimage, translationTable);	
 }
 
 void M_Menu_Setup_f (void)
diff --git a/engine/client/menu.c b/engine/client/menu.c
index 38203cf42..9b674335e 100644
--- a/engine/client/menu.c
+++ b/engine/client/menu.c
@@ -113,12 +113,6 @@ void M_BuildTranslationTable(int top, int bottom)
 	}
 }
 
-/*
-void M_DrawTransPicTranslate (int x, int y, mpic_t *pic)
-{
-	Draw_TransPicTranslate (x + ((vid.width - 320)>>1), y, pic, translationTable);
-}*/
-
 
 void M_DrawTextBox (int x, int y, int width, int lines)
 {
diff --git a/engine/client/menu.h b/engine/client/menu.h
index c5f369bd7..6de400fa4 100644
--- a/engine/client/menu.h
+++ b/engine/client/menu.h
@@ -382,7 +382,6 @@ void M_SListKey(int key);
 
 //drawing funcs
 void M_BuildTranslationTable(int top, int bottom);
-FTE_DEPRECATED void M_DrawTransPicTranslate (int x, int y, mpic_t *pic);
 void M_DrawCharacter (int cx, int line, unsigned int num);
 void M_Print (int cx, int cy, qbyte *str);
 void M_PrintWhite (int cx, int cy, qbyte *str);
diff --git a/engine/client/merged.h b/engine/client/merged.h
index 0578aaef8..9a2888c3e 100644
--- a/engine/client/merged.h
+++ b/engine/client/merged.h
@@ -60,6 +60,7 @@ mpic_t *R2D_SafeCachePic (char *path);
 mpic_t *R2D_SafePicFromWad (char *name);
 void R2D_ScalePic (int x, int y, int width, int height, mpic_t *pic);
 void R2D_SubPic(int x, int y, int width, int height, mpic_t *pic, int srcx, int srcy, int srcwidth, int srcheight);
+void R2D_TransPicTranslate (int x, int y, int width, int height, qbyte *pic, qbyte *translation);
 void R2D_TileClear (int x, int y, int w, int h);
 void R2D_FadeScreen (void);
 
@@ -75,7 +76,6 @@ void R2D_FillBlock(int x, int y, int w, int h);
 extern void	(*Draw_Init)							(void);
 extern void	(*Draw_TinyCharacter)					(int x, int y, unsigned int num);
 extern void	(*Draw_Crosshair)						(void);
-extern void	(*Draw_TransPicTranslate)				(int x, int y, int width, int height, qbyte *image, qbyte *translation);
 extern qboolean (*Draw_IsCached)					(char *picname);	//can be null
 
 extern void	(*R_Init)								(void);
@@ -181,7 +181,6 @@ typedef struct rendererinfo_s {
 	void	(*Draw_Init)				(void);
 	void	(*Draw_Shutdown)			(void);
 	void	(*Draw_Crosshair)			(void); //TODO: MARKED FOR DEMOLITION
-	void	(*Draw_TransPicTranslate)	(int x, int y, int w, int h, qbyte *pic, qbyte *translation); //TODO: MARKED FOR DEMOLITION
 
 	texid_t (*IMG_LoadTexture)			(char *identifier, int width, int height, uploadfmt_t fmt, void *data, unsigned int flags);
 	texid_t (*IMG_LoadTexture8Pal24)	(char *identifier, int width, int height, qbyte *data, qbyte *palette24, unsigned int flags);
diff --git a/engine/client/r_2d.c b/engine/client/r_2d.c
index 27e4d40b5..9647c7555 100644
--- a/engine/client/r_2d.c
+++ b/engine/client/r_2d.c
@@ -4,6 +4,10 @@
 #include "gl_draw.h"
 
 texid_t missing_texture;
+
+texid_t translate_texture;
+shader_t *translate_shader;
+
 static mpic_t *conback;
 static mpic_t *draw_backtile;
 static shader_t *shader_draw_fill, *shader_draw_fill_trans;
@@ -87,6 +91,7 @@ void R2D_Init(void)
 #pragma message("Fixme: move conwidth handling into here")
 
 	missing_texture = R_LoadTexture8("no_texture", 16, 16, (unsigned char*)r_notexture_mip + r_notexture_mip->offsets[0], IF_NOALPHA|IF_NOGAMMA, 0);
+	translate_texture = r_nulltex;
 
 	draw_backtile = R_RegisterShader("gfx/backtile.lmp",
 		"{\n"
@@ -326,6 +331,50 @@ void R2D_SubPic(int x, int y, int width, int height, mpic_t *pic, int srcx, int
 	R2D_Image(x, y, width, height, newsl, newtl, newsh, newth, pic);
 }
 
+/* this is an ugly special case drawing func that's only used for the player color selection menu */
+void R2D_TransPicTranslate (int x, int y, int width, int height, qbyte *pic, qbyte *translation)
+{
+	int				v, u, c;
+	unsigned		trans[64*64], *dest;
+	qbyte			*src;
+	int				p;
+
+	c = width * height;
+
+	dest = trans;
+	for (v=0 ; v<64 ; v++, dest += 64)
+	{
+		src = &pic[ ((v*height)>>6) *width];
+		for (u=0 ; u<64 ; u++)
+		{
+			p = src[(u*width)>>6];
+			if (p == 255)
+				dest[u] = 0x0;
+			else
+				dest[u] =  d_8to24rgbtable[translation[p]];
+		}
+	}
+
+	if (!TEXVALID(translate_texture))
+	{
+		translate_texture = R_AllocNewTexture(64, 64);
+		translate_shader = R_RegisterShader("translatedpic", "{\n"
+#ifdef USE_EGL
+			"program default2d\n"
+#endif
+			"nomipmaps\n"
+			"{\n"
+				"map $diffuse\n"
+				"blendfunc blend\n"
+			"}\n"
+		"}\n");
+		translate_shader->defaulttextures.base = translate_texture;
+	}
+	/* could avoid reuploading already translated textures but this func really isn't used enough anyway */
+	R_Upload(translate_texture, NULL, TF_RGBA32, trans, NULL, 64, 64, IF_NOMIPMAP|IF_NOGAMMA);
+	R2D_ScalePic(x, y, width, height, translate_shader);
+}
+
 /*
 ================
 Draw_ConsoleBackground
@@ -426,7 +475,7 @@ void R2D_Conback_Callback(struct cvar_s *var, char *oldvalue)
 		conback = NULL;
 		return;
 	}
-		
+
 	if (*var->string)
 		conback = R_RegisterPic(var->string);
 	if (!conback || !conback->width)
diff --git a/engine/client/renderer.c b/engine/client/renderer.c
index 30242ba13..722a1271b 100644
--- a/engine/client/renderer.c
+++ b/engine/client/renderer.c
@@ -647,7 +647,6 @@ void	(*Draw_Shutdown)			(void);
 
 void	(*Draw_Crosshair)			(void);
 void	(*Draw_SubPic)				(int x, int y, int width, int height, mpic_t *pic, int srcx, int srcy, int srcwidth, int srcheight);
-void	(*Draw_TransPicTranslate)	(int x, int y, int w, int h, qbyte *image, qbyte *translation);
 
 void	(*R_Init)					(void);
 void	(*R_DeInit)					(void);
@@ -704,7 +703,6 @@ rendererinfo_t dedicatedrendererinfo = {
 	NULL,	//Draw_Init;
 	NULL,	//Draw_Shutdown;
 	NULL,	//Draw_Crosshair;
-	NULL,	//Draw_TransPicTranslate;
 
 	NULL,	//R_LoadTexture
 	NULL,	//R_LoadTexture8Pal24
@@ -1250,7 +1248,6 @@ void R_SetRenderer(rendererinfo_t *ri)
 	Draw_Init				= ri->Draw_Init;
 	Draw_Shutdown			= ri->Draw_Shutdown;
 	Draw_Crosshair			= ri->Draw_Crosshair;
-	Draw_TransPicTranslate	= ri->Draw_TransPicTranslate;
 
 	R_Init					= ri->R_Init;
 	R_DeInit				= ri->R_DeInit;
diff --git a/engine/d3d/vid_d3d.c b/engine/d3d/vid_d3d.c
index d8cc97b96..0f9b5968c 100644
--- a/engine/d3d/vid_d3d.c
+++ b/engine/d3d/vid_d3d.c
@@ -1038,9 +1038,6 @@ static void	(D3D9_Draw_ReInit)				(void)
 static void	(D3D9_Draw_Crosshair)			(void)
 {
 }
-static void	(D3D9_Draw_TransPicTranslate)	(int x, int y, int w, int h, qbyte *pic, qbyte *translation)
-{
-}
 
 static void	(D3D9_R_Init)					(void)
 {
@@ -1169,7 +1166,6 @@ rendererinfo_t d3drendererinfo =
 	D3D9_Draw_Init,
 	D3D9_Draw_ReInit,
 	D3D9_Draw_Crosshair,
-	D3D9_Draw_TransPicTranslate,
 
 	D3D9_LoadTexture,
 	D3D9_LoadTexture8Pal24,
diff --git a/engine/gl/gl_draw.c b/engine/gl/gl_draw.c
index 641d12f45..9a8613638 100644
--- a/engine/gl/gl_draw.c
+++ b/engine/gl/gl_draw.c
@@ -149,7 +149,6 @@ extern cvar_t		gl_texturemode, gl_texture_anisotropic_filtering;
 
 extern cvar_t		gl_savecompressedtex;
 
-texid_t			translate_texture;
 texid_t			missing_texture;	//texture used when one is missing.
 
 texid_t			cs_texture; // crosshair texture
@@ -387,9 +386,6 @@ TRACE(("dbg: GLDraw_ReInit: Allocating upload buffers\n"));
 
 	GL_SetupSceneProcessingTextures();
 
-	// save a texture slot for translated picture
-	translate_texture = GL_AllocNewTexture(0, 0);
-
 	//
 	// get the other pics we need
 	//
@@ -601,58 +597,6 @@ void GLDraw_Crosshair(void)
 	}
 }
 
-/*
-=============
-Draw_TransPicTranslate
-
-Only used for the player color selection menu
-=============
-*/
-void GLDraw_TransPicTranslate (int x, int y, int width, int height, qbyte *pic, qbyte *translation)
-{
-	int				v, u, c;
-	unsigned		trans[64*64], *dest;
-	qbyte			*src;
-	int				p;
-
-	if (gl_config.gles)
-		return; // TODO: NOT FIXED YET
-	
-	GL_MTBind(0, GL_TEXTURE_2D, translate_texture);
-
-	c = width * height;
-
-	dest = trans;
-	for (v=0 ; v<64 ; v++, dest += 64)
-	{
-		src = &pic[ ((v*height)>>6) *width];
-		for (u=0 ; u<64 ; u++)
-		{
-			p = src[(u*width)>>6];
-			if (p == 255)
-				dest[u] = p;
-			else
-				dest[u] =  d_8to24rgbtable[translation[p]];
-		}
-	}
-
-	qglTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, trans);
-
-	qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-	qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
-	qglColor3f (1,1,1);
-	qglBegin (GL_QUADS);
-	qglTexCoord2f (0, 0);
-	qglVertex2f (x, y);
-	qglTexCoord2f (1, 0);
-	qglVertex2f (x+width, y);
-	qglTexCoord2f (1, 1);
-	qglVertex2f (x+width, y+height);
-	qglTexCoord2f (0, 1);
-	qglVertex2f (x, y+height);
-	qglEnd ();
-}
 
 
 //=============================================================================
diff --git a/engine/gl/gl_draw.h b/engine/gl/gl_draw.h
index 0c04c8a4e..54fa7259a 100644
--- a/engine/gl/gl_draw.h
+++ b/engine/gl/gl_draw.h
@@ -25,9 +25,7 @@ void GLDraw_Init (void);
 void GLDraw_ReInit (void);
 void GLDraw_DeInit (void);
 void Surf_DeInit (void);
-void GLDraw_TransPicTranslate (int x, int y, int w, int h, qbyte *pic, qbyte *translation);
 void GLDraw_Crosshair(void);
-void GLDraw_LevelPic (mpic_t *pic);
 
 void R2D_Init(void);
 mpic_t	*R2D_SafeCachePic (char *path);
diff --git a/engine/gl/gl_vidcommon.c b/engine/gl/gl_vidcommon.c
index 88626f967..845021cf2 100644
--- a/engine/gl/gl_vidcommon.c
+++ b/engine/gl/gl_vidcommon.c
@@ -1068,7 +1068,6 @@ rendererinfo_t openglrendererinfo = {
 	GLDraw_Init,
 	GLDraw_ReInit,
 	GLDraw_Crosshair,
-	GLDraw_TransPicTranslate,
 
 	GL_LoadTextureFmt,
 	GL_LoadTexture8Pal24,