From f91e41f90c998b8fb306ed6932fd14f0d91cca31 Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Wed, 12 Jan 2022 10:05:50 +0000 Subject: [PATCH] LibGL: Generate texture in glBindTexture if not previously generated Required by Xash3D, which forgoes glGenTexture and implements its own texture generator. It expects glBindTexture to pick up on this though. The strategy here is to keep texture_object null if we don't find the texture in the allocation textures map, as it will then both generate and set the texture in the allocated textures map using the texture name passed to us, then bind it. --- Userland/Libraries/LibGL/SoftwareGLContext.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index 1728b0516bf..9aa756796e9 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -1765,11 +1765,15 @@ void SoftwareGLContext::gl_bind_texture(GLenum target, GLuint texture) } auto it = m_allocated_textures.find(texture); + RefPtr texture_object; - // The texture name does not exist - RETURN_WITH_ERROR_IF(it == m_allocated_textures.end(), GL_INVALID_VALUE); - - auto texture_object = it->value; + // OpenGL 1.x supports binding texture names that were not previously generated by glGenTextures. + // If there is not an allocated texture, meaning it was not previously generated by glGenTextures, + // we can keep texture_object null to both allocate and bind the texture with the passed in texture name. + // FIXME: Later OpenGL versions such as 4.x enforce that texture names being bound were previously generated + // by glGenTextures. + if (it != m_allocated_textures.end()) + texture_object = it->value; // Binding a texture to a different target than it was first bound is an invalid operation // FIXME: We only support GL_TEXTURE_2D for now