xref: /aosp_15_r20/external/angle/src/libANGLE/Sampler.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2013 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // Sampler.cpp : Implements the Sampler class, which represents a GLES 3
8 // sampler object. Sampler objects store some state needed to sample textures.
9 
10 #include "libANGLE/Sampler.h"
11 #include "libANGLE/angletypes.h"
12 #include "libANGLE/renderer/GLImplFactory.h"
13 #include "libANGLE/renderer/SamplerImpl.h"
14 
15 namespace gl
16 {
17 
Sampler(rx::GLImplFactory * factory,SamplerID id)18 Sampler::Sampler(rx::GLImplFactory *factory, SamplerID id)
19     : RefCountObject(factory->generateSerial(), id),
20       mState(),
21       mDirty(true),
22       mSampler(factory->createSampler(mState)),
23       mLabel()
24 {}
25 
~Sampler()26 Sampler::~Sampler()
27 {
28     SafeDelete(mSampler);
29 }
30 
onDestroy(const Context * context)31 void Sampler::onDestroy(const Context *context)
32 {
33     if (mSampler)
34     {
35         mSampler->onDestroy(context);
36     }
37 }
38 
setLabel(const Context * context,const std::string & label)39 angle::Result Sampler::setLabel(const Context *context, const std::string &label)
40 {
41     mLabel = label;
42 
43     if (mSampler)
44     {
45         return mSampler->onLabelUpdate(context);
46     }
47     return angle::Result::Continue;
48 }
49 
getLabel() const50 const std::string &Sampler::getLabel() const
51 {
52     return mLabel;
53 }
54 
setMinFilter(const Context * context,GLenum minFilter)55 void Sampler::setMinFilter(const Context *context, GLenum minFilter)
56 {
57     mState.setMinFilter(minFilter);
58     signalDirtyState();
59 }
60 
getMinFilter() const61 GLenum Sampler::getMinFilter() const
62 {
63     return mState.getMinFilter();
64 }
65 
setMagFilter(const Context * context,GLenum magFilter)66 void Sampler::setMagFilter(const Context *context, GLenum magFilter)
67 {
68     mState.setMagFilter(magFilter);
69     signalDirtyState();
70 }
71 
getMagFilter() const72 GLenum Sampler::getMagFilter() const
73 {
74     return mState.getMagFilter();
75 }
76 
setWrapS(const Context * context,GLenum wrapS)77 void Sampler::setWrapS(const Context *context, GLenum wrapS)
78 {
79     mState.setWrapS(wrapS);
80     signalDirtyState();
81 }
82 
getWrapS() const83 GLenum Sampler::getWrapS() const
84 {
85     return mState.getWrapS();
86 }
87 
setWrapT(const Context * context,GLenum wrapT)88 void Sampler::setWrapT(const Context *context, GLenum wrapT)
89 {
90     mState.setWrapT(wrapT);
91     signalDirtyState();
92 }
93 
getWrapT() const94 GLenum Sampler::getWrapT() const
95 {
96     return mState.getWrapT();
97 }
98 
setWrapR(const Context * context,GLenum wrapR)99 void Sampler::setWrapR(const Context *context, GLenum wrapR)
100 {
101     mState.setWrapR(wrapR);
102     signalDirtyState();
103 }
104 
getWrapR() const105 GLenum Sampler::getWrapR() const
106 {
107     return mState.getWrapR();
108 }
109 
setMaxAnisotropy(const Context * context,float maxAnisotropy)110 void Sampler::setMaxAnisotropy(const Context *context, float maxAnisotropy)
111 {
112     mState.setMaxAnisotropy(maxAnisotropy);
113     signalDirtyState();
114 }
115 
getMaxAnisotropy() const116 float Sampler::getMaxAnisotropy() const
117 {
118     return mState.getMaxAnisotropy();
119 }
120 
setMinLod(const Context * context,GLfloat minLod)121 void Sampler::setMinLod(const Context *context, GLfloat minLod)
122 {
123     mState.setMinLod(minLod);
124     signalDirtyState();
125 }
126 
getMinLod() const127 GLfloat Sampler::getMinLod() const
128 {
129     return mState.getMinLod();
130 }
131 
setMaxLod(const Context * context,GLfloat maxLod)132 void Sampler::setMaxLod(const Context *context, GLfloat maxLod)
133 {
134     mState.setMaxLod(maxLod);
135     signalDirtyState();
136 }
137 
getMaxLod() const138 GLfloat Sampler::getMaxLod() const
139 {
140     return mState.getMaxLod();
141 }
142 
setCompareMode(const Context * context,GLenum compareMode)143 void Sampler::setCompareMode(const Context *context, GLenum compareMode)
144 {
145     mState.setCompareMode(compareMode);
146     signalDirtyState();
147 }
148 
getCompareMode() const149 GLenum Sampler::getCompareMode() const
150 {
151     return mState.getCompareMode();
152 }
153 
setCompareFunc(const Context * context,GLenum compareFunc)154 void Sampler::setCompareFunc(const Context *context, GLenum compareFunc)
155 {
156     mState.setCompareFunc(compareFunc);
157     signalDirtyState();
158 }
159 
getCompareFunc() const160 GLenum Sampler::getCompareFunc() const
161 {
162     return mState.getCompareFunc();
163 }
164 
setSRGBDecode(const Context * context,GLenum sRGBDecode)165 void Sampler::setSRGBDecode(const Context *context, GLenum sRGBDecode)
166 {
167     mState.setSRGBDecode(sRGBDecode);
168     signalDirtyState();
169 }
170 
getSRGBDecode() const171 GLenum Sampler::getSRGBDecode() const
172 {
173     return mState.getSRGBDecode();
174 }
175 
setBorderColor(const Context * context,const ColorGeneric & color)176 void Sampler::setBorderColor(const Context *context, const ColorGeneric &color)
177 {
178     mState.setBorderColor(color);
179     signalDirtyState();
180 }
181 
getBorderColor() const182 const ColorGeneric &Sampler::getBorderColor() const
183 {
184     return mState.getBorderColor();
185 }
186 
getSamplerState() const187 const SamplerState &Sampler::getSamplerState() const
188 {
189     return mState;
190 }
191 
getImplementation() const192 rx::SamplerImpl *Sampler::getImplementation() const
193 {
194     return mSampler;
195 }
196 
syncState(const Context * context)197 angle::Result Sampler::syncState(const Context *context)
198 {
199     ASSERT(isDirty());
200     angle::Result result = mSampler->syncState(context, mDirty);
201     mDirty               = result != angle::Result::Continue;
202     return result;
203 }
204 
signalDirtyState()205 void Sampler::signalDirtyState()
206 {
207     mDirty = true;
208     onStateChange(angle::SubjectMessage::DirtyBitsFlagged);
209 }
210 
211 }  // namespace gl
212