Update To 11.40.268.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 struct Caps;
28
29 class State
30 {
31   public:
32     State();
33     ~State();
34
35     void initialize(const Caps& caps, GLuint clientVersion);
36     void reset();
37
38     // State chunk getters
39     const RasterizerState &getRasterizerState() const;
40     const BlendState &getBlendState() const;
41     const DepthStencilState &getDepthStencilState() const;
42
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;
48
49     // Write mask manipulation
50     void setColorMask(bool red, bool green, bool blue, bool alpha);
51     void setDepthMask(bool mask);
52
53     // Discard toggle & query
54     bool isRasterizerDiscardEnabled() const;
55     void setRasterizerDiscard(bool enabled);
56
57     // Face culling state manipulation
58     bool isCullFaceEnabled() const;
59     void setCullFace(bool enabled);
60     void setCullMode(GLenum mode);
61     void setFrontFace(GLenum front);
62
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;
69
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;
77
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;
89
90     // Depth bias/polygon offset state manipulation
91     bool isPolygonOffsetFillEnabled() const;
92     void setPolygonOffsetFill(bool enabled);
93     void setPolygonOffsetParams(GLfloat factor, GLfloat units);
94
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);
102
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;
108
109     // Dither state toggle & query
110     bool isDitherEnabled() const;
111     void setDither(bool enabled);
112
113     // Generic state toggle & query
114     void setEnableFeature(GLenum feature, bool enabled);
115     bool getEnableFeature(GLenum feature);
116
117     // Line width state setter
118     void setLineWidth(GLfloat width);
119
120     // Hint setters
121     void setGenerateMipmapHint(GLenum hint);
122     void setFragmentShaderDerivativeHint(GLenum hint);
123
124     // Viewport state setter/getter
125     void setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height);
126     const Rectangle &getViewport() const;
127
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);
135
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);
141
142     // Renderbuffer binding manipulation
143     void setRenderbufferBinding(Renderbuffer *renderbuffer);
144     GLuint getRenderbufferId() const;
145     Renderbuffer *getCurrentRenderbuffer();
146     void detachRenderbuffer(GLuint renderbuffer);
147
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);
158
159     // Vertex array object binding manipulation
160     void setVertexArrayBinding(VertexArray *vertexArray);
161     GLuint getVertexArrayId() const;
162     VertexArray *getVertexArray() const;
163     bool removeVertexArrayBinding(GLuint vertexArray);
164
165     // Program binding manipulation
166     void setCurrentProgram(GLuint programId, Program *newProgram);
167     void setCurrentProgramBinary(ProgramBinary *binary);
168     GLuint getCurrentProgramId() const;
169     ProgramBinary *getCurrentProgramBinary() const;
170
171     // Transform feedback object (not buffer) binding manipulation
172     void setTransformFeedbackBinding(TransformFeedback *transformFeedback);
173     TransformFeedback *getCurrentTransformFeedback() const;
174     void detachTransformFeedback(GLuint transformFeedback);
175
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;
181
182     //// Typed buffer binding point manipulation ////
183     // GL_ARRAY_BUFFER
184     void setArrayBufferBinding(Buffer *buffer);
185     GLuint getArrayBufferId() const;
186     bool removeArrayBufferBinding(GLuint buffer);
187
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;
193
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;
201
202     // GL_COPY_[READ/WRITE]_BUFFER
203     void setCopyReadBufferBinding(Buffer *buffer);
204     void setCopyWriteBufferBinding(Buffer *buffer);
205
206     // GL_PIXEL[PACK/UNPACK]_BUFFER
207     void setPixelPackBufferBinding(Buffer *buffer);
208     void setPixelUnpackBufferBinding(Buffer *buffer);
209
210     // Retrieve typed buffer by target (non-indexed)
211     Buffer *getTargetBuffer(GLenum target) const;
212
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;
223
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;
230
231     // Pixel unpack state manipulation
232     void setUnpackAlignment(GLint alignment);
233     GLint getUnpackAlignment() const;
234     const PixelUnpackState &getUnpackState() const;
235
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);
242
243     bool hasMappedBuffer(GLenum target) const;
244
245   private:
246     DISALLOW_COPY_AND_ASSIGN(State);
247
248     // Cached values from Context's caps
249     GLuint mMaxDrawBuffers;
250     GLuint mMaxCombinedTextureImageUnits;
251
252     ColorF mColorClearValue;
253     GLclampf mDepthClearValue;
254     int mStencilClearValue;
255
256     RasterizerState mRasterizer;
257     bool mScissorTest;
258     Rectangle mScissor;
259
260     BlendState mBlend;
261     ColorF mBlendColor;
262     bool mSampleCoverage;
263     GLclampf mSampleCoverageValue;
264     bool mSampleCoverageInvert;
265
266     DepthStencilState mDepthStencil;
267     GLint mStencilRef;
268     GLint mStencilBackRef;
269
270     GLfloat mLineWidth;
271
272     GLenum mGenerateMipmapHint;
273     GLenum mFragmentShaderDerivativeHint;
274
275     Rectangle mViewport;
276     float mNearZ;
277     float mFarZ;
278
279     BindingPointer<Buffer> mArrayBuffer;
280     Framebuffer *mReadFramebuffer;
281     Framebuffer *mDrawFramebuffer;
282     BindingPointer<Renderbuffer> mRenderbuffer;
283     GLuint mCurrentProgramId;
284     BindingPointer<ProgramBinary> mCurrentProgramBinary;
285
286     typedef std::vector<VertexAttribCurrentValueData> VertexAttribVector;
287     VertexAttribVector mVertexAttribCurrentValues; // From glVertexAttrib
288     VertexArray *mVertexArray;
289
290     // Texture and sampler bindings
291     size_t mActiveSampler;   // Active texture unit selector - GL_TEXTURE0
292
293     typedef std::vector< BindingPointer<Texture> > TextureBindingVector;
294     typedef std::map<GLenum, TextureBindingVector> TextureBindingMap;
295     TextureBindingMap mSamplerTextures;
296
297     typedef std::vector< BindingPointer<Sampler> > SamplerBindingVector;
298     SamplerBindingVector mSamplers;
299
300     typedef std::map< GLenum, BindingPointer<Query> > ActiveQueryMap;
301     ActiveQueryMap mActiveQueries;
302
303     BindingPointer<Buffer> mGenericUniformBuffer;
304     typedef std::vector< OffsetBindingPointer<Buffer> > BufferVector;
305     BufferVector mUniformBuffers;
306
307     BindingPointer<TransformFeedback> mTransformFeedback;
308     BindingPointer<Buffer> mGenericTransformFeedbackBuffer;
309     BufferVector mTransformFeedbackBuffers;
310
311     BindingPointer<Buffer> mCopyReadBuffer;
312     BindingPointer<Buffer> mCopyWriteBuffer;
313
314     PixelUnpackState mUnpack;
315     PixelPackState mPack;
316 };
317
318 }
319
320 #endif // LIBGLESV2_STATE_H_
321