Add samplerconfig

This commit is contained in:
Georg Hagen
2024-07-28 17:42:05 +02:00
parent d5952d1f87
commit 2ed7f7689e
6 changed files with 111 additions and 6 deletions

View File

@@ -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;
}

View File

@@ -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 <cinttypes>
#include <compare>
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;
};
}

View File

@@ -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)
{

View File

@@ -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()
{