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
This commit is contained in:
scorpion-26 2023-03-05 15:05:30 +01:00 committed by GitHub
parent dc7d783d14
commit de5f1b2a83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View file

@ -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) {
@ -312,6 +314,13 @@ void CHyprOpenGLImpl::applyScreenShader(const std::string& path) {
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);

View file

@ -3,6 +3,7 @@
#include "../defines.hpp"
#include "../helpers/Monitor.hpp"
#include "../helpers/Color.hpp"
#include "../helpers/Timer.hpp"
#include <list>
#include <unordered_map>
@ -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);

View file

@ -37,6 +37,8 @@ class CShader {
GLint gradientLength;
GLint angle;
GLint time;
GLint getUniformLocation(const std::string&);
void destroy();