Shader.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2022, Stephan Unverwerth <s.unverwerth@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Error.h>
  8. #include <AK/NonnullRefPtr.h>
  9. #include <AK/Optional.h>
  10. #include <AK/OwnPtr.h>
  11. #include <AK/RefCounted.h>
  12. #include <AK/RefPtr.h>
  13. #include <AK/String.h>
  14. #include <AK/StringView.h>
  15. #include <AK/Vector.h>
  16. #include <LibGL/GL/gl.h>
  17. #include <LibGLSL/ObjectFile.h>
  18. namespace GL {
  19. class Shader final : public RefCounted<Shader> {
  20. public:
  21. static NonnullRefPtr<Shader> create(GLenum shader_type);
  22. void clear_sources() { m_sources.clear(); }
  23. ErrorOr<void> add_source(StringView source_code);
  24. ErrorOr<void> compile();
  25. GLenum type() const { return m_type; }
  26. bool compile_status() const { return m_compile_status; }
  27. GLSL::ObjectFile const* object_file() const { return m_object_file.ptr(); }
  28. size_t info_log_length() const;
  29. size_t combined_source_length() const;
  30. private:
  31. explicit Shader(GLenum shader_type)
  32. : m_type { shader_type }
  33. {
  34. }
  35. Vector<String> m_sources;
  36. GLenum m_type;
  37. bool m_compile_status { false };
  38. Optional<String> m_info_log;
  39. OwnPtr<GLSL::ObjectFile> m_object_file;
  40. };
  41. }