- [Psy-X] VSync support reworked

This commit is contained in:
Ilya Shurumov 2021-05-26 17:52:07 +06:00 committed by InspirationByte
parent a5f7597637
commit d154a77e13
3 changed files with 26 additions and 24 deletions

View File

@ -118,6 +118,9 @@ extern void PsyX_WaitForTimestep(int count);
/* Changes swap interval state */ /* Changes swap interval state */
extern void PsyX_EnableSwapInterval(int enable); extern void PsyX_EnableSwapInterval(int enable);
/* Changes swap interval interval interval */
extern void PsyX_SetSwapInterval(int interval);
#if defined(_LANGUAGE_C_PLUS_PLUS)||defined(__cplusplus)||defined(c_plusplus) #if defined(_LANGUAGE_C_PLUS_PLUS)||defined(__cplusplus)||defined(c_plusplus)
} }
#endif #endif

View File

@ -43,10 +43,9 @@ int strcasecmp(const char* _l, const char* _r)
SDL_Window* g_window = NULL; SDL_Window* g_window = NULL;
#define SWAP_INTERVAL 1 int g_swapInterval = 1;
int g_swapInterval = SWAP_INTERVAL;
int g_enableSwapInterval = 1; int g_enableSwapInterval = 1;
int g_skipSwapInterval = 0;
PsyXKeyboardMapping g_keyboard_mapping; PsyXKeyboardMapping g_keyboard_mapping;
PsyXControllerMapping g_controller_mapping; PsyXControllerMapping g_controller_mapping;
@ -147,7 +146,7 @@ long PsyX_Sys_SetVMode(long mode)
int PsyX_Sys_GetVBlankCount() int PsyX_Sys_GetVBlankCount()
{ {
if (g_swapInterval == 0) if (g_skipSwapInterval)
{ {
// extra speedup. // extra speedup.
// does not affect `vsync_callback` count // does not affect `vsync_callback` count
@ -801,6 +800,7 @@ void PsyX_Sys_DoDebugMouseMotion(int x, int y)
gameDebugMouse(x, y); gameDebugMouse(x, y);
} }
void PsyX_Sys_DoDebugKeys(int nKey, char down) void PsyX_Sys_DoDebugKeys(int nKey, char down)
{ {
if (gameDebugKeys) if (gameDebugKeys)
@ -809,21 +809,9 @@ void PsyX_Sys_DoDebugKeys(int nKey, char down)
if (nKey == SDL_SCANCODE_BACKSPACE) if (nKey == SDL_SCANCODE_BACKSPACE)
{ {
if (down) if (down)
{ g_skipSwapInterval = 1;
if (g_swapInterval != 0)
{
g_swapInterval = 0;
GR_ResetDevice();
}
}
else else
{ g_skipSwapInterval = 0;
if (g_swapInterval != SWAP_INTERVAL)
{
g_swapInterval = SWAP_INTERVAL;
GR_ResetDevice();
}
}
} }
if (!down) if (!down)
@ -919,7 +907,7 @@ void PsyX_WaitForTimestep(int count)
#endif #endif
// wait for vblank // wait for vblank
if (g_swapInterval > 0) if (!g_skipSwapInterval)
{ {
static int swapLastVbl = 0; static int swapLastVbl = 0;

View File

@ -78,6 +78,8 @@ int g_pgxpTextureCorrection = 1;
int g_pgxpZBuffer = 1; int g_pgxpZBuffer = 1;
int g_bilinearFiltering = 0; int g_bilinearFiltering = 0;
extern int g_skipSwapInterval;
// this has to be configured for each game // this has to be configured for each game
float g_pgxpZNear = 0.25f; float g_pgxpZNear = 0.25f;
float g_pgxpZFar = 1000.0f; float g_pgxpZFar = 1000.0f;
@ -511,6 +513,13 @@ void GR_Shutdown()
#endif #endif
} }
void GR_UpdateSwapIntervalState()
{
#if defined(RENDERER_OGL)
SDL_GL_SetSwapInterval((g_enableSwapInterval && !g_skipSwapInterval) ? g_swapInterval : 0);
#endif
}
void GR_BeginScene() void GR_BeginScene()
{ {
g_lastBoundTexture = 0; g_lastBoundTexture = 0;
@ -523,6 +532,7 @@ void GR_BeginScene()
GR_UpdateVRAM(); GR_UpdateVRAM();
GR_SetViewPort(0, 0, g_windowWidth, g_windowHeight); GR_SetViewPort(0, 0, g_windowWidth, g_windowHeight);
GR_UpdateSwapIntervalState();
if (g_wireframeMode) if (g_wireframeMode)
{ {
@ -553,7 +563,7 @@ unsigned short vram[VRAM_WIDTH * VRAM_HEIGHT];
void GR_ResetDevice() void GR_ResetDevice()
{ {
PsyX_EnableSwapInterval(g_enableSwapInterval); GR_UpdateSwapIntervalState();
} }
typedef struct typedef struct
@ -1119,17 +1129,18 @@ int GR_InitialisePSX()
#endif #endif
GR_ResetDevice(); GR_ResetDevice();
PsyX_EnableSwapInterval(g_enableSwapInterval);
return 1; return 1;
} }
void PsyX_SetSwapInterval(int interval)
{
g_swapInterval = interval;
}
void PsyX_EnableSwapInterval(int enable) void PsyX_EnableSwapInterval(int enable)
{ {
g_enableSwapInterval = enable; g_enableSwapInterval = enable;
#if defined(RENDERER_OGL)
SDL_GL_SetSwapInterval(g_enableSwapInterval ? g_swapInterval : 0);
#endif
} }
void GR_Ortho2D(float left, float right, float bottom, float top, float znear, float zfar) void GR_Ortho2D(float left, float right, float bottom, float top, float znear, float zfar)