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 mTexture2DRectZero = new Texture2DRect(0);
146 mTextureExternalZero = new TextureExternal(0);
148 mState.activeSampler = 0;
150 for(int type = 0; type < TEXTURE_TYPE_COUNT; type++)
152 bindTexture((TextureType)type, 0);
157 bindElementArrayBuffer(0);
158 bindReadFramebuffer(0);
159 bindDrawFramebuffer(0);
161 bindGenericUniformBuffer(0);
162 bindTransformFeedback(0);
164 mState.currentProgram = 0;
166 mVertexDataManager = nullptr;
167 mIndexDataManager = nullptr;
169 mInvalidEnum = false;
170 mInvalidValue = false;
171 mInvalidOperation = false;
172 mOutOfMemory = false;
173 mInvalidFramebufferOperation = false;
175 mHasBeenCurrent = false;
182 if(mState.currentProgram != 0)
184 Program *programObject = mResourceManager->getProgram(mState.currentProgram);
187 programObject->release();
189 mState.currentProgram = 0;
192 while(!mFramebufferNameSpace.empty())
194 deleteFramebuffer(mFramebufferNameSpace.firstName());
197 while(!mFenceNameSpace.empty())
199 deleteFence(mFenceNameSpace.firstName());
202 while(!mQueryNameSpace.empty())
204 deleteQuery(mQueryNameSpace.firstName());
207 while(!mVertexArrayNameSpace.empty())
209 deleteVertexArray(mVertexArrayNameSpace.lastName());
212 while(!mTransformFeedbackNameSpace.empty())
214 deleteTransformFeedback(mTransformFeedbackNameSpace.firstName());
217 for(int type = 0; type < TEXTURE_TYPE_COUNT; type++)
219 for(int sampler = 0; sampler < MAX_COMBINED_TEXTURE_IMAGE_UNITS; sampler++)
221 mState.samplerTexture[type][sampler] = nullptr;
225 for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
227 mState.vertexAttribute[i].mBoundBuffer = nullptr;
230 for(int i = 0; i < QUERY_TYPE_COUNT; i++)
232 mState.activeQuery[i] = nullptr;
235 mState.arrayBuffer = nullptr;
236 mState.copyReadBuffer = nullptr;
237 mState.copyWriteBuffer = nullptr;
238 mState.pixelPackBuffer = nullptr;
239 mState.pixelUnpackBuffer = nullptr;
240 mState.genericUniformBuffer = nullptr;
242 for(int i = 0; i < MAX_UNIFORM_BUFFER_BINDINGS; i++) {
243 mState.uniformBuffers[i].set(nullptr, 0, 0);
246 mState.renderbuffer = nullptr;
248 for(int i = 0; i < MAX_COMBINED_TEXTURE_IMAGE_UNITS; ++i)
250 mState.sampler[i] = nullptr;
253 mTexture2DZero = nullptr;
254 mTexture3DZero = nullptr;
255 mTexture2DArrayZero = nullptr;
256 mTextureCubeMapZero = nullptr;
257 mTexture2DRectZero = nullptr;
258 mTextureExternalZero = nullptr;
260 delete mVertexDataManager;
261 delete mIndexDataManager;
263 mResourceManager->release();
267 void Context::makeCurrent(gl::Surface *surface)
271 mVertexDataManager = new VertexDataManager(this);
272 mIndexDataManager = new IndexDataManager();
274 mState.viewportX = 0;
275 mState.viewportY = 0;
276 mState.viewportWidth = surface ? surface->getWidth() : 0;
277 mState.viewportHeight = surface ? surface->getHeight() : 0;
281 mState.scissorWidth = surface ? surface->getWidth() : 0;
282 mState.scissorHeight = surface ? surface->getHeight() : 0;
284 mHasBeenCurrent = true;
289 // Wrap the existing resources into GL objects and assign them to the '0' names
290 egl::Image *defaultRenderTarget = surface->getRenderTarget();
291 egl::Image *depthStencil = surface->getDepthStencil();
293 Colorbuffer *colorbufferZero = new Colorbuffer(defaultRenderTarget);
294 DepthStencilbuffer *depthStencilbufferZero = new DepthStencilbuffer(depthStencil);
295 Framebuffer *framebufferZero = new DefaultFramebuffer(colorbufferZero, depthStencilbufferZero);
297 setFramebufferZero(framebufferZero);
299 if(defaultRenderTarget)
301 defaultRenderTarget->release();
306 depthStencil->release();
311 setFramebufferZero(nullptr);
317 EGLint Context::getClientVersion() const
319 return clientVersion;
322 EGLint Context::getConfigID() const
324 return config->mConfigID;
327 // This function will set all of the state-related dirty flags, so that all state is set during next pre-draw.
328 void Context::markAllStateDirty()
330 mAppliedProgramSerial = 0;
332 mDepthStateDirty = true;
333 mMaskStateDirty = true;
334 mBlendStateDirty = true;
335 mStencilStateDirty = true;
336 mPolygonOffsetStateDirty = true;
337 mSampleStateDirty = true;
338 mDitherStateDirty = true;
339 mFrontFaceDirty = true;
342 void Context::setClearColor(float red, float green, float blue, float alpha)
344 mState.colorClearValue.red = red;
345 mState.colorClearValue.green = green;
346 mState.colorClearValue.blue = blue;
347 mState.colorClearValue.alpha = alpha;
350 void Context::setClearDepth(float depth)
352 mState.depthClearValue = depth;
355 void Context::setClearStencil(int stencil)
357 mState.stencilClearValue = stencil;
360 void Context::setCullFaceEnabled(bool enabled)
362 mState.cullFaceEnabled = enabled;
365 bool Context::isCullFaceEnabled() const
367 return mState.cullFaceEnabled;
370 void Context::setCullMode(GLenum mode)
372 mState.cullMode = mode;
375 void Context::setFrontFace(GLenum front)
377 if(mState.frontFace != front)
379 mState.frontFace = front;
380 mFrontFaceDirty = true;
384 void Context::setDepthTestEnabled(bool enabled)
386 if(mState.depthTestEnabled != enabled)
388 mState.depthTestEnabled = enabled;
389 mDepthStateDirty = true;
393 bool Context::isDepthTestEnabled() const
395 return mState.depthTestEnabled;
398 void Context::setDepthFunc(GLenum depthFunc)
400 if(mState.depthFunc != depthFunc)
402 mState.depthFunc = depthFunc;
403 mDepthStateDirty = true;
407 void Context::setDepthRange(float zNear, float zFar)
409 mState.zNear = zNear;
413 void Context::setBlendEnabled(bool enabled)
415 if(mState.blendEnabled != enabled)
417 mState.blendEnabled = enabled;
418 mBlendStateDirty = true;
422 bool Context::isBlendEnabled() const
424 return mState.blendEnabled;
427 void Context::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha)
429 if(mState.sourceBlendRGB != sourceRGB ||
430 mState.sourceBlendAlpha != sourceAlpha ||
431 mState.destBlendRGB != destRGB ||
432 mState.destBlendAlpha != destAlpha)
434 mState.sourceBlendRGB = sourceRGB;
435 mState.destBlendRGB = destRGB;
436 mState.sourceBlendAlpha = sourceAlpha;
437 mState.destBlendAlpha = destAlpha;
438 mBlendStateDirty = true;
442 void Context::setBlendColor(float red, float green, float blue, float alpha)
444 if(mState.blendColor.red != red ||
445 mState.blendColor.green != green ||
446 mState.blendColor.blue != blue ||
447 mState.blendColor.alpha != alpha)
449 mState.blendColor.red = red;
450 mState.blendColor.green = green;
451 mState.blendColor.blue = blue;
452 mState.blendColor.alpha = alpha;
453 mBlendStateDirty = true;
457 void Context::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation)
459 if(mState.blendEquationRGB != rgbEquation ||
460 mState.blendEquationAlpha != alphaEquation)
462 mState.blendEquationRGB = rgbEquation;
463 mState.blendEquationAlpha = alphaEquation;
464 mBlendStateDirty = true;
468 void Context::setStencilTestEnabled(bool enabled)
470 if(mState.stencilTestEnabled != enabled)
472 mState.stencilTestEnabled = enabled;
473 mStencilStateDirty = true;
477 bool Context::isStencilTestEnabled() const
479 return mState.stencilTestEnabled;
482 void Context::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask)
484 if(mState.stencilFunc != stencilFunc ||
485 mState.stencilRef != stencilRef ||
486 mState.stencilMask != stencilMask)
488 mState.stencilFunc = stencilFunc;
489 mState.stencilRef = (stencilRef > 0) ? stencilRef : 0;
490 mState.stencilMask = stencilMask;
491 mStencilStateDirty = true;
495 void Context::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask)
497 if(mState.stencilBackFunc != stencilBackFunc ||
498 mState.stencilBackRef != stencilBackRef ||
499 mState.stencilBackMask != stencilBackMask)
501 mState.stencilBackFunc = stencilBackFunc;
502 mState.stencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0;
503 mState.stencilBackMask = stencilBackMask;
504 mStencilStateDirty = true;
508 void Context::setStencilWritemask(GLuint stencilWritemask)
510 if(mState.stencilWritemask != stencilWritemask)
512 mState.stencilWritemask = stencilWritemask;
513 mStencilStateDirty = true;
517 void Context::setStencilBackWritemask(GLuint stencilBackWritemask)
519 if(mState.stencilBackWritemask != stencilBackWritemask)
521 mState.stencilBackWritemask = stencilBackWritemask;
522 mStencilStateDirty = true;
526 void Context::setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass)
528 if(mState.stencilFail != stencilFail ||
529 mState.stencilPassDepthFail != stencilPassDepthFail ||
530 mState.stencilPassDepthPass != stencilPassDepthPass)
532 mState.stencilFail = stencilFail;
533 mState.stencilPassDepthFail = stencilPassDepthFail;
534 mState.stencilPassDepthPass = stencilPassDepthPass;
535 mStencilStateDirty = true;
539 void Context::setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass)
541 if(mState.stencilBackFail != stencilBackFail ||
542 mState.stencilBackPassDepthFail != stencilBackPassDepthFail ||
543 mState.stencilBackPassDepthPass != stencilBackPassDepthPass)
545 mState.stencilBackFail = stencilBackFail;
546 mState.stencilBackPassDepthFail = stencilBackPassDepthFail;
547 mState.stencilBackPassDepthPass = stencilBackPassDepthPass;
548 mStencilStateDirty = true;
552 void Context::setPolygonOffsetFillEnabled(bool enabled)
554 if(mState.polygonOffsetFillEnabled != enabled)
556 mState.polygonOffsetFillEnabled = enabled;
557 mPolygonOffsetStateDirty = true;
561 bool Context::isPolygonOffsetFillEnabled() const
563 return mState.polygonOffsetFillEnabled;
566 void Context::setPolygonOffsetParams(GLfloat factor, GLfloat units)
568 if(mState.polygonOffsetFactor != factor ||
569 mState.polygonOffsetUnits != units)
571 mState.polygonOffsetFactor = factor;
572 mState.polygonOffsetUnits = units;
573 mPolygonOffsetStateDirty = true;
577 void Context::setSampleAlphaToCoverageEnabled(bool enabled)
579 if(mState.sampleAlphaToCoverageEnabled != enabled)
581 mState.sampleAlphaToCoverageEnabled = enabled;
582 mSampleStateDirty = true;
586 bool Context::isSampleAlphaToCoverageEnabled() const
588 return mState.sampleAlphaToCoverageEnabled;
591 void Context::setSampleCoverageEnabled(bool enabled)
593 if(mState.sampleCoverageEnabled != enabled)
595 mState.sampleCoverageEnabled = enabled;
596 mSampleStateDirty = true;
600 bool Context::isSampleCoverageEnabled() const
602 return mState.sampleCoverageEnabled;
605 void Context::setSampleCoverageParams(GLclampf value, bool invert)
607 if(mState.sampleCoverageValue != value ||
608 mState.sampleCoverageInvert != invert)
610 mState.sampleCoverageValue = value;
611 mState.sampleCoverageInvert = invert;
612 mSampleStateDirty = true;
616 void Context::setScissorTestEnabled(bool enabled)
618 mState.scissorTestEnabled = enabled;
621 bool Context::isScissorTestEnabled() const
623 return mState.scissorTestEnabled;
626 void Context::setDitherEnabled(bool enabled)
628 if(mState.ditherEnabled != enabled)
630 mState.ditherEnabled = enabled;
631 mDitherStateDirty = true;
635 bool Context::isDitherEnabled() const
637 return mState.ditherEnabled;
640 void Context::setPrimitiveRestartFixedIndexEnabled(bool enabled)
642 mState.primitiveRestartFixedIndexEnabled = enabled;
645 bool Context::isPrimitiveRestartFixedIndexEnabled() const
647 return mState.primitiveRestartFixedIndexEnabled;
650 void Context::setRasterizerDiscardEnabled(bool enabled)
652 mState.rasterizerDiscardEnabled = enabled;
655 bool Context::isRasterizerDiscardEnabled() const
657 return mState.rasterizerDiscardEnabled;
660 void Context::setLineWidth(GLfloat width)
662 mState.lineWidth = width;
663 device->setLineWidth(clamp(width, ALIASED_LINE_WIDTH_RANGE_MIN, ALIASED_LINE_WIDTH_RANGE_MAX));
666 void Context::setGenerateMipmapHint(GLenum hint)
668 mState.generateMipmapHint = hint;
671 void Context::setFragmentShaderDerivativeHint(GLenum hint)
673 mState.fragmentShaderDerivativeHint = hint;
674 // TODO: Propagate the hint to shader translator so we can write
675 // ddx, ddx_coarse, or ddx_fine depending on the hint.
676 // Ignore for now. It is valid for implementations to ignore hint.
679 void Context::setTextureFilteringHint(GLenum hint)
681 mState.textureFilteringHint = hint;
684 void Context::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height)
686 mState.viewportX = x;
687 mState.viewportY = y;
688 mState.viewportWidth = std::min<GLsizei>(width, IMPLEMENTATION_MAX_RENDERBUFFER_SIZE); // GL_MAX_VIEWPORT_DIMS[0]
689 mState.viewportHeight = std::min<GLsizei>(height, IMPLEMENTATION_MAX_RENDERBUFFER_SIZE); // GL_MAX_VIEWPORT_DIMS[1]
692 void Context::setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height)
696 mState.scissorWidth = width;
697 mState.scissorHeight = height;
700 void Context::setColorMask(bool red, bool green, bool blue, bool alpha)
702 if(mState.colorMaskRed != red || mState.colorMaskGreen != green ||
703 mState.colorMaskBlue != blue || mState.colorMaskAlpha != alpha)
705 mState.colorMaskRed = red;
706 mState.colorMaskGreen = green;
707 mState.colorMaskBlue = blue;
708 mState.colorMaskAlpha = alpha;
709 mMaskStateDirty = true;
713 unsigned int Context::getColorMask() const
715 return (mState.colorMaskRed ? 0x1 : 0) |
716 (mState.colorMaskGreen ? 0x2 : 0) |
717 (mState.colorMaskBlue ? 0x4 : 0) |
718 (mState.colorMaskAlpha ? 0x8 : 0);
721 void Context::setDepthMask(bool mask)
723 if(mState.depthMask != mask)
725 mState.depthMask = mask;
726 mMaskStateDirty = true;
730 void Context::setActiveSampler(unsigned int active)
732 mState.activeSampler = active;
735 GLuint Context::getReadFramebufferName() const
737 return mState.readFramebuffer;
740 GLuint Context::getDrawFramebufferName() const
742 return mState.drawFramebuffer;
745 GLuint Context::getRenderbufferName() const
747 return mState.renderbuffer.name();
750 void Context::setFramebufferReadBuffer(GLuint buf)
752 getReadFramebuffer()->setReadBuffer(buf);
755 void Context::setFramebufferDrawBuffers(GLsizei n, const GLenum *bufs)
757 Framebuffer *drawFramebuffer = getDrawFramebuffer();
759 for(int i = 0; i < MAX_COLOR_ATTACHMENTS; i++)
761 drawFramebuffer->setDrawBuffer(i, (i < n) ? bufs[i] : GL_NONE);
765 GLuint Context::getArrayBufferName() const
767 return mState.arrayBuffer.name();
770 GLuint Context::getElementArrayBufferName() const
772 Buffer* elementArrayBuffer = getCurrentVertexArray()->getElementArrayBuffer();
773 return elementArrayBuffer ? elementArrayBuffer->name : 0;
776 GLuint Context::getActiveQuery(GLenum target) const
778 Query *queryObject = nullptr;
782 case GL_ANY_SAMPLES_PASSED_EXT:
783 queryObject = mState.activeQuery[QUERY_ANY_SAMPLES_PASSED];
785 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
786 queryObject = mState.activeQuery[QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE];
788 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
789 queryObject = mState.activeQuery[QUERY_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN];
797 return queryObject->name;
803 void Context::setVertexAttribArrayEnabled(unsigned int attribNum, bool enabled)
805 getCurrentVertexArray()->enableAttribute(attribNum, enabled);
808 void Context::setVertexAttribDivisor(unsigned int attribNum, GLuint divisor)
810 getCurrentVertexArray()->setVertexAttribDivisor(attribNum, divisor);
813 const VertexAttribute &Context::getVertexAttribState(unsigned int attribNum) const
815 return getCurrentVertexArray()->getVertexAttribute(attribNum);
818 void Context::setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type,
819 bool normalized, bool pureInteger, GLsizei stride, const void *pointer)
821 getCurrentVertexArray()->setAttributeState(attribNum, boundBuffer, size, type, normalized, pureInteger, stride, pointer);
824 const void *Context::getVertexAttribPointer(unsigned int attribNum) const
826 return getCurrentVertexArray()->getVertexAttribute(attribNum).mPointer;
829 const VertexAttributeArray &Context::getVertexArrayAttributes()
831 return getCurrentVertexArray()->getVertexAttributes();
834 const VertexAttributeArray &Context::getCurrentVertexAttributes()
836 return mState.vertexAttribute;
839 void Context::setPackAlignment(GLint alignment)
841 mState.packParameters.alignment = alignment;
844 void Context::setUnpackAlignment(GLint alignment)
846 mState.unpackParameters.alignment = alignment;
849 const gl::PixelStorageModes &Context::getUnpackParameters() const
851 return mState.unpackParameters;
854 void Context::setPackRowLength(GLint rowLength)
856 mState.packParameters.rowLength = rowLength;
859 void Context::setPackSkipPixels(GLint skipPixels)
861 mState.packParameters.skipPixels = skipPixels;
864 void Context::setPackSkipRows(GLint skipRows)
866 mState.packParameters.skipRows = skipRows;
869 void Context::setUnpackRowLength(GLint rowLength)
871 mState.unpackParameters.rowLength = rowLength;
874 void Context::setUnpackImageHeight(GLint imageHeight)
876 mState.unpackParameters.imageHeight = imageHeight;
879 void Context::setUnpackSkipPixels(GLint skipPixels)
881 mState.unpackParameters.skipPixels = skipPixels;
884 void Context::setUnpackSkipRows(GLint skipRows)
886 mState.unpackParameters.skipRows = skipRows;
889 void Context::setUnpackSkipImages(GLint skipImages)
891 mState.unpackParameters.skipImages = skipImages;
894 GLuint Context::createBuffer()
896 return mResourceManager->createBuffer();
899 GLuint Context::createProgram()
901 return mResourceManager->createProgram();
904 GLuint Context::createShader(GLenum type)
906 return mResourceManager->createShader(type);
909 GLuint Context::createTexture()
911 return mResourceManager->createTexture();
914 GLuint Context::createRenderbuffer()
916 return mResourceManager->createRenderbuffer();
919 // Returns an unused framebuffer name
920 GLuint Context::createFramebuffer()
922 return mFramebufferNameSpace.allocate();
925 GLuint Context::createFence()
927 return mFenceNameSpace.allocate(new Fence());
930 // Returns an unused query name
931 GLuint Context::createQuery()
933 return mQueryNameSpace.allocate();
936 // Returns an unused vertex array name
937 GLuint Context::createVertexArray()
939 return mVertexArrayNameSpace.allocate();
942 GLsync Context::createFenceSync(GLenum condition, GLbitfield flags)
944 GLuint handle = mResourceManager->createFenceSync(condition, flags);
946 return reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
949 // Returns an unused transform feedback name
950 GLuint Context::createTransformFeedback()
952 return mTransformFeedbackNameSpace.allocate();
955 // Returns an unused sampler name
956 GLuint Context::createSampler()
958 return mResourceManager->createSampler();
961 void Context::deleteBuffer(GLuint buffer)
963 detachBuffer(buffer);
965 mResourceManager->deleteBuffer(buffer);
968 void Context::deleteShader(GLuint shader)
970 mResourceManager->deleteShader(shader);
973 void Context::deleteProgram(GLuint program)
975 mResourceManager->deleteProgram(program);
978 void Context::deleteTexture(GLuint texture)
980 detachTexture(texture);
982 mResourceManager->deleteTexture(texture);
985 void Context::deleteRenderbuffer(GLuint renderbuffer)
987 if(mResourceManager->getRenderbuffer(renderbuffer))
989 detachRenderbuffer(renderbuffer);
992 mResourceManager->deleteRenderbuffer(renderbuffer);
995 void Context::deleteFramebuffer(GLuint framebuffer)
997 detachFramebuffer(framebuffer);
999 Framebuffer *framebufferObject = mFramebufferNameSpace.remove(framebuffer);
1001 if(framebufferObject)
1003 delete framebufferObject;
1007 void Context::deleteFence(GLuint fence)
1009 Fence *fenceObject = mFenceNameSpace.remove(fence);
1017 void Context::deleteQuery(GLuint query)
1019 Query *queryObject = mQueryNameSpace.remove(query);
1023 queryObject->release();
1027 void Context::deleteVertexArray(GLuint vertexArray)
1029 // [OpenGL ES 3.0.2] section 2.10 page 43:
1030 // If a vertex array object that is currently bound is deleted, the binding
1031 // for that object reverts to zero and the default vertex array becomes current.
1032 if(getCurrentVertexArray()->name == vertexArray)
1037 VertexArray *vertexArrayObject = mVertexArrayNameSpace.remove(vertexArray);
1039 if(vertexArrayObject)
1041 delete vertexArrayObject;
1045 void Context::deleteFenceSync(GLsync fenceSync)
1047 // The spec specifies the underlying Fence object is not deleted until all current
1048 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
1049 // and since our API is currently designed for being called from a single thread, we can delete
1050 // the fence immediately.
1051 mResourceManager->deleteFenceSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(fenceSync)));
1054 void Context::deleteTransformFeedback(GLuint transformFeedback)
1056 TransformFeedback *transformFeedbackObject = mTransformFeedbackNameSpace.remove(transformFeedback);
1058 if(transformFeedbackObject)
1060 delete transformFeedbackObject;
1064 void Context::deleteSampler(GLuint sampler)
1066 detachSampler(sampler);
1068 mResourceManager->deleteSampler(sampler);
1071 Buffer *Context::getBuffer(GLuint handle) const
1073 return mResourceManager->getBuffer(handle);
1076 Shader *Context::getShader(GLuint handle) const
1078 return mResourceManager->getShader(handle);
1081 Program *Context::getProgram(GLuint handle) const
1083 return mResourceManager->getProgram(handle);
1086 Texture *Context::getTexture(GLuint handle) const
1088 return mResourceManager->getTexture(handle);
1091 Renderbuffer *Context::getRenderbuffer(GLuint handle) const
1093 return mResourceManager->getRenderbuffer(handle);
1096 Framebuffer *Context::getReadFramebuffer() const
1098 return getFramebuffer(mState.readFramebuffer);
1101 Framebuffer *Context::getDrawFramebuffer() const
1103 return getFramebuffer(mState.drawFramebuffer);
1106 void Context::bindArrayBuffer(unsigned int buffer)
1108 mResourceManager->checkBufferAllocation(buffer);
1110 mState.arrayBuffer = getBuffer(buffer);
1113 void Context::bindElementArrayBuffer(unsigned int buffer)
1115 mResourceManager->checkBufferAllocation(buffer);
1117 getCurrentVertexArray()->setElementArrayBuffer(getBuffer(buffer));
1120 void Context::bindCopyReadBuffer(GLuint buffer)
1122 mResourceManager->checkBufferAllocation(buffer);
1124 mState.copyReadBuffer = getBuffer(buffer);
1127 void Context::bindCopyWriteBuffer(GLuint buffer)
1129 mResourceManager->checkBufferAllocation(buffer);
1131 mState.copyWriteBuffer = getBuffer(buffer);
1134 void Context::bindPixelPackBuffer(GLuint buffer)
1136 mResourceManager->checkBufferAllocation(buffer);
1138 mState.pixelPackBuffer = getBuffer(buffer);
1141 void Context::bindPixelUnpackBuffer(GLuint buffer)
1143 mResourceManager->checkBufferAllocation(buffer);
1145 mState.pixelUnpackBuffer = getBuffer(buffer);
1148 void Context::bindTransformFeedbackBuffer(GLuint buffer)
1150 mResourceManager->checkBufferAllocation(buffer);
1152 TransformFeedback* transformFeedback = getTransformFeedback(mState.transformFeedback);
1154 if(transformFeedback)
1156 transformFeedback->setGenericBuffer(getBuffer(buffer));
1160 void Context::bindTexture(TextureType type, GLuint texture)
1162 mResourceManager->checkTextureAllocation(texture, type);
1164 mState.samplerTexture[type][mState.activeSampler] = getTexture(texture);
1167 void Context::bindReadFramebuffer(GLuint framebuffer)
1169 if(!getFramebuffer(framebuffer))
1171 if(framebuffer == 0)
1173 mFramebufferNameSpace.insert(framebuffer, new DefaultFramebuffer());
1177 mFramebufferNameSpace.insert(framebuffer, new Framebuffer());
1181 mState.readFramebuffer = framebuffer;
1184 void Context::bindDrawFramebuffer(GLuint framebuffer)
1186 if(!getFramebuffer(framebuffer))
1188 if(framebuffer == 0)
1190 mFramebufferNameSpace.insert(framebuffer, new DefaultFramebuffer());
1194 mFramebufferNameSpace.insert(framebuffer, new Framebuffer());
1198 mState.drawFramebuffer = framebuffer;
1201 void Context::bindRenderbuffer(GLuint renderbuffer)
1203 mResourceManager->checkRenderbufferAllocation(renderbuffer);
1205 mState.renderbuffer = getRenderbuffer(renderbuffer);
1208 void Context::bindVertexArray(GLuint array)
1210 VertexArray *vertexArray = getVertexArray(array);
1214 vertexArray = new VertexArray(array);
1215 mVertexArrayNameSpace.insert(array, vertexArray);
1218 mState.vertexArray = array;
1221 void Context::bindGenericUniformBuffer(GLuint buffer)
1223 mResourceManager->checkBufferAllocation(buffer);
1225 mState.genericUniformBuffer = getBuffer(buffer);
1228 void Context::bindIndexedUniformBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size)
1230 mResourceManager->checkBufferAllocation(buffer);
1232 Buffer* bufferObject = getBuffer(buffer);
1233 mState.uniformBuffers[index].set(bufferObject, static_cast<int>(offset), static_cast<int>(size));
1236 void Context::bindGenericTransformFeedbackBuffer(GLuint buffer)
1238 mResourceManager->checkBufferAllocation(buffer);
1240 getTransformFeedback()->setGenericBuffer(getBuffer(buffer));
1243 void Context::bindIndexedTransformFeedbackBuffer(GLuint buffer, GLuint index, GLintptr offset, GLsizeiptr size)
1245 mResourceManager->checkBufferAllocation(buffer);
1247 Buffer* bufferObject = getBuffer(buffer);
1248 getTransformFeedback()->setBuffer(index, bufferObject, offset, size);
1251 void Context::bindTransformFeedback(GLuint id)
1253 if(!getTransformFeedback(id))
1255 mTransformFeedbackNameSpace.insert(id, new TransformFeedback(id));
1258 mState.transformFeedback = id;
1261 bool Context::bindSampler(GLuint unit, GLuint sampler)
1263 mResourceManager->checkSamplerAllocation(sampler);
1265 Sampler* samplerObject = getSampler(sampler);
1267 mState.sampler[unit] = samplerObject;
1269 return !!samplerObject;
1272 void Context::useProgram(GLuint program)
1274 GLuint priorProgram = mState.currentProgram;
1275 mState.currentProgram = program; // Must switch before trying to delete, otherwise it only gets flagged.
1277 if(priorProgram != program)
1279 Program *newProgram = mResourceManager->getProgram(program);
1280 Program *oldProgram = mResourceManager->getProgram(priorProgram);
1284 newProgram->addRef();
1289 oldProgram->release();
1294 void Context::beginQuery(GLenum target, GLuint query)
1296 // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id>
1297 // of zero, if the active query object name for <target> is non-zero (for the
1298 // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if
1299 // the active query for either target is non-zero), if <id> is the name of an
1300 // existing query object whose type does not match <target>, or if <id> is the
1301 // active query object name for any query type, the error INVALID_OPERATION is
1304 // Ensure no other queries are active
1305 // NOTE: If other queries than occlusion are supported, we will need to check
1307 // a) The query ID passed is not the current active query for any target/type
1308 // b) There are no active queries for the requested target (and in the case
1309 // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT,
1310 // no query may be active for either if glBeginQuery targets either.
1311 for(int i = 0; i < QUERY_TYPE_COUNT; i++)
1313 if(mState.activeQuery[i])
1315 switch(mState.activeQuery[i]->getType())
1317 case GL_ANY_SAMPLES_PASSED_EXT:
1318 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
1319 if((target == GL_ANY_SAMPLES_PASSED_EXT) ||
1320 (target == GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT))
1322 return error(GL_INVALID_OPERATION);
1325 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
1326 if(target == GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN)
1328 return error(GL_INVALID_OPERATION);
1340 case GL_ANY_SAMPLES_PASSED_EXT:
1341 qType = QUERY_ANY_SAMPLES_PASSED;
1343 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT:
1344 qType = QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE;
1346 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
1347 qType = QUERY_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN;
1350 UNREACHABLE(target);
1351 return error(GL_INVALID_ENUM);
1354 Query *queryObject = createQuery(query, target);
1356 // Check that name was obtained with glGenQueries
1359 return error(GL_INVALID_OPERATION);
1362 // Check for type mismatch
1363 if(queryObject->getType() != target)
1365 return error(GL_INVALID_OPERATION);
1368 // Set query as active for specified target
1369 mState.activeQuery[qType] = queryObject;
1372 queryObject->begin();
1375 void Context::endQuery(GLenum target)
1381 case GL_ANY_SAMPLES_PASSED_EXT: qType = QUERY_ANY_SAMPLES_PASSED; break;
1382 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT: qType = QUERY_ANY_SAMPLES_PASSED_CONSERVATIVE; break;
1383 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: qType = QUERY_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN; break;
1384 default: UNREACHABLE(target); return;
1387 Query *queryObject = mState.activeQuery[qType];
1391 return error(GL_INVALID_OPERATION);
1396 mState.activeQuery[qType] = nullptr;
1399 void Context::setFramebufferZero(Framebuffer *buffer)
1401 delete mFramebufferNameSpace.remove(0);
1402 mFramebufferNameSpace.insert(0, buffer);
1405 void Context::setRenderbufferStorage(RenderbufferStorage *renderbuffer)
1407 Renderbuffer *renderbufferObject = mState.renderbuffer;
1408 renderbufferObject->setStorage(renderbuffer);
1411 Framebuffer *Context::getFramebuffer(unsigned int handle) const
1413 return mFramebufferNameSpace.find(handle);
1416 Fence *Context::getFence(unsigned int handle) const
1418 return mFenceNameSpace.find(handle);
1421 FenceSync *Context::getFenceSync(GLsync handle) const
1423 return mResourceManager->getFenceSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
1426 Query *Context::getQuery(unsigned int handle) const
1428 return mQueryNameSpace.find(handle);
1431 Query *Context::createQuery(unsigned int handle, GLenum type)
1433 if(!mQueryNameSpace.isReserved(handle))
1439 Query *query = mQueryNameSpace.find(handle);
1442 query = new Query(handle, type);
1444 mQueryNameSpace.insert(handle, query);
1451 VertexArray *Context::getVertexArray(GLuint array) const
1453 return mVertexArrayNameSpace.find(array);
1456 VertexArray *Context::getCurrentVertexArray() const
1458 return getVertexArray(mState.vertexArray);
1461 bool Context::isVertexArray(GLuint array) const
1463 return mVertexArrayNameSpace.isReserved(array);
1466 bool Context::hasZeroDivisor() const
1468 // Verify there is at least one active attribute with a divisor of zero
1469 es2::Program *programObject = getCurrentProgram();
1470 for(int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
1472 bool active = (programObject->getAttributeStream(attributeIndex) != -1);
1473 if(active && getCurrentVertexArray()->getVertexAttribute(attributeIndex).mDivisor == 0)
1482 TransformFeedback *Context::getTransformFeedback(GLuint transformFeedback) const
1484 return mTransformFeedbackNameSpace.find(transformFeedback);
1487 bool Context::isTransformFeedback(GLuint array) const
1489 return mTransformFeedbackNameSpace.isReserved(array);
1492 Sampler *Context::getSampler(GLuint sampler) const
1494 return mResourceManager->getSampler(sampler);
1497 bool Context::isSampler(GLuint sampler) const
1499 return mResourceManager->isSampler(sampler);
1502 Buffer *Context::getArrayBuffer() const
1504 return mState.arrayBuffer;
1507 Buffer *Context::getElementArrayBuffer() const
1509 return getCurrentVertexArray()->getElementArrayBuffer();
1512 Buffer *Context::getCopyReadBuffer() const
1514 return mState.copyReadBuffer;
1517 Buffer *Context::getCopyWriteBuffer() const
1519 return mState.copyWriteBuffer;
1522 Buffer *Context::getPixelPackBuffer() const
1524 return mState.pixelPackBuffer;
1527 Buffer *Context::getPixelUnpackBuffer() const
1529 return mState.pixelUnpackBuffer;
1532 Buffer *Context::getGenericUniformBuffer() const
1534 return mState.genericUniformBuffer;
1537 GLsizei Context::getRequiredBufferSize(GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type) const
1539 GLsizei inputWidth = (mState.unpackParameters.rowLength == 0) ? width : mState.unpackParameters.rowLength;
1540 GLsizei inputPitch = gl::ComputePitch(inputWidth, format, type, mState.unpackParameters.alignment);
1541 GLsizei inputHeight = (mState.unpackParameters.imageHeight == 0) ? height : mState.unpackParameters.imageHeight;
1542 return inputPitch * inputHeight * depth;
1545 GLenum Context::getPixels(const GLvoid **data, GLenum type, GLsizei imageSize) const
1547 if(mState.pixelUnpackBuffer)
1549 if(mState.pixelUnpackBuffer->name)
1551 if(mState.pixelUnpackBuffer->isMapped() ||
1552 (mState.pixelUnpackBuffer->size() < static_cast<size_t>(imageSize)) ||
1553 (static_cast<GLsizei>((ptrdiff_t)(*data)) % GetTypeSize(type)))
1555 return GL_INVALID_OPERATION;
1559 *data = static_cast<const unsigned char*>(mState.pixelUnpackBuffer->data()) + (ptrdiff_t)(*data);
1564 bool Context::getBuffer(GLenum target, es2::Buffer **buffer) const
1568 case GL_ARRAY_BUFFER:
1569 *buffer = getArrayBuffer();
1571 case GL_ELEMENT_ARRAY_BUFFER:
1572 *buffer = getElementArrayBuffer();
1574 case GL_COPY_READ_BUFFER:
1575 if(clientVersion >= 3)
1577 *buffer = getCopyReadBuffer();
1581 case GL_COPY_WRITE_BUFFER:
1582 if(clientVersion >= 3)
1584 *buffer = getCopyWriteBuffer();
1588 case GL_PIXEL_PACK_BUFFER:
1589 if(clientVersion >= 3)
1591 *buffer = getPixelPackBuffer();
1595 case GL_PIXEL_UNPACK_BUFFER:
1596 if(clientVersion >= 3)
1598 *buffer = getPixelUnpackBuffer();
1602 case GL_TRANSFORM_FEEDBACK_BUFFER:
1603 if(clientVersion >= 3)
1605 TransformFeedback* transformFeedback = getTransformFeedback();
1606 *buffer = transformFeedback ? static_cast<es2::Buffer*>(transformFeedback->getGenericBuffer()) : nullptr;
1610 case GL_UNIFORM_BUFFER:
1611 if(clientVersion >= 3)
1613 *buffer = getGenericUniformBuffer();
1623 TransformFeedback *Context::getTransformFeedback() const
1625 return getTransformFeedback(mState.transformFeedback);
1628 Program *Context::getCurrentProgram() const
1630 return mResourceManager->getProgram(mState.currentProgram);
1633 Texture2D *Context::getTexture2D() const
1635 return static_cast<Texture2D*>(getSamplerTexture(mState.activeSampler, TEXTURE_2D));
1638 Texture2D *Context::getTexture2D(GLenum target) const
1642 case GL_TEXTURE_2D: return getTexture2D();
1643 case GL_TEXTURE_RECTANGLE_ARB: return getTexture2DRect();
1644 case GL_TEXTURE_EXTERNAL_OES: return getTextureExternal();
1645 default: UNREACHABLE(target);
1651 Texture3D *Context::getTexture3D() const
1653 return static_cast<Texture3D*>(getSamplerTexture(mState.activeSampler, TEXTURE_3D));
1656 Texture2DArray *Context::getTexture2DArray() const
1658 return static_cast<Texture2DArray*>(getSamplerTexture(mState.activeSampler, TEXTURE_2D_ARRAY));
1661 TextureCubeMap *Context::getTextureCubeMap() const
1663 return static_cast<TextureCubeMap*>(getSamplerTexture(mState.activeSampler, TEXTURE_CUBE));
1666 Texture2DRect *Context::getTexture2DRect() const
1668 return static_cast<Texture2DRect*>(getSamplerTexture(mState.activeSampler, TEXTURE_2D_RECT));
1671 TextureExternal *Context::getTextureExternal() const
1673 return static_cast<TextureExternal*>(getSamplerTexture(mState.activeSampler, TEXTURE_EXTERNAL));
1676 Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
1678 GLuint texid = mState.samplerTexture[type][sampler].name();
1680 if(texid == 0) // Special case: 0 refers to different initial textures based on the target
1684 case TEXTURE_2D: return mTexture2DZero;
1685 case TEXTURE_3D: return mTexture3DZero;
1686 case TEXTURE_2D_ARRAY: return mTexture2DArrayZero;
1687 case TEXTURE_CUBE: return mTextureCubeMapZero;
1688 case TEXTURE_2D_RECT: return mTexture2DRectZero;
1689 case TEXTURE_EXTERNAL: return mTextureExternalZero;
1690 default: UNREACHABLE(type);
1694 return mState.samplerTexture[type][sampler];
1697 void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
1699 mResourceManager->checkSamplerAllocation(sampler);
1701 Sampler *samplerObject = getSampler(sampler);
1702 ASSERT(samplerObject);
1706 case GL_TEXTURE_MIN_FILTER: samplerObject->setMinFilter(static_cast<GLenum>(param)); break;
1707 case GL_TEXTURE_MAG_FILTER: samplerObject->setMagFilter(static_cast<GLenum>(param)); break;
1708 case GL_TEXTURE_WRAP_S: samplerObject->setWrapS(static_cast<GLenum>(param)); break;
1709 case GL_TEXTURE_WRAP_T: samplerObject->setWrapT(static_cast<GLenum>(param)); break;
1710 case GL_TEXTURE_WRAP_R: samplerObject->setWrapR(static_cast<GLenum>(param)); break;
1711 case GL_TEXTURE_MIN_LOD: samplerObject->setMinLod(static_cast<GLfloat>(param)); break;
1712 case GL_TEXTURE_MAX_LOD: samplerObject->setMaxLod(static_cast<GLfloat>(param)); break;
1713 case GL_TEXTURE_COMPARE_MODE: samplerObject->setCompareMode(static_cast<GLenum>(param)); break;
1714 case GL_TEXTURE_COMPARE_FUNC: samplerObject->setCompareFunc(static_cast<GLenum>(param)); break;
1715 default: UNREACHABLE(pname); break;
1719 void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
1721 mResourceManager->checkSamplerAllocation(sampler);
1723 Sampler *samplerObject = getSampler(sampler);
1724 ASSERT(samplerObject);
1728 case GL_TEXTURE_MIN_FILTER: samplerObject->setMinFilter(static_cast<GLenum>(roundf(param))); break;
1729 case GL_TEXTURE_MAG_FILTER: samplerObject->setMagFilter(static_cast<GLenum>(roundf(param))); break;
1730 case GL_TEXTURE_WRAP_S: samplerObject->setWrapS(static_cast<GLenum>(roundf(param))); break;
1731 case GL_TEXTURE_WRAP_T: samplerObject->setWrapT(static_cast<GLenum>(roundf(param))); break;
1732 case GL_TEXTURE_WRAP_R: samplerObject->setWrapR(static_cast<GLenum>(roundf(param))); break;
1733 case GL_TEXTURE_MIN_LOD: samplerObject->setMinLod(param); break;
1734 case GL_TEXTURE_MAX_LOD: samplerObject->setMaxLod(param); break;
1735 case GL_TEXTURE_COMPARE_MODE: samplerObject->setCompareMode(static_cast<GLenum>(roundf(param))); break;
1736 case GL_TEXTURE_COMPARE_FUNC: samplerObject->setCompareFunc(static_cast<GLenum>(roundf(param))); break;
1737 default: UNREACHABLE(pname); break;
1741 GLint Context::getSamplerParameteri(GLuint sampler, GLenum pname)
1743 mResourceManager->checkSamplerAllocation(sampler);
1745 Sampler *samplerObject = getSampler(sampler);
1746 ASSERT(samplerObject);
1750 case GL_TEXTURE_MIN_FILTER: return static_cast<GLint>(samplerObject->getMinFilter());
1751 case GL_TEXTURE_MAG_FILTER: return static_cast<GLint>(samplerObject->getMagFilter());
1752 case GL_TEXTURE_WRAP_S: return static_cast<GLint>(samplerObject->getWrapS());
1753 case GL_TEXTURE_WRAP_T: return static_cast<GLint>(samplerObject->getWrapT());
1754 case GL_TEXTURE_WRAP_R: return static_cast<GLint>(samplerObject->getWrapR());
1755 case GL_TEXTURE_MIN_LOD: return static_cast<GLint>(roundf(samplerObject->getMinLod()));
1756 case GL_TEXTURE_MAX_LOD: return static_cast<GLint>(roundf(samplerObject->getMaxLod()));
1757 case GL_TEXTURE_COMPARE_MODE: return static_cast<GLint>(samplerObject->getCompareMode());
1758 case GL_TEXTURE_COMPARE_FUNC: return static_cast<GLint>(samplerObject->getCompareFunc());
1759 default: UNREACHABLE(pname); return 0;
1763 GLfloat Context::getSamplerParameterf(GLuint sampler, GLenum pname)
1765 mResourceManager->checkSamplerAllocation(sampler);
1767 Sampler *samplerObject = getSampler(sampler);
1768 ASSERT(samplerObject);
1772 case GL_TEXTURE_MIN_FILTER: return static_cast<GLfloat>(samplerObject->getMinFilter());
1773 case GL_TEXTURE_MAG_FILTER: return static_cast<GLfloat>(samplerObject->getMagFilter());
1774 case GL_TEXTURE_WRAP_S: return static_cast<GLfloat>(samplerObject->getWrapS());
1775 case GL_TEXTURE_WRAP_T: return static_cast<GLfloat>(samplerObject->getWrapT());
1776 case GL_TEXTURE_WRAP_R: return static_cast<GLfloat>(samplerObject->getWrapR());
1777 case GL_TEXTURE_MIN_LOD: return samplerObject->getMinLod();
1778 case GL_TEXTURE_MAX_LOD: return samplerObject->getMaxLod();
1779 case GL_TEXTURE_COMPARE_MODE: return static_cast<GLfloat>(samplerObject->getCompareMode());
1780 case GL_TEXTURE_COMPARE_FUNC: return static_cast<GLfloat>(samplerObject->getCompareFunc());
1781 default: UNREACHABLE(pname); return 0;
1785 bool Context::getBooleanv(GLenum pname, GLboolean *params) const
1789 case GL_SHADER_COMPILER: *params = GL_TRUE; break;
1790 case GL_SAMPLE_COVERAGE_INVERT: *params = mState.sampleCoverageInvert; break;
1791 case GL_DEPTH_WRITEMASK: *params = mState.depthMask; break;
1792 case GL_COLOR_WRITEMASK:
1793 params[0] = mState.colorMaskRed;
1794 params[1] = mState.colorMaskGreen;
1795 params[2] = mState.colorMaskBlue;
1796 params[3] = mState.colorMaskAlpha;
1798 case GL_CULL_FACE: *params = mState.cullFaceEnabled; break;
1799 case GL_POLYGON_OFFSET_FILL: *params = mState.polygonOffsetFillEnabled; break;
1800 case GL_SAMPLE_ALPHA_TO_COVERAGE: *params = mState.sampleAlphaToCoverageEnabled; break;
1801 case GL_SAMPLE_COVERAGE: *params = mState.sampleCoverageEnabled; break;
1802 case GL_SCISSOR_TEST: *params = mState.scissorTestEnabled; break;
1803 case GL_STENCIL_TEST: *params = mState.stencilTestEnabled; break;
1804 case GL_DEPTH_TEST: *params = mState.depthTestEnabled; break;
1805 case GL_BLEND: *params = mState.blendEnabled; break;
1806 case GL_DITHER: *params = mState.ditherEnabled; break;
1807 case GL_PRIMITIVE_RESTART_FIXED_INDEX: *params = mState.primitiveRestartFixedIndexEnabled; break;
1808 case GL_RASTERIZER_DISCARD: *params = mState.rasterizerDiscardEnabled; break;
1809 case GL_TRANSFORM_FEEDBACK_ACTIVE:
1811 TransformFeedback* transformFeedback = getTransformFeedback(mState.transformFeedback);
1812 if(transformFeedback)
1814 *params = transformFeedback->isActive();
1819 case GL_TRANSFORM_FEEDBACK_PAUSED:
1821 TransformFeedback* transformFeedback = getTransformFeedback(mState.transformFeedback);
1822 if(transformFeedback)
1824 *params = transformFeedback->isPaused();
1836 bool Context::getFloatv(GLenum pname, GLfloat *params) const
1838 // Please note: DEPTH_CLEAR_VALUE is included in our internal getFloatv implementation
1839 // because it is stored as a float, despite the fact that the GL ES 2.0 spec names
1840 // GetIntegerv as its native query function. As it would require conversion in any
1841 // case, this should make no difference to the calling application.
1844 case GL_LINE_WIDTH: *params = mState.lineWidth; break;
1845 case GL_SAMPLE_COVERAGE_VALUE: *params = mState.sampleCoverageValue; break;
1846 case GL_DEPTH_CLEAR_VALUE: *params = mState.depthClearValue; break;
1847 case GL_POLYGON_OFFSET_FACTOR: *params = mState.polygonOffsetFactor; break;
1848 case GL_POLYGON_OFFSET_UNITS: *params = mState.polygonOffsetUnits; break;
1849 case GL_ALIASED_LINE_WIDTH_RANGE:
1850 params[0] = ALIASED_LINE_WIDTH_RANGE_MIN;
1851 params[1] = ALIASED_LINE_WIDTH_RANGE_MAX;
1853 case GL_ALIASED_POINT_SIZE_RANGE:
1854 params[0] = ALIASED_POINT_SIZE_RANGE_MIN;
1855 params[1] = ALIASED_POINT_SIZE_RANGE_MAX;
1857 case GL_DEPTH_RANGE:
1858 params[0] = mState.zNear;
1859 params[1] = mState.zFar;
1861 case GL_COLOR_CLEAR_VALUE:
1862 params[0] = mState.colorClearValue.red;
1863 params[1] = mState.colorClearValue.green;
1864 params[2] = mState.colorClearValue.blue;
1865 params[3] = mState.colorClearValue.alpha;
1867 case GL_BLEND_COLOR:
1868 params[0] = mState.blendColor.red;
1869 params[1] = mState.blendColor.green;
1870 params[2] = mState.blendColor.blue;
1871 params[3] = mState.blendColor.alpha;
1873 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1874 *params = MAX_TEXTURE_MAX_ANISOTROPY;
1883 template bool Context::getIntegerv<GLint>(GLenum pname, GLint *params) const;
1884 template bool Context::getIntegerv<GLint64>(GLenum pname, GLint64 *params) const;
1886 template<typename T> bool Context::getIntegerv(GLenum pname, T *params) const
1888 // Please note: DEPTH_CLEAR_VALUE is not included in our internal getIntegerv implementation
1889 // because it is stored as a float, despite the fact that the GL ES 2.0 spec names
1890 // GetIntegerv as its native query function. As it would require conversion in any
1891 // case, this should make no difference to the calling application. You may find it in
1892 // Context::getFloatv.
1895 case GL_MAX_VERTEX_ATTRIBS: *params = MAX_VERTEX_ATTRIBS; return true;
1896 case GL_MAX_VERTEX_UNIFORM_VECTORS: *params = MAX_VERTEX_UNIFORM_VECTORS; return true;
1897 case GL_MAX_VARYING_VECTORS: *params = MAX_VARYING_VECTORS; return true;
1898 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: *params = MAX_COMBINED_TEXTURE_IMAGE_UNITS; return true;
1899 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: *params = MAX_VERTEX_TEXTURE_IMAGE_UNITS; return true;
1900 case GL_MAX_TEXTURE_IMAGE_UNITS: *params = MAX_TEXTURE_IMAGE_UNITS; return true;
1901 case GL_MAX_FRAGMENT_UNIFORM_VECTORS: *params = MAX_FRAGMENT_UNIFORM_VECTORS; return true;
1902 case GL_MAX_RENDERBUFFER_SIZE: *params = IMPLEMENTATION_MAX_RENDERBUFFER_SIZE; return true;
1903 case GL_NUM_SHADER_BINARY_FORMATS: *params = 0; return true;
1904 case GL_SHADER_BINARY_FORMATS: /* no shader binary formats are supported */ return true;
1905 case GL_ARRAY_BUFFER_BINDING: *params = getArrayBufferName(); return true;
1906 case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = getElementArrayBufferName(); return true;
1907 // case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1908 case GL_DRAW_FRAMEBUFFER_BINDING: *params = mState.drawFramebuffer; return true;
1909 case GL_READ_FRAMEBUFFER_BINDING: *params = mState.readFramebuffer; return true;
1910 case GL_RENDERBUFFER_BINDING: *params = mState.renderbuffer.name(); return true;
1911 case GL_CURRENT_PROGRAM: *params = mState.currentProgram; return true;
1912 case GL_PACK_ALIGNMENT: *params = mState.packParameters.alignment; return true;
1913 case GL_UNPACK_ALIGNMENT: *params = mState.unpackParameters.alignment; return true;
1914 case GL_GENERATE_MIPMAP_HINT: *params = mState.generateMipmapHint; return true;
1915 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: *params = mState.fragmentShaderDerivativeHint; return true;
1916 case GL_TEXTURE_FILTERING_HINT_CHROMIUM: *params = mState.textureFilteringHint; return true;
1917 case GL_ACTIVE_TEXTURE: *params = (mState.activeSampler + GL_TEXTURE0); return true;
1918 case GL_STENCIL_FUNC: *params = mState.stencilFunc; return true;
1919 case GL_STENCIL_REF: *params = mState.stencilRef; return true;
1920 case GL_STENCIL_VALUE_MASK: *params = sw::clampToSignedInt(mState.stencilMask); return true;
1921 case GL_STENCIL_BACK_FUNC: *params = mState.stencilBackFunc; return true;
1922 case GL_STENCIL_BACK_REF: *params = mState.stencilBackRef; return true;
1923 case GL_STENCIL_BACK_VALUE_MASK: *params = sw::clampToSignedInt(mState.stencilBackMask); return true;
1924 case GL_STENCIL_FAIL: *params = mState.stencilFail; return true;
1925 case GL_STENCIL_PASS_DEPTH_FAIL: *params = mState.stencilPassDepthFail; return true;
1926 case GL_STENCIL_PASS_DEPTH_PASS: *params = mState.stencilPassDepthPass; return true;
1927 case GL_STENCIL_BACK_FAIL: *params = mState.stencilBackFail; return true;
1928 case GL_STENCIL_BACK_PASS_DEPTH_FAIL: *params = mState.stencilBackPassDepthFail; return true;
1929 case GL_STENCIL_BACK_PASS_DEPTH_PASS: *params = mState.stencilBackPassDepthPass; return true;
1930 case GL_DEPTH_FUNC: *params = mState.depthFunc; return true;
1931 case GL_BLEND_SRC_RGB: *params = mState.sourceBlendRGB; return true;
1932 case GL_BLEND_SRC_ALPHA: *params = mState.sourceBlendAlpha; return true;
1933 case GL_BLEND_DST_RGB: *params = mState.destBlendRGB; return true;
1934 case GL_BLEND_DST_ALPHA: *params = mState.destBlendAlpha; return true;
1935 case GL_BLEND_EQUATION_RGB: *params = mState.blendEquationRGB; return true;
1936 case GL_BLEND_EQUATION_ALPHA: *params = mState.blendEquationAlpha; return true;
1937 case GL_STENCIL_WRITEMASK: *params = sw::clampToSignedInt(mState.stencilWritemask); return true;
1938 case GL_STENCIL_BACK_WRITEMASK: *params = sw::clampToSignedInt(mState.stencilBackWritemask); return true;
1939 case GL_STENCIL_CLEAR_VALUE: *params = mState.stencilClearValue; return true;
1940 case GL_SUBPIXEL_BITS: *params = 4; return true;
1941 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB:
1942 case GL_MAX_TEXTURE_SIZE: *params = IMPLEMENTATION_MAX_TEXTURE_SIZE; return true;
1943 case GL_MAX_CUBE_MAP_TEXTURE_SIZE: *params = IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE; return true;
1944 case GL_NUM_COMPRESSED_TEXTURE_FORMATS: *params = NUM_COMPRESSED_TEXTURE_FORMATS; return true;
1945 case GL_MAX_SAMPLES: *params = IMPLEMENTATION_MAX_SAMPLES; return true;
1946 case GL_SAMPLE_BUFFERS:
1949 Framebuffer *framebuffer = getDrawFramebuffer();
1950 int width, height, samples;
1952 if(framebuffer->completeness(width, height, samples) == GL_FRAMEBUFFER_COMPLETE)
1956 case GL_SAMPLE_BUFFERS:
1977 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
1979 Framebuffer *framebuffer = getReadFramebuffer();
1980 *params = framebuffer->getImplementationColorReadType();
1983 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
1985 Framebuffer *framebuffer = getReadFramebuffer();
1986 *params = framebuffer->getImplementationColorReadFormat();
1989 case GL_MAX_VIEWPORT_DIMS:
1991 int maxDimension = IMPLEMENTATION_MAX_RENDERBUFFER_SIZE;
1992 params[0] = maxDimension;
1993 params[1] = maxDimension;
1996 case GL_COMPRESSED_TEXTURE_FORMATS:
1998 for(int i = 0; i < NUM_COMPRESSED_TEXTURE_FORMATS; i++)
2000 params[i] = compressedTextureFormats[i];
2005 params[0] = mState.viewportX;
2006 params[1] = mState.viewportY;
2007 params[2] = mState.viewportWidth;
2008 params[3] = mState.viewportHeight;
2010 case GL_SCISSOR_BOX:
2011 params[0] = mState.scissorX;
2012 params[1] = mState.scissorY;
2013 params[2] = mState.scissorWidth;
2014 params[3] = mState.scissorHeight;
2016 case GL_CULL_FACE_MODE: *params = mState.cullMode; return true;
2017 case GL_FRONT_FACE: *params = mState.frontFace; return true;
2023 Framebuffer *framebuffer = getDrawFramebuffer();
2024 Renderbuffer *colorbuffer = framebuffer->getColorbuffer(0);
2030 case GL_RED_BITS: *params = colorbuffer->getRedSize(); return true;
2031 case GL_GREEN_BITS: *params = colorbuffer->getGreenSize(); return true;
2032 case GL_BLUE_BITS: *params = colorbuffer->getBlueSize(); return true;
2033 case GL_ALPHA_BITS: *params = colorbuffer->getAlphaSize(); return true;
2044 Framebuffer *framebuffer = getDrawFramebuffer();
2045 Renderbuffer *depthbuffer = framebuffer->getDepthbuffer();
2049 *params = depthbuffer->getDepthSize();
2057 case GL_STENCIL_BITS:
2059 Framebuffer *framebuffer = getDrawFramebuffer();
2060 Renderbuffer *stencilbuffer = framebuffer->getStencilbuffer();
2064 *params = stencilbuffer->getStencilSize();
2072 case GL_TEXTURE_BINDING_2D:
2073 if(mState.activeSampler > MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1)
2075 error(GL_INVALID_OPERATION);
2079 *params = mState.samplerTexture[TEXTURE_2D][mState.activeSampler].name();
2081 case GL_TEXTURE_BINDING_CUBE_MAP:
2082 if(mState.activeSampler > MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1)
2084 error(GL_INVALID_OPERATION);
2088 *params = mState.samplerTexture[TEXTURE_CUBE][mState.activeSampler].name();
2090 case GL_TEXTURE_BINDING_RECTANGLE_ARB:
2091 if(mState.activeSampler > MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1)
2093 error(GL_INVALID_OPERATION);
2097 *params = mState.samplerTexture[TEXTURE_2D_RECT][mState.activeSampler].name();
2099 case GL_TEXTURE_BINDING_EXTERNAL_OES:
2100 if(mState.activeSampler > MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1)
2102 error(GL_INVALID_OPERATION);
2106 *params = mState.samplerTexture[TEXTURE_EXTERNAL][mState.activeSampler].name();
2108 case GL_TEXTURE_BINDING_3D_OES:
2109 if(mState.activeSampler > MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1)
2111 error(GL_INVALID_OPERATION);
2115 *params = mState.samplerTexture[TEXTURE_3D][mState.activeSampler].name();
2117 case GL_DRAW_BUFFER0:
2118 case GL_DRAW_BUFFER1:
2119 case GL_DRAW_BUFFER2:
2120 case GL_DRAW_BUFFER3:
2121 case GL_DRAW_BUFFER4:
2122 case GL_DRAW_BUFFER5:
2123 case GL_DRAW_BUFFER6:
2124 case GL_DRAW_BUFFER7:
2125 case GL_DRAW_BUFFER8:
2126 case GL_DRAW_BUFFER9:
2127 case GL_DRAW_BUFFER10:
2128 case GL_DRAW_BUFFER11:
2129 case GL_DRAW_BUFFER12:
2130 case GL_DRAW_BUFFER13:
2131 case GL_DRAW_BUFFER14:
2132 case GL_DRAW_BUFFER15:
2133 if((pname - GL_DRAW_BUFFER0) < MAX_DRAW_BUFFERS)
2135 *params = getDrawFramebuffer()->getDrawBuffer(pname - GL_DRAW_BUFFER0);
2142 case GL_MAX_DRAW_BUFFERS:
2143 *params = MAX_DRAW_BUFFERS;
2145 case GL_MAX_COLOR_ATTACHMENTS: // Note: MAX_COLOR_ATTACHMENTS_EXT added by GL_EXT_draw_buffers
2146 *params = MAX_COLOR_ATTACHMENTS;
2152 if(clientVersion >= 3)
2156 case GL_TEXTURE_BINDING_2D_ARRAY:
2157 if(mState.activeSampler > MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1)
2159 error(GL_INVALID_OPERATION);
2163 *params = mState.samplerTexture[TEXTURE_2D_ARRAY][mState.activeSampler].name();
2165 case GL_COPY_READ_BUFFER_BINDING:
2166 *params = mState.copyReadBuffer.name();
2168 case GL_COPY_WRITE_BUFFER_BINDING:
2169 *params = mState.copyWriteBuffer.name();
2171 case GL_MAJOR_VERSION:
2172 *params = clientVersion;
2174 case GL_MAX_3D_TEXTURE_SIZE:
2175 *params = IMPLEMENTATION_MAX_TEXTURE_SIZE;
2177 case GL_MAX_ARRAY_TEXTURE_LAYERS:
2178 *params = IMPLEMENTATION_MAX_TEXTURE_SIZE;
2180 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
2181 *params = MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS;
2183 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
2184 *params = MAX_VERTEX_UNIFORM_BLOCKS + MAX_FRAGMENT_UNIFORM_BLOCKS;
2186 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
2187 *params = MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS;
2189 case GL_MAX_ELEMENT_INDEX:
2190 *params = MAX_ELEMENT_INDEX;
2192 case GL_MAX_ELEMENTS_INDICES:
2193 *params = MAX_ELEMENTS_INDICES;
2195 case GL_MAX_ELEMENTS_VERTICES:
2196 *params = MAX_ELEMENTS_VERTICES;
2198 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
2199 *params = MAX_FRAGMENT_INPUT_VECTORS * 4;
2201 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
2202 *params = MAX_FRAGMENT_UNIFORM_BLOCKS;
2204 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
2205 *params = MAX_FRAGMENT_UNIFORM_COMPONENTS;
2207 case GL_MAX_PROGRAM_TEXEL_OFFSET:
2208 // Note: SwiftShader has no actual texel offset limit, so this limit can be modified if required.
2209 // In any case, any behavior outside the specified range is valid since the spec mentions:
2210 // (see OpenGL ES 3.0.5, 3.8.10.1 Scale Factor and Level of Detail, p.153)
2211 // "If any of the offset values are outside the range of the implementation-defined values
2212 // MIN_PROGRAM_TEXEL_OFFSET and MAX_PROGRAM_TEXEL_OFFSET, results of the texture lookup are
2214 *params = MAX_PROGRAM_TEXEL_OFFSET;
2216 case GL_MAX_SERVER_WAIT_TIMEOUT:
2219 case GL_MAX_TEXTURE_LOD_BIAS:
2220 *params = MAX_TEXTURE_LOD_BIAS;
2222 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
2223 *params = sw::MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS;
2225 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
2226 *params = MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS;
2228 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
2229 *params = sw::MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS;
2231 case GL_MAX_UNIFORM_BLOCK_SIZE:
2232 *params = MAX_UNIFORM_BLOCK_SIZE;
2234 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
2235 *params = MAX_UNIFORM_BUFFER_BINDINGS;
2237 case GL_MAX_VARYING_COMPONENTS:
2238 *params = MAX_VARYING_VECTORS * 4;
2240 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
2241 *params = MAX_VERTEX_OUTPUT_VECTORS * 4;
2243 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
2244 *params = MAX_VERTEX_UNIFORM_BLOCKS;
2246 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
2247 *params = MAX_VERTEX_UNIFORM_COMPONENTS;
2249 case GL_MIN_PROGRAM_TEXEL_OFFSET:
2250 // Note: SwiftShader has no actual texel offset limit, so this limit can be modified if required.
2251 // In any case, any behavior outside the specified range is valid since the spec mentions:
2252 // (see OpenGL ES 3.0.5, 3.8.10.1 Scale Factor and Level of Detail, p.153)
2253 // "If any of the offset values are outside the range of the implementation-defined values
2254 // MIN_PROGRAM_TEXEL_OFFSET and MAX_PROGRAM_TEXEL_OFFSET, results of the texture lookup are
2256 *params = MIN_PROGRAM_TEXEL_OFFSET;
2258 case GL_MINOR_VERSION:
2261 case GL_NUM_EXTENSIONS:
2262 GLuint numExtensions;
2263 getExtensions(0, &numExtensions);
2264 *params = numExtensions;
2266 case GL_NUM_PROGRAM_BINARY_FORMATS:
2267 *params = NUM_PROGRAM_BINARY_FORMATS;
2269 case GL_PACK_ROW_LENGTH:
2270 *params = mState.packParameters.rowLength;
2272 case GL_PACK_SKIP_PIXELS:
2273 *params = mState.packParameters.skipPixels;
2275 case GL_PACK_SKIP_ROWS:
2276 *params = mState.packParameters.skipRows;
2278 case GL_PIXEL_PACK_BUFFER_BINDING:
2279 *params = mState.pixelPackBuffer.name();
2281 case GL_PIXEL_UNPACK_BUFFER_BINDING:
2282 *params = mState.pixelUnpackBuffer.name();
2284 case GL_PROGRAM_BINARY_FORMATS:
2285 // Since NUM_PROGRAM_BINARY_FORMATS is 0, the input
2286 // should be a 0 sized array, so don't write to params
2288 case GL_READ_BUFFER:
2289 *params = getReadFramebuffer()->getReadBuffer();
2291 case GL_SAMPLER_BINDING:
2292 *params = mState.sampler[mState.activeSampler].name();
2294 case GL_UNIFORM_BUFFER_BINDING:
2295 *params = mState.genericUniformBuffer.name();
2297 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
2298 *params = UNIFORM_BUFFER_OFFSET_ALIGNMENT;
2300 case GL_UNIFORM_BUFFER_SIZE:
2301 *params = static_cast<T>(mState.genericUniformBuffer->size());
2303 case GL_UNIFORM_BUFFER_START:
2304 *params = static_cast<T>(mState.genericUniformBuffer->offset());
2306 case GL_UNPACK_IMAGE_HEIGHT:
2307 *params = mState.unpackParameters.imageHeight;
2309 case GL_UNPACK_ROW_LENGTH:
2310 *params = mState.unpackParameters.rowLength;
2312 case GL_UNPACK_SKIP_IMAGES:
2313 *params = mState.unpackParameters.skipImages;
2315 case GL_UNPACK_SKIP_PIXELS:
2316 *params = mState.unpackParameters.skipPixels;
2318 case GL_UNPACK_SKIP_ROWS:
2319 *params = mState.unpackParameters.skipRows;
2321 case GL_VERTEX_ARRAY_BINDING:
2322 *params = getCurrentVertexArray()->name;
2324 case GL_TRANSFORM_FEEDBACK_BINDING:
2326 TransformFeedback* transformFeedback = getTransformFeedback(mState.transformFeedback);
2327 if(transformFeedback)
2329 *params = transformFeedback->name;
2337 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
2339 TransformFeedback* transformFeedback = getTransformFeedback(mState.transformFeedback);
2340 if(transformFeedback)
2342 *params = transformFeedback->getGenericBufferName();
2358 template bool Context::getTransformFeedbackiv<GLint>(GLuint index, GLenum pname, GLint *param) const;
2359 template bool Context::getTransformFeedbackiv<GLint64>(GLuint index, GLenum pname, GLint64 *param) const;
2361 template<typename T> bool Context::getTransformFeedbackiv(GLuint index, GLenum pname, T *param) const
2363 TransformFeedback* transformFeedback = getTransformFeedback(mState.transformFeedback);
2364 if(!transformFeedback)
2371 case GL_TRANSFORM_FEEDBACK_BINDING: // GLint, initially 0
2372 *param = transformFeedback->name;
2374 case GL_TRANSFORM_FEEDBACK_ACTIVE: // boolean, initially GL_FALSE
2375 *param = transformFeedback->isActive();
2377 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: // name, initially 0
2378 *param = transformFeedback->getBufferName(index);
2380 case GL_TRANSFORM_FEEDBACK_PAUSED: // boolean, initially GL_FALSE
2381 *param = transformFeedback->isPaused();
2383 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE: // indexed[n] 64-bit integer, initially 0
2384 if(transformFeedback->getBuffer(index))
2386 *param = transformFeedback->getSize(index);
2390 case GL_TRANSFORM_FEEDBACK_BUFFER_START: // indexed[n] 64-bit integer, initially 0
2391 if(transformFeedback->getBuffer(index))
2393 *param = transformFeedback->getOffset(index);
2404 template bool Context::getUniformBufferiv<GLint>(GLuint index, GLenum pname, GLint *param) const;
2405 template bool Context::getUniformBufferiv<GLint64>(GLuint index, GLenum pname, GLint64 *param) const;
2407 template<typename T> bool Context::getUniformBufferiv(GLuint index, GLenum pname, T *param) const
2411 case GL_UNIFORM_BUFFER_BINDING:
2412 case GL_UNIFORM_BUFFER_SIZE:
2413 case GL_UNIFORM_BUFFER_START:
2414 if(index >= MAX_UNIFORM_BUFFER_BINDINGS)
2416 return error(GL_INVALID_VALUE, true);
2423 const BufferBinding& uniformBuffer = mState.uniformBuffers[index];
2427 case GL_UNIFORM_BUFFER_BINDING: // name, initially 0
2428 *param = uniformBuffer.get().name();
2430 case GL_UNIFORM_BUFFER_SIZE: // indexed[n] 64-bit integer, initially 0
2431 *param = uniformBuffer.getSize();
2433 case GL_UNIFORM_BUFFER_START: // indexed[n] 64-bit integer, initially 0
2434 *param = uniformBuffer.getOffset();
2443 bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams) const
2445 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
2446 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
2447 // to the fact that it is stored internally as a float, and so would require conversion
2448 // if returned from Context::getIntegerv. Since this conversion is already implemented
2449 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
2450 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
2454 case GL_COMPRESSED_TEXTURE_FORMATS:
2457 *numParams = NUM_COMPRESSED_TEXTURE_FORMATS;
2460 case GL_SHADER_BINARY_FORMATS:
2466 case GL_MAX_VERTEX_ATTRIBS:
2467 case GL_MAX_VERTEX_UNIFORM_VECTORS:
2468 case GL_MAX_VARYING_VECTORS:
2469 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
2470 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
2471 case GL_MAX_TEXTURE_IMAGE_UNITS:
2472 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
2473 case GL_MAX_RENDERBUFFER_SIZE:
2474 case GL_NUM_SHADER_BINARY_FORMATS:
2475 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
2476 case GL_ARRAY_BUFFER_BINDING:
2477 case GL_FRAMEBUFFER_BINDING: // Same as GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
2478 case GL_READ_FRAMEBUFFER_BINDING: // Same as GL_READ_FRAMEBUFFER_BINDING_ANGLE
2479 case GL_RENDERBUFFER_BINDING:
2480 case GL_CURRENT_PROGRAM:
2481 case GL_PACK_ALIGNMENT:
2482 case GL_UNPACK_ALIGNMENT:
2483 case GL_GENERATE_MIPMAP_HINT:
2484 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
2485 case GL_TEXTURE_FILTERING_HINT_CHROMIUM:
2491 case GL_STENCIL_BITS:
2492 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
2493 case GL_CULL_FACE_MODE:
2495 case GL_ACTIVE_TEXTURE:
2496 case GL_STENCIL_FUNC:
2497 case GL_STENCIL_VALUE_MASK:
2498 case GL_STENCIL_REF:
2499 case GL_STENCIL_FAIL:
2500 case GL_STENCIL_PASS_DEPTH_FAIL:
2501 case GL_STENCIL_PASS_DEPTH_PASS:
2502 case GL_STENCIL_BACK_FUNC:
2503 case GL_STENCIL_BACK_VALUE_MASK:
2504 case GL_STENCIL_BACK_REF:
2505 case GL_STENCIL_BACK_FAIL:
2506 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
2507 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
2509 case GL_BLEND_SRC_RGB:
2510 case GL_BLEND_SRC_ALPHA:
2511 case GL_BLEND_DST_RGB:
2512 case GL_BLEND_DST_ALPHA:
2513 case GL_BLEND_EQUATION_RGB:
2514 case GL_BLEND_EQUATION_ALPHA:
2515 case GL_STENCIL_WRITEMASK:
2516 case GL_STENCIL_BACK_WRITEMASK:
2517 case GL_STENCIL_CLEAR_VALUE:
2518 case GL_SUBPIXEL_BITS:
2519 case GL_MAX_TEXTURE_SIZE:
2520 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
2521 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB:
2522 case GL_SAMPLE_BUFFERS:
2524 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
2525 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
2526 case GL_TEXTURE_BINDING_2D:
2527 case GL_TEXTURE_BINDING_CUBE_MAP:
2528 case GL_TEXTURE_BINDING_RECTANGLE_ARB:
2529 case GL_TEXTURE_BINDING_EXTERNAL_OES:
2530 case GL_TEXTURE_BINDING_3D_OES:
2531 case GL_COPY_READ_BUFFER_BINDING:
2532 case GL_COPY_WRITE_BUFFER_BINDING:
2533 case GL_DRAW_BUFFER0:
2534 case GL_DRAW_BUFFER1:
2535 case GL_DRAW_BUFFER2:
2536 case GL_DRAW_BUFFER3:
2537 case GL_DRAW_BUFFER4:
2538 case GL_DRAW_BUFFER5:
2539 case GL_DRAW_BUFFER6:
2540 case GL_DRAW_BUFFER7:
2541 case GL_DRAW_BUFFER8:
2542 case GL_DRAW_BUFFER9:
2543 case GL_DRAW_BUFFER10:
2544 case GL_DRAW_BUFFER11:
2545 case GL_DRAW_BUFFER12:
2546 case GL_DRAW_BUFFER13:
2547 case GL_DRAW_BUFFER14:
2548 case GL_DRAW_BUFFER15:
2549 case GL_MAJOR_VERSION:
2550 case GL_MAX_3D_TEXTURE_SIZE:
2551 case GL_MAX_ARRAY_TEXTURE_LAYERS:
2552 case GL_MAX_COLOR_ATTACHMENTS:
2553 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
2554 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
2555 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
2556 case GL_MAX_DRAW_BUFFERS:
2557 case GL_MAX_ELEMENT_INDEX:
2558 case GL_MAX_ELEMENTS_INDICES:
2559 case GL_MAX_ELEMENTS_VERTICES:
2560 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
2561 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
2562 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
2563 case GL_MAX_PROGRAM_TEXEL_OFFSET:
2564 case GL_MAX_SERVER_WAIT_TIMEOUT:
2565 case GL_MAX_TEXTURE_LOD_BIAS:
2566 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
2567 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
2568 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
2569 case GL_MAX_UNIFORM_BLOCK_SIZE:
2570 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
2571 case GL_MAX_VARYING_COMPONENTS:
2572 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
2573 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
2574 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
2575 case GL_MIN_PROGRAM_TEXEL_OFFSET:
2576 case GL_MINOR_VERSION:
2577 case GL_NUM_EXTENSIONS:
2578 case GL_NUM_PROGRAM_BINARY_FORMATS:
2579 case GL_PACK_ROW_LENGTH:
2580 case GL_PACK_SKIP_PIXELS:
2581 case GL_PACK_SKIP_ROWS:
2582 case GL_PIXEL_PACK_BUFFER_BINDING:
2583 case GL_PIXEL_UNPACK_BUFFER_BINDING:
2584 case GL_PROGRAM_BINARY_FORMATS:
2585 case GL_READ_BUFFER:
2586 case GL_SAMPLER_BINDING:
2587 case GL_TEXTURE_BINDING_2D_ARRAY:
2588 case GL_UNIFORM_BUFFER_BINDING:
2589 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
2590 case GL_UNIFORM_BUFFER_SIZE:
2591 case GL_UNIFORM_BUFFER_START:
2592 case GL_UNPACK_IMAGE_HEIGHT:
2593 case GL_UNPACK_ROW_LENGTH:
2594 case GL_UNPACK_SKIP_IMAGES:
2595 case GL_UNPACK_SKIP_PIXELS:
2596 case GL_UNPACK_SKIP_ROWS:
2597 case GL_VERTEX_ARRAY_BINDING:
2598 case GL_TRANSFORM_FEEDBACK_BINDING:
2599 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
2605 case GL_MAX_SAMPLES:
2611 case GL_MAX_VIEWPORT_DIMS:
2618 case GL_SCISSOR_BOX:
2624 case GL_SHADER_COMPILER:
2625 case GL_SAMPLE_COVERAGE_INVERT:
2626 case GL_DEPTH_WRITEMASK:
2627 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
2628 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
2629 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as bool-natural
2630 case GL_SAMPLE_COVERAGE:
2631 case GL_SCISSOR_TEST:
2632 case GL_STENCIL_TEST:
2636 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
2637 case GL_RASTERIZER_DISCARD:
2638 case GL_TRANSFORM_FEEDBACK_ACTIVE:
2639 case GL_TRANSFORM_FEEDBACK_PAUSED:
2645 case GL_COLOR_WRITEMASK:
2651 case GL_POLYGON_OFFSET_FACTOR:
2652 case GL_POLYGON_OFFSET_UNITS:
2653 case GL_SAMPLE_COVERAGE_VALUE:
2654 case GL_DEPTH_CLEAR_VALUE:
2661 case GL_ALIASED_LINE_WIDTH_RANGE:
2662 case GL_ALIASED_POINT_SIZE_RANGE:
2663 case GL_DEPTH_RANGE:
2669 case GL_COLOR_CLEAR_VALUE:
2670 case GL_BLEND_COLOR:
2676 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
2687 void Context::applyScissor(int width, int height)
2689 if(mState.scissorTestEnabled)
2691 sw::Rect scissor = { mState.scissorX, mState.scissorY, mState.scissorX + mState.scissorWidth, mState.scissorY + mState.scissorHeight };
2692 scissor.clip(0, 0, width, height);
2694 device->setScissorRect(scissor);
2695 device->setScissorEnable(true);
2699 device->setScissorEnable(false);
2703 // Applies the render target surface, depth stencil surface, viewport rectangle and scissor rectangle
2704 bool Context::applyRenderTarget()
2706 Framebuffer *framebuffer = getDrawFramebuffer();
2707 int width, height, samples;
2709 if(!framebuffer || framebuffer->completeness(width, height, samples) != GL_FRAMEBUFFER_COMPLETE)
2711 return error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
2714 for(int i = 0; i < MAX_DRAW_BUFFERS; i++)
2716 if(framebuffer->getDrawBuffer(i) != GL_NONE)
2718 egl::Image *renderTarget = framebuffer->getRenderTarget(i);
2719 GLint layer = framebuffer->getColorbufferLayer(i);
2720 device->setRenderTarget(i, renderTarget, layer);
2721 if(renderTarget) renderTarget->release();
2725 device->setRenderTarget(i, nullptr, 0);
2729 egl::Image *depthBuffer = framebuffer->getDepthBuffer();
2730 GLint dLayer = framebuffer->getDepthbufferLayer();
2731 device->setDepthBuffer(depthBuffer, dLayer);
2732 if(depthBuffer) depthBuffer->release();
2734 egl::Image *stencilBuffer = framebuffer->getStencilBuffer();
2735 GLint sLayer = framebuffer->getStencilbufferLayer();
2736 device->setStencilBuffer(stencilBuffer, sLayer);
2737 if(stencilBuffer) stencilBuffer->release();
2740 float zNear = clamp01(mState.zNear);
2741 float zFar = clamp01(mState.zFar);
2743 viewport.x0 = mState.viewportX;
2744 viewport.y0 = mState.viewportY;
2745 viewport.width = mState.viewportWidth;
2746 viewport.height = mState.viewportHeight;
2747 viewport.minZ = zNear;
2748 viewport.maxZ = zFar;
2750 device->setViewport(viewport);
2752 applyScissor(width, height);
2754 Program *program = getCurrentProgram();
2758 GLfloat nearFarDiff[3] = {zNear, zFar, zFar - zNear};
2759 program->setUniform1fv(program->getUniformLocation("gl_DepthRange.near"), 1, &nearFarDiff[0]);
2760 program->setUniform1fv(program->getUniformLocation("gl_DepthRange.far"), 1, &nearFarDiff[1]);
2761 program->setUniform1fv(program->getUniformLocation("gl_DepthRange.diff"), 1, &nearFarDiff[2]);
2767 // Applies the fixed-function state (culling, depth test, alpha blending, stenciling, etc)
2768 void Context::applyState(GLenum drawMode)
2770 Framebuffer *framebuffer = getDrawFramebuffer();
2772 if(mState.cullFaceEnabled)
2774 device->setCullMode(es2sw::ConvertCullMode(mState.cullMode, mState.frontFace));
2778 device->setCullMode(sw::CULL_NONE);
2781 if(mDepthStateDirty)
2783 if(mState.depthTestEnabled)
2785 device->setDepthBufferEnable(true);
2786 device->setDepthCompare(es2sw::ConvertDepthComparison(mState.depthFunc));
2790 device->setDepthBufferEnable(false);
2793 mDepthStateDirty = false;
2796 if(mBlendStateDirty)
2798 if(mState.blendEnabled)
2800 device->setAlphaBlendEnable(true);
2801 device->setSeparateAlphaBlendEnable(true);
2803 device->setBlendConstant(es2sw::ConvertColor(mState.blendColor));
2805 device->setSourceBlendFactor(es2sw::ConvertBlendFunc(mState.sourceBlendRGB));
2806 device->setDestBlendFactor(es2sw::ConvertBlendFunc(mState.destBlendRGB));
2807 device->setBlendOperation(es2sw::ConvertBlendOp(mState.blendEquationRGB));
2809 device->setSourceBlendFactorAlpha(es2sw::ConvertBlendFunc(mState.sourceBlendAlpha));
2810 device->setDestBlendFactorAlpha(es2sw::ConvertBlendFunc(mState.destBlendAlpha));
2811 device->setBlendOperationAlpha(es2sw::ConvertBlendOp(mState.blendEquationAlpha));
2815 device->setAlphaBlendEnable(false);
2818 mBlendStateDirty = false;
2821 if(mStencilStateDirty || mFrontFaceDirty)
2823 if(mState.stencilTestEnabled && framebuffer->hasStencil())
2825 device->setStencilEnable(true);
2826 device->setTwoSidedStencil(true);
2828 // get the maximum size of the stencil ref
2829 Renderbuffer *stencilbuffer = framebuffer->getStencilbuffer();
2830 GLuint maxStencil = (1 << stencilbuffer->getStencilSize()) - 1;
2832 if(mState.frontFace == GL_CCW)
2834 device->setStencilWriteMask(mState.stencilWritemask);
2835 device->setStencilCompare(es2sw::ConvertStencilComparison(mState.stencilFunc));
2837 device->setStencilReference((mState.stencilRef < (GLint)maxStencil) ? mState.stencilRef : maxStencil);
2838 device->setStencilMask(mState.stencilMask);
2840 device->setStencilFailOperation(es2sw::ConvertStencilOp(mState.stencilFail));
2841 device->setStencilZFailOperation(es2sw::ConvertStencilOp(mState.stencilPassDepthFail));
2842 device->setStencilPassOperation(es2sw::ConvertStencilOp(mState.stencilPassDepthPass));
2844 device->setStencilWriteMaskCCW(mState.stencilBackWritemask);
2845 device->setStencilCompareCCW(es2sw::ConvertStencilComparison(mState.stencilBackFunc));
2847 device->setStencilReferenceCCW((mState.stencilBackRef < (GLint)maxStencil) ? mState.stencilBackRef : maxStencil);
2848 device->setStencilMaskCCW(mState.stencilBackMask);
2850 device->setStencilFailOperationCCW(es2sw::ConvertStencilOp(mState.stencilBackFail));
2851 device->setStencilZFailOperationCCW(es2sw::ConvertStencilOp(mState.stencilBackPassDepthFail));
2852 device->setStencilPassOperationCCW(es2sw::ConvertStencilOp(mState.stencilBackPassDepthPass));
2856 device->setStencilWriteMaskCCW(mState.stencilWritemask);
2857 device->setStencilCompareCCW(es2sw::ConvertStencilComparison(mState.stencilFunc));
2859 device->setStencilReferenceCCW((mState.stencilRef < (GLint)maxStencil) ? mState.stencilRef : maxStencil);
2860 device->setStencilMaskCCW(mState.stencilMask);
2862 device->setStencilFailOperationCCW(es2sw::ConvertStencilOp(mState.stencilFail));
2863 device->setStencilZFailOperationCCW(es2sw::ConvertStencilOp(mState.stencilPassDepthFail));
2864 device->setStencilPassOperationCCW(es2sw::ConvertStencilOp(mState.stencilPassDepthPass));
2866 device->setStencilWriteMask(mState.stencilBackWritemask);
2867 device->setStencilCompare(es2sw::ConvertStencilComparison(mState.stencilBackFunc));
2869 device->setStencilReference((mState.stencilBackRef < (GLint)maxStencil) ? mState.stencilBackRef : maxStencil);
2870 device->setStencilMask(mState.stencilBackMask);
2872 device->setStencilFailOperation(es2sw::ConvertStencilOp(mState.stencilBackFail));
2873 device->setStencilZFailOperation(es2sw::ConvertStencilOp(mState.stencilBackPassDepthFail));
2874 device->setStencilPassOperation(es2sw::ConvertStencilOp(mState.stencilBackPassDepthPass));
2879 device->setStencilEnable(false);
2882 mStencilStateDirty = false;
2883 mFrontFaceDirty = false;
2888 for(int i = 0; i < MAX_DRAW_BUFFERS; i++)
2890 device->setColorWriteMask(i, es2sw::ConvertColorMask(mState.colorMaskRed, mState.colorMaskGreen, mState.colorMaskBlue, mState.colorMaskAlpha));
2893 device->setDepthWriteEnable(mState.depthMask);
2895 mMaskStateDirty = false;
2898 if(mPolygonOffsetStateDirty)
2900 if(mState.polygonOffsetFillEnabled)
2902 Renderbuffer *depthbuffer = framebuffer->getDepthbuffer();
2905 device->setSlopeDepthBias(mState.polygonOffsetFactor);
2906 float depthBias = ldexp(mState.polygonOffsetUnits, -23); // We use 32-bit floating-point for all depth formats, with 23 mantissa bits.
2907 device->setDepthBias(depthBias);
2912 device->setSlopeDepthBias(0);
2913 device->setDepthBias(0);
2916 mPolygonOffsetStateDirty = false;
2919 if(mSampleStateDirty)
2921 if(mState.sampleAlphaToCoverageEnabled)
2923 device->setTransparencyAntialiasing(sw::TRANSPARENCY_ALPHA_TO_COVERAGE);
2927 device->setTransparencyAntialiasing(sw::TRANSPARENCY_NONE);
2930 if(mState.sampleCoverageEnabled)
2932 unsigned int mask = 0;
2933 if(mState.sampleCoverageValue != 0)
2935 int width, height, samples;
2936 framebuffer->completeness(width, height, samples);
2938 float threshold = 0.5f;
2940 for(int i = 0; i < samples; i++)
2944 if((i + 1) * mState.sampleCoverageValue >= threshold)
2952 if(mState.sampleCoverageInvert)
2957 device->setMultiSampleMask(mask);
2961 device->setMultiSampleMask(0xFFFFFFFF);
2964 mSampleStateDirty = false;
2967 if(mDitherStateDirty)
2969 // UNIMPLEMENTED(); // FIXME
2971 mDitherStateDirty = false;
2974 device->setRasterizerDiscard(mState.rasterizerDiscardEnabled);
2977 GLenum Context::applyVertexBuffer(GLint base, GLint first, GLsizei count, GLsizei instanceId)
2979 TranslatedAttribute attributes[MAX_VERTEX_ATTRIBS];
2981 GLenum err = mVertexDataManager->prepareVertexData(first, count, attributes, instanceId);
2982 if(err != GL_NO_ERROR)
2987 Program *program = getCurrentProgram();
2989 device->resetInputStreams(false);
2991 for(int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
2993 if(program->getAttributeStream(i) == -1)
2998 sw::Resource *resource = attributes[i].vertexBuffer;
2999 const void *buffer = (char*)resource->data() + attributes[i].offset;
3001 int stride = attributes[i].stride;
3003 buffer = (char*)buffer + stride * base;
3005 sw::Stream attribute(resource, buffer, stride);
3007 attribute.type = attributes[i].type;
3008 attribute.count = attributes[i].count;
3009 attribute.normalized = attributes[i].normalized;
3011 int stream = program->getAttributeStream(i);
3012 device->setInputStream(stream, attribute);
3018 // Applies the indices and element array bindings
3019 GLenum Context::applyIndexBuffer(const void *indices, GLuint start, GLuint end, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo)
3021 GLenum err = mIndexDataManager->prepareIndexData(mode, type, start, end, count, getCurrentVertexArray()->getElementArrayBuffer(), indices, indexInfo, isPrimitiveRestartFixedIndexEnabled());
3023 if(err == GL_NO_ERROR)
3025 device->setIndexBuffer(indexInfo->indexBuffer);
3031 // Applies the shaders and shader constants
3032 void Context::applyShaders()
3034 Program *programObject = getCurrentProgram();
3035 sw::VertexShader *vertexShader = programObject->getVertexShader();
3036 sw::PixelShader *pixelShader = programObject->getPixelShader();
3038 device->setVertexShader(vertexShader);
3039 device->setPixelShader(pixelShader);
3041 if(programObject->getSerial() != mAppliedProgramSerial)
3043 programObject->dirtyAllUniforms();
3044 mAppliedProgramSerial = programObject->getSerial();
3047 programObject->applyTransformFeedback(device, getTransformFeedback());
3048 programObject->applyUniformBuffers(device, mState.uniformBuffers);
3049 programObject->applyUniforms(device);
3052 void Context::applyTextures()
3054 applyTextures(sw::SAMPLER_PIXEL);
3055 applyTextures(sw::SAMPLER_VERTEX);
3058 void Context::applyTextures(sw::SamplerType samplerType)
3060 Program *programObject = getCurrentProgram();
3062 int samplerCount = (samplerType == sw::SAMPLER_PIXEL) ? MAX_TEXTURE_IMAGE_UNITS : MAX_VERTEX_TEXTURE_IMAGE_UNITS; // Range of samplers of given sampler type
3064 for(int samplerIndex = 0; samplerIndex < samplerCount; samplerIndex++)
3066 int textureUnit = programObject->getSamplerMapping(samplerType, samplerIndex); // OpenGL texture image unit index
3068 if(textureUnit != -1)
3070 TextureType textureType = programObject->getSamplerTextureType(samplerType, samplerIndex);
3072 Texture *texture = getSamplerTexture(textureUnit, textureType);
3074 if(texture->isSamplerComplete())
3076 GLenum wrapS, wrapT, wrapR, minFilter, magFilter, compFunc, compMode;
3077 GLfloat minLOD, maxLOD;
3079 Sampler *samplerObject = mState.sampler[textureUnit];
3082 wrapS = samplerObject->getWrapS();
3083 wrapT = samplerObject->getWrapT();
3084 wrapR = samplerObject->getWrapR();
3085 minFilter = samplerObject->getMinFilter();
3086 magFilter = samplerObject->getMagFilter();
3087 minLOD = samplerObject->getMinLod();
3088 maxLOD = samplerObject->getMaxLod();
3089 compFunc = samplerObject->getCompareFunc();
3090 compMode = samplerObject->getCompareMode();
3094 wrapS = texture->getWrapS();
3095 wrapT = texture->getWrapT();
3096 wrapR = texture->getWrapR();
3097 minFilter = texture->getMinFilter();
3098 magFilter = texture->getMagFilter();
3099 minLOD = texture->getMinLOD();
3100 maxLOD = texture->getMaxLOD();
3101 compFunc = texture->getCompareFunc();
3102 compMode = texture->getCompareMode();
3105 GLfloat maxAnisotropy = texture->getMaxAnisotropy();
3106 GLint baseLevel = texture->getBaseLevel();
3107 GLint maxLevel = texture->getMaxLevel();
3108 GLenum swizzleR = texture->getSwizzleR();
3109 GLenum swizzleG = texture->getSwizzleG();
3110 GLenum swizzleB = texture->getSwizzleB();
3111 GLenum swizzleA = texture->getSwizzleA();
3113 device->setAddressingModeU(samplerType, samplerIndex, es2sw::ConvertTextureWrap(wrapS));
3114 device->setAddressingModeV(samplerType, samplerIndex, es2sw::ConvertTextureWrap(wrapT));
3115 device->setAddressingModeW(samplerType, samplerIndex, es2sw::ConvertTextureWrap(wrapR));
3116 device->setCompareFunc(samplerType, samplerIndex, es2sw::ConvertCompareFunc(compFunc, compMode));
3117 device->setSwizzleR(samplerType, samplerIndex, es2sw::ConvertSwizzleType(swizzleR));
3118 device->setSwizzleG(samplerType, samplerIndex, es2sw::ConvertSwizzleType(swizzleG));
3119 device->setSwizzleB(samplerType, samplerIndex, es2sw::ConvertSwizzleType(swizzleB));
3120 device->setSwizzleA(samplerType, samplerIndex, es2sw::ConvertSwizzleType(swizzleA));
3121 device->setMinLod(samplerType, samplerIndex, minLOD);
3122 device->setMaxLod(samplerType, samplerIndex, maxLOD);
3123 device->setBaseLevel(samplerType, samplerIndex, baseLevel);
3124 device->setMaxLevel(samplerType, samplerIndex, maxLevel);
3125 device->setTextureFilter(samplerType, samplerIndex, es2sw::ConvertTextureFilter(minFilter, magFilter, maxAnisotropy));
3126 device->setMipmapFilter(samplerType, samplerIndex, es2sw::ConvertMipMapFilter(minFilter));
3127 device->setMaxAnisotropy(samplerType, samplerIndex, maxAnisotropy);
3128 device->setHighPrecisionFiltering(samplerType, samplerIndex, mState.textureFilteringHint == GL_NICEST);
3130 applyTexture(samplerType, samplerIndex, texture);
3134 applyTexture(samplerType, samplerIndex, nullptr);
3139 applyTexture(samplerType, samplerIndex, nullptr);
3144 void Context::applyTexture(sw::SamplerType type, int index, Texture *baseTexture)
3146 Program *program = getCurrentProgram();
3147 int sampler = (type == sw::SAMPLER_PIXEL) ? index : 16 + index;
3148 bool textureUsed = false;
3150 if(type == sw::SAMPLER_PIXEL)
3152 textureUsed = program->getPixelShader()->usesSampler(index);
3154 else if(type == sw::SAMPLER_VERTEX)
3156 textureUsed = program->getVertexShader()->usesSampler(index);
3158 else UNREACHABLE(type);
3160 sw::Resource *resource = nullptr;
3162 if(baseTexture && textureUsed)
3164 resource = baseTexture->getResource();
3167 device->setTextureResource(sampler, resource);
3169 if(baseTexture && textureUsed)
3171 int baseLevel = baseTexture->getBaseLevel();
3172 int maxLevel = std::min(baseTexture->getTopLevel(), baseTexture->getMaxLevel());
3173 GLenum target = baseTexture->getTarget();
3178 case GL_TEXTURE_EXTERNAL_OES:
3179 case GL_TEXTURE_RECTANGLE_ARB:
3181 Texture2D *texture = static_cast<Texture2D*>(baseTexture);
3183 for(int mipmapLevel = 0; mipmapLevel < sw::MIPMAP_LEVELS; mipmapLevel++)
3185 int surfaceLevel = mipmapLevel + baseLevel;
3187 if(surfaceLevel > maxLevel)
3189 surfaceLevel = maxLevel;
3192 egl::Image *surface = texture->getImage(surfaceLevel);
3193 device->setTextureLevel(sampler, 0, mipmapLevel, surface,
3194 (target == GL_TEXTURE_RECTANGLE_ARB) ? sw::TEXTURE_RECTANGLE : sw::TEXTURE_2D);
3200 Texture3D *texture = static_cast<Texture3D*>(baseTexture);
3202 for(int mipmapLevel = 0; mipmapLevel < sw::MIPMAP_LEVELS; mipmapLevel++)
3204 int surfaceLevel = mipmapLevel + baseLevel;
3206 if(surfaceLevel > maxLevel)
3208 surfaceLevel = maxLevel;
3211 egl::Image *surface = texture->getImage(surfaceLevel);
3212 device->setTextureLevel(sampler, 0, mipmapLevel, surface, sw::TEXTURE_3D);
3216 case GL_TEXTURE_2D_ARRAY:
3218 Texture2DArray *texture = static_cast<Texture2DArray*>(baseTexture);
3220 for(int mipmapLevel = 0; mipmapLevel < sw::MIPMAP_LEVELS; mipmapLevel++)
3222 int surfaceLevel = mipmapLevel + baseLevel;
3224 if(surfaceLevel > maxLevel)
3226 surfaceLevel = maxLevel;
3229 egl::Image *surface = texture->getImage(surfaceLevel);
3230 device->setTextureLevel(sampler, 0, mipmapLevel, surface, sw::TEXTURE_2D_ARRAY);
3234 case GL_TEXTURE_CUBE_MAP:
3236 TextureCubeMap *cubeTexture = static_cast<TextureCubeMap*>(baseTexture);
3238 for(int mipmapLevel = 0; mipmapLevel < sw::MIPMAP_LEVELS; mipmapLevel++)
3240 cubeTexture->updateBorders(mipmapLevel);
3242 for(int face = 0; face < 6; face++)
3244 int surfaceLevel = mipmapLevel + baseLevel;
3246 if(surfaceLevel > maxLevel)
3248 surfaceLevel = maxLevel;
3251 egl::Image *surface = cubeTexture->getImage(face, surfaceLevel);
3252 device->setTextureLevel(sampler, face, mipmapLevel, surface, sw::TEXTURE_CUBE);
3264 device->setTextureLevel(sampler, 0, 0, 0, sw::TEXTURE_NULL);
3268 void Context::readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLsizei *bufSize, void* pixels)
3270 Framebuffer *framebuffer = getReadFramebuffer();
3271 int framebufferWidth, framebufferHeight, framebufferSamples;
3273 if(framebuffer->completeness(framebufferWidth, framebufferHeight, framebufferSamples) != GL_FRAMEBUFFER_COMPLETE)
3275 return error(GL_INVALID_FRAMEBUFFER_OPERATION);
3278 if(getReadFramebufferName() != 0 && framebufferSamples != 0)
3280 return error(GL_INVALID_OPERATION);
3283 if(!IsValidReadPixelsFormatType(framebuffer, format, type, clientVersion))
3285 return error(GL_INVALID_OPERATION);
3288 GLsizei outputWidth = (mState.packParameters.rowLength > 0) ? mState.packParameters.rowLength : width;
3289 GLsizei outputPitch = gl::ComputePitch(outputWidth, format, type, mState.packParameters.alignment);
3290 GLsizei outputHeight = (mState.packParameters.imageHeight == 0) ? height : mState.packParameters.imageHeight;
3291 pixels = getPixelPackBuffer() ? (unsigned char*)getPixelPackBuffer()->data() + (ptrdiff_t)pixels : (unsigned char*)pixels;
3292 pixels = ((char*)pixels) + gl::ComputePackingOffset(format, type, outputWidth, outputHeight, mState.packParameters);
3294 // Sized query sanity check
3297 int requiredSize = outputPitch * height;
3298 if(requiredSize > *bufSize)
3300 return error(GL_INVALID_OPERATION);
3304 egl::Image *renderTarget = nullptr;
3307 case GL_DEPTH_COMPONENT: // GL_NV_read_depth
3308 renderTarget = framebuffer->getDepthBuffer();
3311 renderTarget = framebuffer->getReadRenderTarget();
3317 return error(GL_INVALID_OPERATION);
3320 sw::RectF rect((float)x, (float)y, (float)(x + width), (float)(y + height));
3321 sw::Rect dstRect(0, 0, width, height);
3322 rect.clip(0.0f, 0.0f, (float)renderTarget->getWidth(), (float)renderTarget->getHeight());
3324 sw::Surface *externalSurface = sw::Surface::create(width, height, 1, gl::ConvertReadFormatType(format, type), pixels, outputPitch, outputPitch * outputHeight);
3325 sw::SliceRectF sliceRect(rect);
3326 sw::SliceRect dstSliceRect(dstRect);
3327 device->blit(renderTarget, sliceRect, externalSurface, dstSliceRect, false, false, false);
3328 delete externalSurface;
3330 renderTarget->release();
3333 void Context::clear(GLbitfield mask)
3335 if(mState.rasterizerDiscardEnabled)
3340 Framebuffer *framebuffer = getDrawFramebuffer();
3342 if(!framebuffer || framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
3344 return error(GL_INVALID_FRAMEBUFFER_OPERATION);
3347 if(!applyRenderTarget())
3352 if(mask & GL_COLOR_BUFFER_BIT)
3354 unsigned int rgbaMask = getColorMask();
3358 device->clearColor(mState.colorClearValue.red, mState.colorClearValue.green, mState.colorClearValue.blue, mState.colorClearValue.alpha, rgbaMask);
3362 if(mask & GL_DEPTH_BUFFER_BIT)
3364 if(mState.depthMask != 0)
3366 float depth = clamp01(mState.depthClearValue);
3367 device->clearDepth(depth);
3371 if(mask & GL_STENCIL_BUFFER_BIT)
3373 if(mState.stencilWritemask != 0)
3375 int stencil = mState.stencilClearValue & 0x000000FF;
3376 device->clearStencil(stencil, mState.stencilWritemask);
3381 void Context::clearColorBuffer(GLint drawbuffer, void *value, sw::Format format)
3383 unsigned int rgbaMask = getColorMask();
3384 if(rgbaMask && !mState.rasterizerDiscardEnabled)
3386 Framebuffer *framebuffer = getDrawFramebuffer();
3387 egl::Image *colorbuffer = framebuffer->getRenderTarget(drawbuffer);
3391 sw::Rect clearRect = colorbuffer->getRect();
3393 if(mState.scissorTestEnabled)
3395 clearRect.clip(mState.scissorX, mState.scissorY, mState.scissorX + mState.scissorWidth, mState.scissorY + mState.scissorHeight);
3398 device->clear(value, format, colorbuffer, clearRect, rgbaMask);
3400 colorbuffer->release();
3405 void Context::clearColorBuffer(GLint drawbuffer, const GLint *value)
3407 clearColorBuffer(drawbuffer, (void*)value, sw::FORMAT_A32B32G32R32I);
3410 void Context::clearColorBuffer(GLint drawbuffer, const GLuint *value)
3412 clearColorBuffer(drawbuffer, (void*)value, sw::FORMAT_A32B32G32R32UI);
3415 void Context::clearColorBuffer(GLint drawbuffer, const GLfloat *value)
3417 clearColorBuffer(drawbuffer, (void*)value, sw::FORMAT_A32B32G32R32F);
3420 void Context::clearDepthBuffer(const GLfloat value)
3422 if(mState.depthMask && !mState.rasterizerDiscardEnabled)
3424 Framebuffer *framebuffer = getDrawFramebuffer();
3425 egl::Image *depthbuffer = framebuffer->getDepthBuffer();
3429 float depth = clamp01(value);
3430 sw::Rect clearRect = depthbuffer->getRect();
3432 if(mState.scissorTestEnabled)
3434 clearRect.clip(mState.scissorX, mState.scissorY, mState.scissorX + mState.scissorWidth, mState.scissorY + mState.scissorHeight);
3437 depthbuffer->clearDepth(depth, clearRect.x0, clearRect.y0, clearRect.width(), clearRect.height());
3439 depthbuffer->release();
3444 void Context::clearStencilBuffer(const GLint value)
3446 if(mState.stencilWritemask && !mState.rasterizerDiscardEnabled)
3448 Framebuffer *framebuffer = getDrawFramebuffer();
3449 egl::Image *stencilbuffer = framebuffer->getStencilBuffer();
3453 unsigned char stencil = value < 0 ? 0 : static_cast<unsigned char>(value & 0x000000FF);
3454 sw::Rect clearRect = stencilbuffer->getRect();
3456 if(mState.scissorTestEnabled)
3458 clearRect.clip(mState.scissorX, mState.scissorY, mState.scissorX + mState.scissorWidth, mState.scissorY + mState.scissorHeight);
3461 stencilbuffer->clearStencil(stencil, static_cast<unsigned char>(mState.stencilWritemask), clearRect.x0, clearRect.y0, clearRect.width(), clearRect.height());
3463 stencilbuffer->release();
3468 void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
3470 if(!applyRenderTarget())
3475 if(mState.currentProgram == 0)
3477 return; // Nothing to process.
3480 sw::DrawType primitiveType;
3482 int verticesPerPrimitive;
3484 if(!es2sw::ConvertPrimitiveType(mode, count, GL_NONE, primitiveType, primitiveCount, verticesPerPrimitive))
3486 return error(GL_INVALID_ENUM);
3491 for(int i = 0; i < instanceCount; ++i)
3493 device->setInstanceID(i);
3495 GLenum err = applyVertexBuffer(0, first, count, i);
3496 if(err != GL_NO_ERROR)
3504 if(!getCurrentProgram()->validateSamplers(false))
3506 return error(GL_INVALID_OPERATION);
3509 if(primitiveCount <= 0)
3514 TransformFeedback* transformFeedback = getTransformFeedback();
3515 if(!cullSkipsDraw(mode) || (transformFeedback->isActive() && !transformFeedback->isPaused()))
3517 device->drawPrimitive(primitiveType, primitiveCount);
3519 if(transformFeedback)
3521 transformFeedback->addVertexOffset(primitiveCount * verticesPerPrimitive);
3526 void Context::drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLsizei instanceCount)
3528 if(!applyRenderTarget())
3533 if(mState.currentProgram == 0)
3535 return; // Nothing to process.
3538 if(!indices && !getCurrentVertexArray()->getElementArrayBuffer())
3540 return error(GL_INVALID_OPERATION);
3543 GLenum internalMode = mode;
3544 if(isPrimitiveRestartFixedIndexEnabled())
3548 case GL_TRIANGLE_FAN:
3549 case GL_TRIANGLE_STRIP:
3550 internalMode = GL_TRIANGLES;
3554 internalMode = GL_LINES;
3561 sw::DrawType primitiveType;
3563 int verticesPerPrimitive;
3565 if(!es2sw::ConvertPrimitiveType(internalMode, count, type, primitiveType, primitiveCount, verticesPerPrimitive))
3567 return error(GL_INVALID_ENUM);
3570 TranslatedIndexData indexInfo(primitiveCount);
3571 GLenum err = applyIndexBuffer(indices, start, end, count, mode, type, &indexInfo);
3572 if(err != GL_NO_ERROR)
3577 applyState(internalMode);
3579 for(int i = 0; i < instanceCount; ++i)
3581 device->setInstanceID(i);
3583 GLsizei vertexCount = indexInfo.maxIndex - indexInfo.minIndex + 1;
3584 err = applyVertexBuffer(-(int)indexInfo.minIndex, indexInfo.minIndex, vertexCount, i);
3585 if(err != GL_NO_ERROR)
3593 if(!getCurrentProgram()->validateSamplers(false))
3595 return error(GL_INVALID_OPERATION);
3598 if(primitiveCount <= 0)
3603 TransformFeedback* transformFeedback = getTransformFeedback();
3604 if(!cullSkipsDraw(internalMode) || (transformFeedback->isActive() && !transformFeedback->isPaused()))
3606 device->drawIndexedPrimitive(primitiveType, indexInfo.indexOffset, indexInfo.primitiveCount);
3608 if(transformFeedback)
3610 transformFeedback->addVertexOffset(indexInfo.primitiveCount * verticesPerPrimitive);
3615 void Context::blit(sw::Surface *source, const sw::SliceRect &sRect, sw::Surface *dest, const sw::SliceRect &dRect)
3617 sw::SliceRectF sRectF((float)sRect.x0, (float)sRect.y0, (float)sRect.x1, (float)sRect.y1, sRect.slice);
3618 device->blit(source, sRectF, dest, dRect, false);
3621 void Context::finish()
3626 void Context::flush()
3628 // We don't queue anything without processing it as fast as possible
3631 void Context::recordInvalidEnum()
3633 mInvalidEnum = true;
3636 void Context::recordInvalidValue()
3638 mInvalidValue = true;
3641 void Context::recordInvalidOperation()
3643 mInvalidOperation = true;
3646 void Context::recordOutOfMemory()
3648 mOutOfMemory = true;
3651 void Context::recordInvalidFramebufferOperation()
3653 mInvalidFramebufferOperation = true;
3656 // Get one of the recorded errors and clear its flag, if any.
3657 // [OpenGL ES 2.0.24] section 2.5 page 13.
3658 GLenum Context::getError()
3662 mInvalidEnum = false;
3664 return GL_INVALID_ENUM;
3669 mInvalidValue = false;
3671 return GL_INVALID_VALUE;
3674 if(mInvalidOperation)
3676 mInvalidOperation = false;
3678 return GL_INVALID_OPERATION;
3683 mOutOfMemory = false;
3685 return GL_OUT_OF_MEMORY;
3688 if(mInvalidFramebufferOperation)
3690 mInvalidFramebufferOperation = false;
3692 return GL_INVALID_FRAMEBUFFER_OPERATION;
3698 int Context::getSupportedMultisampleCount(int requested)
3702 for(int i = NUM_MULTISAMPLE_COUNTS - 1; i >= 0; i--)
3704 if(supported >= requested)
3709 supported = multisampleCount[i];
3715 void Context::detachBuffer(GLuint buffer)
3717 // [OpenGL ES 2.0.24] section 2.9 page 22:
3718 // If a buffer object is deleted while it is bound, all bindings to that object in the current context
3719 // (i.e. in the thread that called Delete-Buffers) are reset to zero.
3721 if(mState.copyReadBuffer.name() == buffer)
3723 mState.copyReadBuffer = nullptr;
3726 if(mState.copyWriteBuffer.name() == buffer)
3728 mState.copyWriteBuffer = nullptr;
3731 if(mState.pixelPackBuffer.name() == buffer)
3733 mState.pixelPackBuffer = nullptr;
3736 if(mState.pixelUnpackBuffer.name() == buffer)
3738 mState.pixelUnpackBuffer = nullptr;
3741 if(mState.genericUniformBuffer.name() == buffer)
3743 mState.genericUniformBuffer = nullptr;
3746 if(getArrayBufferName() == buffer)
3748 mState.arrayBuffer = nullptr;
3751 // Only detach from the current transform feedback
3752 TransformFeedback* currentTransformFeedback = getTransformFeedback();
3753 if(currentTransformFeedback)
3755 currentTransformFeedback->detachBuffer(buffer);
3758 // Only detach from the current vertex array
3759 VertexArray* currentVertexArray = getCurrentVertexArray();
3760 if(currentVertexArray)
3762 currentVertexArray->detachBuffer(buffer);
3765 for(int attribute = 0; attribute < MAX_VERTEX_ATTRIBS; attribute++)
3767 if(mState.vertexAttribute[attribute].mBoundBuffer.name() == buffer)
3769 mState.vertexAttribute[attribute].mBoundBuffer = nullptr;
3774 void Context::detachTexture(GLuint texture)
3776 // [OpenGL ES 2.0.24] section 3.8 page 84:
3777 // If a texture object is deleted, it is as if all texture units which are bound to that texture object are
3778 // rebound to texture object zero
3780 for(int type = 0; type < TEXTURE_TYPE_COUNT; type++)
3782 for(int sampler = 0; sampler < MAX_COMBINED_TEXTURE_IMAGE_UNITS; sampler++)
3784 if(mState.samplerTexture[type][sampler].name() == texture)
3786 mState.samplerTexture[type][sampler] = nullptr;
3791 // [OpenGL ES 2.0.24] section 4.4 page 112:
3792 // If a texture object is deleted while its image is attached to the currently bound framebuffer, then it is
3793 // as if FramebufferTexture2D had been called, with a texture of 0, for each attachment point to which this
3794 // image was attached in the currently bound framebuffer.
3796 Framebuffer *readFramebuffer = getReadFramebuffer();
3797 Framebuffer *drawFramebuffer = getDrawFramebuffer();
3801 readFramebuffer->detachTexture(texture);
3804 if(drawFramebuffer && drawFramebuffer != readFramebuffer)
3806 drawFramebuffer->detachTexture(texture);
3810 void Context::detachFramebuffer(GLuint framebuffer)
3812 // [OpenGL ES 2.0.24] section 4.4 page 107:
3813 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as though
3814 // BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of zero.
3816 if(mState.readFramebuffer == framebuffer)
3818 bindReadFramebuffer(0);
3821 if(mState.drawFramebuffer == framebuffer)
3823 bindDrawFramebuffer(0);
3827 void Context::detachRenderbuffer(GLuint renderbuffer)
3829 // [OpenGL ES 2.0.24] section 4.4 page 109:
3830 // If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though BindRenderbuffer
3831 // had been executed with the target RENDERBUFFER and name of zero.
3833 if(mState.renderbuffer.name() == renderbuffer)
3835 bindRenderbuffer(0);
3838 // [OpenGL ES 2.0.24] section 4.4 page 111:
3839 // If a renderbuffer object is deleted while its image is attached to the currently bound framebuffer,
3840 // then it is as if FramebufferRenderbuffer had been called, with a renderbuffer of 0, for each attachment
3841 // point to which this image was attached in the currently bound framebuffer.
3843 Framebuffer *readFramebuffer = getReadFramebuffer();
3844 Framebuffer *drawFramebuffer = getDrawFramebuffer();
3848 readFramebuffer->detachRenderbuffer(renderbuffer);
3851 if(drawFramebuffer && drawFramebuffer != readFramebuffer)
3853 drawFramebuffer->detachRenderbuffer(renderbuffer);
3857 void Context::detachSampler(GLuint sampler)
3859 // [OpenGL ES 3.0.2] section 3.8.2 pages 123-124:
3860 // If a sampler object that is currently bound to one or more texture units is
3861 // deleted, it is as though BindSampler is called once for each texture unit to
3862 // which the sampler is bound, with unit set to the texture unit and sampler set to zero.
3863 for(size_t textureUnit = 0; textureUnit < MAX_COMBINED_TEXTURE_IMAGE_UNITS; ++textureUnit)
3865 gl::BindingPointer<Sampler> &samplerBinding = mState.sampler[textureUnit];
3866 if(samplerBinding.name() == sampler)
3868 samplerBinding = nullptr;
3873 bool Context::cullSkipsDraw(GLenum drawMode)
3875 return mState.cullFaceEnabled && mState.cullMode == GL_FRONT_AND_BACK && isTriangleMode(drawMode);
3878 bool Context::isTriangleMode(GLenum drawMode)
3883 case GL_TRIANGLE_FAN:
3884 case GL_TRIANGLE_STRIP:
3891 default: UNREACHABLE(drawMode);
3897 void Context::setVertexAttrib(GLuint index, const GLfloat *values)
3899 ASSERT(index < MAX_VERTEX_ATTRIBS);
3901 mState.vertexAttribute[index].setCurrentValue(values);
3903 mVertexDataManager->dirtyCurrentValue(index);
3906 void Context::setVertexAttrib(GLuint index, const GLint *values)
3908 ASSERT(index < MAX_VERTEX_ATTRIBS);
3910 mState.vertexAttribute[index].setCurrentValue(values);
3912 mVertexDataManager->dirtyCurrentValue(index);
3915 void Context::setVertexAttrib(GLuint index, const GLuint *values)
3917 ASSERT(index < MAX_VERTEX_ATTRIBS);
3919 mState.vertexAttribute[index].setCurrentValue(values);
3921 mVertexDataManager->dirtyCurrentValue(index);
3924 void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
3925 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
3926 GLbitfield mask, bool filter, bool allowPartialDepthStencilBlit)
3928 Framebuffer *readFramebuffer = getReadFramebuffer();
3929 Framebuffer *drawFramebuffer = getDrawFramebuffer();
3931 int readBufferWidth, readBufferHeight, readBufferSamples;
3932 int drawBufferWidth, drawBufferHeight, drawBufferSamples;
3934 if(!readFramebuffer || readFramebuffer->completeness(readBufferWidth, readBufferHeight, readBufferSamples) != GL_FRAMEBUFFER_COMPLETE ||
3935 !drawFramebuffer || drawFramebuffer->completeness(drawBufferWidth, drawBufferHeight, drawBufferSamples) != GL_FRAMEBUFFER_COMPLETE)
3937 return error(GL_INVALID_FRAMEBUFFER_OPERATION);
3940 if(drawBufferSamples > 1)
3942 return error(GL_INVALID_OPERATION);
3945 sw::SliceRect sourceRect;
3946 sw::SliceRect destRect;
3947 bool flipX = (srcX0 < srcX1) ^ (dstX0 < dstX1);
3948 bool flipY = (srcY0 < srcY1) ^ (dstY0 < dstY1);
3952 sourceRect.x0 = srcX0;
3953 sourceRect.x1 = srcX1;
3957 sourceRect.x0 = srcX1;
3958 sourceRect.x1 = srcX0;
3963 destRect.x0 = dstX0;
3964 destRect.x1 = dstX1;
3968 destRect.x0 = dstX1;
3969 destRect.x1 = dstX0;
3974 sourceRect.y0 = srcY0;
3975 sourceRect.y1 = srcY1;
3979 sourceRect.y0 = srcY1;
3980 sourceRect.y1 = srcY0;
3985 destRect.y0 = dstY0;
3986 destRect.y1 = dstY1;
3990 destRect.y0 = dstY1;
3991 destRect.y1 = dstY0;
3994 sw::RectF sourceScissoredRect(static_cast<float>(sourceRect.x0), static_cast<float>(sourceRect.y0),
3995 static_cast<float>(sourceRect.x1), static_cast<float>(sourceRect.y1));
3996 sw::Rect destScissoredRect = destRect;
3998 if(mState.scissorTestEnabled) // Only write to parts of the destination framebuffer which pass the scissor test
4000 sw::Rect scissorRect(mState.scissorX, mState.scissorY, mState.scissorX + mState.scissorWidth, mState.scissorY + mState.scissorHeight);
4001 Device::ClipDstRect(sourceScissoredRect, destScissoredRect, scissorRect, flipX, flipY);
4004 sw::SliceRectF sourceTrimmedRect = sourceScissoredRect;
4005 sw::SliceRect destTrimmedRect = destScissoredRect;
4007 // The source & destination rectangles also may need to be trimmed if
4008 // they fall out of the bounds of the actual draw and read surfaces.
4009 sw::Rect sourceTrimRect(0, 0, readBufferWidth, readBufferHeight);
4010 Device::ClipSrcRect(sourceTrimmedRect, destTrimmedRect, sourceTrimRect, flipX, flipY);
4012 sw::Rect destTrimRect(0, 0, drawBufferWidth, drawBufferHeight);
4013 Device::ClipDstRect(sourceTrimmedRect, destTrimmedRect, destTrimRect, flipX, flipY);
4015 bool partialBufferCopy = false;
4017 if(sourceTrimmedRect.y1 - sourceTrimmedRect.y0 < readBufferHeight ||
4018 sourceTrimmedRect.x1 - sourceTrimmedRect.x0 < readBufferWidth ||
4019 destTrimmedRect.y1 - destTrimmedRect.y0 < drawBufferHeight ||
4020 destTrimmedRect.x1 - destTrimmedRect.x0 < drawBufferWidth ||
4021 sourceTrimmedRect.y0 != 0 || destTrimmedRect.y0 != 0 || sourceTrimmedRect.x0 != 0 || destTrimmedRect.x0 != 0)
4023 partialBufferCopy = true;
4026 bool sameBounds = (srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1);
4027 bool blitRenderTarget = false;
4028 bool blitDepth = false;
4029 bool blitStencil = false;
4031 if(mask & GL_COLOR_BUFFER_BIT)
4033 GLenum readColorbufferType = readFramebuffer->getReadBufferType();
4034 GLenum drawColorbufferType = drawFramebuffer->getColorbufferType(0);
4035 const bool validReadType = readColorbufferType == GL_TEXTURE_2D || Framebuffer::IsRenderbuffer(readColorbufferType);
4036 const bool validDrawType = drawColorbufferType == GL_TEXTURE_2D || Framebuffer::IsRenderbuffer(drawColorbufferType);
4037 if(!validReadType || !validDrawType)
4039 return error(GL_INVALID_OPERATION);
4042 if(partialBufferCopy && readBufferSamples > 1 && !sameBounds)
4044 return error(GL_INVALID_OPERATION);
4047 // The GL ES 3.0.2 spec (pg 193) states that:
4048 // 1) If the read buffer is fixed point format, the draw buffer must be as well
4049 // 2) If the read buffer is an unsigned integer format, the draw buffer must be
4051 // 3) If the read buffer is a signed integer format, the draw buffer must be as
4053 es2::Renderbuffer *readRenderbuffer = readFramebuffer->getReadColorbuffer();
4054 es2::Renderbuffer *drawRenderbuffer = drawFramebuffer->getColorbuffer(0);
4055 GLint readFormat = readRenderbuffer->getFormat();
4056 GLint drawFormat = drawRenderbuffer->getFormat();
4057 GLenum readComponentType = GetComponentType(readFormat, GL_COLOR_ATTACHMENT0);
4058 GLenum drawComponentType = GetComponentType(drawFormat, GL_COLOR_ATTACHMENT0);
4059 bool readFixedPoint = ((readComponentType == GL_UNSIGNED_NORMALIZED) ||
4060 (readComponentType == GL_SIGNED_NORMALIZED));
4061 bool drawFixedPoint = ((drawComponentType == GL_UNSIGNED_NORMALIZED) ||
4062 (drawComponentType == GL_SIGNED_NORMALIZED));
4063 bool readFixedOrFloat = (readFixedPoint || (readComponentType == GL_FLOAT));
4064 bool drawFixedOrFloat = (drawFixedPoint || (drawComponentType == GL_FLOAT));
4066 if(readFixedOrFloat != drawFixedOrFloat)
4068 return error(GL_INVALID_OPERATION);
4071 if((readComponentType == GL_UNSIGNED_INT) && (drawComponentType != GL_UNSIGNED_INT))
4073 return error(GL_INVALID_OPERATION);
4076 if((readComponentType == GL_INT) && (drawComponentType != GL_INT))
4078 return error(GL_INVALID_OPERATION);
4081 // Cannot filter integer data
4082 if(((readComponentType == GL_UNSIGNED_INT) || (readComponentType == GL_INT)) && filter)
4084 return error(GL_INVALID_OPERATION);
4087 if((readRenderbuffer->getSamples() > 0) &&
4088 (readRenderbuffer->getFormat() != drawRenderbuffer->getFormat()))
4090 return error(GL_INVALID_OPERATION);
4093 blitRenderTarget = true;
4096 if(mask & (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT))
4098 Renderbuffer *readDSBuffer = nullptr;
4099 Renderbuffer *drawDSBuffer = nullptr;
4101 if(mask & GL_DEPTH_BUFFER_BIT)
4103 if(readFramebuffer->getDepthbuffer() && drawFramebuffer->getDepthbuffer())
4105 GLenum readDepthBufferType = readFramebuffer->getDepthbufferType();
4106 GLenum drawDepthBufferType = drawFramebuffer->getDepthbufferType();
4107 if((readDepthBufferType != drawDepthBufferType) &&
4108 !(Framebuffer::IsRenderbuffer(readDepthBufferType) && Framebuffer::IsRenderbuffer(drawDepthBufferType)))
4110 return error(GL_INVALID_OPERATION);
4114 readDSBuffer = readFramebuffer->getDepthbuffer();
4115 drawDSBuffer = drawFramebuffer->getDepthbuffer();
4117 if(readDSBuffer->getFormat() != drawDSBuffer->getFormat())
4119 return error(GL_INVALID_OPERATION);
4124 if(mask & GL_STENCIL_BUFFER_BIT)
4126 if(readFramebuffer->getStencilbuffer() && drawFramebuffer->getStencilbuffer())
4128 GLenum readStencilBufferType = readFramebuffer->getStencilbufferType();
4129 GLenum drawStencilBufferType = drawFramebuffer->getStencilbufferType();
4130 if((readStencilBufferType != drawStencilBufferType) &&
4131 !(Framebuffer::IsRenderbuffer(readStencilBufferType) && Framebuffer::IsRenderbuffer(drawStencilBufferType)))
4133 return error(GL_INVALID_OPERATION);
4137 readDSBuffer = readFramebuffer->getStencilbuffer();
4138 drawDSBuffer = drawFramebuffer->getStencilbuffer();
4140 if(readDSBuffer->getFormat() != drawDSBuffer->getFormat())
4142 return error(GL_INVALID_OPERATION);
4147 if(partialBufferCopy && !allowPartialDepthStencilBlit)
4149 ERR("Only whole-buffer depth and stencil blits are supported by ANGLE_framebuffer_blit.");
4150 return error(GL_INVALID_OPERATION); // Only whole-buffer copies are permitted
4153 // OpenGL ES 3.0.4 spec, p.199:
4154 // ...an INVALID_OPERATION error is generated if the formats of the read
4155 // and draw framebuffers are not identical or if the source and destination
4156 // rectangles are not defined with the same(X0, Y 0) and (X1, Y 1) bounds.
4157 // If SAMPLE_BUFFERS for the draw framebuffer is greater than zero, an
4158 // INVALID_OPERATION error is generated.
4159 if((drawDSBuffer && drawDSBuffer->getSamples() > 1) ||
4160 ((readDSBuffer && readDSBuffer->getSamples() > 1) &&
4161 (!sameBounds || (drawDSBuffer->getFormat() != readDSBuffer->getFormat()))))
4163 return error(GL_INVALID_OPERATION);
4167 if(blitRenderTarget || blitDepth || blitStencil)
4171 swap(destTrimmedRect.x0, destTrimmedRect.x1);
4175 swap(destTrimmedRect.y0, destTrimmedRect.y1);
4178 if(blitRenderTarget)
4180 egl::Image *readRenderTarget = readFramebuffer->getReadRenderTarget();
4181 egl::Image *drawRenderTarget = drawFramebuffer->getRenderTarget(0);
4183 bool success = device->stretchRect(readRenderTarget, &sourceTrimmedRect, drawRenderTarget, &destTrimmedRect, (filter ? Device::USE_FILTER : 0) | Device::COLOR_BUFFER);
4185 readRenderTarget->release();
4186 drawRenderTarget->release();
4190 ERR("BlitFramebuffer failed.");
4197 egl::Image *readRenderTarget = readFramebuffer->getDepthBuffer();
4198 egl::Image *drawRenderTarget = drawFramebuffer->getDepthBuffer();
4200 bool success = device->stretchRect(readRenderTarget, &sourceTrimmedRect, drawRenderTarget, &destTrimmedRect, (filter ? Device::USE_FILTER : 0) | Device::DEPTH_BUFFER);
4202 readRenderTarget->release();
4203 drawRenderTarget->release();
4207 ERR("BlitFramebuffer failed.");
4214 egl::Image *readRenderTarget = readFramebuffer->getStencilBuffer();
4215 egl::Image *drawRenderTarget = drawFramebuffer->getStencilBuffer();
4217 bool success = device->stretchRect(readRenderTarget, &sourceTrimmedRect, drawRenderTarget, &destTrimmedRect, (filter ? Device::USE_FILTER : 0) | Device::STENCIL_BUFFER);
4219 readRenderTarget->release();
4220 drawRenderTarget->release();
4224 ERR("BlitFramebuffer failed.");
4231 void Context::bindTexImage(gl::Surface *surface)
4233 es2::Texture2D *textureObject = getTexture2D();
4237 textureObject->bindTexImage(surface);
4241 EGLenum Context::validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel)
4243 GLenum textureTarget = GL_NONE;
4247 case EGL_GL_TEXTURE_2D_KHR:
4248 textureTarget = GL_TEXTURE_2D;
4250 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR:
4251 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR:
4252 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR:
4253 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR:
4254 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR:
4255 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR:
4256 textureTarget = GL_TEXTURE_CUBE_MAP;
4258 case EGL_GL_RENDERBUFFER_KHR:
4261 return EGL_BAD_PARAMETER;
4264 if(textureLevel >= es2::IMPLEMENTATION_MAX_TEXTURE_LEVELS)
4266 return EGL_BAD_MATCH;
4269 if(textureTarget != GL_NONE)
4271 es2::Texture *texture = getTexture(name);
4273 if(!texture || texture->getTarget() != textureTarget)
4275 return EGL_BAD_PARAMETER;
4278 if(texture->isShared(textureTarget, textureLevel)) // Bound to an EGLSurface or already an EGLImage sibling
4280 return EGL_BAD_ACCESS;
4283 if(textureLevel != 0 && !texture->isSamplerComplete())
4285 return EGL_BAD_PARAMETER;
4288 if(textureLevel == 0 && !(texture->isSamplerComplete() && texture->getTopLevel() == 0))
4290 return EGL_BAD_PARAMETER;
4293 else if(target == EGL_GL_RENDERBUFFER_KHR)
4295 es2::Renderbuffer *renderbuffer = getRenderbuffer(name);
4299 return EGL_BAD_PARAMETER;
4302 if(renderbuffer->isShared()) // Already an EGLImage sibling
4304 return EGL_BAD_ACCESS;
4307 else UNREACHABLE(target);
4312 egl::Image *Context::createSharedImage(EGLenum target, GLuint name, GLuint textureLevel)
4314 GLenum textureTarget = GL_NONE;
4318 case EGL_GL_TEXTURE_2D_KHR: textureTarget = GL_TEXTURE_2D; break;
4319 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR: textureTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X; break;
4320 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR: textureTarget = GL_TEXTURE_CUBE_MAP_NEGATIVE_X; break;
4321 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR: textureTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_Y; break;
4322 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR: textureTarget = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y; break;
4323 case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR: textureTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_Z; break;
4324 case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR: textureTarget = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; break;
4327 if(textureTarget != GL_NONE)
4329 es2::Texture *texture = getTexture(name);
4331 return texture->createSharedImage(textureTarget, textureLevel);
4333 else if(target == EGL_GL_RENDERBUFFER_KHR)
4335 es2::Renderbuffer *renderbuffer = getRenderbuffer(name);
4337 return renderbuffer->createSharedImage();
4339 else UNREACHABLE(target);
4344 egl::Image *Context::getSharedImage(GLeglImageOES image)
4346 return display->getSharedImage(image);
4349 Device *Context::getDevice()
4354 const GLubyte *Context::getExtensions(GLuint index, GLuint *numExt) const
4356 // Keep list sorted in following order:
4359 // Vendor extensions
4360 static const char *es2extensions[] =
4362 "GL_OES_compressed_ETC1_RGB8_texture",
4365 "GL_OES_depth_texture",
4366 "GL_OES_depth_texture_cube_map",
4368 "GL_OES_EGL_image_external",
4370 "GL_OES_element_index_uint",
4371 "GL_OES_framebuffer_object",
4372 "GL_OES_packed_depth_stencil",
4373 "GL_OES_rgb8_rgba8",
4374 "GL_OES_standard_derivatives",
4375 "GL_OES_texture_float",
4376 "GL_OES_texture_float_linear",
4377 "GL_OES_texture_half_float",
4378 "GL_OES_texture_half_float_linear",
4379 "GL_OES_texture_npot",
4380 "GL_OES_texture_3D",
4381 "GL_OES_vertex_half_float",
4382 "GL_EXT_blend_minmax",
4383 "GL_EXT_color_buffer_half_float",
4384 "GL_EXT_draw_buffers",
4385 "GL_EXT_instanced_arrays",
4386 "GL_EXT_occlusion_query_boolean",
4387 "GL_EXT_read_format_bgra",
4388 "GL_EXT_texture_compression_dxt1",
4389 "GL_EXT_texture_filter_anisotropic",
4390 "GL_EXT_texture_format_BGRA8888",
4391 "GL_EXT_texture_rg",
4393 "GL_KHR_texture_compression_astc_hdr",
4394 "GL_KHR_texture_compression_astc_ldr",
4396 "GL_ARB_texture_rectangle",
4397 "GL_ANGLE_framebuffer_blit",
4398 "GL_ANGLE_framebuffer_multisample",
4399 "GL_ANGLE_instanced_arrays",
4400 "GL_ANGLE_texture_compression_dxt3",
4401 "GL_ANGLE_texture_compression_dxt5",
4402 "GL_APPLE_texture_format_BGRA8888",
4403 "GL_CHROMIUM_color_buffer_float_rgba", // A subset of EXT_color_buffer_float on top of OpenGL ES 2.0
4404 "GL_CHROMIUM_texture_filtering_hint",
4406 "GL_NV_framebuffer_blit",
4410 // Extensions exclusive to OpenGL ES 3.0 and above.
4411 static const char *es3extensions[] =
4413 "GL_EXT_color_buffer_float",
4416 GLuint numES2extensions = sizeof(es2extensions) / sizeof(es2extensions[0]);
4417 GLuint numExtensions = numES2extensions;
4419 if(clientVersion >= 3)
4421 numExtensions += sizeof(es3extensions) / sizeof(es3extensions[0]);
4426 *numExt = numExtensions;
4431 if(index == GL_INVALID_INDEX)
4433 static std::string extensionsCat;
4435 if(extensionsCat.empty() && (numExtensions > 0))
4437 for(const char *extension : es2extensions)
4439 extensionsCat += std::string(extension) + " ";
4442 if(clientVersion >= 3)
4444 for(const char *extension : es3extensions)
4446 extensionsCat += std::string(extension) + " ";
4451 return (const GLubyte*)extensionsCat.c_str();
4454 if(index >= numExtensions)
4459 if(index < numES2extensions)
4461 return (const GLubyte*)es2extensions[index];
4465 return (const GLubyte*)es3extensions[index - numES2extensions];
4471 NO_SANITIZE_FUNCTION egl::Context *es2CreateContext(egl::Display *display, const egl::Context *shareContext, int clientVersion, const egl::Config *config)
4473 ASSERT(!shareContext || shareContext->getClientVersion() == clientVersion); // Should be checked by eglCreateContext
4474 return new es2::Context(display, static_cast<const es2::Context*>(shareContext), clientVersion, config);