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
64
64
}
65
65
66
66
std::unordered_map<backend::ProgramType, backend::Program*> ProgramCache::_cachedPrograms;
67
+ std::unordered_map<std::string, backend::Program*> ProgramCache::_cachedCustomPrograms;
68
+
67
69
ProgramCache* ProgramCache::_sharedProgramCache = nullptr ;
68
70
69
71
ProgramCache* ProgramCache::getInstance ()
@@ -303,6 +305,29 @@ void ProgramCache::removeAllPrograms()
303
305
program.second ->release ();
304
306
}
305
307
_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 ;
306
331
}
307
332
308
333
CC_BACKEND_END
Original file line number Diff line number Diff line change @@ -69,6 +69,16 @@ class ProgramCache : public Ref
69
69
*/
70
70
void removeAllPrograms ();
71
71
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
+
72
82
protected:
73
83
ProgramCache () = default ;
74
84
virtual ~ProgramCache ();
@@ -82,6 +92,7 @@ class ProgramCache : public Ref
82
92
void addProgram (ProgramType type);
83
93
84
94
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.
85
96
static ProgramCache *_sharedProgramCache; // /< A shared instance of the program cache.
86
97
};
87
98
You can’t perform that action at this time.
0 commit comments