Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
impeller::SamplerGLES Class Referencefinal

#include <sampler_gles.h>

Inheritance diagram for impeller::SamplerGLES:
impeller::Sampler impeller::BackendCast< SamplerGLES, Sampler >

Public Member Functions

 ~SamplerGLES ()
 
bool ConfigureBoundTexture (const TextureGLES &texture, const ProcTableGLES &gl) const
 
- Public Member Functions inherited from impeller::Sampler
virtual ~Sampler ()
 
const SamplerDescriptorGetDescriptor () const
 

Friends

class SamplerLibraryGLES
 

Additional Inherited Members

- Static Public Member Functions inherited from impeller::BackendCast< SamplerGLES, Sampler >
static SamplerGLESCast (Sampler &base)
 
static const SamplerGLESCast (const Sampler &base)
 
static SamplerGLESCast (Sampler *base)
 
static const SamplerGLESCast (const Sampler *base)
 
- Protected Member Functions inherited from impeller::Sampler
 Sampler (const SamplerDescriptor &desc)
 
- Protected Attributes inherited from impeller::Sampler
SamplerDescriptor desc_
 

Detailed Description

Definition at line 17 of file sampler_gles.h.

Constructor & Destructor Documentation

◆ ~SamplerGLES()

impeller::SamplerGLES::~SamplerGLES ( )
default

Member Function Documentation

◆ ConfigureBoundTexture()

bool impeller::SamplerGLES::ConfigureBoundTexture ( const TextureGLES texture,
const ProcTableGLES gl 
) const

Definition at line 72 of file sampler_gles.cc.

73 {
74 auto target = ToTextureTarget(texture.GetTextureDescriptor().type);
75
76 if (!target.has_value()) {
77 return false;
78 }
79 const SamplerDescriptor& desc = GetDescriptor();
80
81 GLint mag_filter = ToParam(desc.mag_filter);
82
83 // If the texture doesn't have mipmaps, we can't use mip filtering.
84 GLint min_filter;
85 if (texture.GetTextureDescriptor().mip_count > 1) {
86 min_filter = ToParam(desc.min_filter, desc.mip_filter);
87 } else {
88 min_filter = ToParam(desc.min_filter);
89 }
90
91 gl.TexParameteri(*target, GL_TEXTURE_MIN_FILTER, min_filter);
92 gl.TexParameteri(*target, GL_TEXTURE_MAG_FILTER, mag_filter);
93
94 // Bound the sampled mip range to the levels the texture declares. GLES leaves
95 // GL_TEXTURE_MAX_LEVEL at its default of 1000, so a texture sampled with a
96 // mipmap filter reads as black unless every level down to 1x1 is defined.
97 // Metal and Vulkan allocate exactly mip_count levels, and clamping here gives
98 // the same behavior for a partial, manually uploaded mip chain. The parameter
99 // is unavailable on ES 2.0 without GL_APPLE_texture_max_level, and external
100 // textures have no mip levels, so it is skipped in those cases.
101 if (*target != GL_TEXTURE_EXTERNAL_OES &&
102 gl.GetCapabilities()->SupportsTextureMaxLevel()) {
103 const GLint max_level =
104 static_cast<GLint>(texture.GetTextureDescriptor().mip_count) - 1;
105 gl.TexParameteri(*target, GL_TEXTURE_MAX_LEVEL, max_level);
106 }
107
108 const auto supports_decal_mode =
109 gl.GetCapabilities()->SupportsDecalSamplerAddressMode();
110
111 const auto wrap_s =
112 ToAddressMode(desc.width_address_mode, supports_decal_mode);
113 const auto wrap_t =
114 ToAddressMode(desc.height_address_mode, supports_decal_mode);
115
116 gl.TexParameteri(*target, GL_TEXTURE_WRAP_S, wrap_s);
117 gl.TexParameteri(*target, GL_TEXTURE_WRAP_T, wrap_t);
118
119 if (wrap_s == IMPELLER_GL_CLAMP_TO_BORDER ||
120 wrap_t == IMPELLER_GL_CLAMP_TO_BORDER) {
121 // Transparent black.
122 const GLfloat border_color[4] = {0.0f, 0.0f, 0.0f, 0.0f};
123 gl.TexParameterfv(*target, IMPELLER_GL_TEXTURE_BORDER_COLOR, border_color);
124 }
125
126 // Anisotropy is a per-texture parameter in GLES, so it must be written on
127 // every configuration (including resetting it back to 1) to prevent a
128 // previously configured value from leaking into this sampler's state. The
129 // parameter only exists when GL_EXT_texture_filter_anisotropic is present;
130 // it is applied with TexParameterfv, which is core ES 2.0.
131 const uint32_t max_anisotropy =
132 gl.GetCapabilities()->GetMaxSamplerAnisotropy();
133 if (max_anisotropy > 1) {
134 const GLfloat anisotropy[1] = {static_cast<GLfloat>(
135 std::clamp<uint32_t>(desc.max_anisotropy, 1u, max_anisotropy))};
136 gl.TexParameterfv(*target, IMPELLER_GL_TEXTURE_MAX_ANISOTROPY, anisotropy);
137 }
138
139 return true;
140}
const SamplerDescriptor & GetDescriptor() const
Definition sampler.cc:13
uint32_t * target
FlTexture * texture
constexpr std::optional< GLenum > ToTextureTarget(TextureType type)
static GLint ToAddressMode(SamplerAddressMode mode, bool supports_decal_sampler_address_mode)
static GLint ToParam(MinMagFilter minmag_filter)
#define IMPELLER_GL_TEXTURE_BORDER_COLOR
Definition gles.h:13
#define IMPELLER_GL_CLAMP_TO_BORDER
Definition gles.h:12
#define IMPELLER_GL_TEXTURE_MAX_ANISOTROPY
Definition gles.h:16

References impeller::ProcTableGLES::GetCapabilities(), impeller::SamplerDescriptor::height_address_mode, IMPELLER_GL_CLAMP_TO_BORDER, IMPELLER_GL_TEXTURE_BORDER_COLOR, IMPELLER_GL_TEXTURE_MAX_ANISOTROPY, impeller::SamplerDescriptor::mag_filter, impeller::SamplerDescriptor::max_anisotropy, impeller::SamplerDescriptor::min_filter, impeller::SamplerDescriptor::mip_filter, target, texture, impeller::ToAddressMode(), impeller::ToParam(), impeller::ToTextureTarget(), and impeller::SamplerDescriptor::width_address_mode.

Friends And Related Symbol Documentation

◆ SamplerLibraryGLES

friend class SamplerLibraryGLES
friend

Definition at line 26 of file sampler_gles.h.


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