public static StateBlob Parse(BytecodeReader reader, BytecodeReader shaderReader) { var result = new StateBlob(); result.TechniqueIndex = shaderReader.ReadUInt32(); result.PassIndex = shaderReader.ReadUInt32(); result.SamplerStateIndex = shaderReader.ReadUInt32(); result.AssignmentIndex = shaderReader.ReadUInt32(); result.BlobType = (StateBlobType)shaderReader.ReadUInt32(); var dataReader = shaderReader.CopyAtCurrentPosition(); var blobSize = shaderReader.ReadUInt32(); var paddedSize = blobSize + (blobSize % 4 == 0 ? 0 : 4 - blobSize % 4); //Seak ahead var data = shaderReader.ReadBytes((int)paddedSize); if (result.BlobType == StateBlobType.Shader) { result.Shader = ShaderReader.ReadShader(data); } else if (result.BlobType == StateBlobType.Variable) { result.VariableName = dataReader.TryReadString(); } else if (result.BlobType == StateBlobType.IndexShader) { var _blobSize = dataReader.ReadUInt32(); var variableSize = dataReader.ReadUInt32(); result.VariableName = dataReader.ReadString(); if (variableSize > (result.VariableName.Length + 1)) { var paddingCount = variableSize - (result.VariableName.Length + 1); var padding = dataReader.ReadBytes((int)paddingCount); } result.Shader = result.Shader = ShaderModel.Parse(dataReader); } return(result); }
public static EffectContainer Parse(BytecodeReader reader, uint length) { var result = new EffectContainer(); var chunkReader = reader.CopyAtCurrentPosition(); var footerOffset = chunkReader.ReadUInt32() + 4; var bodyReader = chunkReader.CopyAtCurrentPosition(); var footerReader = reader.CopyAtOffset((int)footerOffset); var variableCount = footerReader.ReadUInt32(); var techniqueCount = footerReader.ReadUInt32(); var passCount = footerReader.ReadUInt32(); var shaderCount = footerReader.ReadUInt32(); for (int i = 0; i < variableCount; i++) { result.Variables.Add(Variable.Parse(bodyReader, footerReader)); } for (int i = 0; i < techniqueCount; i++) { result.Techniques.Add(Technique.Parse(bodyReader, footerReader)); } var variableBlobCount = footerReader.ReadUInt32(); var stateBlobCount = footerReader.ReadUInt32(); for (int i = 0; i < variableBlobCount; i++) { var data = VariableBlob.Parse(bodyReader, footerReader); result.VariableBlobs.Add(data); } for (int i = 0; i < stateBlobCount; i++) { var data = StateBlob.Parse(bodyReader, footerReader); result.StateBlobs.Add(data); } result.BuildBlobLookup(); return(result); }