fix(texture): glGetTexImage readback BGRA texture

This commit is contained in:
Swung0x48 2025-02-28 10:52:15 +08:00
parent 68700c1fcb
commit 34aed04e70

View File

@ -793,17 +793,18 @@ void glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type, void*
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadBuffer(GL_COLOR_ATTACHMENT0);
// if (format == GL_BGRA && (type == GL_UNSIGNED_INT_8_8_8_8 || type == GL_UNSIGNED_INT_8_8_8_8_REV)) {
// void *read_pixels = malloc(width * height * 4);
// glReadPixels(0, 0, width, height, format, type, read_pixels);
// pixel_convert(read_pixels, &pixels, width, height, GL_RGBA, GL_UNSIGNED_BYTE, format, GL_UNSIGNED_BYTE, 0, 1);
// free(read_pixels);
// } else {
// glReadPixels(0, 0, width, height, format, type, pixels);
// }
if (pixels != NULL && format == GL_BGRA && (type == GL_UNSIGNED_INT_8_8_8_8 || type == GL_UNSIGNED_INT_8_8_8_8_REV)) {
void *read_pixels = malloc(width * height * 4);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, read_pixels);
pixel_convert(read_pixels, &pixels, width, height, GL_RGBA, GL_UNSIGNED_BYTE, format, GL_UNSIGNED_BYTE, 0, 1);
free(read_pixels);
} else {
glReadPixels(0, 0, width, height, format, type, pixels);
}
// glReadPixels(0, 0, width, height, format, type, pixels);
glPixelStorei(GL_PACK_ALIGNMENT, oldPackAlignment);
glViewport(oldViewport[0], oldViewport[1], oldViewport[2], oldViewport[3]);
glDeleteFramebuffers(1, &fbo);