Merge remote-tracking branch 'yquake2/master'

This commit is contained in:
Denis Pauk 2024-10-06 22:35:23 +03:00
commit 8c233f78c3
12 changed files with 286 additions and 186 deletions

View file

@ -532,7 +532,8 @@ it's `+set busywait 0` (setting the `busywait` cvar) and `-portable`
squares.
* **gl1_stencilshadow**: If `gl_shadows` is set to `1`, this makes them
look a bit better (no flickering) by using the stencil buffer.
look a bit better (no flickering) by using the stencil buffer. Does
not work when `gl1_stereo` is `3`, `4` or `5`.
* **gl1_lightmapcopies**: When enabled (`1`), keep 3 copies of the same
lightmap rotating, shifting to another one when drawing a new frame.
@ -540,9 +541,10 @@ it's `+set busywait 0` (setting the `busywait` cvar) and `-portable`
(dynamic lighting) causes slowdown. By default in GL1 is disabled,
while in GLES1 is enabled. Needs `gl1_multitexture 1` & `vid_restart`.
* **gl1_discardfb**: Only available in ES1. If set to `1` (default),
send a hint to discard framebuffers after finishing a frame. Useful
for GPUs that attempt to reuse them, something Quake 2 doesn't do.
* **gl1_discardfb**: If `1`, clear color, depth and stencil buffers at
the start of a frame, and discard them at the end if possible. If
`2`, do only depth and stencil, no color. Increases performance in
mobile / embedded. Default in GL1 is `0`, while in GLES1 is `1`.
## Graphics (OpenGL 3.2 and OpenGL ES3 only)

View file

@ -594,7 +594,7 @@ IN_Update(void)
/* workaround for AZERTY-keyboards, which don't have 1, 2, ..., 9, 0 in first row:
* always map those physical keys (scancodes) to those keycodes anyway
* see also https://bugzilla.libsdl.org/show_bug.cgi?id=3188 */
SDL_Scancode sc = event.key.keysym.scancode;
SDL_Scancode sc = event.key.scancode;
if (sc >= SDL_SCANCODE_1 && sc <= SDL_SCANCODE_0)
{
@ -612,14 +612,14 @@ IN_Update(void)
}
else
{
SDL_Keycode kc = event.key.keysym.sym;
SDL_Keycode kc = event.key.key;
if(sc == SDL_SCANCODE_GRAVE && kc != '\'' && kc != '"')
{
// special case/hack: open the console with the "console key"
// (beneath Esc, left of 1, above Tab)
// but not if the keycode for this is a quote (like on Brazilian
// keyboards) - otherwise you couldn't type them in the console
if((event.key.keysym.mod & (SDL_KMOD_CAPS|SDL_KMOD_SHIFT|SDL_KMOD_ALT|SDL_KMOD_CTRL|SDL_KMOD_GUI)) == 0)
if((event.key.mod & (SDL_KMOD_CAPS|SDL_KMOD_SHIFT|SDL_KMOD_ALT|SDL_KMOD_CTRL|SDL_KMOD_GUI)) == 0)
{
// also, only do this if no modifiers like shift or AltGr or whatever are pressed
// so kc will most likely be the ascii char generated by this and can be ignored
@ -797,7 +797,7 @@ IN_Update(void)
#else // gyro read as "secondary joystick"
case SDL_EVENT_JOYSTICK_AXIS_MOTION :
if ( !imu_joystick || event.gdevice.which != SDL_GetJoystickInstanceID(imu_joystick) )
if ( !imu_joystick || event.gdevice.which != SDL_GetJoystickID(imu_joystick) )
{
break; // controller axes handled by SDL_CONTROLLERAXISMOTION
}
@ -881,7 +881,7 @@ IN_Update(void)
break;
case SDL_EVENT_JOYSTICK_BATTERY_UPDATED :
if (!controller || event.jbattery.which != SDL_GetJoystickInstanceID(SDL_GetGamepadJoystick(controller)))
if (!controller || event.jbattery.which != SDL_GetJoystickID(SDL_GetGamepadJoystick(controller)))
{
break;
}
@ -2006,7 +2006,7 @@ Controller_Rumble(const char *name, vec3_t source, qboolean from_player,
// Com_Printf("%-29s: vol %5u - %4u ms - dp %.3f l %5.0f h %5.0f\n",
// name, effect_volume, duration, dist_prop, low_freq, hi_freq);
if (SDL_RumbleGamepad(controller, low_freq, hi_freq, duration) == -1)
if (!SDL_RumbleGamepad(controller, low_freq, hi_freq, duration))
{
if (!joystick_haptic)
{
@ -2053,7 +2053,7 @@ IN_Controller_Init(qboolean notify_user)
int nummappings;
char controllerdb[MAX_OSPATH] = {0};
SDL_Joystick *joystick = NULL;
SDL_bool is_controller = SDL_FALSE;
bool is_controller = false;
cvar = Cvar_Get("in_sdlbackbutton", "1", CVAR_ARCHIVE);
if (cvar)
@ -2092,7 +2092,7 @@ IN_Controller_Init(qboolean notify_user)
SDL_SetHint( SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1" );
#endif
if (SDL_Init(SDL_INIT_GAMEPAD | SDL_INIT_HAPTIC) == -1)
if (!SDL_Init(SDL_INIT_GAMEPAD | SDL_INIT_HAPTIC))
{
Com_Printf ("Couldn't init SDL Gamepad: %s.\n", SDL_GetError());
return;
@ -2184,9 +2184,9 @@ IN_Controller_Init(qboolean notify_user)
if (!is_controller)
{
char joystick_guid[65] = {0};
SDL_JoystickGUID guid = SDL_GetJoystickInstanceGUID(joysticks[i]);
SDL_GUID guid = SDL_GetJoystickGUIDForID(joysticks[i]);
SDL_GetJoystickGUIDString(guid, joystick_guid, 64);
SDL_GUIDToString(guid, joystick_guid, 64);
Com_Printf ("To identify joystick as Gamepad, provide its config by either:\n"
" * Putting 'gamecontrollerdb.txt' file in your game directory.\n"
@ -2213,7 +2213,7 @@ IN_Controller_Init(qboolean notify_user)
#ifdef NATIVE_SDL_GYRO
if (SDL_GamepadHasSensor(controller, SDL_SENSOR_GYRO)
&& !SDL_SetGamepadSensorEnabled(controller, SDL_SENSOR_GYRO, SDL_TRUE) )
&& !SDL_SetGamepadSensorEnabled(controller, SDL_SENSOR_GYRO, true) )
{
show_gyro = true;
Com_Printf( "Gyro sensor enabled at %.2f Hz\n",
@ -2224,7 +2224,7 @@ IN_Controller_Init(qboolean notify_user)
Com_Printf("Gyro sensor not found.\n");
}
SDL_bool hasLED = SDL_GetBooleanProperty(SDL_GetGamepadProperties(controller), SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN, SDL_FALSE);
bool hasLED = SDL_GetBooleanProperty(SDL_GetGamepadProperties(controller), SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN, false);
if (hasLED)
{
SDL_SetGamepadLED(controller, 0, 80, 0); // green light
@ -2248,7 +2248,7 @@ IN_Controller_Init(qboolean notify_user)
show_haptic = true;
}
SDL_bool hasRumble = SDL_GetBooleanProperty(SDL_GetGamepadProperties(controller), SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN, SDL_FALSE);
bool hasRumble = SDL_GetBooleanProperty(SDL_GetGamepadProperties(controller), SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN, false);
if (hasRumble)
{
show_haptic = true;
@ -2345,8 +2345,6 @@ IN_Init(void)
}
}
SDL_StartTextInput();
IN_Controller_Init(false);
Com_Printf("------------------------------------\n\n");

View file

@ -151,6 +151,7 @@ void LM_FreeLightmapBuffers(void);
void Scrap_Free(void);
void Scrap_Init(void);
extern void R_SetDefaultState(void);
extern void R_ResetGLBuffer(void);
void
@ -635,6 +636,19 @@ R_PolyBlend(void)
glColor4f(1, 1, 1, 1);
}
static void
R_ResetClearColor(void)
{
if (gl1_discardfb->value == 1 && !r_clear->value)
{
glClearColor(0, 0, 0, 0.5);
}
else
{
glClearColor(1, 0, 0.5, 0.5);
}
}
static void
R_SetupFrame(void)
{
@ -712,7 +726,7 @@ R_SetupFrame(void)
vid.height - r_newrefdef.height - r_newrefdef.y,
r_newrefdef.width, r_newrefdef.height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1, 0, 0.5, 0.5);
R_ResetClearColor();
glDisable(GL_SCISSOR_TEST);
}
}
@ -814,53 +828,72 @@ R_SetupGL(void)
void
R_Clear(void)
{
// Check whether the stencil buffer needs clearing, and do so if need be.
GLbitfield stencilFlags = 0;
if (gl_state.stereo_mode >= STEREO_MODE_ROW_INTERLEAVED && gl_state.stereo_mode <= STEREO_MODE_PIXEL_INTERLEAVED) {
glClearStencil(GL_FALSE);
stencilFlags |= GL_STENCIL_BUFFER_BIT;
// Define which buffers need clearing
GLbitfield clearFlags = 0;
GLenum depthFunc = GL_LEQUAL;
// This breaks stereo modes, but we'll leave that responsibility to the user
if (r_clear->value)
{
clearFlags |= GL_COLOR_BUFFER_BIT;
}
// No stencil shadows allowed when using certain stereo modes, otherwise "wallhack" happens
if (gl_state.stereo_mode >= STEREO_MODE_ROW_INTERLEAVED && gl_state.stereo_mode <= STEREO_MODE_PIXEL_INTERLEAVED)
{
glClearStencil(0);
clearFlags |= GL_STENCIL_BUFFER_BIT;
}
else if (gl_shadows->value && gl_state.stencil && gl1_stencilshadow->value)
{
glClearStencil(1);
clearFlags |= GL_STENCIL_BUFFER_BIT;
}
if (gl1_ztrick->value)
{
static int trickframe;
if (r_clear->value)
{
glClear(GL_COLOR_BUFFER_BIT | stencilFlags);
}
trickframe++;
if (trickframe & 1)
{
gldepthmin = 0;
gldepthmax = 0.49999;
glDepthFunc(GL_LEQUAL);
}
else
{
gldepthmin = 1;
gldepthmax = 0.5;
glDepthFunc(GL_GEQUAL);
depthFunc = GL_GEQUAL;
}
}
else
{
if (r_clear->value)
{
glClear(GL_COLOR_BUFFER_BIT | stencilFlags | GL_DEPTH_BUFFER_BIT);
}
else
{
glClear(GL_DEPTH_BUFFER_BIT | stencilFlags);
}
clearFlags |= GL_DEPTH_BUFFER_BIT;
gldepthmin = 0;
gldepthmax = 1;
glDepthFunc(GL_LEQUAL);
}
switch ((int)gl1_discardfb->value)
{
case 1:
if (gl_state.stereo_mode == STEREO_MODE_NONE)
{
clearFlags |= GL_COLOR_BUFFER_BIT;
}
case 2:
clearFlags |= GL_STENCIL_BUFFER_BIT;
default:
break;
}
if (clearFlags)
{
glClear(clearFlags);
}
glDepthFunc(depthFunc);
glDepthRange(gldepthmin, gldepthmax);
if (gl_zfix->value)
@ -874,13 +907,6 @@ R_Clear(void)
glPolygonOffset(-0.05, -1);
}
}
/* stencilbuffer shadows */
if (gl_shadows->value && gl_state.stencil && gl1_stencilshadow->value)
{
glClearStencil(GL_TRUE);
glClear(GL_STENCIL_BUFFER_BIT);
}
}
void
@ -932,7 +958,6 @@ R_SetGL2D(void)
static void
R_RenderView(const refdef_t *fd)
{
#ifndef YQ2_GL1_GLES
if ((gl_state.stereo_mode != STEREO_MODE_NONE) && gl_state.camera_separation) {
qboolean drawing_left_eye = gl_state.camera_separation < 0;
@ -982,6 +1007,13 @@ R_RenderView(const refdef_t *fd)
qboolean flip_eyes = true;
int client_x, client_y;
GLshort screen[] = {
0, 0,
(GLshort)vid.width, 0,
(GLshort)vid.width, (GLshort)vid.height,
0, (GLshort)vid.height
};
//GLimp_GetClientAreaOffset(&client_x, &client_y);
client_x = 0;
client_y = 0;
@ -989,47 +1021,53 @@ R_RenderView(const refdef_t *fd)
R_SetGL2D();
glEnable(GL_STENCIL_TEST);
glStencilMask(GL_TRUE);
glStencilMask(1);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glStencilOp(GL_REPLACE, GL_KEEP, GL_KEEP);
glStencilFunc(GL_NEVER, 0, 1);
glBegin(GL_QUADS);
{
glVertex2i(0, 0);
glVertex2i(vid.width, 0);
glVertex2i(vid.width, vid.height);
glVertex2i(0, vid.height);
}
glEnd();
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_SHORT, 0, screen);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glStencilOp(GL_INVERT, GL_KEEP, GL_KEEP);
glStencilFunc(GL_NEVER, 1, 1);
glBegin(GL_LINES);
if (gl_state.stereo_mode == STEREO_MODE_ROW_INTERLEAVED || gl_state.stereo_mode == STEREO_MODE_PIXEL_INTERLEAVED)
{
if (gl_state.stereo_mode == STEREO_MODE_ROW_INTERLEAVED || gl_state.stereo_mode == STEREO_MODE_PIXEL_INTERLEAVED) {
int y;
for (y = 0; y <= vid.height; y += 2) {
glVertex2f(0, y - 0.5f);
glVertex2f(vid.width, y - 0.5f);
}
flip_eyes ^= (client_y & 1);
}
if (gl_state.stereo_mode == STEREO_MODE_COLUMN_INTERLEAVED || gl_state.stereo_mode == STEREO_MODE_PIXEL_INTERLEAVED) {
int x;
for (x = 0; x <= vid.width; x += 2) {
glVertex2f(x - 0.5f, 0);
glVertex2f(x - 0.5f, vid.height);
}
flip_eyes ^= (client_x & 1);
for (int y = 0; y <= vid.height; y += 2)
{
gl_buf.vtx[gl_buf.vt ] = 0;
gl_buf.vtx[gl_buf.vt + 1] = y - 0.5f;
gl_buf.vtx[gl_buf.vt + 2] = vid.width;
gl_buf.vtx[gl_buf.vt + 3] = y - 0.5f;
gl_buf.vt += 4;
}
flip_eyes ^= (client_y & 1);
}
glEnd();
glStencilMask(GL_FALSE);
if (gl_state.stereo_mode == STEREO_MODE_COLUMN_INTERLEAVED || gl_state.stereo_mode == STEREO_MODE_PIXEL_INTERLEAVED)
{
for (int x = 0; x <= vid.width; x += 2)
{
gl_buf.vtx[gl_buf.vt ] = x - 0.5f;
gl_buf.vtx[gl_buf.vt + 1] = 0;
gl_buf.vtx[gl_buf.vt + 2] = x - 0.5f;
gl_buf.vtx[gl_buf.vt + 3] = vid.height;
gl_buf.vt += 4;
}
flip_eyes ^= (client_x & 1);
}
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, gl_buf.vtx);
glDrawArrays(GL_LINES, 0, gl_buf.vt / 2);
glDisableClientState(GL_VERTEX_ARRAY);
gl_buf.vt = 0;
glStencilMask(0);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glStencilFunc(GL_EQUAL, drawing_left_eye ^ flip_eyes, 1);
@ -1040,7 +1078,6 @@ R_RenderView(const refdef_t *fd)
break;
}
}
#endif
if (r_norefresh->value)
{
@ -1182,9 +1219,9 @@ RI_RenderFrame(refdef_t *fd)
}
#ifdef YQ2_GL1_GLES
#define DEFAULT_LMCOPIES "1"
#define GLES1_ENABLED_ONLY "1"
#else
#define DEFAULT_LMCOPIES "0"
#define GLES1_ENABLED_ONLY "0"
#endif
void
@ -1245,10 +1282,8 @@ R_Register(void)
gl1_palettedtexture = ri.Cvar_Get("r_palettedtextures", "0", CVAR_ARCHIVE);
gl1_pointparameters = ri.Cvar_Get("gl1_pointparameters", "1", CVAR_ARCHIVE);
gl1_multitexture = ri.Cvar_Get("gl1_multitexture", "1", CVAR_ARCHIVE);
gl1_lightmapcopies = ri.Cvar_Get("gl1_lightmapcopies", DEFAULT_LMCOPIES, CVAR_ARCHIVE);
#ifdef YQ2_GL1_GLES
gl1_discardfb = ri.Cvar_Get("gl1_discardfb", "1", CVAR_ARCHIVE);
#endif
gl1_lightmapcopies = ri.Cvar_Get("gl1_lightmapcopies", GLES1_ENABLED_ONLY, CVAR_ARCHIVE);
gl1_discardfb = ri.Cvar_Get("gl1_discardfb", GLES1_ENABLED_ONLY, CVAR_ARCHIVE);
gl_drawbuffer = ri.Cvar_Get("gl_drawbuffer", "GL_BACK", 0);
r_vsync = ri.Cvar_Get("r_vsync", "1", CVAR_ARCHIVE);
@ -1286,7 +1321,7 @@ R_Register(void)
ri.Cmd_AddCommand("gl_strings", R_Strings);
}
#undef DEFAULT_LMCOPIES
#undef GLES1_ENABLED_ONLY
/*
* Changes the video mode
@ -1689,28 +1724,28 @@ RI_Init(void)
// ----
/* Discard framebuffer: Available only on GLES1, enables the use of a "performance hint"
* to the graphic driver, to get rid of the contents of the depth and stencil buffers.
/* Discard framebuffer: Enables the use of a "performance hint" to the graphic
* driver in GLES1, to get rid of the contents of the different framebuffers.
* Useful for some GPUs that may attempt to keep them and/or write them back to
* external/uniform memory, actions that are useless for Quake 2 rendering path.
* https://registry.khronos.org/OpenGL/extensions/EXT/EXT_discard_framebuffer.txt
* This extension is used by 'gl1_discardfb', and regardless of its existence,
* that cvar will enable glClear at the start of each frame, helping mobile GPUs.
*/
gl_config.discardfb = false;
#ifdef YQ2_GL1_GLES
R_Printf(PRINT_ALL, " - Discard framebuffer: ");
if (strstr(gl_config.extensions_string, "GL_EXT_discard_framebuffer"))
{
qglDiscardFramebufferEXT = (void (APIENTRY *)(GLenum, GLsizei, const GLenum *))
RI_GetProcAddress ("glDiscardFramebufferEXT");
qglDiscardFramebufferEXT = (void (APIENTRY *)(GLenum, GLsizei, const GLenum *))
RI_GetProcAddress ("glDiscardFramebufferEXT");
}
if (gl1_discardfb->value)
{
if (qglDiscardFramebufferEXT)
if (qglDiscardFramebufferEXT) // enough to verify availability
{
gl_config.discardfb = true;
R_Printf(PRINT_ALL, "Okay\n");
}
else
@ -1740,6 +1775,7 @@ RI_Init(void)
// ----
R_ResetClearColor();
R_SetDefaultState();
R_VertBufferInit();
@ -1789,17 +1825,17 @@ RI_BeginFrame(float camera_separation)
gl_state.camera_separation = camera_separation;
// force a vid_restart if gl1_stereo has been modified.
if ( gl_state.stereo_mode != gl1_stereo->value ) {
if ( gl_state.stereo_mode != gl1_stereo->value )
{
// If we've gone from one mode to another with the same special buffer requirements there's no need to restart.
if ( GL_GetSpecialBufferModeForStereoMode( gl_state.stereo_mode ) == GL_GetSpecialBufferModeForStereoMode( gl1_stereo->value ) ) {
if ( GL_GetSpecialBufferModeForStereoMode( gl_state.stereo_mode ) == GL_GetSpecialBufferModeForStereoMode( gl1_stereo->value ) )
{
gl_state.stereo_mode = gl1_stereo->value;
}
else
{
R_Printf(PRINT_ALL, "stereo supermode changed, restarting video!\n");
cvar_t *ref;
ref = ri.Cvar_Get("vid_fullscreen", "0", CVAR_ARCHIVE);
ref->modified = true;
ri.Cmd_ExecuteText(EXEC_APPEND, "vid_restart\n");
}
}
@ -1894,12 +1930,12 @@ RI_BeginFrame(float camera_separation)
gl1_particle_square->modified = false;
}
#ifndef YQ2_GL1_GLES
/* draw buffer stuff */
if (gl_drawbuffer->modified)
{
gl_drawbuffer->modified = false;
#ifndef YQ2_GL1_GLES
if ((gl_state.camera_separation == 0) || gl_state.stereo_mode != STEREO_MODE_OPENGL)
{
if (Q_stricmp(gl_drawbuffer->string, "GL_FRONT") == 0)
@ -1911,8 +1947,8 @@ RI_BeginFrame(float camera_separation)
glDrawBuffer(GL_BACK);
}
}
}
#endif
}
/* texturemode stuff */
if (gl_texturemode->modified || (gl_config.anisotropic && gl_anisotropic->modified)
@ -1982,7 +2018,7 @@ RI_SetPalette(const unsigned char *palette)
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(1, 0, 0.5, 0.5);
R_ResetClearColor();
}
void

View file

@ -237,6 +237,10 @@ static void
R_DrawAliasShadow(entity_t *currententity, dmdx_t *paliashdr, int posenum,
vec4_t *s_lerped, vec3_t shadevector)
{
// Don't do stencil test on unsupported stereo modes
const qboolean stencilt = ( gl_state.stencil && gl1_stencilshadow->value &&
( gl_state.stereo_mode < STEREO_MODE_ROW_INTERLEAVED
|| gl_state.stereo_mode > STEREO_MODE_PIXEL_INTERLEAVED ) );
int *order, i, num_mesh_nodes;
float height = 0, lheight;
dmdxmesh_t *mesh_nodes;
@ -248,7 +252,7 @@ R_DrawAliasShadow(entity_t *currententity, dmdx_t *paliashdr, int posenum,
R_UpdateGLBuffer(buf_shadow, 0, 0, 0, 1);
/* stencilbuffer shadows */
if (gl_state.stencil && gl1_stencilshadow->value)
if (stencilt)
{
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_EQUAL, 1, 2);
@ -270,7 +274,7 @@ R_DrawAliasShadow(entity_t *currententity, dmdx_t *paliashdr, int posenum,
R_ApplyGLBuffer();
/* stencilbuffer shadows */
if (gl_state.stencil && gl1_stencilshadow->value)
if (stencilt)
{
glDisable(GL_STENCIL_TEST);
}

View file

@ -169,7 +169,6 @@ R_Strings(void)
void
R_SetDefaultState(void)
{
glClearColor(1, 0, 0.5, 0.5);
glDisable(GL_MULTISAMPLE);
glCullFace(GL_FRONT);
glEnable(GL_TEXTURE_2D);

View file

@ -38,6 +38,8 @@ static SDL_GLContext context = NULL;
qboolean IsHighDPIaware = false;
static qboolean vsyncActive = false;
extern cvar_t *gl1_discardfb;
// ----
/*
@ -47,13 +49,26 @@ void
RI_EndFrame(void)
{
R_ApplyGLBuffer(); // to draw buffered 2D text
#ifdef YQ2_GL1_GLES
if (gl_config.discardfb)
static const GLenum attachments[3] = {GL_COLOR_EXT, GL_DEPTH_EXT, GL_STENCIL_EXT};
if (qglDiscardFramebufferEXT)
{
static const GLenum attachments[] = { GL_DEPTH_EXT, GL_STENCIL_EXT };
qglDiscardFramebufferEXT(GL_FRAMEBUFFER_OES, 2, attachments);
switch ((int)gl1_discardfb->value)
{
case 1:
qglDiscardFramebufferEXT(GL_FRAMEBUFFER_OES, 3, &attachments[0]);
break;
case 2:
qglDiscardFramebufferEXT(GL_FRAMEBUFFER_OES, 2, &attachments[1]);
break;
default:
break;
}
}
#endif
SDL_GL_SwapWindow(window);
}
@ -111,7 +126,11 @@ int RI_PrepareForWindow(void)
msaa_samples = gl_msaa_samples->value;
#ifdef USE_SDL3
if (!SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1))
#else
if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1) < 0)
#endif
{
R_Printf(PRINT_ALL, "MSAA is unsupported: %s\n", SDL_GetError());
@ -120,7 +139,11 @@ int RI_PrepareForWindow(void)
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
}
#ifdef USE_SDL3
else if (!SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa_samples))
#else
else if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa_samples) < 0)
#endif
{
R_Printf(PRINT_ALL, "MSAA %ix is unsupported: %s\n", msaa_samples, SDL_GetError());
@ -157,7 +180,11 @@ void RI_SetVsync(void)
vsync = -1;
}
#ifdef USE_SDL3
if (!SDL_GL_SetSwapInterval(vsync))
#else
if (SDL_GL_SetSwapInterval(vsync) == -1)
#endif
{
if (vsync == -1)
{
@ -170,7 +197,7 @@ void RI_SetVsync(void)
#ifdef USE_SDL3
int vsyncState;
if (SDL_GL_GetSwapInterval(&vsyncState) != 0)
if (!SDL_GL_GetSwapInterval(&vsyncState))
{
R_Printf(PRINT_ALL, "Failed to get vsync state, assuming vsync inactive.\n");
vsyncActive = false;
@ -296,7 +323,11 @@ int RI_InitContext(void* win)
if (gl_state.stencil)
{
#ifdef USE_SDL3
if (!SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencil_bits) || stencil_bits < 8)
#else
if (SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencil_bits) < 0 || stencil_bits < 8)
#endif
{
gl_state.stencil = false;
}
@ -350,7 +381,11 @@ RI_ShutdownContext(void)
{
if(context)
{
#ifdef USE_SDL3
SDL_GL_DestroyContext(context);
#else
SDL_GL_DeleteContext(context);
#endif
context = NULL;
}
}
@ -364,12 +399,11 @@ RI_ShutdownContext(void)
int RI_GetSDLVersion()
{
#ifdef USE_SDL3
SDL_Version ver;
int version = SDL_GetVersion();
return SDL_VERSIONNUM_MAJOR(version);
#else
SDL_version ver;
#endif
SDL_VERSION(&ver);
return ver.major;
#endif
}

View file

@ -376,7 +376,7 @@ R_BlendLightmaps(const model_t *currentmodel)
}
static void
R_RenderBrushPoly(const entity_t *currententity, msurface_t *fa)
R_RenderBrushPoly(msurface_t *fa)
{
qboolean is_dynamic = false;
int maps;
@ -517,12 +517,12 @@ R_DrawAlphaSurfaces(void)
}
static void
R_RenderLightmappedPoly(const entity_t *currententity, msurface_t *surf)
R_RenderLightmappedPoly(msurface_t *surf)
{
int i;
int nv = surf->polys->numverts;
mvtx_t* vert;
const int nv = surf->polys->numverts;
float sscroll, tscroll;
mvtx_t* vert;
int i;
c_brush_polys++;
vert = surf->polys->verts;
@ -728,7 +728,7 @@ dynamic_surf:
}
static void
R_DrawTextureChains(const entity_t *currententity)
R_DrawTextureChains(void)
{
int i;
msurface_t *s;
@ -757,7 +757,7 @@ R_DrawTextureChains(const entity_t *currententity)
for ( ; s; s = s->texturechain)
{
R_UpdateGLBuffer(buf_singletex, image->texnum, 0, s->flags, 1);
R_RenderBrushPoly(currententity, s);
R_RenderBrushPoly(s);
}
image->texturechain = NULL;
@ -780,7 +780,7 @@ R_DrawTextureChains(const entity_t *currententity)
if (!(s->flags & SURF_DRAWTURB))
{
R_UpdateGLBuffer(buf_mtex, image->texnum, s->lightmaptexturenum, 0, 1);
R_RenderLightmappedPoly(currententity, s);
R_RenderLightmappedPoly(s);
}
}
}
@ -800,7 +800,7 @@ R_DrawTextureChains(const entity_t *currententity)
if (s->flags & SURF_DRAWTURB)
{
R_UpdateGLBuffer(buf_singletex, image->texnum, 0, s->flags, 1);
R_RenderBrushPoly(currententity, s);
R_RenderBrushPoly(s);
}
}
@ -862,12 +862,12 @@ R_DrawInlineBModel(const entity_t *currententity, const model_t *currentmodel)
{
// Dynamic lighting already generated in R_GetBrushesLighting()
R_UpdateGLBuffer(buf_mtex, image->texnum, psurf->lightmaptexturenum, 0, 1);
R_RenderLightmappedPoly(currententity, psurf);
R_RenderLightmappedPoly(psurf);
}
else
{
R_UpdateGLBuffer(buf_singletex, image->texnum, 0, psurf->flags, 1);
R_RenderBrushPoly(currententity, psurf);
R_RenderBrushPoly(psurf);
}
}
}
@ -1223,7 +1223,7 @@ R_DrawWorld(void)
R_RecursiveWorldNode(&ent, r_worldmodel->nodes);
R_GetBrushesLighting();
R_RegenAllLightmaps();
R_DrawTextureChains(&ent);
R_DrawTextureChains();
R_BlendLightmaps(r_worldmodel);
R_DrawSkyBox();
R_DrawTriangleOutlines();

View file

@ -127,8 +127,6 @@ typedef struct // 832k aprox.
#include "model.h"
void R_SetDefaultState(void);
extern glbuffer_t gl_buf;
extern float gldepthmin, gldepthmax;
@ -397,7 +395,6 @@ typedef struct
qboolean pointparameters;
qboolean multitexture;
qboolean lightmapcopies; // many copies of same lightmap, for embedded
qboolean discardfb;
// ----

View file

@ -155,7 +155,11 @@ void GL3_SetVsync(void)
vsync = -1;
}
#ifdef USE_SDL3
if (!SDL_GL_SetSwapInterval(vsync))
#else
if (SDL_GL_SetSwapInterval(vsync) == -1)
#endif
{
if (vsync == -1)
{
@ -168,7 +172,7 @@ void GL3_SetVsync(void)
#ifdef USE_SDL3
int vsyncState;
if (SDL_GL_GetSwapInterval(&vsyncState) != 0)
if (!SDL_GL_GetSwapInterval(&vsyncState))
{
R_Printf(PRINT_ALL, "Failed to get vsync state, assuming vsync inactive.\n");
vsyncActive = false;
@ -204,7 +208,11 @@ int GL3_PrepareForWindow(void)
while (1)
{
#ifdef USE_SDL3
if (!SDL_GL_LoadLibrary(libgl))
#else
if (SDL_GL_LoadLibrary(libgl) < 0)
#endif
{
if (libgl == NULL)
{
@ -236,7 +244,11 @@ int GL3_PrepareForWindow(void)
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
#ifdef USE_SDL3
if (SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8))
#else
if (SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8) == 0)
#endif
{
gl3config.stencil = true;
}
@ -287,7 +299,11 @@ int GL3_PrepareForWindow(void)
{
msaa_samples = gl_msaa_samples->value;
#ifdef USE_SDL3
if (!SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1))
#else
if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1) < 0)
#endif
{
R_Printf(PRINT_ALL, "MSAA is unsupported: %s\n", SDL_GetError());
@ -296,7 +312,11 @@ int GL3_PrepareForWindow(void)
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
}
#ifdef USE_SDL3
else if (!SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa_samples))
#else
else if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa_samples) < 0)
#endif
{
R_Printf(PRINT_ALL, "MSAA %ix is unsupported: %s\n", msaa_samples, SDL_GetError());
@ -361,7 +381,11 @@ int GL3_InitContext(void* win)
if (gl3config.stencil)
{
#ifdef USE_SDL3
if (!SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencil_bits) || stencil_bits < 8)
#else
if (SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencil_bits) < 0 || stencil_bits < 8)
#endif
{
gl3config.stencil = false;
}
@ -477,7 +501,11 @@ void GL3_ShutdownContext()
{
if(context)
{
#ifdef USE_SDL3
SDL_GL_DestroyContext(context);
#else
SDL_GL_DeleteContext(context);
#endif
context = NULL;
}
}
@ -491,12 +519,11 @@ void GL3_ShutdownContext()
int GL3_GetSDLVersion()
{
#ifdef USE_SDL3
SDL_Version ver;
int version = SDL_GetVersion();
return SDL_VERSIONNUM_MAJOR(version);
#else
SDL_version ver;
#endif
SDL_VERSION(&ver);
return ver.major;
#endif
}

View file

@ -1780,8 +1780,7 @@ RE_IsVsyncActive(void)
static int RE_PrepareForWindow(void)
{
int flags = SDL_SWSURFACE;
return flags;
return 0;
}
/*
@ -1809,17 +1808,18 @@ GetRefAPI(refimport_t imp)
// Need to communicate the SDL major version to the client.
#ifdef USE_SDL3
SDL_Version ver;
int version = SDL_VERSIONNUM_MAJOR(SDL_GetVersion());
#else
SDL_version ver;
#endif
SDL_VERSION(&ver);
int version = ver.major;
#endif
memset(&refexport, 0, sizeof(refexport_t));
ri = imp;
refexport.api_version = API_VERSION;
refexport.framework_version = ver.major;
refexport.framework_version = version;
refexport.BeginRegistration = RE_BeginRegistration;
refexport.RegisterModel = RE_RegisterModel;
@ -1905,7 +1905,8 @@ RE_InitContext(void *win)
if (r_vsync->value)
{
#ifdef USE_SDL3
renderer = SDL_CreateRenderer(window, NULL, SDL_RENDERER_PRESENTVSYNC);
renderer = SDL_CreateRenderer(window, NULL);
SDL_SetRenderVSync(renderer, 1);
#else
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
#endif
@ -1913,7 +1914,7 @@ RE_InitContext(void *win)
else
{
#ifdef USE_SDL3
renderer = SDL_CreateRenderer(window, NULL, 0);
renderer = SDL_CreateRenderer(window, NULL);
#else
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
#endif
@ -2205,7 +2206,11 @@ RE_CleanFrame(void)
memset(swap_buffers, 0,
vid_buffer_height * vid_buffer_width * sizeof(pixel_t) * 2);
#ifdef USE_SDL3
if (!SDL_LockTexture(texture, NULL, (void**)&pixels, &pitch))
#else
if (SDL_LockTexture(texture, NULL, (void**)&pixels, &pitch))
#endif
{
Com_Printf("Can't lock texture: %s\n", SDL_GetError());
return;
@ -2237,7 +2242,11 @@ RE_FlushFrame(int vmin, int vmax)
return;
}
#ifdef USE_SDL3
if (!SDL_LockTexture(texture, NULL, (void**)&pixels, &pitch))
#else
if (SDL_LockTexture(texture, NULL, (void**)&pixels, &pitch))
#endif
{
Com_Printf("Can't lock texture: %s\n", SDL_GetError());
return;

View file

@ -1362,7 +1362,11 @@ SDL_BackendInit(void)
if (!SDL_WasInit(SDL_INIT_AUDIO))
{
#ifdef USE_SDL3
if (!SDL_Init(SDL_INIT_AUDIO))
#else
if (SDL_Init(SDL_INIT_AUDIO) == -1)
#endif
{
Com_Printf ("Couldn't init SDL audio: %s.\n", SDL_GetError ());
return 0;
@ -1423,7 +1427,7 @@ SDL_BackendInit(void)
spec.channels = sndchans;
/* Okay, let's try our luck */
stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &spec, SDL_SDL3Callback, NULL);
stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, SDL_SDL3Callback, NULL);
if (stream == NULL)
{
Com_Printf("SDL_OpenAudio() failed: %s\n", SDL_GetError());

View file

@ -123,11 +123,17 @@ CreateSDLWindow(int flags, int fullscreen, int w, int h)
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, h);
SDL_SetNumberProperty(props, "flags", flags);
if (flags & SDL_WINDOW_OPENGL)
SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_OPENGL_BOOLEAN, true);
window = SDL_CreateWindowWithProperties(props);
SDL_DestroyProperties(props);
if (window)
{
/* enable text input */
SDL_StartTextInput(window);
/* save current display as default */
if ((last_display = SDL_GetDisplayForWindow(window)) == 0)
{
@ -153,19 +159,17 @@ CreateSDLWindow(int flags, int fullscreen, int w, int h)
/* Otherwise try to find a mode near the requested one and
switch to it in exclusive fullscreen mode. */
/* TODO SDL3: Leak? */
const SDL_DisplayMode *closestMode = SDL_GetClosestFullscreenDisplayMode(last_display, w, h, vid_rate->value, false);
SDL_DisplayMode closestMode;
if (closestMode == NULL)
if (SDL_GetClosestFullscreenDisplayMode(last_display, w, h, vid_rate->value, false, &closestMode) != true)
{
Com_Printf("SDL was unable to find a mode close to %ix%i@%f\n", w, h, vid_rate->value);
if (vid_rate->value != 0)
{
Com_Printf("Retrying with desktop refresh rate\n");
closestMode = SDL_GetClosestFullscreenDisplayMode(last_display, w, h, 0, false);
if (closestMode != NULL)
if (SDL_GetClosestFullscreenDisplayMode(last_display, w, h, vid_rate->value, false, &closestMode) == true)
{
Cvar_SetValue("vid_rate", 0);
}
@ -178,31 +182,24 @@ CreateSDLWindow(int flags, int fullscreen, int w, int h)
}
Com_Printf("User requested %ix%i@%f, setting closest mode %ix%i@%f\n",
w, h, vid_rate->value, closestMode->w, closestMode->h , closestMode->refresh_rate);
w, h, vid_rate->value, closestMode.w, closestMode.h , closestMode.refresh_rate);
/* TODO SDL3: Same code is in InitGraphics(), refactor into
* a function? */
if (SDL_SetWindowFullscreenMode(window, closestMode) < 0)
if (!SDL_SetWindowFullscreenMode(window, &closestMode))
{
Com_Printf("Couldn't set closest mode: %s\n", SDL_GetError());
return false;
}
if (SDL_SetWindowFullscreen(window, true) < 0)
if (!SDL_SetWindowFullscreen(window, true))
{
Com_Printf("Couldn't switch to exclusive fullscreen: %s\n", SDL_GetError());
return false;
}
int ret = SDL_SyncWindow(window);
if (ret > 0)
{
Com_Printf("Synchronizing window state timed out\n");
return false;
}
else if (ret < 0)
if (!SDL_SyncWindow(window))
{
Com_Printf("Couldn't synchronize window state: %s\n", SDL_GetError());
return false;
@ -247,7 +244,7 @@ GetWindowSize(int* w, int* h)
return false;
}
if (SDL_GetWindowSize(window, w, h) < 0)
if (!SDL_GetWindowSize(window, w, h))
{
Com_Printf("Couldn't get window size: %s\n", SDL_GetError());
return false;
@ -304,7 +301,7 @@ PrintDisplayModes(void)
}
int nummodes = 0;
const SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(curdisplay, &nummodes);
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(curdisplay, &nummodes);
if (modes)
{
@ -347,7 +344,7 @@ SetSDLIcon()
amask = (q2icon64.bytes_per_pixel == 3) ? 0 : 0xff000000;
#endif
SDL_Surface* icon = SDL_CreateSurfaceFrom((void *)q2icon64.pixel_data, q2icon64.width, q2icon64.height, q2icon64.bytes_per_pixel * q2icon64.width, SDL_GetPixelFormatEnumForMasks(q2icon64.bytes_per_pixel * 8, rmask, gmask, bmask, amask));
SDL_Surface* icon = SDL_CreateSurfaceFrom(q2icon64.width, q2icon64.height, SDL_GetPixelFormatForMasks(q2icon64.bytes_per_pixel * 8, rmask, gmask, bmask, amask), (void *)q2icon64.pixel_data, q2icon64.bytes_per_pixel * q2icon64.width);
SDL_SetWindowIcon(window, icon);
SDL_DestroySurface(icon);
}
@ -407,18 +404,17 @@ GLimp_Init(void)
if (!SDL_WasInit(SDL_INIT_VIDEO))
{
if (SDL_Init(SDL_INIT_VIDEO) == -1)
if (!SDL_Init(SDL_INIT_VIDEO))
{
Com_Printf("Couldn't init SDL video: %s.\n", SDL_GetError());
return false;
}
SDL_Version version;
int version = SDL_GetVersion();
SDL_GetVersion(&version);
Com_Printf("-------- vid initialization --------\n");
Com_Printf("SDL version is: %i.%i.%i\n", (int)version.major, (int)version.minor, (int)version.patch);
Com_Printf("SDL version is: %i.%i.%i\n", SDL_VERSIONNUM_MAJOR(version), SDL_VERSIONNUM_MINOR(version), SDL_VERSIONNUM_MICRO(version));
Com_Printf("SDL video driver is \"%s\".\n", SDL_GetCurrentVideoDriver());
SDL_DisplayID *displays;
@ -506,26 +502,22 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight)
if (initSuccessful && GetWindowSize(&curWidth, &curHeight)
&& (curWidth == width) && (curHeight == height))
{
/* TODO SDL3: Leak? */
const SDL_DisplayMode *closestMode = NULL;
SDL_DisplayMode closestMode;
/* If we want fullscreen, but aren't */
if (GetFullscreenType())
{
if (fullscreen == FULLSCREEN_EXCLUSIVE)
{
closestMode = SDL_GetClosestFullscreenDisplayMode(last_display, width, height, vid_rate->value, false);
if (closestMode == NULL)
if (SDL_GetClosestFullscreenDisplayMode(last_display, width, height, vid_rate->value, false, &closestMode) != true)
{
Com_Printf("SDL was unable to find a mode close to %ix%i@%f\n", width, height, vid_rate->value);
if (vid_rate->value != 0)
{
Com_Printf("Retrying with desktop refresh rate\n");
closestMode = SDL_GetClosestFullscreenDisplayMode(last_display, width, height, 0, false);
if (closestMode != NULL)
if (SDL_GetClosestFullscreenDisplayMode(last_display, width, height, 0, false, &closestMode) == true)
{
Cvar_SetValue("vid_rate", 0);
}
@ -540,31 +532,24 @@ GLimp_InitGraphics(int fullscreen, int *pwidth, int *pheight)
else if (fullscreen == FULLSCREEN_DESKTOP)
{
/* Fullscreen window */
closestMode = NULL;
/* closestMode = NULL; */
}
if (SDL_SetWindowFullscreenMode(window, closestMode) < 0)
if (!SDL_SetWindowFullscreenMode(window, &closestMode))
{
Com_Printf("Couldn't set fullscreen modmode: %s\n", SDL_GetError());
Cvar_SetValue("vid_fullscreen", 0);
}
else
{
if (SDL_SetWindowFullscreen(window, true) < 0)
if (!SDL_SetWindowFullscreen(window, true))
{
Com_Printf("Couldn't switch to exclusive fullscreen: %s\n", SDL_GetError());
Cvar_SetValue("vid_fullscreen", 0);
}
else
{
int ret = SDL_SyncWindow(window);
if (ret > 0)
{
Com_Printf("Synchronizing window state timed out\n");
Cvar_SetValue("vid_fullscreen", 0);
}
else if (ret < 0)
if (!SDL_SyncWindow(window))
{
Com_Printf("Couldn't synchronize window state: %s\n", SDL_GetError());
Cvar_SetValue("vid_fullscreen", 0);
@ -779,14 +764,21 @@ GLimp_GrabInput(qboolean grab)
{
if(window != NULL)
{
SDL_SetWindowMouseGrab(window, grab ? SDL_TRUE : SDL_FALSE);
SDL_SetWindowMouseGrab(window, grab ? true : false);
}
if(SDL_SetRelativeMouseMode(grab ? SDL_TRUE : SDL_FALSE) < 0)
#ifdef USE_SDL3
if(!SDL_SetWindowRelativeMouseMode(window, grab ? true : false))
{
Com_Printf("WARNING: Setting Relative Mousemode failed, reason: %s\n", SDL_GetError());
}
#else
if(SDL_SetWindowRelativeMouseMode(window, grab ? true : false) < 0)
{
Com_Printf("WARNING: Setting Relative Mousemode failed, reason: %s\n", SDL_GetError());
Com_Printf(" You should probably update to SDL 2.0.3 or newer!\n");
}
#endif
}
/*
@ -906,8 +898,6 @@ GLimp_GetWindowDisplayIndex(void)
int
GLimp_GetFrameworkVersion(void)
{
SDL_Version ver;
SDL_VERSION(&ver);
return ver.major;
int version = SDL_GetVersion();
return SDL_VERSIONNUM_MAJOR(version);
}