File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,8 @@ namespace
6464}
6565
6666std::unordered_map<backend::ProgramType, backend::Program*> ProgramCache::_cachedPrograms;
67+ std::unordered_map<std::string, backend::Program*> ProgramCache::_cachedCustomPrograms;
68+
6769ProgramCache* ProgramCache::_sharedProgramCache = nullptr ;
6870
6971ProgramCache* ProgramCache::getInstance ()
@@ -303,6 +305,29 @@ void ProgramCache::removeAllPrograms()
303305 program.second ->release ();
304306 }
305307 _cachedPrograms.clear ();
308+
309+ for (auto & program : _cachedCustomPrograms)
310+ {
311+ program.second ->release ();
312+ }
313+ _cachedCustomPrograms.clear ();
314+ }
315+
316+ void ProgramCache::addCustomProgram (const std::string &key, backend::Program *program)
317+ {
318+ _cachedCustomPrograms.emplace (key, program);
319+ }
320+
321+ backend::Program* ProgramCache::getCustomProgram (const std::string &key) const
322+ {
323+ const auto & iter = ProgramCache::_cachedCustomPrograms.find (key);
324+ if (ProgramCache::_cachedCustomPrograms.end () != iter)
325+ {
326+ return iter->second ;
327+ }
328+
329+ CCLOG (" Warning: program %s not found in cache." , key.c_str ());
330+ return nullptr ;
306331}
307332
308333CC_BACKEND_END
Original file line number Diff line number Diff line change @@ -69,6 +69,16 @@ class ProgramCache : public Ref
6969 */
7070 void removeAllPrograms ();
7171
72+ /* *
73+ * Add custom program to the cache.
74+ * @param key Specifies the key used to store the program.
75+ * @param program Specifies the program to store in the cache.
76+ */
77+ void addCustomProgram (const std::string& key, backend::Program* program);
78+
79+ // / Get custom program from cache.
80+ backend::Program* getCustomProgram (const std::string& key) const ;
81+
7282protected:
7383 ProgramCache () = default ;
7484 virtual ~ProgramCache ();
@@ -82,6 +92,7 @@ class ProgramCache : public Ref
8292 void addProgram (ProgramType type);
8393
8494 static std::unordered_map<backend::ProgramType, backend::Program*> _cachedPrograms; // /< The cached program object.
95+ static std::unordered_map<std::string, backend::Program*> _cachedCustomPrograms; // /< The cached custom program object.
8596 static ProgramCache *_sharedProgramCache; // /< A shared instance of the program cache.
8697};
8798
You can’t perform that action at this time.
0 commit comments