Commit b6d684ec by Rémi Verschelde

basis_universal: Update to upstream commit from Jan 4, 2020

BinomialLLC/basis_universal@895ee8ee7e04f22267f8d16d46de04d5a01d63ac.
parent ef51726f
...@@ -91,7 +91,7 @@ static PoolVector<uint8_t> basis_universal_packer(const Ref<Image> &p_image, Ima ...@@ -91,7 +91,7 @@ static PoolVector<uint8_t> basis_universal_packer(const Ref<Image> &p_image, Ima
//params.m_quality_level = 0; //params.m_quality_level = 0;
//params.m_disable_hierarchical_endpoint_codebooks = true; //params.m_disable_hierarchical_endpoint_codebooks = true;
//params.m_no_selector_rdo = true; //params.m_no_selector_rdo = true;
params.m_no_auto_global_sel_pal = true; params.m_auto_global_sel_pal = false;
basisu::job_pool jpool(OS::get_singleton()->get_processor_count()); basisu::job_pool jpool(OS::get_singleton()->get_processor_count());
params.m_pJob_pool = &jpool; params.m_pJob_pool = &jpool;
...@@ -170,13 +170,13 @@ static Ref<Image> basis_universal_unpacker(const PoolVector<uint8_t> &p_buffer) ...@@ -170,13 +170,13 @@ static Ref<Image> basis_universal_unpacker(const PoolVector<uint8_t> &p_buffer)
case BASIS_DECOMPRESS_RG: { case BASIS_DECOMPRESS_RG: {
if (VS::get_singleton()->has_os_feature("rgtc")) { if (VS::get_singleton()->has_os_feature("rgtc")) {
format = basist::cTFBC5; // get this from renderer format = basist::transcoder_texture_format::cTFBC5; // get this from renderer
imgfmt = Image::FORMAT_RGTC_RG; imgfmt = Image::FORMAT_RGTC_RG;
} else if (VS::get_singleton()->has_os_feature("etc2")) { } else if (VS::get_singleton()->has_os_feature("etc2")) {
//unfortunately, basis universal does not support //unfortunately, basis universal does not support
// //
ERR_FAIL_V(image); //unimplemented here ERR_FAIL_V(image); //unimplemented here
//format = basist::cTFETC1; // get this from renderer //format = basist::transcoder_texture_format::cTFETC1; // get this from renderer
//imgfmt = Image::FORMAT_RGTC_RG; //imgfmt = Image::FORMAT_RGTC_RG;
} else { } else {
//decompress //decompress
...@@ -184,47 +184,47 @@ static Ref<Image> basis_universal_unpacker(const PoolVector<uint8_t> &p_buffer) ...@@ -184,47 +184,47 @@ static Ref<Image> basis_universal_unpacker(const PoolVector<uint8_t> &p_buffer)
} break; } break;
case BASIS_DECOMPRESS_RGB: { case BASIS_DECOMPRESS_RGB: {
if (VS::get_singleton()->has_os_feature("bptc")) { if (VS::get_singleton()->has_os_feature("bptc")) {
format = basist::cTFBC7_M6_OPAQUE_ONLY; // get this from renderer format = basist::transcoder_texture_format::cTFBC7_M6_OPAQUE_ONLY; // get this from renderer
imgfmt = Image::FORMAT_BPTC_RGBA; imgfmt = Image::FORMAT_BPTC_RGBA;
} else if (VS::get_singleton()->has_os_feature("s3tc")) { } else if (VS::get_singleton()->has_os_feature("s3tc")) {
format = basist::cTFBC1; // get this from renderer format = basist::transcoder_texture_format::cTFBC1; // get this from renderer
imgfmt = Image::FORMAT_DXT1; imgfmt = Image::FORMAT_DXT1;
} else if (VS::get_singleton()->has_os_feature("etc")) { } else if (VS::get_singleton()->has_os_feature("etc")) {
format = basist::cTFETC1; // get this from renderer format = basist::transcoder_texture_format::cTFETC1; // get this from renderer
imgfmt = Image::FORMAT_ETC; imgfmt = Image::FORMAT_ETC;
} else { } else {
format = basist::cTFBGR565; // get this from renderer format = basist::transcoder_texture_format::cTFBGR565; // get this from renderer
imgfmt = Image::FORMAT_RGB565; imgfmt = Image::FORMAT_RGB565;
} }
} break; } break;
case BASIS_DECOMPRESS_RGBA: { case BASIS_DECOMPRESS_RGBA: {
if (VS::get_singleton()->has_os_feature("bptc")) { if (VS::get_singleton()->has_os_feature("bptc")) {
format = basist::cTFBC7_M5; // get this from renderer format = basist::transcoder_texture_format::cTFBC7_M5; // get this from renderer
imgfmt = Image::FORMAT_BPTC_RGBA; imgfmt = Image::FORMAT_BPTC_RGBA;
} else if (VS::get_singleton()->has_os_feature("s3tc")) { } else if (VS::get_singleton()->has_os_feature("s3tc")) {
format = basist::cTFBC3; // get this from renderer format = basist::transcoder_texture_format::cTFBC3; // get this from renderer
imgfmt = Image::FORMAT_DXT5; imgfmt = Image::FORMAT_DXT5;
} else if (VS::get_singleton()->has_os_feature("etc2")) { } else if (VS::get_singleton()->has_os_feature("etc2")) {
format = basist::cTFETC2; // get this from renderer format = basist::transcoder_texture_format::cTFETC2; // get this from renderer
imgfmt = Image::FORMAT_ETC2_RGBA8; imgfmt = Image::FORMAT_ETC2_RGBA8;
} else { } else {
//gles2 most likely //gles2 most likely
format = basist::cTFRGBA4444; // get this from renderer format = basist::transcoder_texture_format::cTFRGBA4444; // get this from renderer
imgfmt = Image::FORMAT_RGBA4444; imgfmt = Image::FORMAT_RGBA4444;
} }
} break; } break;
case BASIS_DECOMPRESS_RG_AS_RA: { case BASIS_DECOMPRESS_RG_AS_RA: {
if (VS::get_singleton()->has_os_feature("s3tc")) { if (VS::get_singleton()->has_os_feature("s3tc")) {
format = basist::cTFBC3; // get this from renderer format = basist::transcoder_texture_format::cTFBC3; // get this from renderer
imgfmt = Image::FORMAT_DXT5_RA_AS_RG; imgfmt = Image::FORMAT_DXT5_RA_AS_RG;
} else if (VS::get_singleton()->has_os_feature("etc2")) { } else if (VS::get_singleton()->has_os_feature("etc2")) {
format = basist::cTFETC2; // get this from renderer format = basist::transcoder_texture_format::cTFETC2; // get this from renderer
imgfmt = Image::FORMAT_ETC2_RGBA8; imgfmt = Image::FORMAT_ETC2_RGBA8;
} else { } else {
//gles2 most likely, bad for normalmaps, nothing to do about this. //gles2 most likely, bad for normalmaps, nothing to do about this.
format = basist::cTFRGBA32; format = basist::transcoder_texture_format::cTFRGBA32;
imgfmt = Image::FORMAT_RGBA8; imgfmt = Image::FORMAT_RGBA8;
} }
} break; } break;
......
...@@ -16,7 +16,7 @@ Subcategories (`###` level) where needed are separated by a single empty line. ...@@ -16,7 +16,7 @@ Subcategories (`###` level) where needed are separated by a single empty line.
## basis_universal ## basis_universal
- Upstream: https://github.com/BinomialLLC/basis_universal - Upstream: https://github.com/BinomialLLC/basis_universal
- Version: git (6afb2fc, 2019) - Version: git (895ee8e, 2020)
- License: Apache 2.0 - License: Apache 2.0
Files extracted from upstream source: Files extracted from upstream source:
......
...@@ -597,7 +597,7 @@ namespace basisu ...@@ -597,7 +597,7 @@ namespace basisu
const uint32_t num_blocks_y = m_slices[slice_index].m_num_blocks_y; const uint32_t num_blocks_y = m_slices[slice_index].m_num_blocks_y;
gpu_image gi; gpu_image gi;
gi.init(cETC1, width, height); gi.init(texture_format::cETC1, width, height);
for (uint32_t block_y = 0; block_y < num_blocks_y; block_y++) for (uint32_t block_y = 0; block_y < num_blocks_y; block_y++)
{ {
......
...@@ -32,7 +32,7 @@ namespace basisu ...@@ -32,7 +32,7 @@ namespace basisu
for (uint32_t i = 0; i < encoder_output.m_slice_desc.size(); i++) for (uint32_t i = 0; i < encoder_output.m_slice_desc.size(); i++)
m_header.m_total_images = maximum<uint32_t>(m_header.m_total_images, encoder_output.m_slice_desc[i].m_source_file_index + 1); m_header.m_total_images = maximum<uint32_t>(m_header.m_total_images, encoder_output.m_slice_desc[i].m_source_file_index + 1);
m_header.m_format = basist::cETC1; m_header.m_format = 0;// basist::block_format::cETC1;
m_header.m_flags = 0; m_header.m_flags = 0;
if (encoder_output.m_etc1s) if (encoder_output.m_etc1s)
......
...@@ -57,7 +57,7 @@ namespace basisu ...@@ -57,7 +57,7 @@ namespace basisu
PRINT_BOOL_VALUE(m_debug); PRINT_BOOL_VALUE(m_debug);
PRINT_BOOL_VALUE(m_debug_images); PRINT_BOOL_VALUE(m_debug_images);
PRINT_BOOL_VALUE(m_global_sel_pal); PRINT_BOOL_VALUE(m_global_sel_pal);
PRINT_BOOL_VALUE(m_no_auto_global_sel_pal); PRINT_BOOL_VALUE(m_auto_global_sel_pal);
PRINT_BOOL_VALUE(m_compression_level); PRINT_BOOL_VALUE(m_compression_level);
PRINT_BOOL_VALUE(m_no_hybrid_sel_cb); PRINT_BOOL_VALUE(m_no_hybrid_sel_cb);
PRINT_BOOL_VALUE(m_perceptual); PRINT_BOOL_VALUE(m_perceptual);
...@@ -774,7 +774,7 @@ namespace basisu ...@@ -774,7 +774,7 @@ namespace basisu
} }
m_auto_global_sel_pal = false; m_auto_global_sel_pal = false;
if (!m_params.m_global_sel_pal && !m_params.m_no_auto_global_sel_pal) if (!m_params.m_global_sel_pal && m_params.m_auto_global_sel_pal)
{ {
const float bits_per_selector_cluster = 31.0f; const float bits_per_selector_cluster = 31.0f;
double selector_codebook_bpp_est = (bits_per_selector_cluster * selector_clusters) / total_texels; double selector_codebook_bpp_est = (bits_per_selector_cluster * selector_clusters) / total_texels;
...@@ -860,7 +860,7 @@ namespace basisu ...@@ -860,7 +860,7 @@ namespace basisu
const uint32_t width = num_blocks_x * 4; const uint32_t width = num_blocks_x * 4;
const uint32_t height = num_blocks_y * 4; const uint32_t height = num_blocks_y * 4;
m_frontend_output_textures[i].init(cETC1, width, height); m_frontend_output_textures[i].init(texture_format::cETC1, width, height);
for (uint32_t block_y = 0; block_y < num_blocks_y; block_y++) for (uint32_t block_y = 0; block_y < num_blocks_y; block_y++)
for (uint32_t block_x = 0; block_x < num_blocks_x; block_x++) for (uint32_t block_x = 0; block_x < num_blocks_x; block_x++)
...@@ -875,7 +875,7 @@ namespace basisu ...@@ -875,7 +875,7 @@ namespace basisu
} }
#endif #endif
m_best_etc1s_images[i].init(cETC1, width, height); m_best_etc1s_images[i].init(texture_format::cETC1, width, height);
for (uint32_t block_y = 0; block_y < num_blocks_y; block_y++) for (uint32_t block_y = 0; block_y < num_blocks_y; block_y++)
for (uint32_t block_x = 0; block_x < num_blocks_x; block_x++) for (uint32_t block_x = 0; block_x < num_blocks_x; block_x++)
memcpy(m_best_etc1s_images[i].get_block_ptr(block_x, block_y, 0), &m_frontend.get_etc1s_block(slice_desc.m_first_block_index + block_x + block_y * num_blocks_x), sizeof(etc_block)); memcpy(m_best_etc1s_images[i].get_block_ptr(block_x, block_y, 0), &m_frontend.get_etc1s_block(slice_desc.m_first_block_index + block_x + block_y * num_blocks_x), sizeof(etc_block));
...@@ -970,12 +970,12 @@ namespace basisu ...@@ -970,12 +970,12 @@ namespace basisu
for (uint32_t i = 0; i < m_slice_descs.size(); i++) for (uint32_t i = 0; i < m_slice_descs.size(); i++)
{ {
gpu_image decoded_texture; gpu_image decoded_texture;
decoded_texture.init(cETC1, m_slice_descs[i].m_width, m_slice_descs[i].m_height); decoded_texture.init(texture_format::cETC1, m_slice_descs[i].m_width, m_slice_descs[i].m_height);
tm.start(); tm.start();
if (!decoder.transcode_slice(&comp_data[0], (uint32_t)comp_data.size(), i, if (!decoder.transcode_slice(&comp_data[0], (uint32_t)comp_data.size(), i,
reinterpret_cast<etc_block *>(decoded_texture.get_ptr()), m_slice_descs[i].m_num_blocks_x * m_slice_descs[i].m_num_blocks_y, basist::cETC1, 8)) reinterpret_cast<etc_block *>(decoded_texture.get_ptr()), m_slice_descs[i].m_num_blocks_x * m_slice_descs[i].m_num_blocks_y, basist::block_format::cETC1, 8))
{ {
error_printf("Transcoding failed to ETC1 on slice %u!\n", i); error_printf("Transcoding failed to ETC1 on slice %u!\n", i);
return false; return false;
...@@ -1008,12 +1008,12 @@ namespace basisu ...@@ -1008,12 +1008,12 @@ namespace basisu
for (uint32_t i = 0; i < m_slice_descs.size(); i++) for (uint32_t i = 0; i < m_slice_descs.size(); i++)
{ {
gpu_image decoded_texture; gpu_image decoded_texture;
decoded_texture.init(cBC1, m_slice_descs[i].m_width, m_slice_descs[i].m_height); decoded_texture.init(texture_format::cBC1, m_slice_descs[i].m_width, m_slice_descs[i].m_height);
tm.start(); tm.start();
if (!decoder.transcode_slice(&comp_data[0], (uint32_t)comp_data.size(), i, if (!decoder.transcode_slice(&comp_data[0], (uint32_t)comp_data.size(), i,
reinterpret_cast<etc_block *>(decoded_texture.get_ptr()), m_slice_descs[i].m_num_blocks_x * m_slice_descs[i].m_num_blocks_y, basist::cBC1, 8)) reinterpret_cast<etc_block *>(decoded_texture.get_ptr()), m_slice_descs[i].m_num_blocks_x * m_slice_descs[i].m_num_blocks_y, basist::block_format::cBC1, 8))
{ {
error_printf("Transcoding failed to BC1 on slice %u!\n", i); error_printf("Transcoding failed to BC1 on slice %u!\n", i);
return false; return false;
...@@ -1066,9 +1066,7 @@ namespace basisu ...@@ -1066,9 +1066,7 @@ namespace basisu
{ {
const uint8_vec &comp_data = m_basis_file.get_compressed_data(); const uint8_vec &comp_data = m_basis_file.get_compressed_data();
std::string basis_filename(m_params.m_out_filename); const std::string& basis_filename = m_params.m_out_filename;
string_remove_extension(basis_filename);
basis_filename += ".basis";
if (!write_vec_to_file(basis_filename.c_str(), comp_data)) if (!write_vec_to_file(basis_filename.c_str(), comp_data))
{ {
......
...@@ -207,7 +207,7 @@ namespace basisu ...@@ -207,7 +207,7 @@ namespace basisu
m_debug.clear(); m_debug.clear();
m_debug_images.clear(); m_debug_images.clear();
m_global_sel_pal.clear(); m_global_sel_pal.clear();
m_no_auto_global_sel_pal.clear(); m_auto_global_sel_pal.clear();
m_no_hybrid_sel_cb.clear(); m_no_hybrid_sel_cb.clear();
m_perceptual.clear(); m_perceptual.clear();
m_no_selector_rdo.clear(); m_no_selector_rdo.clear();
...@@ -279,7 +279,7 @@ namespace basisu ...@@ -279,7 +279,7 @@ namespace basisu
param<int> m_compression_level; param<int> m_compression_level;
bool_param<false> m_global_sel_pal; bool_param<false> m_global_sel_pal;
bool_param<false> m_no_auto_global_sel_pal; bool_param<false> m_auto_global_sel_pal;
// Frontend/backend codec parameters // Frontend/backend codec parameters
bool_param<false> m_no_hybrid_sel_cb; bool_param<false> m_no_hybrid_sel_cb;
......
...@@ -1070,7 +1070,7 @@ namespace basisu ...@@ -1070,7 +1070,7 @@ namespace basisu
assert(node.is_leaf()); assert(node.is_leaf());
var_heap.delete_top(); var_heap.delete_top();
if (node.m_training_vecs.size() > 1) if (node.m_training_vecs.size() > 1)
{ {
if (split_node(node_index, var_heap, l_children, r_children)) if (split_node(node_index, var_heap, l_children, r_children))
...@@ -1197,11 +1197,11 @@ namespace basisu ...@@ -1197,11 +1197,11 @@ namespace basisu
} }
if ((l_child.m_var > 0.0f) && (l_child.m_training_vecs.size() > 1)) if ((l_child.m_var > 0.0f) && (l_child.m_training_vecs.size() > 1))
var_heap.add_heap(l_child_index, l_var); var_heap.add_heap(l_child_index, l_child.m_var);
if ((r_child.m_var > 0.0f) && (r_child.m_training_vecs.size() > 1)) if ((r_child.m_var > 0.0f) && (r_child.m_training_vecs.size() > 1))
var_heap.add_heap(r_child_index, r_var); var_heap.add_heap(r_child_index, r_child.m_var);
return true; return true;
} }
......
...@@ -343,6 +343,7 @@ namespace basisu ...@@ -343,6 +343,7 @@ namespace basisu
cur_blk.set_block_color5_etc1s(get_endpoint_cluster_unscaled_color(endpoint_cluster_index, false)); cur_blk.set_block_color5_etc1s(get_endpoint_cluster_unscaled_color(endpoint_cluster_index, false));
cur_blk.set_inten_tables_etc1s(get_endpoint_cluster_inten_table(endpoint_cluster_index, false)); cur_blk.set_inten_tables_etc1s(get_endpoint_cluster_inten_table(endpoint_cluster_index, false));
cur_blk.set_raw_selector_bits(get_selector_cluster_selector_bits(old_selector_cluster_index).get_raw_selector_bits()); cur_blk.set_raw_selector_bits(get_selector_cluster_selector_bits(old_selector_cluster_index).get_raw_selector_bits());
cur_blk.set_flip_bit(true);
const uint64_t cur_err = cur_blk.evaluate_etc1_error(get_source_pixel_block(block_index).get_ptr(), m_params.m_perceptual); const uint64_t cur_err = cur_blk.evaluate_etc1_error(get_source_pixel_block(block_index).get_ptr(), m_params.m_perceptual);
...@@ -2385,7 +2386,7 @@ namespace basisu ...@@ -2385,7 +2386,7 @@ namespace basisu
void basisu_frontend::dump_debug_image(const char *pFilename, uint32_t first_block, uint32_t num_blocks_x, uint32_t num_blocks_y, bool output_blocks) void basisu_frontend::dump_debug_image(const char *pFilename, uint32_t first_block, uint32_t num_blocks_x, uint32_t num_blocks_y, bool output_blocks)
{ {
gpu_image g; gpu_image g;
g.init(cETC1, num_blocks_x * 4, num_blocks_y * 4); g.init(texture_format::cETC1, num_blocks_x * 4, num_blocks_y * 4);
for (uint32_t y = 0; y < num_blocks_y; y++) for (uint32_t y = 0; y < num_blocks_y; y++)
{ {
......
...@@ -37,7 +37,7 @@ namespace basisu ...@@ -37,7 +37,7 @@ namespace basisu
void clear() void clear()
{ {
m_fmt = cInvalidTextureFormat; m_fmt = texture_format::cInvalidTextureFormat;
m_width = 0; m_width = 0;
m_height = 0; m_height = 0;
m_block_width = 0; m_block_width = 0;
...@@ -101,7 +101,7 @@ namespace basisu ...@@ -101,7 +101,7 @@ namespace basisu
m_blocks.resize(m_blocks_x * m_blocks_y * m_qwords_per_block); m_blocks.resize(m_blocks_x * m_blocks_y * m_qwords_per_block);
} }
bool unpack(image& img, bool pvrtc_wrap_addressing = true) const; bool unpack(image& img) const;
void override_dimensions(uint32_t w, uint32_t h) void override_dimensions(uint32_t w, uint32_t h)
{ {
...@@ -132,6 +132,7 @@ namespace basisu ...@@ -132,6 +132,7 @@ namespace basisu
bool write_compressed_texture_file(const char *pFilename, const gpu_image &g); bool write_compressed_texture_file(const char *pFilename, const gpu_image &g);
bool write_3dfx_out_file(const char* pFilename, const gpu_image& gi);
// GPU texture block unpacking // GPU texture block unpacking
void unpack_etc2_eac(const void *pBlock_bits, color_rgba *pPixels); void unpack_etc2_eac(const void *pBlock_bits, color_rgba *pPixels);
...@@ -142,6 +143,9 @@ namespace basisu ...@@ -142,6 +143,9 @@ namespace basisu
bool unpack_bc7_mode6(const void *pBlock_bits, color_rgba *pPixels); bool unpack_bc7_mode6(const void *pBlock_bits, color_rgba *pPixels);
bool unpack_bc7_mode5(const void* pBlock_bits, color_rgba* pPixels); bool unpack_bc7_mode5(const void* pBlock_bits, color_rgba* pPixels);
void unpack_atc(const void* pBlock_bits, color_rgba* pPixels); void unpack_atc(const void* pBlock_bits, color_rgba* pPixels);
bool unpack_fxt1(const void* p, color_rgba* pPixels);
bool unpack_pvrtc2(const void* p, color_rgba* pPixels);
void unpack_etc2_eac_rg(const void* p, color_rgba* pPixels);
// unpack_block() is only capable of unpacking texture data created by the transcoder. // unpack_block() is only capable of unpacking texture data created by the transcoder.
// For some texture formats (like BC7, or ETC2) it's not a complete implementation. // For some texture formats (like BC7, or ETC2) it's not a complete implementation.
......
...@@ -193,21 +193,12 @@ namespace basisu ...@@ -193,21 +193,12 @@ namespace basisu
int block_x1 = block_x0 + 1; int block_x1 = block_x0 + 1;
int block_y0 = (static_cast<int>(y) - 2) >> 2; int block_y0 = (static_cast<int>(y) - 2) >> 2;
int block_y1 = block_y0 + 1; int block_y1 = block_y0 + 1;
if (m_wrap_addressing)
{ block_x0 = posmod(block_x0, m_block_width);
block_x0 = posmod(block_x0, m_block_width); block_x1 = posmod(block_x1, m_block_width);
block_x1 = posmod(block_x1, m_block_width); block_y0 = posmod(block_y0, m_block_height);
block_y0 = posmod(block_y0, m_block_height); block_y1 = posmod(block_y1, m_block_height);
block_y1 = posmod(block_y1, m_block_height);
}
else
{
block_x0 = clamp<int>(block_x0, 0, m_block_width - 1);
block_x1 = clamp<int>(block_x1, 0, m_block_width - 1);
block_y0 = clamp<int>(block_y0, 0, m_block_height - 1);
block_y1 = clamp<int>(block_y1, 0, m_block_height - 1);
}
pColors[0] = interpolate(x, y, m_blocks(block_x0, block_y0).get_endpoint_5554(0), m_blocks(block_x1, block_y0).get_endpoint_5554(0), m_blocks(block_x0, block_y1).get_endpoint_5554(0), m_blocks(block_x1, block_y1).get_endpoint_5554(0)); pColors[0] = interpolate(x, y, m_blocks(block_x0, block_y0).get_endpoint_5554(0), m_blocks(block_x1, block_y0).get_endpoint_5554(0), m_blocks(block_x0, block_y1).get_endpoint_5554(0), m_blocks(block_x1, block_y1).get_endpoint_5554(0));
pColors[3] = interpolate(x, y, m_blocks(block_x0, block_y0).get_endpoint_5554(1), m_blocks(block_x1, block_y0).get_endpoint_5554(1), m_blocks(block_x0, block_y1).get_endpoint_5554(1), m_blocks(block_x1, block_y1).get_endpoint_5554(1)); pColors[3] = interpolate(x, y, m_blocks(block_x0, block_y0).get_endpoint_5554(1), m_blocks(block_x1, block_y0).get_endpoint_5554(1), m_blocks(block_x0, block_y1).get_endpoint_5554(1), m_blocks(block_x1, block_y1).get_endpoint_5554(1));
...@@ -240,21 +231,12 @@ namespace basisu ...@@ -240,21 +231,12 @@ namespace basisu
int block_x1 = block_x0 + 1; int block_x1 = block_x0 + 1;
int block_y0 = (static_cast<int>(y) - 2) >> 2; int block_y0 = (static_cast<int>(y) - 2) >> 2;
int block_y1 = block_y0 + 1; int block_y1 = block_y0 + 1;
if (m_wrap_addressing)
{ block_x0 = posmod(block_x0, m_block_width);
block_x0 = posmod(block_x0, m_block_width); block_x1 = posmod(block_x1, m_block_width);
block_x1 = posmod(block_x1, m_block_width); block_y0 = posmod(block_y0, m_block_height);
block_y0 = posmod(block_y0, m_block_height); block_y1 = posmod(block_y1, m_block_height);
block_y1 = posmod(block_y1, m_block_height);
}
else
{
block_x0 = clamp<int>(block_x0, 0, m_block_width - 1);
block_x1 = clamp<int>(block_x1, 0, m_block_width - 1);
block_y0 = clamp<int>(block_y0, 0, m_block_height - 1);
block_y1 = clamp<int>(block_y1, 0, m_block_height - 1);
}
if (get_block_uses_transparent_modulation(x >> 2, y >> 2)) if (get_block_uses_transparent_modulation(x >> 2, y >> 2))
{ {
if (m == 0) if (m == 0)
......
...@@ -168,15 +168,14 @@ namespace basisu ...@@ -168,15 +168,14 @@ namespace basisu
{ {
public: public:
inline pvrtc4_image() : inline pvrtc4_image() :
m_width(0), m_height(0), m_block_width(0), m_block_height(0), m_wrap_addressing(false), m_uses_alpha(false) m_width(0), m_height(0), m_block_width(0), m_block_height(0), m_uses_alpha(false)
{ {
} }
inline pvrtc4_image(uint32_t width, uint32_t height, bool wrap_addressing = false) : inline pvrtc4_image(uint32_t width, uint32_t height) :
m_width(0), m_height(0), m_block_width(0), m_block_height(0), m_wrap_addressing(false), m_uses_alpha(false) m_width(0), m_height(0), m_block_width(0), m_block_height(0), m_uses_alpha(false)
{ {
resize(width, height); resize(width, height);
set_wrap_addressing(wrap_addressing);
} }
inline void clear() inline void clear()
...@@ -187,7 +186,6 @@ namespace basisu ...@@ -187,7 +186,6 @@ namespace basisu
m_block_height = 0; m_block_height = 0;
m_blocks.clear(); m_blocks.clear();
m_uses_alpha = false; m_uses_alpha = false;
m_wrap_addressing = false;
} }
inline void resize(uint32_t width, uint32_t height) inline void resize(uint32_t width, uint32_t height)
...@@ -218,9 +216,6 @@ namespace basisu ...@@ -218,9 +216,6 @@ namespace basisu
inline bool get_uses_alpha() const { return m_uses_alpha; } inline bool get_uses_alpha() const { return m_uses_alpha; }
inline void set_uses_alpha(bool uses_alpha) { m_uses_alpha = uses_alpha; } inline void set_uses_alpha(bool uses_alpha) { m_uses_alpha = uses_alpha; }
inline void set_wrap_addressing(bool wrapping) { m_wrap_addressing = wrapping; }
inline bool get_wrap_addressing() const { return m_wrap_addressing; }
inline bool are_blocks_equal(const pvrtc4_image& rhs) const inline bool are_blocks_equal(const pvrtc4_image& rhs) const
{ {
return m_blocks == rhs.m_blocks; return m_blocks == rhs.m_blocks;
...@@ -298,24 +293,24 @@ namespace basisu ...@@ -298,24 +293,24 @@ namespace basisu
dst(x, y) = get_pixel(block_x * 4 + x, block_y * 4 + y); dst(x, y) = get_pixel(block_x * 4 + x, block_y * 4 + y);
} }
inline int wrap_or_clamp_x(int x) const inline int wrap_x(int x) const
{ {
return m_wrap_addressing ? posmod(x, m_width) : clamp<int>(x, 0, m_width - 1); return posmod(x, m_width);
} }
inline int wrap_or_clamp_y(int y) const inline int wrap_y(int y) const
{ {
return m_wrap_addressing ? posmod(y, m_height) : clamp<int>(y, 0, m_height - 1); return posmod(y, m_height);
} }
inline int wrap_or_clamp_block_x(int bx) const inline int wrap_block_x(int bx) const
{ {
return m_wrap_addressing ? posmod(bx, m_block_width) : clamp<int>(bx, 0, m_block_width - 1); return posmod(bx, m_block_width);
} }
inline int wrap_or_clamp_block_y(int by) const inline int wrap_block_y(int by) const
{ {
return m_wrap_addressing ? posmod(by, m_block_height) : clamp<int>(by, 0, m_block_height - 1); return posmod(by, m_block_height);
} }
inline vec2F get_interpolation_factors(uint32_t x, uint32_t y) const inline vec2F get_interpolation_factors(uint32_t x, uint32_t y) const
...@@ -362,7 +357,6 @@ namespace basisu ...@@ -362,7 +357,6 @@ namespace basisu
pvrtc4_block_vector2D m_blocks; pvrtc4_block_vector2D m_blocks;
uint32_t m_block_width, m_block_height; uint32_t m_block_width, m_block_height;
bool m_wrap_addressing;
bool m_uses_alpha; bool m_uses_alpha;
}; };
......
...@@ -301,7 +301,7 @@ namespace basisu ...@@ -301,7 +301,7 @@ namespace basisu
// GPU texture formats // GPU texture formats
enum texture_format enum class texture_format
{ {
cInvalidTextureFormat = -1, cInvalidTextureFormat = -1,
...@@ -321,6 +321,10 @@ namespace basisu ...@@ -321,6 +321,10 @@ namespace basisu
cPVRTC1_4_RGBA, cPVRTC1_4_RGBA,
cATC_RGB, cATC_RGB,
cATC_RGBA_INTERPOLATED_ALPHA, cATC_RGBA_INTERPOLATED_ALPHA,
cFXT1_RGB,
cPVRTC2_4_RGBA,
cETC2_R11_EAC,
cETC2_RG11_EAC,
// Uncompressed/raw pixels // Uncompressed/raw pixels
cRGBA32, cRGBA32,
...@@ -334,17 +338,19 @@ namespace basisu ...@@ -334,17 +338,19 @@ namespace basisu
{ {
switch (fmt) switch (fmt)
{ {
case cETC1: case texture_format::cETC1:
case cETC1S: case texture_format::cETC1S:
case cETC2_RGB: case texture_format::cETC2_RGB:
case cETC2_ALPHA: case texture_format::cETC2_ALPHA:
case cBC1: case texture_format::cBC1:
case cBC4: case texture_format::cBC4:
case cPVRTC1_4_RGB: case texture_format::cPVRTC1_4_RGB:
case cPVRTC1_4_RGBA: case texture_format::cPVRTC1_4_RGBA:
case cATC_RGB: case texture_format::cATC_RGB:
case texture_format::cPVRTC2_4_RGBA:
case texture_format::cETC2_R11_EAC:
return 8; return 8;
case cRGBA32: case texture_format::cRGBA32:
return sizeof(uint32_t) * 16; return sizeof(uint32_t) * 16;
default: default:
break; break;
...@@ -360,6 +366,13 @@ namespace basisu ...@@ -360,6 +366,13 @@ namespace basisu
inline uint32_t get_block_width(texture_format fmt) inline uint32_t get_block_width(texture_format fmt)
{ {
BASISU_NOTE_UNUSED(fmt); BASISU_NOTE_UNUSED(fmt);
switch (fmt)
{
case texture_format::cFXT1_RGB:
return 8;
default:
break;
}
return 4; return 4;
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -42,7 +42,7 @@ namespace basist ...@@ -42,7 +42,7 @@ namespace basist
{ {
// Low-level formats directly supported by the transcoder (other supported texture formats are combinations of these low-level block formats). // Low-level formats directly supported by the transcoder (other supported texture formats are combinations of these low-level block formats).
// You probably don't care about these enum's unless you are going pretty low-level and calling the transcoder to decode individual slices. // You probably don't care about these enum's unless you are going pretty low-level and calling the transcoder to decode individual slices.
enum block_format enum class block_format
{ {
cETC1, // ETC1S RGB cETC1, // ETC1S RGB
cBC1, // DXT1 RGB cBC1, // DXT1 RGB
...@@ -57,6 +57,7 @@ namespace basist ...@@ -57,6 +57,7 @@ namespace basist
// data. If you use a sRGB ASTC format you'll get ~1 LSB of additional error, because of the different way ASTC decoders scale 8-bit endpoints to 16-bits during unpacking. // data. If you use a sRGB ASTC format you'll get ~1 LSB of additional error, because of the different way ASTC decoders scale 8-bit endpoints to 16-bits during unpacking.
cATC_RGB, cATC_RGB,
cATC_RGBA_INTERPOLATED_ALPHA, cATC_RGBA_INTERPOLATED_ALPHA,
cFXT1_RGB, // Opaque-only, has oddball 8x4 pixel block size
cIndices, // Used internally: Write 16-bit endpoint and selector indices directly to output (output block must be at least 32-bits) cIndices, // Used internally: Write 16-bit endpoint and selector indices directly to output (output block must be at least 32-bits)
...@@ -71,6 +72,11 @@ namespace basist ...@@ -71,6 +72,11 @@ namespace basist
cRGBA4444_ALPHA, cRGBA4444_ALPHA,
cRGBA4444_COLOR_OPAQUE, cRGBA4444_COLOR_OPAQUE,
cPVRTC2_4_RGB,
cPVRTC2_4_RGBA,
cETC2_EAC_R11,
cTotalBlockFormats cTotalBlockFormats
}; };
...@@ -624,6 +630,11 @@ namespace basist ...@@ -624,6 +630,11 @@ namespace basist
struct decoder_etc_block; struct decoder_etc_block;
inline uint8_t clamp255(int32_t i)
{
return (uint8_t)((i & 0xFFFFFF00U) ? (~(i >> 31)) : i);
}
struct color32 struct color32
{ {
union union
...@@ -647,6 +658,8 @@ namespace basist ...@@ -647,6 +658,8 @@ namespace basist
void set(uint32_t vr, uint32_t vg, uint32_t vb, uint32_t va) { c[0] = static_cast<uint8_t>(vr); c[1] = static_cast<uint8_t>(vg); c[2] = static_cast<uint8_t>(vb); c[3] = static_cast<uint8_t>(va); } void set(uint32_t vr, uint32_t vg, uint32_t vb, uint32_t va) { c[0] = static_cast<uint8_t>(vr); c[1] = static_cast<uint8_t>(vg); c[2] = static_cast<uint8_t>(vb); c[3] = static_cast<uint8_t>(va); }
void set_clamped(int vr, int vg, int vb, int va) { c[0] = clamp255(vr); c[1] = clamp255(vg); c[2] = clamp255(vb); c[3] = clamp255(va); }
uint8_t operator[] (uint32_t idx) const { assert(idx < 4); return c[idx]; } uint8_t operator[] (uint32_t idx) const { assert(idx < 4); return c[idx]; }
uint8_t &operator[] (uint32_t idx) { assert(idx < 4); return c[idx]; } uint8_t &operator[] (uint32_t idx) { assert(idx < 4); return c[idx]; }
...@@ -733,6 +746,8 @@ namespace basist ...@@ -733,6 +746,8 @@ namespace basist
} }
}; };
bool basis_block_format_is_uncompressed(block_format tex_type);
} // namespace basist } // namespace basist
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment