OpenGL2/3: Backup and restore GL_UNPACK state in UpdateTexture() (#9473)#9473
Closed
Turtle-PB wants to merge 1 commit into
Closed
OpenGL2/3: Backup and restore GL_UNPACK state in UpdateTexture() (#9473)#9473Turtle-PB wants to merge 1 commit into
Turtle-PB wants to merge 1 commit into
Conversation
…rnut#9473) The OpenGL2 and OpenGL3 backends set GL_UNPACK_ROW_LENGTH=0 and GL_UNPACK_ALIGNMENT=1 during texture creation and updates, but never restored the original values. This corrupted the calling application's pixel store state when ImGui created or updated textures mid-frame (e.g., dynamic font atlas updates). Fix: Backup GL_UNPACK_ROW_LENGTH and GL_UNPACK_ALIGNMENT at the start of UpdateTexture(), and restore them at the end. This resolves the FIXME in ImGui_ImplOpenGL3_UpdateTexture(): 'FIXME: Consider backing up and restoring' Issues: ocornut#8802 (original UNPACK_ALIGNMENT change), ocornut#9473 (this fix)
ocornut
pushed a commit
that referenced
this pull request
Jul 15, 2026
Owner
|
Merged as e3927dc + amends 0ff4a8a. Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The OpenGL2 and OpenGL3 backends set
GL_UNPACK_ROW_LENGTH=0andGL_UNPACK_ALIGNMENT=1during texture creation and updates, but never restored the original values. This corrupted the calling application's pixel store state when ImGui created or updated textures mid-frame (e.g., dynamic font atlas updates).This was flagged as a FIXME in
ImGui_ImplOpenGL3_UpdateTexture():Fix
Backup
GL_UNPACK_ROW_LENGTHandGL_UNPACK_ALIGNMENTat the start ofUpdateTexture(), and restore them at the end. This matches the pattern already used forGL_TEXTURE_BINDING_2Din the same function.OpenGL3 (
imgui_impl_opengl3.cpp)GL_UNPACK_ROW_LENGTHandGL_UNPACK_ALIGNMENTviaglGetIntegerv()at function entryOpenGL2 (
imgui_impl_opengl2.cpp)Testing
#ifdef GL_UNPACK_ROW_LENGTH/#ifdef GL_UNPACK_ALIGNMENTfor WebGL/ES compatibility (where these constants may not exist)GL_CALLmacro is used for all backup/restore calls, matching the existing code styleRelated Issues
GL_UNPACK_ALIGNMENT=1(but without restore)ImGui_ImplOpenGL3_UpdateTexture()