本文整理汇总了C++中ProgramObject::IsValid方法的典型用法代码示例。如果您正苦于以下问题:C++ ProgramObject::IsValid方法的具体用法?C++ ProgramObject::IsValid怎么用?C++ ProgramObject::IsValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProgramObject
的用法示例。
在下文中一共展示了ProgramObject::IsValid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadFromCache
iShaderProgram::CacheLoadResult csShaderGLCGCommon::LoadFromCache (
iHierarchicalCache* cache, iBase* previous, iDocumentNode* node,
csRef<iString>* failReason, csRef<iString>* tag,
ProfileLimitsPair* cacheLimits)
{
if (!cache) return iShaderProgram::loadFail;
csRef<iShaderProgramCG> prevCG (scfQueryInterfaceSafe<iShaderProgramCG> (
previous));
csRef<iStringArray> allCachedPrograms;
if ((programType == progVP) && prevCG.IsValid())
{
csShaderGLCGFP* prevFP = static_cast<csShaderGLCGFP*> (
(iShaderProgramCG*)prevCG);
csString tagStr ("CG");
tagStr += prevFP->cacheLimits.ToString();
if (failReason) failReason->AttachNew (
new scfString ("paired cached programs not found"));
allCachedPrograms.AttachNew (new scfStringArray);
allCachedPrograms->Push (tagStr);
}
else
allCachedPrograms = cache->GetSubItems ("/");
if (!allCachedPrograms.IsValid() || (allCachedPrograms->GetSize() == 0))
{
if (failReason) failReason->AttachNew (
new scfString ("no cached programs found"));
return iShaderProgram::loadFail;
}
if (!GetProgramNode (node)) return iShaderProgram::loadFail;
csRef<iDataBuffer> programBuffer = GetProgramData();
CS::Utility::Checksum::MD5::Digest progHash = CS::Utility::Checksum::MD5::Encode (
programBuffer->GetData(), programBuffer->GetSize());
csArray<CachedShaderWrapper> cachedProgWrappers;
for (size_t i = 0; i < allCachedPrograms->GetSize(); i++)
{
const char* tag = allCachedPrograms->Get (i);
if ((tag[0] != 'C') || (tag[1] != 'G')) continue;
CachedShaderWrapper wrapper;
if (!wrapper.limits.FromString (tag+2)) continue;
wrapper.name = tag;
csString cachePath ("/");
cachePath.Append (tag);
csRef<iDataBuffer> cacheBuf = cache->ReadCache (cachePath);
if (!cacheBuf.IsValid()) continue;
csRef<iFile> cacheFile;
cacheFile.AttachNew (new csMemFile (cacheBuf, true));
wrapper.cacheFile = cacheFile;
uint32 diskMagic;
if (cacheFile->Read ((char*)&diskMagic, sizeof (diskMagic))
!= sizeof (diskMagic)) continue;
if (csLittleEndian::UInt32 (diskMagic) != cacheFileMagic)
continue;
CS::Utility::Checksum::MD5::Digest diskHash;
if (cacheFile->Read ((char*)&diskHash, sizeof (diskHash))
!= sizeof (diskHash)) continue;
if (diskHash != progHash) continue;
cachedProgWrappers.Push (wrapper);
}
if (cachedProgWrappers.GetSize() == 0)
{
if (failReason && !*failReason) failReason->AttachNew (
new scfString ("all cached programs failed to read"));
return iShaderProgram::loadFail;
}
cachedProgWrappers.Sort ();
ProfileLimits currentLimits (
(programType == progVP) ? shaderPlug->currentLimits.vp
: shaderPlug->currentLimits.fp);
bool strictMatch = (programType == progVP) ? shaderPlug->strictMatchVP
: shaderPlug->strictMatchFP;
const char* progTypeNode = 0;
switch (programType)
{
case progVP: progTypeNode = "cgvp"; break;
case progFP: progTypeNode = "cgfp"; break;
}
csString allReasons;
bool oneReadCorrectly = false;
ProfileLimits bestLimits (
CS::PluginCommon::ShaderProgramPluginGL::Other,
CG_PROFILE_UNKNOWN);
bool bestLimitsSet = false;
for (size_t i = cachedProgWrappers.GetSize(); i-- > 0;)
{
const CachedShaderWrapper& wrapper = cachedProgWrappers[i];
//.........这里部分代码省略.........
示例2: WriteToCacheWorker
bool csShaderGLCGCommon::WriteToCacheWorker (iHierarchicalCache* cache,
const ProfileLimits& limits, const ProfileLimitsPair& limitsPair,
const char* tag, const ProgramObject& program,
csString& failReason)
{
if (!cache) return false;
csMemFile cacheFile;
uint32 diskMagic = csLittleEndian::UInt32 (cacheFileMagic);
if (cacheFile.Write ((char*)&diskMagic, sizeof (diskMagic))
!= sizeof (diskMagic))
{
failReason = "write error (magic)";
return false;
}
csRef<iDataBuffer> programBuffer = GetProgramData();
CS::Utility::Checksum::MD5::Digest progHash = CS::Utility::Checksum::MD5::Encode (
programBuffer->GetData(), programBuffer->GetSize());
if (cacheFile.Write ((char*)&progHash, sizeof (progHash))
!= sizeof (progHash))
{
failReason = "write error (hash)";
return false;
}
if (!program.IsValid())
{
uint32 diskState = csLittleEndian::UInt32 (cpsInvalid);
if (cacheFile.Write ((char*)&diskState, sizeof (diskState))
!= sizeof (diskState))
{
failReason = "write error (state-invalid)";
return false;
}
}
else
{
{
uint32 diskState = csLittleEndian::UInt32 (cpsValid);
if (cacheFile.Write ((char*)&diskState, sizeof (diskState))
!= sizeof (diskState))
{
failReason = "write error (state-valid)";
return false;
}
}
CS::PluginCommon::ShaderCacheHelper::WriteString (&cacheFile, description);
CS_ASSERT(!program.GetID().archive.IsEmpty());
CS::PluginCommon::ShaderCacheHelper::WriteString (&cacheFile,
program.GetID().archive);
CS_ASSERT(!program.GetID().item.IsEmpty());
CS::PluginCommon::ShaderCacheHelper::WriteString (&cacheFile,
program.GetID().item);
}
csString cacheName ("/");
cacheName += tag;
if (!cache->CacheData (cacheFile.GetData(), cacheFile.GetSize(),
cacheName))
{
failReason = "failed writing to cache";
return false;
}
return true;
}