Browse Source

Docs: update Backends with direction for implementing RenderDrawData function and supporting ImGuiBackendFlags_RendererHasTextures. (#8735, #8465)

ocornut 1 tháng trước cách đây
mục cha
commit
47570d045d
7 tập tin đã thay đổi với 228 bổ sung111 xóa
  1. 177 14
      docs/BACKENDS.md
  2. 3 0
      docs/CHANGELOG.txt
  3. 1 1
      docs/EXAMPLES.md
  4. 11 2
      docs/FAQ.md
  5. 30 93
      imgui.cpp
  6. 1 1
      imgui.h
  7. 5 0
      imgui_demo.cpp

+ 177 - 14
docs/BACKENDS.md

@@ -7,9 +7,10 @@ _(You may browse this at https://github.com/ocornut/imgui/blob/master/docs/BACKE
 - [Introduction](#introduction)
 - [Using standard backends](#using-standard-backends)
 - [List of third-party backends](#list-of-third-party-backends)
-- [Writing your own backend](#writing-your-own-backend)
+- [Writing your own Backend](#writing-your-own-backend)
   - [Using a custom engine?](#using-a-custom-engine)
-  - [Adding support for `ImGuiBackendFlags_RendererHasTextures` (1.92+)](#adding-support-for-imguibackendflags_rendererhastextures-192)
+  - [Rendering: Implementing your RenderDrawData function](#rendering-implementing-your-renderdrawdata-function)
+  - [Rendering: Adding support for `ImGuiBackendFlags_RendererHasTextures` (1.92+)](#rendering-adding-support-for-imguibackendflags_rendererhastextures-192)
 
 ## Introduction
 
@@ -117,15 +118,20 @@ If your application runs on Windows or if you are using multi-viewport, the win3
 
 See https://github.com/ocornut/imgui/wiki/Bindings for the full list (e.g. Adventure Game Studio, Cinder, Cocos2d-x, Game Maker Studio2, Godot, LÖVE+LUA, Magnum, Monogame, Ogre, openFrameworks, OpenSceneGraph, SFML, Sokol, Unity, Unreal Engine and many others).
 
-## Writing your own backend
+## Writing your own Backend
 
 ### Using a custom engine?
 
 You will likely be tempted to start by rewrite your own backend using your own custom/high-level facilities...<BR>
 Think twice!
 
+TL;DR;
+- Writing your own Renderer Backend is easy.
+- Writing your own Platform Backend is harder and you are more likely to introduce bugs.
+- **It is unlikely you will add value to your project by creating your own backend.**
+
 **Consider using the existing backends as-is**.
-You will save lots of time integrating the library. 
+You will save lots of time integrating the library.
 Standard backends are battle-tested and handle subtleties that you are likely to implement incorrectly.
 You can LATER decide to rewrite yourself a custom backend if you really need to.
 In most situations, custom backends have fewer features and more bugs than the standard backends we provide.
@@ -148,23 +154,180 @@ Suggestion: try using a non-portable backend first (e.g. win32 + underlying grap
 your desktop builds working first. This will get you running faster and get your acquainted with
 how Dear ImGui works and is setup. You can then rewrite a custom backend using your own engine API...
 
-TL;DR;
-- **It is unlikely you will add value to your project by creating your own backend.**
-- Writing your own Renderer Backend is easier.
-- Writing your own Platform Backend is harder and you are more likely to introduce bugs.
-
 Also:
 The [multi-viewports feature](https://github.com/ocornut/imgui/wiki/Multi-Viewports) of the 'docking' branch allows
 Dear ImGui windows to be seamlessly detached from the main application window. This is achieved using an
 extra layer to the Platform and Renderer backends, which allows Dear ImGui to communicate platform-specific
 requests such as: "create an additional OS window", "create a render context", "get the OS position of this
-window" etc. See 'ImGuiPlatformIO' for details.
+window", but some things are more difficult "find OS window under mouse position BUT with some windows marked as passthrough". See 'ImGuiPlatformIO' for details.
 Supporting the multi-viewports feature correctly using 100% of your own abstractions is more difficult
 than supporting single-viewport.
 If you decide to use unmodified imgui_impl_XXXX.cpp files, you can automatically benefit from
 improvements and fixes related to viewports and platform windows without extra work on your side.
 
-### Adding support for `ImGuiBackendFlags_RendererHasTextures` (1.92+)
-
-Version [1.92.0](https://github.com/ocornut/imgui/releases/tag/v1.92.0), released June 2025, added texture support in Rendering Backends, which is the backbone for supporting dynamic font scaling among other things.
-<BR>**In order to move forward and take advantage of all new features, support for `ImGuiBackendFlags_RendererHasTextures` will likely be REQUIRED for all backends before June 2026.**
+### Rendering: Implementing your RenderDrawData function
+
+Note: set `ImGuiBackendFlags_RendererHasVtxOffset` to signify your backend can handle rendering with a vertex offset (`ImDrawCmd::VtxOffset` field).
+Otherwise, rendering will be limited to 64K vertices per window, which may be limiting for advanced plot.
+As an alternative, you may also use `#define ImDrawIdx unsigned int` in your `imconfig.h` file to support 32-bit indices.
+
+```cpp
+void MyImGuiBackend_RenderDrawData(ImDrawData* draw_data)
+{
+    // TODO: Update textures.
+    // - Most of the times, the list will have 1 element with an OK status, aka nothing to do.
+    // - This almost always points to ImGui::GetPlatformIO().Textures[] but is part of ImDrawData to allow overriding or disabling texture updates.
+    if (draw_data->Textures != nullptr)
+        for (ImTextureData* tex : *draw_data->Textures)
+            if (tex->Status != ImTextureStatus_OK)
+                MyImGuiBackend_UpdateTexture(tex);
+
+    // TODO: Setup render state:
+    // - Alpha-blending enabled
+    // - No backface culling
+    // - No depth testing, no depth writing
+    // - Scissor enabled
+    MyEngineSetupenderState();
+
+    // TODO: Setup texture sampling state
+    // - Sample with bilinear filtering (NOT point/nearest filtering).
+    // - Use 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines;' to allow point/nearest filtering.
+
+    // TODO: Setup viewport covering draw_data->DisplayPos to draw_data->DisplayPos + draw_data->DisplaySize
+
+    // TODO: Setup orthographic projection matrix cover draw_data->DisplayPos to draw_data->DisplayPos + draw_data->DisplaySize
+
+    // TODO: Setup shader: vertex { float2 pos, float2 uv, u32 color }, fragment shader sample color from 1 texture, multiply by vertex color.
+
+    // Render command lists
+    ImVec2 clip_off = draw_data->DisplayPos;
+    ImVec2 clip_scale = draw_data->FramebufferScale;
+    for (int n = 0; n < draw_data->CmdListsCount; n++)
+    {
+        const ImDrawList* cmd_list = draw_data->CmdLists[n];
+        const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data;  // vertex buffer generated by Dear ImGui
+        const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data;   // index buffer generated by Dear ImGui
+        for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
+        {
+            const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
+            if (pcmd->UserCallback)
+            {
+                if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
+                    MyEngineSetupenderState();
+                else
+                    pcmd->UserCallback(cmd_list, pcmd);
+            }
+            else
+            {
+                // Project scissor/clipping rectangles into framebuffer space
+                // - Clipping coordinates are provided in imgui coordinates space:
+                //   - For a given viewport, draw_data->DisplayPos == viewport->Pos and draw_data->DisplaySize == viewport->Size
+                //   - In a single viewport application, draw_data->DisplayPos == (0,0) and draw_data->DisplaySize == io.DisplaySize, but always use GetMainViewport()->Pos/Size instead of hardcoding those values.
+                //   - In the interest of supporting multi-viewport applications (see 'docking' branch on github),
+                //     always subtract draw_data->DisplayPos from clipping bounds to convert them to your viewport space.
+                // - Note that pcmd->ClipRect contains Min+Max bounds. Some graphics API may use Min+Max, other may use Min+Size (size being Max-Min)
+                ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y);
+                ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y);
+                if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
+                    continue;
+
+                // We are using scissoring to clip some objects. All low-level graphics API should support it.
+                // - If your engine doesn't support scissoring yet, you may ignore this at first. You will get some small glitches
+                //   (some elements visible outside their bounds) but you can fix that once everything else works!
+                MyEngineSetScissor(clip_min.x, clip_min.y, clip_max.x, clip_max.y);
+
+                // The texture for the draw call is specified by pcmd->GetTexID().
+                // The vast majority of draw calls will use the Dear ImGui texture atlas, which value you have set yourself during initialization.
+                MyEngineBindTexture((MyTexture*)pcmd->GetTexID());
+
+                // Render 'pcmd->ElemCount/3' indexed triangles.
+                // By default the indices ImDrawIdx are 16-bit, you can change them to 32-bit in imconfig.h if your engine doesn't support 16-bit indices.
+                MyEngineDrawIndexedTriangles(pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer + pcmd->IdxOffset, vtx_buffer, pcmd->VtxOffset);
+            }
+        }
+    }
+}
+```
+
+### Rendering: Adding support for `ImGuiBackendFlags_RendererHasTextures` (1.92+)
+
+Version [1.92.0](https://github.com/ocornut/imgui/releases/tag/v1.92.0) (June 2025), added texture support in Rendering Backends, which is the backbone for supporting dynamic font scaling among other things.
+
+**In order to move forward and take advantage of all new features, support for `ImGuiBackendFlags_RendererHasTextures` will likely be REQUIRED for all backends before June 2026.**
+
+**TD;DR: List of commits which added support for `ImGuiBackendFlags_RendererHasTextures` in standard backends:**
+
+- Allegro5: [ee8941e](https://github.com/ocornut/imgui/commit/ee8941e) (+35 lines)
+- DirectX9: [75efba7](https://github.com/ocornut/imgui/commit/75efba7) (+48 lines)
+- DirectX10: [2d2b1bc](https://github.com/ocornut/imgui/commit/2d2b1bc) (+40 lines)
+- DirectX11: [372fd27](https://github.com/ocornut/imgui/commit/372fd27) (+40 lines)
+- DirectX12: [eefe5d5](https://github.com/ocornut/imgui/commit/eefe5d5) (+87 lines)
+- Metal: [26c017d](https://github.com/ocornut/imgui/commit/26c017d) (+55 lines)
+- OpenGL Legacy: [0430c55](https://github.com/ocornut/imgui/commit/0430c55) (+25 lines)
+- OpenGL3/WebGL/ES: [dbb91a5](https://github.com/ocornut/imgui/commit/dbb91a5) (+47 lines)
+- SDL_Renderer2: [9fa65cd](https://github.com/ocornut/imgui/commit/9fa65cd) (+20 lines)
+- SDL_Renderer3: [e538883](https://github.com/ocornut/imgui/commit/e538883) (+19 lines)
+- SDL_GPU: [16fe666](https://github.com/ocornut/imgui/commit/16fe666) (+41 lines)
+- Vulkan: [abe294b](https://github.com/ocornut/imgui/commit/abe294b) (+33 lines)
+- WGPU: [571dae9](https://github.com/ocornut/imgui/commit/571dae9) (+30 lines)
+
+**Instructions**
+
+- Set `ImGuiBackendFlags_RendererHasTextures` to signify your backend can handle the feature.
+- During rendering, e.g. in your RenderDrawData function, iterate `ImDrawData->Textures` array and process all textures.
+- During shutdown, iterate the `ImGui::GetPlatformIO().Textures` and destroy all textures.
+- (Both arrays are `ImVector<ImTextureData*>`. They are only in different location because: to allow advanced users to perform multi-threaded rendering, we store a pointer to the texture list in ImDrawData, with the aim that multi-threaded rendering users replace it with their own pointer.)
+
+Pseudo-code for processing a texture:
+```cpp
+if (draw_data->Textures != nullptr)
+    for (ImTextureData* tex : *draw_data->Textures)
+        if (tex->Status != ImTextureStatus_OK)
+            MyImGuiBackend_UpdateTexture(tex);
+```
+```cpp
+void MyImGuiBackend_UpdateTexture(ImTextureData* tex)
+{
+    if (tex->Status == ImTextureStatus_WantCreate)
+    {
+        // Create texture based on tex->Width, tex->Height.
+        // - Most backends only support tex->Format == ImTextureFormat_RGBA32.
+        // - Backends for particularly memory constrainted platforms may support tex->Format == ImTextureFormat_Alpha8.
+
+        // Upload all texture pixels
+        // - Read from our CPU-side copy of the texture and copy to your graphics API.
+        // - Use tex->Width, tex->Height, tex->GetPixels(), tex->GetPixelsAt(), tex->GetPitch() as needed.
+
+        // Store your data, and acknowledge creation.
+        tex->SetTexID(xxxx); // Specify backend-specific ImTextureID identifier which will be stored in ImDrawCmd.
+        tex->SetStatus(ImTextureStatus_OK);
+        tex->BackendUserData = xxxx; // Store more backend data if needed (most backend allocate a small texture to store data in there)
+    }
+    if (tex->Status == ImTextureStatus_WantUpdates)
+    {
+        // Upload a rectangle of pixels to the existing texture
+        // - We only ever write to textures regions which have never been used before!
+        // - Use tex->TexID or tex->BackendUserData to retrieve your stored data.
+        // - Use tex->UpdateRect.x/y, tex->UpdateRect.w/h to obtain the block position and size.
+        //   - Use tex->Updates[] to obtain individual sub-regions within tex->UpdateRect. Not recommended.
+        // - Read from our CPU-side copy of the texture and copy to your graphics API.
+        // - Use tex->Width, tex->Height, tex->GetPixels(), tex->GetPixelsAt(), tex->GetPitch() as needed.
+
+        // Acknowledge update
+        tex->SetStatus(ImTextureStatus_OK);
+    }
+    if (tex->Status == ImTextureStatus_WantDestroy && tex->UnusedFrames > 0)
+    {
+        // If you use staged rendering and have in-flight renders, changed tex->UnusedFrames > 0 check to higher count as needed e.g. > 2
+
+        // Destroy texture
+        // - Use tex->TexID or tex->BackendUserData to retrieve your stored data.
+        // - Destroy texture in your graphics API.
+
+        // Acknowledge destruction
+        tex->SetTexID(ImTextureID_Invalid);
+        tex->SetStatus(ImTextureStatus_Destroyed);
+    }
+}
+```
+Refer to "List of commits which added support for `ImGuiBackendFlags_RendererHasTextures` in standard backends" above for concrete examples of this.

+ 3 - 0
docs/CHANGELOG.txt

@@ -57,6 +57,9 @@ THIS VERSION CONTAINS THE LARGEST AMOUNT OF BREAKING CHANGES SINCE 2015!
 I TRIED REALLY HARD TO KEEP THEM TO A MINIMUM, REDUCE THE AMOUNT OF INTERFERENCE,
 BUT INEVITABLY SOME USERS OR THIRD-PARTY EXTENSIONS WILL BE AFFECTED.
 
+For instructions to upgrade your custom backend:
+--> See https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md
+
 IN ORDER TO HELP US IMPROVE THE TRANSITION PROCESS, INCL. DOCUMENTATION AND COMMENTS,
 PLEASE REPORT **ANY** DOUBT, CONFUSION, QUESTIONS, FEEDBACK TO:
     https://github.com/ocornut/imgui/issues/

+ 1 - 1
docs/EXAMPLES.md

@@ -3,7 +3,7 @@ _(You may browse this at https://github.com/ocornut/imgui/blob/master/docs/EXAMP
 ## Dear ImGui: Examples
 
 **The [examples/](https://github.com/ocornut/imgui/blob/master/examples) folder example applications (standalone, ready-to-build) for variety of
-platforms and graphics APIs.** They all use standard backends from the [backends/](https://github.com/ocornut/imgui/blob/master/backends) folder (see [BACKENDS.md](https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md)).
+platforms and graphics APIs.** They all use standard backends from the [backends/](https://github.com/ocornut/imgui/blob/master/backends) folder (see [docs/BACKENDS.md](https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md)).
 
 The purpose of Examples is to showcase integration with backends, let you try Dear ImGui, and guide you toward
 integrating Dear ImGui in your own application/game/engine.

+ 11 - 2
docs/FAQ.md

@@ -19,6 +19,7 @@ or view this file with any Markdown viewer.
 | **[How can I tell whether to dispatch mouse/keyboard to Dear ImGui or my application?](#q-how-can-i-tell-whether-to-dispatch-mousekeyboard-to-dear-imgui-or-my-application)** |
 | [How can I enable keyboard or gamepad controls?](#q-how-can-i-enable-keyboard-or-gamepad-controls) |
 | [How can I use this on a machine without mouse, keyboard or screen? (input share, remote display)](#q-how-can-i-use-this-on-a-machine-without-mouse-keyboard-or-screen-input-share-remote-display) |
+| [How can I create my own backend?](q-how-can-i-create-my-own-backend)
 | [I integrated Dear ImGui in my engine and little squares are showing instead of text...](#q-i-integrated-dear-imgui-in-my-engine-and-little-squares-are-showing-instead-of-text) |
 | [I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around...](#q-i-integrated-dear-imgui-in-my-engine-and-some-elements-are-clipping-or-disappearing-when-i-move-windows-around) |
 | [I integrated Dear ImGui in my engine and some elements are displaying outside their expected windows boundaries...](#q-i-integrated-dear-imgui-in-my-engine-and-some-elements-are-displaying-outside-their-expected-windows-boundaries) |
@@ -92,8 +93,8 @@ Many projects are using this branch and it is kept in sync with master regularly
 ### Q: How to get started?
 
 Read [Getting Started](https://github.com/ocornut/imgui/wiki/Getting-Started). <BR>
-Read [EXAMPLES.md](https://github.com/ocornut/imgui/blob/master/docs/EXAMPLES.md). <BR>
-Read [BACKENDS.md](https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md). <BR>
+Read [docs/EXAMPLES.md](https://github.com/ocornut/imgui/blob/master/docs/EXAMPLES.md). <BR>
+Read [docs/BACKENDS.md](https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md). <BR>
 Read `PROGRAMMER GUIDE` section of [imgui.cpp](https://github.com/ocornut/imgui/blob/master/imgui.cpp). <BR>
 The [Wiki](https://github.com/ocornut/imgui/wiki) is a hub to many resources and links.
 
@@ -159,6 +160,14 @@ Console SDK also sometimes provide equivalent tooling or wrapper for Synergy-lik
 
 ---
 
+### Q: How can I create my own backend?
+- See [docs/BACKENDS.md](https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md).
+- See Documentation at the top of imgui.cpp.
+
+##### [Return to Index](#index)
+
+---
+
 ### Q: I integrated Dear ImGui in my engine and little squares are showing instead of text...
 Your renderer backend is not using the font texture correctly or it hasn't been uploaded to the GPU.
 - If this happens using standard backends (before 1.92): A) have you modified the font atlas after `ImGui_ImplXXX_NewFrame()`? B) maybe the texture failed to upload, which **can if your texture atlas is too big**. Also see [docs/FONTS.md](https://github.com/ocornut/imgui/blob/master/docs/FONTS.md).

+ 30 - 93
imgui.cpp

@@ -53,7 +53,7 @@ DOCUMENTATION
   - HOW TO UPDATE TO A NEWER VERSION OF DEAR IMGUI
   - GETTING STARTED WITH INTEGRATING DEAR IMGUI IN YOUR CODE/ENGINE
   - HOW A SIMPLE APPLICATION MAY LOOK LIKE
-  - HOW A SIMPLE RENDERING FUNCTION MAY LOOK LIKE
+  - USING CUSTOM BACKEND / CUSTOM ENGINE
 - API BREAKING CHANGES (read me when you update!)
 - FREQUENTLY ASKED QUESTIONS (FAQ)
   - Read all answers online: https://www.dearimgui.com/faq, or in docs/FAQ.md (with a Markdown viewer)
@@ -274,7 +274,8 @@ CODE
 
  HOW A SIMPLE APPLICATION MAY LOOK LIKE
  --------------------------------------
- EXHIBIT 1: USING THE EXAMPLE BACKENDS (= imgui_impl_XXX.cpp files from the backends/ folder).
+
+ USING THE EXAMPLE BACKENDS (= imgui_impl_XXX.cpp files from the backends/ folder).
  The sub-folders in examples/ contain examples applications following this structure.
 
      // Application init: create a dear imgui context, setup some options, load fonts
@@ -310,7 +311,27 @@ CODE
      ImGui_ImplWin32_Shutdown();
      ImGui::DestroyContext();
 
- EXHIBIT 2: IMPLEMENTING CUSTOM BACKEND / CUSTOM ENGINE
+ To decide whether to dispatch mouse/keyboard inputs to Dear ImGui to the rest of your application,
+ you should read the 'io.WantCaptureMouse', 'io.WantCaptureKeyboard' and 'io.WantTextInput' flags!
+ Please read the FAQ entry "How can I tell whether to dispatch mouse/keyboard to Dear ImGui or my application?" about this.
+
+
+USING CUSTOM BACKEND / CUSTOM ENGINE
+------------------------------------
+
+IMPLEMENTING YOUR RenderDrawData() function:
+ -> see https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md
+ -> the Renderer Backends in impl_impl_XXX.cpp files contain many implementations of a ImGui_ImplXXXX_RenderDrawData() function.
+
+IMPLEMENTING SUPPORT for ImGuiBackendFlags_RendererHasTextures:
+ -> see https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md
+ -> the Renderer Backends in impl_impl_XXX.cpp files contain many implementations of a ImGui_ImplXXXX_UpdateTexture() function.
+
+IMPLEMENTING YOUR PLATFORM BACKEND:
+ -> missing documentation.
+ -> the Platform backends in impl_impl_XXX.cpp files contain many implementations.
+
+ Basic application/backend skeleton:
 
      // Application init: create a Dear ImGui context, setup some options, load fonts
      ImGui::CreateContext();
@@ -319,7 +340,7 @@ CODE
      io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;  // Enable keyboard controls
 
      // TODO: Load TTF/OTF fonts if you don't want to use the default font.
-     io.Fonts->AddFontFromFileTTF("NotoSans.ttf", 18.0f);
+     io.Fonts->AddFontFromFileTTF("NotoSans.ttf");
 
      // Application main loop
      while (true)
@@ -361,95 +382,6 @@ CODE
      // Shutdown
      ImGui::DestroyContext();
 
- To decide whether to dispatch mouse/keyboard inputs to Dear ImGui to the rest of your application,
- you should read the 'io.WantCaptureMouse', 'io.WantCaptureKeyboard' and 'io.WantTextInput' flags!
- Please read the FAQ entry "How can I tell whether to dispatch mouse/keyboard to Dear ImGui or my application?" about this.
-
- HOW A SIMPLE RENDERING FUNCTION MAY LOOK LIKE
- ---------------------------------------------
- The backends in impl_impl_XXX.cpp files contain many working implementations of a rendering function.
-
-    void MyImGuiBackend_UpdateTexture(ImTextureData* tex)
-    {
-        if (tex->Status == ImTextureStatus_WantCreate)
-        {
-            // <create texture based on tex->Width/Height/Pixels>
-            tex->SetTexID(xxxx); // specify backend-specific ImTextureID identifier
-            tex->SetStatus(ImTextureStatus_OK);
-            tex->BackendUserData = xxxx; // store more backend data
-        }
-        if (tex->Status == ImTextureStatus_WantUpdates)
-        {
-            // <update texture blocks based on tex->UpdateRect>
-            tex->SetStatus(ImTextureStatus_OK);
-        }
-        if (tex->Status == ImTextureStatus_WantDestroy)
-        {
-            // <destroy texture>
-            tex->SetTexID(ImTextureID_Invalid);
-            tex->SetStatus(ImTextureStatus_Destroyed);
-        }
-    }
-
-    void MyImGuiBackend_RenderDrawData(ImDrawData* draw_data)
-    {
-       if (draw_data->Textures != nullptr)
-           for (ImTextureData* tex : *draw_data->Textures)
-               if (tex->Status != ImTextureStatus_OK)
-                   MyImGuiBackend_UpdateTexture(tex);
-
-
-       // TODO: Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled
-       // TODO: Setup texture sampling state: sample with bilinear filtering (NOT point/nearest filtering). Use 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines;' to allow point/nearest filtering.
-       // TODO: Setup viewport covering draw_data->DisplayPos to draw_data->DisplayPos + draw_data->DisplaySize
-       // TODO: Setup orthographic projection matrix cover draw_data->DisplayPos to draw_data->DisplayPos + draw_data->DisplaySize
-       // TODO: Setup shader: vertex { float2 pos, float2 uv, u32 color }, fragment shader sample color from 1 texture, multiply by vertex color.
-       ImVec2 clip_off = draw_data->DisplayPos;
-       for (int n = 0; n < draw_data->CmdListsCount; n++)
-       {
-          const ImDrawList* cmd_list = draw_data->CmdLists[n];
-          const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data;  // vertex buffer generated by Dear ImGui
-          const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data;   // index buffer generated by Dear ImGui
-          for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
-          {
-             const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
-             if (pcmd->UserCallback)
-             {
-                 if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
-                     MyEngineResetRenderState();
-                 else
-                     pcmd->UserCallback(cmd_list, pcmd);
-             }
-             else
-             {
-                 // Project scissor/clipping rectangles into framebuffer space
-                 ImVec2 clip_min(pcmd->ClipRect.x - clip_off.x, pcmd->ClipRect.y - clip_off.y);
-                 ImVec2 clip_max(pcmd->ClipRect.z - clip_off.x, pcmd->ClipRect.w - clip_off.y);
-                 if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
-                     continue;
-
-                 // We are using scissoring to clip some objects. All low-level graphics API should support it.
-                 // - If your engine doesn't support scissoring yet, you may ignore this at first. You will get some small glitches
-                 //   (some elements visible outside their bounds) but you can fix that once everything else works!
-                 // - Clipping coordinates are provided in imgui coordinates space:
-                 //   - For a given viewport, draw_data->DisplayPos == viewport->Pos and draw_data->DisplaySize == viewport->Size
-                 //   - In a single viewport application, draw_data->DisplayPos == (0,0) and draw_data->DisplaySize == io.DisplaySize, but always use GetMainViewport()->Pos/Size instead of hardcoding those values.
-                 //   - In the interest of supporting multi-viewport applications (see 'docking' branch on github),
-                 //     always subtract draw_data->DisplayPos from clipping bounds to convert them to your viewport space.
-                 // - Note that pcmd->ClipRect contains Min+Max bounds. Some graphics API may use Min+Max, other may use Min+Size (size being Max-Min)
-                 MyEngineSetScissor(clip_min.x, clip_min.y, clip_max.x, clip_max.y);
-
-                 // The texture for the draw call is specified by pcmd->GetTexID().
-                 // The vast majority of draw calls will use the Dear ImGui texture atlas, which value you have set yourself during initialization.
-                 MyEngineBindTexture((MyTexture*)pcmd->GetTexID());
-
-                 // Render 'pcmd->ElemCount/3' indexed triangles.
-                 // By default the indices ImDrawIdx are 16-bit, you can change them to 32-bit in imconfig.h if your engine doesn't support 16-bit indices.
-                 MyEngineDrawIndexedTriangles(pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer + pcmd->IdxOffset, vtx_buffer, pcmd->VtxOffset);
-             }
-          }
-       }
-    }
 
 
  API BREAKING CHANGES
@@ -15941,7 +15873,12 @@ void ImGui::ShowFontAtlas(ImFontAtlas* atlas)
     //SetItemTooltip("When io.ConfigDpiScaleFonts is set, this value is automatically overwritten.");
     //EndDisabled();
     if ((io.BackendFlags & ImGuiBackendFlags_RendererHasTextures) == 0)
+    {
         BulletText("Warning: Font scaling will NOT be smooth, because\nImGuiBackendFlags_RendererHasTextures is not set!");
+        BulletText("For instructions, see:");
+        SameLine();
+        TextLinkOpenURL("docs/BACKENDS.md", "https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md");
+    }
     BulletText("Load a nice font for better results!");
     BulletText("Please submit feedback:");
     SameLine(); TextLinkOpenURL("#8465", "https://github.com/ocornut/imgui/issues/8465");

+ 1 - 1
imgui.h

@@ -1691,7 +1691,7 @@ enum ImGuiBackendFlags_
     ImGuiBackendFlags_HasMouseCursors       = 1 << 1,   // Backend Platform supports honoring GetMouseCursor() value to change the OS cursor shape.
     ImGuiBackendFlags_HasSetMousePos        = 1 << 2,   // Backend Platform supports io.WantSetMousePos requests to reposition the OS mouse position (only used if io.ConfigNavMoveSetMousePos is set).
     ImGuiBackendFlags_RendererHasVtxOffset  = 1 << 3,   // Backend Renderer supports ImDrawCmd::VtxOffset. This enables output of large meshes (64K+ vertices) while still using 16-bit indices.
-    ImGuiBackendFlags_RendererHasTextures   = 1 << 4,   // Backend Renderer supports ImTextureData requests to create/update/destroy textures. This enables incremental texture updates and texture reloads.
+    ImGuiBackendFlags_RendererHasTextures   = 1 << 4,   // Backend Renderer supports ImTextureData requests to create/update/destroy textures. This enables incremental texture updates and texture reloads. See https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md for instructions on how to upgrade your custom backend.
 };
 
 // Enumeration for PushStyleColor() / PopStyleColor()

+ 5 - 0
imgui_demo.cpp

@@ -8230,7 +8230,12 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
         // General
         SeparatorText("General");
         if ((GetIO().BackendFlags & ImGuiBackendFlags_RendererHasTextures) == 0)
+        {
             BulletText("Warning: Font scaling will NOT be smooth, because\nImGuiBackendFlags_RendererHasTextures is not set!");
+            BulletText("For instructions, see:");
+            SameLine();
+            TextLinkOpenURL("docs/BACKENDS.md", "https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md");
+        }
 
         if (ShowStyleSelector("Colors##Selector"))
             ref_saved_style = style;