Flutter Engine
The Flutter Engine
sampler_gles.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
12
13namespace impeller {
14
15SamplerGLES::SamplerGLES(SamplerDescriptor desc) : Sampler(std::move(desc)) {}
16
17SamplerGLES::~SamplerGLES() = default;
18
19static GLint ToParam(MinMagFilter minmag_filter) {
20 switch (minmag_filter) {
21 case MinMagFilter::kNearest:
22 return GL_NEAREST;
24 return GL_LINEAR;
25 }
27}
28
29static GLint ToParam(MinMagFilter minmag_filter, MipFilter mip_filter) {
30 switch (mip_filter) {
31 case MipFilter::kBase:
32 return ToParam(minmag_filter);
33 case MipFilter::kNearest:
34 switch (minmag_filter) {
35 case MinMagFilter::kNearest:
36 return GL_NEAREST_MIPMAP_NEAREST;
38 return GL_LINEAR_MIPMAP_NEAREST;
39 }
41 switch (minmag_filter) {
42 case MinMagFilter::kNearest:
43 return GL_NEAREST_MIPMAP_LINEAR;
45 return GL_LINEAR_MIPMAP_LINEAR;
46 }
47 }
49}
50
52 bool supports_decal_sampler_address_mode) {
53 switch (mode) {
54 case SamplerAddressMode::kClampToEdge:
55 return GL_CLAMP_TO_EDGE;
56 case SamplerAddressMode::kRepeat:
57 return GL_REPEAT;
58 case SamplerAddressMode::kMirror:
59 return GL_MIRRORED_REPEAT;
60 case SamplerAddressMode::kDecal:
61 if (supports_decal_sampler_address_mode) {
63 } else {
64 return GL_CLAMP_TO_EDGE;
65 }
66 }
68}
69
70bool SamplerGLES::ConfigureBoundTexture(const TextureGLES& texture,
71 const ProcTableGLES& gl) const {
72 if (texture.NeedsMipmapGeneration()) {
74 << "Texture mip count is > 1, but the mipmap has not been generated. "
75 "Texture can not be sampled safely.";
76 return false;
77 }
78
79 auto target = ToTextureTarget(texture.GetTextureDescriptor().type);
80
81 if (!target.has_value()) {
82 return false;
83 }
84 const auto& desc = GetDescriptor();
85
86 GLint mag_filter = ToParam(desc.mag_filter);
87
88 // If the texture doesn't have mipmaps, we can't use mip filtering.
89 GLint min_filter;
90 if (texture.GetTextureDescriptor().mip_count > 1) {
91 min_filter = ToParam(desc.min_filter, desc.mip_filter);
92 } else {
93 min_filter = ToParam(desc.min_filter);
94 }
95
96 gl.TexParameteri(*target, GL_TEXTURE_MIN_FILTER, min_filter);
97 gl.TexParameteri(*target, GL_TEXTURE_MAG_FILTER, mag_filter);
98
99 const auto supports_decal_mode =
100 gl.GetCapabilities()->SupportsDecalSamplerAddressMode();
101
102 const auto wrap_s =
103 ToAddressMode(desc.width_address_mode, supports_decal_mode);
104 const auto wrap_t =
105 ToAddressMode(desc.height_address_mode, supports_decal_mode);
106
107 gl.TexParameteri(*target, GL_TEXTURE_WRAP_S, wrap_s);
108 gl.TexParameteri(*target, GL_TEXTURE_WRAP_T, wrap_t);
109
110 if (wrap_s == IMPELLER_GL_CLAMP_TO_BORDER ||
111 wrap_t == IMPELLER_GL_CLAMP_TO_BORDER) {
112 // Transparent black.
113 const GLfloat border_color[4] = {0.0f, 0.0f, 0.0f, 0.0f};
114 gl.TexParameterfv(*target, IMPELLER_GL_TEXTURE_BORDER_COLOR, border_color);
115 }
116
117 return true;
118}
119
120} // namespace impeller
uint32_t * target
#define FML_UNREACHABLE()
Definition: logging.h:109
FlTexture * texture
static constexpr skcms_TransferFunction kLinear
Definition: SkColorSpace.h:51
std::function< ProfileSample(void)> Sampler
Sampler is run during SamplingProfiler::SampleRepeatedly. Each platform should implement its version ...
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
constexpr std::optional< GLenum > ToTextureTarget(TextureType type)
Definition: formats_gles.h:183
static GLint ToAddressMode(SamplerAddressMode mode, bool supports_decal_sampler_address_mode)
Definition: sampler_gles.cc:51
MipFilter
Options for selecting and filtering between mipmap levels.
Definition: formats.h:419
static GLint ToParam(MinMagFilter minmag_filter, MipFilter mip_filter)
Definition: sampler_gles.cc:29
SamplerAddressMode
Definition: formats.h:435
MinMagFilter
Describes how the texture should be sampled when the texture is being shrunk (minified) or expanded (...
Definition: formats.h:409
gl
Definition: malisc.py:41
Definition: ref_ptr.h:256
#define IMPELLER_GL_TEXTURE_BORDER_COLOR
Definition: gles.h:13
#define IMPELLER_GL_CLAMP_TO_BORDER
Definition: gles.h:12
#define VALIDATION_LOG
Definition: validation.h:73