196 lines
5.6 KiB
C++
196 lines
5.6 KiB
C++
#pragma once
|
|
|
|
#include <system_error>
|
|
#include <vector>
|
|
#include <filesystem>
|
|
|
|
#include "assets/data_loaders/glsl_loader.hpp"
|
|
#include "../assets/dynamic_read_buffers"
|
|
#include "opengl/handles/mesh_handle.hpp"
|
|
#include "opengl/handles/material_handle.hpp"
|
|
#include "opengl/handles/point_cloud_handle.hpp"
|
|
#include "SFML/Window.hpp"
|
|
|
|
#include "opengl/data/mesh_data.hpp"
|
|
#include "opengl/data/material_data.hpp"
|
|
#include "opengl/data/point_cloud_data.hpp"
|
|
#include "opengl/data/shader_program_data.hpp"
|
|
|
|
#include "assets/dynamic_data_loaders/dynamic_mesh_loader.hpp"
|
|
#include "assets/data_loaders/obj_loader.hpp"
|
|
#include "assets/data_loaders/stl_loader.hpp"
|
|
|
|
#include "assets/dynamic_data_loaders/dynamic_point_cloud_loader.hpp"
|
|
#include "assets/data_loaders/kitti_loader.hpp"
|
|
#include "assets/data_loaders/uos_loader.hpp"
|
|
#include "assets/data_loaders/uos_normal_loader.hpp"
|
|
#include "assets/data_loaders/uos_rgb_loader.hpp"
|
|
#include "assets/data_loaders/uosr_loader.hpp"
|
|
#include "geometry/aabb.hpp"
|
|
#include "opengl/data/shader_data.hpp"
|
|
|
|
|
|
namespace viewer
|
|
{
|
|
|
|
class asset_loader
|
|
{
|
|
public:
|
|
using dynamic_mesh_loader_type = dynamic_mesh_loader<
|
|
obj_loader, stl_loader
|
|
>;
|
|
|
|
using dynamic_point_cloud_loader_type = dynamic_point_cloud_loader<
|
|
kitti_loader,
|
|
uos_loader,
|
|
uos_normal_loader,
|
|
uos_rgb_loader,
|
|
uos_loader,
|
|
uosr_loader
|
|
>;
|
|
|
|
struct dynamic_point_cloud_handle_type
|
|
{
|
|
zgl::point_cloud_handle handle;
|
|
aabb bounding_box;
|
|
components::point_cloud_vertex::flags components;
|
|
};
|
|
|
|
struct dynamic_material_handle_type
|
|
{
|
|
zgl::material_handle handle;
|
|
material_component::flags components;
|
|
};
|
|
|
|
struct dynamic_mesh_handle_type
|
|
{
|
|
zgl::mesh_handle handle;
|
|
aabb bounding_box;
|
|
components::mesh_vertex::flags components;
|
|
};
|
|
|
|
using material_reference_entry_type = std::pair<ztu::u32, ztu::u32>;
|
|
|
|
std::error_code init(
|
|
components::mesh_vertex::flags enabled_mesh_components,
|
|
material_component::flags enabled_material_components,
|
|
components::point_cloud_vertex::flags enabled_point_cloud_components,
|
|
const dynamic_material_data& default_material
|
|
);
|
|
|
|
std::error_code load_shader(
|
|
GLenum type,
|
|
const std::filesystem::path& filename,
|
|
zgl::shader_handle& shader_handle
|
|
);
|
|
|
|
std::error_code build_shader_program(
|
|
const zgl::shader_handle& vertex_shader,
|
|
const zgl::shader_handle& geometry_shader,
|
|
const zgl::shader_handle& fragment_shader,
|
|
zgl::shader_program_handle& shader_program_handle
|
|
);
|
|
|
|
std::error_code load_asset(
|
|
const std::string& format,
|
|
const std::filesystem::path& filename,
|
|
std::vector<std::pair<dynamic_mesh_handle_type, dynamic_material_handle_type>>& dynamic_mesh_handles,
|
|
std::vector<dynamic_point_cloud_handle_type>& dynamic_point_cloud_handles
|
|
);
|
|
|
|
std::error_code load_asset_directory(
|
|
const std::string& format,
|
|
const std::filesystem::path& path,
|
|
std::vector<std::pair<dynamic_mesh_handle_type, dynamic_material_handle_type>>& dynamic_mesh_handles,
|
|
std::vector<dynamic_point_cloud_handle_type>& dynamic_point_cloud_handles
|
|
);
|
|
|
|
bool unload(const zgl::shader_program_handle& shader_handle);
|
|
|
|
void unload_shader_data();
|
|
|
|
bool unload(const zgl::mesh_handle& mesh_handle);
|
|
|
|
bool unload(const zgl::point_cloud_handle& point_cloud_handle);
|
|
|
|
|
|
protected:
|
|
std::error_code load_mesh(
|
|
const std::string& format,
|
|
const std::filesystem::path& filename,
|
|
std::vector<std::pair<dynamic_mesh_handle_type, dynamic_material_handle_type>>& dynamic_mesh_handles
|
|
);
|
|
|
|
std::error_code load_point_cloud(
|
|
const std::string& format,
|
|
const std::filesystem::path& filename,
|
|
std::vector<dynamic_point_cloud_handle_type>& dynamic_point_cloud_handles
|
|
);
|
|
|
|
std::error_code load_mesh_directory(
|
|
const std::string& format,
|
|
const std::filesystem::path& path,
|
|
std::vector<std::pair<dynamic_mesh_handle_type, dynamic_material_handle_type>>& dynamic_mesh_handles
|
|
);
|
|
|
|
std::error_code load_point_cloud_directory(
|
|
const std::string& format,
|
|
const std::filesystem::path& path,
|
|
std::vector<dynamic_point_cloud_handle_type>& dynamic_point_cloud_handles
|
|
);
|
|
|
|
std::error_code process_materials_and_meshes(
|
|
std::vector<std::pair<dynamic_mesh_handle_type, dynamic_material_handle_type>>& dynamic_mesh_handles
|
|
);
|
|
|
|
std::error_code process_point_clouds(
|
|
std::vector<dynamic_point_cloud_handle_type>& dynamic_point_cloud_handles
|
|
);
|
|
|
|
|
|
std::error_code create_gl_materials();
|
|
|
|
void create_gl_meshes(std::span<const material_reference_entry_type> material_references);
|
|
|
|
void create_gl_point_clouds();
|
|
|
|
std::error_code create_gl_shader();
|
|
|
|
private:
|
|
//sf::Context m_ctx;
|
|
|
|
components::mesh_vertex::flags m_enabled_mesh_components{
|
|
components::mesh_vertex::flags::none
|
|
};
|
|
material_component::flags m_enabled_material_components{
|
|
material_component::flags::none
|
|
};
|
|
|
|
components::point_cloud_vertex::flags m_enabled_point_cloud_components{
|
|
components::point_cloud_vertex::flags::none
|
|
};
|
|
|
|
glsl_loader m_shader_loader{};
|
|
dynamic_mesh_loader_type m_mesh_loader{};
|
|
dynamic_point_cloud_loader_type m_point_cloud_loader{};
|
|
|
|
dynamic_shader_data m_dynamic_shader_data_buffer{};
|
|
std::vector<dynamic_mesh_data> m_dynamic_mesh_data_buffer{};
|
|
std::vector<dynamic_material_data> m_dynamic_material_data_buffer{};
|
|
std::vector<dynamic_point_cloud_data> m_dynamic_point_cloud_buffer{};
|
|
|
|
std::vector<ztu::u8> m_vertex_buffer{};
|
|
|
|
std::vector<zgl::shader_data> m_gl_shader_data{};
|
|
std::vector<zgl::shader_program_data> m_gl_shader_program_data{};
|
|
std::vector<std::pair<zgl::mesh_data, aabb>> m_gl_mesh_data{};
|
|
std::vector<std::pair<zgl::point_cloud_data, aabb>> m_gl_point_cloud_data{};
|
|
std::vector<zgl::material_data> m_gl_material_data{};
|
|
std::vector<material_reference_entry_type> m_gl_material_data_references{};
|
|
|
|
ztu::u32 next_materials_id{ 0 };
|
|
|
|
};
|
|
|
|
}
|