In the middle of multithreading parsers.
This commit is contained in:
122
include/assets/file_parsers/glsl_parser.hpp
Normal file
122
include/assets/file_parsers/glsl_parser.hpp
Normal file
@@ -0,0 +1,122 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#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,
|
||||
std::mutex& m_store_mutex
|
||||
);
|
||||
|
||||
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;
|
||||
std::mutex* m_store_mutex;
|
||||
shader_source_data m_buffer{};
|
||||
std::vector<std::string_view> m_value_buffer{};
|
||||
std::vector<std::size_t> m_declaration_value_count_buffer{};
|
||||
std::array<std::size_t, 4> m_declaration_type_index_buffer{};
|
||||
};
|
||||
|
||||
[[nodiscard]] static std::error_code read_file(
|
||||
const std::filesystem::path& filename,
|
||||
std::vector<char>& source
|
||||
);
|
||||
|
||||
static void tokenize_declarations(
|
||||
std::string_view source,
|
||||
std::vector<std::string_view>& value_buffer,
|
||||
std::vector<std::size_t>& declaration_value_count_buffer,
|
||||
std::array<std::size_t, 4>& declaration_type_index_buffer
|
||||
);
|
||||
|
||||
static [[nodiscard]] bool parse_metadata_from_tokens(
|
||||
const std::vector<std::string_view>& value_buffer,
|
||||
const std::vector<std::size_t>& declaration_value_count_buffer,
|
||||
const std::array<std::size_t, 4>& declaration_type_index_buffer,
|
||||
shader_source_data& buffer
|
||||
);
|
||||
|
||||
static void remove_metadata_declarations(
|
||||
const std::vector<std::string_view>& value_buffer,
|
||||
const std::vector<std::size_t>& declaration_value_count_buffer,
|
||||
const std::array<std::size_t, 4>& declaration_type_index_buffer,
|
||||
std::vector<char>& source
|
||||
);
|
||||
|
||||
[[nodiscard]] static bool parse_geometry_declaration(
|
||||
std::span<const std::string_view> values,
|
||||
model_geometry::types& geometry_type
|
||||
);
|
||||
|
||||
[[nodiscard]] static bool parse_stage_declaration(
|
||||
std::span<const std::string_view> values,
|
||||
shader_components::stage& stage
|
||||
);
|
||||
|
||||
[[nodiscard]] static bool parse_components_declaration(
|
||||
std::span<const std::string_view> values,
|
||||
shader_source_data& buffer
|
||||
);
|
||||
|
||||
[[nodiscard]] static bool parse_static_enable_declaration(
|
||||
std::span<const std::string_view> values,
|
||||
shader_source_data& buffer
|
||||
);
|
||||
|
||||
[[nodiscard]] static bool parse_dynamic_enable_declaration(
|
||||
std::span<const std::string_view> values,
|
||||
shader_source_data& buffer
|
||||
);
|
||||
|
||||
[[nodiscard]] static bool parse_component_tokens(
|
||||
std::span<const std::string_view> values,
|
||||
model_geometry::types geometry_type,
|
||||
shader_components::flags& components
|
||||
);
|
||||
|
||||
private:
|
||||
std::vector<std::string_view> m_value_token_buffer;
|
||||
std::vector<std::size_t> m_declaration_token_count_buffer;
|
||||
std::array<std::size_t, 4> m_declaration_type_index_buffer;
|
||||
std::vector<lookup_type::const_pointer> m_path_buffer;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user