neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
texture.hpp
Go to the documentation of this file.
1
// texture.hpp
2
/*
3
neogfx C++ App/Game Engine
4
Copyright (c) 2018, 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
>
24
#include <
neolib/core/string.hpp
>
25
#include <
neogfx/gfx/i_texture.hpp
>
26
#include <
neogfx/gfx/i_sub_texture.hpp
>
27
#include <
neogfx/gfx/i_texture_manager.hpp
>
28
#include <
neogfx/game/ecs_ids.hpp
>
29
#include <
neogfx/game/component.hpp
>
30
#include <
neogfx/game/i_component_data.hpp
>
31
#include <
neogfx/game/image.hpp
>
32
33
namespace
neogfx::game
34
{
35
struct
texture
36
{
37
neolib::cookie_ref_ptr
id
;
38
texture_type
type
;
39
std::optional<texture_sampling>
sampling
;
40
scalar
dpiScalingFactor
;
41
vec2
extents
;
42
optional_aabb_2d
subTexture
;
43
44
struct
meta
:
i_component_data::meta
45
{
46
static
const
neolib::uuid
&
id
()
47
{
48
static
const
neolib::uuid
sId = { 0x9f08230d, 0x25f, 0x4466, 0x9aab, { 0x1, 0x8d, 0x3, 0x29, 0x2e, 0xdc } };
49
return
sId;
50
}
51
static
const
i_string
&
name
()
52
{
53
static
const
string
sName =
"Texture"
;
54
return
sName;
55
}
56
static
uint32_t
field_count
()
57
{
58
return
6;
59
}
60
static
component_data_field_type
field_type
(uint32_t aFieldIndex)
61
{
62
switch
(aFieldIndex)
63
{
64
case
0:
65
return
component_data_field_type::Id;
66
case
1:
67
return
component_data_field_type::Enum | component_data_field_type::Uint32;
68
case
2:
69
return
component_data_field_type::Enum | component_data_field_type::Uint32 | component_data_field_type::Optional;
70
case
3:
71
return
component_data_field_type::Scalar;
72
case
4:
73
return
component_data_field_type::Vec2;
74
case
5:
75
return
component_data_field_type::Aabb2d | component_data_field_type::Optional;
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
case
1:
86
case
2:
87
case
3:
88
case
4:
89
case
5:
90
return
neolib::uuid
{};
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
"Id"
,
100
"Type"
,
101
"Sampling"
,
102
"DPI Scale Factor"
,
103
"Extents"
,
104
"Sub Texture"
105
};
106
return
sFieldNames[aFieldIndex];
107
}
108
};
109
};
110
111
inline
bool
batchable
(
const
texture
& lhs,
const
texture
& rhs)
112
{
113
if
(lhs.
sampling
!= rhs.
sampling
)
114
return
false
;
115
auto
const
& lhsTexture = *service<i_texture_manager>().find_texture(lhs.
id
.cookie());
116
auto
const
& rhsTexture = *service<i_texture_manager>().find_texture(rhs.
id
.cookie());
117
return
lhsTexture.native_handle() == rhsTexture.native_handle();
118
}
119
}
neolib::i_string
Definition
i_string.hpp:49
neolib::math::basic_vector
Definition
numerical.hpp:112
neolib::optional< aabb_2d >
image.hpp
i_sub_texture.hpp
i_texture.hpp
i_texture_manager.hpp
neogfx::game
Definition
aabb_octree.hpp:31
neogfx::game::batchable
bool batchable(const filter &lhs, const filter &rhs)
Definition
filter.hpp:88
neogfx::texture_type
texture_type
Definition
i_texture.hpp:36
neolib::ecs::component_data_field_type
component_data_field_type
Definition
i_component_data.hpp:52
neolib::math::scalar
double scalar
Definition
numerical.hpp:63
neolib::cookie_ref_ptr
basic_cookie_ref_ptr< cookie > cookie_ref_ptr
Definition
jar.hpp:732
component.hpp
ecs_ids.hpp
i_component_data.hpp
neogfx.hpp
string.hpp
neogfx::game::texture::meta
Definition
texture.hpp:45
neogfx::game::texture::meta::field_type_id
static neolib::uuid field_type_id(uint32_t aFieldIndex)
Definition
texture.hpp:80
neogfx::game::texture::meta::name
static const i_string & name()
Definition
texture.hpp:51
neogfx::game::texture::meta::id
static const neolib::uuid & id()
Definition
texture.hpp:46
neogfx::game::texture::meta::field_name
static const i_string & field_name(uint32_t aFieldIndex)
Definition
texture.hpp:95
neogfx::game::texture::meta::field_type
static component_data_field_type field_type(uint32_t aFieldIndex)
Definition
texture.hpp:60
neogfx::game::texture::meta::field_count
static uint32_t field_count()
Definition
texture.hpp:56
neogfx::game::texture
Definition
texture.hpp:36
neogfx::game::texture::sampling
std::optional< texture_sampling > sampling
Definition
texture.hpp:39
neogfx::game::texture::dpiScalingFactor
scalar dpiScalingFactor
Definition
texture.hpp:40
neogfx::game::texture::extents
vec2 extents
Definition
texture.hpp:41
neogfx::game::texture::type
texture_type type
Definition
texture.hpp:38
neogfx::game::texture::subTexture
optional_aabb_2d subTexture
Definition
texture.hpp:42
neogfx::game::texture::id
neolib::cookie_ref_ptr id
Definition
texture.hpp:37
neolib::ecs::i_component_data::meta::invalid_field_index
Definition
i_component_data.hpp:134
neolib::ecs::i_component_data::meta
Definition
i_component_data.hpp:133
neolib::uuid
Definition
uuid.hpp:51
uuid.hpp
include
neogfx
game
texture.hpp
Generated by
1.9.8