public static GLTextureCubeArray FromDDS(DDS dds) { int size = (int)dds.Width; GLTextureCubeArray texture = new GLTextureCubeArray(); texture.Width = size; texture.Height = size; texture.Bind(); var format = dds.Platform.OutputFormat; var surfaces = dds.GetSurfaces(); List <byte[]> cubemapSurfaces = new List <byte[]>(); for (int a = 0; a < surfaces.Count; a++) { cubemapSurfaces.Add(surfaces[a].mipmaps[0]); } int depth = surfaces.Count; Console.WriteLine($"depth {depth}"); byte[] buffer = ByteUtils.CombineArray(cubemapSurfaces.ToArray()); for (int j = 0; j < dds.MipCount; j++) { int mipWidth = CalculateMipDimension(texture.Width, j); int mipHeight = CalculateMipDimension(texture.Height, j); if (dds.IsBCNCompressed()) { var internalFormat = GLFormatHelper.ConvertCompressedFormat(format, true); GLTextureDataLoader.LoadCompressedImage(texture.Target, mipWidth, mipHeight, depth, internalFormat, buffer, j); } else { var formatInfo = GLFormatHelper.ConvertPixelFormat(format); if (dds.Platform.OutputFormat == TexFormat.RGBA8_UNORM) { formatInfo.Format = PixelFormat.Rgba; } GLTextureDataLoader.LoadImage(texture.Target, mipWidth, mipHeight, depth, formatInfo, buffer, j); } } GL.TexParameter(texture.Target, TextureParameterName.TextureBaseLevel, 0); GL.TexParameter(texture.Target, TextureParameterName.TextureMaxLevel, 13); GL.GenerateMipmap(GenerateMipmapTarget.TextureCubeMapArray); texture.Unbind(); return(texture); }
public static GLTextureCubeArray CreateEmptyCubemap(int size, int arrayCount, int mipCount, PixelInternalFormat pixelInternalFormat = PixelInternalFormat.Rgba8, PixelFormat pixelFormat = PixelFormat.Rgba, PixelType pixelType = PixelType.UnsignedByte) { GLTextureCubeArray texture = new GLTextureCubeArray(); texture.PixelFormat = pixelFormat; texture.PixelType = pixelType; texture.PixelInternalFormat = pixelInternalFormat; texture.Width = size; texture.Height = size; texture.Target = TextureTarget.TextureCubeMapArray; texture.MinFilter = TextureMinFilter.LinearMipmapLinear; texture.MagFilter = TextureMagFilter.Linear; texture.MipCount = mipCount; texture.ArrayCount = arrayCount; texture.Bind(); //Allocate mip data if (texture.MipCount > 1) { texture.GenerateMipmaps(); } for (int mip = 0; mip < texture.MipCount; mip++) { int mipWidth = (int)(texture.Width * Math.Pow(0.5, mip)); int mipHeight = (int)(texture.Height * Math.Pow(0.5, mip)); GL.TexImage3D(texture.Target, 0, texture.PixelInternalFormat, mipWidth, mipHeight, texture.ArrayCount * 6, mip, texture.PixelFormat, texture.PixelType, IntPtr.Zero); } texture.UpdateParameters(); texture.Unbind(); return(texture); }