diff options
author | 2019-10-13 13:50:38 +0200 | |
---|---|---|
committer | 2019-10-13 07:50:38 -0400 | |
commit | 0837e7451a84f95c29dbdb9bd6b8b931fee1635d (patch) | |
tree | 626bcbd250a7fbebdf5958a288d2f438d4f9fb5a /3rdparty/bimg/src/image_encode.cpp | |
parent | c913ccb59d713ce0b91135520719ac5385e54358 (diff) |
WIP: sync bgfx, bx and bimg with latest upstream (#5723)
* Sync with bgfx upstream revision b91d0b6
* Sync with bx upstream revision d60912b
* Sync with bimg upstream revision bd81f60
* Add astc-codec decoder
* Rename VertexDecl to VertexLayout
* Rename UniformType enum Int1 to Sampler.
* Add NVN stub
* Fix unused-const-variable error on macOS
* Drop redundant explicit language parameters
buildoptions_cpp are only applied to c++ files and buildoptions_objcpp are only
applied to objective c++ files. As such, hardcoding -x offers no benefit while
preventing overrides (such as one needed by 3rdparty/bgfx/src/renderer_vk.cpp on
macOS) from working.
* Re-introduce -x c++ in places where C code is compiled as C++ to prevent clang from throwing a warning
* Build bgfx as Objective-C++ on macOS
It is needed due to included headers
* Enable Direct3D12 and Vulkan bgfx rendering backends
* Enable building of spirv shaders
* Properly escape /c in cmd call
* Comment out dx12 bgfx renderer
* Honor VERBOSE setting during shaders build
* Only invert hlsl shader XYZ_TO_sRGB matrix for opengl
* Add spirv shaders
* OpenGL ES needs transposed matrix too
* Metal needs transposed matrix as well
Diffstat (limited to '3rdparty/bimg/src/image_encode.cpp')
-rw-r--r-- | 3rdparty/bimg/src/image_encode.cpp | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/3rdparty/bimg/src/image_encode.cpp b/3rdparty/bimg/src/image_encode.cpp index 09586fe5105..7d24cc5d672 100644 --- a/3rdparty/bimg/src/image_encode.cpp +++ b/3rdparty/bimg/src/image_encode.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bimg#license-bsd-2-clause */ @@ -30,19 +30,29 @@ namespace bimg { static uint32_t s_squishQuality[] = { + // Standard + squish::kColourClusterFit, // Default + squish::kColourIterativeClusterFit, // Highest + squish::kColourRangeFit, // Fastest + // Normal map squish::kColourClusterFit, // Default squish::kColourIterativeClusterFit, // Highest squish::kColourRangeFit, // Fastest }; BX_STATIC_ASSERT(Quality::Count == BX_COUNTOF(s_squishQuality) ); - static const ASTC_COMPRESS_MODE s_astcQuality[] = - { - ASTC_COMPRESS_MEDIUM, // Default - ASTC_COMPRESS_THOROUGH, // Highest - ASTC_COMPRESS_FAST, // Fastest - }; - BX_STATIC_ASSERT(Quality::Count == BX_COUNTOF(s_astcQuality)); + static const ASTC_COMPRESS_MODE s_astcQuality[] = + { + // Standard + ASTC_COMPRESS_MEDIUM, // Default + ASTC_COMPRESS_THOROUGH, // Highest + ASTC_COMPRESS_FAST, // Fastest + // Normal map + ASTC_COMPRESS_MEDIUM, // Default + ASTC_COMPRESS_THOROUGH, // Highest + ASTC_COMPRESS_FAST, // Fastest + }; + BX_STATIC_ASSERT(Quality::Count == BX_COUNTOF(s_astcQuality)); void imageEncodeFromRgba8(bx::AllocatorI* _allocator, void* _dst, const void* _src, uint32_t _width, uint32_t _height, uint32_t _depth, TextureFormat::Enum _format, Quality::Enum _quality, bx::Error* _err) { @@ -138,12 +148,19 @@ namespace bimg case TextureFormat::ASTC8x6: case TextureFormat::ASTC10x5: { - const bimg::ImageBlockInfo& astcBlockInfo = bimg::getBlockInfo(_format); + const bimg::ImageBlockInfo& astcBlockInfo = bimg::getBlockInfo(_format); - ASTC_COMPRESS_MODE compress_mode = s_astcQuality[_quality]; - ASTC_DECODE_MODE decode_mode = ASTC_DECODE_LDR_LINEAR; + ASTC_COMPRESS_MODE compress_mode = s_astcQuality[_quality]; + ASTC_DECODE_MODE decode_mode = ASTC_DECODE_LDR_LINEAR; - astc_compress(_width, _height, src, ASTC_RGBA, srcPitch, astcBlockInfo.blockWidth, astcBlockInfo.blockHeight, compress_mode, decode_mode, dst); + if (Quality::NormalMapDefault <= _quality) + { + astc_compress(_width, _height, src, ASTC_ENC_NORMAL_RA, srcPitch, astcBlockInfo.blockWidth, astcBlockInfo.blockHeight, compress_mode, decode_mode, dst); + } + else + { + astc_compress(_width, _height, src, ASTC_RGBA, srcPitch, astcBlockInfo.blockWidth, astcBlockInfo.blockHeight, compress_mode, decode_mode, dst); + } } break; @@ -152,7 +169,7 @@ namespace bimg break; case TextureFormat::RGBA8: - bx::memCopy(_dst, _src, srcPitch, _height, srcPitch, dstPitch); + bx::memCopy(_dst, dstPitch, _src, srcPitch, srcPitch, _height); break; default: @@ -490,7 +507,7 @@ namespace bimg return rgba[3]; } - float imageAlphaTestCoverage(TextureFormat::Enum _format, uint32_t _width, uint32_t _height, uint32_t _srcPitch, const void* _src, float _alphaRef, float _scale) + float imageAlphaTestCoverage(TextureFormat::Enum _format, uint32_t _width, uint32_t _height, uint32_t _srcPitch, const void* _src, float _alphaRef, float _scale, uint32_t _upscale) { UnpackFn unpack = getUnpack(_format); if (NULL == unpack) @@ -501,7 +518,8 @@ namespace bimg float coverage = 0.0f; const uint8_t* src = (const uint8_t*)_src; const uint32_t xstep = getBitsPerPixel(_format) / 8; - const float numSamples = 8.0f; + const uint32_t numSamples = _upscale; + const float sampleStep = 1.0f / numSamples; for (uint32_t yy = 0, ystep = _srcPitch; yy < _height-1; ++yy, src += ystep) { @@ -513,9 +531,9 @@ namespace bimg float alpha01 = _scale * getAlpha(unpack, data+ystep); float alpha11 = _scale * getAlpha(unpack, data+ystep+xstep); - for (float fy = 0.5f/numSamples; fy < 1.0f; fy += 1.0f) + for (float fy = 0.0f; fy < 1.0f; fy += sampleStep) { - for (float fx = 0.5f/numSamples; fx < 1.0f; fx += 1.0f) + for (float fx = 0.0f; fx < 1.0f; fx += sampleStep) { float alpha = 0.0f + alpha00 * (1.0f - fx) * (1.0f - fy) @@ -536,7 +554,7 @@ namespace bimg return coverage / float(_width*_height*numSamples*numSamples); } - void imageScaleAlphaToCoverage(TextureFormat::Enum _format, uint32_t _width, uint32_t _height, uint32_t _srcPitch, void* _src, float _desiredCoverage, float _alphaRef) + void imageScaleAlphaToCoverage(TextureFormat::Enum _format, uint32_t _width, uint32_t _height, uint32_t _srcPitch, void* _src, float _desiredCoverage, float _alphaRef, uint32_t _upscale) { PackFn pack = getPack(_format); UnpackFn unpack = getUnpack(_format); @@ -550,7 +568,7 @@ namespace bimg float max = 4.0f; float scale = 1.0f; - for (uint32_t ii = 0; ii < 8; ++ii) + for (uint32_t ii = 0; ii < 10; ++ii) { float coverage = imageAlphaTestCoverage( _format @@ -560,6 +578,7 @@ namespace bimg , _src , _alphaRef , scale + , _upscale ); if (coverage < _desiredCoverage) |