Skip to content

Commit 14a8086

Browse files
committed
Add command to log texture format support
Interesting to get information of what formats are supported by the platform you are targeting (e.g. ASTC support)
1 parent 45f0299 commit 14a8086

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Assets/Plugins/WebGL/WebGLTools/WebGlBridge.Commands.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// </author>
99
// --------------------------------------------------------------------------------------------------------------------
1010

11+
using System;
12+
using System.Collections.Generic;
1113
using Supyrb.Attributes;
1214
using UnityEngine;
1315

@@ -125,5 +127,39 @@ public void LogMessage(string message)
125127
{
126128
Debug.Log(message);
127129
}
130+
131+
/// <summary>
132+
/// Log information of all texture formats that Unity supports, which ones are supported by
133+
/// the current platform and browser, and which ones are not supported
134+
/// </summary>
135+
[WebGlCommand(Description = "Log supported and unsupported texture formats")]
136+
public void LogTextureSupport()
137+
{
138+
List<TextureFormat> supportedFormats = new List<TextureFormat>();
139+
List<TextureFormat> unsupportedFormats = new List<TextureFormat>();
140+
141+
foreach (TextureFormat textureFormat in Enum.GetValues(typeof(TextureFormat)))
142+
{
143+
var memberInfos = typeof(TextureFormat).GetMember(textureFormat.ToString());
144+
object[] obsoleteAttributes = memberInfos[0].GetCustomAttributes(typeof(ObsoleteAttribute), false);
145+
if (obsoleteAttributes.Length > 0)
146+
{
147+
// don't evaluate obsolete enum values
148+
continue;
149+
}
150+
151+
if (SystemInfo.SupportsTextureFormat(textureFormat))
152+
{
153+
supportedFormats.Add(textureFormat);
154+
}
155+
else
156+
{
157+
unsupportedFormats.Add(textureFormat);
158+
}
159+
}
160+
161+
Debug.Log($"Supported Texture formats: \n{string.Join(", ", supportedFormats)}");
162+
Debug.Log($"Unsupported Texture formats: \n{string.Join(", ", unsupportedFormats)}");
163+
}
128164
}
129165
}

0 commit comments

Comments
 (0)