neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
mesh_renderer.hpp
Go to the documentation of this file.
1// mesh_renderer.hpp
2/*
3neogfx C++ App/Game Engine
4Copyright (c) 2018, 2020 Leigh Johnston. All Rights Reserved.
5
6This program is free software: you can redistribute it and / or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along 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>
25#include <neogfx/gfx/color.hpp>
29#include <neogfx/game/patch.hpp>
30
31namespace neogfx::game
32{
34 {
38 std::optional<game::filter> filter;
39 bool barrier;
40
42 {
43 static const neolib::uuid& id()
44 {
45 static const neolib::uuid sId = { 0x19dc8436, 0xfa0d, 0x437c, 0xa784, { 0xca, 0x6a, 0x7a, 0x35, 0x44, 0x8b } };
46 return sId;
47 }
48 static const i_string& name()
49 {
50 static const string sName = "Mesh Renderer";
51 return sName;
52 }
53 static uint32_t field_count()
54 {
55 return 4;
56 }
57 static component_data_field_type field_type(uint32_t aFieldIndex)
58 {
59 switch (aFieldIndex)
60 {
61 case 0:
62 return component_data_field_type::ComponentData;
63 case 1:
64 return component_data_field_type::ComponentData | component_data_field_type::Array;
65 case 2:
66 return component_data_field_type::Int32;
67 case 3:
68 return component_data_field_type::ComponentData | component_data_field_type::Optional;
69 case 4:
70 return component_data_field_type::Bool;
71 default:
72 throw invalid_field_index();
73 }
74 }
75 static neolib::uuid field_type_id(uint32_t aFieldIndex)
76 {
77 switch (aFieldIndex)
78 {
79 case 0:
80 return material::meta::id();
81 case 1:
82 return patch::meta::id();
83 case 3:
84 return neolib::uuid{};
85 case 2:
86 return filter::meta::id();
87 case 4:
88 return neolib::uuid{};
89 default:
90 throw invalid_field_index();
91 }
92 }
93 static const i_string& field_name(uint32_t aFieldIndex)
94 {
95 static const string sFieldNames[] =
96 {
97 "Material",
98 "Patches",
99 "Layer",
100 "Filter",
101 "Barrier"
102 };
103 return sFieldNames[aFieldIndex];
104 }
105 static constexpr bool has_updater = true;
106 static void update(mesh_renderer& aData, i_ecs&, entity_id)
107 {
108 std::sort(aData.patches.begin(), aData.patches.end(), [](const patch& lhs, const patch& rhs)
109 {
110 auto lhsTexture = lhs.material.texture != std::nullopt ?
111 lhs.material.texture->id : lhs.material.sharedTexture != std::nullopt ?
112 lhs.material.sharedTexture->ptr->id : neolib::cookie_ref_ptr{};
113 auto rhsTexture = rhs.material.texture != std::nullopt ?
114 rhs.material.texture->id : rhs.material.sharedTexture != std::nullopt ?
116 return lhsTexture < rhsTexture;
117 });
118 }
119 };
120 };
121
122 inline bool batchable(const mesh_renderer& lhs, const mesh_renderer& rhs)
123 {
124 return batchable(lhs.material, rhs.material) && batchable(lhs.filter, rhs.filter) && !lhs.barrier && !rhs.barrier;
125 }
126}
bool batchable(const filter &lhs, const filter &rhs)
Definition filter.hpp:88
std::vector< patch > patches
Definition patch.hpp:88
id_t entity_id
Definition ecs_ids.hpp:51
basic_cookie_ref_ptr< cookie > cookie_ref_ptr
Definition jar.hpp:732
static const neolib::uuid & id()
Definition filter.hpp:41
static const neolib::uuid & id()
Definition material.hpp:47
std::optional< texture > texture
Definition material.hpp:41
std::optional< shared< texture > > sharedTexture
Definition material.hpp:40
static const i_string & field_name(uint32_t aFieldIndex)
static const i_string & name()
static void update(mesh_renderer &aData, i_ecs &, entity_id)
static neolib::uuid field_type_id(uint32_t aFieldIndex)
static const neolib::uuid & id()
static component_data_field_type field_type(uint32_t aFieldIndex)
std::optional< game::filter > filter
static const neolib::uuid & id()
Definition patch.hpp:38
material material
Definition patch.hpp:33