Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sampler.cc
Go to the documentation of this file.
1 
18 #include "ion/gfx/sampler.h"
19 
20 #include "ion/base/enumhelper.h"
21 #include "ion/base/static_assert.h"
22 #include "ion/portgfx/glheaders.h"
23 
24 namespace ion {
25 namespace gfx {
26 
28  : auto_mipmapping_enabled_(kAutoMipmappingChanged, false, this),
29  max_anisotropy_(kMaxAnisotropyChanged, 1.f, 1.f, 32.f, this),
30  min_lod_(kMinLodChanged, -1000.f, this),
31  max_lod_(kMaxLodChanged, 1000.f, this),
32  compare_function_(
33  kCompareFunctionChanged, kLess, kAlways, kNotEqual, this),
34  compare_mode_(kCompareModeChanged, kNone, kCompareToTexture, kNone, this),
35  min_filter_(kMinFilterChanged, kNearest, kNearest, kLinearMipmapLinear,
36  this),
37  mag_filter_(kMagFilterChanged, kNearest, kNearest, kLinear, this),
38  wrap_r_(kWrapRChanged, kRepeat, kClampToEdge, kMirroredRepeat, this),
39  wrap_s_(kWrapSChanged, kRepeat, kClampToEdge, kMirroredRepeat, this),
40  wrap_t_(kWrapTChanged, kRepeat, kClampToEdge, kMirroredRepeat, this) {}
41 
43 }
44 
45 } // namespace gfx
46 
47 namespace base {
48 
49 using gfx::Sampler;
50 
52 template <> ION_API const EnumHelper::EnumData<Sampler::CompareFunction>
53 EnumHelper::GetEnumData() {
54  static const GLenum kValues[] = {
55  GL_ALWAYS, GL_EQUAL, GL_GREATER, GL_GEQUAL, GL_LESS, GL_LEQUAL, GL_NEVER,
56  GL_NOTEQUAL
57  };
58  static const char* kStrings[] = {
59  "Always", "Equal", "Greater", "GreaterOrEqual", "Less", "LessOrEqual",
60  "Never", "NotEqual"
61  };
62  ION_STATIC_ASSERT(ARRAYSIZE(kValues) == ARRAYSIZE(kStrings),
63  "EnumHelper size mismatch");
64  return EnumData<Sampler::CompareFunction>(
66  ARRAYSIZE(kValues)),
67  kStrings);
68 }
69 
71 template <> ION_API const EnumHelper::EnumData<Sampler::CompareMode>
72 EnumHelper::GetEnumData() {
73  static const GLenum kValues[] = { GL_COMPARE_REF_TO_TEXTURE, GL_NONE };
74  static const char* kStrings[] = { "CompareToTexture", "None" };
75  ION_STATIC_ASSERT(ARRAYSIZE(kValues) == ARRAYSIZE(kStrings),
76  "EnumHelper size mismatch");
77  return EnumData<Sampler::CompareMode>(
78  base::IndexMap<Sampler::CompareMode, GLenum>(kValues, ARRAYSIZE(kValues)),
79  kStrings);
80 }
81 
83 template <> ION_API const EnumHelper::EnumData<Sampler::FilterMode>
84 EnumHelper::GetEnumData() {
85  static const GLenum kValues[] = {
86  GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR,
87  GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR
88  };
89  static const char* kStrings[] = {
90  "Nearest", "Linear", "NearestMipmapNearest", "NearestMipmapLinear",
91  "LinearMipmapNearest", "LinearMipmapLinear"
92  };
93  ION_STATIC_ASSERT(ARRAYSIZE(kValues) == ARRAYSIZE(kStrings),
94  "EnumHelper size mismatch");
95  return EnumData<Sampler::FilterMode>(
96  base::IndexMap<Sampler::FilterMode, GLenum>(kValues, ARRAYSIZE(kValues)),
97  kStrings);
98 }
99 
101 template <> ION_API const EnumHelper::EnumData<Sampler::WrapMode>
102 EnumHelper::GetEnumData() {
103  static const GLenum kValues[] = {
104  GL_CLAMP_TO_EDGE, GL_REPEAT, GL_MIRRORED_REPEAT
105  };
106  static const char* kStrings[] = { "ClampToEdge", "Repeat", "MirroredRepeat" };
107  ION_STATIC_ASSERT(ARRAYSIZE(kValues) == ARRAYSIZE(kStrings),
108  "EnumHelper size mismatch");
109  return EnumData<Sampler::WrapMode>(
110  base::IndexMap<Sampler::WrapMode, GLenum>(kValues, ARRAYSIZE(kValues)),
111  kStrings);
112 }
113 
114 } // namespace base
115 
116 } // namespace ion
This template class can be used to map between two kinds of indices when the following assumptions ap...
Definition: indexmap.h:40
~Sampler() override
The destructor is protected because all base::Referent classes must have protected or private destruc...
Definition: sampler.cc:42
#define ION_STATIC_ASSERT(expr, message)
Copyright 2016 Google Inc.
Definition: static_assert.h:35
A Sampler object represents texture parameters that control how texture data is accessed in shaders...
Definition: sampler.h:29