MCPcopy Create free account
hub / github.com/defold/defold / GetSupportedCompressionFormatForType

Function GetSupportedCompressionFormatForType

engine/graphics/src/graphics.cpp:1018–1065  ·  view source on GitHub ↗

The goal is to find a supported compression format, since they're smaller than the uncompressed ones The user can also choose RGB(a) 16BPP as the fallback if they wish to have smaller size than full RGB(a)

Source from the content-addressed store, hash-verified

1016 // The goal is to find a supported compression format, since they're smaller than the uncompressed ones
1017 // The user can also choose RGB(a) 16BPP as the fallback if they wish to have smaller size than full RGB(a)
1018 dmGraphics::TextureFormat GetSupportedCompressionFormatForType(dmGraphics::HContext context, dmGraphics::TextureFormat format, uint32_t width, uint32_t height, TextureType type)
1019 {
1020 #define TEST_AND_RETURN(_TYPEN_ENUM) if (dmGraphics::IsTextureFormatSupported(context, (_TYPEN_ENUM))) return (_TYPEN_ENUM);
1021 #define TEST_AND_RETURN_FOR_TYPE(_TYPEN_ENUM) if (dmGraphics::IsTextureFormatSupportedForType(context, type, (_TYPEN_ENUM))) return (_TYPEN_ENUM);
1022
1023 if (IsFormatRGBA(format))
1024 {
1025 TEST_AND_RETURN(dmGraphics::TEXTURE_FORMAT_RGBA_BC7);
1026 TEST_AND_RETURN_FOR_TYPE(dmGraphics::TEXTURE_FORMAT_RGBA_ASTC_4X4);
1027 TEST_AND_RETURN(dmGraphics::TEXTURE_FORMAT_RGBA_ETC2);
1028 if (width == height) {
1029 TEST_AND_RETURN(dmGraphics::TEXTURE_FORMAT_RGBA_PVRTC_4BPPV1);
1030 }
1031 TEST_AND_RETURN(format);
1032 return dmGraphics::TEXTURE_FORMAT_RGBA;
1033 }
1034
1035 if (IsFormatRGB(format))
1036 {
1037 TEST_AND_RETURN(dmGraphics::TEXTURE_FORMAT_RGB_BC1);
1038 TEST_AND_RETURN(dmGraphics::TEXTURE_FORMAT_RGB_ETC1);
1039 if (width == height) {
1040 TEST_AND_RETURN(dmGraphics::TEXTURE_FORMAT_RGB_PVRTC_4BPPV1);
1041 }
1042 TEST_AND_RETURN(format);
1043 return dmGraphics::TEXTURE_FORMAT_RGB;
1044 }
1045
1046 if (IsFormatRG(format))
1047 {
1048 TEST_AND_RETURN(dmGraphics::TEXTURE_FORMAT_RG_BC5);
1049 TEST_AND_RETURN(dmGraphics::TEXTURE_FORMAT_RG_ETC2);
1050 TEST_AND_RETURN(format);
1051 return dmGraphics::TEXTURE_FORMAT_LUMINANCE_ALPHA;
1052 }
1053
1054 if (IsFormatR(format))
1055 {
1056 TEST_AND_RETURN(dmGraphics::TEXTURE_FORMAT_R_BC4);
1057 TEST_AND_RETURN(dmGraphics::TEXTURE_FORMAT_R_ETC2);
1058 TEST_AND_RETURN(format);
1059 return dmGraphics::TEXTURE_FORMAT_LUMINANCE;
1060 }
1061
1062 #undef TEST_AND_RETURN
1063 #undef TEST_AND_RETURN_FOR_TYPE
1064 return format;
1065 }
1066
1067 dmGraphics::TextureFormat GetSupportedCompressionFormat(dmGraphics::HContext context, dmGraphics::TextureFormat format, uint32_t width, uint32_t height)
1068 {

Callers 3

CreateImageFunction · 0.85
CreateTextureAsyncFunction · 0.85

Calls 4

IsFormatRGBAFunction · 0.85
IsFormatRGBFunction · 0.85
IsFormatRGFunction · 0.85
IsFormatRFunction · 0.85

Tested by

no test coverage detected