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.
This commit is contained in:
Luke Wilde 2022-01-12 10:05:50 +00:00 committed by Idan Horowitz
parent 53d6e1600c
commit f91e41f90c
Notes: sideshowbarker 2024-07-17 21:01:42 +09:00

View file

@ -1765,11 +1765,15 @@ void SoftwareGLContext::gl_bind_texture(GLenum target, GLuint texture)
}
auto it = m_allocated_textures.find(texture);
RefPtr<Texture> 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