diff options
author | Stephan Unverwerth <s.unverwerth@serenityos.org> | 2022-08-28 19:24:58 +0200 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-17 22:39:09 -0700 |
commit | 4ad41e6680bad5397ab9f16110514268673c3ab2 (patch) | |
tree | def69c603495369ba9ca4d458c45acde120cefad /Userland/Libraries/LibGL/Shaders | |
parent | 67b2f8d68dd8a9d0c87551650777700bd8f9d841 (diff) | |
download | serenity-4ad41e6680bad5397ab9f16110514268673c3ab2.zip |
LibGL: Use LibGLSL to compile shaders
Diffstat (limited to 'Userland/Libraries/LibGL/Shaders')
-rw-r--r-- | Userland/Libraries/LibGL/Shaders/Program.cpp | 38 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/Shaders/Program.h | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/Shaders/Shader.cpp | 17 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/Shaders/Shader.h | 6 |
4 files changed, 62 insertions, 3 deletions
diff --git a/Userland/Libraries/LibGL/Shaders/Program.cpp b/Userland/Libraries/LibGL/Shaders/Program.cpp index f55598d75e..8a76a258fd 100644 --- a/Userland/Libraries/LibGL/Shaders/Program.cpp +++ b/Userland/Libraries/LibGL/Shaders/Program.cpp @@ -6,6 +6,7 @@ #include <LibGL/GL/gl.h> #include <LibGL/Shaders/Program.h> +#include <LibGLSL/Linker.h> namespace GL { @@ -49,7 +50,42 @@ ErrorOr<void> Program::attach_shader(Shader& shader) ErrorOr<void> Program::link() { - // FIXME: Implement actual program linker + m_info_log = TRY(String::from_utf8(""sv)); + + GLSL::Linker linker; + + // Link vertex shader objects + + Vector<GLSL::ObjectFile const*> vertex_shader_object_files; + for (auto vertex_shader : m_vertex_shaders) + vertex_shader_object_files.append(vertex_shader->object_file()); + + auto linked_vertex_shader_or_error = linker.link(vertex_shader_object_files); + + if (linked_vertex_shader_or_error.is_error()) { + m_link_status = false; + m_info_log = linker.messages(); + return linked_vertex_shader_or_error.error(); + } + + m_linked_vertex_shader = linked_vertex_shader_or_error.release_value(); + + // Link fragment shader objects + + Vector<GLSL::ObjectFile const*> fragment_shader_object_files; + for (auto fragment_shader : m_fragment_shaders) + fragment_shader_object_files.append(fragment_shader->object_file()); + + auto linked_fragment_shader_or_error = linker.link(fragment_shader_object_files); + + if (linked_fragment_shader_or_error.is_error()) { + m_link_status = false; + m_info_log = linker.messages(); + return linked_fragment_shader_or_error.error(); + } + + m_linked_fragment_shader = linked_fragment_shader_or_error.release_value(); + m_link_status = true; return {}; } diff --git a/Userland/Libraries/LibGL/Shaders/Program.h b/Userland/Libraries/LibGL/Shaders/Program.h index 7c9320cc6a..9c3b217add 100644 --- a/Userland/Libraries/LibGL/Shaders/Program.h +++ b/Userland/Libraries/LibGL/Shaders/Program.h @@ -9,10 +9,12 @@ #include <AK/Error.h> #include <AK/NonnullRefPtr.h> #include <AK/Optional.h> +#include <AK/OwnPtr.h> #include <AK/RefCounted.h> #include <AK/String.h> #include <AK/Vector.h> #include <LibGL/Shaders/Shader.h> +#include <LibGLSL/LinkedShader.h> namespace GL { @@ -31,6 +33,8 @@ private: Vector<NonnullRefPtr<Shader>> m_vertex_shaders; Vector<NonnullRefPtr<Shader>> m_fragment_shaders; Optional<String> m_info_log; + OwnPtr<GLSL::LinkedShader> m_linked_vertex_shader; + OwnPtr<GLSL::LinkedShader> m_linked_fragment_shader; }; } diff --git a/Userland/Libraries/LibGL/Shaders/Shader.cpp b/Userland/Libraries/LibGL/Shaders/Shader.cpp index 8de48e6e07..501140aa0f 100644 --- a/Userland/Libraries/LibGL/Shaders/Shader.cpp +++ b/Userland/Libraries/LibGL/Shaders/Shader.cpp @@ -6,6 +6,7 @@ #include <AK/String.h> #include <LibGL/Shaders/Shader.h> +#include <LibGLSL/Compiler.h> namespace GL { @@ -23,8 +24,22 @@ ErrorOr<void> Shader::add_source(StringView source_code) ErrorOr<void> Shader::compile() { - // FIXME: Implement actual shader compilation + m_info_log = TRY(String::from_utf8(""sv)); + + GLSL::Compiler compiler; + + auto object_file_or_error = compiler.compile(m_sources); + + if (object_file_or_error.is_error()) { + m_compile_status = false; + m_info_log = compiler.messages(); + return object_file_or_error.error(); + } + + m_object_file = object_file_or_error.release_value(); + m_compile_status = true; + return {}; } diff --git a/Userland/Libraries/LibGL/Shaders/Shader.h b/Userland/Libraries/LibGL/Shaders/Shader.h index 108298c33a..c4662ecbd6 100644 --- a/Userland/Libraries/LibGL/Shaders/Shader.h +++ b/Userland/Libraries/LibGL/Shaders/Shader.h @@ -9,12 +9,14 @@ #include <AK/Error.h> #include <AK/NonnullRefPtr.h> #include <AK/Optional.h> +#include <AK/OwnPtr.h> #include <AK/RefCounted.h> #include <AK/RefPtr.h> #include <AK/String.h> #include <AK/StringView.h> #include <AK/Vector.h> -#include <LibGL/GL/glplatform.h> +#include <LibGL/GL/gl.h> +#include <LibGLSL/ObjectFile.h> namespace GL { @@ -27,6 +29,7 @@ public: ErrorOr<void> compile(); GLenum type() const { return m_type; } bool compile_status() const { return m_compile_status; } + GLSL::ObjectFile const* object_file() const { return m_object_file.ptr(); } size_t info_log_length() const; size_t combined_source_length() const; @@ -41,6 +44,7 @@ private: GLenum m_type; bool m_compile_status { false }; Optional<String> m_info_log; + OwnPtr<GLSL::ObjectFile> m_object_file; }; } |