Unravel Engine C++ Reference
Loading...
Searching...
No Matches
batch_instance.h
Go to the documentation of this file.
1#pragma once
2
3#include <math/math.h>
4
5#include <vector>
6
7namespace unravel
8{
9
17{
19 const math::mat4* world_transform_ptr = nullptr;
20
22 math::vec3 lod_params = math::vec3(0.0f, -1.0f, 0.0f);
23
25 float padding = 0.0f;
26
30 batch_instance() = default;
31
36 explicit batch_instance(const math::mat4* world_transform_ptr);
37
43 batch_instance(const math::mat4* world_transform_ptr, const math::vec3& lod_params);
44
49 auto is_valid() const -> bool;
50
55 auto to_string() const -> std::string;
56};
57
67{
68 static auto packed_size() -> size_t
69 {
70 return 64;
71 }
73 math::mat4 world_matrix;
74
79
84 explicit instance_vertex_data(const batch_instance& instance);
85
90 void set_lod_param(float lod_param);
91
96 auto get_lod_param() const -> float;
97
102 auto is_valid() const -> bool;
103
108 auto to_string() const -> std::string;
109};
110
118{
119public:
120 using container_type = std::vector<batch_instance>;
121 using iterator = container_type::iterator;
122 using const_iterator = container_type::const_iterator;
123
128
133 void reserve(size_t count);
134
139 void add_instance(const batch_instance& instance);
140
145 void add_instance(const math::mat4& world_transform);
146
150 void clear();
151
156 auto size() const -> size_t;
157
162 auto empty() const -> bool;
163
169 auto operator[](size_t index) -> batch_instance&;
170
176 auto operator[](size_t index) const -> const batch_instance&;
177
182 auto begin() -> iterator;
183
188 auto end() -> iterator;
189
194 auto begin() const -> const_iterator;
195
200 auto end() const -> const_iterator;
201
206 auto to_vertex_data() const -> std::vector<instance_vertex_data>;
207
212 auto get_gpu_memory_size() const -> size_t;
213
214private:
215 container_type instances_;
216};
217
218// Utility functions
219
226
233void unpack_instance_data(const instance_vertex_data& vertex_data,
234 math::mat4& out_transform,
235 math::vec3& out_lod_params);
236
242auto pack_instances_bulk(const std::vector<batch_instance>& instances) -> std::vector<instance_vertex_data>;
243
248auto validate_instance_data_layout() -> bool;
249
250} // namespace unravel
Collection of batch instances with utilities.
container_type::const_iterator const_iterator
batch_instance_collection()=default
Default constructor.
container_type::iterator iterator
std::vector< batch_instance > container_type
Definition bbox.cpp:5
Hash specialization for batch_key to enable use in std::unordered_map.
auto pack_instances_bulk(const std::vector< batch_instance > &instances) -> std::vector< instance_vertex_data >
Pack multiple instances into GPU vertex data.
auto pack_instance_data(const batch_instance &instance) -> instance_vertex_data
Pack batch instance data into GPU vertex format.
void unpack_instance_data(const instance_vertex_data &vertex_data, math::mat4 &out_transform, math::vec3 &out_lod_params)
Unpack GPU vertex data back to transform matrix and LOD params.
auto validate_instance_data_layout() -> bool
Validate that instance data is properly aligned and sized.
Instance data for a single object in a batch.
auto is_valid() const -> bool
Check if this instance has valid data.
const math::mat4 * world_transform_ptr
Pointer to world transformation matrix for this instance (valid only during frame processing)
batch_instance()=default
Default constructor.
math::vec3 lod_params
LOD blending parameters (x = current blend factor, y = target blend, z = transition time)
float padding
Padding to ensure alignment (unused, reserved for future use)
GPU-friendly vertex data for instancing.
math::mat4 world_matrix
World transformation matrix with LOD parameter packed in [3][3] (i_data0, i_data1,...
instance_vertex_data()=default
Default constructor.
static auto packed_size() -> size_t