static void LoadCompressedImage2D(int mipLevel, int width, int height, InternalFormat format, byte[] data) { int imageSize = GLFormatHelper.CalculateImageSize(width, height, format); GL.CompressedTexImage2D(TextureTarget.Texture2D, mipLevel, format, width, height, 0, imageSize, data); }
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 GLTexture2DArray FromDDS(DDS dds) { GLTexture2DArray texture = new GLTexture2DArray(); texture.Width = (int)dds.Width; texture.Height = (int)dds.Height; texture.Bind(); GL.TexParameter(texture.Target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(texture.Target, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear); GL.TexParameter(texture.Target, TextureParameterName.TextureBaseLevel, 0); GL.TexParameter(texture.Target, TextureParameterName.TextureMaxLevel, 13); GL.TexParameter(texture.Target, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); GL.TexParameter(texture.Target, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); GL.TexParameter(texture.Target, TextureParameterName.TextureWrapR, (int)TextureWrapMode.ClampToEdge); InternalFormat format = InternalFormat.Rgba8; 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) * (int)dds.ArrayCount; List <byte[]> levels = new List <byte[]>(); for (int i = 0; i < dds.ArrayCount; i++) { var data = dds.GetDecodedSurface(i, j); if (i == 0 || i == 1) { data = FlipHorizontal(mipWidth, mipHeight, data); } levels.Add(data); } var surface = ByteUtils.CombineArray(levels.ToArray()); if (format == InternalFormat.Rgba8) { GL.TexImage3D(TextureTarget.Texture2DArray, j, PixelInternalFormat.Rgba, mipWidth, mipHeight, (int)dds.ArrayCount, 0, PixelFormat.Bgra, PixelType.UnsignedByte, surface); } else { GL.CompressedTexImage3D(TextureTarget.Texture2DArray, j, format, mipWidth, mipHeight, (int)dds.ArrayCount, 0, imageSize, surface); } } texture.Unbind(); return(texture); }
public void LoadImage(int width, int height, TexFormat format, byte[] data) { if (TextureFormatHelper.IsBCNCompressed(format)) { var internalFormat = GLFormatHelper.ConvertCompressedFormat(format, true); int imageSize = GLFormatHelper.CalculateImageSize(width, height, internalFormat); GL.CompressedTexImage3D(TextureTarget.Texture2DArray, 0, internalFormat, width, height, 1, 0, imageSize, data); } else { var formatInfo = GLFormatHelper.ConvertPixelFormat(format); GL.TexImage3D(Target, 0, formatInfo.InternalFormat, width, height, 1, 0, formatInfo.Format, formatInfo.Type, data); } }
public static GLTextureCube FromDDS(DDS dds, bool flipY = false, bool isBGRA = false) { 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; } if (dds.Platform.OutputFormat == TexFormat.RGBA8_UNORM) { format = InternalFormat.Rgba8; } 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); var surface = dds.GetDeswizzledSurface(i, j); if (dds.Parameters.UseSoftwareDecoder || flipY) { surface = dds.GetDecodedSurface(i, j); format = InternalFormat.Rgba8; } if (flipY) { surface = FlipVertical(mipWidth, mipHeight, surface); } if (format == InternalFormat.Rgba8) { GL.TexImage2D(TextureTarget.TextureCubeMapPositiveX + i, j, PixelInternalFormat.Rgba, mipWidth, mipHeight, 0, PixelFormat.Rgba, PixelType.UnsignedByte, surface); } else { GL.CompressedTexImage2D(TextureTarget.TextureCubeMapPositiveX + i, j, format, mipWidth, mipHeight, 0, imageSize, surface); } } } texture.Unbind(); return(texture); }