163 lines
4.9 KiB
C++
163 lines
4.9 KiB
C++
#pragma once
|
|
|
|
#include "Point_Visual.h"
|
|
|
|
#include <renderive/event/Event.hpp>
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
class Scene_Base;
|
|
|
|
namespace renderive::render_3d {
|
|
|
|
struct Extent {
|
|
std::uint32_t width{};
|
|
std::uint32_t height{};
|
|
[[nodiscard]] constexpr bool empty() const noexcept { return width == 0 || height == 0; }
|
|
bool operator==(const Extent&) const = default;
|
|
};
|
|
|
|
struct Clear_Color {
|
|
float red{0.035F};
|
|
float green{0.045F};
|
|
float blue{0.07F};
|
|
float alpha{1.0F};
|
|
bool operator==(const Clear_Color&) const = default;
|
|
};
|
|
|
|
enum class Frame_Mode : std::uint8_t {
|
|
Manual,
|
|
Low_Latency,
|
|
Playback,
|
|
};
|
|
|
|
enum struct Visual_Family : std::uint8_t {
|
|
Point,
|
|
Splat,
|
|
Pixel,
|
|
Marker,
|
|
Sphere,
|
|
Segment,
|
|
Vector,
|
|
Primitive,
|
|
Mesh,
|
|
Path,
|
|
Image,
|
|
Labels,
|
|
Glyph,
|
|
Text,
|
|
Volume,
|
|
};
|
|
|
|
struct Scene_Options {
|
|
Extent viewport{560, 320};
|
|
Clear_Color clear_color;
|
|
Frame_Mode frame_mode{Frame_Mode::Low_Latency};
|
|
double maximum_frames_per_second{60.0};
|
|
std::uint32_t gpu_index{};
|
|
bool validation_enabled{};
|
|
Visual_Family visual_family{Visual_Family::Point};
|
|
};
|
|
|
|
struct Pixel_Frame {
|
|
Extent extent;
|
|
std::uint64_t sequence{};
|
|
std::vector<std::byte> rgba8;
|
|
};
|
|
|
|
struct Runtime_Admission_Statistics {
|
|
std::size_t capacity{};
|
|
std::size_t active{};
|
|
std::size_t peak_active{};
|
|
std::size_t queued{};
|
|
std::size_t peak_queued{};
|
|
std::uint64_t backpressure_count{};
|
|
std::uint64_t backpressure_wait_ns{};
|
|
};
|
|
|
|
struct Runtime_Statistics {
|
|
Runtime_Admission_Statistics render_domain;
|
|
Runtime_Admission_Statistics gpu_completion;
|
|
std::uint64_t render_domain_unhandled_exception_count{};
|
|
std::uint64_t gpu_completion_fault_count{};
|
|
std::uint64_t gpu_completion_abandoned_count{};
|
|
};
|
|
|
|
struct Frame_Status {
|
|
Frame_Mode mode{Frame_Mode::Low_Latency};
|
|
double frequency_hz{};
|
|
std::uint64_t produced_frame_count{};
|
|
std::uint64_t consumed_frame_count{};
|
|
std::uint64_t dropped_frame_count{};
|
|
std::uint64_t failed_operation_count{};
|
|
std::uint64_t pending_frame_count{};
|
|
std::uint64_t latest_sequence{};
|
|
std::uint64_t next_refresh_interval_ns{};
|
|
};
|
|
|
|
// Owns frame scheduling and the single Datoviz mutation/render domain.
|
|
class Point_Scene final {
|
|
public:
|
|
Point_Scene(Scene_Options options, std::shared_ptr<Point_Visual> visual);
|
|
~Point_Scene();
|
|
|
|
Point_Scene(const Point_Scene&) = delete;
|
|
Point_Scene& operator=(const Point_Scene&) = delete;
|
|
Point_Scene(Point_Scene&&) = delete;
|
|
Point_Scene& operator=(Point_Scene&&) = delete;
|
|
|
|
void resize(Extent extent);
|
|
void set_clear_color(Clear_Color color);
|
|
void dispatch(const ::renderive::Event& event);
|
|
|
|
template <::renderive::Event_Point Point_Type>
|
|
void dispatch(const ::renderive::Basic_Pointer_Event<Point_Type>& event) {
|
|
dispatch_pointer(event.type, static_cast<float>(event.position.x),
|
|
static_cast<float>(event.position.y), event.button,
|
|
event.buttons, event.modifiers);
|
|
}
|
|
|
|
template <::renderive::Event_Point Point_Type>
|
|
void dispatch(const ::renderive::Basic_Wheel_Event<Point_Type>& event) {
|
|
dispatch_wheel(static_cast<float>(event.position.x),
|
|
static_cast<float>(event.position.y),
|
|
static_cast<float>(event.pixel_delta_x),
|
|
static_cast<float>(event.pixel_delta_y),
|
|
static_cast<float>(event.angle_delta_x),
|
|
static_cast<float>(event.angle_delta_y), event.modifiers);
|
|
}
|
|
|
|
void dispatch(const ::renderive::Key_Event& event);
|
|
|
|
// Frame strategy operations. request_frame() is the complete low-latency path.
|
|
[[nodiscard]] bool prepare_frame();
|
|
[[nodiscard]] bool refresh_manual_frame();
|
|
[[nodiscard]] bool discard_pending_frame();
|
|
[[nodiscard]] bool render_prepared_frame();
|
|
[[nodiscard]] bool request_frame();
|
|
|
|
[[nodiscard]] std::shared_ptr<const Pixel_Frame> latest_frame() const;
|
|
[[nodiscard]] Frame_Status frame_status() const;
|
|
[[nodiscard]] Runtime_Statistics runtime_statistics() const noexcept;
|
|
[[nodiscard]] Scene_Base& render_scene() noexcept;
|
|
[[nodiscard]] const Scene_Base& render_scene() const noexcept;
|
|
|
|
private:
|
|
void dispatch_pointer(::renderive::Event_Type type, float x, float y,
|
|
::renderive::Mouse_Button button,
|
|
::renderive::Mouse_Button_Mask buttons,
|
|
::renderive::Keyboard_Modifier modifiers);
|
|
void dispatch_wheel(float x, float y, float pixel_delta_x,
|
|
float pixel_delta_y, float angle_delta_x,
|
|
float angle_delta_y,
|
|
::renderive::Keyboard_Modifier modifiers);
|
|
|
|
struct Impl;
|
|
std::unique_ptr<Impl> impl_;
|
|
};
|
|
|
|
} // namespace renderive::render_3d
|