示例#1
0
 public LoadedTexture GetConverted(TextureLoadParams textureLoadParams)
 {
     if (_attemptedConversion)
     {
         return(_converted);
     }
     _attemptedConversion = true;
     _converted           = Convert(Native, textureLoadParams);
     return(_converted);
 }
示例#2
0
        public LoadedTexture GetAlpha(string name, TextureLoadParams textureLoadParams)
        {
            if (DontLoadTextures)
            {
                return(new LoadedTexture(DummyTexture, false));
            }

            if (!_alpha.ContainsKey(name))
            {
                return(ParentName != null?Parent.GetAlpha(name, textureLoadParams) : null);
            }

            return(_alpha[name].GetConverted(textureLoadParams));
        }
示例#3
0
        private static LoadedTexture Convert(TextureNative src, TextureLoadParams textureLoadParams)
        {
            TextureFormat format;

            var loadMips = (src.Format & RasterFormat.ExtMipMap) == RasterFormat.ExtMipMap;
            var autoMips = (src.Format & RasterFormat.ExtAutoMipMap) == RasterFormat.ExtAutoMipMap;

            switch (src.Format & RasterFormat.NoExt)
            {
            case RasterFormat.BGRA8:
            case RasterFormat.BGR8:
                format = TextureFormat.RGBA32;
                break;

            case RasterFormat.LUM8:
                format = TextureFormat.Alpha8;
                break;

            case RasterFormat.R4G4B4A4:
                format = TextureFormat.RGBA4444;
                break;

            case RasterFormat.A1R5G5B5:
                format = TextureFormat.ARGB32;
                break;

            case RasterFormat.R5G6B5:
                format = TextureFormat.RGB565;
                break;

            default:
                throw new NotImplementedException(string.Format("RasterFormat.{0}", src.Format & RasterFormat.NoExt));
            }

            switch (src.Compression)
            {
            case CompressionMode.None:
                break;

            case CompressionMode.DXT1:
                format = TextureFormat.DXT1;
                break;

            case CompressionMode.DXT3:
                format = TextureFormat.DXT5;
                break;

            default:
                throw new NotImplementedException(string.Format("CompressionMode.{0}", src.Compression));
            }

            var tex = new Texture2D(src.Width, src.Height, format, false /*loadMips*/);

            switch (src.FilterFlags)
            {
            case Filter.None:
            case Filter.Nearest:
            case Filter.MipNearest:
                tex.filterMode = FilterMode.Point;
                break;

            case Filter.Linear:
            case Filter.MipLinear:
            case Filter.LinearMipNearest:
                tex.filterMode = FilterMode.Bilinear;
                break;

            case Filter.LinearMipLinear:
            case Filter.Unknown:
                tex.filterMode = FilterMode.Trilinear;
                break;
            }

            var data = src.ImageData;

            switch (src.Format & RasterFormat.NoExt)
            {
            case RasterFormat.BGR8:
            case RasterFormat.BGRA8:
                data = ConvertBGRToRGB(data);
                break;
            }

            switch (src.Compression)
            {
            case CompressionMode.DXT3:
                data = ConvertDXT3ToDXT5(data);
                break;
            }

            tex.LoadRawTextureData(data);
            tex.Apply(loadMips || autoMips, textureLoadParams.makeNoLongerReadable);

            return(new LoadedTexture(tex, src.Alpha));
        }