private static EffectPassCollection ReadPasses(BinaryReader reader, Effect effect, Shader[] shaders)
{
var count = (int)reader.ReadByte();
var passes = new EffectPass[count];
for (var i = 0; i < count; i++)
{
var name = reader.ReadString();
var annotations = ReadAnnotations(reader);
// Get the vertex shader.
Shader vertexShader = null;
var shaderIndex = (int)reader.ReadByte();
if (shaderIndex != 255)
vertexShader = shaders[shaderIndex];
// Get the pixel shader.
Shader pixelShader = null;
shaderIndex = (int)reader.ReadByte();
if (shaderIndex != 255)
pixelShader = shaders[shaderIndex];
BlendState blend = null;
DepthStencilState depth = null;
RasterizerState raster = null;
if (reader.ReadBoolean())
{
blend = new BlendState
{
AlphaBlendFunction = (BlendFunction)reader.ReadByte(),
AlphaDestinationBlend = (Blend)reader.ReadByte(),
AlphaSourceBlend = (Blend)reader.ReadByte(),
BlendFactor = new Color(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte()),
ColorBlendFunction = (BlendFunction)reader.ReadByte(),
ColorDestinationBlend = (Blend)reader.ReadByte(),
ColorSourceBlend = (Blend)reader.ReadByte(),
ColorWriteChannels = (ColorWriteChannels)reader.ReadByte(),
ColorWriteChannels1 = (ColorWriteChannels)reader.ReadByte(),
ColorWriteChannels2 = (ColorWriteChannels)reader.ReadByte(),
ColorWriteChannels3 = (ColorWriteChannels)reader.ReadByte(),
MultiSampleMask = reader.ReadInt32(),
};
}
if (reader.ReadBoolean())
{
depth = new DepthStencilState
{
CounterClockwiseStencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
CounterClockwiseStencilFail = (StencilOperation)reader.ReadByte(),
CounterClockwiseStencilFunction = (CompareFunction)reader.ReadByte(),
CounterClockwiseStencilPass = (StencilOperation)reader.ReadByte(),
DepthBufferEnable = reader.ReadBoolean(),
DepthBufferFunction = (CompareFunction)reader.ReadByte(),
DepthBufferWriteEnable = reader.ReadBoolean(),
ReferenceStencil = reader.ReadInt32(),
StencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
StencilEnable = reader.ReadBoolean(),
StencilFail = (StencilOperation)reader.ReadByte(),
StencilFunction = (CompareFunction)reader.ReadByte(),
StencilMask = reader.ReadInt32(),
StencilPass = (StencilOperation)reader.ReadByte(),
StencilWriteMask = reader.ReadInt32(),
TwoSidedStencilMode = reader.ReadBoolean(),
};
}
if (reader.ReadBoolean())
{
raster = new RasterizerState
{
CullMode = (CullMode)reader.ReadByte(),
DepthBias = reader.ReadSingle(),
FillMode = (FillMode)reader.ReadByte(),
MultiSampleAntiAlias = reader.ReadBoolean(),
ScissorTestEnable = reader.ReadBoolean(),
SlopeScaleDepthBias = reader.ReadSingle(),
};
}
passes[i] = new EffectPass(effect, name, vertexShader, pixelShader, blend, depth, raster, annotations);
}
return new EffectPassCollection(passes);
}