Пример #1
0
        public static EffectAssignment Parse(BytecodeReader reader, BytecodeReader annotationReader)
        {
            //MemberType type, such as AddressV or Filter
            var memberType = (EffectAssignmentType)annotationReader.ReadUInt32();
            //	$"EffectStateAnnotationType is {memberType}");
            //MemberIndex is 1 for BlendEnable[1] = TRUE;
            var memberIndex        = annotationReader.ReadUInt32();
            var assignmentType     = (EffectCompilerAssignmentType)annotationReader.ReadUInt32();
            var valueOffset        = annotationReader.ReadUInt32();
            var typeSpecificReader = reader.CopyAtOffset((int)valueOffset);
            EffectAssignment result;

            switch (assignmentType)
            {
            case EffectCompilerAssignmentType.Constant:
                result = EffectConstantAssignment.Parse(reader, typeSpecificReader);
                break;

            case EffectCompilerAssignmentType.Variable:
                result = EffectVariableAssignment.Parse(reader, typeSpecificReader);
                break;

            case EffectCompilerAssignmentType.ConstantIndex:
                result = EffectConstantIndexAssignment.Parse(reader, typeSpecificReader);
                break;

            case EffectCompilerAssignmentType.VariableIndex:
                result = EffectVariableIndexAssignment.Parse(reader, typeSpecificReader);
                break;

            case EffectCompilerAssignmentType.ExpressionIndex:
                result = EffectExpressionIndexAssignment.Parse(reader, typeSpecificReader);
                break;

            case EffectCompilerAssignmentType.Expression:
                result = EffectExpressionAssignment.Parse(reader, typeSpecificReader);
                break;

            case EffectCompilerAssignmentType.InlineShader:
                result = EffectInlineShaderAssignment.Parse(reader, typeSpecificReader);
                break;

            case EffectCompilerAssignmentType.InlineShader5:
                result = EffectInlineShader5Assignment.Parse(reader, typeSpecificReader);
                break;

            default:
                throw new ParseException($"Unsupported EffectCompilerAssignmentType {assignmentType}");
            }
            result.MemberType     = memberType;
            result.MemberIndex    = memberIndex;
            result.AssignmentType = assignmentType;
            result.ValueOffset    = valueOffset;
            return(result);
        }
        public new static EffectInlineShader5Assignment Parse(BytecodeReader reader, BytecodeReader variableReader)
        {
            var result       = new EffectInlineShader5Assignment();
            var shaderOffset = variableReader.ReadUInt32();

            result.SODeclsOffset[0] = variableReader.ReadUInt32();
            result.SODeclsOffset[1] = variableReader.ReadUInt32();
            result.SODeclsOffset[2] = variableReader.ReadUInt32();
            result.SODeclsOffset[3] = variableReader.ReadUInt32();
            var SoDeclsCount = result.SODeclsCount = variableReader.ReadUInt32();

            result.RasterizedStream = variableReader.ReadUInt32();
            var interfaceBindingCount  = variableReader.ReadUInt32();
            var interfaceBindingOffset = variableReader.ReadUInt32();
            var shaderReader           = reader.CopyAtOffset((int)shaderOffset);
            var shaderSize             = shaderReader.ReadUInt32();

            if (shaderSize != 0)
            {
                result.Shader = BytecodeContainer.Parse(shaderReader.ReadBytes((int)shaderSize));
            }
            for (int i = 0; i < 4; i++)
            {
                var offset = result.SODeclsOffset[i];
                if (offset != 0)
                {
                    var soDeclReader = reader.CopyAtOffset((int)offset);
                    result.SODecls.Add(soDeclReader.ReadString());
                }
            }
            var interfaceReader = reader.CopyAtOffset((int)interfaceBindingOffset);

            for (int i = 0; i < interfaceBindingCount; i++)
            {
                result.InterfaceBindings.Add(EffectInterfaceInitializer.Parse(reader, interfaceReader));
            }
            return(result);
        }