Unravel Engine C++ Reference
Loading...
Searching...
No Matches
batch_key.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <graphics/texture.h>
6#include <math/math.h>
7
8#include <cstdint>
9#include <memory>
10#include <optional>
11#include <string>
12
13#include "material.h"
14
15namespace unravel
16{
17class mesh;
18class material;
19
28{
30 std::shared_ptr<mesh> mesh_ptr;
31
33 std::shared_ptr<material> material_ptr;
34
36 uint32_t lod_index = 0;
37
39 uint32_t submesh_index = 0;
40
44 batch_key() = default;
45
53 batch_key(std::shared_ptr<mesh> mesh_ptr,
54 std::shared_ptr<material> material_ptr,
55 uint32_t lod_index,
56 uint32_t submesh_index);
57
65 batch_key(const asset_handle<mesh>& mesh_handle,
66 const asset_handle<material>& material_handle,
67 uint32_t lod_index,
68 uint32_t submesh_index);
69
75 auto operator<=>(const batch_key& other) const = default;
76
82 auto operator==(const batch_key& other) const -> bool = default;
83
88 auto hash() const noexcept -> size_t;
89
94 auto is_valid() const -> bool;
95
100 auto to_string() const -> std::string;
101};
102
105{
106 std::shared_ptr<gfx::texture> color_map;
107 float alpha_test_value = 1.0f;
108 math::color base_color{};
109 math::vec2 tiling{1.0f, 1.0f};
110};
111
119{
120 std::shared_ptr<mesh> mesh_ptr;
121 uint32_t lod_index = 0;
122 uint32_t submesh_index = 0;
123 cull_type cull = cull_type::counter_clockwise;
124 std::optional<shadow_cutout_state> cutout;
125
126 shadow_batch_key() = default;
127
128 shadow_batch_key(std::shared_ptr<mesh> mesh,
129 uint32_t lod,
130 uint32_t submesh,
132 std::optional<shadow_cutout_state> cutout_state = std::nullopt);
133
134 auto operator<=>(const shadow_batch_key& other) const -> std::strong_ordering;
135 auto operator==(const shadow_batch_key& other) const -> bool;
136
137 [[nodiscard]] auto hash() const noexcept -> size_t;
138 [[nodiscard]] auto is_valid() const -> bool;
139 [[nodiscard]] auto uses_alpha_cutout() const -> bool;
140 [[nodiscard]] auto to_string() const -> std::string;
141};
142
144auto make_shadow_batch_key(const std::shared_ptr<mesh>& mesh_ptr,
145 uint32_t lod_index,
146 uint32_t submesh_index,
147 const std::shared_ptr<material>& material_ptr) -> shadow_batch_key;
148
149} // namespace unravel
150
154namespace std
155{
156template<>
157struct hash<unravel::batch_key>
158{
159 auto operator()(const unravel::batch_key& key) const noexcept -> size_t
160 {
161 return key.hash();
162 }
163};
164
165template<>
166struct hash<unravel::shadow_batch_key>
167{
168 auto operator()(const unravel::shadow_batch_key& key) const noexcept -> size_t
169 {
170 return key.hash();
171 }
172};
173}
Base class for materials used in rendering.
Definition material.h:44
Main class representing a 3D mesh with support for different LODs, submeshes, and skinning.
Definition mesh.h:323
Hash specialization for batch_key to enable use in std::unordered_map.
cull_type
Enum representing the type of culling to be used.
Definition material.h:25
Thread-safe handle to an asset.
auto operator()(const unravel::batch_key &key) const noexcept -> size_t
Definition batch_key.h:159
auto operator()(const unravel::shadow_batch_key &key) const noexcept -> size_t
Definition batch_key.h:168
Batch key structure for grouping compatible draw calls.
Definition batch_key.h:28
batch_key()=default
Default constructor.
auto hash() const noexcept -> size_t
Generate hash value for this batch key.
Definition batch_key.cpp:34
auto operator<=>(const batch_key &other) const =default
Three-way comparison operator for sorting and equality.
auto is_valid() const -> bool
Check if this batch key is valid.
Definition batch_key.cpp:46
std::shared_ptr< material > material_ptr
Shared pointer to the material.
Definition batch_key.h:33
uint32_t lod_index
Level of detail index.
Definition batch_key.h:36
std::shared_ptr< mesh > mesh_ptr
Shared pointer to the mesh geometry.
Definition batch_key.h:30
uint32_t submesh_index
Submesh index within the mesh.
Definition batch_key.h:39
auto operator==(const batch_key &other) const -> bool=default
Equality comparison operator.
Batch key for shadow depth passes — geometry-first, optional cutout bucket.
Definition batch_key.h:119
std::shared_ptr< mesh > mesh_ptr
Definition batch_key.h:120
std::optional< shadow_cutout_state > cutout
Definition batch_key.h:124
Per-draw state for alpha-cutout shadow batches (texture + clip threshold).
Definition batch_key.h:105
std::shared_ptr< gfx::texture > color_map
Definition batch_key.h:106