예제 #1
0
        public static int getImageSize(FTEX_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);
            }
        }
예제 #2
0
        public static SFTex.Texture2D CreateTexture2D(FTEX_Texture tex, int surfaceIndex = 0)
        {
            bool compressedFormatWithMipMaps = SFTex.TextureFormatTools.IsCompressed(tex.pixelInternalFormat);

            //Todo. Use mip maps from FTEX
            if (compressedFormatWithMipMaps)
            {
                if (tex.mipMapData.Count > 1)
                {
                    // Only load the first level and generate the rest.
                    SFTex.Texture2D texture = new SFTex.Texture2D();
                    texture.LoadImageData(tex.width, tex.height, tex.data, tex.mipMapData.Count,
                                          (InternalFormat)tex.pixelInternalFormat);
                    return(texture);
                }
                else
                {
                    // Only load the first level and generate the rest.
                    SFTex.Texture2D texture = new SFTex.Texture2D();
                    texture.LoadImageData(tex.width, tex.height, tex.data, tex.mipMapData.Count,
                                          (InternalFormat)tex.pixelInternalFormat);
                    return(texture);
                }
            }
            else
            {
                // Uncompressed.
                SFTex.Texture2D texture = new SFTex.Texture2D();
                texture.LoadImageData(tex.width, tex.height, tex.data, tex.mipMapCount,
                                      new SFTex.TextureFormatUncompressed(tex.pixelInternalFormat, tex.pixelFormat, tex.pixelType));
                return(texture);
            }
        }
예제 #3
0
        public static int loadImage(FTEX_Texture t)
        {
            int texID = GL.GenTexture();

            GL.BindTexture(TextureTarget.Texture2D, texID);

            if (t.type != PixelInternalFormat.Rgba)
            {
                GL.CompressedTexImage2D <byte>(TextureTarget.Texture2D, 0, (InternalFormat)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);
        }