RAII scope that samples the images drawn inside it with nearest-neighbor filtering. More...
#include <draw_sampling.h>

Public Member Functions | |
| ScopedNearestSampling (ImDrawList *draw_list) | |
| ~ScopedNearestSampling () | |
| ScopedNearestSampling (const ScopedNearestSampling &)=delete | |
| ScopedNearestSampling & | operator= (const ScopedNearestSampling &)=delete |
| bool | active () const |
Static Private Member Functions | |
| static bool | IsActiveOn (const ImDrawList *draw_list) |
Private Attributes | |
| ImDrawList * | draw_list_ = nullptr |
| const ScopedNearestSampling * | outer_ = nullptr |
Static Private Attributes | |
| static thread_local const ScopedNearestSampling * | innermost_ = nullptr |
RAII scope that samples the images drawn inside it with nearest-neighbor filtering.
Renderer backends sample textures with linear filtering by default, which blurs pixel-art bitmaps when a canvas zooms them. The scope adds the backend's DrawCallback_SetSamplerNearest to the draw list. On destruction it adds DrawCallback_SetSamplerLinear, or DrawCallback_ResetRenderState when the backend has no linear callback, so text and lines drawn later keep linear sampling.
When the backend does not provide DrawCallback_SetSamplerNearest, the scope adds no callbacks. SDLRenderer2 is such a backend: it cannot change the scale mode while rendering, so its textures keep the SDL texture setting.
A scope created while another scope is active on the same draw list adds nothing. Otherwise the inner scope would switch the outer scope's remaining images back to linear. Create scopes on the stack only.
Usage: { ScopedNearestSampling nearest_sampling(draw_list); draw_list->AddImage(texture, p_min, p_max); }
Definition at line 34 of file draw_sampling.h.
|
inlineexplicit |
Definition at line 36 of file draw_sampling.h.
References draw_list_, innermost_, IsActiveOn(), and outer_.

|
inline |
Definition at line 51 of file draw_sampling.h.
References draw_list_, innermost_, and outer_.
|
delete |
|
delete |
|
inline |
Definition at line 70 of file draw_sampling.h.
References draw_list_.
|
inlinestaticprivate |
Definition at line 73 of file draw_sampling.h.
References innermost_, and outer_.
Referenced by ScopedNearestSampling().
|
private |
Definition at line 83 of file draw_sampling.h.
Referenced by active(), ScopedNearestSampling(), and ~ScopedNearestSampling().
|
private |
Definition at line 84 of file draw_sampling.h.
Referenced by IsActiveOn(), ScopedNearestSampling(), and ~ScopedNearestSampling().
|
inlinestaticprivate |
Definition at line 88 of file draw_sampling.h.
Referenced by IsActiveOn(), ScopedNearestSampling(), and ~ScopedNearestSampling().