mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-11 00:04:24 +00:00
Textures: Added ImTextureData::UsedRect.
# Conflicts: # imgui_internal.h
This commit is contained in:
parent
2bf6879dae
commit
e98a314e06
4 changed files with 15 additions and 5 deletions
|
|
@ -15724,10 +15724,13 @@ void ImGui::DebugNodeTexture(ImTextureData* tex)
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
if (TreeNode(tex, "Texture #%03d (%dx%d pixels)", tex->UniqueID, tex->Width, tex->Height))
|
if (TreeNode(tex, "Texture #%03d (%dx%d pixels)", tex->UniqueID, tex->Width, tex->Height))
|
||||||
{
|
{
|
||||||
|
ImGuiMetricsConfig* cfg = &g.DebugMetricsConfig;
|
||||||
|
Checkbox("Show used rect", &cfg->ShowTextureUsedRect);
|
||||||
PushStyleVar(ImGuiStyleVar_ImageBorderSize, ImMax(1.0f, g.Style.ImageBorderSize));
|
PushStyleVar(ImGuiStyleVar_ImageBorderSize, ImMax(1.0f, g.Style.ImageBorderSize));
|
||||||
ImTextureRef tex_id;
|
ImVec2 p = GetCursorScreenPos();
|
||||||
tex_id._TexData = tex; // Don't use tex->TexID directly so first frame works.
|
ImageWithBg(tex->GetTexRef(), ImVec2((float)tex->Width, (float)tex->Height), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||||
ImageWithBg(tex_id, ImVec2((float)tex->Width, (float)tex->Height), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
|
if (cfg->ShowTextureUsedRect)
|
||||||
|
GetWindowDrawList()->AddRect(ImVec2(p.x + tex->UsedRect.x, p.y + tex->UsedRect.y), ImVec2(p.x + tex->UsedRect.x + tex->UsedRect.w, p.y + tex->UsedRect.y + tex->UsedRect.h), IM_COL32(255, 0, 255, 255));
|
||||||
PopStyleVar();
|
PopStyleVar();
|
||||||
|
|
||||||
char texid_desc[20];
|
char texid_desc[20];
|
||||||
|
|
|
||||||
3
imgui.h
3
imgui.h
|
|
@ -3389,7 +3389,8 @@ struct IMGUI_API ImTextureData
|
||||||
unsigned char* Pixels; // Pointer to buffer holding 'Width*Height' pixels and 'Width*Height*BytesPerPixels' bytes.
|
unsigned char* Pixels; // Pointer to buffer holding 'Width*Height' pixels and 'Width*Height*BytesPerPixels' bytes.
|
||||||
ImTextureID TexID; // Always use SetTexID() to modify! Identifier stored in ImDrawCmd::GetTexID() and passed to backend RenderDrawData loop.
|
ImTextureID TexID; // Always use SetTexID() to modify! Identifier stored in ImDrawCmd::GetTexID() and passed to backend RenderDrawData loop.
|
||||||
void* BackendUserData; // Convenience storage for backend. Some backends may have enough with TexID.
|
void* BackendUserData; // Convenience storage for backend. Some backends may have enough with TexID.
|
||||||
ImTextureRect UpdateRect; // Bounding box encompassing all individual updates.
|
ImTextureRect UsedRect; // Bounding box encompassing all past and queued Updates[].
|
||||||
|
ImTextureRect UpdateRect; // Bounding box encompassing all queued Updates[].
|
||||||
ImVector<ImTextureRect> Updates; // Array of individual updates.
|
ImVector<ImTextureRect> Updates; // Array of individual updates.
|
||||||
int UnusedFrames; // In order to facilitate handling Status==WantDestroy in some backend: this is a count successive frames where the texture was not used. Always >0 when Status==WantDestroy.
|
int UnusedFrames; // In order to facilitate handling Status==WantDestroy in some backend: this is a count successive frames where the texture was not used. Always >0 when Status==WantDestroy.
|
||||||
unsigned short RefCount; // Number of contexts using this texture.
|
unsigned short RefCount; // Number of contexts using this texture.
|
||||||
|
|
|
||||||
|
|
@ -2439,6 +2439,7 @@ void ImTextureData::Create(ImTextureFormat format, int w, int h)
|
||||||
Pixels = (unsigned char*)IM_ALLOC(Width * Height * BytesPerPixel);
|
Pixels = (unsigned char*)IM_ALLOC(Width * Height * BytesPerPixel);
|
||||||
IM_ASSERT(Pixels != NULL);
|
IM_ASSERT(Pixels != NULL);
|
||||||
memset(Pixels, 0, Width * Height * BytesPerPixel);
|
memset(Pixels, 0, Width * Height * BytesPerPixel);
|
||||||
|
UsedRect.x = UsedRect.y = UsedRect.w = UsedRect.h = 0;
|
||||||
UpdateRect.x = UpdateRect.y = (unsigned short)~0;
|
UpdateRect.x = UpdateRect.y = (unsigned short)~0;
|
||||||
UpdateRect.w = UpdateRect.h = 0;
|
UpdateRect.w = UpdateRect.h = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -2918,6 +2919,10 @@ void ImFontAtlasTextureBlockQueueUpload(ImFontAtlas* atlas, ImTextureData* tex,
|
||||||
tex->UpdateRect.y = ImMin(tex->UpdateRect.y, req.y);
|
tex->UpdateRect.y = ImMin(tex->UpdateRect.y, req.y);
|
||||||
tex->UpdateRect.w = (unsigned short)(new_x1 - tex->UpdateRect.x);
|
tex->UpdateRect.w = (unsigned short)(new_x1 - tex->UpdateRect.x);
|
||||||
tex->UpdateRect.h = (unsigned short)(new_y1 - tex->UpdateRect.y);
|
tex->UpdateRect.h = (unsigned short)(new_y1 - tex->UpdateRect.y);
|
||||||
|
tex->UsedRect.x = ImMin(tex->UsedRect.x, req.x);
|
||||||
|
tex->UsedRect.y = ImMin(tex->UsedRect.y, req.y);
|
||||||
|
tex->UsedRect.w = (unsigned short)(ImMax(tex->UsedRect.x + tex->UsedRect.w, req.x + req.w) - tex->UsedRect.x);
|
||||||
|
tex->UsedRect.h = (unsigned short)(ImMax(tex->UsedRect.y + tex->UsedRect.h, req.y + req.h) - tex->UsedRect.y);
|
||||||
atlas->TexIsBuilt = false;
|
atlas->TexIsBuilt = false;
|
||||||
|
|
||||||
// No need to queue if status is _WantCreate
|
// No need to queue if status is _WantCreate
|
||||||
|
|
@ -3957,7 +3962,7 @@ void ImFontAtlasBuildGrowTexture(ImFontAtlas* atlas, int old_tex_w, int old_tex_
|
||||||
old_tex_h = atlas->TexData->Height;
|
old_tex_h = atlas->TexData->Height;
|
||||||
|
|
||||||
// FIXME-NEWATLAS-V2: What to do when reaching limits exposed by backend?
|
// FIXME-NEWATLAS-V2: What to do when reaching limits exposed by backend?
|
||||||
// FIXME-NEWATLAS-V2: Does ImFontAtlasFlags_NoPowerOfTwoHeight makes sense now? Allow 'lock' and 'compact' operations? Could we expose e.g. tex->UsedRect.
|
// FIXME-NEWATLAS-V2: Does ImFontAtlasFlags_NoPowerOfTwoHeight makes sense now? Allow 'lock' and 'compact' operations?
|
||||||
IM_ASSERT(ImIsPowerOfTwo(old_tex_w) && ImIsPowerOfTwo(old_tex_h));
|
IM_ASSERT(ImIsPowerOfTwo(old_tex_w) && ImIsPowerOfTwo(old_tex_h));
|
||||||
IM_ASSERT(ImIsPowerOfTwo(atlas->TexMinWidth) && ImIsPowerOfTwo(atlas->TexMaxWidth) && ImIsPowerOfTwo(atlas->TexMinHeight) && ImIsPowerOfTwo(atlas->TexMaxHeight));
|
IM_ASSERT(ImIsPowerOfTwo(atlas->TexMinWidth) && ImIsPowerOfTwo(atlas->TexMaxWidth) && ImIsPowerOfTwo(atlas->TexMinHeight) && ImIsPowerOfTwo(atlas->TexMaxHeight));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2075,6 +2075,7 @@ struct ImGuiMetricsConfig
|
||||||
bool ShowDrawCmdMesh = true;
|
bool ShowDrawCmdMesh = true;
|
||||||
bool ShowDrawCmdBoundingBoxes = true;
|
bool ShowDrawCmdBoundingBoxes = true;
|
||||||
bool ShowTextEncodingViewer = false;
|
bool ShowTextEncodingViewer = false;
|
||||||
|
bool ShowTextureUsedRect = false;
|
||||||
int ShowWindowsRectsType = -1;
|
int ShowWindowsRectsType = -1;
|
||||||
int ShowTablesRectsType = -1;
|
int ShowTablesRectsType = -1;
|
||||||
int HighlightMonitorIdx = -1;
|
int HighlightMonitorIdx = -1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue