Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / src / libGLESv2 / State.h
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 LIBGLESV2_STATE_H_
10 #define LIBGLESV2_STATE_H_
11
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"
21
22 namespace gl
23 {
24 class Query;
25 class VertexArray;
26 class Context;
27
28 class State
29 {
30   public:
31     State();
32     ~State();
33
34     void setContext(Context *context) { mContext = context; }
35
36     // State chunk getters
37     const RasterizerState &getRasterizerState() const;
38     const BlendState &getBlendState() const;
39     const DepthStencilState &getDepthStencilState() const;
40
41     // Clear behavior setters & state parameter block generation function
42     void setClearColor(float red, float green, float blue, float alpha);
43     void setClearDepth(float depth);
44     void setClearStencil(int stencil);
45     ClearParameters getClearParameters(GLbitfield mask) const;
46
47     // Write mask manipulation
48     void setColorMask(bool red, bool green, bool blue, bool alpha);
49     void setDepthMask(bool mask);
50
51     // Discard toggle & query
52     bool isRasterizerDiscardEnabled() const;
53     void setRasterizerDiscard(bool enabled);
54
55     // Face culling state manipulation
56     bool isCullFaceEnabled() const;
57     void setCullFace(bool enabled);
58     void setCullMode(GLenum mode);
59     void setFrontFace(GLenum front);
60
61     // Depth test state manipulation
62     bool isDepthTestEnabled() const;
63     void setDepthTest(bool enabled);
64     void setDepthFunc(GLenum depthFunc);
65     void setDepthRange(float zNear, float zFar);
66     void getDepthRange(float *zNear, float *zFar) const;
67
68     // Blend state manipulation
69     bool isBlendEnabled() const;
70     void setBlend(bool enabled);
71     void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha);
72     void setBlendColor(float red, float green, float blue, float alpha);
73     void setBlendEquation(GLenum rgbEquation, GLenum alphaEquation);
74     const ColorF &getBlendColor() const;
75
76     // Stencil state maniupulation
77     bool isStencilTestEnabled() const;
78     void setStencilTest(bool enabled);
79     void setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask);
80     void setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask);
81     void setStencilWritemask(GLuint stencilWritemask);
82     void setStencilBackWritemask(GLuint stencilBackWritemask);
83     void setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass);
84     void setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass);
85     GLint getStencilRef() const;
86     GLint getStencilBackRef() const;
87
88     // Depth bias/polygon offset state manipulation
89     bool isPolygonOffsetFillEnabled() const;
90     void setPolygonOffsetFill(bool enabled);
91     void setPolygonOffsetParams(GLfloat factor, GLfloat units);
92
93     // Multisample coverage state manipulation
94     bool isSampleAlphaToCoverageEnabled() const;
95     void setSampleAlphaToCoverage(bool enabled);
96     bool isSampleCoverageEnabled() const;
97     void setSampleCoverage(bool enabled);
98     void setSampleCoverageParams(GLclampf value, bool invert);
99     void getSampleCoverageParams(GLclampf *value, bool *invert);
100
101     // Scissor test state toggle & query
102     bool isScissorTestEnabled() const;
103     void setScissorTest(bool enabled);
104     void setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height);
105     const Rectangle &getScissor() const;
106
107     // Dither state toggle & query
108     bool isDitherEnabled() const;
109     void setDither(bool enabled);
110
111     // Generic state toggle & query
112     void setEnableFeature(GLenum feature, bool enabled);
113     bool getEnableFeature(GLenum feature);
114
115     // Line width state setter
116     void setLineWidth(GLfloat width);
117
118     // Hint setters
119     void setGenerateMipmapHint(GLenum hint);
120     void setFragmentShaderDerivativeHint(GLenum hint);
121
122     // Viewport state setter/getter
123     void setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height);
124     const Rectangle &getViewport() const;
125
126     // Texture binding & active texture unit manipulation
127     void setActiveSampler(unsigned int active);
128     unsigned int getActiveSampler() const;
129     void setSamplerTexture(TextureType type, Texture *texture);
130     Texture *getSamplerTexture(unsigned int sampler, TextureType type) const;
131     GLuint getSamplerTextureId(unsigned int sampler, TextureType type) const;
132     void detachTexture(GLuint texture);
133
134     // Sampler object binding manipulation
135     void setSamplerBinding(GLuint textureUnit, Sampler *sampler);
136     GLuint getSamplerId(GLuint textureUnit) const;
137     Sampler *getSampler(GLuint textureUnit) const;
138     void detachSampler(GLuint sampler);
139
140     // Renderbuffer binding manipulation
141     void setRenderbufferBinding(Renderbuffer *renderbuffer);
142     GLuint getRenderbufferId() const;
143     Renderbuffer *getCurrentRenderbuffer();
144     void detachRenderbuffer(GLuint renderbuffer);
145
146     // Framebuffer binding manipulation
147     void setReadFramebufferBinding(Framebuffer *framebuffer);
148     void setDrawFramebufferBinding(Framebuffer *framebuffer);
149     Framebuffer *getTargetFramebuffer(GLenum target) const;
150     Framebuffer *getReadFramebuffer();
151     Framebuffer *getDrawFramebuffer();
152     const Framebuffer *getReadFramebuffer() const;
153     const Framebuffer *getDrawFramebuffer() const;
154     bool removeReadFramebufferBinding(GLuint framebuffer);
155     bool removeDrawFramebufferBinding(GLuint framebuffer);
156
157     // Vertex array object binding manipulation
158     void setVertexArrayBinding(VertexArray *vertexArray);
159     GLuint getVertexArrayId() const;
160     VertexArray *getVertexArray() const;
161     bool removeVertexArrayBinding(GLuint vertexArray);
162
163     // Program binding manipulation
164     void setCurrentProgram(GLuint programId, Program *newProgram);
165     void setCurrentProgramBinary(ProgramBinary *binary);
166     GLuint getCurrentProgramId() const;
167     ProgramBinary *getCurrentProgramBinary() const;
168
169     // Transform feedback object (not buffer) binding manipulation
170     void setTransformFeedbackBinding(TransformFeedback *transformFeedback);
171     TransformFeedback *getCurrentTransformFeedback() const;
172     void detachTransformFeedback(GLuint transformFeedback);
173
174     // Query binding manipulation
175     bool isQueryActive() const;
176     void setActiveQuery(GLenum target, Query *query);
177     GLuint getActiveQueryId(GLenum target) const;
178     Query *getActiveQuery(GLenum target) const;
179
180     //// Typed buffer binding point manipulation ////
181     // GL_ARRAY_BUFFER
182     void setArrayBufferBinding(Buffer *buffer);
183     GLuint getArrayBufferId() const;
184     bool removeArrayBufferBinding(GLuint buffer);
185
186     // GL_UNIFORM_BUFFER - Both indexed and generic targets
187     void setGenericUniformBufferBinding(Buffer *buffer);
188     void setIndexedUniformBufferBinding(GLuint index, Buffer *buffer, GLintptr offset, GLsizeiptr size);
189     GLuint getIndexedUniformBufferId(GLuint index) const;
190     Buffer *getIndexedUniformBuffer(GLuint index) const;
191
192     // GL_TRANSFORM_FEEDBACK_BUFFER - Both indexed and generic targets
193     void setGenericTransformFeedbackBufferBinding(Buffer *buffer);
194     void setIndexedTransformFeedbackBufferBinding(GLuint index, Buffer *buffer, GLintptr offset, GLsizeiptr size);
195     GLuint getIndexedTransformFeedbackBufferId(GLuint index) const;
196     Buffer *getIndexedTransformFeedbackBuffer(GLuint index) const;
197     GLuint getIndexedTransformFeedbackBufferOffset(GLuint index) const;
198
199     // GL_COPY_[READ/WRITE]_BUFFER
200     void setCopyReadBufferBinding(Buffer *buffer);
201     void setCopyWriteBufferBinding(Buffer *buffer);
202
203     // GL_PIXEL[PACK/UNPACK]_BUFFER
204     void setPixelPackBufferBinding(Buffer *buffer);
205     void setPixelUnpackBufferBinding(Buffer *buffer);
206
207     // Retrieve typed buffer by target (non-indexed)
208     Buffer *getTargetBuffer(GLenum target) const;
209
210     // Vertex attrib manipulation
211     void setEnableVertexAttribArray(unsigned int attribNum, bool enabled);
212     void setVertexAttribf(GLuint index, const GLfloat values[4]);
213     void setVertexAttribu(GLuint index, const GLuint values[4]);
214     void setVertexAttribi(GLuint index, const GLint values[4]);
215     void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type,
216                               bool normalized, bool pureInteger, GLsizei stride, const void *pointer);
217     const VertexAttribute &getVertexAttribState(unsigned int attribNum) const;
218     const VertexAttribCurrentValueData &getVertexAttribCurrentValue(unsigned int attribNum) const;
219     const VertexAttribCurrentValueData *getVertexAttribCurrentValues() const;
220     const void *getVertexAttribPointer(unsigned int attribNum) const;
221
222     // Pixel pack state manipulation
223     void setPackAlignment(GLint alignment);
224     GLint getPackAlignment() const;
225     void setPackReverseRowOrder(bool reverseRowOrder);
226     bool getPackReverseRowOrder() const;
227     const PixelPackState &getPackState() const;
228
229     // Pixel unpack state manipulation
230     void setUnpackAlignment(GLint alignment);
231     GLint getUnpackAlignment() const;
232     const PixelUnpackState &getUnpackState() const;
233
234     // State query functions
235     void getBooleanv(GLenum pname, GLboolean *params);
236     void getFloatv(GLenum pname, GLfloat *params);
237     void getIntegerv(GLenum pname, GLint *params);
238     bool getIndexedIntegerv(GLenum target, GLuint index, GLint *data);
239     bool getIndexedInteger64v(GLenum target, GLuint index, GLint64 *data);
240
241     bool hasMappedBuffer(GLenum target) const;
242
243   private:
244     DISALLOW_COPY_AND_ASSIGN(State);
245
246     Context *mContext;
247
248     ColorF mColorClearValue;
249     GLclampf mDepthClearValue;
250     int mStencilClearValue;
251
252     RasterizerState mRasterizer;
253     bool mScissorTest;
254     Rectangle mScissor;
255
256     BlendState mBlend;
257     ColorF mBlendColor;
258     bool mSampleCoverage;
259     GLclampf mSampleCoverageValue;
260     bool mSampleCoverageInvert;
261
262     DepthStencilState mDepthStencil;
263     GLint mStencilRef;
264     GLint mStencilBackRef;
265
266     GLfloat mLineWidth;
267
268     GLenum mGenerateMipmapHint;
269     GLenum mFragmentShaderDerivativeHint;
270
271     Rectangle mViewport;
272     float mNearZ;
273     float mFarZ;
274
275     unsigned int mActiveSampler;   // Active texture unit selector - GL_TEXTURE0
276     BindingPointer<Buffer> mArrayBuffer;
277     Framebuffer *mReadFramebuffer;
278     Framebuffer *mDrawFramebuffer;
279     BindingPointer<Renderbuffer> mRenderbuffer;
280     GLuint mCurrentProgramId;
281     BindingPointer<ProgramBinary> mCurrentProgramBinary;
282
283     VertexAttribCurrentValueData mVertexAttribCurrentValues[MAX_VERTEX_ATTRIBS]; // From glVertexAttrib
284     VertexArray *mVertexArray;
285
286     BindingPointer<Texture> mSamplerTexture[TEXTURE_TYPE_COUNT][IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS];
287     BindingPointer<Sampler> mSamplers[IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS];
288
289     typedef std::map< GLenum, BindingPointer<Query> > ActiveQueryMap;
290     ActiveQueryMap mActiveQueries;
291
292     BindingPointer<Buffer> mGenericUniformBuffer;
293     OffsetBindingPointer<Buffer> mUniformBuffers[IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS];
294
295     BindingPointer<TransformFeedback> mTransformFeedback;
296     BindingPointer<Buffer> mGenericTransformFeedbackBuffer;
297     OffsetBindingPointer<Buffer> mTransformFeedbackBuffers[IMPLEMENTATION_MAX_TRANSFORM_FEEDBACK_BUFFERS];
298
299     BindingPointer<Buffer> mCopyReadBuffer;
300     BindingPointer<Buffer> mCopyWriteBuffer;
301
302     PixelUnpackState mUnpack;
303     PixelPackState mPack;
304 };
305
306 }
307
308 #endif // LIBGLESV2_STATE_H_
309