Lines Matching defs:atlas
2033 // Build atlas on demand
2226 IM_ASSERT(TexWidth > 0 && TexHeight > 0); // Font atlas needs to be built before we can calculate UV coordinates
2262 // - Note that we do not reassign to atlas->FontBuilderIO, since it is likely to point to static data which
2309 int DstIndex; // Index into atlas->Fonts[] and dst_tmp_array[]
2337 static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
2339 IM_ASSERT(atlas->ConfigData.Size > 0);
2341 ImFontAtlasBuildInit(atlas);
2343 // Clear atlas
2344 atlas->TexID = (ImTextureID)NULL;
2345 atlas->TexWidth = atlas->TexHeight = 0;
2346 atlas->TexUvScale = ImVec2(0.0f, 0.0f);
2347 atlas->TexUvWhitePixel = ImVec2(0.0f, 0.0f);
2348 atlas->ClearTexData();
2353 src_tmp_array.resize(atlas->ConfigData.Size);
2354 dst_tmp_array.resize(atlas->Fonts.Size);
2359 for (int src_i = 0; src_i < atlas->ConfigData.Size; src_i++)
2362 ImFontConfig& cfg = atlas->ConfigData[src_i];
2363 IM_ASSERT(cfg.DstFont && (!cfg.DstFont->IsLoaded() || cfg.DstFont->ContainerAtlas == atlas));
2367 for (int output_i = 0; output_i < atlas->Fonts.Size && src_tmp.DstIndex == -1; output_i++)
2368 if (cfg.DstFont == atlas->Fonts[output_i])
2372 IM_ASSERT(src_tmp.DstIndex != -1); // cfg.DstFont not pointing within atlas->Fonts[] array?
2383 src_tmp.SrcRanges = cfg.GlyphRanges ? cfg.GlyphRanges : atlas->GetGlyphRangesDefault();
2455 ImFontConfig& cfg = atlas->ConfigData[src_i];
2466 const int padding = atlas->TexGlyphPadding;
2483 atlas->TexHeight = 0;
2484 if (atlas->TexDesiredWidth > 0)
2485 atlas->TexWidth = atlas->TexDesiredWidth;
2487 atlas->TexWidth = (surface_sqrt >= 4096 * 0.7f) ? 4096 : (surface_sqrt >= 2048 * 0.7f) ? 2048 : (surface_sqrt >= 1024 * 0.7f) ? 1024 : 512;
2493 stbtt_PackBegin(&spc, NULL, atlas->TexWidth, TEX_HEIGHT_MAX, 0, atlas->TexGlyphPadding, NULL);
2494 ImFontAtlasBuildPackCustomRects(atlas, spc.pack_info);
2509 atlas->TexHeight = ImMax(atlas->TexHeight, src_tmp.Rects[glyph_i].y + src_tmp.Rects[glyph_i].h);
2513 atlas->TexHeight = (atlas->Flags & ImFontAtlasFlags_NoPowerOfTwoHeight) ? (atlas->TexHeight + 1) : ImUpperPowerOfTwo(atlas->TexHeight);
2514 atlas->TexUvScale = ImVec2(1.0f / atlas->TexWidth, 1.0f / atlas->TexHeight);
2515 atlas->TexPixelsAlpha8 = (unsigned char*)IM_ALLOC(atlas->TexWidth * atlas->TexHeight);
2516 memset(atlas->TexPixelsAlpha8, 0, atlas->TexWidth * atlas->TexHeight);
2517 spc.pixels = atlas->TexPixelsAlpha8;
2518 spc.height = atlas->TexHeight;
2523 ImFontConfig& cfg = atlas->ConfigData[src_i];
2538 ImFontAtlasBuildMultiplyRectAlpha8(multiply_table, atlas->TexPixelsAlpha8, r->x, r->y, r->w, r->h, atlas->TexWidth * 1);
2557 ImFontConfig& cfg = atlas->ConfigData[src_i];
2566 ImFontAtlasBuildSetupFont(atlas, dst_font, &cfg, ascent, descent);
2577 stbtt_GetPackedQuad(src_tmp.PackedChars, atlas->TexWidth, atlas->TexHeight, glyph_i, &unused_x, &unused_y, &q, 0);
2585 ImFontAtlasBuildFinish(atlas);
2598 void ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* font_config, float ascent, float descent)
2606 font->ContainerAtlas = atlas;
2613 void ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* stbrp_context_opaque)
2618 ImVector<ImFontAtlasCustomRect>& user_rects = atlas->CustomRects;
2636 atlas->TexHeight = ImMax(atlas->TexHeight, pack_rects[i].y + pack_rects[i].h);
2640 void ImFontAtlasBuildRender8bppRectFromString(ImFontAtlas* atlas, int x, int y, int w, int h, const char* in_str, char in_marker_char, unsigned char in_marker_pixel_value)
2642 IM_ASSERT(x >= 0 && x + w <= atlas->TexWidth);
2643 IM_ASSERT(y >= 0 && y + h <= atlas->TexHeight);
2644 unsigned char* out_pixel = atlas->TexPixelsAlpha8 + x + (y * atlas->TexWidth);
2645 for (int off_y = 0; off_y < h; off_y++, out_pixel += atlas->TexWidth, in_str += w)
2650 void ImFontAtlasBuildRender32bppRectFromString(ImFontAtlas* atlas, int x, int y, int w, int h, const char* in_str, char in_marker_char, unsigned int in_marker_pixel_value)
2652 IM_ASSERT(x >= 0 && x + w <= atlas->TexWidth);
2653 IM_ASSERT(y >= 0 && y + h <= atlas->TexHeight);
2654 unsigned int* out_pixel = atlas->TexPixelsRGBA32 + x + (y * atlas->TexWidth);
2655 for (int off_y = 0; off_y < h; off_y++, out_pixel += atlas->TexWidth, in_str += w)
2660 static void ImFontAtlasBuildRenderDefaultTexData(ImFontAtlas* atlas)
2662 ImFontAtlasCustomRect* r = atlas->GetCustomRectByIndex(atlas->PackIdMouseCursors);
2665 const int w = atlas->TexWidth;
2666 if (!(atlas->Flags & ImFontAtlasFlags_NoMouseCursors))
2672 if (atlas->TexPixelsAlpha8 != NULL)
2674 ImFontAtlasBuildRender8bppRectFromString(atlas, x_for_white, r->Y, FONT_ATLAS_DEFAULT_TEX_DATA_W, FONT_ATLAS_DEFAULT_TEX_DATA_H, FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, '.', 0xFF);
2675 ImFontAtlasBuildRender8bppRectFromString(atlas, x_for_black, r->Y, FONT_ATLAS_DEFAULT_TEX_DATA_W, FONT_ATLAS_DEFAULT_TEX_DATA_H, FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, 'X', 0xFF);
2679 ImFontAtlasBuildRender32bppRectFromString(atlas, x_for_white, r->Y, FONT_ATLAS_DEFAULT_TEX_DATA_W, FONT_ATLAS_DEFAULT_TEX_DATA_H, FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, '.', IM_COL32_WHITE);
2680 ImFontAtlasBuildRender32bppRectFromString(atlas, x_for_black, r->Y, FONT_ATLAS_DEFAULT_TEX_DATA_W, FONT_ATLAS_DEFAULT_TEX_DATA_H, FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, 'X', IM_COL32_WHITE);
2688 if (atlas->TexPixelsAlpha8 != NULL)
2690 atlas->TexPixelsAlpha8[offset] = atlas->TexPixelsAlpha8[offset + 1] = atlas->TexPixelsAlpha8[offset + w] = atlas->TexPixelsAlpha8[offset + w + 1] = 0xFF;
2694 atlas->TexPixelsRGBA32[offset] = atlas->TexPixelsRGBA32[offset + 1] = atlas->TexPixelsRGBA32[offset + w] = atlas->TexPixelsRGBA32[offset + w + 1] = IM_COL32_WHITE;
2697 atlas->TexUvWhitePixel = ImVec2((r->X + 0.5f) * atlas->TexUvScale.x, (r->Y + 0.5f) * atlas->TexUvScale.y);
2700 static void ImFontAtlasBuildRenderLinesTexData(ImFontAtlas* atlas)
2702 if (atlas->Flags & ImFontAtlasFlags_NoBakedLines)
2706 ImFontAtlasCustomRect* r = atlas->GetCustomRectByIndex(atlas->PackIdLines);
2718 if (atlas->TexPixelsAlpha8 != NULL)
2720 unsigned char* write_ptr = &atlas->TexPixelsAlpha8[r->X + ((r->Y + y) * atlas->TexWidth)];
2732 unsigned int* write_ptr = &atlas->TexPixelsRGBA32[r->X + ((r->Y + y) * atlas->TexWidth)];
2744 ImVec2 uv0 = ImVec2((float)(r->X + pad_left - 1), (float)(r->Y + y)) * atlas->TexUvScale;
2745 ImVec2 uv1 = ImVec2((float)(r->X + pad_left + line_width + 1), (float)(r->Y + y + 1)) * atlas->TexUvScale;
2747 atlas->TexUvLines[n] = ImVec4(uv0.x, half_v, uv1.x, half_v);
2752 void ImFontAtlasBuildInit(ImFontAtlas* atlas)
2755 if (atlas->PackIdMouseCursors < 0)
2757 if (!(atlas->Flags & ImFontAtlasFlags_NoMouseCursors))
2758 atlas->PackIdMouseCursors = atlas->AddCustomRectRegular(FONT_ATLAS_DEFAULT_TEX_DATA_W * 2 + 1, FONT_ATLAS_DEFAULT_TEX_DATA_H);
2760 atlas->PackIdMouseCursors = atlas->AddCustomRectRegular(2, 2);
2765 if (atlas->PackIdLines < 0)
2767 if (!(atlas->Flags & ImFontAtlasFlags_NoBakedLines))
2768 atlas->PackIdLines = atlas->AddCustomRectRegular(IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 2, IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1);
2773 void ImFontAtlasBuildFinish(ImFontAtlas* atlas)
2776 IM_ASSERT(atlas->TexPixelsAlpha8 != NULL || atlas->TexPixelsRGBA32 != NULL);
2777 ImFontAtlasBuildRenderDefaultTexData(atlas);
2778 ImFontAtlasBuildRenderLinesTexData(atlas);
2781 for (int i = 0; i < atlas->CustomRects.Size; i++)
2783 const ImFontAtlasCustomRect* r = &atlas->CustomRects[i];
2788 IM_ASSERT(r->Font->ContainerAtlas == atlas);
2790 atlas->CalcCustomRectUV(r, &uv0, &uv1);
2795 for (int i = 0; i < atlas->Fonts.Size; i++)
2796 if (atlas->Fonts[i]->DirtyLookupTables)
2797 atlas->Fonts[i]->BuildLookupTable();
2799 atlas->TexReady = true;
3518 // Note: as with every ImDrawList drawing function, this expects that the font atlas texture is bound.
3533 // Note: as with every ImDrawList drawing function, this expects that the font atlas texture is bound.