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>
31#include <neogfx/game/image.hpp>
32
33namespace neogfx::game
34{
35 struct texture
36 {
39 std::optional<texture_sampling> sampling;
43
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}
bool batchable(const filter &lhs, const filter &rhs)
Definition filter.hpp:88
double scalar
Definition numerical.hpp:63
basic_cookie_ref_ptr< cookie > cookie_ref_ptr
Definition jar.hpp:732
static neolib::uuid field_type_id(uint32_t aFieldIndex)
Definition texture.hpp:80
static const i_string & name()
Definition texture.hpp:51
static const neolib::uuid & id()
Definition texture.hpp:46
static const i_string & field_name(uint32_t aFieldIndex)
Definition texture.hpp:95
static component_data_field_type field_type(uint32_t aFieldIndex)
Definition texture.hpp:60
static uint32_t field_count()
Definition texture.hpp:56
std::optional< texture_sampling > sampling
Definition texture.hpp:39
texture_type type
Definition texture.hpp:38
optional_aabb_2d subTexture
Definition texture.hpp:42
neolib::cookie_ref_ptr id
Definition texture.hpp:37