yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::gui::ScopedNearestSampling Class Reference

RAII scope that samples the images drawn inside it with nearest-neighbor filtering. More...

#include <draw_sampling.h>

Collaboration diagram for yaze::gui::ScopedNearestSampling:

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ScopedNearestSampling() [1/2]

yaze::gui::ScopedNearestSampling::ScopedNearestSampling ( ImDrawList * draw_list)
inlineexplicit

Definition at line 36 of file draw_sampling.h.

References draw_list_, innermost_, IsActiveOn(), and outer_.

Here is the call graph for this function:

◆ ~ScopedNearestSampling()

yaze::gui::ScopedNearestSampling::~ScopedNearestSampling ( )
inline

Definition at line 51 of file draw_sampling.h.

References draw_list_, innermost_, and outer_.

◆ ScopedNearestSampling() [2/2]

yaze::gui::ScopedNearestSampling::ScopedNearestSampling ( const ScopedNearestSampling & )
delete

Member Function Documentation

◆ operator=()

ScopedNearestSampling & yaze::gui::ScopedNearestSampling::operator= ( const ScopedNearestSampling & )
delete

◆ active()

bool yaze::gui::ScopedNearestSampling::active ( ) const
inline

Definition at line 70 of file draw_sampling.h.

References draw_list_.

◆ IsActiveOn()

static bool yaze::gui::ScopedNearestSampling::IsActiveOn ( const ImDrawList * draw_list)
inlinestaticprivate

Definition at line 73 of file draw_sampling.h.

References innermost_, and outer_.

Referenced by ScopedNearestSampling().

Member Data Documentation

◆ draw_list_

ImDrawList* yaze::gui::ScopedNearestSampling::draw_list_ = nullptr
private

Definition at line 83 of file draw_sampling.h.

Referenced by active(), ScopedNearestSampling(), and ~ScopedNearestSampling().

◆ outer_

const ScopedNearestSampling* yaze::gui::ScopedNearestSampling::outer_ = nullptr
private

Definition at line 84 of file draw_sampling.h.

Referenced by IsActiveOn(), ScopedNearestSampling(), and ~ScopedNearestSampling().

◆ innermost_

thread_local const ScopedNearestSampling* yaze::gui::ScopedNearestSampling::innermost_ = nullptr
inlinestaticprivate

Definition at line 88 of file draw_sampling.h.

Referenced by IsActiveOn(), ScopedNearestSampling(), and ~ScopedNearestSampling().


The documentation for this class was generated from the following file: