示例#1
0
        public unsafe void SaveBitmap(string filePath)
        {
            var rawData = new byte[Width * Height * 4];

            if (Format == TextureFormat.BGRA32)
            {
                Buffer.BlockCopy(RawData, 0, rawData, 0, rawData.Length);
            }
            else if (Format == TextureFormat.ARGB32)
                fixed(byte *pPixels = rawData, pData = RawData)
                {
                    var rPixels = (uint *)pPixels;
                    var rData   = (uint *)pData;

                    for (var i = 0; i < Width * Height; ++i)
                    {
                        var d     = *rData++;
                        var b     = (byte)(d >> 24);
                        var g     = (byte)(d >> 16);
                        var r     = (byte)(d >> 8);
                        var a     = (byte)d;
                        var color =
                            ((uint)(a << 24) & 0xFF000000) |
                            ((uint)(r << 16) & 0x00FF0000) |
                            ((uint)(g << 8) & 0x0000FF00) |
                            ((uint)(b << 0) & 0x000000FF);
                        *rPixels++ = color;
                    }
                }
            else if (Format == TextureFormat.RGBA32)
                fixed(byte *pPixels = rawData, pData = RawData)
                {
                    var rPixels = (uint *)pPixels;
                    var rData   = (uint *)pData;

                    for (var i = 0; i < Width * Height; ++i)
                    {
                        var d     = *rData++;
                        var a     = (byte)(d >> 24);
                        var b     = (byte)(d >> 16);
                        var g     = (byte)(d >> 8);
                        var r     = (byte)d;
                        var color =
                            ((uint)(a << 24) & 0xFF000000) |
                            ((uint)(r << 16) & 0x00FF0000) |
                            ((uint)(g << 8) & 0x0000FF00) |
                            ((uint)(b << 0) & 0x000000FF);
                        *rPixels++ = color;
                    }
                }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(Format), Format.ToString());
            }
            using (var bmp = new Bitmap(Width, Height, Width * 4, PixelFormat.Format32bppRgb, Marshal.UnsafeAddrOfPinnedArrayElement(rawData, 0)))
                bmp.Save(filePath);
        }
    void CreateTextureQuad(TextureFormat format, Vector3 pos)
    {
        if ((int)format >= 0)
        {
            GameObject   go  = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            Transform    t   = go.GetComponent <Transform> ();
            MeshRenderer mr  = go.GetComponent <MeshRenderer> ();
            Material     mat = new Material(_shader);

            Texture3D tex = null;
            if (SystemInfo.SupportsTextureFormat(format))
            {
                if (setPixelSupport.Contains(format))
                {
                    if (debugMode)
                    {
                        Debug.Log("Texture supported " + format.ToString());
                    }
                    tex = new Texture3D(widthheight, widthheight, widthheight, format, false);
                    tex.SetPixels(refTexture.GetPixels());

                    LabelMaker.MakeLabel(format.ToString(), Color.green, t);
                }
                else
                {
                    if (debugMode)
                    {
                        Debug.LogWarning("Texture not supported with SetPixels " + format.ToString());
                    }
                    LabelMaker.MakeLabel(format.ToString(), Color.yellow, t);
                    //tex = warningTexture;
                }
            }
            else
            {
                if (debugMode)
                {
                    Debug.LogWarning("Texture not supported on platform " + format.ToString());
                }
                LabelMaker.MakeLabel(format.ToString(), Color.red, t);
                //tex = errorTexture;
            }

            if (tex != null)
            {
                tex.filterMode = FilterMode.Point;
                mat.SetTexture("_texture", tex);
                mat.name     = format.ToString();
                go.name      = format.ToString();
                mr.material  = mat;
                tex.wrapMode = TextureWrapMode.Repeat;
                tex.Apply();
            }

            t.SetParent(transform);
            t.position = pos;
        }
    }
示例#3
0
		public static void DecodeTextureDataToWriter(byte[] data, int width, int height, TextureFormat format,
													PipelineWriter writer)
		{
			if (!format.IsSupported())
				throw new FormatException("Unsupported format: " + format.ToString());
			PipelineReader reader = null;
			switch (format)
			{
				case TextureFormat.DXT1:
					reader = new DXT1Reader(data, format, width, height);
					break;
				case TextureFormat.DXT2:
				case TextureFormat.DXT3:
					reader = new DXT3Reader(data, format, width, height);
					break;
				case TextureFormat.DXT4:
				case TextureFormat.DXT5:
					reader = new DXT5Reader(data, format, width, height);
					break;
				case TextureFormat.BC4:
					reader = new BC4Reader(data, format, width, height);
					break;
				case TextureFormat.BC5:
					reader = new BC5Reader(data, format, width, height);
					break;
				default:
					reader = new DefaultReader(data, format, width, height);
					break;
			}
			reader.Read(writer);
		}
        public static void ReadColor(NativeArray <byte> bytes, TextureFormat format, int colorIndex, ref Color color)
        {
            var index = colorIndex * (format == TextureFormat.RGB24 ? 3 : 4);

            switch (format)
            {
            case TextureFormat.ARGB32:
                color.a = bytes[index] / ByteMaxValueF;
                color.r = bytes[index + 1] / ByteMaxValueF;
                color.g = bytes[index + 2] / ByteMaxValueF;
                color.b = bytes[index + 3] / ByteMaxValueF;
                break;

            case TextureFormat.RGB24:
                color.r = bytes[index] / ByteMaxValueF;
                color.g = bytes[index + 1] / ByteMaxValueF;
                color.b = bytes[index + 2] / ByteMaxValueF;
                color.a = 1f;
                break;

            case TextureFormat.RGBA32:
                color.r = bytes[index] / ByteMaxValueF;
                color.g = bytes[index + 1] / ByteMaxValueF;
                color.b = bytes[index + 2] / ByteMaxValueF;
                color.a = bytes[index + 3] / ByteMaxValueF;
                break;

            default:
                Debug.LogError($"SyncTextureImporter.GetColor: TextureFormat {format.ToString()} is not supported!");
                break;
            }
        }
        public static void WriteColor(NativeArray <byte> bytes, TextureFormat format, int colorIndex, Color color)
        {
            var index = colorIndex * (format == TextureFormat.RGB24 ? 3 : 4);

            switch (format)
            {
            case TextureFormat.ARGB32:
                bytes[index]     = (byte)(color.a * ByteMaxValueF);
                bytes[index + 1] = (byte)(color.r * ByteMaxValueF);
                bytes[index + 2] = (byte)(color.g * ByteMaxValueF);
                bytes[index + 3] = (byte)(color.b * ByteMaxValueF);
                break;

            case TextureFormat.RGB24:
                bytes[index]     = (byte)(color.r * ByteMaxValueF);
                bytes[index + 1] = (byte)(color.g * ByteMaxValueF);
                bytes[index + 2] = (byte)(color.b * ByteMaxValueF);
                break;

            case TextureFormat.RGBA32:
                bytes[index]     = (byte)(color.r * ByteMaxValueF);
                bytes[index + 1] = (byte)(color.g * ByteMaxValueF);
                bytes[index + 2] = (byte)(color.b * ByteMaxValueF);
                bytes[index + 3] = (byte)(color.a * ByteMaxValueF);
                break;

            default:
                Debug.LogError($"SyncTextureImporter.GetColor: TextureFormat {format.ToString()} is not supported!");
                return;
            }
        }
示例#6
0
    protected override void PostLoadData(XmlNode node)
    {
        base.PostLoadData(node);

        m_Infos.Add(new CheatInfo("Show", "FPS", "FPS 표시 On/Off"));
        m_Infos.Add(new CheatInfo("Show", "Memory", "Memory 표시 On/Off"));
        m_Infos.Add(new CheatInfo("Show", "DeviceInfo", "DeviceInfo 표시 On/Off"));

        List <string> texture_formats = new List <string>();

        foreach (var value in Enum.GetValues(typeof(TextureFormat)))
        {
            TextureFormat format = (TextureFormat)value;
            try
            {
                if (SystemInfo.SupportsTextureFormat(format))
                {
                    texture_formats.Add(format.ToString());
                }
            }
            catch (ArgumentException)
            {
            }
        }

        m_Infos.Add(new CheatInfo("Show", "TextureFormat", "TextureFormat 표시", texture_formats.ToArray()));

        m_Infos.Add(new CheatInfo("Set", "Quality", "Qulity 선택", QualitySettings.names));
    }
        /// <summary>
        /// 获取当前平台纹理的格式
        /// </summary>
        public static string GetTextureFormatString(Texture tex)
        {
            var           assembly = typeof(AssetDatabase).Assembly;
            var           type     = assembly.GetType("UnityEditor.TextureUtil");
            TextureFormat format   = (TextureFormat)EditorTools.InvokePublicStaticMethod(type, "GetTextureFormat", tex);

            return(format.ToString());
        }
示例#8
0
		public static PixelFormat GetBestBitmapFormat(this TextureFormat format)
        {
            switch (format)
            {
                case TextureFormat.R32G32B32A32F:
                case TextureFormat.R32G32B32A32_UINT:
                case TextureFormat.R32G32B32F:
                case TextureFormat.R32G32B32_UINT:
                case TextureFormat.R16G16B16A16_UNORM:
                case TextureFormat.R16G16B16A16F:
                case TextureFormat.R32G32F:
                case TextureFormat.R32G32_UINT:
                case TextureFormat.R16G16B16A16_UINT:
                case TextureFormat.R16G16B16:
                case TextureFormat.R16G16_UNORM:
                case TextureFormat.R16G16F:
                case TextureFormat.R16G16_UINT:
                case TextureFormat.R24G8_TYPELESS:
                case TextureFormat.D32_S8X24_UINT:
                case TextureFormat.D24_UNORM_S8_UINT:
                case TextureFormat.R11G11B10F:
                    return PixelFormat.Format64bppArgb;
                case TextureFormat.D24_UNORM_X8_UINT:
                case TextureFormat.D32F:
                case TextureFormat.R32_UINT:
                case TextureFormat.R32F:
                case TextureFormat.R16_UNORM:
                case TextureFormat.R16F:
                case TextureFormat.D16_UNORM:
                case TextureFormat.L16_UNORM:
                case TextureFormat.R16_UINT:
                    return PixelFormat.Format16bppGrayScale;
                case TextureFormat.A8_UNORM:
                case TextureFormat.L8_UNORM:
                case TextureFormat.R8_UNORM:
                case TextureFormat.R8_UINT:
                    return PixelFormat.Format8bppIndexed;
                case TextureFormat.B8G8R8A8_UNORM:
                case TextureFormat.B8G8R8X8_UNORM:
                case TextureFormat.R8G8B8A8_UNORM:
                case TextureFormat.R8G8B8A8_UINT:
                case TextureFormat.R8G8B8:
                case TextureFormat.B8G8R8:
                case TextureFormat.R8G8_UNORM:
                case TextureFormat.DXT1:
                case TextureFormat.DXT2:
                case TextureFormat.DXT3:
                case TextureFormat.DXT4:
                case TextureFormat.DXT5:
                case TextureFormat.BC4:
                case TextureFormat.BC5:
                case TextureFormat.BC6H_UF16:
                case TextureFormat.BC7:
                    return PixelFormat.Format32bppArgb;
                default:
                    throw new Exception("Unsupported format:" + format.ToString());
            }
        }
示例#9
0
		public static int GetColorChannel(this TextureFormat format)
		{
			switch (format)
			{
				case TextureFormat.R32G32B32A32F:
				case TextureFormat.R32G32B32A32_UINT:
				case TextureFormat.R16G16B16A16_UNORM:
				case TextureFormat.R16G16B16A16F:
				case TextureFormat.R16G16B16A16_UINT:
				case TextureFormat.B8G8R8A8_UNORM:
				case TextureFormat.R8G8B8A8_UNORM:
				case TextureFormat.R8G8B8A8_UINT:
				case TextureFormat.DXT1:
				case TextureFormat.DXT2:
				case TextureFormat.DXT3:
				case TextureFormat.DXT4:
				case TextureFormat.DXT5:
				case TextureFormat.BC6H_UF16:
				case TextureFormat.BC7:
					return 4;
				case TextureFormat.R32G32B32F:
				case TextureFormat.R32G32B32_UINT:
				case TextureFormat.B8G8R8X8_UNORM:
				case TextureFormat.R16G16B16:
				case TextureFormat.R11G11B10F:
				case TextureFormat.R8G8B8:
				case TextureFormat.B8G8R8:
					return 3;
				case TextureFormat.D32_S8X24_UINT:
				case TextureFormat.R32G32F:
				case TextureFormat.R32G32_UINT:
				case TextureFormat.R16G16_UNORM:
				case TextureFormat.R16G16F:
				case TextureFormat.D24_UNORM_S8_UINT:
				case TextureFormat.R24G8_TYPELESS:
				case TextureFormat.R16G16_UINT:
				case TextureFormat.R8G8_UNORM:
				case TextureFormat.BC5:
					return 2;
				case TextureFormat.R32_UINT:
				case TextureFormat.D24_UNORM_X8_UINT:
				case TextureFormat.D32F:
				case TextureFormat.R32F:
				case TextureFormat.R16_UNORM:
				case TextureFormat.R16F:
				case TextureFormat.D16_UNORM:
				case TextureFormat.L16_UNORM:
				case TextureFormat.R16_UINT:
				case TextureFormat.A8_UNORM:
				case TextureFormat.L8_UNORM:
				case TextureFormat.R8_UNORM:
				case TextureFormat.R8_UINT:
				case TextureFormat.BC4:
					return 1;
				default:
					throw new Exception("Unsupported format:" + format.ToString());
			}
		}
示例#10
0
        private static QFormat ToQFormat(TextureFormat format)
        {
            switch (format)
            {
            case TextureFormat.DXT1:
            case TextureFormat.DXT1Crunched:
                return(QFormat.Q_FORMAT_S3TC_DXT1_RGB);

            case TextureFormat.DXT3:
                return(QFormat.Q_FORMAT_S3TC_DXT3_RGBA);

            case TextureFormat.DXT5:
            case TextureFormat.DXT5Crunched:
                return(QFormat.Q_FORMAT_S3TC_DXT5_RGBA);

            case TextureFormat.RHalf:
                return(QFormat.Q_FORMAT_R_16F);

            case TextureFormat.RGHalf:
                return(QFormat.Q_FORMAT_RG_HF);

            case TextureFormat.RGBAHalf:
                return(QFormat.Q_FORMAT_RGBA_HF);

            case TextureFormat.RFloat:
                return(QFormat.Q_FORMAT_R_F);

            case TextureFormat.RGFloat:
                return(QFormat.Q_FORMAT_RG_F);

            case TextureFormat.RGBAFloat:
                return(QFormat.Q_FORMAT_RGBA_F);

            case TextureFormat.RGB9e5Float:
                return(QFormat.Q_FORMAT_RGB9_E5);

            case TextureFormat.ATC_RGB4:
                return(QFormat.Q_FORMAT_ATITC_RGB);

            case TextureFormat.ATC_RGBA8:
                return(QFormat.Q_FORMAT_ATC_RGBA_INTERPOLATED_ALPHA);

            case TextureFormat.EAC_R:
                return(QFormat.Q_FORMAT_EAC_R_UNSIGNED);

            case TextureFormat.EAC_R_SIGNED:
                return(QFormat.Q_FORMAT_EAC_R_SIGNED);

            case TextureFormat.EAC_RG:
                return(QFormat.Q_FORMAT_EAC_RG_UNSIGNED);

            case TextureFormat.EAC_RG_SIGNED:
                return(QFormat.Q_FORMAT_EAC_RG_SIGNED);

            default:
                throw new NotSupportedException(format.ToString());
            }
        }
示例#11
0
 private static bool IsSupportedFormat(TextureFormat format)
 {
     // Supported float for PNG export: ARGB32, RGB32, RGB24, Aplha8 or one of float formats
     //
     return(format == TextureFormat.ARGB32 ||
            format == TextureFormat.RGBA32 ||
            format == TextureFormat.RGB24 ||
            format == TextureFormat.Alpha8 ||
            format.ToString().Contains("Float"));
 }
示例#12
0
 private void SetFilename(string filename)
 {
     this.filename = filename;
     if (Settings.MRUList.Contains(filename))
     {
         int i = Settings.MRUList.IndexOf(filename);
         Settings.MRUList.RemoveAt(i);
         recentFilesToolStripMenuItem.DropDownItems.RemoveAt(i);
     }
     Settings.MRUList.Insert(0, filename);
     recentFilesToolStripMenuItem.DropDownItems.Insert(0, new ToolStripMenuItem(filename.Replace("&", "&&")));
     Text = format.ToString() + " Editor - " + filename;
 }
示例#13
0
        static bool IsCompressed(TextureFormat format)
        {
            var formatString = format.ToString();

            if (formatString.StartsWith("ETC") ||
                formatString.StartsWith("ASTC") ||
                formatString.StartsWith("PVRTC") ||
                formatString.StartsWith("DXT"))
            {
                return(true);
            }

            return(false);
        }
示例#14
0
    public static bool CheckTextureSize(Texture2D [] arys, out float width, out float height, out TextureFormat format, out string errorMessage)
    {
        width  = 0;
        height = 0;
        format = TextureFormat.ARGB32;
        bool found = false;
        int  index = 0;

        for (int i = 0; i < arys.Length; i++)
        {
            if (null == arys [i])
            {
                continue;
            }
            if (found)
            {
                if (arys [i].width != width || arys [i].height != height)
                {
                    errorMessage  = "第" + index.ToString() + "张图";
                    errorMessage += "与第" + i.ToString() + "张图";
                    errorMessage += "宽高不一致";
                    return(false);
                }

                if (format != arys [i].format)
                {
                    errorMessage  = "第" + index.ToString() + "张图";
                    errorMessage += "格式" + format.ToString();
                    errorMessage += "与第" + i.ToString() + "张图";
                    errorMessage += "格式" + arys [i].format.ToString();
                    errorMessage += "格式不一致";
                    return(false);
                }
            }
            else
            {
                width  = arys [i].width;
                height = arys [i].height;
                format = arys [i].format;
                index  = i;
                found  = true;
            }
        }
        errorMessage = "";
        return(true);
    }
示例#15
0
    static public TextureFormat GetFourierTextureFormat()
    {
        TextureFormat fmt = TextureFormat.ARGB32;

        if (SystemInfo.SupportsTextureFormat(TextureFormat.RGBAFloat))
        {
            fmt = TextureFormat.RGBAFloat;
        }
        else if (SystemInfo.SupportsTextureFormat(TextureFormat.RGBAHalf))
        {
            fmt = TextureFormat.RGBAHalf;
        }

        Debug.Log("FourierTextureFormat = " + fmt.ToString());

        return(fmt);
    }
示例#16
0
 public void SetPixelsRFloat(float[] data)
 {
     if (_IsReady && _Format == TextureFormat.FloatR)
     {
         if (data.Length == _TotalDataSize)
         {
             _DataBuffer.SetData(data);
             PerformWriteRFloat();
         }
     }
     else if (_Format != TextureFormat.FloatR)
     {
         Logging.Warning <Texture3DCompute>("Cannot use SetPixelsRFloat() for format {0}", _Format.ToString());
     }
     else
     {
         Logging.Warning <Texture3DCompute>("Not initialized properly");
     }
 }
示例#17
0
        private static TexgenpackTexturetype ToTexgenpackTexturetype(TextureFormat format)
        {
            switch (format)
            {
            case TextureFormat.BC4:
                return(TexgenpackTexturetype.RGTC1);

            case TextureFormat.BC5:
                return(TexgenpackTexturetype.RGTC2);

            case TextureFormat.BC6H:
                return(TexgenpackTexturetype.BPTC_FLOAT);

            case TextureFormat.BC7:
                return(TexgenpackTexturetype.BPTC);

            default:
                throw new NotSupportedException(format.ToString());
            }
        }
示例#18
0
        public virtual XmlNode ToXml(XmlDocument worldDoc)
        {
            XmlNode iaNode = worldDoc.CreateElement("ImageAccessor");

            XmlNode lztsdNode = worldDoc.CreateElement("LevelZeroTileSizeDegrees");

            lztsdNode.AppendChild(worldDoc.CreateTextNode(LevelZeroTileSizeDegrees.ToString()));
            iaNode.AppendChild(lztsdNode);

            XmlNode extNode = worldDoc.CreateElement("ImageFileExtension");

            extNode.AppendChild(worldDoc.CreateTextNode(ImageExtension));
            iaNode.AppendChild(extNode);

            XmlNode tsizeNode = worldDoc.CreateElement("TextureSizePixels");

            tsizeNode.AppendChild(worldDoc.CreateTextNode("512"));
            iaNode.AppendChild(tsizeNode);

            XmlNode nlevelsNode = worldDoc.CreateElement("NumberLevels");

            nlevelsNode.AppendChild(worldDoc.CreateTextNode(LevelCount.ToString()));
            iaNode.AppendChild(nlevelsNode);

            XmlNode formatNode = worldDoc.CreateElement("TextureFormat");

            formatNode.AppendChild(worldDoc.CreateTextNode(TextureFormat.ToString()));
            iaNode.AppendChild(formatNode);

            // If no ImageTileService...
            if (m_dataDirectory != null)
            {
                XmlNode permDirNode = worldDoc.CreateElement("PermanentDirectory");
                permDirNode.AppendChild(worldDoc.CreateTextNode(m_dataDirectory));
                iaNode.AppendChild(permDirNode);
            }


            return(iaNode);
        }
        void OnWizardOtherButton()
        {
            helpString = "";
            if (textureArray == null)
            {
                helpString = "Please assign a texture array";
                return;
            }

            MB3_EditorMethods editorMethods = new MB3_EditorMethods();

            if (!editorMethods.TextureImporterFormatExistsForTextureFormat(format))
            {
                helpString = "No ImporterFormat exists for the selected format. Please select a different format.";
                return;
            }

            if (textureArray.format != TextureFormat.ARGB32 &&
                textureArray.format != TextureFormat.RGB24)
            {
                helpString = "Source TextureArray must be in format ARGB32 or RGB24. This will probably be changed in" +
                             "a future version of Mesh Baker.";
                return;
            }

            Texture2DArray outArray = new Texture2DArray(textureArray.width, textureArray.height, textureArray.depth, format, true);

            if (editorMethods.ConvertTexture2DArray(textureArray, outArray, format))
            {
                string pth = UnityEditor.AssetDatabase.GetAssetPath(textureArray);
                if (pth == null)
                {
                    pth = "Assets/TextureArray.asset";
                }
                pth  = pth.Replace(".asset", "");
                pth += format.ToString() + ".asset";
                UnityEditor.AssetDatabase.CreateAsset(outArray, pth);
                Debug.Log("Convert success saved asset: " + pth);
            }
        }
    private static int BPP(TextureFormat format)
    {
        switch (format)
        {
        case TextureFormat.ARGB32:
        case TextureFormat.BGRA32:
        case TextureFormat.RGBA32:
            return(32);

        case TextureFormat.RGB24:
            return(24);

        case TextureFormat.R16:
            return(16);

        case TextureFormat.R8:
        case TextureFormat.Alpha8:
            return(8);

        default:
            throw new ArgumentException("unsupported format {0}", format.ToString());
        }
    }
示例#21
0
    public static GraphicsFormat TextureFormatToGraphicsFormat(TextureFormat format)
    {
        switch (format)
        {
        case TextureFormat.Alpha8:
            return(GraphicsFormat.R8_UNorm);

        case TextureFormat.RGB24:
            return(GraphicsFormat.R8G8B8_SRGB);

        case TextureFormat.RGBA32:
            return(GraphicsFormat.R8G8B8A8_SRGB);

        case TextureFormat.RGFloat:
            return(GraphicsFormat.R32G32_SFloat);

        case TextureFormat.RGBAFloat:
            return(GraphicsFormat.R32G32B32A32_SFloat);

        default:
            Debug.LogError("Unspecfied graphics format for texture format: " + format.ToString());
            throw new ArgumentOutOfRangeException();
        }
    }
示例#22
0
        private void OnGUI()
        {
            if (_preview == null)
            {
                return;
            }

            _windowScrollPos = EditorGUILayout.BeginScrollView(_windowScrollPos, false, false);

            RefreshItems();

            GUILayout.Label(_windowTitle, TexturePackerStyles.Heading);
            GUILayout.BeginVertical(TexturePackerStyles.Section);

            GUILayout.Label("Inputs", TexturePackerStyles.Heading);
            foreach (TextureItem item in _items)
            {
                item.Draw();
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("+"))
            {
                TextureInput entry = new TextureInput();
                _texturePacker.Add(entry);
                _items.Add(new TextureItem(entry));
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            int prevRes = _texturePacker.resolution;

            _texturePacker.resolution = 128;

            _preview.Draw(_texturePacker);

            _texturePacker.resolution = prevRes;

            GUILayout.Label("Options", TexturePackerStyles.Heading);
            GUILayout.BeginVertical(TexturePackerStyles.Section);
            textureFormat             = (TextureFormat)EditorGUILayout.EnumPopup("> Format:", textureFormat);
            _texturePacker.resolution = EditorGUILayout.IntPopup("> Resolution:", _texturePacker.resolution, _textureResolutionsNames.ToArray(), _textureResolutions.ToArray());
            GUILayout.EndVertical();

            if (GUILayout.Button("Generate Texture", TexturePackerStyles.Button))
            {
                string savePath = EditorUtility.SaveFilePanel("Save", Application.dataPath, "texture.png", textureFormat.ToString());
                if (savePath != string.Empty)
                {
                    Texture2D output = _texturePacker.Create();

                    if (textureFormat == TextureFormat.JPG)
                    {
                        File.WriteAllBytes(savePath, output.EncodeToJPG());
                    }
                    else if (textureFormat == TextureFormat.PNG)
                    {
                        File.WriteAllBytes(savePath, output.EncodeToPNG());
                    }
                    else if (textureFormat == TextureFormat.TGA)
                    {
                        File.WriteAllBytes(savePath, output.EncodeToTGA());
                    }
                    else
                    {
                        File.WriteAllBytes(savePath, output.EncodeToEXR());
                    }

                    AssetDatabase.Refresh();
                }
            }

            GUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
        }
示例#23
0
        protected virtual void InitData()
        {
            Debug.Assert(SystemInfo.SupportsRenderTextureFormat(TextureFormat), "The graphics device does not support the render texture format " + TextureFormat.ToString());

            Debug.Assert(OceanRenderer.Instance.CurrentLodCount <= MAX_LOD_COUNT);

            var resolution = OceanRenderer.Instance.LodDataResolution;
            var desc       = new RenderTextureDescriptor(resolution, resolution, TextureFormat, 0);

            _targets = CreateLodDataTextures(desc, SimName, NeedToReadWriteTextureData);
        }
示例#24
0
        public Texture2D(AssetPreloadData preloadData, bool readSwitch)
        {
            var sourceFile = preloadData.sourceFile;
            var reader     = preloadData.InitReader();

            version = sourceFile.version;

            if (sourceFile.platform == -2)
            {
                uint m_ObjectHideFlags    = reader.ReadUInt32();
                PPtr m_PrefabParentObject = sourceFile.ReadPPtr();
                PPtr m_PrefabInternal     = sourceFile.ReadPPtr();
            }

            m_Name = reader.ReadAlignedString();
            if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 3))//2017.3 and up
            {
                var m_ForcedFallbackFormat = reader.ReadInt32();
                var m_DownscaleFallback    = reader.ReadBoolean();
                reader.AlignStream(4);
            }
            m_Width             = reader.ReadInt32();
            m_Height            = reader.ReadInt32();
            m_CompleteImageSize = reader.ReadInt32();
            m_TextureFormat     = (TextureFormat)reader.ReadInt32();

            if (version[0] < 5 || (version[0] == 5 && version[1] < 2))
            {
                m_MipMap = reader.ReadBoolean();
            }
            else
            {
                dwFlags      += 0x20000;
                dwMipMapCount = reader.ReadInt32();//is this with or without main image?
                dwCaps       += 0x400008;
            }

            m_IsReadable  = reader.ReadBoolean(); //2.6.0 and up
            m_ReadAllowed = reader.ReadBoolean(); //3.0.0 - 5.4
            reader.AlignStream(4);

            m_ImageCount       = reader.ReadInt32();
            m_TextureDimension = reader.ReadInt32();
            //m_TextureSettings
            m_FilterMode = reader.ReadInt32();
            m_Aniso      = reader.ReadInt32();
            m_MipBias    = reader.ReadSingle();
            m_WrapMode   = reader.ReadInt32();
            if (version[0] >= 2017)//2017.x and up
            {
                int m_WrapV = reader.ReadInt32();
                int m_WrapW = reader.ReadInt32();
            }
            if (version[0] >= 3)
            {
                m_LightmapFormat = reader.ReadInt32();
                if (version[0] >= 4 || version[1] >= 5)
                {
                    m_ColorSpace = reader.ReadInt32();
                }                                                                              //3.5.0 and up
            }

            image_data_size = reader.ReadInt32();

            if (m_MipMap)
            {
                dwFlags      += 0x20000;
                dwMipMapCount = Convert.ToInt32(Math.Log(Math.Max(m_Width, m_Height)) / Math.Log(2));
                dwCaps       += 0x400008;
            }

            if (image_data_size == 0 && ((version[0] == 5 && version[1] >= 3) || version[0] > 5))//5.3.0 and up
            {
                offset          = reader.ReadUInt32();
                size            = reader.ReadUInt32();
                image_data_size = (int)size;
                path            = reader.ReadAlignedString();
            }

            if (readSwitch)
            {
                if (!string.IsNullOrEmpty(path))
                {
                    var resourceFileName = Path.GetFileName(path);
                    var resourceFilePath = Path.GetDirectoryName(sourceFile.filePath) + "\\" + resourceFileName;
                    if (!File.Exists(resourceFilePath))
                    {
                        var findFiles = Directory.GetFiles(Path.GetDirectoryName(sourceFile.filePath), resourceFileName, SearchOption.AllDirectories);
                        if (findFiles.Length > 0)
                        {
                            resourceFilePath = findFiles[0];
                        }
                    }
                    if (File.Exists(resourceFilePath))
                    {
                        using (var resourceReader = new BinaryReader(File.OpenRead(resourceFilePath)))
                        {
                            resourceReader.BaseStream.Position = offset;
                            image_data = resourceReader.ReadBytes(image_data_size);
                        }
                    }
                    else
                    {
                        if (Studio.resourceFileReaders.TryGetValue(resourceFileName.ToUpper(), out var resourceReader))
                        {
                            resourceReader.Position = offset;
                            image_data = resourceReader.ReadBytes(image_data_size);
                        }
                        else
                        {
                            MessageBox.Show($"can't find the resource file {resourceFileName}");
                        }
                    }
                }
                else
                {
                    image_data = reader.ReadBytes(image_data_size);
                }

                switch (m_TextureFormat)
                {
                //TODO 导出到DDS容器时应该用原像素还是转换以后的像素?
                case TextureFormat.Alpha8:     //test pass
                {
                    /*dwFlags2 = 0x2;
                     * dwRGBBitCount = 0x8;
                     * dwRBitMask = 0x0;
                     * dwGBitMask = 0x0;
                     * dwBBitMask = 0x0;
                     * dwABitMask = 0xFF; */

                    //转BGRA32
                    var BGRA32 = Enumerable.Repeat <byte>(0xFF, image_data_size * 4).ToArray();
                    for (var i = 0; i < image_data_size; i++)
                    {
                        BGRA32[i * 4 + 3] = image_data[i];
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }

                case TextureFormat.ARGB4444:     //test pass
                {
                    SwapBytesForXbox(sourceFile.platform);

                    /*dwFlags2 = 0x41;
                     * dwRGBBitCount = 0x10;
                     * dwRBitMask = 0xF00;
                     * dwGBitMask = 0xF0;
                     * dwBBitMask = 0xF;
                     * dwABitMask = 0xF000;*/

                    //转BGRA32
                    var BGRA32 = new byte[image_data_size * 2];
                    for (var i = 0; i < image_data_size / 2; i++)
                    {
                        var pixelNew      = new byte[4];
                        var pixelOldShort = BitConverter.ToUInt16(image_data, i * 2);
                        pixelNew[0] = (byte)(pixelOldShort & 0x000f);
                        pixelNew[1] = (byte)((pixelOldShort & 0x00f0) >> 4);
                        pixelNew[2] = (byte)((pixelOldShort & 0x0f00) >> 8);
                        pixelNew[3] = (byte)((pixelOldShort & 0xf000) >> 12);
                        // convert range
                        for (var j = 0; j < 4; j++)
                        {
                            pixelNew[j] = (byte)((pixelNew[j] << 4) | pixelNew[j]);
                        }
                        pixelNew.CopyTo(BGRA32, i * 4);
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }

                case TextureFormat.RGB24:     //test pass
                {
                    /*dwFlags2 = 0x40;
                     * dwRGBBitCount = 0x18;
                     * dwRBitMask = 0xFF;
                     * dwGBitMask = 0xFF00;
                     * dwBBitMask = 0xFF0000;
                     * dwABitMask = 0x0;*/

                    //转BGRA32
                    var BGRA32 = new byte[image_data_size / 3 * 4];
                    for (var i = 0; i < image_data_size / 3; i++)
                    {
                        BGRA32[i * 4]     = image_data[i * 3 + 2];
                        BGRA32[i * 4 + 1] = image_data[i * 3 + 1];
                        BGRA32[i * 4 + 2] = image_data[i * 3 + 0];
                        BGRA32[i * 4 + 3] = 255;
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }

                case TextureFormat.RGBA32:     //test pass
                {
                    /*dwFlags2 = 0x41;
                     * dwRGBBitCount = 0x20;
                     * dwRBitMask = 0xFF;
                     * dwGBitMask = 0xFF00;
                     * dwBBitMask = 0xFF0000;
                     * dwABitMask = -16777216;*/

                    //转BGRA32
                    var BGRA32 = new byte[image_data_size];
                    for (var i = 0; i < image_data_size; i += 4)
                    {
                        BGRA32[i]     = image_data[i + 2];
                        BGRA32[i + 1] = image_data[i + 1];
                        BGRA32[i + 2] = image_data[i + 0];
                        BGRA32[i + 3] = image_data[i + 3];
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }

                case TextureFormat.ARGB32:    //test pass
                {
                    /*dwFlags2 = 0x41;
                     * dwRGBBitCount = 0x20;
                     * dwRBitMask = 0xFF00;
                     * dwGBitMask = 0xFF0000;
                     * dwBBitMask = -16777216;
                     * dwABitMask = 0xFF;*/

                    //转BGRA32
                    var BGRA32 = new byte[image_data_size];
                    for (var i = 0; i < image_data_size; i += 4)
                    {
                        BGRA32[i]     = image_data[i + 3];
                        BGRA32[i + 1] = image_data[i + 2];
                        BGRA32[i + 2] = image_data[i + 1];
                        BGRA32[i + 3] = image_data[i + 0];
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }

                case TextureFormat.RGB565:     //test pass
                {
                    SwapBytesForXbox(sourceFile.platform);

                    dwFlags2      = 0x40;
                    dwRGBBitCount = 0x10;
                    dwRBitMask    = 0xF800;
                    dwGBitMask    = 0x7E0;
                    dwBBitMask    = 0x1F;
                    dwABitMask    = 0x0;
                    break;
                }

                case TextureFormat.R16:     //test pass
                {
                    //转BGRA32
                    var BGRA32 = new byte[image_data_size * 2];
                    for (var i = 0; i < image_data_size; i += 2)
                    {
                        float f = Half.ToHalf(image_data, i);
                        BGRA32[i * 2 + 2] = (byte)Math.Ceiling(f * 255); //R
                        BGRA32[i * 2 + 3] = 255;                         //A
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }

                case TextureFormat.DXT1:         //test pass
                case TextureFormat.DXT1Crunched: //test pass
                {
                    SwapBytesForXbox(sourceFile.platform);

                    if (m_MipMap)
                    {
                        dwPitchOrLinearSize = m_Height * m_Width / 2;
                    }
                    dwFlags2      = 0x4;
                    dwFourCC      = 0x31545844;
                    dwRGBBitCount = 0x0;
                    dwRBitMask    = 0x0;
                    dwGBitMask    = 0x0;
                    dwBBitMask    = 0x0;
                    dwABitMask    = 0x0;

                    q_format = QFORMAT.Q_FORMAT_S3TC_DXT1_RGB;
                    break;
                }

                case TextureFormat.DXT5:         //test pass
                case TextureFormat.DXT5Crunched: //test pass
                {
                    SwapBytesForXbox(sourceFile.platform);

                    if (m_MipMap)
                    {
                        dwPitchOrLinearSize = m_Height * m_Width / 2;
                    }
                    dwFlags2      = 0x4;
                    dwFourCC      = 0x35545844;
                    dwRGBBitCount = 0x0;
                    dwRBitMask    = 0x0;
                    dwGBitMask    = 0x0;
                    dwBBitMask    = 0x0;
                    dwABitMask    = 0x0;

                    q_format = QFORMAT.Q_FORMAT_S3TC_DXT5_RGBA;
                    break;
                }

                case TextureFormat.RGBA4444:     //test pass
                {
                    /*dwFlags2 = 0x41;
                     * dwRGBBitCount = 0x10;
                     * dwRBitMask = 0xF000;
                     * dwGBitMask = 0xF00;
                     * dwBBitMask = 0xF0;
                     * dwABitMask = 0xF;*/

                    //转BGRA32
                    var BGRA32 = new byte[image_data_size * 2];
                    for (var i = 0; i < image_data_size / 2; i++)
                    {
                        var pixelNew      = new byte[4];
                        var pixelOldShort = BitConverter.ToUInt16(image_data, i * 2);
                        pixelNew[0] = (byte)((pixelOldShort & 0x00f0) >> 4);
                        pixelNew[1] = (byte)((pixelOldShort & 0x0f00) >> 8);
                        pixelNew[2] = (byte)((pixelOldShort & 0xf000) >> 12);
                        pixelNew[3] = (byte)(pixelOldShort & 0x000f);
                        // convert range
                        for (var j = 0; j < 4; j++)
                        {
                            pixelNew[j] = (byte)((pixelNew[j] << 4) | pixelNew[j]);
                        }
                        pixelNew.CopyTo(BGRA32, i * 4);
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }

                case TextureFormat.BGRA32:     //test pass
                {
                    dwFlags2      = 0x41;
                    dwRGBBitCount = 0x20;
                    dwRBitMask    = 0xFF0000;
                    dwGBitMask    = 0xFF00;
                    dwBBitMask    = 0xFF;
                    dwABitMask    = -16777216;
                    break;
                }

                case TextureFormat.RHalf:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_R_16F;
                    glInternalFormat     = KTXHeader.GL_R16F;
                    glBaseInternalFormat = KTXHeader.GL_RED;
                    break;
                }

                case TextureFormat.RGHalf:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_RG_HF;
                    glInternalFormat     = KTXHeader.GL_RG16F;
                    glBaseInternalFormat = KTXHeader.GL_RG;
                    break;
                }

                case TextureFormat.RGBAHalf:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_RGBA_HF;
                    glInternalFormat     = KTXHeader.GL_RGBA16F;
                    glBaseInternalFormat = KTXHeader.GL_RGBA;
                    break;
                }

                case TextureFormat.RFloat:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_R_F;
                    glInternalFormat     = KTXHeader.GL_R32F;
                    glBaseInternalFormat = KTXHeader.GL_RED;
                    break;
                }

                case TextureFormat.RGFloat:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_RG_F;
                    glInternalFormat     = KTXHeader.GL_RG32F;
                    glBaseInternalFormat = KTXHeader.GL_RG;
                    break;
                }

                case TextureFormat.RGBAFloat:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_RGBA_F;
                    glInternalFormat     = KTXHeader.GL_RGBA32F;
                    glBaseInternalFormat = KTXHeader.GL_RGBA;
                    break;
                }

                case TextureFormat.YUY2:     //test pass
                {
                    pvrPixelFormat = 17;
                    break;
                }

                case TextureFormat.RGB9e5Float:
                {
                    q_format = QFORMAT.Q_FORMAT_RGB9_E5;
                    break;
                }

                case TextureFormat.BC4:     //test pass
                {
                    texturetype          = texgenpack_texturetype.RGTC1;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RED_RGTC1;
                    glBaseInternalFormat = KTXHeader.GL_RED;
                    break;
                }

                case TextureFormat.BC5:     //test pass
                {
                    texturetype          = texgenpack_texturetype.RGTC2;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RG_RGTC2;
                    glBaseInternalFormat = KTXHeader.GL_RG;
                    break;
                }

                case TextureFormat.BC6H:     //test pass
                {
                    texturetype          = texgenpack_texturetype.BPTC_FLOAT;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT;
                    glBaseInternalFormat = KTXHeader.GL_RGB;
                    break;
                }

                case TextureFormat.BC7:     //test pass
                {
                    texturetype          = texgenpack_texturetype.BPTC;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGBA_BPTC_UNORM;
                    glBaseInternalFormat = KTXHeader.GL_RGBA;
                    break;
                }

                case TextureFormat.PVRTC_RGB2:     //test pass
                {
                    pvrPixelFormat       = 0;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
                    glBaseInternalFormat = KTXHeader.GL_RGB;
                    break;
                }

                case TextureFormat.PVRTC_RGBA2:     //test pass
                {
                    pvrPixelFormat       = 1;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
                    glBaseInternalFormat = KTXHeader.GL_RGBA;
                    break;
                }

                case TextureFormat.PVRTC_RGB4:     //test pass
                {
                    pvrPixelFormat       = 2;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
                    glBaseInternalFormat = KTXHeader.GL_RGB;
                    break;
                }

                case TextureFormat.PVRTC_RGBA4:     //test pass
                {
                    pvrPixelFormat       = 3;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
                    glBaseInternalFormat = KTXHeader.GL_RGBA;
                    break;
                }

                case TextureFormat.ETC_RGB4Crunched:
                case TextureFormat.ETC_RGB4_3DS: //test pass
                case TextureFormat.ETC_RGB4:     //test pass
                {
                    pvrPixelFormat       = 6;
                    glInternalFormat     = KTXHeader.GL_ETC1_RGB8_OES;
                    glBaseInternalFormat = KTXHeader.GL_RGB;
                    break;
                }

                case TextureFormat.ATC_RGB4:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_ATITC_RGB;
                    glInternalFormat     = KTXHeader.GL_ATC_RGB_AMD;
                    glBaseInternalFormat = KTXHeader.GL_RGB;
                    break;
                }

                case TextureFormat.ATC_RGBA8:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_ATC_RGBA_INTERPOLATED_ALPHA;
                    glInternalFormat     = KTXHeader.GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD;
                    glBaseInternalFormat = KTXHeader.GL_RGBA;
                    break;
                }

                case TextureFormat.EAC_R:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_EAC_R_UNSIGNED;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_R11_EAC;
                    glBaseInternalFormat = KTXHeader.GL_RED;
                    break;
                }

                case TextureFormat.EAC_R_SIGNED:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_EAC_R_SIGNED;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_SIGNED_R11_EAC;
                    glBaseInternalFormat = KTXHeader.GL_RED;
                    break;
                }

                case TextureFormat.EAC_RG:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_EAC_RG_UNSIGNED;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RG11_EAC;
                    glBaseInternalFormat = KTXHeader.GL_RG;
                    break;
                }

                case TextureFormat.EAC_RG_SIGNED:     //test pass
                {
                    q_format             = QFORMAT.Q_FORMAT_EAC_RG_SIGNED;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_SIGNED_RG11_EAC;
                    glBaseInternalFormat = KTXHeader.GL_RG;
                    break;
                }

                case TextureFormat.ETC2_RGB:      //test pass
                {
                    pvrPixelFormat       = 22;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGB8_ETC2;
                    glBaseInternalFormat = KTXHeader.GL_RGB;
                    break;
                }

                case TextureFormat.ETC2_RGBA1:      //test pass
                {
                    pvrPixelFormat       = 24;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
                    glBaseInternalFormat = KTXHeader.GL_RGBA;
                    break;
                }

                case TextureFormat.ETC2_RGBA8Crunched:
                case TextureFormat.ETC_RGBA8_3DS:   //test pass
                case TextureFormat.ETC2_RGBA8:      //test pass
                {
                    pvrPixelFormat       = 23;
                    glInternalFormat     = KTXHeader.GL_COMPRESSED_RGBA8_ETC2_EAC;
                    glBaseInternalFormat = KTXHeader.GL_RGBA;
                    break;
                }

                case TextureFormat.ASTC_RGB_4x4:     //test pass
                case TextureFormat.ASTC_RGBA_4x4:    //test pass
                {
                    pvrPixelFormat = 27;
                    break;
                }

                case TextureFormat.ASTC_RGB_5x5:     //test pass
                case TextureFormat.ASTC_RGBA_5x5:    //test pass
                {
                    pvrPixelFormat = 29;
                    break;
                }

                case TextureFormat.ASTC_RGB_6x6:     //test pass
                case TextureFormat.ASTC_RGBA_6x6:    //test pass
                {
                    pvrPixelFormat = 31;
                    break;
                }

                case TextureFormat.ASTC_RGB_8x8:     //test pass
                case TextureFormat.ASTC_RGBA_8x8:    //test pass
                {
                    pvrPixelFormat = 34;
                    break;
                }

                case TextureFormat.ASTC_RGB_10x10:     //test pass
                case TextureFormat.ASTC_RGBA_10x10:    //test pass
                {
                    pvrPixelFormat = 38;
                    break;
                }

                case TextureFormat.ASTC_RGB_12x12:     //test pass
                case TextureFormat.ASTC_RGBA_12x12:    //test pass
                {
                    pvrPixelFormat = 40;
                    break;
                }

                case TextureFormat.RG16:     //test pass
                {
                    //转BGRA32
                    var BGRA32 = new byte[image_data_size * 2];
                    for (var i = 0; i < image_data_size; i += 2)
                    {
                        BGRA32[i * 2 + 1] = image_data[i + 1]; //G
                        BGRA32[i * 2 + 2] = image_data[i];     //R
                        BGRA32[i * 2 + 3] = 255;               //A
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }

                case TextureFormat.R8:     //test pass
                {
                    //转BGRA32
                    var BGRA32 = new byte[image_data_size * 4];
                    for (var i = 0; i < image_data_size; i++)
                    {
                        BGRA32[i * 4 + 2] = image_data[i]; //R
                        BGRA32[i * 4 + 3] = 255;           //A
                    }
                    SetBGRA32Info(BGRA32);
                    break;
                }
                }
            }
            else
            {
                preloadData.InfoText = $"Width: {m_Width}\nHeight: {m_Height}\nFormat: ";

                string type = m_TextureFormat.ToString();
                preloadData.InfoText += type;

                switch (m_TextureFormat)
                {
                case TextureFormat.Alpha8:
                case TextureFormat.ARGB4444:
                case TextureFormat.RGB24:
                case TextureFormat.RGBA32:
                case TextureFormat.ARGB32:
                case TextureFormat.RGB565:
                case TextureFormat.R16:
                case TextureFormat.DXT1:
                case TextureFormat.DXT5:
                case TextureFormat.RGBA4444:
                case TextureFormat.BGRA32:
                case TextureFormat.RG16:
                case TextureFormat.R8:
                    preloadData.extension = ".dds"; break;

                case TextureFormat.DXT1Crunched:
                case TextureFormat.DXT5Crunched:
                case TextureFormat.ETC_RGB4Crunched:
                case TextureFormat.ETC2_RGBA8Crunched:
                    preloadData.extension = ".crn"; break;

                case TextureFormat.YUY2:
                case TextureFormat.PVRTC_RGB2:
                case TextureFormat.PVRTC_RGBA2:
                case TextureFormat.PVRTC_RGB4:
                case TextureFormat.PVRTC_RGBA4:
                case TextureFormat.ETC_RGB4:
                case TextureFormat.ETC2_RGB:
                case TextureFormat.ETC2_RGBA1:
                case TextureFormat.ETC2_RGBA8:
                case TextureFormat.ASTC_RGB_4x4:
                case TextureFormat.ASTC_RGB_5x5:
                case TextureFormat.ASTC_RGB_6x6:
                case TextureFormat.ASTC_RGB_8x8:
                case TextureFormat.ASTC_RGB_10x10:
                case TextureFormat.ASTC_RGB_12x12:
                case TextureFormat.ASTC_RGBA_4x4:
                case TextureFormat.ASTC_RGBA_5x5:
                case TextureFormat.ASTC_RGBA_6x6:
                case TextureFormat.ASTC_RGBA_8x8:
                case TextureFormat.ASTC_RGBA_10x10:
                case TextureFormat.ASTC_RGBA_12x12:
                case TextureFormat.ETC_RGB4_3DS:
                case TextureFormat.ETC_RGBA8_3DS:
                    preloadData.extension = ".pvr"; break;

                case TextureFormat.RHalf:
                case TextureFormat.RGHalf:
                case TextureFormat.RGBAHalf:
                case TextureFormat.RFloat:
                case TextureFormat.RGFloat:
                case TextureFormat.RGBAFloat:
                case TextureFormat.BC4:
                case TextureFormat.BC5:
                case TextureFormat.BC6H:
                case TextureFormat.BC7:
                case TextureFormat.ATC_RGB4:
                case TextureFormat.ATC_RGBA8:
                case TextureFormat.EAC_R:
                case TextureFormat.EAC_R_SIGNED:
                case TextureFormat.EAC_RG:
                case TextureFormat.EAC_RG_SIGNED:
                    preloadData.extension = ".ktx"; break;

                default:
                    preloadData.extension = ".tex"; break;
                }

                switch (m_FilterMode)
                {
                case 0: preloadData.InfoText += "\nFilter Mode: Point "; break;

                case 1: preloadData.InfoText += "\nFilter Mode: Bilinear "; break;

                case 2: preloadData.InfoText += "\nFilter Mode: Trilinear "; break;
                }

                preloadData.InfoText += $"\nAnisotropic level: {m_Aniso}\nMip map bias: {m_MipBias}";

                switch (m_WrapMode)
                {
                case 0: preloadData.InfoText += "\nWrap mode: Repeat"; break;

                case 1: preloadData.InfoText += "\nWrap mode: Clamp"; break;
                }

                preloadData.Text = m_Name;
                if (!string.IsNullOrEmpty(path))
                {
                    preloadData.fullSize = preloadData.Size + (int)size;
                }
            }
        }
示例#25
0
        protected virtual void InitData()
        {
            Debug.Assert(SystemInfo.SupportsRenderTextureFormat(TextureFormat), "The graphics device does not support the render texture format " + TextureFormat.ToString());

            Debug.Assert(OceanRenderer.Instance.CurrentLodCount <= MAX_LOD_COUNT);

            var resolution = OceanRenderer.Instance.LodDataResolution;
            var desc       = new RenderTextureDescriptor(resolution, resolution, TextureFormat, 0);

            _targets = CreateLodDataTextures(desc, SimName, NeedToReadWriteTextureData);

            // Bind globally once here on init, which will bind to all graphics shaders (not compute)
            Shader.SetGlobalTexture(GetParamIdSampler(), _targets);
        }
        protected override void InitData()
        {
            base.InitData();

            Debug.Assert(SystemInfo.SupportsRenderTextureFormat(TextureFormat), "The graphics device does not support the render texture format " + TextureFormat.ToString());

            int resolution = OceanRenderer.Instance.LodDataResolution;
            var desc       = new RenderTextureDescriptor(resolution, resolution, TextureFormat, 0);

            _sources = new RenderTexture[OceanRenderer.Instance.CurrentLodCount];
            for (int i = 0; i < _sources.Length; i++)
            {
                _sources[i]              = new RenderTexture(desc);
                _sources[i].wrapMode     = TextureWrapMode.Clamp;
                _sources[i].antiAliasing = 1;
                _sources[i].filterMode   = FilterMode.Bilinear;
                _sources[i].anisoLevel   = 0;
                _sources[i].useMipMap    = false;
                _sources[i].name         = SimName + "_" + i + "_1";
            }
        }
示例#27
0
 public override string ToString()
 {
     return(string.Format("0x{0} {1}x{2}-{3} format:{4} propertyNameId:{5}", m_NativeTexture.ToString("X16"),
                          m_Width.ToString(), m_Height.ToString(), m_MipmapCount.ToString(),
                          m_Format.ToString(), m_PropertyNameId.ToString()));
 }
 void append(StringBuilder sb, TextureFormat fmt)
 {
     sb.Append(fmt.ToString() + "\t\t" + SystemInfo.SupportsTextureFormat(fmt) + "\n");
 }
示例#29
0
 internal bool ValidateFormat(TextureFormat format)
 {
     if (SystemInfo.SupportsTextureFormat(format))
     {
         return(true);
     }
     else if (GraphicsFormatUtility.IsCompressedTextureFormat(format))
     {
         Debug.LogWarning(String.Format("'{0}' is not supported on this platform. Decompressing texture. Use 'SystemInfo.SupportsTextureFormat' C# API to check format support.", format.ToString()), this);
         return(true);
     }
     else
     {
         Debug.LogError(String.Format("Texture creation failed. '{0}' is not supported on this platform. Use 'SystemInfo.SupportsTextureFormat' C# API to check format support.", format.ToString()), this);
         return(false);
     }
 }
示例#30
0
    /// <summary>
    /// 获取当前平台纹理的格式
    /// </summary>
    public static string GetTextureFormatString(Texture tex)
    {
        TextureFormat format = (TextureFormat)InvokeStaticMethod("UnityEditor.TextureUtil", "GetTextureFormat", tex);

        return(format.ToString());
    }