本文整理汇总了C++中FilePtr::Read方法的典型用法代码示例。如果您正苦于以下问题:C++ FilePtr::Read方法的具体用法?C++ FilePtr::Read怎么用?C++ FilePtr::Read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilePtr
的用法示例。
在下文中一共展示了FilePtr::Read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
std::shared_ptr<ShaderProgram> ContentManager::LoadNew(const std::string &name, bool async)
{
FilePtr fp = FileManager::Instance()->OpenFile(name);
if (!fp)
{
LOG("Failed loading '%s': file not found", name.c_str());
return nullptr;
}
int size = fp->GetSize();
char *data = new char[size + 1];
fp->Read(data, size);
fp->Close();
data[size] = 0;
ShaderProgramPtr program = std::make_shared<ShaderProgram>();
ShaderPtr vs = std::make_shared<Shader>(GL_VERTEX_SHADER);
if (!vs->Load(data))
{
LOG("Error loading '%s' vertex shader: %s", name.c_str(), vs->ErrorMessage().c_str());
return nullptr;
}
program->AddShader(vs);
ShaderPtr ps = std::make_shared<Shader>(GL_FRAGMENT_SHADER);
if (!ps->Load(data))
{
LOG("Error loading '%s' fragment shader: %s", name.c_str(), vs->ErrorMessage().c_str());
return nullptr;
}
program->AddShader(ps);
if (!program->Link())
{
LOG("Error loading '%s': link failed", name.c_str());
return nullptr;
}
ContentManager::Instance()->CacheObject(name, program);
LOG("Loaded shader '%s'", name.c_str());
return program;
}
示例2: Create
bool DisplaySurface::Create(const boost::any& _rConfig)
{
CreateInfo* pInfo = boost::any_cast<CreateInfo*>(_rConfig);
FilePtr pFile = NULL;
bool bResult = (NULL != pInfo);
{
pFile = FS::GetRoot()->OpenFile(pInfo->m_strPath, FS::EOpenMode_READBINARY);
bResult = (NULL != pFile);
}
if (false != bResult)
{
int sSize = pFile->Size();
unsigned char* pBuffer = new unsigned char[sSize];
sSize = pFile->Read(pBuffer, sSize);
bResult = SUCCEEDED(D3DXGetImageInfoFromFileInMemory(pBuffer, sSize, &m_oInfo));
if (false != bResult)
{
#pragma message(__FUNCTION__" : for better support some image formats must be converted into supported surface format. For example luminance image should be translated into paletted surface.")
bResult = SUCCEEDED(m_rDisplay.GetDevicePtr()->CreateOffscreenPlainSurface(m_oInfo.Width, m_oInfo.Height, m_oInfo.Format, D3DPOOL_DEFAULT, &m_pSurface, NULL));
}
if (false != bResult)
{
bResult = SUCCEEDED(D3DXLoadSurfaceFromFileInMemory(m_pSurface, NULL, NULL, pBuffer, sSize, NULL, D3DX_FILTER_NONE, 0xff000000, NULL));
}
if (false != bResult)
{
m_uBPP = m_rDisplay.GetFormatBitsPerPixel(m_oInfo.Format);
bResult = (0 != m_uBPP);
}
delete[] pBuffer;
FS::GetRoot()->CloseFile(pFile);
}
return bResult;
}
示例3: Loadfile
bool Lua::Loadfile(const string& _strFileName, LuaStatePtr _pState)
{
FilePtr pFile = FS::GetRoot()->OpenFile(_strFileName, FS::EOpenMode_READTEXT);
bool bResult = (NULL != pFile);
if (false != bResult)
{
int sSize = pFile->Size();
char* pSourceCode = new char[sSize + 1];
sSize = pFile->Read(pSourceCode, sSize);
FS::GetRoot()->CloseFile(pFile);
pSourceCode[sSize] = '\0';
_pState = (NULL == _pState) ? s_pState : _pState;
const int sResult = _pState->DoString(pSourceCode);
bResult = (0 == sResult);
delete[] pSourceCode;
if (false == bResult)
{
OutputError(sResult, _pState);
}
}
return bResult;
}