Beispiel #1
0
        internal EffectPass(Effect effect,
                            string name,
                            Shader vertexShader,
                            Shader pixelShader,
                            BlendState blendState,
                            DepthStencilState depthStencilState,
                            RasterizerState rasterizerState,
                            EffectAnnotationCollection annotations)
        {
            Debug.Assert(effect != null, "Got a null effect!");
            Debug.Assert(annotations != null, "Got a null annotation collection!");

            _effect = effect;

            Name = name;

            _vertexShader = vertexShader;
            _pixelShader  = pixelShader;

            _blendState        = blendState;
            _depthStencilState = depthStencilState;
            _rasterizerState   = rasterizerState;

            Annotations = annotations;
        }
Beispiel #2
0
        private static EffectPassCollection ReadPasses(BinaryReader reader, Effect effect, List <Shader> shaders)
        {
            Shader vertexShader = (Shader)null;
            Shader pixelShader  = (Shader)null;
            EffectPassCollection effectPassCollection = new EffectPassCollection();
            int num = (int)reader.ReadByte();

            for (int index1 = 0; index1 < num; ++index1)
            {
                string name = reader.ReadString();
                EffectAnnotationCollection annotations = Effect.ReadAnnotations(reader);
                int index2 = (int)reader.ReadByte();
                if (index2 != (int)byte.MaxValue)
                {
                    vertexShader = shaders[index2];
                }
                int index3 = (int)reader.ReadByte();
                if (index3 != (int)byte.MaxValue)
                {
                    pixelShader = shaders[index3];
                }
                EffectPass pass = new EffectPass(effect, name, vertexShader, pixelShader, (BlendState)null, (DepthStencilState)null, (RasterizerState)null, annotations);
                effectPassCollection.Add(pass);
            }
            return(effectPassCollection);
        }
Beispiel #3
0
        internal EffectParameter(EffectParameterClass class_,
                                 EffectParameterType type,
                                 string name,
                                 int rowCount,
                                 int columnCount,
                                 string semantic,
                                 EffectAnnotationCollection annotations,
                                 EffectParameterCollection elements,
                                 EffectParameterCollection structMembers,
                                 object data)
        {
            ParameterClass = class_;
            ParameterType  = type;

            Name        = name;
            Semantic    = semantic;
            Annotations = annotations;

            RowCount    = rowCount;
            ColumnCount = columnCount;

            Elements         = elements;
            StructureMembers = structMembers;

            Data     = data;
            StateKey = unchecked (NextStateKey++);
        }
 /// <summary>
 /// Creates a new instance of <see cref="XNAEffectAnnotationCollection"/>.
 /// </summary>
 /// <param name="coll">The underlying XNA effect annotation collection.</param>
 internal XNAEffectAnnotationCollection(XFG.EffectAnnotationCollection coll)
 {
     _annotations = new List <XNAEffectAnnotation>(coll.Count);
     for (int i = 0; i < coll.Count; i++)
     {
         _annotations.Add(new XNAEffectAnnotation(coll[i]));
     }
 }
Beispiel #5
0
        private EffectParameterCollection ReadParameters(BinaryReader reader)
        {
            EffectParameterCollection parameterCollection = new EffectParameterCollection();
            int num = (int)reader.ReadByte();

            if (num == 0)
            {
                return(parameterCollection);
            }
            for (int index1 = 0; index1 < num; ++index1)
            {
                EffectParameterClass class_ = (EffectParameterClass)reader.ReadByte();
                EffectParameterType  type   = (EffectParameterType)reader.ReadByte();
                string name     = reader.ReadString();
                string semantic = reader.ReadString();
                EffectAnnotationCollection annotations = Effect.ReadAnnotations(reader);
                int rowCount      = (int)reader.ReadByte();
                int columnCount   = (int)reader.ReadByte();
                int registerCount = this.version >= 3 ? (int)reader.ReadByte() : rowCount;
                EffectParameterCollection elements      = this.ReadParameters(reader);
                EffectParameterCollection structMembers = this.ReadParameters(reader);
                object data = (object)null;
                if (elements.Count == 0 && structMembers.Count == 0)
                {
                    switch (type)
                    {
                    case EffectParameterType.Bool:
                    case EffectParameterType.Int32:
                        int[] numArray1 = new int[rowCount * columnCount];
                        for (int index2 = 0; index2 < numArray1.Length; ++index2)
                        {
                            numArray1[index2] = reader.ReadInt32();
                        }
                        data = (object)numArray1;
                        break;

                    case EffectParameterType.Single:
                        float[] numArray2 = new float[rowCount * columnCount];
                        for (int index2 = 0; index2 < numArray2.Length; ++index2)
                        {
                            numArray2[index2] = reader.ReadSingle();
                        }
                        data = (object)numArray2;
                        break;

                    case EffectParameterType.String:
                        throw new NotImplementedException();
                    }
                }
                EffectParameter effectParameter = new EffectParameter(class_, type, name, rowCount, columnCount, registerCount, semantic, annotations, elements, structMembers, data);
                parameterCollection.Add(effectParameter);
            }
            return(parameterCollection);
        }
Beispiel #6
0
 internal EffectPass(
     string name,
     EffectAnnotationCollection annotations,
     Effect parent,
     uint passIndex)
 {
     this.Name         = name;
     this.Annotations  = annotations;
     this.parentEffect = parent;
     this.pass         = passIndex;
 }
Beispiel #7
0
 internal EffectTechnique(
     string name,
     IntPtr pointer,
     EffectPassCollection passes,
     EffectAnnotationCollection annotations
     )
 {
     Name             = name;
     Passes           = passes;
     Annotations      = annotations;
     TechniquePointer = pointer;
 }
Beispiel #8
0
        private void ReadEffect(BinaryReader reader)
        {
            if (new string(reader.ReadChars("MGFX".Length)) != "MGFX")
            {
                throw new Exception("The MGFX file is corrupt!");
            }
            this.version = (int)reader.ReadByte();
            if (this.version < 4)
            {
                throw new Exception("Unsupported MGFX file version!");
            }
            if ((int)reader.ReadByte() != 0)
            {
                throw new Exception("The MGFX effect is the wrong profile for this platform!");
            }
            int length = (int)reader.ReadByte();

            this.ConstantBuffers = new ConstantBuffer[length];
            for (int index1 = 0; index1 < length; ++index1)
            {
                string name             = reader.ReadString();
                int    sizeInBytes      = (int)reader.ReadInt16();
                int[]  parameterIndexes = new int[(int)reader.ReadByte()];
                int[]  parameterOffsets = new int[parameterIndexes.Length];
                for (int index2 = 0; index2 < parameterIndexes.Length; ++index2)
                {
                    parameterIndexes[index2] = (int)reader.ReadByte();
                    parameterOffsets[index2] = (int)reader.ReadUInt16();
                }
                ConstantBuffer constantBuffer = new ConstantBuffer(this.GraphicsDevice, sizeInBytes, parameterIndexes, parameterOffsets, name);
                this.ConstantBuffers[index1] = constantBuffer;
            }
            this._shaderList = new List <Shader>();
            int num1 = (int)reader.ReadByte();

            for (int index = 0; index < num1; ++index)
            {
                this._shaderList.Add(new Shader(this.GraphicsDevice, reader));
            }
            this.Parameters = this.ReadParameters(reader);
            this.Techniques = new EffectTechniqueCollection();
            int num2 = (int)reader.ReadByte();

            for (int index = 0; index < num2; ++index)
            {
                string name = reader.ReadString();
                EffectAnnotationCollection annotations = Effect.ReadAnnotations(reader);
                EffectPassCollection       passes      = Effect.ReadPasses(reader, this, this._shaderList);
                this.Techniques.Add(new EffectTechnique(this, name, passes, annotations));
            }
            this.CurrentTechnique = this.Techniques[0];
        }
Beispiel #9
0
        private static EffectAnnotationCollection ReadAnnotations(BinaryReader reader)
        {
            EffectAnnotationCollection annotationCollection = new EffectAnnotationCollection();

            if ((int)reader.ReadByte() == 0)
            {
                return(annotationCollection);
            }
            else
            {
                return(annotationCollection);
            }
        }
Beispiel #10
0
 internal EffectPass(
     string name,
     EffectAnnotationCollection annotations,
     Effect parent,
     IntPtr technique,
     uint passIndex
     )
 {
     Name            = name;
     Annotations     = annotations;
     parentEffect    = parent;
     parentTechnique = technique;
     pass            = passIndex;
 }
Beispiel #11
0
        private static EffectAnnotationCollection ReadAnnotations(BinaryReader reader)
        {
            var collection = new EffectAnnotationCollection();

            var count = (int)reader.ReadByte();

            if (count == 0)
            {
                return(collection);
            }

            // TODO: Annotations are not implemented!

            return(collection);
        }
Beispiel #12
0
        internal EffectPass(Effect effect, EffectPass cloneSource)
        {
            Debug.Assert(effect != null, "Got a null effect!");
            Debug.Assert(cloneSource != null, "Got a null cloneSource!");

            _effect = effect;

            // Share all the immutable types.
            Name               = cloneSource.Name;
            _blendState        = cloneSource._blendState;
            _depthStencilState = cloneSource._depthStencilState;
            _rasterizerState   = cloneSource._rasterizerState;
            Annotations        = cloneSource.Annotations;
            _vertexShader      = cloneSource._vertexShader;
            _pixelShader       = cloneSource._pixelShader;
        }
Beispiel #13
0
 internal EffectParameter(
     string name,
     string semantic,
     int rowCount,
     int columnCount,
     int elementCount,
     EffectParameterClass parameterClass,
     EffectParameterType parameterType,
     EffectParameterCollection structureMembers,
     EffectAnnotationCollection annotations,
     IntPtr data
     )
 {
     Name        = name;
     Semantic    = semantic;
     RowCount    = rowCount;
     ColumnCount = columnCount;
     if (elementCount > 0)
     {
         List <EffectParameter> elements = new List <EffectParameter>(elementCount);
         for (int i = 0; i < elementCount; i += 1)
         {
             // FIXME: Probably incomplete? -flibit
             elements.Add(new EffectParameter(
                              null,
                              null,
                              rowCount,
                              columnCount,
                              0,
                              ParameterClass,
                              parameterType,
                              null,            // FIXME: See mojoshader_effects.c:readvalue -flibit
                              null,
                              new IntPtr(
                                  data.ToInt64() + (i * rowCount * columnCount)
                                  )
                              ));
         }
         Elements = new EffectParameterCollection(elements);
     }
     ParameterClass   = parameterClass;
     ParameterType    = parameterType;
     StructureMembers = structureMembers;
     Annotations      = annotations;
     values           = data;
 }
Beispiel #14
0
        internal EffectParameter(
            string name,
            string semantic,
            int rowCount,
            int columnCount,
            int elementCount,
            EffectParameterClass parameterClass,
            EffectParameterType parameterType,
            EffectParameterCollection structureMembers,
            EffectAnnotationCollection annotations,
            IntPtr data,
            uint dataSizeBytes
            )
        {
            if (data == IntPtr.Zero)
            {
                throw new ArgumentNullException("data");
            }

            Name        = name;
            Semantic    = semantic ?? string.Empty;
            RowCount    = rowCount;
            ColumnCount = columnCount;
            if (elementCount > 0)
            {
                int curOffset = 0;
                List <EffectParameter> elements = new List <EffectParameter>(elementCount);
                for (int i = 0; i < elementCount; i += 1)
                {
                    EffectParameterCollection elementMembers = null;
                    if (structureMembers != null)
                    {
                        List <EffectParameter> memList = new List <EffectParameter>();
                        for (int j = 0; j < structureMembers.Count; j += 1)
                        {
                            int memElems = 0;
                            if (structureMembers[j].Elements != null)
                            {
                                memElems = structureMembers[j].Elements.Count;
                            }
                            int memSize = structureMembers[j].RowCount * 4;
                            if (memElems > 0)
                            {
                                memSize *= memElems;
                            }
                            memList.Add(new EffectParameter(
                                            structureMembers[j].Name,
                                            structureMembers[j].Semantic,
                                            structureMembers[j].RowCount,
                                            structureMembers[j].ColumnCount,
                                            memElems,
                                            structureMembers[j].ParameterClass,
                                            structureMembers[j].ParameterType,
                                            null,                     // FIXME: Nested structs! -flibit
                                            structureMembers[j].Annotations,
                                            new IntPtr(data.ToInt64() + curOffset),
                                            (uint)memSize * 4
                                            ));
                            curOffset += memSize * 4;
                        }
                        elementMembers = new EffectParameterCollection(memList);
                    }
                    // FIXME: Probably incomplete? -flibit
                    elements.Add(new EffectParameter(
                                     null,
                                     null,
                                     rowCount,
                                     columnCount,
                                     0,
                                     ParameterClass,
                                     parameterType,
                                     elementMembers,
                                     null,
                                     new IntPtr(
                                         data.ToInt64() + (i * rowCount * 16)
                                         ),
                                     // FIXME: Not obvious to me how to compute this -kg
                                     0
                                     ));
                }
                Elements = new EffectParameterCollection(elements);
            }
            ParameterClass   = parameterClass;
            ParameterType    = parameterType;
            StructureMembers = structureMembers;
            Annotations      = annotations;
            values           = data;
            valuesSizeBytes  = dataSizeBytes;
        }
Beispiel #15
0
 internal EffectParameter(
     string name,
     string semantic,
     int rowCount,
     int columnCount,
     int elementCount,
     EffectParameterClass parameterClass,
     EffectParameterType parameterType,
     EffectParameterCollection structureMembers,
     EffectAnnotationCollection annotations,
     IntPtr data
     )
 {
     Name        = name;
     Semantic    = semantic;
     RowCount    = rowCount;
     ColumnCount = columnCount;
     if (elementCount > 0)
     {
         int curOffset = 0;
         List <EffectParameter> elements = new List <EffectParameter>(elementCount);
         for (int i = 0; i < elementCount; i += 1)
         {
             EffectParameterCollection elementMembers = null;
             if (structureMembers != null)
             {
                 List <EffectParameter> memList = new List <EffectParameter>();
                 for (int j = 0; j < structureMembers.Count; j += 1)
                 {
                     int memElems = 0;
                     if (structureMembers[j].Elements != null)
                     {
                         memElems = structureMembers[j].Elements.Count;
                     }
                     memList.Add(new EffectParameter(
                                     structureMembers[j].Name,
                                     structureMembers[j].Semantic,
                                     structureMembers[j].RowCount,
                                     structureMembers[j].ColumnCount,
                                     memElems,
                                     structureMembers[j].ParameterClass,
                                     structureMembers[j].ParameterType,
                                     null,                     // FIXME: Nested structs! -flibit
                                     structureMembers[j].Annotations,
                                     new IntPtr(data.ToInt64() + curOffset)
                                     ));
                     int memSize = structureMembers[j].RowCount * 4;
                     if (memElems > 0)
                     {
                         memSize *= memElems;
                     }
                     curOffset += memSize * 4;
                 }
                 elementMembers = new EffectParameterCollection(memList);
             }
             // FIXME: Probably incomplete? -flibit
             elements.Add(new EffectParameter(
                              null,
                              null,
                              rowCount,
                              columnCount,
                              0,
                              ParameterClass,
                              parameterType,
                              elementMembers,
                              null,
                              new IntPtr(
                                  data.ToInt64() + (i * rowCount * 16)
                                  )
                              ));
         }
         Elements = new EffectParameterCollection(elements);
     }
     ParameterClass   = parameterClass;
     ParameterType    = parameterType;
     StructureMembers = structureMembers;
     Annotations      = annotations;
     values           = data;
 }
Beispiel #16
0
 public EffectTechnique(string name, IntPtr pointer, EffectPassCollection passes,
                        EffectAnnotationCollection annotations)
 {
 }
Beispiel #17
0
 public EffectPass(string name, EffectAnnotationCollection annotations,
                   Effect parent, IntPtr technique, uint passIndex)
 {
 }
Beispiel #18
0
        private static EffectPassCollection ReadPasses(BinaryReader reader, Effect effect, List <Shader> shaders)
        {
            Shader vertexShader = (Shader)null;
            Shader pixelShader  = (Shader)null;
            EffectPassCollection effectPassCollection = new EffectPassCollection();
            int num = (int)reader.ReadByte();

            for (int index1 = 0; index1 < num; ++index1)
            {
                string name = reader.ReadString();
                EffectAnnotationCollection annotations = Effect.ReadAnnotations(reader);
                int index2 = (int)reader.ReadByte();
                if (index2 != (int)byte.MaxValue)
                {
                    vertexShader = shaders[index2];
                }
                int index3 = (int)reader.ReadByte();
                if (index3 != (int)byte.MaxValue)
                {
                    pixelShader = shaders[index3];
                }
                BlendState        blendState        = (BlendState)null;
                DepthStencilState depthStencilState = (DepthStencilState)null;
                RasterizerState   rasterizerState   = (RasterizerState)null;
                if (reader.ReadBoolean())
                {
                    blendState = new BlendState()
                    {
                        AlphaBlendFunction    = (BlendFunction)reader.ReadByte(),
                        AlphaDestinationBlend = (Blend)reader.ReadByte(),
                        AlphaSourceBlend      = (Blend)reader.ReadByte(),
                        BlendFactor           = new Color((int)reader.ReadByte(), (int)reader.ReadByte(), (int)reader.ReadByte(), (int)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())
                {
                    depthStencilState = 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())
                {
                    rasterizerState = new RasterizerState()
                    {
                        CullMode             = (CullMode)reader.ReadByte(),
                        DepthBias            = reader.ReadSingle(),
                        FillMode             = (FillMode)reader.ReadByte(),
                        MultiSampleAntiAlias = reader.ReadBoolean(),
                        ScissorTestEnable    = reader.ReadBoolean(),
                        SlopeScaleDepthBias  = reader.ReadSingle()
                    }
                }
                ;
                EffectPass pass = new EffectPass(effect, name, vertexShader, pixelShader, blendState, depthStencilState, rasterizerState, annotations);
                effectPassCollection.Add(pass);
            }
            return(effectPassCollection);
        }
Beispiel #19
0
 internal EffectParameter(EffectParameterClass class_, EffectParameterType type, string name, int rowCount, int columnCount, int registerCount, string semantic, EffectAnnotationCollection annotations, EffectParameterCollection elements, EffectParameterCollection structMembers, object data)
 {
     this.ParameterClass   = class_;
     this.ParameterType    = type;
     this.Name             = name;
     this.Semantic         = semantic;
     this.Annotations      = annotations;
     this.RowCount         = rowCount;
     this.ColumnCount      = columnCount;
     this.RegisterCount    = registerCount;
     this.Elements         = elements;
     this.StructureMembers = structMembers;
     this.Data             = data;
     this.StateKey         = EffectParameter.NextStateKey++;
 }
Beispiel #20
0
 internal EffectTechnique(Effect effect, string name, EffectPassCollection passes, EffectAnnotationCollection annotations)
 {
     Name        = name;
     Passes      = passes;
     Annotations = annotations;
 }