Exemplo n.º 1
0
 /// <summary>
 /// Returns whether the given <see cref="TextureImageFormat"/> is color-renderable.
 /// </summary>
 public static bool IsImageFormatColorRenderable(TextureImageFormat imageFormat)
 {
     return(imageFormat == TextureImageFormat.Color4b ||
            (imageFormat >= TextureImageFormat.Float && imageFormat <= TextureImageFormat.Float4) ||
            (imageFormat >= TextureImageFormat.Int && imageFormat <= TextureImageFormat.Int4) ||
            (imageFormat >= TextureImageFormat.UnsignedInt && imageFormat <= TextureImageFormat.UnsignedInt4));
 }
Exemplo n.º 2
0
        public TextureInfo ConstructTextureWithGpxTrack(TileRange tiles, BoundingBox bbox, string fileName,
                                                        TextureImageFormat mimeType, IEnumerable <GeoPoint> gpxPoints, bool drawGpxVertices = false, Rgba32 color = default(Rgba32), float lineWidth = 5f)
        {
            // where is the bbox in the final image ?

            // get pixel in full map
            int zoomLevel     = tiles.Tiles.First().TileInfo.Zoom;
            var projectedBbox = ConvertWorldToMap(bbox, zoomLevel, tiles.TileSize);
            var tilesBbox     = GetTilesBoundingBox(tiles);
            int xOffset       = (int)(tilesBbox.xMin - projectedBbox.xMin);
            int yOffset       = (int)(tilesBbox.yMin - projectedBbox.yMin);


            //DrawDebugBmpBbox(tiles, localBbox, tilesBbox, fileName, mimeType);
            int tileSize = tiles.TileSize;

            var pointsOnTexture = gpxPoints
                                  .Select(pt => TileUtils.PositionToGlobalPixel(new LatLong(pt.Latitude, pt.Longitude), zoomLevel, tiles.TileSize))
                                  .Select(pt => new PointF((float)(pt.X - (int)projectedBbox.xMin), (float)(pt.Y - (int)projectedBbox.yMin)));


            using (Image <Rgba32> outputImage = new Image <Rgba32>((int)projectedBbox.Width, (int)projectedBbox.Height))
            {
                foreach (var tile in tiles.Tiles)
                {
                    using (Image <Rgba32> tileImg = Image.Load(tile.Image))
                    {
                        int x = (tile.TileInfo.X - tiles.Start.X) * tileSize + xOffset;
                        int y = (tile.TileInfo.Y - tiles.Start.Y) * tileSize + yOffset;

                        outputImage.Mutate(o => o
                                           .DrawImage(tileImg, new Point(x, y), 1f)
                                           );
                    }
                }

                outputImage.Mutate(o => o
                                   .DrawLines(color == default(Rgba32) ? new Rgba32(1, 0, 0, 1f) : color, lineWidth, pointsOnTexture.ToArray())
                                   );

                if (drawGpxVertices)
                {
                    PathCollection pc = new PathCollection(pointsOnTexture.Select(p => new EllipsePolygon(p, new SizeF(10f, 10f))));
                    outputImage.Mutate(o => o.Draw(GraphicsOptions.Default, Pens.Solid(Rgba32.Violet, 3), pc));
                }

                // with encoder
                //IImageEncoder encoder = ConvertFormat(mimeType);
                //outputImage.Save(fileName, encoder);

                outputImage.Save(fileName);
            }

            return(new TextureInfo(fileName, mimeType, (int)projectedBbox.Width, (int)projectedBbox.Height, zoomLevel,
                                   projectedBbox));
        }
Exemplo n.º 3
0
 public TextureInfo(string filePath, TextureImageFormat imageFormat, int width, int height, int zoom = 0, BoundingBox projectedBounds = null)
 {
     this.FilePath        = filePath;
     this.FileName        = Path.GetFileName(filePath);
     this.ImageFormat     = imageFormat;
     this.Width           = width;
     this.Height          = height;
     this.ProjectedZoom   = zoom;
     this.ProjectedBounds = projectedBounds;
 }
Exemplo n.º 4
0
        public TextureInfo ConstructTexture(TileRange tiles, BoundingBox bbox, string fileName,
                                            TextureImageFormat mimeType)
        {
            // where is the bbox in the final image ?

            // get pixel in full map
            int zoomLevel     = tiles.Tiles.First().TileInfo.Zoom;
            var projectedBbox = ConvertWorldToMap(bbox, zoomLevel);
            var tilesBbox     = GetTilesBoundingBox(tiles);

            //DrawDebugBmpBbox(tiles, localBbox, tilesBbox, fileName, mimeType);
            int tileSize = tiles.TileSize;

            using (Image <Rgba32> outputImage = new Image <Rgba32>((int)projectedBbox.Width, (int)projectedBbox.Height))
            {
                int xOffset = (int)(tilesBbox.xMin - projectedBbox.xMin);
                int yOffset = (int)(tilesBbox.yMin - projectedBbox.yMin);

                foreach (var tile in tiles.Tiles)
                {
                    try
                    {
                        int x = (tile.TileInfo.X - tiles.Start.X) * tileSize + xOffset;
                        int y = (tile.TileInfo.Y - tiles.Start.Y) * tileSize + yOffset;

                        if (x >= projectedBbox.Width || y >= projectedBbox.Height)
                        {
                            continue;
                        }

                        using (Image <Rgba32> tileImg = Image.Load(tile.Image))
                        {
                            outputImage.Mutate(o => o
                                               .DrawImage(tileImg, new Point(x, y), 1f)
                                               );
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"Error while generating texture: {ex.Message}");
                    }
                }

                // with encoder
                //IImageEncoder encoder = ConvertFormat(mimeType);
                //outputImage.Save(fileName, encoder);

                outputImage.Save(fileName);
            }

            return(new TextureInfo(fileName, mimeType, (int)projectedBbox.Width, (int)projectedBbox.Height, zoomLevel,
                                   projectedBbox, tiles.Count));
            //return new TextureInfo(fileName, format, (int)tilesBbox.Width, (int)tilesBbox.Height);
        }
Exemplo n.º 5
0
        public void GivenTheTextureResourceContainsASecondImageFormatListCompressionTypeIsAndAlphaChannelIs(string textureName, string p1, bool p2)
        {
            TextureResource t1 = ScenarioContext.Current.Get<TextureResource>(textureName);

            TextureImageFormat f1 = new TextureImageFormat();
            f1.Type = (CompressionType)Enum.Parse(typeof(CompressionType), p1, true);
            f1.AlphaChannel = p2;

            t1.TexureImageFormatList.Add(f1);
            ScenarioContext.Current.Set<TextureImageFormat>(f1);
        }
Exemplo n.º 6
0
        public void GivenTheTextureResourceContainsAnImageFormatListCompressionTypeIsAndBleuGreenAndRedChannelIs(string textureName, string p1, bool p2, bool p3, bool p4)
        {
            TextureResource t1 = ScenarioContext.Current.Get<TextureResource>(textureName);

            TextureImageFormat f1 = new TextureImageFormat();
            f1.Type = (CompressionType)Enum.Parse(typeof(CompressionType), p1, true);
            f1.BlueChannel = p2;
            f1.GreenChannel = p3;
            f1.RedChannel = p4;

            t1.TexureImageFormatList.Add(f1);
            ScenarioContext.Current.Set<TextureImageFormat>(f1);
        }
Exemplo n.º 7
0
        private IImageEncoder ConvertFormat(TextureImageFormat format)
        {
            ImageFormatManager imageFormatManager = new ImageFormatManager();
            IImageFormat       imageFormat        = null;

            if (format == TextureImageFormat.image_jpeg)
            {
                imageFormat = imageFormatManager.FindFormatByFileExtension(".jpg");
            }
            else
            {
                imageFormat = imageFormatManager.FindFormatByFileExtension(".png");
            }

            return(imageFormatManager.FindEncoder(imageFormat));
        }
Exemplo n.º 8
0
 /// <summary>
 /// Gets the default <see cref="PixelFormat"/> for get texture data operations for the specified <see cref="TextureImageFormat"/>.
 /// </summary>
 public static PixelFormat GetDefaultGetDataFormat(TextureImageFormat format)
 {
     if (IsImageFormatColorRenderable(format))
     {
         return(PixelFormat.Rgba);
     }
     else if (IsImageFormatDepthOnly(format))
     {
         return(PixelFormat.DepthComponent);
     }
     else if (IsImageFormatDepthStencil(format))
     {
         return(PixelFormat.DepthStencil);
     }
     else if (IsImageFormatStencilOnly(format))
     {
         return(PixelFormat.StencilIndex);
     }
     throw new ArgumentException("The given " + nameof(TextureImageFormat) + " isn't valid");
 }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a <see cref="Texture"/> with specified <see cref="TextureType"/> and <see cref="TextureImageFormat"/>.
        /// </summary>
        /// <param name="graphicsDevice">The <see cref="GraphicsDevice"/> this resource will use.</param>
        /// <param name="type">The type of texture (or texture target) the texture will be.</param>
        /// <param name="imageFormat">The type of image format this texture will store.</param>
        internal Texture(GraphicsDevice graphicsDevice, TextureType type, TextureImageFormat imageFormat) : base(graphicsDevice)
        {
            if (!Enum.IsDefined(typeof(TextureType), type))
            {
                throw new FormatException("Invalid texture target");
            }

            if (!Enum.IsDefined(typeof(TextureImageFormat), imageFormat))
            {
                throw new FormatException("Invalid texture image format");
            }

            TextureType = type;
            ImageFormat = imageFormat;
            TrippyUtils.GetTextureFormatEnums(imageFormat, out PixelInternalFormat, out PixelType, out PixelFormat);
            lastBindUnit     = 0;
            IsMipmapped      = false;
            isNotMipmappable = !TrippyUtils.IsTextureTypeMipmappable(type);
            Handle           = GL.GenTexture();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates a <see cref="TextureCubemap"/> with the desired parameters but no image data.
        /// </summary>
        /// <param name="graphicsDevice">The <see cref="GraphicsDevice"/> this resource will use.</param>
        /// <param name="size">The size (width and height) of the cubemap's faces.</param>
        /// <param name="imageFormat">The image format for this <see cref="TextureCubemap"/>.</param>
        public TextureCubemap(GraphicsDevice graphicsDevice, uint size, TextureImageFormat imageFormat = TextureImageFormat.Color4b)
            : base(graphicsDevice, TextureType.TextureCubeMap, imageFormat)
        {
            ValidateTextureSize(size);
            Size = size;
            GraphicsDevice.BindTextureSetActive(this);
            GL.TexParameter((TextureTarget)TextureType, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter((TextureTarget)TextureType, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter((TextureTarget)TextureType, TextureParameterName.TextureWrapR, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter((TextureTarget)TextureType, TextureParameterName.TextureMinFilter, (int)DefaultMinFilter);
            GL.TexParameter((TextureTarget)TextureType, TextureParameterName.TextureMagFilter, (int)DefaultMagFilter);

            unsafe
            {
                GL.TexImage2D(TextureTarget.TextureCubeMapPositiveX, 0, (int)PixelInternalFormat, size, size, 0, PixelFormat, PixelType, (void *)0);
                GL.TexImage2D(TextureTarget.TextureCubeMapNegativeX, 0, (int)PixelInternalFormat, size, size, 0, PixelFormat, PixelType, (void *)0);
                GL.TexImage2D(TextureTarget.TextureCubeMapPositiveY, 0, (int)PixelInternalFormat, size, size, 0, PixelFormat, PixelType, (void *)0);
                GL.TexImage2D(TextureTarget.TextureCubeMapNegativeY, 0, (int)PixelInternalFormat, size, size, 0, PixelFormat, PixelType, (void *)0);
                GL.TexImage2D(TextureTarget.TextureCubeMapPositiveZ, 0, (int)PixelInternalFormat, size, size, 0, PixelFormat, PixelType, (void *)0);
                GL.TexImage2D(TextureTarget.TextureCubeMapNegativeZ, 0, (int)PixelInternalFormat, size, size, 0, PixelFormat, PixelType, (void *)0);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Creates a <see cref="Texture2D"/> with the desired parameters but no image data.
        /// </summary>
        /// <param name="graphicsDevice">The <see cref="GraphicsDevice"/> this resource will use.</param>
        /// <param name="width">The width of the <see cref="Texture2D"/>.</param>
        /// <param name="height">The height of the <see cref="Texture2D"/>.</param>
        /// <param name="generateMipmaps">Whether to generate mipmaps for this <see cref="Texture2D"/>.</param>
        /// <param name="samples">The amount of samples for this <see cref="Texture2D"/>. Default is 0.</param>
        /// <param name="imageFormat">The image format for this <see cref="Texture2D"/>.</param>
        public Texture2D(GraphicsDevice graphicsDevice, uint width, uint height, bool generateMipmaps = false, uint samples = 0, TextureImageFormat imageFormat = TextureImageFormat.Color4b)
            : base(graphicsDevice, samples == 0 ? TextureType.Texture2D : TextureType.Texture2DMultisample, samples, imageFormat)
        {
            RecreateImage(width, height); //This also binds the texture

            if (generateMipmaps)
            {
                GenerateMipmaps();
            }

            if (Samples == 0)
            {
                GL.TexParameter((TextureTarget)TextureType, TextureParameterName.TextureMinFilter, IsMipmapped ? (int)DefaultMipmapMinFilter : (int)DefaultMinFilter);
                GL.TexParameter((TextureTarget)TextureType, TextureParameterName.TextureMagFilter, (int)DefaultMagFilter);
            }
        }
Exemplo n.º 12
0
        public TextureInfo ConstructTextureWithGpxTrack(TileRange tiles, BoundingBox bbox, string fileName, TextureImageFormat mimeType, IEnumerable <GeoPoint> gpxPoints)
        {
            // where is the bbox in the final image ?

            // get pixel in full map
            int zoomLevel     = tiles.First().TileInfo.Zoom;
            var projectedBbox = ConvertWorldToMap(bbox, zoomLevel);
            var tilesBbox     = GetTilesBoundingBox(tiles);
            int xOffset       = (int)(tilesBbox.xMin - projectedBbox.xMin);
            int yOffset       = (int)(tilesBbox.yMin - projectedBbox.yMin);


            //DrawDebugBmpBbox(tiles, localBbox, tilesBbox, fileName, mimeType);
            int tileSize = tiles.Provider.TileSize;

            var pointsOnTexture = gpxPoints.Select(pt => TileUtils.LatLongToPixelXY(pt.Latitude, pt.Longitude, zoomLevel))
                                  .Select(pt => new PointF(pt.X - (int)projectedBbox.xMin, pt.Y - (int)projectedBbox.yMin));

#if NETFULL
            ImageFormat format = mimeType == TextureImageFormat.image_jpeg ?
                                 ImageFormat.Jpeg
                 : ImageFormat.Png;

            using (Bitmap bmp = new Bitmap((int)projectedBbox.Width, (int)projectedBbox.Height))
            {
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    foreach (var tile in tiles)
                    {
                        using (MemoryStream stream = new MemoryStream(tile.Image))
                        {
                            using (Image tileImg = Image.FromStream(stream))
                            {
                                int x = (tile.TileInfo.X - tiles.Start.X) * tileSize + xOffset;
                                int y = (tile.TileInfo.Y - tiles.Start.Y) * tileSize + yOffset;
                                g.DrawImage(tileImg, x, y);
                            }
                        }
                    }
                }
                bmp.Save(fileName, format);
            }
            throw new NotImplementedException("GPX drawing not implemented yet in .Net Full");
#else
            using (Image <Rgba32> outputImage = new Image <Rgba32>((int)projectedBbox.Width, (int)projectedBbox.Height))
            {
                foreach (var tile in tiles)
                {
                    using (Image <Rgba32> tileImg = Image.Load(tile.Image))
                    {
                        int x = (tile.TileInfo.X - tiles.Start.X) * tileSize + xOffset;
                        int y = (tile.TileInfo.Y - tiles.Start.Y) * tileSize + yOffset;

                        outputImage.Mutate(o => o
                                           .DrawImage(tileImg, new Point(x, y), 1f)
                                           );
                    }
                }

                outputImage.Mutate(o => o
                                   .DrawLines(new Rgba32(1, 0, 0, 1f), 5f, pointsOnTexture.ToArray())
                                   );
                // with encoder
                //IImageEncoder encoder = ConvertFormat(mimeType);
                //outputImage.Save(fileName, encoder);

                outputImage.Save(fileName);
            }
#endif
            return(new TextureInfo(fileName, mimeType, (int)projectedBbox.Width, (int)projectedBbox.Height, zoomLevel, projectedBbox));
            //return new TextureInfo(fileName, format, (int)tilesBbox.Width, (int)tilesBbox.Height);
        }
Exemplo n.º 13
0
        public TextureInfo ConstructTexture(TileRange tiles, BoundingBox bbox, string fileName, TextureImageFormat mimeType)
        {
            // where is the bbox in the final image ?

            // get pixel in full map
            int zoomLevel     = tiles.First().TileInfo.Zoom;
            var projectedBbox = ConvertWorldToMap(bbox, zoomLevel);
            var tilesBbox     = GetTilesBoundingBox(tiles);

            //DrawDebugBmpBbox(tiles, localBbox, tilesBbox, fileName, mimeType);
            int tileSize = tiles.Provider.TileSize;

#if NETFULL
            ImageFormat format = mimeType == TextureImageFormat.image_jpeg ?
                                 ImageFormat.Jpeg
                 : ImageFormat.Png;

            using (Bitmap bmp = new Bitmap((int)projectedBbox.Width, (int)projectedBbox.Height))
            {
                int xOffset = (int)(tilesBbox.xMin - projectedBbox.xMin);
                int yOffset = (int)(tilesBbox.yMin - projectedBbox.yMin);
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    foreach (var tile in tiles)
                    {
                        using (MemoryStream stream = new MemoryStream(tile.Image))
                        {
                            using (Image tileImg = Image.FromStream(stream))
                            {
                                int x = (tile.TileInfo.X - tiles.Start.X) * tileSize + xOffset;
                                int y = (tile.TileInfo.Y - tiles.Start.Y) * tileSize + yOffset;
                                g.DrawImage(tileImg, x, y);
                            }
                        }
                    }
                }
                bmp.Save(fileName, format);
            }
#else
            using (Image <Rgba32> outputImage = new Image <Rgba32>((int)projectedBbox.Width, (int)projectedBbox.Height))
            {
                int xOffset = (int)(tilesBbox.xMin - projectedBbox.xMin);
                int yOffset = (int)(tilesBbox.yMin - projectedBbox.yMin);

                foreach (var tile in tiles)
                {
                    using (Image <Rgba32> tileImg = Image.Load(tile.Image))
                    {
                        int x = (tile.TileInfo.X - tiles.Start.X) * tileSize + xOffset;
                        int y = (tile.TileInfo.Y - tiles.Start.Y) * tileSize + yOffset;

                        outputImage.Mutate(o => o
                                           .DrawImage(tileImg, new Point(x, y), 1f)
                                           );
                    }
                }

                // with encoder
                //IImageEncoder encoder = ConvertFormat(mimeType);
                //outputImage.Save(fileName, encoder);

                outputImage.Save(fileName);
            }
#endif
            return(new TextureInfo(fileName, mimeType, (int)projectedBbox.Width, (int)projectedBbox.Height, zoomLevel, projectedBbox));
            //return new TextureInfo(fileName, format, (int)tilesBbox.Width, (int)tilesBbox.Height);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Creates a <see cref="Texture1D"/> with the desired parameters.
        /// </summary>
        /// <param name="graphicsDevice">The <see cref="GraphicsDevice"/> this resource will use.</param>
        /// <param name="width">The size of the <see cref="Texture1D"/>.</param>
        /// <param name="generateMipmaps">Whether to generate mipmaps for this <see cref="Texture1D"/>.</param>
        /// <param name="imageFormat">The image format for this <see cref="Texture1D"/>.</param>
        public Texture1D(GraphicsDevice graphicsDevice, uint width, bool generateMipmaps = false, TextureImageFormat imageFormat = TextureImageFormat.Color4b)
            : base(graphicsDevice, TextureType.Texture1D, imageFormat)
        {
            RecreateImage(width);

            if (generateMipmaps)
            {
                GenerateMipmaps();
            }

            GL.TexParameter((TextureTarget)TextureType, TextureParameterName.TextureMinFilter, IsMipmapped ? (int)DefaultMipmapMinFilter : (int)DefaultMinFilter);
            GL.TexParameter((TextureTarget)TextureType, TextureParameterName.TextureMagFilter, (int)DefaultMagFilter);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Turns a value from the <see cref="TextureImageFormat"/> enum into the necessary
        /// enums to create a <see cref="Texture"/>'s image/storage.
        /// </summary>
        /// <param name="imageFormat">The requested image format.</param>
        /// <param name="pixelInternalFormat">The pixel's internal format.</param>
        /// <param name="pixelType">The pixel's type.</param>
        /// <param name="pixelFormat">The pixel's format.</param>
        public static void GetTextureFormatEnums(TextureImageFormat imageFormat, out InternalFormat pixelInternalFormat, out PixelType pixelType, out PixelFormat pixelFormat)
        {
            // The workings of this function are related to the numbers assigned to each enum value
            int b = (int)imageFormat / 32;

            switch (b)
            {
            case 0:
                #region UnsignedByteTypes
                pixelType = PixelType.UnsignedByte;
                switch ((int)imageFormat - b * 32)
                {
                case 5:
                    pixelInternalFormat = InternalFormat.Rgba8;
                    pixelFormat         = PixelFormat.Rgba;
                    return;
                }
                break;

                #endregion
            case 1:
                #region FloatTypes
                pixelType = PixelType.Float;
                switch ((int)imageFormat - b * 32)
                {
                case 1:
                    pixelInternalFormat = InternalFormat.R32f;
                    pixelFormat         = PixelFormat.Red;
                    return;

                case 2:
                    pixelInternalFormat = InternalFormat.RG32f;
                    pixelFormat         = PixelFormat.RG;
                    return;

                case 3:
                    pixelInternalFormat = InternalFormat.Rgb32f;
                    pixelFormat         = PixelFormat.Rgb;
                    return;

                case 4:
                    pixelInternalFormat = InternalFormat.Rgba32f;
                    pixelFormat         = PixelFormat.Rgba;
                    return;

                case 5:
                    pixelInternalFormat = InternalFormat.DepthComponent16;
                    pixelFormat         = PixelFormat.DepthComponent;
                    return;

                case 6:
                    pixelInternalFormat = InternalFormat.DepthComponent24Arb;
                    pixelFormat         = PixelFormat.DepthComponent;
                    return;

                case 7:
                    pixelInternalFormat = InternalFormat.DepthComponent32f;
                    pixelFormat         = PixelFormat.DepthComponent;
                    return;
                }
                break;

                #endregion
            case 2:
                #region IntTypes
                pixelType = PixelType.Int;
                switch ((int)imageFormat - b * 32)
                {
                case 1:
                    pixelInternalFormat = InternalFormat.R32i;
                    pixelFormat         = PixelFormat.RgbaInteger;
                    return;

                case 2:
                    pixelInternalFormat = InternalFormat.RG32i;
                    pixelFormat         = PixelFormat.RgbaInteger;
                    return;

                case 3:
                    pixelInternalFormat = InternalFormat.Rgb32i;
                    pixelFormat         = PixelFormat.RgbaInteger;
                    return;

                case 4:
                    pixelInternalFormat = InternalFormat.Rgba32i;
                    pixelFormat         = PixelFormat.RgbaInteger;
                    return;
                }
                break;

                #endregion
            case 3:
                #region UnsignedIntTypes
                pixelType = PixelType.UnsignedInt;
                switch ((int)imageFormat - b * 32)
                {
                case 1:
                    pixelInternalFormat = InternalFormat.R32ui;
                    pixelFormat         = PixelFormat.RedInteger;
                    return;

                case 2:
                    pixelInternalFormat = InternalFormat.RG32ui;
                    pixelFormat         = PixelFormat.RGInteger;
                    return;

                case 3:
                    pixelInternalFormat = InternalFormat.Rgb32ui;
                    pixelFormat         = PixelFormat.RgbInteger;
                    return;

                case 4:
                    pixelInternalFormat = InternalFormat.Rgba32ui;
                    pixelFormat         = PixelFormat.RgbaInteger;
                    return;
                }
                break;

                #endregion
            case 4:
                #region Depth24Stencil8
                switch ((int)imageFormat - b * 32)
                {
                case 1:
                    pixelType           = (PixelType)GLEnum.UnsignedInt248;
                    pixelInternalFormat = InternalFormat.Depth24Stencil8;
                    pixelFormat         = PixelFormat.DepthStencil;
                    return;
                }
                break;
                #endregion
            }

            throw new ArgumentException("Image format is not a valid TextureImageFormat value", nameof(imageFormat));
        }
Exemplo n.º 16
0
 /// <summary>
 /// Returns whether the given <see cref="TextureImageFormat"/> represents a format with integer base type.
 /// </summary>
 public static bool IsImageFormatIntegerType(TextureImageFormat imageFormat)
 {
     return((imageFormat >= TextureImageFormat.Int && imageFormat <= TextureImageFormat.Int4) ||
            (imageFormat >= TextureImageFormat.UnsignedInt && imageFormat <= TextureImageFormat.UnsignedInt4));
 }
Exemplo n.º 17
0
        public TextureInfo ConstructTexture(TileRange tiles, BoundingBox bbox, string fileName,
                                            TextureImageFormat mimeType, float quality = 0.98f)
        {
            // where is the bbox in the final image ?

            // get pixel in full map
            int zoomLevel     = tiles.Tiles.First().TileInfo.Zoom;
            var projectedBbox = ConvertWorldToMap(bbox, zoomLevel, tiles.TileSize);
            var tilesBbox     = GetTilesBoundingBox(tiles);

            //DrawDebugBmpBbox(tiles, localBbox, tilesBbox, fileName, mimeType);
            int tileSize = tiles.TileSize;

            using (Image <Rgba32> outputImage = new Image <Rgba32>((int)Math.Ceiling(projectedBbox.Width), (int)Math.Ceiling(projectedBbox.Height)))
            {
                int xOffset = (int)(tilesBbox.xMin - projectedBbox.xMin);
                int yOffset = (int)(tilesBbox.yMin - projectedBbox.yMin);

                foreach (var tile in tiles.Tiles)
                {
                    try
                    {
                        int x = (tile.TileInfo.X - tiles.Start.X) * tileSize + xOffset;
                        int y = (tile.TileInfo.Y - tiles.Start.Y) * tileSize + yOffset;

                        if (x >= projectedBbox.Width || y >= projectedBbox.Height)
                        {
                            continue;
                        }

                        if (tile.Image.Length == 0)
                        {
                            _logger.LogWarning($"Tile {tile.Uri} is empty. Skipping.");
                            continue;
                        }
                        using (Image <Rgba32> tileImg = Image.Load(tile.Image))
                        {
                            outputImage.Mutate(o => o
                                               .DrawImage(tileImg, new Point(x, y), 1f)
                                               );
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"Error while generating texture: {ex.Message}");
                    }
                }

                // with encoder
                //IImageEncoder encoder = ConvertFormat(mimeType);
                //outputImage.Save(fileName, encoder);

                // Make image power of two dimensions
                if (options.PowerOfTwoImages)
                {
                    int nearestPowerOf2 = ToNextNearestPowerOf2(Math.Max(outputImage.Width, outputImage.Height));
                    outputImage.Mutate(o => o.Resize(nearestPowerOf2, nearestPowerOf2));
                }

                SaveImage(outputImage, fileName, quality);
            }

            return(new TextureInfo(fileName, mimeType, (int)Math.Ceiling(projectedBbox.Width), (int)Math.Ceiling(projectedBbox.Height), zoomLevel,
                                   projectedBbox, tiles.Count));
        }
Exemplo n.º 18
0
 /// <summary>
 /// Returns whether the given <see cref="TextureImageFormat"/> represents a depth-only format.
 /// </summary>
 public static bool IsImageFormatDepthOnly(TextureImageFormat imageFormat)
 {
     return(imageFormat >= TextureImageFormat.Depth16 && imageFormat <= TextureImageFormat.Depth32f);
 }
Exemplo n.º 19
0
        public Texture2DArray(GraphicsDevice graphicsDevice, uint width, uint height, uint depth, uint samples = 0, TextureImageFormat imageFormat = TextureImageFormat.Color4b)
            : base(graphicsDevice, samples == 0 ? TextureTarget.Texture2DArray : TextureTarget.Texture2DMultisampleArray, samples, imageFormat)
        {
            RecreateImage(width, height, depth); //this also binds the texture

            if (samples == 0)
            {
                GL.TexParameter(TextureType, TextureParameterName.TextureMinFilter, (int)DefaultMinFilter);
                GL.TexParameter(TextureType, TextureParameterName.TextureMagFilter, (int)DefaultMagFilter);
            }
        }
Exemplo n.º 20
0
#pragma warning disable IDE0060 // Remove unused parameter
#pragma warning disable CA1801
        /// <summary>
        /// Returns whether the given <see cref="TextureImageFormat"/> represents a stencil-only format.
        /// </summary>
        public static bool IsImageFormatStencilOnly(TextureImageFormat imageFormat)
        {
            return(false); //there are no stencil-only image formats haha yes
        }
Exemplo n.º 21
0
#pragma warning restore IDE0060 // Remove unused parameter
#pragma warning restore CA1801

        /// <summary>
        /// Returns whether the given <see cref="TextureImageFormat"/> represents a depth-stencil format.
        /// </summary>
        public static bool IsImageFormatDepthStencil(TextureImageFormat imageFormat)
        {
            return(imageFormat == TextureImageFormat.Depth24Stencil8);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Gets the default valid <see cref="FramebufferAttachmentPoint"/> for a <see cref="TextureImageFormat"/>
        /// (depth/stencil/depthstencil/color0).
        /// </summary>
        public static FramebufferAttachmentPoint GetCorrespondingTextureFramebufferAttachmentPoint(TextureImageFormat format)
        {
            if (IsImageFormatColorRenderable(format))
            {
                return(FramebufferAttachmentPoint.Color0);
            }
            if (IsImageFormatDepthOnly(format))
            {
                return(FramebufferAttachmentPoint.Depth);
            }
            if (IsImageFormatDepthStencil(format))
            {
                return(FramebufferAttachmentPoint.DepthStencil);
            }
            if (IsImageFormatStencilOnly(format))
            {
                return(FramebufferAttachmentPoint.Stencil);
            }

            throw new ArgumentException("Given " + nameof(TextureImageFormat) + " has no default valid " + nameof(FramebufferAttachmentPoint));
        }
Exemplo n.º 23
0
 internal TextureMultisamplable(GraphicsDevice graphicsDevice, TextureTarget type, uint samples, TextureImageFormat imageFormat)
     : base(graphicsDevice, type, imageFormat)
 {
     ValidateSampleCount(samples);
     Samples = samples;
 }