FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_textureImage.hpp
1/*
2 * Copyright 2024 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_VULKAN_C_TEXTUREIMAGE_HPP_INCLUDED
18#define _FGE_VULKAN_C_TEXTUREIMAGE_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "FastEngine/C_rect.hpp"
22#include "FastEngine/C_vector.hpp"
23#include "FastEngine/vulkan/C_contextAware.hpp"
24#include "FastEngine/vulkan/C_descriptorSet.hpp"
25#include "FastEngine/vulkan/vulkanGlobal.hpp"
26#include "SDL_surface.h"
27
28#define FGE_TEXTURE_IMAGE_MIPMAPS_LEVELS_AUTO 0
29
30namespace fge::vulkan
31{
32
33class FGE_API TextureImage : public ContextAware
34{
35public:
36 explicit TextureImage(Context const& context);
37 TextureImage(TextureImage const& r) = delete;
38 TextureImage(TextureImage&& r) noexcept;
39 ~TextureImage() override;
40
41 TextureImage& operator=(TextureImage const& r) = delete;
42 TextureImage& operator=(TextureImage&& r) noexcept;
43
44 bool create(glm::vec<2, int> const& size, uint32_t levels = 1);
45 bool create(SDL_Surface* surface, uint32_t levels = 1);
46 void destroy() final;
47
48 [[nodiscard]] SDL_Surface* copyToSurface() const;
49
50 void update(SDL_Surface* surface, glm::vec<2, int> const& offset);
51 void update(TextureImage const& textureImage, glm::vec<2, int> const& offset);
52 void update(void* buffer, std::size_t bufferSize, glm::vec<2, int> const& size, glm::vec<2, int> const& offset);
53
54 void generateMipmaps(uint32_t levels = FGE_TEXTURE_IMAGE_MIPMAPS_LEVELS_AUTO);
55 [[nodiscard]] uint32_t getMipLevels() const;
56 void forceMipLod(float mipLodBias, float mipLodMin, float mipLodMax);
57
58 [[nodiscard]] glm::vec<2, int> const& getSize() const;
59 [[nodiscard]] VkExtent2D getExtent() const;
60 [[nodiscard]] int getBytesPerPixel() const;
61
62 [[nodiscard]] VkImage getTextureImage() const;
63 [[nodiscard]] VmaAllocation getTextureImageAllocation() const;
64
65 [[nodiscard]] VkImageView getTextureImageView() const;
66 [[nodiscard]] VkSampler getTextureSampler() const;
67
68 void setNormalizedCoordinates(bool normalized);
69 [[nodiscard]] bool getNormalizedCoordinates() const;
70
71 void setFilter(VkFilter filter);
72 [[nodiscard]] VkFilter getFilter() const;
73
74 [[nodiscard]] fge::vulkan::DescriptorSet const& getDescriptorSet() const;
75
76 [[nodiscard]] fge::Vector2f normalizeTextureCoords(fge::Vector2i const& coords) const;
77 [[nodiscard]] fge::RectFloat normalizeTextureRect(fge::RectInt const& rect) const;
78
79 [[nodiscard]] uint32_t getModificationCount() const;
80
81private:
82 void createTextureSampler(float mipLodBias, float mipLodMin, float mipLodMax);
83
84 VkImage g_textureImage;
85 VmaAllocation g_textureImageAllocation;
86
87 VkImageView g_textureImageView;
88 VkSampler g_textureSampler;
89
90 glm::vec<2, int> g_textureSize;
91 int g_textureBytesPerPixel;
92
93 VkFilter g_filter;
94 bool g_normalizedCoordinates;
95
96 fge::vulkan::DescriptorSet g_textureDescriptorSet;
97
98 uint32_t g_mipLevels;
99 uint32_t g_modificationCount;
100};
101
102} // namespace fge::vulkan
103
104#endif //_FGE_VULKAN_C_TEXTUREIMAGE_HPP_INCLUDED
Definition C_contextAware.hpp:28
Vulkan context.
Definition C_context.hpp:70
This class abstract the vulkan descriptor set for easier use.
Definition C_descriptorSet.hpp:41
Definition C_textureImage.hpp:34