neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
material.hpp
Go to the documentation of this file.
1// material.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>
27#include <neogfx/gfx/image.hpp>
30#include <neogfx/game/color.hpp>
33
34namespace neogfx::game
35{
36 struct material
37 {
38 std::optional<color> color;
39 std::optional<gradient> gradient;
40 std::optional<shared<texture>> sharedTexture;
41 std::optional<texture> texture;
42 std::optional<shader_effect> shaderEffect;
44
46 {
47 static const neolib::uuid& id()
48 {
49 static const neolib::uuid sId = { 0x5e04e3ad, 0xb4dd, 0x4bd2, 0x888d, { 0xaa, 0x58, 0xe9, 0x4f, 0x3a, 0x5e } };
50 return sId;
51 }
52 static const i_string& name()
53 {
54 static const string sName = "Material";
55 return sName;
56 }
57 static uint32_t field_count()
58 {
59 return 6;
60 }
61 static component_data_field_type field_type(uint32_t aFieldIndex)
62 {
63 switch (aFieldIndex)
64 {
65 case 0:
66 case 1:
67 return component_data_field_type::ComponentData | component_data_field_type::Optional;
68 case 2:
69 return component_data_field_type::ComponentData | component_data_field_type::Optional | component_data_field_type::Shared;
70 case 3:
71 return component_data_field_type::ComponentData | component_data_field_type::Optional;
72 case 4:
73 return component_data_field_type::Enum | component_data_field_type::Uint32 | component_data_field_type::Optional;
74 case 5:
75 return component_data_field_type::Bool;
76 default:
77 throw invalid_field_index();
78 }
79 }
80 static neolib::uuid field_type_id(uint32_t aFieldIndex)
81 {
82 switch (aFieldIndex)
83 {
84 case 0:
85 return color::meta::id();
86 case 1:
87 return gradient::meta::id();
88 case 2:
89 case 3:
90 return texture::meta::id();
91 default:
92 throw invalid_field_index();
93 }
94 }
95 static const i_string& field_name(uint32_t aFieldIndex)
96 {
97 static const string sFieldNames[] =
98 {
99 "Color",
100 "Gradient",
101 "Shared Texture",
102 "Texture",
103 "Shader Effect",
104 "Subpixel"
105 };
106 return sFieldNames[aFieldIndex];
107 }
108 };
109 };
110
111 inline bool batchable(const material& lhs, const material& rhs)
112 {
113 return batchable(lhs.gradient, rhs.gradient) &&
115 batchable(lhs.texture, rhs.texture) &&
116 lhs.shaderEffect == rhs.shaderEffect &&
117 lhs.subpixel == rhs.subpixel;
118 }
119}
gradient_id id() const override
bool batchable(const filter &lhs, const filter &rhs)
Definition filter.hpp:88
static neolib::uuid field_type_id(uint32_t aFieldIndex)
Definition material.hpp:80
static component_data_field_type field_type(uint32_t aFieldIndex)
Definition material.hpp:61
static uint32_t field_count()
Definition material.hpp:57
static const i_string & name()
Definition material.hpp:52
static const i_string & field_name(uint32_t aFieldIndex)
Definition material.hpp:95
static const neolib::uuid & id()
Definition material.hpp:47
std::optional< color > color
Definition material.hpp:38
std::optional< gradient > gradient
Definition material.hpp:39
std::optional< texture > texture
Definition material.hpp:41
std::optional< shared< texture > > sharedTexture
Definition material.hpp:40
std::optional< shader_effect > shaderEffect
Definition material.hpp:42
static const neolib::uuid & id()
Definition texture.hpp:46