Revamp cshifts and implement in glsl.

The renderer should now be free of any direct access to client code. Even
3d rendering is now done via a function pointer.

The cshift code is done as a 2d screen function.
This commit is contained in:
Bill Currie 2012-01-28 20:45:14 +09:00
parent 315db554b5
commit 7e078c7f9c
19 changed files with 215 additions and 180 deletions

View file

@ -157,6 +157,10 @@ void Draw_TextBox (int x, int y, int width, int lines, byte alpha);
/** Darken the screen.
*/
void Draw_FadeScreen (void);
/** Shift the screen colors.
*/
void Draw_BlendScreen (quat_t color);
//@}
/** \defgroup video_renderer_draw_qpic QPic functions

View file

@ -37,7 +37,8 @@ void SCR_Init (void);
typedef void (*SCR_Func)(void);
// scr_funcs is a null terminated array
void SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs);
void SCR_UpdateScreen (double realtime, SCR_Func scr_3dfunc,
SCR_Func *scr_funcs);
void SCR_UpdateWholeScreen (void);
void SCR_SizeUp (void);

View file

@ -63,6 +63,7 @@ typedef struct {
int numpages;
qboolean recalc_refdef; // if true, recalc vid-based stuff
qboolean cshift_changed;
quat_t cshift_color;
void *conbuffer;
int conrowbytes;
unsigned int conwidth;

View file

@ -51,6 +51,4 @@ void V_Register (void);
void V_SetContentsColor (int contents);
void V_CalcBlend (void);
extern float v_blend[4];
#endif // __clview_h_

View file

@ -910,3 +910,25 @@ GL_FlushText (void)
flush_text ();
}
}
void
Draw_BlendScreen (quat_t color)
{
if (!color[3])
return;
qfglDisable (GL_TEXTURE_2D);
qfglBegin (GL_QUADS);
qfglColor4fv (color);
qfglVertex2f (0, 0);
qfglVertex2f (vid.conwidth, 0);
qfglVertex2f (vid.conwidth, vid.conheight);
qfglVertex2f (0, vid.conheight);
qfglEnd ();
qfglColor3ubv (color_white);
qfglEnable (GL_TEXTURE_2D);
}

View file

@ -65,7 +65,6 @@ static __attribute__ ((used)) const char rcsid[] =
#include "r_dynamic.h"
#include "r_local.h"
#include "varrays.h"
#include "clview.h" //FIXME
entity_t r_worldentity;
@ -403,8 +402,6 @@ R_SetupFrame (void)
// current viewleaf
r_viewleaf = Mod_PointInLeaf (r_origin, r_worldentity.model);
V_SetContentsColor (r_viewleaf->contents);
r_cache_thrash = false;
c_brush_polys = 0;
@ -947,6 +944,7 @@ R_RenderViewFishEye (void)
VISIBLE void
R_ClearState (void)
{
r_worldentity.model = 0;
R_ClearEfrags ();
R_ClearDlights ();
R_ClearParticles ();

View file

@ -61,7 +61,6 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$";
#include "r_local.h"
#include "r_screen.h"
#include "sbar.h"
#include "clview.h" //FIXME
/* SCREEN SHOTS */
@ -202,7 +201,7 @@ SCR_TileClear (void)
needs almost the entire 256k of stack space!
*/
VISIBLE void
SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
SCR_UpdateScreen (double realtime, SCR_Func scr_3dfunc, SCR_Func *scr_funcs)
{
double time1 = 0, time2;
static int begun = 0;
@ -240,30 +239,12 @@ SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
SCR_CalcRefdef ();
// do 3D refresh drawing, and then update the screen
V_RenderView ();
scr_3dfunc ();
SCR_SetUpToDrawConsole ();
GL_Set2D ();
GL_DrawReset ();
// also makes polyblend apply to whole screen
if (v_blend[3]) {
qfglDisable (GL_TEXTURE_2D);
qfglBegin (GL_QUADS);
qfglColor4fv (v_blend);
qfglVertex2f (0, 0);
qfglVertex2f (vid.width, 0);
qfglVertex2f (vid.width, vid.height);
qfglVertex2f (0, vid.height);
qfglEnd ();
qfglColor3ubv (color_white);
qfglEnable (GL_TEXTURE_2D);
}
// draw any areas not covered by the refresh
SCR_TileClear ();

View file

@ -692,13 +692,19 @@ Draw_Fill (int x, int y, int w, int h, int c)
draw_pic (x, y, w, h, white_pic, 0, 0, 8, 8, color);
}
static inline void
draw_blendscreen (quat_t color)
{
draw_pic (0, 0, vid.conwidth, vid.conheight, white_pic, 0, 0, 8, 8, color);
}
VISIBLE void
Draw_FadeScreen (void)
{
static quat_t color = { 0, 0, 0, 0.7 };
GL_FlushText (); // Flush text that should be rendered before the menu
draw_pic (0, 0, vid.conwidth, vid.conheight, white_pic, 0, 0, 8, 8, color);
draw_blendscreen (color);
}
static void
@ -761,3 +767,11 @@ GL_FlushText (void)
if (char_queue->size)
flush_text ();
}
void
Draw_BlendScreen (quat_t color)
{
if (!color[3])
return;
draw_blendscreen (color);
}

View file

@ -57,7 +57,6 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$";
#include "QF/GLSL/qf_textures.h"
#include "QF/GLSL/qf_vid.h"
#include "clview.h"//FIXME
#include "gl_draw.h"
#include "r_cvar.h"
#include "r_dynamic.h"
@ -157,7 +156,7 @@ SCR_TileClear (void)
}
VISIBLE void
SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
SCR_UpdateScreen (double realtime, SCR_Func scr_3dfunc, SCR_Func *scr_funcs)
{
static int begun = 0;
@ -187,7 +186,7 @@ SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
if (vid.recalc_refdef)
SCR_CalcRefdef ();
V_RenderView (); // FIXME (scr_3dfuncs?)
scr_3dfunc ();
SCR_SetUpToDrawConsole ();
GL_Set2D ();

View file

@ -645,3 +645,30 @@ Draw_FadeScreen (void)
S_ExtraUpdate ();
VID_LockBuffer ();
}
VISIBLE void
Draw_BlendScreen (quat_t color)
{
int r, g, b, i;
byte *basepal, *newpal;
byte pal[768];
basepal = vid.basepal;
newpal = pal;
for (i = 0; i < 256; i++) {
r = basepal[0];
g = basepal[1];
b = basepal[2];
basepal += 3;
r += (int) (color[3] * (color[0] * 256 - r));
g += (int) (color[3] * (color[1] * 256 - g));
b += (int) (color[3] * (color[2] * 256 - b));
newpal[0] = gammatable[r];
newpal[1] = gammatable[g];
newpal[2] = gammatable[b];
newpal += 3;
}
VID_ShiftPalette (pal);
}

View file

@ -55,34 +55,6 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$";
#include "r_local.h"
#include "r_screen.h"
#include "sbar.h"
#include "clview.h" //FIXME
static void
SCR_ApplyBlend (void) // Used to be V_UpdatePalette
{
int r, g, b, i;
byte *basepal, *newpal;
byte pal[768];
basepal = vid.basepal;
newpal = pal;
for (i = 0; i < 256; i++) {
r = basepal[0];
g = basepal[1];
b = basepal[2];
basepal += 3;
r += (int) (v_blend[3] * (v_blend[0] * 256 - r));
g += (int) (v_blend[3] * (v_blend[1] * 256 - g));
b += (int) (v_blend[3] * (v_blend[2] * 256 - b));
newpal[0] = gammatable[r];
newpal[1] = gammatable[g];
newpal[2] = gammatable[b];
newpal += 3;
}
VID_ShiftPalette (pal);
}
/* SCREEN SHOTS */
@ -221,7 +193,7 @@ SCR_ScreenShot_f (void)
needs almost the entire 256k of stack space!
*/
void
SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
SCR_UpdateScreen (double realtime, SCR_Func scr_3dfunc, SCR_Func *scr_funcs)
{
vrect_t vrect;
@ -261,7 +233,7 @@ SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
D_DisableBackBufferAccess (); // for adapters that can't stay mapped
// in for linear writes all the time
VID_LockBuffer ();
V_RenderView ();
scr_3dfunc ();
VID_UnlockBuffer ();
D_EnableBackBufferAccess (); // of all overlay stuff if drawing
@ -278,8 +250,6 @@ SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
D_UpdateRects (pconupdate);
}
SCR_ApplyBlend ();
// update one of three areas
if (scr_copyeverything) {
vrect.x = 0;

View file

@ -56,7 +56,6 @@ static __attribute__ ((used)) const char rcsid[] =
#include "r_cvar.h"
#include "r_dynamic.h"
#include "r_local.h"
#include "clview.h" //FIXME
#ifdef PIC
# undef USE_INTEL_ASM //XXX asm pic hack
@ -791,8 +790,6 @@ R_RenderView_ (void)
if (r_dowarp)
D_WarpScreen ();
V_SetContentsColor (r_viewleaf->contents);
if (r_timegraph->int_val)
R_TimeGraph ();

View file

@ -1112,3 +1112,97 @@ Draw_FadeScreen (void)
S_ExtraUpdate ();
VID_LockBuffer ();
}
VISIBLE void
Draw_BlendScreen (quat_t color)
{
int r, g, b, i;
byte *basepal, *newpal;
byte pal[768];
switch(r_pixbytes) {
case 1:
{
basepal = vid.basepal;
newpal = pal;
for (i = 0; i < 256; i++) {
r = basepal[0];
g = basepal[1];
b = basepal[2];
basepal += 3;
r += (int) (color[3] * (color[0] * 256 - r));
g += (int) (color[3] * (color[1] * 256 - g));
b += (int) (color[3] * (color[2] * 256 -g));
newpal[0] = gammatable[r];
newpal[1] = gammatable[g];
newpal[2] = gammatable[b];
newpal += 3;
}
VID_ShiftPalette (pal);
}
break;
case 2:
{
unsigned int g1, g2, x, y;
unsigned short rramp[32], gramp[64], bramp[32], *temp;
for (i = 0; i < 32; i++) {
r = i << 3;
g1 = i << 3;
g2 = g1 + 4;
b = i << 3;
r += (int) (color[3] * (color[0] * 256 - r));
g1 += (int) (color[3] * (color[1] - g1));
g2 += (int) (color[3] * (color[1] - g2));
b += (int) (color[3] * (color[2] - b));
rramp[i] = (gammatable[r] << 8) & 0xF800;
gramp[i*2+0] = (gammatable[g1] << 3) & 0x07E0;
gramp[i*2+1] = (gammatable[g2] << 3) & 0x07E0;
bramp[i] = (gammatable[b] >> 3) & 0x001F;
}
temp = vid.buffer;
for (y = 0;y < vid.height;y++, temp += (vid.rowbytes >> 1))
for (x = 0;x < vid.width;x++)
temp[x] = rramp[(temp[x] & 0xF800) >> 11]
+ gramp[(temp[x] & 0x07E0) >> 5] + bramp[temp[x] & 0x001F];
}
break;
case 4:
{
unsigned int x, y;
byte ramp[256][4], *temp;
for (i = 0; i < 256; i++) {
r = i;
g = i;
b = i;
r += (int) (color[3] * (color[0] * 256 - r));
g += (int) (color[3] * (color[1] * 256 - g));
b += (int) (color[3] * (color[2] * 256 - b));
ramp[i][0] = gammatable[r];
ramp[i][1] = gammatable[g];
ramp[i][2] = gammatable[b];
ramp[i][3] = 0;
}
temp = vid.buffer;
for (y = 0;y < vid.height;y++, temp += vid.rowbytes)
{
for (x = 0;x < vid.width;x++)
{
temp[x*4+0] = ramp[temp[x*4+0]][0];
temp[x*4+1] = ramp[temp[x*4+1]][1];
temp[x*4+2] = ramp[temp[x*4+2]][2];
temp[x*4+3] = 0;
}
}
}
break;
default:
Sys_Error("V_UpdatePalette: unsupported r_pixbytes %i", r_pixbytes);
}
}

View file

@ -56,101 +56,6 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$";
#include "r_local.h"
#include "r_screen.h"
#include "sbar.h"
#include "clview.h"
static void
SCR_ApplyBlend (void) // Used to be V_UpdatePalette
{
int r, g, b, i;
byte *basepal, *newpal;
byte pal[768];
switch(r_pixbytes) {
case 1:
{
basepal = vid.basepal;
newpal = pal;
for (i = 0; i < 256; i++) {
r = basepal[0];
g = basepal[1];
b = basepal[2];
basepal += 3;
r += (int) (v_blend[3] * (v_blend[0] * 256 - r));
g += (int) (v_blend[3] * (v_blend[1] * 256 - g));
b += (int) (v_blend[3] * (v_blend[2] * 256 -g));
newpal[0] = gammatable[r];
newpal[1] = gammatable[g];
newpal[2] = gammatable[b];
newpal += 3;
}
VID_ShiftPalette (pal);
}
break;
case 2:
{
unsigned int g1, g2, x, y;
unsigned short rramp[32], gramp[64], bramp[32], *temp;
for (i = 0; i < 32; i++) {
r = i << 3;
g1 = i << 3;
g2 = g1 + 4;
b = i << 3;
r += (int) (v_blend[3] * (v_blend[0] * 256 - r));
g1 += (int) (v_blend[3] * (v_blend[1] - g1));
g2 += (int) (v_blend[3] * (v_blend[1] - g2));
b += (int) (v_blend[3] * (v_blend[2] - b));
rramp[i] = (gammatable[r] << 8) & 0xF800;
gramp[i*2+0] = (gammatable[g1] << 3) & 0x07E0;
gramp[i*2+1] = (gammatable[g2] << 3) & 0x07E0;
bramp[i] = (gammatable[b] >> 3) & 0x001F;
}
temp = vid.buffer;
for (y = 0;y < vid.height;y++, temp += (vid.rowbytes >> 1))
for (x = 0;x < vid.width;x++)
temp[x] = rramp[(temp[x] & 0xF800) >> 11]
+ gramp[(temp[x] & 0x07E0) >> 5] + bramp[temp[x] & 0x001F];
}
break;
case 4:
{
unsigned int x, y;
byte ramp[256][4], *temp;
for (i = 0; i < 256; i++) {
r = i;
g = i;
b = i;
r += (int) (v_blend[3] * (v_blend[0] * 256 - r));
g += (int) (v_blend[3] * (v_blend[1] * 256 - g));
b += (int) (v_blend[3] * (v_blend[2] * 256 - b));
ramp[i][0] = gammatable[r];
ramp[i][1] = gammatable[g];
ramp[i][2] = gammatable[b];
ramp[i][3] = 0;
}
temp = vid.buffer;
for (y = 0;y < vid.height;y++, temp += vid.rowbytes)
{
for (x = 0;x < vid.width;x++)
{
temp[x*4+0] = ramp[temp[x*4+0]][0];
temp[x*4+1] = ramp[temp[x*4+1]][1];
temp[x*4+2] = ramp[temp[x*4+2]][2];
temp[x*4+3] = 0;
}
}
}
break;
default:
Sys_Error("V_UpdatePalette: unsupported r_pixbytes %i", r_pixbytes);
}
}
/* SCREEN SHOTS */
@ -242,7 +147,7 @@ SCR_ScreenShot_f (void)
needs almost the entire 256k of stack space!
*/
VISIBLE void
SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
SCR_UpdateScreen (double realtime, SCR_Func scr_3dfunc, SCR_Func *scr_funcs)
{
vrect_t vrect;
@ -282,7 +187,7 @@ SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
D_DisableBackBufferAccess (); // for adapters that can't stay mapped
// in for linear writes all the time
VID_LockBuffer ();
V_RenderView ();
scr_3dfunc ();
VID_UnlockBuffer ();
D_EnableBackBufferAccess (); // of all overlay stuff if drawing
@ -299,8 +204,6 @@ SCR_UpdateScreen (double realtime, SCR_Func *scr_funcs)
D_UpdateRects (pconupdate);
}
SCR_ApplyBlend ();
// update one of three areas
if (scr_copyeverything) {
vrect.x = 0;

View file

@ -53,7 +53,6 @@ static __attribute__ ((used)) const char rcsid[] =
#include "r_cvar.h"
#include "r_dynamic.h"
#include "r_local.h"
#include "clview.h"
//define PASSAGES
@ -807,8 +806,6 @@ R_RenderView_ (void)
if (r_dowarp)
D_WarpScreen ();
V_SetContentsColor (r_viewleaf->contents);
if (r_timegraph->int_val)
R_TimeGraph ();

View file

@ -76,6 +76,20 @@ SCR_DrawLoading (void)
(vid.conheight - 48 - pic->height) / 2, pic);
}
static void
SCR_CShift (void)
{
mleaf_t *leaf;
int contents = CONTENTS_EMPTY;
if (cls.signon != SIGNONS && cl.worldmodel) {
leaf = Mod_PointInLeaf (r_refdef.vieworg, cl.worldmodel);
contents = leaf->contents;
}
V_SetContentsColor (contents);
Draw_BlendScreen (vid.cshift_color);
}
static SCR_Func scr_funcs_normal[] = {
Draw_Crosshair,
SCR_DrawRam,
@ -86,6 +100,7 @@ static SCR_Func scr_funcs_normal[] = {
Sbar_Draw,
Con_DrawConsole,
SCR_DrawLoading,
SCR_CShift,
0
};
@ -118,5 +133,5 @@ CL_UpdateScreen (double realtime)
cl_wateralpha = r_wateralpha->value;
V_PrepBlend ();
SCR_UpdateScreen (realtime, scr_funcs[index]);
SCR_UpdateScreen (realtime, V_RenderView, scr_funcs[index]);
}

View file

@ -81,7 +81,6 @@ cvar_t *v_ipitch_level;
cvar_t *v_idlescale;
float v_dmg_time, v_dmg_roll, v_dmg_pitch;
float v_blend[4];
cshift_t cshift_empty = { {130, 80, 50}, 0};
@ -390,10 +389,10 @@ V_CalcBlend (void)
b *= a2;
}
v_blend[0] = min (r, 255.0) / 255.0;
v_blend[1] = min (g, 255.0) / 255.0;
v_blend[2] = min (b, 255.0) / 255.0;
v_blend[3] = bound (0.0, a, 1.0);
vid.cshift_color[0] = min (r, 255.0) / 255.0;
vid.cshift_color[1] = min (g, 255.0) / 255.0;
vid.cshift_color[2] = min (b, 255.0) / 255.0;
vid.cshift_color[3] = bound (0.0, a, 1.0);
}
void

View file

@ -53,6 +53,7 @@ static __attribute__ ((used)) const char rcsid[] =
#include "cl_parse.h"
#include "client.h"
#include "clview.h"
#include "compat.h"
#include "r_local.h"
#include "r_cvar.h"
@ -71,6 +72,20 @@ SCR_DrawNet (void)
Draw_Pic (scr_vrect.x + 64, scr_vrect.y, scr_net);
}
static void
SCR_CShift (void)
{
mleaf_t *leaf;
int contents = CONTENTS_EMPTY;
if (r_active && cl.worldmodel) {
leaf = Mod_PointInLeaf (r_refdef.vieworg, cl.worldmodel);
contents = leaf->contents;
}
V_SetContentsColor (contents);
Draw_BlendScreen (vid.cshift_color);
}
static SCR_Func scr_funcs_normal[] = {
Draw_Crosshair,
SCR_DrawRam,
@ -81,6 +96,7 @@ static SCR_Func scr_funcs_normal[] = {
Sbar_DrawCenterPrint,
Sbar_Draw,
Con_DrawConsole,
SCR_CShift,
0
};
@ -119,7 +135,7 @@ CL_UpdateScreen (double realtime)
}
V_PrepBlend ();
SCR_UpdateScreen (realtime, scr_funcs[index]);
SCR_UpdateScreen (realtime, V_RenderView, scr_funcs[index]);
}
void

View file

@ -81,7 +81,6 @@ cvar_t *v_ipitch_level;
cvar_t *v_idlescale;
float v_dmg_time, v_dmg_roll, v_dmg_pitch;
float v_blend[4];
frame_t *view_frame;
@ -427,10 +426,10 @@ V_CalcBlend (void)
b *= a2;
}
v_blend[0] = min (r, 255.0) / 255.0;
v_blend[1] = min (g, 255.0) / 255.0;
v_blend[2] = min (b, 255.0) / 255.0;
v_blend[3] = bound (0.0, a, 1.0);
vid.cshift_color[0] = min (r, 255.0) / 255.0;
vid.cshift_color[1] = min (g, 255.0) / 255.0;
vid.cshift_color[2] = min (b, 255.0) / 255.0;
vid.cshift_color[3] = bound (0.0, a, 1.0);
}
void