com.crashinvaders.basisu.wrapper.BasisuTranscoderTextureFormatSupportIndex Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of basisu-wrapper Show documentation
Show all versions of basisu-wrapper Show documentation
Java wrapper for Basis Universal texture transcoder native code.
The newest version!
package com.crashinvaders.basisu.wrapper;
import java.util.*;
/**
* Keeps track of {@link BasisuTranscoderTextureFormat} support for the current platform.
*
* The sole purpose of this class is to cache the index of supported formats and avoid frequent calls to the native based
* {@link BasisuWrapper#isTranscoderTexFormatSupported(BasisuTranscoderTextureFormat, BasisuTextureFormat)} method
* everytime we need to check if the transcoder texture is supported.
*/
public class BasisuTranscoderTextureFormatSupportIndex {
static final HashMap> supportMap = new HashMap<>();
/**
* Checks weather the transcoder can transcode to the specified texture format.
*/
public synchronized static boolean isTextureFormatSupported(BasisuTranscoderTextureFormat textureFormat, BasisuTextureFormat basisTexFormat) {
return getSupportedTextureFormats(basisTexFormat).contains(textureFormat);
}
/**
* Returns a list of the texture formats that the transcoder can transcode to.
* Basis Universal library is compiled with some transcode tables excluded per platform to save up space.
*/
public synchronized static Set getSupportedTextureFormats(BasisuTextureFormat basisTexFormat) {
Set supportIndex = supportMap.get(basisTexFormat);
if (supportIndex == null) {
supportIndex = new HashSet<>();
collectSupportedTextureFormats(basisTexFormat, supportIndex);
supportMap.put(basisTexFormat, supportIndex);
}
return supportIndex;
}
private static void collectSupportedTextureFormats(BasisuTextureFormat basisTexFormat, Set result) {
for (BasisuTranscoderTextureFormat format : BasisuTranscoderTextureFormat.values()) {
if (BasisuWrapper.isTranscoderTexFormatSupported(format, basisTexFormat)) {
result.add(format);
}
}
}
}