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.
7 // State.h: Defines the State class, encapsulating raw GL state
9 #ifndef LIBGLESV2_STATE_H_
10 #define LIBGLESV2_STATE_H_
12 #include "common/angleutils.h"
13 #include "common/RefCountObject.h"
14 #include "libGLESv2/angletypes.h"
15 #include "libGLESv2/VertexAttribute.h"
16 #include "libGLESv2/Renderbuffer.h"
17 #include "libGLESv2/Texture.h"
18 #include "libGLESv2/TransformFeedback.h"
19 #include "libGLESv2/Program.h"
20 #include "libGLESv2/Sampler.h"
35 void initialize(const Caps& caps, GLuint clientVersion);
38 // State chunk getters
39 const RasterizerState &getRasterizerState() const;
40 const BlendState &getBlendState() const;
41 const DepthStencilState &getDepthStencilState() const;
43 // Clear behavior setters & state parameter block generation function
44 void setClearColor(float red, float green, float blue, float alpha);
45 void setClearDepth(float depth);
46 void setClearStencil(int stencil);
47 ClearParameters getClearParameters(GLbitfield mask) const;
49 // Write mask manipulation
50 void setColorMask(bool red, bool green, bool blue, bool alpha);
51 void setDepthMask(bool mask);
53 // Discard toggle & query
54 bool isRasterizerDiscardEnabled() const;
55 void setRasterizerDiscard(bool enabled);
57 // Face culling state manipulation
58 bool isCullFaceEnabled() const;
59 void setCullFace(bool enabled);
60 void setCullMode(GLenum mode);
61 void setFrontFace(GLenum front);
63 // Depth test state manipulation
64 bool isDepthTestEnabled() const;
65 void setDepthTest(bool enabled);
66 void setDepthFunc(GLenum depthFunc);
67 void setDepthRange(float zNear, float zFar);
68 void getDepthRange(float *zNear, float *zFar) const;
70 // Blend state manipulation
71 bool isBlendEnabled() const;
72 void setBlend(bool enabled);
73 void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha);
74 void setBlendColor(float red, float green, float blue, float alpha);
75 void setBlendEquation(GLenum rgbEquation, GLenum alphaEquation);
76 const ColorF &getBlendColor() const;
78 // Stencil state maniupulation
79 bool isStencilTestEnabled() const;
80 void setStencilTest(bool enabled);
81 void setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask);
82 void setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask);
83 void setStencilWritemask(GLuint stencilWritemask);
84 void setStencilBackWritemask(GLuint stencilBackWritemask);
85 void setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass);
86 void setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass);
87 GLint getStencilRef() const;
88 GLint getStencilBackRef() const;
90 // Depth bias/polygon offset state manipulation
91 bool isPolygonOffsetFillEnabled() const;
92 void setPolygonOffsetFill(bool enabled);
93 void setPolygonOffsetParams(GLfloat factor, GLfloat units);
95 // Multisample coverage state manipulation
96 bool isSampleAlphaToCoverageEnabled() const;
97 void setSampleAlphaToCoverage(bool enabled);
98 bool isSampleCoverageEnabled() const;
99 void setSampleCoverage(bool enabled);
100 void setSampleCoverageParams(GLclampf value, bool invert);
101 void getSampleCoverageParams(GLclampf *value, bool *invert);
103 // Scissor test state toggle & query
104 bool isScissorTestEnabled() const;
105 void setScissorTest(bool enabled);
106 void setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height);
107 const Rectangle &getScissor() const;
109 // Dither state toggle & query
110 bool isDitherEnabled() const;
111 void setDither(bool enabled);
113 // Generic state toggle & query
114 void setEnableFeature(GLenum feature, bool enabled);
115 bool getEnableFeature(GLenum feature);
117 // Line width state setter
118 void setLineWidth(GLfloat width);
121 void setGenerateMipmapHint(GLenum hint);
122 void setFragmentShaderDerivativeHint(GLenum hint);
124 // Viewport state setter/getter
125 void setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height);
126 const Rectangle &getViewport() const;
128 // Texture binding & active texture unit manipulation
129 void setActiveSampler(unsigned int active);
130 unsigned int getActiveSampler() const;
131 void setSamplerTexture(GLenum type, Texture *texture);
132 Texture *getSamplerTexture(unsigned int sampler, GLenum type) const;
133 GLuint getSamplerTextureId(unsigned int sampler, GLenum type) const;
134 void detachTexture(GLuint texture);
136 // Sampler object binding manipulation
137 void setSamplerBinding(GLuint textureUnit, Sampler *sampler);
138 GLuint getSamplerId(GLuint textureUnit) const;
139 Sampler *getSampler(GLuint textureUnit) const;
140 void detachSampler(GLuint sampler);
142 // Renderbuffer binding manipulation
143 void setRenderbufferBinding(Renderbuffer *renderbuffer);
144 GLuint getRenderbufferId() const;
145 Renderbuffer *getCurrentRenderbuffer();
146 void detachRenderbuffer(GLuint renderbuffer);
148 // Framebuffer binding manipulation
149 void setReadFramebufferBinding(Framebuffer *framebuffer);
150 void setDrawFramebufferBinding(Framebuffer *framebuffer);
151 Framebuffer *getTargetFramebuffer(GLenum target) const;
152 Framebuffer *getReadFramebuffer();
153 Framebuffer *getDrawFramebuffer();
154 const Framebuffer *getReadFramebuffer() const;
155 const Framebuffer *getDrawFramebuffer() const;
156 bool removeReadFramebufferBinding(GLuint framebuffer);
157 bool removeDrawFramebufferBinding(GLuint framebuffer);
159 // Vertex array object binding manipulation
160 void setVertexArrayBinding(VertexArray *vertexArray);
161 GLuint getVertexArrayId() const;
162 VertexArray *getVertexArray() const;
163 bool removeVertexArrayBinding(GLuint vertexArray);
165 // Program binding manipulation
166 void setCurrentProgram(GLuint programId, Program *newProgram);
167 void setCurrentProgramBinary(ProgramBinary *binary);
168 GLuint getCurrentProgramId() const;
169 ProgramBinary *getCurrentProgramBinary() const;
171 // Transform feedback object (not buffer) binding manipulation
172 void setTransformFeedbackBinding(TransformFeedback *transformFeedback);
173 TransformFeedback *getCurrentTransformFeedback() const;
174 void detachTransformFeedback(GLuint transformFeedback);
176 // Query binding manipulation
177 bool isQueryActive() const;
178 void setActiveQuery(GLenum target, Query *query);
179 GLuint getActiveQueryId(GLenum target) const;
180 Query *getActiveQuery(GLenum target) const;
182 //// Typed buffer binding point manipulation ////
184 void setArrayBufferBinding(Buffer *buffer);
185 GLuint getArrayBufferId() const;
186 bool removeArrayBufferBinding(GLuint buffer);
188 // GL_UNIFORM_BUFFER - Both indexed and generic targets
189 void setGenericUniformBufferBinding(Buffer *buffer);
190 void setIndexedUniformBufferBinding(GLuint index, Buffer *buffer, GLintptr offset, GLsizeiptr size);
191 GLuint getIndexedUniformBufferId(GLuint index) const;
192 Buffer *getIndexedUniformBuffer(GLuint index) const;
194 // GL_TRANSFORM_FEEDBACK_BUFFER - Both indexed and generic targets
195 void setGenericTransformFeedbackBufferBinding(Buffer *buffer);
196 void setIndexedTransformFeedbackBufferBinding(GLuint index, Buffer *buffer, GLintptr offset, GLsizeiptr size);
197 GLuint getIndexedTransformFeedbackBufferId(GLuint index) const;
198 Buffer *getIndexedTransformFeedbackBuffer(GLuint index) const;
199 GLuint getIndexedTransformFeedbackBufferOffset(GLuint index) const;
200 size_t getTransformFeedbackBufferIndexRange() const;
202 // GL_COPY_[READ/WRITE]_BUFFER
203 void setCopyReadBufferBinding(Buffer *buffer);
204 void setCopyWriteBufferBinding(Buffer *buffer);
206 // GL_PIXEL[PACK/UNPACK]_BUFFER
207 void setPixelPackBufferBinding(Buffer *buffer);
208 void setPixelUnpackBufferBinding(Buffer *buffer);
210 // Retrieve typed buffer by target (non-indexed)
211 Buffer *getTargetBuffer(GLenum target) const;
213 // Vertex attrib manipulation
214 void setEnableVertexAttribArray(unsigned int attribNum, bool enabled);
215 void setVertexAttribf(GLuint index, const GLfloat values[4]);
216 void setVertexAttribu(GLuint index, const GLuint values[4]);
217 void setVertexAttribi(GLuint index, const GLint values[4]);
218 void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type,
219 bool normalized, bool pureInteger, GLsizei stride, const void *pointer);
220 const VertexAttribute &getVertexAttribState(unsigned int attribNum) const;
221 const VertexAttribCurrentValueData &getVertexAttribCurrentValue(unsigned int attribNum) const;
222 const void *getVertexAttribPointer(unsigned int attribNum) const;
224 // Pixel pack state manipulation
225 void setPackAlignment(GLint alignment);
226 GLint getPackAlignment() const;
227 void setPackReverseRowOrder(bool reverseRowOrder);
228 bool getPackReverseRowOrder() const;
229 const PixelPackState &getPackState() const;
231 // Pixel unpack state manipulation
232 void setUnpackAlignment(GLint alignment);
233 GLint getUnpackAlignment() const;
234 const PixelUnpackState &getUnpackState() const;
236 // State query functions
237 void getBooleanv(GLenum pname, GLboolean *params);
238 void getFloatv(GLenum pname, GLfloat *params);
239 void getIntegerv(GLenum pname, GLint *params);
240 bool getIndexedIntegerv(GLenum target, GLuint index, GLint *data);
241 bool getIndexedInteger64v(GLenum target, GLuint index, GLint64 *data);
243 bool hasMappedBuffer(GLenum target) const;
246 DISALLOW_COPY_AND_ASSIGN(State);
248 // Cached values from Context's caps
249 GLuint mMaxDrawBuffers;
250 GLuint mMaxCombinedTextureImageUnits;
252 ColorF mColorClearValue;
253 GLclampf mDepthClearValue;
254 int mStencilClearValue;
256 RasterizerState mRasterizer;
262 bool mSampleCoverage;
263 GLclampf mSampleCoverageValue;
264 bool mSampleCoverageInvert;
266 DepthStencilState mDepthStencil;
268 GLint mStencilBackRef;
272 GLenum mGenerateMipmapHint;
273 GLenum mFragmentShaderDerivativeHint;
279 BindingPointer<Buffer> mArrayBuffer;
280 Framebuffer *mReadFramebuffer;
281 Framebuffer *mDrawFramebuffer;
282 BindingPointer<Renderbuffer> mRenderbuffer;
283 GLuint mCurrentProgramId;
284 BindingPointer<ProgramBinary> mCurrentProgramBinary;
286 typedef std::vector<VertexAttribCurrentValueData> VertexAttribVector;
287 VertexAttribVector mVertexAttribCurrentValues; // From glVertexAttrib
288 VertexArray *mVertexArray;
290 // Texture and sampler bindings
291 size_t mActiveSampler; // Active texture unit selector - GL_TEXTURE0
293 typedef std::vector< BindingPointer<Texture> > TextureBindingVector;
294 typedef std::map<GLenum, TextureBindingVector> TextureBindingMap;
295 TextureBindingMap mSamplerTextures;
297 typedef std::vector< BindingPointer<Sampler> > SamplerBindingVector;
298 SamplerBindingVector mSamplers;
300 typedef std::map< GLenum, BindingPointer<Query> > ActiveQueryMap;
301 ActiveQueryMap mActiveQueries;
303 BindingPointer<Buffer> mGenericUniformBuffer;
304 typedef std::vector< OffsetBindingPointer<Buffer> > BufferVector;
305 BufferVector mUniformBuffers;
307 BindingPointer<TransformFeedback> mTransformFeedback;
308 BindingPointer<Buffer> mGenericTransformFeedbackBuffer;
309 BufferVector mTransformFeedbackBuffers;
311 BindingPointer<Buffer> mCopyReadBuffer;
312 BindingPointer<Buffer> mCopyWriteBuffer;
314 PixelUnpackState mUnpack;
315 PixelPackState mPack;
320 #endif // LIBGLESV2_STATE_H_