From db8573b774dc6c48119b7caa24c0651d29313eea Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 26 Dec 2011 21:43:15 +0900 Subject: [PATCH] Make the cross-hair data sharable between renderers. --- include/r_local.h | 9 +++ libs/video/renderer/Makefile.am | 2 +- libs/video/renderer/crosshair.c | 98 ++++++++++++++++++++++++++++++++ libs/video/renderer/gl/gl_draw.c | 55 +++--------------- 4 files changed, 116 insertions(+), 48 deletions(-) create mode 100644 libs/video/renderer/crosshair.c diff --git a/include/r_local.h b/include/r_local.h index e36e9da1b..634103a11 100644 --- a/include/r_local.h +++ b/include/r_local.h @@ -384,4 +384,13 @@ void R_DrawSurfaceBlock32_mip1 (void); void R_DrawSurfaceBlock32_mip2 (void); void R_DrawSurfaceBlock32_mip3 (void); +extern byte crosshair_data[]; +#define CROSSHAIR_WIDTH 8 +#define CROSSHAIR_HEIGHT 8 +#define CROSSHAIR_TILEX 2 +#define CROSSHAIR_TILEY 2 +#define CROSSHAIR_COUNT (CROSSHAIR_TILEX * CROSSHAIR_TILEY) + +struct qpic_s *Draw_CrosshairPic (void); + #endif // _R_LOCAL_H diff --git a/libs/video/renderer/Makefile.am b/libs/video/renderer/Makefile.am index a79abbe47..878c24943 100644 --- a/libs/video/renderer/Makefile.am +++ b/libs/video/renderer/Makefile.am @@ -10,7 +10,7 @@ EXTRA_LTLIBRARIES= libQFrenderer_sw.la libQFrenderer_sw32.la \ libQFrenderer_gl.la libQFrenderer_glsl.la common_sources= \ - r_cvar.c r_efrag.c r_ent.c r_graph.c r_light.c r_main.c \ + crosshair.c r_cvar.c r_efrag.c r_ent.c r_graph.c r_light.c r_main.c \ r_part.c r_progs.c r_screen.c libQFrenderer_gl_la_LDFLAGS= -version-info $(QUAKE_LIBRARY_VERSION_INFO) -rpath $(libdir) diff --git a/libs/video/renderer/crosshair.c b/libs/video/renderer/crosshair.c new file mode 100644 index 000000000..eaa4a2c24 --- /dev/null +++ b/libs/video/renderer/crosshair.c @@ -0,0 +1,98 @@ +/* + crosshair.c + + Crosshair static data. + + Copyright (C) 1996-1997 Id Software, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + +*/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +static __attribute__ ((used)) const char rcsid[] = "$Id$"; + +#include + +#include "QF/qtypes.h" +#include "QF/wadfile.h" + +#include "r_local.h" + +// NOTE: this array is INCORRECT for direct uploading in GL +// but is optimal for SW +byte crosshair_data[CROSSHAIR_WIDTH * CROSSHAIR_HEIGHT * CROSSHAIR_COUNT] = { + 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, + 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, + 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + + 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, + 0xff, 0xfe, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xfe, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, + 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + + //From FitzQuake + 255,255,255,255,255,255,255,255, + 255,255,255, 8, 9,255,255,255, + 255,255,255, 6, 8, 2,255,255, + 255, 6, 8, 8, 6, 8, 8,255, + 255,255, 2, 8, 8, 2, 2, 2, + 255,255,255, 7, 8, 2,255,255, + 255,255,255,255, 2, 2,255,255, + 255,255,255,255,255,255,255,255, +}; + +qpic_t * +Draw_CrosshairPic (void) +{ + qpic_t *pic; + byte *data; + int i, j, x, y, ind; + + pic = malloc (field_offset (qpic_t, data[sizeof (crosshair_data)])); + pic->width = CROSSHAIR_TILEX * CROSSHAIR_WIDTH; + pic->height = CROSSHAIR_TILEY * CROSSHAIR_HEIGHT; + // re-arrange the crosshair_data bytes so they're layed out properly for + // subimaging + data = crosshair_data; + for (j = 0; j < CROSSHAIR_TILEY; j++) { + for (i = 0; i < CROSSHAIR_TILEX; i++) { + for (y = 0; y < CROSSHAIR_HEIGHT; y++) { + for (x = 0; x < CROSSHAIR_WIDTH; x++) { + ind = j * CROSSHAIR_HEIGHT + y; + ind *= CROSSHAIR_WIDTH * CROSSHAIR_TILEX; + ind += i * CROSSHAIR_WIDTH + x; + pic->data[ind] = *data++; + } + } + } + } + return pic; +} diff --git a/libs/video/renderer/gl/gl_draw.c b/libs/video/renderer/gl/gl_draw.c index c05362d2c..ce812e452 100644 --- a/libs/video/renderer/gl/gl_draw.c +++ b/libs/video/renderer/gl/gl_draw.c @@ -61,6 +61,7 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$"; #include "compat.h" #include "gl_draw.h" #include "r_cvar.h" +#include "r_local.h" #include "r_shared.h" #include "sbar.h" #include "varrays.h" @@ -93,37 +94,6 @@ static int cs_texture; // crosshair texturea static byte color_0_8[4] = { 204, 204, 204, 255 }; -// NOTE: this array is INCORRECT for direct uploading see Draw_Init -static byte cs_data[8 * 8 * 4] = { - 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, - 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, - 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - - 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, - 0xff, 0xfe, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xfe, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, - 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - - //From FitzQuake - 255,255,255,255,255,255,255,255, - 255,255,255, 8, 9,255,255,255, - 255,255,255, 6, 8, 2,255,255, - 255, 6, 8, 8, 6, 8, 8,255, - 255,255, 2, 8, 8, 2, 2, 2, - 255,255,255, 7, 8, 2,255,255, - 255,255,255,255, 2, 2,255,255, - 255,255,255,255,255,255,255,255, -}; - typedef struct { int texnum; } glpic_t; @@ -338,8 +308,8 @@ Draw_Init (void) { int i; tex_t *image; - byte *cs_tmp_data; float width, height; + qpic_t *ch_pic; Cmd_AddCommand ("gl_texturemode", &GL_TextureMode_f, "Texture mipmap quality."); @@ -391,21 +361,12 @@ Draw_Init (void) char_cells[i].bly = frow - CELL_INSET / height + CELL_SIZE; } - // re-arrange the cs_data bytes so they're layed out properly for - // subimaging - cs_tmp_data = malloc (sizeof (cs_data)); - for (i = 0; i < 8 * 8; i++) { - int x, y; - x = i % 8; - y = i / 8; - cs_tmp_data[y * 16 + x + 0 * 8 * 8 + 0] = cs_data[i + 0 * 8 * 8]; - cs_tmp_data[y * 16 + x + 0 * 8 * 8 + 8] = cs_data[i + 1 * 8 * 8]; - cs_tmp_data[y * 16 + x + 2 * 8 * 8 + 0] = cs_data[i + 2 * 8 * 8]; - cs_tmp_data[y * 16 + x + 2 * 8 * 8 + 8] = cs_data[i + 3 * 8 * 8]; - } - cs_texture = GL_LoadTexture ("crosshair", 16, 16, cs_tmp_data, - false, true, 1); - free (cs_tmp_data); + ch_pic = Draw_CrosshairPic (); + cs_texture = GL_LoadTexture ("crosshair", + CROSSHAIR_WIDTH * CROSSHAIR_TILEX, + CROSSHAIR_HEIGHT * CROSSHAIR_TILEY, + ch_pic->data, false, true, 1); + free (ch_pic); qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);