9 #ifndef OGLPLUS_UTILS_PROGRAM_FILE_HPP
10 #define OGLPLUS_UTILS_PROGRAM_FILE_HPP
12 #include "../gl_api/enum_types.hpp"
13 #include "../glsl/source_ref.hpp"
20 namespace eagine::oglp {
22 class shader_source_block {
24 structured_memory_block<const shader_source_header> _header;
30 shader_source_block(
const shader_source_header* ptr)
31 : _header(
as_bytes(view_one(ptr))) {}
33 auto is_valid() const noexcept ->
bool {
34 return _header->magic.is_valid();
37 auto type() const noexcept -> shader_type {
38 EAGINE_ASSERT(is_valid());
39 return shader_type(_header->shader_type);
43 EAGINE_ASSERT(is_valid());
45 _header->source_text.data(),
span_size(_header->source_text.size())};
48 operator glsl_source_ref() const noexcept {
49 EAGINE_ASSERT(is_valid());
50 return glsl_source_ref(_header->source_text);
54 class shader_source_file
55 : protected_member<file_contents>
56 ,
public shader_source_block {
58 shader_source_file(file_contents&& fc)
59 : protected_member<file_contents>(std::move(fc))
60 , shader_source_block(get_the_member()) {}
63 : shader_source_file(file_contents(path)) {}
65 shader_source_file(
const std::string& path)
69 class program_source_block {
71 structured_memory_block<const program_source_header> _header;
77 auto is_valid() const noexcept ->
bool {
78 return _header->magic.is_valid();
81 auto shader_source_count() const noexcept ->
span_size_t {
82 EAGINE_ASSERT(is_valid());
83 return _header->shader_sources.size();
86 auto shader_source(
span_size_t index)
const noexcept
87 -> shader_source_block {
88 EAGINE_ASSERT(is_valid());
89 EAGINE_ASSERT(index < _header->shader_sources.size());
90 return {_header->shader_sources[index]};
94 class program_source_file
95 : protected_member<file_contents>
96 ,
public program_source_block {
98 program_source_file(file_contents&& fc)
99 : protected_member<file_contents>(std::move(fc))
100 , program_source_block(get_the_member()) {}
103 : program_source_file(file_contents(path)) {}
105 program_source_file(
const std::string& path)
111 #endif // OGLPLUS_UTILS_PROGRAM_FILE_HPP