コード例 #1
0
        public void Dispose()
        {
            if (vertexBuffer != null)
            {
                vertexBuffer.Dispose();
                GC.SuppressFinalize(vertexBuffer);
                vertexBuffer = null;
            }

            if (fallbackVertexBuffer != null)
            {
                fallbackVertexBuffer.Dispose();
                GC.SuppressFinalize(fallbackVertexBuffer);
                fallbackVertexBuffer = null;
            }

            if (spriteCornerVertexBuffer != null)
            {
                spriteCornerVertexBuffer.Dispose();
                GC.SuppressFinalize(spriteCornerVertexBuffer);
                spriteCornerVertexBuffer = null;
            }

            if (indexBuffer != null)
            {
                indexBuffer.Dispose();
                GC.SuppressFinalize(indexBuffer);
                indexBuffer = null;
            }
        }
コード例 #2
0
        private void createIndexBuffer(SharpDX.Direct3D11.Device device, int pointCount)
        {
            uint[] indices = new uint[pointCount * 6];
            for (uint i = 0; i < pointCount; ++i)
            {
                indices[i * 6 + 0] = i * 4 + 0;
                indices[i * 6 + 1] = i * 4 + 1;
                indices[i * 6 + 2] = i * 4 + 2;
                indices[i * 6 + 3] = i * 4 + 0;
                indices[i * 6 + 4] = i * 4 + 2;
                indices[i * 6 + 5] = i * 4 + 3;
            }

            indexBuffer = new IndexBuffer11(device, indices);
        }
コード例 #3
0
        //[LayerProperty]
        //public override Color Color
        //{
        //    get
        //    {
        //        return base.Color;
        //    }
        //    set
        //    {
        //        base.Color = value;
        //        CleanUp();
        //    }
        //}

        public override void CleanUp()
        {
            if (shapeFileIndex != null)
            {
                shapeFileIndex.Dispose();
                GC.SuppressFinalize(shapeFileIndex);
                shapeFileIndex = null;
            }
            if (shapeFileVertex != null)
            {
                shapeFileVertex.Dispose();
                GC.SuppressFinalize(shapeFileVertex);

                shapeFileVertex = null;
            }
        }
コード例 #4
0
        public override void CleanUpGeometryOnly()
        {
            base.CleanUpGeometryOnly();

            if (this.vertexBuffer != null)
            {
                this.vertexBuffer.Dispose();
                GC.SuppressFinalize(vertexBuffer);
                this.vertexBuffer = null;
            }

            if (this.indexBuffer != null)
            {
                indexBuffer.Dispose();
                GC.SuppressFinalize(indexBuffer);
                indexBuffer = null;
            }
        }
コード例 #5
0
        public static void ReturnShortIndexBuffer(IndexBuffer11 buff)
        {
            if (buff == null)
            {
                return;
            }
            //old code to dispose buffers
            buff.Dispose();
            GC.SuppressFinalize(buff);

            //todo11 reenable buffer pooling
            //int count = buff.Count;
            //if (!IndexPools.ContainsKey(count))
            //{
            //    IndexPools.Add(count, new Buffers(count));
            //}

            //IndexPools[count].Entries.Push(buff);
        }
コード例 #6
0
        public override void CleanUp()
        {
            CleanAndReady = false;

            if (shapeFileIndex != null)
            {
                shapeFileIndex.Dispose();
                GC.SuppressFinalize(shapeFileIndex);
                shapeFileIndex = null;
            }
            if (shapeFileVertex != null)
            {
                shapeFileVertex.Dispose();
                GC.SuppressFinalize(shapeFileVertex);

                shapeFileVertex = null;
            }


            if (lineList != null)
            {
                lineList.Clear();
            }
            if (lineList2d != null)
            {
                lineList2d.Clear();
            }

            if (triangleList2d != null)
            {
                triangleList2d.Clear();
            }

            if (triangleList != null)
            {
                triangleList.Clear();
            }
            if (textBatch != null)
            {
                textBatch.CleanUp();
            }
        }
コード例 #7
0
        public override bool CreateGeometry(RenderContext11 renderContext, bool uiThread)
        {
            if (texture == null)
            {
                if (this.texture == null)
                {
                    if (TextureReady)
                    {

                        texture = BufferPool11.GetTexture(FileName);

                        double aspect = (double)texture.Width / (double)texture.Height;

                        if (aspect < 1.5)
                        {
                            domeMaster = true;
                        }

                    }
                    else
                    {
                        return false;
                    }
                }

                iTileBuildCount++;

                if (vertexBuffer == null)
                {
                    vertexBuffer = new VertexBuffer11(typeof(PositionNormalTexturedX2), VertexCount, RenderContext11.PrepDevice);
                    indexBuffer = new IndexBuffer11[4];

                    OnCreateVertexBuffer(vertexBuffer);
                    sphereRadius = 1;
                    sphereCenter = new Vector3d(0, 0, 0);
                }
            }
            ReadyToRender = true;
            return true;
        }
コード例 #8
0
        public override void CleanUp(bool removeFromParent)
        {
            base.CleanUp(removeFromParent);

            this.ImageData = null;

            if (this.texture != null)
            {
                this.texture.Dispose();
                GC.SuppressFinalize(texture);
                this.texture = null;
            }

            if (this.vertexBuffer != null)
            {
                try
                {
                    this.vertexBuffer.Dispose();
                    GC.SuppressFinalize(vertexBuffer);
                    this.vertexBuffer = null;
                }
                catch
                {
                }
            }

            if (this.indexBuffer != null)
            {
                try
                {
                    indexBuffer.Dispose();
                    GC.SuppressFinalize(indexBuffer);
                    indexBuffer = null;
                }
                catch
                {
                }
            }
        }
コード例 #9
0
        private void ProcessIndexBuffer(short[] indexArray, int part)
        {
            if (level == 0)
            {
                rootIndexBuffer[part] = new IndexBuffer11(RenderContext11.PrepDevice, indexArray);
                return;
            }

            for (int a = 0; a < 16; a++)
            {
                short[] partArray = indexArray.Clone() as short[];
                ProcessAccomindations(partArray, a);
                if (backslash)
                {
                    backSlashIndexBuffer[part, a] = new IndexBuffer11(RenderContext11.PrepDevice, partArray);
                }
                else
                {
                    slashIndexBuffer[part, a] = new IndexBuffer11(RenderContext11.PrepDevice, partArray);
                }
            }
        }
コード例 #10
0
        public override bool CreateGeometry(RenderContext11 renderContext, bool uiThread)
        {
            if (texture == null)
            {
                if (this.texture == null)
                {
                    if (TextureReady)
                    {
                        texture = BufferPool11.GetTexture(FileName);

                        double aspect = (double)texture.Width / (double)texture.Height;

                        if (aspect < 1.5)
                        {
                            domeMaster = true;
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }


                iTileBuildCount++;

                if (vertexBuffer == null)
                {
                    vertexBuffer = new VertexBuffer11(typeof(PositionNormalTexturedX2), VertexCount, RenderContext11.PrepDevice);
                    indexBuffer  = new IndexBuffer11[4];

                    OnCreateVertexBuffer(vertexBuffer);
                    sphereRadius = 1;
                    sphereCenter = new Vector3d(0, 0, 0);
                }
            }
            ReadyToRender = true;
            return(true);
        }
コード例 #11
0
        public static void DisposeBuffers()
        {
            foreach (Buffers pool in IndexPools.Values)
            {
                foreach (object buf in pool.Entries)
                {
                    IndexBuffer11 indexBuf = buf as IndexBuffer11;
                    indexBuf.Dispose();
                    GC.SuppressFinalize(indexBuf);
                }
            }
            IndexPools.Clear();

            foreach (Buffers pool in VertexX2Pools.Values)
            {
                foreach (object buf in pool.Entries)
                {
                    VertexBuffer11 vertexBuf = buf as VertexBuffer11;
                    vertexBuf.Dispose();
                    GC.SuppressFinalize(vertexBuf);
                }
            }
            Vector3dPools.Clear();

            // no need to dispose since these are just managed buffers
            LockX2Pools.Clear();
            Vector3dPools.Clear();
            IndexU32Pools.Clear();
            IndexU32Pools.Clear();
            TriangleListPool.Entries.Clear();

            foreach (Texture11 texture in TexturePool256)
            {
                texture.Dispose();
                GC.SuppressFinalize(texture);
            }
            TexturePool256.Clear();
        }
コード例 #12
0
        public override bool Draw(RenderContext11 renderContext, float opacity, bool flat)
        {
            if (shapefile == null)
            {
                return false;
            }

            if (shapeFileVertex == null)
            {

                var vertList = new List<Vector3>();
                var indexList = new List<UInt32>();
                UInt32 firstItemIndex = 0;
                var lastItem = new Vector3();
                var firstItem = true;

                var north = true;
                double offsetX = 0;
                double offsetY = 0;
                double centralMeridian = 0;
                double mapScale = 0;
                double standardParallel = 70;

                if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                {
                    north = shapefile.FileHeader.ProjectionInfo.Name.ToLower().Contains("north");
                    standardParallel = shapefile.FileHeader.ProjectionInfo.GetParameter("standard_parallel_1");
                    centralMeridian = shapefile.FileHeader.ProjectionInfo.GetParameter("central_meridian");
                    mapScale = shapefile.FileHeader.ProjectionInfo.GetParameter("scale_factor");
                    offsetY = shapefile.FileHeader.ProjectionInfo.GetParameter("false_easting");
                    offsetX = shapefile.FileHeader.ProjectionInfo.GetParameter("false_northing");

                }

                UInt32 currentIndex = 0;
                var color = Color;
                var count = 360;
                for (var i = 0; i < shapefile.Shapes.Count; i++)
                {
                    if (shapefile.Shapes[i].GetType() == typeof(Polygon))
                    {
                        var p = (Polygon)shapefile.Shapes[i];

                        for (var z = 0; z < p.Rings.Length; z++)
                        {
                            count = (p.Rings[z].Points.Length);

                            // content from DBF
                            var dr = p.Rings[z].Attributes;

                            for (var k = 0; k < p.Rings[z].Points.Length; k++)
                            {
                                // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used.
                                var Xcoord = p.Rings[z].Points[k].X;
                                var Ycoord = p.Rings[z].Points[k].Y;

                                if (shapefile.Projection == ShapeFile.Projections.Geo)
                                {
                                    lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord);
                                }
                                else if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                                {
                                    lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3;
                                }

                                if (k == 0)
                                {
                                    firstItemIndex = currentIndex;
                                    firstItem = true;
                                }

                                vertList.Add(lastItem);

                                if (firstItem)
                                {
                                    firstItem = false;
                                }
                                else
                                {
                                    indexList.Add(currentIndex);
                                    currentIndex++;
                                    indexList.Add(currentIndex);
                                }
                            }

                            indexList.Add(currentIndex);
                            indexList.Add(firstItemIndex);
                            currentIndex++;

                        }
                    }
                    else if (shapefile.Shapes[i].GetType() == typeof(PolygonZ))
                    {
                        var p = (PolygonZ)shapefile.Shapes[i];

                        for (var z = 0; z < p.Rings.Length; z++)
                        {
                            count = (p.Rings[z].Points.Length);

                            // content from DBF
                            var dr = p.Rings[z].Attributes;

                            for (var k = 0; k < p.Rings[z].Points.Length; k++)
                            {
                                // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used.
                                var Xcoord = p.Rings[z].Points[k].X;
                                var Ycoord = p.Rings[z].Points[k].Y;

                                if (shapefile.Projection == ShapeFile.Projections.Geo)
                                {
                                    lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord);
                                }
                                else if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                                {
                                    lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3;
                                }

                                if (k == 0)
                                {
                                    firstItemIndex = currentIndex;
                                    firstItem = true;
                                }

                                vertList.Add(lastItem);

                                if (firstItem)
                                {
                                    firstItem = false;
                                }
                                else
                                {
                                    indexList.Add(currentIndex);
                                    currentIndex++;
                                    indexList.Add(currentIndex);
                                }
                            }

                            indexList.Add(currentIndex);
                            indexList.Add(firstItemIndex);
                            currentIndex++;

                        }
                    }
                    else if (shapefile.Shapes[i].GetType() == typeof(PolyLine))
                    {
                        var p = (PolyLine)shapefile.Shapes[i];
                        for (var z = 0; z < p.Lines.Length; z++)
                        {
                            count = (p.Lines[z].Points.Length);

                            firstItem = true;
                            for (var k = 0; k < p.Lines[z].Points.Length; k++)
                            {
                                // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used.
                                var Xcoord = p.Lines[z].Points[k].X;
                                var Ycoord = p.Lines[z].Points[k].Y;
                                if (shapefile.Projection == ShapeFile.Projections.Geo)
                                {
                                    lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord);
                                }
                                else if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                                {
                                    lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3;
                                }

                                if (k == 0)
                                {
                                    firstItemIndex = currentIndex;
                                    firstItem = true;
                                }

                                vertList.Add(lastItem);

                                if (firstItem)
                                {
                                    firstItem = false;
                                }
                                else
                                {
                                    indexList.Add(currentIndex);
                                    currentIndex++;
                                    indexList.Add(currentIndex);
                                }

                            }
                            currentIndex++;

                        }
                    }
                    else if (shapefile.Shapes[i].GetType() == typeof(PolyLineZ))
                    {
                        var p = (PolyLineZ)shapefile.Shapes[i];
                        for (var z = 0; z < p.Lines.Length; z++)
                        {
                            count = (p.Lines[z].Points.Length);
                            var points = new Vector3[(count)];

                            firstItem = true;
                            for (var k = 0; k < p.Lines[z].Points.Length; k++)
                            {
                                // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used.
                                var Xcoord = p.Lines[z].Points[k].X;
                                var Ycoord = p.Lines[z].Points[k].Y;
                                if (shapefile.Projection == ShapeFile.Projections.Geo)
                                {
                                    lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord);
                                }
                                else if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                                {
                                    lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3;
                                }

                                if (k == 0)
                                {
                                    firstItemIndex = currentIndex;
                                    firstItem = true;
                                }

                                vertList.Add(lastItem);

                                if (firstItem)
                                {
                                    firstItem = false;
                                }
                                else
                                {
                                    indexList.Add(currentIndex);
                                    currentIndex++;
                                    indexList.Add(currentIndex);
                                }

                            }
                            currentIndex++;

                        }
                    }
                    else if (shapefile.Shapes[i].GetType() == typeof(Point))
                    {
                        var p = (Point)shapefile.Shapes[i];

                        // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used.
                        var Xcoord = p.X;
                        var Ycoord = p.Y;
                        if (shapefile.Projection == ShapeFile.Projections.Geo)
                        {
                            lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord);
                        }
                        else if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                        {
                            lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3;
                        }

                        vertList.Add(lastItem);

                        currentIndex++;
                        lines = false;
                    }

                }

                shapeVertexCount = vertList.Count;
                shapeFileVertex = new PositionVertexBuffer11(vertList.Count, RenderContext11.PrepDevice);

                var verts = (Vector3[])shapeFileVertex.Lock(0, 0); // Lock the buffer (which will return our structs)
                var indexer = 0;
                foreach (var vert in vertList)
                {
                    verts[indexer++] = vert;
                }
                shapeFileVertex.Unlock();

                shapeIndexCount = indexList.Count;

                if (lines)
                {
                    if (indexList.Count > 65500)
                    {
                        isLongIndex = true;
                        shapeFileIndex = new IndexBuffer11(typeof(UInt32), indexList.Count, RenderContext11.PrepDevice);
                    }
                    else
                    {
                        isLongIndex = false;
                        shapeFileIndex = new IndexBuffer11(typeof(short), indexList.Count, RenderContext11.PrepDevice);
                    }

                    if (isLongIndex)
                    {
                        indexer = 0;
                        var indexes = (UInt32[])shapeFileIndex.Lock();
                        foreach (var indexVal in indexList)
                        {
                            indexes[indexer++] = indexVal;
                        }
                        shapeFileIndex.Unlock();
                    }
                    else
                    {
                        indexer = 0;
                        var indexes = (short[])shapeFileIndex.Lock();
                        foreach (var indexVal in indexList)
                        {
                            indexes[indexer++] = (short)indexVal;
                        }
                        shapeFileIndex.Unlock();
                    }
                }
            }

            renderContext.DepthStencilMode = DepthStencilMode.Off;
            renderContext.BlendMode = BlendMode.Alpha;
            SimpleLineShader11.Color = Color.FromArgb((int)(opacity * 255), Color);

            var mat = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            mat.Transpose();

            SimpleLineShader11.WVPMatrix = mat;
            SimpleLineShader11.CameraPosition = Vector3d.TransformCoordinate(renderContext.CameraPosition, Matrix3d.Invert(renderContext.World)).Vector3;
            SimpleLineShader11.ShowFarSide = false;
            SimpleLineShader11.Sky = false;

            renderContext.SetVertexBuffer(shapeFileVertex);
            SimpleLineShader11.Use(renderContext.devContext);

            if (lines)
            {
                renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineList;
                renderContext.SetIndexBuffer(shapeFileIndex);
                renderContext.devContext.DrawIndexed(shapeFileIndex.Count, 0, 0);
            }
            else
            {
                renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList;
                renderContext.devContext.Draw(shapeVertexCount, 0);
            }

            renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;

            return true;
        }
コード例 #13
0
        public override void OnCreateVertexBuffer(VertexBuffer11 vb)
        {
            for (var i = 0; i < 4; i++)
            {
                indexBuffer[i] = new IndexBuffer11(typeof(short), ((SubDivisions / 2) * (SubDivisions / 2) * 6), RenderContext11.PrepDevice);
            }
            try
            {
                if (!topDown)
                {
                    OnCreateVertexBufferBottomsUp(vb);
                    return;
                }

                int index;
                var tileDegrees = dataset.BaseTileDegrees / (Math.Pow(2, level));

                var latMin = (90 - (this.y * tileDegrees));
                var latMax = (90 - ((this.y + 1) * tileDegrees));
                var lngMin = ((this.x * tileDegrees) - 180.0);
                var lngMax = (((this.x + 1) * tileDegrees) - 180.0);
                var tileDegreesX = lngMax - lngMin;
                var tileDegreesY = latMax - latMin;

                //bugbug altitude broken
                TopLeft = GeoTo3dWithAltitude(latMin, lngMin, false);
                BottomRight = GeoTo3dWithAltitude(latMax, lngMax, false);
                TopRight = GeoTo3dWithAltitude(latMin, lngMax, false);
                BottomLeft = GeoTo3dWithAltitude(latMax, lngMin, false);

                // Create a vertex buffer
                var verts = (PositionNormalTexturedX2[])vb.Lock(0, 0); // Lock the buffer (which will return our structs)
                int x, y;

                var textureStep = 1.0f / SubDivisions;
                for (y = 0; y <= SubDivisions; y++)
                {
                    double lat;
                    if (y != SubDivisions)
                    {
                        lat = latMin + (textureStep * tileDegreesY * y);
                    }
                    else
                    {
                        lat = latMax;
                    }
                    for (x = 0; x <= SubDivisions; x++)
                    {
                        double lng;
                        if (x != SubDivisions)
                        {
                            lng = lngMin + (textureStep * tileDegreesX * x);
                        }
                        else
                        {
                            lng = lngMax;
                        }
                        index = y * (SubDivisions + 1) + x;
                        verts[index].Position = GeoTo3dWithAltitude(lat, lng, true);// Add Altitude mapping here
                        verts[index].Normal = GeoTo3d(lat, lng, false);
                        verts[index].Tu = x * textureStep;
                        verts[index].Tv = y * textureStep;
                        verts[index].Lat = lat;
                        verts[index].Lng = lng;

                    }
                }
                vb.Unlock();
                TriangleCount = (SubDivisions) * (SubDivisions) * 2;

                var quarterDivisions = SubDivisions / 2;
                var part = 0;
                for (var y2 = 0; y2 < 2; y2++)
                {
                    for (var x2 = 0; x2 < 2; x2++)
                    {
                        var indexArray = (short[])indexBuffer[part].Lock();
                        index = 0;
                        for (var y1 = (quarterDivisions * y2); y1 < (quarterDivisions * (y2 + 1)); y1++)
                        {
                            for (var x1 = (quarterDivisions * x2); x1 < (quarterDivisions * (x2 + 1)); x1++)
                            {
                                //index = ((y1 * quarterDivisions * 6) + 6 * x1);
                                // First triangle in quad
                                indexArray[index] = (short)(y1 * (SubDivisions + 1) + x1);
                                indexArray[index + 1] = (short)((y1 + 1) * (SubDivisions + 1) + x1);
                                indexArray[index + 2] = (short)(y1 * (SubDivisions + 1) + (x1 + 1));

                                // Second triangle in quad
                                indexArray[index + 3] = (short)(y1 * (SubDivisions + 1) + (x1 + 1));
                                indexArray[index + 4] = (short)((y1 + 1) * (SubDivisions + 1) + x1);
                                indexArray[index + 5] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1));
                                index += 6;
                            }
                        }
                        indexBuffer[part].Unlock();
                        part++;
                    }
                }
            }
            catch
            {
            }
        }
コード例 #14
0
        private void ProcessIndexBuffer(short[] indexArray, int part)
        {
            if (level == 0)
            {
                rootIndexBuffer[part] = new IndexBuffer11(RenderContext11.PrepDevice, indexArray);
                return;
            }

            for (var a = 0; a < 16; a++)
            {
                var partArray = indexArray.Clone() as short[];
                ProcessAccomindations(partArray, a);
                if (backslash)
                {
                    backSlashIndexBuffer[part, a] = new IndexBuffer11(RenderContext11.PrepDevice, partArray);
                }
                else
                {
                    slashIndexBuffer[part, a] = new IndexBuffer11(RenderContext11.PrepDevice, partArray);
                }
            }
        }
コード例 #15
0
        public void CreateWarpVertexBuffer()
        {
            ReadWarpMeshFile();
            int warpSubX = meshX - 1;
            int warpSubY = meshY - 1;

            CleanUpWarpBuffers();


            warpIndexBuffer = new IndexBuffer11(typeof(short), (warpSubX * warpSubY * 6), RenderContext11.PrepDevice);
            warpVertexBuffer = new PositionColorTexturedVertexBuffer11(((warpSubX + 1) * (warpSubY + 1)), RenderContext11.PrepDevice);

            warpVertexCount = ((warpSubX + 1) * (warpSubY + 1));


            int index = 0;

            PositionColorTexturedVertexBuffer11 vb = warpVertexBuffer;
            // Create a vertex buffer 
            PositionColoredTextured[] verts = (PositionColoredTextured[])vb.Lock(0, 0); // Lock the buffer (which will return our structs)
            int x1, y1;



            double textureStepX = 1.0f / warpSubX;
            double textureStepY = 1.0f / warpSubY;
            for (y1 = 0; y1 <= warpSubY; y1++)
            {

                for (x1 = 0; x1 <= warpSubX; x1++)
                {

                    index = y1 * (warpSubX + 1) + x1;
                    verts[index].Position = mesh[x1, y1].Position;
                    verts[index].Tu = mesh[x1, y1].Tu;
                    verts[index].Tv = mesh[x1, y1].Tv;
                    verts[index].Color = mesh[x1, y1].Color;
                }
            }
            vb.Unlock();
            warpTriangleCount = (warpSubX) * (warpSubY) * 2;
            short[] indexArray = (short[])warpIndexBuffer.Lock();
            index = 0;
            for (y1 = 0; y1 < warpSubY; y1++)
            {
                for (x1 = 0; x1 < warpSubX; x1++)
                {
                    // First triangle in quad
                    indexArray[index] = (short)(y1 * (warpSubX + 1) + x1);
                    indexArray[index + 1] = (short)((y1 + 1) * (warpSubX + 1) + x1);
                    indexArray[index + 2] = (short)(y1 * (warpSubX + 1) + (x1 + 1));

                    // Second triangle in quad
                    indexArray[index + 3] = (short)(y1 * (warpSubX + 1) + (x1 + 1));
                    indexArray[index + 4] = (short)((y1 + 1) * (warpSubX + 1) + x1);
                    indexArray[index + 5] = (short)((y1 + 1) * (warpSubX + 1) + (x1 + 1));
                    index += 6;
                }
            }
            this.warpIndexBuffer.Unlock();
        }
コード例 #16
0
        private void MakeDistortionGrid()
        {
            Bitmap bmpBlend = new Bitmap(config.BlendFile);
            FastBitmap fastBlend = new FastBitmap(bmpBlend);
            Bitmap bmpDistort = new Bitmap(config.DistortionGrid);
            FastBitmap fastDistort = new FastBitmap(bmpDistort);


            fastBlend.LockBitmapRgb();
            fastDistort.LockBitmapRgb();
            int subX = bmpBlend.Width - 1;
            int subY = subX;

            if (distortIndexBuffer != null)
            {
                distortIndexBuffer.Dispose();
                GC.SuppressFinalize(distortIndexBuffer);
            }

            if (distortVertexBuffer != null)
            {
                distortVertexBuffer.Dispose();
                GC.SuppressFinalize(distortVertexBuffer);
            }


            distortIndexBuffer = new IndexBuffer11(typeof(int), (subX * subY * 6), RenderContext11.PrepDevice);
            distortVertexBuffer = new PositionColorTexturedVertexBuffer11(((subX + 1) * (subY + 1)), RenderContext11.PrepDevice);

            distortVertexCount = (subX + 1) * (subY + 1);


            int index = 0;


            // Create a vertex buffer 
            PositionColoredTextured[] verts = (PositionColoredTextured[])distortVertexBuffer.Lock(0, 0); // Lock the buffer (which will return our structs)
            int x1, y1;

            unsafe
            {
                double maxU = 0;
                double maxV = 0;
                double textureStepX = 1.0f / subX;
                double textureStepY = 1.0f / subY;
                for (y1 = 0; y1 <= subY; y1++)
                {
                    double tv;
                    for (x1 = 0; x1 <= subX; x1++)
                    {
                        double tu;


                        index = y1 * (subX + 1) + x1;
                        PixelDataRgb* pdata = fastDistort.GetRgbPixel(x1, y1);

                        tu = (float)(pdata->blue + ((uint)pdata->red % 16) * 256) / 4095f;
                        tv = (float)(pdata->green + ((uint)pdata->red / 16) * 256) / 4095f;

                        //tu = (tu - .5f) * 1.7777778 + .5f;

                        if (tu > maxU)
                        {
                            maxU = tu;
                        }
                        if (tv > maxV)
                        {
                            maxV = tv;
                        }

                        verts[index].Position = new SharpDX.Vector4(((float)x1 / subX) - .5f, (1f - ((float)y1 / subY)) - .5f, .9f, 1f);
                        verts[index].Tu = (float)tu;
                        verts[index].Tv = (float)tv;
                        PixelDataRgb* pPixel = fastBlend.GetRgbPixel(x1, y1);

                        verts[index].Color = Color.FromArgb(255, pPixel->red, pPixel->green, pPixel->blue);

                    }
                }
                distortVertexBuffer.Unlock();
                distortTriangleCount = (subX) * (subY) * 2;
                uint[] indexArray = (uint[])distortIndexBuffer.Lock();
                index = 0;
                for (y1 = 0; y1 < subY; y1++)
                {
                    for (x1 = 0; x1 < subX; x1++)
                    {
                        // First triangle in quad
                        indexArray[index] = (uint)(y1 * (subX + 1) + x1);
                        indexArray[index + 1] = (uint)((y1 + 1) * (subX + 1) + x1);
                        indexArray[index + 2] = (uint)(y1 * (subX + 1) + (x1 + 1));

                        // Second triangle in quad
                        indexArray[index + 3] = (uint)(y1 * (subX + 1) + (x1 + 1));
                        indexArray[index + 4] = (uint)((y1 + 1) * (subX + 1) + x1);
                        indexArray[index + 5] = (uint)((y1 + 1) * (subX + 1) + (x1 + 1));
                        index += 6;
                    }
                }
                this.distortIndexBuffer.Unlock();
            }
            fastDistort.UnlockBitmap();
            fastBlend.UnlockBitmap();
            fastDistort.Dispose();
            GC.SuppressFinalize(fastDistort);
            fastBlend.Dispose();
            GC.SuppressFinalize(fastBlend);
        }
コード例 #17
0
        // Convert the vertex data to a GPU vertex buffer
        public void commitToDevice(SharpDX.Direct3D11.Device device)
        {
            if (vertices != null)
            {
                vertexBuffer = new GenVertexBuffer<PositionNormalTextured>(device, vertices);
            }
            else if (tangentVertices != null)
            {
                tangentVertexBuffer = new GenVertexBuffer<PositionNormalTexturedTangent>(device, tangentVertices);
            }

            indexBuffer = new IndexBuffer11(device, indices);
        }
コード例 #18
0
        public override void CleanUp(bool removeFromParent)
        {
            base.CleanUp(removeFromParent);

            ImageData = null;

            if (texture != null)
            {
                texture.Dispose();
                GC.SuppressFinalize(texture);
                texture = null;
            }

            if (vertexBuffer != null)
            {
                try
                {
                    vertexBuffer.Dispose();
                    GC.SuppressFinalize(vertexBuffer);
                    vertexBuffer = null;
                }
                catch
                {
                }
            }

            if (indexBuffer != null)
            {
                try
                {
                    indexBuffer.Dispose();
                    GC.SuppressFinalize(indexBuffer);
                    indexBuffer = null;
                }
                catch
                {
                }
            }
        }
コード例 #19
0
        public override void OnCreateVertexBuffer(VertexBuffer11 vb)
        {
            indexBuffer[0] = new IndexBuffer11(typeof(short), subDivisionsX * subDivisionsY * 6, RenderContext11.PrepDevice);

            double lat, lng;

            int index = 0;
            //            double tileDegrees = 360;

            double latMin = 90;
            double latMax = -90;
            double lngMin = -180;
            double lngMax = 180;

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

            double latDegrees = latMax - latMin;
            double lngDegrees = lngMax - lngMin;

            double textureStepX = 1.0f / subDivisionsX;
            double textureStepY = 1.0f / subDivisionsY;

            for (y1 = 0; y1 <= subDivisionsY; y1++)
            {
                if (y1 != subDivisionsY)
                {
                    lat = latMax - (textureStepY * latDegrees * (double)y1);
                }
                else
                {
                    lat = latMin;
                }

                for (x1 = 0; x1 <= subDivisionsX; x1++)
                {
                    if (x1 != subDivisionsX)
                    {
                        lng = lngMin + (textureStepX * lngDegrees * (double)x1);
                    }
                    else
                    {
                        lng = lngMax;
                    }
                    index = y1 * (subDivisionsX + 1) + x1;
                    verts[index].Position = GeoTo3d(lat, lng, false);// Add Altitude mapping here
                    verts[index].Normal   = verts[index].Position;
                    if (domeMaster)
                    {
                        double dist = (90 - lat) / 180;
                        verts[index].Tu = (float)(.5 + Math.Sin((lng + 180) / 180 * Math.PI) * dist);
                        verts[index].Tv = (float)(.5 + Math.Cos((lng + 180) / 180 * Math.PI) * dist);
                    }
                    else
                    {
                        verts[index].Tu = (float)(x1 * textureStepX);
                        verts[index].Tv = (float)(1f - (y1 * textureStepY));
                    }
                }
            }
            vb.Unlock();
            TriangleCount = (subDivisionsX) * (subDivisionsY) * 2;
            short[] indexArray = (short[])this.indexBuffer[0].Lock();

            for (y1 = 0; y1 < subDivisionsY; y1++)
            {
                if (!(domeMaster && y1 < subDivisionsY / 2))
                {
                    for (x1 = 0; x1 < subDivisionsX; x1++)
                    {
                        index = (y1 * subDivisionsX * 6) + 6 * x1;
                        // First triangle in quad
                        indexArray[index]     = (short)(y1 * (subDivisionsX + 1) + x1);
                        indexArray[index + 2] = (short)((y1 + 1) * (subDivisionsX + 1) + x1);
                        indexArray[index + 1] = (short)(y1 * (subDivisionsX + 1) + (x1 + 1));

                        // Second triangle in quad
                        indexArray[index + 3] = (short)(y1 * (subDivisionsX + 1) + (x1 + 1));
                        indexArray[index + 5] = (short)((y1 + 1) * (subDivisionsX + 1) + x1);
                        indexArray[index + 4] = (short)((y1 + 1) * (subDivisionsX + 1) + (x1 + 1));
                    }
                }
            }
            this.indexBuffer[0].Unlock();
        }
コード例 #20
0
        static void InitSphere()
        {
            if (sphereIndexBuffers != null)
            {
                foreach (var indexBuf in sphereIndexBuffers)
                {
                    indexBuf.Dispose();
                    GC.SuppressFinalize(indexBuf);
                }
            }
            if (sphereVertexBuffers != null)
            {
                foreach (var vertBuf in sphereVertexBuffers)
                {
                    vertBuf.Dispose();
                    GC.SuppressFinalize(vertBuf);
                }
            }
            sphereVertexBuffers = new VertexBuffer11[sphereCount];
            sphereIndexBuffers = new IndexBuffer11[sphereCount];

            triangleCountSphere = new int[sphereCount];
            vertexCountSphere = new int[sphereCount];

            var countX = maxSubDivisionsX;
            var countY = maxSubDivisionsY;

            for (var sphereIndex = 0; sphereIndex < sphereCount; sphereIndex++)
            {
                triangleCountSphere[sphereIndex] = countX * countY * 2;
                vertexCountSphere[sphereIndex] = (countX + 1) * (countY + 1);
                sphereVertexBuffers[sphereIndex] = new VertexBuffer11(typeof(PositionNormalTexturedX2), ((countX + 1) * (countY + 1)),RenderContext11.PrepDevice);

                sphereIndexBuffers[sphereIndex] = new IndexBuffer11(typeof(int), countX * countY * 6, RenderContext11.PrepDevice);

                double lat, lng;

                var index = 0;
                double latMin = 90;
                double latMax = -90;
                double lngMin = -180;
                double lngMax = 180;

                // Create a vertex buffer
                var verts = (PositionNormalTexturedX2[])sphereVertexBuffers[sphereIndex].Lock(0, 0); // Lock the buffer (which will return our structs)
                int x1, y1;

                var latDegrees = latMax - latMin;
                var lngDegrees = lngMax - lngMin;

                double textureStepX = 1.0f / countX;
                double textureStepY = 1.0f / countY;
                for (y1 = 0; y1 <= countY; y1++)
                {

                    if (y1 != countY)
                    {
                        lat = latMax - (textureStepY * latDegrees * y1);
                    }
                    else
                    {
                        lat = latMin;
                    }

                    for (x1 = 0; x1 <= countX; x1++)
                    {
                        if (x1 != countX)
                        {
                            lng = lngMin + (textureStepX * lngDegrees * x1);
                        }
                        else
                        {
                            lng = lngMax;
                        }
                        index = y1 * (countX + 1) + x1;
                        verts[index].Position = Coordinates.GeoTo3dDouble(lat, lng);// Add Altitude mapping here
                        verts[index].Normal = verts[index].Position;// with altitude will come normal recomputer from adjacent triangles
                        verts[index].Tu = (float)(x1 * textureStepX);
                        verts[index].Tv = (float)(1f - (y1 * textureStepY));
                    }
                }
                sphereVertexBuffers[sphereIndex].Unlock();
                var indexArray = (int[])sphereIndexBuffers[sphereIndex].Lock();
                for (y1 = 0; y1 < countY; y1++)
                {
                    var bWinding = (y1 % 2) == 0;
                    for (x1 = 0; x1 < countX; x1++)
                    {
                        index = (y1 * countX * 6) + 6 * x1;
                        if (bWinding)
                        {
                            // First triangle in quad
                            indexArray[index] = y1 * (countX + 1) + x1; //A
                            indexArray[index + 2] = y1 * (countX + 1) + (x1 + 1);//B
                            indexArray[index + 1] = (y1 + 1) * (countX + 1) + x1;//C

                            // Second triangle in quad
                            indexArray[index + 3] = y1 * (countX + 1) + (x1 + 1);//B
                            indexArray[index + 5] = (y1 + 1) * (countX + 1) + (x1 + 1); //D
                            indexArray[index + 4] = (y1 + 1) * (countX + 1) + x1;// C
                        }
                        else
                        {
                            // First triangle in quad
                            indexArray[index] = y1 * (countX + 1) + x1; //A
                            indexArray[index + 2] = (y1 + 1) * (countX + 1) + (x1 + 1); //D
                            indexArray[index + 1] = (y1 + 1) * (countX + 1) + x1;//C

                            // Second triangle in quad
                            indexArray[index + 3] = y1 * (countX + 1) + (x1 + 1);//B
                            indexArray[index + 5] = (y1 + 1) * (countX + 1) + (x1 + 1); //D
                            indexArray[index + 4] = y1 * (countX + 1) + x1; //A
                        }
                    }
                }
                sphereIndexBuffers[sphereIndex].Unlock();
                countX /= 2;
                countY /= 2;
            }
        }
コード例 #21
0
 private void createSpriteCornersIndexBuffer(Device device)
 {
     uint[] indices = { 0, 1, 2, 0, 2, 3 };
     indexBuffer = new IndexBuffer11(device, indices);
 }
コード例 #22
0
        private void createIndexBuffer(Device device, int pointCount)
        {
            var indices = new uint[pointCount * 6];
            for (uint i = 0; i < pointCount; ++i)
            {
                indices[i * 6 + 0] = i * 4 + 0;
                indices[i * 6 + 1] = i * 4 + 1;
                indices[i * 6 + 2] = i * 4 + 2;
                indices[i * 6 + 3] = i * 4 + 0;
                indices[i * 6 + 4] = i * 4 + 2;
                indices[i * 6 + 5] = i * 4 + 3;
            }

            indexBuffer = new IndexBuffer11(device, indices);
        }
コード例 #23
0
        public void Draw(RenderContext11 renderContext, int count, Texture11 texture, float opacity, IndexBuffer11 indexBufferIn)
        {
            setupShader(renderContext, texture, opacity);


            count = Math.Min(this.count, count);

            switch (renderStrategy)
            {
            case RenderStrategy.GeometryShader:
                renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.PointList;
                renderContext.SetVertexBuffer(0, vertexBuffer);
                renderContext.SetIndexBuffer(indexBufferIn);
                renderContext.devContext.DrawIndexed(count, 0, 0);
                renderContext.Device.ImmediateContext.GeometryShader.Set(null);
                break;
            }
        }
コード例 #24
0
        public void Draw(RenderContext11 renderContext, int count, Texture11 texture, float opacity, IndexBuffer11 indexBufferIn)
        {
            setupShader(renderContext, texture, opacity);

            count = Math.Min(this.count, count);

            switch (renderStrategy)
            {
                case RenderStrategy.GeometryShader:
                    renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList;
                    renderContext.SetVertexBuffer(0, vertexBuffer);
                    renderContext.SetIndexBuffer(indexBufferIn);
                    renderContext.devContext.DrawIndexed(count, 0, 0);
                    renderContext.Device.ImmediateContext.GeometryShader.Set(null);
                    break;

            }
        }
コード例 #25
0
 public void SetIndexBuffer(IndexBuffer11 indexBuffer)
 {
     if (indexBuffer != null)
     {
         devContext.InputAssembler.SetIndexBuffer(indexBuffer.IndexBuffer, indexBuffer.format, 0);
     }
     else
     {
         devContext.InputAssembler.SetIndexBuffer(null, Format.R32_UInt, 0);
     }
 }
コード例 #26
0
        public override void CleanUpGeometryOnly()
        {
            base.CleanUpGeometryOnly();

            if (vertexBuffer != null)
            {
                vertexBuffer.Dispose();
                GC.SuppressFinalize(vertexBuffer);
                vertexBuffer = null;
            }

            if (indexBuffer != null)
            {
                indexBuffer.Dispose();
                GC.SuppressFinalize(indexBuffer);
                indexBuffer = null;
            }
        }
コード例 #27
0
        public override bool Draw(RenderContext11 renderContext, float opacity, bool flat)
        {
            if (shapefile == null)
            {
                return(false);
            }

            if (shapeFileVertex == null)
            {
                List <Vector3> vertList       = new List <Vector3>();
                List <UInt32>  indexList      = new List <UInt32>();
                UInt32         firstItemIndex = 0;
                Vector3        lastItem       = new Vector3();
                bool           firstItem      = true;



                bool   north            = true;
                double offsetX          = 0;
                double offsetY          = 0;
                double centralMeridian  = 0;
                double mapScale         = 0;
                double standardParallel = 70;

                if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                {
                    north            = shapefile.FileHeader.ProjectionInfo.Name.ToLower().Contains("north");
                    standardParallel = shapefile.FileHeader.ProjectionInfo.GetParameter("standard_parallel_1");
                    centralMeridian  = shapefile.FileHeader.ProjectionInfo.GetParameter("central_meridian");
                    mapScale         = shapefile.FileHeader.ProjectionInfo.GetParameter("scale_factor");
                    offsetY          = shapefile.FileHeader.ProjectionInfo.GetParameter("false_easting");
                    offsetX          = shapefile.FileHeader.ProjectionInfo.GetParameter("false_northing");
                }



                UInt32 currentIndex = 0;
                Color  color        = Color;
                int    count        = 360;
                for (int i = 0; i < shapefile.Shapes.Count; i++)
                {
                    if (shapefile.Shapes[i].GetType() == typeof(Polygon))
                    {
                        Polygon p = (Polygon)shapefile.Shapes[i];

                        for (int z = 0; z < p.Rings.Length; z++)
                        {
                            count = (p.Rings[z].Points.Length);

                            // content from DBF
                            DataRow dr = p.Rings[z].Attributes;

                            for (int k = 0; k < p.Rings[z].Points.Length; k++)
                            {
                                // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used.
                                double Xcoord = p.Rings[z].Points[k].X;
                                double Ycoord = p.Rings[z].Points[k].Y;

                                if (shapefile.Projection == ShapeFile.Projections.Geo)
                                {
                                    lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord);
                                }
                                else if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                                {
                                    lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3;
                                }

                                if (k == 0)
                                {
                                    firstItemIndex = currentIndex;
                                    firstItem      = true;
                                }

                                vertList.Add(lastItem);

                                if (firstItem)
                                {
                                    firstItem = false;
                                }
                                else
                                {
                                    indexList.Add(currentIndex);
                                    currentIndex++;
                                    indexList.Add(currentIndex);
                                }
                            }

                            indexList.Add(currentIndex);
                            indexList.Add(firstItemIndex);
                            currentIndex++;
                        }
                    }
                    else if (shapefile.Shapes[i].GetType() == typeof(PolygonZ))
                    {
                        PolygonZ p = (PolygonZ)shapefile.Shapes[i];

                        for (int z = 0; z < p.Rings.Length; z++)
                        {
                            count = (p.Rings[z].Points.Length);

                            // content from DBF
                            DataRow dr = p.Rings[z].Attributes;

                            for (int k = 0; k < p.Rings[z].Points.Length; k++)
                            {
                                // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used.
                                double Xcoord = p.Rings[z].Points[k].X;
                                double Ycoord = p.Rings[z].Points[k].Y;

                                if (shapefile.Projection == ShapeFile.Projections.Geo)
                                {
                                    lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord);
                                }
                                else if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                                {
                                    lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3;
                                }


                                if (k == 0)
                                {
                                    firstItemIndex = currentIndex;
                                    firstItem      = true;
                                }

                                vertList.Add(lastItem);

                                if (firstItem)
                                {
                                    firstItem = false;
                                }
                                else
                                {
                                    indexList.Add(currentIndex);
                                    currentIndex++;
                                    indexList.Add(currentIndex);
                                }
                            }

                            indexList.Add(currentIndex);
                            indexList.Add(firstItemIndex);
                            currentIndex++;
                        }
                    }
                    else if (shapefile.Shapes[i].GetType() == typeof(PolyLine))
                    {
                        PolyLine p = (PolyLine)shapefile.Shapes[i];
                        for (int z = 0; z < p.Lines.Length; z++)
                        {
                            count = (p.Lines[z].Points.Length);

                            firstItem = true;
                            for (int k = 0; k < p.Lines[z].Points.Length; k++)
                            {
                                // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used.
                                double Xcoord = p.Lines[z].Points[k].X;
                                double Ycoord = p.Lines[z].Points[k].Y;
                                if (shapefile.Projection == ShapeFile.Projections.Geo)
                                {
                                    lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord);
                                }
                                else if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                                {
                                    lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3;
                                }

                                if (k == 0)
                                {
                                    firstItemIndex = currentIndex;
                                    firstItem      = true;
                                }

                                vertList.Add(lastItem);

                                if (firstItem)
                                {
                                    firstItem = false;
                                }
                                else
                                {
                                    indexList.Add(currentIndex);
                                    currentIndex++;
                                    indexList.Add(currentIndex);
                                }
                            }
                            currentIndex++;
                        }
                    }
                    else if (shapefile.Shapes[i].GetType() == typeof(PolyLineZ))
                    {
                        PolyLineZ p = (PolyLineZ)shapefile.Shapes[i];
                        for (int z = 0; z < p.Lines.Length; z++)
                        {
                            count = (p.Lines[z].Points.Length);
                            Vector3[] points = new Vector3[(count)];

                            firstItem = true;
                            for (int k = 0; k < p.Lines[z].Points.Length; k++)
                            {
                                // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used.
                                double Xcoord = p.Lines[z].Points[k].X;
                                double Ycoord = p.Lines[z].Points[k].Y;
                                if (shapefile.Projection == ShapeFile.Projections.Geo)
                                {
                                    lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord);
                                }
                                else if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                                {
                                    lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3;
                                }

                                if (k == 0)
                                {
                                    firstItemIndex = currentIndex;
                                    firstItem      = true;
                                }

                                vertList.Add(lastItem);

                                if (firstItem)
                                {
                                    firstItem = false;
                                }
                                else
                                {
                                    indexList.Add(currentIndex);
                                    currentIndex++;
                                    indexList.Add(currentIndex);
                                }
                            }
                            currentIndex++;
                        }
                    }
                    else if (shapefile.Shapes[i].GetType() == typeof(ShapefileTools.Point))
                    {
                        ShapefileTools.Point p = (ShapefileTools.Point)shapefile.Shapes[i];

                        // 2D Point coordinates. 3d also supported which would add a Z. There's also an optional measure (M) that can be used.
                        double Xcoord = p.X;
                        double Ycoord = p.Y;
                        if (shapefile.Projection == ShapeFile.Projections.Geo)
                        {
                            lastItem = Coordinates.GeoTo3d(Ycoord, Xcoord);
                        }
                        else if (shapefile.Projection == ShapeFile.Projections.PolarStereo)
                        {
                            lastItem = Coordinates.SterographicTo3d(Xcoord, Ycoord, 1, standardParallel, centralMeridian, offsetX, offsetY, mapScale, north).Vector3;
                        }

                        vertList.Add(lastItem);

                        currentIndex++;
                        lines = false;
                    }
                }

                shapeVertexCount = vertList.Count;
                shapeFileVertex  = new PositionVertexBuffer11(vertList.Count, RenderContext11.PrepDevice);

                Vector3[] verts   = (Vector3[])shapeFileVertex.Lock(0, 0); // Lock the buffer (which will return our structs)
                int       indexer = 0;
                foreach (Vector3 vert in vertList)
                {
                    verts[indexer++] = vert;
                }
                shapeFileVertex.Unlock();


                shapeIndexCount = indexList.Count;

                if (lines)
                {
                    if (indexList.Count > 65500)
                    {
                        isLongIndex    = true;
                        shapeFileIndex = new IndexBuffer11(typeof(UInt32), indexList.Count, RenderContext11.PrepDevice);
                    }
                    else
                    {
                        isLongIndex    = false;
                        shapeFileIndex = new IndexBuffer11(typeof(short), indexList.Count, RenderContext11.PrepDevice);
                    }

                    if (isLongIndex)
                    {
                        indexer = 0;
                        UInt32[] indexes = (UInt32[])shapeFileIndex.Lock();
                        foreach (UInt32 indexVal in indexList)
                        {
                            indexes[indexer++] = indexVal;
                        }
                        shapeFileIndex.Unlock();
                    }
                    else
                    {
                        indexer = 0;
                        short[] indexes = (short[])shapeFileIndex.Lock();
                        foreach (UInt32 indexVal in indexList)
                        {
                            indexes[indexer++] = (short)indexVal;
                        }
                        shapeFileIndex.Unlock();
                    }
                }
            }


            renderContext.DepthStencilMode = DepthStencilMode.Off;
            renderContext.BlendMode        = BlendMode.Alpha;
            SimpleLineShader11.Color       = Color.FromArgb((int)(opacity * 255), Color);

            SharpDX.Matrix mat = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
            mat.Transpose();

            SimpleLineShader11.WVPMatrix      = mat;
            SimpleLineShader11.CameraPosition = Vector3d.TransformCoordinate(renderContext.CameraPosition, Matrix3d.Invert(renderContext.World)).Vector3;
            SimpleLineShader11.ShowFarSide    = false;
            SimpleLineShader11.Sky            = false;

            renderContext.SetVertexBuffer(shapeFileVertex);
            SimpleLineShader11.Use(renderContext.devContext);

            if (lines)
            {
                renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.LineList;
                renderContext.SetIndexBuffer(shapeFileIndex);
                renderContext.devContext.DrawIndexed(shapeFileIndex.Count, 0, 0);
            }
            else
            {
                renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.PointList;
                renderContext.devContext.Draw(shapeVertexCount, 0);
            }

            renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;

            return(true);
        }
コード例 #28
0
        public void Dispose()
        {
            if (vertexBuffer != null)
            {
                vertexBuffer.Dispose();
                GC.SuppressFinalize(vertexBuffer);
                vertexBuffer = null;
            }

            if (tangentVertexBuffer != null)
            {
                tangentVertexBuffer.Dispose();
                GC.SuppressFinalize(tangentVertexBuffer);
                tangentVertexBuffer = null;
            }

            if (indexBuffer != null)
            {
                indexBuffer.Dispose();
                GC.SuppressFinalize(indexBuffer);
                indexBuffer = null;
            }
        }
コード例 #29
0
        public override bool CreateGeometry(RenderContext11 renderContext, bool uiThread)
        {
            if (texture == null || (Volitile && !ReadyToRender))
            {
                GetParameters();
                if (ImageData != null)
                {
                    try
                    {
                        MemoryStream ms = new MemoryStream(ImageData);

                        Texture11 old = this.texture;

                        texture = Texture11.FromStream(RenderContext11.PrepDevice, ms);

                        ReadyToRender = true;
                        if (old != null)
                        {
                            old.Dispose();
                            GC.SuppressFinalize(old);
                        }

                        if (Width == 0 && Height == 0)
                        {
                            Width  = texture.Width;
                            Height = texture.Height;
                            if (dataset.WcsImage != null)
                            {
                                if (dataset.WcsImage.SizeX != 0)
                                {
                                    Width = dataset.WcsImage.SizeX;
                                }
                                if (dataset.WcsImage.SizeY != 0)
                                {
                                    Height = dataset.WcsImage.SizeY;
                                }
                            }
                        }
                        ms.Dispose();
                        ImageData = null;
                    }
                    catch
                    {
                        return(false);
                    }
                }

                if (TextureReady)
                {
                    if (dataset.WcsImage != null)
                    {
                        if (dataset.WcsImage is FitsImage)
                        {
                            SetTexture(dataset.WcsImage.GetBitmap());
                            ReadyToRender = true;
                        }
                    }
                }
                if (this.texture == null)
                {
                    if (dataset.WcsImage != null)
                    {
                        if (dataset.WcsImage is FitsImage)
                        {
                            SetTexture(dataset.WcsImage.GetBitmap());
                            ReadyToRender = true;
                        }
                    }

                    if (TextureReady)
                    {
                        paintColor = Color.White;
                        if (dataset.WcsImage != null)
                        {
                            paintColor = dataset.WcsImage.Color;
                            blend      = !dataset.WcsImage.ColorCombine;
                        }


                        if (string.IsNullOrEmpty(FileName))
                        {
                            texture       = Texture11.FromBitmap(RenderContext11.PrepDevice, Image);
                            ReadyToRender = true;
                        }
                        else
                        {
                            try
                            {
                                texture       = Texture11.FromFile(RenderContext11.PrepDevice, FileName);
                                ReadyToRender = true;


                                ReadyToRender = true;
                                if (Width == 0 && Height == 0)
                                {
                                    Width  = texture.Width;
                                    Height = texture.Height;
                                    if (dataset.WcsImage != null)
                                    {
                                        if (dataset.WcsImage.SizeX != 0)
                                        {
                                            Width = dataset.WcsImage.SizeX;
                                        }
                                        if (dataset.WcsImage.SizeY != 0)
                                        {
                                            Height = dataset.WcsImage.SizeY;
                                        }
                                    }
                                }
                            }
                            catch
                            {
                                try
                                {
                                    //texture = Texture.FromBitmap(prepDevice, bmp, Usage.AutoGenerateMipMap, Tile.PoolToUse);

                                    texture       = Texture11.FromFile(RenderContext11.PrepDevice, FileName);
                                    ReadyToRender = true;
                                    Width         = texture.Width;
                                    Height        = texture.Height;
                                    if (dataset.WcsImage.SizeX != 0)
                                    {
                                        Width = dataset.WcsImage.SizeX;
                                    }
                                    if (dataset.WcsImage.SizeY != 0)
                                    {
                                        Height = dataset.WcsImage.SizeY;
                                    }
                                }
                                catch
                                {
                                    errored = true;
                                }
                            }
                        }
                    }
                }
            }

            if (vertexBuffer == null)
            {
                GetParameters();
                vertexBuffer = new VertexBuffer11(typeof(PositionNormalTexturedX2), 4, RenderContext11.PrepDevice);
                indexBuffer  = new IndexBuffer11(typeof(short), 6, RenderContext11.PrepDevice);
                this.OnCreateVertexBuffer(vertexBuffer);
            }



            return(true);
        }
コード例 #30
0
        void CreateDomeFaceVertexBuffer(int face)
        {
            int domeSubX = 50;
            int domeSubY = 50;

            CleanupDomeVertexBuffer(face);

            double fea = Math.Min(250, Properties.Settings.Default.FisheyeAngle) / 180;
            double fa = Math.Min(250, Properties.Settings.Default.FisheyeAngle);

            domeIndexBuffer[face] = new IndexBuffer11(typeof(short), (domeSubX * domeSubY * 6), RenderContext11.PrepDevice);
            domeVertexBuffer[face] = new PositionColorTexturedVertexBuffer11(((domeSubX + 1) * (domeSubY + 1)), RenderContext11.PrepDevice);

            domeVertexCount = domeSubX * domeSubY * 6;


            int index = 0;

            PositionColorTexturedVertexBuffer11 vb = domeVertexBuffer[face];

            PositionColoredTextured[] verts = (PositionColoredTextured[])vb.Lock(0, 0);
            int x1, y1;



            Vector3d topLeft = new Vector3d();
            Vector3d topRight = new Vector3d();
            Vector3d bottomLeft = new Vector3d();
            Vector3d bottomRight = new Vector3d();

            RenderTypes faceType = (RenderTypes)face;

            switch (faceType)
            {
                case RenderTypes.DomeFront:
                    topLeft = new Vector3d(-1, 1, 1);
                    topRight = new Vector3d(1, 1, 1);
                    bottomLeft = new Vector3d(-1, -1, 1);
                    bottomRight = new Vector3d(1, -1, 1);
                    break;
                case RenderTypes.DomeRight:
                    topLeft = new Vector3d(1, 1, 1);
                    topRight = new Vector3d(1, 1, -1);
                    bottomLeft = new Vector3d(1, -1, 1);
                    bottomRight = new Vector3d(1, -1, -1);
                    break;
                case RenderTypes.DomeUp:
                    topLeft = new Vector3d(-1, 1, -1);
                    topRight = new Vector3d(1, 1, -1);
                    bottomLeft = new Vector3d(-1, 1, 1);
                    bottomRight = new Vector3d(1, 1, 1);
                    break;
                case RenderTypes.DomeLeft:
                    topLeft = new Vector3d(-1, 1, -1);
                    topRight = new Vector3d(-1, 1, 1);
                    bottomLeft = new Vector3d(-1, -1, -1);
                    bottomRight = new Vector3d(-1, -1, 1);
                    break;
                case RenderTypes.DomeBack:
                    topLeft = new Vector3d(1, 1, -1);
                    topRight = new Vector3d(-1, 1, -1);
                    bottomLeft = new Vector3d(1, -1, -1);
                    bottomRight = new Vector3d(-1, -1, -1);
                    break;
            }

            double textureStepX = 1.0f / domeSubX;
            double textureStepY = 1.0f / domeSubY;
            for (y1 = 0; y1 <= domeSubY; y1++)
            {
                double tv;
                if (y1 != domeSubY)
                {
                    tv = textureStepY * y1;
                }
                else
                {
                    tv = 1;
                }

                for (x1 = 0; x1 <= domeSubX; x1++)
                {
                    double tu;
                    if (x1 != domeSubX)
                    {
                        tu = textureStepX * x1;
                    }
                    else
                    {
                        tu = 1;
                    }

                    Vector3d top = Vector3d.Lerp(topLeft, topRight, tu);
                    Vector3d bottom = Vector3d.Lerp(bottomLeft, bottomRight, tu);
                    Vector3d net = Vector3d.Lerp(top, bottom, tv);
                    net.Normalize();
                    Coordinates netNet = Coordinates.CartesianToSpherical2(net.Vector3);
                    double dist = (180 - (netNet.Lat + 90)) / (180 * fea);
                    dist = Math.Min(.5, dist);

                    double x = Math.Sin((netNet.Lng + 90) / 180 * Math.PI) * dist;
                    double y = Math.Cos((netNet.Lng + 90) / 180 * Math.PI) * dist;

                    index = y1 * (domeSubX + 1) + x1;
                    verts[index].Position = new SharpDX.Vector4((float)x, (float)y, .9f, 1);
                    verts[index].Tu = (float)tu;
                    verts[index].Tv = (float)tv;
                    verts[index].Color = Color.White;
                }
            }
            vb.Unlock();
            domeTriangleCount = (domeSubX) * (domeSubY) * 2;
            short[] indexArray = (short[])domeIndexBuffer[face].Lock();
            index = 0;
            for (y1 = 0; y1 < domeSubY; y1++)
            {
                for (x1 = 0; x1 < domeSubX; x1++)
                {
                    //index = (y1 * domeSubX * 6) + 6 * x1;
                    // First triangle in quad
                    indexArray[index] = (short)(y1 * (domeSubX + 1) + x1);
                    indexArray[index + 1] = (short)((y1 + 1) * (domeSubX + 1) + x1);
                    indexArray[index + 2] = (short)(y1 * (domeSubX + 1) + (x1 + 1));

                    // Second triangle in quad
                    indexArray[index + 3] = (short)(y1 * (domeSubX + 1) + (x1 + 1));
                    indexArray[index + 4] = (short)((y1 + 1) * (domeSubX + 1) + x1);
                    indexArray[index + 5] = (short)((y1 + 1) * (domeSubX + 1) + (x1 + 1));
                    index += 6;
                }
            }
            this.domeIndexBuffer[face].Unlock();
        }
コード例 #31
0
 private void createSpriteCornersIndexBuffer(SharpDX.Direct3D11.Device device)
 {
     uint[] indices = { 0, 1, 2, 0, 2, 3 };
     indexBuffer = new IndexBuffer11(device, indices);
 }
コード例 #32
0
        public override void OnCreateVertexBuffer(VertexBuffer11 vb)
        {
            for (int i = 0; i < 4; i++)
            {
                indexBuffer[i] = new IndexBuffer11(typeof(short), ((SubDivisions / 2) * (SubDivisions / 2) * 6), RenderContext11.PrepDevice);
            }
            try
            {
                if (!topDown)
                {
                    OnCreateVertexBufferBottomsUp(vb);
                    return;
                }
                double lat, lng;

                int    index       = 0;
                double tileDegrees = this.dataset.BaseTileDegrees / (Math.Pow(2, this.level));

                double latMin       = (90 - (((double)this.y) * tileDegrees));
                double latMax       = (90 - (((double)(this.y + 1)) * tileDegrees));
                double lngMin       = (((double)this.x * tileDegrees) - 180.0);
                double lngMax       = ((((double)(this.x + 1)) * tileDegrees) - 180.0);
                double tileDegreesX = lngMax - lngMin;
                double tileDegreesY = latMax - latMin;

                //bugbug altitude broken
                TopLeft     = GeoTo3dWithAltitude(latMin, lngMin, false);
                BottomRight = GeoTo3dWithAltitude(latMax, lngMax, false);
                TopRight    = GeoTo3dWithAltitude(latMin, lngMax, false);
                BottomLeft  = GeoTo3dWithAltitude(latMax, lngMin, false);



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

                float textureStep = 1.0f / SubDivisions;
                for (y = 0; y <= SubDivisions; y++)
                {
                    if (y != SubDivisions)
                    {
                        lat = latMin + (textureStep * tileDegreesY * y);
                    }
                    else
                    {
                        lat = latMax;
                    }
                    for (x = 0; x <= SubDivisions; x++)
                    {
                        if (x != SubDivisions)
                        {
                            lng = lngMin + (textureStep * tileDegreesX * x);
                        }
                        else
                        {
                            lng = lngMax;
                        }
                        index = y * (SubDivisions + 1) + x;
                        verts[index].Position = GeoTo3dWithAltitude(lat, lng, true);// Add Altitude mapping here
                        verts[index].Normal   = GeoTo3d(lat, lng, false);
                        verts[index].Tu       = x * textureStep;
                        verts[index].Tv       = y * textureStep;
                        verts[index].Lat      = lat;
                        verts[index].Lng      = lng;
                    }
                }
                vb.Unlock();
                TriangleCount = (SubDivisions) * (SubDivisions) * 2;

                int quarterDivisions = SubDivisions / 2;
                int part          = 0;
                for (int y2 = 0; y2 < 2; y2++)
                {
                    for (int x2 = 0; x2 < 2; x2++)
                    {
                        short[] indexArray = (short[])this.indexBuffer[part].Lock();
                        index = 0;
                        for (int y1 = (quarterDivisions * y2); y1 < (quarterDivisions * (y2 + 1)); y1++)
                        {
                            for (int x1 = (quarterDivisions * x2); x1 < (quarterDivisions * (x2 + 1)); x1++)
                            {
                                //index = ((y1 * quarterDivisions * 6) + 6 * x1);
                                // First triangle in quad
                                indexArray[index]     = (short)(y1 * (SubDivisions + 1) + x1);
                                indexArray[index + 1] = (short)((y1 + 1) * (SubDivisions + 1) + x1);
                                indexArray[index + 2] = (short)(y1 * (SubDivisions + 1) + (x1 + 1));

                                // Second triangle in quad
                                indexArray[index + 3] = (short)(y1 * (SubDivisions + 1) + (x1 + 1));
                                indexArray[index + 4] = (short)((y1 + 1) * (SubDivisions + 1) + x1);
                                indexArray[index + 5] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1));
                                index += 6;
                            }
                        }
                        this.indexBuffer[part].Unlock();
                        part++;
                    }
                }
            }
            catch
            {
            }
        }
コード例 #33
0
        public static void ReturnShortIndexBuffer(IndexBuffer11 buff)
        {
            if (buff == null)
            {
                return;
            }
            //old code to dispose buffers
            buff.Dispose();
            GC.SuppressFinalize(buff);

            //todo11 reenable buffer pooling
            //int count = buff.Count;
            //if (!IndexPools.ContainsKey(count))
            //{
            //    IndexPools.Add(count, new Buffers(count));
            //}

            //IndexPools[count].Entries.Push(buff);
        }
コード例 #34
0
        public override void CleanUp()
        {
            CleanAndReady = false;

            if (shapeFileIndex != null)
            {
                shapeFileIndex.Dispose();
                GC.SuppressFinalize(shapeFileIndex);
                shapeFileIndex = null;
            }
            if (shapeFileVertex != null)
            {
                shapeFileVertex.Dispose();
                GC.SuppressFinalize(shapeFileVertex);

                shapeFileVertex = null;
            }

            if (lineList != null)
            {
                lineList.Clear();
            }
            if (lineList2d != null)
            {
                lineList2d.Clear();
            }

            if (triangleList2d != null)
            {
                triangleList2d.Clear();
            }

            if (triangleList != null)
            {
                triangleList.Clear();
            }
            if (textBatch != null)
            {
                textBatch.CleanUp();
            }
        }
コード例 #35
0
        static MercatorTile()
        {
            sharredIndexBuffer = new IndexBuffer11[4, 16];
            for (int i = 0; i < 4; i++)
            {
                for (int a = 0; a < 16; a++)
                {
                    sharredIndexBuffer[i, a] = new IndexBuffer11(typeof(short), ((SubDivisions / 2) * (SubDivisions / 2) * 6), RenderContext11.PrepDevice);
                }
            }

            for (int a = 0; a < 16; a++)
            {
                int  index            = 0;
                bool flipFlop         = false;
                int  quarterDivisions = SubDivisions / 2;
                int  part             = 0;
                for (int y2 = 0; y2 < 2; y2++)
                {
                    for (int x2 = 0; x2 < 2; x2++)
                    {
                        short[] indexArray = (short[])sharredIndexBuffer[part, a].Lock();
                        index = 0;
                        for (int y1 = (quarterDivisions * y2); y1 < (quarterDivisions * (y2 + 1)); y1++)
                        {
                            for (int x1 = (quarterDivisions * x2); x1 < (quarterDivisions * (x2 + 1)); x1++)
                            {
                                if (flipFlop)
                                {
                                    //index = ((y1 * quarterDivisions * 6) + 6 * x1);
                                    // First triangle in quad
                                    indexArray[index]     = (short)(y1 * (SubDivisions + 1) + x1);
                                    indexArray[index + 2] = (short)((y1 + 1) * (SubDivisions + 1) + x1);
                                    indexArray[index + 1] = (short)(y1 * (SubDivisions + 1) + (x1 + 1));

                                    // Second triangle in quad
                                    indexArray[index + 3] = (short)(y1 * (SubDivisions + 1) + (x1 + 1));
                                    indexArray[index + 5] = (short)((y1 + 1) * (SubDivisions + 1) + x1);
                                    indexArray[index + 4] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1));
                                    index += 6;
                                }
                                else
                                {
                                    //index = ((y1 * quarterDivisions * 6) + 6 * x1);
                                    // First triangle in quad
                                    indexArray[index]     = (short)(y1 * (SubDivisions + 1) + x1);
                                    indexArray[index + 2] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1));
                                    indexArray[index + 1] = (short)(y1 * (SubDivisions + 1) + (x1 + 1));

                                    // Second triangle in quad
                                    indexArray[index + 3] = (short)(y1 * (SubDivisions + 1) + (x1));
                                    indexArray[index + 5] = (short)((y1 + 1) * (SubDivisions + 1) + x1);
                                    indexArray[index + 4] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1));
                                    index += 6;
                                }
                                flipFlop = !flipFlop;
                            }
                            flipFlop = !flipFlop;
                        }
                        ProcessAccomindations(indexArray, a);


                        sharredIndexBuffer[part, a].Unlock();
                        part++;
                    }
                }
            }
        }
コード例 #36
0
        //[LayerProperty]
        //public override Color Color
        //{
        //    get
        //    {
        //        return base.Color;
        //    }
        //    set
        //    {
        //        base.Color = value;
        //        CleanUp();
        //    }
        //}
        public override void CleanUp()
        {
            if (shapeFileIndex != null)
            {
                shapeFileIndex.Dispose();
                GC.SuppressFinalize(shapeFileIndex);
                shapeFileIndex = null;
            }
            if (shapeFileVertex != null)
            {
                shapeFileVertex.Dispose();
                GC.SuppressFinalize(shapeFileVertex);

                shapeFileVertex = null;
            }
        }
コード例 #37
0
        public override void OnCreateVertexBuffer(VertexBuffer11 vb)
        {
            for (int i = 0; i < 4; i++)
            {
                indexBuffer[i] = new IndexBuffer11(typeof(short), ((SubDivisions / 2) * (SubDivisions / 2) * 6), RenderContext11.PrepDevice);
            }
            try
            {
                if (!topDown)
                {
                    OnCreateVertexBufferBottomsUp(vb);
                    return;
                }
                double lat, lng;

                int index = 0;
                float tileDegrees = (float)this.dataset.BaseTileDegrees / ((float)Math.Pow(2, this.level));

                float latMin = (float)(((double)this.dataset.BaseTileDegrees / 2.0 - (((double)this.y) * tileDegrees)) + this.dataset.OffsetY);
                float latMax = (float)(((double)this.dataset.BaseTileDegrees / 2.0 - (((double)(this.y + 1)) * tileDegrees)) + this.dataset.OffsetY);
                float lngMin = (float)((((double)this.x * tileDegrees) - (float)this.dataset.BaseTileDegrees / dataset.WidthFactor) + this.dataset.OffsetX);
                float lngMax = (float)(((((double)(this.x + 1)) * tileDegrees) - (float)this.dataset.BaseTileDegrees / dataset.WidthFactor) + this.dataset.OffsetX);
                float tileDegreesX = lngMax - lngMin;
                float tileDegreesY = latMax - latMin;

                TopLeft = GeoTo3d(latMin, lngMin, false);
                BottomRight = GeoTo3d(latMax, lngMax, false);
                TopRight = GeoTo3d(latMin, lngMax, false);
                BottomLeft = GeoTo3d(latMax, lngMin, false);

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

                float textureStep = 1.0f / SubDivisions;
                for (y = 0; y <= SubDivisions; y++)
                {
                    if (y != SubDivisions)
                    {
                        lat = latMin + (textureStep * tileDegreesY * y);
                    }
                    else
                    {
                        lat = latMax;
                    }
                    for (x = 0; x <= SubDivisions; x++)
                    {

                        if (x != SubDivisions)
                        {
                            lng = lngMin + (textureStep * tileDegreesX * x);
                        }
                        else
                        {
                            lng = lngMax;
                        }
                        index = y * (SubDivisions + 1) + x;
                        verts[index].Position = GeoTo3d(lat, lng, true);
                        verts[index].Normal = GeoTo3d(lat, lng, false);
                        verts[index].Tu = x * textureStep +.002f;
                        verts[index].Tv = y * textureStep +.002f;

                    }
                }

                vb.Unlock();
                TriangleCount = (SubDivisions) * (SubDivisions) * 2;

                int quarterDivisions = SubDivisions / 2;
                int part = 0;
                for (int y2 = 0; y2 < 2; y2++)
                {
                    for (int x2 = 0; x2 < 2; x2++)
                    {
                        short[] indexArray = (short[])this.indexBuffer[part].Lock();
                        index = 0;
                        for (int y1 = (quarterDivisions * y2); y1 < (quarterDivisions * (y2 + 1)); y1++)
                        {
                            for (int x1 = (quarterDivisions * x2); x1 < (quarterDivisions * (x2 + 1)); x1++)
                            {
                                //index = ((y1 * quarterDivisions * 6) + 6 * x1);
                                // First triangle in quad
                                indexArray[index] = (short)(y1 * (SubDivisions + 1) + x1);
                                indexArray[index + 2] = (short)((y1 + 1) * (SubDivisions + 1) + x1);
                                indexArray[index + 1] = (short)(y1 * (SubDivisions + 1) + (x1 + 1));

                                // Second triangle in quad
                                indexArray[index + 3] = (short)(y1 * (SubDivisions + 1) + (x1 + 1));
                                indexArray[index + 5] = (short)((y1 + 1) * (SubDivisions + 1) + x1);
                                indexArray[index + 4] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1));
                                index += 6;
                            }
                        }
                        this.indexBuffer[part].Unlock();
                        part++;
                    }
                }
            }
            catch
            {
            }
        }
コード例 #38
0
        public override void OnCreateVertexBuffer(VertexBuffer11 vb)
        {
            indexBuffer[0] = new IndexBuffer11(typeof(short), subDivisionsX * subDivisionsY * 6, RenderContext11.PrepDevice);

            double lat, lng;

            int index = 0;
            //            double tileDegrees = 360;

            double latMin = 90;
            double latMax = -90;
            double lngMin = -180;
            double lngMax = 180;

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

            double latDegrees = latMax - latMin;
            double lngDegrees = lngMax - lngMin;

            double textureStepX = 1.0f / subDivisionsX;
            double textureStepY = 1.0f / subDivisionsY;
            for (y1 = 0; y1 <= subDivisionsY; y1++)
            {

                if (y1 != subDivisionsY)
                {
                    lat = latMax - (textureStepY * latDegrees * (double)y1);
                }
                else
                {
                    lat = latMin;
                }

                for (x1 = 0; x1 <= subDivisionsX; x1++)
                {
                    if (x1 != subDivisionsX)
                    {
                        lng = lngMin + (textureStepX * lngDegrees * (double)x1);
                    }
                    else
                    {
                        lng = lngMax;
                    }
                    index = y1 * (subDivisionsX + 1) + x1;
                    verts[index].Position = GeoTo3d(lat, lng, false);// Add Altitude mapping here
                    verts[index].Normal = verts[index].Position;
                    if (domeMaster)
                    {
                        double dist = (90-lat) / 180;
                        verts[index].Tu = (float)(.5 +Math.Sin((lng+180)/180*Math.PI)*dist);
                        verts[index].Tv = (float)(.5 + Math.Cos((lng+180) / 180 * Math.PI) * dist);
                    }
                    else
                    {
                        verts[index].Tu = (float)(x1 * textureStepX);
                        verts[index].Tv = (float)(1f - (y1 * textureStepY));
                    }
                }
            }
            vb.Unlock();
            TriangleCount = (subDivisionsX) * (subDivisionsY) * 2;
            short[] indexArray = (short[])this.indexBuffer[0].Lock();

            for (y1 = 0; y1 < subDivisionsY; y1++)
            {
                if (!(domeMaster && y1 < subDivisionsY / 2))
                {
                    for (x1 = 0; x1 < subDivisionsX; x1++)
                    {
                        index = (y1 * subDivisionsX * 6) + 6 * x1;
                        // First triangle in quad
                        indexArray[index] = (short)(y1 * (subDivisionsX + 1) + x1);
                        indexArray[index + 2] = (short)((y1 + 1) * (subDivisionsX + 1) + x1);
                        indexArray[index + 1] = (short)(y1 * (subDivisionsX + 1) + (x1 + 1));

                        // Second triangle in quad
                        indexArray[index + 3] = (short)(y1 * (subDivisionsX + 1) + (x1 + 1));
                        indexArray[index + 5] = (short)((y1 + 1) * (subDivisionsX + 1) + x1);
                        indexArray[index + 4] = (short)((y1 + 1) * (subDivisionsX + 1) + (x1 + 1));
                    }
                }
            }
            this.indexBuffer[0].Unlock();
        }
コード例 #39
0
        public override bool CreateGeometry(RenderContext11 renderContext, bool uiThread)
        {
            if (texture == null || (Volitile && !ReadyToRender))
            {
                GetParameters();
                if ( ImageData != null)
                {
                    try
                    {
                        var ms = new MemoryStream(ImageData);

                        var old = texture;

                        texture = Texture11.FromStream(RenderContext11.PrepDevice, ms);

                        ReadyToRender = true;
                        if (old != null)
                        {
                            old.Dispose();
                            GC.SuppressFinalize(old);
                        }

                        if (Width == 0 && Height == 0)
                        {
                            Width = texture.Width;
                            Height = texture.Height;
                            if (dataset.WcsImage != null)
                            {
                                if (dataset.WcsImage.SizeX != 0)
                                {
                                    Width = dataset.WcsImage.SizeX;
                                }
                                if (dataset.WcsImage.SizeY != 0)
                                {
                                    Height = dataset.WcsImage.SizeY;
                                }

                            }
                        }
                        ms.Dispose();
                        ImageData = null;

                    }
                    catch
                    {
                        return false;
                    }
                }

                if (TextureReady)
                {
                    if (dataset.WcsImage != null)
                    {
                        if (dataset.WcsImage is FitsImage)
                        {
                            SetTexture(dataset.WcsImage.GetBitmap());
                            ReadyToRender = true;
                        }
                    }
                }
                if (texture == null)
                {
                        if (dataset.WcsImage != null)
                        {
                            if (dataset.WcsImage is FitsImage)
                            {
                                SetTexture(dataset.WcsImage.GetBitmap());
                                ReadyToRender = true;
                            }
                        }

                    if (TextureReady)
                    {
                        paintColor = Color.White;
                        if (dataset.WcsImage != null)
                        {
                            paintColor = dataset.WcsImage.Color;
                            blend = !dataset.WcsImage.ColorCombine;
                        }

                        if (string.IsNullOrEmpty(FileName))
                        {
                            texture = Texture11.FromBitmap(RenderContext11.PrepDevice, Image);
                            ReadyToRender = true;
                        }
                        else
                        {

                            try
                            {
                                texture = Texture11.FromFile(RenderContext11.PrepDevice, FileName);
                                ReadyToRender = true;

                                ReadyToRender = true;
                                if (Width == 0 && Height == 0)
                                {
                                    Width = texture.Width;
                                    Height = texture.Height;
                                    if (dataset.WcsImage != null)
                                    {
                                        if (dataset.WcsImage.SizeX != 0)
                                        {
                                            Width = dataset.WcsImage.SizeX;
                                        }
                                        if (dataset.WcsImage.SizeY != 0)
                                        {
                                            Height = dataset.WcsImage.SizeY;
                                        }

                                    }
                                }
                            }
                            catch
                            {
                                try
                                {
                                    //texture = Texture.FromBitmap(prepDevice, bmp, Usage.AutoGenerateMipMap, Tile.PoolToUse);

                                    texture = Texture11.FromFile(RenderContext11.PrepDevice, FileName);
                                    ReadyToRender = true;
                                    Width = texture.Width;
                                    Height = texture.Height;
                                    if (dataset.WcsImage.SizeX != 0)
                                    {
                                        Width = dataset.WcsImage.SizeX;
                                    }
                                    if (dataset.WcsImage.SizeY != 0)
                                    {
                                        Height = dataset.WcsImage.SizeY;
                                    }
                                }
                                catch
                                {
                                    errored = true;
                                }
                            }

                        }
                    }
                }

            }

            if (vertexBuffer == null)
            {
                GetParameters();
                vertexBuffer = new VertexBuffer11(typeof(PositionNormalTexturedX2), 4, RenderContext11.PrepDevice);
                indexBuffer = new IndexBuffer11(typeof(short), 6, RenderContext11.PrepDevice);
                OnCreateVertexBuffer(vertexBuffer);

            }

            return true;
        }
コード例 #40
0
        static MercatorTile()
        {
            sharredIndexBuffer = new IndexBuffer11[4, 16];
            for (var i = 0; i < 4; i++)
            {
                for (var a = 0; a < 16; a++)
                {
                    sharredIndexBuffer[i, a] = new IndexBuffer11(typeof(short), ((SubDivisions / 2) * (SubDivisions / 2) * 6), RenderContext11.PrepDevice);
                }
            }

            for (var a = 0; a < 16; a++)
            {

                var index = 0;
                var flipFlop = false;
                var quarterDivisions = SubDivisions / 2;
                var part = 0;
                for (var y2 = 0; y2 < 2; y2++)
                {
                    for (var x2 = 0; x2 < 2; x2++)
                    {
                        var indexArray = (short[])sharredIndexBuffer[part, a].Lock();
                        index = 0;
                        for (var y1 = (quarterDivisions * y2); y1 < (quarterDivisions * (y2 + 1)); y1++)
                        {
                            for (var x1 = (quarterDivisions * x2); x1 < (quarterDivisions * (x2 + 1)); x1++)
                            {
                                if (flipFlop)
                                {
                                    //index = ((y1 * quarterDivisions * 6) + 6 * x1);
                                    // First triangle in quad
                                    indexArray[index] = (short)(y1 * (SubDivisions + 1) + x1);
                                    indexArray[index + 2] = (short)((y1 + 1) * (SubDivisions + 1) + x1);
                                    indexArray[index + 1] = (short)(y1 * (SubDivisions + 1) + (x1 + 1));

                                    // Second triangle in quad
                                    indexArray[index + 3] = (short)(y1 * (SubDivisions + 1) + (x1 + 1));
                                    indexArray[index + 5] = (short)((y1 + 1) * (SubDivisions + 1) + x1);
                                    indexArray[index + 4] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1));
                                    index += 6;
                                }
                                else
                                {
                                    //index = ((y1 * quarterDivisions * 6) + 6 * x1);
                                    // First triangle in quad
                                    indexArray[index] = (short)(y1 * (SubDivisions + 1) + x1);
                                    indexArray[index + 2] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1));
                                    indexArray[index + 1] = (short)(y1 * (SubDivisions + 1) + (x1 + 1));

                                    // Second triangle in quad
                                    indexArray[index + 3] = (short)(y1 * (SubDivisions + 1) + (x1));
                                    indexArray[index + 5] = (short)((y1 + 1) * (SubDivisions + 1) + x1);
                                    indexArray[index + 4] = (short)((y1 + 1) * (SubDivisions + 1) + (x1 + 1));
                                    index += 6;
                                }
                                flipFlop = !flipFlop;
                            }
                            flipFlop = !flipFlop;

                        }
                        ProcessAccomindations(indexArray, a);

                        sharredIndexBuffer[part,a].Unlock();
                        part++;
                    }
                }
            }
        }
コード例 #41
0
        public void Dispose()
        {
            if (vertexBuffer != null)
            {
                vertexBuffer.Dispose();
                GC.SuppressFinalize(vertexBuffer);
                vertexBuffer = null;
            }

            if (fallbackVertexBuffer != null)
            {
                fallbackVertexBuffer.Dispose();
                GC.SuppressFinalize(fallbackVertexBuffer);
                fallbackVertexBuffer = null;
            }

            if (spriteCornerVertexBuffer != null)
            {
                spriteCornerVertexBuffer.Dispose();
                GC.SuppressFinalize(spriteCornerVertexBuffer);
                spriteCornerVertexBuffer = null;
            }

            if (indexBuffer != null)
            {
                indexBuffer.Dispose();
                GC.SuppressFinalize(indexBuffer);
                indexBuffer = null;
            }
        }