From b38edf994b4ce9c341980c22b3579f185e3a8d26 Mon Sep 17 00:00:00 2001 From: Stephan Unverwerth Date: Wed, 18 Aug 2021 13:25:48 +0200 Subject: [PATCH] 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. --- Userland/Libraries/LibGL/Tex/Texture2D.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibGL/Tex/Texture2D.cpp b/Userland/Libraries/LibGL/Tex/Texture2D.cpp index 0ab7e5c525..b0fd569c13 100644 --- a/Userland/Libraries/LibGL/Tex/Texture2D.cpp +++ b/Userland/Libraries/LibGL/Tex/Texture2D.cpp @@ -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 // checks here to see if we support them; the program will simply fail to compile.. - // Somebody passed us in nullptr... - // Apparently this allocates memory on the GPU (according to Khronos docs..)? + auto& mip = m_mipmaps[lod]; + mip.set_width(width); + mip.set_height(height); + + // No pixel data was supplied. Just allocate texture memory and leave it uninitialized. if (pixels == nullptr) { - dbgln("LibGL: pixels == nullptr when uploading texture data."); - VERIFY_NOT_REACHED(); + mip.pixel_data().resize(width * height); + return; } m_internal_format = internal_format; - // Get reference to the mip - auto& mip = m_mipmaps[lod]; const u8* pixel_byte_array = reinterpret_cast(pixels); mip.pixel_data().clear(); @@ -75,9 +76,6 @@ void Texture2D::upload_texture_data(GLenum, GLint lod, GLint internal_format, GL } else { VERIFY_NOT_REACHED(); } - - mip.set_width(width); - mip.set_height(height); } MipMap const& Texture2D::mipmap(unsigned lod) const