Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 std::optional<MipFilter> mip_filter = std::nullopt) {
21 if (!mip_filter.has_value()) {
22 switch (minmag_filter) {
23 case MinMagFilter::kNearest:
24 return GL_NEAREST;
25 case MinMagFilter::kLinear:
26 return GL_LINEAR;
27 }
29 }
30
31 switch (mip_filter.value()) {
32 case MipFilter::kNearest:
33 switch (minmag_filter) {
34 case MinMagFilter::kNearest:
35 return GL_NEAREST_MIPMAP_NEAREST;
36 case MinMagFilter::kLinear:
37 return GL_LINEAR_MIPMAP_NEAREST;
38 }
39 case MipFilter::kLinear:
40 switch (minmag_filter) {
41 case MinMagFilter::kNearest:
42 return GL_NEAREST_MIPMAP_LINEAR;
43 case MinMagFilter::kLinear:
44 return GL_LINEAR_MIPMAP_LINEAR;
45 }
46 }
48}
49
51 bool supports_decal_sampler_address_mode) {
52 switch (mode) {
53 case SamplerAddressMode::kClampToEdge:
54 return GL_CLAMP_TO_EDGE;
55 case SamplerAddressMode::kRepeat:
56 return GL_REPEAT;
57 case SamplerAddressMode::kMirror:
58 return GL_MIRRORED_REPEAT;
59 case SamplerAddressMode::kDecal:
60 if (supports_decal_sampler_address_mode) {
62 } else {
63 return GL_CLAMP_TO_EDGE;
64 }
65 }
67}
68
69bool SamplerGLES::ConfigureBoundTexture(const TextureGLES& texture,
70 const ProcTableGLES& gl) const {
71 if (texture.NeedsMipmapGeneration()) {
73 << "Texture mip count is > 1, but the mipmap has not been generated. "
74 "Texture can not be sampled safely.";
75 return false;
76 }
77
78 auto target = ToTextureTarget(texture.GetTextureDescriptor().type);
79
80 if (!target.has_value()) {
81 return false;
82 }
83 const auto& desc = GetDescriptor();
84
85 std::optional<MipFilter> mip_filter = std::nullopt;
86 if (texture.GetTextureDescriptor().mip_count > 1) {
87 mip_filter = desc.mip_filter;
88 }
89
90 gl.TexParameteri(*target, GL_TEXTURE_MIN_FILTER,
91 ToParam(desc.min_filter, mip_filter));
92 gl.TexParameteri(*target, GL_TEXTURE_MAG_FILTER, ToParam(desc.mag_filter));
93
94 const auto supports_decal_mode =
95 gl.GetCapabilities()->SupportsDecalSamplerAddressMode();
96
97 const auto wrap_s =
98 ToAddressMode(desc.width_address_mode, supports_decal_mode);
99 const auto wrap_t =
100 ToAddressMode(desc.height_address_mode, supports_decal_mode);
101
102 gl.TexParameteri(*target, GL_TEXTURE_WRAP_S, wrap_s);
103 gl.TexParameteri(*target, GL_TEXTURE_WRAP_T, wrap_t);
104
105 if (wrap_s == IMPELLER_GL_CLAMP_TO_BORDER ||
106 wrap_t == IMPELLER_GL_CLAMP_TO_BORDER) {
107 // Transparent black.
108 const GLfloat border_color[4] = {0.0f, 0.0f, 0.0f, 0.0f};
109 gl.TexParameterfv(*target, IMPELLER_GL_TEXTURE_BORDER_COLOR, border_color);
110 }
111
112 return true;
113}
114
115} // namespace impeller
uint32_t * target
#define FML_UNREACHABLE()
Definition logging.h:109
FlTexture * texture
std::function< ProfileSample(void)> Sampler
Sampler is run during SamplingProfiler::SampleRepeatedly. Each platform should implement its version ...
constexpr std::optional< GLenum > ToTextureTarget(TextureType type)
static GLint ToAddressMode(SamplerAddressMode mode, bool supports_decal_sampler_address_mode)
static GLint ToParam(MinMagFilter minmag_filter, std::optional< MipFilter > mip_filter=std::nullopt)
SamplerAddressMode
Definition formats.h:423
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