From 2861b786817a8af3be958873f6173ec36fc9e42e Mon Sep 17 00:00:00 2001 From: Shylie Date: Mon, 27 May 2024 11:42:17 -0400 Subject: [PATCH] Update to allow GL_ARB_shader_viewport_layer_array as well. --- source/glad.c | 11 ++++++--- source/glad/glad.h | 13 +++++++--- source/glerminal-private.h | 2 +- source/glerminal.cpp | 50 +++++++++++++++++++++++++------------- 4 files changed, 50 insertions(+), 26 deletions(-) diff --git a/source/glad.c b/source/glad.c index e046964..737ec49 100644 --- a/source/glad.c +++ b/source/glad.c @@ -1,22 +1,23 @@ /* - OpenGL loader generated by glad 0.1.36 on Sun May 26 16:07:25 2024. + OpenGL loader generated by glad 0.1.36 on Mon May 27 15:25:59 2024. Language/Generator: C/C++ Specification: gl APIs: gl=4.5 Profile: core Extensions: - GL_AMD_vertex_shader_layer + GL_AMD_vertex_shader_layer, + GL_ARB_shader_viewport_layer_array Loader: True Local files: False Omit khrplatform: False Reproducible: False Commandline: - --profile="core" --api="gl=4.5" --generator="c" --spec="gl" --extensions="GL_AMD_vertex_shader_layer" + --profile="core" --api="gl=4.5" --generator="c" --spec="gl" --extensions="GL_AMD_vertex_shader_layer,GL_ARB_shader_viewport_layer_array" Online: - https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D4.5&extensions=GL_AMD_vertex_shader_layer + https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D4.5&extensions=GL_AMD_vertex_shader_layer&extensions=GL_ARB_shader_viewport_layer_array */ #include @@ -969,6 +970,7 @@ PFNGLVIEWPORTINDEXEDFPROC glad_glViewportIndexedf = NULL; PFNGLVIEWPORTINDEXEDFVPROC glad_glViewportIndexedfv = NULL; PFNGLWAITSYNCPROC glad_glWaitSync = NULL; int GLAD_GL_AMD_vertex_shader_layer = 0; +int GLAD_GL_ARB_shader_viewport_layer_array = 0; static void load_GL_VERSION_1_0(GLADloadproc load) { if(!GLAD_GL_VERSION_1_0) return; glad_glCullFace = (PFNGLCULLFACEPROC)load("glCullFace"); @@ -1725,6 +1727,7 @@ static void load_GL_VERSION_4_5(GLADloadproc load) { static int find_extensionsGL(void) { if (!get_exts()) return 0; GLAD_GL_AMD_vertex_shader_layer = has_ext("GL_AMD_vertex_shader_layer"); + GLAD_GL_ARB_shader_viewport_layer_array = has_ext("GL_ARB_shader_viewport_layer_array"); free_exts(); return 1; } diff --git a/source/glad/glad.h b/source/glad/glad.h index 12ef68a..6ac72e3 100644 --- a/source/glad/glad.h +++ b/source/glad/glad.h @@ -1,22 +1,23 @@ /* - OpenGL loader generated by glad 0.1.36 on Sun May 26 16:07:25 2024. + OpenGL loader generated by glad 0.1.36 on Mon May 27 15:25:59 2024. Language/Generator: C/C++ Specification: gl APIs: gl=4.5 Profile: core Extensions: - GL_AMD_vertex_shader_layer + GL_AMD_vertex_shader_layer, + GL_ARB_shader_viewport_layer_array Loader: True Local files: False Omit khrplatform: False Reproducible: False Commandline: - --profile="core" --api="gl=4.5" --generator="c" --spec="gl" --extensions="GL_AMD_vertex_shader_layer" + --profile="core" --api="gl=4.5" --generator="c" --spec="gl" --extensions="GL_AMD_vertex_shader_layer,GL_ARB_shader_viewport_layer_array" Online: - https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D4.5&extensions=GL_AMD_vertex_shader_layer + https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D4.5&extensions=GL_AMD_vertex_shader_layer&extensions=GL_ARB_shader_viewport_layer_array */ @@ -3652,6 +3653,10 @@ GLAPI PFNGLTEXTUREBARRIERPROC glad_glTextureBarrier; #define GL_AMD_vertex_shader_layer 1 GLAPI int GLAD_GL_AMD_vertex_shader_layer; #endif +#ifndef GL_ARB_shader_viewport_layer_array +#define GL_ARB_shader_viewport_layer_array 1 +GLAPI int GLAD_GL_ARB_shader_viewport_layer_array; +#endif #ifdef __cplusplus } diff --git a/source/glerminal-private.h b/source/glerminal-private.h index 2ca2459..51258e9 100644 --- a/source/glerminal-private.h +++ b/source/glerminal-private.h @@ -85,8 +85,8 @@ namespace glerminal #ifdef GLERMINAL_OPENGL_DEBUG_CONTEXT mutable std::ofstream m_log; - void log(GLenum type, GLuint id, GLenum severity, const char* message) const; #endif + void log(GLenum type, GLuint id, GLenum severity, const char* message) const; void init_glfw(); void init_gl(); diff --git a/source/glerminal.cpp b/source/glerminal.cpp index f665e9d..1635345 100644 --- a/source/glerminal.cpp +++ b/source/glerminal.cpp @@ -53,8 +53,9 @@ namespace "}"; // note: AMD_vertex_shader_layer support required - constexpr char VERTEX_SHADER_AMD_SOURCE[] = + constexpr char VERTEX_SHADER_ARB_SOURCE[] = "#version 450 core\n" + "#extension GL_ARB_shader_viewport_layer_array : enable\n" "#extension GL_AMD_vertex_shader_layer : enable\n" "layout (location = 0) in vec2 position;\n" "layout (location = 1) in vec2 offset;\n" @@ -81,7 +82,7 @@ namespace "}"; constexpr const char* VERTEX_SHADER_SOURCE_PTR = VERTEX_SHADER_SOURCE; - constexpr const char* VERTEX_SHADER_AMD_SOURCE_PTR = VERTEX_SHADER_AMD_SOURCE; + constexpr const char* VERTEX_SHADER_ARB_SOURCE_PTR = VERTEX_SHADER_ARB_SOURCE; constexpr char GEOMETRY_SHADER_SOURCE[] = "#version 450 core\n" @@ -128,7 +129,7 @@ namespace "}"; // note: AMD_vertex_shader_layer support required - constexpr char FRAGMENT_SHADER_AMD_SOURCE[] = + constexpr char FRAGMENT_SHADER_ARB_SOURCE[] = "#version 450 core\n" "in VS_OUT {\n" " flat int sprite;\n" @@ -142,7 +143,7 @@ namespace "}"; constexpr const char* FRAGMENT_SHADER_SOURCE_PTR = FRAGMENT_SHADER_SOURCE; - constexpr const char* FRAGMENT_SHADER_AMD_SOURCE_PTR = FRAGMENT_SHADER_AMD_SOURCE; + constexpr const char* FRAGMENT_SHADER_ARB_SOURCE_PTR = FRAGMENT_SHADER_ARB_SOURCE; constexpr char SCREEN_VERTEX_SHADER_SOURCE[] = "#version 450 core\n" @@ -363,12 +364,12 @@ namespace glerminal } } -#ifdef GLERMINAL_OPENGL_DEBUG_CONTEXT void glerminal::log(GLenum type, GLuint id, GLenum severity, const char* message) const { +#ifdef GLERMINAL_OPENGL_DEBUG_CONTEXT glDebugMessageInsert(GL_DEBUG_SOURCE_THIRD_PARTY, type, id, severity, -1, message); - } #endif + } void glerminal::init_gl() { @@ -494,11 +495,12 @@ namespace glerminal // -- setup shader program -- // test for features - const bool vertex_shader_layer_supported = glfwExtensionSupported("GL_AMD_vertex_shader_layer"); + const bool vertex_shader_layer_supported = + glfwExtensionSupported("GL_ARB_shader_viewport_layer_array") || glfwExtensionSupported("GL_AMD_vertex_shader_layer"); // compile const unsigned int vertex_shader = glCreateShader(GL_VERTEX_SHADER); - glShaderSource(vertex_shader, 1, &(vertex_shader_layer_supported ? VERTEX_SHADER_AMD_SOURCE_PTR : VERTEX_SHADER_SOURCE_PTR), nullptr); + glShaderSource(vertex_shader, 1, &(vertex_shader_layer_supported ? VERTEX_SHADER_ARB_SOURCE_PTR : VERTEX_SHADER_SOURCE_PTR), nullptr); glCompileShader(vertex_shader); const unsigned int geometry_shader = glCreateShader(GL_GEOMETRY_SHADER); @@ -506,12 +508,12 @@ namespace glerminal glCompileShader(geometry_shader); const unsigned int fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); - glShaderSource(fragment_shader, 1, &(vertex_shader_layer_supported ? FRAGMENT_SHADER_AMD_SOURCE_PTR : FRAGMENT_SHADER_SOURCE_PTR), nullptr); + glShaderSource(fragment_shader, 1, &(vertex_shader_layer_supported ? FRAGMENT_SHADER_ARB_SOURCE_PTR : FRAGMENT_SHADER_SOURCE_PTR), nullptr); glCompileShader(fragment_shader); constexpr int INFO_LOG_SIZE = 512; int success; - char info_log[INFO_LOG_SIZE]; + char info_log[INFO_LOG_SIZE + 1] = {}; // verify compile glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &success); @@ -523,7 +525,9 @@ namespace glerminal glDeleteShader(geometry_shader); glDeleteShader(fragment_shader); - throw std::runtime_error("Could not compile vertex shader."); + log(GL_DEBUG_TYPE_ERROR, 0, 0, "Could not compile vertex shader."); + log(GL_DEBUG_TYPE_ERROR, 0, 0, info_log); + throw std::runtime_error(""); } glGetShaderiv(geometry_shader, GL_COMPILE_STATUS, &success); @@ -535,7 +539,9 @@ namespace glerminal glDeleteShader(geometry_shader); glDeleteShader(fragment_shader); - throw std::runtime_error("Could not compile geometry shader."); + log(GL_DEBUG_TYPE_ERROR, 1, 0, "Could not compile geometry shader."); + log(GL_DEBUG_TYPE_ERROR, 1, 0, info_log); + throw std::runtime_error(""); } glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &success); @@ -547,7 +553,9 @@ namespace glerminal glDeleteShader(geometry_shader); glDeleteShader(fragment_shader); - throw std::runtime_error("Could not compile fragment shader."); + log(GL_DEBUG_TYPE_ERROR, 2, 0, "Could not compile fragment shader."); + log(GL_DEBUG_TYPE_ERROR, 2, 0, info_log); + throw std::runtime_error(""); } // link @@ -572,7 +580,9 @@ namespace glerminal glDeleteProgram(m_program); - throw std::runtime_error("Could not link shader program."); + log(GL_DEBUG_TYPE_ERROR, 3, 0, "Could not link shader program."); + log(GL_DEBUG_TYPE_ERROR, 3, 0, info_log); + throw std::runtime_error(""); } // setup uniforms @@ -599,7 +609,9 @@ namespace glerminal glDeleteShader(screen_vertex_shader); glDeleteShader(screen_fragment_shader); - throw std::runtime_error("Could not compile screen vertex shader."); + log(GL_DEBUG_TYPE_ERROR, 4, 0, "Could not compile screen vertex shader."); + log(GL_DEBUG_TYPE_ERROR, 4, 0, info_log); + throw std::runtime_error(""); } glGetShaderiv(screen_fragment_shader, GL_COMPILE_STATUS, &success); @@ -610,7 +622,9 @@ namespace glerminal glDeleteShader(screen_vertex_shader); glDeleteShader(screen_fragment_shader); - throw std::runtime_error("Could not compile screen fragment shader."); + log(GL_DEBUG_TYPE_ERROR, 5, 0, "Could not compile screen fragment shader."); + log(GL_DEBUG_TYPE_ERROR, 5, 0, info_log); + throw std::runtime_error(""); } // link @@ -627,7 +641,9 @@ namespace glerminal { glDeleteProgram(m_screen_program); - throw std::runtime_error("Could not link screen shader program."); + log(GL_DEBUG_TYPE_ERROR, 6, 0, "Could not link screen shader program."); + log(GL_DEBUG_TYPE_ERROR, 6, 0, info_log); + throw std::runtime_error(""); } // setup uniforms later