public void LoadCompressedMips(TextureTarget textureTarget, STGenericTexture.Surface ImageData, int mipwidth, int mipheight, int MipLevel = 0)
        {
            GL.CompressedTexImage2D <byte>(textureTarget, MipLevel, (InternalFormat)pixelInternalFormat,
                                           mipwidth, mipheight, 0, getImageSize(this), ImageData.mipmaps[MipLevel]);

            //  GL.GenerateMipmap((GenerateMipmapTarget)textureTarget);
        }
        public void LoadUncompressedMips(TextureTarget textureTarget, STGenericTexture.Surface ImageData, int mipwidth, int mipheight, int MipLevel = 0)
        {
            GL.TexImage2D <byte>(textureTarget, MipLevel, pixelInternalFormat, mipwidth, mipheight, 0,
                                 pixelFormat, PixelType.UnsignedByte, ImageData.mipmaps[MipLevel]);

            //   GL.GenerateMipmap((GenerateMipmapTarget)textureTarget);
        }
Beispiel #3
0
        public override void SaveDDS(string fileName)
        {
            List <STGenericTexture.Surface> surfaces = new List <STGenericTexture.Surface>();

            Bind();

            int size = this.Width;

            for (int i = 0; i < 6 * ArrayCount; i++)
            {
                var surface = new STGenericTexture.Surface();
                surfaces.Add(surface);

                for (int m = 0; m < MipCount; m++)
                {
                    int    mipSize   = (int)(size * Math.Pow(0.5, m));
                    byte[] outputRaw = new byte[mipSize * mipSize * 4];
                    GL.GetTextureSubImage(this.ID, m, 0, 0, i, Width, Height, 1,
                                          PixelFormat.Rgba, PixelType.UnsignedByte, outputRaw.Length, outputRaw);

                    surface.mipmaps.Add(outputRaw);
                }
            }

            var dds = new DDS();

            dds.MainHeader.Width             = (uint)this.Width;
            dds.MainHeader.Height            = (uint)this.Height;
            dds.MainHeader.Depth             = 1;
            dds.MainHeader.MipCount          = (uint)this.MipCount;
            dds.MainHeader.PitchOrLinearSize = (uint)surfaces[0].mipmaps[0].Length;
            dds.ArrayCount = (uint)this.ArrayCount * 6;

            dds.SetFlags(TexFormat.RGBA8_UNORM, ArrayCount > 6, true);

            if (dds.IsDX10)
            {
                if (dds.Dx10Header == null)
                {
                    dds.Dx10Header = new DDS.DX10Header();
                }

                dds.Dx10Header.ResourceDim = 3;
                dds.Dx10Header.ArrayCount  = (uint)ArrayCount * 6;
            }

            dds.Save(fileName, surfaces);

            Unbind();
        }
        public override void SaveDDS(string fileName)
        {
            List <STGenericTexture.Surface> surfaces = new List <STGenericTexture.Surface>();

            Bind();

            var surface = new STGenericTexture.Surface();

            surfaces.Add(surface);

            for (int m = 0; m < this.MipCount; m++)
            {
                int mipWidth  = (int)(Width * Math.Pow(0.5, m));
                int mipHeight = (int)(Height * Math.Pow(0.5, m));

                byte[] outputRaw = new byte[mipWidth * mipHeight * 4];
                GL.GetTexImage(this.Target, m,
                               PixelFormat.Bgra, PixelType.UnsignedByte, outputRaw);

                surface.mipmaps.Add(outputRaw);
            }

            var dds = new DDS();

            dds.MainHeader.Width             = (uint)this.Width;
            dds.MainHeader.Height            = (uint)this.Height;
            dds.MainHeader.Depth             = 1;
            dds.MainHeader.MipCount          = (uint)this.MipCount;
            dds.MainHeader.PitchOrLinearSize = (uint)surfaces[0].mipmaps[0].Length;

            dds.SetFlags(TexFormat.RGBA8_UNORM, false, false);

            if (dds.IsDX10)
            {
                if (dds.Dx10Header == null)
                {
                    dds.Dx10Header = new DDS.DX10Header();
                }

                dds.Dx10Header.ResourceDim = 3;
                dds.Dx10Header.ArrayCount  = 1;
            }

            dds.Save(fileName, surfaces);

            Unbind();
        }