public static GLTextureCube FromDDS(DDS dds, DDS mipLevel2) { var surfaces = dds.GetSurfaces(0, false, 6); var surfacesMip = mipLevel2.GetSurfaces(0, false, 6); int size = (int)dds.Width; GLTextureCube texture = new GLTextureCube(); texture.Width = size; texture.Height = size; texture.Bind(); InternalFormat format = InternalFormat.CompressedRgbaS3tcDxt5Ext; if (dds.Platform.OutputFormat == TexFormat.BC6H_UF16) { format = InternalFormat.CompressedRgbBptcUnsignedFloat; } if (dds.Platform.OutputFormat == TexFormat.BC6H_SF16) { format = InternalFormat.CompressedRgbBptcSignedFloat; } for (int i = 0; i < 6; i++) { for (int j = 0; j < dds.MipCount; j++) { int mipWidth = CalculateMipDimension(texture.Width, j); int mipHeight = CalculateMipDimension(texture.Height, j); int imageSize = GLFormatHelper.CalculateImageSize(mipWidth, mipHeight, format); if (j == 0) { GL.CompressedTexImage2D(TextureTarget.TextureCubeMapPositiveX + i, j, format, mipWidth, mipHeight, 0, imageSize, surfaces[i].mipmaps[0]); } else if (j == 1) { GL.CompressedTexImage2D(TextureTarget.TextureCubeMapPositiveX + i, j, format, mipWidth, mipHeight, 0, imageSize, surfacesMip[i].mipmaps[0]); } else { GL.CompressedTexImage2D(TextureTarget.TextureCubeMapPositiveX + i, j, format, mipWidth, mipHeight, 0, imageSize, IntPtr.Zero); } } } texture.Unbind(); return(texture); }
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); }