Ejemplo n.º 1
0
        public static Texture2D CreateTexture2D(BRTI_Texture tex, int surfaceIndex = 0)
        {
            bool compressedFormatWithMipMaps = SFGraphics.GLObjects.Textures.TextureFormats.TextureFormatTools.IsCompressed(tex.pixelInternalFormat);

            if (compressedFormatWithMipMaps)
            {
                if (tex.mipMapCount > 1)
                {
                    Texture2D texture = new Texture2D();
                    texture.LoadImageData(tex.width, tex.height, tex.mipmaps,
                                          (InternalFormat)tex.pixelInternalFormat);
                    return(texture);
                }
                else
                {
                    // Only load the first level and generate the rest.
                    Texture2D texture = new Texture2D();
                    texture.LoadImageData(tex.width, tex.height, tex.mipmaps[0], (InternalFormat)tex.pixelInternalFormat);
                    return(texture);
                }
            }
            else
            {
                // Uncompressed.
                Texture2D texture = new Texture2D();
                texture.LoadImageData(tex.width, tex.height, tex.mipmaps[0],
                                      new TextureFormatUncompressed(tex.pixelInternalFormat, tex.pixelFormat, tex.pixelType));
                return(texture);
            }
        }
Ejemplo n.º 2
0
        public static int getImageSize(BRTI_Texture t)
        {
            switch (t.type)
            {
            case PixelInternalFormat.CompressedRgbaS3tcDxt1Ext:
            case PixelInternalFormat.CompressedSrgbAlphaS3tcDxt1Ext:
            case PixelInternalFormat.CompressedRedRgtc1:
            case PixelInternalFormat.CompressedSignedRedRgtc1:
                return(t.width * t.height / 2);

            case PixelInternalFormat.CompressedRgbaS3tcDxt3Ext:
            case PixelInternalFormat.CompressedSrgbAlphaS3tcDxt3Ext:
            case PixelInternalFormat.CompressedRgbaS3tcDxt5Ext:
            case PixelInternalFormat.CompressedSrgbAlphaS3tcDxt5Ext:
            case PixelInternalFormat.CompressedSignedRgRgtc2:
            case PixelInternalFormat.CompressedRgRgtc2:
                return(t.width * t.height);

            case PixelInternalFormat.Rgba:
                return(t.data.Length);

            default:
                return(t.data.Length);
            }
        }
Ejemplo n.º 3
0
        public unsafe void ExportAsImage(BRTI_Texture t, int id, string path)
        {
            Bitmap bitmap = new Bitmap(t.width, t.height);

            System.Drawing.Imaging.BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, t.width, t.height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            GL.BindTexture(TextureTarget.Texture2D, id);
            GL.GetTexImage(TextureTarget.Texture2D, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bitmapData.Scan0);

            bitmap.UnlockBits(bitmapData);
            bitmap.Save(path);
        }
Ejemplo n.º 4
0
        public static int loadImage(BRTI_Texture t)
        {
            int texID = GL.GenTexture();

            GL.BindTexture(TextureTarget.Texture2D, texID);

            if (t.type != PixelInternalFormat.Rgba)
            {
                GL.CompressedTexImage2D <byte>(TextureTarget.Texture2D, 0, t.type,
                                               t.width, t.height, 0, getImageSize(t), t.data);
                //Debug.WriteLine(GL.GetError());
            }
            else
            {
                GL.TexImage2D <byte>(TextureTarget.Texture2D, 0, t.type, t.width, t.height, 0,
                                     t.utype, PixelType.UnsignedByte, t.data);
            }

            GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);

            return(texID);
        }
Ejemplo n.º 5
0
        private void LoadFormats(BRTI_Texture texture, uint format, int mipLevel, int width, int height)
        {
            switch (format >> 8)
            {
            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC1):
                texture.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext;
                break;

            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC2):
                if (DataType == (byte)Formats.BNTXImageTypes.UNORM)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext;
                }
                else if (DataType == (byte)Formats.BNTXImageTypes.SRGB)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt3Ext;
                }
                else
                {
                    throw new Exception("Unsupported data type for BC2");
                }
                break;

            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC3):
                if (DataType == (byte)Formats.BNTXImageTypes.UNORM)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext;
                }
                else if (DataType == (byte)Formats.BNTXImageTypes.SRGB)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt5Ext;
                }
                else
                {
                    throw new Exception("Unsupported data type for BC3");
                }
                break;

            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC4):
                if (DataType == (byte)Formats.BNTXImageTypes.UNORM)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.CompressedRedRgtc1;
                }
                else if (DataType == (byte)Formats.BNTXImageTypes.SNORM)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.CompressedSignedRedRgtc1;
                }
                else
                {
                    throw new Exception("Unsupported data type for BC4");
                }
                break;

            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC5):
                if (DataType == (byte)Formats.BNTXImageTypes.UNORM)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.CompressedRgRgtc2;
                }
                else if (DataType == (byte)Formats.BNTXImageTypes.SNORM)
                {
                    //    texture.pixelInternalFormat = PixelInternalFormat.CompressedRgRgtc2;


                    byte[] fixBC5 = DDS_Decompress.DecompressBC5(texture.mipmaps[mipLevel], width, height, true);
                    texture.mipmaps[mipLevel]   = fixBC5;
                    texture.pixelInternalFormat = PixelInternalFormat.Rgba;
                    texture.pixelFormat         = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
                }
                else
                {
                    Console.WriteLine("Unsupported data type for BC5");
                }
                break;

            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC7):
                if (DataType == (byte)Formats.BNTXImageTypes.UNORM || DataType == (byte)Formats.BNTXImageTypes.SRGB)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.CompressedRgbaBptcUnorm;
                }
                break;

            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_R8_G8_B8_A8):
                if (DataType == (byte)Formats.BNTXImageTypes.UNORM || DataType == (byte)Formats.BNTXImageTypes.SRGB)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.Rgba;
                    texture.pixelFormat         = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
                }
                else
                {
                    throw new Exception("Unsupported data type for R8_G8_B8_A8");
                }
                break;
            }
        }