2025-04-27 23:20:52 +02:00
|
|
|
module;
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#define GLM_FORCE_RADIANS
|
|
|
|
|
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
|
|
|
|
#define GLM_ENABLE_EXPERIMENTAL
|
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
|
#include <glm/gtc/matrix_inverse.hpp>
|
|
|
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
|
|
|
|
|
|
|
|
export module Crafter.Graphics:VulkanTexture;
|
|
|
|
|
import :VulkanDevice;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Crafter {
|
|
|
|
|
class VulkanTexture {
|
|
|
|
|
public:
|
|
|
|
|
static void createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory) {
|
|
|
|
|
VkImageCreateInfo imageInfo{};
|
|
|
|
|
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
|
|
|
|
imageInfo.imageType = VK_IMAGE_TYPE_2D;
|
|
|
|
|
imageInfo.extent.width = width;
|
|
|
|
|
imageInfo.extent.height = height;
|
|
|
|
|
imageInfo.extent.depth = 1;
|
|
|
|
|
imageInfo.mipLevels = 1;
|
|
|
|
|
imageInfo.arrayLayers = 1;
|
|
|
|
|
imageInfo.format = format;
|
|
|
|
|
imageInfo.tiling = tiling;
|
|
|
|
|
imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
|
|
|
imageInfo.usage = usage;
|
|
|
|
|
imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
|
|
|
|
|
imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
2025-05-03 02:34:38 +02:00
|
|
|
VulkanDevice::CHECK_VK_RESULT(vkCreateImage(VulkanDevice::device, &imageInfo, nullptr, &image));
|
2025-04-27 23:20:52 +02:00
|
|
|
|
|
|
|
|
VkMemoryRequirements memRequirements;
|
2025-05-03 02:34:38 +02:00
|
|
|
vkGetImageMemoryRequirements(VulkanDevice::device, image, &memRequirements);
|
2025-04-27 23:20:52 +02:00
|
|
|
|
|
|
|
|
VkMemoryAllocateInfo allocInfo{};
|
|
|
|
|
allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
|
|
|
|
allocInfo.allocationSize = memRequirements.size;
|
|
|
|
|
allocInfo.memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, properties);
|
|
|
|
|
|
2025-05-03 02:34:38 +02:00
|
|
|
VulkanDevice::CHECK_VK_RESULT(vkAllocateMemory(VulkanDevice::device, &allocInfo, nullptr, &imageMemory));
|
2025-04-27 23:20:52 +02:00
|
|
|
|
2025-05-03 02:34:38 +02:00
|
|
|
vkBindImageMemory(VulkanDevice::device, image, imageMemory, 0);
|
2025-04-27 23:20:52 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|