neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
mesh_render_cache.hpp
Go to the documentation of this file.
1// mesh_render_cache.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
23#include <neolib/core/uuid.hpp>
27
28namespace neogfx::game
29{
30 enum class cache_state : uint32_t
31 {
32 Invalid = 0x00000000,
33 Dirty = 0x00000001,
34 Clean = 0x00000002
35 };
36
38 {
41 mutable std::vector<vec2u32> patchVertexArrayIndices;
42
44 {
45 static const neolib::uuid& id()
46 {
47 static const neolib::uuid sId = { 0x4fdfc50f, 0x6562, 0x4cf1, 0x80cf, { 0x87, 0x2c, 0xff, 0xf, 0xa4, 0x2f } };
48 return sId;
49 }
50 static const i_string& name()
51 {
52 static const string sName = "mesh_render_cache";
53 return sName;
54 }
55 static uint32_t field_count()
56 {
57 return 3;
58 }
59 static component_data_field_type field_type(uint32_t aFieldIndex)
60 {
61 switch (aFieldIndex)
62 {
63 case 0:
64 return component_data_field_type::Enum | component_data_field_type::Internal;
65 case 1:
66 return component_data_field_type::Vec2u32 | component_data_field_type::Internal;
67 case 2:
68 return component_data_field_type::Vec2u32 | component_data_field_type::Array | component_data_field_type::Internal;
69 default:
70 throw invalid_field_index();
71 }
72 }
73 static const i_string& field_name(uint32_t aFieldIndex)
74 {
75 static const string sFieldNames[] =
76 {
77 "State",
78 "Mesh Vertex Array Indices",
79 "Patch Vertex Array Indices"
80 };
81 return sFieldNames[aFieldIndex];
82 }
83 };
84 };
85
87 {
88 return aCache.has_entity_record_no_lock(aEntity) &&
89 aCache.entity_record_no_lock(aEntity).state != cache_state::Invalid;
90 }
91
93 {
94 return aCache.has_entity_record_no_lock(aEntity) &&
95 aCache.entity_record_no_lock(aEntity).state == cache_state::Dirty;
96 }
97
99 {
100 return aCache.has_entity_record_no_lock(aEntity) &&
101 aCache.entity_record_no_lock(aEntity).state == cache_state::Clean;
102 }
103
105 {
106 auto& cache = aCache.entity_record_no_lock(aEntity, true);
107 cache.state = cache_state::Invalid;
108 }
109
111 {
112 auto& cache = aCache.entity_record_no_lock(aEntity, true);
113 if (cache.state == cache_state::Clean)
114 cache.state = cache_state::Dirty;
115 }
116
118 {
119 auto& cache = aCache.entity_record_no_lock(aEntity, true);
120 if (cache.state == cache_state::Dirty)
121 cache.state = cache_state::Clean;
122 }
123
124 inline bool is_render_cache_valid_no_lock(i_ecs const& aEcs, entity_id aEntity)
125 {
127 }
128
129 inline bool is_render_cache_dirty_no_lock(i_ecs const& aEcs, entity_id aEntity)
130 {
132 }
133
134 inline bool is_render_cache_clean_no_lock(i_ecs const& aEcs, entity_id aEntity)
135 {
137 }
138
143
145 {
147 }
148
150 {
152 }
153
155 {
156 return aCache.has_entity_record(aEntity) &&
157 aCache.entity_record(aEntity).state != cache_state::Invalid;
158 }
159
161 {
162 return aCache.has_entity_record(aEntity) &&
163 aCache.entity_record(aEntity).state == cache_state::Dirty;
164 }
165
167 {
168
169 return aCache.has_entity_record(aEntity) &&
170 aCache.entity_record(aEntity).state == cache_state::Clean;
171 }
172
174 {
175 auto& cache = aCache.entity_record(aEntity, true);
176 cache.state = cache_state::Invalid;
177 }
178
180 {
181 auto& cache = aCache.entity_record(aEntity, true);
182 if (cache.state == cache_state::Clean)
183 cache.state = cache_state::Dirty;
184 }
185
187 {
188 auto& cache = aCache.entity_record(aEntity, true);
189 if (cache.state == cache_state::Dirty)
190 cache.state = cache_state::Clean;
191 }
192
193 inline bool is_render_cache_valid(i_ecs const& aEcs, entity_id aEntity)
194 {
195 return is_render_cache_valid(aEcs.component<mesh_render_cache>(), aEntity);
196 }
197
198 inline bool is_render_cache_dirty(i_ecs const& aEcs, entity_id aEntity)
199 {
200 return is_render_cache_dirty(aEcs.component<mesh_render_cache>(), aEntity);
201 }
202
203 inline bool is_render_cache_clean(i_ecs const& aEcs, entity_id aEntity)
204 {
205 return is_render_cache_clean(aEcs.component<mesh_render_cache>(), aEntity);
206 }
207
208 inline void set_render_cache_invalid(i_ecs& aEcs, entity_id aEntity)
209 {
211 }
212
213 inline void set_render_cache_dirty(i_ecs& aEcs, entity_id aEntity)
214 {
216 }
217
218 inline void set_render_cache_clean(i_ecs& aEcs, entity_id aEntity)
219 {
221 }
222}
bool has_entity_record(entity_id aEntity) const override
bool has_entity_record_no_lock(entity_id aEntity) const override
const value_type & entity_record_no_lock(entity_id aEntity) const
const value_type & entity_record(entity_id aEntity) const
virtual const i_component & component(component_id aComponentId) const =0
bool is_render_cache_clean_no_lock(component< game::mesh_render_cache > const &aCache, entity_id aEntity)
void set_render_cache_dirty_no_lock(component< game::mesh_render_cache > &aCache, entity_id aEntity)
bool is_render_cache_valid(component< game::mesh_render_cache > const &aCache, entity_id aEntity)
void set_render_cache_invalid(component< game::mesh_render_cache > &aCache, entity_id aEntity)
bool is_render_cache_dirty_no_lock(component< game::mesh_render_cache > const &aCache, entity_id aEntity)
bool is_render_cache_valid_no_lock(component< game::mesh_render_cache > const &aCache, entity_id aEntity)
void set_render_cache_clean(component< game::mesh_render_cache > &aCache, entity_id aEntity)
bool is_render_cache_dirty(component< game::mesh_render_cache > const &aCache, entity_id aEntity)
bool is_render_cache_clean(component< game::mesh_render_cache > const &aCache, entity_id aEntity)
void set_render_cache_clean_no_lock(component< game::mesh_render_cache > &aCache, entity_id aEntity)
void set_render_cache_dirty(component< game::mesh_render_cache > &aCache, entity_id aEntity)
void set_render_cache_invalid_no_lock(component< game::mesh_render_cache > &aCache, entity_id aEntity)
id_t entity_id
Definition ecs_ids.hpp:51
vector2u32 vec2u32
static const i_string & field_name(uint32_t aFieldIndex)
static component_data_field_type field_type(uint32_t aFieldIndex)
std::vector< vec2u32 > patchVertexArrayIndices