Use Texture's format when creating an Image from Canvas

This commit is contained in:
Luna 2022-03-03 23:14:35 -03:00 committed by Bjorn
parent ef41e06fc9
commit ea1bc6c5c4
1 changed files with 6 additions and 3 deletions

View File

@ -2123,8 +2123,9 @@ Image* lovrCanvasNewImage(Canvas* canvas, uint32_t index) {
glBindFramebuffer(GL_READ_FRAMEBUFFER, canvas->resolveBuffer);
}
#ifndef LOVR_WEBGL
Texture* texture = canvas->attachments[index].texture;
#ifndef LOVR_WEBGL
if ((texture->incoherent >> BARRIER_TEXTURE) & 1) {
lovrGpuSync(1 << BARRIER_TEXTURE);
}
@ -2134,8 +2135,10 @@ Image* lovrCanvasNewImage(Canvas* canvas, uint32_t index) {
glReadBuffer(index);
}
Image* image = lovrImageCreate(canvas->width, canvas->height, NULL, 0x0, FORMAT_RGBA);
glReadPixels(0, 0, canvas->width, canvas->height, GL_RGBA, GL_UNSIGNED_BYTE, image->blob->data);
Image* image = lovrImageCreate(canvas->width, canvas->height, NULL, 0x0, texture->format);
GLenum glFormat = convertTextureFormat(texture->format);
GLenum glFormatType = convertTextureFormatType(texture->format);
glReadPixels(0, 0, canvas->width, canvas->height, glFormat, glFormatType, image->blob->data);
if (index != 0) {
glReadBuffer(0);