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 GLTextureCube CreateEmptyCubemap(int size,
                                                       PixelInternalFormat pixelInternalFormat = PixelInternalFormat.Rgba8,
                                                       PixelFormat pixelFormat = PixelFormat.Rgba,
                                                       PixelType pixelType     = PixelType.UnsignedByte, int numMips = 1)
        {
            GLTextureCube texture = new GLTextureCube();

            texture.PixelFormat = pixelFormat;
            texture.PixelType   = pixelType;
            texture.Width       = size; texture.Height = size;
            texture.Target      = TextureTarget.TextureCubeMap;

            texture.Bind();
            texture.WrapR     = TextureWrapMode.ClampToEdge;
            texture.WrapS     = TextureWrapMode.ClampToEdge;
            texture.WrapT     = TextureWrapMode.ClampToEdge;
            texture.MinFilter = TextureMinFilter.LinearMipmapLinear;
            texture.MagFilter = TextureMagFilter.Linear;
            texture.MipCount  = numMips;

            //Allocate mip data
            if (texture.MipCount > 1)
            {
                texture.GenerateMipmaps();
            }

            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < texture.MipCount; j++)
                {
                    var width  = CalculateMipDimension(texture.Width, j);
                    var height = CalculateMipDimension(texture.Height, j);

                    GL.TexImage2D(TextureTarget.TextureCubeMapPositiveX + i, j, pixelInternalFormat,
                                  width, height,
                                  0, pixelFormat, pixelType, IntPtr.Zero);
                }
            }
            texture.UpdateParameters();
            texture.Unbind();
            return(texture);
        }
        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);
        }