1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 // Context.h: Defines the Context class, managing all GL state and performing
16 // rendering operations. It is the GLES2 specific implementation of EGLContext.
18 #ifndef LIBGLESV2_CONTEXT_H_
19 #define LIBGLESV2_CONTEXT_H_
21 #include "ResourceManager.h"
23 #include "libEGL/Context.hpp"
24 #include "common/NameSpace.hpp"
25 #include "common/Object.hpp"
26 #include "common/Image.hpp"
27 #include "Renderer/Sampler.hpp"
29 #include <GLES2/gl2.h>
30 #include <GLES2/gl2ext.h>
31 #include <GLES3/gl3.h>
46 struct TranslatedAttribute;
47 struct TranslatedIndexData;
57 class TextureExternal;
60 class RenderbufferStorage;
63 class StreamingIndexBuffer;
65 class DepthStencilbuffer;
66 class VertexDataManager;
67 class IndexDataManager;
73 class TransformFeedback;
77 MAX_VERTEX_ATTRIBS = sw::MAX_VERTEX_INPUTS,
78 MAX_UNIFORM_VECTORS = 256, // Device limit
79 MAX_VERTEX_UNIFORM_VECTORS = sw::VERTEX_UNIFORM_VECTORS - 3, // Reserve space for gl_DepthRange
80 MAX_VARYING_VECTORS = MIN(sw::MAX_FRAGMENT_INPUTS, sw::MAX_VERTEX_OUTPUTS),
81 MAX_TEXTURE_IMAGE_UNITS = sw::TEXTURE_IMAGE_UNITS,
82 MAX_VERTEX_TEXTURE_IMAGE_UNITS = sw::VERTEX_TEXTURE_IMAGE_UNITS,
83 MAX_COMBINED_TEXTURE_IMAGE_UNITS = MAX_TEXTURE_IMAGE_UNITS + MAX_VERTEX_TEXTURE_IMAGE_UNITS,
84 MAX_FRAGMENT_UNIFORM_VECTORS = sw::FRAGMENT_UNIFORM_VECTORS - 3, // Reserve space for gl_DepthRange
85 MAX_ELEMENT_INDEX = 0x7FFFFFFF,
86 MAX_ELEMENTS_INDICES = 0x7FFFFFFF,
87 MAX_ELEMENTS_VERTICES = 0x7FFFFFFF,
88 MAX_VERTEX_OUTPUT_VECTORS = 16,
89 MAX_FRAGMENT_INPUT_VECTORS = 15,
90 MIN_PROGRAM_TEXEL_OFFSET = sw::MIN_PROGRAM_TEXEL_OFFSET,
91 MAX_PROGRAM_TEXEL_OFFSET = sw::MAX_PROGRAM_TEXEL_OFFSET,
92 MAX_DRAW_BUFFERS = sw::RENDERTARGETS,
93 MAX_COLOR_ATTACHMENTS = MAX(MAX_DRAW_BUFFERS, 8),
94 MAX_FRAGMENT_UNIFORM_BLOCKS = sw::MAX_FRAGMENT_UNIFORM_BLOCKS,
95 MAX_VERTEX_UNIFORM_BLOCKS = sw::MAX_VERTEX_UNIFORM_BLOCKS,
96 MAX_FRAGMENT_UNIFORM_COMPONENTS = sw::FRAGMENT_UNIFORM_VECTORS * 4,
97 MAX_VERTEX_UNIFORM_COMPONENTS = sw::VERTEX_UNIFORM_VECTORS * 4,
98 MAX_UNIFORM_BLOCK_SIZE = sw::MAX_UNIFORM_BLOCK_SIZE,
99 MAX_FRAGMENT_UNIFORM_BLOCKS_COMPONENTS = sw::MAX_FRAGMENT_UNIFORM_BLOCKS * MAX_UNIFORM_BLOCK_SIZE / 4,
100 MAX_VERTEX_UNIFORM_BLOCKS_COMPONENTS = MAX_VERTEX_UNIFORM_BLOCKS * MAX_UNIFORM_BLOCK_SIZE / 4,
101 MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS = MAX_FRAGMENT_UNIFORM_BLOCKS_COMPONENTS + MAX_FRAGMENT_UNIFORM_COMPONENTS,
102 MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS = MAX_VERTEX_UNIFORM_BLOCKS_COMPONENTS + MAX_VERTEX_UNIFORM_COMPONENTS,
103 MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = 4,
104 MAX_UNIFORM_BUFFER_BINDINGS = sw::MAX_UNIFORM_BUFFER_BINDINGS,
105 UNIFORM_BUFFER_OFFSET_ALIGNMENT = 1,
106 NUM_PROGRAM_BINARY_FORMATS = 0,
109 const GLenum compressedTextureFormats[] =
113 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
114 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
115 GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE,
116 GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE,
118 #if (GL_ES_VERSION_3_0)
119 GL_COMPRESSED_R11_EAC,
120 GL_COMPRESSED_SIGNED_R11_EAC,
121 GL_COMPRESSED_RG11_EAC,
122 GL_COMPRESSED_SIGNED_RG11_EAC,
123 GL_COMPRESSED_RGB8_ETC2,
124 GL_COMPRESSED_SRGB8_ETC2,
125 GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
126 GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
127 GL_COMPRESSED_RGBA8_ETC2_EAC,
128 GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
129 GL_COMPRESSED_RGBA_ASTC_4x4_KHR,
130 GL_COMPRESSED_RGBA_ASTC_5x4_KHR,
131 GL_COMPRESSED_RGBA_ASTC_5x5_KHR,
132 GL_COMPRESSED_RGBA_ASTC_6x5_KHR,
133 GL_COMPRESSED_RGBA_ASTC_6x6_KHR,
134 GL_COMPRESSED_RGBA_ASTC_8x5_KHR,
135 GL_COMPRESSED_RGBA_ASTC_8x6_KHR,
136 GL_COMPRESSED_RGBA_ASTC_8x8_KHR,
137 GL_COMPRESSED_RGBA_ASTC_10x5_KHR,
138 GL_COMPRESSED_RGBA_ASTC_10x6_KHR,
139 GL_COMPRESSED_RGBA_ASTC_10x8_KHR,
140 GL_COMPRESSED_RGBA_ASTC_10x10_KHR,
141 GL_COMPRESSED_RGBA_ASTC_12x10_KHR,
142 GL_COMPRESSED_RGBA_ASTC_12x12_KHR,
143 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
144 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
145 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
146 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
147 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
148 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
149 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
150 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
151 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
152 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
153 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
154 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
155 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
156 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
160 const GLint NUM_COMPRESSED_TEXTURE_FORMATS = sizeof(compressedTextureFormats) / sizeof(compressedTextureFormats[0]);
162 const GLint multisampleCount[] = {4, 2, 1};
163 const GLint NUM_MULTISAMPLE_COUNTS = sizeof(multisampleCount) / sizeof(multisampleCount[0]);
164 const GLint IMPLEMENTATION_MAX_SAMPLES = multisampleCount[0];
166 const float ALIASED_LINE_WIDTH_RANGE_MIN = 1.0f;
167 const float ALIASED_LINE_WIDTH_RANGE_MAX = 1.0f;
168 const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f;
169 const float ALIASED_POINT_SIZE_RANGE_MAX = 8192.0f;
170 const float MAX_TEXTURE_MAX_ANISOTROPY = 16.0f;
174 QUERY_ANY_SAMPLES_PASSED,
175 QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE,
176 QUERY_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN,
189 // Helper structure describing a single vertex attribute
190 class VertexAttribute
193 VertexAttribute() : mType(GL_FLOAT), mSize(0), mNormalized(false), mStride(0), mDivisor(0), mPointer(nullptr), mArrayEnabled(false)
195 mCurrentValue[0].f = 0.0f;
196 mCurrentValue[1].f = 0.0f;
197 mCurrentValue[2].f = 0.0f;
198 mCurrentValue[3].f = 1.0f;
199 mCurrentValueType = GL_FLOAT;
206 case GL_BYTE: return mSize * sizeof(GLbyte);
207 case GL_UNSIGNED_BYTE: return mSize * sizeof(GLubyte);
208 case GL_SHORT: return mSize * sizeof(GLshort);
209 case GL_UNSIGNED_SHORT: return mSize * sizeof(GLushort);
210 case GL_INT: return mSize * sizeof(GLint);
211 case GL_UNSIGNED_INT: return mSize * sizeof(GLuint);
212 case GL_FIXED: return mSize * sizeof(GLfixed);
213 case GL_FLOAT: return mSize * sizeof(GLfloat);
214 case GL_HALF_FLOAT: return mSize * sizeof(GLhalf);
215 case GL_INT_2_10_10_10_REV: return sizeof(GLint);
216 case GL_UNSIGNED_INT_2_10_10_10_REV: return sizeof(GLuint);
217 default: UNREACHABLE(mType); return mSize * sizeof(GLfloat);
221 GLenum currentValueType() const
223 return mCurrentValueType;
226 GLsizei stride() const
228 return mStride ? mStride : typeSize();
231 inline float getCurrentValueBitsAsFloat(int i) const
233 return mCurrentValue[i].f;
236 inline float getCurrentValueF(int i) const
238 switch(mCurrentValueType)
240 case GL_FLOAT: return mCurrentValue[i].f;
241 case GL_INT: return static_cast<float>(mCurrentValue[i].i);
242 case GL_UNSIGNED_INT: return static_cast<float>(mCurrentValue[i].ui);
243 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].f;
247 inline GLint getCurrentValueI(int i) const
249 switch(mCurrentValueType)
251 case GL_FLOAT: return static_cast<GLint>(mCurrentValue[i].f);
252 case GL_INT: return mCurrentValue[i].i;
253 case GL_UNSIGNED_INT: return static_cast<GLint>(mCurrentValue[i].ui);
254 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].i;
258 inline GLuint getCurrentValueUI(int i) const
260 switch(mCurrentValueType)
262 case GL_FLOAT: return static_cast<GLuint>(mCurrentValue[i].f);
263 case GL_INT: return static_cast<GLuint>(mCurrentValue[i].i);
264 case GL_UNSIGNED_INT: return mCurrentValue[i].ui;
265 default: UNREACHABLE(mCurrentValueType); return mCurrentValue[i].ui;
269 inline void setCurrentValue(const GLfloat *values)
271 mCurrentValue[0].f = values[0];
272 mCurrentValue[1].f = values[1];
273 mCurrentValue[2].f = values[2];
274 mCurrentValue[3].f = values[3];
275 mCurrentValueType = GL_FLOAT;
278 inline void setCurrentValue(const GLint *values)
280 mCurrentValue[0].i = values[0];
281 mCurrentValue[1].i = values[1];
282 mCurrentValue[2].i = values[2];
283 mCurrentValue[3].i = values[3];
284 mCurrentValueType = GL_INT;
287 inline void setCurrentValue(const GLuint *values)
289 mCurrentValue[0].ui = values[0];
290 mCurrentValue[1].ui = values[1];
291 mCurrentValue[2].ui = values[2];
292 mCurrentValue[3].ui = values[3];
293 mCurrentValueType = GL_UNSIGNED_INT;
296 // From glVertexAttribPointer
300 GLsizei mStride; // 0 means natural stride
301 GLuint mDivisor; // From glVertexAttribDivisor
305 const void *mPointer;
309 gl::BindingPointer<Buffer> mBoundBuffer; // Captured when glVertexAttribPointer is called.
311 bool mArrayEnabled; // From glEnable/DisableVertexAttribArray
321 ValueUnion mCurrentValue[4]; // From glVertexAttrib
322 GLenum mCurrentValueType;
325 typedef VertexAttribute VertexAttributeArray[MAX_VERTEX_ATTRIBS];
327 // Helper structure to store all raw state
330 Color colorClearValue;
331 GLclampf depthClearValue;
332 int stencilClearValue;
334 bool cullFaceEnabled;
337 bool depthTestEnabled;
340 GLenum sourceBlendRGB;
342 GLenum sourceBlendAlpha;
343 GLenum destBlendAlpha;
344 GLenum blendEquationRGB;
345 GLenum blendEquationAlpha;
347 bool stencilTestEnabled;
352 GLenum stencilPassDepthFail;
353 GLenum stencilPassDepthPass;
354 GLuint stencilWritemask;
355 GLenum stencilBackFunc;
356 GLint stencilBackRef;
357 GLuint stencilBackMask;
358 GLenum stencilBackFail;
359 GLenum stencilBackPassDepthFail;
360 GLenum stencilBackPassDepthPass;
361 GLuint stencilBackWritemask;
362 bool polygonOffsetFillEnabled;
363 GLfloat polygonOffsetFactor;
364 GLfloat polygonOffsetUnits;
365 bool sampleAlphaToCoverageEnabled;
366 bool sampleCoverageEnabled;
367 GLclampf sampleCoverageValue;
368 bool sampleCoverageInvert;
369 bool scissorTestEnabled;
371 bool primitiveRestartFixedIndexEnabled;
372 bool rasterizerDiscardEnabled;
373 bool colorLogicOpEnabled;
374 GLenum logicalOperation;
378 GLenum generateMipmapHint;
379 GLenum fragmentShaderDerivativeHint;
383 GLsizei viewportWidth;
384 GLsizei viewportHeight;
390 GLsizei scissorWidth;
391 GLsizei scissorHeight;
399 unsigned int activeSampler; // Active texture unit selector - GL_TEXTURE0
400 gl::BindingPointer<Buffer> arrayBuffer;
401 gl::BindingPointer<Buffer> copyReadBuffer;
402 gl::BindingPointer<Buffer> copyWriteBuffer;
403 gl::BindingPointer<Buffer> pixelPackBuffer;
404 gl::BindingPointer<Buffer> pixelUnpackBuffer;
405 gl::BindingPointer<Buffer> genericUniformBuffer;
406 BufferBinding uniformBuffers[MAX_UNIFORM_BUFFER_BINDINGS];
408 GLuint readFramebuffer;
409 GLuint drawFramebuffer;
410 gl::BindingPointer<Renderbuffer> renderbuffer;
411 GLuint currentProgram;
413 GLuint transformFeedback;
414 gl::BindingPointer<Sampler> sampler[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
416 VertexAttribute vertexAttribute[MAX_VERTEX_ATTRIBS];
417 gl::BindingPointer<Texture> samplerTexture[TEXTURE_TYPE_COUNT][MAX_COMBINED_TEXTURE_IMAGE_UNITS];
418 gl::BindingPointer<Query> activeQuery[QUERY_TYPE_COUNT];
420 egl::Image::UnpackInfo unpackInfo;
423 GLint packImageHeight;
424 GLint packSkipPixels;
426 GLint packSkipImages;
429 class Context : public egl::Context
432 Context(egl::Display *display, const Context *shareContext, EGLint clientVersion);
434 virtual void makeCurrent(egl::Surface *surface);
435 virtual EGLint getClientVersion() const;
437 void markAllStateDirty();
439 // State manipulation
440 void setClearColor(float red, float green, float blue, float alpha);
441 void setClearDepth(float depth);
442 void setClearStencil(int stencil);
444 void setCullFaceEnabled(bool enabled);
445 bool isCullFaceEnabled() const;
446 void setCullMode(GLenum mode);
447 void setFrontFace(GLenum front);
449 void setDepthTestEnabled(bool enabled);
450 bool isDepthTestEnabled() const;
451 void setDepthFunc(GLenum depthFunc);
452 void setDepthRange(float zNear, float zFar);
454 void setBlendEnabled(bool enabled);
455 bool isBlendEnabled() const;
456 void setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha);
457 void setBlendColor(float red, float green, float blue, float alpha);
458 void setBlendEquation(GLenum rgbEquation, GLenum alphaEquation);
460 void setStencilTestEnabled(bool enabled);
461 bool isStencilTestEnabled() const;
462 void setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask);
463 void setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask);
464 void setStencilWritemask(GLuint stencilWritemask);
465 void setStencilBackWritemask(GLuint stencilBackWritemask);
466 void setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass);
467 void setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass);
469 void setPolygonOffsetFillEnabled(bool enabled);
470 bool isPolygonOffsetFillEnabled() const;
471 void setPolygonOffsetParams(GLfloat factor, GLfloat units);
473 void setSampleAlphaToCoverageEnabled(bool enabled);
474 bool isSampleAlphaToCoverageEnabled() const;
475 void setSampleCoverageEnabled(bool enabled);
476 bool isSampleCoverageEnabled() const;
477 void setSampleCoverageParams(GLclampf value, bool invert);
479 void setDitherEnabled(bool enabled);
480 bool isDitherEnabled() const;
482 void setPrimitiveRestartFixedIndexEnabled(bool enabled);
483 bool isPrimitiveRestartFixedIndexEnabled() const;
485 void setRasterizerDiscardEnabled(bool enabled);
486 bool isRasterizerDiscardEnabled() const;
488 void setLineWidth(GLfloat width);
490 void setGenerateMipmapHint(GLenum hint);
491 void setFragmentShaderDerivativeHint(GLenum hint);
493 void setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height);
495 void setScissorTestEnabled(bool enabled);
496 bool isScissorTestEnabled() const;
497 void setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height);
499 void setColorMask(bool red, bool green, bool blue, bool alpha);
500 unsigned int getColorMask() const;
501 void setDepthMask(bool mask);
503 void setActiveSampler(unsigned int active);
505 GLuint getReadFramebufferName() const;
506 GLuint getDrawFramebufferName() const;
507 GLuint getRenderbufferName() const;
509 void setFramebufferReadBuffer(GLenum buf);
510 void setFramebufferDrawBuffers(GLsizei n, const GLenum *bufs);
511 GLuint getReadFramebufferColorIndex() const;
513 GLuint getActiveQuery(GLenum target) const;
515 GLuint getArrayBufferName() const;
516 GLuint getElementArrayBufferName() const;
518 void setVertexAttribArrayEnabled(unsigned int attribNum, bool enabled);
519 void setVertexAttribDivisor(unsigned int attribNum, GLuint divisor);
520 const VertexAttribute &getVertexAttribState(unsigned int attribNum) const;
521 void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type,
522 bool normalized, GLsizei stride, const void *pointer);
523 const void *getVertexAttribPointer(unsigned int attribNum) const;
525 const VertexAttributeArray &getVertexArrayAttributes();
526 // Context attribute current values can be queried independently from VAO current values
527 const VertexAttributeArray &getCurrentVertexAttributes();
529 void setUnpackAlignment(GLint alignment);
530 void setUnpackRowLength(GLint rowLength);
531 void setUnpackImageHeight(GLint imageHeight);
532 void setUnpackSkipPixels(GLint skipPixels);
533 void setUnpackSkipRows(GLint skipRows);
534 void setUnpackSkipImages(GLint skipImages);
535 const egl::Image::UnpackInfo& getUnpackInfo() const;
537 void setPackAlignment(GLint alignment);
538 void setPackRowLength(GLint rowLength);
539 void setPackImageHeight(GLint imageHeight);
540 void setPackSkipPixels(GLint skipPixels);
541 void setPackSkipRows(GLint skipRows);
542 void setPackSkipImages(GLint skipImages);
544 // These create and destroy methods are merely pass-throughs to
545 // ResourceManager, which owns these object types
546 GLuint createBuffer();
547 GLuint createShader(GLenum type);
548 GLuint createProgram();
549 GLuint createTexture();
550 GLuint createRenderbuffer();
551 GLuint createSampler();
552 GLsync createFenceSync(GLenum condition, GLbitfield flags);
554 void deleteBuffer(GLuint buffer);
555 void deleteShader(GLuint shader);
556 void deleteProgram(GLuint program);
557 void deleteTexture(GLuint texture);
558 void deleteRenderbuffer(GLuint renderbuffer);
559 void deleteSampler(GLuint sampler);
560 void deleteFenceSync(GLsync fenceSync);
562 // Framebuffers are owned by the Context, so these methods do not pass through
563 GLuint createFramebuffer();
564 void deleteFramebuffer(GLuint framebuffer);
566 // Fences are owned by the Context
567 GLuint createFence();
568 void deleteFence(GLuint fence);
570 // Queries are owned by the Context
571 GLuint createQuery();
572 void deleteQuery(GLuint query);
574 // Vertex arrays are owned by the Context
575 GLuint createVertexArray();
576 void deleteVertexArray(GLuint array);
578 // Transform feedbacks are owned by the Context
579 GLuint createTransformFeedback();
580 void deleteTransformFeedback(GLuint transformFeedback);
582 void bindArrayBuffer(GLuint buffer);
583 void bindElementArrayBuffer(GLuint buffer);
584 void bindCopyReadBuffer(GLuint buffer);
585 void bindCopyWriteBuffer(GLuint buffer);
586 void bindPixelPackBuffer(GLuint buffer);
587 void bindPixelUnpackBuffer(GLuint buffer);
588 void bindTransformFeedbackBuffer(GLuint buffer);
589 void bindTexture2D(GLuint texture);
590 void bindTextureCubeMap(GLuint texture);
591 void bindTextureExternal(GLuint texture);
592 void bindTexture3D(GLuint texture);
593 void bindTexture2DArray(GLuint texture);
594 void bindReadFramebuffer(GLuint framebuffer);
595 void bindDrawFramebuffer(GLuint framebuffer);
596 void bindRenderbuffer(GLuint renderbuffer);
597 void bindVertexArray(GLuint array);
598 void bindGenericUniformBuffer(GLuint buffer);
599 void bindIndexedUniformBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);
600 void bindGenericTransformFeedbackBuffer(GLuint buffer);
601 void bindIndexedTransformFeedbackBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size);
602 void bindTransformFeedback(GLuint transformFeedback);
603 bool bindSampler(GLuint unit, GLuint sampler);
604 void useProgram(GLuint program);
606 void beginQuery(GLenum target, GLuint query);
607 void endQuery(GLenum target);
609 void setFramebufferZero(Framebuffer *framebuffer);
611 void setRenderbufferStorage(RenderbufferStorage *renderbuffer);
613 void setVertexAttrib(GLuint index, const GLfloat *values);
614 void setVertexAttrib(GLuint index, const GLint *values);
615 void setVertexAttrib(GLuint index, const GLuint *values);
617 Buffer *getBuffer(GLuint handle) const;
618 Fence *getFence(GLuint handle) const;
619 FenceSync *getFenceSync(GLsync handle) const;
620 Shader *getShader(GLuint handle) const;
621 Program *getProgram(GLuint handle) const;
622 virtual Texture *getTexture(GLuint handle) const;
623 Framebuffer *getFramebuffer(GLuint handle) const;
624 virtual Renderbuffer *getRenderbuffer(GLuint handle) const;
625 Query *getQuery(GLuint handle) const;
626 VertexArray *getVertexArray(GLuint array) const;
627 VertexArray *getCurrentVertexArray() const;
628 bool isVertexArray(GLuint array) const;
629 TransformFeedback *getTransformFeedback(GLuint transformFeedback) const;
630 TransformFeedback *getTransformFeedback() const;
631 Sampler *getSampler(GLuint sampler) const;
632 bool isSampler(GLuint sampler) const;
634 Buffer *getArrayBuffer() const;
635 Buffer *getElementArrayBuffer() const;
636 Buffer *getCopyReadBuffer() const;
637 Buffer *getCopyWriteBuffer() const;
638 Buffer *getPixelPackBuffer() const;
639 Buffer *getPixelUnpackBuffer() const;
640 Buffer *getGenericUniformBuffer() const;
641 const GLvoid* getPixels(const GLvoid* data) const;
642 bool getBuffer(GLenum target, es2::Buffer **buffer) const;
643 Program *getCurrentProgram() const;
644 Texture2D *getTexture2D() const;
645 Texture3D *getTexture3D() const;
646 Texture2DArray *getTexture2DArray() const;
647 TextureCubeMap *getTextureCubeMap() const;
648 TextureExternal *getTextureExternal() const;
649 Texture *getSamplerTexture(unsigned int sampler, TextureType type) const;
650 Framebuffer *getReadFramebuffer() const;
651 Framebuffer *getDrawFramebuffer() const;
653 bool getFloatv(GLenum pname, GLfloat *params) const;
654 template<typename T> bool getIntegerv(GLenum pname, T *params) const;
655 bool getBooleanv(GLenum pname, GLboolean *params) const;
656 template<typename T> bool getTransformFeedbackiv(GLuint index, GLenum pname, T *param) const;
657 template<typename T> bool getUniformBufferiv(GLuint index, GLenum pname, T *param) const;
658 void samplerParameteri(GLuint sampler, GLenum pname, GLint param);
659 void samplerParameterf(GLuint sampler, GLenum pname, GLfloat param);
660 GLint getSamplerParameteri(GLuint sampler, GLenum pname);
661 GLfloat getSamplerParameterf(GLuint sampler, GLenum pname);
663 bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams) const;
665 bool hasZeroDivisor() const;
667 void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels);
668 void clear(GLbitfield mask);
669 void clearColorBuffer(GLint drawbuffer, const GLint *value);
670 void clearColorBuffer(GLint drawbuffer, const GLuint *value);
671 void clearColorBuffer(GLint drawbuffer, const GLfloat *value);
672 void clearDepthBuffer(const GLfloat value);
673 void clearStencilBuffer(const GLint value);
674 void drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount = 1);
675 void drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLsizei instanceCount = 1);
679 void recordInvalidEnum();
680 void recordInvalidValue();
681 void recordInvalidOperation();
682 void recordOutOfMemory();
683 void recordInvalidFramebufferOperation();
687 static int getSupportedMultisampleCount(int requested);
689 void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
690 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
691 GLbitfield mask, bool filter, bool allowPartialDepthStencilBlit);
693 virtual void bindTexImage(egl::Surface *surface);
694 virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel);
695 virtual egl::Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel);
696 egl::Image *getSharedImage(GLeglImageOES image);
700 const GLubyte *getExtensions(GLuint index, GLuint *numExt = nullptr) const;
705 void applyScissor(int width, int height);
706 bool applyRenderTarget();
707 void applyState(GLenum drawMode);
708 GLenum applyVertexBuffer(GLint base, GLint first, GLsizei count, GLsizei instanceId);
709 GLenum applyIndexBuffer(const void *indices, GLuint start, GLuint end, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
711 void applyTextures();
712 void applyTextures(sw::SamplerType type);
713 void applyTexture(sw::SamplerType type, int sampler, Texture *texture);
714 void clearColorBuffer(GLint drawbuffer, void *value, sw::Format format);
716 void detachBuffer(GLuint buffer);
717 void detachTexture(GLuint texture);
718 void detachFramebuffer(GLuint framebuffer);
719 void detachRenderbuffer(GLuint renderbuffer);
720 void detachSampler(GLuint sampler);
722 bool cullSkipsDraw(GLenum drawMode);
723 bool isTriangleMode(GLenum drawMode);
725 Query *createQuery(GLuint handle, GLenum type);
727 const EGLint clientVersion;
731 gl::BindingPointer<Texture2D> mTexture2DZero;
732 gl::BindingPointer<Texture3D> mTexture3DZero;
733 gl::BindingPointer<Texture2DArray> mTexture2DArrayZero;
734 gl::BindingPointer<TextureCubeMap> mTextureCubeMapZero;
735 gl::BindingPointer<TextureExternal> mTextureExternalZero;
737 gl::NameSpace<Framebuffer> mFramebufferNameSpace;
738 gl::NameSpace<Fence, 0> mFenceNameSpace;
739 gl::NameSpace<Query> mQueryNameSpace;
740 gl::NameSpace<VertexArray> mVertexArrayNameSpace;
741 gl::NameSpace<TransformFeedback> mTransformFeedbackNameSpace;
743 VertexDataManager *mVertexDataManager;
744 IndexDataManager *mIndexDataManager;
749 bool mInvalidOperation;
751 bool mInvalidFramebufferOperation;
753 bool mHasBeenCurrent;
755 unsigned int mAppliedProgramSerial;
757 // state caching flags
758 bool mDepthStateDirty;
759 bool mMaskStateDirty;
760 bool mBlendStateDirty;
761 bool mStencilStateDirty;
762 bool mPolygonOffsetStateDirty;
763 bool mSampleStateDirty;
764 bool mFrontFaceDirty;
765 bool mDitherStateDirty;
768 ResourceManager *mResourceManager;
772 #endif // INCLUDE_CONTEXT_H_