1
- // dear imgui, v1.92.1
1
+ // dear imgui, v1.92.2b
2
2
// (drawing and font code)
3
3
4
4
/*
@@ -2312,17 +2312,16 @@ void ImDrawData::DeIndexAllBuffers()
2312
2312
{
2313
2313
ImVector<ImDrawVert> new_vtx_buffer;
2314
2314
TotalVtxCount = TotalIdxCount = 0 ;
2315
- for (int i = 0 ; i < CmdListsCount; i++ )
2315
+ for (ImDrawList* draw_list : CmdLists )
2316
2316
{
2317
- ImDrawList* cmd_list = CmdLists[i];
2318
- if (cmd_list->IdxBuffer .empty ())
2317
+ if (draw_list->IdxBuffer .empty ())
2319
2318
continue ;
2320
- new_vtx_buffer.resize (cmd_list ->IdxBuffer .Size );
2321
- for (int j = 0 ; j < cmd_list ->IdxBuffer .Size ; j++)
2322
- new_vtx_buffer[j] = cmd_list ->VtxBuffer [cmd_list ->IdxBuffer [j]];
2323
- cmd_list ->VtxBuffer .swap (new_vtx_buffer);
2324
- cmd_list ->IdxBuffer .resize (0 );
2325
- TotalVtxCount += cmd_list ->VtxBuffer .Size ;
2319
+ new_vtx_buffer.resize (draw_list ->IdxBuffer .Size );
2320
+ for (int j = 0 ; j < draw_list ->IdxBuffer .Size ; j++)
2321
+ new_vtx_buffer[j] = draw_list ->VtxBuffer [draw_list ->IdxBuffer [j]];
2322
+ draw_list ->VtxBuffer .swap (new_vtx_buffer);
2323
+ draw_list ->IdxBuffer .resize (0 );
2324
+ TotalVtxCount += draw_list ->VtxBuffer .Size ;
2326
2325
}
2327
2326
}
2328
2327
@@ -2457,8 +2456,10 @@ const char* ImTextureDataGetFormatName(ImTextureFormat format)
2457
2456
2458
2457
void ImTextureData::Create (ImTextureFormat format, int w, int h)
2459
2458
{
2459
+ IM_ASSERT (Status == ImTextureStatus_Destroyed);
2460
2460
DestroyPixels ();
2461
2461
Format = format;
2462
+ Status = ImTextureStatus_WantCreate;
2462
2463
Width = w;
2463
2464
Height = h;
2464
2465
BytesPerPixel = ImTextureDataGetFormatBytesPerPixel (format);
@@ -2630,6 +2631,7 @@ ImFontAtlas::ImFontAtlas()
2630
2631
TexMinHeight = 128 ;
2631
2632
TexMaxWidth = 8192 ;
2632
2633
TexMaxHeight = 8192 ;
2634
+ TexRef._TexID = ImTextureID_Invalid;
2633
2635
RendererHasTextures = false ; // Assumed false by default, as apps can call e.g Atlas::Build() after backend init and before ImGui can update.
2634
2636
TexNextUniqueID = 1 ;
2635
2637
FontNextUniqueID = 1 ;
@@ -2739,10 +2741,9 @@ void ImFontAtlasUpdateNewFrame(ImFontAtlas* atlas, int frame_count, bool rendere
2739
2741
if (atlas->Builder == NULL ) // This will only happen if fonts were not already loaded.
2740
2742
ImFontAtlasBuildMain (atlas);
2741
2743
}
2742
- else // Legacy backend
2743
- {
2744
+ // Legacy backend
2745
+ if (!atlas-> RendererHasTextures )
2744
2746
IM_ASSERT_USER_ERROR (atlas->TexIsBuilt , " Backend does not support ImGuiBackendFlags_RendererHasTextures, and font atlas is not built! Update backend OR make sure you called ImGui_ImplXXXX_NewFrame() function for renderer backend, which should call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8()." );
2745
- }
2746
2747
if (atlas->TexIsBuilt && atlas->Builder ->PreloadedAllGlyphsRanges )
2747
2748
IM_ASSERT_USER_ERROR (atlas->RendererHasTextures == false , " Called ImFontAtlas::Build() before ImGuiBackendFlags_RendererHasTextures got set! With new backends: you don't need to call Build()." );
2748
2749
@@ -2797,8 +2798,9 @@ void ImFontAtlasUpdateNewFrame(ImFontAtlas* atlas, int frame_count, bool rendere
2797
2798
}
2798
2799
else if (tex->WantDestroyNextFrame && tex->Status != ImTextureStatus_WantDestroy)
2799
2800
{
2800
- // Request destroy. Keep bool as it allows us to keep track of things.
2801
- // We don't destroy pixels right away, as backend may have an in-flight copy from RAM.
2801
+ // Request destroy.
2802
+ // - Keep bool to true in order to differentiate a planned destroy vs a destroy decided by the backend.
2803
+ // - We don't destroy pixels right away, as backend may have an in-flight copy from RAM.
2802
2804
IM_ASSERT (tex->Status == ImTextureStatus_OK || tex->Status == ImTextureStatus_WantCreate || tex->Status == ImTextureStatus_WantUpdates);
2803
2805
tex->Status = ImTextureStatus_WantDestroy;
2804
2806
}
@@ -2954,7 +2956,7 @@ void ImFontAtlasTextureBlockQueueUpload(ImFontAtlas* atlas, ImTextureData* tex,
2954
2956
tex->UsedRect .h = (unsigned short )(ImMax (tex->UsedRect .y + tex->UsedRect .h , req.y + req.h ) - tex->UsedRect .y );
2955
2957
atlas->TexIsBuilt = false ;
2956
2958
2957
- // No need to queue if status is _WantCreate
2959
+ // No need to queue if status is == ImTextureStatus_WantCreate
2958
2960
if (tex->Status == ImTextureStatus_OK || tex->Status == ImTextureStatus_WantUpdates)
2959
2961
{
2960
2962
tex->Status = ImTextureStatus_WantUpdates;
@@ -3361,11 +3363,7 @@ void ImFontAtlasBuildMain(ImFontAtlas* atlas)
3361
3363
{
3362
3364
IM_ASSERT (!atlas->Locked && " Cannot modify a locked ImFontAtlas!" );
3363
3365
if (atlas->TexData && atlas->TexData ->Format != atlas->TexDesiredFormat )
3364
- {
3365
- ImVec2i new_tex_size = ImFontAtlasTextureGetSizeEstimate (atlas);
3366
- ImFontAtlasBuildDestroy (atlas);
3367
- ImFontAtlasTextureAdd (atlas, new_tex_size.x , new_tex_size.y );
3368
- }
3366
+ ImFontAtlasBuildClear (atlas);
3369
3367
3370
3368
if (atlas->Builder == NULL )
3371
3369
ImFontAtlasBuildInit (atlas);
@@ -3971,7 +3969,6 @@ ImTextureData* ImFontAtlasTextureAdd(ImFontAtlas* atlas, int w, int h)
3971
3969
}
3972
3970
3973
3971
new_tex->Create (atlas->TexDesiredFormat , w, h);
3974
- new_tex->Status = ImTextureStatus_WantCreate;
3975
3972
atlas->TexIsBuilt = false ;
3976
3973
3977
3974
ImFontAtlasBuildSetTexture (atlas, new_tex);
@@ -4375,6 +4372,7 @@ ImTextureRect* ImFontAtlasPackGetRectSafe(ImFontAtlas* atlas, ImFontAtlasRectId
4375
4372
if (atlas->Builder == NULL )
4376
4373
ImFontAtlasBuildInit (atlas);
4377
4374
ImFontAtlasBuilder* builder = (ImFontAtlasBuilder*)atlas->Builder ;
4375
+ IM_MSVC_WARNING_SUPPRESS (28182 ); // Static Analysis false positive "warning C28182: Dereferencing NULL pointer 'builder'"
4378
4376
if (index_idx >= builder->RectsIndex .Size )
4379
4377
return NULL ;
4380
4378
ImFontAtlasRectEntry* index_entry = &builder->RectsIndex [index_idx];
@@ -4417,7 +4415,7 @@ static ImFontGlyph* ImFontBaked_BuildLoadGlyph(ImFontBaked* baked, ImWchar codep
4417
4415
if (atlas->Locked || (font->Flags & ImFontFlags_NoLoadGlyphs))
4418
4416
{
4419
4417
// Lazily load fallback glyph
4420
- if (baked->FallbackGlyphIndex == -1 && baked->LockLoadingFallback == 0 )
4418
+ if (baked->FallbackGlyphIndex == -1 && baked->LoadNoFallback == 0 )
4421
4419
ImFontAtlasBuildSetupFontBakedFallback (baked);
4422
4420
return NULL ;
4423
4421
}
@@ -4469,7 +4467,7 @@ static ImFontGlyph* ImFontBaked_BuildLoadGlyph(ImFontBaked* baked, ImWchar codep
4469
4467
}
4470
4468
4471
4469
// Lazily load fallback glyph
4472
- if (baked->LockLoadingFallback )
4470
+ if (baked->LoadNoFallback )
4473
4471
return NULL ;
4474
4472
if (baked->FallbackGlyphIndex == -1 )
4475
4473
ImFontAtlasBuildSetupFontBakedFallback (baked);
@@ -4483,7 +4481,7 @@ static ImFontGlyph* ImFontBaked_BuildLoadGlyph(ImFontBaked* baked, ImWchar codep
4483
4481
4484
4482
static float ImFontBaked_BuildLoadGlyphAdvanceX (ImFontBaked* baked, ImWchar codepoint)
4485
4483
{
4486
- if (baked->Size >= IMGUI_FONT_SIZE_THRESHOLD_FOR_LOADADVANCEXONLYMODE)
4484
+ if (baked->Size >= IMGUI_FONT_SIZE_THRESHOLD_FOR_LOADADVANCEXONLYMODE || baked-> LoadNoRenderOnLayout )
4487
4485
{
4488
4486
// First load AdvanceX value used by CalcTextSize() API then load the rest when loaded by drawing API.
4489
4487
float only_advance_x = 0 .0f ;
@@ -4572,15 +4570,16 @@ static bool ImGui_ImplStbTrueType_FontSrcInit(ImFontAtlas* atlas, ImFontConfig*
4572
4570
}
4573
4571
src->FontLoaderData = bd_font_data;
4574
4572
4573
+ const float ref_size = src->DstFont ->Sources [0 ]->SizePixels ;
4575
4574
if (src->MergeMode && src->SizePixels == 0 .0f )
4576
- src->SizePixels = src-> DstFont -> Sources [ 0 ]-> SizePixels ;
4575
+ src->SizePixels = ref_size ;
4577
4576
4578
4577
if (src->SizePixels >= 0 .0f )
4579
4578
bd_font_data->ScaleFactor = stbtt_ScaleForPixelHeight (&bd_font_data->FontInfo , 1 .0f );
4580
4579
else
4581
4580
bd_font_data->ScaleFactor = stbtt_ScaleForMappingEmToPixels (&bd_font_data->FontInfo , 1 .0f );
4582
- if (src->MergeMode && src->SizePixels != 0 .0f )
4583
- bd_font_data->ScaleFactor *= src->SizePixels / src-> DstFont -> Sources [ 0 ]-> SizePixels ; // FIXME-NEWATLAS: Should tidy up that a bit
4581
+ if (src->MergeMode && src->SizePixels != 0 .0f && ref_size != 0 . 0f )
4582
+ bd_font_data->ScaleFactor *= src->SizePixels / ref_size ; // FIXME-NEWATLAS: Should tidy up that a bit
4584
4583
4585
4584
return true ;
4586
4585
}
@@ -4679,15 +4678,12 @@ static bool ImGui_ImplStbTrueType_FontBakedLoadGlyph(ImFontAtlas* atlas, ImFontC
4679
4678
builder->TempBuffer .resize (w * h * 1 );
4680
4679
unsigned char * bitmap_pixels = builder->TempBuffer .Data ;
4681
4680
memset (bitmap_pixels, 0 , w * h * 1 );
4682
- stbtt_MakeGlyphBitmapSubpixel (&bd_font_data->FontInfo , bitmap_pixels, r->w - oversample_h + 1 , r->h - oversample_v + 1 , w,
4683
- scale_for_raster_x, scale_for_raster_y, 0 , 0 , glyph_index);
4684
4681
4685
- // Oversampling
4682
+ // Render with oversampling
4686
4683
// (those functions conveniently assert if pixels are not cleared, which is another safety layer)
4687
- if (oversample_h > 1 )
4688
- stbtt__h_prefilter (bitmap_pixels, r->w , r->h , r->w , oversample_h);
4689
- if (oversample_v > 1 )
4690
- stbtt__v_prefilter (bitmap_pixels, r->w , r->h , r->w , oversample_v);
4684
+ float sub_x, sub_y;
4685
+ stbtt_MakeGlyphBitmapSubpixelPrefilter (&bd_font_data->FontInfo , bitmap_pixels, w, h, w,
4686
+ scale_for_raster_x, scale_for_raster_y, 0 , 0 , oversample_h, oversample_v, &sub_x, &sub_y, glyph_index);
4691
4687
4692
4688
const float ref_size = baked->ContainerFont ->Sources [0 ]->SizePixels ;
4693
4689
const float offsets_scale = (ref_size != 0 .0f ) ? (baked->Size / ref_size) : 1 .0f ;
@@ -4697,8 +4693,8 @@ static bool ImGui_ImplStbTrueType_FontBakedLoadGlyph(ImFontAtlas* atlas, ImFontC
4697
4693
font_off_x = IM_ROUND (font_off_x);
4698
4694
if (src->PixelSnapV )
4699
4695
font_off_y = IM_ROUND (font_off_y);
4700
- font_off_x += stbtt__oversample_shift (oversample_h) ;
4701
- font_off_y += stbtt__oversample_shift (oversample_v) + IM_ROUND (baked->Ascent );
4696
+ font_off_x += sub_x ;
4697
+ font_off_y += sub_y + IM_ROUND (baked->Ascent );
4702
4698
float recip_h = 1 .0f / (oversample_h * rasterizer_density);
4703
4699
float recip_v = 1 .0f / (oversample_v * rasterizer_density);
4704
4700
@@ -5225,9 +5221,9 @@ ImFontGlyph* ImFontBaked::FindGlyphNoFallback(ImWchar c)
5225
5221
if (i != IM_FONTGLYPH_INDEX_UNUSED)
5226
5222
return &Glyphs.Data [i];
5227
5223
}
5228
- LockLoadingFallback = true ; // This is actually a rare call, not done in hot-loop, so we prioritize not adding extra cruft to ImFontBaked_BuildLoadGlyph() call sites.
5224
+ LoadNoFallback = true ; // This is actually a rare call, not done in hot-loop, so we prioritize not adding extra cruft to ImFontBaked_BuildLoadGlyph() call sites.
5229
5225
ImFontGlyph* glyph = ImFontBaked_BuildLoadGlyph (this , c, NULL );
5230
- LockLoadingFallback = false ;
5226
+ LoadNoFallback = false ;
5231
5227
return glyph;
5232
5228
}
5233
5229
0 commit comments