internal static Image <T>[] GenerateMipmaps <T>(Image <T> baseImage) where T : struct, IPixel <T> { uint mipLevelCount = MipmapHelper.ComputeMipLevels((uint)baseImage.Width, (uint)baseImage.Height); Image <T>[] mipLevels = new Image <T> [mipLevelCount]; mipLevels[0] = baseImage; int i = 1; int currentWidth = baseImage.Width; int currentHeight = baseImage.Height; while (currentWidth != 1 || currentHeight != 1) { int newWidth = Math.Max(1, currentWidth / 2); int newHeight = Math.Max(1, currentHeight / 2); Image <T> newImage = baseImage.Clone(context => context.Resize(newWidth, newHeight, KnownResamplers.Lanczos3)); Debug.Assert(i < mipLevelCount); mipLevels[i] = newImage; i++; currentWidth = newWidth; currentHeight = newHeight; } Debug.Assert(i == mipLevelCount); return(mipLevels); }
public ImageSharpTexture(Image <Rgba32> image, bool mipmap, bool srgb) { VkFormat = srgb ? VkFormat.R8G8B8A8SRgb : VkFormat.R8G8B8A8UNorm; if (mipmap) { Images = MipmapHelper.GenerateMipmaps(image); } else { Images = new Image <Rgba32>[] { image }; } }
public ImageSharpCubemapTexture( Image <Rgba32> positiveX, Image <Rgba32> negativeX, Image <Rgba32> positiveY, Image <Rgba32> negativeY, Image <Rgba32> positiveZ, Image <Rgba32> negativeZ, bool mipmap = true) { CubemapTextures = new Image <Rgba32> [6][]; if (mipmap) { CubemapTextures[0] = MipmapHelper.GenerateMipmaps(positiveX); CubemapTextures[1] = MipmapHelper.GenerateMipmaps(negativeX); CubemapTextures[2] = MipmapHelper.GenerateMipmaps(positiveY); CubemapTextures[3] = MipmapHelper.GenerateMipmaps(negativeY); CubemapTextures[4] = MipmapHelper.GenerateMipmaps(positiveZ); CubemapTextures[5] = MipmapHelper.GenerateMipmaps(negativeZ); } else { CubemapTextures[0] = new Image <Rgba32>[1] { positiveX }; CubemapTextures[1] = new Image <Rgba32>[1] { negativeX }; CubemapTextures[2] = new Image <Rgba32>[1] { positiveY }; CubemapTextures[3] = new Image <Rgba32>[1] { negativeY }; CubemapTextures[4] = new Image <Rgba32>[1] { positiveZ }; CubemapTextures[5] = new Image <Rgba32>[1] { negativeZ }; } }