本文整理汇总了C++中IFileSystem::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ IFileSystem::Write方法的具体用法?C++ IFileSystem::Write怎么用?C++ IFileSystem::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileSystem
的用法示例。
在下文中一共展示了IFileSystem::Write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Create
bool CShaderHLSL::Create(P3D::sShaderDesc &desc)
{
const char *pData;
ULONG fsize;
IFileSystem* pFS = CRenderer::mEngine()->mFilesystem();
wchar path[P3DMAX_PATH];
wsprintf(path, P3DMAX_PATH-1, _W("shaders/%s.rshader"), desc.ShaderFile.Get());
FSFILE *fp = pFS->Load(path, (BYTE *&)pData, fsize, true);
if (!fp)
{
CON(MSG_ERR, _W("Can't open %s.hlsl shader file from data/shaders directory!"), desc.ShaderFile.Get());
return false;
}
ID3D10Blob *pShaderBlob = NULL;
ID3D10Blob *pErrors = NULL;
UINT flags = D3D10_SHADER_DEBUG; //D3D10_SHADER_OPTIMIZATION_LEVEL3
char profile[128];
switch(desc.ShaderType)
{
case SHADERTYPE_VERTEX_SHADER:
strcpy(profile, D3D10GetVertexShaderProfile(g_pD3ddev));
break;
case SHADERTYPE_GEOMETRY_SHADER:
strcpy(profile, D3D10GetGeometryShaderProfile(g_pD3ddev));
break;
case SHADERTYPE_PIXEL_SHADER:
strcpy(profile, D3D10GetPixelShaderProfile(g_pD3ddev));
break;
default:
CON(MSG_ERR, _W("Chader creation failed. No apropriate ShaderType given."));
return false;
}
CIncludeHandler includeHandler;
D3D10_SHADER_MACRO Shader_Macros[] =
{
{ "DX10", NULL },
{ "SM4", NULL },
NULL
};
if(!CheckHRResult(D3DX10CompileFromMemory(
pData,
fsize,
NULL,
Shader_Macros,
&includeHandler,
_W2A(desc.EntryFunction.Get()),
profile,
flags,
0,
NULL,
&pShaderBlob,
&pErrors,
NULL
)))
{
if(pErrors) CON(MSG_ERR, _W("%s"), _A2W((char*)pErrors->GetBufferPointer()));
else CON(MSG_ERR, _W("Error description not given"));
CON(MSG_ERR, _W("Shader %s could not be compiled"), desc.ShaderFile.Get());
SAFE_RELEASE(pErrors);
return false;
}
pFS->UnLoad(fp, (BYTE *)pData);
//save to cache
fp = pFS->Open(_W("cache/shaders/hlsl"), _W("wb"));
const char* cs = (const char*)pShaderBlob->GetBufferPointer();
pFS->Write(cs, 1, pShaderBlob->GetBufferSize(), fp);
pFS->Close(fp);
bool shaderCreated = false;
switch(desc.ShaderType)
{
case SHADERTYPE_VERTEX_SHADER:
shaderCreated = CheckHRResult(g_pD3ddev->CreateVertexShader(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), &m_pVS));
break;
case SHADERTYPE_GEOMETRY_SHADER:
shaderCreated = CheckHRResult(g_pD3ddev->CreateGeometryShader(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), &m_pGS));
break;
case SHADERTYPE_PIXEL_SHADER:
shaderCreated = CheckHRResult(g_pD3ddev->CreatePixelShader(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), &m_pPS));
break;
}
if(!shaderCreated)
{
CON(MSG_ERR, _W("Shader creation error"));
return false;
}
//if(!CheckHRResult(D3DReflect((DWORD*)pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), __uuidof(ID3D10ShaderReflection), &m_pReflection)))
if(!CheckHRResult(D3D10ReflectShader(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), &m_pReflection)))
{
CON(MSG_ERR, _W("Could not create a Shader reflection"));
return false;
//.........这里部分代码省略.........
示例2: Create
bool CShaderHLSL::Create(P3D::sShaderDesc &desc)
{
const char *pData;
ULONG fsize;
IFileSystem* pFS = CRenderer::mEngine()->mFilesystem();
wchar path[P3DMAX_PATH];
wsprintf(path, P3DMAX_PATH-1, _W("shaders/%s.rshader"), desc.ShaderFile.Get());
FSFILE *fp = pFS->Load(path, (BYTE *&)pData, fsize, true);
if (!fp)
{
CON(MSG_ERR, _W("Can't open %s.hlsl shader file from data/shaders directory!"), desc.ShaderFile.Get());
return false;
}
ID3DXBuffer *pShaderBlob = NULL;
ID3DXBuffer *pErrors = NULL;
DWORD flags = D3DXSHADER_DEBUG; //D3DXSHADER_OPTIMIZATION_LEVEL3
char profile[128];
switch(desc.ShaderType)
{
case SHADERTYPE_VERTEX_SHADER:
strcpy(profile, D3DXGetVertexShaderProfile(g_pD3ddev));
break;
case SHADERTYPE_PIXEL_SHADER:
strcpy(profile, D3DXGetPixelShaderProfile(g_pD3ddev));
break;
case SHADERTYPE_GEOMETRY_SHADER:
CON(MSG_ERR, _W("DX9 does not support geometry shaders."));
return false;
default:
CON(MSG_ERR, _W("Chader creation failed. No apropriate ShaderType given."));
return false;
}
CIncludeHandler includeHandler;
D3DXMACRO Shader_Macros[] =
{
{ "DX9", NULL },
{ "SM3", NULL },
NULL
};
if(FAILED(D3DXCompileShader(
pData,
fsize,
Shader_Macros,
&includeHandler,
_W2A(desc.EntryFunction.Get()),
profile,
flags,
&pShaderBlob,
&pErrors,
&m_pConstTable
)))
{
if(pErrors) CON(MSG_ERR, _W("%s"), _A2W((char*)pErrors->GetBufferPointer()));
else CON(MSG_ERR, _W("Error description not given"));
CON(MSG_ERR, _W("Shader %s could not be compiled"), desc.ShaderFile.Get());
SAFE_RELEASE(pErrors);
return false;
}
pFS->UnLoad(fp, (BYTE *)pData);
//save to cache
fp = pFS->Open(_W("cache/shaders/hlsl"), _W("wb"));
const char* cs = (const char*)pShaderBlob->GetBufferPointer();
pFS->Write(cs, 1, pShaderBlob->GetBufferSize(), fp);
pFS->Close(fp);
bool shaderCreated = false;
switch(desc.ShaderType)
{
case SHADERTYPE_VERTEX_SHADER:
shaderCreated = SUCCEEDED(g_pD3ddev->CreateVertexShader((const DWORD*)pShaderBlob->GetBufferPointer(), &m_pVS));
break;
case SHADERTYPE_PIXEL_SHADER:
shaderCreated = SUCCEEDED(g_pD3ddev->CreatePixelShader((const DWORD*)pShaderBlob->GetBufferPointer(), &m_pPS));
break;
}
if(!shaderCreated)
{
CON(MSG_ERR, _W("Shader creation error"));
return false;
}
//set constant to their default values
m_pConstTable->SetDefaults(g_pD3ddev);
//create vertex declaration
if(desc.ShaderType == SHADERTYPE_VERTEX_SHADER)
m_pVertDecl = new CVertexDeclaration(CRenderer::cGraphicsManager()->GetVertexDescByID(desc.VertexDescID), pShaderBlob);
SAFE_RELEASE(pShaderBlob);
m_desc = desc;
//.........这里部分代码省略.........