diff --git a/kraken/KRContext.cpp b/kraken/KRContext.cpp index 4d05d00..3009bd2 100755 --- a/kraken/KRContext.cpp +++ b/kraken/KRContext.cpp @@ -100,6 +100,8 @@ KRContext::KRContext(const KrInitializeInfo* initializeInfo) m_absolute_time = 0.0f; m_pBundleManager = std::make_unique(*this); + m_deviceManager = std::make_unique(*this); + m_surfaceManager = std::make_unique(*this); m_pPipelineManager = std::make_unique(*this); m_pSamplerManager = std::make_unique(*this); m_pSamplerManager->init(); @@ -114,8 +116,6 @@ KRContext::KRContext(const KrInitializeInfo* initializeInfo) m_pUnknownManager = std::make_unique(*this); m_pShaderManager = std::make_unique(*this); m_pSourceManager = std::make_unique(*this); - m_deviceManager = std::make_unique(*this); - m_surfaceManager = std::make_unique(*this); m_streamingEnabled = true; #if defined(_WIN32) || defined(_WIN64) diff --git a/kraken/KRSampler.cpp b/kraken/KRSampler.cpp index 60b51bc..1031357 100644 --- a/kraken/KRSampler.cpp +++ b/kraken/KRSampler.cpp @@ -31,8 +31,9 @@ #include "KRSampler.h" #include "KRSamplerManager.h" +#include "KRDeviceManager.h" -KRSampler::KRSampler(KRContext& context, const SamplerInfo& info) +KRSampler::KRSampler(KRContext& context) : KRContextObject(context) { // TODO - Implement stub function @@ -40,7 +41,31 @@ KRSampler::KRSampler(KRContext& context, const SamplerInfo& info) KRSampler::~KRSampler() { - // TODO - Implement stub function + destroy(); +} + +bool KRSampler::createSamplers(const SamplerInfo& info) +{ + bool success = true; + m_samplers.clear(); + KRDeviceManager* deviceManager = getContext().getDeviceManager(); + int iAllocation = 0; + + for (auto deviceItr = deviceManager->getDevices().begin(); deviceItr != deviceManager->getDevices().end() && iAllocation < KRENGINE_MAX_GPU_COUNT; deviceItr++, iAllocation++) { + KRDevice& device = *(*deviceItr).second; + VkSampler sampler = VK_NULL_HANDLE; + if (vkCreateSampler(device.m_logicalDevice, &info.createInfo, nullptr, &sampler) != VK_SUCCESS) { + success = false; + break; + } + m_samplers.push_back(std::make_pair(deviceItr->first, sampler)); + } + + if (!success) { + destroy(); + } + + return success; } VkSampler KRSampler::getSampler(KrDeviceHandle& handle) @@ -54,3 +79,8 @@ VkSampler KRSampler::getSampler(KrDeviceHandle& handle) assert(false); return VK_NULL_HANDLE; } + +void KRSampler::destroy() +{ + +} \ No newline at end of file diff --git a/kraken/KRSampler.h b/kraken/KRSampler.h index a91975b..cfc6b37 100644 --- a/kraken/KRSampler.h +++ b/kraken/KRSampler.h @@ -41,11 +41,12 @@ class KRSampler : public KRContextObject { public: - KRSampler(KRContext& context, const SamplerInfo& info); + KRSampler(KRContext& context); virtual ~KRSampler(); VkSampler getSampler(KrDeviceHandle &handle); - + bool createSamplers(const SamplerInfo& info); + void destroy(); private: typedef std::vector> SamplerSet; SamplerSet m_samplers; diff --git a/kraken/KRSamplerManager.cpp b/kraken/KRSamplerManager.cpp index d285929..45ce3e0 100644 --- a/kraken/KRSamplerManager.cpp +++ b/kraken/KRSamplerManager.cpp @@ -98,7 +98,8 @@ KRSampler* KRSamplerManager::getSampler(const SamplerInfo& info) if (itr != m_samplers.end()) { return itr->second; } - KRSampler* sampler = new KRSampler(getContext(), info); + KRSampler* sampler = new KRSampler(getContext()); + sampler->createSamplers(info); m_samplers[info] = sampler; return sampler; }