diff options
author | Stephan Unverwerth <s.unverwerth@serenityos.org> | 2022-08-28 10:51:37 +0200 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-17 22:39:09 -0700 |
commit | a0adbfbf81688421998a342dbbc0236e724a570a (patch) | |
tree | 1c1571ecce1dd52dfa0b6d50f81f5676eb331ced | |
parent | b975569a4009ebb089cd9edc262164177d358a54 (diff) | |
download | serenity-a0adbfbf81688421998a342dbbc0236e724a570a.zip |
LibGL: Implement glCreateShader and glDeleteShader
-rw-r--r-- | Userland/Libraries/LibGL/GL/gl.h | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/GLContext.h | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/Shader.cpp | 26 |
3 files changed, 31 insertions, 5 deletions
diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h index a5fcfede01..5740f79e83 100644 --- a/Userland/Libraries/LibGL/GL/gl.h +++ b/Userland/Libraries/LibGL/GL/gl.h @@ -600,6 +600,9 @@ extern "C" { #define GL_DYNAMIC_DRAW 0x88e8 #define GL_DYNAMIC_READ 0x88e9 #define GL_DYNAMIC_COPY 0x88ea +// Programmable pipeline +#define GL_FRAGMENT_SHADER 0x8B30 +#define GL_VERTEX_SHADER 0x8B31 GLAPI void glBegin(GLenum mode); GLAPI void glClear(GLbitfield mask); diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h index d7a4e2fc75..9b30b44b1b 100644 --- a/Userland/Libraries/LibGL/GLContext.h +++ b/Userland/Libraries/LibGL/GLContext.h @@ -17,6 +17,8 @@ #include <AK/Vector.h> #include <LibGL/Buffer/Buffer.h> #include <LibGL/NameAllocator.h> +#include <LibGL/Shaders/Program.h> +#include <LibGL/Shaders/Shader.h> #include <LibGL/Tex/Texture.h> #include <LibGL/Tex/TextureUnit.h> #include <LibGPU/Device.h> @@ -408,6 +410,11 @@ private: bool m_sampler_config_is_dirty { true }; bool m_light_state_is_dirty { true }; + NameAllocator m_shader_name_allocator; + NameAllocator m_program_name_allocator; + HashMap<GLuint, RefPtr<Shader>> m_allocated_shaders; + HashMap<GLuint, RefPtr<Program>> m_allocated_programs; + struct Listing { template<typename F> diff --git a/Userland/Libraries/LibGL/Shader.cpp b/Userland/Libraries/LibGL/Shader.cpp index e5c1df98f7..eb58a38a78 100644 --- a/Userland/Libraries/LibGL/Shader.cpp +++ b/Userland/Libraries/LibGL/Shader.cpp @@ -11,15 +11,31 @@ namespace GL { GLuint GLContext::gl_create_shader(GLenum shader_type) { - dbgln("gl_create_shader({}) unimplemented ", shader_type); - TODO(); - return 0; + // FIXME: Add support for GL_COMPUTE_SHADER, GL_TESS_CONTROL_SHADER, GL_TESS_EVALUATION_SHADER and GL_GEOMETRY_SHADER. + RETURN_VALUE_WITH_ERROR_IF(shader_type != GL_VERTEX_SHADER + && shader_type != GL_FRAGMENT_SHADER, + GL_INVALID_ENUM, + 0); + + GLuint shader_name; + m_shader_name_allocator.allocate(1, &shader_name); + auto shader = Shader::create(shader_type); + m_allocated_shaders.set(shader_name, shader); + return shader_name; } void GLContext::gl_delete_shader(GLuint shader) { - dbgln("gl_delete_shader({}) unimplemented ", shader); - TODO(); + // "A value of 0 for shader will be silently ignored." (https://registry.khronos.org/OpenGL-Refpages/gl4/html/glDeleteShader.xhtml) + if (shader == 0) + return; + + auto it = m_allocated_shaders.find(shader); + RETURN_WITH_ERROR_IF(it == m_allocated_shaders.end(), GL_INVALID_VALUE); + + // FIXME: According to the spec, we should only flag the shader for deletion here and delete it once it is detached from all programs. + m_allocated_shaders.remove(it); + m_shader_name_allocator.free(shader); } void GLContext::gl_shader_source(GLuint shader, GLsizei count, GLchar const** string, GLint const* length) |