I'm testing out YAML to see if it would be a good fit for a data storage format for a game engine. I've created this sample YAML file:
---
ShaderProperties:
EntryPoint : UnlitHomogenousVS
Profile : vs_4_0
Model : HLSL_4
Uniforms:
- name : gTint
type : kShaderUniformTypeFloat4
defaultValue : 1.0f, 1.0f, 1.0f, 1.0f
constantBuffer : cbObjectProperties
constantBufferOffset : 0
usage : Property
Samplers:
ConstantBuffers:
- name : cbObjectProperties
register : 2
size : 16
type : kShaderTypeVertex
Attributes:
- name : position
type : kShaderAttributeTypeFloat4
usage : kShaderAttributeUsagePosition
- name : color
type : kShaderAttributeTypeFloat4
usage : kShaderAttributeUsageColor0
ShaderText: >
//--
// UnlitHomogenous.vs
//
// This vertex shader will color geometry with only a homogenous transform.
//--
//--
// VertexInput
//--
struct VertexInput
{
float4 position : POSITION;
float4 color : COLOR;
};
//--
// VertexOutput
//--
struct VertexOutput
{
float4 position : SV_POSITION;
float4 color : COLOR;
};
//--
// Global Variables
//--
cbuffer cbObjectProperties : register(b2)
{
float4 gTint = float4( 1.0f, 1.0f, 1.0f, 1.0f );
};
//--
// Main Function
//--
VertexOutput UnlitHomogenousVS( VertexInput input )
{
VertexOutput output = (VertexOutput)0;
output.position = input.position * gTint;
output.color = input.color;
return output;
}
...
Now, this file loads and seems to parse fine, but when I try to read in the node "EntryPoint" I get a valid node returned, but with an undefined node type, where I was expecting a scalar.
Here is the code that I'm using to read in the node.
YAML::Node root = YAML::LoadFile( filepathString );
if( root.IsNull() )
{
return Failure_FileNotFound;
}
YAML::Node shaderProperties = root[ "ShaderProperties" ];
if( shaderProperties.IsNull() )
{
return Failure_MalformedData;
}
YAML::Node& entryPointNode = shaderProperties[ "EntryPoint" ];
if( entryPointNode.IsNull() || !entryPointNode.IsDefined() )
{
TC_SHADER_IMPORTER_LOG_ERROR( TCString( "Failed to parse shader: ") + mCurrentName + TCString( ", no entry point was found" ) );
return Failure_MalformedData;
}
output->mEntryPointName = entryPointNode.as<std::string>().c_str();
Is there anything obvious that I'm missing? I am able to successfully load this file, so I assume that the YAML is valid. If I take out the check for IsDefined() and just try to cast the node to a string, I get a bad conversion.
Thanks for any and all help!
EDIT:
The issue was that I was using \t tabs between the tag name, (EntryPoint), and the colon instead of ' 's to tab.