1 //
2 // Copyright (c) 2014 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 // State.h: Defines the State class, encapsulating raw GL state
8 
9 #ifndef LIBANGLE_STATE_H_
10 #define LIBANGLE_STATE_H_
11 
12 #include <bitset>
13 #include <memory>
14 
15 #include "common/Color.h"
16 #include "common/angleutils.h"
17 #include "common/bitset_utils.h"
18 #include "libANGLE/Debug.h"
19 #include "libANGLE/Program.h"
20 #include "libANGLE/ProgramPipeline.h"
21 #include "libANGLE/RefCountObject.h"
22 #include "libANGLE/Renderbuffer.h"
23 #include "libANGLE/Sampler.h"
24 #include "libANGLE/Texture.h"
25 #include "libANGLE/TransformFeedback.h"
26 #include "libANGLE/Version.h"
27 #include "libANGLE/VertexAttribute.h"
28 #include "libANGLE/angletypes.h"
29 
30 namespace gl
31 {
32 class Query;
33 class VertexArray;
34 class Context;
35 struct Caps;
36 
37 class State : public angle::ObserverInterface, angle::NonCopyable
38 {
39   public:
40     State();
41     ~State() override;
42 
43     void initialize(const Context *context,
44                     bool debug,
45                     bool bindGeneratesResource,
46                     bool clientArraysEnabled,
47                     bool robustResourceInit,
48                     bool programBinaryCacheEnabled);
49     void reset(const Context *context);
50 
51     // State chunk getters
52     const RasterizerState &getRasterizerState() const;
53     const BlendState &getBlendState() const;
54     const DepthStencilState &getDepthStencilState() const;
55 
56     // Clear behavior setters & state parameter block generation function
57     void setColorClearValue(float red, float green, float blue, float alpha);
58     void setDepthClearValue(float depth);
59     void setStencilClearValue(int stencil);
60 
getColorClearValue()61     const ColorF &getColorClearValue() const { return mColorClearValue; }
getDepthClearValue()62     float getDepthClearValue() const { return mDepthClearValue; }
getStencilClearValue()63     int getStencilClearValue() const { return mStencilClearValue; }
64 
65     // Write mask manipulation
66     void setColorMask(bool red, bool green, bool blue, bool alpha);
67     void setDepthMask(bool mask);
68 
69     // Discard toggle & query
70     bool isRasterizerDiscardEnabled() const;
71     void setRasterizerDiscard(bool enabled);
72 
73     // Primitive restart
74     bool isPrimitiveRestartEnabled() const;
75     void setPrimitiveRestart(bool enabled);
76 
77     // Face culling state manipulation
78     bool isCullFaceEnabled() const;
79     void setCullFace(bool enabled);
80     void setCullMode(CullFaceMode mode);
81     void setFrontFace(GLenum front);
82 
83     // Depth test state manipulation
84     bool isDepthTestEnabled() const;
85     void setDepthTest(bool enabled);
86     void setDepthFunc(GLenum depthFunc);
87     void setDepthRange(float zNear, float zFar);
88     float getNearPlane() const;
89     float getFarPlane() const;
90 
91     // Blend state manipulation
92     bool isBlendEnabled() const;
93     void setBlend(bool enabled);
94     void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha);
95     void setBlendColor(float red, float green, float blue, float alpha);
96     void setBlendEquation(GLenum rgbEquation, GLenum alphaEquation);
97     const ColorF &getBlendColor() const;
98 
99     // Stencil state maniupulation
100     bool isStencilTestEnabled() const;
101     void setStencilTest(bool enabled);
102     void setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask);
103     void setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask);
104     void setStencilWritemask(GLuint stencilWritemask);
105     void setStencilBackWritemask(GLuint stencilBackWritemask);
106     void setStencilOperations(GLenum stencilFail,
107                               GLenum stencilPassDepthFail,
108                               GLenum stencilPassDepthPass);
109     void setStencilBackOperations(GLenum stencilBackFail,
110                                   GLenum stencilBackPassDepthFail,
111                                   GLenum stencilBackPassDepthPass);
112     GLint getStencilRef() const;
113     GLint getStencilBackRef() const;
114 
115     // Depth bias/polygon offset state manipulation
116     bool isPolygonOffsetFillEnabled() const;
117     void setPolygonOffsetFill(bool enabled);
118     void setPolygonOffsetParams(GLfloat factor, GLfloat units);
119 
120     // Multisample coverage state manipulation
121     bool isSampleAlphaToCoverageEnabled() const;
122     void setSampleAlphaToCoverage(bool enabled);
123     bool isSampleCoverageEnabled() const;
124     void setSampleCoverage(bool enabled);
125     void setSampleCoverageParams(GLclampf value, bool invert);
126     GLfloat getSampleCoverageValue() const;
127     bool getSampleCoverageInvert() const;
128 
129     // Multisample mask state manipulation.
130     bool isSampleMaskEnabled() const;
131     void setSampleMaskEnabled(bool enabled);
132     void setSampleMaskParams(GLuint maskNumber, GLbitfield mask);
133     GLbitfield getSampleMaskWord(GLuint maskNumber) const;
134     GLuint getMaxSampleMaskWords() const;
135 
136     // Multisampling/alpha to one manipulation.
137     void setSampleAlphaToOne(bool enabled);
138     bool isSampleAlphaToOneEnabled() const;
139     void setMultisampling(bool enabled);
140     bool isMultisamplingEnabled() const;
141 
142     // Scissor test state toggle & query
143     bool isScissorTestEnabled() const;
144     void setScissorTest(bool enabled);
145     void setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height);
146     const Rectangle &getScissor() const;
147 
148     // Dither state toggle & query
149     bool isDitherEnabled() const;
150     void setDither(bool enabled);
151 
152     // Generic state toggle & query
153     void setEnableFeature(GLenum feature, bool enabled);
154     bool getEnableFeature(GLenum feature) const;
155 
156     // Line width state setter
157     void setLineWidth(GLfloat width);
158     float getLineWidth() const;
159 
160     // Hint setters
161     void setGenerateMipmapHint(GLenum hint);
162     void setFragmentShaderDerivativeHint(GLenum hint);
163 
164     // GL_CHROMIUM_bind_generates_resource
165     bool isBindGeneratesResourceEnabled() const;
166 
167     // GL_ANGLE_client_arrays
168     bool areClientArraysEnabled() const;
169 
170     // Viewport state setter/getter
171     void setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height);
172     const Rectangle &getViewport() const;
173 
174     // Texture binding & active texture unit manipulation
175     void setActiveSampler(unsigned int active);
176     unsigned int getActiveSampler() const;
177     void setSamplerTexture(const Context *context, GLenum type, Texture *texture);
178     Texture *getTargetTexture(GLenum target) const;
179     Texture *getSamplerTexture(unsigned int sampler, GLenum type) const;
180     GLuint getSamplerTextureId(unsigned int sampler, GLenum type) const;
181     void detachTexture(const Context *context, const TextureMap &zeroTextures, GLuint texture);
182     void initializeZeroTextures(const Context *context, const TextureMap &zeroTextures);
183 
184     // Sampler object binding manipulation
185     void setSamplerBinding(const Context *context, GLuint textureUnit, Sampler *sampler);
186     GLuint getSamplerId(GLuint textureUnit) const;
187     Sampler *getSampler(GLuint textureUnit) const;
188     void detachSampler(const Context *context, GLuint sampler);
189 
190     // Renderbuffer binding manipulation
191     void setRenderbufferBinding(const Context *context, Renderbuffer *renderbuffer);
192     GLuint getRenderbufferId() const;
193     Renderbuffer *getCurrentRenderbuffer() const;
194     void detachRenderbuffer(const Context *context, GLuint renderbuffer);
195 
196     // Framebuffer binding manipulation
197     void setReadFramebufferBinding(Framebuffer *framebuffer);
198     void setDrawFramebufferBinding(Framebuffer *framebuffer);
199     Framebuffer *getTargetFramebuffer(GLenum target) const;
200     Framebuffer *getReadFramebuffer() const;
201     Framebuffer *getDrawFramebuffer() const;
202     bool removeReadFramebufferBinding(GLuint framebuffer);
203     bool removeDrawFramebufferBinding(GLuint framebuffer);
204 
205     // Vertex array object binding manipulation
206     void setVertexArrayBinding(VertexArray *vertexArray);
207     GLuint getVertexArrayId() const;
208     VertexArray *getVertexArray() const;
209     bool removeVertexArrayBinding(GLuint vertexArray);
210 
211     // Program binding manipulation
212     void setProgram(const Context *context, Program *newProgram);
213     Program *getProgram() const;
214 
215     // Transform feedback object (not buffer) binding manipulation
216     void setTransformFeedbackBinding(const Context *context, TransformFeedback *transformFeedback);
217     TransformFeedback *getCurrentTransformFeedback() const;
218     bool isTransformFeedbackActiveUnpaused() const;
219     bool removeTransformFeedbackBinding(const Context *context, GLuint transformFeedback);
220 
221     // Query binding manipulation
222     bool isQueryActive(const GLenum type) const;
223     bool isQueryActive(Query *query) const;
224     void setActiveQuery(const Context *context, GLenum target, Query *query);
225     GLuint getActiveQueryId(GLenum target) const;
226     Query *getActiveQuery(GLenum target) const;
227 
228     // Program Pipeline binding manipulation
229     void setProgramPipelineBinding(const Context *context, ProgramPipeline *pipeline);
230     void detachProgramPipeline(const Context *context, GLuint pipeline);
231 
232     //// Typed buffer binding point manipulation ////
233     void setBufferBinding(const Context *context, BufferBinding target, Buffer *buffer);
234     Buffer *getTargetBuffer(BufferBinding target) const;
235     void setIndexedBufferBinding(const Context *context,
236                                  BufferBinding target,
237                                  GLuint index,
238                                  Buffer *buffer,
239                                  GLintptr offset,
240                                  GLsizeiptr size);
241 
242     const OffsetBindingPointer<Buffer> &getIndexedUniformBuffer(size_t index) const;
243     const OffsetBindingPointer<Buffer> &getIndexedAtomicCounterBuffer(size_t index) const;
244     const OffsetBindingPointer<Buffer> &getIndexedShaderStorageBuffer(size_t index) const;
245 
246     // Detach a buffer from all bindings
247     void detachBuffer(const Context *context, GLuint bufferName);
248 
249     // Vertex attrib manipulation
250     void setEnableVertexAttribArray(unsigned int attribNum, bool enabled);
251     void setElementArrayBuffer(const Context *context, Buffer *buffer);
252     void setVertexAttribf(GLuint index, const GLfloat values[4]);
253     void setVertexAttribu(GLuint index, const GLuint values[4]);
254     void setVertexAttribi(GLuint index, const GLint values[4]);
255     void setVertexAttribPointer(const Context *context,
256                                 unsigned int attribNum,
257                                 Buffer *boundBuffer,
258                                 GLint size,
259                                 GLenum type,
260                                 bool normalized,
261                                 bool pureInteger,
262                                 GLsizei stride,
263                                 const void *pointer);
264     void setVertexAttribDivisor(const Context *context, GLuint index, GLuint divisor);
265     const VertexAttribCurrentValueData &getVertexAttribCurrentValue(size_t attribNum) const;
266     const std::vector<VertexAttribCurrentValueData> &getVertexAttribCurrentValues() const;
267     const void *getVertexAttribPointer(unsigned int attribNum) const;
268     void bindVertexBuffer(const Context *context,
269                           GLuint bindingIndex,
270                           Buffer *boundBuffer,
271                           GLintptr offset,
272                           GLsizei stride);
273     void setVertexAttribFormat(GLuint attribIndex,
274                                GLint size,
275                                GLenum type,
276                                bool normalized,
277                                bool pureInteger,
278                                GLuint relativeOffset);
279     void setVertexAttribBinding(const Context *context, GLuint attribIndex, GLuint bindingIndex);
280     void setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor);
281 
282     // Pixel pack state manipulation
283     void setPackAlignment(GLint alignment);
284     GLint getPackAlignment() const;
285     void setPackReverseRowOrder(bool reverseRowOrder);
286     bool getPackReverseRowOrder() const;
287     void setPackRowLength(GLint rowLength);
288     GLint getPackRowLength() const;
289     void setPackSkipRows(GLint skipRows);
290     GLint getPackSkipRows() const;
291     void setPackSkipPixels(GLint skipPixels);
292     GLint getPackSkipPixels() const;
293     const PixelPackState &getPackState() const;
294     PixelPackState &getPackState();
295 
296     // Pixel unpack state manipulation
297     void setUnpackAlignment(GLint alignment);
298     GLint getUnpackAlignment() const;
299     void setUnpackRowLength(GLint rowLength);
300     GLint getUnpackRowLength() const;
301     void setUnpackImageHeight(GLint imageHeight);
302     GLint getUnpackImageHeight() const;
303     void setUnpackSkipImages(GLint skipImages);
304     GLint getUnpackSkipImages() const;
305     void setUnpackSkipRows(GLint skipRows);
306     GLint getUnpackSkipRows() const;
307     void setUnpackSkipPixels(GLint skipPixels);
308     GLint getUnpackSkipPixels() const;
309     const PixelUnpackState &getUnpackState() const;
310     PixelUnpackState &getUnpackState();
311 
312     // Debug state
313     const Debug &getDebug() const;
314     Debug &getDebug();
315 
316     // CHROMIUM_framebuffer_mixed_samples coverage modulation
317     void setCoverageModulation(GLenum components);
318     GLenum getCoverageModulation() const;
319 
320     // CHROMIUM_path_rendering
321     void loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix);
322     const GLfloat *getPathRenderingMatrix(GLenum which) const;
323     void setPathStencilFunc(GLenum func, GLint ref, GLuint mask);
324 
325     GLenum getPathStencilFunc() const;
326     GLint getPathStencilRef() const;
327     GLuint getPathStencilMask() const;
328 
329     // GL_EXT_sRGB_write_control
330     void setFramebufferSRGB(bool sRGB);
331     bool getFramebufferSRGB() const;
332 
333     // State query functions
334     void getBooleanv(GLenum pname, GLboolean *params);
335     void getFloatv(GLenum pname, GLfloat *params);
336     void getIntegerv(const Context *context, GLenum pname, GLint *params);
337     void getPointerv(GLenum pname, void **params) const;
338     void getIntegeri_v(GLenum target, GLuint index, GLint *data);
339     void getInteger64i_v(GLenum target, GLuint index, GLint64 *data);
340     void getBooleani_v(GLenum target, GLuint index, GLboolean *data);
341 
342     bool hasMappedBuffer(BufferBinding target) const;
isRobustResourceInitEnabled()343     bool isRobustResourceInitEnabled() const { return mRobustResourceInit; }
344 
345     // Sets the dirty bit for the program executable.
346     void onProgramExecutableChange(Program *program);
347 
348     enum DirtyBitType
349     {
350         DIRTY_BIT_SCISSOR_TEST_ENABLED,
351         DIRTY_BIT_SCISSOR,
352         DIRTY_BIT_VIEWPORT,
353         DIRTY_BIT_DEPTH_RANGE,
354         DIRTY_BIT_BLEND_ENABLED,
355         DIRTY_BIT_BLEND_COLOR,
356         DIRTY_BIT_BLEND_FUNCS,
357         DIRTY_BIT_BLEND_EQUATIONS,
358         DIRTY_BIT_COLOR_MASK,
359         DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED,
360         DIRTY_BIT_SAMPLE_COVERAGE_ENABLED,
361         DIRTY_BIT_SAMPLE_COVERAGE,
362         DIRTY_BIT_SAMPLE_MASK_ENABLED,
363         DIRTY_BIT_SAMPLE_MASK,
364         DIRTY_BIT_DEPTH_TEST_ENABLED,
365         DIRTY_BIT_DEPTH_FUNC,
366         DIRTY_BIT_DEPTH_MASK,
367         DIRTY_BIT_STENCIL_TEST_ENABLED,
368         DIRTY_BIT_STENCIL_FUNCS_FRONT,
369         DIRTY_BIT_STENCIL_FUNCS_BACK,
370         DIRTY_BIT_STENCIL_OPS_FRONT,
371         DIRTY_BIT_STENCIL_OPS_BACK,
372         DIRTY_BIT_STENCIL_WRITEMASK_FRONT,
373         DIRTY_BIT_STENCIL_WRITEMASK_BACK,
374         DIRTY_BIT_CULL_FACE_ENABLED,
375         DIRTY_BIT_CULL_FACE,
376         DIRTY_BIT_FRONT_FACE,
377         DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED,
378         DIRTY_BIT_POLYGON_OFFSET,
379         DIRTY_BIT_RASTERIZER_DISCARD_ENABLED,
380         DIRTY_BIT_LINE_WIDTH,
381         DIRTY_BIT_PRIMITIVE_RESTART_ENABLED,
382         DIRTY_BIT_CLEAR_COLOR,
383         DIRTY_BIT_CLEAR_DEPTH,
384         DIRTY_BIT_CLEAR_STENCIL,
385         DIRTY_BIT_UNPACK_STATE,
386         DIRTY_BIT_UNPACK_BUFFER_BINDING,
387         DIRTY_BIT_PACK_STATE,
388         DIRTY_BIT_PACK_BUFFER_BINDING,
389         DIRTY_BIT_DITHER_ENABLED,
390         DIRTY_BIT_GENERATE_MIPMAP_HINT,
391         DIRTY_BIT_SHADER_DERIVATIVE_HINT,
392         DIRTY_BIT_READ_FRAMEBUFFER_BINDING,
393         DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING,
394         DIRTY_BIT_RENDERBUFFER_BINDING,
395         DIRTY_BIT_VERTEX_ARRAY_BINDING,
396         DIRTY_BIT_DRAW_INDIRECT_BUFFER_BINDING,
397         DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING,
398         DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING,
399         // TODO(jmadill): Fine-grained dirty bits for each index.
400         DIRTY_BIT_UNIFORM_BUFFER_BINDINGS,
401         DIRTY_BIT_PROGRAM_BINDING,
402         DIRTY_BIT_PROGRAM_EXECUTABLE,
403         // TODO(jmadill): Fine-grained dirty bits for each texture/sampler.
404         DIRTY_BIT_TEXTURE_BINDINGS,
405         DIRTY_BIT_SAMPLER_BINDINGS,
406         DIRTY_BIT_TRANSFORM_FEEDBACK_BINDING,
407         DIRTY_BIT_MULTISAMPLING,
408         DIRTY_BIT_SAMPLE_ALPHA_TO_ONE,
409         DIRTY_BIT_COVERAGE_MODULATION,         // CHROMIUM_framebuffer_mixed_samples
410         DIRTY_BIT_PATH_RENDERING_MATRIX_MV,    // CHROMIUM_path_rendering path model view matrix
411         DIRTY_BIT_PATH_RENDERING_MATRIX_PROJ,  // CHROMIUM_path_rendering path projection matrix
412         DIRTY_BIT_PATH_RENDERING_STENCIL_STATE,
413         DIRTY_BIT_FRAMEBUFFER_SRGB,  // GL_EXT_sRGB_write_control
414         DIRTY_BIT_CURRENT_VALUES,
415         DIRTY_BIT_INVALID,
416         DIRTY_BIT_MAX = DIRTY_BIT_INVALID,
417     };
418 
419     static_assert(DIRTY_BIT_MAX <= 64, "State dirty bits must be capped at 64");
420 
421     // TODO(jmadill): Consider storing dirty objects in a list instead of by binding.
422     enum DirtyObjectType
423     {
424         DIRTY_OBJECT_READ_FRAMEBUFFER,
425         DIRTY_OBJECT_DRAW_FRAMEBUFFER,
426         DIRTY_OBJECT_VERTEX_ARRAY,
427         // Use a very coarse bit for any program or texture change.
428         // TODO(jmadill): Fine-grained dirty bits for each texture/sampler.
429         DIRTY_OBJECT_PROGRAM_TEXTURES,
430         DIRTY_OBJECT_UNKNOWN,
431         DIRTY_OBJECT_MAX = DIRTY_OBJECT_UNKNOWN,
432     };
433 
434     using DirtyBits = angle::BitSet<DIRTY_BIT_MAX>;
getDirtyBits()435     const DirtyBits &getDirtyBits() const { return mDirtyBits; }
clearDirtyBits()436     void clearDirtyBits() { mDirtyBits.reset(); }
clearDirtyBits(const DirtyBits & bitset)437     void clearDirtyBits(const DirtyBits &bitset) { mDirtyBits &= ~bitset; }
setAllDirtyBits()438     void setAllDirtyBits() { mDirtyBits.set(); }
439 
440     using DirtyObjects = angle::BitSet<DIRTY_OBJECT_MAX>;
clearDirtyObjects()441     void clearDirtyObjects() { mDirtyObjects.reset(); }
setAllDirtyObjects()442     void setAllDirtyObjects() { mDirtyObjects.set(); }
443     void syncDirtyObjects(const Context *context);
444     void syncDirtyObjects(const Context *context, const DirtyObjects &bitset);
445     void syncDirtyObject(const Context *context, GLenum target);
446     void setObjectDirty(GLenum target);
447 
448     // This actually clears the current value dirty bits.
449     // TODO(jmadill): Pass mutable dirty bits into Impl.
450     AttributesMask getAndResetDirtyCurrentValues() const;
451 
452     void setImageUnit(const Context *context,
453                       GLuint unit,
454                       Texture *texture,
455                       GLint level,
456                       GLboolean layered,
457                       GLint layer,
458                       GLenum access,
459                       GLenum format);
460 
461     const ImageUnit &getImageUnit(GLuint unit) const;
getCompleteTextureCache()462     const std::vector<Texture *> &getCompleteTextureCache() const { return mCompleteTextureCache; }
getCurrentValuesTypeMask()463     ComponentTypeMask getCurrentValuesTypeMask() const { return mCurrentValuesTypeMask; }
464 
465     // Observer implementation.
466     void onSubjectStateChange(const Context *context,
467                               angle::SubjectIndex index,
468                               angle::SubjectMessage message) override;
469 
470     Error clearUnclearedActiveTextures(const Context *context);
471 
472   private:
473     void syncProgramTextures(const Context *context);
474 
475     // Cached values from Context's caps
476     GLuint mMaxDrawBuffers;
477     GLuint mMaxCombinedTextureImageUnits;
478 
479     ColorF mColorClearValue;
480     GLfloat mDepthClearValue;
481     int mStencilClearValue;
482 
483     RasterizerState mRasterizer;
484     bool mScissorTest;
485     Rectangle mScissor;
486 
487     BlendState mBlend;
488     ColorF mBlendColor;
489     bool mSampleCoverage;
490     GLfloat mSampleCoverageValue;
491     bool mSampleCoverageInvert;
492     bool mSampleMask;
493     GLuint mMaxSampleMaskWords;
494     std::array<GLbitfield, MAX_SAMPLE_MASK_WORDS> mSampleMaskValues;
495 
496     DepthStencilState mDepthStencil;
497     GLint mStencilRef;
498     GLint mStencilBackRef;
499 
500     GLfloat mLineWidth;
501 
502     GLenum mGenerateMipmapHint;
503     GLenum mFragmentShaderDerivativeHint;
504 
505     bool mBindGeneratesResource;
506     bool mClientArraysEnabled;
507 
508     Rectangle mViewport;
509     float mNearZ;
510     float mFarZ;
511 
512     Framebuffer *mReadFramebuffer;
513     Framebuffer *mDrawFramebuffer;
514     BindingPointer<Renderbuffer> mRenderbuffer;
515     Program *mProgram;
516     BindingPointer<ProgramPipeline> mProgramPipeline;
517 
518     typedef std::vector<VertexAttribCurrentValueData> VertexAttribVector;
519     VertexAttribVector mVertexAttribCurrentValues;  // From glVertexAttrib
520     VertexArray *mVertexArray;
521     ComponentTypeMask mCurrentValuesTypeMask;
522 
523     // Texture and sampler bindings
524     size_t mActiveSampler;  // Active texture unit selector - GL_TEXTURE0
525 
526     typedef std::vector<BindingPointer<Texture>> TextureBindingVector;
527     typedef std::map<GLenum, TextureBindingVector> TextureBindingMap;
528     TextureBindingMap mSamplerTextures;
529 
530     // Texture Completeness Caching
531     // ----------------------------
532     // The texture completeness cache uses dirty bits to avoid having to scan the list of textures
533     // each draw call. This gl::State class implements angle::Observer interface. When subject
534     // Textures have state changes, messages reach 'State' (also any observing Framebuffers) via the
535     // onSubjectStateChange method (above). This then invalidates the completeness cache.
536     //
537     // Note this requires that we also invalidate the completeness cache manually on events like
538     // re-binding textures/samplers or a change in the program. For more information see the
539     // signal_utils.h header and the design doc linked there.
540 
541     // A cache of complete textures. nullptr indicates unbound or incomplete.
542     // Don't use BindingPointer because this cache is only valid within a draw call.
543     // Also stores a notification channel to the texture itself to handle texture change events.
544     std::vector<Texture *> mCompleteTextureCache;
545     std::vector<angle::ObserverBinding> mCompleteTextureBindings;
546     InitState mCachedTexturesInitState;
547     using ActiveTextureMask = angle::BitSet<IMPLEMENTATION_MAX_ACTIVE_TEXTURES>;
548     ActiveTextureMask mActiveTexturesMask;
549 
550     typedef std::vector<BindingPointer<Sampler>> SamplerBindingVector;
551     SamplerBindingVector mSamplers;
552 
553     typedef std::vector<ImageUnit> ImageUnitVector;
554     ImageUnitVector mImageUnits;
555 
556     typedef std::map<GLenum, BindingPointer<Query>> ActiveQueryMap;
557     ActiveQueryMap mActiveQueries;
558 
559     // Stores the currently bound buffer for each binding point. It has entries for the element
560     // array buffer and the transform feedback buffer but these should not be used. Instead these
561     // bind points are respectively owned by current the vertex array object and the current
562     // transform feedback object.
563     using BoundBufferMap = angle::PackedEnumMap<BufferBinding, BindingPointer<Buffer>>;
564     BoundBufferMap mBoundBuffers;
565 
566     using BufferVector = std::vector<OffsetBindingPointer<Buffer>>;
567     BufferVector mUniformBuffers;
568     BufferVector mAtomicCounterBuffers;
569     BufferVector mShaderStorageBuffers;
570 
571     BindingPointer<TransformFeedback> mTransformFeedback;
572 
573     BindingPointer<Buffer> mPixelUnpackBuffer;
574     PixelUnpackState mUnpack;
575     BindingPointer<Buffer> mPixelPackBuffer;
576     PixelPackState mPack;
577 
578     bool mPrimitiveRestart;
579 
580     Debug mDebug;
581 
582     bool mMultiSampling;
583     bool mSampleAlphaToOne;
584 
585     GLenum mCoverageModulation;
586 
587     // CHROMIUM_path_rendering
588     GLfloat mPathMatrixMV[16];
589     GLfloat mPathMatrixProj[16];
590     GLenum mPathStencilFunc;
591     GLint mPathStencilRef;
592     GLuint mPathStencilMask;
593 
594     // GL_EXT_sRGB_write_control
595     bool mFramebufferSRGB;
596 
597     // GL_ANGLE_robust_resource_intialization
598     bool mRobustResourceInit;
599 
600     // GL_ANGLE_program_cache_control
601     bool mProgramBinaryCacheEnabled;
602 
603     DirtyBits mDirtyBits;
604     DirtyObjects mDirtyObjects;
605     mutable AttributesMask mDirtyCurrentValues;
606 };
607 
608 }  // namespace gl
609 
610 #endif  // LIBANGLE_STATE_H_
611