Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
vulkan_texture_resources.hpp
Go to the documentation of this file.
1// This file is part of the Rendering Engine project.
2// Author: Alexander Obzherin <alexanderobzherin@gmail.com>
3// Copyright (c) 2025 Alexander Obzherin
4// Distributed under the terms of the zlib License. See LICENSE.md for details.
5
6#pragma once
7
9#include <cstring>
10#include <memory>
11#include <iostream>
12#include <cstdint>
13#include <fstream>
14
15#define GLFW_INCLUDE_VULKAN
16#include <GLFW/glfw3.h>
17
18#define GLM_FORCE_RADIANS
19#define GLM_FORCE_DEPTH_ZERO_TO_ONE
20#include <glm/vec4.hpp>
21#include <glm/mat4x4.hpp>
23#include "image_data.hpp"
24
25#define GLM_FORCE_RADIANS
26#define GLM_FORCE_DEPTH_ZERO_TO_ONE
27#include <glm/glm.hpp>
28#include <glm/gtc/matrix_transform.hpp>
29
30namespace rendering_engine
31{
32class VulkanRenderer;
33class ImageData;
34
35/**
36 * @class VulkanTextureResources
37 * @brief Vulkan-specific implementation of ITextureRenderResources.
38 *
39 * This class manages texture memory and resources on the GPU using Vulkan.
40 */
42{
43public:
44 /**
45 * @brief Vulkan-specific implementation of ITextureRenderResources.
46 *
47 * @internal
48 * Handles uploading, managing, and releasing texture data on the GPU using Vulkan.
49 * This class is used internally by the rendering engine and is not intended for public use.
50 *
51 * @note Serves as a backend implementation; other graphics APIs can provide their own versions.
52 */
54
55 /**
56 * @brief Uploads the texture data from CPU to GPU memory using Vulkan.
57 *
58 * @param data The image data to upload.
59 */
60 void LoadToGPU(const ImageData& data) override;
61
62 /**
63 * @brief Releases the texture data from GPU memory using Vulkan.
64 */
65 void ReleaseFromGPU() override;
66
67 /**
68 * @brief Checks if the texture is currently loaded in GPU memory.
69 *
70 * @return True if the texture is in GPU memory, false otherwise.
71 */
72 bool IsTextureLoadedInGPU() override;
73
74 /**
75 * @brief Returns the size of the texture in GPU memory in bytes.
76 *
77 * @return Size in bytes.
78 */
79 size_t GetSizeInGPUBytes() const override;
80
81 /**
82 * @brief Returns the Vulkan image view associated with this texture resource.
83 *
84 * This image view is typically used for binding the texture to shaders via descriptor sets.
85 *
86 * @return The VkImageView handle for this texture resource.
87 */
88 VkImageView GetVkImageView() const { return mTextureImageView; }
89
90 /**
91 * @brief Returns the Vulkan sampler associated with this texture resource.
92 *
93 * This sampler is used to define how the texture is sampled in shaders (e.g., filtering, addressing modes).
94 *
95 * @return The VkSampler handle for this texture resource.
96 */
97 VkSampler GetVkSampler() const { return mTextureSampler; }
98
99private:
101 VulkanTextureResources& operator=(VulkanTextureResources const& rhs);
102
103protected:
104 void CreateTextureImage();
105 void CreateVulkanImage(uint32_t width, uint32_t height, std::uint32_t mipmapLevels, VkSampleCountFlagBits numSamples, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage,
106 VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory);
108 VkImageView CreateImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFlags, std::uint32_t mipmapLevels);
110
111protected:
115 std::uint32_t mMipmapLevels;
117 VkDeviceMemory mTextureImageMemory;
118 VkImageView mTextureImageView;
120 VkDeviceSize mGpuMemorySize;
121};
122
123}
Interface for backend-specific GPU texture resource management.
Represents raw 2D image data stored in memory.
Vulkan-based implementation of the IRenderer interface.
Vulkan-specific implementation of ITextureRenderResources.
VulkanTextureResources(VulkanRenderer *renderer)
Vulkan-specific implementation of ITextureRenderResources.
size_t GetSizeInGPUBytes() const override
Returns the size of the texture in GPU memory in bytes.
VkImageView GetVkImageView() const
Returns the Vulkan image view associated with this texture resource.
VkImageView CreateImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFlags, std::uint32_t mipmapLevels)
bool IsTextureLoadedInGPU() override
Checks if the texture is currently loaded in GPU memory.
void LoadToGPU(const ImageData &data) override
Uploads the texture data from CPU to GPU memory using Vulkan.
VkSampler GetVkSampler() const
Returns the Vulkan sampler associated with this texture resource.
void ReleaseFromGPU() override
Releases the texture data from GPU memory using Vulkan.
void CreateVulkanImage(uint32_t width, uint32_t height, std::uint32_t mipmapLevels, VkSampleCountFlagBits numSamples, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage &image, VkDeviceMemory &imageMemory)