diff --git a/openVulkanoCpp/Scene/SamplerConfig.cpp b/openVulkanoCpp/Scene/SamplerConfig.cpp new file mode 100644 index 0000000..43443b9 --- /dev/null +++ b/openVulkanoCpp/Scene/SamplerConfig.cpp @@ -0,0 +1,12 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#include "SamplerConfig.hpp" + +namespace OpenVulkano::Scene +{ + const SamplerConfig SamplerConfig::DEFAULT; +} \ No newline at end of file diff --git a/openVulkanoCpp/Scene/SamplerConfig.hpp b/openVulkanoCpp/Scene/SamplerConfig.hpp new file mode 100644 index 0000000..980744f --- /dev/null +++ b/openVulkanoCpp/Scene/SamplerConfig.hpp @@ -0,0 +1,89 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include +#include + +namespace OpenVulkano::Scene +{ + enum class TextureSamplerFilter : int + { + NEAREST = 0, + LINEAR = 1, + CUBIC = 1000015000 + }; + + enum class TextureSamplerEdgeMode : int + { + REPEAT = 0, + MIRRORED_REPEAT = 1, + CLAMP_TO_EDGE = 2, + CLAMP_TO_BORDER = 3, + MIRROR_CLAMP_TO_EDGE = 4 + }; + + enum class TextureSamplerMipmapMode : int + { + NEAREST = 0, + LINEAR = 1 + }; + + class SamplerConfig final + { + public: + using bool32_t = uint32_t; + + private: + uint32_t type = 31; // To allow casting to vulkan struct + const void* next = nullptr; // To allow casting to vulkan struct + + public: + uint32_t flags = 0; + TextureSamplerFilter magFilter = TextureSamplerFilter::NEAREST; + TextureSamplerFilter minFilter = TextureSamplerFilter::NEAREST; + TextureSamplerMipmapMode mipmapMode = TextureSamplerMipmapMode::NEAREST; + TextureSamplerEdgeMode edgeModeU = TextureSamplerEdgeMode::REPEAT; + TextureSamplerEdgeMode edgeModeV = TextureSamplerEdgeMode::REPEAT; + TextureSamplerEdgeMode edgeModeW = TextureSamplerEdgeMode::REPEAT; + float mipLoadBias = 0; + bool32_t anisotropyEnabled = false; + float maxAnisotropy = 0; + bool32_t compareEnabled = false; + uint32_t compareOp = 0; //TODO + float minLod = 0, maxLod = 0; + uint32_t borderColor = 0; + bool32_t unnormalizedCoordinates = false; + + SamplerConfig(TextureSamplerEdgeMode edgeMode, TextureSamplerMipmapMode mipmapMode = TextureSamplerMipmapMode::NEAREST, + TextureSamplerFilter magFilter = TextureSamplerFilter::NEAREST, TextureSamplerFilter minFilter = TextureSamplerFilter::NEAREST) + : magFilter(magFilter), minFilter(minFilter), mipmapMode(mipmapMode), edgeModeU(edgeMode), edgeModeV(edgeMode), edgeModeW(edgeMode) + {} + + SamplerConfig(uint32_t flags = 0, TextureSamplerFilter magFilter = TextureSamplerFilter::NEAREST, + TextureSamplerFilter minFilter = TextureSamplerFilter::NEAREST, + TextureSamplerMipmapMode mipmapMode = TextureSamplerMipmapMode::NEAREST, + TextureSamplerEdgeMode edgeModeU = TextureSamplerEdgeMode::REPEAT, + TextureSamplerEdgeMode edgeModeV = TextureSamplerEdgeMode::REPEAT, + TextureSamplerEdgeMode edgeModeW = TextureSamplerEdgeMode::REPEAT, + float mipLoadBias = 0, bool32_t anisotropyEnabled = false, float maxAnisotropy = 0, + bool32_t compareEnabled = false, uint32_t compareOp = 0, //TODO + float minLod = 0, float maxLod = 0, uint32_t borderColor = 0, bool32_t unnormalizedCoordinates = false) + : flags(flags), magFilter(magFilter), minFilter(minFilter), mipmapMode(mipmapMode) + , edgeModeU(edgeModeU), edgeModeV(edgeModeV), edgeModeW(edgeModeW) + , mipLoadBias(mipLoadBias), anisotropyEnabled(anisotropyEnabled), maxAnisotropy(maxAnisotropy) + , compareEnabled(compareEnabled), compareOp(compareOp) + , minLod(minLod), maxLod(maxLod), borderColor(borderColor), unnormalizedCoordinates(unnormalizedCoordinates) + {} + + auto operator <=>(const SamplerConfig& other) const = default; + + public: + // Default configs + static const SamplerConfig DEFAULT; + }; +} \ No newline at end of file diff --git a/openVulkanoCpp/Scene/Textrue.cpp b/openVulkanoCpp/Scene/Textrue.cpp index 4c1052c..8f74300 100644 --- a/openVulkanoCpp/Scene/Textrue.cpp +++ b/openVulkanoCpp/Scene/Textrue.cpp @@ -8,7 +8,7 @@ namespace OpenVulkano::Scene { - Texture Texture::PLACEHOLDER = Texture(true); + Texture Texture::PLACEHOLDER = Texture(SamplerConfig::DEFAULT, true); void Texture::MakePlaceholder(uint32_t width, uint32_t height, Math::Vector4uc color1, Math::Vector4uc color2) { diff --git a/openVulkanoCpp/Scene/Texture.hpp b/openVulkanoCpp/Scene/Texture.hpp index ab3d30c..41b854d 100644 --- a/openVulkanoCpp/Scene/Texture.hpp +++ b/openVulkanoCpp/Scene/Texture.hpp @@ -7,6 +7,7 @@ #pragma once #include "UpdateFrequency.hpp" +#include "SamplerConfig.hpp" #include "Base/ICloseable.hpp" #include "Math/Math.hpp" #include "DataFormat.hpp" @@ -32,10 +33,13 @@ namespace OpenVulkano::Scene size_t size = 0; Math::Vector3ui resolution = {0,0,0}; DataFormat format = DataFormat::B8G8R8A8_UNORM; - bool updated = true; UpdateFrequency updateFrequency = UpdateFrequency::Never; + const SamplerConfig& m_samplerConfig; + bool updated = true; - Texture(bool placeholder = false) { if (placeholder) MakePlaceholder(); } + Texture(const SamplerConfig& samplerConfig = SamplerConfig::DEFAULT, bool placeholder = false) + : m_samplerConfig(samplerConfig) + { if (placeholder) MakePlaceholder(); } ~Texture() { diff --git a/openVulkanoCpp/Vulkan/Resources/ResourceManager.cpp b/openVulkanoCpp/Vulkan/Resources/ResourceManager.cpp index 721d7e3..69e29f5 100644 --- a/openVulkanoCpp/Vulkan/Resources/ResourceManager.cpp +++ b/openVulkanoCpp/Vulkan/Resources/ResourceManager.cpp @@ -53,6 +53,7 @@ namespace OpenVulkano::Vulkan ResourceManager::ResourceManager() { static_assert(sizeof(DescriptorSetLayoutBinding) == sizeof(vk::DescriptorSetLayoutBinding)); + static_assert(sizeof(Scene::SamplerConfig) == sizeof(vk::SamplerCreateInfo)); } ResourceManager::~ResourceManager() noexcept diff --git a/openVulkanoCpp/Vulkan/Scene/VulkanTexture.hpp b/openVulkanoCpp/Vulkan/Scene/VulkanTexture.hpp index a7c50c4..d38ba22 100644 --- a/openVulkanoCpp/Vulkan/Scene/VulkanTexture.hpp +++ b/openVulkanoCpp/Vulkan/Scene/VulkanTexture.hpp @@ -19,7 +19,6 @@ namespace OpenVulkano::Vulkan class VulkanTexture : public Scene::RenderTexture, public IRecordable, public Image { public: - static inline vk::SamplerCreateInfo DEFAULT_SAMPLER_CONFIG {}; vk::Sampler m_sampler; vk::DescriptorSet m_descriptorSet; @@ -30,7 +29,7 @@ namespace OpenVulkano::Vulkan resManager->CopyDataToImage(m_texture->size, m_texture->textureBuffer, this); texture->updated = false; - m_sampler = resManager->CreateSampler(DEFAULT_SAMPLER_CONFIG); + m_sampler = resManager->CreateSampler(reinterpret_cast(texture->m_samplerConfig)); SetDescriptorSet(resManager, descriptorSetLayout, binding); texture->renderTexture = this; @@ -43,7 +42,7 @@ namespace OpenVulkano::Vulkan texture->updated = false; texture->textureBuffer = Map(); - m_sampler = resManager->CreateSampler(DEFAULT_SAMPLER_CONFIG); + m_sampler = resManager->CreateSampler(reinterpret_cast(texture->m_samplerConfig)); SetDescriptorSet(resManager, descriptorSetLayout, binding); texture->renderTexture = this;