3 #include <ext/bc7enc_rdo/bc7enc.h>
25 bool BC7TextureWriter::write(
int width,
int height,
int bytesPerPixel,
const ByteBuffer& textureByteBuffer, vector<uint8_t>& bc7Data) {
27 bc7enc_compress_block_params bc7encParameters;
28 bc7encParameters.m_uber_level = BC7ENC_MAX_UBER_LEVEL;
29 bc7enc_compress_block_params_init(&bc7encParameters);
30 bc7enc_compress_block_params_init_linear_weights(&bc7encParameters);
33 auto xBlocks =
static_cast<int>(Math::ceil(width / 4.0f));
34 auto yBlocks =
static_cast<int>(Math::ceil(height / 4.0f));
35 bc7Data.resize(xBlocks * yBlocks * 16);
38 for (
auto yBlock = 0; yBlock < yBlocks; yBlock++) {
39 for (
auto xBlock = 0; xBlock < xBlocks; xBlock++) {
41 array<uint8_t, 4 * 4 * 4> rgbaBlockPixels { 0 };
42 auto blockPixelIdx = 0;
43 auto xBlockOffset = xBlock * 4;
44 auto yBlockOffset = yBlock * 4;
45 for (
int y = 0; y < 4; y++) {
46 for (
int x = 0; x < 4; x++) {
47 auto offset = (yBlockOffset + y) * width * bytesPerPixel + (xBlockOffset + x) * bytesPerPixel;
53 red = textureByteBuffer.
get(offset + 0);
54 green = textureByteBuffer.
get(offset + 1);
55 blue = textureByteBuffer.
get(offset + 2);
56 alpha = bytesPerPixel == 4?textureByteBuffer.
get(offset + 3):0xff;
58 rgbaBlockPixels[blockPixelIdx * 4 + 0] = red;
59 rgbaBlockPixels[blockPixelIdx * 4 + 1] = green;
60 rgbaBlockPixels[blockPixelIdx * 4 + 2] = blue;
61 rgbaBlockPixels[blockPixelIdx * 4 + 3] = alpha;
66 bc7enc_compress_block_init();
67 bc7enc_compress_block(&bc7Data.data()[yBlock * xBlocks * 16 + xBlock * 16], rgbaBlockPixels.data(), &bc7encParameters);
BC7 texture writer class.
uint8_t get(int64_t position) const
virtual int64_t getCapacity() const