Skip to content

Add ImTextureData-based texture management#414

Open
Igrium wants to merge 9 commits into
SpaiR:mainfrom
Igrium:textureManagement2
Open

Add ImTextureData-based texture management#414
Igrium wants to merge 9 commits into
SpaiR:mainfrom
Igrium:textureManagement2

Conversation

@Igrium

@Igrium Igrium commented Jul 23, 2026

Copy link
Copy Markdown

Added bindings for ImGui's new texture-management API: ImTextureData, ImTextureRect, ImTextureStatus, plus the relevant accessors.

Additionally:

  • Wired up the default GL3 backend (ImGuiImplG13) to use the new dynamic font rendering
  • Updated the example app to demonstrate this new flow

Notes:

  • SDL backend has not been updated yet.
  • Binaries only compiled for Linux (I do not own a Mac or Windows machine)
  • Minor changes or tweaks (quality of life stuff)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

I maay have vibe-coded this lol

claude and others added 9 commits July 23, 2026 09:19
Bind Dear ImGui 1.92's texture-management structs and enums so backends can
drive ImGuiBackendFlags_RendererHasTextures:

- ImTextureFormat / ImTextureStatus flag enums (AST-generated).
- ImTextureRect wrapper (x/y/w/h of an update region).
- ImTextureData wrapper exposing the struct fields (status, format, size,
  pixels, texID, update rects, ...) and binding through the C++ SetStatus/
  SetTexID/Create/DestroyPixels methods. getPixels() returns a direct
  ByteBuffer over the native pixel buffer (no copy).

These are the core-library/backend-facing types; end-user application code
does not need them. Follow-up commits expose the per-frame texture lists and
wire the LWJGL GL3 backend.

Co-authored-by: Claude <noreply@anthropic.com>
Add the accessors a renderer backend needs to honor texture requests each
frame:

- ImDrawData.getTexturesSize()/getTextures(idx) over ImDrawData::Textures
  (may be NULL when texture updates are disabled).
- ImGuiPlatformIO.getTexturesSize()/getTextures(idx) over the platform IO
  texture list, plus Renderer_TextureMaxWidth/Height getters and setters so
  the backend can advertise its maximum texture size.

Co-authored-by: Claude <noreply@anthropic.com>
Wire ImGuiImplGl3 to Dear ImGui 1.92's texture-management system and enable
ImGuiBackendFlags_RendererHasTextures end-to-end:

- init(): advertise RendererHasTextures and publish the GL max texture size
  via ImGuiPlatformIO.Renderer_TextureMaxWidth/Height; shutdown() clears the
  flag.
- renderDrawData(): before drawing, iterate ImDrawData's texture list and
  reconcile every non-OK ImTextureData with the GPU.
- updateTexture()/destroyTexture(): create (glTexImage2D from the texture's
  pixel buffer), incrementally update (glTexSubImage2D over UpdateRect
  blocks using UNPACK_ROW_LENGTH) and destroy GL textures, reporting the new
  TexID/status back through the C++ SetTexID/SetStatus methods.
- createDeviceObjects()/newFrame() no longer eagerly build the font texture;
  destroyDeviceObjects() frees every owned texture (RefCount == 1).

The legacy createFontsTexture()/destroyFontsTexture() methods are kept and
deprecated for source compatibility, but are no longer part of the frame
loop.

Co-authored-by: Claude <noreply@anthropic.com>
Add a "Texture Management" section to the example that reads the live
ImTextureData list the GL3 backend now maintains
(ImGuiBackendFlags_RendererHasTextures): it reports the backend flag state,
lists each managed texture's id/size/format/status/texID, and renders the
uploaded font-atlas texture inline via ImGui.image().

Co-authored-by: Claude <noreply@anthropic.com>
Rebuild bin/libimgui-java64.so (linux64) so the new ImTextureData /
ImTextureRect / ImDrawData / ImGuiPlatformIO native methods resolve at
runtime; without this the branch throws UnsatisfiedLinkError against the
stale prebuilt library.

NOTE: only the linux64 native is refreshed here — the macOS/Windows natives
in bin/ still predate these JNI methods and will be regenerated by CI's
post-merge native build.

Co-authored-by: Claude <noreply@anthropic.com>
…s backend

With the 1.92 texture-management backend the font atlas is baked lazily by
the renderer. Calling build() explicitly sets PreloadedAllGlyphsRanges and
trips the 'you don't need to call Build()' assertion in ImFontAtlasUpdateNewFrame,
after which NewFrame proceeds with an inconsistent atlas and the render path
crashes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jj7rjyyfxUigrtxA4fMRKf
…ream

Compared updateTexture against the current imgui_impl_opengl3.cpp
ImGui_ImplOpenGL3_UpdateTexture. Upstream backs up GL_UNPACK_ROW_LENGTH and
GL_UNPACK_ALIGNMENT on entry and restores them on exit; the port previously
set them without restoring, breaking the backend's back-up/restore-all-GL-state
contract for hosts with non-default unpack state. Mirror upstream exactly:
save both, set ALIGNMENT=1, set ROW_LENGTH=0 in WantCreate / =width in
WantUpdates, then restore both.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jj7rjyyfxUigrtxA4fMRKf
@Igrium Igrium changed the title Texture management2 Add ImTextureData-based texture management Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants