internal void ReadEffect(BinaryReader reader) { var effectPass = new EffectPass(this, "Pass", null, null, BlendState.AlphaBlend, DepthStencilState.Default, RasterizerState.CullNone, new EffectAnnotationCollection()); effectPass._shaderProgram = new ShaderProgram(reader.ReadBytes((int)reader.BaseStream.Length)); var shaderProgram = effectPass._shaderProgram; Parameters = new EffectParameterCollection(); for (int i = 0; i < shaderProgram.UniformCount; i++) { Parameters.Add(EffectParameterForUniform(shaderProgram, i)); } #warning Hacks for BasicEffect as we don't have these parameters yet Parameters.Add(new EffectParameter( EffectParameterClass.Vector, EffectParameterType.Single, "SpecularColor", 3, 1, "float3", new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[3])); Parameters.Add(new EffectParameter( EffectParameterClass.Scalar, EffectParameterType.Single, "SpecularPower", 1, 1, "float", new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), 0.0f)); Parameters.Add(new EffectParameter( EffectParameterClass.Vector, EffectParameterType.Single, "FogVector", 4, 1, "float4", new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4])); Parameters.Add(new EffectParameter( EffectParameterClass.Vector, EffectParameterType.Single, "DiffuseColor", 4, 1, "float4", new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4])); Techniques = new EffectTechniqueCollection(); var effectPassCollection = new EffectPassCollection(); effectPassCollection.Add(effectPass); Techniques.Add(new EffectTechnique(this, "Name", effectPassCollection, new EffectAnnotationCollection())); ConstantBuffers = new ConstantBuffer[0]; CurrentTechnique = Techniques[0]; }
private void ReadEffect(BinaryReader reader) { // Check the header to make sure the file and version is correct! var header = new string (reader.ReadChars(MGFXHeader.Length)); var version = (int)reader.ReadByte(); if (header != MGFXHeader) { throw new Exception("The MGFX file is corrupt!"); } if (version != MGFXVersion) { throw new Exception("Wrong MGFX file version!"); } var profile = reader.ReadByte(); #if DIRECTX if (profile != 1) #else if (profile != 0) #endif { throw new Exception("The MGFX effect is the wrong profile for this platform!"); } // TODO: Maybe we should be reading in a string // table here to save some bytes in the file. // Read in all the constant buffers. var buffers = (int)reader.ReadByte(); ConstantBuffers = new ConstantBuffer[buffers]; for (var c = 0; c < buffers; c++) { #if OPENGL string name = reader.ReadString(); #else string name = null; #endif // Create the backing system memory buffer. var sizeInBytes = (int)reader.ReadInt16(); // Read the parameter index values. int[] parameters = new int[reader.ReadByte()]; int[] offsets = new int[parameters.Length]; for (var i = 0; i < parameters.Length; i++) { parameters [i] = (int)reader.ReadByte(); offsets [i] = (int)reader.ReadUInt16(); } var buffer = new ConstantBuffer(GraphicsDevice, sizeInBytes, parameters, offsets, name); ConstantBuffers[c] = buffer; } // Read in all the shader objects. _shaderList = new List <Shader>(); var shaders = (int)reader.ReadByte(); for (var s = 0; s < shaders; s++) { var shader = new Shader(GraphicsDevice, reader); _shaderList.Add(shader); } // Read in the parameters. Parameters = ReadParameters(reader); // Read the techniques. Techniques = new EffectTechniqueCollection(); var techniques = (int)reader.ReadByte(); for (var t = 0; t < techniques; t++) { var name = reader.ReadString(); var annotations = ReadAnnotations(reader); var passes = ReadPasses(reader, this, _shaderList); var technique = new EffectTechnique(this, name, passes, annotations); Techniques.Add(technique); } CurrentTechnique = Techniques[0]; }