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.cpp: Implements the es2::Context class, managing all GL state and performing
16 // rendering operations. It is the GLES2 specific implementation of EGLContext.
22 #include "utilities.h"
23 #include "ResourceManager.h"
26 #include "Framebuffer.h"
29 #include "Renderbuffer.h"
33 #include "TransformFeedback.h"
34 #include "VertexArray.h"
35 #include "VertexDataManager.h"
36 #include "IndexDataManager.h"
37 #include "libEGL/Display.h"
38 #include "common/Surface.hpp"
39 #include "Common/Half.hpp"
41 #include <EGL/eglext.h>
48 Context::Context(egl::Display *display, const Context *shareContext, EGLint clientVersion, const egl::Config *config)
49 : egl::Context(display), clientVersion(clientVersion), config(config)
51 sw::Context *context = new sw::Context();
52 device = new es2::Device(context);
54 setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
56 mState.depthClearValue = 1.0f;
57 mState.stencilClearValue = 0;
59 mState.cullFaceEnabled = false;
60 mState.cullMode = GL_BACK;
61 mState.frontFace = GL_CCW;
62 mState.depthTestEnabled = false;
63 mState.depthFunc = GL_LESS;
64 mState.blendEnabled = false;
65 mState.sourceBlendRGB = GL_ONE;
66 mState.sourceBlendAlpha = GL_ONE;
67 mState.destBlendRGB = GL_ZERO;
68 mState.destBlendAlpha = GL_ZERO;
69 mState.blendEquationRGB = GL_FUNC_ADD;
70 mState.blendEquationAlpha = GL_FUNC_ADD;
71 mState.blendColor.red = 0;
72 mState.blendColor.green = 0;
73 mState.blendColor.blue = 0;
74 mState.blendColor.alpha = 0;
75 mState.stencilTestEnabled = false;
76 mState.stencilFunc = GL_ALWAYS;
77 mState.stencilRef = 0;
78 mState.stencilMask = 0xFFFFFFFFu;
79 mState.stencilWritemask = 0xFFFFFFFFu;
80 mState.stencilBackFunc = GL_ALWAYS;
81 mState.stencilBackRef = 0;
82 mState.stencilBackMask = 0xFFFFFFFFu;
83 mState.stencilBackWritemask = 0xFFFFFFFFu;
84 mState.stencilFail = GL_KEEP;
85 mState.stencilPassDepthFail = GL_KEEP;
86 mState.stencilPassDepthPass = GL_KEEP;
87 mState.stencilBackFail = GL_KEEP;
88 mState.stencilBackPassDepthFail = GL_KEEP;
89 mState.stencilBackPassDepthPass = GL_KEEP;
90 mState.polygonOffsetFillEnabled = false;
91 mState.polygonOffsetFactor = 0.0f;
92 mState.polygonOffsetUnits = 0.0f;
93 mState.sampleAlphaToCoverageEnabled = false;
94 mState.sampleCoverageEnabled = false;
95 mState.sampleCoverageValue = 1.0f;
96 mState.sampleCoverageInvert = false;
97 mState.scissorTestEnabled = false;
98 mState.ditherEnabled = true;
99 mState.primitiveRestartFixedIndexEnabled = false;
100 mState.rasterizerDiscardEnabled = false;
101 mState.generateMipmapHint = GL_DONT_CARE;
102 mState.fragmentShaderDerivativeHint = GL_DONT_CARE;
103 mState.textureFilteringHint = GL_DONT_CARE;
105 mState.lineWidth = 1.0f;
107 mState.viewportX = 0;
108 mState.viewportY = 0;
109 mState.viewportWidth = 0;
110 mState.viewportHeight = 0;
116 mState.scissorWidth = 0;
117 mState.scissorHeight = 0;
119 mState.colorMaskRed = true;
120 mState.colorMaskGreen = true;
121 mState.colorMaskBlue = true;
122 mState.colorMaskAlpha = true;
123 mState.depthMask = true;
127 mResourceManager = shareContext->mResourceManager;
128 mResourceManager->addRef();
132 mResourceManager = new ResourceManager();
135 // [OpenGL ES 2.0.24] section 3.7 page 83:
136 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional
137 // and cube map texture state vectors respectively associated with them.
138 // In order that access to these initial textures not be lost, they are treated as texture
139 // objects all of whose names are 0.
141 mTexture2DZero = new Texture2D(0);
142 mTexture3DZero = new Texture3D(0);
143 mTexture2DArrayZero = new Texture2DArray(0);
144 mTextureCubeMapZero = new TextureCubeMap(0);
145 mTextureExternalZero = new TextureExternal(0);
147 mState.activeSampler = 0;
150 bindElementArrayBuffer(0);
151 bindTextureCubeMap(0);
153 bindReadFramebuffer(0);
154 bindDrawFramebuffer(0);
156 bindGenericUniformBuffer(0);
157 bindTransformFeedback(0);
159 mState.currentProgram = 0;
161 mState.packAlignment = 4;
162 mState.unpackInfo.alignment = 4;
163 mState.packRowLength = 0;
164 mState.packImageHeight = 0;
165 mState.packSkipPixels = 0;
166 mState.packSkipRows = 0;
167 mState.packSkipImages = 0;
168 mState.unpackInfo.rowLength = 0;
169 mState.unpackInfo.imageHeight = 0;
170 mState.unpackInfo.skipPixels = 0;
171 mState.unpackInfo.skipRows = 0;
172 mState.unpackInfo.skipImages = 0;
174 mVertexDataManager = nullptr;
175 mIndexDataManager = nullptr;
177 mInvalidEnum = false;
178 mInvalidValue = false;
179 mInvalidOperation = false;
180 mOutOfMemory = false;
181 mInvalidFramebufferOperation = false;
183 mHasBeenCurrent = false;
190 if(mState.currentProgram != 0)
192 Program *programObject = mResourceManager->getProgram(mState.currentProgram);
195 programObject->release();
197 mState.currentProgram = 0;
200 while(!mFramebufferNameSpace.empty())
202 deleteFramebuffer(mFramebufferNameSpace.firstName());
205 while(!mFenceNameSpace.empty())
207 deleteFence(mFenceNameSpace.firstName());
210 while(!mQueryNameSpace.empty())
212 deleteQuery(mQueryNameSpace.firstName());
215 while(!mVertexArrayNameSpace.empty())
217 deleteVertexArray(mVertexArrayNameSpace.lastName());
220 while(!mTransformFeedbackNameSpace.empty())
222 deleteTransformFeedback(mTransformFeedbackNameSpace.firstName());
225 for(int type = 0; type < TEXTURE_TYPE_COUNT; type++)
227 for(int sampler = 0; sampler < MAX_COMBINED_TEXTURE_IMAGE_UNITS; sampler++)
229 mState.samplerTexture[type][sampler] = nullptr;
233 for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
235 mState.vertexAttribute[i].mBoundBuffer = nullptr;
238 for(int i = 0; i < QUERY_TYPE_COUNT; i++)
240 mState.activeQuery[i] = nullptr;
243 mState.arrayBuffer = nullptr;
244 mState.copyReadBuffer = nullptr;
245 mState.copyWriteBuffer = nullptr;
246 mState.pixelPackBuffer = nullptr;
247 mState.pixelUnpackBuffer = nullptr;
248 mState.genericUniformBuffer = nullptr;
250 for(int i = 0; i < MAX_UNIFORM_BUFFER_BINDINGS; i++) {
251 mState.uniformBuffers[i].set(nullptr, 0, 0);
254 mState.renderbuffer = nullptr;
256 for(int i = 0; i < MAX_COMBINED_TEXTURE_IMAGE_UNITS; ++i)
258 mState.sampler[i] = nullptr;
261 mTexture2DZero = nullptr;
262 mTexture3DZero = nullptr;
263 mTexture2DArrayZero = nullptr;
264 mTextureCubeMapZero = nullptr;
265 mTextureExternalZero = nullptr;
267 delete mVertexDataManager;
268 delete mIndexDataManager;
270 mResourceManager->release();
274 void Context::makeCurrent(gl::Surface *surface)
278 mVertexDataManager = new VertexDataManager(this);
279 mIndexDataManager = new IndexDataManager();
281 mState.viewportX = 0;
282 mState.viewportY = 0;
283 mState.viewportWidth = surface ? surface->getWidth() : 0;
284 mState.viewportHeight = surface ? surface->getHeight() : 0;
288 mState.scissorWidth = surface ? surface->getWidth() : 0;
289 mState.scissorHeight = surface ? surface->getHeight() : 0;
291 mHasBeenCurrent = true;
296 // Wrap the existing resources into GL objects and assign them to the '0' names
297 egl::Image *defaultRenderTarget = surface->getRenderTarget();
298 egl::Image *depthStencil = surface->getDepthStencil();
300 Colorbuffer *colorbufferZero = new Colorbuffer(defaultRenderTarget);
301 DepthStencilbuffer *depthStencilbufferZero = new DepthStencilbuffer(depthStencil);
302 Framebuffer *framebufferZero = new DefaultFramebuffer(colorbufferZero, depthStencilbufferZero);
304 setFramebufferZero(framebufferZero);
306 if(defaultRenderTarget)
308 defaultRenderTarget->release();
313 depthStencil->release();
318 setFramebufferZero(nullptr);
324 EGLint Context::getClientVersion() const
326 return clientVersion;
329 EGLint Context::getConfigID() const
331 return config->mConfigID;
334 // This function will set all of the state-related dirty flags, so that all state is set during next pre-draw.
335 void Context::markAllStateDirty()
337 mAppliedProgramSerial = 0;
339 mDepthStateDirty = true;
340 mMaskStateDirty = true;
341 mBlendStateDirty = true;
342 mStencilStateDirty = true;
343 mPolygonOffsetStateDirty = true;
344 mSampleStateDirty = true;
345 mDitherStateDirty = true;
346 mFrontFaceDirty = true;
349 void Context::setClearColor(float red, float green, float blue, float alpha)
351 mState.colorClearValue.red = red;
352 mState.colorClearValue.green = green;
353 mState.colorClearValue.blue = blue;
354 mState.colorClearValue.alpha = alpha;
357 void Context::setClearDepth(float depth)
359 mState.depthClearValue = depth;
362 void Context::setClearStencil(int stencil)
364 mState.stencilClearValue = stencil;
367 void Context::setCullFaceEnabled(bool enabled)
369 mState.cullFaceEnabled = enabled;
372 bool Context::isCullFaceEnabled() const
374 return mState.cullFaceEnabled;
377 void Context::setCullMode(GLenum mode)
379 mState.cullMode = mode;
382 void Context::setFrontFace(GLenum front)
384 if(mState.frontFace != front)
386 mState.frontFace = front;
387 mFrontFaceDirty = true;
391 void Context::setDepthTestEnabled(bool enabled)
393 if(mState.depthTestEnabled != enabled)
395 mState.depthTestEnabled = enabled;
396 mDepthStateDirty = true;
400 bool Context::isDepthTestEnabled() const
402 return mState.depthTestEnabled;
405 void Context::setDepthFunc(GLenum depthFunc)
407 if(mState.depthFunc != depthFunc)
409 mState.depthFunc = depthFunc;
410 mDepthStateDirty = true;
414 void Context::setDepthRange(float zNear, float zFar)
416 mState.zNear = zNear;
420 void Context::setBlendEnabled(bool enabled)
422 if(mState.blendEnabled != enabled)
424 mState.blendEnabled = enabled;
425 mBlendStateDirty = true;
429 bool Context::isBlendEnabled() const
431 return mState.blendEnabled;
434 void Context::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha)
436 if(mState.sourceBlendRGB != sourceRGB ||
437 mState.sourceBlendAlpha != sourceAlpha ||
438 mState.destBlendRGB != destRGB ||
439 mState.destBlendAlpha != destAlpha)
441 mState.sourceBlendRGB = sourceRGB;
442 mState.destBlendRGB = destRGB;
443 mState.sourceBlendAlpha = sourceAlpha;
444 mState.destBlendAlpha = destAlpha;
445 mBlendStateDirty = true;
449 void Context::setBlendColor(float red, float green, float blue, float alpha)
451 if(mState.blendColor.red != red ||
452 mState.blendColor.green != green ||
453 mState.blendColor.blue != blue ||
454 mState.blendColor.alpha != alpha)
456 mState.blendColor.red = red;
457 mState.blendColor.green = green;
458 mState.blendColor.blue = blue;
459 mState.blendColor.alpha = alpha;
460 mBlendStateDirty = true;
464 void Context::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation)
466 if(mState.blendEquationRGB != rgbEquation ||
467 mState.blendEquationAlpha != alphaEquation)
469 mState.blendEquationRGB = rgbEquation;
470 mState.blendEquationAlpha = alphaEquation;
471 mBlendStateDirty = true;
475 void Context::setStencilTestEnabled(bool enabled)
477 if(mState.stencilTestEnabled != enabled)
479 mState.stencilTestEnabled = enabled;
480 mStencilStateDirty = true;
484 bool Context::isStencilTestEnabled() const
486 return mState.stencilTestEnabled;
489 void Context::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask)
491 if(mState.stencilFunc != stencilFunc ||
492 mState.stencilRef != stencilRef ||
493 mState.stencilMask != stencilMask)
495 mState.stencilFunc = stencilFunc;
496 mState.stencilRef = (stencilRef > 0) ? stencilRef : 0;
497 mState.stencilMask = stencilMask;
498 mStencilStateDirty = true;
502 void Context::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask)
504 if(mState.stencilBackFunc != stencilBackFunc ||
505 mState.stencilBackRef != stencilBackRef ||
506 mState.stencilBackMask != stencilBackMask)
508 mState.stencilBackFunc = stencilBackFunc;
509 mState.stencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0;
510 mState.stencilBackMask = stencilBackMask;
511 mStencilStateDirty = true;
515 void Context::setStencilWritemask(GLuint stencilWritemask)
517 if(mState.stencilWritemask != stencilWritemask)
519 mState.stencilWritemask = stencilWritemask;
520 mStencilStateDirty = true;
524 void Context::setStencilBackWritemask(GLuint stencilBackWritemask)
526 if(mState.stencilBackWritemask != stencilBackWritemask)
528 mState.stencilBackWritemask = stencilBackWritemask;
529 mStencilStateDirty = true;
533 void Context::setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass)
535 if(mState.stencilFail != stencilFail ||
536 mState.stencilPassDepthFail != stencilPassDepthFail ||
537 mState.stencilPassDepthPass != stencilPassDepthPass)
539 mState.stencilFail = stencilFail;
540 mState.stencilPassDepthFail = stencilPassDepthFail;
541 mState.stencilPassDepthPass = stencilPassDepthPass;
542 mStencilStateDirty = true;
546 void Context::setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass)
548 if(mState.stencilBackFail != stencilBackFail ||
549 mState.stencilBackPassDepthFail != stencilBackPassDepthFail ||
550 mState.stencilBackPassDepthPass != stencilBackPassDepthPass)
552 mState.stencilBackFail = stencilBackFail;
553 mState.stencilBackPassDepthFail = stencilBackPassDepthFail;
554 mState.stencilBackPassDepthPass = stencilBackPassDepthPass;
555 mStencilStateDirty = true;
559 void Context::setPolygonOffsetFillEnabled(bool enabled)
561 if(mState.polygonOffsetFillEnabled != enabled)
563 mState.polygonOffsetFillEnabled = enabled;
564 mPolygonOffsetStateDirty = true;
568 bool Context::isPolygonOffsetFillEnabled() const
570 return mState.polygonOffsetFillEnabled;
573 void Context::setPolygonOffsetParams(GLfloat factor, GLfloat units)
575 if(mState.polygonOffsetFactor != factor ||
576 mState.polygonOffsetUnits != units)
578 mState.polygonOffsetFactor = factor;
579 mState.polygonOffsetUnits = units;
580 mPolygonOffsetStateDirty = true;
584 void Context::setSampleAlphaToCoverageEnabled(bool enabled)
586 if(mState.sampleAlphaToCoverageEnabled != enabled)
588 mState.sampleAlphaToCoverageEnabled = enabled;
589 mSampleStateDirty = true;
593 bool Context::isSampleAlphaToCoverageEnabled() const
595 return mState.sampleAlphaToCoverageEnabled;
598 void Context::setSampleCoverageEnabled(bool enabled)
600 if(mState.sampleCoverageEnabled != enabled)
602 mState.sampleCoverageEnabled = enabled;
603 mSampleStateDirty = true;
607 bool Context::isSampleCoverageEnabled() const
609 return mState.sampleCoverageEnabled;
612 void Context::setSampleCoverageParams(GLclampf value, bool invert)
614 if(mState.sampleCoverageValue != value ||
615 mState.sampleCoverageInvert != invert)
617 mState.sampleCoverageValue = value;
618 mState.sampleCoverageInvert = invert;
619 mSampleStateDirty = true;
623 void Context::setScissorTestEnabled(bool enabled)
625 mState.scissorTestEnabled = enabled;
628 bool Context::isScissorTestEnabled() const
630 return mState.scissorTestEnabled;
633 void Context::setDitherEnabled(bool enabled)
635 if(mState.ditherEnabled != enabled)
637 mState.ditherEnabled = enabled;
638 mDitherStateDirty = true;
642 bool Context::isDitherEnabled() const
644 return mState.ditherEnabled;
647 void Context::setPrimitiveRestartFixedIndexEnabled(bool enabled)
649 mState.primitiveRestartFixedIndexEnabled = enabled;
652 bool Context::isPrimitiveRestartFixedIndexEnabled() const
654 return mState.primitiveRestartFixedIndexEnabled;
657 void Context::setRasterizerDiscardEnabled(bool enabled)
659 mState.rasterizerDiscardEnabled = enabled;
662 bool Context::isRasterizerDiscardEnabled() const
664 return mState.rasterizerDiscardEnabled;
667 void Context::setLineWidth(GLfloat width)
669 mState.lineWidth = width;
670 device->setLineWidth(clamp(width, ALIASED_LINE_WIDTH_RANGE_MIN, ALIASED_LINE_WIDTH_RANGE_MAX));
673 void Context::setGenerateMipmapHint(GLenum hint)
675 mState.generateMipmapHint = hint;
678 void Context::setFragmentShaderDerivativeHint(GLenum hint)
680 mState.fragmentShaderDerivativeHint = hint;
681 // TODO: Propagate the hint to shader translator so we can write
682 // ddx, ddx_coarse, or ddx_fine depending on the hint.
683 // Ignore for now. It is valid for implementations to ignore hint.
686 void Context::setTextureFilteringHint(GLenum hint)
688 mState.textureFilteringHint = hint;
691 void Context::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height)
693 mState.viewportX = x;
694 mState.viewportY = y;
695 mState.viewportWidth = std::min<GLsizei>(width, IMPLEMENTATION_MAX_RENDERBUFFER_SIZE); // GL_MAX_VIEWPORT_DIMS[0]
696 mState.viewportHeight = std::min<GLsizei>(height, IMPLEMENTATION_MAX_RENDERBUFFER_SIZE); // GL_MAX_VIEWPORT_DIMS[1]
699 void Context::setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height)
703 mState.scissorWidth = width;
704 mState.scissorHeight = height;
707 void Context::setColorMask(bool red, bool green, bool blue, bool alpha)
709 if(mState.colorMaskRed != red || mState.colorMaskGreen != green ||
710 mState.colorMaskBlue != blue || mState.colorMaskAlpha != alpha)
712 mState.colorMaskRed = red;
713 mState.colorMaskGreen = green;
714 mState.colorMaskBlue = blue;
715 mState.colorMaskAlpha = alpha;
716 mMaskStateDirty = true;
720 unsigned int Context::getColorMask() const
722 return (mState.colorMaskRed ? 0x1 : 0) |
723 (mState.colorMaskGreen ? 0x2 : 0) |
724 (mState.colorMaskBlue ? 0x4 : 0) |
725 (mState.colorMaskAlpha ? 0x8 : 0);
728 void Context::setDepthMask(bool mask)
730 if(mState.depthMask != mask)
732 mState.depthMask = mask;
733 mMaskStateDirty = true;
737 void Context::setActiveSampler(unsigned int active)
739 mState.activeSampler = active;
742 GLuint Context::getReadFramebufferName() const
744 return mState.readFramebuffer;
747 GLuint Context::getDrawFramebufferName() const
749 return mState.drawFramebuffer;
752 GLuint Context::getRenderbufferName() const
754 return mState.renderbuffer.name();
757 void Context::setFramebufferReadBuffer(GLuint buf)
759 getReadFramebuffer()->setReadBuffer(buf);
762 void Context::setFramebufferDrawBuffers(GLsizei n, const GLenum *bufs)
764 Framebuffer *drawFramebuffer = getDrawFramebuffer();
766 for(int i = 0; i < MAX_COLOR_ATTACHMENTS; i++)
768 drawFramebuffer->setDrawBuffer(i, (i < n) ? bufs[i] : GL_NONE);
772 GLuint Context::getArrayBufferName() const
774 return mState.arrayBuffer.name();
777 GLuint Context::getElementArrayBufferName() const
779 Buffer* elementArrayBuffer = getCurrentVertexArray()->getElementArrayBuffer();
780 return elementArrayBuffer ? elementArrayBuffer->name : 0;
783 GLuint Context::getActiveQuery(GLenum target) const
785 Query *queryObject = nullptr;
789 case GL_ANY_SAMPLES_PASSED_EXT:
790 queryObject = mState.activeQuery[QUERY_ANY_SAMPLES_PASSED];
792 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
793 queryObject = mState.activeQuery[QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE];
795 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
796 queryObject = mState.activeQuery[QUERY_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN];
804 return queryObject->name;
810 void Context::setVertexAttribArrayEnabled(unsigned int attribNum, bool enabled)
812 getCurrentVertexArray()->enableAttribute(attribNum, enabled);
815 void Context::setVertexAttribDivisor(unsigned int attribNum, GLuint divisor)
817 getCurrentVertexArray()->setVertexAttribDivisor(attribNum, divisor);
820 const VertexAttribute &Context::getVertexAttribState(unsigned int attribNum) const
822 return getCurrentVertexArray()->getVertexAttribute(attribNum);
825 void Context::setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type,
826 bool normalized, bool pureInteger, GLsizei stride, const void *pointer)
828 getCurrentVertexArray()->setAttributeState(attribNum, boundBuffer, size, type, normalized, pureInteger, stride, pointer);
831 const void *Context::getVertexAttribPointer(unsigned int attribNum) const
833 return getCurrentVertexArray()->getVertexAttribute(attribNum).mPointer;
836 const VertexAttributeArray &Context::getVertexArrayAttributes()
838 return getCurrentVertexArray()->getVertexAttributes();
841 const VertexAttributeArray &Context::getCurrentVertexAttributes()
843 return mState.vertexAttribute;
846 void Context::setPackAlignment(GLint alignment)
848 mState.packAlignment = alignment;
851 void Context::setUnpackAlignment(GLint alignment)
853 mState.unpackInfo.alignment = alignment;
856 const egl::Image::UnpackInfo& Context::getUnpackInfo() const
858 return mState.unpackInfo;
861 void Context::setPackRowLength(GLint rowLength)
863 mState.packRowLength = rowLength;
866 void Context::setPackImageHeight(GLint imageHeight)
868 mState.packImageHeight = imageHeight;
871 void Context::setPackSkipPixels(GLint skipPixels)
873 mState.packSkipPixels = skipPixels;
876 void Context::setPackSkipRows(GLint skipRows)
878 mState.packSkipRows = skipRows;
881 void Context::setPackSkipImages(GLint skipImages)
883 mState.packSkipImages = skipImages;
886 void Context::setUnpackRowLength(GLint rowLength)
888 mState.unpackInfo.rowLength = rowLength;
891 void Context::setUnpackImageHeight(GLint imageHeight)
893 mState.unpackInfo.imageHeight = imageHeight;
896 void Context::setUnpackSkipPixels(GLint skipPixels)
898 mState.unpackInfo.skipPixels = skipPixels;
901 void Context::setUnpackSkipRows(GLint skipRows)
903 mState.unpackInfo.skipRows = skipRows;
906 void Context::setUnpackSkipImages(GLint skipImages)
908 mState.unpackInfo.skipImages = skipImages;
911 GLuint Context::createBuffer()
913 return mResourceManager->createBuffer();
916 GLuint Context::createProgram()
918 return mResourceManager->createProgram();
921 GLuint Context::createShader(GLenum type)
923 return mResourceManager->createShader(type);
926 GLuint Context::createTexture()
928 return mResourceManager->createTexture();
931 GLuint Context::createRenderbuffer()
933 return mResourceManager->createRenderbuffer();
936 // Returns an unused framebuffer name
937 GLuint Context::createFramebuffer()
939 return mFramebufferNameSpace.allocate();
942 GLuint Context::createFence()
944 return mFenceNameSpace.allocate(new Fence());
947 // Returns an unused query name
948 GLuint Context::createQuery()
950 return mQueryNameSpace.allocate();
953 // Returns an unused vertex array name
954 GLuint Context::createVertexArray()
956 return mVertexArrayNameSpace.allocate();
959 GLsync Context::createFenceSync(GLenum condition, GLbitfield flags)
961 GLuint handle = mResourceManager->createFenceSync(condition, flags);
963 return reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
966 // Returns an unused transform feedback name
967 GLuint Context::createTransformFeedback()
969 return mTransformFeedbackNameSpace.allocate();
972 // Returns an unused sampler name
973 GLuint Context::createSampler()
975 return mResourceManager->createSampler();
978 void Context::deleteBuffer(GLuint buffer)
980 detachBuffer(buffer);
982 mResourceManager->deleteBuffer(buffer);
985 void Context::deleteShader(GLuint shader)
987 mResourceManager->deleteShader(shader);
990 void Context::deleteProgram(GLuint program)
992 mResourceManager->deleteProgram(program);
995 void Context::deleteTexture(GLuint texture)
997 detachTexture(texture);
999 mResourceManager->deleteTexture(texture);
1002 void Context::deleteRenderbuffer(GLuint renderbuffer)
1004 if(mResourceManager->getRenderbuffer(renderbuffer))
1006 detachRenderbuffer(renderbuffer);
1009 mResourceManager->deleteRenderbuffer(renderbuffer);
1012 void Context::deleteFramebuffer(GLuint framebuffer)
1014 detachFramebuffer(framebuffer);
1016 Framebuffer *framebufferObject = mFramebufferNameSpace.remove(framebuffer);
1018 if(framebufferObject)
1020 delete framebufferObject;
1024 void Context::deleteFence(GLuint fence)
1026 Fence *fenceObject = mFenceNameSpace.remove(fence);
1034 void Context::deleteQuery(GLuint query)
1036 Query *queryObject = mQueryNameSpace.remove(query);
1040 queryObject->release();
1044 void Context::deleteVertexArray(GLuint vertexArray)
1046 // [OpenGL ES 3.0.2] section 2.10 page 43:
1047 // If a vertex array object that is currently bound is deleted, the binding
1048 // for that object reverts to zero and the default vertex array becomes current.
1049 if(getCurrentVertexArray()->name == vertexArray)
1054 VertexArray *vertexArrayObject = mVertexArrayNameSpace.remove(vertexArray);
1056 if(vertexArrayObject)
1058 delete vertexArrayObject;
1062 void Context::deleteFenceSync(GLsync fenceSync)
1064 // The spec specifies the underlying Fence object is not deleted until all current
1065 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
1066 // and since our API is currently designed for being called from a single thread, we can delete
1067 // the fence immediately.
1068 mResourceManager->deleteFenceSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(fenceSync)));
1071 void Context::deleteTransformFeedback(GLuint transformFeedback)
1073 TransformFeedback *transformFeedbackObject = mTransformFeedbackNameSpace.remove(transformFeedback);
1075 if(transformFeedbackObject)
1077 delete transformFeedbackObject;
1081 void Context::deleteSampler(GLuint sampler)
1083 detachSampler(sampler);
1085 mResourceManager->deleteSampler(sampler);
1088 Buffer *Context::getBuffer(GLuint handle) const
1090 return mResourceManager->getBuffer(handle);
1093 Shader *Context::getShader(GLuint handle) const
1095 return mResourceManager->getShader(handle);
1098 Program *Context::getProgram(GLuint handle) const
1100 return mResourceManager->getProgram(handle);
1103 Texture *Context::getTexture(GLuint handle) const
1105 return mResourceManager->getTexture(handle);
1108 Renderbuffer *Context::getRenderbuffer(GLuint handle) const
1110 return mResourceManager->getRenderbuffer(handle);
1113 Framebuffer *Context::getReadFramebuffer() const
1115 return getFramebuffer(mState.readFramebuffer);
1118 Framebuffer *Context::getDrawFramebuffer() const
1120 return getFramebuffer(mState.drawFramebuffer);
1123 void Context::bindArrayBuffer(unsigned int buffer)
1125 mResourceManager->checkBufferAllocation(buffer);
1127 mState.arrayBuffer = getBuffer(buffer);
1130 void Context::bindElementArrayBuffer(unsigned int buffer)
1132 mResourceManager->checkBufferAllocation(buffer);
1134 getCurrentVertexArray()->setElementArrayBuffer(getBuffer(buffer));
1137 void Context::bindCopyReadBuffer(GLuint buffer)
1139 mResourceManager->checkBufferAllocation(buffer);
1141 mState.copyReadBuffer = getBuffer(buffer);
1144 void Context::bindCopyWriteBuffer(GLuint buffer)
1146 mResourceManager->checkBufferAllocation(buffer);
1148 mState.copyWriteBuffer = getBuffer(buffer);
1151 void Context::bindPixelPackBuffer(GLuint buffer)
1153 mResourceManager->checkBufferAllocation(buffer);
1155 mState.pixelPackBuffer = getBuffer(buffer);
1158 void Context::bindPixelUnpackBuffer(GLuint buffer)
1160 mResourceManager->checkBufferAllocation(buffer);
1162 mState.pixelUnpackBuffer = getBuffer(buffer);
1165 void Context::bindTransformFeedbackBuffer(GLuint buffer)
1167 mResourceManager->checkBufferAllocation(buffer);
1169 TransformFeedback* transformFeedback = getTransformFeedback(mState.transformFeedback);
1171 if(transformFeedback)
1173 transformFeedback->setGenericBuffer(getBuffer(buffer));
1177 void Context::bindTexture2D(GLuint texture)
1179 mResourceManager->checkTextureAllocation(texture, TEXTURE_2D);
1181 mState.samplerTexture[TEXTURE_2D][mState.activeSampler] = getTexture(texture);
1184 void Context::bindTextureCubeMap(GLuint texture)
1186 mResourceManager->checkTextureAllocation(texture, TEXTURE_CUBE);
1188 mState.samplerTexture[TEXTURE_CUBE][mState.activeSampler] = getTexture(texture);
1191 void Context::bindTextureExternal(GLuint texture)
1193 mResourceManager->checkTextureAllocation(texture, TEXTURE_EXTERNAL);
1195 mState.samplerTexture[TEXTURE_EXTERNAL][mState.activeSampler] = getTexture(texture);
1198 void Context::bindTexture3D(GLuint texture)
1200 mResourceManager->checkTextureAllocation(texture, TEXTURE_3D);
1202 mState.samplerTexture[TEXTURE_3D][mState.activeSampler] = getTexture(texture);
1205 void Context::bindTexture2DArray(GLuint texture)
1207 mResourceManager->checkTextureAllocation(texture, TEXTURE_2D_ARRAY);
1209 mState.samplerTexture[TEXTURE_2D_ARRAY][mState.activeSampler] = getTexture(texture);
1212 void Context::bindReadFramebuffer(GLuint framebuffer)
1214 if(!getFramebuffer(framebuffer))
1216 if(framebuffer == 0)
1218 mFramebufferNameSpace.insert(framebuffer, new DefaultFramebuffer());
1222 mFramebufferNameSpace.insert(framebuffer, new Framebuffer());
1226 mState.readFramebuffer = framebuffer;
1229 void Context::bindDrawFramebuffer(GLuint framebuffer)
1231 if(!getFramebuffer(framebuffer))
1233 if(framebuffer == 0)
1235 mFramebufferNameSpace.insert(framebuffer, new DefaultFramebuffer());
1239 mFramebufferNameSpace.insert(framebuffer, new Framebuffer());
1243 mState.drawFramebuffer = framebuffer;
1246 void Context::bindRenderbuffer(GLuint renderbuffer)
1248 mResourceManager->checkRenderbufferAllocation(renderbuffer);
1250 mState.renderbuffer = getRenderbuffer(renderbuffer);
1253 void Context::bindVertexArray(GLuint array)
1255 VertexArray *vertexArray = getVertexArray(array);
1259 vertexArray = new VertexArray(array);
1260 mVertexArrayNameSpace.insert(array, vertexArray);
1263 mState.vertexArray = array;
1266 void Context::bindGenericUniformBuffer(GLuint buffer)
1268 mResourceManager->checkBufferAllocation(buffer);
1270 mState.genericUniformBuffer = getBuffer(buffer);
1273 void Context::bindIndexedUniformBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size)
1275 mResourceManager->checkBufferAllocation(buffer);
1277 Buffer* bufferObject = getBuffer(buffer);
1278 mState.uniformBuffers[index].set(bufferObject, static_cast<int>(offset), static_cast<int>(size));
1281 void Context::bindGenericTransformFeedbackBuffer(GLuint buffer)
1283 mResourceManager->checkBufferAllocation(buffer);
1285 getTransformFeedback()->setGenericBuffer(getBuffer(buffer));
1288 void Context::bindIndexedTransformFeedbackBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size)
1290 mResourceManager->checkBufferAllocation(buffer);
1292 Buffer* bufferObject = getBuffer(buffer);
1293 getTransformFeedback()->setBuffer(index, bufferObject, offset, size);
1296 void Context::bindTransformFeedback(GLuint id)
1298 if(!getTransformFeedback(id))
1300 mTransformFeedbackNameSpace.insert(id, new TransformFeedback(id));
1303 mState.transformFeedback = id;
1306 bool Context::bindSampler(GLuint unit, GLuint sampler)
1308 mResourceManager->checkSamplerAllocation(sampler);
1310 Sampler* samplerObject = getSampler(sampler);
1312 mState.sampler[unit] = samplerObject;
1314 return !!samplerObject;
1317 void Context::useProgram(GLuint program)
1319 GLuint priorProgram = mState.currentProgram;
1320 mState.currentProgram = program; // Must switch before trying to delete, otherwise it only gets flagged.
1322 if(priorProgram != program)
1324 Program *newProgram = mResourceManager->getProgram(program);
1325 Program *oldProgram = mResourceManager->getProgram(priorProgram);
1329 newProgram->addRef();
1334 oldProgram->release();
1339 void Context::beginQuery(GLenum target, GLuint query)
1341 // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id>
1342 // of zero, if the active query object name for <target> is non-zero (for the
1343 // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if
1344 // the active query for either target is non-zero), if <id> is the name of an
1345 // existing query object whose type does not match <target>, or if <id> is the
1346 // active query object name for any query type, the error INVALID_OPERATION is
1349 // Ensure no other queries are active
1350 // NOTE: If other queries than occlusion are supported, we will need to check
1352 // a) The query ID passed is not the current active query for any target/type
1353 // b) There are no active queries for the requested target (and in the case
1354 // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT,
1355 // no query may be active for either if glBeginQuery targets either.
1356 for(int i = 0; i < QUERY_TYPE_COUNT; i++)
1358 if(mState.activeQuery[i])
1360 switch(mState.activeQuery[i]->getType())
1362 case GL_ANY_SAMPLES_PASSED_EXT:
1363 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
1364 if((target == GL_ANY_SAMPLES_PASSED_EXT) ||
1365 (target == GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT))
1367 return error(GL_INVALID_OPERATION);
1370 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
1371 if(target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
1373 return error(GL_INVALID_OPERATION);
1385 case GL_ANY_SAMPLES_PASSED_EXT:
1386 qType = QUERY_ANY_SAMPLES_PASSED;
1388 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
1389 qType = QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE;
1391 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
1392 qType = QUERY_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN;
1395 UNREACHABLE(target);
1396 return error(GL_INVALID_ENUM);
1399 Query *queryObject = createQuery(query, target);
1401 // Check that name was obtained with glGenQueries
1404 return error(GL_INVALID_OPERATION);
1407 // Check for type mismatch
1408 if(queryObject->getType() != target)
1410 return error(GL_INVALID_OPERATION);
1413 // Set query as active for specified target
1414 mState.activeQuery[qType] = queryObject;
1417 queryObject->begin();
1420 void Context::endQuery(GLenum target)
1426 case GL_ANY_SAMPLES_PASSED_EXT: qType = QUERY_ANY_SAMPLES_PASSED; break;
1427 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT: qType = QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE; break;
1428 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: qType = QUERY_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN; break;
1429 default: UNREACHABLE(target); return;
1432 Query *queryObject = mState.activeQuery[qType];
1436 return error(GL_INVALID_OPERATION);
1441 mState.activeQuery[qType] = nullptr;
1444 void Context::setFramebufferZero(Framebuffer *buffer)
1446 delete mFramebufferNameSpace.remove(0);
1447 mFramebufferNameSpace.insert(0, buffer);
1450 void Context::setRenderbufferStorage(RenderbufferStorage *renderbuffer)
1452 Renderbuffer *renderbufferObject = mState.renderbuffer;
1453 renderbufferObject->setStorage(renderbuffer);
1456 Framebuffer *Context::getFramebuffer(unsigned int handle) const
1458 return mFramebufferNameSpace.find(handle);
1461 Fence *Context::getFence(unsigned int handle) const
1463 return mFenceNameSpace.find(handle);
1466 FenceSync *Context::getFenceSync(GLsync handle) const
1468 return mResourceManager->getFenceSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
1471 Query *Context::getQuery(unsigned int handle) const
1473 return mQueryNameSpace.find(handle);
1476 Query *Context::createQuery(unsigned int handle, GLenum type)
1478 if(!mQueryNameSpace.isReserved(handle))
1484 Query *query = mQueryNameSpace.find(handle);
1487 query = new Query(handle, type);
1489 mQueryNameSpace.insert(handle, query);
1496 VertexArray *Context::getVertexArray(GLuint array) const
1498 return mVertexArrayNameSpace.find(array);
1501 VertexArray *Context::getCurrentVertexArray() const
1503 return getVertexArray(mState.vertexArray);
1506 bool Context::isVertexArray(GLuint array) const
1508 return mVertexArrayNameSpace.isReserved(array);
1511 bool Context::hasZeroDivisor() const
1513 // Verify there is at least one active attribute with a divisor of zero
1514 es2::Program *programObject = getCurrentProgram();
1515 for(int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
1517 bool active = (programObject->getAttributeStream(attributeIndex) != -1);
1518 if(active && getCurrentVertexArray()->getVertexAttribute(attributeIndex).mDivisor == 0)
1527 TransformFeedback *Context::getTransformFeedback(GLuint transformFeedback) const
1529 return mTransformFeedbackNameSpace.find(transformFeedback);
1532 bool Context::isTransformFeedback(GLuint array) const
1534 return mTransformFeedbackNameSpace.isReserved(array);
1537 Sampler *Context::getSampler(GLuint sampler) const
1539 return mResourceManager->getSampler(sampler);
1542 bool Context::isSampler(GLuint sampler) const
1544 return mResourceManager->isSampler(sampler);
1547 Buffer *Context::getArrayBuffer() const
1549 return mState.arrayBuffer;
1552 Buffer *Context::getElementArrayBuffer() const
1554 return getCurrentVertexArray()->getElementArrayBuffer();
1557 Buffer *Context::getCopyReadBuffer() const
1559 return mState.copyReadBuffer;
1562 Buffer *Context::getCopyWriteBuffer() const
1564 return mState.copyWriteBuffer;
1567 Buffer *Context::getPixelPackBuffer() const
1569 return mState.pixelPackBuffer;
1572 Buffer *Context::getPixelUnpackBuffer() const
1574 return mState.pixelUnpackBuffer;
1577 Buffer *Context::getGenericUniformBuffer() const
1579 return mState.genericUniformBuffer;
1582 GLsizei Context::getRequiredBufferSize(GLsizei width, GLsizei height, GLsizei depth, GLint internalformat, GLenum type) const
1584 GLenum format = GetSizedInternalFormat(internalformat, type);
1585 GLsizei inputWidth = (mState.unpackInfo.rowLength == 0) ? width : mState.unpackInfo.rowLength;
1586 GLsizei inputPitch = egl::ComputePitch(inputWidth, format, type, mState.unpackInfo.alignment);
1587 GLsizei inputHeight = (mState.unpackInfo.imageHeight == 0) ? height : mState.unpackInfo.imageHeight;
1588 return inputPitch * inputHeight * depth;
1591 GLenum Context::getPixels(const GLvoid **data, GLenum type, GLsizei imageSize) const
1593 if(mState.pixelUnpackBuffer)
1595 if(mState.pixelUnpackBuffer->name)
1597 if(mState.pixelUnpackBuffer->isMapped() ||
1598 (mState.pixelUnpackBuffer->size() < static_cast<size_t>(imageSize)) ||
1599 (static_cast<GLsizei>((ptrdiff_t)(*data)) % GetTypeSize(type)))
1601 return GL_INVALID_OPERATION;
1605 *data = static_cast<const unsigned char*>(mState.pixelUnpackBuffer->data()) + (ptrdiff_t)(*data);
1610 bool Context::getBuffer(GLenum target, es2::Buffer **buffer) const
1614 case GL_ARRAY_BUFFER:
1615 *buffer = getArrayBuffer();
1617 case GL_ELEMENT_ARRAY_BUFFER:
1618 *buffer = getElementArrayBuffer();
1620 case GL_COPY_READ_BUFFER:
1621 if(clientVersion >= 3)
1623 *buffer = getCopyReadBuffer();
1627 case GL_COPY_WRITE_BUFFER:
1628 if(clientVersion >= 3)
1630 *buffer = getCopyWriteBuffer();
1634 case GL_PIXEL_PACK_BUFFER:
1635 if(clientVersion >= 3)
1637 *buffer = getPixelPackBuffer();
1641 case GL_PIXEL_UNPACK_BUFFER:
1642 if(clientVersion >= 3)
1644 *buffer = getPixelUnpackBuffer();
1648 case GL_TRANSFORM_FEEDBACK_BUFFER:
1649 if(clientVersion >= 3)
1651 TransformFeedback* transformFeedback = getTransformFeedback();
1652 *buffer = transformFeedback ? static_cast<es2::Buffer*>(transformFeedback->getGenericBuffer()) : nullptr;
1656 case GL_UNIFORM_BUFFER:
1657 if(clientVersion >= 3)
1659 *buffer = getGenericUniformBuffer();
1669 TransformFeedback *Context::getTransformFeedback() const
1671 return getTransformFeedback(mState.transformFeedback);
1674 Program *Context::getCurrentProgram() const
1676 return mResourceManager->getProgram(mState.currentProgram);
1679 Texture2D *Context::getTexture2D() const
1681 return static_cast<Texture2D*>(getSamplerTexture(mState.activeSampler, TEXTURE_2D));
1684 Texture3D *Context::getTexture3D() const
1686 return static_cast<Texture3D*>(getSamplerTexture(mState.activeSampler, TEXTURE_3D));
1689 Texture2DArray *Context::getTexture2DArray() const
1691 return static_cast<Texture2DArray*>(getSamplerTexture(mState.activeSampler, TEXTURE_2D_ARRAY));
1694 TextureCubeMap *Context::getTextureCubeMap() const
1696 return static_cast<TextureCubeMap*>(getSamplerTexture(mState.activeSampler, TEXTURE_CUBE));
1699 TextureExternal *Context::getTextureExternal() const
1701 return static_cast<TextureExternal*>(getSamplerTexture(mState.activeSampler, TEXTURE_EXTERNAL));
1704 Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
1706 GLuint texid = mState.samplerTexture[type][sampler].name();
1708 if(texid == 0) // Special case: 0 refers to different initial textures based on the target
1712 case TEXTURE_2D: return mTexture2DZero;
1713 case TEXTURE_3D: return mTexture3DZero;
1714 case TEXTURE_2D_ARRAY: return mTexture2DArrayZero;
1715 case TEXTURE_CUBE: return mTextureCubeMapZero;
1716 case TEXTURE_EXTERNAL: return mTextureExternalZero;
1717 default: UNREACHABLE(type);
1721 return mState.samplerTexture[type][sampler];
1724 void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
1726 mResourceManager->checkSamplerAllocation(sampler);
1728 Sampler *samplerObject = getSampler(sampler);
1729 ASSERT(samplerObject);
1733 case GL_TEXTURE_MIN_FILTER: samplerObject->setMinFilter(static_cast<GLenum>(param)); break;
1734 case GL_TEXTURE_MAG_FILTER: samplerObject->setMagFilter(static_cast<GLenum>(param)); break;
1735 case GL_TEXTURE_WRAP_S: samplerObject->setWrapS(static_cast<GLenum>(param)); break;
1736 case GL_TEXTURE_WRAP_T: samplerObject->setWrapT(static_cast<GLenum>(param)); break;
1737 case GL_TEXTURE_WRAP_R: samplerObject->setWrapR(static_cast<GLenum>(param)); break;
1738 case GL_TEXTURE_MIN_LOD: samplerObject->setMinLod(static_cast<GLfloat>(param)); break;
1739 case GL_TEXTURE_MAX_LOD: samplerObject->setMaxLod(static_cast<GLfloat>(param)); break;
1740 case GL_TEXTURE_COMPARE_MODE: samplerObject->setCompareMode(static_cast<GLenum>(param)); break;
1741 case GL_TEXTURE_COMPARE_FUNC: samplerObject->setCompareFunc(static_cast<GLenum>(param)); break;
1742 default: UNREACHABLE(pname); break;
1746 void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
1748 mResourceManager->checkSamplerAllocation(sampler);
1750 Sampler *samplerObject = getSampler(sampler);
1751 ASSERT(samplerObject);
1755 case GL_TEXTURE_MIN_FILTER: samplerObject->setMinFilter(static_cast<GLenum>(roundf(param))); break;
1756 case GL_TEXTURE_MAG_FILTER: samplerObject->setMagFilter(static_cast<GLenum>(roundf(param))); break;
1757 case GL_TEXTURE_WRAP_S: samplerObject->setWrapS(static_cast<GLenum>(roundf(param))); break;
1758 case GL_TEXTURE_WRAP_T: samplerObject->setWrapT(static_cast<GLenum>(roundf(param))); break;
1759 case GL_TEXTURE_WRAP_R: samplerObject->setWrapR(static_cast<GLenum>(roundf(param))); break;
1760 case GL_TEXTURE_MIN_LOD: samplerObject->setMinLod(param); break;
1761 case GL_TEXTURE_MAX_LOD: samplerObject->setMaxLod(param); break;
1762 case GL_TEXTURE_COMPARE_MODE: samplerObject->setCompareMode(static_cast<GLenum>(roundf(param))); break;
1763 case GL_TEXTURE_COMPARE_FUNC: samplerObject->setCompareFunc(static_cast<GLenum>(roundf(param))); break;
1764 default: UNREACHABLE(pname); break;
1768 GLint Context::getSamplerParameteri(GLuint sampler, GLenum pname)
1770 mResourceManager->checkSamplerAllocation(sampler);
1772 Sampler *samplerObject = getSampler(sampler);
1773 ASSERT(samplerObject);
1777 case GL_TEXTURE_MIN_FILTER: return static_cast<GLint>(samplerObject->getMinFilter());
1778 case GL_TEXTURE_MAG_FILTER: return static_cast<GLint>(samplerObject->getMagFilter());
1779 case GL_TEXTURE_WRAP_S: return static_cast<GLint>(samplerObject->getWrapS());
1780 case GL_TEXTURE_WRAP_T: return static_cast<GLint>(samplerObject->getWrapT());
1781 case GL_TEXTURE_WRAP_R: return static_cast<GLint>(samplerObject->getWrapR());
1782 case GL_TEXTURE_MIN_LOD: return static_cast<GLint>(roundf(samplerObject->getMinLod()));
1783 case GL_TEXTURE_MAX_LOD: return static_cast<GLint>(roundf(samplerObject->getMaxLod()));
1784 case GL_TEXTURE_COMPARE_MODE: return static_cast<GLint>(samplerObject->getCompareMode());
1785 case GL_TEXTURE_COMPARE_FUNC: return static_cast<GLint>(samplerObject->getCompareFunc());
1786 default: UNREACHABLE(pname); return 0;
1790 GLfloat Context::getSamplerParameterf(GLuint sampler, GLenum pname)
1792 mResourceManager->checkSamplerAllocation(sampler);
1794 Sampler *samplerObject = getSampler(sampler);
1795 ASSERT(samplerObject);
1799 case GL_TEXTURE_MIN_FILTER: return static_cast<GLfloat>(samplerObject->getMinFilter());
1800 case GL_TEXTURE_MAG_FILTER: return static_cast<GLfloat>(samplerObject->getMagFilter());
1801 case GL_TEXTURE_WRAP_S: return static_cast<GLfloat>(samplerObject->getWrapS());
1802 case GL_TEXTURE_WRAP_T: return static_cast<GLfloat>(samplerObject->getWrapT());
1803 case GL_TEXTURE_WRAP_R: return static_cast<GLfloat>(samplerObject->getWrapR());
1804 case GL_TEXTURE_MIN_LOD: return samplerObject->getMinLod();
1805 case GL_TEXTURE_MAX_LOD: return samplerObject->getMaxLod();
1806 case GL_TEXTURE_COMPARE_MODE: return static_cast<GLfloat>(samplerObject->getCompareMode());
1807 case GL_TEXTURE_COMPARE_FUNC: return static_cast<GLfloat>(samplerObject->getCompareFunc());
1808 default: UNREACHABLE(pname); return 0;
1812 bool Context::getBooleanv(GLenum pname, GLboolean *params) const
1816 case GL_SHADER_COMPILER: *params = GL_TRUE; break;
1817 case GL_SAMPLE_COVERAGE_INVERT: *params = mState.sampleCoverageInvert; break;
1818 case GL_DEPTH_WRITEMASK: *params = mState.depthMask; break;
1819 case GL_COLOR_WRITEMASK:
1820 params[0] = mState.colorMaskRed;
1821 params[1] = mState.colorMaskGreen;
1822 params[2] = mState.colorMaskBlue;
1823 params[3] = mState.colorMaskAlpha;
1825 case GL_CULL_FACE: *params = mState.cullFaceEnabled; break;
1826 case GL_POLYGON_OFFSET_FILL: *params = mState.polygonOffsetFillEnabled; break;
1827 case GL_SAMPLE_ALPHA_TO_COVERAGE: *params = mState.sampleAlphaToCoverageEnabled; break;
1828 case GL_SAMPLE_COVERAGE: *params = mState.sampleCoverageEnabled; break;
1829 case GL_SCISSOR_TEST: *params = mState.scissorTestEnabled; break;
1830 case GL_STENCIL_TEST: *params = mState.stencilTestEnabled; break;
1831 case GL_DEPTH_TEST: *params = mState.depthTestEnabled; break;
1832 case GL_BLEND: *params = mState.blendEnabled; break;
1833 case GL_DITHER: *params = mState.ditherEnabled; break;
1834 case GL_PRIMITIVE_RESTART_FIXED_INDEX: *params = mState.primitiveRestartFixedIndexEnabled; break;
1835 case GL_RASTERIZER_DISCARD: *params = mState.rasterizerDiscardEnabled; break;
1836 case GL_TRANSFORM_FEEDBACK_ACTIVE:
1838 TransformFeedback* transformFeedback = getTransformFeedback(mState.transformFeedback);
1839 if(transformFeedback)
1841 *params = transformFeedback->isActive();
1846 case GL_TRANSFORM_FEEDBACK_PAUSED:
1848 TransformFeedback* transformFeedback = getTransformFeedback(mState.transformFeedback);
1849 if(transformFeedback)
1851 *params = transformFeedback->isPaused();
1863 bool Context::getFloatv(GLenum pname, GLfloat *params) const
1865 // Please note: DEPTH_CLEAR_VALUE is included in our internal getFloatv implementation
1866 // because it is stored as a float, despite the fact that the GL ES 2.0 spec names
1867 // GetIntegerv as its native query function. As it would require conversion in any
1868 // case, this should make no difference to the calling application.
1871 case GL_LINE_WIDTH: *params = mState.lineWidth; break;
1872 case GL_SAMPLE_COVERAGE_VALUE: *params = mState.sampleCoverageValue; break;
1873 case GL_DEPTH_CLEAR_VALUE: *params = mState.depthClearValue; break;
1874 case GL_POLYGON_OFFSET_FACTOR: *params = mState.polygonOffsetFactor; break;
1875 case GL_POLYGON_OFFSET_UNITS: *params = mState.polygonOffsetUnits; break;
1876 case GL_ALIASED_LINE_WIDTH_RANGE:
1877 params[0] = ALIASED_LINE_WIDTH_RANGE_MIN;
1878 params[1] = ALIASED_LINE_WIDTH_RANGE_MAX;
1880 case GL_ALIASED_POINT_SIZE_RANGE:
1881 params[0] = ALIASED_POINT_SIZE_RANGE_MIN;
1882 params[1] = ALIASED_POINT_SIZE_RANGE_MAX;
1884 case GL_DEPTH_RANGE:
1885 params[0] = mState.zNear;
1886 params[1] = mState.zFar;
1888 case GL_COLOR_CLEAR_VALUE:
1889 params[0] = mState.colorClearValue.red;
1890 params[1] = mState.colorClearValue.green;
1891 params[2] = mState.colorClearValue.blue;
1892 params[3] = mState.colorClearValue.alpha;
1894 case GL_BLEND_COLOR:
1895 params[0] = mState.blendColor.red;
1896 params[1] = mState.blendColor.green;
1897 params[2] = mState.blendColor.blue;
1898 params[3] = mState.blendColor.alpha;
1900 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1901 *params = MAX_TEXTURE_MAX_ANISOTROPY;
1910 template bool Context::getIntegerv<GLint>(GLenum pname, GLint *params) const;
1911 template bool Context::getIntegerv<GLint64>(GLenum pname, GLint64 *params) const;
1913 template<typename T> bool Context::getIntegerv(GLenum pname, T *params) const
1915 // Please note: DEPTH_CLEAR_VALUE is not included in our internal getIntegerv implementation
1916 // because it is stored as a float, despite the fact that the GL ES 2.0 spec names
1917 // GetIntegerv as its native query function. As it would require conversion in any
1918 // case, this should make no difference to the calling application. You may find it in
1919 // Context::getFloatv.
1922 case GL_MAX_VERTEX_ATTRIBS: *params = MAX_VERTEX_ATTRIBS; return true;
1923 case GL_MAX_VERTEX_UNIFORM_VECTORS: *params = MAX_VERTEX_UNIFORM_VECTORS; return true;
1924 case GL_MAX_VARYING_VECTORS: *params = MAX_VARYING_VECTORS; return true;
1925 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: *params = MAX_COMBINED_TEXTURE_IMAGE_UNITS; return true;
1926 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: *params = MAX_VERTEX_TEXTURE_IMAGE_UNITS; return true;
1927 case GL_MAX_TEXTURE_IMAGE_UNITS: *params = MAX_TEXTURE_IMAGE_UNITS; return true;
1928 case GL_MAX_FRAGMENT_UNIFORM_VECTORS: *params = MAX_FRAGMENT_UNIFORM_VECTORS; return true;
1929 case GL_MAX_RENDERBUFFER_SIZE: *params = IMPLEMENTATION_MAX_RENDERBUFFER_SIZE; return true;
1930 case GL_NUM_SHADER_BINARY_FORMATS: *params = 0; return true;
1931 case GL_SHADER_BINARY_FORMATS: /* no shader binary formats are supported */ return true;
1932 case GL_ARRAY_BUFFER_BINDING: *params = getArrayBufferName(); return true;
1933 case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = getElementArrayBufferName(); return true;
1934 // case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1935 case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE: *params = mState.drawFramebuffer; return true;
1936 case GL_READ_FRAMEBUFFER_BINDING_ANGLE: *params = mState.readFramebuffer; return true;
1937 case GL_RENDERBUFFER_BINDING: *params = mState.renderbuffer.name(); return true;
1938 case GL_CURRENT_PROGRAM: *params = mState.currentProgram; return true;
1939 case GL_PACK_ALIGNMENT: *params = mState.packAlignment; return true;
1940 case GL_UNPACK_ALIGNMENT: *params = mState.unpackInfo.alignment; return true;
1941 case GL_GENERATE_MIPMAP_HINT: *params = mState.generateMipmapHint; return true;
1942 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: *params = mState.fragmentShaderDerivativeHint; return true;
1943 case GL_TEXTURE_FILTERING_HINT_CHROMIUM: *params = mState.textureFilteringHint; return true;
1944 case GL_ACTIVE_TEXTURE: *params = (mState.activeSampler + GL_TEXTURE0); return true;
1945 case GL_STENCIL_FUNC: *params = mState.stencilFunc; return true;
1946 case GL_STENCIL_REF: *params = mState.stencilRef; return true;
1947 case GL_STENCIL_VALUE_MASK: *params = sw::clampToSignedInt(mState.stencilMask); return true;
1948 case GL_STENCIL_BACK_FUNC: *params = mState.stencilBackFunc; return true;
1949 case GL_STENCIL_BACK_REF: *params = mState.stencilBackRef; return true;
1950 case GL_STENCIL_BACK_VALUE_MASK: *params = sw::clampToSignedInt(mState.stencilBackMask); return true;
1951 case GL_STENCIL_FAIL: *params = mState.stencilFail; return true;
1952 case GL_STENCIL_PASS_DEPTH_FAIL: *params = mState.stencilPassDepthFail; return true;
1953 case GL_STENCIL_PASS_DEPTH_PASS: *params = mState.stencilPassDepthPass; return true;
1954 case GL_STENCIL_BACK_FAIL: *params = mState.stencilBackFail; return true;
1955 case GL_STENCIL_BACK_PASS_DEPTH_FAIL: *params = mState.stencilBackPassDepthFail; return true;
1956 case GL_STENCIL_BACK_PASS_DEPTH_PASS: *params = mState.stencilBackPassDepthPass; return true;
1957 case GL_DEPTH_FUNC: *params = mState.depthFunc; return true;
1958 case GL_BLEND_SRC_RGB: *params = mState.sourceBlendRGB; return true;
1959 case GL_BLEND_SRC_ALPHA: *params = mState.sourceBlendAlpha; return true;
1960 case GL_BLEND_DST_RGB: *params = mState.destBlendRGB; return true;
1961 case GL_BLEND_DST_ALPHA: *params = mState.destBlendAlpha; return true;
1962 case GL_BLEND_EQUATION_RGB: *params = mState.blendEquationRGB; return true;
1963 case GL_BLEND_EQUATION_ALPHA: *params = mState.blendEquationAlpha; return true;
1964 case GL_STENCIL_WRITEMASK: *params = sw::clampToSignedInt(mState.stencilWritemask); return true;
1965 case GL_STENCIL_BACK_WRITEMASK: *params = sw::clampToSignedInt(mState.stencilBackWritemask); return true;
1966 case GL_STENCIL_CLEAR_VALUE: *params = mState.stencilClearValue; return true;
1967 case GL_SUBPIXEL_BITS: *params = 4; return true;
1968 case GL_MAX_TEXTURE_SIZE: *params = IMPLEMENTATION_MAX_TEXTURE_SIZE; return true;
1969 case GL_MAX_CUBE_MAP_TEXTURE_SIZE: *params = IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE; return true;
1970 case GL_NUM_COMPRESSED_TEXTURE_FORMATS: *params = NUM_COMPRESSED_TEXTURE_FORMATS; return true;
1971 case GL_MAX_SAMPLES_ANGLE: *params = IMPLEMENTATION_MAX_SAMPLES; return true;
1972 case GL_SAMPLE_BUFFERS:
1975 Framebuffer *framebuffer = getDrawFramebuffer();
1976 int width, height, samples;
1978 if(framebuffer->completeness(width, height, samples) == GL_FRAMEBUFFER_COMPLETE)
1982 case GL_SAMPLE_BUFFERS:
2003 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
2005 Framebuffer *framebuffer = getReadFramebuffer();
2006 *params = framebuffer->getImplementationColorReadType();
2009 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
2011 Framebuffer *framebuffer = getReadFramebuffer();
2012 *params = framebuffer->getImplementationColorReadFormat();
2015 case GL_MAX_VIEWPORT_DIMS:
2017 int maxDimension = IMPLEMENTATION_MAX_RENDERBUFFER_SIZE;
2018 params[0] = maxDimension;
2019 params[1] = maxDimension;
2022 case GL_COMPRESSED_TEXTURE_FORMATS:
2024 for(int i = 0; i < NUM_COMPRESSED_TEXTURE_FORMATS; i++)
2026 params[i] = compressedTextureFormats[i];
2031 params[0] = mState.viewportX;
2032 params[1] = mState.viewportY;
2033 params[2] = mState.viewportWidth;
2034 params[3] = mState.viewportHeight;
2036 case GL_SCISSOR_BOX:
2037 params[0] = mState.scissorX;
2038 params[1] = mState.scissorY;
2039 params[2] = mState.scissorWidth;
2040 params[3] = mState.scissorHeight;
2042 case GL_CULL_FACE_MODE: *params = mState.cullMode; return true;
2043 case GL_FRONT_FACE: *params = mState.frontFace; return true;
2049 Framebuffer *framebuffer = getDrawFramebuffer();
2050 Renderbuffer *colorbuffer = framebuffer->getColorbuffer(0);
2056 case GL_RED_BITS: *params = colorbuffer->getRedSize(); return true;
2057 case GL_GREEN_BITS: *params = colorbuffer->getGreenSize(); return true;
2058 case GL_BLUE_BITS: *params = colorbuffer->getBlueSize(); return true;
2059 case GL_ALPHA_BITS: *params = colorbuffer->getAlphaSize(); return true;
2070 Framebuffer *framebuffer = getDrawFramebuffer();
2071 Renderbuffer *depthbuffer = framebuffer->getDepthbuffer();
2075 *params = depthbuffer->getDepthSize();
2083 case GL_STENCIL_BITS:
2085 Framebuffer *framebuffer = getDrawFramebuffer();
2086 Renderbuffer *stencilbuffer = framebuffer->getStencilbuffer();
2090 *params = stencilbuffer->getStencilSize();
2098 case GL_TEXTURE_BINDING_2D:
2099 if(mState.activeSampler > MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1)
2101 error(GL_INVALID_OPERATION);
2105 *params = mState.samplerTexture[TEXTURE_2D][mState.activeSampler].name();
2107 case GL_TEXTURE_BINDING_CUBE_MAP:
2108 if(mState.activeSampler > MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1)
2110 error(GL_INVALID_OPERATION);
2114 *params = mState.samplerTexture[TEXTURE_CUBE][mState.activeSampler].name();
2116 case GL_TEXTURE_BINDING_EXTERNAL_OES:
2117 if(mState.activeSampler > MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1)
2119 error(GL_INVALID_OPERATION);
2123 *params = mState.samplerTexture[TEXTURE_EXTERNAL][mState.activeSampler].name();
2125 case GL_TEXTURE_BINDING_3D_OES:
2126 if(mState.activeSampler > MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1)
2128 error(GL_INVALID_OPERATION);
2132 *params = mState.samplerTexture[TEXTURE_3D][mState.activeSampler].name();
2134 case GL_DRAW_BUFFER0:
2135 case GL_DRAW_BUFFER1:
2136 case GL_DRAW_BUFFER2:
2137 case GL_DRAW_BUFFER3:
2138 case GL_DRAW_BUFFER4:
2139 case GL_DRAW_BUFFER5:
2140 case GL_DRAW_BUFFER6:
2141 case GL_DRAW_BUFFER7:
2142 case GL_DRAW_BUFFER8:
2143 case GL_DRAW_BUFFER9:
2144 case GL_DRAW_BUFFER10:
2145 case GL_DRAW_BUFFER11:
2146 case GL_DRAW_BUFFER12:
2147 case GL_DRAW_BUFFER13:
2148 case GL_DRAW_BUFFER14:
2149 case GL_DRAW_BUFFER15:
2150 if((pname - GL_DRAW_BUFFER0) < MAX_DRAW_BUFFERS)
2152 *params = getDrawFramebuffer()->getDrawBuffer(pname - GL_DRAW_BUFFER0);
2159 case GL_MAX_DRAW_BUFFERS:
2160 *params = MAX_DRAW_BUFFERS;
2162 case GL_MAX_COLOR_ATTACHMENTS: // Note: MAX_COLOR_ATTACHMENTS_EXT added by GL_EXT_draw_buffers
2163 *params = MAX_COLOR_ATTACHMENTS;
2169 if(clientVersion >= 3)
2173 case GL_TEXTURE_BINDING_2D_ARRAY:
2174 if(mState.activeSampler > MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1)
2176 error(GL_INVALID_OPERATION);
2180 *params = mState.samplerTexture[TEXTURE_2D_ARRAY][mState.activeSampler].name();
2182 case GL_COPY_READ_BUFFER_BINDING:
2183 *params = mState.copyReadBuffer.name();
2185 case GL_COPY_WRITE_BUFFER_BINDING:
2186 *params = mState.copyWriteBuffer.name();
2188 case GL_MAJOR_VERSION:
2189 *params = clientVersion;
2191 case GL_MAX_3D_TEXTURE_SIZE:
2192 *params = IMPLEMENTATION_MAX_TEXTURE_SIZE;
2194 case GL_MAX_ARRAY_TEXTURE_LAYERS:
2195 *params = IMPLEMENTATION_MAX_TEXTURE_SIZE;
2197 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
2198 *params = MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS;
2200 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
2201 *params = MAX_VERTEX_UNIFORM_BLOCKS + MAX_FRAGMENT_UNIFORM_BLOCKS;
2203 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
2204 *params = MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS;
2206 case GL_MAX_ELEMENT_INDEX:
2207 *params = MAX_ELEMENT_INDEX;
2209 case GL_MAX_ELEMENTS_INDICES:
2210 *params = MAX_ELEMENTS_INDICES;
2212 case GL_MAX_ELEMENTS_VERTICES:
2213 *params = MAX_ELEMENTS_VERTICES;
2215 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
2216 *params = MAX_FRAGMENT_INPUT_VECTORS * 4;
2218 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
2219 *params = MAX_FRAGMENT_UNIFORM_BLOCKS;
2221 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
2222 *params = MAX_FRAGMENT_UNIFORM_COMPONENTS;
2224 case GL_MAX_PROGRAM_TEXEL_OFFSET:
2225 // Note: SwiftShader has no actual texel offset limit, so this limit can be modified if required.
2226 // In any case, any behavior outside the specified range is valid since the spec mentions:
2227 // (see OpenGL ES 3.0.5, 3.8.10.1 Scale Factor and Level of Detail, p.153)
2228 // "If any of the offset values are outside the range of the implementation-defined values
2229 // MIN_PROGRAM_TEXEL_OFFSET and MAX_PROGRAM_TEXEL_OFFSET, results of the texture lookup are
2231 *params = MAX_PROGRAM_TEXEL_OFFSET;
2233 case GL_MAX_SERVER_WAIT_TIMEOUT:
2236 case GL_MAX_TEXTURE_LOD_BIAS:
2237 *params = MAX_TEXTURE_LOD_BIAS;
2239 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
2240 *params = sw::MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS;
2242 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
2243 *params = MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS;
2245 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
2246 *params = sw::MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS;
2248 case GL_MAX_UNIFORM_BLOCK_SIZE:
2249 *params = MAX_UNIFORM_BLOCK_SIZE;
2251 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
2252 *params = MAX_UNIFORM_BUFFER_BINDINGS;
2254 case GL_MAX_VARYING_COMPONENTS:
2255 *params = MAX_VARYING_VECTORS * 4;
2257 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
2258 *params = MAX_VERTEX_OUTPUT_VECTORS * 4;
2260 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
2261 *params = MAX_VERTEX_UNIFORM_BLOCKS;
2263 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
2264 *params = MAX_VERTEX_UNIFORM_COMPONENTS;
2266 case GL_MIN_PROGRAM_TEXEL_OFFSET:
2267 // Note: SwiftShader has no actual texel offset limit, so this limit can be modified if required.
2268 // In any case, any behavior outside the specified range is valid since the spec mentions:
2269 // (see OpenGL ES 3.0.5, 3.8.10.1 Scale Factor and Level of Detail, p.153)
2270 // "If any of the offset values are outside the range of the implementation-defined values
2271 // MIN_PROGRAM_TEXEL_OFFSET and MAX_PROGRAM_TEXEL_OFFSET, results of the texture lookup are
2273 *params = MIN_PROGRAM_TEXEL_OFFSET;
2275 case GL_MINOR_VERSION:
2278 case GL_NUM_EXTENSIONS:
2279 GLuint numExtensions;
2280 getExtensions(0, &numExtensions);
2281 *params = numExtensions;
2283 case GL_NUM_PROGRAM_BINARY_FORMATS:
2284 *params = NUM_PROGRAM_BINARY_FORMATS;
2286 case GL_PACK_ROW_LENGTH:
2287 *params = mState.packRowLength;
2289 case GL_PACK_SKIP_PIXELS:
2290 *params = mState.packSkipPixels;
2292 case GL_PACK_SKIP_ROWS:
2293 *params = mState.packSkipRows;
2295 case GL_PIXEL_PACK_BUFFER_BINDING:
2296 *params = mState.pixelPackBuffer.name();
2298 case GL_PIXEL_UNPACK_BUFFER_BINDING:
2299 *params = mState.pixelUnpackBuffer.name();
2301 case GL_PROGRAM_BINARY_FORMATS:
2302 // Since NUM_PROGRAM_BINARY_FORMATS is 0, the input
2303 // should be a 0 sized array, so don't write to params
2305 case GL_READ_BUFFER:
2306 *params = getReadFramebuffer()->getReadBuffer();
2308 case GL_SAMPLER_BINDING:
2309 *params = mState.sampler[mState.activeSampler].name();
2311 case GL_UNIFORM_BUFFER_BINDING:
2312 *params = mState.genericUniformBuffer.name();
2314 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
2315 *params = UNIFORM_BUFFER_OFFSET_ALIGNMENT;
2317 case GL_UNIFORM_BUFFER_SIZE:
2318 *params = static_cast<T>(mState.genericUniformBuffer->size());
2320 case GL_UNIFORM_BUFFER_START:
2321 *params = static_cast<T>(mState.genericUniformBuffer->offset());
2323 case GL_UNPACK_IMAGE_HEIGHT:
2324 *params = mState.unpackInfo.imageHeight;
2326 case GL_UNPACK_ROW_LENGTH:
2327 *params = mState.unpackInfo.rowLength;
2329 case GL_UNPACK_SKIP_IMAGES:
2330 *params = mState.unpackInfo.skipImages;
2332 case GL_UNPACK_SKIP_PIXELS:
2333 *params = mState.unpackInfo.skipPixels;
2335 case GL_UNPACK_SKIP_ROWS:
2336 *params = mState.unpackInfo.skipRows;
2338 case GL_VERTEX_ARRAY_BINDING:
2339 *params = getCurrentVertexArray()->name;
2341 case GL_TRANSFORM_FEEDBACK_BINDING:
2343 TransformFeedback* transformFeedback = getTransformFeedback(mState.transformFeedback);
2344 if(transformFeedback)
2346 *params = transformFeedback->name;
2354 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
2356 TransformFeedback* transformFeedback = getTransformFeedback(mState.transformFeedback);
2357 if(transformFeedback)
2359 *params = transformFeedback->getGenericBufferName();
2375 template bool Context::getTransformFeedbackiv<GLint>(GLuint index, GLenum pname, GLint *param) const;
2376 template bool Context::getTransformFeedbackiv<GLint64>(GLuint index, GLenum pname, GLint64 *param) const;
2378 template<typename T> bool Context::getTransformFeedbackiv(GLuint index, GLenum pname, T *param) const
2380 TransformFeedback* transformFeedback = getTransformFeedback(mState.transformFeedback);
2381 if(!transformFeedback)
2388 case GL_TRANSFORM_FEEDBACK_BINDING: // GLint, initially 0
2389 *param = transformFeedback->name;
2391 case GL_TRANSFORM_FEEDBACK_ACTIVE: // boolean, initially GL_FALSE
2392 *param = transformFeedback->isActive();
2394 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: // name, initially 0
2395 *param = transformFeedback->getBufferName(index);
2397 case GL_TRANSFORM_FEEDBACK_PAUSED: // boolean, initially GL_FALSE
2398 *param = transformFeedback->isPaused();
2400 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE: // indexed[n] 64-bit integer, initially 0
2401 if(transformFeedback->getBuffer(index))
2403 *param = transformFeedback->getSize(index);
2407 case GL_TRANSFORM_FEEDBACK_BUFFER_START: // indexed[n] 64-bit integer, initially 0
2408 if(transformFeedback->getBuffer(index))
2410 *param = transformFeedback->getOffset(index);
2421 template bool Context::getUniformBufferiv<GLint>(GLuint index, GLenum pname, GLint *param) const;
2422 template bool Context::getUniformBufferiv<GLint64>(GLuint index, GLenum pname, GLint64 *param) const;
2424 template<typename T> bool Context::getUniformBufferiv(GLuint index, GLenum pname, T *param) const
2428 case GL_UNIFORM_BUFFER_BINDING:
2429 case GL_UNIFORM_BUFFER_SIZE:
2430 case GL_UNIFORM_BUFFER_START:
2431 if(index >= MAX_UNIFORM_BUFFER_BINDINGS)
2433 return error(GL_INVALID_VALUE, true);
2440 const BufferBinding& uniformBuffer = mState.uniformBuffers[index];
2444 case GL_UNIFORM_BUFFER_BINDING: // name, initially 0
2445 *param = uniformBuffer.get().name();
2447 case GL_UNIFORM_BUFFER_SIZE: // indexed[n] 64-bit integer, initially 0
2448 *param = uniformBuffer.getSize();
2450 case GL_UNIFORM_BUFFER_START: // indexed[n] 64-bit integer, initially 0
2451 *param = uniformBuffer.getOffset();
2460 bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams) const
2462 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
2463 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
2464 // to the fact that it is stored internally as a float, and so would require conversion
2465 // if returned from Context::getIntegerv. Since this conversion is already implemented
2466 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
2467 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
2471 case GL_COMPRESSED_TEXTURE_FORMATS:
2474 *numParams = NUM_COMPRESSED_TEXTURE_FORMATS;
2477 case GL_SHADER_BINARY_FORMATS:
2483 case GL_MAX_VERTEX_ATTRIBS:
2484 case GL_MAX_VERTEX_UNIFORM_VECTORS:
2485 case GL_MAX_VARYING_VECTORS:
2486 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
2487 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
2488 case GL_MAX_TEXTURE_IMAGE_UNITS:
2489 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
2490 case GL_MAX_RENDERBUFFER_SIZE:
2491 case GL_NUM_SHADER_BINARY_FORMATS:
2492 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
2493 case GL_ARRAY_BUFFER_BINDING:
2494 case GL_FRAMEBUFFER_BINDING: // Same as GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
2495 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
2496 case GL_RENDERBUFFER_BINDING:
2497 case GL_CURRENT_PROGRAM:
2498 case GL_PACK_ALIGNMENT:
2499 case GL_UNPACK_ALIGNMENT:
2500 case GL_GENERATE_MIPMAP_HINT:
2501 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
2502 case GL_TEXTURE_FILTERING_HINT_CHROMIUM:
2508 case GL_STENCIL_BITS:
2509 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
2510 case GL_CULL_FACE_MODE:
2512 case GL_ACTIVE_TEXTURE:
2513 case GL_STENCIL_FUNC:
2514 case GL_STENCIL_VALUE_MASK:
2515 case GL_STENCIL_REF:
2516 case GL_STENCIL_FAIL:
2517 case GL_STENCIL_PASS_DEPTH_FAIL:
2518 case GL_STENCIL_PASS_DEPTH_PASS:
2519 case GL_STENCIL_BACK_FUNC:
2520 case GL_STENCIL_BACK_VALUE_MASK:
2521 case GL_STENCIL_BACK_REF:
2522 case GL_STENCIL_BACK_FAIL:
2523 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
2524 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
2526 case GL_BLEND_SRC_RGB:
2527 case GL_BLEND_SRC_ALPHA:
2528 case GL_BLEND_DST_RGB:
2529 case GL_BLEND_DST_ALPHA:
2530 case GL_BLEND_EQUATION_RGB:
2531 case GL_BLEND_EQUATION_ALPHA:
2532 case GL_STENCIL_WRITEMASK:
2533 case GL_STENCIL_BACK_WRITEMASK:
2534 case GL_STENCIL_CLEAR_VALUE:
2535 case GL_SUBPIXEL_BITS:
2536 case GL_MAX_TEXTURE_SIZE:
2537 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
2538 case GL_SAMPLE_BUFFERS:
2540 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
2541 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
2542 case GL_TEXTURE_BINDING_2D:
2543 case GL_TEXTURE_BINDING_CUBE_MAP:
2544 case GL_TEXTURE_BINDING_EXTERNAL_OES:
2545 case GL_TEXTURE_BINDING_3D_OES:
2546 case GL_COPY_READ_BUFFER_BINDING:
2547 case GL_COPY_WRITE_BUFFER_BINDING:
2548 case GL_DRAW_BUFFER0:
2549 case GL_DRAW_BUFFER1:
2550 case GL_DRAW_BUFFER2:
2551 case GL_DRAW_BUFFER3:
2552 case GL_DRAW_BUFFER4:
2553 case GL_DRAW_BUFFER5:
2554 case GL_DRAW_BUFFER6:
2555 case GL_DRAW_BUFFER7:
2556 case GL_DRAW_BUFFER8:
2557 case GL_DRAW_BUFFER9:
2558 case GL_DRAW_BUFFER10:
2559 case GL_DRAW_BUFFER11:
2560 case GL_DRAW_BUFFER12:
2561 case GL_DRAW_BUFFER13:
2562 case GL_DRAW_BUFFER14:
2563 case GL_DRAW_BUFFER15:
2564 case GL_MAJOR_VERSION:
2565 case GL_MAX_3D_TEXTURE_SIZE:
2566 case GL_MAX_ARRAY_TEXTURE_LAYERS:
2567 case GL_MAX_COLOR_ATTACHMENTS:
2568 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
2569 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
2570 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
2571 case GL_MAX_DRAW_BUFFERS:
2572 case GL_MAX_ELEMENT_INDEX:
2573 case GL_MAX_ELEMENTS_INDICES:
2574 case GL_MAX_ELEMENTS_VERTICES:
2575 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
2576 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
2577 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
2578 case GL_MAX_PROGRAM_TEXEL_OFFSET:
2579 case GL_MAX_SERVER_WAIT_TIMEOUT:
2580 case GL_MAX_TEXTURE_LOD_BIAS:
2581 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
2582 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
2583 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
2584 case GL_MAX_UNIFORM_BLOCK_SIZE:
2585 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
2586 case GL_MAX_VARYING_COMPONENTS:
2587 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
2588 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
2589 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
2590 case GL_MIN_PROGRAM_TEXEL_OFFSET:
2591 case GL_MINOR_VERSION:
2592 case GL_NUM_EXTENSIONS:
2593 case GL_NUM_PROGRAM_BINARY_FORMATS:
2594 case GL_PACK_ROW_LENGTH:
2595 case GL_PACK_SKIP_PIXELS:
2596 case GL_PACK_SKIP_ROWS:
2597 case GL_PIXEL_PACK_BUFFER_BINDING:
2598 case GL_PIXEL_UNPACK_BUFFER_BINDING:
2599 case GL_PROGRAM_BINARY_FORMATS:
2600 case GL_READ_BUFFER:
2601 case GL_SAMPLER_BINDING:
2602 case GL_TEXTURE_BINDING_2D_ARRAY:
2603 case GL_UNIFORM_BUFFER_BINDING:
2604 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
2605 case GL_UNIFORM_BUFFER_SIZE:
2606 case GL_UNIFORM_BUFFER_START:
2607 case GL_UNPACK_IMAGE_HEIGHT:
2608 case GL_UNPACK_ROW_LENGTH:
2609 case GL_UNPACK_SKIP_IMAGES:
2610 case GL_UNPACK_SKIP_PIXELS:
2611 case GL_UNPACK_SKIP_ROWS:
2612 case GL_VERTEX_ARRAY_BINDING:
2613 case GL_TRANSFORM_FEEDBACK_BINDING:
2614 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
2620 case GL_MAX_SAMPLES_ANGLE:
2626 case GL_MAX_VIEWPORT_DIMS:
2633 case GL_SCISSOR_BOX:
2639 case GL_SHADER_COMPILER:
2640 case GL_SAMPLE_COVERAGE_INVERT:
2641 case GL_DEPTH_WRITEMASK:
2642 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
2643 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
2644 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as bool-natural
2645 case GL_SAMPLE_COVERAGE:
2646 case GL_SCISSOR_TEST:
2647 case GL_STENCIL_TEST:
2651 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
2652 case GL_RASTERIZER_DISCARD:
2653 case GL_TRANSFORM_FEEDBACK_ACTIVE:
2654 case GL_TRANSFORM_FEEDBACK_PAUSED:
2660 case GL_COLOR_WRITEMASK:
2666 case GL_POLYGON_OFFSET_FACTOR:
2667 case GL_POLYGON_OFFSET_UNITS:
2668 case GL_SAMPLE_COVERAGE_VALUE:
2669 case GL_DEPTH_CLEAR_VALUE:
2676 case GL_ALIASED_LINE_WIDTH_RANGE:
2677 case GL_ALIASED_POINT_SIZE_RANGE:
2678 case GL_DEPTH_RANGE:
2684 case GL_COLOR_CLEAR_VALUE:
2685 case GL_BLEND_COLOR:
2691 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
2702 void Context::applyScissor(int width, int height)
2704 if(mState.scissorTestEnabled)
2706 sw::Rect scissor = { mState.scissorX, mState.scissorY, mState.scissorX + mState.scissorWidth, mState.scissorY + mState.scissorHeight };
2707 scissor.clip(0, 0, width, height);
2709 device->setScissorRect(scissor);
2710 device->setScissorEnable(true);
2714 device->setScissorEnable(false);
2718 // Applies the render target surface, depth stencil surface, viewport rectangle and scissor rectangle
2719 bool Context::applyRenderTarget()
2721 Framebuffer *framebuffer = getDrawFramebuffer();
2722 int width, height, samples;
2724 if(!framebuffer || framebuffer->completeness(width, height, samples) != GL_FRAMEBUFFER_COMPLETE)
2726 return error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
2729 for(int i = 0; i < MAX_DRAW_BUFFERS; i++)
2731 if(framebuffer->getDrawBuffer(i) != GL_NONE)
2733 egl::Image *renderTarget = framebuffer->getRenderTarget(i);
2734 GLint layer = framebuffer->getColorbufferLayer(i);
2735 device->setRenderTarget(i, renderTarget, layer);
2736 if(renderTarget) renderTarget->release();
2740 device->setRenderTarget(i, nullptr, 0);
2744 egl::Image *depthBuffer = framebuffer->getDepthBuffer();
2745 GLint dLayer = framebuffer->getDepthbufferLayer();
2746 device->setDepthBuffer(depthBuffer, dLayer);
2747 if(depthBuffer) depthBuffer->release();
2749 egl::Image *stencilBuffer = framebuffer->getStencilBuffer();
2750 GLint sLayer = framebuffer->getStencilbufferLayer();
2751 device->setStencilBuffer(stencilBuffer, sLayer);
2752 if(stencilBuffer) stencilBuffer->release();
2755 float zNear = clamp01(mState.zNear);
2756 float zFar = clamp01(mState.zFar);
2758 viewport.x0 = mState.viewportX;
2759 viewport.y0 = mState.viewportY;
2760 viewport.width = mState.viewportWidth;
2761 viewport.height = mState.viewportHeight;
2762 viewport.minZ = zNear;
2763 viewport.maxZ = zFar;
2765 device->setViewport(viewport);
2767 applyScissor(width, height);
2769 Program *program = getCurrentProgram();
2773 GLfloat nearFarDiff[3] = {zNear, zFar, zFar - zNear};
2774 program->setUniform1fv(program->getUniformLocation("gl_DepthRange.near"), 1, &nearFarDiff[0]);
2775 program->setUniform1fv(program->getUniformLocation("gl_DepthRange.far"), 1, &nearFarDiff[1]);
2776 program->setUniform1fv(program->getUniformLocation("gl_DepthRange.diff"), 1, &nearFarDiff[2]);
2782 // Applies the fixed-function state (culling, depth test, alpha blending, stenciling, etc)
2783 void Context::applyState(GLenum drawMode)
2785 Framebuffer *framebuffer = getDrawFramebuffer();
2787 if(mState.cullFaceEnabled)
2789 device->setCullMode(es2sw::ConvertCullMode(mState.cullMode, mState.frontFace));
2793 device->setCullMode(sw::CULL_NONE);
2796 if(mDepthStateDirty)
2798 if(mState.depthTestEnabled)
2800 device->setDepthBufferEnable(true);
2801 device->setDepthCompare(es2sw::ConvertDepthComparison(mState.depthFunc));
2805 device->setDepthBufferEnable(false);
2808 mDepthStateDirty = false;
2811 if(mBlendStateDirty)
2813 if(mState.blendEnabled)
2815 device->setAlphaBlendEnable(true);
2816 device->setSeparateAlphaBlendEnable(true);
2818 device->setBlendConstant(es2sw::ConvertColor(mState.blendColor));
2820 device->setSourceBlendFactor(es2sw::ConvertBlendFunc(mState.sourceBlendRGB));
2821 device->setDestBlendFactor(es2sw::ConvertBlendFunc(mState.destBlendRGB));
2822 device->setBlendOperation(es2sw::ConvertBlendOp(mState.blendEquationRGB));
2824 device->setSourceBlendFactorAlpha(es2sw::ConvertBlendFunc(mState.sourceBlendAlpha));
2825 device->setDestBlendFactorAlpha(es2sw::ConvertBlendFunc(mState.destBlendAlpha));
2826 device->setBlendOperationAlpha(es2sw::ConvertBlendOp(mState.blendEquationAlpha));
2830 device->setAlphaBlendEnable(false);
2833 mBlendStateDirty = false;
2836 if(mStencilStateDirty || mFrontFaceDirty)
2838 if(mState.stencilTestEnabled && framebuffer->hasStencil())
2840 device->setStencilEnable(true);
2841 device->setTwoSidedStencil(true);
2843 // get the maximum size of the stencil ref
2844 Renderbuffer *stencilbuffer = framebuffer->getStencilbuffer();
2845 GLuint maxStencil = (1 << stencilbuffer->getStencilSize()) - 1;
2847 if(mState.frontFace == GL_CCW)
2849 device->setStencilWriteMask(mState.stencilWritemask);
2850 device->setStencilCompare(es2sw::ConvertStencilComparison(mState.stencilFunc));
2852 device->setStencilReference((mState.stencilRef < (GLint)maxStencil) ? mState.stencilRef : maxStencil);
2853 device->setStencilMask(mState.stencilMask);
2855 device->setStencilFailOperation(es2sw::ConvertStencilOp(mState.stencilFail));
2856 device->setStencilZFailOperation(es2sw::ConvertStencilOp(mState.stencilPassDepthFail));
2857 device->setStencilPassOperation(es2sw::ConvertStencilOp(mState.stencilPassDepthPass));
2859 device->setStencilWriteMaskCCW(mState.stencilBackWritemask);
2860 device->setStencilCompareCCW(es2sw::ConvertStencilComparison(mState.stencilBackFunc));
2862 device->setStencilReferenceCCW((mState.stencilBackRef < (GLint)maxStencil) ? mState.stencilBackRef : maxStencil);
2863 device->setStencilMaskCCW(mState.stencilBackMask);
2865 device->setStencilFailOperationCCW(es2sw::ConvertStencilOp(mState.stencilBackFail));
2866 device->setStencilZFailOperationCCW(es2sw::ConvertStencilOp(mState.stencilBackPassDepthFail));
2867 device->setStencilPassOperationCCW(es2sw::ConvertStencilOp(mState.stencilBackPassDepthPass));
2871 device->setStencilWriteMaskCCW(mState.stencilWritemask);
2872 device->setStencilCompareCCW(es2sw::ConvertStencilComparison(mState.stencilFunc));
2874 device->setStencilReferenceCCW((mState.stencilRef < (GLint)maxStencil) ? mState.stencilRef : maxStencil);
2875 device->setStencilMaskCCW(mState.stencilMask);
2877 device->setStencilFailOperationCCW(es2sw::ConvertStencilOp(mState.stencilFail));
2878 device->setStencilZFailOperationCCW(es2sw::ConvertStencilOp(mState.stencilPassDepthFail));
2879 device->setStencilPassOperationCCW(es2sw::ConvertStencilOp(mState.stencilPassDepthPass));
2881 device->setStencilWriteMask(mState.stencilBackWritemask);
2882 device->setStencilCompare(es2sw::ConvertStencilComparison(mState.stencilBackFunc));
2884 device->setStencilReference((mState.stencilBackRef < (GLint)maxStencil) ? mState.stencilBackRef : maxStencil);
2885 device->setStencilMask(mState.stencilBackMask);
2887 device->setStencilFailOperation(es2sw::ConvertStencilOp(mState.stencilBackFail));
2888 device->setStencilZFailOperation(es2sw::ConvertStencilOp(mState.stencilBackPassDepthFail));
2889 device->setStencilPassOperation(es2sw::ConvertStencilOp(mState.stencilBackPassDepthPass));
2894 device->setStencilEnable(false);
2897 mStencilStateDirty = false;
2898 mFrontFaceDirty = false;
2903 for(int i = 0; i < MAX_DRAW_BUFFERS; i++)
2905 device->setColorWriteMask(i, es2sw::ConvertColorMask(mState.colorMaskRed, mState.colorMaskGreen, mState.colorMaskBlue, mState.colorMaskAlpha));
2908 device->setDepthWriteEnable(mState.depthMask);
2910 mMaskStateDirty = false;
2913 if(mPolygonOffsetStateDirty)
2915 if(mState.polygonOffsetFillEnabled)
2917 Renderbuffer *depthbuffer = framebuffer->getDepthbuffer();
2920 device->setSlopeDepthBias(mState.polygonOffsetFactor);
2921 float depthBias = ldexp(mState.polygonOffsetUnits, -23); // We use 32-bit floating-point for all depth formats, with 23 mantissa bits.
2922 device->setDepthBias(depthBias);
2927 device->setSlopeDepthBias(0);
2928 device->setDepthBias(0);
2931 mPolygonOffsetStateDirty = false;
2934 if(mSampleStateDirty)
2936 if(mState.sampleAlphaToCoverageEnabled)
2938 device->setTransparencyAntialiasing(sw::TRANSPARENCY_ALPHA_TO_COVERAGE);
2942 device->setTransparencyAntialiasing(sw::TRANSPARENCY_NONE);
2945 if(mState.sampleCoverageEnabled)
2947 unsigned int mask = 0;
2948 if(mState.sampleCoverageValue != 0)
2950 int width, height, samples;
2951 framebuffer->completeness(width, height, samples);
2953 float threshold = 0.5f;
2955 for(int i = 0; i < samples; i++)
2959 if((i + 1) * mState.sampleCoverageValue >= threshold)
2967 if(mState.sampleCoverageInvert)
2972 device->setMultiSampleMask(mask);
2976 device->setMultiSampleMask(0xFFFFFFFF);
2979 mSampleStateDirty = false;
2982 if(mDitherStateDirty)
2984 // UNIMPLEMENTED(); // FIXME
2986 mDitherStateDirty = false;
2989 device->setRasterizerDiscard(mState.rasterizerDiscardEnabled);
2992 GLenum Context::applyVertexBuffer(GLint base, GLint first, GLsizei count, GLsizei instanceId)
2994 TranslatedAttribute attributes[MAX_VERTEX_ATTRIBS];
2996 GLenum err = mVertexDataManager->prepareVertexData(first, count, attributes, instanceId);
2997 if(err != GL_NO_ERROR)
3002 Program *program = getCurrentProgram();
3004 device->resetInputStreams(false);
3006 for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
3008 if(program->getAttributeStream(i) == -1)
3013 sw::Resource *resource = attributes[i].vertexBuffer;
3014 const void *buffer = (char*)resource->data() + attributes[i].offset;
3016 int stride = attributes[i].stride;
3018 buffer = (char*)buffer + stride * base;
3020 sw::Stream attribute(resource, buffer, stride);
3022 attribute.type = attributes[i].type;
3023 attribute.count = attributes[i].count;
3024 attribute.normalized = attributes[i].normalized;
3026 int stream = program->getAttributeStream(i);
3027 device->setInputStream(stream, attribute);
3033 // Applies the indices and element array bindings
3034 GLenum Context::applyIndexBuffer(const void *indices, GLuint start, GLuint end, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo)
3036 GLenum err = mIndexDataManager->prepareIndexData(mode, type, start, end, count, getCurrentVertexArray()->getElementArrayBuffer(), indices, indexInfo, isPrimitiveRestartFixedIndexEnabled());
3038 if(err == GL_NO_ERROR)
3040 device->setIndexBuffer(indexInfo->indexBuffer);
3046 // Applies the shaders and shader constants
3047 void Context::applyShaders()
3049 Program *programObject = getCurrentProgram();
3050 sw::VertexShader *vertexShader = programObject->getVertexShader();
3051 sw::PixelShader *pixelShader = programObject->getPixelShader();
3053 device->setVertexShader(vertexShader);
3054 device->setPixelShader(pixelShader);
3056 if(programObject->getSerial() != mAppliedProgramSerial)
3058 programObject->dirtyAllUniforms();
3059 mAppliedProgramSerial = programObject->getSerial();
3062 programObject->applyTransformFeedback(device, getTransformFeedback());
3063 programObject->applyUniformBuffers(device, mState.uniformBuffers);
3064 programObject->applyUniforms(device);
3067 void Context::applyTextures()
3069 applyTextures(sw::SAMPLER_PIXEL);
3070 applyTextures(sw::SAMPLER_VERTEX);
3073 void Context::applyTextures(sw::SamplerType samplerType)
3075 Program *programObject = getCurrentProgram();
3077 int samplerCount = (samplerType == sw::SAMPLER_PIXEL) ? MAX_TEXTURE_IMAGE_UNITS : MAX_VERTEX_TEXTURE_IMAGE_UNITS; // Range of samplers of given sampler type
3079 for(int samplerIndex = 0; samplerIndex < samplerCount; samplerIndex++)
3081 int textureUnit = programObject->getSamplerMapping(samplerType, samplerIndex); // OpenGL texture image unit index
3083 if(textureUnit != -1)
3085 TextureType textureType = programObject->getSamplerTextureType(samplerType, samplerIndex);
3087 Texture *texture = getSamplerTexture(textureUnit, textureType);
3089 if(texture->isSamplerComplete())
3091 GLenum wrapS, wrapT, wrapR, minFilter, magFilter, compFunc, compMode;
3092 GLfloat minLOD, maxLOD;
3094 Sampler *samplerObject = mState.sampler[textureUnit];
3097 wrapS = samplerObject->getWrapS();
3098 wrapT = samplerObject->getWrapT();
3099 wrapR = samplerObject->getWrapR();
3100 minFilter = samplerObject->getMinFilter();
3101 magFilter = samplerObject->getMagFilter();
3102 minLOD = samplerObject->getMinLod();
3103 maxLOD = samplerObject->getMaxLod();
3104 compFunc = samplerObject->getCompareFunc();
3105 compMode = samplerObject->getCompareMode();
3109 wrapS = texture->getWrapS();
3110 wrapT = texture->getWrapT();
3111 wrapR = texture->getWrapR();
3112 minFilter = texture->getMinFilter();
3113 magFilter = texture->getMagFilter();
3114 minLOD = texture->getMinLOD();
3115 maxLOD = texture->getMaxLOD();
3116 compFunc = texture->getCompareFunc();
3117 compMode = texture->getCompareMode();
3120 GLfloat maxAnisotropy = texture->getMaxAnisotropy();
3121 GLint baseLevel = texture->getBaseLevel();
3122 GLint maxLevel = texture->getMaxLevel();
3123 GLenum swizzleR = texture->getSwizzleR();
3124 GLenum swizzleG = texture->getSwizzleG();
3125 GLenum swizzleB = texture->getSwizzleB();
3126 GLenum swizzleA = texture->getSwizzleA();
3128 device->setAddressingModeU(samplerType, samplerIndex, es2sw::ConvertTextureWrap(wrapS));
3129 device->setAddressingModeV(samplerType, samplerIndex, es2sw::ConvertTextureWrap(wrapT));
3130 device->setAddressingModeW(samplerType, samplerIndex, es2sw::ConvertTextureWrap(wrapR));
3131 device->setCompareFunc(samplerType, samplerIndex, es2sw::ConvertCompareFunc(compFunc, compMode));
3132 device->setSwizzleR(samplerType, samplerIndex, es2sw::ConvertSwizzleType(swizzleR));
3133 device->setSwizzleG(samplerType, samplerIndex, es2sw::ConvertSwizzleType(swizzleG));
3134 device->setSwizzleB(samplerType, samplerIndex, es2sw::ConvertSwizzleType(swizzleB));
3135 device->setSwizzleA(samplerType, samplerIndex, es2sw::ConvertSwizzleType(swizzleA));
3136 device->setMinLod(samplerType, samplerIndex, minLOD);
3137 device->setMaxLod(samplerType, samplerIndex, maxLOD);
3138 device->setBaseLevel(samplerType, samplerIndex, baseLevel);
3139 device->setMaxLevel(samplerType, samplerIndex, maxLevel);
3140 device->setTextureFilter(samplerType, samplerIndex, es2sw::ConvertTextureFilter(minFilter, magFilter, maxAnisotropy));
3141 device->setMipmapFilter(samplerType, samplerIndex, es2sw::ConvertMipMapFilter(minFilter));
3142 device->setMaxAnisotropy(samplerType, samplerIndex, maxAnisotropy);
3143 device->setHighPrecisionFiltering(samplerType, samplerIndex, mState.textureFilteringHint == GL_NICEST);
3145 applyTexture(samplerType, samplerIndex, texture);
3149 applyTexture(samplerType, samplerIndex, nullptr);
3154 applyTexture(samplerType, samplerIndex, nullptr);
3159 void Context::applyTexture(sw::SamplerType type, int index, Texture *baseTexture)
3161 Program *program = getCurrentProgram();
3162 int sampler = (type == sw::SAMPLER_PIXEL) ? index : 16 + index;
3163 bool textureUsed = false;
3165 if(type == sw::SAMPLER_PIXEL)
3167 textureUsed = program->getPixelShader()->usesSampler(index);
3169 else if(type == sw::SAMPLER_VERTEX)
3171 textureUsed = program->getVertexShader()->usesSampler(index);
3173 else UNREACHABLE(type);
3175 sw::Resource *resource = nullptr;
3177 if(baseTexture && textureUsed)
3179 resource = baseTexture->getResource();
3182 device->setTextureResource(sampler, resource);
3184 if(baseTexture && textureUsed)
3186 int baseLevel = baseTexture->getBaseLevel();
3187 int maxLevel = std::min(baseTexture->getTopLevel(), baseTexture->getMaxLevel());
3189 if(baseTexture->getTarget() == GL_TEXTURE_2D || baseTexture->getTarget() == GL_TEXTURE_EXTERNAL_OES)
3191 Texture2D *texture = static_cast<Texture2D*>(baseTexture);
3193 for(int mipmapLevel = 0; mipmapLevel < sw::MIPMAP_LEVELS; mipmapLevel++)
3195 int surfaceLevel = mipmapLevel + baseLevel;
3197 if(surfaceLevel > maxLevel)
3199 surfaceLevel = maxLevel;
3202 egl::Image *surface = texture->getImage(surfaceLevel);
3203 device->setTextureLevel(sampler, 0, mipmapLevel, surface, sw::TEXTURE_2D);
3206 else if(baseTexture->getTarget() == GL_TEXTURE_3D)
3208 Texture3D *texture = static_cast<Texture3D*>(baseTexture);
3210 for(int mipmapLevel = 0; mipmapLevel < sw::MIPMAP_LEVELS; mipmapLevel++)
3212 int surfaceLevel = mipmapLevel + baseLevel;
3214 if(surfaceLevel > maxLevel)
3216 surfaceLevel = maxLevel;
3219 egl::Image *surface = texture->getImage(surfaceLevel);
3220 device->setTextureLevel(sampler, 0, mipmapLevel, surface, sw::TEXTURE_3D);
3223 else if(baseTexture->getTarget() == GL_TEXTURE_2D_ARRAY)
3225 Texture2DArray *texture = static_cast<Texture2DArray*>(baseTexture);
3227 for(int mipmapLevel = 0; mipmapLevel < sw::MIPMAP_LEVELS; mipmapLevel++)
3229 int surfaceLevel = mipmapLevel + baseLevel;
3231 if(surfaceLevel > maxLevel)
3233 surfaceLevel = maxLevel;
3236 egl::Image *surface = texture->getImage(surfaceLevel);
3237 device->setTextureLevel(sampler, 0, mipmapLevel, surface, sw::TEXTURE_2D_ARRAY);
3240 else if(baseTexture->getTarget() == GL_TEXTURE_CUBE_MAP)
3242 TextureCubeMap *cubeTexture = static_cast<TextureCubeMap*>(baseTexture);
3244 for(int mipmapLevel = 0; mipmapLevel < sw::MIPMAP_LEVELS; mipmapLevel++)
3246 cubeTexture->updateBorders(mipmapLevel);
3248 for(int face = 0; face < 6; face++)
3250 int surfaceLevel = mipmapLevel + baseLevel;
3252 if(surfaceLevel > maxLevel)
3254 surfaceLevel = maxLevel;
3257 egl::Image *surface = cubeTexture->getImage(face, surfaceLevel);
3258 device->setTextureLevel(sampler, face, mipmapLevel, surface, sw::TEXTURE_CUBE);
3262 else UNIMPLEMENTED();
3266 device->setTextureLevel(sampler, 0, 0, 0, sw::TEXTURE_NULL);
3270 void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels)
3272 Framebuffer *framebuffer = getReadFramebuffer();
3273 int framebufferWidth, framebufferHeight, framebufferSamples;
3275 if(framebuffer->completeness(framebufferWidth, framebufferHeight, framebufferSamples) != GL_FRAMEBUFFER_COMPLETE)
3277 return error(GL_INVALID_FRAMEBUFFER_OPERATION);
3280 if(getReadFramebufferName() != 0 && framebufferSamples != 0)
3282 return error(GL_INVALID_OPERATION);
3285 if(!IsValidReadPixelsFormatType(framebuffer, format, type, clientVersion))
3287 return error(GL_INVALID_OPERATION);
3290 GLsizei outputWidth = (mState.packRowLength > 0) ? mState.packRowLength : width;
3291 GLsizei outputPitch = egl::ComputePitch(outputWidth, format, type, mState.packAlignment);
3292 GLsizei outputHeight = (mState.packImageHeight == 0) ? height : mState.packImageHeight;
3293 pixels = getPixelPackBuffer() ? (unsigned char*)getPixelPackBuffer()->data() + (ptrdiff_t)pixels : (unsigned char*)pixels;
3294 pixels = ((char*)pixels) + egl::ComputePackingOffset(format, type, outputWidth, outputHeight, mState.packAlignment, mState.packSkipImages, mState.packSkipRows, mState.packSkipPixels);
3296 // Sized query sanity check
3299 int requiredSize = outputPitch * height;
3300 if(requiredSize > *bufSize)
3302 return error(GL_INVALID_OPERATION);
3306 egl::Image *renderTarget = nullptr;
3309 case GL_DEPTH_COMPONENT: // GL_NV_read_depth
3310 renderTarget = framebuffer->getDepthBuffer();
3313 renderTarget = framebuffer->getReadRenderTarget();
3319 return error(GL_INVALID_OPERATION);
3322 sw::RectF rect((float)x, (float)y, (float)(x + width), (float)(y + height));
3323 sw::Rect dstRect(0, 0, width, height);
3324 rect.clip(0.0f, 0.0f, (float)renderTarget->getWidth(), (float)renderTarget->getHeight());
3326 sw::Surface *externalSurface = sw::Surface::create(width, height, 1, egl::ConvertFormatType(format, type), pixels, outputPitch, outputPitch * outputHeight);
3327 sw::SliceRectF sliceRect(rect);
3328 sw::SliceRect dstSliceRect(dstRect);
3329 device->blit(renderTarget, sliceRect, externalSurface, dstSliceRect, false, false, false);
3330 delete externalSurface;
3332 renderTarget->release();
3335 void Context::clear(GLbitfield mask)
3337 if(mState.rasterizerDiscardEnabled)
3342 Framebuffer *framebuffer = getDrawFramebuffer();
3344 if(!framebuffer || framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
3346 return error(GL_INVALID_FRAMEBUFFER_OPERATION);
3349 if(!applyRenderTarget())
3354 if(mask & GL_COLOR_BUFFER_BIT)
3356 unsigned int rgbaMask = getColorMask();
3360 device->clearColor(mState.colorClearValue.red, mState.colorClearValue.green, mState.colorClearValue.blue, mState.colorClearValue.alpha, rgbaMask);
3364 if(mask & GL_DEPTH_BUFFER_BIT)
3366 if(mState.depthMask != 0)
3368 float depth = clamp01(mState.depthClearValue);
3369 device->clearDepth(depth);
3373 if(mask & GL_STENCIL_BUFFER_BIT)
3375 if(mState.stencilWritemask != 0)
3377 int stencil = mState.stencilClearValue & 0x000000FF;
3378 device->clearStencil(stencil, mState.stencilWritemask);
3383 void Context::clearColorBuffer(GLint drawbuffer, void *value, sw::Format format)
3385 unsigned int rgbaMask = getColorMask();
3386 if(rgbaMask && !mState.rasterizerDiscardEnabled)
3388 Framebuffer *framebuffer = getDrawFramebuffer();
3389 egl::Image *colorbuffer = framebuffer->getRenderTarget(drawbuffer);
3393 sw::Rect clearRect = colorbuffer->getRect();
3395 if(mState.scissorTestEnabled)
3397 clearRect.clip(mState.scissorX, mState.scissorY, mState.scissorX + mState.scissorWidth, mState.scissorY + mState.scissorHeight);
3400 device->clear(value, format, colorbuffer, clearRect, rgbaMask);
3402 colorbuffer->release();
3407 void Context::clearColorBuffer(GLint drawbuffer, const GLint *value)
3409 clearColorBuffer(drawbuffer, (void*)value, sw::FORMAT_A32B32G32R32I);
3412 void Context::clearColorBuffer(GLint drawbuffer, const GLuint *value)
3414 clearColorBuffer(drawbuffer, (void*)value, sw::FORMAT_A32B32G32R32UI);
3417 void Context::clearColorBuffer(GLint drawbuffer, const GLfloat *value)
3419 clearColorBuffer(drawbuffer, (void*)value, sw::FORMAT_A32B32G32R32F);
3422 void Context::clearDepthBuffer(const GLfloat value)
3424 if(mState.depthMask && !mState.rasterizerDiscardEnabled)
3426 Framebuffer *framebuffer = getDrawFramebuffer();
3427 egl::Image *depthbuffer = framebuffer->getDepthBuffer();
3431 float depth = clamp01(value);
3432 sw::Rect clearRect = depthbuffer->getRect();
3434 if(mState.scissorTestEnabled)
3436 clearRect.clip(mState.scissorX, mState.scissorY, mState.scissorX + mState.scissorWidth, mState.scissorY + mState.scissorHeight);
3439 depthbuffer->clearDepth(depth, clearRect.x0, clearRect.y0, clearRect.width(), clearRect.height());
3441 depthbuffer->release();
3446 void Context::clearStencilBuffer(const GLint value)
3448 if(mState.stencilWritemask && !mState.rasterizerDiscardEnabled)
3450 Framebuffer *framebuffer = getDrawFramebuffer();
3451 egl::Image *stencilbuffer = framebuffer->getStencilBuffer();
3455 unsigned char stencil = value < 0 ? 0 : static_cast<unsigned char>(value & 0x000000FF);
3456 sw::Rect clearRect = stencilbuffer->getRect();
3458 if(mState.scissorTestEnabled)
3460 clearRect.clip(mState.scissorX, mState.scissorY, mState.scissorX + mState.scissorWidth, mState.scissorY + mState.scissorHeight);
3463 stencilbuffer->clearStencil(stencil, static_cast<unsigned char>(mState.stencilWritemask), clearRect.x0, clearRect.y0, clearRect.width(), clearRect.height());
3465 stencilbuffer->release();
3470 void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
3472 sw::DrawType primitiveType;
3474 int verticesPerPrimitive;
3476 if(!es2sw::ConvertPrimitiveType(mode, count, GL_NONE, primitiveType, primitiveCount, verticesPerPrimitive))
3478 return error(GL_INVALID_ENUM);
3481 if(!applyRenderTarget())
3488 for(int i = 0; i < instanceCount; ++i)
3490 device->setInstanceID(i);
3492 GLenum err = applyVertexBuffer(0, first, count, i);
3493 if(err != GL_NO_ERROR)
3498 if(!mState.currentProgram)
3506 if(!getCurrentProgram()->validateSamplers(false))
3508 return error(GL_INVALID_OPERATION);
3511 if(primitiveCount <= 0)
3516 TransformFeedback* transformFeedback = getTransformFeedback();
3517 if(!cullSkipsDraw(mode) || (transformFeedback->isActive() && !transformFeedback->isPaused()))
3519 device->drawPrimitive(primitiveType, primitiveCount);
3521 if(transformFeedback)
3523 transformFeedback->addVertexOffset(primitiveCount * verticesPerPrimitive);
3528 void Context::drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLsizei instanceCount)
3530 if(!indices && !getCurrentVertexArray()->getElementArrayBuffer())
3532 return error(GL_INVALID_OPERATION);
3535 GLenum internalMode = mode;
3536 if(isPrimitiveRestartFixedIndexEnabled())
3540 case GL_TRIANGLE_FAN:
3541 case GL_TRIANGLE_STRIP:
3542 internalMode = GL_TRIANGLES;
3546 internalMode = GL_LINES;
3553 sw::DrawType primitiveType;
3555 int verticesPerPrimitive;
3557 if(!es2sw::ConvertPrimitiveType(internalMode, count, type, primitiveType, primitiveCount, verticesPerPrimitive))
3559 return error(GL_INVALID_ENUM);
3562 if(!applyRenderTarget())
3567 TranslatedIndexData indexInfo(primitiveCount);
3568 GLenum err = applyIndexBuffer(indices, start, end, count, mode, type, &indexInfo);
3569 if(err != GL_NO_ERROR)
3574 applyState(internalMode);
3576 for(int i = 0; i < instanceCount; ++i)
3578 device->setInstanceID(i);
3580 GLsizei vertexCount = indexInfo.maxIndex - indexInfo.minIndex + 1;
3581 err = applyVertexBuffer(-(int)indexInfo.minIndex, indexInfo.minIndex, vertexCount, i);
3582 if(err != GL_NO_ERROR)
3587 if(!mState.currentProgram)
3595 if(!getCurrentProgram()->validateSamplers(false))
3597 return error(GL_INVALID_OPERATION);
3600 if(primitiveCount <= 0)
3605 TransformFeedback* transformFeedback = getTransformFeedback();
3606 if(!cullSkipsDraw(internalMode) || (transformFeedback->isActive() && !transformFeedback->isPaused()))
3608 device->drawIndexedPrimitive(primitiveType, indexInfo.indexOffset, indexInfo.primitiveCount);
3610 if(transformFeedback)
3612 transformFeedback->addVertexOffset(indexInfo.primitiveCount * verticesPerPrimitive);
3617 void Context::blit(sw::Surface *source, const sw::SliceRect &sRect, sw::Surface *dest, const sw::SliceRect &dRect)
3619 sw::SliceRectF sRectF((float)sRect.x0, (float)sRect.y0, (float)sRect.x1, (float)sRect.y1, sRect.slice);
3620 device->blit(source, sRectF, dest, dRect, false);
3623 void Context::finish()
3628 void Context::flush()
3630 // We don't queue anything without processing it as fast as possible
3633 void Context::recordInvalidEnum()
3635 mInvalidEnum = true;
3638 void Context::recordInvalidValue()
3640 mInvalidValue = true;
3643 void Context::recordInvalidOperation()
3645 mInvalidOperation = true;
3648 void Context::recordOutOfMemory()
3650 mOutOfMemory = true;
3653 void Context::recordInvalidFramebufferOperation()
3655 mInvalidFramebufferOperation = true;
3658 // Get one of the recorded errors and clear its flag, if any.
3659 // [OpenGL ES 2.0.24] section 2.5 page 13.
3660 GLenum Context::getError()
3664 mInvalidEnum = false;
3666 return GL_INVALID_ENUM;
3671 mInvalidValue = false;
3673 return GL_INVALID_VALUE;
3676 if(mInvalidOperation)
3678 mInvalidOperation = false;
3680 return GL_INVALID_OPERATION;
3685 mOutOfMemory = false;
3687 return GL_OUT_OF_MEMORY;
3690 if(mInvalidFramebufferOperation)
3692 mInvalidFramebufferOperation = false;
3694 return GL_INVALID_FRAMEBUFFER_OPERATION;
3700 int Context::getSupportedMultisampleCount(int requested)
3704 for(int i = NUM_MULTISAMPLE_COUNTS - 1; i >= 0; i--)
3706 if(supported >= requested)
3711 supported = multisampleCount[i];
3717 void Context::detachBuffer(GLuint buffer)
3719 // [OpenGL ES 2.0.24] section 2.9 page 22:
3720 // If a buffer object is deleted while it is bound, all bindings to that object in the current context
3721 // (i.e. in the thread that called Delete-Buffers) are reset to zero.
3723 if(mState.copyReadBuffer.name() == buffer)
3725 mState.copyReadBuffer = nullptr;
3728 if(mState.copyWriteBuffer.name() == buffer)
3730 mState.copyWriteBuffer = nullptr;
3733 if(mState.pixelPackBuffer.name() == buffer)
3735 mState.pixelPackBuffer = nullptr;
3738 if(mState.pixelUnpackBuffer.name() == buffer)
3740 mState.pixelUnpackBuffer = nullptr;
3743 if(mState.genericUniformBuffer.name() == buffer)
3745 mState.genericUniformBuffer = nullptr;
3748 if(getArrayBufferName() == buffer)
3750 mState.arrayBuffer = nullptr;
3753 // Only detach from the current transform feedback
3754 TransformFeedback* currentTransformFeedback = getTransformFeedback();
3755 if(currentTransformFeedback)
3757 currentTransformFeedback->detachBuffer(buffer);
3760 // Only detach from the current vertex array
3761 VertexArray* currentVertexArray = getCurrentVertexArray();
3762 if(currentVertexArray)
3764 currentVertexArray->detachBuffer(buffer);
3767 for(int attribute = 0; attribute < MAX_VERTEX_ATTRIBS; attribute++)
3769 if(mState.vertexAttribute[attribute].mBoundBuffer.name() == buffer)
3771 mState.vertexAttribute[attribute].mBoundBuffer = nullptr;
3776 void Context::detachTexture(GLuint texture)
3778 // [OpenGL ES 2.0.24] section 3.8 page 84:
3779 // If a texture object is deleted, it is as if all texture units which are bound to that texture object are
3780 // rebound to texture object zero
3782 for(int type = 0; type < TEXTURE_TYPE_COUNT; type++)
3784 for(int sampler = 0; sampler < MAX_COMBINED_TEXTURE_IMAGE_UNITS; sampler++)
3786 if(mState.samplerTexture[type][sampler].name() == texture)
3788 mState.samplerTexture[type][sampler] = nullptr;
3793 // [OpenGL ES 2.0.24] section 4.4 page 112:
3794 // If a texture object is deleted while its image is attached to the currently bound framebuffer, then it is
3795 // as if FramebufferTexture2D had been called, with a texture of 0, for each attachment point to which this
3796 // image was attached in the currently bound framebuffer.
3798 Framebuffer *readFramebuffer = getReadFramebuffer();
3799 Framebuffer *drawFramebuffer = getDrawFramebuffer();
3803 readFramebuffer->detachTexture(texture);
3806 if(drawFramebuffer && drawFramebuffer != readFramebuffer)
3808 drawFramebuffer->detachTexture(texture);
3812 void Context::detachFramebuffer(GLuint framebuffer)
3814 // [OpenGL ES 2.0.24] section 4.4 page 107:
3815 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as though
3816 // BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of zero.
3818 if(mState.readFramebuffer == framebuffer)
3820 bindReadFramebuffer(0);
3823 if(mState.drawFramebuffer == framebuffer)
3825 bindDrawFramebuffer(0);
3829 void Context::detachRenderbuffer(GLuint renderbuffer)
3831 // [OpenGL ES 2.0.24] section 4.4 page 109:
3832 // If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though BindRenderbuffer
3833 // had been executed with the target RENDERBUFFER and name of zero.
3835 if(mState.renderbuffer.name() == renderbuffer)
3837 bindRenderbuffer(0);
3840 // [OpenGL ES 2.0.24] section 4.4 page 111:
3841 // If a renderbuffer object is deleted while its image is attached to the currently bound framebuffer,
3842 // then it is as if FramebufferRenderbuffer had been called, with a renderbuffer of 0, for each attachment
3843 // point to which this image was attached in the currently bound framebuffer.
3845 Framebuffer *readFramebuffer = getReadFramebuffer();
3846 Framebuffer *drawFramebuffer = getDrawFramebuffer();
3850 readFramebuffer->detachRenderbuffer(renderbuffer);
3853 if(drawFramebuffer && drawFramebuffer != readFramebuffer)
3855 drawFramebuffer->detachRenderbuffer(renderbuffer);
3859 void Context::detachSampler(GLuint sampler)
3861 // [OpenGL ES 3.0.2] section 3.8.2 pages 123-124:
3862 // If a sampler object that is currently bound to one or more texture units is
3863 // deleted, it is as though BindSampler is called once for each texture unit to
3864 // which the sampler is bound, with unit set to the texture unit and sampler set to zero.
3865 for(size_t textureUnit = 0; textureUnit < MAX_COMBINED_TEXTURE_IMAGE_UNITS; ++textureUnit)
3867 gl::BindingPointer<Sampler> &samplerBinding = mState.sampler[textureUnit];
3868 if(samplerBinding.name() == sampler)
3870 samplerBinding = nullptr;
3875 bool Context::cullSkipsDraw(GLenum drawMode)
3877 return mState.cullFaceEnabled && mState.cullMode == GL_FRONT_AND_BACK && isTriangleMode(drawMode);
3880 bool Context::isTriangleMode(GLenum drawMode)
3885 case GL_TRIANGLE_FAN:
3886 case GL_TRIANGLE_STRIP:
3893 default: UNREACHABLE(drawMode);
3899 void Context::setVertexAttrib(GLuint index, const GLfloat *values)
3901 ASSERT(index < MAX_VERTEX_ATTRIBS);
3903 mState.vertexAttribute[index].setCurrentValue(values);
3905 mVertexDataManager->dirtyCurrentValue(index);
3908 void Context::setVertexAttrib(GLuint index, const GLint *values)
3910 ASSERT(index < MAX_VERTEX_ATTRIBS);
3912 mState.vertexAttribute[index].setCurrentValue(values);
3914 mVertexDataManager->dirtyCurrentValue(index);
3917 void Context::setVertexAttrib(GLuint index, const GLuint *values)
3919 ASSERT(index < MAX_VERTEX_ATTRIBS);
3921 mState.vertexAttribute[index].setCurrentValue(values);
3923 mVertexDataManager->dirtyCurrentValue(index);
3926 void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
3927 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
3928 GLbitfield mask, bool filter, bool allowPartialDepthStencilBlit)
3930 Framebuffer *readFramebuffer = getReadFramebuffer();
3931 Framebuffer *drawFramebuffer = getDrawFramebuffer();
3933 int readBufferWidth, readBufferHeight, readBufferSamples;
3934 int drawBufferWidth, drawBufferHeight, drawBufferSamples;
3936 if(!readFramebuffer || readFramebuffer->completeness(readBufferWidth, readBufferHeight, readBufferSamples) != GL_FRAMEBUFFER_COMPLETE ||
3937 !drawFramebuffer || drawFramebuffer->completeness(drawBufferWidth, drawBufferHeight, drawBufferSamples) != GL_FRAMEBUFFER_COMPLETE)
3939 return error(GL_INVALID_FRAMEBUFFER_OPERATION);
3942 if(drawBufferSamples > 1)
3944 return error(GL_INVALID_OPERATION);
3947 sw::SliceRect sourceRect;
3948 sw::SliceRect destRect;
3949 bool flipX = (srcX0 < srcX1) ^ (dstX0 < dstX1);
3950 bool flipY = (srcY0 < srcY1) ^ (dstY0 < dstY1);
3954 sourceRect.x0 = srcX0;
3955 sourceRect.x1 = srcX1;
3959 sourceRect.x0 = srcX1;
3960 sourceRect.x1 = srcX0;
3965 destRect.x0 = dstX0;
3966 destRect.x1 = dstX1;
3970 destRect.x0 = dstX1;
3971 destRect.x1 = dstX0;
3976 sourceRect.y0 = srcY0;
3977 sourceRect.y1 = srcY1;
3981 sourceRect.y0 = srcY1;
3982 sourceRect.y1 = srcY0;
3987 destRect.y0 = dstY0;
3988 destRect.y1 = dstY1;
3992 destRect.y0 = dstY1;
3993 destRect.y1 = dstY0;
3996 sw::RectF sourceScissoredRect(static_cast<float>(sourceRect.x0), static_cast<float>(sourceRect.y0),
3997 static_cast<float>(sourceRect.x1), static_cast<float>(sourceRect.y1));
3998 sw::Rect destScissoredRect = destRect;
4000 if(mState.scissorTestEnabled) // Only write to parts of the destination framebuffer which pass the scissor test
4002 sw::Rect scissorRect(mState.scissorX, mState.scissorY, mState.scissorX + mState.scissorWidth, mState.scissorY + mState.scissorHeight);
4003 Device::ClipDstRect(sourceScissoredRect, destScissoredRect, scissorRect, flipX, flipY);
4006 sw::SliceRectF sourceTrimmedRect = sourceScissoredRect;
4007 sw::SliceRect destTrimmedRect = destScissoredRect;
4009 // The source & destination rectangles also may need to be trimmed if
4010 // they fall out of the bounds of the actual draw and read surfaces.
4011 sw::Rect sourceTrimRect(0, 0, readBufferWidth, readBufferHeight);
4012 Device::ClipSrcRect(sourceTrimmedRect, destTrimmedRect, sourceTrimRect, flipX, flipY);
4014 sw::Rect destTrimRect(0, 0, drawBufferWidth, drawBufferHeight);
4015 Device::ClipDstRect(sourceTrimmedRect, destTrimmedRect, destTrimRect, flipX, flipY);
4017 bool partialBufferCopy = false;
4019 if(sourceTrimmedRect.y1 - sourceTrimmedRect.y0 < readBufferHeight ||
4020 sourceTrimmedRect.x1 - sourceTrimmedRect.x0 < readBufferWidth ||
4021 destTrimmedRect.y1 - destTrimmedRect.y0 < drawBufferHeight ||
4022 destTrimmedRect.x1 - destTrimmedRect.x0 < drawBufferWidth ||
4023 sourceTrimmedRect.y0 != 0 || destTrimmedRect.y0 != 0 || sourceTrimmedRect.x0 != 0 || destTrimmedRect.x0 != 0)
4025 partialBufferCopy = true;
4028 bool sameBounds = (srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1);
4029 bool blitRenderTarget = false;
4030 bool blitDepth = false;
4031 bool blitStencil = false;
4033 if(mask & GL_COLOR_BUFFER_BIT)
4035 GLenum readColorbufferType = readFramebuffer->getReadBufferType();
4036 GLenum drawColorbufferType = drawFramebuffer->getColorbufferType(0);
4037 const bool validReadType = readColorbufferType == GL_TEXTURE_2D || Framebuffer::IsRenderbuffer(readColorbufferType);
4038 const bool validDrawType = drawColorbufferType == GL_TEXTURE_2D || Framebuffer::IsRenderbuffer(drawColorbufferType);
4039 if(!validReadType || !validDrawType)
4041 return error(GL_INVALID_OPERATION);
4044 if(partialBufferCopy && readBufferSamples > 1 && !sameBounds)
4046 return error(GL_INVALID_OPERATION);
4049 // The GL ES 3.0.2 spec (pg 193) states that:
4050 // 1) If the read buffer is fixed point format, the draw buffer must be as well
4051 // 2) If the read buffer is an unsigned integer format, the draw buffer must be
4053 // 3) If the read buffer is a signed integer format, the draw buffer must be as
4055 es2::Renderbuffer *readRenderbuffer = readFramebuffer->getReadColorbuffer();
4056 es2::Renderbuffer *drawRenderbuffer = drawFramebuffer->getColorbuffer(0);
4057 GLint readFormat = readRenderbuffer->getFormat();
4058 GLint drawFormat = drawRenderbuffer->getFormat();
4059 GLenum readComponentType = GetComponentType(readFormat, GL_COLOR_ATTACHMENT0);
4060 GLenum drawComponentType = GetComponentType(drawFormat, GL_COLOR_ATTACHMENT0);
4061 bool readFixedPoint = ((readComponentType == GL_UNSIGNED_NORMALIZED) ||
4062 (readComponentType == GL_SIGNED_NORMALIZED));
4063 bool drawFixedPoint = ((drawComponentType == GL_UNSIGNED_NORMALIZED) ||
4064 (drawComponentType == GL_SIGNED_NORMALIZED));
4065 bool readFixedOrFloat = (readFixedPoint || (readComponentType == GL_FLOAT));
4066 bool drawFixedOrFloat = (drawFixedPoint || (drawComponentType == GL_FLOAT));
4068 if(readFixedOrFloat != drawFixedOrFloat)
4070 return error(GL_INVALID_OPERATION);
4073 if((readComponentType == GL_UNSIGNED_INT) && (drawComponentType != GL_UNSIGNED_INT))
4075 return error(GL_INVALID_OPERATION);
4078 if((readComponentType == GL_INT) && (drawComponentType != GL_INT))
4080 return error(GL_INVALID_OPERATION);
4083 // Cannot filter integer data
4084 if(((readComponentType == GL_UNSIGNED_INT) || (readComponentType == GL_INT)) && filter)
4086 return error(GL_INVALID_OPERATION);
4089 if((readRenderbuffer->getSamples() > 0) &&
4090 (readRenderbuffer->getFormat() != drawRenderbuffer->getFormat()))
4092 return error(GL_INVALID_OPERATION);
4095 blitRenderTarget = true;
4098 if(mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
4100 Renderbuffer *readDSBuffer = nullptr;
4101 Renderbuffer *drawDSBuffer = nullptr;
4103 if(mask & GL_DEPTH_BUFFER_BIT)
4105 if(readFramebuffer->getDepthbuffer() && drawFramebuffer->getDepthbuffer())
4107 GLenum readDepthBufferType = readFramebuffer->getDepthbufferType();
4108 GLenum drawDepthBufferType = drawFramebuffer->getDepthbufferType();
4109 if((readDepthBufferType != drawDepthBufferType) &&
4110 !(Framebuffer::IsRenderbuffer(readDepthBufferType) && Framebuffer::IsRenderbuffer(drawDepthBufferType)))
4112 return error(GL_INVALID_OPERATION);
4116 readDSBuffer = readFramebuffer->getDepthbuffer();
4117 drawDSBuffer = drawFramebuffer->getDepthbuffer();
4119 if(readDSBuffer->getFormat() != drawDSBuffer->getFormat())
4121 return error(GL_INVALID_OPERATION);
4126 if(mask & GL_STENCIL_BUFFER_BIT)
4128 if(readFramebuffer->getStencilbuffer() && drawFramebuffer->getStencilbuffer())
4130 GLenum readStencilBufferType = readFramebuffer->getStencilbufferType();
4131 GLenum drawStencilBufferType = drawFramebuffer->getStencilbufferType();
4132 if((readStencilBufferType != drawStencilBufferType) &&
4133 !(Framebuffer::IsRenderbuffer(readStencilBufferType) && Framebuffer::IsRenderbuffer(drawStencilBufferType)))
4135 return error(GL_INVALID_OPERATION);
4139 readDSBuffer = readFramebuffer->getStencilbuffer();
4140 drawDSBuffer = drawFramebuffer->getStencilbuffer();
4142 if(readDSBuffer->getFormat() != drawDSBuffer->getFormat())
4144 return error(GL_INVALID_OPERATION);
4149 if(partialBufferCopy && !allowPartialDepthStencilBlit)
4151 ERR("Only whole-buffer depth and stencil blits are supported by ANGLE_framebuffer_blit.");
4152 return error(GL_INVALID_OPERATION); // Only whole-buffer copies are permitted
4155 // OpenGL ES 3.0.4 spec, p.199:
4156 // ...an INVALID_OPERATION error is generated if the formats of the read
4157 // and draw framebuffers are not identical or if the source and destination
4158 // rectangles are not defined with the same(X0, Y 0) and (X1, Y 1) bounds.
4159 // If SAMPLE_BUFFERS for the draw framebuffer is greater than zero, an
4160 // INVALID_OPERATION error is generated.
4161 if((drawDSBuffer && drawDSBuffer->getSamples() > 1) ||
4162 ((readDSBuffer && readDSBuffer->getSamples() > 1) &&
4163 (!sameBounds || (drawDSBuffer->getFormat() != readDSBuffer->getFormat()))))
4165 return error(GL_INVALID_OPERATION);
4169 if(blitRenderTarget || blitDepth || blitStencil)
4173 swap(destTrimmedRect.x0, destTrimmedRect.x1);
4177 swap(destTrimmedRect.y0, destTrimmedRect.y1);
4180 if(blitRenderTarget)
4182 egl::Image *readRenderTarget = readFramebuffer->getReadRenderTarget();
4183 egl::Image *drawRenderTarget = drawFramebuffer->getRenderTarget(0);
4185 bool success = device->stretchRect(readRenderTarget, &sourceTrimmedRect, drawRenderTarget, &destTrimmedRect, (filter ? Device::USE_FILTER : 0) | Device::COLOR_BUFFER);
4187 readRenderTarget->release();
4188 drawRenderTarget->release();
4192 ERR("BlitFramebuffer failed.");
4199 egl::Image *readRenderTarget = readFramebuffer->getDepthBuffer();
4200 egl::Image *drawRenderTarget = drawFramebuffer->getDepthBuffer();
4202 bool success = device->stretchRect(readRenderTarget, &sourceTrimmedRect, drawRenderTarget, &destTrimmedRect, (filter ? Device::USE_FILTER : 0) | Device::DEPTH_BUFFER);
4204 readRenderTarget->release();
4205 drawRenderTarget->release();
4209 ERR("BlitFramebuffer failed.");
4216 egl::Image *readRenderTarget = readFramebuffer->getStencilBuffer();
4217 egl::Image *drawRenderTarget = drawFramebuffer->getStencilBuffer();
4219 bool success = device->stretchRect(readRenderTarget, &sourceTrimmedRect, drawRenderTarget, &destTrimmedRect, (filter ? Device::USE_FILTER : 0) | Device::STENCIL_BUFFER);
4221 readRenderTarget->release();
4222 drawRenderTarget->release();
4226 ERR("BlitFramebuffer failed.");
4233 void Context::bindTexImage(gl::Surface *surface)
4235 es2::Texture2D *textureObject = getTexture2D();
4239 textureObject->bindTexImage(surface);
4243 EGLenum Context::validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel)
4245 GLenum textureTarget = GL_NONE;
4249 case EGL_GL_TEXTURE_2D_KHR:
4250 textureTarget = GL_TEXTURE_2D;
4252 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR:
4253 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR:
4254 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR:
4255 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR:
4256 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR:
4257 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR:
4258 textureTarget = GL_TEXTURE_CUBE_MAP;
4260 case EGL_GL_RENDERBUFFER_KHR:
4263 return EGL_BAD_PARAMETER;
4266 if(textureLevel >= es2::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
4268 return EGL_BAD_MATCH;
4271 if(textureTarget != GL_NONE)
4273 es2::Texture *texture = getTexture(name);
4275 if(!texture || texture->getTarget() != textureTarget)
4277 return EGL_BAD_PARAMETER;
4280 if(texture->isShared(textureTarget, textureLevel)) // Bound to an EGLSurface or already an EGLImage sibling
4282 return EGL_BAD_ACCESS;
4285 if(textureLevel != 0 && !texture->isSamplerComplete())
4287 return EGL_BAD_PARAMETER;
4290 if(textureLevel == 0 && !(texture->isSamplerComplete() && texture->getTopLevel() == 0))
4292 return EGL_BAD_PARAMETER;
4295 else if(target == EGL_GL_RENDERBUFFER_KHR)
4297 es2::Renderbuffer *renderbuffer = getRenderbuffer(name);
4301 return EGL_BAD_PARAMETER;
4304 if(renderbuffer->isShared()) // Already an EGLImage sibling
4306 return EGL_BAD_ACCESS;
4309 else UNREACHABLE(target);
4314 egl::Image *Context::createSharedImage(EGLenum target, GLuint name, GLuint textureLevel)
4316 GLenum textureTarget = GL_NONE;
4320 case EGL_GL_TEXTURE_2D_KHR: textureTarget = GL_TEXTURE_2D; break;
4321 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR: textureTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X; break;
4322 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR: textureTarget = GL_TEXTURE_CUBE_MAP_NEGATIVE_X; break;
4323 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR: textureTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_Y; break;
4324 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR: textureTarget = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; break;
4325 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR: textureTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_Z; break;
4326 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR: textureTarget = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; break;
4329 if(textureTarget != GL_NONE)
4331 es2::Texture *texture = getTexture(name);
4333 return texture->createSharedImage(textureTarget, textureLevel);
4335 else if(target == EGL_GL_RENDERBUFFER_KHR)
4337 es2::Renderbuffer *renderbuffer = getRenderbuffer(name);
4339 return renderbuffer->createSharedImage();
4341 else UNREACHABLE(target);
4346 egl::Image *Context::getSharedImage(GLeglImageOES image)
4348 return display->getSharedImage(image);
4351 Device *Context::getDevice()
4356 const GLubyte *Context::getExtensions(GLuint index, GLuint *numExt) const
4358 // Keep list sorted in following order:
4361 // Vendor extensions
4362 static const char *es2extensions[] =
4364 "GL_OES_compressed_ETC1_RGB8_texture",
4367 "GL_OES_depth_texture",
4368 "GL_OES_depth_texture_cube_map",
4370 "GL_OES_EGL_image_external",
4372 "GL_OES_element_index_uint",
4373 "GL_OES_framebuffer_object",
4374 "GL_OES_packed_depth_stencil",
4375 "GL_OES_rgb8_rgba8",
4376 "GL_OES_standard_derivatives",
4377 "GL_OES_texture_float",
4378 "GL_OES_texture_float_linear",
4379 "GL_OES_texture_half_float",
4380 "GL_OES_texture_half_float_linear",
4381 "GL_OES_texture_npot",
4382 "GL_OES_texture_3D",
4383 "GL_OES_vertex_half_float",
4384 "GL_EXT_blend_minmax",
4385 "GL_EXT_color_buffer_half_float",
4386 "GL_EXT_draw_buffers",
4387 "GL_EXT_instanced_arrays",
4388 "GL_EXT_occlusion_query_boolean",
4389 "GL_EXT_read_format_bgra",
4391 "GL_EXT_texture_compression_dxt1",
4393 "GL_EXT_texture_filter_anisotropic",
4394 "GL_EXT_texture_format_BGRA8888",
4395 "GL_EXT_texture_rg",
4397 "GL_KHR_texture_compression_astc_hdr",
4398 "GL_KHR_texture_compression_astc_ldr",
4400 "GL_ANGLE_framebuffer_blit",
4401 "GL_ANGLE_framebuffer_multisample",
4402 "GL_ANGLE_instanced_arrays",
4404 "GL_ANGLE_texture_compression_dxt3",
4405 "GL_ANGLE_texture_compression_dxt5",
4407 //"GL_APPLE_texture_format_BGRA8888",
4408 "GL_CHROMIUM_texture_filtering_hint",
4410 "GL_NV_framebuffer_blit",
4414 // Extensions exclusive to OpenGL ES 3.0 and above.
4415 static const char *es3extensions[] =
4417 "GL_EXT_color_buffer_float",
4420 GLuint numES2extensions = sizeof(es2extensions) / sizeof(es2extensions[0]);
4421 GLuint numExtensions = numES2extensions;
4423 if(clientVersion >= 3)
4425 numExtensions += sizeof(es3extensions) / sizeof(es3extensions[0]);
4430 *numExt = numExtensions;
4435 if(index == GL_INVALID_INDEX)
4437 static std::string extensionsCat;
4439 if(extensionsCat.empty() && (numExtensions > 0))
4441 for(const char *extension : es2extensions)
4443 extensionsCat += std::string(extension) + " ";
4446 if(clientVersion >= 3)
4448 for(const char *extension : es3extensions)
4450 extensionsCat += std::string(extension) + " ";
4455 return (const GLubyte*)extensionsCat.c_str();
4458 if(index >= numExtensions)
4463 if(index < numES2extensions)
4465 return (const GLubyte*)es2extensions[index];
4469 return (const GLubyte*)es3extensions[index - numES2extensions];
4475 NO_SANITIZE_FUNCTION egl::Context *es2CreateContext(egl::Display *display, const egl::Context *shareContext, int clientVersion, const egl::Config *config)
4477 ASSERT(!shareContext || shareContext->getClientVersion() == clientVersion); // Should be checked by eglCreateContext
4478 return new es2::Context(display, static_cast<const es2::Context*>(shareContext), clientVersion, config);