OSDN Git Service

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