Avara3D 0.2.0
C++ API reference
Sampler.h
1//
2// Sampler.h
3// avara3d
4//
5// Created by Morgan Davis on 2/7/24.
6// Copyright © 2026 Morgan K Davis. All rights reserved.
7//
8
9#ifndef AVARA3D_VISUAL_MATERIAL_SAMPLER_H
10#define AVARA3D_VISUAL_MATERIAL_SAMPLER_H
11
12#include <climits>
13
14#include "a3d/Id.h"
15#include "a3d/util/Bitmask.h"
16
17namespace a3d {
18
19 class Color;
20 class Image;
21
23 class Sampler {
24
25 public:
26 // [Public Types]
27
28 // TODO: don't use GL constants
30 enum class FilterMode : uint16_t {
31 Nearest = 0x2600,
32 Linear = 0x2601,
33 NearestMipmapNearest = 0x2700,
34 LinearMipmapNearest = 0x2701,
35 NearestMipmapLinear = 0x2702,
36 LinearMipmapLinear = 0x2703
37 };
38
39 // TODO: don't use GL constants
41 enum class WrapMode : uint16_t {
42 Repeat = 0x2901,
43 MirroredRepeat = 0x8370,
44 ClampToEdge = 0x812F
45 };
46
47 // [Public Lifecycle Functions]
48
51
52 Sampler(const Sampler& other);
53 Sampler& operator=(const Sampler& other);
54
55 Sampler(Sampler&& other);
56 Sampler& operator=(Sampler&& other);
57
58 ~Sampler();
59
60 // [Public Member Functions]
61
64
67
70
73
75 float maxAnisotropy() const;
76
82 void maxAnisotropy(float max);
83
85 WrapMode wrapS() const;
86
88 void wrapS(WrapMode mode);
89
91 WrapMode wrapT() const;
92
94 void wrapT(WrapMode mode);
95
97 WrapMode wrapR() const;
98
100 void wrapR(WrapMode mode);
101
102 // [Internal Types]
103
104 enum class DirtyMask : uint32_t {
105 None = 0,
106 MinificationFilter = 1 << 0,
107 MagnificationFilter = 1 << 1,
108 MaxAnisotropy = 1 << 2,
109 WrapS = 1 << 3,
110 WrapT = 1 << 4,
111 WrapR = 1 << 5,
112 All = UINT_MAX
113 };
114
115 // [Internal Member Functions]
116
117 SamplerId id() const noexcept;
118
119 DirtyMask dirtyMask() const;
120 void dirtyMask(DirtyMask mask);
121
122 private:
123 // [Private Member Variables]
124
125 SamplerId _id;
126 FilterMode _minificationFilter;
127 FilterMode _magnificationFilter;
128 float _maxAnisotropy;
129 WrapMode _wrapS;
130 WrapMode _wrapT;
131 WrapMode _wrapR;
132
133 DirtyMask _dirtyMask;
134 };
135
136 namespace util::bitmask {
137
138 template<>
139 struct enable_ops<Sampler::DirtyMask> : std::true_type {};
140
141 }
142}
143
144#endif // AVARA3D_VISUAL_MATERIAL_SAMPLER_H
Describes filtering, anisotropy, and coordinate wrapping for a Texture.
Definition: Sampler.h:23
void wrapT(WrapMode mode)
Sets the T-coordinate wrap mode.
void wrapR(WrapMode mode)
Sets the R-coordinate wrap mode used by cubemap sampling.
void magnificationFilter(FilterMode mode)
Sets the magnification filter; magnification supports Nearest or Linear filtering.
WrapMode wrapT() const
Returns the T-coordinate wrap mode.
void wrapS(WrapMode mode)
Sets the S-coordinate wrap mode.
void maxAnisotropy(float max)
Sets the requested maximum anisotropy.
WrapMode
Selects how texture coordinates outside the image range are wrapped.
Definition: Sampler.h:41
WrapMode wrapS() const
Returns the S-coordinate wrap mode.
WrapMode wrapR() const
Returns the R-coordinate wrap mode used by cubemap sampling.
FilterMode minificationFilter() const
Returns the texture minification filter.
float maxAnisotropy() const
Returns the requested maximum anisotropy.
FilterMode magnificationFilter() const
Returns the texture magnification filter.
Sampler()
Creates a Sampler with default filtering, anisotropy, and wrapping state.
FilterMode
Selects texture filtering and optional mipmap interpolation.
Definition: Sampler.h:30
void minificationFilter(FilterMode mode)
Sets the texture minification filter.