2
0
Эх сурвалжийг харах

Textures: Added ImTextureRef::GetTexID() mostly for consistency.

Without it the logic may seem more confusing to grok for end-user.
ocornut 5 сар өмнө
parent
commit
8bd1fc4f04
1 өөрчлөгдсөн 8 нэмэгдсэн , 2 устгасан
  1. 8 2
      imgui.h

+ 8 - 2
imgui.h

@@ -343,6 +343,7 @@ struct ImTextureRef
     ImTextureRef(void* tex_id)              { memset(this, 0, sizeof(*this)); _TexID = (ImTextureID)(size_t)tex_id; }   // For legacy backends casting to ImTextureID
     ImTextureRef(void* tex_id)              { memset(this, 0, sizeof(*this)); _TexID = (ImTextureID)(size_t)tex_id; }   // For legacy backends casting to ImTextureID
     //inline operator intptr_t() const      { return (intptr_t)_TexID; }                                                // For legacy backends casting to ImTextureID
     //inline operator intptr_t() const      { return (intptr_t)_TexID; }                                                // For legacy backends casting to ImTextureID
 #endif
 #endif
+    inline ImTextureID GetTexID() const;    // == (_TexData ? _TexData->TexID : _TexID) // Implemented below in the file.
 
 
     // Members
     // Members
     ImTextureData*  _TexData;               // Texture, generally owned by a ImFontAtlas
     ImTextureData*  _TexData;               // Texture, generally owned by a ImFontAtlas
@@ -3072,7 +3073,7 @@ struct ImDrawCmd
     // Since 1.83: returns ImTextureID associated with this draw call. Warning: DO NOT assume this is always same as 'TextureId' (we will change this function for an upcoming feature)
     // Since 1.83: returns ImTextureID associated with this draw call. Warning: DO NOT assume this is always same as 'TextureId' (we will change this function for an upcoming feature)
     // Since 1.92: removed ImDrawCmd::TextureId field, the getter function must be used!
     // Since 1.92: removed ImDrawCmd::TextureId field, the getter function must be used!
     // If for some reason you non C++ tech stack makes it difficult to call it, we may decide to separate the fields in ImDrawCmd.
     // If for some reason you non C++ tech stack makes it difficult to call it, we may decide to separate the fields in ImDrawCmd.
-    inline ImTextureID GetTexID() const;
+    inline ImTextureID GetTexID() const;    // == (TexRef._TexData ? TexRef._TexData->TexID : TexRef._TexID
 };
 };
 
 
 // Vertex layout
 // Vertex layout
@@ -3735,7 +3736,12 @@ struct ImFont
     IMGUI_API bool              IsGlyphRangeUnused(unsigned int c_begin, unsigned int c_last);
     IMGUI_API bool              IsGlyphRangeUnused(unsigned int c_begin, unsigned int c_last);
 };
 };
 
 
-// Added indirection to avoid patching ImDrawCmd after texture updates.
+// We added an indirection to avoid patching ImDrawCmd after texture updates but this could be a solution too.
+inline ImTextureID ImTextureRef::GetTexID() const
+{
+    return _TexData ? _TexData->TexID : _TexID;
+}
+
 inline ImTextureID ImDrawCmd::GetTexID() const
 inline ImTextureID ImDrawCmd::GetTexID() const
 {
 {
     // If you are getting this assert: A renderer backend with support for ImGuiBackendFlags_RendererHasTextures (1.92)
     // If you are getting this assert: A renderer backend with support for ImGuiBackendFlags_RendererHasTextures (1.92)