LibGL: Implement glGetProgramiv

This commit is contained in:
Stephan Unverwerth 2022-08-28 16:34:17 +02:00 committed by Andrew Kaster
parent 424e0a2792
commit 1b7b6e6c91
Notes: sideshowbarker 2024-07-17 09:56:35 +09:00
6 changed files with 56 additions and 0 deletions

View file

@ -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
}

View file

@ -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);

View file

@ -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();

View file

@ -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();
}
}
}

View file

@ -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;
}
}

View file

@ -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;
};
}