Added KRSamplerManager::DEFAULT_CLAMPED_SAMPLER and DEFAULT_WRAPPING_SAMPLER

Added KRSamplerManager::init
This commit is contained in:
2022-08-25 00:00:55 -07:00
parent 191167f9d3
commit e318a5b4aa
4 changed files with 38 additions and 1 deletions

View File

@@ -102,6 +102,7 @@ KRContext::KRContext(const KrInitializeInfo* initializeInfo)
m_pBundleManager = std::make_unique<KRBundleManager>(*this); m_pBundleManager = std::make_unique<KRBundleManager>(*this);
m_pPipelineManager = std::make_unique<KRPipelineManager>(*this); m_pPipelineManager = std::make_unique<KRPipelineManager>(*this);
m_pSamplerManager = std::make_unique<KRSamplerManager>(*this); m_pSamplerManager = std::make_unique<KRSamplerManager>(*this);
m_pSamplerManager->init();
m_pTextureManager = std::make_unique<KRTextureManager>(*this); m_pTextureManager = std::make_unique<KRTextureManager>(*this);
m_pMaterialManager = std::make_unique<KRMaterialManager>(*this, m_pTextureManager.get(), m_pPipelineManager.get()); m_pMaterialManager = std::make_unique<KRMaterialManager>(*this, m_pTextureManager.get(), m_pPipelineManager.get());
m_pMeshManager = std::make_unique<KRMeshManager>(*this); m_pMeshManager = std::make_unique<KRMeshManager>(*this);

View File

@@ -34,6 +34,7 @@
KRSampler::KRSampler(KRContext& context, const SamplerInfo& info) KRSampler::KRSampler(KRContext& context, const SamplerInfo& info)
: KRContextObject(context) : KRContextObject(context)
, m_sampler(VK_NULL_HANDLE)
{ {
// TODO - Implement stub function // TODO - Implement stub function
} }

View File

@@ -45,6 +45,8 @@ bool SamplerInfo::operator==(const SamplerInfo& rhs) const
KRSamplerManager::KRSamplerManager(KRContext& context) KRSamplerManager::KRSamplerManager(KRContext& context)
: KRContextObject(context) : KRContextObject(context)
, DEFAULT_CLAMPED_SAMPLER(nullptr)
, DEFAULT_WRAPPING_SAMPLER(nullptr)
{ {
} }
@@ -61,6 +63,35 @@ void KRSamplerManager::destroy()
m_samplers.clear(); m_samplers.clear();
} }
void KRSamplerManager::init()
{
SamplerInfo info{};
info.createInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
info.createInfo.magFilter = VK_FILTER_LINEAR;
info.createInfo.minFilter = VK_FILTER_LINEAR;
info.createInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
info.createInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
info.createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
info.createInfo.anisotropyEnable = VK_TRUE;
info.createInfo.maxAnisotropy = 16; // TODO - This should be dynamic
info.createInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
info.createInfo.unnormalizedCoordinates = VK_FALSE;
info.createInfo.compareEnable = VK_FALSE;
info.createInfo.compareOp = VK_COMPARE_OP_ALWAYS;
info.createInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
info.createInfo.mipLodBias = 0.0f;
info.createInfo.minLod = 0.0f;
info.createInfo.maxLod = 0.0f;
DEFAULT_CLAMPED_SAMPLER = getSampler(info);
info.createInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
info.createInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
info.createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
DEFAULT_WRAPPING_SAMPLER = getSampler(info);
}
KRSampler* KRSamplerManager::getSampler(const SamplerInfo& info) KRSampler* KRSamplerManager::getSampler(const SamplerInfo& info)
{ {
SamplerMap::iterator itr = m_samplers.find(info); SamplerMap::iterator itr = m_samplers.find(info);
@@ -68,6 +99,6 @@ KRSampler* KRSamplerManager::getSampler(const SamplerInfo& info)
return itr->second; return itr->second;
} }
KRSampler* sampler = new KRSampler(getContext(), info); KRSampler* sampler = new KRSampler(getContext(), info);
m_samplers.emplace(info, sampler); m_samplers[info] = sampler;
return sampler; return sampler;
} }

View File

@@ -63,9 +63,13 @@ class KRSamplerManager : public KRContextObject
public: public:
KRSamplerManager(KRContext& context); KRSamplerManager(KRContext& context);
virtual ~KRSamplerManager(); virtual ~KRSamplerManager();
void init();
KRSampler* getSampler(const SamplerInfo& info); KRSampler* getSampler(const SamplerInfo& info);
void destroy(); void destroy();
KRSampler* DEFAULT_CLAMPED_SAMPLER;
KRSampler* DEFAULT_WRAPPING_SAMPLER;
private: private:
typedef std::unordered_map<SamplerInfo, KRSampler*, SamplerInfoHasher> SamplerMap; typedef std::unordered_map<SamplerInfo, KRSampler*, SamplerInfoHasher> SamplerMap;
SamplerMap m_samplers; SamplerMap m_samplers;