本文整理汇总了C++中ShaderCode::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ ShaderCode::resize方法的具体用法?C++ ShaderCode::resize怎么用?C++ ShaderCode::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShaderCode
的用法示例。
在下文中一共展示了ShaderCode::resize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: memcpy
static bool dx11_compile_shader( ShaderCode& out_shader, const ShaderCode& source, const char* entry, const char* profile_str, FileSystem* /*fs*/, const char* /*include_dir*/ )
{
LPD3DBLOB code_blob = NULL;
LPD3DBLOB error_blob = NULL;
uint32 flags = D3D10_SHADER_DEBUG | D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY;
HRESULT hr = D3DCompile(source.data(), source.size(), "", NULL, NULL, entry, profile_str, flags, 0, &code_blob, &error_blob);
out_shader.clear();
if( hr == S_OK )
{
size_t size = code_blob->GetBufferSize();
out_shader.resize(size);
memcpy(out_shader.data(), code_blob->GetBufferPointer(), size);
}
if( error_blob != NULL )
{
char* error_str = (char*)error_blob->GetBufferPointer();
Log::error("Failed to compile shader\n%s", error_str);
}
SafeRelease(code_blob);
SafeRelease(error_blob);
if( hr == S_OK )
{
return true;
}
else
{
return false;
}
}
示例2: if
static bool dx9_compile_shader(ShaderCode& out_shader, const ShaderCode& source, ShaderType::type type, FileSystem* fs=NULL, const char* include_dir=NULL)
{
R_ASSERT(source.type == ShaderCodeType_Text);
HRESULT hr = S_OK;
ID3DXBuffer* error_buffer = NULL;
ID3DXBuffer* shader_buffer = NULL;
ID3DXConstantTable* constant_table = NULL;
uint32 flags = D3DXSHADER_DEBUG;
const char* profile = shader_profile_string(type);
static const char dummy_vertex_shader[] = "float4 vertex() : POSITION { return 1; }";
static const char dummy_pixel_shader[] = "float4 pixel() : COLOR { return float4(1,0,1,1); }";
DX9ShaderIncluder includer(fs, include_dir);
hr = D3DXCompileShader(source.data(), (UINT)source.size(), NULL, &includer, "main", profile, flags, &shader_buffer, &error_buffer, &constant_table );
if( hr!=S_OK && error_buffer && error_buffer->GetBufferPointer() )
{
char* tmp = (char*)error_buffer->GetBufferPointer();
R_ERROR_MESSAGE_BOX(tmp, "Shader compile error");
shader_buffer = NULL;
error_buffer = NULL;
//create dummy shader
if( type == ShaderType::Pixel )
{
hr = D3DXCompileShader(
dummy_pixel_shader, uint32(strlen(dummy_pixel_shader)), NULL, NULL, "pixel", "ps_2_0",
flags, &shader_buffer, &error_buffer, NULL );
validate_d3d_result(hr, true);
}
else if( type == ShaderType::Vertex )
{
hr = D3DXCompileShader(
dummy_vertex_shader, uint32(strlen(dummy_vertex_shader)), NULL, NULL, "vertex", "vs_2_0",
flags, &shader_buffer, &error_buffer, NULL );
validate_d3d_result(hr, true);
}
}
out_shader.type = ShaderCodeType_Binary;
out_shader.clear();
uint32 size = shader_buffer->GetBufferSize();
if( size )
{
out_shader.resize(size);
memcpy(out_shader.data(), shader_buffer->GetBufferPointer(), size);
}
if(error_buffer) error_buffer->Release();
if(shader_buffer) shader_buffer->Release();
if(constant_table) constant_table->Release();
return true;
}