Example #1
0
        private void renderIndexBuffer(
            m3g.IndexBuffer primitives,
            m3g.VertexBuffer vertices,
            float alphaFactor)
        {
            ushort[]      stripLengths    = primitives.getStripLengths();
            short[]       explicitIndices = primitives.getExplicitIndices();
            bool          flag1           = primitives.isStripped();
            bool          flag2           = primitives.isImplicit();
            int           primitiveType1  = primitives.getPrimitiveType();
            PrimitiveType primitiveType2  = PrimitiveType.TriangleStrip;

            Vertex[] finalVertices = vertices.getFinalVertices();
            Effect   effect;

            if (this.alphaTest)
            {
                effect = (Effect)this.alphaTestEffect;
                this.alphaTestEffect.View       = this.viewMat;
                this.alphaTestEffect.Projection = this.projMat;
                this.alphaTestEffect.World      = this.worldMat;
                int defaultColor = vertices.getDefaultColor();
                this.alphaTestEffect.DiffuseColor       = vertices.getXnaDiffuse();
                this.alphaTestEffect.Alpha              = (float)(defaultColor >> 24 & (int)byte.MaxValue) / (float)byte.MaxValue * alphaFactor;
                this.alphaTestEffect.VertexColorEnabled = vertices.getColors() != null;
            }
            else
            {
                effect = (Effect)this.basicEffect;
                this.basicEffect.View       = this.viewMat;
                this.basicEffect.Projection = this.projMat;
                this.basicEffect.World      = this.worldMat;
                int defaultColor = vertices.getDefaultColor();
                this.basicEffect.DiffuseColor       = vertices.getXnaDiffuse();
                this.basicEffect.Alpha              = (float)(defaultColor >> 24 & (int)byte.MaxValue) / (float)byte.MaxValue * alphaFactor;
                this.basicEffect.VertexColorEnabled = vertices.getColors() != null && !this.basicEffect.TextureEnabled;
            }
            for (int index1 = 0; index1 < effect.CurrentTechnique.Passes.Count; ++index1)
            {
                effect.CurrentTechnique.Passes[index1].Apply();
                switch (primitiveType1)
                {
                case 8:
                    primitiveType2 = !flag1 ? PrimitiveType.TriangleList : PrimitiveType.TriangleStrip;
                    break;

                case 9:
                    primitiveType2 = !flag1 ? PrimitiveType.LineList : PrimitiveType.LineStrip;
                    break;

                case 10:
                    primitiveType2 = PrimitiveType.TriangleStrip;
                    if (!flag1)
                    {
                        break;
                    }
                    break;
                }
                if (flag1)
                {
                    int      length   = stripLengths.Length;
                    ushort[] numArray = stripLengths;
                    if (!flag2)
                    {
                        short[] indexData   = explicitIndices;
                        int     indexOffset = 0;
                        for (int index2 = 0; index2 < length; ++index2)
                        {
                            int num            = (int)numArray[index2];
                            int primitiveCount = 1 + (num - 3);
                            this.device.DrawUserIndexedPrimitives <Vertex>(primitiveType2, finalVertices, 0, vertices.getVertexCount(), indexData, indexOffset, primitiveCount);
                            indexOffset += num;
                        }
                    }
                    else
                    {
                        int firstIndex = primitives.getFirstIndex();
                        for (int index2 = 0; index2 < length; ++index2)
                        {
                            int num            = (int)numArray[index2];
                            int primitiveCount = 1 + (num - 3);
                            this.device.DrawUserPrimitives <Vertex>(primitiveType2, finalVertices, firstIndex, primitiveCount);
                            firstIndex += num;
                        }
                    }
                }
                else
                {
                    int primitiveCount = primitives.getPrimitiveCount();
                    if (!flag2)
                    {
                        short[] indexData = explicitIndices;
                        this.device.DrawUserIndexedPrimitives <Vertex>(primitiveType2, finalVertices, 0, vertices.getVertexCount(), indexData, 0, primitiveCount);
                    }
                    else
                    {
                        int firstIndex = primitives.getFirstIndex();
                        this.device.DrawUserPrimitives <Vertex>(primitiveType2, finalVertices, firstIndex, primitiveCount);
                    }
                }
            }
        }
Example #2
0
        public override void render(
            m3g.VertexBuffer vertices,
            VertexArray skinIndices,
            VertexArray skinWeights,
            Matrix[] matrixPalette,
            m3g.IndexBuffer primitives,
            AppearanceBase appearance,
            float alphaFactor)
        {
            this.m_matrixPalette = matrixPalette;
            this.processVertexBufferPositionsSoftwareSkinned(vertices);
            if (appearance != this.m_cachedAppearance)
            {
                this.processApperance((Appearance)appearance);
                this.m_cachedAppearance = appearance;
            }
            ushort[]      stripLengths    = primitives.getStripLengths();
            short[]       explicitIndices = primitives.getExplicitIndices();
            bool          flag1           = primitives.isStripped();
            bool          flag2           = primitives.isImplicit();
            int           primitiveType1  = primitives.getPrimitiveType();
            PrimitiveType primitiveType2  = PrimitiveType.TriangleStrip;

            Vertex[] vertexDataTransformed = vertices.skinVertexDataTransformed;
            Effect   effect;

            if (this.alphaTest)
            {
                effect = (Effect)this.alphaTestEffect;
                this.alphaTestEffect.View       = this.viewMat;
                this.alphaTestEffect.Projection = this.projMat;
                this.alphaTestEffect.World      = this.worldMat;
                int defaultColor = vertices.getDefaultColor();
                this.alphaTestEffect.DiffuseColor       = vertices.getXnaDiffuse();
                this.alphaTestEffect.Alpha              = (float)(defaultColor >> 24 & (int)byte.MaxValue) / (float)byte.MaxValue * alphaFactor;
                this.alphaTestEffect.VertexColorEnabled = vertices.getColors() != null;
            }
            else
            {
                effect = (Effect)this.basicEffect;
                this.basicEffect.View       = this.viewMat;
                this.basicEffect.Projection = this.projMat;
                this.basicEffect.World      = this.worldMat;
                int defaultColor = vertices.getDefaultColor();
                this.basicEffect.DiffuseColor       = vertices.getXnaDiffuse();
                this.basicEffect.Alpha              = (float)(defaultColor >> 24 & (int)byte.MaxValue) / (float)byte.MaxValue * alphaFactor;
                this.basicEffect.VertexColorEnabled = vertices.getColors() != null && !this.basicEffect.TextureEnabled;
            }
            for (int index1 = 0; index1 < effect.CurrentTechnique.Passes.Count; ++index1)
            {
                effect.CurrentTechnique.Passes[index1].Apply();
                switch (primitiveType1)
                {
                case 8:
                    primitiveType2 = !flag1 ? PrimitiveType.TriangleList : PrimitiveType.TriangleStrip;
                    break;

                case 9:
                    primitiveType2 = !flag1 ? PrimitiveType.LineList : PrimitiveType.LineStrip;
                    break;

                case 10:
                    primitiveType2 = PrimitiveType.TriangleStrip;
                    if (!flag1)
                    {
                        break;
                    }
                    break;
                }
                if (flag1)
                {
                    int      length   = stripLengths.Length;
                    ushort[] numArray = stripLengths;
                    if (!flag2)
                    {
                        short[] indexData   = explicitIndices;
                        int     indexOffset = 0;
                        for (int index2 = 0; index2 < length; ++index2)
                        {
                            int num            = (int)numArray[index2];
                            int primitiveCount = 1 + (num - 3);
                            this.device.DrawUserIndexedPrimitives <Vertex>(primitiveType2, vertexDataTransformed, 0, vertices.getVertexCount(), indexData, indexOffset, primitiveCount);
                            indexOffset += num;
                        }
                    }
                    else
                    {
                        int firstIndex = primitives.getFirstIndex();
                        for (int index2 = 0; index2 < length; ++index2)
                        {
                            int num            = (int)numArray[index2];
                            int primitiveCount = 1 + (num - 3);
                            this.device.DrawUserPrimitives <Vertex>(primitiveType2, vertexDataTransformed, firstIndex, primitiveCount);
                            firstIndex += num;
                        }
                    }
                }
                else
                {
                    int primitiveCount = primitives.getPrimitiveCount();
                    if (!flag2)
                    {
                        short[] indexData = explicitIndices;
                        this.device.DrawUserIndexedPrimitives <Vertex>(primitiveType2, vertexDataTransformed, 0, vertices.getVertexCount(), indexData, 0, primitiveCount);
                    }
                    else
                    {
                        int firstIndex = primitives.getFirstIndex();
                        this.device.DrawUserPrimitives <Vertex>(primitiveType2, vertexDataTransformed, firstIndex, primitiveCount);
                    }
                }
            }
        }