本文整理汇总了C++中Shader::IsCompiledAndLinked方法的典型用法代码示例。如果您正苦于以下问题:C++ Shader::IsCompiledAndLinked方法的具体用法?C++ Shader::IsCompiledAndLinked怎么用?C++ Shader::IsCompiledAndLinked使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shader
的用法示例。
在下文中一共展示了Shader::IsCompiledAndLinked方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Load
ShaderPtr ShaderLoader::Load(const Path & vertex_file_name, const Path & fragment_file_name, bool replaceCached)
{
Path resourceName = vertex_file_name.filename().generic_string() + fragment_file_name.filename().generic_string();
Resource<Shader> existingResource = this->GetResource(resourceName);
if (existingResource.resource && !replaceCached)
{
GetContext().GetLogger()->log(LOG_LOG, "Shader returned from cache.");
return existingResource.resource;
}
FilePtr vertexFile = GetContext().GetFileSystem()->OpenRead(vertex_file_name);
FilePtr fragmentFile = GetContext().GetFileSystem()->OpenRead(fragment_file_name);
if (!vertexFile->IsOpen() || !fragmentFile->IsOpen())
{
return ShaderPtr();
}
GetContext().GetLogger()->log(LOG_LOG, "Shader resource name: %s", resourceName.generic_string().c_str());
ByteBufferPtr vertexBuffer = vertexFile->ReadText();
ByteBufferPtr fragmentBuffer = fragmentFile->ReadText();
Shader * shader = new Shader(resourceName.generic_string(), (char*)vertexBuffer->data(), (char*)fragmentBuffer->data(), "");
shader->Compile();
if (shader->IsCompiledAndLinked())
{
if (existingResource.resource)
{
RemoveResource(existingResource.path);
GetContext().GetLogger()->log(LOG_LOG, "Removed cached shader: '%s'.", resourceName.c_str());
}
GetContext().GetLogger()->log(LOG_LOG, "Shader loaded: '%s'.", resourceName.c_str());
Resource<Shader> res(ShaderPtr(shader), resourceName);
this->AddResource(res);
return res.resource;
}
else
{
delete shader;
if (existingResource.resource)
GetContext().GetLogger()->log(LOG_ERROR, "Shader failed to load: '%s', using cached version.", resourceName.generic_string().c_str());
else
GetContext().GetLogger()->log(LOG_ERROR, "Shader failed to load: '%s'.", resourceName.generic_string().c_str());
return existingResource.resource;
}
}