OSDN Git Service

Enable glsl integer code
[android-x86/external-swiftshader.git] / src / OpenGL / libGLESv2 / Context.h
1 // SwiftShader Software Renderer\r
2 //\r
3 // Copyright(c) 2005-2013 TransGaming Inc.\r
4 //\r
5 // All rights reserved. No part of this software may be copied, distributed, transmitted,\r
6 // transcribed, stored in a retrieval system, translated into any human or computer\r
7 // language by any means, or disclosed to third parties without the explicit written\r
8 // agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express\r
9 // or implied, including but not limited to any patent rights, are granted to you.\r
10 //\r
11 \r
12 // Context.h: Defines the Context class, managing all GL state and performing\r
13 // rendering operations. It is the GLES2 specific implementation of EGLContext.\r
14 \r
15 #ifndef LIBGLESV2_CONTEXT_H_\r
16 #define LIBGLESV2_CONTEXT_H_\r
17 \r
18 #include "libEGL/Context.hpp"\r
19 #include "ResourceManager.h"\r
20 #include "common/NameSpace.hpp"\r
21 #include "common/Object.hpp"\r
22 #include "common/Image.hpp"\r
23 #include "Renderer/Sampler.hpp"\r
24 #include "TransformFeedback.h"\r
25 \r
26 #include <GLES2/gl2.h>\r
27 #include <GLES2/gl2ext.h>\r
28 #include <GLES3/gl3.h>\r
29 #include <EGL/egl.h>\r
30 \r
31 #include <map>\r
32 #include <string>\r
33 \r
34 namespace egl\r
35 {\r
36 class Display;\r
37 class Surface;\r
38 class Config;\r
39 }\r
40 \r
41 namespace es2\r
42 {\r
43 struct TranslatedAttribute;\r
44 struct TranslatedIndexData;\r
45 \r
46 class Device;\r
47 class Buffer;\r
48 class Shader;\r
49 class Program;\r
50 class Texture;\r
51 class Texture2D;\r
52 class Texture3D;\r
53 class Texture2DArray;\r
54 class TextureCubeMap;\r
55 class TextureExternal;\r
56 class Framebuffer;\r
57 class Renderbuffer;\r
58 class RenderbufferStorage;\r
59 class Colorbuffer;\r
60 class Depthbuffer;\r
61 class StreamingIndexBuffer;\r
62 class Stencilbuffer;\r
63 class DepthStencilbuffer;\r
64 class VertexDataManager;\r
65 class IndexDataManager;\r
66 class Fence;\r
67 class FenceSync;\r
68 class Query;\r
69 class Sampler;\r
70 class VertexArray;\r
71 \r
72 enum\r
73 {\r
74     MAX_VERTEX_ATTRIBS = VERTEX_ATTRIBUTES,\r
75         MAX_UNIFORM_VECTORS = 256,   // Device limit\r
76     MAX_VERTEX_UNIFORM_VECTORS = VERTEX_UNIFORM_VECTORS - 3,   // Reserve space for gl_DepthRange\r
77     MAX_VARYING_VECTORS = 10,\r
78     MAX_TEXTURE_IMAGE_UNITS = TEXTURE_IMAGE_UNITS,\r
79     MAX_VERTEX_TEXTURE_IMAGE_UNITS = VERTEX_TEXTURE_IMAGE_UNITS,\r
80     MAX_COMBINED_TEXTURE_IMAGE_UNITS = MAX_TEXTURE_IMAGE_UNITS + MAX_VERTEX_TEXTURE_IMAGE_UNITS,\r
81     MAX_FRAGMENT_UNIFORM_VECTORS = FRAGMENT_UNIFORM_VECTORS - 3,    // Reserve space for gl_DepthRange\r
82     MAX_DRAW_BUFFERS = 1,\r
83         MAX_ELEMENT_INDEX = 0x7FFFFFFF,\r
84         MAX_ELEMENTS_INDICES = 0x7FFFFFFF,\r
85         MAX_ELEMENTS_VERTICES = 0x7FFFFFFF,\r
86     MAX_VERTEX_OUTPUT_VECTORS = 16,\r
87     MAX_FRAGMENT_INPUT_VECTORS = 15,\r
88     MIN_PROGRAM_TEXEL_OFFSET = -8,\r
89     MAX_PROGRAM_TEXEL_OFFSET = 7,\r
90 };\r
91 \r
92 const GLenum compressedTextureFormats[] =\r
93 {\r
94         GL_ETC1_RGB8_OES,\r
95 #if (S3TC_SUPPORT)\r
96         GL_COMPRESSED_RGB_S3TC_DXT1_EXT,\r
97         GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,\r
98         GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE,\r
99         GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE,\r
100 #endif\r
101 #if (GL_ES_VERSION_3_0)\r
102         GL_COMPRESSED_R11_EAC,\r
103         GL_COMPRESSED_SIGNED_R11_EAC,\r
104         GL_COMPRESSED_RG11_EAC,\r
105         GL_COMPRESSED_SIGNED_RG11_EAC,\r
106         GL_COMPRESSED_RGB8_ETC2,\r
107         GL_COMPRESSED_SRGB8_ETC2,\r
108         GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,\r
109         GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,\r
110         GL_COMPRESSED_RGBA8_ETC2_EAC,\r
111         GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,\r
112 #endif\r
113 };\r
114 \r
115 const GLint NUM_COMPRESSED_TEXTURE_FORMATS = sizeof(compressedTextureFormats) / sizeof(compressedTextureFormats[0]);\r
116 \r
117 const float ALIASED_LINE_WIDTH_RANGE_MIN = 1.0f;\r
118 const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f;\r
119 const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f;\r
120 const float ALIASED_POINT_SIZE_RANGE_MAX = 8192.0f;\r
121 const float MAX_TEXTURE_MAX_ANISOTROPY = 16.0f;\r
122 \r
123 enum QueryType\r
124 {\r
125     QUERY_ANY_SAMPLES_PASSED,\r
126     QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE,\r
127     QUERY_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN,\r
128 \r
129     QUERY_TYPE_COUNT\r
130 };\r
131 \r
132 struct Color\r
133 {\r
134     float red;\r
135     float green;\r
136     float blue;\r
137     float alpha;\r
138 };\r
139 \r
140 // Helper structure describing a single vertex attribute\r
141 class VertexAttribute\r
142 {\r
143 public:\r
144     VertexAttribute() : mType(GL_FLOAT), mSize(0), mNormalized(false), mStride(0), mDivisor(0), mPointer(NULL), mArrayEnabled(false)\r
145     {\r
146         mCurrentValue[0].f = 0.0f;\r
147         mCurrentValue[1].f = 0.0f;\r
148         mCurrentValue[2].f = 0.0f;\r
149         mCurrentValue[3].f = 1.0f;\r
150                 mCurrentValueType = ValueUnion::FloatType;\r
151     }\r
152 \r
153     int typeSize() const\r
154     {\r
155         switch (mType)\r
156         {\r
157         case GL_BYTE:           return mSize * sizeof(GLbyte);\r
158         case GL_UNSIGNED_BYTE:  return mSize * sizeof(GLubyte);\r
159         case GL_SHORT:          return mSize * sizeof(GLshort);\r
160         case GL_UNSIGNED_SHORT: return mSize * sizeof(GLushort);\r
161         case GL_FIXED:          return mSize * sizeof(GLfixed);\r
162         case GL_FLOAT:          return mSize * sizeof(GLfloat);\r
163         default: UNREACHABLE(mType); return mSize * sizeof(GLfloat);\r
164         }\r
165     }\r
166 \r
167     GLsizei stride() const\r
168     {\r
169         return mStride ? mStride : typeSize();\r
170     }\r
171 \r
172         inline float getCurrentValueBitsAsFloat(int i) const\r
173         {\r
174                 return mCurrentValue[i].f;\r
175         }\r
176 \r
177         inline float getCurrentValueF(int i) const\r
178         {\r
179                 switch(mCurrentValueType)\r
180                 {\r
181                 case ValueUnion::FloatType:     return mCurrentValue[i].f;\r
182                 case ValueUnion::IntType:       return static_cast<float>(mCurrentValue[i].i);\r
183                 case ValueUnion::UIntType:      return static_cast<float>(mCurrentValue[i].ui);\r
184                 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].f;\r
185                 }\r
186         }\r
187 \r
188         inline GLint getCurrentValueI(int i) const\r
189         {\r
190                 switch(mCurrentValueType)\r
191                 {\r
192                 case ValueUnion::FloatType:     return static_cast<GLint>(mCurrentValue[i].f);\r
193                 case ValueUnion::IntType:       return mCurrentValue[i].i;\r
194                 case ValueUnion::UIntType:      return static_cast<GLint>(mCurrentValue[i].ui);\r
195                 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].i;\r
196                 }\r
197         }\r
198 \r
199         inline GLuint getCurrentValueUI(int i) const\r
200         {\r
201                 switch(mCurrentValueType)\r
202                 {\r
203                 case ValueUnion::FloatType:     return static_cast<GLuint>(mCurrentValue[i].f);\r
204                 case ValueUnion::IntType:       return static_cast<GLuint>(mCurrentValue[i].i);\r
205                 case ValueUnion::UIntType:      return mCurrentValue[i].ui;\r
206                 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].ui;\r
207                 }\r
208         }\r
209 \r
210         inline void setCurrentValue(const GLfloat *values)\r
211         {\r
212                 mCurrentValue[0].f = values[0];\r
213                 mCurrentValue[1].f = values[1];\r
214                 mCurrentValue[2].f = values[2];\r
215                 mCurrentValue[3].f = values[3];\r
216                 mCurrentValueType = ValueUnion::FloatType;\r
217         }\r
218 \r
219         inline void setCurrentValue(const GLint *values)\r
220         {\r
221                 mCurrentValue[0].i = values[0];\r
222                 mCurrentValue[1].i = values[1];\r
223                 mCurrentValue[2].i = values[2];\r
224                 mCurrentValue[3].i = values[3];\r
225                 mCurrentValueType = ValueUnion::IntType;\r
226         }\r
227 \r
228         inline void setCurrentValue(const GLuint *values)\r
229         {\r
230                 mCurrentValue[0].ui = values[0];\r
231                 mCurrentValue[1].ui = values[1];\r
232                 mCurrentValue[2].ui = values[2];\r
233                 mCurrentValue[3].ui = values[3];\r
234                 mCurrentValueType = ValueUnion::UIntType;\r
235         }\r
236 \r
237     // From glVertexAttribPointer\r
238     GLenum mType;\r
239     GLint mSize;\r
240     bool mNormalized;\r
241     GLsizei mStride;   // 0 means natural stride\r
242     GLuint mDivisor;   // From glVertexAttribDivisor\r
243 \r
244     union\r
245     {\r
246         const void *mPointer;\r
247         intptr_t mOffset;\r
248     };\r
249 \r
250     gl::BindingPointer<Buffer> mBoundBuffer;   // Captured when glVertexAttribPointer is called.\r
251 \r
252     bool mArrayEnabled;   // From glEnable/DisableVertexAttribArray\r
253 \r
254 private:\r
255         union ValueUnion\r
256         {\r
257                 enum Type { FloatType, IntType, UIntType };\r
258 \r
259                 float f;\r
260                 GLint i;\r
261                 GLuint ui;\r
262         };\r
263 \r
264         ValueUnion mCurrentValue[4];   // From glVertexAttrib\r
265         ValueUnion::Type mCurrentValueType;\r
266 };\r
267 \r
268 typedef VertexAttribute VertexAttributeArray[MAX_VERTEX_ATTRIBS];\r
269 \r
270 // Helper structure to store all raw state\r
271 struct State\r
272 {\r
273     Color colorClearValue;\r
274     GLclampf depthClearValue;\r
275     int stencilClearValue;\r
276 \r
277     bool cullFaceEnabled;\r
278     GLenum cullMode;\r
279     GLenum frontFace;\r
280     bool depthTestEnabled;\r
281     GLenum depthFunc;\r
282     bool blendEnabled;\r
283     GLenum sourceBlendRGB;\r
284     GLenum destBlendRGB;\r
285     GLenum sourceBlendAlpha;\r
286     GLenum destBlendAlpha;\r
287     GLenum blendEquationRGB;\r
288     GLenum blendEquationAlpha;\r
289     Color blendColor;\r
290     bool stencilTestEnabled;\r
291     GLenum stencilFunc;\r
292     GLint stencilRef;\r
293     GLuint stencilMask;\r
294     GLenum stencilFail;\r
295     GLenum stencilPassDepthFail;\r
296     GLenum stencilPassDepthPass;\r
297     GLuint stencilWritemask;\r
298     GLenum stencilBackFunc;\r
299     GLint stencilBackRef;\r
300     GLuint stencilBackMask;\r
301     GLenum stencilBackFail;\r
302     GLenum stencilBackPassDepthFail;\r
303     GLenum stencilBackPassDepthPass;\r
304     GLuint stencilBackWritemask;\r
305     bool polygonOffsetFillEnabled;\r
306     GLfloat polygonOffsetFactor;\r
307     GLfloat polygonOffsetUnits;\r
308     bool sampleAlphaToCoverageEnabled;\r
309     bool sampleCoverageEnabled;\r
310     GLclampf sampleCoverageValue;\r
311     bool sampleCoverageInvert;\r
312     bool scissorTestEnabled;\r
313     bool ditherEnabled;\r
314     bool primitiveRestartFixedIndexEnabled;\r
315     bool rasterizerDiscardEnabled;\r
316     bool colorLogicOpEnabled;\r
317     GLenum logicalOperation;\r
318 \r
319     GLfloat lineWidth;\r
320 \r
321     GLenum generateMipmapHint;\r
322     GLenum fragmentShaderDerivativeHint;\r
323 \r
324     GLint viewportX;\r
325     GLint viewportY;\r
326     GLsizei viewportWidth;\r
327     GLsizei viewportHeight;\r
328     float zNear;\r
329     float zFar;\r
330 \r
331     GLint scissorX;\r
332     GLint scissorY;\r
333     GLsizei scissorWidth;\r
334     GLsizei scissorHeight;\r
335 \r
336     bool colorMaskRed;\r
337     bool colorMaskGreen;\r
338     bool colorMaskBlue;\r
339     bool colorMaskAlpha;\r
340     bool depthMask;\r
341 \r
342     unsigned int activeSampler;   // Active texture unit selector - GL_TEXTURE0\r
343     gl::BindingPointer<Buffer> arrayBuffer;\r
344         gl::BindingPointer<Buffer> copyReadBuffer;\r
345         gl::BindingPointer<Buffer> copyWriteBuffer;\r
346         gl::BindingPointer<Buffer> pixelPackBuffer;\r
347         gl::BindingPointer<Buffer> pixelUnpackBuffer;\r
348         gl::BindingPointer<Buffer> genericUniformBuffer;\r
349         gl::BindingPointer<Buffer> uniformBuffers[MAX_UNIFORM_BUFFER_BINDINGS];\r
350 \r
351     GLuint readFramebuffer;\r
352     GLuint drawFramebuffer;\r
353     GLuint readFramebufferColorIndex;\r
354     GLuint drawFramebufferColorIndices[MAX_COLOR_ATTACHMENTS];\r
355     gl::BindingPointer<Renderbuffer> renderbuffer;\r
356     GLuint currentProgram;\r
357         GLuint vertexArray;\r
358         GLuint transformFeedback;\r
359         gl::BindingPointer<Sampler> sampler[MAX_COMBINED_TEXTURE_IMAGE_UNITS];\r
360 \r
361     VertexAttribute vertexAttribute[MAX_VERTEX_ATTRIBS];\r
362     gl::BindingPointer<Texture> samplerTexture[TEXTURE_TYPE_COUNT][MAX_COMBINED_TEXTURE_IMAGE_UNITS];\r
363         gl::BindingPointer<Query> activeQuery[QUERY_TYPE_COUNT];\r
364 \r
365         egl::Image::UnpackInfo unpackInfo;\r
366     GLint packAlignment;\r
367         GLint packRowLength;\r
368         GLint packSkipPixels;\r
369         GLint packSkipRows;\r
370 };\r
371 \r
372 class Context : public egl::Context\r
373 {\r
374 public:\r
375     Context(const egl::Config *config, const Context *shareContext, EGLint clientVersion);\r
376 \r
377         virtual void makeCurrent(egl::Surface *surface);\r
378         virtual EGLint getClientVersion() const;\r
379 \r
380     void markAllStateDirty();\r
381 \r
382     // State manipulation\r
383     void setClearColor(float red, float green, float blue, float alpha);\r
384     void setClearDepth(float depth);\r
385     void setClearStencil(int stencil);\r
386 \r
387     void setCullFaceEnabled(bool enabled);\r
388     bool isCullFaceEnabled() const;\r
389     void setCullMode(GLenum mode);\r
390     void setFrontFace(GLenum front);\r
391 \r
392     void setDepthTestEnabled(bool enabled);\r
393     bool isDepthTestEnabled() const;\r
394     void setDepthFunc(GLenum depthFunc);\r
395     void setDepthRange(float zNear, float zFar);\r
396     \r
397     void setBlendEnabled(bool enabled);\r
398     bool isBlendEnabled() const;\r
399     void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha);\r
400     void setBlendColor(float red, float green, float blue, float alpha);\r
401     void setBlendEquation(GLenum rgbEquation, GLenum alphaEquation);\r
402 \r
403     void setStencilTestEnabled(bool enabled);\r
404     bool isStencilTestEnabled() const;\r
405     void setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask);\r
406     void setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask);\r
407     void setStencilWritemask(GLuint stencilWritemask);\r
408     void setStencilBackWritemask(GLuint stencilBackWritemask);\r
409     void setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass);\r
410     void setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass);\r
411 \r
412     void setPolygonOffsetFillEnabled(bool enabled);\r
413     bool isPolygonOffsetFillEnabled() const;\r
414     void setPolygonOffsetParams(GLfloat factor, GLfloat units);\r
415 \r
416     void setSampleAlphaToCoverageEnabled(bool enabled);\r
417     bool isSampleAlphaToCoverageEnabled() const;\r
418     void setSampleCoverageEnabled(bool enabled);\r
419     bool isSampleCoverageEnabled() const;\r
420     void setSampleCoverageParams(GLclampf value, bool invert);\r
421 \r
422     void setDitherEnabled(bool enabled);\r
423     bool isDitherEnabled() const;\r
424 \r
425     void setPrimitiveRestartFixedIndexEnabled(bool enabled);\r
426     bool isPrimitiveRestartFixedIndexEnabled() const;\r
427 \r
428     void setRasterizerDiscardEnabled(bool enabled);\r
429     bool isRasterizerDiscardEnabled() const;\r
430 \r
431     void setLineWidth(GLfloat width);\r
432 \r
433     void setGenerateMipmapHint(GLenum hint);\r
434     void setFragmentShaderDerivativeHint(GLenum hint);\r
435 \r
436     void setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height);\r
437 \r
438         void setScissorTestEnabled(bool enabled);\r
439     bool isScissorTestEnabled() const;\r
440     void setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height);\r
441 \r
442     void setColorMask(bool red, bool green, bool blue, bool alpha);\r
443     unsigned int getColorMask() const;\r
444     void setDepthMask(bool mask);\r
445 \r
446     void setActiveSampler(unsigned int active);\r
447 \r
448     GLuint getReadFramebufferName() const;\r
449     GLuint getDrawFramebufferName() const;\r
450     GLuint getRenderbufferName() const;\r
451 \r
452         void setReadFramebufferColorIndex(GLuint index);\r
453         void setDrawFramebufferColorIndices(GLsizei n, const GLenum *bufs);\r
454         GLuint getReadFramebufferColorIndex() const;\r
455 \r
456         GLuint getActiveQuery(GLenum target) const;\r
457 \r
458     GLuint getArrayBufferName() const;\r
459         GLuint getElementArrayBufferName() const;\r
460 \r
461     void setVertexAttribArrayEnabled(unsigned int attribNum, bool enabled);\r
462     void setVertexAttribDivisor(unsigned int attribNum, GLuint divisor);\r
463     const VertexAttribute &getVertexAttribState(unsigned int attribNum) const;\r
464     void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type,\r
465                               bool normalized, GLsizei stride, const void *pointer);\r
466     const void *getVertexAttribPointer(unsigned int attribNum) const;\r
467 \r
468         const VertexAttributeArray &getVertexArrayAttributes();\r
469         // Context attribute current values can be queried independently from VAO current values\r
470         const VertexAttributeArray &getCurrentVertexAttributes();\r
471 \r
472     void setUnpackAlignment(GLint alignment);\r
473         void setUnpackRowLength(GLint rowLength);\r
474         void setUnpackImageHeight(GLint imageHeight);\r
475         void setUnpackSkipPixels(GLint skipPixels);\r
476         void setUnpackSkipRows(GLint skipRows);\r
477         void setUnpackSkipImages(GLint skipImages);\r
478         const egl::Image::UnpackInfo& getUnpackInfo() const;\r
479 \r
480     void setPackAlignment(GLint alignment);\r
481         void setPackRowLength(GLint rowLength);\r
482         void setPackSkipPixels(GLint skipPixels);\r
483         void setPackSkipRows(GLint skipRows);\r
484 \r
485     // These create  and destroy methods are merely pass-throughs to \r
486     // ResourceManager, which owns these object types\r
487     GLuint createBuffer();\r
488     GLuint createShader(GLenum type);\r
489     GLuint createProgram();\r
490     GLuint createTexture();\r
491     GLuint createRenderbuffer();\r
492     GLuint createSampler();\r
493     GLsync createFenceSync(GLenum condition, GLbitfield flags);\r
494 \r
495     void deleteBuffer(GLuint buffer);\r
496     void deleteShader(GLuint shader);\r
497     void deleteProgram(GLuint program);\r
498     void deleteTexture(GLuint texture);\r
499     void deleteRenderbuffer(GLuint renderbuffer);\r
500     void deleteSampler(GLuint sampler);\r
501     void deleteFenceSync(GLsync fenceSync);\r
502 \r
503     // Framebuffers are owned by the Context, so these methods do not pass through\r
504     GLuint createFramebuffer();\r
505     void deleteFramebuffer(GLuint framebuffer);\r
506 \r
507     // Fences are owned by the Context\r
508     GLuint createFence();\r
509     void deleteFence(GLuint fence);\r
510 \r
511         // Queries are owned by the Context\r
512     GLuint createQuery();\r
513     void deleteQuery(GLuint query);\r
514 \r
515         // Vertex arrays are owned by the Context\r
516         GLuint createVertexArray();\r
517         void deleteVertexArray(GLuint array);\r
518 \r
519         // Transform feedbacks are owned by the Context\r
520         GLuint createTransformFeedback();\r
521         void deleteTransformFeedback(GLuint transformFeedback);\r
522 \r
523     void bindArrayBuffer(GLuint buffer);\r
524     void bindElementArrayBuffer(GLuint buffer);\r
525         void bindCopyReadBuffer(GLuint buffer);\r
526         void bindCopyWriteBuffer(GLuint buffer);\r
527         void bindPixelPackBuffer(GLuint buffer);\r
528         void bindPixelUnpackBuffer(GLuint buffer);\r
529         void bindTransformFeedbackBuffer(GLuint buffer);\r
530     void bindTexture2D(GLuint texture);\r
531     void bindTextureCubeMap(GLuint texture);\r
532     void bindTextureExternal(GLuint texture);\r
533         void bindTexture3D(GLuint texture);\r
534         void bindTexture2DArray(GLuint texture);\r
535     void bindReadFramebuffer(GLuint framebuffer);\r
536     void bindDrawFramebuffer(GLuint framebuffer);\r
537     void bindRenderbuffer(GLuint renderbuffer);\r
538         bool bindVertexArray(GLuint array);\r
539         void bindGenericUniformBuffer(GLuint buffer);\r
540         void bindIndexedUniformBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);\r
541         void bindGenericTransformFeedbackBuffer(GLuint buffer);\r
542         void bindIndexedTransformFeedbackBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);\r
543         bool bindTransformFeedback(GLuint transformFeedback);\r
544         bool bindSampler(GLuint unit, GLuint sampler);\r
545     void useProgram(GLuint program);\r
546 \r
547         void beginQuery(GLenum target, GLuint query);\r
548     void endQuery(GLenum target);\r
549 \r
550     void setFramebufferZero(Framebuffer *framebuffer);\r
551 \r
552     void setRenderbufferStorage(RenderbufferStorage *renderbuffer);\r
553 \r
554     void setVertexAttrib(GLuint index, const GLfloat *values);\r
555     void setVertexAttrib(GLuint index, const GLint *values);\r
556     void setVertexAttrib(GLuint index, const GLuint *values);\r
557 \r
558         Buffer *getBuffer(GLuint handle) const;\r
559         Fence *getFence(GLuint handle) const;\r
560         FenceSync *getFenceSync(GLsync handle) const;\r
561         Shader *getShader(GLuint handle) const;\r
562         Program *getProgram(GLuint handle) const;\r
563         virtual Texture *getTexture(GLuint handle) const;\r
564         Framebuffer *getFramebuffer(GLuint handle) const;\r
565         virtual Renderbuffer *getRenderbuffer(GLuint handle) const;\r
566         Query *getQuery(GLuint handle) const;\r
567         VertexArray *getVertexArray(GLuint array) const;\r
568         VertexArray *getCurrentVertexArray() const;\r
569         TransformFeedback *getTransformFeedback(GLuint transformFeedback) const;\r
570         TransformFeedback *getTransformFeedback() const;\r
571         Sampler *getSampler(GLuint sampler) const;\r
572         bool isSampler(GLuint sampler) const;\r
573 \r
574         Buffer *getArrayBuffer() const;\r
575         Buffer *getElementArrayBuffer() const;\r
576         Buffer *getCopyReadBuffer() const;\r
577         Buffer *getCopyWriteBuffer() const;\r
578         Buffer *getPixelPackBuffer() const;\r
579         Buffer *getPixelUnpackBuffer() const;\r
580         Buffer *getGenericUniformBuffer() const;\r
581         bool getBuffer(GLenum target, es2::Buffer **buffer) const;\r
582         Program *getCurrentProgram() const;\r
583         Texture2D *getTexture2D() const;\r
584         Texture3D *getTexture3D() const;\r
585         Texture2DArray *getTexture2DArray() const;\r
586         TextureCubeMap *getTextureCubeMap() const;\r
587         TextureExternal *getTextureExternal() const;\r
588         Texture *getSamplerTexture(unsigned int sampler, TextureType type) const;\r
589         Framebuffer *getReadFramebuffer() const;\r
590         Framebuffer *getDrawFramebuffer() const;\r
591 \r
592         bool getFloatv(GLenum pname, GLfloat *params) const;\r
593         template<typename T> bool getIntegerv(GLenum pname, T *params) const;\r
594         bool getBooleanv(GLenum pname, GLboolean *params) const;\r
595         template<typename T> bool getTransformFeedbackiv(GLuint xfb, GLenum pname, T *param) const;\r
596         void samplerParameteri(GLuint sampler, GLenum pname, GLint param);\r
597         void samplerParameterf(GLuint sampler, GLenum pname, GLfloat param);\r
598         GLint getSamplerParameteri(GLuint sampler, GLenum pname);\r
599         GLfloat getSamplerParameterf(GLuint sampler, GLenum pname);\r
600 \r
601         bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams) const;\r
602 \r
603         bool hasZeroDivisor() const;\r
604 \r
605     void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels);\r
606     void clear(GLbitfield mask);\r
607     void clearColorBuffer(GLint drawbuffer, const GLint *value);\r
608     void clearColorBuffer(GLint drawbuffer, const GLuint *value);\r
609     void clearColorBuffer(GLint drawbuffer, const GLfloat *value);\r
610     void clearDepthBuffer(GLint drawbuffer, const GLfloat *value);\r
611     void clearStencilBuffer(GLint drawbuffer, const GLint *value);\r
612     void clearDepthStencilBuffer(GLint drawbuffer, GLfloat depth, GLint stencil);\r
613     void drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount = 1);\r
614     void drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLsizei instanceCount = 1);\r
615     void finish();\r
616     void flush();\r
617 \r
618     void recordInvalidEnum();\r
619     void recordInvalidValue();\r
620     void recordInvalidOperation();\r
621     void recordOutOfMemory();\r
622     void recordInvalidFramebufferOperation();\r
623 \r
624     GLenum getError();\r
625 \r
626     static int getSupportedMultiSampleDepth(sw::Format format, int requested);\r
627     \r
628     void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, \r
629                          GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,\r
630                          GLbitfield mask);\r
631 \r
632         virtual void bindTexImage(egl::Surface *surface);\r
633         virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel);\r
634         virtual egl::Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel);\r
635 \r
636         Device *getDevice();\r
637 \r
638         const GLubyte* getExtensions(GLuint index, GLuint* numExt = nullptr) const;\r
639 \r
640 private:\r
641         virtual ~Context();\r
642 \r
643         egl::Image *getScissoredImage(GLint drawbuffer, int &x0, int &y0, int &width, int &height, bool depthStencil);\r
644         void applyScissor(int width, int height);\r
645     bool applyRenderTarget();\r
646     void applyState(GLenum drawMode);\r
647         GLenum applyVertexBuffer(GLint base, GLint first, GLsizei count, GLsizei instanceId);\r
648     GLenum applyIndexBuffer(const void *indices, GLuint start, GLuint end, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);\r
649     void applyShaders();\r
650     void applyTextures();\r
651     void applyTextures(sw::SamplerType type);\r
652         void applyTexture(sw::SamplerType type, int sampler, Texture *texture);\r
653 \r
654     void detachBuffer(GLuint buffer);\r
655     void detachTexture(GLuint texture);\r
656     void detachFramebuffer(GLuint framebuffer);\r
657     void detachRenderbuffer(GLuint renderbuffer);\r
658     void detachSampler(GLuint sampler);\r
659 \r
660     bool cullSkipsDraw(GLenum drawMode);\r
661     bool isTriangleMode(GLenum drawMode);\r
662 \r
663         Query *createQuery(GLuint handle, GLenum type);\r
664 \r
665         const EGLint clientVersion;\r
666     const egl::Config *const mConfig;\r
667 \r
668     State mState;\r
669 \r
670         gl::BindingPointer<Texture2D> mTexture2DZero;\r
671         gl::BindingPointer<Texture3D> mTexture3DZero;\r
672         gl::BindingPointer<Texture2DArray> mTexture2DArrayZero;\r
673         gl::BindingPointer<TextureCubeMap> mTextureCubeMapZero;\r
674     gl::BindingPointer<TextureExternal> mTextureExternalZero;\r
675 \r
676     typedef std::map<GLint, Framebuffer*> FramebufferMap;\r
677     FramebufferMap mFramebufferMap;\r
678     gl::NameSpace mFramebufferNameSpace;\r
679 \r
680     typedef std::map<GLint, Fence*> FenceMap;\r
681     FenceMap mFenceMap;\r
682     gl::NameSpace mFenceNameSpace;\r
683 \r
684         typedef std::map<GLint, Query*> QueryMap;\r
685     QueryMap mQueryMap;\r
686     gl::NameSpace mQueryNameSpace;\r
687 \r
688         typedef std::map<GLint, VertexArray*> VertexArrayMap;\r
689         VertexArrayMap mVertexArrayMap;\r
690         gl::NameSpace mVertexArrayNameSpace;\r
691 \r
692         typedef std::map<GLint, TransformFeedback*> TransformFeedbackMap;\r
693         TransformFeedbackMap mTransformFeedbackMap;\r
694         gl::NameSpace mTransformFeedbackNameSpace;\r
695 \r
696     VertexDataManager *mVertexDataManager;\r
697     IndexDataManager *mIndexDataManager;\r
698 \r
699     // Recorded errors\r
700     bool mInvalidEnum;\r
701     bool mInvalidValue;\r
702     bool mInvalidOperation;\r
703     bool mOutOfMemory;\r
704     bool mInvalidFramebufferOperation;\r
705 \r
706     bool mHasBeenCurrent;\r
707 \r
708     unsigned int mAppliedProgramSerial;\r
709     \r
710     // state caching flags\r
711     bool mDepthStateDirty;\r
712     bool mMaskStateDirty;\r
713     bool mPixelPackingStateDirty;\r
714     bool mBlendStateDirty;\r
715     bool mStencilStateDirty;\r
716     bool mPolygonOffsetStateDirty;\r
717     bool mSampleStateDirty;\r
718     bool mFrontFaceDirty;\r
719     bool mDitherStateDirty;\r
720 \r
721         Device *device;\r
722     ResourceManager *mResourceManager;\r
723 };\r
724 }\r
725 \r
726 #endif   // INCLUDE_CONTEXT_H_\r