Example #1
0
        public void PurgeDrawManager()
        {
            graphicsDevice = null;
            SpriteBatch    = null;

            blendStates.Clear();
            depthEnableStencilState  = null;
            depthDisableStencilState = null;

            effectStack.Clear();
            PrimitiveEffect = null;
            AlphaTestEffect = null;
            defaultEffect   = null;
            currentEffect   = null;

            currentRenderTarget = null;

            quadsBuffer      = null;
            quadsIndexBuffer = null;

            currentTexture = null;

            quadsVertices = null;
            quadsIndices  = null;
            TmpVertices.Clear();
        }
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (disposing)
            {
                Indices          = null;
                OriginalVertices = null;
                Vertices         = null;
                indexBuffer      = null;
                vertexBuffer     = null;
            }
        }
Example #3
0
        internal void DrawBuffer <T, T2>(CCVertexBuffer <T> vertexBuffer, CCIndexBuffer <T2> indexBuffer, int start, int count)
            where T : struct, IVertexType
            where T2 : struct
        {
            graphicsDevice.Indices = indexBuffer.IndexBuffer;
            graphicsDevice.SetVertexBuffer(vertexBuffer.VertexBuffer);

            ApplyEffectParams();

            EffectPassCollection passes = currentEffect.CurrentTechnique.Passes;

            for (int i = 0; i < passes.Count; i++)
            {
                passes[i].Apply();
                graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexBuffer.VertexBuffer.VertexCount, start, count);
            }

            graphicsDevice.SetVertexBuffer(null);
            graphicsDevice.Indices = null;
        }
Example #4
0
        void CheckQuadsIndexBuffer(int capacity)
        {
            if (quadsIndexBuffer == null || quadsIndexBuffer.Capacity < capacity * 6)
            {
                capacity = Math.Max(capacity, DefaultQuadBufferSize);

                if (quadsIndexBuffer == null)
                {
                    quadsIndexBuffer       = new CCIndexBuffer <short>(capacity * 6, BufferUsage.WriteOnly);
                    quadsIndexBuffer.Count = quadsIndexBuffer.Capacity;
                }

                if (quadsIndexBuffer.Capacity < capacity * 6)
                {
                    quadsIndexBuffer.Capacity = capacity * 6;
                    quadsIndexBuffer.Count    = quadsIndexBuffer.Capacity;
                }

                var indices = quadsIndexBuffer.Data.Elements;

                int i6 = 0;
                int i4 = 0;

                for (int i = 0; i < capacity; ++i)
                {
                    indices[i6 + 0] = (short)(i4 + 0);
                    indices[i6 + 1] = (short)(i4 + 2);
                    indices[i6 + 2] = (short)(i4 + 1);

                    indices[i6 + 3] = (short)(i4 + 1);
                    indices[i6 + 4] = (short)(i4 + 2);
                    indices[i6 + 5] = (short)(i4 + 3);

                    i6 += 6;
                    i4 += 4;
                }

                quadsIndexBuffer.UpdateBuffer();
            }
        }
Example #5
0
        public override void CalculateVertexPoints()
        {
            float width  = Texture.PixelsWide;
            float height = Texture.PixelsHigh;
            float imageH = Texture.ContentSizeInPixels.Height;

            int numOfPoints = (GridSize.X + 1) * (GridSize.Y + 1);

            vertexBuffer       = new CCVertexBuffer <CCV3F_T2F>(numOfPoints, CCBufferUsage.WriteOnly);
            vertexBuffer.Count = numOfPoints;
            indexBuffer        = new CCIndexBuffer <ushort>(GridSize.X * GridSize.Y * 6, BufferUsage.WriteOnly);
            indexBuffer.Count  = GridSize.X * GridSize.Y * 6;

            Vertices = vertexBuffer.Data.Elements;
            Indices  = indexBuffer.Data.Elements;

            OriginalVertices = new CCVertex3F[numOfPoints];

            CCV3F_T2F[] vertArray = Vertices;
            ushort[]    idxArray  = Indices;

            var l1   = new int[4];
            var l2   = new CCVertex3F[4];
            var tex1 = new int[4];
            var tex2 = new CCPoint[4];

            //int idx = -1;
            for (int x = 0; x < GridSize.X; ++x)
            {
                for (int y = 0; y < GridSize.Y; ++y)
                {
                    float x1 = x * Step.X;
                    float x2 = x1 + Step.X;
                    float y1 = y * Step.Y;
                    float y2 = y1 + Step.Y;

                    var a = (short)(x * (GridSize.Y + 1) + y);
                    var b = (short)((x + 1) * (GridSize.Y + 1) + y);
                    var c = (short)((x + 1) * (GridSize.Y + 1) + (y + 1));
                    var d = (short)(x * (GridSize.Y + 1) + (y + 1));

                    int idx = ((y * GridSize.X) + x) * 6;

                    idxArray[idx + 0] = (ushort)a;
                    idxArray[idx + 1] = (ushort)b;
                    idxArray[idx + 2] = (ushort)d;
                    idxArray[idx + 3] = (ushort)b;
                    idxArray[idx + 4] = (ushort)c;
                    idxArray[idx + 5] = (ushort)d;

                    //var tempidx = new short[6] {a, d, b, b, d, c};
                    //Array.Copy(tempidx, 0, idxArray, 6 * idx, tempidx.Length);

                    l1[0] = a;
                    l1[1] = b;
                    l1[2] = c;
                    l1[3] = d;

                    //var e = new Vector3(x1, y1, 0);
                    //var f = new Vector3(x2, y1, 0);
                    //var g = new Vector3(x2, y2, 0);
                    //var h = new Vector3(x1, y2, 0);

                    l2[0] = new CCVertex3F(x1, y1, 0);
                    l2[1] = new CCVertex3F(x2, y1, 0);
                    l2[2] = new CCVertex3F(x2, y2, 0);
                    l2[3] = new CCVertex3F(x1, y2, 0);

                    tex1[0] = a;
                    tex1[1] = b;
                    tex1[2] = c;
                    tex1[3] = d;

                    tex2[0] = new CCPoint(x1, y1);
                    tex2[1] = new CCPoint(x2, y1);
                    tex2[2] = new CCPoint(x2, y2);
                    tex2[3] = new CCPoint(x1, y2);

                    for (int i = 0; i < 4; ++i)
                    {
                        vertArray[l1[i]].Vertices = l2[i];

                        vertArray[tex1[i]].TexCoords.U = tex2[i].X / width;

                        if (TextureFlipped)
                        {
                            vertArray[tex1[i]].TexCoords.V = tex2[i].Y / height;
                        }
                        else
                        {
                            vertArray[tex1[i]].TexCoords.V = (imageH - tex2[i].Y) / height;
                        }
                    }
                }
            }

            int n = (GridSize.X + 1) * (GridSize.Y + 1);

            for (int i = 0; i < n; i++)
            {
                OriginalVertices[i] = Vertices[i].Vertices;
            }

            indexBuffer.UpdateBuffer();

            dirty = true;
        }
Example #6
0
        public override void CalculateVertexPoints()
        {
            float width  = Texture.PixelsWide;
            float height = Texture.PixelsHigh;
            float imageH = Texture.ContentSizeInPixels.Height;

            int numQuads = GridSize.X * GridSize.Y;

            vertexBuffer       = new CCVertexBuffer <CCV3F_T2F>(numQuads * 4, CCBufferUsage.WriteOnly);
            vertexBuffer.Count = numQuads * 4;
            indexBuffer        = new CCIndexBuffer <short>(numQuads * 6, BufferUsage.WriteOnly);
            indexBuffer.Count  = numQuads * 6;

            Vertices = vertexBuffer.Data.Elements;
            Indices  = indexBuffer.Data.Elements;

            OriginalVertices = new CCQuad3[numQuads];

            CCV3F_T2F[] vertArray = Vertices;
            short[]     idxArray  = Indices;


            int index = 0;

            for (int x = 0; x < GridSize.X; x++)
            {
                for (int y = 0; y < GridSize.Y; y++)
                {
                    float x1 = x * Step.X;
                    float x2 = x1 + Step.X;
                    float y1 = y * Step.Y;
                    float y2 = y1 + Step.Y;

                    vertArray[index + 0].Vertices = new CCVertex3F(x1, y1, 0);
                    vertArray[index + 1].Vertices = new CCVertex3F(x2, y1, 0);
                    vertArray[index + 2].Vertices = new CCVertex3F(x1, y2, 0);
                    vertArray[index + 3].Vertices = new CCVertex3F(x2, y2, 0);

                    float newY1 = y1;
                    float newY2 = y2;

                    if (!TextureFlipped)
                    {
                        newY1 = imageH - y1;
                        newY2 = imageH - y2;
                    }

                    vertArray[index + 0].TexCoords = new CCTex2F(x1 / width, newY1 / height);
                    vertArray[index + 1].TexCoords = new CCTex2F(x2 / width, newY1 / height);
                    vertArray[index + 2].TexCoords = new CCTex2F(x1 / width, newY2 / height);
                    vertArray[index + 3].TexCoords = new CCTex2F(x2 / width, newY2 / height);

                    index += 4;
                }
            }

            for (int x = 0; x < numQuads; x++)
            {
                int i6 = x * 6;
                int i4 = x * 4;
                idxArray[i6 + 0] = (short)(i4 + 0);
                idxArray[i6 + 1] = (short)(i4 + 2);
                idxArray[i6 + 2] = (short)(i4 + 1);

                idxArray[i6 + 3] = (short)(i4 + 1);
                idxArray[i6 + 4] = (short)(i4 + 2);
                idxArray[i6 + 5] = (short)(i4 + 3);
            }

            indexBuffer.UpdateBuffer();

            for (int i = 0; i < numQuads; i++)
            {
                int i4 = i * 4;
                OriginalVertices[i].BottomLeft  = vertArray[i4 + 0].Vertices;
                OriginalVertices[i].BottomRight = vertArray[i4 + 1].Vertices;
                OriginalVertices[i].TopLeft     = vertArray[i4 + 2].Vertices;
                OriginalVertices[i].TopRight    = vertArray[i4 + 3].Vertices;
            }
        }
Example #7
0
 public CCPrimitive(CCVertexBuffer <T> vertexBuffer, CCIndexBuffer <T2> indexBuffer = null, PrimitiveType primitiveType = PrimitiveType.TriangleList)
 {
     VertexBuffer  = vertexBuffer;
     IndexBuffer   = indexBuffer;
     PrimitiveType = primitiveType;
 }