OSDN Git Service

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