diff --git a/Source/Plugins/Plugin_VideoOGL/Src/SamplerCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/SamplerCache.cpp index b0e6e1f8aa..d883d7e981 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/SamplerCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/SamplerCache.cpp @@ -49,36 +49,30 @@ void SamplerCache::SetSamplerState(int stage, const TexMode0& tm0, const TexMode // TODO: Should keep a circular buffer for each stage of recently used samplers. - auto const& active_sampler = m_active_samplers[stage]; + auto& active_sampler = m_active_samplers[stage]; if (active_sampler.first != params || !active_sampler.second.sampler_id) { // Active sampler does not match parameters (or is invalid), bind the proper one. - auto const new_sampler = GetEntry(params); - - glBindSampler(stage, new_sampler.second.sampler_id); - m_active_samplers[stage] = new_sampler; + active_sampler.first = params; + active_sampler.second = GetEntry(params); + glBindSampler(stage, active_sampler.second.sampler_id); } - - //active_it->second.last_frame_used = frameCount; } -auto SamplerCache::GetEntry(const Params& params) -> std::pair +auto SamplerCache::GetEntry(const Params& params) -> Value& { - auto it = m_cache.find(params); - if (m_cache.end() == it) + auto& val = m_cache[params]; + if (!val.sampler_id) { // Sampler not found in cache, create it. - Value val; glGenSamplers(1, &val.sampler_id); SetParameters(val.sampler_id, params); - it = m_cache.insert(std::make_pair(params, val)).first; - // TODO: Maybe kill old samplers if the cache gets huge. It doesn't seem to get huge though. //ERROR_LOG(VIDEO, "Sampler cache size is now %ld.", m_cache.size()); } - return *it; + return val; } void SamplerCache::SetParameters(GLuint sampler_id, const Params& params) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/SamplerCache.h b/Source/Plugins/Plugin_VideoOGL/Src/SamplerCache.h index 5c1d951e1a..4666e5bf19 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/SamplerCache.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/SamplerCache.h @@ -59,15 +59,13 @@ private: { Value() : sampler_id() - // , last_frame_used() {} GLuint sampler_id; - //int last_frame_used; }; void SetParameters(GLuint sampler_id, const Params& params); - std::pair GetEntry(const Params& params); + Value& GetEntry(const Params& params); std::map m_cache; std::pair m_active_samplers[8];