mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-25 10:30:15 +00:00
Hack VSync: use sleep
This commit is contained in:
parent
55375a91b1
commit
fd7d698ee0
@ -276,7 +276,7 @@ void GRenderWindow::InitRenderTarget() {
|
||||
QGLFormat fmt;
|
||||
fmt.setVersion(3, 3);
|
||||
fmt.setProfile(QGLFormat::CoreProfile);
|
||||
fmt.setSwapInterval(Settings::values.use_vsync);
|
||||
fmt.setSwapInterval(false);
|
||||
|
||||
// Requests a forward-compatible context, which is required to get a 3.2+ context on OS X
|
||||
fmt.setOption(QGL::NoDeprecatedFunctions);
|
||||
|
@ -2,8 +2,10 @@
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <numeric>
|
||||
#include <thread>
|
||||
#include <type_traits>
|
||||
|
||||
#include "common/color.h"
|
||||
@ -411,6 +413,19 @@ static void VBlankCallback(u64 userdata, int cycles_late) {
|
||||
last_skip_frame = g_skip_frame;
|
||||
g_skip_frame = (frame_count & Settings::values.frame_skip) != 0;
|
||||
|
||||
if (Settings::values.use_vsync) {
|
||||
using namespace std::chrono;
|
||||
static auto frame_time = high_resolution_clock::now();
|
||||
static constexpr auto update_duration = duration_cast<high_resolution_clock::duration>(16667us);
|
||||
auto now = high_resolution_clock::now();
|
||||
if (now < frame_time) {
|
||||
std::this_thread::sleep_until(frame_time);
|
||||
frame_time += update_duration;
|
||||
} else {
|
||||
frame_time = now + update_duration;
|
||||
}
|
||||
}
|
||||
|
||||
// Swap buffers based on the frameskip mode, which is a little bit tricky. When
|
||||
// a frame is being skipped, nothing is being rendered to the internal framebuffer(s).
|
||||
// So, we should only swap frames if the last frame was rendered. The rules are:
|
||||
|
Loading…
Reference in New Issue
Block a user