This commit is contained in:
ZY4N
2024-12-22 16:58:40 +01:00
parent 2704814de2
commit db8db8f9d7
161 changed files with 17102 additions and 0 deletions

118
include/viewer/instance.hpp Normal file
View File

@@ -0,0 +1,118 @@
#pragma once
#include <vector>
#include <variant>
#include "viewer/settings.hpp"
#include <mutex>
#include "asset_types.hpp"
#include "geometry/aabb.hpp"
#include "rendering/modes/mesh_modes.hpp"
#include "rendering/modes/point_cloud_modes.hpp"
#include "scene/flying_camera.hpp"
#include "scene/camera_view.hpp"
#include "scene/lighting_setup.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 "rendering/batch_renderers/mesh_batch_renderer.hpp"
#include "rendering/batch_renderers/point_cloud_batch_renderer.hpp"
#include "rendering/shader_program_lookups/mesh_lookup.hpp"
#include "rendering/shader_program_lookups/point_cloud_lookup.hpp"
#include "SFML/Graphics/RenderWindow.hpp"
#include "SFML/Graphics/Font.hpp"
#include "SFML/Graphics/Image.hpp"
namespace viewer {
class instance
{
static constexpr auto id_mesh_index = static_cast<int>(asset_types::mesh);
static constexpr auto id_point_cloud_index = static_cast<int>(asset_types::point_cloud);
public:
using asset_id = std::variant<
rendering::mesh_batch_renderer::id_type,
rendering::point_cloud_batch_renderer::id_type
>;
instance();
std::error_code init(std::string title);
std::optional<asset_id> add_mesh(
const zgl::mesh_handle& mesh,
const aabb& bounding_box,
components::mesh_vertex::flags mesh_components,
const zgl::material_handle& material,
material_component::flags material_components
);
std::optional<asset_id> add_point_cloud(
const zgl::point_cloud_handle& point_cloud,
const aabb& bounding_box,
components::point_cloud_vertex::flags point_cloud_components
);
void add_shader_program(
asset_types type, zgl::shader_program_handle shader_program_handle
);
void set_background_color(const glm::vec4& color);
bool remove(asset_id id);
void run_progress(
std::mutex& lock,
std::string& title,
float& progress,
double fps = 30.0f
);
bool look_at(asset_id id);
void run(std::mutex& gl_resource_lock, double fps = std::numeric_limits<double>::max());
void windowed(unsigned int width, unsigned int height, bool decorations = true);
void fullscreen();
void size(unsigned int width, unsigned int height);
protected:
bool update(double dt);
void render();
public: // TODO fix
sf::ContextSettings m_context_settings;
sf::RenderWindow m_window;
std::string m_title;
glm::ivec2 m_screen_size;
sf::Font m_font{};
sf::Image m_logo{}, m_spinner{};
rendering::shader_program_lookups::mesh_lookup m_mesh_shader_program_lookup;
rendering::shader_program_lookups::point_cloud_lookup m_point_cloud_shader_program_lookup;
rendering::mesh_batch_renderer m_mesh_renderer;
rendering::point_cloud_batch_renderer m_point_cloud_renderer;
rendering::modes::mesh m_mesh_render_mode;
rendering::modes::point_cloud m_point_cloud_render_mode;
flying_camera m_camera;
camera_view m_view;
settings m_settings;
bool m_mouse_locked{ false };
};
} // namespace viewer