diff options
author | Stephan Unverwerth <s.unverwerth@serenityos.org> | 2022-08-28 10:36:31 +0200 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-17 22:39:09 -0700 |
commit | b975569a4009ebb089cd9edc262164177d358a54 (patch) | |
tree | de1c5fbc343a9b238a003931c5a95781af0453ba /Userland/Libraries/LibGL | |
parent | cd7d2c344657a1926c74764c5216f582e78070a0 (diff) | |
download | serenity-b975569a4009ebb089cd9edc262164177d358a54.zip |
LibGL: Add Shader and Program class stubs
Diffstat (limited to 'Userland/Libraries/LibGL')
-rw-r--r-- | Userland/Libraries/LibGL/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/Shaders/Program.cpp | 28 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/Shaders/Program.h | 28 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/Shaders/Shader.cpp | 30 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/Shaders/Shader.h | 38 |
5 files changed, 126 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGL/CMakeLists.txt b/Userland/Libraries/LibGL/CMakeLists.txt index 1b53acb7cb..7b29573dee 100644 --- a/Userland/Libraries/LibGL/CMakeLists.txt +++ b/Userland/Libraries/LibGL/CMakeLists.txt @@ -11,6 +11,8 @@ set(SOURCES Matrix.cpp NameAllocator.cpp Shader.cpp + Shaders/Program.cpp + Shaders/Shader.cpp Stencil.cpp Tex/Texture2D.cpp Texture.cpp diff --git a/Userland/Libraries/LibGL/Shaders/Program.cpp b/Userland/Libraries/LibGL/Shaders/Program.cpp new file mode 100644 index 0000000000..e432b24680 --- /dev/null +++ b/Userland/Libraries/LibGL/Shaders/Program.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022, Stephan Unverwerth <s.unverwerth@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibGL/Shaders/Program.h> + +namespace GL { + +NonnullRefPtr<Program> Program::create() +{ + return adopt_ref(*new Program()); +} + +ErrorOr<void> Program::attach_shader(Shader&) +{ + TODO(); + return {}; +} + +ErrorOr<void> Program::link() +{ + TODO(); + return {}; +} + +} diff --git a/Userland/Libraries/LibGL/Shaders/Program.h b/Userland/Libraries/LibGL/Shaders/Program.h new file mode 100644 index 0000000000..3e619c3b2f --- /dev/null +++ b/Userland/Libraries/LibGL/Shaders/Program.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022, Stephan Unverwerth <s.unverwerth@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/NonnullRefPtr.h> +#include <AK/RefCounted.h> +#include <AK/Vector.h> +#include <LibGL/Shaders/Shader.h> + +namespace GL { + +class Program final : public RefCounted<Program> { +public: + static NonnullRefPtr<Program> create(); + + ErrorOr<void> attach_shader(Shader&); + ErrorOr<void> link(); + +private: + Vector<NonnullRefPtr<Shader>> m_vertex_shaders; + Vector<NonnullRefPtr<Shader>> m_fragment_shaders; +}; + +} diff --git a/Userland/Libraries/LibGL/Shaders/Shader.cpp b/Userland/Libraries/LibGL/Shaders/Shader.cpp new file mode 100644 index 0000000000..007a4fc76a --- /dev/null +++ b/Userland/Libraries/LibGL/Shaders/Shader.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022, Stephan Unverwerth <s.unverwerth@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <AK/String.h> +#include <LibGL/Shaders/Shader.h> + +namespace GL { + +NonnullRefPtr<Shader> Shader::create(GLenum shader_type) +{ + return adopt_ref(*new Shader(shader_type)); +} + +ErrorOr<void> Shader::add_source(StringView source_code) +{ + auto source_code_content = TRY(String::from_utf8(source_code)); + TRY(m_sources.try_append(move(source_code_content))); + return {}; +} + +ErrorOr<void> Shader::compile() +{ + TODO(); + return {}; +} + +} diff --git a/Userland/Libraries/LibGL/Shaders/Shader.h b/Userland/Libraries/LibGL/Shaders/Shader.h new file mode 100644 index 0000000000..c4a1a7d70f --- /dev/null +++ b/Userland/Libraries/LibGL/Shaders/Shader.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022, Stephan Unverwerth <s.unverwerth@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/Error.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> + +namespace GL { + +class Shader final : public RefCounted<Shader> { +public: + static NonnullRefPtr<Shader> create(GLenum shader_type); + + void clear_sources() { m_sources.clear(); } + ErrorOr<void> add_source(StringView source_code); + ErrorOr<void> compile(); + GLenum type() const { return m_type; } + +private: + explicit Shader(GLenum shader_type) + : m_type { shader_type } + { + } + + Vector<String> m_sources; + GLenum m_type; +}; + +} |