diff options
author | Stephan Unverwerth <s.unverwerth@serenityos.org> | 2022-08-28 16:34:17 +0200 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-17 22:39:09 -0700 |
commit | 1b7b6e6c918406613e6a9ea2226725c59bc8b6ee (patch) | |
tree | 9930bb4f5e0711989eca0e032719404f0d91c58a /Userland/Libraries/LibGL | |
parent | 424e0a279278437791271fc40529120ce8d14655 (diff) | |
download | serenity-1b7b6e6c918406613e6a9ea2226725c59bc8b6ee.zip |
LibGL: Implement glGetProgramiv
Diffstat (limited to 'Userland/Libraries/LibGL')
-rw-r--r-- | Userland/Libraries/LibGL/GL/gl.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/GLAPI.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/GLContext.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/Shader.cpp | 35 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/Shaders/Program.cpp | 9 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/Shaders/Program.h | 4 |
6 files changed, 56 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h index ad34de16b9..0cfe285af4 100644 --- a/Userland/Libraries/LibGL/GL/gl.h +++ b/Userland/Libraries/LibGL/GL/gl.h @@ -606,6 +606,7 @@ extern "C" { #define GL_SHADER_TYPE 0x8B4F #define GL_DELETE_STATUS 0x8B80 #define GL_COMPILE_STATUS 0x8B81 +#define GL_LINK_STATUS 0x8B82 #define GL_INFO_LOG_LENGTH 0x8B84 #define GL_SHADER_SOURCE_LENGTH 0x8B88 @@ -832,6 +833,7 @@ GLAPI void glDeleteProgram(GLuint program); GLAPI void glAttachShader(GLuint program, GLuint shader); GLAPI void glLinkProgram(GLuint program); GLAPI void glUseProgram(GLuint program); +GLAPI void glGetProgramiv(GLuint program, GLenum pname, GLint* params); #ifdef __cplusplus } diff --git a/Userland/Libraries/LibGL/GLAPI.cpp b/Userland/Libraries/LibGL/GLAPI.cpp index ab6e464a0a..293d18e900 100644 --- a/Userland/Libraries/LibGL/GLAPI.cpp +++ b/Userland/Libraries/LibGL/GLAPI.cpp @@ -499,6 +499,11 @@ void glGetMaterialiv(GLenum face, GLenum pname, GLint* params) g_gl_context->gl_get_material(face, pname, params, GL_INT); } +void glGetProgramiv(GLuint program, GLenum pname, GLint* params) +{ + g_gl_context->gl_get_program(program, pname, params); +} + GLubyte const* glGetString(GLenum name) { return g_gl_context->gl_get_string(name); diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h index 3d5431609e..e0cecbaddc 100644 --- a/Userland/Libraries/LibGL/GLContext.h +++ b/Userland/Libraries/LibGL/GLContext.h @@ -241,6 +241,7 @@ public: void gl_attach_shader(GLuint program, GLuint shader); void gl_link_program(GLuint program); void gl_use_program(GLuint program); + void gl_get_program(GLuint program, GLenum pname, GLint* params); private: void sync_device_config(); diff --git a/Userland/Libraries/LibGL/Shader.cpp b/Userland/Libraries/LibGL/Shader.cpp index 611191be2d..8742c1e8cb 100644 --- a/Userland/Libraries/LibGL/Shader.cpp +++ b/Userland/Libraries/LibGL/Shader.cpp @@ -177,4 +177,39 @@ void GLContext::gl_use_program(GLuint program) m_current_program = it->value; } +void GLContext::gl_get_program(GLuint program, GLenum pname, GLint* params) +{ + auto it = m_allocated_programs.find(program); + + // FIXME: implement check "GL_INVALID_VALUE is generated if program is not a value generated by OpenGL." + RETURN_WITH_ERROR_IF(it == m_allocated_programs.end(), GL_INVALID_OPERATION); + // FIXME: implement check "GL_INVALID_OPERATION is generated if pname is GL_GEOMETRY_VERTICES_OUT, GL_GEOMETRY_INPUT_TYPE, or GL_GEOMETRY_OUTPUT_TYPE, and program does not contain a geometry shader." + + // FIXME: implement all the other allowed pname values (https://registry.khronos.org/OpenGL-Refpages/gl4/html/glGetProgram.xhtml) + RETURN_WITH_ERROR_IF(pname != GL_DELETE_STATUS + && pname != GL_LINK_STATUS + && pname != GL_INFO_LOG_LENGTH, + GL_INVALID_ENUM); + + // FIXME: implement check "GL_INVALID_OPERATION is generated if pname is GL_COMPUTE_WORK_GROUP_SIZE and program does not contain a binary for the compute shader stage." + + switch (pname) { + case GL_DELETE_STATUS: + // FIXME: Return the actual delete status once we implement this missing feature + *params = GL_FALSE; + break; + + case GL_LINK_STATUS: + *params = it->value->link_status() ? GL_TRUE : GL_FALSE; + break; + + case GL_INFO_LOG_LENGTH: + *params = it->value->info_log_length(); + break; + + default: + VERIFY_NOT_REACHED(); + } +} + } diff --git a/Userland/Libraries/LibGL/Shaders/Program.cpp b/Userland/Libraries/LibGL/Shaders/Program.cpp index 28c5cc8069..f55598d75e 100644 --- a/Userland/Libraries/LibGL/Shaders/Program.cpp +++ b/Userland/Libraries/LibGL/Shaders/Program.cpp @@ -54,4 +54,13 @@ ErrorOr<void> Program::link() return {}; } +size_t Program::info_log_length() const +{ + if (!m_info_log.has_value()) + return 0; + + // Per the spec we return the size including the null terminator + return m_info_log.value().bytes().size() + 1; +} + } diff --git a/Userland/Libraries/LibGL/Shaders/Program.h b/Userland/Libraries/LibGL/Shaders/Program.h index 3cdf377d87..7c9320cc6a 100644 --- a/Userland/Libraries/LibGL/Shaders/Program.h +++ b/Userland/Libraries/LibGL/Shaders/Program.h @@ -8,7 +8,9 @@ #include <AK/Error.h> #include <AK/NonnullRefPtr.h> +#include <AK/Optional.h> #include <AK/RefCounted.h> +#include <AK/String.h> #include <AK/Vector.h> #include <LibGL/Shaders/Shader.h> @@ -22,11 +24,13 @@ public: ErrorOr<void> attach_shader(Shader&); ErrorOr<void> link(); bool link_status() const { return m_link_status; } + size_t info_log_length() const; private: bool m_link_status { false }; Vector<NonnullRefPtr<Shader>> m_vertex_shaders; Vector<NonnullRefPtr<Shader>> m_fragment_shaders; + Optional<String> m_info_log; }; } |