示例#1
0
        private void ReturnBuffers()
        {
            if (vertexList != null)
            {
                BufferPool11.ReturnPositionTextureList(vertexList);
                vertexList = null;
            }

            if (childTriangleList != null)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (childTriangleList[i] != null)
                    {
                        BufferPool11.ReturnTriangleList(childTriangleList[i]);
                        childTriangleList[i] = null;
                    }
                }
            }
        }
示例#2
0
        public override void OnCreateVertexBuffer(VertexBuffer11 vb)
        {
            bool dem = DemEnabled;

            if (!subDivided)
            {
                if (vertexList == null)
                {
                    InitializeGrids();
                }


                for (int i = 0; i < 4; i++)
                {
                    int count = subDivisionLevel;
                    while (count-- > 1)
                    {
                        List <Triangle> newList = BufferPool11.GetTriagleList();
                        foreach (Triangle tri in childTriangleList[i])
                        {
                            tri.SubDivide(newList, vertexList);
                        }
                        BufferPool11.ReturnTriangleList(childTriangleList[i]);
                        childTriangleList[i] = newList;
                    }
                }
                subDivided = true;
            }

            //for (int i = 0; i < 4; i++)
            //{
            //    indexBuffer[i] = BufferPool11.GetShortIndexBuffer(childTriangleList[i].Count * 3);
            //}
            int indexCount = childTriangleList[0].Count * 3;


            demIndex = 0;
            try
            {
                // Create a vertex buffer
                PositionNormalTexturedX2[] verts = (PositionNormalTexturedX2[])vb.Lock(0, 0); // Lock the buffer (which will return our structs)

                int index = 0;
                if (dem && level > 1)
                {
                    demArray = new double[17 * 17];
                    if (backslash)
                    {
                        if (backslashYIndex == null)
                        {
                            tempBackslashYIndex = new byte[demSize];
                            tempBackslashXIndex = new byte[demSize];
                        }
                    }
                    else
                    {
                        if (slashYIndex == null)
                        {
                            tempSlashYIndex = new byte[demSize];
                            tempSlashXIndex = new byte[demSize];
                        }
                    }
                }

                foreach (PositionTexture vert in vertexList)
                {
                    if (dem)
                    {
                        // todo map this with backslash as well
                        verts[index++] = GetMappedVertex(vert);
                    }
                    else
                    {
                        verts[index++] = vert.PositionNormalTextured(localCenter, backslash);
                    }
                    demIndex++;
                }

                vb.Unlock();
                TriangleCount = childTriangleList[0].Count * 4;

                int quarterDivisions = SubDivisions / 2;
                int part             = 0;
                foreach (List <Triangle> triList in childTriangleList)
                {
                    if (GetIndexBuffer(part, 0) == null)
                    {
                        short[] indexArray = new short[indexCount];
                        int     indexer    = 0;
                        //dumpMutex.WaitOne();
                        //System.Diagnostics.Debug.WriteLine("start Index dump:" + part.ToString() + ";" + (backslash ? "Backslash" : "Slash"));
                        foreach (Triangle tri in triList)
                        {
                            indexArray[indexer++] = (short)tri.A;
                            indexArray[indexer++] = (short)tri.B;
                            indexArray[indexer++] = (short)tri.C;
                            //WriteDebugVertex(tri.A);
                            //WriteDebugVertex(tri.B);
                            //WriteDebugVertex(tri.C);
                        }
                        //System.Diagnostics.Debug.WriteLine("End Index dump");
                        //dumpMutex.ReleaseMutex();
                        ProcessIndexBuffer(indexArray, part);
                    }
                    part++;
                }

                if (backslash)
                {
                    if (tempBackslashXIndex != null)
                    {
                        backslashXIndex     = tempBackslashXIndex;
                        backslashYIndex     = tempBackslashYIndex;
                        tempBackslashXIndex = null;
                        tempBackslashYIndex = null;
                    }
                }
                else
                {
                    if (tempSlashYIndex != null)
                    {
                        slashXIndex     = tempSlashXIndex;
                        slashYIndex     = tempSlashYIndex;
                        tempSlashYIndex = null;
                        tempSlashXIndex = null;
                    }
                }
            }
            catch
            {
            }

            ReturnBuffers();
        }