mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-10 07:12:07 +00:00
Apply the same cleanup to gl1_sdl.c as to gl3_sdl.c
* Sync both files as much as possible. * Another round of general cleanup. * Fix stencil tests. * Simplify gamma handling, hardware gamma is now default. * Support new client <-> renderer API.
This commit is contained in:
parent
b8a062e36b
commit
9a53a681bb
5 changed files with 112 additions and 129 deletions
|
@ -1299,8 +1299,6 @@ void
|
|||
R_InitImages(void)
|
||||
{
|
||||
int i, j;
|
||||
// use 1/gamma so higher value is brighter, to match HW gamma settings
|
||||
float g = 1.0f/vid_gamma->value;
|
||||
|
||||
registration_sequence = 1;
|
||||
|
||||
|
@ -1328,28 +1326,7 @@ R_InitImages(void)
|
|||
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
if ((g == 1) || gl_state.hwgamma)
|
||||
{
|
||||
gammatable[i] = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
float inf;
|
||||
|
||||
inf = 255 * pow((i + 0.5) / 255.5, g) + 0.5;
|
||||
|
||||
if (inf < 0)
|
||||
{
|
||||
inf = 0;
|
||||
}
|
||||
|
||||
if (inf > 255)
|
||||
{
|
||||
inf = 255;
|
||||
}
|
||||
|
||||
gammatable[i] = inf;
|
||||
}
|
||||
gammatable[i] = i;
|
||||
}
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
|
|
|
@ -66,7 +66,6 @@ float r_base_world_matrix[16];
|
|||
refdef_t r_newrefdef;
|
||||
|
||||
int r_viewcluster, r_viewcluster2, r_oldviewcluster, r_oldviewcluster2;
|
||||
extern qboolean have_stencil;
|
||||
unsigned r_rawpalette[256];
|
||||
|
||||
cvar_t *r_norefresh;
|
||||
|
@ -898,7 +897,7 @@ R_Clear(void)
|
|||
}
|
||||
|
||||
/* stencilbuffer shadows */
|
||||
if (gl_shadows->value && have_stencil && gl1_stencilshadow->value)
|
||||
if (gl_shadows->value && gl_state.stencil && gl1_stencilshadow->value)
|
||||
{
|
||||
glClearStencil(1);
|
||||
glClear(GL_STENCIL_BUFFER_BIT);
|
||||
|
@ -1459,8 +1458,8 @@ RI_Init()
|
|||
|
||||
if (strstr(gl_config.extensions_string, "GL_ARB_point_parameters"))
|
||||
{
|
||||
qglPointParameterfARB = (void (APIENTRY *)(GLenum, GLfloat))GLimp_GetProcAddress ( "glPointParameterfARB" );
|
||||
qglPointParameterfvARB = (void (APIENTRY *)(GLenum, const GLfloat *))GLimp_GetProcAddress ( "glPointParameterfvARB" );
|
||||
qglPointParameterfARB = (void (APIENTRY *)(GLenum, GLfloat))RI_GetProcAddress ( "glPointParameterfARB" );
|
||||
qglPointParameterfvARB = (void (APIENTRY *)(GLenum, const GLfloat *))RI_GetProcAddress ( "glPointParameterfvARB" );
|
||||
}
|
||||
|
||||
gl_config.pointparameters = false;
|
||||
|
@ -1491,7 +1490,7 @@ RI_Init()
|
|||
strstr(gl_config.extensions_string, "GL_EXT_shared_texture_palette"))
|
||||
{
|
||||
qglColorTableEXT = (void (APIENTRY *)(GLenum, GLenum, GLsizei, GLenum, GLenum, const GLvoid * ))
|
||||
GLimp_GetProcAddress ("glColorTableEXT");
|
||||
RI_GetProcAddress ("glColorTableEXT");
|
||||
}
|
||||
|
||||
gl_config.palettedtexture = false;
|
||||
|
@ -1574,15 +1573,12 @@ RI_Shutdown(void)
|
|||
R_ShutdownImages();
|
||||
|
||||
/* shutdown OS specific OpenGL stuff like contexts, etc. */
|
||||
RI_ShutdownWindow(false);
|
||||
RI_ShutdownContext();
|
||||
|
||||
/* shutdown our QGL subsystem */
|
||||
QGL_Shutdown();
|
||||
}
|
||||
|
||||
extern void UpdateHardwareGamma();
|
||||
extern void RI_SetSwapInterval(void);
|
||||
|
||||
void
|
||||
RI_BeginFrame(float camera_separation)
|
||||
{
|
||||
|
@ -1612,11 +1608,7 @@ RI_BeginFrame(float camera_separation)
|
|||
if (vid_gamma->modified)
|
||||
{
|
||||
vid_gamma->modified = false;
|
||||
|
||||
if (gl_state.hwgamma)
|
||||
{
|
||||
UpdateHardwareGamma();
|
||||
}
|
||||
RI_UpdateGamma();
|
||||
}
|
||||
|
||||
// Clamp overbrightbits
|
||||
|
@ -1711,7 +1703,7 @@ RI_BeginFrame(float camera_separation)
|
|||
if (r_vsync->modified)
|
||||
{
|
||||
r_vsync->modified = false;
|
||||
RI_SetSwapInterval();
|
||||
RI_SetVsync();
|
||||
}
|
||||
|
||||
/* clear screen if desired */
|
||||
|
@ -1882,7 +1874,7 @@ GetRefAPI(refimport_t imp)
|
|||
re.Shutdown = RI_Shutdown;
|
||||
re.PrepareForWindow = RI_PrepareForWindow;
|
||||
re.InitContext = RI_InitContext;
|
||||
re.ShutdownContext = RI_ShutdownWindow;
|
||||
re.ShutdownContext = RI_ShutdownContext;
|
||||
re.IsVSyncActive = RI_IsVSyncActive;
|
||||
re.BeginRegistration = RI_BeginRegistration;
|
||||
re.RegisterModel = RI_RegisterModel;
|
||||
|
|
|
@ -44,7 +44,6 @@ vec3_t shadevector;
|
|||
float shadelight[3];
|
||||
float *shadedots = r_avertexnormal_dots[0];
|
||||
extern vec3_t lightspot;
|
||||
extern qboolean have_stencil;
|
||||
|
||||
void
|
||||
R_LerpVerts(int nverts, dtrivertx_t *v, dtrivertx_t *ov,
|
||||
|
@ -266,7 +265,7 @@ R_DrawAliasShadow(dmdl_t *paliashdr, int posenum)
|
|||
height = -lheight + 0.1f;
|
||||
|
||||
/* stencilbuffer shadows */
|
||||
if (have_stencil && gl1_stencilshadow->value)
|
||||
if (gl_state.stencil && gl1_stencilshadow->value)
|
||||
{
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glStencilFunc(GL_EQUAL, 1, 2);
|
||||
|
@ -324,7 +323,7 @@ R_DrawAliasShadow(dmdl_t *paliashdr, int posenum)
|
|||
}
|
||||
|
||||
/* stencilbuffer shadows */
|
||||
if (have_stencil && gl1_stencilshadow->value)
|
||||
if (gl_state.stencil && gl1_stencilshadow->value)
|
||||
{
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
}
|
||||
|
|
|
@ -20,13 +20,12 @@
|
|||
*
|
||||
* =======================================================================
|
||||
*
|
||||
* SDL-specific OpenGL shit formerly in refresh.c
|
||||
* SDL backend for the GL1 renderer.
|
||||
*
|
||||
* =======================================================================
|
||||
*/
|
||||
|
||||
#include "header/local.h"
|
||||
#include "../../header/ref.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
|
@ -36,55 +35,63 @@
|
|||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
||||
static qboolean vsyncActive = false;
|
||||
static SDL_Window* window = NULL;
|
||||
static SDL_GLContext context = NULL;
|
||||
static qboolean vsyncActive = false;
|
||||
|
||||
qboolean have_stencil = false;
|
||||
// ----
|
||||
|
||||
/*
|
||||
* Swaps the buffers and shows the next frame.
|
||||
*/
|
||||
void
|
||||
RI_EndFrame(void)
|
||||
{
|
||||
SDL_GL_SwapWindow(window);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the adress of a GL function
|
||||
*/
|
||||
void *
|
||||
GLimp_GetProcAddress (const char* proc)
|
||||
RI_GetProcAddress(const char* proc)
|
||||
{
|
||||
return SDL_GL_GetProcAddress ( proc );
|
||||
return SDL_GL_GetProcAddress(proc);
|
||||
}
|
||||
|
||||
void
|
||||
UpdateHardwareGamma(void)
|
||||
/*
|
||||
* Returns whether the vsync is enabled.
|
||||
*/
|
||||
qboolean RI_IsVSyncActive(void)
|
||||
{
|
||||
float gamma = (vid_gamma->value);
|
||||
|
||||
Uint16 ramp[256];
|
||||
SDL_CalculateGammaRamp(gamma, ramp);
|
||||
|
||||
if(SDL_SetWindowGammaRamp(window, ramp, ramp, ramp) != 0)
|
||||
{
|
||||
R_Printf(PRINT_ALL, "Setting gamma failed: %s\n", SDL_GetError());
|
||||
}
|
||||
return vsyncActive;
|
||||
}
|
||||
|
||||
static void InitGamma()
|
||||
{
|
||||
R_Printf(PRINT_ALL, "Using hardware gamma via SDL.\n");
|
||||
|
||||
gl_state.hwgamma = true;
|
||||
vid_gamma->modified = true;
|
||||
}
|
||||
|
||||
// called by GLimp_InitGraphics() before creating window,
|
||||
// returns flags for SDL window creation
|
||||
/*
|
||||
* This function returns the flags used at the SDL window
|
||||
* creation by GLimp_InitGraphics(). In case of error -1
|
||||
* is returned.
|
||||
*/
|
||||
int RI_PrepareForWindow(void)
|
||||
{
|
||||
int msaa_samples = 0;
|
||||
|
||||
// Set GL context attributs bound to the window.
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
||||
|
||||
if (SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8) < 0)
|
||||
{
|
||||
gl_state.stencil = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
gl_state.stencil = false;
|
||||
}
|
||||
|
||||
// Let's see if the driver supports MSAA.
|
||||
int msaa_samples = 0;
|
||||
|
||||
if (gl_msaa_samples->value)
|
||||
{
|
||||
|
@ -115,23 +122,43 @@ int RI_PrepareForWindow(void)
|
|||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
|
||||
}
|
||||
|
||||
/* Initiate the flags */
|
||||
return SDL_WINDOW_OPENGL;
|
||||
}
|
||||
|
||||
void RI_SetSwapInterval(void)
|
||||
|
||||
/*
|
||||
* Enables or disabes the vsync.
|
||||
*/
|
||||
void RI_SetVsync(void)
|
||||
{
|
||||
/* Set vsync - TODO: -1 could be set for "late swap tearing" */
|
||||
SDL_GL_SetSwapInterval(r_vsync->value ? 1 : 0);
|
||||
vsyncActive = SDL_GL_GetSwapInterval() != 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Updates the gamma ramp.
|
||||
*/
|
||||
void
|
||||
RI_UpdateGamma(void)
|
||||
{
|
||||
float gamma = (vid_gamma->value);
|
||||
|
||||
Uint16 ramp[256];
|
||||
SDL_CalculateGammaRamp(gamma, ramp);
|
||||
|
||||
if (SDL_SetWindowGammaRamp(window, ramp, ramp, ramp) != 0)
|
||||
{
|
||||
R_Printf(PRINT_ALL, "Setting gamma failed: %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Initializes the OpenGL context. Returns true at
|
||||
* success and false at failure.
|
||||
*/
|
||||
int RI_InitContext(void* win)
|
||||
{
|
||||
int msaa_samples = 0, stencil_bits = 0;
|
||||
char title[40] = {0};
|
||||
|
||||
if(win == NULL)
|
||||
// Coders are stupid.
|
||||
if (win == NULL)
|
||||
{
|
||||
ri.Sys_Error(ERR_FATAL, "R_InitContext() must not be called with NULL argument!");
|
||||
|
||||
|
@ -140,9 +167,10 @@ int RI_InitContext(void* win)
|
|||
|
||||
window = (SDL_Window*)win;
|
||||
|
||||
// Initialize GL context.
|
||||
context = SDL_GL_CreateContext(window);
|
||||
|
||||
if(context == NULL)
|
||||
if (context == NULL)
|
||||
{
|
||||
R_Printf(PRINT_ALL, "R_InitContext(): Creating OpenGL Context failed: %s\n", SDL_GetError());
|
||||
|
||||
|
@ -151,6 +179,7 @@ int RI_InitContext(void* win)
|
|||
return false;
|
||||
}
|
||||
|
||||
// Check if it's really OpenGL 1.4.
|
||||
const char* glver = (char *)glGetString(GL_VERSION);
|
||||
sscanf(glver, "%d.%d", &gl_config.major_version, &gl_config.minor_version);
|
||||
|
||||
|
@ -161,6 +190,9 @@ int RI_InitContext(void* win)
|
|||
return false;
|
||||
}
|
||||
|
||||
// Check if we've got the requested MSAA.
|
||||
int msaa_samples = 0;
|
||||
|
||||
if (gl_msaa_samples->value)
|
||||
{
|
||||
if (SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &msaa_samples) == 0)
|
||||
|
@ -169,49 +201,37 @@ int RI_InitContext(void* win)
|
|||
}
|
||||
}
|
||||
|
||||
/* For SDL2, this must be done after creating the window */
|
||||
RI_SetSwapInterval();
|
||||
// Enable vsync if requested.
|
||||
RI_SetVsync();
|
||||
|
||||
/* Initialize the stencil buffer */
|
||||
if (!SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencil_bits))
|
||||
// Check if we've got 8 stencil bits.
|
||||
int stencil_bits = 0;
|
||||
|
||||
if (gl_state.stencil)
|
||||
{
|
||||
R_Printf(PRINT_ALL, "Got %d bits of stencil.\n", stencil_bits);
|
||||
|
||||
if (stencil_bits >= 1)
|
||||
if (SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencil_bits) != 8)
|
||||
{
|
||||
have_stencil = true;
|
||||
gl_state.stencil = false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize hardware gamma */
|
||||
InitGamma();
|
||||
// Initialize gamma.
|
||||
vid_gamma->modified = true;
|
||||
|
||||
/* Window title - set here so we can display renderer name in it */
|
||||
snprintf(title, sizeof(title), "Yamagi Quake II %s - OpenGL 1.x", YQ2VERSION);
|
||||
// Window title - set here so we can display renderer name in it.
|
||||
char title[40] = {0};
|
||||
|
||||
snprintf(title, sizeof(title), "Yamagi Quake II %s - OpenGL 1.4", YQ2VERSION);
|
||||
SDL_SetWindowTitle(window, title);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
qboolean RI_IsVSyncActive(void)
|
||||
{
|
||||
return vsyncActive;
|
||||
}
|
||||
|
||||
/*
|
||||
* Swaps the buffers to show the new frame
|
||||
* Shuts the GL context down.
|
||||
*/
|
||||
void
|
||||
RI_EndFrame(void)
|
||||
{
|
||||
SDL_GL_SwapWindow(window);
|
||||
}
|
||||
|
||||
/*
|
||||
* Shuts the SDL render backend down
|
||||
*/
|
||||
void
|
||||
RI_ShutdownWindow(qboolean contextOnly)
|
||||
RI_ShutdownContext(void)
|
||||
{
|
||||
if (window)
|
||||
{
|
||||
|
@ -220,15 +240,5 @@ RI_ShutdownWindow(qboolean contextOnly)
|
|||
SDL_GL_DeleteContext(context);
|
||||
context = NULL;
|
||||
}
|
||||
|
||||
if (!contextOnly)
|
||||
{
|
||||
// FIXME
|
||||
//ri.GLimp_ShutdownGraphics();
|
||||
|
||||
window = NULL;
|
||||
gl_state.hwgamma = false;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -351,11 +351,7 @@ typedef struct
|
|||
float camera_separation;
|
||||
enum stereo_modes stereo_mode;
|
||||
|
||||
qboolean hwgamma;
|
||||
|
||||
unsigned char originalRedGammaTable[256];
|
||||
unsigned char originalGreenGammaTable[256];
|
||||
unsigned char originalBlueGammaTable[256];
|
||||
qboolean stencil;
|
||||
} glstate_t;
|
||||
|
||||
typedef struct
|
||||
|
@ -376,15 +372,24 @@ extern glconfig_t gl_config;
|
|||
extern glstate_t gl_state;
|
||||
|
||||
/*
|
||||
* Shuts the render context and SDL window down
|
||||
* (if contextOnly, the window will not be shutdown)
|
||||
* Updates the gamma ramp.
|
||||
*/
|
||||
void RI_ShutdownWindow(qboolean contextOnly);
|
||||
void RI_UpdateGamma(void);
|
||||
|
||||
/*
|
||||
* Enables or disabes the vsync.
|
||||
*/
|
||||
void RI_SetVsync(void);
|
||||
|
||||
/*
|
||||
* Shuts the GL context down.
|
||||
*/
|
||||
void RI_ShutdownContext(void);
|
||||
|
||||
/*
|
||||
* Returns the address of the GL function proc,
|
||||
* or NULL if the function is not found.
|
||||
*/
|
||||
void *GLimp_GetProcAddress (const char* proc);
|
||||
void *RI_GetProcAddress (const char* proc);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue