OSDN Git Service

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