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
This commit is contained in:
jill 2024-03-21 17:46:23 +03:00 committed by GitHub
parent 4c796683c0
commit ee00cb1dd8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 3 deletions

View file

@ -59,6 +59,23 @@ CHyprOpenGLImpl::CHyprOpenGLImpl() {
m_tGlobalTimer.reset(); 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<GLchar> 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) { GLuint CHyprOpenGLImpl::createProgram(const std::string& vert, const std::string& frag, bool dynamic) {
auto vertCompiled = compileShader(GL_VERTEX_SHADER, vert, dynamic); auto vertCompiled = compileShader(GL_VERTEX_SHADER, vert, dynamic);
if (dynamic) { if (dynamic) {
@ -89,8 +106,10 @@ GLuint CHyprOpenGLImpl::createProgram(const std::string& vert, const std::string
GLint ok; GLint ok;
glGetProgramiv(prog, GL_LINK_STATUS, &ok); glGetProgramiv(prog, GL_LINK_STATUS, &ok);
if (dynamic) { if (dynamic) {
if (ok == GL_FALSE) if (ok == GL_FALSE) {
logShaderError(prog, true);
return 0; return 0;
}
} else { } else {
RASSERT(ok != GL_FALSE, "createProgram() failed! GL_LINK_STATUS not OK!"); 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; GLint ok;
glGetShaderiv(shader, GL_COMPILE_STATUS, &ok); glGetShaderiv(shader, GL_COMPILE_STATUS, &ok);
if (dynamic) { if (dynamic) {
if (ok == GL_FALSE) if (ok == GL_FALSE) {
logShaderError(shader, false);
return 0; return 0;
}
} else { } else {
RASSERT(ok != GL_FALSE, "compileShader() failed! GL_COMPILE_STATUS not OK!"); 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); m_sFinalScreenShader.program = createProgram(fragmentShader.starts_with("#version 320 es") ? TEXVERTSRC320 : TEXVERTSRC, fragmentShader, true);
if (!m_sFinalScreenShader.program) { 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; return;
} }

View file

@ -219,6 +219,7 @@ class CHyprOpenGLImpl {
CShader m_sFinalScreenShader; CShader m_sFinalScreenShader;
CTimer m_tGlobalTimer; CTimer m_tGlobalTimer;
void logShaderError(const GLuint&, bool program = false);
GLuint createProgram(const std::string&, const std::string&, bool dynamic = false); GLuint createProgram(const std::string&, const std::string&, bool dynamic = false);
GLuint compileShader(const GLuint&, std::string, bool dynamic = false); GLuint compileShader(const GLuint&, std::string, bool dynamic = false);
void createBGTextureForMonitor(CMonitor*); void createBGTextureForMonitor(CMonitor*);