Connect up palette setting for gl and glsl.

The GL plugin now seems to work. GLSL still segs :(
This commit is contained in:
Bill Currie 2012-04-12 13:57:05 +09:00
parent 525dbcc13e
commit 8401704c4e
10 changed files with 104 additions and 94 deletions

View file

@ -88,4 +88,7 @@ void R_DrawAliasModel (entity_t *e);
void R_MarkLeaves (void);
void GL_SetPalette (const byte *palette);
void GLSL_SetPalette (const byte *palette);
#endif//__r_internal_h

View file

@ -12,7 +12,6 @@ extern unsigned short sw32_8to16table[256];
void VID_GetWindowSize (int def_w, int def_h);
void VID_SetPalette (const byte *palette);
void VID_InitGamma (unsigned char *);
qboolean VID_SetGamma (double);
void VID_UpdateGamma (struct cvar_s *);

View file

@ -702,10 +702,10 @@ VID_Init8bitPalette (void)
}
}
static __attribute__((used)) void //FIXME
VID_SetPalette (unsigned char *palette)
void
GL_SetPalette (const byte *palette)
{
byte *pal;
const byte *pal;
char s[255];
float dist, bestdist;
int r1, g1, b1, k;

View file

@ -66,25 +66,23 @@ GLSL_Common_Init_Cvars (void)
{
}
static __attribute__((used)) void //FIXME
VID_SetPalette (unsigned char *palette)
void
GLSL_SetPalette (const byte *palette)
{
byte *pal, *col, *ip, *op;
unsigned int r, g, b, v;
const byte *col, *ip;
byte *pal, *op;
unsigned r, g, b, v;
unsigned short i;
unsigned int *table;
unsigned *table;
// 8 8 8 encoding
Sys_MaskPrintf (SYS_VID, "Converting 8to24\n");
pal = palette;
table = d_8to24table;
for (i = 0; i < 255; i++) { // used to be i<256, see d_8to24table below
r = pal[0];
g = pal[1];
b = pal[2];
pal += 3;
r = palette[i * 3 + 0];
g = palette[i * 3 + 1];
b = palette[i * 3 + 2];
#ifdef WORDS_BIGENDIAN
v = (255 << 0) + (r << 24) + (g << 16) + (b << 8);
#else

View file

@ -124,6 +124,7 @@ vid_render_funcs_t gl_vid_render_funcs = {
static void
gl_vid_render_init (void)
{
vr_data.vid->set_palette = GL_SetPalette;
vr_data.vid->init_gl = GL_Init_Common;
vr_data.vid->load_gl ();
vr_funcs = &gl_vid_render_funcs;

View file

@ -34,6 +34,8 @@
#include "QF/plugin/general.h"
#include "QF/plugin/vid_render.h"
#include "QF/GLSL/qf_vid.h"
#include "mod_internal.h"
#include "r_internal.h"
@ -122,6 +124,9 @@ vid_render_funcs_t glsl_vid_render_funcs = {
static void
glsl_vid_render_init (void)
{
vr_data.vid->set_palette = GLSL_SetPalette;
vr_data.vid->init_gl = GLSL_Init_Common;
vr_data.vid->load_gl ();
vr_funcs = &glsl_vid_render_funcs;
m_funcs = &model_funcs;
vid = *vr_data.vid;

View file

@ -217,7 +217,7 @@ VID_UpdateGamma (cvar_t *vid_gamma)
VID_BuildGammaTable (gamma);
for (i = 0; i < 256 * 3; i++)
viddef.palette[i] = viddef.gammatable[viddef.basepal[i]];
VID_SetPalette (viddef.palette); // update with the new palette
viddef.set_palette (viddef.palette); // update with the new palette
}
}
@ -232,7 +232,6 @@ VID_InitGamma (unsigned char *pal)
int i;
double gamma = 1.45;
viddef.set_palette = VID_SetPalette;
viddef.gammatable = malloc (256);
viddef.basepal = pal;
viddef.palette = malloc (256 * 3);

View file

@ -251,31 +251,6 @@ loadpalette (unsigned short *red, unsigned short *green, unsigned short *blue)
Sys_Error("ioctl FBIOPUTCMAP %s", strerror(errno));
}
void
VID_SetPalette (const byte *palette)
{
static unsigned short tmppalr[256], tmppalg[256], tmppalb[256];
unsigned short i, *tpr, *tpg, *tpb;
if (!fbdev_inited || fbdev_backgrounded || fb_fd < 0)
return;
memcpy (vid_current_palette, palette, sizeof (vid_current_palette));
if (current_mode.depth == 8) {
tpr = tmppalr;
tpg = tmppalg;
tpb = tmppalb;
for (i = 0; i < 256; i++) {
*tpr++ = (*palette++) << 8;
*tpg++ = (*palette++) << 8;
*tpb++ = (*palette++) << 8;
}
loadpalette(tmppalr, tmppalg, tmppalb);
}
}
static int
VID_SetMode (const char *name, unsigned char *palette)
{
@ -324,7 +299,7 @@ VID_SetMode (const char *name, unsigned char *palette)
Sys_Error ("Video mode failed: %s", name);
ConvertToVideoMode(&var, &current_mode);
current_mode.name = current_name;
VID_SetPalette (palette);
viddef.set_palette (palette);
err = ioctl(fb_fd, FBIOGET_FSCREENINFO, &fix);
if (err)
@ -397,6 +372,31 @@ fb_switch_init (void)
}
}
static void
VID_SetPalette (const byte *palette)
{
static unsigned short tmppalr[256], tmppalg[256], tmppalb[256];
unsigned short i, *tpr, *tpg, *tpb;
if (!fbdev_inited || fbdev_backgrounded || fb_fd < 0)
return;
memcpy (vid_current_palette, palette, sizeof (vid_current_palette));
if (current_mode.depth == 8) {
tpr = tmppalr;
tpg = tmppalg;
tpb = tmppalb;
for (i = 0; i < 256; i++) {
*tpr++ = (*palette++) << 8;
*tpg++ = (*palette++) << 8;
*tpb++ = (*palette++) << 8;
}
loadpalette(tmppalr, tmppalg, tmppalb);
}
}
void
VID_Init (byte *palette, byte *colormap)
{
@ -409,6 +409,8 @@ VID_Init (byte *palette, byte *colormap)
if (fbdev_inited)
return;
viddef.set_palette = VID_SetPalette;
if (COM_CheckParm ("-novideo")) {
viddef.width = 320;
viddef.height = 200;
@ -460,7 +462,7 @@ VID_Init (byte *palette, byte *colormap)
VID_SetMode (current_mode.name, palette);
VID_InitGamma (palette);
VID_SetPalette (viddef.palette);
viddef.set_palette (viddef.palette);
viddef.initialized = true;
}
@ -485,7 +487,7 @@ VID_Update (vrect_t *rects)
} else if (fbdev_backgrounded == 2) {
fb_switch_acquire();
fbdev_backgrounded = 0;
VID_SetPalette(vid_current_palette);
viddef.set_palette (vid_current_palette);
} else if (fbdev_backgrounded == 1) {
fb_switch_release();
fbdev_backgrounded = 3;

View file

@ -66,7 +66,7 @@ int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes = 0;
SDL_Surface *screen = NULL;
void
static void
VID_SetPalette (const byte *palette)
{
SDL_Color colors[256];
@ -90,6 +90,8 @@ VID_Init (byte *palette, byte *colormap)
{
Uint32 flags;
viddef.set_palette = VID_SetPalette;
// Load the SDL library
if (SDL_Init (SDL_INIT_VIDEO) < 0)
Sys_Error ("VID: Couldn't load SDL: %s", SDL_GetError ());
@ -109,7 +111,7 @@ VID_Init (byte *palette, byte *colormap)
Sys_Error ("VID: Couldn't set video mode: %s", SDL_GetError ());
VID_InitGamma (palette);
VID_SetPalette (viddef.palette);
viddef.set_palette (viddef.palette);
// now know everything we need to know about the buffer
VGA_width = viddef.width;

View file

@ -633,53 +633,7 @@ x11_create_context (void)
// X11_AddEvent (x_shmeventtype, event_shm);
}
/*
Set up color translation tables and the window. Takes a 256-color 8-bit
palette. Palette data will go away after the call, so copy it if you'll
need it later.
*/
void
VID_Init (byte *palette, byte *colormap)
{
choose_visual = x11_choose_visual;
create_context = x11_create_context;
viddef.load_gl = glx_load_gl;
R_LoadModule ();
viddef.numpages = 2;
viddef.colormap8 = colormap;
viddef.fullbright = 256 - viddef.colormap8[256 * VID_GRADES];
srandom (getpid ());
VID_GetWindowSize (320, 200);
X11_OpenDisplay ();
choose_visual ();
X11_SetVidMode (viddef.width, viddef.height);
X11_CreateWindow (viddef.width, viddef.height);
X11_CreateNullCursor (); // hide mouse pointer
create_context ();
VID_InitGamma (palette);
VID_SetPalette (viddef.palette);
Sys_MaskPrintf (SYS_VID, "Video mode %dx%d initialized.\n",
viddef.width, viddef.height);
viddef.initialized = true;
viddef.recalc_refdef = 1; // force a surface cache flush
}
void
VID_Init_Cvars ()
{
X11_Init_Cvars ();
gl_driver = Cvar_Get ("gl_driver", GL_DRIVER, CVAR_ROM, NULL,
"The OpenGL library to use. (path optional)");
}
void
static void
VID_SetPalette (const byte *palette)
{
int i;
@ -707,6 +661,53 @@ VID_SetPalette (const byte *palette)
}
}
/*
Set up color translation tables and the window. Takes a 256-color 8-bit
palette. Palette data will go away after the call, so copy it if you'll
need it later.
*/
void
VID_Init (byte *palette, byte *colormap)
{
choose_visual = x11_choose_visual;
create_context = x11_create_context;
viddef.load_gl = glx_load_gl;
viddef.set_palette = VID_SetPalette;
R_LoadModule ();
viddef.numpages = 2;
viddef.colormap8 = colormap;
viddef.fullbright = 256 - viddef.colormap8[256 * VID_GRADES];
srandom (getpid ());
VID_GetWindowSize (320, 200);
X11_OpenDisplay ();
choose_visual ();
X11_SetVidMode (viddef.width, viddef.height);
X11_CreateWindow (viddef.width, viddef.height);
X11_CreateNullCursor (); // hide mouse pointer
create_context ();
VID_InitGamma (palette);
viddef.set_palette (viddef.palette);
Sys_MaskPrintf (SYS_VID, "Video mode %dx%d initialized.\n",
viddef.width, viddef.height);
viddef.initialized = true;
viddef.recalc_refdef = 1; // force a surface cache flush
}
void
VID_Init_Cvars ()
{
X11_Init_Cvars ();
gl_driver = Cvar_Get ("gl_driver", GL_DRIVER, CVAR_ROM, NULL,
"The OpenGL library to use. (path optional)");
}
/*
VID_Shutdown