示例#1
0
        void _render_batch(Graphics gfx, String pass)
        {
            Texture texture = null;
            BlendMode? blendMode = null;

            while (passState [pass].batchQueue.Count > 0)
            {
                Batch batch = passState [pass].batchQueue.Dequeue ();

                if (!blendMode.HasValue || texture != batch.Texture)
                {
                    gfx.SetActive(batch.Texture, 0);
                    texture = batch.Texture;
                }

                if (!blendMode.HasValue || blendMode != batch.BlendMode)
                {
                    gfx.SetBlendEquation(batch.BlendMode.Value);
                    blendMode = batch.BlendMode;
                }

                Int32 n = batch.Buffer.Length;

                FrameStats.Add ("DrawUserPrimitivesCount", 1);
                switch(batch.Type.Value)
                {
                    case Type.PRIM_QUADS:
                        gfx.DrawUserIndexedPrimitives<VertexPositionTextureColour>(
                            PrimitiveType.TriangleList, //primitiveType
                            batch.Buffer, //vertexData
                            0, //vertexOffset
                            n, //numVertices
                            quadIndices, //indexData
                            0, //indexOffset
                            n / 4 * 2);//primitiveCount
                        break;

                    case Type.PRIM_TRIPLES:
                        gfx.DrawUserPrimitives<VertexPositionTextureColour>(
                            PrimitiveType.TriangleList,//primitiveType
                            batch.Buffer, //vertexData
                            0,//vertexOffset
                            n / 3);//primitiveCount
                        break;

                    case Type.PRIM_LINES:
                        gfx.DrawUserPrimitives<VertexPositionTextureColour>(
                            PrimitiveType.LineList,//primitiveType
                            batch.Buffer, //vertexData
                            0,//vertexOffset
                            n / 2);//primitiveCount
                        break;
                }
            }
        }
示例#2
0
        internal void Render(Graphics zGfx, string pass, Matrix44 zView, Matrix44 zProjection)
        {
            if (!activeShapes.ContainsKey(pass))
                return;

            var shapesForThisPass = this.activeShapes[pass];

            // Calculate the total number of vertices we're going to be rendering.
            int vertexCount = 0;
            foreach (var shape in shapesForThisPass)
                vertexCount += shape.LineCount * 2;

            // If we have some vertices to draw
            if (vertexCount > 0)
            {
                // Make sure our array is large enough
                if (verts.Length < vertexCount)
                {
                    // If we have to resize, we make our array twice as large as necessary so
                    // we hopefully won't have to resize it for a while.
                    verts = new VertexPositionColour[vertexCount * 2];
                }

                // Now go through the shapes again to move the vertices to our array and
                // add up the number of lines to draw.
                int lineCount = 0;
                int vertIndex = 0;
                foreach (DebugShape shape in shapesForThisPass)
                {
                    lineCount += shape.LineCount;
                    int shapeVerts = shape.LineCount * 2;
                    for (int i = 0; i < shapeVerts; i++)
                        verts[vertIndex++] = shape.Vertices[i];
                }

                zGfx.SetCullMode (CullMode.None);

                // Update the render states on the gpu
                zGfx.SetBlendEquation (BlendMode.Default);

                zGfx.SetActive ((VertexBuffer)null);
                zGfx.SetActive ((IndexBuffer)null);

                debugShader.SetVariable ("View", zView);
                debugShader.SetVariable ("Projection", zProjection);

                // Start our effect to begin rendering.
                zGfx.SetActive (debugShader, VertexPositionColour.Default.VertexDeclaration);

                // We draw in a loop because the Reach profile only supports 65,535 primitives. While it's
                // not incredibly likely, if a game tries to render more than 65,535 lines we don't want to
                // crash. We handle this by doing a loop and drawing as many lines as we can at a time, capped
                // at our limit. We then move ahead in our vertex array and draw the next set of lines.
                int vertexOffset = 0;
                while (lineCount > 0)
                {
                    // Figure out how many lines we're going to draw
                    int linesToDraw = Math.Min (lineCount, 65535);

                    FrameStats.Add ("DrawUserPrimitivesCount", 1);
                    zGfx.DrawUserPrimitives (PrimitiveType.LineList, verts, vertexOffset, linesToDraw);

                    // Move our vertex offset ahead based on the lines we drew
                    vertexOffset += linesToDraw * 2;

                    // Remove these lines from our total line count
                    lineCount -= linesToDraw;
                }
            }
        }