FastEngine 0.9.4
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
texture_manager.hpp
1/*
2 * Copyright 2025 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_TEXTURE_MANAGER_HPP_INCLUDED
18#define _FGE_TEXTURE_MANAGER_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21
22#include "FastEngine/graphic/C_surface.hpp"
23#include "FastEngine/manager/C_baseManager.hpp"
24#include "FastEngine/textureType.hpp"
25#include <vector>
26
27#define FGE_TEXTURE_BAD FGE_MANAGER_BAD
28#define FGE_TEXTURE_BAD_W 32
29#define FGE_TEXTURE_BAD_H 32
30#define FGE_TEXTURE_BAD_COLOR_1 fge::Color::Black
31#define FGE_TEXTURE_BAD_COLOR_2 fge::Color::Magenta
32
33namespace fge::texture
34{
35
36struct DataBlock final : manager::BaseDataBlock<TextureType>
37{
38 inline void unload() override { this->_group.clear(); }
39
40 [[nodiscard]] inline virtual bool duplicate(BaseDataBlock& block) const override
41 {
42 auto& castedBlock = dynamic_cast<DataBlock&>(block);
43 if (!BaseDataBlock::duplicate(castedBlock))
44 {
45 return false;
46 }
47 castedBlock._group.clear();
48 for (auto& group: this->_group)
49 {
50 castedBlock._group.emplace_back(std::make_shared<TextureType>(*group));
51 }
52 castedBlock._group = this->_group;
53 return true;
54 }
55
56 std::vector<DataPointer> _group;
57};
58
68class FGE_API TextureManager final : public manager::BaseManager<TextureType, DataBlock>
69{
70public:
71 using BaseManager::BaseManager;
72
73 bool initialize() override;
74 void uninitialize() override;
75
83 bool loadFromSurface(std::string_view name, fge::Surface const& surface);
91 bool loadFromFile(std::string_view name, std::filesystem::path const& path);
99 bool loadToGroupFromSurface(std::string_view name, fge::Surface const& surface) const;
100};
101
106FGE_API extern TextureManager gManager;
107
108} // namespace fge::texture
109
110#endif // _FGE_TEXTURE_MANAGER_HPP_INCLUDED
Abstraction of SDL_Surface.
Definition graphic/C_surface.hpp:55
Base class for all managers.
Definition C_baseManager.hpp:78
Manage textures.
Definition texture_manager.hpp:69
bool loadFromSurface(std::string_view name, fge::Surface const &surface)
Load a texture from a surface.
bool loadFromFile(std::string_view name, std::filesystem::path const &path)
Load a texture from a file.
bool loadToGroupFromSurface(std::string_view name, fge::Surface const &surface) const
Load a texture from a surface and add it to a group.
bool initialize() override
Initialize the manager.
FGE_API TextureManager gManager
The global texture manager.
Definition C_baseManager.hpp:42
Definition texture_manager.hpp:37