Skip to content
Closed
Binary file modified bin/libimgui-java64.so
Binary file not shown.
72 changes: 71 additions & 1 deletion example/src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
import imgui.ImFontGlyphRangesBuilder;
import imgui.ImGui;
import imgui.ImGuiIO;
import imgui.ImGuiPlatformIO;
import imgui.ImTextureData;
import imgui.app.Application;
import imgui.app.Configuration;
import imgui.flag.ImGuiBackendFlags;
import imgui.flag.ImGuiConfigFlags;
import imgui.flag.ImGuiInputTextFlags;
import imgui.flag.ImGuiWindowFlags;
import imgui.flag.ImTextureFormat;
import imgui.flag.ImTextureStatus;
import imgui.type.ImString;

import java.io.IOException;
Expand Down Expand Up @@ -68,7 +73,9 @@ private void initFonts(final ImGuiIO io) {
io.getFonts().addFontFromMemoryTTF(loadFromResources("NotoSansCJKjp-Medium.otf"), 14, fontConfig, glyphRanges); // japanese glyphs
io.getFonts().addFontFromMemoryTTF(loadFromResources("fa-regular-400.ttf"), 14, fontConfig, glyphRanges); // font awesome
io.getFonts().addFontFromMemoryTTF(loadFromResources("fa-solid-900.ttf"), 14, fontConfig, glyphRanges); // font awesome
io.getFonts().build();

// NB: With the 1.92 texture-management backend (ImGuiBackendFlags_RendererHasTextures) the atlas is baked
// lazily by the renderer — you must NOT call ImFontAtlas::build() yourself, or Dear ImGui will assert.

fontConfig.destroy();
}
Expand Down Expand Up @@ -100,10 +107,73 @@ public void process() {
ImGui.separator();
ImGui.text("Extra");
Extra.show(this);

ImGui.separator();
showTextureManagement();
}
ImGui.end();
}

/**
* Demonstrates Dear ImGui 1.92's texture-management system (ImGuiBackendFlags_RendererHasTextures).
* <p>
* The GL3 backend now drives texture create/update/destroy through {@link ImTextureData}, so the font atlas is
* uploaded (and incrementally updated) automatically each frame. Here we simply inspect the live texture list that
* the backend maintains and render the managed atlas texture inline.
*/
private void showTextureManagement() {
if (!ImGui.collapsingHeader("Texture Management")) {
return;
}

final ImGuiIO io = ImGui.getIO();
final boolean hasTextures = io.hasBackendFlags(ImGuiBackendFlags.RendererHasTextures);
ImGui.text("RendererHasTextures: " + (hasTextures ? "enabled" : "disabled"));

final ImGuiPlatformIO platformIO = ImGui.getPlatformIO();
final int texturesCount = platformIO.getTexturesSize();
ImGui.text("Textures managed by Dear ImGui: " + texturesCount);

for (int i = 0; i < texturesCount; i++) {
final ImTextureData tex = platformIO.getTextures(i);
ImGui.bulletText(String.format(
"#%d %dx%d %s status=%s texID=%d",
tex.getUniqueID(), tex.getWidth(), tex.getHeight(),
formatName(tex.getFormat()), statusName(tex.getStatus()), tex.getTexID()));

// Render any RGBA texture that has already been uploaded (the font atlas is the usual one).
if (tex.getStatus() == ImTextureStatus.OK && tex.getTexID() != 0 && tex.getFormat() == ImTextureFormat.RGBA32) {
final float preview = 256.0f;
final float aspect = tex.getHeight() / (float) tex.getWidth();
ImGui.image(tex.getTexID(), preview, preview * aspect);
}
}
}

private static String formatName(final int format) {
if (format == ImTextureFormat.RGBA32) {
return "RGBA32";
} else if (format == ImTextureFormat.Alpha8) {
return "Alpha8";
}
return "Unknown(" + format + ")";
}

private static String statusName(final int status) {
if (status == ImTextureStatus.OK) {
return "OK";
} else if (status == ImTextureStatus.WantCreate) {
return "WantCreate";
} else if (status == ImTextureStatus.WantUpdates) {
return "WantUpdates";
} else if (status == ImTextureStatus.WantDestroy) {
return "WantDestroy";
} else if (status == ImTextureStatus.Destroyed) {
return "Destroyed";
}
return "Unknown(" + status + ")";
}

private static byte[] loadFromResources(String name) {
try {
return Files.readAllBytes(Paths.get(Main.class.getResource(name).toURI()));
Expand Down
26 changes: 26 additions & 0 deletions imgui-binding/src/generated/java/imgui/ImDrawData.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public final class ImDrawData extends ImGuiStruct {
private static final int RESIZE_FACTOR = 5_000;
private static ByteBuffer dataBuffer = ByteBuffer.allocateDirect(25_000).order(ByteOrder.nativeOrder());

private static final ImTextureData _GETTEXTURES_1 = new ImTextureData(0);

public ImDrawData(final long ptr) {
super(ptr);
}
Expand Down Expand Up @@ -134,6 +136,30 @@ public ByteBuffer getCmdListVtxBufferData(final int cmdListIdx) {
memcpy(vtxBuffer, THIS->CmdLists[cmdListIdx]->VtxBuffer.Data, vtxBufferCapacity);
*/

/**
* Number of textures to update before rendering this draw data. Most of the time the list is shared by all
* ImDrawData, has only one texture and does not need any update. This almost always mirrors
* {@link ImGuiPlatformIO#getTexturesSize()}. May be zero if texture updates are disabled (list set to NULL).
*/
public native int getTexturesSize(); /*
return THIS->Textures != NULL ? THIS->Textures->Size : 0;
*/

/**
* Texture to update at the given index. The returned value is a shared instance, valid only until the next call to
* this method.
*
* @param idx index in {@code [0, getTexturesSize())}
*/
public ImTextureData getTextures(final int idx) {
_GETTEXTURES_1.ptr = nGetTextures(idx);
return _GETTEXTURES_1;
}

private native long nGetTextures(int idx); /*
return (uintptr_t)(*THIS->Textures)[idx];
*/

public static native int sizeOfImDrawVert(); /*
return (int)sizeof(ImDrawVert);
*/
Expand Down
60 changes: 60 additions & 0 deletions imgui-binding/src/generated/java/imgui/ImGuiPlatformIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public final class ImGuiPlatformIO extends ImGuiStruct {
private static final ImGuiViewport TMP_VIEWPORT = new ImGuiViewport(0);
private static final ImGuiPlatformMonitor TMP_MONITOR = new ImGuiPlatformMonitor(0);
private static final ImVec2 TMP_IM_VEC2 = new ImVec2();
private static final ImTextureData TMP_TEXTURE_DATA = new ImTextureData(0);

public ImGuiPlatformIO(final long ptr) {
super(ptr);
Expand Down Expand Up @@ -545,4 +546,63 @@ public ImGuiViewport getViewports(final int idx) {
private native long nGetViewports(int idx); /*
return (uintptr_t)IMGUI_PLATFORM_IO->Viewports[idx];
*/

//------------------------------------------------------------------
// Textures list (updated by dear imgui, honored by the renderer backend)
//------------------------------------------------------------------

/**
* Maximum texture width the renderer backend supports. Set by the renderer backend during initialization so the
* core library can split the font atlas accordingly. Zero means unbounded.
*/
public native int getRendererTextureMaxWidth(); /*
return IMGUI_PLATFORM_IO->Renderer_TextureMaxWidth;
*/

/**
* Maximum texture width the renderer backend supports. Set by the renderer backend during initialization so the
* core library can split the font atlas accordingly. Zero means unbounded.
*/
public native void setRendererTextureMaxWidth(int value); /*
IMGUI_PLATFORM_IO->Renderer_TextureMaxWidth = value;
*/

/**
* Maximum texture height the renderer backend supports. Set by the renderer backend during initialization so the
* core library can split the font atlas accordingly. Zero means unbounded.
*/
public native int getRendererTextureMaxHeight(); /*
return IMGUI_PLATFORM_IO->Renderer_TextureMaxHeight;
*/

/**
* Maximum texture height the renderer backend supports. Set by the renderer backend during initialization so the
* core library can split the font atlas accordingly. Zero means unbounded.
*/
public native void setRendererTextureMaxHeight(int value); /*
IMGUI_PLATFORM_IO->Renderer_TextureMaxHeight = value;
*/

/**
* Number of textures used by Dear ImGui (most often one). The renderer backend iterates this list to
* create/update/destroy textures.
*/
public native int getTexturesSize(); /*
return IMGUI_PLATFORM_IO->Textures.Size;
*/

/**
* Texture at the given index. The returned value is a shared instance, valid only until the next call to this
* method.
*
* @param idx index in {@code [0, getTexturesSize())}
*/
public ImTextureData getTextures(final int idx) {
TMP_TEXTURE_DATA.ptr = nGetTextures(idx);
return TMP_TEXTURE_DATA;
}

private native long nGetTextures(int idx); /*
return (uintptr_t)IMGUI_PLATFORM_IO->Textures[idx];
*/
}
Loading
Loading