Flutter Impeller
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 
7 #include <iostream>
8 
10 #include "impeller/core/formats.h"
14 
15 namespace impeller {
16 
17 SamplerGLES::SamplerGLES(SamplerDescriptor desc) : Sampler(std::move(desc)) {}
18 
19 SamplerGLES::~SamplerGLES() = default;
20 
21 bool SamplerGLES::IsValid() const {
22  return true;
23 }
24 
25 static GLint ToParam(MinMagFilter minmag_filter,
26  std::optional<MipFilter> mip_filter = std::nullopt) {
27  if (!mip_filter.has_value()) {
28  switch (minmag_filter) {
30  return GL_NEAREST;
32  return GL_LINEAR;
33  }
34  FML_UNREACHABLE();
35  }
36 
37  switch (mip_filter.value()) {
39  switch (minmag_filter) {
41  return GL_NEAREST_MIPMAP_NEAREST;
43  return GL_LINEAR_MIPMAP_NEAREST;
44  }
45  case MipFilter::kLinear:
46  switch (minmag_filter) {
48  return GL_NEAREST_MIPMAP_LINEAR;
50  return GL_LINEAR_MIPMAP_LINEAR;
51  }
52  }
53  FML_UNREACHABLE();
54 }
55 
56 static GLint ToAddressMode(SamplerAddressMode mode) {
57  switch (mode) {
59  return GL_CLAMP_TO_EDGE;
61  return GL_REPEAT;
63  return GL_MIRRORED_REPEAT;
65  break; // Unsupported.
66  }
67  FML_UNREACHABLE();
68 }
69 
71  const ProcTableGLES& gl) const {
72  if (!IsValid()) {
73  return false;
74  }
75 
76  if (texture.NeedsMipmapGeneration()) {
78  << "Texture mip count is > 1, but the mipmap has not been generated. "
79  "Texture can not be sampled safely.";
80  return false;
81  }
82 
83  auto target = ToTextureTarget(texture.GetTextureDescriptor().type);
84 
85  if (!target.has_value()) {
86  return false;
87  }
88  const auto& desc = GetDescriptor();
89 
90  std::optional<MipFilter> mip_filter = std::nullopt;
91  if (texture.GetTextureDescriptor().mip_count > 1) {
92  mip_filter = desc.mip_filter;
93  }
94 
95  gl.TexParameteri(target.value(), GL_TEXTURE_MIN_FILTER,
96  ToParam(desc.min_filter, mip_filter));
97  gl.TexParameteri(target.value(), GL_TEXTURE_MAG_FILTER,
98  ToParam(desc.mag_filter));
99  gl.TexParameteri(target.value(), GL_TEXTURE_WRAP_S,
100  ToAddressMode(desc.width_address_mode));
101  gl.TexParameteri(target.value(), GL_TEXTURE_WRAP_T,
102  ToAddressMode(desc.height_address_mode));
103  return true;
104 }
105 
106 } // namespace impeller
impeller::Texture::NeedsMipmapGeneration
bool NeedsMipmapGeneration() const
Definition: texture.cc:85
impeller::SamplerAddressMode
SamplerAddressMode
Definition: formats.h:377
impeller::Texture::GetTextureDescriptor
const TextureDescriptor & GetTextureDescriptor() const
Definition: texture.cc:57
impeller::SamplerGLES::~SamplerGLES
~SamplerGLES()
formats.h
texture_gles.h
impeller::TextureDescriptor::mip_count
size_t mip_count
Definition: texture_descriptor.h:44
impeller::SamplerAddressMode::kClampToEdge
@ kClampToEdge
validation.h
sampler_gles.h
impeller::SamplerGLES::ConfigureBoundTexture
bool ConfigureBoundTexture(const TextureGLES &texture, const ProcTableGLES &gl) const
Definition: sampler_gles.cc:70
impeller::MinMagFilter::kNearest
@ kNearest
Select nearest to the sample point. Most widely supported.
impeller::TextureDescriptor::type
TextureType type
Definition: texture_descriptor.h:41
impeller::ToAddressMode
static GLint ToAddressMode(SamplerAddressMode mode)
Definition: sampler_gles.cc:56
impeller::MipFilter::kNearest
@ kNearest
Sample from the nearest mip level.
impeller::MinMagFilter::kLinear
@ kLinear
impeller::MinMagFilter
MinMagFilter
Definition: formats.h:361
impeller::ProcTableGLES
Definition: proc_table_gles.h:188
proc_table_gles.h
impeller::ToParam
static constexpr int ToParam(size_t index)
Definition: archive_statement.cc:75
formats_gles.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60
impeller::SamplerAddressMode::kMirror
@ kMirror
std
Definition: comparable.h:98
impeller::MipFilter::kLinear
@ kLinear
impeller::Sampler::GetDescriptor
const SamplerDescriptor & GetDescriptor() const
Definition: sampler.cc:13
impeller::ToTextureTarget
constexpr std::optional< GLenum > ToTextureTarget(TextureType type)
Definition: formats_gles.h:183
impeller::TextureGLES
Definition: texture_gles.h:15
impeller
Definition: aiks_context.cc:10
impeller::SamplerAddressMode::kRepeat
@ kRepeat
impeller::SamplerAddressMode::kDecal
@ kDecal
decal sampling mode is only supported on devices that pass the Capabilities.SupportsDecalSamplerAddre...