OSDN Git Service

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