20 #ifndef ANTKEEPER_GL_SHADER_TEMPLATE_HPP
21 #define ANTKEEPER_GL_SHADER_TEMPLATE_HPP
29 #include <unordered_map>
30 #include <unordered_set>
125 [[nodiscard]] std::unique_ptr<gl::shader_program>
build(
const dictionary_type& definitions = {})
const;
130 return !m_vertex_directives.empty();
136 return !m_fragment_directives.empty();
142 return !m_geometry_directives.empty();
153 [[nodiscard]]
inline constexpr std::size_t
hash() const noexcept
159 void find_directives();
162 void replace_define_directives(
const dictionary_type& definitions)
const;
165 std::unordered_set<std::size_t> m_vertex_directives;
166 std::unordered_set<std::size_t> m_fragment_directives;
167 std::unordered_set<std::size_t> m_geometry_directives;
168 std::multimap<std::string, std::size_t> m_define_directives;
169 std::size_t m_hash{0};
170 std::vector<std::shared_ptr<text_file>> m_include_files;
Template used to for generating one or more shader variants from a single source.
std::string configure(gl::shader_stage stage, const dictionary_type &definitions={}) const
Configures shader object source code for a given shader stage and template dictionary.
constexpr std::size_t hash() const noexcept
Returns a hash of the template source code.
std::unique_ptr< gl::shader_program > build(const dictionary_type &definitions={}) const
Configures and compiles shader objects, then links them into a shader program.
std::unordered_map< std::string, std::string > dictionary_type
Container of definitions used to generate #pragma define <key> <value> directives.
bool has_geometry_directive() const noexcept
Returns true if the template source contains one or more #pragma geometry directive.
constexpr shader_template() noexcept=default
Constructs an empty shader template.
bool has_define_directive(const std::string &key) const
Returns true if the template source contains one or more instance of #pragma define <key>.
bool has_vertex_directive() const noexcept
Returns true if the template source contains one or more #pragma vertex directive.
void source(const text_file &source_code)
Replaces the source code of the shader template.
std::unique_ptr< gl::shader_object > compile(gl::shader_stage stage, const dictionary_type &definitions={}) const
Configures and compiles a shader object.
bool has_fragment_directive() const noexcept
Returns true if the template source contains one or more #pragma fragment directive.
Graphics library interface.
shader_stage
Enumerates all supported shader stages.