Exemple #1
0
        public static ShaderFileFormat Detect(Stream stream)
        {
            long tempPosition = stream.Position;
            var  format       = ShaderFileFormat.Unknown;

            using (var reader = new BinaryReader(stream, new UTF8Encoding(), true))
            {
                uint signature = (uint)reader.ReadInt32();
                if (signature == FourCC.Make("rgxa"))
                {
                    format = ShaderFileFormat.Rgxa;
                }
                else
                {
                    stream.Position = tempPosition;
                    signature       = reader.ReadUInt32();
                    if (signature == 0xFFFE0300 || signature == 0xFFFF0300)
                    {
                        format = ShaderFileFormat.Hlsl;
                    }
                }
            }

            stream.Position = tempPosition;
            return(format);
        }
        public void ReadFileHeader()
        {
            int signature = ReadInt32();

            if (signature != FourCC.Make("rgxa"))
            {
                Console.WriteLine("Error: unknown file format!");
                throw new InvalidDataException();
            }

            numShaders = ReadByte();

            location = Location.VertexShaders;
        }
Exemple #3
0
        private byte[] GetConstantTableData()
        {
            int ctabToken   = FourCC.Make("CTAB");
            var ctabComment = Instructions.FirstOrDefault(x => x.Opcode == Opcode.Comment && x.Params[0] == ctabToken);

            if (ctabComment == null)
            {
                return(null);
            }

            byte[] constantTable = new byte[ctabComment.Params.Length * 4];
            for (int i = 1; i < ctabComment.Params.Length; i++)
            {
                constantTable[i * 4 - 4] = (byte)(ctabComment.Params[i] & 0xFF);
                constantTable[i * 4 - 3] = (byte)((ctabComment.Params[i] >> 8) & 0xFF);
                constantTable[i * 4 - 2] = (byte)((ctabComment.Params[i] >> 16) & 0xFF);
                constantTable[i * 4 - 1] = (byte)((ctabComment.Params[i] >> 24) & 0xFF);
            }

            return(constantTable);
        }