Merge pull request #52 from docentYT/code-optimization

Small code optimizations that results with 3x faster main loop
This commit is contained in:
2026-02-08 13:06:00 +01:00
committed by GitHub
2 changed files with 10 additions and 6 deletions

View File

@@ -13,8 +13,8 @@ gl::fence::~fence()
bool gl::fence::is_signalled()
{
GLsizei len = 0;
GLint val;
glGetSynciv(sync, GL_SYNC_STATUS, 1, &len, &val);
return len == 1 && val == GL_SIGNALED;
// glClientWaitSync is faster than glGetSynciv. glGetSynciv probably tries to synchronize cpu and gpu
// https://stackoverflow.com/questions/34601376/which-to-use-for-opengl-client-side-waiting-glgetsynciv-vs-glclientwaitsync
GLenum r = glClientWaitSync(sync, GL_SYNC_FLUSH_COMMANDS_BIT, 1);
return r == GL_ALREADY_SIGNALED || r == GL_CONDITION_SATISFIED;
}

View File

@@ -657,9 +657,13 @@ void opengl33_renderer::Render_pass(viewport_config &vp, rendermode const Mode)
glDebug("rendermode::color");
glDebug("context switch");
glfwMakeContextCurrent(vp.window);
static bool was_made = false;
m_current_viewport = &vp;
if (m_current_viewport != &vp)
{
glfwMakeContextCurrent(vp.window);
m_current_viewport = &vp;
}
if ((!simulation::is_ready) || (Global.gfx_skiprendering))
{