Make the cross-hair data sharable between renderers.

This commit is contained in:
Bill Currie 2011-12-26 21:43:15 +09:00
parent 705d07fa39
commit db8573b774
4 changed files with 116 additions and 48 deletions

View file

@ -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

View file

@ -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)

View file

@ -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 <stdlib.h>
#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;
}

View file

@ -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);