scaling v2

This commit is contained in:
Eric Wasylishen 2017-05-24 12:35:17 -06:00
parent 371ff81fc3
commit 80e1c797c1
4 changed files with 119 additions and 4 deletions

View file

@ -112,6 +112,8 @@ float map_wateralpha, map_lavaalpha, map_telealpha, map_slimealpha;
qboolean r_drawflat_cheatsafe, r_fullbright_cheatsafe, r_lightmap_cheatsafe, r_drawworld_cheatsafe; //johnfitz qboolean r_drawflat_cheatsafe, r_fullbright_cheatsafe, r_lightmap_cheatsafe, r_drawworld_cheatsafe; //johnfitz
extern cvar_t scr_vidscale;
//============================================================================== //==============================================================================
// //
// GLSL GAMMA CORRECTION // GLSL GAMMA CORRECTION
@ -472,13 +474,15 @@ R_SetupGL
*/ */
void R_SetupGL (void) void R_SetupGL (void)
{ {
int vidscale = CLAMP(1, (int)scr_vidscale.value, 4);
//johnfitz -- rewrote this section //johnfitz -- rewrote this section
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity (); glLoadIdentity ();
glViewport (glx + r_refdef.vrect.x, glViewport (glx + r_refdef.vrect.x,
gly + glheight - r_refdef.vrect.y - r_refdef.vrect.height, gly + glheight - r_refdef.vrect.y - r_refdef.vrect.height,
r_refdef.vrect.width, r_refdef.vrect.width / vidscale,
r_refdef.vrect.height); r_refdef.vrect.height / vidscale);
//johnfitz //johnfitz
GL_SetFrustum (r_fovx, r_fovy); //johnfitz -- use r_fov* vars GL_SetFrustum (r_fovx, r_fovy); //johnfitz -- use r_fov* vars
@ -936,6 +940,106 @@ void R_RenderScene (void)
R_ShowBoundingBoxes (); //johnfitz R_ShowBoundingBoxes (); //johnfitz
} }
static GLuint r_scaleview_texture;
static int r_scaleview_texture_width, r_scaleview_texture_height;
/*
=============
R_ScaleView_DeleteTexture
=============
*/
void R_ScaleView_DeleteTexture (void)
{
glDeleteTextures (1, &r_scaleview_texture);
r_scaleview_texture = 0;
}
/*
================
R_ScaleView
================
*/
void R_ScaleView (void)
{
float smax, tmax;
int vidscale;
int srcx, srcy, srcw, srch;
if (scr_vidscale.value == 1)
return;
// copied from R_SetupGL()
vidscale = CLAMP(1, (int)scr_vidscale.value, 4);
srcx = glx + r_refdef.vrect.x;
srcy = gly + glheight - r_refdef.vrect.y - r_refdef.vrect.height;
srcw = r_refdef.vrect.width / vidscale;
srch = r_refdef.vrect.height / vidscale;
// create render-to-texture texture if needed
if (!r_scaleview_texture)
{
glGenTextures (1, &r_scaleview_texture);
glBindTexture (GL_TEXTURE_2D, r_scaleview_texture);
r_scaleview_texture_width = 0;
r_scaleview_texture_height = 0;
}
// resize render-to-texture texture if needed
if (r_scaleview_texture_width < srcw
|| r_scaleview_texture_height < srch)
{
r_scaleview_texture_width = srcw;
r_scaleview_texture_height = srch;
if (!gl_texture_NPOT)
{
r_scaleview_texture_width = TexMgr_Pad(r_scaleview_texture_width);
r_scaleview_texture_height = TexMgr_Pad(r_scaleview_texture_height);
}
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, r_scaleview_texture_width, r_scaleview_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
// copy the framebuffer to the texture
GL_DisableMultitexture();
glBindTexture (GL_TEXTURE_2D, r_scaleview_texture);
glCopyTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, srcx, srcy, srcw, srch);
// draw the texture back to the framebuffer
glDisable (GL_ALPHA_TEST);
glDisable (GL_DEPTH_TEST);
glDisable (GL_CULL_FACE);
glDisable (GL_BLEND);
glViewport (srcx, srcy, r_refdef.vrect.width, r_refdef.vrect.height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity ();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity ();
// correction factor if we lack NPOT textures, normally these are 1.0f
smax = srcw/(float)r_scaleview_texture_width;
tmax = srch/(float)r_scaleview_texture_height;
glBegin (GL_QUADS);
glTexCoord2f (0, 0);
glVertex2f (-1, -1);
glTexCoord2f (smax, 0);
glVertex2f (1, -1);
glTexCoord2f (smax, tmax);
glVertex2f (1, 1);
glTexCoord2f (0, tmax);
glVertex2f (-1, 1);
glEnd ();
// clear cached binding
GL_ClearBindings ();
}
/* /*
================ ================
R_RenderView R_RenderView
@ -1002,6 +1106,8 @@ void R_RenderView (void)
} }
//johnfitz //johnfitz
R_ScaleView ();
//johnfitz -- modified r_speeds output //johnfitz -- modified r_speeds output
time2 = Sys_DoubleTime (); time2 = Sys_DoubleTime ();
if (r_pos.value) if (r_pos.value)

View file

@ -88,6 +88,10 @@ cvar_t scr_showfps = {"scr_showfps", "0", CVAR_NONE};
cvar_t scr_clock = {"scr_clock", "0", CVAR_NONE}; cvar_t scr_clock = {"scr_clock", "0", CVAR_NONE};
//johnfitz //johnfitz
//ericw -- scaling
cvar_t scr_vidscale = {"scr_vidscale", "1", CVAR_ARCHIVE};
//ericw
cvar_t scr_viewsize = {"viewsize","100", CVAR_ARCHIVE}; cvar_t scr_viewsize = {"viewsize","100", CVAR_ARCHIVE};
cvar_t scr_fov = {"fov","90",CVAR_NONE}; // 10 - 170 cvar_t scr_fov = {"fov","90",CVAR_NONE}; // 10 - 170
cvar_t scr_fov_adapt = {"fov_adapt","1",CVAR_ARCHIVE}; cvar_t scr_fov_adapt = {"fov_adapt","1",CVAR_ARCHIVE};
@ -421,6 +425,8 @@ void SCR_Init (void)
Cvar_RegisterVariable (&scr_centertime); Cvar_RegisterVariable (&scr_centertime);
Cvar_RegisterVariable (&scr_printspeed); Cvar_RegisterVariable (&scr_printspeed);
Cvar_RegisterVariable (&gl_triplebuffer); Cvar_RegisterVariable (&gl_triplebuffer);
Cvar_RegisterVariable (&scr_vidscale);
Cvar_SetCallback (&scr_vidscale, SCR_Callback_refdef);
Cmd_AddCommand ("screenshot",SCR_ScreenShot_f); Cmd_AddCommand ("screenshot",SCR_ScreenShot_f);
Cmd_AddCommand ("sizeup",SCR_SizeUp_f); Cmd_AddCommand ("sizeup",SCR_SizeUp_f);

View file

@ -756,6 +756,7 @@ static void VID_Restart (void)
TexMgr_DeleteTextureObjects (); TexMgr_DeleteTextureObjects ();
GLSLGamma_DeleteTexture (); GLSLGamma_DeleteTexture ();
R_ScaleView_DeleteTexture ();
R_DeleteShaders (); R_DeleteShaders ();
GL_DeleteBModelVertexBuffer (); GL_DeleteBModelVertexBuffer ();
GLMesh_DeleteVertexBuffers (); GLMesh_DeleteVertexBuffers ();

View file

@ -395,6 +395,8 @@ void GL_ClearBufferBindings ();
void GLSLGamma_DeleteTexture (void); void GLSLGamma_DeleteTexture (void);
void GLSLGamma_GammaCorrect (void); void GLSLGamma_GammaCorrect (void);
void R_ScaleView_DeleteTexture (void);
float GL_WaterAlphaForSurface (msurface_t *fa); float GL_WaterAlphaForSurface (msurface_t *fa);
#endif /* __GLQUAKE_H */ #endif /* __GLQUAKE_H */