2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2018-2019 Xiamen Yaji Software Co., Ltd.
|
2022-09-24 10:42:11 +08:00
|
|
|
Copyright (c) 2022 Bytedance Inc.
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-10-12 19:44:31 +08:00
|
|
|
#include "ProgramManager.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
#include "Device.h"
|
|
|
|
#include "ShaderModule.h"
|
2023-06-11 13:08:08 +08:00
|
|
|
#include "renderer/Shaders.h"
|
|
|
|
#include "base/Macros.h"
|
|
|
|
#include "base/Configuration.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2023-07-25 09:13:20 +08:00
|
|
|
#include "xxhash.h"
|
2023-07-25 19:06:12 +08:00
|
|
|
#include <inttypes.h>
|
2023-07-25 09:13:20 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BACKEND_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-10-12 19:44:31 +08:00
|
|
|
ProgramManager* ProgramManager::_sharedProgramManager = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-10-12 19:44:31 +08:00
|
|
|
ProgramManager* ProgramManager::getInstance()
|
|
|
|
{
|
|
|
|
if (!_sharedProgramManager)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-10-12 19:44:31 +08:00
|
|
|
_sharedProgramManager = new ProgramManager();
|
|
|
|
if (!_sharedProgramManager->init())
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-10-12 19:44:31 +08:00
|
|
|
AX_SAFE_DELETE(_sharedProgramManager);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2022-10-12 19:44:31 +08:00
|
|
|
return _sharedProgramManager;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2022-10-12 19:44:31 +08:00
|
|
|
void ProgramManager::destroyInstance()
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-10-12 19:44:31 +08:00
|
|
|
AX_SAFE_RELEASE_NULL(_sharedProgramManager);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2023-07-25 09:13:20 +08:00
|
|
|
ProgramManager::ProgramManager()
|
|
|
|
{
|
|
|
|
_programIdGen = XXH64_createState();
|
|
|
|
}
|
|
|
|
|
2022-10-12 19:44:31 +08:00
|
|
|
ProgramManager::~ProgramManager()
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2023-07-25 09:13:20 +08:00
|
|
|
XXH64_freeState(_programIdGen);
|
|
|
|
|
2022-07-21 19:19:08 +08:00
|
|
|
for (auto&& program : _cachedPrograms)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_SAFE_RELEASE(program.second);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2022-10-12 19:44:31 +08:00
|
|
|
AXLOGINFO("deallocing ProgramManager: %p", this);
|
|
|
|
backend::ShaderCache::destroyInstance();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2022-09-23 22:41:30 +08:00
|
|
|
// ### end of vertex layout setup functions
|
2023-07-20 17:55:16 +08:00
|
|
|
static std::string joinPath(std::string_view path, std::string_view childPath)
|
|
|
|
{
|
2023-07-20 10:18:30 +08:00
|
|
|
std::string ret;
|
|
|
|
ret.reserve(path.length() + childPath.length());
|
|
|
|
ret += path;
|
|
|
|
ret += childPath;
|
|
|
|
return ret;
|
|
|
|
}
|
2022-09-23 22:41:30 +08:00
|
|
|
|
2022-10-12 19:44:31 +08:00
|
|
|
bool ProgramManager::init()
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2023-07-20 10:18:30 +08:00
|
|
|
auto fileUtils = FileUtils::getInstance();
|
|
|
|
#if AX_TARGET_PLATFORM == AX_PLATFORM_WIN32 || AX_TARGET_PLATFORM == AX_PLATFORM_LINUX
|
|
|
|
// load compiled shader from exeDir/axslc
|
|
|
|
auto axslcDir = joinPath(fileUtils->getAppRoot(), "axslc"sv);
|
|
|
|
fileUtils->addSearchPath(axslcDir);
|
2023-07-20 17:55:16 +08:00
|
|
|
#else // APPLE, ANDROID, WINRT
|
2023-07-20 10:18:30 +08:00
|
|
|
fileUtils->addSearchPath("axslc"sv);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
registerProgram(ProgramType::POSITION_TEXTURE_COLOR, positionTextureColor_vert, positionTextureColor_frag,
|
2023-07-25 09:13:20 +08:00
|
|
|
VertexLayoutType::Sprite);
|
|
|
|
registerProgram(ProgramType::DUAL_SAMPLER, positionTextureColor_vert, dualSampler_frag, VertexLayoutType::Sprite);
|
2023-07-20 10:18:30 +08:00
|
|
|
registerProgram(ProgramType::LABEL_DISTANCE_NORMAL, positionTextureColor_vert, label_distanceNormal_frag,
|
2023-07-25 09:13:20 +08:00
|
|
|
VertexLayoutType::Sprite);
|
|
|
|
registerProgram(ProgramType::LABEL_NORMAL, positionTextureColor_vert, label_normal_frag, VertexLayoutType::Sprite);
|
2023-07-20 17:55:16 +08:00
|
|
|
registerProgram(ProgramType::LABLE_OUTLINE, positionTextureColor_vert, label_outline_frag,
|
2023-07-25 09:13:20 +08:00
|
|
|
VertexLayoutType::Sprite);
|
2023-07-20 17:55:16 +08:00
|
|
|
registerProgram(ProgramType::LABEL_DISTANCE_OUTLINE, positionTextureColor_vert, label_distanceOutline_frag,
|
2023-07-25 09:13:20 +08:00
|
|
|
VertexLayoutType::Sprite);
|
2023-07-20 17:55:16 +08:00
|
|
|
registerProgram(ProgramType::LABLE_DISTANCE_GLOW, positionTextureColor_vert, label_distanceGlow_frag,
|
2023-07-25 09:13:20 +08:00
|
|
|
VertexLayoutType::Sprite);
|
2023-07-20 10:18:30 +08:00
|
|
|
registerProgram(ProgramType::POSITION_COLOR_LENGTH_TEXTURE, positionColorLengthTexture_vert,
|
2023-07-25 09:13:20 +08:00
|
|
|
positionColorLengthTexture_frag, VertexLayoutType::DrawNode);
|
2023-07-20 10:18:30 +08:00
|
|
|
registerProgram(ProgramType::POSITION_COLOR_TEXTURE_AS_POINTSIZE, positionColorTextureAsPointsize_vert,
|
2023-07-25 09:13:20 +08:00
|
|
|
positionColor_frag, VertexLayoutType::DrawNode);
|
|
|
|
registerProgram(ProgramType::POSITION_COLOR, positionColor_vert, positionColor_frag, VertexLayoutType::posColor);
|
|
|
|
registerProgram(ProgramType::LAYER_RADIA_GRADIENT, position_vert, layer_radialGradient_frag, VertexLayoutType::Pos);
|
2023-07-20 10:18:30 +08:00
|
|
|
registerProgram(ProgramType::POSITION_TEXTURE, positionTexture_vert, positionTexture_frag,
|
2023-07-25 09:13:20 +08:00
|
|
|
VertexLayoutType::Texture);
|
2023-07-20 10:18:30 +08:00
|
|
|
registerProgram(ProgramType::POSITION_TEXTURE_COLOR_ALPHA_TEST, positionTextureColor_vert,
|
2023-07-25 09:13:20 +08:00
|
|
|
positionTextureColorAlphaTest_frag, VertexLayoutType::Sprite);
|
|
|
|
registerProgram(ProgramType::POSITION_UCOLOR, positionUColor_vert, positionColor_frag, VertexLayoutType::Pos);
|
2023-07-20 10:18:30 +08:00
|
|
|
registerProgram(ProgramType::DUAL_SAMPLER_GRAY, positionTextureColor_vert, dualSampler_gray_frag,
|
2023-07-25 09:13:20 +08:00
|
|
|
VertexLayoutType::Sprite);
|
|
|
|
registerProgram(ProgramType::GRAY_SCALE, positionTextureColor_vert, grayScale_frag, VertexLayoutType::Sprite);
|
|
|
|
registerProgram(ProgramType::LINE_COLOR_3D, lineColor_vert, lineColor_frag, VertexLayoutType::DrawNode3D);
|
|
|
|
registerProgram(ProgramType::CAMERA_CLEAR, cameraClear_vert, cameraClear_frag, VertexLayoutType::Sprite);
|
|
|
|
registerProgram(ProgramType::SKYBOX_3D, skybox_vert, skybox_frag, VertexLayoutType::SkyBox);
|
2023-07-20 10:18:30 +08:00
|
|
|
registerProgram(ProgramType::SKINPOSITION_TEXTURE_3D, skinPositionTexture_vert, colorTexture_frag,
|
2023-07-25 09:13:20 +08:00
|
|
|
VertexLayoutType::Unspec);
|
2023-07-20 10:18:30 +08:00
|
|
|
registerProgram(ProgramType::SKINPOSITION_NORMAL_TEXTURE_3D, skinPositionNormalTexture_vert,
|
2023-07-25 09:13:20 +08:00
|
|
|
colorNormalTexture_frag, VertexLayoutType::Unspec);
|
2023-07-20 17:55:16 +08:00
|
|
|
registerProgram(ProgramType::POSITION_NORMAL_TEXTURE_3D, positionNormalTexture_vert, colorNormalTexture_frag,
|
2023-07-25 09:13:20 +08:00
|
|
|
VertexLayoutType::Unspec);
|
2023-07-20 10:18:30 +08:00
|
|
|
registerProgram(ProgramType::POSITION_TEXTURE_3D, positionTexture3D_vert, colorTexture_frag,
|
2023-07-25 09:13:20 +08:00
|
|
|
VertexLayoutType::Unspec);
|
2023-07-28 14:13:01 +08:00
|
|
|
registerProgram(ProgramType::POSITION_TEXTURE_3D_INSTANCE, positionTextureInstance_vert, colorTexture_frag,
|
|
|
|
VertexLayoutType::Unspec);
|
2023-07-25 09:13:20 +08:00
|
|
|
registerProgram(ProgramType::POSITION_3D, positionTexture3D_vert, color_frag, VertexLayoutType::Sprite);
|
2023-07-20 10:18:30 +08:00
|
|
|
registerProgram(ProgramType::POSITION_NORMAL_3D, positionNormalTexture_vert, colorNormal_frag,
|
2023-07-25 09:13:20 +08:00
|
|
|
VertexLayoutType::Unspec);
|
2023-07-20 17:55:16 +08:00
|
|
|
registerProgram(ProgramType::POSITION_BUMPEDNORMAL_TEXTURE_3D, positionNormalTexture_vert_1,
|
2023-07-25 09:13:20 +08:00
|
|
|
colorNormalTexture_frag_1, VertexLayoutType::Unspec);
|
2023-07-20 17:55:16 +08:00
|
|
|
registerProgram(ProgramType::SKINPOSITION_BUMPEDNORMAL_TEXTURE_3D, skinPositionNormalTexture_vert_1,
|
2023-07-25 09:13:20 +08:00
|
|
|
colorNormalTexture_frag_1, VertexLayoutType::Unspec);
|
|
|
|
registerProgram(ProgramType::TERRAIN_3D, terrain_vert, terrain_frag, VertexLayoutType::Terrain3D);
|
|
|
|
registerProgram(ProgramType::PARTICLE_TEXTURE_3D, particle_vert, particleTexture_frag, VertexLayoutType::PU3D);
|
|
|
|
registerProgram(ProgramType::PARTICLE_COLOR_3D, particle_vert, particleColor_frag, VertexLayoutType::PU3D);
|
|
|
|
registerProgram(ProgramType::QUAD_COLOR_2D, quadColor_vert, quadColor_frag, VertexLayoutType::Unspec);
|
|
|
|
registerProgram(ProgramType::QUAD_TEXTURE_2D, quadTexture_vert, quadTexture_frag, VertexLayoutType::Unspec);
|
|
|
|
registerProgram(ProgramType::HSV, positionTextureColor_vert, hsv_frag, VertexLayoutType::Sprite);
|
2023-07-20 10:18:30 +08:00
|
|
|
registerProgram(ProgramType::HSV_DUAL_SAMPLER, positionTextureColor_vert, dualSampler_hsv_frag,
|
2023-07-25 09:13:20 +08:00
|
|
|
VertexLayoutType::Sprite);
|
2021-06-27 20:58:50 +08:00
|
|
|
|
2023-07-20 17:55:16 +08:00
|
|
|
registerProgram(ProgramType::VIDEO_TEXTURE_YUY2, positionTextureColor_vert, videoTextureYUY2_frag,
|
2023-07-25 09:13:20 +08:00
|
|
|
VertexLayoutType::Sprite);
|
2023-07-20 17:55:16 +08:00
|
|
|
registerProgram(ProgramType::VIDEO_TEXTURE_NV12, positionTextureColor_vert, videoTextureNV12_frag,
|
2023-07-25 09:13:20 +08:00
|
|
|
VertexLayoutType::Sprite);
|
2023-03-25 08:37:51 +08:00
|
|
|
|
2021-06-27 20:58:50 +08:00
|
|
|
// The builtin dual sampler shader registry
|
|
|
|
ProgramStateRegistry::getInstance()->registerProgram(ProgramType::POSITION_TEXTURE_COLOR,
|
2023-07-20 17:55:16 +08:00
|
|
|
TextureSamplerFlag::DUAL_SAMPLER, ProgramType::DUAL_SAMPLER);
|
2021-06-27 20:58:50 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ProgramStateRegistry::getInstance()->registerProgram(ProgramType::GRAY_SCALE, TextureSamplerFlag::DUAL_SAMPLER,
|
2023-07-19 23:41:16 +08:00
|
|
|
ProgramType::DUAL_SAMPLER_GRAY);
|
2021-06-27 20:58:50 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ProgramStateRegistry::getInstance()->registerProgram(ProgramType::HSV, TextureSamplerFlag::DUAL_SAMPLER,
|
2023-07-19 23:41:16 +08:00
|
|
|
ProgramType::HSV_DUAL_SAMPLER);
|
2019-11-23 20:27:39 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-07-25 09:13:20 +08:00
|
|
|
Program* ProgramManager::getBuiltinProgram(uint32_t type)
|
2020-10-16 16:23:14 +08:00
|
|
|
{
|
2023-07-25 09:13:20 +08:00
|
|
|
assert(type < ProgramType::BUILTIN_COUNT);
|
|
|
|
|
|
|
|
auto& info = _builtinRegistry[static_cast<int>(type)];
|
|
|
|
return loadProgram(info.vsName, info.fsName, type, static_cast<uint64_t>(type), info.vlt);
|
2020-10-16 16:23:14 +08:00
|
|
|
}
|
|
|
|
|
2023-07-25 09:13:20 +08:00
|
|
|
Program* ProgramManager::loadProgram(uint64_t progId)
|
2020-10-16 16:23:14 +08:00
|
|
|
{
|
2023-07-25 09:13:20 +08:00
|
|
|
if (progId < ProgramType::BUILTIN_COUNT)
|
|
|
|
return getBuiltinProgram(static_cast<uint32_t>(progId));
|
2020-10-16 16:23:14 +08:00
|
|
|
|
2023-07-25 09:13:20 +08:00
|
|
|
auto it = _customRegistry.find(progId);
|
|
|
|
if (it != _customRegistry.end())
|
|
|
|
return loadProgram(it->second.vsName, it->second.fsName, ProgramType::CUSTOM_PROGRAM, progId, it->second.vlt);
|
|
|
|
return nullptr;
|
2020-10-16 16:23:14 +08:00
|
|
|
}
|
|
|
|
|
2023-07-25 09:13:20 +08:00
|
|
|
Program* ProgramManager::loadProgram(std::string_view vsName, std::string_view fsName, VertexLayoutType vlt)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2023-07-25 09:13:20 +08:00
|
|
|
return loadProgram(vsName, fsName, ProgramType::CUSTOM_PROGRAM, computeProgramId(vsName, fsName), vlt);
|
|
|
|
}
|
|
|
|
|
|
|
|
Program* ProgramManager::loadProgram(std::string_view vsName,
|
|
|
|
std::string_view fsName,
|
|
|
|
uint32_t progType,
|
|
|
|
uint64_t progId,
|
|
|
|
VertexLayoutType vlt)
|
|
|
|
{
|
|
|
|
assert(!vsName.empty() && !fsName.empty());
|
|
|
|
|
|
|
|
auto it = _cachedPrograms.find(progId);
|
|
|
|
if (it != _cachedPrograms.end())
|
|
|
|
return it->second;
|
|
|
|
|
2023-07-25 19:06:12 +08:00
|
|
|
AXLOG("Loading shader: %" PRIu64 " %s, %s ...", progId, vsName.data(), fsName.data());
|
|
|
|
|
2023-07-25 09:13:20 +08:00
|
|
|
auto fileUtils = FileUtils::getInstance();
|
|
|
|
auto vertFile = fileUtils->fullPathForFilename(vsName);
|
|
|
|
auto fragFile = fileUtils->fullPathForFilename(fsName);
|
|
|
|
auto vertSource = fileUtils->getStringFromFile(vertFile);
|
|
|
|
auto fragSource = fileUtils->getStringFromFile(fragFile);
|
|
|
|
auto program = backend::Device::getInstance()->newProgram(vertSource, fragSource);
|
2020-10-16 16:23:14 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (program)
|
|
|
|
{
|
2023-07-25 09:13:20 +08:00
|
|
|
program->setProgramIds(progType, progId);
|
|
|
|
if (vlt < VertexLayoutType::Count)
|
|
|
|
program->setupVertexLayout(vlt);
|
|
|
|
_cachedPrograms.emplace(progId, program);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2020-10-16 16:23:14 +08:00
|
|
|
return program;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2023-07-25 09:13:20 +08:00
|
|
|
uint64_t ProgramManager::registerCustomProgram(std::string_view vsName,
|
|
|
|
std::string_view fsName,
|
|
|
|
VertexLayoutType vlt,
|
|
|
|
bool force)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2023-07-25 09:13:20 +08:00
|
|
|
return registerProgram(ProgramType::CUSTOM_PROGRAM, vsName, fsName, vlt, force);
|
2020-10-16 16:23:14 +08:00
|
|
|
}
|
|
|
|
|
2023-07-25 09:13:20 +08:00
|
|
|
uint64_t ProgramManager::registerProgram(uint32_t progType,
|
|
|
|
std::string_view vsName,
|
|
|
|
std::string_view fsName,
|
|
|
|
VertexLayoutType vlt,
|
|
|
|
bool force)
|
2020-10-16 16:23:14 +08:00
|
|
|
{
|
2023-07-25 09:13:20 +08:00
|
|
|
uint64_t progId = 0;
|
|
|
|
if (progType < ProgramType::BUILTIN_COUNT)
|
|
|
|
{
|
|
|
|
_builtinRegistry[static_cast<int>(progType)] = {vsName, fsName, vlt};
|
|
|
|
progId = progType;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else
|
|
|
|
{
|
2023-07-25 09:13:20 +08:00
|
|
|
progId = computeProgramId(vsName, fsName);
|
|
|
|
auto it = _customRegistry.find(progId);
|
2023-07-20 17:55:16 +08:00
|
|
|
if (it == _customRegistry.end())
|
2023-07-25 09:13:20 +08:00
|
|
|
_customRegistry.emplace(progId, BuiltinRegInfo{vsName, fsName, vlt});
|
|
|
|
else if (force)
|
|
|
|
it->second = BuiltinRegInfo{vsName, fsName, vlt};
|
|
|
|
else
|
|
|
|
progId = 0;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2023-07-25 09:13:20 +08:00
|
|
|
return progId;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2023-07-25 09:13:20 +08:00
|
|
|
uint64_t ProgramManager::computeProgramId(std::string_view vsName, std::string_view fsName)
|
|
|
|
{
|
|
|
|
XXH64_reset(_programIdGen, 0);
|
|
|
|
XXH64_update(_programIdGen, vsName.data(), vsName.length());
|
|
|
|
XXH64_update(_programIdGen, fsName.data(), fsName.length());
|
|
|
|
return XXH64_digest(_programIdGen);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProgramManager::unloadProgram(Program* program)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (!program)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2023-07-25 09:13:20 +08:00
|
|
|
auto it = _cachedPrograms.find(program->_programId);
|
|
|
|
if (it != _cachedPrograms.end())
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2023-07-25 09:13:20 +08:00
|
|
|
it->second->release();
|
|
|
|
_cachedPrograms.erase(it);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-25 09:13:20 +08:00
|
|
|
void ProgramManager::unloadUnusedPrograms()
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
for (auto iter = _cachedPrograms.cbegin(); iter != _cachedPrograms.cend();)
|
|
|
|
{
|
|
|
|
auto program = iter->second;
|
|
|
|
if (program->getReferenceCount() == 1)
|
|
|
|
{
|
2022-10-01 16:24:52 +08:00
|
|
|
// AXLOG("axmol: TextureCache: removing unused program");
|
2019-11-23 20:27:39 +08:00
|
|
|
program->release();
|
|
|
|
iter = _cachedPrograms.erase(iter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-25 09:13:20 +08:00
|
|
|
void ProgramManager::unloadAllPrograms()
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
ProgramStateRegistry::getInstance()->clearPrograms();
|
2022-07-21 19:19:08 +08:00
|
|
|
for (auto&& program : _cachedPrograms)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
program.second->release();
|
|
|
|
}
|
|
|
|
_cachedPrograms.clear();
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BACKEND_END
|