nv2a: Use soft 2D texture decompression

This commit is contained in:
Matt Borgerson 2022-05-23 21:59:01 -07:00 committed by mborgerson
parent 66b57dca9c
commit 0efef88181
3 changed files with 38 additions and 5 deletions

View File

@ -6985,7 +6985,8 @@ static void upload_gl_texture(GLenum gl_target,
int level;
for (level = 0; level < s.levels; level++) {
if (f.gl_format == 0) { /* compressed */
assert(width >= 4 && height >= 4 &&
"Compressed texture padding");
width = MAX(width, 4); height = MAX(height, 4);
unsigned int block_size;
@ -6995,10 +6996,11 @@ static void upload_gl_texture(GLenum gl_target,
block_size = 16;
}
glCompressedTexImage2D(gl_target, level, f.gl_internal_format,
width, height, 0,
width/4 * height/4 * block_size,
texture_data);
uint8_t *converted = decompress_2d_texture_data(
f.gl_internal_format, texture_data, width, height);
glTexImage2D(gl_target, level, GL_RGBA, width, height, 0,
GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, converted);
g_free(converted);
texture_data += width/4 * height/4 * block_size;
} else {

View File

@ -215,3 +215,30 @@ uint8_t *decompress_3d_texture_data(GLint color_format,
}
return converted_data;
}
uint8_t *decompress_2d_texture_data(GLint color_format, const uint8_t *data,
unsigned int width, unsigned int height)
{
assert((width > 0) && (width % 4 == 0));
assert((height > 0) && (height % 4 == 0));
int num_blocks_x = width / 4, num_blocks_y = height / 4;
uint8_t *converted_data = (uint8_t *)g_malloc(width * height * 4);
for (int j = 0; j < num_blocks_y; j++) {
for (int i = 0; i < num_blocks_x; i++) {
int block_index = j * num_blocks_x + i;
if (color_format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
decompress_dxt1_block(data + 8 * block_index,
converted_data, i, j, width, 0);
} else if (color_format == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT) {
decompress_dxt3_block(data + 16 * block_index,
converted_data, i, j, width, 0);
} else if (color_format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) {
decompress_dxt5_block(data + 16 * block_index,
converted_data, i, j, width, 0);
} else {
assert(false);
}
}
}
return converted_data;
}

View File

@ -32,4 +32,8 @@ uint8_t *decompress_3d_texture_data(GLint color_format,
unsigned int width,
unsigned int height,
unsigned int depth);
uint8_t *decompress_2d_texture_data(GLint color_format, const uint8_t *data,
unsigned int width, unsigned int height);
#endif