#pragma once #include #include "assets/path_id_lookups.hpp" #include "assets/data_stores/shader_source_store.hpp" #include "assets/data/shader_source_data.hpp" namespace assets { struct glsl_parser { static constexpr auto name = std::string_view("glsl"); using data_type = shader_source_data; using store_type = shader_source_store; using lookup_type = shader_source_id_lookup; [[nodiscard]] std::error_code prefetch( path_id_lookups& lookups ); [[nodiscard]] std::error_code load( const path_id_lookups& lookups, store_type& store, bool pedantic = false ); protected: class parser_context { public: parser_context(store_type& m_store); void operator()(lookup_type::const_pointer entry) noexcept; protected: void reset(); void tokenize_declarations(); [[nodiscard]] bool parse_metadata_from_tokens(); void remove_metadata_declarations(); private: store_type* m_store; shader_source_data m_buffer{}; std::vector m_value_buffer{}; std::vector m_declaration_value_count_buffer{}; std::array m_declaration_type_index_buffer{}; }; [[nodiscard]] static std::error_code read_file( const std::filesystem::path& filename, std::vector& source ); [[nodiscard]] static bool parse_geometry_declaration( std::span values, shader_source_data::metadata& meta ); [[nodiscard]] static bool parse_stage_declaration( std::span values, shader_source_data::metadata& meta ); [[nodiscard]] static bool parse_components_declaration( std::span values, shader_source_data::metadata& meta ); [[nodiscard]] static bool parse_static_enable_declaration( std::span values, shader_source_data::metadata& meta ); [[nodiscard]] static bool parse_dynamic_enable_declaration( std::span values, shader_source_data::metadata& meta ); [[nodiscard]] static bool parse_component_tokens( std::span values, model_geometry::types geometry_type, shader_components::flags& components ); private: std::vector m_value_token_buffer; std::vector m_declaration_token_count_buffer; std::array m_declaration_type_index_buffer; std::vector m_path_buffer; }; }