LibGL: Allow glTexImage2D to create uninitialized textures

When passing a nullptr as the pixel array LibGL now allocates texture
memory but does not initialize the texture contents.
This commit is contained in:
Stephan Unverwerth 2021-08-18 13:25:48 +02:00 committed by Andreas Kling
parent 22905daacb
commit b38edf994b
Notes: sideshowbarker 2024-07-18 05:30:45 +09:00

View file

@ -18,17 +18,18 @@ void Texture2D::upload_texture_data(GLenum, GLint lod, GLint internal_format, GL
// Considering we control this library, and `gl.h` itself, we don't need to add any // Considering we control this library, and `gl.h` itself, we don't need to add any
// checks here to see if we support them; the program will simply fail to compile.. // checks here to see if we support them; the program will simply fail to compile..
// Somebody passed us in nullptr... auto& mip = m_mipmaps[lod];
// Apparently this allocates memory on the GPU (according to Khronos docs..)? mip.set_width(width);
mip.set_height(height);
// No pixel data was supplied. Just allocate texture memory and leave it uninitialized.
if (pixels == nullptr) { if (pixels == nullptr) {
dbgln("LibGL: pixels == nullptr when uploading texture data."); mip.pixel_data().resize(width * height);
VERIFY_NOT_REACHED(); return;
} }
m_internal_format = internal_format; m_internal_format = internal_format;
// Get reference to the mip
auto& mip = m_mipmaps[lod];
const u8* pixel_byte_array = reinterpret_cast<const u8*>(pixels); const u8* pixel_byte_array = reinterpret_cast<const u8*>(pixels);
mip.pixel_data().clear(); mip.pixel_data().clear();
@ -75,9 +76,6 @@ void Texture2D::upload_texture_data(GLenum, GLint lod, GLint internal_format, GL
} else { } else {
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
mip.set_width(width);
mip.set_height(height);
} }
MipMap const& Texture2D::mipmap(unsigned lod) const MipMap const& Texture2D::mipmap(unsigned lod) const