示例#1
0
        /// <summary>
        ///     Computes the expected texture size in bytes.
        /// </summary>
        /// <param name="width">Texture width in pixels. Must be power of 2.</param>
        /// <param name="height">Texture height in pixels. Must be power of 2.</param>
        /// <param name="format"></param>
        /// <param name="mimpaps">Whether the texture has mipmaps.</param>
        /// <returns></returns>
        public static long ComputeTextureSize(int width, int height,
                                              TextureCompressionFormat format = TextureCompressionFormat.Uncompressed, bool mimpaps = true)
        {
            if (format != TextureCompressionFormat.Uncompressed && format != TextureCompressionFormat.UncompressedWithAlpha)
            {
                throw new NotImplementedException("Only uncompressed textures are supported at this time.");
            }

            if (!MathUtils.IsPowerOfTwo(width) || !MathUtils.IsPowerOfTwo(height))
            {
                throw new Exception("Image dimensions must by power of 2");
            }

            int  bpp  = format.BitsPerPixel();
            long size = 0;

            while (true)
            {
                size += width * height * bpp;

                if (width == 1 && height == 1)
                {
                    return(size / 8);
                }

                width  = MathUtils.Clamp(width >> 1, 1);
                height = MathUtils.Clamp(height >> 1, 1);
            }
        }
示例#2
0
        public static long ComputeMipmapSize(int width, int height, int mipLevel,
                                             TextureCompressionFormat format = TextureCompressionFormat.Uncompressed)
        {
            if (format != TextureCompressionFormat.Uncompressed && format != TextureCompressionFormat.UncompressedWithAlpha)
            {
                throw new NotImplementedException("Only uncompressed textures are supported at this time.");
            }

            ComputeMipmapDimensions(width, height, mipLevel, out int mipWidth, out int mipHeight);
            return(mipWidth * mipHeight * format.BitsPerPixel());
        }