From ee00cb1dd87115f7c2b0fb41268e88050f28e7ed Mon Sep 17 00:00:00 2001 From: jill Date: Thu, 21 Mar 2024 17:46:23 +0300 Subject: [PATCH] opengl: report shader compilation errors from screen_shader (#5138) * opengl: report shader compilation errors from screen_shader * opengl: prefer .data() * opengl: move shader error logging to logError * opengl: quick glGetShaderiv -> glGetProgramiv fix * opengl: typo fix * opengl: format fixes * opengl: minor compile fixes * opengl: logError -> logShaderError --- src/render/OpenGL.cpp | 28 +++++++++++++++++++++++++--- src/render/OpenGL.hpp | 1 + 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index d34a90b0..df03e8e9 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -59,6 +59,23 @@ CHyprOpenGLImpl::CHyprOpenGLImpl() { m_tGlobalTimer.reset(); } +void CHyprOpenGLImpl::logShaderError(const GLuint& shader, bool program) { + GLint maxLength = 0; + if (program) + glGetProgramiv(shader, GL_INFO_LOG_LENGTH, &maxLength); + else + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength); + + std::vector errorLog(maxLength); + if (program) + glGetProgramInfoLog(shader, maxLength, &maxLength, errorLog.data()); + else + glGetShaderInfoLog(shader, maxLength, &maxLength, errorLog.data()); + std::string errorStr(errorLog.begin(), errorLog.end()); + + g_pConfigManager->addParseError((program ? "Screen shader parser: Error linking program:" : "Screen shader parser: Error compiling shader: ") + errorStr); +} + GLuint CHyprOpenGLImpl::createProgram(const std::string& vert, const std::string& frag, bool dynamic) { auto vertCompiled = compileShader(GL_VERTEX_SHADER, vert, dynamic); if (dynamic) { @@ -89,8 +106,10 @@ GLuint CHyprOpenGLImpl::createProgram(const std::string& vert, const std::string GLint ok; glGetProgramiv(prog, GL_LINK_STATUS, &ok); if (dynamic) { - if (ok == GL_FALSE) + if (ok == GL_FALSE) { + logShaderError(prog, true); return 0; + } } else { RASSERT(ok != GL_FALSE, "createProgram() failed! GL_LINK_STATUS not OK!"); } @@ -108,9 +127,12 @@ GLuint CHyprOpenGLImpl::compileShader(const GLuint& type, std::string src, bool GLint ok; glGetShaderiv(shader, GL_COMPILE_STATUS, &ok); + if (dynamic) { - if (ok == GL_FALSE) + if (ok == GL_FALSE) { + logShaderError(shader, false); return 0; + } } else { RASSERT(ok != GL_FALSE, "compileShader() failed! GL_COMPILE_STATUS not OK!"); } @@ -550,7 +572,7 @@ void CHyprOpenGLImpl::applyScreenShader(const std::string& path) { m_sFinalScreenShader.program = createProgram(fragmentShader.starts_with("#version 320 es") ? TEXVERTSRC320 : TEXVERTSRC, fragmentShader, true); if (!m_sFinalScreenShader.program) { - g_pConfigManager->addParseError("Screen shader parser: Screen shader parse failed"); + // Error will have been sent by now by the underlying cause return; } diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index f6dff805..b18e9108 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -219,6 +219,7 @@ class CHyprOpenGLImpl { CShader m_sFinalScreenShader; CTimer m_tGlobalTimer; + void logShaderError(const GLuint&, bool program = false); GLuint createProgram(const std::string&, const std::string&, bool dynamic = false); GLuint compileShader(const GLuint&, std::string, bool dynamic = false); void createBGTextureForMonitor(CMonitor*);