From de5f1b2a833a59d3b0375f24675d27cea99e56d1 Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Sun, 5 Mar 2023 15:05:30 +0100 Subject: [PATCH] Optionally expose time to screen shaders (#1700) * Optionally expose time to screen shaders Since that collides with damage tracking, it will only be done, when damage tracking is disabled, meaning this comes at no cost for everyone not using time. * Rename m_Timer to m_tGlobalTimer --- src/render/OpenGL.cpp | 21 +++++++++++++++++++-- src/render/OpenGL.hpp | 2 ++ src/render/Shader.hpp | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 6a9baedf..7caf8ad1 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -31,6 +31,8 @@ CHyprOpenGLImpl::CHyprOpenGLImpl() { pixman_region32_init(&m_rOriginalDamageRegion); RASSERT(eglMakeCurrent(wlr_egl_get_display(g_pCompositor->m_sWLREGL), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT), "Couldn't unset current EGL!"); + + m_tGlobalTimer.reset(); } GLuint CHyprOpenGLImpl::createProgram(const std::string& vert, const std::string& frag, bool dynamic) { @@ -310,8 +312,15 @@ void CHyprOpenGLImpl::applyScreenShader(const std::string& path) { return; } - m_sFinalScreenShader.proj = glGetUniformLocation(m_sFinalScreenShader.program, "proj"); - m_sFinalScreenShader.tex = glGetUniformLocation(m_sFinalScreenShader.program, "tex"); + m_sFinalScreenShader.proj = glGetUniformLocation(m_sFinalScreenShader.program, "proj"); + m_sFinalScreenShader.tex = glGetUniformLocation(m_sFinalScreenShader.program, "tex"); + m_sFinalScreenShader.time = glGetUniformLocation(m_sFinalScreenShader.program, "time"); + if (m_sFinalScreenShader.time != -1 && g_pConfigManager->getInt("debug:damage_tracking") != 0) { + // The screen shader uses the "time" uniform + // Since the screen shader could change every frame, damage tracking *needs* to be disabled + g_pConfigManager->addParseError("Screen shader: Screen shader uses uniform 'time', which requires debug:damage_tracking to be switched off.\n" + "WARNING: Disabling damage tracking will *massively* increase GPU utilization!"); + } m_sFinalScreenShader.texAttrib = glGetAttribLocation(m_sFinalScreenShader.program, "texcoord"); m_sFinalScreenShader.posAttrib = glGetAttribLocation(m_sFinalScreenShader.program, "pos"); } @@ -523,6 +532,14 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, wlr_b glUniformMatrix3fv(shader->proj, 1, GL_FALSE, glMatrix); #endif glUniform1i(shader->tex, 0); + + if (usingFinalShader && g_pConfigManager->getInt("debug:damage_tracking") == 0) { + glUniform1f(shader->time, m_tGlobalTimer.getSeconds()); + } else if (usingFinalShader) { + // Don't let time be unitialised + glUniform1f(shader->time, 0.f); + } + if (!usingFinalShader) { glUniform1f(shader->alpha, alpha); glUniform1i(shader->discardOpaque, (int)discardOpaque); diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index d2dd5ce6..171efb35 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -3,6 +3,7 @@ #include "../defines.hpp" #include "../helpers/Monitor.hpp" #include "../helpers/Color.hpp" +#include "../helpers/Timer.hpp" #include #include @@ -134,6 +135,7 @@ class CHyprOpenGLImpl { bool m_bApplyFinalShader = false; CShader m_sFinalScreenShader; + CTimer m_tGlobalTimer; GLuint createProgram(const std::string&, const std::string&, bool dynamic = false); GLuint compileShader(const GLuint&, std::string, bool dynamic = false); diff --git a/src/render/Shader.hpp b/src/render/Shader.hpp index a5aa6efb..6d3ca09b 100644 --- a/src/render/Shader.hpp +++ b/src/render/Shader.hpp @@ -37,6 +37,8 @@ class CShader { GLint gradientLength; GLint angle; + GLint time; + GLint getUniformLocation(const std::string&); void destroy();