Skip to content

Commit 9b04311

Browse files
committed
WIP - Fonts: avoid both ImTextureRef being set simultaneously.
1 parent 9037251 commit 9b04311

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

imgui.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -3520,7 +3520,7 @@ struct IMGUI_API ImTextureData
35203520
unsigned char* GetPixelsAt(int x, int y) { IM_ASSERT(Pixels != NULL); return Pixels + (x + y * Width) * BytesPerPixel; }
35213521
int GetSizeInBytes() const { return Width * Height * BytesPerPixel; }
35223522
int GetPitch() const { return Width * BytesPerPixel; }
3523-
ImTextureRef GetTexRef() { ImTextureRef tex_ref; tex_ref._TexData = this; tex_ref._TexID = TexID; return tex_ref; } // FIXME-TEXREF
3523+
ImTextureRef GetTexRef() { ImTextureRef tex_ref; tex_ref._TexData = this; tex_ref._TexID = ImTextureID_Invalid; return tex_ref; }
35243524
ImTextureID GetTexID() const { return TexID; }
35253525
void SetTexID(ImTextureID tex_id){ TexID = tex_id; } // Called by the Renderer backend after creating or destroying the texture. Never modify TexID directly!
35263526
};
@@ -3852,11 +3852,12 @@ struct ImFont
38523852
// We added an indirection to avoid patching ImDrawCmd after texture updates but this could be a solution too.
38533853
inline ImTextureID ImTextureRef::GetTexID() const
38543854
{
3855+
IM_ASSERT(!(_TexData != NULL && _TexID != ImTextureID_Invalid));
38553856
return _TexData ? _TexData->TexID : _TexID;
38563857
}
38573858
inline ImTextureID ImDrawCmd::GetTexID() const
38583859
{
3859-
ImTextureID tex_id = TexRef._TexData ? TexRef._TexData->TexID : TexRef._TexID;
3860+
ImTextureID tex_id = TexRef.GetTexID();
38603861
IM_ASSERT((TexRef._TexData == NULL || tex_id != ImTextureID_Invalid) && "ImDrawCmd is referring to ImTextureData that wasn't uploaded to graphics system. Backend must call ImTextureData::SetTexID()!");
38613862
return tex_id;
38623863
}

imgui_draw.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -2617,7 +2617,6 @@ ImFontAtlas::ImFontAtlas()
26172617
TexMaxWidth = 8192;
26182618
TexMaxHeight = 8192;
26192619
RendererHasTextures = false; // Assumed false by default, as apps can call e.g Atlas::Build() after backend init and before ImGui can update.
2620-
TexRef._TexData = NULL;// this;
26212620
TexNextUniqueID = 1;
26222621
FontNextUniqueID = 1;
26232622
Builder = NULL;
@@ -3885,9 +3884,8 @@ static void ImFontAtlasBuildSetTexture(ImFontAtlas* atlas, ImTextureData* tex)
38853884
atlas->TexData = tex;
38863885
atlas->TexUvScale = ImVec2(1.0f / tex->Width, 1.0f / tex->Height);
38873886
atlas->TexRef._TexData = tex;
3888-
//atlas->TexID._TexID = tex->TexID; // <-- We intentionally don't do that and leave it 0, to allow late upload.
3889-
ImTextureRef new_tex_ref = atlas->TexRef;
3890-
ImFontAtlasUpdateDrawListsTextures(atlas, old_tex_ref, new_tex_ref);
3887+
//atlas->TexRef._TexID = tex->TexID; // <-- We intentionally don't do that. It would be misleading and betray promise that both fields aren't set.
3888+
ImFontAtlasUpdateDrawListsTextures(atlas, old_tex_ref, atlas->TexRef);
38913889
}
38923890

38933891
// Create a new texture, discard previous one

0 commit comments

Comments
 (0)