OSDN Git Service

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