mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-15 16:41:22 +00:00
Roll back current implementation
This commit is contained in:
parent
a2d26ebcac
commit
371ff81fc3
8 changed files with 45 additions and 91 deletions
|
@ -722,7 +722,7 @@ void GL_SetCanvas (canvastype newcanvas)
|
|||
break;
|
||||
case CANVAS_WARPIMAGE:
|
||||
glOrtho (0, 128, 0, 128, -99999, 99999);
|
||||
glViewport (0, vid.unscaled_height-gl_warpimagesize, gl_warpimagesize, gl_warpimagesize);
|
||||
glViewport (glx, gly+glheight-gl_warpimagesize, gl_warpimagesize, gl_warpimagesize);
|
||||
break;
|
||||
case CANVAS_CROSSHAIR: //0,0 is center of viewport
|
||||
s = CLAMP (1.0, scr_crosshairscale.value, 10.0);
|
||||
|
|
|
@ -118,9 +118,9 @@ qboolean r_drawflat_cheatsafe, r_fullbright_cheatsafe, r_lightmap_cheatsafe, r_d
|
|||
//
|
||||
//==============================================================================
|
||||
|
||||
static GLuint r_postprocess_texture;
|
||||
static GLuint r_gamma_texture;
|
||||
static GLuint r_gamma_program;
|
||||
static int r_postprocess_texture_width, r_postprocess_texture_height;
|
||||
static int r_gamma_texture_width, r_gamma_texture_height;
|
||||
|
||||
// uniforms used in gamma shader
|
||||
static GLuint gammaLoc;
|
||||
|
@ -134,8 +134,8 @@ GLSLGamma_DeleteTexture
|
|||
*/
|
||||
void GLSLGamma_DeleteTexture (void)
|
||||
{
|
||||
glDeleteTextures (1, &r_postprocess_texture);
|
||||
r_postprocess_texture = 0;
|
||||
glDeleteTextures (1, &r_gamma_texture);
|
||||
r_gamma_texture = 0;
|
||||
r_gamma_program = 0; // deleted in R_DeleteShaders
|
||||
}
|
||||
|
||||
|
@ -180,46 +180,41 @@ static void GLSLGamma_CreateShaders (void)
|
|||
|
||||
/*
|
||||
=============
|
||||
R_Postprocess
|
||||
|
||||
Performs:
|
||||
- GLSL gamma correction (requires OpenGL 2.0)
|
||||
- framebuffer scaling (vid_scale) (any OpenGL version)
|
||||
GLSLGamma_GammaCorrect
|
||||
=============
|
||||
*/
|
||||
void R_Postprocess (void)
|
||||
void GLSLGamma_GammaCorrect (void)
|
||||
{
|
||||
qboolean wants_gamma, wants_scaling;
|
||||
float smax, tmax;
|
||||
|
||||
wants_gamma = gl_glsl_gamma_able && (vid_gamma.value != 1 || vid_contrast.value != 1);
|
||||
wants_scaling = (vid.unscaled_width != vid.width || vid.unscaled_height != vid.height);
|
||||
if (!gl_glsl_gamma_able)
|
||||
return;
|
||||
|
||||
if (!wants_gamma && !wants_scaling)
|
||||
if (vid_gamma.value == 1 && vid_contrast.value == 1)
|
||||
return;
|
||||
|
||||
// create render-to-texture texture if needed
|
||||
if (!r_postprocess_texture)
|
||||
if (!r_gamma_texture)
|
||||
{
|
||||
glGenTextures (1, &r_postprocess_texture);
|
||||
glBindTexture (GL_TEXTURE_2D, r_postprocess_texture);
|
||||
glGenTextures (1, &r_gamma_texture);
|
||||
glBindTexture (GL_TEXTURE_2D, r_gamma_texture);
|
||||
|
||||
r_postprocess_texture_width = glwidth;
|
||||
r_postprocess_texture_height = glheight;
|
||||
r_gamma_texture_width = glwidth;
|
||||
r_gamma_texture_height = glheight;
|
||||
|
||||
if (!gl_texture_NPOT)
|
||||
{
|
||||
r_postprocess_texture_width = TexMgr_Pad(r_postprocess_texture_width);
|
||||
r_postprocess_texture_height = TexMgr_Pad(r_postprocess_texture_height);
|
||||
r_gamma_texture_width = TexMgr_Pad(r_gamma_texture_width);
|
||||
r_gamma_texture_height = TexMgr_Pad(r_gamma_texture_height);
|
||||
}
|
||||
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, r_postprocess_texture_width, r_postprocess_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, r_gamma_texture_width, r_gamma_texture_height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
}
|
||||
|
||||
// create shader if needed
|
||||
if (wants_gamma && !r_gamma_program)
|
||||
if (!r_gamma_program)
|
||||
{
|
||||
GLSLGamma_CreateShaders ();
|
||||
if (!r_gamma_program)
|
||||
|
@ -230,29 +225,22 @@ void R_Postprocess (void)
|
|||
|
||||
// copy the framebuffer to the texture
|
||||
GL_DisableMultitexture();
|
||||
glBindTexture (GL_TEXTURE_2D, r_postprocess_texture);
|
||||
glBindTexture (GL_TEXTURE_2D, r_gamma_texture);
|
||||
glCopyTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, glx, gly, glwidth, glheight);
|
||||
|
||||
// draw the texture back to the framebuffer with a fragment shader
|
||||
if (wants_gamma)
|
||||
{
|
||||
GL_UseProgramFunc (r_gamma_program);
|
||||
GL_Uniform1fFunc (gammaLoc, vid_gamma.value);
|
||||
GL_Uniform1fFunc (contrastLoc, q_min(2.0, q_max(1.0, vid_contrast.value)));
|
||||
GL_Uniform1iFunc (textureLoc, 0); // use texture unit 0
|
||||
}
|
||||
GL_UseProgramFunc (r_gamma_program);
|
||||
GL_Uniform1fFunc (gammaLoc, vid_gamma.value);
|
||||
GL_Uniform1fFunc (contrastLoc, q_min(2.0, q_max(1.0, vid_contrast.value)));
|
||||
GL_Uniform1iFunc (textureLoc, 0); // use texture unit 0
|
||||
|
||||
glDisable (GL_ALPHA_TEST);
|
||||
glDisable (GL_DEPTH_TEST);
|
||||
|
||||
glViewport (0, 0, vid.unscaled_width, vid.unscaled_height);
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glLoadIdentity ();
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glLoadIdentity ();
|
||||
glViewport (glx, gly, glwidth, glheight);
|
||||
|
||||
smax = glwidth/(float)r_postprocess_texture_width;
|
||||
tmax = glheight/(float)r_postprocess_texture_height;
|
||||
smax = glwidth/(float)r_gamma_texture_width;
|
||||
tmax = glheight/(float)r_gamma_texture_height;
|
||||
|
||||
glBegin (GL_QUADS);
|
||||
glTexCoord2f (0, 0);
|
||||
|
@ -265,11 +253,9 @@ void R_Postprocess (void)
|
|||
glVertex2f (-1, 1);
|
||||
glEnd ();
|
||||
|
||||
// unbind program if we enabled it
|
||||
if (wants_gamma)
|
||||
GL_UseProgramFunc (0);
|
||||
GL_UseProgramFunc (0);
|
||||
|
||||
// clear cached texture binding
|
||||
// clear cached binding
|
||||
GL_ClearBindings ();
|
||||
}
|
||||
|
||||
|
|
|
@ -784,17 +784,17 @@ void SCR_ScreenShot_f (void)
|
|||
}
|
||||
|
||||
//get data
|
||||
if (!(buffer = (byte *) malloc(vid.unscaled_width*vid.unscaled_height*3)))
|
||||
if (!(buffer = (byte *) malloc(glwidth*glheight*3)))
|
||||
{
|
||||
Con_Printf ("SCR_ScreenShot_f: Couldn't allocate memory\n");
|
||||
return;
|
||||
}
|
||||
|
||||
glPixelStorei (GL_PACK_ALIGNMENT, 1);/* for widths that aren't a multiple of 4 */
|
||||
glReadPixels (0, 0, vid.unscaled_width, vid.unscaled_height, GL_RGB, GL_UNSIGNED_BYTE, buffer);
|
||||
glReadPixels (glx, gly, glwidth, glheight, GL_RGB, GL_UNSIGNED_BYTE, buffer);
|
||||
|
||||
// now write the file
|
||||
if (Image_WriteTGA (tganame, buffer, vid.unscaled_width, vid.unscaled_height, 24, false))
|
||||
if (Image_WriteTGA (tganame, buffer, glwidth, glheight, 24, false))
|
||||
Con_Printf ("Wrote %s\n", tganame);
|
||||
else
|
||||
Con_Printf ("SCR_ScreenShot_f: Couldn't create a TGA file\n");
|
||||
|
@ -1080,7 +1080,7 @@ void SCR_UpdateScreen (void)
|
|||
|
||||
V_UpdateBlend (); //johnfitz -- V_UpdatePalette cleaned up and renamed
|
||||
|
||||
R_Postprocess ();
|
||||
GLSLGamma_GammaCorrect ();
|
||||
|
||||
GL_EndRendering ();
|
||||
}
|
||||
|
|
|
@ -563,9 +563,9 @@ void TexMgr_RecalcWarpImageSize (void)
|
|||
|
||||
gl_warpimagesize = TexMgr_SafeTextureSize (512);
|
||||
|
||||
while (gl_warpimagesize > vid.unscaled_width)
|
||||
while (gl_warpimagesize > vid.width)
|
||||
gl_warpimagesize >>= 1;
|
||||
while (gl_warpimagesize > vid.unscaled_height)
|
||||
while (gl_warpimagesize > vid.height)
|
||||
gl_warpimagesize >>= 1;
|
||||
|
||||
// ericw -- removed early exit if (gl_warpimagesize == oldsize).
|
||||
|
|
|
@ -154,7 +154,6 @@ static cvar_t vid_borderless = {"vid_borderless", "0", CVAR_ARCHIVE}; // QuakeSp
|
|||
|
||||
cvar_t vid_gamma = {"gamma", "1", CVAR_ARCHIVE}; //johnfitz -- moved here from view.c
|
||||
cvar_t vid_contrast = {"contrast", "1", CVAR_ARCHIVE}; //QuakeSpasm, MarkV
|
||||
cvar_t vid_scale = {"vid_scale", "1", CVAR_ARCHIVE}; // QuakeSpasm
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
|
@ -351,31 +350,6 @@ static int VID_GetCurrentHeight (void)
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
=======================
|
||||
VID_CalcRenderSize
|
||||
|
||||
returns the size that we will render to, possilby smaller than the actual
|
||||
framebuffer size if the vid_scale cvar is in use.
|
||||
=======================
|
||||
*/
|
||||
static void VID_GetRenderSize (int *w, int *h)
|
||||
{
|
||||
float scale_factor;
|
||||
|
||||
#if defined(USE_SDL2)
|
||||
SDL_GetWindowSize(draw_context, w, h);
|
||||
#else
|
||||
*w = draw_context->w;
|
||||
*h = draw_context->h;
|
||||
#endif
|
||||
|
||||
scale_factor = 1.0f / CLAMP(1, (int)vid_scale.value, 4);
|
||||
|
||||
*w *= scale_factor;
|
||||
*h *= scale_factor;
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
VID_GetCurrentBPP
|
||||
|
@ -693,9 +667,8 @@ static qboolean VID_SetMode (int width, int height, int bpp, qboolean fullscreen
|
|||
SDL_WM_SetCaption(caption, caption);
|
||||
#endif /* !defined(USE_SDL2) */
|
||||
|
||||
VID_GetRenderSize(&vid.width, &vid.height);
|
||||
vid.unscaled_width = VID_GetCurrentWidth();
|
||||
vid.unscaled_height = VID_GetCurrentHeight();
|
||||
vid.width = VID_GetCurrentWidth();
|
||||
vid.height = VID_GetCurrentHeight();
|
||||
vid.conwidth = vid.width & 0xFFFFFFF8;
|
||||
vid.conheight = vid.conwidth * vid.height / vid.width;
|
||||
vid.numpages = 2;
|
||||
|
@ -1536,8 +1509,7 @@ void VID_Init (void)
|
|||
"vid_vsync",
|
||||
"vid_fsaa",
|
||||
"vid_desktopfullscreen",
|
||||
"vid_borderless",
|
||||
"vid_scale"};
|
||||
"vid_borderless"};
|
||||
#define num_readvars ( sizeof(read_vars)/sizeof(read_vars[0]) )
|
||||
|
||||
Cvar_RegisterVariable (&vid_fullscreen); //johnfitz
|
||||
|
@ -1548,7 +1520,6 @@ void VID_Init (void)
|
|||
Cvar_RegisterVariable (&vid_fsaa); //QuakeSpasm
|
||||
Cvar_RegisterVariable (&vid_desktopfullscreen); //QuakeSpasm
|
||||
Cvar_RegisterVariable (&vid_borderless); //QuakeSpasm
|
||||
Cvar_RegisterVariable (&vid_scale); //QuakeSpasm
|
||||
Cvar_SetCallback (&vid_fullscreen, VID_Changed_f);
|
||||
Cvar_SetCallback (&vid_width, VID_Changed_f);
|
||||
Cvar_SetCallback (&vid_height, VID_Changed_f);
|
||||
|
@ -1557,7 +1528,6 @@ void VID_Init (void)
|
|||
Cvar_SetCallback (&vid_fsaa, VID_FSAA_f);
|
||||
Cvar_SetCallback (&vid_desktopfullscreen, VID_Changed_f);
|
||||
Cvar_SetCallback (&vid_borderless, VID_Changed_f);
|
||||
Cvar_SetCallback (&vid_scale, VID_Changed_f);
|
||||
|
||||
Cmd_AddCommand ("vid_unlock", VID_Unlock); //johnfitz
|
||||
Cmd_AddCommand ("vid_restart", VID_Restart); //johnfitz
|
||||
|
|
|
@ -255,7 +255,7 @@ void R_UpdateWarpTextures (void)
|
|||
|
||||
//copy to texture
|
||||
GL_Bind (tx->warpimage);
|
||||
glCopyTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 0, vid.unscaled_height-gl_warpimagesize, gl_warpimagesize, gl_warpimagesize);
|
||||
glCopyTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, glx, gly+glheight-gl_warpimagesize, gl_warpimagesize, gl_warpimagesize);
|
||||
|
||||
tx->update_warp = false;
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ void R_UpdateWarpTextures (void)
|
|||
GL_SetCanvas(CANVAS_DEFAULT);
|
||||
|
||||
//if warp render went down into sbar territory, we need to be sure to refresh it next frame
|
||||
if (gl_warpimagesize + sb_lines > vid.unscaled_height)
|
||||
if (gl_warpimagesize + sb_lines > glheight)
|
||||
Sbar_Changed ();
|
||||
|
||||
//if viewsize is less than 100, we need to redraw the frame around the viewport
|
||||
|
|
|
@ -393,7 +393,7 @@ void GL_BindBuffer (GLenum target, GLuint buffer);
|
|||
void GL_ClearBufferBindings ();
|
||||
|
||||
void GLSLGamma_DeleteTexture (void);
|
||||
void R_Postprocess (void);
|
||||
void GLSLGamma_GammaCorrect (void);
|
||||
|
||||
float GL_WaterAlphaForSurface (msurface_t *fa);
|
||||
|
||||
|
|
|
@ -54,8 +54,6 @@ typedef struct
|
|||
int rowbytes; // may be > width if displayed in a window
|
||||
int width;
|
||||
int height;
|
||||
int unscaled_width;
|
||||
int unscaled_height;
|
||||
float aspect; // width / height -- < 0 is taller than wide
|
||||
int numpages;
|
||||
int recalc_refdef; // if true, recalc vid-based stuff
|
||||
|
|
Loading…
Reference in a new issue