blob: 5a62efebcc8d4f1fe8c5031205edc6f7e781ab53 [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Tobin Ehlisd7890bc2018-06-29 11:57:22 -060017#include "common/PackedEnums.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030018#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040019#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050020#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050021#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050022#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050023#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040024#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050025#include "libANGLE/Fence.h"
26#include "libANGLE/Framebuffer.h"
27#include "libANGLE/FramebufferAttachment.h"
Lingfeng Yang461b09a2018-04-23 09:02:09 -070028#include "libANGLE/GLES1Renderer.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030029#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080031#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050033#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050034#include "libANGLE/ResourceManager.h"
35#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050036#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050037#include "libANGLE/Texture.h"
38#include "libANGLE/TransformFeedback.h"
39#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070040#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040041#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030042#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040043#include "libANGLE/queryutils.h"
Jamie Madill6d32cef2018-08-14 02:34:28 -040044#include "libANGLE/renderer/BufferImpl.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040045#include "libANGLE/renderer/ContextImpl.h"
46#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040047#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040048#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000049
Jamie Madill752d2202018-11-27 13:29:48 -050050namespace gl
51{
Geoff Langf6db0982015-08-25 13:04:00 -040052namespace
53{
54
Jamie Madillb6664922017-07-25 12:55:04 -040055#define ANGLE_HANDLE_ERR(X) \
Jamie Madill4f6592f2018-11-27 16:37:45 -050056 (void)(X); \
Jamie Madillb6664922017-07-25 12:55:04 -040057 return;
58#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
59
Ian Ewell3ffd78b2016-01-22 16:09:42 -050060template <typename T>
Jamie Madill752d2202018-11-27 13:29:48 -050061std::vector<Path *> GatherPaths(PathManager &resourceManager,
62 GLsizei numPaths,
63 const void *paths,
64 GLuint pathBase)
Sami Väisänend59ca052016-06-21 16:10:00 +030065{
Jamie Madill752d2202018-11-27 13:29:48 -050066 std::vector<Path *> ret;
Sami Väisänend59ca052016-06-21 16:10:00 +030067 ret.reserve(numPaths);
68
69 const auto *nameArray = static_cast<const T *>(paths);
70
71 for (GLsizei i = 0; i < numPaths; ++i)
72 {
73 const GLuint pathName = nameArray[i] + pathBase;
74
75 ret.push_back(resourceManager.getPath(pathName));
76 }
77
78 return ret;
79}
80
Jamie Madill752d2202018-11-27 13:29:48 -050081std::vector<Path *> GatherPaths(PathManager &resourceManager,
82 GLsizei numPaths,
83 GLenum pathNameType,
84 const void *paths,
85 GLuint pathBase)
Sami Väisänend59ca052016-06-21 16:10:00 +030086{
87 switch (pathNameType)
88 {
89 case GL_UNSIGNED_BYTE:
90 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
91
92 case GL_BYTE:
93 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
94
95 case GL_UNSIGNED_SHORT:
96 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
97
98 case GL_SHORT:
99 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
100
101 case GL_UNSIGNED_INT:
102 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
103
104 case GL_INT:
105 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
106 }
107
108 UNREACHABLE();
Jamie Madill752d2202018-11-27 13:29:48 -0500109 return std::vector<Path *>();
Sami Väisänend59ca052016-06-21 16:10:00 +0300110}
111
112template <typename T>
Jamie Madill752d2202018-11-27 13:29:48 -0500113angle::Result GetQueryObjectParameter(const Context *context, Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500114{
Geoff Lang2186c382016-10-14 10:54:54 -0400115 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116
117 switch (pname)
118 {
119 case GL_QUERY_RESULT_EXT:
Jamie Madill5188a272018-07-25 10:53:56 -0400120 return query->getResult(context, params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500121 case GL_QUERY_RESULT_AVAILABLE_EXT:
122 {
123 bool available;
Jamie Madill666818e2018-11-14 09:54:33 -0500124 ANGLE_TRY(query->isResultAvailable(context, &available));
Jamie Madill752d2202018-11-27 13:29:48 -0500125 *params = CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Jamie Madill7c985f52018-11-29 18:16:17 -0500126 return angle::Result::Continue;
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500127 }
128 default:
129 UNREACHABLE();
Jamie Madill7c985f52018-11-29 18:16:17 -0500130 return angle::Result::Stop;
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500131 }
132}
133
Jamie Madill752d2202018-11-27 13:29:48 -0500134ANGLE_INLINE void MarkTransformFeedbackBufferUsage(const Context *context,
Jamie Madill956ab4d2018-10-10 16:13:03 -0400135 GLsizei count,
136 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400137{
Jamie Madillae6ba9f2018-12-21 23:00:04 -0500138 if (context->getStateCache().isTransformFeedbackActiveUnpaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400139 {
Jamie Madillae6ba9f2018-12-21 23:00:04 -0500140 TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback();
Jamie Madill09463932018-04-04 05:26:59 -0400141 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400142 }
143}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500144
145// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300146EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500147{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400148 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500149}
150
Martin Radev1be913c2016-07-11 17:59:16 +0300151EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
152{
153 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
154}
155
Jamie Madill752d2202018-11-27 13:29:48 -0500156Version GetClientVersion(const egl::AttributeMap &attribs)
Geoff Langeb66a6e2016-10-31 13:06:12 -0400157{
Jamie Madill752d2202018-11-27 13:29:48 -0500158 return Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
Geoff Langeb66a6e2016-10-31 13:06:12 -0400159}
160
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500161GLenum GetResetStrategy(const egl::AttributeMap &attribs)
162{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800163 EGLAttrib attrib =
164 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165 switch (attrib)
166 {
167 case EGL_NO_RESET_NOTIFICATION:
168 return GL_NO_RESET_NOTIFICATION_EXT;
169 case EGL_LOSE_CONTEXT_ON_RESET:
170 return GL_LOSE_CONTEXT_ON_RESET_EXT;
171 default:
172 UNREACHABLE();
173 return GL_NONE;
174 }
175}
176
177bool GetRobustAccess(const egl::AttributeMap &attribs)
178{
Geoff Lang077f20a2016-11-01 10:08:02 -0400179 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
180 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
181 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500182}
183
184bool GetDebug(const egl::AttributeMap &attribs)
185{
Geoff Lang077f20a2016-11-01 10:08:02 -0400186 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
187 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500188}
189
190bool GetNoError(const egl::AttributeMap &attribs)
191{
192 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
193}
194
Geoff Langc287ea62016-09-16 14:46:51 -0400195bool GetWebGLContext(const egl::AttributeMap &attribs)
196{
Jamie Madill4230d482018-09-14 10:14:45 -0400197 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
Geoff Langc287ea62016-09-16 14:46:51 -0400198}
199
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400200bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
201{
202 // If the context is WebGL, extensions are disabled by default
203 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
204 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
205}
206
Geoff Langf41a7152016-09-19 15:11:17 -0400207bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
208{
Jamie Madill4230d482018-09-14 10:14:45 -0400209 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
Geoff Langf41a7152016-09-19 15:11:17 -0400210}
211
Geoff Langfeb8c682017-02-13 16:07:35 -0500212bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
213{
214 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
215}
216
Geoff Langb433e872017-10-05 14:01:47 -0400217bool GetRobustResourceInit(const egl::AttributeMap &attribs)
218{
219 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
220}
221
Martin Radev9d901792016-07-15 15:58:58 +0300222std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
223{
224 std::string labelName;
225 if (label != nullptr)
226 {
227 size_t labelLength = length < 0 ? strlen(label) : length;
228 labelName = std::string(label, labelLength);
229 }
230 return labelName;
231}
232
233void GetObjectLabelBase(const std::string &objectLabel,
234 GLsizei bufSize,
235 GLsizei *length,
236 GLchar *label)
237{
238 size_t writeLength = objectLabel.length();
239 if (label != nullptr && bufSize > 0)
240 {
241 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
242 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
243 label[writeLength] = '\0';
244 }
245
246 if (length != nullptr)
247 {
248 *length = static_cast<GLsizei>(writeLength);
249 }
250}
251
Jamie Madill0f80ed82017-09-19 00:24:56 -0400252template <typename CapT, typename MaxT>
253void LimitCap(CapT *cap, MaxT maximum)
254{
255 *cap = std::min(*cap, static_cast<CapT>(maximum));
256}
257
Jamie Madill752d2202018-11-27 13:29:48 -0500258constexpr angle::PackedEnumMap<PrimitiveMode, GLsizei> kMinimumPrimitiveCounts = {{
259 {PrimitiveMode::Points, 1},
260 {PrimitiveMode::Lines, 2},
261 {PrimitiveMode::LineLoop, 2},
262 {PrimitiveMode::LineStrip, 2},
263 {PrimitiveMode::Triangles, 3},
264 {PrimitiveMode::TriangleStrip, 3},
265 {PrimitiveMode::TriangleFan, 3},
266 {PrimitiveMode::LinesAdjacency, 2},
267 {PrimitiveMode::LineStripAdjacency, 2},
268 {PrimitiveMode::TrianglesAdjacency, 3},
269 {PrimitiveMode::TriangleStripAdjacency, 3},
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600270}};
Jamie Madill752d2202018-11-27 13:29:48 -0500271
272// The rest default to false.
273constexpr angle::PackedEnumMap<PrimitiveMode, bool, angle::EnumSize<PrimitiveMode>() + 1>
274 kValidBasicDrawModes = {{
275 {PrimitiveMode::Points, true},
276 {PrimitiveMode::Lines, true},
277 {PrimitiveMode::LineLoop, true},
278 {PrimitiveMode::LineStrip, true},
279 {PrimitiveMode::Triangles, true},
280 {PrimitiveMode::TriangleStrip, true},
281 {PrimitiveMode::TriangleFan, true},
282 }};
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600283
Jamie Madill6d32cef2018-08-14 02:34:28 -0400284enum SubjectIndexes : angle::SubjectIndex
285{
286 kTexture0SubjectIndex = 0,
Jamie Madille3e680c2018-12-03 17:49:08 -0500287 kTextureMaxSubjectIndex = kTexture0SubjectIndex + IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
288 kImage0SubjectIndex = kTextureMaxSubjectIndex,
289 kImageMaxSubjectIndex = kImage0SubjectIndex + IMPLEMENTATION_MAX_IMAGE_UNITS,
290 kUniformBuffer0SubjectIndex = kImageMaxSubjectIndex,
Jamie Madill6d32cef2018-08-14 02:34:28 -0400291 kUniformBufferMaxSubjectIndex =
Jamie Madille3e680c2018-12-03 17:49:08 -0500292 kUniformBuffer0SubjectIndex + IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS,
Jamie Madille25b8002018-09-20 13:39:49 -0400293 kSampler0SubjectIndex = kUniformBufferMaxSubjectIndex,
Jamie Madille3e680c2018-12-03 17:49:08 -0500294 kSamplerMaxSubjectIndex = kSampler0SubjectIndex + IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
Jamie Madille25b8002018-09-20 13:39:49 -0400295 kVertexArraySubjectIndex = kSamplerMaxSubjectIndex,
Jamie Madill6d32cef2018-08-14 02:34:28 -0400296 kReadFramebufferSubjectIndex,
297 kDrawFramebufferSubjectIndex
298};
Geoff Langf6db0982015-08-25 13:04:00 -0400299} // anonymous namespace
300
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400301Context::Context(rx::EGLImplFactory *implFactory,
302 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400303 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500304 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400305 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500306 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700307 const egl::DisplayExtensions &displayExtensions,
308 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500309 : mState(reinterpret_cast<ContextID>(this),
310 shareContext ? &shareContext->mState : nullptr,
311 shareTextures,
312 GetClientVersion(attribs),
313 &mGLState,
314 mCaps,
315 mTextureCaps,
316 mExtensions,
317 mLimitations),
318 mSkipValidation(GetNoError(attribs)),
319 mDisplayTextureShareGroup(shareTextures != nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400320 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400321 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400322 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400323 mGLState(GetDebug(attribs),
324 GetBindGeneratesResource(attribs),
325 GetClientArraysEnabled(attribs),
326 GetRobustResourceInit(attribs),
327 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400328 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500329 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400330 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500331 mHasBeenCurrent(false),
332 mContextLost(false),
333 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700334 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500335 mResetStrategy(GetResetStrategy(attribs)),
336 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400337 mSurfacelessSupported(displayExtensions.surfacelessContext),
338 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400339 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
340 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500341 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400342 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400343 mMemoryProgramCache(memoryProgramCache),
Jamie Madilla11819d2018-07-30 10:26:01 -0400344 mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
345 mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
346 mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400347 mScratchBuffer(1000u),
jchen107ae70d82018-07-06 13:47:01 +0800348 mZeroFilledBuffer(1000u),
349 mThreadPool(nullptr)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000350{
Jamie Madill6d32cef2018-08-14 02:34:28 -0400351 for (angle::SubjectIndex uboIndex = kUniformBuffer0SubjectIndex;
352 uboIndex < kUniformBufferMaxSubjectIndex; ++uboIndex)
353 {
354 mUniformBufferObserverBindings.emplace_back(this, uboIndex);
355 }
Jamie Madille25b8002018-09-20 13:39:49 -0400356
357 for (angle::SubjectIndex samplerIndex = kSampler0SubjectIndex;
358 samplerIndex < kSamplerMaxSubjectIndex; ++samplerIndex)
359 {
360 mSamplerObserverBindings.emplace_back(this, samplerIndex);
361 }
Jamie Madille3e680c2018-12-03 17:49:08 -0500362
363 for (angle::SubjectIndex imageIndex = kImage0SubjectIndex; imageIndex < kImageMaxSubjectIndex;
364 ++imageIndex)
365 {
366 mImageObserverBindings.emplace_back(this, imageIndex);
367 }
Geoff Lang33f11fb2018-05-07 13:42:47 -0400368}
Jamie Madill5b772312018-03-08 20:28:32 -0500369
Geoff Lang33f11fb2018-05-07 13:42:47 -0400370void Context::initialize()
371{
372 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400373
Geoff Lang33f11fb2018-05-07 13:42:47 -0400374 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700375 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400376
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400377 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100378
Shannon Woods53a94a82014-06-24 15:20:36 -0400379 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400380
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000381 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400382 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000383 // and cube map texture state vectors respectively associated with them.
384 // In order that access to these initial textures not be lost, they are treated as texture
385 // objects all of whose names are 0.
386
Corentin Wallez99d492c2018-02-27 15:17:10 -0500387 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800388 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500389
Corentin Wallez99d492c2018-02-27 15:17:10 -0500390 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800391 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400392
Geoff Langeb66a6e2016-10-31 13:06:12 -0400393 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400394 {
395 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500396 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800397 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400398
Corentin Wallez99d492c2018-02-27 15:17:10 -0500399 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800400 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400401 }
Yizhou Jiang7818a852018-09-06 15:02:04 +0800402 if (getClientVersion() >= Version(3, 1) || mSupportedExtensions.textureMultisample)
Geoff Lang3b573612016-10-31 14:08:10 -0400403 {
404 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500405 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800406 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Yizhou Jiang7818a852018-09-06 15:02:04 +0800407 }
408 if (getClientVersion() >= Version(3, 1))
409 {
Olli Etuahod310a432018-08-24 15:40:23 +0300410 Texture *zeroTexture2DMultisampleArray =
411 new Texture(mImplementation.get(), 0, TextureType::_2DMultisampleArray);
412 mZeroTextures[TextureType::_2DMultisampleArray].set(this, zeroTexture2DMultisampleArray);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800413
Jiajia Qin6eafb042016-12-27 17:04:07 +0800414 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
415 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800416 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800417 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800418
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800419 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
420 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400421 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800422 }
Geoff Lang3b573612016-10-31 14:08:10 -0400423 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000424
Geoff Langb0f917f2017-12-05 13:41:54 -0500425 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400426 {
427 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500428 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800429 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400430 }
431
Geoff Langb0f917f2017-12-05 13:41:54 -0500432 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400433 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500434 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800435 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400436 }
437
Jamie Madill4928b7c2017-06-20 12:57:39 -0400438 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500439
Jamie Madill57a89722013-07-02 11:57:03 -0400440 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000441
Geoff Langeb66a6e2016-10-31 13:06:12 -0400442 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400443 {
444 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
445 // In the initial state, a default transform feedback object is bound and treated as
446 // a transform feedback object with a name of zero. That object is bound any time
447 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400448 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400449 }
Geoff Langc8058452014-02-03 12:04:11 -0500450
Corentin Wallez336129f2017-10-17 15:55:40 -0400451 for (auto type : angle::AllEnums<BufferBinding>())
452 {
453 bindBuffer(type, 0);
454 }
455
456 bindRenderbuffer(GL_RENDERBUFFER, 0);
457
458 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
459 {
460 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
461 }
462
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700463 // Initialize GLES1 renderer if appropriate.
464 if (getClientVersion() < Version(2, 0))
465 {
466 mGLES1Renderer.reset(new GLES1Renderer());
467 }
468
Jamie Madillad9f24e2016-02-12 09:27:24 -0500469 // Initialize dirty bit masks
Jamie Madill9d0bb3d2018-10-09 20:29:13 -0400470 mAllDirtyBits.set();
471
Geoff Lang9bf86f02018-07-26 11:46:34 -0400472 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
473 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
Jamie Madille3e680c2018-12-03 17:49:08 -0500474 mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400475 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400476 mDrawDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400477
478 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
479 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
Jamie Madille3e680c2018-12-03 17:49:08 -0500480 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madille25b8002018-09-20 13:39:49 -0400481 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400482
Jamie Madillc67323a2017-11-02 23:11:41 -0400483 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500484 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500485 // No dirty objects.
486
487 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400488 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500489 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400490 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500491 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
492
493 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
494 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
495 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
496 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
497 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
498 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
499 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
500 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
501 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
502 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
503 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400504 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500505 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
506
507 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
508 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700509 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400510 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
511 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500512 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
513 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400514
Xinghua Cao10a4d432017-11-28 14:46:26 +0800515 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
jchen1099118c12018-09-10 16:28:51 +0800516 mComputeDirtyBits.set(State::DIRTY_BIT_UNIFORM_BUFFER_BINDINGS);
517 mComputeDirtyBits.set(State::DIRTY_BIT_ATOMIC_COUNTER_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800518 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
519 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
520 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
521 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
jchen1099118c12018-09-10 16:28:51 +0800522 mComputeDirtyBits.set(State::DIRTY_BIT_IMAGE_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800523 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jamie Madille3e680c2018-12-03 17:49:08 -0500524 mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400525 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400526 mComputeDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800527
Jamie Madillb4927eb2018-07-16 11:39:46 -0400528 mImplementation->setErrorSet(&mErrors);
529
Jamie Madill4f6592f2018-11-27 16:37:45 -0500530 ANGLE_CONTEXT_TRY(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000531}
532
Jamie Madill4928b7c2017-06-20 12:57:39 -0400533egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000534{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700535 if (mGLES1Renderer)
536 {
537 mGLES1Renderer->onDestroy(this, &mGLState);
538 }
539
Jamie Madille7b3fe22018-04-05 09:42:46 -0400540 ANGLE_TRY(releaseSurface(display));
541
Corentin Wallez80b24112015-08-25 16:41:57 -0400542 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000543 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400544 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000545 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400546 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000547
Corentin Wallez80b24112015-08-25 16:41:57 -0400548 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000549 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400550 if (query.second != nullptr)
551 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400552 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400553 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000554 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400555 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000556
Corentin Wallez80b24112015-08-25 16:41:57 -0400557 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400558 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400559 if (vertexArray.second)
560 {
561 vertexArray.second->onDestroy(this);
562 }
Jamie Madill57a89722013-07-02 11:57:03 -0400563 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400564 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400565
Corentin Wallez80b24112015-08-25 16:41:57 -0400566 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500567 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500568 if (transformFeedback.second != nullptr)
569 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500570 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500571 }
Geoff Langc8058452014-02-03 12:04:11 -0500572 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400573 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500574
Jamie Madill5b772312018-03-08 20:28:32 -0500575 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400576 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800577 if (zeroTexture.get() != nullptr)
578 {
Jamie Madill1c7f08c2018-10-10 16:13:02 -0400579 zeroTexture->onDestroy(this);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800580 zeroTexture.set(this, nullptr);
581 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400582 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000583
Jamie Madill2f348d22017-06-05 10:50:59 -0400584 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500585
Jamie Madill4928b7c2017-06-20 12:57:39 -0400586 mGLState.reset(this);
587
Jamie Madill6c1f6712017-02-14 19:08:04 -0500588 mState.mBuffers->release(this);
589 mState.mShaderPrograms->release(this);
590 mState.mTextures->release(this);
591 mState.mRenderbuffers->release(this);
592 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400593 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500594 mState.mPaths->release(this);
595 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800596 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400597
jchen107ae70d82018-07-06 13:47:01 +0800598 mThreadPool.reset();
599
Jamie Madill76e471e2017-10-21 09:56:01 -0400600 mImplementation->onDestroy(this);
601
Jamie Madill4928b7c2017-06-20 12:57:39 -0400602 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000603}
604
Jamie Madillb980c562018-11-27 11:34:27 -0500605Context::~Context() {}
Jamie Madill70ee0f62017-02-06 16:04:20 -0500606
Geoff Lang75359662018-04-11 01:42:27 -0400607void Context::setLabel(EGLLabelKHR label)
608{
609 mLabel = label;
610}
611
612EGLLabelKHR Context::getLabel() const
613{
614 return mLabel;
615}
616
Jamie Madill4928b7c2017-06-20 12:57:39 -0400617egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000618{
Jamie Madill61e16b42017-06-19 11:13:23 -0400619 mCurrentDisplay = display;
620
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000621 if (!mHasBeenCurrent)
622 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400623 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000624 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500625 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400626 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000627
Corentin Wallezc295e512017-01-27 17:47:50 -0500628 int width = 0;
629 int height = 0;
630 if (surface != nullptr)
631 {
632 width = surface->getWidth();
633 height = surface->getHeight();
634 }
635
636 mGLState.setViewportParams(0, 0, width, height);
637 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000638
639 mHasBeenCurrent = true;
640 }
641
Jamie Madill1b94d432015-08-07 13:23:23 -0400642 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700643 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400644 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400645
Jamie Madill4928b7c2017-06-20 12:57:39 -0400646 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500647
648 Framebuffer *newDefault = nullptr;
649 if (surface != nullptr)
650 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400651 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500652 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400653 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500654 }
655 else
656 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400657 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500658 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000659
Corentin Wallez37c39792015-08-20 14:19:46 -0400660 // Update default framebuffer, the binding of the previous default
661 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400662 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400663 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700664 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400665 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400666 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400667 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700668 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400669 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400670 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400671 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400672 }
Ian Ewell292f0052016-02-04 10:37:32 -0500673
Jamie Madill32643ce2018-10-19 11:38:03 -0400674 // Notify the renderer of a context switch.
Jamie Madill7c985f52018-11-29 18:16:17 -0500675 return angle::ResultToEGL(mImplementation->onMakeCurrent(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000676}
677
Jamie Madill4928b7c2017-06-20 12:57:39 -0400678egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400679{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400680 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400681
Geoff Langbf7b95d2018-05-01 16:48:21 -0400682 // Remove the default framebuffer
683 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500684 {
685 mGLState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400686 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500687 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400688
689 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500690 {
691 mGLState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400692 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500693 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400694
695 if (defaultFramebuffer)
696 {
697 defaultFramebuffer->onDestroy(this);
698 delete defaultFramebuffer;
699 }
700
Corentin Wallezc295e512017-01-27 17:47:50 -0500701 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
702
703 if (mCurrentSurface)
704 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400705 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500706 mCurrentSurface = nullptr;
707 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400708
709 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400710}
711
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000712GLuint Context::createBuffer()
713{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500714 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000715}
716
717GLuint Context::createProgram()
718{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500719 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000720}
721
Jiawei Shao385b3e02018-03-21 09:43:28 +0800722GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000723{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500724 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000725}
726
727GLuint Context::createTexture()
728{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500729 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000730}
731
732GLuint Context::createRenderbuffer()
733{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500734 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000735}
736
Jamie Madill13951342018-09-30 15:24:28 -0400737void Context::tryGenPaths(GLsizei range, GLuint *createdOut)
738{
Jamie Madill526392d2018-11-16 09:35:14 -0500739 ANGLE_CONTEXT_TRY(mState.mPaths->createPaths(this, range, createdOut));
Jamie Madill13951342018-09-30 15:24:28 -0400740}
741
Brandon Jones59770802018-04-02 13:18:42 -0700742GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300743{
Jamie Madill13951342018-09-30 15:24:28 -0400744 GLuint created = 0;
745 tryGenPaths(range, &created);
746 return created;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300747}
748
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000749// Returns an unused framebuffer name
750GLuint Context::createFramebuffer()
751{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500752 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000753}
754
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500755void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000756{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500757 for (int i = 0; i < n; i++)
758 {
759 GLuint handle = mFenceNVHandleAllocator.allocate();
760 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
761 fences[i] = handle;
762 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000763}
764
Yunchao Hea336b902017-08-02 16:05:21 +0800765GLuint Context::createProgramPipeline()
766{
767 return mState.mPipelines->createProgramPipeline();
768}
769
Jiawei Shao385b3e02018-03-21 09:43:28 +0800770GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800771{
772 UNIMPLEMENTED();
773 return 0u;
774}
775
James Darpinian4d9d4832018-03-13 12:43:28 -0700776void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000777{
James Darpinian4d9d4832018-03-13 12:43:28 -0700778 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
779 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000780 {
781 detachBuffer(buffer);
782 }
Jamie Madill893ab082014-05-16 16:56:10 -0400783
James Darpinian4d9d4832018-03-13 12:43:28 -0700784 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000785}
786
787void Context::deleteShader(GLuint shader)
788{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500789 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000790}
791
792void Context::deleteProgram(GLuint program)
793{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500794 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000795}
796
797void Context::deleteTexture(GLuint texture)
798{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500799 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000800 {
801 detachTexture(texture);
802 }
803
Jamie Madill6c1f6712017-02-14 19:08:04 -0500804 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000805}
806
807void Context::deleteRenderbuffer(GLuint renderbuffer)
808{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500809 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000810 {
811 detachRenderbuffer(renderbuffer);
812 }
Jamie Madill893ab082014-05-16 16:56:10 -0400813
Jamie Madill6c1f6712017-02-14 19:08:04 -0500814 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000815}
816
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400817void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400818{
819 // The spec specifies the underlying Fence object is not deleted until all current
820 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
821 // and since our API is currently designed for being called from a single thread, we can delete
822 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400823 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400824}
825
Yunchao Hea336b902017-08-02 16:05:21 +0800826void Context::deleteProgramPipeline(GLuint pipeline)
827{
828 if (mState.mPipelines->getProgramPipeline(pipeline))
829 {
830 detachProgramPipeline(pipeline);
831 }
832
833 mState.mPipelines->deleteObject(this, pipeline);
834}
835
Sami Väisänene45e53b2016-05-25 10:36:04 +0300836void Context::deletePaths(GLuint first, GLsizei range)
837{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500838 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300839}
840
Brandon Jones59770802018-04-02 13:18:42 -0700841bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300842{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500843 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300844 if (pathObj == nullptr)
845 return false;
846
847 return pathObj->hasPathData();
848}
849
Brandon Jones59770802018-04-02 13:18:42 -0700850bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300851{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500852 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300853}
854
Brandon Jones59770802018-04-02 13:18:42 -0700855void Context::pathCommands(GLuint path,
856 GLsizei numCommands,
857 const GLubyte *commands,
858 GLsizei numCoords,
859 GLenum coordType,
860 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300861{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500862 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300863
Jamie Madill4f6592f2018-11-27 16:37:45 -0500864 ANGLE_CONTEXT_TRY(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300865}
866
Jamie Madill007530e2017-12-28 14:27:04 -0500867void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300868{
Jamie Madill007530e2017-12-28 14:27:04 -0500869 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300870
871 switch (pname)
872 {
873 case GL_PATH_STROKE_WIDTH_CHROMIUM:
874 pathObj->setStrokeWidth(value);
875 break;
876 case GL_PATH_END_CAPS_CHROMIUM:
877 pathObj->setEndCaps(static_cast<GLenum>(value));
878 break;
879 case GL_PATH_JOIN_STYLE_CHROMIUM:
880 pathObj->setJoinStyle(static_cast<GLenum>(value));
881 break;
882 case GL_PATH_MITER_LIMIT_CHROMIUM:
883 pathObj->setMiterLimit(value);
884 break;
885 case GL_PATH_STROKE_BOUND_CHROMIUM:
886 pathObj->setStrokeBound(value);
887 break;
888 default:
889 UNREACHABLE();
890 break;
891 }
892}
893
Jamie Madill007530e2017-12-28 14:27:04 -0500894void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300895{
Jamie Madill007530e2017-12-28 14:27:04 -0500896 // TODO(jmadill): Should use proper clamping/casting.
897 pathParameterf(path, pname, static_cast<GLfloat>(value));
898}
899
900void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
901{
902 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300903
904 switch (pname)
905 {
906 case GL_PATH_STROKE_WIDTH_CHROMIUM:
907 *value = pathObj->getStrokeWidth();
908 break;
909 case GL_PATH_END_CAPS_CHROMIUM:
910 *value = static_cast<GLfloat>(pathObj->getEndCaps());
911 break;
912 case GL_PATH_JOIN_STYLE_CHROMIUM:
913 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
914 break;
915 case GL_PATH_MITER_LIMIT_CHROMIUM:
916 *value = pathObj->getMiterLimit();
917 break;
918 case GL_PATH_STROKE_BOUND_CHROMIUM:
919 *value = pathObj->getStrokeBound();
920 break;
921 default:
922 UNREACHABLE();
923 break;
924 }
925}
926
Jamie Madill007530e2017-12-28 14:27:04 -0500927void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
928{
929 GLfloat val = 0.0f;
930 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
931 if (value)
932 *value = static_cast<GLint>(val);
933}
934
Brandon Jones59770802018-04-02 13:18:42 -0700935void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300936{
937 mGLState.setPathStencilFunc(func, ref, mask);
938}
939
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000940void Context::deleteFramebuffer(GLuint framebuffer)
941{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500942 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000943 {
944 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000945 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500946
Jamie Madill6c1f6712017-02-14 19:08:04 -0500947 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000948}
949
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500950void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000951{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500952 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000953 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500954 GLuint fence = fences[i];
955
956 FenceNV *fenceObject = nullptr;
957 if (mFenceNVMap.erase(fence, &fenceObject))
958 {
959 mFenceNVHandleAllocator.release(fence);
960 delete fenceObject;
961 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000962 }
963}
964
Geoff Lang70d0f492015-12-10 17:45:46 -0500965Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000966{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500967 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000968}
969
Geoff Lang70d0f492015-12-10 17:45:46 -0500970Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000971{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500972 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000973}
974
Jamie Madill70b5bb02017-08-28 13:32:37 -0400975Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400976{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400977 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400978}
979
Jamie Madill57a89722013-07-02 11:57:03 -0400980VertexArray *Context::getVertexArray(GLuint handle) const
981{
Jamie Madill96a483b2017-06-27 16:49:21 -0400982 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400983}
984
Jamie Madilldc356042013-07-19 16:36:57 -0400985Sampler *Context::getSampler(GLuint handle) const
986{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500987 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400988}
989
Geoff Langc8058452014-02-03 12:04:11 -0500990TransformFeedback *Context::getTransformFeedback(GLuint handle) const
991{
Jamie Madill96a483b2017-06-27 16:49:21 -0400992 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500993}
994
Yunchao Hea336b902017-08-02 16:05:21 +0800995ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
996{
997 return mState.mPipelines->getProgramPipeline(handle);
998}
999
Geoff Lang75359662018-04-11 01:42:27 -04001000gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001001{
1002 switch (identifier)
1003 {
1004 case GL_BUFFER:
1005 return getBuffer(name);
1006 case GL_SHADER:
1007 return getShader(name);
1008 case GL_PROGRAM:
Jamie Madill44a6fbf2018-10-02 13:38:56 -04001009 return getProgramNoResolveLink(name);
Geoff Lang70d0f492015-12-10 17:45:46 -05001010 case GL_VERTEX_ARRAY:
1011 return getVertexArray(name);
1012 case GL_QUERY:
1013 return getQuery(name);
1014 case GL_TRANSFORM_FEEDBACK:
1015 return getTransformFeedback(name);
1016 case GL_SAMPLER:
1017 return getSampler(name);
1018 case GL_TEXTURE:
1019 return getTexture(name);
1020 case GL_RENDERBUFFER:
1021 return getRenderbuffer(name);
1022 case GL_FRAMEBUFFER:
1023 return getFramebuffer(name);
1024 default:
1025 UNREACHABLE();
1026 return nullptr;
1027 }
1028}
1029
Geoff Lang75359662018-04-11 01:42:27 -04001030gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001031{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001032 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001033}
1034
Martin Radev9d901792016-07-15 15:58:58 +03001035void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1036{
Geoff Lang75359662018-04-11 01:42:27 -04001037 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001038 ASSERT(object != nullptr);
1039
1040 std::string labelName = GetObjectLabelFromPointer(length, label);
Jamie Madille90d4ee2018-11-28 14:04:00 -05001041 object->setLabel(this, labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001042
1043 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1044 // specified object is active until we do this.
1045 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001046}
1047
1048void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1049{
Geoff Lang75359662018-04-11 01:42:27 -04001050 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001051 ASSERT(object != nullptr);
1052
1053 std::string labelName = GetObjectLabelFromPointer(length, label);
Jamie Madille90d4ee2018-11-28 14:04:00 -05001054 object->setLabel(this, labelName);
Martin Radev9d901792016-07-15 15:58:58 +03001055}
1056
1057void Context::getObjectLabel(GLenum identifier,
1058 GLuint name,
1059 GLsizei bufSize,
1060 GLsizei *length,
1061 GLchar *label) const
1062{
Geoff Lang75359662018-04-11 01:42:27 -04001063 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001064 ASSERT(object != nullptr);
1065
1066 const std::string &objectLabel = object->getLabel();
1067 GetObjectLabelBase(objectLabel, bufSize, length, label);
1068}
1069
1070void Context::getObjectPtrLabel(const void *ptr,
1071 GLsizei bufSize,
1072 GLsizei *length,
1073 GLchar *label) const
1074{
Geoff Lang75359662018-04-11 01:42:27 -04001075 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001076 ASSERT(object != nullptr);
1077
1078 const std::string &objectLabel = object->getLabel();
1079 GetObjectLabelBase(objectLabel, bufSize, length, label);
1080}
1081
Jamie Madilldc356042013-07-19 16:36:57 -04001082bool Context::isSampler(GLuint samplerName) const
1083{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001084 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001085}
1086
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001087void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001088{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001089 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001090
Jamie Madilldedd7b92014-11-05 16:30:36 -05001091 if (handle == 0)
1092 {
1093 texture = mZeroTextures[target].get();
1094 }
1095 else
1096 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001097 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001098 }
1099
1100 ASSERT(texture);
Jamie Madille3e680c2018-12-03 17:49:08 -05001101 mGLState.setSamplerTexture(this, target, texture);
Jamie Madilld84b6732018-09-06 15:54:35 -04001102 mStateCache.onActiveTextureChange(this);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001103}
1104
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001105void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001106{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001107 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1108 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001109 mGLState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001110 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001111}
1112
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001113void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001114{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001115 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1116 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001117 mGLState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001118 mDrawFramebufferObserverBinding.bind(framebuffer);
Jamie Madilld84b6732018-09-06 15:54:35 -04001119 mStateCache.onDrawFramebufferChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001120}
1121
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001122void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001123{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001124 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001125 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001126 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001127 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001128}
1129
Shao80957d92017-02-20 21:25:59 +08001130void Context::bindVertexBuffer(GLuint bindingIndex,
1131 GLuint bufferHandle,
1132 GLintptr offset,
1133 GLsizei stride)
1134{
1135 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001136 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001137 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001138}
1139
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001140void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001141{
Geoff Lang76b10c92014-09-05 16:28:14 -04001142 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001143 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001144 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001145 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04001146 mSamplerObserverBindings[textureUnit].bind(sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001147}
1148
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001149void Context::bindImageTexture(GLuint unit,
1150 GLuint texture,
1151 GLint level,
1152 GLboolean layered,
1153 GLint layer,
1154 GLenum access,
1155 GLenum format)
1156{
1157 Texture *tex = mState.mTextures->getTexture(texture);
1158 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
Jamie Madille3e680c2018-12-03 17:49:08 -05001159 mImageObserverBindings[unit].bind(tex);
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001160}
1161
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001162void Context::useProgram(GLuint program)
1163{
Jamie Madille3bb6b72018-10-03 17:51:15 -04001164 ANGLE_CONTEXT_TRY(mGLState.setProgram(this, getProgramResolveLink(program)));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001165 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001166}
1167
Jiajia Qin5451d532017-11-16 17:16:34 +08001168void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1169{
1170 UNIMPLEMENTED();
1171}
1172
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001173void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001174{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001175 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001176 TransformFeedback *transformFeedback =
1177 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001178 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001179}
1180
Yunchao Hea336b902017-08-02 16:05:21 +08001181void Context::bindProgramPipeline(GLuint pipelineHandle)
1182{
1183 ProgramPipeline *pipeline =
1184 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1185 mGLState.setProgramPipelineBinding(this, pipeline);
1186}
1187
Corentin Wallezad3ae902018-03-09 13:40:42 -05001188void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001189{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001190 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001191 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001192
Geoff Lang5aad9672014-09-08 11:10:42 -04001193 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001194 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001195
1196 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001197 mGLState.setActiveQuery(this, target, queryObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04001198 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001199}
1200
Corentin Wallezad3ae902018-03-09 13:40:42 -05001201void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001202{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001203 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001204 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001205
Jamie Madill4f6592f2018-11-27 16:37:45 -05001206 // Intentionally don't call try here. We don't want an early return.
1207 (void)(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001208
Geoff Lang5aad9672014-09-08 11:10:42 -04001209 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001210 mGLState.setActiveQuery(this, target, nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04001211 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001212}
1213
Corentin Wallezad3ae902018-03-09 13:40:42 -05001214void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001215{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001216 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001217
1218 Query *queryObject = getQuery(id, true, target);
1219 ASSERT(queryObject);
1220
Jamie Madill4f6592f2018-11-27 16:37:45 -05001221 ANGLE_CONTEXT_TRY(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001222}
1223
Corentin Wallezad3ae902018-03-09 13:40:42 -05001224void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001225{
1226 switch (pname)
1227 {
1228 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001229 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001230 break;
1231 case GL_QUERY_COUNTER_BITS_EXT:
1232 switch (target)
1233 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001234 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001235 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1236 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001237 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001238 params[0] = getExtensions().queryCounterBitsTimestamp;
1239 break;
1240 default:
1241 UNREACHABLE();
1242 params[0] = 0;
1243 break;
1244 }
1245 break;
1246 default:
1247 UNREACHABLE();
1248 return;
1249 }
1250}
1251
Corentin Wallezad3ae902018-03-09 13:40:42 -05001252void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001253 GLenum pname,
1254 GLsizei bufSize,
1255 GLsizei *length,
1256 GLint *params)
1257{
1258 getQueryiv(target, pname, params);
1259}
1260
Geoff Lang2186c382016-10-14 10:54:54 -04001261void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001262{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001263 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001264}
1265
Brandon Jones59770802018-04-02 13:18:42 -07001266void Context::getQueryObjectivRobust(GLuint id,
1267 GLenum pname,
1268 GLsizei bufSize,
1269 GLsizei *length,
1270 GLint *params)
1271{
1272 getQueryObjectiv(id, pname, params);
1273}
1274
Geoff Lang2186c382016-10-14 10:54:54 -04001275void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001276{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001277 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001278}
1279
Brandon Jones59770802018-04-02 13:18:42 -07001280void Context::getQueryObjectuivRobust(GLuint id,
1281 GLenum pname,
1282 GLsizei bufSize,
1283 GLsizei *length,
1284 GLuint *params)
1285{
1286 getQueryObjectuiv(id, pname, params);
1287}
1288
Geoff Lang2186c382016-10-14 10:54:54 -04001289void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001290{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001291 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001292}
1293
Brandon Jones59770802018-04-02 13:18:42 -07001294void Context::getQueryObjecti64vRobust(GLuint id,
1295 GLenum pname,
1296 GLsizei bufSize,
1297 GLsizei *length,
1298 GLint64 *params)
1299{
1300 getQueryObjecti64v(id, pname, params);
1301}
1302
Geoff Lang2186c382016-10-14 10:54:54 -04001303void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001304{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001305 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001306}
1307
Brandon Jones59770802018-04-02 13:18:42 -07001308void Context::getQueryObjectui64vRobust(GLuint id,
1309 GLenum pname,
1310 GLsizei bufSize,
1311 GLsizei *length,
1312 GLuint64 *params)
1313{
1314 getQueryObjectui64v(id, pname, params);
1315}
1316
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001317Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001318{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001319 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001320}
1321
Jamie Madill2f348d22017-06-05 10:50:59 -04001322FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001323{
Jamie Madill96a483b2017-06-27 16:49:21 -04001324 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001325}
1326
Corentin Wallezad3ae902018-03-09 13:40:42 -05001327Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001328{
Jamie Madill96a483b2017-06-27 16:49:21 -04001329 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001330 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001331 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001332 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001333
1334 Query *query = mQueryMap.query(handle);
1335 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001336 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001337 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001338 query = new Query(mImplementation->createQuery(type), handle);
1339 query->addRef();
1340 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001341 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001342 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001343}
1344
Geoff Lang70d0f492015-12-10 17:45:46 -05001345Query *Context::getQuery(GLuint handle) const
1346{
Jamie Madill96a483b2017-06-27 16:49:21 -04001347 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001348}
1349
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001350Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001351{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001352 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1353 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001354}
1355
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001356Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001357{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001358 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001359}
1360
Geoff Lang492a7e42014-11-05 13:27:06 -05001361Compiler *Context::getCompiler() const
1362{
Jamie Madill2f348d22017-06-05 10:50:59 -04001363 if (mCompiler.get() == nullptr)
1364 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001365 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001366 }
1367 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001368}
1369
Jamie Madillc1d770e2017-04-13 17:31:24 -04001370void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001371{
1372 switch (pname)
1373 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001374 case GL_SHADER_COMPILER:
1375 *params = GL_TRUE;
1376 break;
1377 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1378 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1379 break;
1380 default:
1381 mGLState.getBooleanv(pname, params);
1382 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001383 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001384}
1385
Jamie Madillc1d770e2017-04-13 17:31:24 -04001386void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001387{
Shannon Woods53a94a82014-06-24 15:20:36 -04001388 // Queries about context capabilities and maximums are answered by Context.
1389 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001390 switch (pname)
1391 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001392 case GL_ALIASED_LINE_WIDTH_RANGE:
1393 params[0] = mCaps.minAliasedLineWidth;
1394 params[1] = mCaps.maxAliasedLineWidth;
1395 break;
1396 case GL_ALIASED_POINT_SIZE_RANGE:
1397 params[0] = mCaps.minAliasedPointSize;
1398 params[1] = mCaps.maxAliasedPointSize;
1399 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001400 case GL_SMOOTH_POINT_SIZE_RANGE:
1401 params[0] = mCaps.minSmoothPointSize;
1402 params[1] = mCaps.maxSmoothPointSize;
1403 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001404 case GL_SMOOTH_LINE_WIDTH_RANGE:
1405 params[0] = mCaps.minSmoothLineWidth;
1406 params[1] = mCaps.maxSmoothLineWidth;
1407 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001408 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1409 ASSERT(mExtensions.textureFilterAnisotropic);
1410 *params = mExtensions.maxTextureAnisotropy;
1411 break;
1412 case GL_MAX_TEXTURE_LOD_BIAS:
1413 *params = mCaps.maxLODBias;
1414 break;
1415
1416 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1417 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1418 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001419 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1420 // GLES1 constants for modelview/projection matrix.
1421 if (getClientVersion() < Version(2, 0))
1422 {
1423 mGLState.getFloatv(pname, params);
1424 }
1425 else
1426 {
1427 ASSERT(mExtensions.pathRendering);
1428 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1429 memcpy(params, m, 16 * sizeof(GLfloat));
1430 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001431 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001432 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001433
Jamie Madill231c7f52017-04-26 13:45:37 -04001434 default:
1435 mGLState.getFloatv(pname, params);
1436 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001437 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001438}
1439
Jamie Madillc1d770e2017-04-13 17:31:24 -04001440void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001441{
Shannon Woods53a94a82014-06-24 15:20:36 -04001442 // Queries about context capabilities and maximums are answered by Context.
1443 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001444
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001445 switch (pname)
1446 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001447 case GL_MAX_VERTEX_ATTRIBS:
1448 *params = mCaps.maxVertexAttributes;
1449 break;
1450 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1451 *params = mCaps.maxVertexUniformVectors;
1452 break;
1453 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001454 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001455 break;
1456 case GL_MAX_VARYING_VECTORS:
1457 *params = mCaps.maxVaryingVectors;
1458 break;
1459 case GL_MAX_VARYING_COMPONENTS:
1460 *params = mCaps.maxVertexOutputComponents;
1461 break;
1462 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1463 *params = mCaps.maxCombinedTextureImageUnits;
1464 break;
1465 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001466 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001467 break;
1468 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001469 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001470 break;
1471 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1472 *params = mCaps.maxFragmentUniformVectors;
1473 break;
1474 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001475 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001476 break;
1477 case GL_MAX_RENDERBUFFER_SIZE:
1478 *params = mCaps.maxRenderbufferSize;
1479 break;
1480 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1481 *params = mCaps.maxColorAttachments;
1482 break;
1483 case GL_MAX_DRAW_BUFFERS_EXT:
1484 *params = mCaps.maxDrawBuffers;
1485 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001486 case GL_SUBPIXEL_BITS:
1487 *params = 4;
1488 break;
1489 case GL_MAX_TEXTURE_SIZE:
1490 *params = mCaps.max2DTextureSize;
1491 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001492 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1493 *params = mCaps.maxRectangleTextureSize;
1494 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001495 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1496 *params = mCaps.maxCubeMapTextureSize;
1497 break;
1498 case GL_MAX_3D_TEXTURE_SIZE:
1499 *params = mCaps.max3DTextureSize;
1500 break;
1501 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1502 *params = mCaps.maxArrayTextureLayers;
1503 break;
1504 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1505 *params = mCaps.uniformBufferOffsetAlignment;
1506 break;
1507 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1508 *params = mCaps.maxUniformBufferBindings;
1509 break;
1510 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001511 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001512 break;
1513 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001514 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001515 break;
1516 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1517 *params = mCaps.maxCombinedTextureImageUnits;
1518 break;
1519 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1520 *params = mCaps.maxVertexOutputComponents;
1521 break;
1522 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1523 *params = mCaps.maxFragmentInputComponents;
1524 break;
1525 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1526 *params = mCaps.minProgramTexelOffset;
1527 break;
1528 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1529 *params = mCaps.maxProgramTexelOffset;
1530 break;
1531 case GL_MAJOR_VERSION:
1532 *params = getClientVersion().major;
1533 break;
1534 case GL_MINOR_VERSION:
1535 *params = getClientVersion().minor;
1536 break;
1537 case GL_MAX_ELEMENTS_INDICES:
1538 *params = mCaps.maxElementsIndices;
1539 break;
1540 case GL_MAX_ELEMENTS_VERTICES:
1541 *params = mCaps.maxElementsVertices;
1542 break;
1543 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1544 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1545 break;
1546 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1547 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1548 break;
1549 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1550 *params = mCaps.maxTransformFeedbackSeparateComponents;
1551 break;
1552 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1553 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1554 break;
1555 case GL_MAX_SAMPLES_ANGLE:
1556 *params = mCaps.maxSamples;
1557 break;
1558 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001559 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001560 params[0] = mCaps.maxViewportWidth;
1561 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001562 }
1563 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001564 case GL_COMPRESSED_TEXTURE_FORMATS:
1565 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1566 params);
1567 break;
1568 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1569 *params = mResetStrategy;
1570 break;
1571 case GL_NUM_SHADER_BINARY_FORMATS:
1572 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1573 break;
1574 case GL_SHADER_BINARY_FORMATS:
1575 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1576 break;
1577 case GL_NUM_PROGRAM_BINARY_FORMATS:
1578 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1579 break;
1580 case GL_PROGRAM_BINARY_FORMATS:
1581 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1582 break;
1583 case GL_NUM_EXTENSIONS:
1584 *params = static_cast<GLint>(mExtensionStrings.size());
1585 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001586
Geoff Lang38f24ee2018-10-01 13:04:59 -04001587 // GL_ANGLE_request_extension
1588 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
1589 *params = static_cast<GLint>(mRequestableExtensionStrings.size());
1590 break;
1591
Jamie Madill231c7f52017-04-26 13:45:37 -04001592 // GL_KHR_debug
1593 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1594 *params = mExtensions.maxDebugMessageLength;
1595 break;
1596 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1597 *params = mExtensions.maxDebugLoggedMessages;
1598 break;
1599 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1600 *params = mExtensions.maxDebugGroupStackDepth;
1601 break;
1602 case GL_MAX_LABEL_LENGTH:
1603 *params = mExtensions.maxLabelLength;
1604 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001605
Martin Radeve5285d22017-07-14 16:23:53 +03001606 // GL_ANGLE_multiview
1607 case GL_MAX_VIEWS_ANGLE:
1608 *params = mExtensions.maxViews;
1609 break;
1610
Jamie Madill231c7f52017-04-26 13:45:37 -04001611 // GL_EXT_disjoint_timer_query
1612 case GL_GPU_DISJOINT_EXT:
1613 *params = mImplementation->getGPUDisjoint();
1614 break;
1615 case GL_MAX_FRAMEBUFFER_WIDTH:
1616 *params = mCaps.maxFramebufferWidth;
1617 break;
1618 case GL_MAX_FRAMEBUFFER_HEIGHT:
1619 *params = mCaps.maxFramebufferHeight;
1620 break;
1621 case GL_MAX_FRAMEBUFFER_SAMPLES:
1622 *params = mCaps.maxFramebufferSamples;
1623 break;
1624 case GL_MAX_SAMPLE_MASK_WORDS:
1625 *params = mCaps.maxSampleMaskWords;
1626 break;
1627 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1628 *params = mCaps.maxColorTextureSamples;
1629 break;
1630 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1631 *params = mCaps.maxDepthTextureSamples;
1632 break;
1633 case GL_MAX_INTEGER_SAMPLES:
1634 *params = mCaps.maxIntegerSamples;
1635 break;
1636 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1637 *params = mCaps.maxVertexAttribRelativeOffset;
1638 break;
1639 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1640 *params = mCaps.maxVertexAttribBindings;
1641 break;
1642 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1643 *params = mCaps.maxVertexAttribStride;
1644 break;
1645 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001646 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001647 break;
1648 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001649 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001650 break;
1651 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001652 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001653 break;
1654 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001655 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001656 break;
1657 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001658 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001659 break;
1660 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001661 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001662 break;
1663 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001664 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001665 break;
1666 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001667 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001668 break;
1669 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1670 *params = mCaps.minProgramTextureGatherOffset;
1671 break;
1672 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1673 *params = mCaps.maxProgramTextureGatherOffset;
1674 break;
1675 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1676 *params = mCaps.maxComputeWorkGroupInvocations;
1677 break;
1678 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001679 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001680 break;
1681 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001682 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001683 break;
1684 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1685 *params = mCaps.maxComputeSharedMemorySize;
1686 break;
1687 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001688 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001689 break;
1690 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001691 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001692 break;
1693 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001694 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001695 break;
1696 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001697 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001698 break;
1699 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001700 *params =
1701 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001702 break;
1703 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001704 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001705 break;
1706 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1707 *params = mCaps.maxCombinedShaderOutputResources;
1708 break;
1709 case GL_MAX_UNIFORM_LOCATIONS:
1710 *params = mCaps.maxUniformLocations;
1711 break;
1712 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1713 *params = mCaps.maxAtomicCounterBufferBindings;
1714 break;
1715 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1716 *params = mCaps.maxAtomicCounterBufferSize;
1717 break;
1718 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1719 *params = mCaps.maxCombinedAtomicCounterBuffers;
1720 break;
1721 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1722 *params = mCaps.maxCombinedAtomicCounters;
1723 break;
1724 case GL_MAX_IMAGE_UNITS:
1725 *params = mCaps.maxImageUnits;
1726 break;
1727 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1728 *params = mCaps.maxCombinedImageUniforms;
1729 break;
1730 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1731 *params = mCaps.maxShaderStorageBufferBindings;
1732 break;
1733 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1734 *params = mCaps.maxCombinedShaderStorageBlocks;
1735 break;
1736 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1737 *params = mCaps.shaderStorageBufferOffsetAlignment;
1738 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001739
1740 // GL_EXT_geometry_shader
1741 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1742 *params = mCaps.maxFramebufferLayers;
1743 break;
1744 case GL_LAYER_PROVOKING_VERTEX_EXT:
1745 *params = mCaps.layerProvokingVertex;
1746 break;
1747 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001748 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001749 break;
1750 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001751 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001752 break;
1753 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001754 *params =
1755 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001756 break;
1757 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1758 *params = mCaps.maxGeometryInputComponents;
1759 break;
1760 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1761 *params = mCaps.maxGeometryOutputComponents;
1762 break;
1763 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1764 *params = mCaps.maxGeometryOutputVertices;
1765 break;
1766 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1767 *params = mCaps.maxGeometryTotalOutputComponents;
1768 break;
1769 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1770 *params = mCaps.maxGeometryShaderInvocations;
1771 break;
1772 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001773 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001774 break;
1775 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001776 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001777 break;
1778 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001779 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001780 break;
1781 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001782 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001783 break;
1784 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001785 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001786 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001787 // GLES1 emulation: Caps queries
1788 case GL_MAX_TEXTURE_UNITS:
1789 *params = mCaps.maxMultitextureUnits;
1790 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001791 case GL_MAX_MODELVIEW_STACK_DEPTH:
1792 *params = mCaps.maxModelviewMatrixStackDepth;
1793 break;
1794 case GL_MAX_PROJECTION_STACK_DEPTH:
1795 *params = mCaps.maxProjectionMatrixStackDepth;
1796 break;
1797 case GL_MAX_TEXTURE_STACK_DEPTH:
1798 *params = mCaps.maxTextureMatrixStackDepth;
1799 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001800 case GL_MAX_LIGHTS:
1801 *params = mCaps.maxLights;
1802 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001803 case GL_MAX_CLIP_PLANES:
1804 *params = mCaps.maxClipPlanes;
1805 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001806 // GLES1 emulation: Vertex attribute queries
1807 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1808 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1809 case GL_COLOR_ARRAY_BUFFER_BINDING:
1810 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1811 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1812 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1813 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1814 break;
1815 case GL_VERTEX_ARRAY_STRIDE:
1816 case GL_NORMAL_ARRAY_STRIDE:
1817 case GL_COLOR_ARRAY_STRIDE:
1818 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1819 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1820 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1821 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1822 break;
1823 case GL_VERTEX_ARRAY_SIZE:
1824 case GL_COLOR_ARRAY_SIZE:
1825 case GL_TEXTURE_COORD_ARRAY_SIZE:
1826 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1827 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1828 break;
1829 case GL_VERTEX_ARRAY_TYPE:
1830 case GL_COLOR_ARRAY_TYPE:
1831 case GL_NORMAL_ARRAY_TYPE:
1832 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1833 case GL_TEXTURE_COORD_ARRAY_TYPE:
1834 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1835 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1836 break;
1837
jchen1082af6202018-06-22 10:59:52 +08001838 // GL_KHR_parallel_shader_compile
1839 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1840 *params = mGLState.getMaxShaderCompilerThreads();
1841 break;
1842
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001843 // GL_EXT_blend_func_extended
1844 case GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT:
1845 *params = mExtensions.maxDualSourceDrawBuffers;
1846 break;
1847
Jamie Madill231c7f52017-04-26 13:45:37 -04001848 default:
Jamie Madill4f6592f2018-11-27 16:37:45 -05001849 ANGLE_CONTEXT_TRY(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001850 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001851 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001852}
1853
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001854void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001855{
Shannon Woods53a94a82014-06-24 15:20:36 -04001856 // Queries about context capabilities and maximums are answered by Context.
1857 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001858 switch (pname)
1859 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001860 case GL_MAX_ELEMENT_INDEX:
1861 *params = mCaps.maxElementIndex;
1862 break;
1863 case GL_MAX_UNIFORM_BLOCK_SIZE:
1864 *params = mCaps.maxUniformBlockSize;
1865 break;
1866 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001867 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001868 break;
1869 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001870 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001871 break;
1872 case GL_MAX_SERVER_WAIT_TIMEOUT:
1873 *params = mCaps.maxServerWaitTimeout;
1874 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001875
Jamie Madill231c7f52017-04-26 13:45:37 -04001876 // GL_EXT_disjoint_timer_query
1877 case GL_TIMESTAMP_EXT:
1878 *params = mImplementation->getTimestamp();
1879 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001880
Jamie Madill231c7f52017-04-26 13:45:37 -04001881 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1882 *params = mCaps.maxShaderStorageBlockSize;
1883 break;
1884 default:
1885 UNREACHABLE();
1886 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001887 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001888}
1889
Geoff Lang70d0f492015-12-10 17:45:46 -05001890void Context::getPointerv(GLenum pname, void **params) const
1891{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001892 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001893}
1894
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001895void Context::getPointervRobustANGLERobust(GLenum pname,
1896 GLsizei bufSize,
1897 GLsizei *length,
1898 void **params)
1899{
1900 UNIMPLEMENTED();
1901}
1902
Martin Radev66fb8202016-07-28 11:45:20 +03001903void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001904{
Shannon Woods53a94a82014-06-24 15:20:36 -04001905 // Queries about context capabilities and maximums are answered by Context.
1906 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001907
1908 GLenum nativeType;
1909 unsigned int numParams;
1910 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1911 ASSERT(queryStatus);
1912
1913 if (nativeType == GL_INT)
1914 {
1915 switch (target)
1916 {
1917 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1918 ASSERT(index < 3u);
1919 *data = mCaps.maxComputeWorkGroupCount[index];
1920 break;
1921 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1922 ASSERT(index < 3u);
1923 *data = mCaps.maxComputeWorkGroupSize[index];
1924 break;
1925 default:
1926 mGLState.getIntegeri_v(target, index, data);
1927 }
1928 }
1929 else
1930 {
1931 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1932 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001933}
1934
Brandon Jones59770802018-04-02 13:18:42 -07001935void Context::getIntegeri_vRobust(GLenum target,
1936 GLuint index,
1937 GLsizei bufSize,
1938 GLsizei *length,
1939 GLint *data)
1940{
1941 getIntegeri_v(target, index, data);
1942}
1943
Martin Radev66fb8202016-07-28 11:45:20 +03001944void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001945{
Shannon Woods53a94a82014-06-24 15:20:36 -04001946 // Queries about context capabilities and maximums are answered by Context.
1947 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001948
1949 GLenum nativeType;
1950 unsigned int numParams;
1951 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1952 ASSERT(queryStatus);
1953
1954 if (nativeType == GL_INT_64_ANGLEX)
1955 {
1956 mGLState.getInteger64i_v(target, index, data);
1957 }
1958 else
1959 {
1960 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1961 }
1962}
1963
Brandon Jones59770802018-04-02 13:18:42 -07001964void Context::getInteger64i_vRobust(GLenum target,
1965 GLuint index,
1966 GLsizei bufSize,
1967 GLsizei *length,
1968 GLint64 *data)
1969{
1970 getInteger64i_v(target, index, data);
1971}
1972
Martin Radev66fb8202016-07-28 11:45:20 +03001973void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1974{
1975 // Queries about context capabilities and maximums are answered by Context.
1976 // Queries about current GL state values are answered by State.
1977
1978 GLenum nativeType;
1979 unsigned int numParams;
1980 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1981 ASSERT(queryStatus);
1982
1983 if (nativeType == GL_BOOL)
1984 {
1985 mGLState.getBooleani_v(target, index, data);
1986 }
1987 else
1988 {
1989 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1990 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001991}
1992
Brandon Jones59770802018-04-02 13:18:42 -07001993void Context::getBooleani_vRobust(GLenum target,
1994 GLuint index,
1995 GLsizei bufSize,
1996 GLsizei *length,
1997 GLboolean *data)
1998{
1999 getBooleani_v(target, index, data);
2000}
2001
Corentin Wallez336129f2017-10-17 15:55:40 -04002002void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002003{
2004 Buffer *buffer = mGLState.getTargetBuffer(target);
2005 QueryBufferParameteriv(buffer, pname, params);
2006}
2007
Brandon Jones59770802018-04-02 13:18:42 -07002008void Context::getBufferParameterivRobust(BufferBinding target,
2009 GLenum pname,
2010 GLsizei bufSize,
2011 GLsizei *length,
2012 GLint *params)
2013{
2014 getBufferParameteriv(target, pname, params);
2015}
2016
He Yunchao010e4db2017-03-03 14:22:06 +08002017void Context::getFramebufferAttachmentParameteriv(GLenum target,
2018 GLenum attachment,
2019 GLenum pname,
2020 GLint *params)
2021{
2022 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002023 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002024}
2025
Brandon Jones59770802018-04-02 13:18:42 -07002026void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2027 GLenum attachment,
2028 GLenum pname,
2029 GLsizei bufSize,
2030 GLsizei *length,
2031 GLint *params)
2032{
2033 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2034}
2035
He Yunchao010e4db2017-03-03 14:22:06 +08002036void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2037{
2038 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2039 QueryRenderbufferiv(this, renderbuffer, pname, params);
2040}
2041
Brandon Jones59770802018-04-02 13:18:42 -07002042void Context::getRenderbufferParameterivRobust(GLenum target,
2043 GLenum pname,
2044 GLsizei bufSize,
2045 GLsizei *length,
2046 GLint *params)
2047{
2048 getRenderbufferParameteriv(target, pname, params);
2049}
2050
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002051void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002052{
Till Rathmannb8543632018-10-02 19:46:14 +02002053 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002054 QueryTexParameterfv(texture, pname, params);
2055}
2056
Brandon Jones59770802018-04-02 13:18:42 -07002057void Context::getTexParameterfvRobust(TextureType target,
2058 GLenum pname,
2059 GLsizei bufSize,
2060 GLsizei *length,
2061 GLfloat *params)
2062{
2063 getTexParameterfv(target, pname, params);
2064}
2065
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002066void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002067{
Till Rathmannb8543632018-10-02 19:46:14 +02002068 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002069 QueryTexParameteriv(texture, pname, params);
2070}
Jiajia Qin5451d532017-11-16 17:16:34 +08002071
Till Rathmannb8543632018-10-02 19:46:14 +02002072void Context::getTexParameterIiv(TextureType target, GLenum pname, GLint *params)
2073{
2074 const Texture *const texture = getTargetTexture(target);
2075 QueryTexParameterIiv(texture, pname, params);
2076}
2077
2078void Context::getTexParameterIuiv(TextureType target, GLenum pname, GLuint *params)
2079{
2080 const Texture *const texture = getTargetTexture(target);
2081 QueryTexParameterIuiv(texture, pname, params);
2082}
2083
Brandon Jones59770802018-04-02 13:18:42 -07002084void Context::getTexParameterivRobust(TextureType target,
2085 GLenum pname,
2086 GLsizei bufSize,
2087 GLsizei *length,
2088 GLint *params)
2089{
2090 getTexParameteriv(target, pname, params);
2091}
2092
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002093void Context::getTexParameterIivRobust(TextureType target,
2094 GLenum pname,
2095 GLsizei bufSize,
2096 GLsizei *length,
2097 GLint *params)
2098{
2099 UNIMPLEMENTED();
2100}
2101
2102void Context::getTexParameterIuivRobust(TextureType target,
2103 GLenum pname,
2104 GLsizei bufSize,
2105 GLsizei *length,
2106 GLuint *params)
2107{
2108 UNIMPLEMENTED();
2109}
2110
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002111void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002112{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002113 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002114 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002115}
2116
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002117void Context::getTexLevelParameterivRobust(TextureTarget target,
2118 GLint level,
2119 GLenum pname,
2120 GLsizei bufSize,
2121 GLsizei *length,
2122 GLint *params)
2123{
2124 UNIMPLEMENTED();
2125}
2126
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002127void Context::getTexLevelParameterfv(TextureTarget target,
2128 GLint level,
2129 GLenum pname,
2130 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002131{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002132 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002133 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002134}
2135
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002136void Context::getTexLevelParameterfvRobust(TextureTarget target,
2137 GLint level,
2138 GLenum pname,
2139 GLsizei bufSize,
2140 GLsizei *length,
2141 GLfloat *params)
2142{
2143 UNIMPLEMENTED();
2144}
2145
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002146void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002147{
Till Rathmannb8543632018-10-02 19:46:14 +02002148 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002149 SetTexParameterf(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002150}
2151
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002152void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002153{
Till Rathmannb8543632018-10-02 19:46:14 +02002154 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002155 SetTexParameterfv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002156}
2157
Brandon Jones59770802018-04-02 13:18:42 -07002158void Context::texParameterfvRobust(TextureType target,
2159 GLenum pname,
2160 GLsizei bufSize,
2161 const GLfloat *params)
2162{
2163 texParameterfv(target, pname, params);
2164}
2165
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002166void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002167{
Till Rathmannb8543632018-10-02 19:46:14 +02002168 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002169 SetTexParameteri(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002170}
2171
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002172void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002173{
Till Rathmannb8543632018-10-02 19:46:14 +02002174 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002175 SetTexParameteriv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002176}
2177
Till Rathmannb8543632018-10-02 19:46:14 +02002178void Context::texParameterIiv(TextureType target, GLenum pname, const GLint *params)
2179{
2180 Texture *const texture = getTargetTexture(target);
2181 SetTexParameterIiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002182}
2183
2184void Context::texParameterIuiv(TextureType target, GLenum pname, const GLuint *params)
2185{
2186 Texture *const texture = getTargetTexture(target);
2187 SetTexParameterIuiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002188}
2189
Brandon Jones59770802018-04-02 13:18:42 -07002190void Context::texParameterivRobust(TextureType target,
2191 GLenum pname,
2192 GLsizei bufSize,
2193 const GLint *params)
2194{
2195 texParameteriv(target, pname, params);
2196}
2197
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002198void Context::texParameterIivRobust(TextureType target,
2199 GLenum pname,
2200 GLsizei bufSize,
2201 const GLint *params)
2202{
2203 UNIMPLEMENTED();
2204}
2205
2206void Context::texParameterIuivRobust(TextureType target,
2207 GLenum pname,
2208 GLsizei bufSize,
2209 const GLuint *params)
2210{
2211 UNIMPLEMENTED();
2212}
2213
Jamie Madill493f9572018-05-24 19:52:15 -04002214void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002215{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002216 // No-op if count draws no primitives for given mode
2217 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002218 {
2219 return;
2220 }
2221
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002222 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002223 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05002224 MarkTransformFeedbackBufferUsage(this, count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002225}
2226
Jamie Madill493f9572018-05-24 19:52:15 -04002227void Context::drawArraysInstanced(PrimitiveMode mode,
2228 GLint first,
2229 GLsizei count,
2230 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002231{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002232 // No-op if count draws no primitives for given mode
2233 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002234 {
2235 return;
2236 }
2237
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002238 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002239 ANGLE_CONTEXT_TRY(
2240 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05002241 MarkTransformFeedbackBufferUsage(this, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002242}
2243
Jamie Madill8dc27f92018-11-29 11:45:44 -05002244void Context::drawElements(PrimitiveMode mode,
2245 GLsizei count,
2246 DrawElementsType type,
2247 const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002248{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002249 // No-op if count draws no primitives for given mode
2250 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002251 {
2252 return;
2253 }
2254
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002255 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002256 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002257}
2258
Jamie Madill493f9572018-05-24 19:52:15 -04002259void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002260 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002261 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002262 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002263 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002264{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002265 // No-op if count draws no primitives for given mode
2266 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002267 {
2268 return;
2269 }
2270
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002271 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002272 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002273 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002274}
2275
Jamie Madill493f9572018-05-24 19:52:15 -04002276void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002277 GLuint start,
2278 GLuint end,
2279 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002280 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002281 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002282{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002283 // No-op if count draws no primitives for given mode
2284 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002285 {
2286 return;
2287 }
2288
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002289 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002290 ANGLE_CONTEXT_TRY(
2291 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002292}
2293
Jamie Madill493f9572018-05-24 19:52:15 -04002294void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002295{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002296 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002297 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002298}
2299
Jamie Madill8dc27f92018-11-29 11:45:44 -05002300void Context::drawElementsIndirect(PrimitiveMode mode, DrawElementsType type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002301{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002302 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002303 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002304}
2305
Jamie Madill675fe712016-12-19 13:07:54 -05002306void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002307{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002308 ANGLE_CONTEXT_TRY(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002309}
2310
Jamie Madill675fe712016-12-19 13:07:54 -05002311void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002312{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002313 ANGLE_CONTEXT_TRY(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002314}
2315
Austin Kinross6ee1e782015-05-29 17:05:37 -07002316void Context::insertEventMarker(GLsizei length, const char *marker)
2317{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002318 ASSERT(mImplementation);
2319 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002320}
2321
2322void Context::pushGroupMarker(GLsizei length, const char *marker)
2323{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002324 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002325
2326 if (marker == nullptr)
2327 {
2328 // From the EXT_debug_marker spec,
2329 // "If <marker> is null then an empty string is pushed on the stack."
2330 mImplementation->pushGroupMarker(length, "");
2331 }
2332 else
2333 {
2334 mImplementation->pushGroupMarker(length, marker);
2335 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002336}
2337
2338void Context::popGroupMarker()
2339{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002340 ASSERT(mImplementation);
2341 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002342}
2343
Geoff Langd8605522016-04-13 10:19:12 -04002344void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2345{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002346 Program *programObject = getProgramResolveLink(program);
Geoff Langd8605522016-04-13 10:19:12 -04002347 ASSERT(programObject);
2348
2349 programObject->bindUniformLocation(location, name);
2350}
2351
Brandon Jones59770802018-04-02 13:18:42 -07002352void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002353{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002354 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002355}
2356
Brandon Jones59770802018-04-02 13:18:42 -07002357void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002358{
2359 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2360}
2361
Brandon Jones59770802018-04-02 13:18:42 -07002362void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002363{
2364 GLfloat I[16];
2365 angle::Matrix<GLfloat>::setToIdentity(I);
2366
2367 mGLState.loadPathRenderingMatrix(matrixMode, I);
2368}
2369
2370void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2371{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002372 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002373 if (!pathObj)
2374 return;
2375
Geoff Lang9bf86f02018-07-26 11:46:34 -04002376 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002377
2378 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2379}
2380
2381void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2382{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002383 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002384 if (!pathObj)
2385 return;
2386
Geoff Lang9bf86f02018-07-26 11:46:34 -04002387 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002388
2389 mImplementation->stencilStrokePath(pathObj, reference, mask);
2390}
2391
2392void Context::coverFillPath(GLuint path, GLenum coverMode)
2393{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002394 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002395 if (!pathObj)
2396 return;
2397
Geoff Lang9bf86f02018-07-26 11:46:34 -04002398 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002399
2400 mImplementation->coverFillPath(pathObj, coverMode);
2401}
2402
2403void Context::coverStrokePath(GLuint path, GLenum coverMode)
2404{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002405 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002406 if (!pathObj)
2407 return;
2408
Geoff Lang9bf86f02018-07-26 11:46:34 -04002409 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002410
2411 mImplementation->coverStrokePath(pathObj, coverMode);
2412}
2413
2414void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2415{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002416 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002417 if (!pathObj)
2418 return;
2419
Geoff Lang9bf86f02018-07-26 11:46:34 -04002420 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002421
2422 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2423}
2424
2425void Context::stencilThenCoverStrokePath(GLuint path,
2426 GLint reference,
2427 GLuint mask,
2428 GLenum coverMode)
2429{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002430 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002431 if (!pathObj)
2432 return;
2433
Geoff Lang9bf86f02018-07-26 11:46:34 -04002434 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002435
2436 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2437}
2438
Sami Väisänend59ca052016-06-21 16:10:00 +03002439void Context::coverFillPathInstanced(GLsizei numPaths,
2440 GLenum pathNameType,
2441 const void *paths,
2442 GLuint pathBase,
2443 GLenum coverMode,
2444 GLenum transformType,
2445 const GLfloat *transformValues)
2446{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002447 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002448
Geoff Lang9bf86f02018-07-26 11:46:34 -04002449 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002450
2451 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2452}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002453
Sami Väisänend59ca052016-06-21 16:10:00 +03002454void Context::coverStrokePathInstanced(GLsizei numPaths,
2455 GLenum pathNameType,
2456 const void *paths,
2457 GLuint pathBase,
2458 GLenum coverMode,
2459 GLenum transformType,
2460 const GLfloat *transformValues)
2461{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002462 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002463
2464 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002465 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002466
2467 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2468 transformValues);
2469}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002470
Sami Väisänend59ca052016-06-21 16:10:00 +03002471void Context::stencilFillPathInstanced(GLsizei numPaths,
2472 GLenum pathNameType,
2473 const void *paths,
2474 GLuint pathBase,
2475 GLenum fillMode,
2476 GLuint mask,
2477 GLenum transformType,
2478 const GLfloat *transformValues)
2479{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002480 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002481
2482 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002483 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002484
2485 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2486 transformValues);
2487}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002488
Sami Väisänend59ca052016-06-21 16:10:00 +03002489void Context::stencilStrokePathInstanced(GLsizei numPaths,
2490 GLenum pathNameType,
2491 const void *paths,
2492 GLuint pathBase,
2493 GLint reference,
2494 GLuint mask,
2495 GLenum transformType,
2496 const GLfloat *transformValues)
2497{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002498 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002499
Geoff Lang9bf86f02018-07-26 11:46:34 -04002500 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002501
2502 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2503 transformValues);
2504}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002505
Sami Väisänend59ca052016-06-21 16:10:00 +03002506void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2507 GLenum pathNameType,
2508 const void *paths,
2509 GLuint pathBase,
2510 GLenum fillMode,
2511 GLuint mask,
2512 GLenum coverMode,
2513 GLenum transformType,
2514 const GLfloat *transformValues)
2515{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002516 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002517
Geoff Lang9bf86f02018-07-26 11:46:34 -04002518 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002519
2520 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2521 transformType, transformValues);
2522}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002523
Sami Väisänend59ca052016-06-21 16:10:00 +03002524void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2525 GLenum pathNameType,
2526 const void *paths,
2527 GLuint pathBase,
2528 GLint reference,
2529 GLuint mask,
2530 GLenum coverMode,
2531 GLenum transformType,
2532 const GLfloat *transformValues)
2533{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002534 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002535
Geoff Lang9bf86f02018-07-26 11:46:34 -04002536 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002537
2538 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2539 transformType, transformValues);
2540}
2541
Sami Väisänen46eaa942016-06-29 10:26:37 +03002542void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2543{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002544 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002545
2546 programObject->bindFragmentInputLocation(location, name);
2547}
2548
2549void Context::programPathFragmentInputGen(GLuint program,
2550 GLint location,
2551 GLenum genMode,
2552 GLint components,
2553 const GLfloat *coeffs)
2554{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002555 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002556
jchen103fd614d2018-08-13 12:21:58 +08002557 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002558}
2559
jchen1015015f72017-03-16 13:54:21 +08002560GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2561{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002562 const Program *programObject = getProgramResolveLink(program);
jchen1015015f72017-03-16 13:54:21 +08002563 return QueryProgramResourceIndex(programObject, programInterface, name);
2564}
2565
jchen10fd7c3b52017-03-21 15:36:03 +08002566void Context::getProgramResourceName(GLuint program,
2567 GLenum programInterface,
2568 GLuint index,
2569 GLsizei bufSize,
2570 GLsizei *length,
2571 GLchar *name)
2572{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002573 const Program *programObject = getProgramResolveLink(program);
jchen10fd7c3b52017-03-21 15:36:03 +08002574 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2575}
2576
jchen10191381f2017-04-11 13:59:04 +08002577GLint Context::getProgramResourceLocation(GLuint program,
2578 GLenum programInterface,
2579 const GLchar *name)
2580{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002581 const Program *programObject = getProgramResolveLink(program);
jchen10191381f2017-04-11 13:59:04 +08002582 return QueryProgramResourceLocation(programObject, programInterface, name);
2583}
2584
jchen10880683b2017-04-12 16:21:55 +08002585void Context::getProgramResourceiv(GLuint program,
2586 GLenum programInterface,
2587 GLuint index,
2588 GLsizei propCount,
2589 const GLenum *props,
2590 GLsizei bufSize,
2591 GLsizei *length,
2592 GLint *params)
2593{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002594 const Program *programObject = getProgramResolveLink(program);
jchen10880683b2017-04-12 16:21:55 +08002595 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2596 length, params);
2597}
2598
jchen10d9cd7b72017-08-30 15:04:25 +08002599void Context::getProgramInterfaceiv(GLuint program,
2600 GLenum programInterface,
2601 GLenum pname,
2602 GLint *params)
2603{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002604 const Program *programObject = getProgramResolveLink(program);
jchen10d9cd7b72017-08-30 15:04:25 +08002605 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2606}
2607
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002608void Context::getProgramInterfaceivRobust(GLuint program,
2609 GLenum programInterface,
2610 GLenum pname,
2611 GLsizei bufSize,
2612 GLsizei *length,
2613 GLint *params)
2614{
2615 UNIMPLEMENTED();
2616}
2617
Jamie Madillabfbc0f2018-10-09 12:48:52 -04002618void Context::handleError(GLenum errorCode,
2619 const char *message,
2620 const char *file,
2621 const char *function,
2622 unsigned int line)
2623{
2624 mErrors.handleError(errorCode, message, file, function, line);
2625}
2626
Jamie Madilla139f012018-10-10 16:13:03 -04002627void Context::validationError(GLenum errorCode, const char *message)
2628{
2629 mErrors.validationError(errorCode, message);
2630}
2631
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002632// Get one of the recorded errors and clear its flag, if any.
2633// [OpenGL ES 2.0.24] section 2.5 page 13.
2634GLenum Context::getError()
2635{
Geoff Langda5777c2014-07-11 09:52:58 -04002636 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002637 {
Geoff Langda5777c2014-07-11 09:52:58 -04002638 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002639 }
Geoff Langda5777c2014-07-11 09:52:58 -04002640 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002641 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002642 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002643 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002644}
2645
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002646// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002647void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002648{
2649 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002650 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002651 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002652 mContextLostForced = true;
2653 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002654 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002655}
2656
Jamie Madillfa920eb2018-01-04 11:45:50 -05002657GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002658{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002659 // Even if the application doesn't want to know about resets, we want to know
2660 // as it will allow us to skip all the calls.
2661 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002662 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002663 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002664 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002665 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002666 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002667
2668 // EXT_robustness, section 2.6: If the reset notification behavior is
2669 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2670 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2671 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002672 }
2673
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002674 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2675 // status should be returned at least once, and GL_NO_ERROR should be returned
2676 // once the device has finished resetting.
2677 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002678 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002679 ASSERT(mResetStatus == GL_NO_ERROR);
2680 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002681
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002682 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002683 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002684 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002685 }
2686 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002687 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002688 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002689 // If markContextLost was used to mark the context lost then
2690 // assume that is not recoverable, and continue to report the
2691 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002692 mResetStatus = mImplementation->getResetStatus();
2693 }
Jamie Madill893ab082014-05-16 16:56:10 -04002694
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002695 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002696}
2697
2698bool Context::isResetNotificationEnabled()
2699{
2700 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2701}
2702
Corentin Walleze3b10e82015-05-20 11:06:25 -04002703const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002704{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002705 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002706}
2707
2708EGLenum Context::getClientType() const
2709{
2710 return mClientType;
2711}
2712
2713EGLenum Context::getRenderBuffer() const
2714{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002715 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2716 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002717 {
2718 return EGL_NONE;
2719 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002720
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002721 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002722 ASSERT(backAttachment != nullptr);
2723 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002724}
2725
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002726VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002727{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002728 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002729 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2730 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002731 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002732 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2733 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002734
Jamie Madill96a483b2017-06-27 16:49:21 -04002735 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002736 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002737
2738 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002739}
2740
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002741TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002742{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002743 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002744 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2745 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002746 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002747 transformFeedback =
2748 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002749 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002750 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002751 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002752
2753 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002754}
2755
2756bool Context::isVertexArrayGenerated(GLuint vertexArray)
2757{
Jamie Madill96a483b2017-06-27 16:49:21 -04002758 ASSERT(mVertexArrayMap.contains(0));
2759 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002760}
2761
2762bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2763{
Jamie Madill96a483b2017-06-27 16:49:21 -04002764 ASSERT(mTransformFeedbackMap.contains(0));
2765 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002766}
2767
Shannon Woods53a94a82014-06-24 15:20:36 -04002768void Context::detachTexture(GLuint texture)
2769{
2770 // Simple pass-through to State's detachTexture method, as textures do not require
2771 // allocation map management either here or in the resource manager at detach time.
2772 // Zero textures are held by the Context, and we don't attempt to request them from
2773 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002774 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002775}
2776
James Darpinian4d9d4832018-03-13 12:43:28 -07002777void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002778{
Yuly Novikov5807a532015-12-03 13:01:22 -05002779 // Simple pass-through to State's detachBuffer method, since
2780 // only buffer attachments to container objects that are bound to the current context
2781 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002782
Yuly Novikov5807a532015-12-03 13:01:22 -05002783 // [OpenGL ES 3.2] section 5.1.2 page 45:
2784 // Attachments to unbound container objects, such as
2785 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2786 // are not affected and continue to act as references on the deleted object
Geoff Lang91002262018-12-12 16:05:24 -05002787 ANGLE_CONTEXT_TRY(mGLState.detachBuffer(this, buffer));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002788}
2789
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002790void Context::detachFramebuffer(GLuint framebuffer)
2791{
Shannon Woods53a94a82014-06-24 15:20:36 -04002792 // Framebuffer detachment is handled by Context, because 0 is a valid
2793 // Framebuffer object, and a pointer to it must be passed from Context
2794 // to State at binding time.
2795
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002796 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002797 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2798 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2799 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002800
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002801 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002802 {
2803 bindReadFramebuffer(0);
2804 }
2805
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002806 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002807 {
2808 bindDrawFramebuffer(0);
2809 }
2810}
2811
2812void Context::detachRenderbuffer(GLuint renderbuffer)
2813{
Jamie Madilla02315b2017-02-23 14:14:47 -05002814 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002815}
2816
Jamie Madill57a89722013-07-02 11:57:03 -04002817void Context::detachVertexArray(GLuint vertexArray)
2818{
Jamie Madill77a72f62015-04-14 11:18:32 -04002819 // Vertex array detachment is handled by Context, because 0 is a valid
2820 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002821 // binding time.
2822
Jamie Madill57a89722013-07-02 11:57:03 -04002823 // [OpenGL ES 3.0.2] section 2.10 page 43:
2824 // If a vertex array object that is currently bound is deleted, the binding
2825 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002826 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002827 {
2828 bindVertexArray(0);
2829 }
2830}
2831
Geoff Langc8058452014-02-03 12:04:11 -05002832void Context::detachTransformFeedback(GLuint transformFeedback)
2833{
Corentin Walleza2257da2016-04-19 16:43:12 -04002834 // Transform feedback detachment is handled by Context, because 0 is a valid
2835 // transform feedback, and a pointer to it must be passed from Context to State at
2836 // binding time.
2837
2838 // The OpenGL specification doesn't mention what should happen when the currently bound
2839 // transform feedback object is deleted. Since it is a container object, we treat it like
2840 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002841 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002842 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002843 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002844 }
Geoff Langc8058452014-02-03 12:04:11 -05002845}
2846
Jamie Madilldc356042013-07-19 16:36:57 -04002847void Context::detachSampler(GLuint sampler)
2848{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002849 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002850}
2851
Yunchao Hea336b902017-08-02 16:05:21 +08002852void Context::detachProgramPipeline(GLuint pipeline)
2853{
2854 mGLState.detachProgramPipeline(this, pipeline);
2855}
2856
Jamie Madill3ef140a2017-08-26 23:11:21 -04002857void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002858{
Shaodde78e82017-05-22 14:13:27 +08002859 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002860 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002861}
2862
Jamie Madille29d1672013-07-19 16:36:57 -04002863void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2864{
Till Rathmannb8543632018-10-02 19:46:14 +02002865 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002866 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002867 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002868}
Jamie Madille29d1672013-07-19 16:36:57 -04002869
Geoff Langc1984ed2016-10-07 12:41:00 -04002870void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2871{
Till Rathmannb8543632018-10-02 19:46:14 +02002872 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002873 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002874 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002875}
2876
Till Rathmannb8543632018-10-02 19:46:14 +02002877void Context::samplerParameterIiv(GLuint sampler, GLenum pname, const GLint *param)
2878{
2879 Sampler *const samplerObject =
2880 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2881 SetSamplerParameterIiv(this, samplerObject, pname, param);
2882}
2883
2884void Context::samplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *param)
2885{
2886 Sampler *const samplerObject =
2887 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2888 SetSamplerParameterIuiv(this, samplerObject, pname, param);
2889}
2890
Brandon Jones59770802018-04-02 13:18:42 -07002891void Context::samplerParameterivRobust(GLuint sampler,
2892 GLenum pname,
2893 GLsizei bufSize,
2894 const GLint *param)
2895{
2896 samplerParameteriv(sampler, pname, param);
2897}
2898
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002899void Context::samplerParameterIivRobust(GLuint sampler,
2900 GLenum pname,
2901 GLsizei bufSize,
2902 const GLint *param)
2903{
2904 UNIMPLEMENTED();
2905}
2906
2907void Context::samplerParameterIuivRobust(GLuint sampler,
2908 GLenum pname,
2909 GLsizei bufSize,
2910 const GLuint *param)
2911{
2912 UNIMPLEMENTED();
2913}
2914
Jamie Madille29d1672013-07-19 16:36:57 -04002915void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2916{
Till Rathmannb8543632018-10-02 19:46:14 +02002917 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002918 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002919 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002920}
2921
Geoff Langc1984ed2016-10-07 12:41:00 -04002922void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002923{
Till Rathmannb8543632018-10-02 19:46:14 +02002924 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002925 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002926 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002927}
2928
Brandon Jones59770802018-04-02 13:18:42 -07002929void Context::samplerParameterfvRobust(GLuint sampler,
2930 GLenum pname,
2931 GLsizei bufSize,
2932 const GLfloat *param)
2933{
2934 samplerParameterfv(sampler, pname, param);
2935}
2936
Geoff Langc1984ed2016-10-07 12:41:00 -04002937void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002938{
Till Rathmannb8543632018-10-02 19:46:14 +02002939 const Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002940 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002941 QuerySamplerParameteriv(samplerObject, pname, params);
2942}
Jamie Madill9675b802013-07-19 16:36:59 -04002943
Till Rathmannb8543632018-10-02 19:46:14 +02002944void Context::getSamplerParameterIiv(GLuint sampler, GLenum pname, GLint *params)
2945{
2946 const Sampler *const samplerObject =
2947 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2948 QuerySamplerParameterIiv(samplerObject, pname, params);
2949}
2950
2951void Context::getSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint *params)
2952{
2953 const Sampler *const samplerObject =
2954 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2955 QuerySamplerParameterIuiv(samplerObject, pname, params);
2956}
2957
Brandon Jones59770802018-04-02 13:18:42 -07002958void Context::getSamplerParameterivRobust(GLuint sampler,
2959 GLenum pname,
2960 GLsizei bufSize,
2961 GLsizei *length,
2962 GLint *params)
2963{
2964 getSamplerParameteriv(sampler, pname, params);
2965}
2966
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002967void Context::getSamplerParameterIivRobust(GLuint sampler,
2968 GLenum pname,
2969 GLsizei bufSize,
2970 GLsizei *length,
2971 GLint *params)
2972{
2973 UNIMPLEMENTED();
2974}
2975
2976void Context::getSamplerParameterIuivRobust(GLuint sampler,
2977 GLenum pname,
2978 GLsizei bufSize,
2979 GLsizei *length,
2980 GLuint *params)
2981{
2982 UNIMPLEMENTED();
2983}
2984
Geoff Langc1984ed2016-10-07 12:41:00 -04002985void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2986{
Till Rathmannb8543632018-10-02 19:46:14 +02002987 const Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002988 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002989 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002990}
2991
Brandon Jones59770802018-04-02 13:18:42 -07002992void Context::getSamplerParameterfvRobust(GLuint sampler,
2993 GLenum pname,
2994 GLsizei bufSize,
2995 GLsizei *length,
2996 GLfloat *params)
2997{
2998 getSamplerParameterfv(sampler, pname, params);
2999}
3000
Olli Etuahof0fee072016-03-30 15:11:58 +03003001void Context::programParameteri(GLuint program, GLenum pname, GLint value)
3002{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04003003 gl::Program *programObject = getProgramResolveLink(program);
Yunchao He61afff12017-03-14 15:34:03 +08003004 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03003005}
3006
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003007void Context::initRendererString()
3008{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00003009 std::ostringstream rendererString;
3010 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003011 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00003012 rendererString << ")";
3013
Geoff Langcec35902014-04-16 10:52:36 -04003014 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003015}
3016
Geoff Langc339c4e2016-11-29 10:37:36 -05003017void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003018{
Geoff Langc339c4e2016-11-29 10:37:36 -05003019 const Version &clientVersion = getClientVersion();
3020
3021 std::ostringstream versionString;
3022 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
3023 << ANGLE_VERSION_STRING << ")";
3024 mVersionString = MakeStaticString(versionString.str());
3025
3026 std::ostringstream shadingLanguageVersionString;
3027 shadingLanguageVersionString << "OpenGL ES GLSL ES "
3028 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
3029 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
3030 << ")";
3031 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003032}
3033
Geoff Langcec35902014-04-16 10:52:36 -04003034void Context::initExtensionStrings()
3035{
Geoff Langc339c4e2016-11-29 10:37:36 -05003036 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
3037 std::ostringstream combinedStringStream;
3038 std::copy(strings.begin(), strings.end(),
3039 std::ostream_iterator<const char *>(combinedStringStream, " "));
3040 return MakeStaticString(combinedStringStream.str());
3041 };
3042
3043 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003044 for (const auto &extensionString : mExtensions.getStrings())
3045 {
3046 mExtensionStrings.push_back(MakeStaticString(extensionString));
3047 }
Geoff Langc339c4e2016-11-29 10:37:36 -05003048 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003049
Geoff Langc339c4e2016-11-29 10:37:36 -05003050 mRequestableExtensionStrings.clear();
3051 for (const auto &extensionInfo : GetExtensionInfoMap())
3052 {
3053 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003054 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003055 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003056 {
3057 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3058 }
3059 }
3060 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003061}
3062
Geoff Langc339c4e2016-11-29 10:37:36 -05003063const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003064{
Geoff Langc339c4e2016-11-29 10:37:36 -05003065 switch (name)
3066 {
3067 case GL_VENDOR:
3068 return reinterpret_cast<const GLubyte *>("Google Inc.");
3069
3070 case GL_RENDERER:
3071 return reinterpret_cast<const GLubyte *>(mRendererString);
3072
3073 case GL_VERSION:
3074 return reinterpret_cast<const GLubyte *>(mVersionString);
3075
3076 case GL_SHADING_LANGUAGE_VERSION:
3077 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3078
3079 case GL_EXTENSIONS:
3080 return reinterpret_cast<const GLubyte *>(mExtensionString);
3081
3082 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3083 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3084
3085 default:
3086 UNREACHABLE();
3087 return nullptr;
3088 }
Geoff Langcec35902014-04-16 10:52:36 -04003089}
3090
Geoff Langc339c4e2016-11-29 10:37:36 -05003091const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003092{
Geoff Langc339c4e2016-11-29 10:37:36 -05003093 switch (name)
3094 {
3095 case GL_EXTENSIONS:
3096 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3097
3098 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3099 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3100
3101 default:
3102 UNREACHABLE();
3103 return nullptr;
3104 }
Geoff Langcec35902014-04-16 10:52:36 -04003105}
3106
3107size_t Context::getExtensionStringCount() const
3108{
3109 return mExtensionStrings.size();
3110}
3111
Geoff Lang111a99e2017-10-17 10:58:41 -04003112bool Context::isExtensionRequestable(const char *name)
3113{
3114 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3115 auto extension = extensionInfos.find(name);
3116
Geoff Lang111a99e2017-10-17 10:58:41 -04003117 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003118 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003119}
3120
Geoff Langc339c4e2016-11-29 10:37:36 -05003121void Context::requestExtension(const char *name)
3122{
3123 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3124 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3125 const auto &extension = extensionInfos.at(name);
3126 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003127 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003128
3129 if (mExtensions.*(extension.ExtensionsMember))
3130 {
3131 // Extension already enabled
3132 return;
3133 }
3134
3135 mExtensions.*(extension.ExtensionsMember) = true;
3136 updateCaps();
3137 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003138
Jamie Madill2f348d22017-06-05 10:50:59 -04003139 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3140 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003141
Jamie Madill81c2e252017-09-09 23:32:46 -04003142 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3143 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003144 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003145 for (auto &zeroTexture : mZeroTextures)
3146 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003147 if (zeroTexture.get() != nullptr)
3148 {
Jamie Madille3e680c2018-12-03 17:49:08 -05003149 zeroTexture->signalDirtyStorage(this, InitState::Initialized);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003150 }
Geoff Lang9aded172017-04-05 11:07:56 -04003151 }
3152
Jamie Madillb983a4b2018-08-01 11:34:51 -04003153 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003154}
3155
3156size_t Context::getRequestableExtensionStringCount() const
3157{
3158 return mRequestableExtensionStrings.size();
3159}
3160
Jamie Madill493f9572018-05-24 19:52:15 -04003161void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003162{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003163 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003164 ASSERT(transformFeedback != nullptr);
3165 ASSERT(!transformFeedback->isPaused());
3166
Geoff Lang91002262018-12-12 16:05:24 -05003167 ANGLE_CONTEXT_TRY(transformFeedback->begin(this, primitiveMode, mGLState.getProgram()));
Jamie Madill3a256222018-12-08 09:56:39 -05003168 mStateCache.onActiveTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003169}
3170
3171bool Context::hasActiveTransformFeedback(GLuint program) const
3172{
3173 for (auto pair : mTransformFeedbackMap)
3174 {
3175 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3176 {
3177 return true;
3178 }
3179 }
3180 return false;
3181}
3182
Geoff Lang33f11fb2018-05-07 13:42:47 -04003183Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003184{
3185 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3186
jchen1082af6202018-06-22 10:59:52 +08003187 // Explicitly enable GL_KHR_parallel_shader_compile
3188 supportedExtensions.parallelShaderCompile = true;
3189
Geoff Langb0f917f2017-12-05 13:41:54 -05003190 if (getClientVersion() < ES_2_0)
3191 {
3192 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003193 supportedExtensions.pointSizeArray = true;
3194 supportedExtensions.textureCubeMap = true;
3195 supportedExtensions.pointSprite = true;
3196 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003197 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003198 }
3199
3200 if (getClientVersion() < ES_3_0)
3201 {
3202 // Disable ES3+ extensions
3203 supportedExtensions.colorBufferFloat = false;
3204 supportedExtensions.eglImageExternalEssl3 = false;
3205 supportedExtensions.textureNorm16 = false;
3206 supportedExtensions.multiview = false;
3207 supportedExtensions.maxViews = 1u;
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07003208 supportedExtensions.copyTexture3d = false;
Yizhou Jiang7818a852018-09-06 15:02:04 +08003209 supportedExtensions.textureMultisample = false;
Geoff Lang7198ebc2018-11-22 14:36:06 -05003210
3211 // Don't expose GL_EXT_texture_sRGB_decode without sRGB texture support
3212 if (!supportedExtensions.sRGB)
3213 {
3214 supportedExtensions.textureSRGBDecode = false;
3215 }
Geoff Langb0f917f2017-12-05 13:41:54 -05003216 }
3217
3218 if (getClientVersion() < ES_3_1)
3219 {
3220 // Disable ES3.1+ extensions
3221 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003222
3223 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3224 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003225 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003226 }
3227
3228 if (getClientVersion() > ES_2_0)
3229 {
3230 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3231 // supportedExtensions.sRGB = false;
3232 }
3233
3234 // Some extensions are always available because they are implemented in the GL layer.
3235 supportedExtensions.bindUniformLocation = true;
3236 supportedExtensions.vertexArrayObject = true;
3237 supportedExtensions.bindGeneratesResource = true;
3238 supportedExtensions.clientArrays = true;
3239 supportedExtensions.requestExtension = true;
Austin Eng7cf9cd22018-10-09 15:27:32 -07003240 supportedExtensions.multiDraw = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003241
3242 // Enable the no error extension if the context was created with the flag.
3243 supportedExtensions.noError = mSkipValidation;
3244
3245 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003246 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003247
3248 // Explicitly enable GL_KHR_debug
3249 supportedExtensions.debug = true;
3250 supportedExtensions.maxDebugMessageLength = 1024;
3251 supportedExtensions.maxDebugLoggedMessages = 1024;
3252 supportedExtensions.maxDebugGroupStackDepth = 1024;
3253 supportedExtensions.maxLabelLength = 1024;
3254
3255 // Explicitly enable GL_ANGLE_robust_client_memory
3256 supportedExtensions.robustClientMemory = true;
3257
3258 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003259 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003260
3261 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3262 // supports it.
3263 supportedExtensions.robustBufferAccessBehavior =
3264 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3265
3266 // Enable the cache control query unconditionally.
3267 supportedExtensions.programCacheControl = true;
3268
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003269 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003270 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003271 {
3272 // GL_ANGLE_explicit_context_gles1
3273 supportedExtensions.explicitContextGles1 = true;
3274 // GL_ANGLE_explicit_context
3275 supportedExtensions.explicitContext = true;
3276 }
3277
Geoff Lang79b91402018-10-04 15:11:30 -04003278 supportedExtensions.memorySize = true;
3279
Geoff Langb0f917f2017-12-05 13:41:54 -05003280 return supportedExtensions;
3281}
3282
Geoff Lang33f11fb2018-05-07 13:42:47 -04003283void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003284{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003285 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003286
Geoff Lang33f11fb2018-05-07 13:42:47 -04003287 mSupportedExtensions = generateSupportedExtensions();
3288 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003289
3290 mLimitations = mImplementation->getNativeLimitations();
3291
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003292 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3293 if (getClientVersion() < Version(2, 0))
3294 {
3295 mCaps.maxMultitextureUnits = 4;
3296 mCaps.maxClipPlanes = 6;
3297 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003298 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3299 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3300 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003301 mCaps.minSmoothPointSize = 1.0f;
3302 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003303 mCaps.minSmoothLineWidth = 1.0f;
3304 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003305 }
3306
Luc Ferronad2ae932018-06-11 15:31:17 -04003307 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003308 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003309
Luc Ferronad2ae932018-06-11 15:31:17 -04003310 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3311
Jamie Madill0f80ed82017-09-19 00:24:56 -04003312 if (getClientVersion() < ES_3_1)
3313 {
3314 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3315 }
3316 else
3317 {
3318 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3319 }
Geoff Lang301d1612014-07-09 10:34:37 -04003320
Jiawei Shao54aafe52018-04-27 14:54:57 +08003321 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3322 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003323 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3324
Jamie Madill0f80ed82017-09-19 00:24:56 -04003325 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3326 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3327
3328 // Limit textures as well, so we can use fast bitsets with texture bindings.
3329 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003330 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3331 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3332 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3333 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003334
Jamie Madille3e680c2018-12-03 17:49:08 -05003335 LimitCap(&mCaps.maxImageUnits, IMPLEMENTATION_MAX_IMAGE_UNITS);
3336
Jiawei Shaodb342272017-09-27 10:21:45 +08003337 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3338
Geoff Langc287ea62016-09-16 14:46:51 -04003339 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003340 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003341 for (const auto &extensionInfo : GetExtensionInfoMap())
3342 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003343 // If the user has requested that extensions start disabled and they are requestable,
3344 // disable them.
3345 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003346 {
3347 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3348 }
3349 }
3350
3351 // Generate texture caps
3352 updateCaps();
3353}
3354
3355void Context::updateCaps()
3356{
Geoff Lang900013c2014-07-07 11:32:19 -04003357 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003358 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003359
Jamie Madill7b62cf92017-11-02 15:20:49 -04003360 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003361 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003362 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003363 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003364
Geoff Lang0d8b7242015-09-09 14:56:53 -04003365 // Update the format caps based on the client version and extensions.
3366 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3367 // ES3.
3368 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003369 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003370 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003371 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003372 formatCaps.textureAttachment =
3373 formatCaps.textureAttachment &&
3374 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3375 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3376 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003377
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003378 // OpenGL ES does not support multisampling with non-rendererable formats
3379 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003380 if (!formatCaps.renderbuffer ||
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003381 (getClientVersion() < ES_3_1 && !mSupportedExtensions.textureMultisample &&
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003382 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003383 {
Geoff Langd87878e2014-09-19 15:42:59 -04003384 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003385 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003386 else
3387 {
3388 // We may have limited the max samples for some required renderbuffer formats due to
3389 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3390 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3391
3392 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3393 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3394 // exception of signed and unsigned integer formats."
3395 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3396 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3397 {
3398 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3399 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3400 }
3401
3402 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003403 if (getClientVersion() >= ES_3_1 || mSupportedExtensions.textureMultisample)
Olli Etuaho50c562d2017-06-06 14:43:30 +03003404 {
3405 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3406 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3407 // the exception that the signed and unsigned integer formats are required only to
3408 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3409 // multisamples, which must be at least one."
3410 if (formatInfo.componentType == GL_INT ||
3411 formatInfo.componentType == GL_UNSIGNED_INT)
3412 {
3413 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3414 }
3415
3416 // GLES 3.1 section 19.3.1.
3417 if (formatCaps.texturable)
3418 {
3419 if (formatInfo.depthBits > 0)
3420 {
3421 mCaps.maxDepthTextureSamples =
3422 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3423 }
3424 else if (formatInfo.redBits > 0)
3425 {
3426 mCaps.maxColorTextureSamples =
3427 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3428 }
3429 }
3430 }
3431 }
Geoff Langd87878e2014-09-19 15:42:59 -04003432
3433 if (formatCaps.texturable && formatInfo.compressed)
3434 {
Geoff Langca271392017-04-05 12:30:00 -04003435 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003436 }
3437
Geoff Langca271392017-04-05 12:30:00 -04003438 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003439 }
Jamie Madill32447362017-06-28 14:53:52 -04003440
3441 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003442 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003443 {
3444 mMemoryProgramCache = nullptr;
3445 }
Corentin Walleze4477002017-12-01 14:39:58 -05003446
3447 // Compute which buffer types are allowed
3448 mValidBufferBindings.reset();
3449 mValidBufferBindings.set(BufferBinding::ElementArray);
3450 mValidBufferBindings.set(BufferBinding::Array);
3451
3452 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3453 {
3454 mValidBufferBindings.set(BufferBinding::PixelPack);
3455 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3456 }
3457
3458 if (getClientVersion() >= ES_3_0)
3459 {
3460 mValidBufferBindings.set(BufferBinding::CopyRead);
3461 mValidBufferBindings.set(BufferBinding::CopyWrite);
3462 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3463 mValidBufferBindings.set(BufferBinding::Uniform);
3464 }
3465
3466 if (getClientVersion() >= ES_3_1)
3467 {
3468 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3469 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3470 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3471 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3472 }
jchen107ae70d82018-07-06 13:47:01 +08003473
3474 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Jamie Madillac66f982018-10-09 18:30:01 -04003475
Jamie Madillef9fcd92018-11-28 14:03:59 -05003476 // Reinitialize some dirty bits that depend on extensions.
Jamie Madill132d15c2018-11-30 15:25:38 -05003477 bool robustInit = mGLState.isRobustResourceInitEnabled();
3478 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3479 mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3480 mDrawDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
3481 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3482 mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3483 mComputeDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
Jamie Madillef9fcd92018-11-28 14:03:59 -05003484
Jamie Madillac66f982018-10-09 18:30:01 -04003485 // Reinitialize state cache after extension changes.
3486 mStateCache.initialize(this);
Geoff Lang493daf52014-07-03 13:38:44 -04003487}
3488
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003489void Context::initWorkarounds()
3490{
Jamie Madill761b02c2017-06-23 16:27:06 -04003491 // Apply back-end workarounds.
3492 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3493
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003494 // Lose the context upon out of memory error if the application is
3495 // expecting to watch for those events.
3496 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
Jamie Madilld4f07762018-10-19 19:24:07 -04003497
3498 if (mWorkarounds.syncFramebufferBindingsOnTexImage)
3499 {
3500 // Update the Framebuffer bindings on TexImage to work around an Intel bug.
3501 mTexImageDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
3502 mTexImageDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
3503 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003504}
3505
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003506// Return true if the draw is a no-op, else return false.
3507// A no-op draw occurs if the count of vertices is less than the minimum required to
3508// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3509bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3510{
3511 return count < kMinimumPrimitiveCounts[mode];
3512}
3513
3514bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3515{
3516 return (instanceCount == 0) || noopDraw(mode, count);
3517}
3518
Jamie Madill132d15c2018-11-30 15:25:38 -05003519ANGLE_INLINE angle::Result Context::syncDirtyBits()
3520{
3521 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3522 ANGLE_TRY(mImplementation->syncState(this, dirtyBits, mAllDirtyBits));
3523 mGLState.clearDirtyBits();
Jamie Madill7c985f52018-11-29 18:16:17 -05003524 return angle::Result::Continue;
Jamie Madill132d15c2018-11-30 15:25:38 -05003525}
3526
3527ANGLE_INLINE angle::Result Context::syncDirtyBits(const State::DirtyBits &bitMask)
3528{
3529 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
3530 ANGLE_TRY(mImplementation->syncState(this, dirtyBits, bitMask));
3531 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill7c985f52018-11-29 18:16:17 -05003532 return angle::Result::Continue;
Jamie Madill132d15c2018-11-30 15:25:38 -05003533}
3534
3535ANGLE_INLINE angle::Result Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
3536{
3537 return mGLState.syncDirtyObjects(this, objectMask);
3538}
3539
3540ANGLE_INLINE angle::Result Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003541{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003542 if (mGLES1Renderer)
3543 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003544 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003545 }
3546
Geoff Lang9bf86f02018-07-26 11:46:34 -04003547 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madill132d15c2018-11-30 15:25:38 -05003548 ASSERT(!isRobustResourceInitEnabled() ||
3549 !mGLState.getDrawFramebuffer()->hasResourceThatNeedsInit());
3550 return syncDirtyBits();
Geoff Langd4fff502017-09-22 11:28:28 -04003551}
3552
Jamie Madill526392d2018-11-16 09:35:14 -05003553angle::Result Context::prepareForClear(GLbitfield mask)
Geoff Langd4fff502017-09-22 11:28:28 -04003554{
Geoff Langa8cb2872018-03-09 16:09:40 -05003555 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003556 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003557 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003558 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003559}
3560
Jamie Madill526392d2018-11-16 09:35:14 -05003561angle::Result Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
Geoff Langd4fff502017-09-22 11:28:28 -04003562{
Geoff Langa8cb2872018-03-09 16:09:40 -05003563 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003564 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3565 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003566 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003567 return angle::Result::Continue;
Jamie Madill05b35b22017-10-03 09:01:44 -04003568}
3569
Jamie Madill132d15c2018-11-30 15:25:38 -05003570ANGLE_INLINE angle::Result Context::prepareForDispatch()
3571{
3572 ANGLE_TRY(syncDirtyObjects(mComputeDirtyObjects));
3573 return syncDirtyBits(mComputeDirtyBits);
3574}
3575
Jamie Madill526392d2018-11-16 09:35:14 -05003576angle::Result Context::syncState(const State::DirtyBits &bitMask,
3577 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003578{
Geoff Langa8cb2872018-03-09 16:09:40 -05003579 ANGLE_TRY(syncDirtyObjects(objectMask));
3580 ANGLE_TRY(syncDirtyBits(bitMask));
Jamie Madill7c985f52018-11-29 18:16:17 -05003581 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003582}
3583
Jamie Madillc29968b2016-01-20 11:17:23 -05003584void Context::blitFramebuffer(GLint srcX0,
3585 GLint srcY0,
3586 GLint srcX1,
3587 GLint srcY1,
3588 GLint dstX0,
3589 GLint dstY0,
3590 GLint dstX1,
3591 GLint dstY1,
3592 GLbitfield mask,
3593 GLenum filter)
3594{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003595 if (mask == 0)
3596 {
3597 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3598 // buffers are copied.
3599 return;
3600 }
3601
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003602 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003603 ASSERT(drawFramebuffer);
3604
3605 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3606 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3607
Jamie Madillbc918e72018-03-08 09:47:21 -05003608 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003609
Jamie Madill4f6592f2018-11-27 16:37:45 -05003610 ANGLE_CONTEXT_TRY(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003611}
Jamie Madillc29968b2016-01-20 11:17:23 -05003612
3613void Context::clear(GLbitfield mask)
3614{
Geoff Langd4fff502017-09-22 11:28:28 -04003615 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3616 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003617}
3618
3619void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3620{
Olli Etuaho78df3362018-10-05 16:43:27 +03003621 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3622 const FramebufferAttachment *attachment = nullptr;
3623 if (buffer == GL_DEPTH)
3624 {
3625 attachment = framebufferObject->getDepthbuffer();
3626 }
3627 if (buffer == GL_COLOR &&
3628 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3629 {
3630 attachment = framebufferObject->getColorbuffer(drawbuffer);
3631 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003632 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3633 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003634 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003635 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003636 return;
3637 }
Geoff Langd4fff502017-09-22 11:28:28 -04003638 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003639 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003640}
3641
3642void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3643{
Olli Etuaho78df3362018-10-05 16:43:27 +03003644 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3645 const FramebufferAttachment *attachment = nullptr;
3646 if (buffer == GL_COLOR &&
3647 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3648 {
3649 attachment = framebufferObject->getColorbuffer(drawbuffer);
3650 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003651 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3652 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003653 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003654 {
3655 return;
3656 }
Geoff Langd4fff502017-09-22 11:28:28 -04003657 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003658 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003659}
3660
3661void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3662{
Olli Etuaho78df3362018-10-05 16:43:27 +03003663 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3664 const FramebufferAttachment *attachment = nullptr;
3665 if (buffer == GL_STENCIL)
3666 {
3667 attachment = framebufferObject->getStencilbuffer();
3668 }
3669 if (buffer == GL_COLOR &&
3670 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3671 {
3672 attachment = framebufferObject->getColorbuffer(drawbuffer);
3673 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003674 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3675 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003676 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003677 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003678 return;
3679 }
Geoff Langd4fff502017-09-22 11:28:28 -04003680 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003681 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003682}
3683
3684void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3685{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003686 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003687 ASSERT(framebufferObject);
3688
3689 // If a buffer is not present, the clear has no effect
3690 if (framebufferObject->getDepthbuffer() == nullptr &&
3691 framebufferObject->getStencilbuffer() == nullptr)
3692 {
3693 return;
3694 }
3695
Geoff Langd4fff502017-09-22 11:28:28 -04003696 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3697 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003698}
3699
3700void Context::readPixels(GLint x,
3701 GLint y,
3702 GLsizei width,
3703 GLsizei height,
3704 GLenum format,
3705 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003706 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003707{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003708 if (width == 0 || height == 0)
3709 {
3710 return;
3711 }
3712
Jamie Madillbc918e72018-03-08 09:47:21 -05003713 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003714
Jamie Madillb6664922017-07-25 12:55:04 -04003715 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3716 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003717
3718 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003719 ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003720}
3721
Brandon Jones59770802018-04-02 13:18:42 -07003722void Context::readPixelsRobust(GLint x,
3723 GLint y,
3724 GLsizei width,
3725 GLsizei height,
3726 GLenum format,
3727 GLenum type,
3728 GLsizei bufSize,
3729 GLsizei *length,
3730 GLsizei *columns,
3731 GLsizei *rows,
3732 void *pixels)
3733{
3734 readPixels(x, y, width, height, format, type, pixels);
3735}
3736
3737void Context::readnPixelsRobust(GLint x,
3738 GLint y,
3739 GLsizei width,
3740 GLsizei height,
3741 GLenum format,
3742 GLenum type,
3743 GLsizei bufSize,
3744 GLsizei *length,
3745 GLsizei *columns,
3746 GLsizei *rows,
3747 void *data)
3748{
3749 readPixels(x, y, width, height, format, type, data);
3750}
3751
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003752void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003753 GLint level,
3754 GLenum internalformat,
3755 GLint x,
3756 GLint y,
3757 GLsizei width,
3758 GLsizei height,
3759 GLint border)
3760{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003761 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003762 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003763
Jamie Madillc29968b2016-01-20 11:17:23 -05003764 Rectangle sourceArea(x, y, width, height);
3765
Jamie Madill05b35b22017-10-03 09:01:44 -04003766 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003767 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003768 ANGLE_CONTEXT_TRY(
3769 texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003770}
3771
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003772void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003773 GLint level,
3774 GLint xoffset,
3775 GLint yoffset,
3776 GLint x,
3777 GLint y,
3778 GLsizei width,
3779 GLsizei height)
3780{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003781 if (width == 0 || height == 0)
3782 {
3783 return;
3784 }
3785
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003786 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003787 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003788
Jamie Madillc29968b2016-01-20 11:17:23 -05003789 Offset destOffset(xoffset, yoffset, 0);
3790 Rectangle sourceArea(x, y, width, height);
3791
Jamie Madill05b35b22017-10-03 09:01:44 -04003792 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003793 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003794 ANGLE_CONTEXT_TRY(
3795 texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003796}
3797
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003798void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003799 GLint level,
3800 GLint xoffset,
3801 GLint yoffset,
3802 GLint zoffset,
3803 GLint x,
3804 GLint y,
3805 GLsizei width,
3806 GLsizei height)
3807{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003808 if (width == 0 || height == 0)
3809 {
3810 return;
3811 }
3812
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003813 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003814 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003815
Jamie Madillc29968b2016-01-20 11:17:23 -05003816 Offset destOffset(xoffset, yoffset, zoffset);
3817 Rectangle sourceArea(x, y, width, height);
3818
Jamie Madill05b35b22017-10-03 09:01:44 -04003819 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3820 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003821 ANGLE_CONTEXT_TRY(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level,
3822 destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003823}
3824
3825void Context::framebufferTexture2D(GLenum target,
3826 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003827 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003828 GLuint texture,
3829 GLint level)
3830{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003831 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003832 ASSERT(framebuffer);
3833
3834 if (texture != 0)
3835 {
3836 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003837 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003838 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003839 }
3840 else
3841 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003842 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003843 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003844
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003845 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003846}
3847
3848void Context::framebufferRenderbuffer(GLenum target,
3849 GLenum attachment,
3850 GLenum renderbuffertarget,
3851 GLuint renderbuffer)
3852{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003853 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003854 ASSERT(framebuffer);
3855
3856 if (renderbuffer != 0)
3857 {
3858 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003859
Jamie Madillcc129372018-04-12 09:13:18 -04003860 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003861 renderbufferObject);
3862 }
3863 else
3864 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003865 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003866 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003867
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003868 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003869}
3870
3871void Context::framebufferTextureLayer(GLenum target,
3872 GLenum attachment,
3873 GLuint texture,
3874 GLint level,
3875 GLint layer)
3876{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003877 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003878 ASSERT(framebuffer);
3879
3880 if (texture != 0)
3881 {
3882 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003883 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003884 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003885 }
3886 else
3887 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003888 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003889 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003890
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003891 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003892}
3893
Brandon Jones59770802018-04-02 13:18:42 -07003894void Context::framebufferTextureMultiviewLayered(GLenum target,
3895 GLenum attachment,
3896 GLuint texture,
3897 GLint level,
3898 GLint baseViewIndex,
3899 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003900{
Martin Radev82ef7742017-08-08 17:44:58 +03003901 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3902 ASSERT(framebuffer);
3903
3904 if (texture != 0)
3905 {
3906 Texture *textureObj = getTexture(texture);
3907
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003908 ImageIndex index;
3909 if (textureObj->getType() == TextureType::_2DArray)
3910 {
3911 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3912 }
3913 else
3914 {
3915 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3916 ASSERT(level == 0);
3917 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3918 }
Martin Radev82ef7742017-08-08 17:44:58 +03003919 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3920 numViews, baseViewIndex);
3921 }
3922 else
3923 {
3924 framebuffer->resetAttachment(this, attachment);
3925 }
3926
3927 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003928}
3929
Brandon Jones59770802018-04-02 13:18:42 -07003930void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3931 GLenum attachment,
3932 GLuint texture,
3933 GLint level,
3934 GLsizei numViews,
3935 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003936{
Martin Radev5dae57b2017-07-14 16:15:55 +03003937 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3938 ASSERT(framebuffer);
3939
3940 if (texture != 0)
3941 {
3942 Texture *textureObj = getTexture(texture);
3943
3944 ImageIndex index = ImageIndex::Make2D(level);
3945 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3946 textureObj, numViews, viewportOffsets);
3947 }
3948 else
3949 {
3950 framebuffer->resetAttachment(this, attachment);
3951 }
3952
3953 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003954}
3955
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003956void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3957{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003958 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3959 ASSERT(framebuffer);
3960
3961 if (texture != 0)
3962 {
3963 Texture *textureObj = getTexture(texture);
3964
3965 ImageIndex index = ImageIndex::MakeFromType(
3966 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3967 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3968 }
3969 else
3970 {
3971 framebuffer->resetAttachment(this, attachment);
3972 }
3973
3974 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003975}
3976
Jamie Madillc29968b2016-01-20 11:17:23 -05003977void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3978{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003979 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003980 ASSERT(framebuffer);
3981 framebuffer->setDrawBuffers(n, bufs);
Jamie Madillef9fcd92018-11-28 14:03:59 -05003982 mGLState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04003983 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003984}
3985
3986void Context::readBuffer(GLenum mode)
3987{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003988 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003989 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003990 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003991}
3992
3993void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3994{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003995 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003996 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003997
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003998 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003999 ASSERT(framebuffer);
4000
4001 // The specification isn't clear what should be done when the framebuffer isn't complete.
4002 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4f6592f2018-11-27 16:37:45 -05004003 ANGLE_CONTEXT_TRY(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05004004}
4005
4006void Context::invalidateFramebuffer(GLenum target,
4007 GLsizei numAttachments,
4008 const GLenum *attachments)
4009{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004010 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05004011 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004012
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004013 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05004014 ASSERT(framebuffer);
4015
Jamie Madill427064d2018-04-13 16:20:34 -04004016 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05004017 {
Jamie Madill437fa652016-05-03 15:13:24 -04004018 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05004019 }
Jamie Madill437fa652016-05-03 15:13:24 -04004020
Jamie Madill4f6592f2018-11-27 16:37:45 -05004021 ANGLE_CONTEXT_TRY(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05004022}
4023
4024void Context::invalidateSubFramebuffer(GLenum target,
4025 GLsizei numAttachments,
4026 const GLenum *attachments,
4027 GLint x,
4028 GLint y,
4029 GLsizei width,
4030 GLsizei height)
4031{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004032 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05004033 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004034
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004035 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05004036 ASSERT(framebuffer);
4037
Jamie Madill427064d2018-04-13 16:20:34 -04004038 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05004039 {
Jamie Madill437fa652016-05-03 15:13:24 -04004040 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05004041 }
Jamie Madill437fa652016-05-03 15:13:24 -04004042
4043 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004044 ANGLE_CONTEXT_TRY(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05004045}
4046
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004047void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004048 GLint level,
4049 GLint internalformat,
4050 GLsizei width,
4051 GLsizei height,
4052 GLint border,
4053 GLenum format,
4054 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004055 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004056{
Jamie Madillbc918e72018-03-08 09:47:21 -05004057 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004058
4059 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004060 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004061 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(), target, level,
4062 internalformat, size, format, type,
4063 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004064}
4065
Brandon Jones59770802018-04-02 13:18:42 -07004066void Context::texImage2DRobust(TextureTarget target,
4067 GLint level,
4068 GLint internalformat,
4069 GLsizei width,
4070 GLsizei height,
4071 GLint border,
4072 GLenum format,
4073 GLenum type,
4074 GLsizei bufSize,
4075 const void *pixels)
4076{
4077 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
4078}
4079
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004080void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004081 GLint level,
4082 GLint internalformat,
4083 GLsizei width,
4084 GLsizei height,
4085 GLsizei depth,
4086 GLint border,
4087 GLenum format,
4088 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004089 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004090{
Jamie Madillbc918e72018-03-08 09:47:21 -05004091 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004092
4093 Extents size(width, height, depth);
4094 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004095 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(),
4096 NonCubeTextureTypeToTarget(target), level, internalformat,
4097 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004098}
4099
Brandon Jones59770802018-04-02 13:18:42 -07004100void Context::texImage3DRobust(TextureType target,
4101 GLint level,
4102 GLint internalformat,
4103 GLsizei width,
4104 GLsizei height,
4105 GLsizei depth,
4106 GLint border,
4107 GLenum format,
4108 GLenum type,
4109 GLsizei bufSize,
4110 const void *pixels)
4111{
4112 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4113}
4114
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004115void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004116 GLint level,
4117 GLint xoffset,
4118 GLint yoffset,
4119 GLsizei width,
4120 GLsizei height,
4121 GLenum format,
4122 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004123 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004124{
4125 // Zero sized uploads are valid but no-ops
4126 if (width == 0 || height == 0)
4127 {
4128 return;
4129 }
4130
Jamie Madillbc918e72018-03-08 09:47:21 -05004131 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004132
4133 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004134 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004135
4136 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4137
Jamie Madill4f6592f2018-11-27 16:37:45 -05004138 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target,
4139 level, area, format, type,
4140 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004141}
4142
Brandon Jones59770802018-04-02 13:18:42 -07004143void Context::texSubImage2DRobust(TextureTarget target,
4144 GLint level,
4145 GLint xoffset,
4146 GLint yoffset,
4147 GLsizei width,
4148 GLsizei height,
4149 GLenum format,
4150 GLenum type,
4151 GLsizei bufSize,
4152 const void *pixels)
4153{
4154 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4155}
4156
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004157void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004158 GLint level,
4159 GLint xoffset,
4160 GLint yoffset,
4161 GLint zoffset,
4162 GLsizei width,
4163 GLsizei height,
4164 GLsizei depth,
4165 GLenum format,
4166 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004167 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004168{
4169 // Zero sized uploads are valid but no-ops
4170 if (width == 0 || height == 0 || depth == 0)
4171 {
4172 return;
4173 }
4174
Jamie Madillbc918e72018-03-08 09:47:21 -05004175 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004176
4177 Box area(xoffset, yoffset, zoffset, width, height, depth);
4178 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004179
4180 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4181
Jamie Madill4f6592f2018-11-27 16:37:45 -05004182 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
4183 NonCubeTextureTypeToTarget(target), level, area, format,
4184 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004185}
4186
Brandon Jones59770802018-04-02 13:18:42 -07004187void Context::texSubImage3DRobust(TextureType target,
4188 GLint level,
4189 GLint xoffset,
4190 GLint yoffset,
4191 GLint zoffset,
4192 GLsizei width,
4193 GLsizei height,
4194 GLsizei depth,
4195 GLenum format,
4196 GLenum type,
4197 GLsizei bufSize,
4198 const void *pixels)
4199{
4200 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4201 pixels);
4202}
4203
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004204void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004205 GLint level,
4206 GLenum internalformat,
4207 GLsizei width,
4208 GLsizei height,
4209 GLint border,
4210 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004211 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004212{
Jamie Madillbc918e72018-03-08 09:47:21 -05004213 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004214
4215 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004216 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004217 ANGLE_CONTEXT_TRY(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4218 internalformat, size, imageSize,
4219 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004220}
4221
Brandon Jones59770802018-04-02 13:18:42 -07004222void Context::compressedTexImage2DRobust(TextureTarget target,
4223 GLint level,
4224 GLenum internalformat,
4225 GLsizei width,
4226 GLsizei height,
4227 GLint border,
4228 GLsizei imageSize,
4229 GLsizei dataSize,
4230 const GLvoid *data)
4231{
4232 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4233}
4234
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004235void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004236 GLint level,
4237 GLenum internalformat,
4238 GLsizei width,
4239 GLsizei height,
4240 GLsizei depth,
4241 GLint border,
4242 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004243 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004244{
Jamie Madillbc918e72018-03-08 09:47:21 -05004245 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004246
4247 Extents size(width, height, depth);
4248 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004249 ANGLE_CONTEXT_TRY(texture->setCompressedImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004250 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004251 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004252}
4253
Brandon Jones59770802018-04-02 13:18:42 -07004254void Context::compressedTexImage3DRobust(TextureType target,
4255 GLint level,
4256 GLenum internalformat,
4257 GLsizei width,
4258 GLsizei height,
4259 GLsizei depth,
4260 GLint border,
4261 GLsizei imageSize,
4262 GLsizei dataSize,
4263 const GLvoid *data)
4264{
4265 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4266 data);
4267}
4268
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004269void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004270 GLint level,
4271 GLint xoffset,
4272 GLint yoffset,
4273 GLsizei width,
4274 GLsizei height,
4275 GLenum format,
4276 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004277 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004278{
Jamie Madillbc918e72018-03-08 09:47:21 -05004279 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004280
4281 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004282 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004283 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level,
4284 area, format, imageSize,
4285 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004286}
4287
Brandon Jones59770802018-04-02 13:18:42 -07004288void Context::compressedTexSubImage2DRobust(TextureTarget target,
4289 GLint level,
4290 GLint xoffset,
4291 GLint yoffset,
4292 GLsizei width,
4293 GLsizei height,
4294 GLenum format,
4295 GLsizei imageSize,
4296 GLsizei dataSize,
4297 const GLvoid *data)
4298{
4299 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4300 data);
4301}
4302
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004303void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004304 GLint level,
4305 GLint xoffset,
4306 GLint yoffset,
4307 GLint zoffset,
4308 GLsizei width,
4309 GLsizei height,
4310 GLsizei depth,
4311 GLenum format,
4312 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004313 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004314{
4315 // Zero sized uploads are valid but no-ops
4316 if (width == 0 || height == 0)
4317 {
4318 return;
4319 }
4320
Jamie Madillbc918e72018-03-08 09:47:21 -05004321 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004322
4323 Box area(xoffset, yoffset, zoffset, width, height, depth);
4324 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004325 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004326 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004327 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004328}
4329
Brandon Jones59770802018-04-02 13:18:42 -07004330void Context::compressedTexSubImage3DRobust(TextureType target,
4331 GLint level,
4332 GLint xoffset,
4333 GLint yoffset,
4334 GLint zoffset,
4335 GLsizei width,
4336 GLsizei height,
4337 GLsizei depth,
4338 GLenum format,
4339 GLsizei imageSize,
4340 GLsizei dataSize,
4341 const GLvoid *data)
4342{
4343 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4344 imageSize, data);
4345}
4346
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004347void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004348{
4349 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004350 ANGLE_CONTEXT_TRY(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004351}
4352
Jamie Madill007530e2017-12-28 14:27:04 -05004353void Context::copyTexture(GLuint sourceId,
4354 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004355 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004356 GLuint destId,
4357 GLint destLevel,
4358 GLint internalFormat,
4359 GLenum destType,
4360 GLboolean unpackFlipY,
4361 GLboolean unpackPremultiplyAlpha,
4362 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004363{
Jamie Madillbc918e72018-03-08 09:47:21 -05004364 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004365
4366 gl::Texture *sourceTexture = getTexture(sourceId);
4367 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004368 ANGLE_CONTEXT_TRY(
4369 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4370 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4371 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004372}
4373
Jamie Madill007530e2017-12-28 14:27:04 -05004374void Context::copySubTexture(GLuint sourceId,
4375 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004376 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004377 GLuint destId,
4378 GLint destLevel,
4379 GLint xoffset,
4380 GLint yoffset,
4381 GLint x,
4382 GLint y,
4383 GLsizei width,
4384 GLsizei height,
4385 GLboolean unpackFlipY,
4386 GLboolean unpackPremultiplyAlpha,
4387 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004388{
4389 // Zero sized copies are valid but no-ops
4390 if (width == 0 || height == 0)
4391 {
4392 return;
4393 }
4394
Jamie Madillbc918e72018-03-08 09:47:21 -05004395 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004396
4397 gl::Texture *sourceTexture = getTexture(sourceId);
4398 gl::Texture *destTexture = getTexture(destId);
4399 Offset offset(xoffset, yoffset, 0);
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004400 Box box(x, y, 0, width, height, 1);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004401 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4402 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4403 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4404 sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004405}
4406
4407void Context::copyTexture3D(GLuint sourceId,
4408 GLint sourceLevel,
4409 TextureTarget destTarget,
4410 GLuint destId,
4411 GLint destLevel,
4412 GLint internalFormat,
4413 GLenum destType,
4414 GLboolean unpackFlipY,
4415 GLboolean unpackPremultiplyAlpha,
4416 GLboolean unpackUnmultiplyAlpha)
4417{
4418 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4419
4420 Texture *sourceTexture = getTexture(sourceId);
4421 Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004422 ANGLE_CONTEXT_TRY(
4423 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4424 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4425 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004426}
4427
4428void Context::copySubTexture3D(GLuint sourceId,
4429 GLint sourceLevel,
4430 TextureTarget destTarget,
4431 GLuint destId,
4432 GLint destLevel,
4433 GLint xoffset,
4434 GLint yoffset,
4435 GLint zoffset,
4436 GLint x,
4437 GLint y,
4438 GLint z,
4439 GLsizei width,
4440 GLsizei height,
4441 GLsizei depth,
4442 GLboolean unpackFlipY,
4443 GLboolean unpackPremultiplyAlpha,
4444 GLboolean unpackUnmultiplyAlpha)
4445{
4446 // Zero sized copies are valid but no-ops
4447 if (width == 0 || height == 0 || depth == 0)
4448 {
4449 return;
4450 }
4451
4452 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4453
4454 Texture *sourceTexture = getTexture(sourceId);
4455 Texture *destTexture = getTexture(destId);
4456 Offset offset(xoffset, yoffset, zoffset);
4457 Box box(x, y, z, width, height, depth);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004458 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4459 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4460 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4461 sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004462}
4463
Jamie Madill007530e2017-12-28 14:27:04 -05004464void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004465{
Jamie Madillbc918e72018-03-08 09:47:21 -05004466 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004467
4468 gl::Texture *sourceTexture = getTexture(sourceId);
4469 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004470 ANGLE_CONTEXT_TRY(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004471}
4472
Corentin Wallez336129f2017-10-17 15:55:40 -04004473void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004474{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004475 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004476 ASSERT(buffer);
4477
Geoff Lang496c02d2016-10-20 11:38:11 -07004478 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004479}
4480
Brandon Jones59770802018-04-02 13:18:42 -07004481void Context::getBufferPointervRobust(BufferBinding target,
4482 GLenum pname,
4483 GLsizei bufSize,
4484 GLsizei *length,
4485 void **params)
4486{
4487 getBufferPointerv(target, pname, params);
4488}
4489
Corentin Wallez336129f2017-10-17 15:55:40 -04004490void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004491{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004492 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004493 ASSERT(buffer);
4494
Jamie Madill7c985f52018-11-29 18:16:17 -05004495 if (buffer->map(this, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004496 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004497 return nullptr;
4498 }
4499
4500 return buffer->getMapPointer();
4501}
4502
Corentin Wallez336129f2017-10-17 15:55:40 -04004503GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004504{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004505 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004506 ASSERT(buffer);
4507
4508 GLboolean result;
Jamie Madill7c985f52018-11-29 18:16:17 -05004509 if (buffer->unmap(this, &result) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004510 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004511 return GL_FALSE;
4512 }
4513
4514 return result;
4515}
4516
Corentin Wallez336129f2017-10-17 15:55:40 -04004517void *Context::mapBufferRange(BufferBinding target,
4518 GLintptr offset,
4519 GLsizeiptr length,
4520 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004521{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004522 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004523 ASSERT(buffer);
4524
Jamie Madill7c985f52018-11-29 18:16:17 -05004525 if (buffer->mapRange(this, offset, length, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004526 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004527 return nullptr;
4528 }
4529
4530 return buffer->getMapPointer();
4531}
4532
Corentin Wallez336129f2017-10-17 15:55:40 -04004533void Context::flushMappedBufferRange(BufferBinding /*target*/,
4534 GLintptr /*offset*/,
4535 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004536{
4537 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4538}
4539
Jamie Madill526392d2018-11-16 09:35:14 -05004540angle::Result Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004541{
Geoff Langa8cb2872018-03-09 16:09:40 -05004542 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004543}
4544
Jamie Madill526392d2018-11-16 09:35:14 -05004545angle::Result Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004546{
Geoff Langa8cb2872018-03-09 16:09:40 -05004547 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004548}
4549
Jamie Madill526392d2018-11-16 09:35:14 -05004550angle::Result Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004551{
Geoff Langa8cb2872018-03-09 16:09:40 -05004552 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004553}
4554
Jamie Madill526392d2018-11-16 09:35:14 -05004555angle::Result Context::syncStateForPathOperation()
Geoff Lang9bf86f02018-07-26 11:46:34 -04004556{
4557 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4558
4559 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4560 ANGLE_TRY(syncDirtyBits());
4561
Jamie Madill7c985f52018-11-29 18:16:17 -05004562 return angle::Result::Continue;
Geoff Lang9bf86f02018-07-26 11:46:34 -04004563}
4564
Jiajia Qin5451d532017-11-16 17:16:34 +08004565void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4566{
4567 UNIMPLEMENTED();
4568}
4569
Jamie Madillc20ab272016-06-09 07:20:46 -07004570void Context::activeTexture(GLenum texture)
4571{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004572 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004573}
4574
Jamie Madill876429b2017-04-20 15:46:24 -04004575void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004576{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004577 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004578}
4579
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004580void Context::blendEquation(GLenum mode)
4581{
4582 mGLState.setBlendEquation(mode, mode);
4583}
4584
Jamie Madillc20ab272016-06-09 07:20:46 -07004585void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4586{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004587 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004588}
4589
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004590void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4591{
4592 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4593}
4594
Jamie Madillc20ab272016-06-09 07:20:46 -07004595void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4596{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004597 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004598}
4599
Jamie Madill876429b2017-04-20 15:46:24 -04004600void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004601{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004602 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004603}
4604
Jamie Madill876429b2017-04-20 15:46:24 -04004605void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004606{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004607 mGLState.setDepthClearValue(clamp01(depth));
Jamie Madillc20ab272016-06-09 07:20:46 -07004608}
4609
4610void Context::clearStencil(GLint s)
4611{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004612 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004613}
4614
4615void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4616{
Geoff Lang92019432017-11-20 13:09:34 -05004617 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4618 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004619}
4620
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004621void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004622{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004623 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004624}
4625
4626void Context::depthFunc(GLenum func)
4627{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004628 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004629}
4630
4631void Context::depthMask(GLboolean flag)
4632{
Geoff Lang92019432017-11-20 13:09:34 -05004633 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004634}
4635
Jamie Madill876429b2017-04-20 15:46:24 -04004636void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004637{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004638 mGLState.setDepthRange(clamp01(zNear), clamp01(zFar));
Jamie Madillc20ab272016-06-09 07:20:46 -07004639}
4640
4641void Context::disable(GLenum cap)
4642{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004643 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004644 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004645}
4646
4647void Context::disableVertexAttribArray(GLuint index)
4648{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004649 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004650 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004651}
4652
4653void Context::enable(GLenum cap)
4654{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004655 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004656 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004657}
4658
4659void Context::enableVertexAttribArray(GLuint index)
4660{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004661 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004662 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004663}
4664
4665void Context::frontFace(GLenum mode)
4666{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004667 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004668}
4669
4670void Context::hint(GLenum target, GLenum mode)
4671{
4672 switch (target)
4673 {
4674 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004675 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004676 break;
4677
4678 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004679 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004680 break;
4681
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004682 case GL_PERSPECTIVE_CORRECTION_HINT:
4683 case GL_POINT_SMOOTH_HINT:
4684 case GL_LINE_SMOOTH_HINT:
4685 case GL_FOG_HINT:
4686 mGLState.gles1().setHint(target, mode);
4687 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004688 default:
4689 UNREACHABLE();
4690 return;
4691 }
4692}
4693
4694void Context::lineWidth(GLfloat width)
4695{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004696 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004697}
4698
4699void Context::pixelStorei(GLenum pname, GLint param)
4700{
4701 switch (pname)
4702 {
4703 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004704 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004705 break;
4706
4707 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004708 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004709 break;
4710
4711 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004712 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004713 break;
4714
4715 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004716 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004717 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004718 break;
4719
4720 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004721 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004722 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004723 break;
4724
4725 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004726 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004727 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004728 break;
4729
4730 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004731 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004732 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004733 break;
4734
4735 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004736 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004737 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004738 break;
4739
4740 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004741 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004742 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004743 break;
4744
4745 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004746 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004747 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004748 break;
4749
4750 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004751 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004752 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004753 break;
4754
4755 default:
4756 UNREACHABLE();
4757 return;
4758 }
4759}
4760
4761void Context::polygonOffset(GLfloat factor, GLfloat units)
4762{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004763 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004764}
4765
Jamie Madill876429b2017-04-20 15:46:24 -04004766void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004767{
Geoff Lang92019432017-11-20 13:09:34 -05004768 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004769}
4770
Jiawei Shaodb342272017-09-27 10:21:45 +08004771void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4772{
4773 mGLState.setSampleMaskParams(maskNumber, mask);
4774}
4775
Jamie Madillc20ab272016-06-09 07:20:46 -07004776void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4777{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004778 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004779}
4780
4781void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4782{
4783 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4784 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004785 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004786 }
4787
4788 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4789 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004790 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004791 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004792
4793 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004794}
4795
4796void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4797{
4798 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4799 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004800 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004801 }
4802
4803 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4804 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004805 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004806 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004807
4808 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004809}
4810
4811void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4812{
4813 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4814 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004815 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004816 }
4817
4818 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4819 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004820 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004821 }
4822}
4823
4824void Context::vertexAttrib1f(GLuint index, GLfloat x)
4825{
4826 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004827 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004828 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004829}
4830
4831void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4832{
4833 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004834 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004835 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004836}
4837
4838void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4839{
4840 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004841 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004842 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004843}
4844
4845void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4846{
4847 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004848 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004849 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004850}
4851
4852void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4853{
4854 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004855 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004856 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004857}
4858
4859void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4860{
4861 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004862 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004863 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004864}
4865
4866void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4867{
4868 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004869 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004870 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004871}
4872
4873void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4874{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004875 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004876 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004877}
4878
4879void Context::vertexAttribPointer(GLuint index,
4880 GLint size,
4881 GLenum type,
4882 GLboolean normalized,
4883 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004884 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004885{
Corentin Wallez336129f2017-10-17 15:55:40 -04004886 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004887 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004888 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004889}
4890
Shao80957d92017-02-20 21:25:59 +08004891void Context::vertexAttribFormat(GLuint attribIndex,
4892 GLint size,
4893 GLenum type,
4894 GLboolean normalized,
4895 GLuint relativeOffset)
4896{
Geoff Lang92019432017-11-20 13:09:34 -05004897 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004898 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004899 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004900}
4901
4902void Context::vertexAttribIFormat(GLuint attribIndex,
4903 GLint size,
4904 GLenum type,
4905 GLuint relativeOffset)
4906{
4907 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004908 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004909}
4910
4911void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4912{
Shaodde78e82017-05-22 14:13:27 +08004913 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004914 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004915}
4916
Jiajia Qin5451d532017-11-16 17:16:34 +08004917void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004918{
4919 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004920 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004921}
4922
Jamie Madillc20ab272016-06-09 07:20:46 -07004923void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4924{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004925 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004926}
4927
4928void Context::vertexAttribIPointer(GLuint index,
4929 GLint size,
4930 GLenum type,
4931 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004932 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004933{
Corentin Wallez336129f2017-10-17 15:55:40 -04004934 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4935 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004936 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004937}
4938
4939void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4940{
4941 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004942 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004943 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004944}
4945
4946void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4947{
4948 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004949 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004950 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004951}
4952
4953void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4954{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004955 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004956 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004957}
4958
4959void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4960{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004961 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004962 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004963}
4964
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004965void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4966{
4967 const VertexAttribCurrentValueData &currentValues =
4968 getGLState().getVertexAttribCurrentValue(index);
4969 const VertexArray *vao = getGLState().getVertexArray();
4970 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4971 currentValues, pname, params);
4972}
4973
Brandon Jones59770802018-04-02 13:18:42 -07004974void Context::getVertexAttribivRobust(GLuint index,
4975 GLenum pname,
4976 GLsizei bufSize,
4977 GLsizei *length,
4978 GLint *params)
4979{
4980 getVertexAttribiv(index, pname, params);
4981}
4982
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004983void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4984{
4985 const VertexAttribCurrentValueData &currentValues =
4986 getGLState().getVertexAttribCurrentValue(index);
4987 const VertexArray *vao = getGLState().getVertexArray();
4988 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4989 currentValues, pname, params);
4990}
4991
Brandon Jones59770802018-04-02 13:18:42 -07004992void Context::getVertexAttribfvRobust(GLuint index,
4993 GLenum pname,
4994 GLsizei bufSize,
4995 GLsizei *length,
4996 GLfloat *params)
4997{
4998 getVertexAttribfv(index, pname, params);
4999}
5000
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005001void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
5002{
5003 const VertexAttribCurrentValueData &currentValues =
5004 getGLState().getVertexAttribCurrentValue(index);
5005 const VertexArray *vao = getGLState().getVertexArray();
5006 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
5007 currentValues, pname, params);
5008}
5009
Brandon Jones59770802018-04-02 13:18:42 -07005010void Context::getVertexAttribIivRobust(GLuint index,
5011 GLenum pname,
5012 GLsizei bufSize,
5013 GLsizei *length,
5014 GLint *params)
5015{
5016 getVertexAttribIiv(index, pname, params);
5017}
5018
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005019void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
5020{
5021 const VertexAttribCurrentValueData &currentValues =
5022 getGLState().getVertexAttribCurrentValue(index);
5023 const VertexArray *vao = getGLState().getVertexArray();
5024 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
5025 currentValues, pname, params);
5026}
5027
Brandon Jones59770802018-04-02 13:18:42 -07005028void Context::getVertexAttribIuivRobust(GLuint index,
5029 GLenum pname,
5030 GLsizei bufSize,
5031 GLsizei *length,
5032 GLuint *params)
5033{
5034 getVertexAttribIuiv(index, pname, params);
5035}
5036
Jamie Madill876429b2017-04-20 15:46:24 -04005037void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005038{
5039 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
5040 QueryVertexAttribPointerv(attrib, pname, pointer);
5041}
5042
Brandon Jones59770802018-04-02 13:18:42 -07005043void Context::getVertexAttribPointervRobust(GLuint index,
5044 GLenum pname,
5045 GLsizei bufSize,
5046 GLsizei *length,
5047 void **pointer)
5048{
5049 getVertexAttribPointerv(index, pname, pointer);
5050}
5051
Jamie Madillc20ab272016-06-09 07:20:46 -07005052void Context::debugMessageControl(GLenum source,
5053 GLenum type,
5054 GLenum severity,
5055 GLsizei count,
5056 const GLuint *ids,
5057 GLboolean enabled)
5058{
5059 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005060 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05005061 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07005062}
5063
5064void Context::debugMessageInsert(GLenum source,
5065 GLenum type,
5066 GLuint id,
5067 GLenum severity,
5068 GLsizei length,
5069 const GLchar *buf)
5070{
5071 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005072 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07005073}
5074
5075void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
5076{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005077 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07005078}
5079
5080GLuint Context::getDebugMessageLog(GLuint count,
5081 GLsizei bufSize,
5082 GLenum *sources,
5083 GLenum *types,
5084 GLuint *ids,
5085 GLenum *severities,
5086 GLsizei *lengths,
5087 GLchar *messageLog)
5088{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005089 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
5090 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07005091}
5092
5093void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
5094{
5095 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005096 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05005097 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07005098}
5099
5100void Context::popDebugGroup()
5101{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005102 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05005103 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07005104}
5105
Corentin Wallez336129f2017-10-17 15:55:40 -04005106void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04005107{
5108 Buffer *buffer = mGLState.getTargetBuffer(target);
5109 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005110 ANGLE_CONTEXT_TRY(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04005111}
5112
Corentin Wallez336129f2017-10-17 15:55:40 -04005113void Context::bufferSubData(BufferBinding target,
5114 GLintptr offset,
5115 GLsizeiptr size,
5116 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04005117{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06005118 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04005119 {
5120 return;
5121 }
5122
5123 Buffer *buffer = mGLState.getTargetBuffer(target);
5124 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005125 ANGLE_CONTEXT_TRY(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04005126}
5127
Jamie Madillef300b12016-10-07 15:12:09 -04005128void Context::attachShader(GLuint program, GLuint shader)
5129{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05005130 Program *programObject = mState.mShaderPrograms->getProgram(program);
5131 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04005132 ASSERT(programObject && shaderObject);
5133 programObject->attachShader(shaderObject);
5134}
5135
Kenneth Russellf2f6f652016-10-05 19:53:23 -07005136const Workarounds &Context::getWorkarounds() const
5137{
5138 return mWorkarounds;
5139}
5140
Corentin Wallez336129f2017-10-17 15:55:40 -04005141void Context::copyBufferSubData(BufferBinding readTarget,
5142 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005143 GLintptr readOffset,
5144 GLintptr writeOffset,
5145 GLsizeiptr size)
5146{
5147 // if size is zero, the copy is a successful no-op
5148 if (size == 0)
5149 {
5150 return;
5151 }
5152
5153 // TODO(jmadill): cache these.
5154 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
5155 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
5156
Jamie Madill4f6592f2018-11-27 16:37:45 -05005157 ANGLE_CONTEXT_TRY(
5158 writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005159}
5160
Jamie Madill01a80ee2016-11-07 12:06:18 -05005161void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5162{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005163 // Ideally we could share the program query with the validation layer if possible.
5164 Program *programObject = getProgramResolveLink(program);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005165 ASSERT(programObject);
5166 programObject->bindAttributeLocation(index, name);
5167}
5168
Corentin Wallez336129f2017-10-17 15:55:40 -04005169void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005170{
Corentin Wallez336129f2017-10-17 15:55:40 -04005171 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5172 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04005173 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005174}
5175
Corentin Wallez336129f2017-10-17 15:55:40 -04005176void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005177{
5178 bindBufferRange(target, index, buffer, 0, 0);
5179}
5180
Corentin Wallez336129f2017-10-17 15:55:40 -04005181void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005182 GLuint index,
5183 GLuint buffer,
5184 GLintptr offset,
5185 GLsizeiptr size)
5186{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005187 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
Geoff Lang91002262018-12-12 16:05:24 -05005188 ANGLE_CONTEXT_TRY(mGLState.setIndexedBufferBinding(this, target, index, object, offset, size));
Jamie Madill6d32cef2018-08-14 02:34:28 -04005189 if (target == BufferBinding::Uniform)
5190 {
Jamie Madill472ddc82018-10-18 18:41:56 -04005191 mUniformBufferObserverBindings[index].bind(object);
Jamie Madilld84b6732018-09-06 15:54:35 -04005192 mStateCache.onUniformBufferStateChange(this);
5193 }
5194 else
5195 {
5196 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005197 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005198}
5199
Jamie Madill01a80ee2016-11-07 12:06:18 -05005200void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5201{
5202 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5203 {
5204 bindReadFramebuffer(framebuffer);
5205 }
5206
5207 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5208 {
5209 bindDrawFramebuffer(framebuffer);
5210 }
5211}
5212
5213void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5214{
5215 ASSERT(target == GL_RENDERBUFFER);
5216 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005217 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005218 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005219}
5220
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005221void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005222 GLsizei samples,
5223 GLenum internalformat,
5224 GLsizei width,
5225 GLsizei height,
5226 GLboolean fixedsamplelocations)
5227{
5228 Extents size(width, height, 1);
5229 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005230 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5231 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005232}
5233
Olli Etuaho89664842018-08-24 14:45:36 +03005234void Context::texStorage3DMultisample(TextureType target,
5235 GLsizei samples,
5236 GLenum internalformat,
5237 GLsizei width,
5238 GLsizei height,
5239 GLsizei depth,
5240 GLboolean fixedsamplelocations)
5241{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005242 Extents size(width, height, depth);
5243 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005244 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5245 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005246}
5247
JiangYizhoubddc46b2016-12-09 09:50:51 +08005248void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5249{
JiangYizhou5b03f472017-01-09 10:22:53 +08005250 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5251 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005252 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005253 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005254
5255 switch (pname)
5256 {
5257 case GL_SAMPLE_POSITION:
Jamie Madill4f6592f2018-11-27 16:37:45 -05005258 ANGLE_CONTEXT_TRY(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005259 break;
5260 default:
5261 UNREACHABLE();
5262 }
5263}
5264
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005265void Context::getMultisamplefvRobust(GLenum pname,
5266 GLuint index,
5267 GLsizei bufSize,
5268 GLsizei *length,
5269 GLfloat *val)
5270{
5271 UNIMPLEMENTED();
5272}
5273
Jamie Madille8fb6402017-02-14 17:56:40 -05005274void Context::renderbufferStorage(GLenum target,
5275 GLenum internalformat,
5276 GLsizei width,
5277 GLsizei height)
5278{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005279 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5280 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5281
Jamie Madille8fb6402017-02-14 17:56:40 -05005282 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005283 ANGLE_CONTEXT_TRY(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005284}
5285
5286void Context::renderbufferStorageMultisample(GLenum target,
5287 GLsizei samples,
5288 GLenum internalformat,
5289 GLsizei width,
5290 GLsizei height)
5291{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005292 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5293 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005294
5295 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005296 ANGLE_CONTEXT_TRY(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005297 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005298}
5299
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005300void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5301{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005302 const Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005303 ANGLE_CONTEXT_TRY(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005304}
5305
JiangYizhoue18e6392017-02-20 10:32:23 +08005306void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5307{
5308 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5309 QueryFramebufferParameteriv(framebuffer, pname, params);
5310}
5311
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005312void Context::getFramebufferParameterivRobust(GLenum target,
5313 GLenum pname,
5314 GLsizei bufSize,
5315 GLsizei *length,
5316 GLint *params)
5317{
5318 UNIMPLEMENTED();
5319}
5320
Jiajia Qin5451d532017-11-16 17:16:34 +08005321void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005322{
5323 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005324 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005325}
5326
Jamie Madilldec86232018-07-11 09:01:18 -04005327bool Context::getScratchBuffer(size_t requstedSizeBytes,
5328 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005329{
Jamie Madilldec86232018-07-11 09:01:18 -04005330 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005331}
5332
Jamie Madilldec86232018-07-11 09:01:18 -04005333bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5334 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005335{
Jamie Madilldec86232018-07-11 09:01:18 -04005336 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005337}
5338
Xinghua Cao2b396592017-03-29 15:36:04 +08005339void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5340{
5341 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5342 {
5343 return;
5344 }
5345
Xinghua Cao10a4d432017-11-28 14:46:26 +08005346 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005347 ANGLE_CONTEXT_TRY(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005348}
5349
Jiajia Qin5451d532017-11-16 17:16:34 +08005350void Context::dispatchComputeIndirect(GLintptr indirect)
5351{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005352 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005353 ANGLE_CONTEXT_TRY(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005354}
5355
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005356void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005357 GLsizei levels,
5358 GLenum internalFormat,
5359 GLsizei width,
5360 GLsizei height)
5361{
5362 Extents size(width, height, 1);
5363 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005364 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005365}
5366
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005367void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005368 GLsizei levels,
5369 GLenum internalFormat,
5370 GLsizei width,
5371 GLsizei height,
5372 GLsizei depth)
5373{
5374 Extents size(width, height, depth);
5375 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005376 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005377}
5378
Jiajia Qin5451d532017-11-16 17:16:34 +08005379void Context::memoryBarrier(GLbitfield barriers)
5380{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005381 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005382}
5383
5384void Context::memoryBarrierByRegion(GLbitfield barriers)
5385{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005386 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005387}
5388
Austin Eng1bf18ce2018-10-19 15:34:02 -07005389void Context::multiDrawArrays(PrimitiveMode mode,
5390 const GLint *firsts,
5391 const GLsizei *counts,
5392 GLsizei drawcount)
5393{
5394 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5395 Program *programObject = mGLState.getLinkedProgram(this);
5396 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5397 if (hasDrawID)
5398 {
5399 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5400 {
5401 if (noopDraw(mode, counts[drawID]))
5402 {
5403 continue;
5404 }
5405 programObject->setDrawIDUniform(drawID);
5406 ANGLE_CONTEXT_TRY(
5407 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005408 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005409 }
5410 }
5411 else
5412 {
5413 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5414 {
5415 if (noopDraw(mode, counts[drawID]))
5416 {
5417 continue;
5418 }
5419 ANGLE_CONTEXT_TRY(
5420 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005421 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005422 }
5423 }
5424}
5425
5426void Context::multiDrawArraysInstanced(PrimitiveMode mode,
5427 const GLint *firsts,
5428 const GLsizei *counts,
5429 const GLsizei *instanceCounts,
5430 GLsizei drawcount)
5431{
5432 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5433 Program *programObject = mGLState.getLinkedProgram(this);
5434 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5435 if (hasDrawID)
5436 {
5437 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5438 {
5439 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5440 {
5441 continue;
5442 }
5443 programObject->setDrawIDUniform(drawID);
5444 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5445 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005446 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005447 }
5448 }
5449 else
5450 {
5451 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5452 {
5453 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5454 {
5455 continue;
5456 }
5457 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5458 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005459 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005460 }
5461 }
5462}
5463
5464void Context::multiDrawElements(PrimitiveMode mode,
5465 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005466 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005467 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005468 GLsizei drawcount)
5469{
5470 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5471 Program *programObject = mGLState.getLinkedProgram(this);
5472 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5473 if (hasDrawID)
5474 {
5475 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5476 {
5477 if (noopDraw(mode, counts[drawID]))
5478 {
5479 continue;
5480 }
5481 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005482 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005483 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005484 }
5485 }
5486 else
5487 {
5488 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5489 {
5490 if (noopDraw(mode, counts[drawID]))
5491 {
5492 continue;
5493 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005494 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005495 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005496 }
5497 }
5498}
5499
5500void Context::multiDrawElementsInstanced(PrimitiveMode mode,
5501 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005502 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005503 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005504 const GLsizei *instanceCounts,
5505 GLsizei drawcount)
5506{
5507 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5508 Program *programObject = mGLState.getLinkedProgram(this);
5509 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5510 if (hasDrawID)
5511 {
5512 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5513 {
5514 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5515 {
5516 continue;
5517 }
5518 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005519 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005520 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005521 }
5522 }
5523 else
5524 {
5525 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5526 {
5527 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5528 {
5529 continue;
5530 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005531 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005532 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005533 }
5534 }
5535}
5536
Jamie Madillc1d770e2017-04-13 17:31:24 -04005537GLenum Context::checkFramebufferStatus(GLenum target)
5538{
5539 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5540 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005541 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005542}
5543
5544void Context::compileShader(GLuint shader)
5545{
5546 Shader *shaderObject = GetValidShader(this, shader);
5547 if (!shaderObject)
5548 {
5549 return;
5550 }
5551 shaderObject->compile(this);
5552}
5553
5554void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5555{
5556 for (int i = 0; i < n; i++)
5557 {
5558 deleteBuffer(buffers[i]);
5559 }
5560}
5561
5562void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5563{
5564 for (int i = 0; i < n; i++)
5565 {
5566 if (framebuffers[i] != 0)
5567 {
5568 deleteFramebuffer(framebuffers[i]);
5569 }
5570 }
5571}
5572
5573void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5574{
5575 for (int i = 0; i < n; i++)
5576 {
5577 deleteRenderbuffer(renderbuffers[i]);
5578 }
5579}
5580
5581void Context::deleteTextures(GLsizei n, const GLuint *textures)
5582{
5583 for (int i = 0; i < n; i++)
5584 {
5585 if (textures[i] != 0)
5586 {
5587 deleteTexture(textures[i]);
5588 }
5589 }
5590}
5591
5592void Context::detachShader(GLuint program, GLuint shader)
5593{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005594 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005595 ASSERT(programObject);
5596
5597 Shader *shaderObject = getShader(shader);
5598 ASSERT(shaderObject);
5599
5600 programObject->detachShader(this, shaderObject);
5601}
5602
5603void Context::genBuffers(GLsizei n, GLuint *buffers)
5604{
5605 for (int i = 0; i < n; i++)
5606 {
5607 buffers[i] = createBuffer();
5608 }
5609}
5610
5611void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5612{
5613 for (int i = 0; i < n; i++)
5614 {
5615 framebuffers[i] = createFramebuffer();
5616 }
5617}
5618
5619void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5620{
5621 for (int i = 0; i < n; i++)
5622 {
5623 renderbuffers[i] = createRenderbuffer();
5624 }
5625}
5626
5627void Context::genTextures(GLsizei n, GLuint *textures)
5628{
5629 for (int i = 0; i < n; i++)
5630 {
5631 textures[i] = createTexture();
5632 }
5633}
5634
5635void Context::getActiveAttrib(GLuint program,
5636 GLuint index,
5637 GLsizei bufsize,
5638 GLsizei *length,
5639 GLint *size,
5640 GLenum *type,
5641 GLchar *name)
5642{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005643 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005644 ASSERT(programObject);
5645 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5646}
5647
5648void Context::getActiveUniform(GLuint program,
5649 GLuint index,
5650 GLsizei bufsize,
5651 GLsizei *length,
5652 GLint *size,
5653 GLenum *type,
5654 GLchar *name)
5655{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005656 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005657 ASSERT(programObject);
5658 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5659}
5660
5661void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5662{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005663 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005664 ASSERT(programObject);
5665 programObject->getAttachedShaders(maxcount, count, shaders);
5666}
5667
5668GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5669{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005670 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005671 ASSERT(programObject);
5672 return programObject->getAttributeLocation(name);
5673}
5674
5675void Context::getBooleanv(GLenum pname, GLboolean *params)
5676{
5677 GLenum nativeType;
5678 unsigned int numParams = 0;
5679 getQueryParameterInfo(pname, &nativeType, &numParams);
5680
5681 if (nativeType == GL_BOOL)
5682 {
5683 getBooleanvImpl(pname, params);
5684 }
5685 else
5686 {
5687 CastStateValues(this, nativeType, pname, numParams, params);
5688 }
5689}
5690
Brandon Jones59770802018-04-02 13:18:42 -07005691void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5692{
5693 getBooleanv(pname, params);
5694}
5695
Jamie Madillc1d770e2017-04-13 17:31:24 -04005696void Context::getFloatv(GLenum pname, GLfloat *params)
5697{
5698 GLenum nativeType;
5699 unsigned int numParams = 0;
5700 getQueryParameterInfo(pname, &nativeType, &numParams);
5701
5702 if (nativeType == GL_FLOAT)
5703 {
5704 getFloatvImpl(pname, params);
5705 }
5706 else
5707 {
5708 CastStateValues(this, nativeType, pname, numParams, params);
5709 }
5710}
5711
Brandon Jones59770802018-04-02 13:18:42 -07005712void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5713{
5714 getFloatv(pname, params);
5715}
5716
Jamie Madillc1d770e2017-04-13 17:31:24 -04005717void Context::getIntegerv(GLenum pname, GLint *params)
5718{
5719 GLenum nativeType;
5720 unsigned int numParams = 0;
5721 getQueryParameterInfo(pname, &nativeType, &numParams);
5722
5723 if (nativeType == GL_INT)
5724 {
5725 getIntegervImpl(pname, params);
5726 }
5727 else
5728 {
5729 CastStateValues(this, nativeType, pname, numParams, params);
5730 }
5731}
5732
Brandon Jones59770802018-04-02 13:18:42 -07005733void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5734{
5735 getIntegerv(pname, data);
5736}
5737
Jamie Madillc1d770e2017-04-13 17:31:24 -04005738void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5739{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005740 // Don't resolve link if checking the link completion status.
5741 Program *programObject = (pname == GL_COMPLETION_STATUS_KHR ? getProgramNoResolveLink(program)
5742 : getProgramResolveLink(program));
Jamie Madillc1d770e2017-04-13 17:31:24 -04005743 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005744 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005745}
5746
Brandon Jones59770802018-04-02 13:18:42 -07005747void Context::getProgramivRobust(GLuint program,
5748 GLenum pname,
5749 GLsizei bufSize,
5750 GLsizei *length,
5751 GLint *params)
5752{
5753 getProgramiv(program, pname, params);
5754}
5755
Jiajia Qin5451d532017-11-16 17:16:34 +08005756void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5757{
5758 UNIMPLEMENTED();
5759}
5760
Jamie Madillbe849e42017-05-02 15:49:00 -04005761void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005762{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005763 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005764 ASSERT(programObject);
5765 programObject->getInfoLog(bufsize, length, infolog);
5766}
5767
Jiajia Qin5451d532017-11-16 17:16:34 +08005768void Context::getProgramPipelineInfoLog(GLuint pipeline,
5769 GLsizei bufSize,
5770 GLsizei *length,
5771 GLchar *infoLog)
5772{
5773 UNIMPLEMENTED();
5774}
5775
Jamie Madillc1d770e2017-04-13 17:31:24 -04005776void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5777{
5778 Shader *shaderObject = getShader(shader);
5779 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005780 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005781}
5782
Brandon Jones59770802018-04-02 13:18:42 -07005783void Context::getShaderivRobust(GLuint shader,
5784 GLenum pname,
5785 GLsizei bufSize,
5786 GLsizei *length,
5787 GLint *params)
5788{
5789 getShaderiv(shader, pname, params);
5790}
5791
Jamie Madillc1d770e2017-04-13 17:31:24 -04005792void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5793{
5794 Shader *shaderObject = getShader(shader);
5795 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005796 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005797}
5798
5799void Context::getShaderPrecisionFormat(GLenum shadertype,
5800 GLenum precisiontype,
5801 GLint *range,
5802 GLint *precision)
5803{
5804 // TODO(jmadill): Compute shaders.
5805
5806 switch (shadertype)
5807 {
5808 case GL_VERTEX_SHADER:
5809 switch (precisiontype)
5810 {
5811 case GL_LOW_FLOAT:
5812 mCaps.vertexLowpFloat.get(range, precision);
5813 break;
5814 case GL_MEDIUM_FLOAT:
5815 mCaps.vertexMediumpFloat.get(range, precision);
5816 break;
5817 case GL_HIGH_FLOAT:
5818 mCaps.vertexHighpFloat.get(range, precision);
5819 break;
5820
5821 case GL_LOW_INT:
5822 mCaps.vertexLowpInt.get(range, precision);
5823 break;
5824 case GL_MEDIUM_INT:
5825 mCaps.vertexMediumpInt.get(range, precision);
5826 break;
5827 case GL_HIGH_INT:
5828 mCaps.vertexHighpInt.get(range, precision);
5829 break;
5830
5831 default:
5832 UNREACHABLE();
5833 return;
5834 }
5835 break;
5836
5837 case GL_FRAGMENT_SHADER:
5838 switch (precisiontype)
5839 {
5840 case GL_LOW_FLOAT:
5841 mCaps.fragmentLowpFloat.get(range, precision);
5842 break;
5843 case GL_MEDIUM_FLOAT:
5844 mCaps.fragmentMediumpFloat.get(range, precision);
5845 break;
5846 case GL_HIGH_FLOAT:
5847 mCaps.fragmentHighpFloat.get(range, precision);
5848 break;
5849
5850 case GL_LOW_INT:
5851 mCaps.fragmentLowpInt.get(range, precision);
5852 break;
5853 case GL_MEDIUM_INT:
5854 mCaps.fragmentMediumpInt.get(range, precision);
5855 break;
5856 case GL_HIGH_INT:
5857 mCaps.fragmentHighpInt.get(range, precision);
5858 break;
5859
5860 default:
5861 UNREACHABLE();
5862 return;
5863 }
5864 break;
5865
5866 default:
5867 UNREACHABLE();
5868 return;
5869 }
5870}
5871
5872void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5873{
5874 Shader *shaderObject = getShader(shader);
5875 ASSERT(shaderObject);
5876 shaderObject->getSource(bufsize, length, source);
5877}
5878
5879void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5880{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005881 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005882 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005883 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005884}
5885
Brandon Jones59770802018-04-02 13:18:42 -07005886void Context::getUniformfvRobust(GLuint program,
5887 GLint location,
5888 GLsizei bufSize,
5889 GLsizei *length,
5890 GLfloat *params)
5891{
5892 getUniformfv(program, location, params);
5893}
5894
Jamie Madillc1d770e2017-04-13 17:31:24 -04005895void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5896{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005897 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005898 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005899 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005900}
5901
Brandon Jones59770802018-04-02 13:18:42 -07005902void Context::getUniformivRobust(GLuint program,
5903 GLint location,
5904 GLsizei bufSize,
5905 GLsizei *length,
5906 GLint *params)
5907{
5908 getUniformiv(program, location, params);
5909}
5910
Jamie Madillc1d770e2017-04-13 17:31:24 -04005911GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5912{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005913 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005914 ASSERT(programObject);
5915 return programObject->getUniformLocation(name);
5916}
5917
5918GLboolean Context::isBuffer(GLuint buffer)
5919{
5920 if (buffer == 0)
5921 {
5922 return GL_FALSE;
5923 }
5924
5925 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5926}
5927
5928GLboolean Context::isEnabled(GLenum cap)
5929{
5930 return mGLState.getEnableFeature(cap);
5931}
5932
5933GLboolean Context::isFramebuffer(GLuint framebuffer)
5934{
5935 if (framebuffer == 0)
5936 {
5937 return GL_FALSE;
5938 }
5939
5940 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5941}
5942
5943GLboolean Context::isProgram(GLuint program)
5944{
5945 if (program == 0)
5946 {
5947 return GL_FALSE;
5948 }
5949
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005950 return (getProgramNoResolveLink(program) ? GL_TRUE : GL_FALSE);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005951}
5952
5953GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5954{
5955 if (renderbuffer == 0)
5956 {
5957 return GL_FALSE;
5958 }
5959
5960 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5961}
5962
5963GLboolean Context::isShader(GLuint shader)
5964{
5965 if (shader == 0)
5966 {
5967 return GL_FALSE;
5968 }
5969
5970 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5971}
5972
5973GLboolean Context::isTexture(GLuint texture)
5974{
5975 if (texture == 0)
5976 {
5977 return GL_FALSE;
5978 }
5979
5980 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5981}
5982
5983void Context::linkProgram(GLuint program)
5984{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005985 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005986 ASSERT(programObject);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005987 ANGLE_CONTEXT_TRY(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005988
5989 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5990 // don't need to worry that:
5991 // 1. Draw calls after link use the new executable code or the old one depending on the link
5992 // result.
5993 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5994 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5995 // ProgramD3D.
5996 if (programObject->isInUse())
5997 {
Jamie Madill785e8a02018-10-04 17:42:00 -04005998 programObject->resolveLink(this);
Jamie Madilldf836ff2018-10-01 10:36:24 -04005999 if (programObject->isLinked())
6000 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04006001 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006002 }
jchen107ae70d82018-07-06 13:47:01 +08006003 mStateCache.onProgramExecutableChange(this);
6004 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04006005}
6006
6007void Context::releaseShaderCompiler()
6008{
Jamie Madill4928b7c2017-06-20 12:57:39 -04006009 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006010}
6011
6012void Context::shaderBinary(GLsizei n,
6013 const GLuint *shaders,
6014 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04006015 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006016 GLsizei length)
6017{
6018 // No binary shader formats are supported.
6019 UNIMPLEMENTED();
6020}
6021
Olli Etuaho0ca09752018-09-24 11:00:50 +03006022void Context::bindFragDataLocationIndexed(GLuint program,
6023 GLuint colorNumber,
6024 GLuint index,
6025 const char *name)
6026{
6027 Program *programObject = getProgramNoResolveLink(program);
6028 programObject->bindFragmentOutputLocation(colorNumber, name);
6029 programObject->bindFragmentOutputIndex(index, name);
6030}
6031
6032void Context::bindFragDataLocation(GLuint program, GLuint colorNumber, const char *name)
6033{
6034 bindFragDataLocationIndexed(program, colorNumber, 0u, name);
6035}
6036
6037int Context::getFragDataIndex(GLuint program, const char *name)
6038{
6039 Program *programObject = getProgramResolveLink(program);
6040 return programObject->getFragDataIndex(name);
6041}
6042
6043int Context::getProgramResourceLocationIndex(GLuint program,
6044 GLenum programInterface,
6045 const char *name)
6046{
6047 Program *programObject = getProgramResolveLink(program);
6048 ASSERT(programInterface == GL_PROGRAM_OUTPUT);
6049 return programObject->getFragDataIndex(name);
6050}
6051
Jamie Madillc1d770e2017-04-13 17:31:24 -04006052void Context::shaderSource(GLuint shader,
6053 GLsizei count,
6054 const GLchar *const *string,
6055 const GLint *length)
6056{
6057 Shader *shaderObject = getShader(shader);
6058 ASSERT(shaderObject);
6059 shaderObject->setSource(count, string, length);
6060}
6061
6062void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
6063{
6064 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
6065}
6066
6067void Context::stencilMask(GLuint mask)
6068{
6069 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6070}
6071
6072void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6073{
6074 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6075}
6076
6077void Context::uniform1f(GLint location, GLfloat x)
6078{
6079 Program *program = mGLState.getProgram();
6080 program->setUniform1fv(location, 1, &x);
6081}
6082
6083void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
6084{
6085 Program *program = mGLState.getProgram();
6086 program->setUniform1fv(location, count, v);
6087}
6088
Jamie Madill7e4eff12018-08-08 15:49:26 -04006089void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006090{
Jamie Madille3e680c2018-12-03 17:49:08 -05006091 program->setUniform1iv(this, location, count, v);
6092}
6093
6094void Context::onSamplerUniformChange(size_t textureUnitIndex)
6095{
6096 mGLState.onActiveTextureChange(this, textureUnitIndex);
6097 mStateCache.onActiveTextureChange(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006098}
6099
Jamie Madill7e4eff12018-08-08 15:49:26 -04006100void Context::uniform1i(GLint location, GLint x)
6101{
6102 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
6103}
6104
Jamie Madillc1d770e2017-04-13 17:31:24 -04006105void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
6106{
Jamie Madill7e4eff12018-08-08 15:49:26 -04006107 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006108}
6109
6110void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
6111{
6112 GLfloat xy[2] = {x, y};
6113 Program *program = mGLState.getProgram();
6114 program->setUniform2fv(location, 1, xy);
6115}
6116
6117void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
6118{
6119 Program *program = mGLState.getProgram();
6120 program->setUniform2fv(location, count, v);
6121}
6122
6123void Context::uniform2i(GLint location, GLint x, GLint y)
6124{
6125 GLint xy[2] = {x, y};
6126 Program *program = mGLState.getProgram();
6127 program->setUniform2iv(location, 1, xy);
6128}
6129
6130void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
6131{
6132 Program *program = mGLState.getProgram();
6133 program->setUniform2iv(location, count, v);
6134}
6135
6136void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6137{
6138 GLfloat xyz[3] = {x, y, z};
6139 Program *program = mGLState.getProgram();
6140 program->setUniform3fv(location, 1, xyz);
6141}
6142
6143void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
6144{
6145 Program *program = mGLState.getProgram();
6146 program->setUniform3fv(location, count, v);
6147}
6148
6149void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
6150{
6151 GLint xyz[3] = {x, y, z};
6152 Program *program = mGLState.getProgram();
6153 program->setUniform3iv(location, 1, xyz);
6154}
6155
6156void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
6157{
6158 Program *program = mGLState.getProgram();
6159 program->setUniform3iv(location, count, v);
6160}
6161
6162void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6163{
6164 GLfloat xyzw[4] = {x, y, z, w};
6165 Program *program = mGLState.getProgram();
6166 program->setUniform4fv(location, 1, xyzw);
6167}
6168
6169void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
6170{
6171 Program *program = mGLState.getProgram();
6172 program->setUniform4fv(location, count, v);
6173}
6174
6175void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6176{
6177 GLint xyzw[4] = {x, y, z, w};
6178 Program *program = mGLState.getProgram();
6179 program->setUniform4iv(location, 1, xyzw);
6180}
6181
6182void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
6183{
6184 Program *program = mGLState.getProgram();
6185 program->setUniform4iv(location, count, v);
6186}
6187
6188void Context::uniformMatrix2fv(GLint location,
6189 GLsizei count,
6190 GLboolean transpose,
6191 const GLfloat *value)
6192{
6193 Program *program = mGLState.getProgram();
6194 program->setUniformMatrix2fv(location, count, transpose, value);
6195}
6196
6197void Context::uniformMatrix3fv(GLint location,
6198 GLsizei count,
6199 GLboolean transpose,
6200 const GLfloat *value)
6201{
6202 Program *program = mGLState.getProgram();
6203 program->setUniformMatrix3fv(location, count, transpose, value);
6204}
6205
6206void Context::uniformMatrix4fv(GLint location,
6207 GLsizei count,
6208 GLboolean transpose,
6209 const GLfloat *value)
6210{
6211 Program *program = mGLState.getProgram();
6212 program->setUniformMatrix4fv(location, count, transpose, value);
6213}
6214
6215void Context::validateProgram(GLuint program)
6216{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006217 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006218 ASSERT(programObject);
6219 programObject->validate(mCaps);
6220}
6221
Jiajia Qin5451d532017-11-16 17:16:34 +08006222void Context::validateProgramPipeline(GLuint pipeline)
6223{
6224 UNIMPLEMENTED();
6225}
6226
Jamie Madilld04908b2017-06-09 14:15:35 -04006227void Context::getProgramBinary(GLuint program,
6228 GLsizei bufSize,
6229 GLsizei *length,
6230 GLenum *binaryFormat,
6231 void *binary)
6232{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006233 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006234 ASSERT(programObject != nullptr);
6235
Jamie Madill4f6592f2018-11-27 16:37:45 -05006236 ANGLE_CONTEXT_TRY(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
Jamie Madilld04908b2017-06-09 14:15:35 -04006237}
6238
6239void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
6240{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006241 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006242 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04006243
Jamie Madill4f6592f2018-11-27 16:37:45 -05006244 ANGLE_CONTEXT_TRY(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madill70aeda42018-08-20 12:17:40 -04006245 if (programObject->isInUse())
6246 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04006247 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006248 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006249 }
Jamie Madilld04908b2017-06-09 14:15:35 -04006250}
6251
Jamie Madillff325f12017-08-26 15:06:05 -04006252void Context::uniform1ui(GLint location, GLuint v0)
6253{
6254 Program *program = mGLState.getProgram();
6255 program->setUniform1uiv(location, 1, &v0);
6256}
6257
6258void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
6259{
6260 Program *program = mGLState.getProgram();
6261 const GLuint xy[] = {v0, v1};
6262 program->setUniform2uiv(location, 1, xy);
6263}
6264
6265void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6266{
6267 Program *program = mGLState.getProgram();
6268 const GLuint xyz[] = {v0, v1, v2};
6269 program->setUniform3uiv(location, 1, xyz);
6270}
6271
6272void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6273{
6274 Program *program = mGLState.getProgram();
6275 const GLuint xyzw[] = {v0, v1, v2, v3};
6276 program->setUniform4uiv(location, 1, xyzw);
6277}
6278
6279void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
6280{
6281 Program *program = mGLState.getProgram();
6282 program->setUniform1uiv(location, count, value);
6283}
6284void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
6285{
6286 Program *program = mGLState.getProgram();
6287 program->setUniform2uiv(location, count, value);
6288}
6289
6290void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
6291{
6292 Program *program = mGLState.getProgram();
6293 program->setUniform3uiv(location, count, value);
6294}
6295
6296void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
6297{
6298 Program *program = mGLState.getProgram();
6299 program->setUniform4uiv(location, count, value);
6300}
6301
Jamie Madillf0e04492017-08-26 15:28:42 -04006302void Context::genQueries(GLsizei n, GLuint *ids)
6303{
6304 for (GLsizei i = 0; i < n; i++)
6305 {
6306 GLuint handle = mQueryHandleAllocator.allocate();
6307 mQueryMap.assign(handle, nullptr);
6308 ids[i] = handle;
6309 }
6310}
6311
6312void Context::deleteQueries(GLsizei n, const GLuint *ids)
6313{
6314 for (int i = 0; i < n; i++)
6315 {
6316 GLuint query = ids[i];
6317
6318 Query *queryObject = nullptr;
6319 if (mQueryMap.erase(query, &queryObject))
6320 {
6321 mQueryHandleAllocator.release(query);
6322 if (queryObject)
6323 {
6324 queryObject->release(this);
6325 }
6326 }
6327 }
6328}
6329
6330GLboolean Context::isQuery(GLuint id)
6331{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006332 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006333}
6334
Jamie Madillc8c95812017-08-26 18:40:09 -04006335void Context::uniformMatrix2x3fv(GLint location,
6336 GLsizei count,
6337 GLboolean transpose,
6338 const GLfloat *value)
6339{
6340 Program *program = mGLState.getProgram();
6341 program->setUniformMatrix2x3fv(location, count, transpose, value);
6342}
6343
6344void Context::uniformMatrix3x2fv(GLint location,
6345 GLsizei count,
6346 GLboolean transpose,
6347 const GLfloat *value)
6348{
6349 Program *program = mGLState.getProgram();
6350 program->setUniformMatrix3x2fv(location, count, transpose, value);
6351}
6352
6353void Context::uniformMatrix2x4fv(GLint location,
6354 GLsizei count,
6355 GLboolean transpose,
6356 const GLfloat *value)
6357{
6358 Program *program = mGLState.getProgram();
6359 program->setUniformMatrix2x4fv(location, count, transpose, value);
6360}
6361
6362void Context::uniformMatrix4x2fv(GLint location,
6363 GLsizei count,
6364 GLboolean transpose,
6365 const GLfloat *value)
6366{
6367 Program *program = mGLState.getProgram();
6368 program->setUniformMatrix4x2fv(location, count, transpose, value);
6369}
6370
6371void Context::uniformMatrix3x4fv(GLint location,
6372 GLsizei count,
6373 GLboolean transpose,
6374 const GLfloat *value)
6375{
6376 Program *program = mGLState.getProgram();
6377 program->setUniformMatrix3x4fv(location, count, transpose, value);
6378}
6379
6380void Context::uniformMatrix4x3fv(GLint location,
6381 GLsizei count,
6382 GLboolean transpose,
6383 const GLfloat *value)
6384{
6385 Program *program = mGLState.getProgram();
6386 program->setUniformMatrix4x3fv(location, count, transpose, value);
6387}
6388
Jamie Madilld7576732017-08-26 18:49:50 -04006389void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6390{
6391 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6392 {
6393 GLuint vertexArray = arrays[arrayIndex];
6394
6395 if (arrays[arrayIndex] != 0)
6396 {
6397 VertexArray *vertexArrayObject = nullptr;
6398 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6399 {
6400 if (vertexArrayObject != nullptr)
6401 {
6402 detachVertexArray(vertexArray);
6403 vertexArrayObject->onDestroy(this);
6404 }
6405
6406 mVertexArrayHandleAllocator.release(vertexArray);
6407 }
6408 }
6409 }
6410}
6411
6412void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6413{
6414 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6415 {
6416 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6417 mVertexArrayMap.assign(vertexArray, nullptr);
6418 arrays[arrayIndex] = vertexArray;
6419 }
6420}
6421
6422bool Context::isVertexArray(GLuint array)
6423{
6424 if (array == 0)
6425 {
6426 return GL_FALSE;
6427 }
6428
6429 VertexArray *vao = getVertexArray(array);
6430 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6431}
6432
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006433void Context::endTransformFeedback()
6434{
6435 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006436 ANGLE_CONTEXT_TRY(transformFeedback->end(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006437 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006438}
6439
6440void Context::transformFeedbackVaryings(GLuint program,
6441 GLsizei count,
6442 const GLchar *const *varyings,
6443 GLenum bufferMode)
6444{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006445 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006446 ASSERT(programObject);
6447 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6448}
6449
6450void Context::getTransformFeedbackVarying(GLuint program,
6451 GLuint index,
6452 GLsizei bufSize,
6453 GLsizei *length,
6454 GLsizei *size,
6455 GLenum *type,
6456 GLchar *name)
6457{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006458 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006459 ASSERT(programObject);
6460 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6461}
6462
6463void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6464{
6465 for (int i = 0; i < n; i++)
6466 {
6467 GLuint transformFeedback = ids[i];
6468 if (transformFeedback == 0)
6469 {
6470 continue;
6471 }
6472
6473 TransformFeedback *transformFeedbackObject = nullptr;
6474 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6475 {
6476 if (transformFeedbackObject != nullptr)
6477 {
6478 detachTransformFeedback(transformFeedback);
6479 transformFeedbackObject->release(this);
6480 }
6481
6482 mTransformFeedbackHandleAllocator.release(transformFeedback);
6483 }
6484 }
6485}
6486
6487void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6488{
6489 for (int i = 0; i < n; i++)
6490 {
6491 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6492 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6493 ids[i] = transformFeedback;
6494 }
6495}
6496
6497bool Context::isTransformFeedback(GLuint id)
6498{
6499 if (id == 0)
6500 {
6501 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6502 // returns FALSE
6503 return GL_FALSE;
6504 }
6505
6506 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6507 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6508}
6509
6510void Context::pauseTransformFeedback()
6511{
6512 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006513 ANGLE_CONTEXT_TRY(transformFeedback->pause(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006514 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006515}
6516
6517void Context::resumeTransformFeedback()
6518{
6519 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006520 ANGLE_CONTEXT_TRY(transformFeedback->resume(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006521 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006522}
6523
Jamie Madill12e957f2017-08-26 21:42:26 -04006524void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6525{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006526 const Program *programObject = getProgramResolveLink(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006527 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006528}
6529
Brandon Jones59770802018-04-02 13:18:42 -07006530void Context::getUniformuivRobust(GLuint program,
6531 GLint location,
6532 GLsizei bufSize,
6533 GLsizei *length,
6534 GLuint *params)
6535{
6536 getUniformuiv(program, location, params);
6537}
6538
Jamie Madill12e957f2017-08-26 21:42:26 -04006539GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6540{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006541 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006542 return programObject->getFragDataLocation(name);
6543}
6544
6545void Context::getUniformIndices(GLuint program,
6546 GLsizei uniformCount,
6547 const GLchar *const *uniformNames,
6548 GLuint *uniformIndices)
6549{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006550 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006551 if (!programObject->isLinked())
6552 {
6553 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6554 {
6555 uniformIndices[uniformId] = GL_INVALID_INDEX;
6556 }
6557 }
6558 else
6559 {
6560 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6561 {
6562 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6563 }
6564 }
6565}
6566
6567void Context::getActiveUniformsiv(GLuint program,
6568 GLsizei uniformCount,
6569 const GLuint *uniformIndices,
6570 GLenum pname,
6571 GLint *params)
6572{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006573 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006574 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6575 {
6576 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006577 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006578 }
6579}
6580
6581GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6582{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006583 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006584 return programObject->getUniformBlockIndex(uniformBlockName);
6585}
6586
6587void Context::getActiveUniformBlockiv(GLuint program,
6588 GLuint uniformBlockIndex,
6589 GLenum pname,
6590 GLint *params)
6591{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006592 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006593 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6594}
6595
Brandon Jones59770802018-04-02 13:18:42 -07006596void Context::getActiveUniformBlockivRobust(GLuint program,
6597 GLuint uniformBlockIndex,
6598 GLenum pname,
6599 GLsizei bufSize,
6600 GLsizei *length,
6601 GLint *params)
6602{
6603 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6604}
6605
Jamie Madill12e957f2017-08-26 21:42:26 -04006606void Context::getActiveUniformBlockName(GLuint program,
6607 GLuint uniformBlockIndex,
6608 GLsizei bufSize,
6609 GLsizei *length,
6610 GLchar *uniformBlockName)
6611{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006612 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006613 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6614}
6615
6616void Context::uniformBlockBinding(GLuint program,
6617 GLuint uniformBlockIndex,
6618 GLuint uniformBlockBinding)
6619{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006620 Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006621 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006622
Jamie Madill956ab4d2018-10-10 16:13:03 -04006623 // Note: If the Program is shared between Contexts we would be better using Observer/Subject.
Jamie Madill70aeda42018-08-20 12:17:40 -04006624 if (programObject->isInUse())
6625 {
6626 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006627 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006628 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006629}
6630
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006631GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6632{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006633 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6634 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006635
Jamie Madill70b5bb02017-08-28 13:32:37 -04006636 Sync *syncObject = getSync(syncHandle);
Jamie Madill7c985f52018-11-29 18:16:17 -05006637 if (syncObject->set(this, condition, flags) == angle::Result::Stop)
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006638 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006639 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006640 return nullptr;
6641 }
6642
Jamie Madill70b5bb02017-08-28 13:32:37 -04006643 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006644}
6645
6646GLboolean Context::isSync(GLsync sync)
6647{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006648 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006649}
6650
6651GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6652{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006653 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006654
6655 GLenum result = GL_WAIT_FAILED;
Jamie Madill7c985f52018-11-29 18:16:17 -05006656 if (syncObject->clientWait(this, flags, timeout, &result) == angle::Result::Stop)
Jamie Madill4f6592f2018-11-27 16:37:45 -05006657 {
6658 return GL_WAIT_FAILED;
6659 }
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006660 return result;
6661}
6662
6663void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6664{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006665 Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006666 ANGLE_CONTEXT_TRY(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006667}
6668
6669void Context::getInteger64v(GLenum pname, GLint64 *params)
6670{
6671 GLenum nativeType = GL_NONE;
6672 unsigned int numParams = 0;
6673 getQueryParameterInfo(pname, &nativeType, &numParams);
6674
6675 if (nativeType == GL_INT_64_ANGLEX)
6676 {
6677 getInteger64vImpl(pname, params);
6678 }
6679 else
6680 {
6681 CastStateValues(this, nativeType, pname, numParams, params);
6682 }
6683}
6684
Brandon Jones59770802018-04-02 13:18:42 -07006685void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6686{
6687 getInteger64v(pname, data);
6688}
6689
Corentin Wallez336129f2017-10-17 15:55:40 -04006690void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006691{
6692 Buffer *buffer = mGLState.getTargetBuffer(target);
6693 QueryBufferParameteri64v(buffer, pname, params);
6694}
6695
Brandon Jones59770802018-04-02 13:18:42 -07006696void Context::getBufferParameteri64vRobust(BufferBinding target,
6697 GLenum pname,
6698 GLsizei bufSize,
6699 GLsizei *length,
6700 GLint64 *params)
6701{
6702 getBufferParameteri64v(target, pname, params);
6703}
6704
Jamie Madill3ef140a2017-08-26 23:11:21 -04006705void Context::genSamplers(GLsizei count, GLuint *samplers)
6706{
6707 for (int i = 0; i < count; i++)
6708 {
6709 samplers[i] = mState.mSamplers->createSampler();
6710 }
6711}
6712
6713void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6714{
6715 for (int i = 0; i < count; i++)
6716 {
6717 GLuint sampler = samplers[i];
6718
6719 if (mState.mSamplers->getSampler(sampler))
6720 {
6721 detachSampler(sampler);
6722 }
6723
6724 mState.mSamplers->deleteObject(this, sampler);
6725 }
6726}
6727
6728void Context::getInternalformativ(GLenum target,
6729 GLenum internalformat,
6730 GLenum pname,
6731 GLsizei bufSize,
6732 GLint *params)
6733{
6734 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6735 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6736}
6737
Brandon Jones59770802018-04-02 13:18:42 -07006738void Context::getInternalformativRobust(GLenum target,
6739 GLenum internalformat,
6740 GLenum pname,
6741 GLsizei bufSize,
6742 GLsizei *length,
6743 GLint *params)
6744{
6745 getInternalformativ(target, internalformat, pname, bufSize, params);
6746}
6747
Jiajia Qin5451d532017-11-16 17:16:34 +08006748void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6749{
6750 programUniform1iv(program, location, 1, &v0);
6751}
6752
6753void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6754{
6755 GLint xy[2] = {v0, v1};
6756 programUniform2iv(program, location, 1, xy);
6757}
6758
6759void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6760{
6761 GLint xyz[3] = {v0, v1, v2};
6762 programUniform3iv(program, location, 1, xyz);
6763}
6764
6765void Context::programUniform4i(GLuint program,
6766 GLint location,
6767 GLint v0,
6768 GLint v1,
6769 GLint v2,
6770 GLint v3)
6771{
6772 GLint xyzw[4] = {v0, v1, v2, v3};
6773 programUniform4iv(program, location, 1, xyzw);
6774}
6775
6776void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6777{
6778 programUniform1uiv(program, location, 1, &v0);
6779}
6780
6781void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6782{
6783 GLuint xy[2] = {v0, v1};
6784 programUniform2uiv(program, location, 1, xy);
6785}
6786
6787void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6788{
6789 GLuint xyz[3] = {v0, v1, v2};
6790 programUniform3uiv(program, location, 1, xyz);
6791}
6792
6793void Context::programUniform4ui(GLuint program,
6794 GLint location,
6795 GLuint v0,
6796 GLuint v1,
6797 GLuint v2,
6798 GLuint v3)
6799{
6800 GLuint xyzw[4] = {v0, v1, v2, v3};
6801 programUniform4uiv(program, location, 1, xyzw);
6802}
6803
6804void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6805{
6806 programUniform1fv(program, location, 1, &v0);
6807}
6808
6809void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6810{
6811 GLfloat xy[2] = {v0, v1};
6812 programUniform2fv(program, location, 1, xy);
6813}
6814
6815void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6816{
6817 GLfloat xyz[3] = {v0, v1, v2};
6818 programUniform3fv(program, location, 1, xyz);
6819}
6820
6821void Context::programUniform4f(GLuint program,
6822 GLint location,
6823 GLfloat v0,
6824 GLfloat v1,
6825 GLfloat v2,
6826 GLfloat v3)
6827{
6828 GLfloat xyzw[4] = {v0, v1, v2, v3};
6829 programUniform4fv(program, location, 1, xyzw);
6830}
6831
Jamie Madill81c2e252017-09-09 23:32:46 -04006832void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6833{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006834 Program *programObject = getProgramResolveLink(program);
Jamie Madill81c2e252017-09-09 23:32:46 -04006835 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006836 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006837}
6838
Jiajia Qin5451d532017-11-16 17:16:34 +08006839void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6840{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006841 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006842 ASSERT(programObject);
6843 programObject->setUniform2iv(location, count, value);
6844}
6845
6846void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6847{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006848 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006849 ASSERT(programObject);
6850 programObject->setUniform3iv(location, count, value);
6851}
6852
6853void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6854{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006855 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006856 ASSERT(programObject);
6857 programObject->setUniform4iv(location, count, value);
6858}
6859
6860void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6861{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006862 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006863 ASSERT(programObject);
6864 programObject->setUniform1uiv(location, count, value);
6865}
6866
6867void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6868{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006869 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006870 ASSERT(programObject);
6871 programObject->setUniform2uiv(location, count, value);
6872}
6873
6874void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6875{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006876 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006877 ASSERT(programObject);
6878 programObject->setUniform3uiv(location, count, value);
6879}
6880
6881void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6882{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006883 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006884 ASSERT(programObject);
6885 programObject->setUniform4uiv(location, count, value);
6886}
6887
6888void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6889{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006890 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006891 ASSERT(programObject);
6892 programObject->setUniform1fv(location, count, value);
6893}
6894
6895void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6896{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006897 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006898 ASSERT(programObject);
6899 programObject->setUniform2fv(location, count, value);
6900}
6901
6902void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6903{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006904 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006905 ASSERT(programObject);
6906 programObject->setUniform3fv(location, count, value);
6907}
6908
6909void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6910{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006911 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006912 ASSERT(programObject);
6913 programObject->setUniform4fv(location, count, value);
6914}
6915
6916void Context::programUniformMatrix2fv(GLuint program,
6917 GLint location,
6918 GLsizei count,
6919 GLboolean transpose,
6920 const GLfloat *value)
6921{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006922 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006923 ASSERT(programObject);
6924 programObject->setUniformMatrix2fv(location, count, transpose, value);
6925}
6926
6927void Context::programUniformMatrix3fv(GLuint program,
6928 GLint location,
6929 GLsizei count,
6930 GLboolean transpose,
6931 const GLfloat *value)
6932{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006933 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006934 ASSERT(programObject);
6935 programObject->setUniformMatrix3fv(location, count, transpose, value);
6936}
6937
6938void Context::programUniformMatrix4fv(GLuint program,
6939 GLint location,
6940 GLsizei count,
6941 GLboolean transpose,
6942 const GLfloat *value)
6943{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006944 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006945 ASSERT(programObject);
6946 programObject->setUniformMatrix4fv(location, count, transpose, value);
6947}
6948
6949void Context::programUniformMatrix2x3fv(GLuint program,
6950 GLint location,
6951 GLsizei count,
6952 GLboolean transpose,
6953 const GLfloat *value)
6954{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006955 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006956 ASSERT(programObject);
6957 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6958}
6959
6960void Context::programUniformMatrix3x2fv(GLuint program,
6961 GLint location,
6962 GLsizei count,
6963 GLboolean transpose,
6964 const GLfloat *value)
6965{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006966 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006967 ASSERT(programObject);
6968 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6969}
6970
6971void Context::programUniformMatrix2x4fv(GLuint program,
6972 GLint location,
6973 GLsizei count,
6974 GLboolean transpose,
6975 const GLfloat *value)
6976{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006977 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006978 ASSERT(programObject);
6979 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6980}
6981
6982void Context::programUniformMatrix4x2fv(GLuint program,
6983 GLint location,
6984 GLsizei count,
6985 GLboolean transpose,
6986 const GLfloat *value)
6987{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006988 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006989 ASSERT(programObject);
6990 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6991}
6992
6993void Context::programUniformMatrix3x4fv(GLuint program,
6994 GLint location,
6995 GLsizei count,
6996 GLboolean transpose,
6997 const GLfloat *value)
6998{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006999 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08007000 ASSERT(programObject);
7001 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
7002}
7003
7004void Context::programUniformMatrix4x3fv(GLuint program,
7005 GLint location,
7006 GLsizei count,
7007 GLboolean transpose,
7008 const GLfloat *value)
7009{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007010 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08007011 ASSERT(programObject);
7012 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
7013}
7014
James Darpiniane8a93c62018-01-04 18:02:24 -08007015bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
7016{
7017 return mGLState.isCurrentTransformFeedback(tf);
7018}
James Darpiniane8a93c62018-01-04 18:02:24 -08007019
Yunchao Hea336b902017-08-02 16:05:21 +08007020void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
7021{
7022 for (int i = 0; i < count; i++)
7023 {
7024 pipelines[i] = createProgramPipeline();
7025 }
7026}
7027
7028void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
7029{
7030 for (int i = 0; i < count; i++)
7031 {
7032 if (pipelines[i] != 0)
7033 {
7034 deleteProgramPipeline(pipelines[i]);
7035 }
7036 }
7037}
7038
7039GLboolean Context::isProgramPipeline(GLuint pipeline)
7040{
7041 if (pipeline == 0)
7042 {
7043 return GL_FALSE;
7044 }
7045
7046 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
7047}
7048
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007049void Context::finishFenceNV(GLuint fence)
7050{
7051 FenceNV *fenceObject = getFenceNV(fence);
7052
7053 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madill4f6592f2018-11-27 16:37:45 -05007054 ANGLE_CONTEXT_TRY(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007055}
7056
7057void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
7058{
7059 FenceNV *fenceObject = getFenceNV(fence);
7060
7061 ASSERT(fenceObject && fenceObject->isSet());
7062
7063 switch (pname)
7064 {
7065 case GL_FENCE_STATUS_NV:
7066 {
7067 // GL_NV_fence spec:
7068 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
7069 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
7070 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
7071 GLboolean status = GL_TRUE;
7072 if (fenceObject->getStatus() != GL_TRUE)
7073 {
Jamie Madilla0691b72018-07-25 10:41:22 -04007074 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007075 }
7076 *params = status;
7077 break;
7078 }
7079
7080 case GL_FENCE_CONDITION_NV:
7081 {
7082 *params = static_cast<GLint>(fenceObject->getCondition());
7083 break;
7084 }
7085
7086 default:
7087 UNREACHABLE();
7088 }
7089}
7090
7091void Context::getTranslatedShaderSource(GLuint shader,
7092 GLsizei bufsize,
7093 GLsizei *length,
7094 GLchar *source)
7095{
7096 Shader *shaderObject = getShader(shader);
7097 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08007098 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007099}
7100
7101void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
7102{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007103 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007104 ASSERT(programObject);
7105
7106 programObject->getUniformfv(this, location, params);
7107}
7108
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007109void Context::getnUniformfvRobust(GLuint program,
7110 GLint location,
7111 GLsizei bufSize,
7112 GLsizei *length,
7113 GLfloat *params)
7114{
7115 UNIMPLEMENTED();
7116}
7117
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007118void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
7119{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007120 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007121 ASSERT(programObject);
7122
7123 programObject->getUniformiv(this, location, params);
7124}
7125
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007126void Context::getnUniformivRobust(GLuint program,
7127 GLint location,
7128 GLsizei bufSize,
7129 GLsizei *length,
7130 GLint *params)
7131{
7132 UNIMPLEMENTED();
7133}
7134
7135void Context::getnUniformuivRobust(GLuint program,
7136 GLint location,
7137 GLsizei bufSize,
7138 GLsizei *length,
7139 GLuint *params)
7140{
7141 UNIMPLEMENTED();
7142}
7143
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007144GLboolean Context::isFenceNV(GLuint fence)
7145{
7146 FenceNV *fenceObject = getFenceNV(fence);
7147
7148 if (fenceObject == nullptr)
7149 {
7150 return GL_FALSE;
7151 }
7152
7153 // GL_NV_fence spec:
7154 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
7155 // existing fence.
7156 return fenceObject->isSet();
7157}
7158
7159void Context::readnPixels(GLint x,
7160 GLint y,
7161 GLsizei width,
7162 GLsizei height,
7163 GLenum format,
7164 GLenum type,
7165 GLsizei bufSize,
7166 void *data)
7167{
7168 return readPixels(x, y, width, height, format, type, data);
7169}
7170
Jamie Madill007530e2017-12-28 14:27:04 -05007171void Context::setFenceNV(GLuint fence, GLenum condition)
7172{
7173 ASSERT(condition == GL_ALL_COMPLETED_NV);
7174
7175 FenceNV *fenceObject = getFenceNV(fence);
7176 ASSERT(fenceObject != nullptr);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007177 ANGLE_CONTEXT_TRY(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05007178}
7179
7180GLboolean Context::testFenceNV(GLuint fence)
7181{
7182 FenceNV *fenceObject = getFenceNV(fence);
7183
7184 ASSERT(fenceObject != nullptr);
7185 ASSERT(fenceObject->isSet() == GL_TRUE);
7186
7187 GLboolean result = GL_TRUE;
Jamie Madill7c985f52018-11-29 18:16:17 -05007188 if (fenceObject->test(this, &result) == angle::Result::Stop)
Jamie Madill007530e2017-12-28 14:27:04 -05007189 {
Jamie Madill007530e2017-12-28 14:27:04 -05007190 return GL_TRUE;
7191 }
7192
7193 return result;
7194}
7195
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007196void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007197{
7198 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07007199 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007200 ANGLE_CONTEXT_TRY(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007201}
7202
Jamie Madillfa920eb2018-01-04 11:45:50 -05007203void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007204{
7205 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07007206 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007207 ANGLE_CONTEXT_TRY(renderbuffer->setStorageEGLImageTarget(this, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007208}
7209
Jamie Madillfa920eb2018-01-04 11:45:50 -05007210void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
7211{
7212 UNIMPLEMENTED();
7213}
7214
Jamie Madill5b772312018-03-08 20:28:32 -05007215bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
7216{
7217 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
7218 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
7219 // to the fact that it is stored internally as a float, and so would require conversion
7220 // if returned from Context::getIntegerv. Since this conversion is already implemented
7221 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
7222 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
7223 // application.
7224 switch (pname)
7225 {
7226 case GL_COMPRESSED_TEXTURE_FORMATS:
7227 {
7228 *type = GL_INT;
7229 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
7230 return true;
7231 }
7232 case GL_SHADER_BINARY_FORMATS:
7233 {
7234 *type = GL_INT;
7235 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
7236 return true;
7237 }
7238
7239 case GL_MAX_VERTEX_ATTRIBS:
7240 case GL_MAX_VERTEX_UNIFORM_VECTORS:
7241 case GL_MAX_VARYING_VECTORS:
7242 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
7243 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
7244 case GL_MAX_TEXTURE_IMAGE_UNITS:
7245 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
7246 case GL_MAX_RENDERBUFFER_SIZE:
7247 case GL_NUM_SHADER_BINARY_FORMATS:
7248 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
7249 case GL_ARRAY_BUFFER_BINDING:
Jamie Madillef9fcd92018-11-28 14:03:59 -05007250 case GL_FRAMEBUFFER_BINDING: // GL_FRAMEBUFFER_BINDING now equivalent to
7251 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
Jamie Madill5b772312018-03-08 20:28:32 -05007252 case GL_RENDERBUFFER_BINDING:
7253 case GL_CURRENT_PROGRAM:
7254 case GL_PACK_ALIGNMENT:
7255 case GL_UNPACK_ALIGNMENT:
7256 case GL_GENERATE_MIPMAP_HINT:
7257 case GL_RED_BITS:
7258 case GL_GREEN_BITS:
7259 case GL_BLUE_BITS:
7260 case GL_ALPHA_BITS:
7261 case GL_DEPTH_BITS:
7262 case GL_STENCIL_BITS:
7263 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
7264 case GL_CULL_FACE_MODE:
7265 case GL_FRONT_FACE:
7266 case GL_ACTIVE_TEXTURE:
7267 case GL_STENCIL_FUNC:
7268 case GL_STENCIL_VALUE_MASK:
7269 case GL_STENCIL_REF:
7270 case GL_STENCIL_FAIL:
7271 case GL_STENCIL_PASS_DEPTH_FAIL:
7272 case GL_STENCIL_PASS_DEPTH_PASS:
7273 case GL_STENCIL_BACK_FUNC:
7274 case GL_STENCIL_BACK_VALUE_MASK:
7275 case GL_STENCIL_BACK_REF:
7276 case GL_STENCIL_BACK_FAIL:
7277 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
7278 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
7279 case GL_DEPTH_FUNC:
7280 case GL_BLEND_SRC_RGB:
7281 case GL_BLEND_SRC_ALPHA:
7282 case GL_BLEND_DST_RGB:
7283 case GL_BLEND_DST_ALPHA:
7284 case GL_BLEND_EQUATION_RGB:
7285 case GL_BLEND_EQUATION_ALPHA:
7286 case GL_STENCIL_WRITEMASK:
7287 case GL_STENCIL_BACK_WRITEMASK:
7288 case GL_STENCIL_CLEAR_VALUE:
7289 case GL_SUBPIXEL_BITS:
7290 case GL_MAX_TEXTURE_SIZE:
7291 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
7292 case GL_SAMPLE_BUFFERS:
7293 case GL_SAMPLES:
7294 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
7295 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
7296 case GL_TEXTURE_BINDING_2D:
7297 case GL_TEXTURE_BINDING_CUBE_MAP:
7298 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
7299 {
7300 *type = GL_INT;
7301 *numParams = 1;
7302 return true;
7303 }
7304 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
7305 {
7306 if (!getExtensions().packReverseRowOrder)
7307 {
7308 return false;
7309 }
7310 *type = GL_INT;
7311 *numParams = 1;
7312 return true;
7313 }
7314 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7315 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7316 {
7317 if (!getExtensions().textureRectangle)
7318 {
7319 return false;
7320 }
7321 *type = GL_INT;
7322 *numParams = 1;
7323 return true;
7324 }
7325 case GL_MAX_DRAW_BUFFERS_EXT:
7326 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7327 {
7328 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7329 {
7330 return false;
7331 }
7332 *type = GL_INT;
7333 *numParams = 1;
7334 return true;
7335 }
7336 case GL_MAX_VIEWPORT_DIMS:
7337 {
7338 *type = GL_INT;
7339 *numParams = 2;
7340 return true;
7341 }
7342 case GL_VIEWPORT:
7343 case GL_SCISSOR_BOX:
7344 {
7345 *type = GL_INT;
7346 *numParams = 4;
7347 return true;
7348 }
7349 case GL_SHADER_COMPILER:
7350 case GL_SAMPLE_COVERAGE_INVERT:
7351 case GL_DEPTH_WRITEMASK:
7352 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7353 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7354 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7355 // bool-natural
7356 case GL_SAMPLE_COVERAGE:
7357 case GL_SCISSOR_TEST:
7358 case GL_STENCIL_TEST:
7359 case GL_DEPTH_TEST:
7360 case GL_BLEND:
7361 case GL_DITHER:
7362 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7363 {
7364 *type = GL_BOOL;
7365 *numParams = 1;
7366 return true;
7367 }
7368 case GL_COLOR_WRITEMASK:
7369 {
7370 *type = GL_BOOL;
7371 *numParams = 4;
7372 return true;
7373 }
7374 case GL_POLYGON_OFFSET_FACTOR:
7375 case GL_POLYGON_OFFSET_UNITS:
7376 case GL_SAMPLE_COVERAGE_VALUE:
7377 case GL_DEPTH_CLEAR_VALUE:
7378 case GL_LINE_WIDTH:
7379 {
7380 *type = GL_FLOAT;
7381 *numParams = 1;
7382 return true;
7383 }
7384 case GL_ALIASED_LINE_WIDTH_RANGE:
7385 case GL_ALIASED_POINT_SIZE_RANGE:
7386 case GL_DEPTH_RANGE:
7387 {
7388 *type = GL_FLOAT;
7389 *numParams = 2;
7390 return true;
7391 }
7392 case GL_COLOR_CLEAR_VALUE:
7393 case GL_BLEND_COLOR:
7394 {
7395 *type = GL_FLOAT;
7396 *numParams = 4;
7397 return true;
7398 }
7399 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7400 if (!getExtensions().textureFilterAnisotropic)
7401 {
7402 return false;
7403 }
7404 *type = GL_FLOAT;
7405 *numParams = 1;
7406 return true;
7407 case GL_TIMESTAMP_EXT:
7408 if (!getExtensions().disjointTimerQuery)
7409 {
7410 return false;
7411 }
7412 *type = GL_INT_64_ANGLEX;
7413 *numParams = 1;
7414 return true;
7415 case GL_GPU_DISJOINT_EXT:
7416 if (!getExtensions().disjointTimerQuery)
7417 {
7418 return false;
7419 }
7420 *type = GL_INT;
7421 *numParams = 1;
7422 return true;
7423 case GL_COVERAGE_MODULATION_CHROMIUM:
7424 if (!getExtensions().framebufferMixedSamples)
7425 {
7426 return false;
7427 }
7428 *type = GL_INT;
7429 *numParams = 1;
7430 return true;
7431 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7432 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7433 {
7434 return false;
7435 }
7436 *type = GL_INT;
7437 *numParams = 1;
7438 return true;
7439 }
7440
7441 if (getExtensions().debug)
7442 {
7443 switch (pname)
7444 {
7445 case GL_DEBUG_LOGGED_MESSAGES:
7446 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7447 case GL_DEBUG_GROUP_STACK_DEPTH:
7448 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7449 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7450 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7451 case GL_MAX_LABEL_LENGTH:
7452 *type = GL_INT;
7453 *numParams = 1;
7454 return true;
7455
7456 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7457 case GL_DEBUG_OUTPUT:
7458 *type = GL_BOOL;
7459 *numParams = 1;
7460 return true;
7461 }
7462 }
7463
7464 if (getExtensions().multisampleCompatibility)
7465 {
7466 switch (pname)
7467 {
7468 case GL_MULTISAMPLE_EXT:
7469 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7470 *type = GL_BOOL;
7471 *numParams = 1;
7472 return true;
7473 }
7474 }
7475
7476 if (getExtensions().pathRendering)
7477 {
7478 switch (pname)
7479 {
7480 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7481 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7482 *type = GL_FLOAT;
7483 *numParams = 16;
7484 return true;
7485 }
7486 }
7487
7488 if (getExtensions().bindGeneratesResource)
7489 {
7490 switch (pname)
7491 {
7492 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7493 *type = GL_BOOL;
7494 *numParams = 1;
7495 return true;
7496 }
7497 }
7498
7499 if (getExtensions().clientArrays)
7500 {
7501 switch (pname)
7502 {
7503 case GL_CLIENT_ARRAYS_ANGLE:
7504 *type = GL_BOOL;
7505 *numParams = 1;
7506 return true;
7507 }
7508 }
7509
7510 if (getExtensions().sRGBWriteControl)
7511 {
7512 switch (pname)
7513 {
7514 case GL_FRAMEBUFFER_SRGB_EXT:
7515 *type = GL_BOOL;
7516 *numParams = 1;
7517 return true;
7518 }
7519 }
7520
7521 if (getExtensions().robustResourceInitialization &&
7522 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7523 {
7524 *type = GL_BOOL;
7525 *numParams = 1;
7526 return true;
7527 }
7528
7529 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7530 {
7531 *type = GL_BOOL;
7532 *numParams = 1;
7533 return true;
7534 }
7535
jchen1082af6202018-06-22 10:59:52 +08007536 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7537 {
7538 *type = GL_INT;
7539 *numParams = 1;
7540 return true;
7541 }
7542
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007543 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7544 {
7545 *type = GL_INT;
7546 *numParams = 1;
7547 return true;
7548 }
7549
Jamie Madill5b772312018-03-08 20:28:32 -05007550 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7551 switch (pname)
7552 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05007553 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE equivalent to FRAMEBUFFER_BINDING
Jamie Madill5b772312018-03-08 20:28:32 -05007554 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7555 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7556 {
7557 return false;
7558 }
7559 *type = GL_INT;
7560 *numParams = 1;
7561 return true;
7562
7563 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7564 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7565 {
7566 return false;
7567 }
7568 *type = GL_INT;
7569 *numParams = 1;
7570 return true;
7571
7572 case GL_PROGRAM_BINARY_FORMATS_OES:
7573 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7574 {
7575 return false;
7576 }
7577 *type = GL_INT;
7578 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7579 return true;
7580
7581 case GL_PACK_ROW_LENGTH:
7582 case GL_PACK_SKIP_ROWS:
7583 case GL_PACK_SKIP_PIXELS:
7584 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7585 {
7586 return false;
7587 }
7588 *type = GL_INT;
7589 *numParams = 1;
7590 return true;
7591 case GL_UNPACK_ROW_LENGTH:
7592 case GL_UNPACK_SKIP_ROWS:
7593 case GL_UNPACK_SKIP_PIXELS:
7594 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7595 {
7596 return false;
7597 }
7598 *type = GL_INT;
7599 *numParams = 1;
7600 return true;
7601 case GL_VERTEX_ARRAY_BINDING:
7602 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7603 {
7604 return false;
7605 }
7606 *type = GL_INT;
7607 *numParams = 1;
7608 return true;
7609 case GL_PIXEL_PACK_BUFFER_BINDING:
7610 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7611 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7612 {
7613 return false;
7614 }
7615 *type = GL_INT;
7616 *numParams = 1;
7617 return true;
7618 case GL_MAX_SAMPLES:
7619 {
7620 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7621 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7622 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7623 {
7624 return false;
7625 }
7626 *type = GL_INT;
7627 *numParams = 1;
7628 return true;
7629
7630 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7631 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7632 {
7633 return false;
7634 }
7635 *type = GL_INT;
7636 *numParams = 1;
7637 return true;
7638 }
7639 }
7640
7641 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7642 {
7643 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7644 {
7645 return false;
7646 }
7647 *type = GL_INT;
7648 *numParams = 1;
7649 return true;
7650 }
7651
7652 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7653 {
7654 *type = GL_INT;
7655 *numParams = 1;
7656 return true;
7657 }
7658
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007659 if (getClientVersion() < Version(2, 0))
7660 {
7661 switch (pname)
7662 {
7663 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007664 case GL_CLIENT_ACTIVE_TEXTURE:
7665 case GL_MATRIX_MODE:
7666 case GL_MAX_TEXTURE_UNITS:
7667 case GL_MAX_MODELVIEW_STACK_DEPTH:
7668 case GL_MAX_PROJECTION_STACK_DEPTH:
7669 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007670 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007671 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007672 case GL_VERTEX_ARRAY_STRIDE:
7673 case GL_NORMAL_ARRAY_STRIDE:
7674 case GL_COLOR_ARRAY_STRIDE:
7675 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7676 case GL_VERTEX_ARRAY_SIZE:
7677 case GL_COLOR_ARRAY_SIZE:
7678 case GL_TEXTURE_COORD_ARRAY_SIZE:
7679 case GL_VERTEX_ARRAY_TYPE:
7680 case GL_NORMAL_ARRAY_TYPE:
7681 case GL_COLOR_ARRAY_TYPE:
7682 case GL_TEXTURE_COORD_ARRAY_TYPE:
7683 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7684 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7685 case GL_COLOR_ARRAY_BUFFER_BINDING:
7686 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7687 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7688 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7689 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007690 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007691 case GL_MODELVIEW_STACK_DEPTH:
7692 case GL_PROJECTION_STACK_DEPTH:
7693 case GL_TEXTURE_STACK_DEPTH:
7694 case GL_LOGIC_OP_MODE:
7695 case GL_BLEND_SRC:
7696 case GL_BLEND_DST:
7697 case GL_PERSPECTIVE_CORRECTION_HINT:
7698 case GL_POINT_SMOOTH_HINT:
7699 case GL_LINE_SMOOTH_HINT:
7700 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007701 *type = GL_INT;
7702 *numParams = 1;
7703 return true;
7704 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007705 case GL_FOG_DENSITY:
7706 case GL_FOG_START:
7707 case GL_FOG_END:
7708 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007709 case GL_POINT_SIZE:
7710 case GL_POINT_SIZE_MIN:
7711 case GL_POINT_SIZE_MAX:
7712 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007713 *type = GL_FLOAT;
7714 *numParams = 1;
7715 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007716 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007717 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007718 *type = GL_FLOAT;
7719 *numParams = 2;
7720 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007721 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007722 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007723 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007724 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007725 *type = GL_FLOAT;
7726 *numParams = 4;
7727 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007728 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007729 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007730 *type = GL_FLOAT;
7731 *numParams = 3;
7732 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007733 case GL_MODELVIEW_MATRIX:
7734 case GL_PROJECTION_MATRIX:
7735 case GL_TEXTURE_MATRIX:
7736 *type = GL_FLOAT;
7737 *numParams = 16;
7738 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007739 case GL_LIGHT_MODEL_TWO_SIDE:
7740 *type = GL_BOOL;
7741 *numParams = 1;
7742 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007743 }
7744 }
7745
Jamie Madill5b772312018-03-08 20:28:32 -05007746 if (getClientVersion() < Version(3, 0))
7747 {
7748 return false;
7749 }
7750
7751 // Check for ES3.0+ parameter names
7752 switch (pname)
7753 {
7754 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7755 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7756 case GL_UNIFORM_BUFFER_BINDING:
7757 case GL_TRANSFORM_FEEDBACK_BINDING:
7758 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7759 case GL_COPY_READ_BUFFER_BINDING:
7760 case GL_COPY_WRITE_BUFFER_BINDING:
7761 case GL_SAMPLER_BINDING:
7762 case GL_READ_BUFFER:
7763 case GL_TEXTURE_BINDING_3D:
7764 case GL_TEXTURE_BINDING_2D_ARRAY:
7765 case GL_MAX_3D_TEXTURE_SIZE:
7766 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7767 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7768 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7769 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7770 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7771 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7772 case GL_MAX_VARYING_COMPONENTS:
7773 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7774 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7775 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7776 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7777 case GL_NUM_EXTENSIONS:
7778 case GL_MAJOR_VERSION:
7779 case GL_MINOR_VERSION:
7780 case GL_MAX_ELEMENTS_INDICES:
7781 case GL_MAX_ELEMENTS_VERTICES:
7782 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7783 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7784 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7785 case GL_UNPACK_IMAGE_HEIGHT:
7786 case GL_UNPACK_SKIP_IMAGES:
7787 {
7788 *type = GL_INT;
7789 *numParams = 1;
7790 return true;
7791 }
7792
7793 case GL_MAX_ELEMENT_INDEX:
7794 case GL_MAX_UNIFORM_BLOCK_SIZE:
7795 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7796 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7797 case GL_MAX_SERVER_WAIT_TIMEOUT:
7798 {
7799 *type = GL_INT_64_ANGLEX;
7800 *numParams = 1;
7801 return true;
7802 }
7803
7804 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7805 case GL_TRANSFORM_FEEDBACK_PAUSED:
7806 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7807 case GL_RASTERIZER_DISCARD:
7808 {
7809 *type = GL_BOOL;
7810 *numParams = 1;
7811 return true;
7812 }
7813
7814 case GL_MAX_TEXTURE_LOD_BIAS:
7815 {
7816 *type = GL_FLOAT;
7817 *numParams = 1;
7818 return true;
7819 }
7820 }
7821
7822 if (getExtensions().requestExtension)
7823 {
7824 switch (pname)
7825 {
7826 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7827 *type = GL_INT;
7828 *numParams = 1;
7829 return true;
7830 }
7831 }
7832
Yizhou Jiang7818a852018-09-06 15:02:04 +08007833 if (getExtensions().textureMultisample)
7834 {
7835 switch (pname)
7836 {
7837 case GL_MAX_COLOR_TEXTURE_SAMPLES_ANGLE:
7838 case GL_MAX_INTEGER_SAMPLES_ANGLE:
7839 case GL_MAX_DEPTH_TEXTURE_SAMPLES_ANGLE:
7840 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ANGLE:
Yizhou Jiang7310da32018-11-05 14:40:01 +08007841 case GL_MAX_SAMPLE_MASK_WORDS:
Yizhou Jiang7818a852018-09-06 15:02:04 +08007842 *type = GL_INT;
7843 *numParams = 1;
7844 return true;
7845 }
7846 }
7847
Jamie Madill5b772312018-03-08 20:28:32 -05007848 if (getClientVersion() < Version(3, 1))
7849 {
7850 return false;
7851 }
7852
7853 switch (pname)
7854 {
7855 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7856 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7857 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7858 case GL_MAX_FRAMEBUFFER_WIDTH:
7859 case GL_MAX_FRAMEBUFFER_HEIGHT:
7860 case GL_MAX_FRAMEBUFFER_SAMPLES:
7861 case GL_MAX_SAMPLE_MASK_WORDS:
7862 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7863 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7864 case GL_MAX_INTEGER_SAMPLES:
7865 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7866 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7867 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7868 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7869 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7870 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7871 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7872 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7873 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7874 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7875 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7876 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7877 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7878 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7879 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7880 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7881 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7882 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7883 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7884 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7885 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7886 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7887 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7888 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7889 case GL_MAX_UNIFORM_LOCATIONS:
7890 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7891 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7892 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7893 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7894 case GL_MAX_IMAGE_UNITS:
7895 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7896 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7897 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7898 case GL_SHADER_STORAGE_BUFFER_BINDING:
7899 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7900 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007901 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007902 *type = GL_INT;
7903 *numParams = 1;
7904 return true;
7905 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7906 *type = GL_INT_64_ANGLEX;
7907 *numParams = 1;
7908 return true;
7909 case GL_SAMPLE_MASK:
7910 *type = GL_BOOL;
7911 *numParams = 1;
7912 return true;
7913 }
7914
7915 if (getExtensions().geometryShader)
7916 {
7917 switch (pname)
7918 {
7919 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7920 case GL_LAYER_PROVOKING_VERTEX_EXT:
7921 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7922 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7923 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7924 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7925 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7926 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7927 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7928 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7929 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7930 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7931 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7932 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7933 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7934 *type = GL_INT;
7935 *numParams = 1;
7936 return true;
7937 }
7938 }
7939
7940 return false;
7941}
7942
7943bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7944{
7945 if (getClientVersion() < Version(3, 0))
7946 {
7947 return false;
7948 }
7949
7950 switch (target)
7951 {
7952 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7953 case GL_UNIFORM_BUFFER_BINDING:
7954 {
7955 *type = GL_INT;
7956 *numParams = 1;
7957 return true;
7958 }
7959 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7960 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7961 case GL_UNIFORM_BUFFER_START:
7962 case GL_UNIFORM_BUFFER_SIZE:
7963 {
7964 *type = GL_INT_64_ANGLEX;
7965 *numParams = 1;
7966 return true;
7967 }
7968 }
7969
7970 if (getClientVersion() < Version(3, 1))
7971 {
7972 return false;
7973 }
7974
7975 switch (target)
7976 {
7977 case GL_IMAGE_BINDING_LAYERED:
7978 {
7979 *type = GL_BOOL;
7980 *numParams = 1;
7981 return true;
7982 }
7983 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7984 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7985 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7986 case GL_SHADER_STORAGE_BUFFER_BINDING:
7987 case GL_VERTEX_BINDING_BUFFER:
7988 case GL_VERTEX_BINDING_DIVISOR:
7989 case GL_VERTEX_BINDING_OFFSET:
7990 case GL_VERTEX_BINDING_STRIDE:
7991 case GL_SAMPLE_MASK_VALUE:
7992 case GL_IMAGE_BINDING_NAME:
7993 case GL_IMAGE_BINDING_LEVEL:
7994 case GL_IMAGE_BINDING_LAYER:
7995 case GL_IMAGE_BINDING_ACCESS:
7996 case GL_IMAGE_BINDING_FORMAT:
7997 {
7998 *type = GL_INT;
7999 *numParams = 1;
8000 return true;
8001 }
8002 case GL_ATOMIC_COUNTER_BUFFER_START:
8003 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
8004 case GL_SHADER_STORAGE_BUFFER_START:
8005 case GL_SHADER_STORAGE_BUFFER_SIZE:
8006 {
8007 *type = GL_INT_64_ANGLEX;
8008 *numParams = 1;
8009 return true;
8010 }
8011 }
8012
8013 return false;
8014}
8015
Jamie Madill44a6fbf2018-10-02 13:38:56 -04008016Program *Context::getProgramNoResolveLink(GLuint handle) const
Jamie Madill5b772312018-03-08 20:28:32 -05008017{
8018 return mState.mShaderPrograms->getProgram(handle);
8019}
8020
8021Shader *Context::getShader(GLuint handle) const
8022{
8023 return mState.mShaderPrograms->getShader(handle);
8024}
8025
Jamie Madill5b772312018-03-08 20:28:32 -05008026bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
8027{
8028 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
8029}
8030
8031bool Context::isFramebufferGenerated(GLuint framebuffer) const
8032{
8033 return mState.mFramebuffers->isHandleGenerated(framebuffer);
8034}
8035
8036bool Context::isProgramPipelineGenerated(GLuint pipeline) const
8037{
8038 return mState.mPipelines->isHandleGenerated(pipeline);
8039}
8040
8041bool Context::usingDisplayTextureShareGroup() const
8042{
8043 return mDisplayTextureShareGroup;
8044}
8045
8046GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
8047{
8048 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
8049 internalformat == GL_DEPTH_STENCIL
8050 ? GL_DEPTH24_STENCIL8
8051 : internalformat;
8052}
8053
jchen1082af6202018-06-22 10:59:52 +08008054void Context::maxShaderCompilerThreads(GLuint count)
8055{
jchen107ae70d82018-07-06 13:47:01 +08008056 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08008057 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08008058 // A count of zero specifies a request for no parallel compiling or linking.
8059 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
8060 {
8061 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
8062 }
8063 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08008064}
8065
Jamie Madill2eb65032018-07-30 10:25:57 -04008066bool Context::isGLES1() const
8067{
8068 return mState.getClientVersion() < Version(2, 0);
8069}
8070
Jamie Madilla11819d2018-07-30 10:26:01 -04008071void Context::onSubjectStateChange(const Context *context,
8072 angle::SubjectIndex index,
8073 angle::SubjectMessage message)
8074{
Jamie Madilla11819d2018-07-30 10:26:01 -04008075 switch (index)
8076 {
8077 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008078 switch (message)
8079 {
8080 case angle::SubjectMessage::CONTENTS_CHANGED:
8081 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
8082 mStateCache.onVertexArrayBufferContentsChange(this);
8083 break;
8084 case angle::SubjectMessage::RESOURCE_MAPPED:
8085 case angle::SubjectMessage::RESOURCE_UNMAPPED:
8086 case angle::SubjectMessage::BINDING_CHANGED:
8087 mStateCache.onVertexArrayBufferStateChange(this);
8088 break;
8089 default:
8090 break;
8091 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008092 break;
8093
8094 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008095 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8096 {
8097 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
8098 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008099 break;
8100
8101 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008102 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8103 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05008104 mGLState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04008105 }
8106 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04008107 break;
8108
8109 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04008110 if (index < kTextureMaxSubjectIndex)
8111 {
Jamie Madille3e680c2018-12-03 17:49:08 -05008112 mGLState.onActiveTextureStateChange(this, index);
Jamie Madilld84b6732018-09-06 15:54:35 -04008113 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008114 }
Jamie Madille3e680c2018-12-03 17:49:08 -05008115 else if (index < kImageMaxSubjectIndex)
8116 {
8117 mGLState.onImageStateChange(this, index - kImage0SubjectIndex);
8118 }
Jamie Madille25b8002018-09-20 13:39:49 -04008119 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04008120 {
Jamie Madill6d32cef2018-08-14 02:34:28 -04008121 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04008122 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008123 }
Jamie Madille25b8002018-09-20 13:39:49 -04008124 else
8125 {
8126 ASSERT(index < kSamplerMaxSubjectIndex);
8127 mGLState.setSamplerDirty(index - kSampler0SubjectIndex);
8128 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008129 break;
8130 }
8131}
8132
Jamie Madill6b873dd2018-07-12 23:56:30 -04008133// ErrorSet implementation.
Jamie Madillb980c562018-11-27 11:34:27 -05008134ErrorSet::ErrorSet(Context *context) : mContext(context) {}
Jamie Madill6b873dd2018-07-12 23:56:30 -04008135
8136ErrorSet::~ErrorSet() = default;
8137
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008138void ErrorSet::handleError(GLenum errorCode,
8139 const char *message,
8140 const char *file,
8141 const char *function,
8142 unsigned int line)
8143{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008144 if (errorCode == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
8145 {
8146 mContext->markContextLost();
8147 }
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008148
Jamie Madill4f6592f2018-11-27 16:37:45 -05008149 std::stringstream errorStream;
8150 errorStream << "Error: " << gl::FmtHex(errorCode) << ", in " << file << ", " << function << ":"
8151 << line << ". " << message;
8152
Geoff Lang7139b432018-12-14 16:57:28 -05008153 std::string formattedMessage = errorStream.str();
8154
8155 // Always log a warning, this function is only called on unexpected internal errors.
8156 WARN() << formattedMessage;
8157
Jamie Madill4f6592f2018-11-27 16:37:45 -05008158 // validationError does the necessary work to process the error.
Geoff Lang7139b432018-12-14 16:57:28 -05008159 validationError(errorCode, formattedMessage.c_str());
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008160}
8161
Jamie Madilla139f012018-10-10 16:13:03 -04008162void ErrorSet::validationError(GLenum errorCode, const char *message)
8163{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008164 ASSERT(errorCode != GL_NO_ERROR);
8165 mErrors.insert(errorCode);
8166
8167 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
8168 errorCode, GL_DEBUG_SEVERITY_HIGH, message);
Jamie Madilla139f012018-10-10 16:13:03 -04008169}
8170
Jamie Madill6b873dd2018-07-12 23:56:30 -04008171bool ErrorSet::empty() const
8172{
8173 return mErrors.empty();
8174}
8175
8176GLenum ErrorSet::popError()
8177{
8178 ASSERT(!empty());
8179 GLenum error = *mErrors.begin();
8180 mErrors.erase(mErrors.begin());
8181 return error;
8182}
Jamie Madilldc358af2018-07-31 11:22:13 -04008183
8184// StateCache implementation.
Jamie Madillac66f982018-10-09 18:30:01 -04008185StateCache::StateCache()
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008186 : mCachedHasAnyEnabledClientAttrib(false),
8187 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04008188 mCachedInstancedVertexElementLimit(0),
Jamie Madill1e853262018-12-21 09:07:38 -05008189 mCachedBasicDrawStatesError(kInvalidPointer),
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008190 mCachedBasicDrawElementsError(kInvalidPointer),
8191 mCachedTransformFeedbackActiveUnpaused(false)
Jamie Madillb980c562018-11-27 11:34:27 -05008192{}
Jamie Madilldc358af2018-07-31 11:22:13 -04008193
8194StateCache::~StateCache() = default;
8195
Jamie Madillac66f982018-10-09 18:30:01 -04008196void StateCache::initialize(Context *context)
8197{
8198 updateValidDrawModes(context);
8199 updateValidBindTextureTypes(context);
Jamie Madill8dc27f92018-11-29 11:45:44 -05008200 updateValidDrawElementsTypes(context);
Jamie Madill1e853262018-12-21 09:07:38 -05008201 updateBasicDrawStatesError();
8202 updateBasicDrawElementsError();
Jamie Madillac66f982018-10-09 18:30:01 -04008203}
8204
Jamie Madilldc358af2018-07-31 11:22:13 -04008205void StateCache::updateActiveAttribsMask(Context *context)
8206{
8207 bool isGLES1 = context->isGLES1();
8208 const State &glState = context->getGLState();
8209
8210 if (!isGLES1 && !glState.getProgram())
8211 {
8212 mCachedActiveBufferedAttribsMask = AttributesMask();
8213 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04008214 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04008215 return;
8216 }
8217
8218 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
8219 : glState.getProgram()->getActiveAttribLocationsMask();
8220
8221 const VertexArray *vao = glState.getVertexArray();
8222 ASSERT(vao);
8223
8224 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
8225 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04008226 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008227
Jamie Madill0a17e482018-08-31 17:19:11 -04008228 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
8229 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04008230 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008231 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
8232}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008233
8234void StateCache::updateVertexElementLimits(Context *context)
8235{
8236 const VertexArray *vao = context->getGLState().getVertexArray();
8237
8238 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8239 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8240
8241 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
8242 // If there are no buffered attributes then we should not limit the draw call count.
8243 if (!vao || !mCachedActiveBufferedAttribsMask.any())
8244 {
8245 return;
8246 }
8247
8248 const auto &vertexAttribs = vao->getVertexAttributes();
8249 const auto &vertexBindings = vao->getVertexBindings();
8250
8251 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
8252 {
8253 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
8254 ASSERT(attrib.enabled);
8255
8256 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
8257 ASSERT(context->isGLES1() ||
8258 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
8259
8260 GLint64 limit = attrib.getCachedElementLimit();
8261 if (binding.getDivisor() > 0)
8262 {
8263 mCachedInstancedVertexElementLimit =
8264 std::min(mCachedInstancedVertexElementLimit, limit);
8265 }
8266 else
8267 {
8268 mCachedNonInstancedVertexElementLimit =
8269 std::min(mCachedNonInstancedVertexElementLimit, limit);
8270 }
8271 }
8272}
Jamie Madillc43cdad2018-08-08 15:49:25 -04008273
Jamie Madilld84b6732018-09-06 15:54:35 -04008274void StateCache::updateBasicDrawStatesError()
8275{
8276 mCachedBasicDrawStatesError = kInvalidPointer;
8277}
8278
Jamie Madill1e853262018-12-21 09:07:38 -05008279void StateCache::updateBasicDrawElementsError()
8280{
8281 mCachedBasicDrawElementsError = kInvalidPointer;
8282}
8283
Jamie Madilld84b6732018-09-06 15:54:35 -04008284intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
8285{
8286 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
8287 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
8288 return mCachedBasicDrawStatesError;
8289}
8290
Jamie Madill1e853262018-12-21 09:07:38 -05008291intptr_t StateCache::getBasicDrawElementsErrorImpl(Context *context) const
8292{
8293 ASSERT(mCachedBasicDrawElementsError == kInvalidPointer);
8294 mCachedBasicDrawElementsError = reinterpret_cast<intptr_t>(ValidateDrawElementsStates(context));
8295 return mCachedBasicDrawElementsError;
8296}
8297
Jamie Madillc43cdad2018-08-08 15:49:25 -04008298void StateCache::onVertexArrayBindingChange(Context *context)
8299{
8300 updateActiveAttribsMask(context);
8301 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008302 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008303}
8304
8305void StateCache::onProgramExecutableChange(Context *context)
8306{
8307 updateActiveAttribsMask(context);
8308 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008309 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04008310 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04008311}
8312
Jamie Madilld84b6732018-09-06 15:54:35 -04008313void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04008314{
8315 updateVertexElementLimits(context);
8316}
8317
Jamie Madilld84b6732018-09-06 15:54:35 -04008318void StateCache::onVertexArrayBufferContentsChange(Context *context)
8319{
8320 updateVertexElementLimits(context);
8321 updateBasicDrawStatesError();
8322}
8323
Jamie Madillc43cdad2018-08-08 15:49:25 -04008324void StateCache::onVertexArrayStateChange(Context *context)
8325{
8326 updateActiveAttribsMask(context);
8327 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008328 updateBasicDrawStatesError();
8329}
8330
8331void StateCache::onVertexArrayBufferStateChange(Context *context)
8332{
8333 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008334 updateBasicDrawElementsError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008335}
8336
8337void StateCache::onGLES1ClientStateChange(Context *context)
8338{
8339 updateActiveAttribsMask(context);
8340}
Jamie Madilld84b6732018-09-06 15:54:35 -04008341
8342void StateCache::onDrawFramebufferChange(Context *context)
8343{
8344 updateBasicDrawStatesError();
8345}
8346
8347void StateCache::onContextCapChange(Context *context)
8348{
8349 updateBasicDrawStatesError();
8350}
8351
8352void StateCache::onStencilStateChange(Context *context)
8353{
8354 updateBasicDrawStatesError();
8355}
8356
8357void StateCache::onDefaultVertexAttributeChange(Context *context)
8358{
8359 updateBasicDrawStatesError();
8360}
8361
8362void StateCache::onActiveTextureChange(Context *context)
8363{
8364 updateBasicDrawStatesError();
8365}
8366
8367void StateCache::onQueryChange(Context *context)
8368{
8369 updateBasicDrawStatesError();
8370}
8371
Jamie Madill3a256222018-12-08 09:56:39 -05008372void StateCache::onActiveTransformFeedbackChange(Context *context)
Jamie Madilld84b6732018-09-06 15:54:35 -04008373{
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008374 updateTransformFeedbackActiveUnpaused(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008375 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008376 updateBasicDrawElementsError();
Jamie Madill9b025062018-12-12 15:44:12 -05008377 updateValidDrawModes(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008378}
8379
8380void StateCache::onUniformBufferStateChange(Context *context)
8381{
8382 updateBasicDrawStatesError();
8383}
8384
8385void StateCache::onBufferBindingChange(Context *context)
8386{
8387 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008388 updateBasicDrawElementsError();
Jamie Madilld84b6732018-09-06 15:54:35 -04008389}
Jamie Madill526a6f62018-09-12 11:03:05 -04008390
Jamie Madill9b025062018-12-12 15:44:12 -05008391void StateCache::setValidDrawModes(bool pointsOK,
8392 bool linesOK,
8393 bool trisOK,
8394 bool lineAdjOK,
8395 bool triAdjOK)
8396{
8397 mCachedValidDrawModes[PrimitiveMode::Points] = pointsOK;
8398 mCachedValidDrawModes[PrimitiveMode::Lines] = linesOK;
8399 mCachedValidDrawModes[PrimitiveMode::LineStrip] = linesOK;
8400 mCachedValidDrawModes[PrimitiveMode::LineLoop] = linesOK;
8401 mCachedValidDrawModes[PrimitiveMode::Triangles] = trisOK;
8402 mCachedValidDrawModes[PrimitiveMode::TriangleFan] = trisOK;
8403 mCachedValidDrawModes[PrimitiveMode::TriangleStrip] = trisOK;
8404 mCachedValidDrawModes[PrimitiveMode::LinesAdjacency] = lineAdjOK;
8405 mCachedValidDrawModes[PrimitiveMode::LineStripAdjacency] = lineAdjOK;
8406 mCachedValidDrawModes[PrimitiveMode::TrianglesAdjacency] = triAdjOK;
8407 mCachedValidDrawModes[PrimitiveMode::TriangleStripAdjacency] = triAdjOK;
8408}
8409
Jamie Madill526a6f62018-09-12 11:03:05 -04008410void StateCache::updateValidDrawModes(Context *context)
8411{
Jamie Madill9b025062018-12-12 15:44:12 -05008412 const State &state = context->getGLState();
8413 Program *program = state.getProgram();
8414
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008415 if (mCachedTransformFeedbackActiveUnpaused)
Jamie Madill9b025062018-12-12 15:44:12 -05008416 {
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008417 TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback();
8418
Jamie Madill9b025062018-12-12 15:44:12 -05008419 // ES Spec 3.0 validation text:
8420 // When transform feedback is active and not paused, all geometric primitives generated must
8421 // match the value of primitiveMode passed to BeginTransformFeedback. The error
8422 // INVALID_OPERATION is generated by DrawArrays and DrawArraysInstanced if mode is not
8423 // identical to primitiveMode. The error INVALID_OPERATION is also generated by
8424 // DrawElements, DrawElementsInstanced, and DrawRangeElements while transform feedback is
8425 // active and not paused, regardless of mode. Any primitive type may be used while transform
8426 // feedback is paused.
8427 if (!context->getExtensions().geometryShader)
8428 {
8429 mCachedValidDrawModes.fill(false);
8430 mCachedValidDrawModes[curTransformFeedback->getPrimitiveMode()] = true;
8431 return;
8432 }
8433
8434 // EXT_geometry_shader validation text:
8435 // When transform feedback is active and not paused, all geometric primitives generated must
8436 // be compatible with the value of <primitiveMode> passed to BeginTransformFeedback. If a
8437 // geometry shader is active, the type of primitive emitted by that shader is used instead
8438 // of the <mode> parameter passed to drawing commands for the purposes of this error check.
8439 // Any primitive type may be used while transform feedback is paused.
8440 bool pointsOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Points;
8441 bool linesOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Lines;
8442 bool trisOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Triangles;
8443
8444 setValidDrawModes(pointsOK, linesOK, trisOK, false, false);
8445 return;
8446 }
8447
Jamie Madill526a6f62018-09-12 11:03:05 -04008448 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8449 {
Jamie Madill752d2202018-11-27 13:29:48 -05008450 mCachedValidDrawModes = kValidBasicDrawModes;
Jamie Madill9b025062018-12-12 15:44:12 -05008451 return;
Jamie Madill526a6f62018-09-12 11:03:05 -04008452 }
Jamie Madill526a6f62018-09-12 11:03:05 -04008453
Jamie Madill9b025062018-12-12 15:44:12 -05008454 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8455 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
Jamie Madill526a6f62018-09-12 11:03:05 -04008456
Jamie Madill9b025062018-12-12 15:44:12 -05008457 bool pointsOK = gsMode == PrimitiveMode::Points;
8458 bool linesOK = gsMode == PrimitiveMode::Lines;
8459 bool trisOK = gsMode == PrimitiveMode::Triangles;
8460 bool lineAdjOK = gsMode == PrimitiveMode::LinesAdjacency;
8461 bool triAdjOK = gsMode == PrimitiveMode::TrianglesAdjacency;
8462
8463 setValidDrawModes(pointsOK, linesOK, trisOK, lineAdjOK, triAdjOK);
Jamie Madill526a6f62018-09-12 11:03:05 -04008464}
Jamie Madillac66f982018-10-09 18:30:01 -04008465
8466void StateCache::updateValidBindTextureTypes(Context *context)
8467{
8468 const Extensions &exts = context->getExtensions();
8469 bool isGLES3 = context->getClientMajorVersion() >= 3;
8470 bool isGLES31 = context->getClientVersion() >= Version(3, 1);
8471
8472 mCachedValidBindTextureTypes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008473 {TextureType::_2D, true},
8474 {TextureType::_2DArray, isGLES3},
8475 {TextureType::_2DMultisample, isGLES31 || exts.textureMultisample},
8476 {TextureType::_2DMultisampleArray, exts.textureStorageMultisample2DArray},
8477 {TextureType::_3D, isGLES3},
8478 {TextureType::External, exts.eglImageExternal || exts.eglStreamConsumerExternal},
8479 {TextureType::Rectangle, exts.textureRectangle},
8480 {TextureType::CubeMap, true},
Jamie Madillac66f982018-10-09 18:30:01 -04008481 }};
8482}
Jamie Madill8dc27f92018-11-29 11:45:44 -05008483
8484void StateCache::updateValidDrawElementsTypes(Context *context)
8485{
8486 bool supportsUint =
8487 (context->getClientMajorVersion() >= 3 || context->getExtensions().elementIndexUint);
8488
8489 mCachedValidDrawElementsTypes = {{
8490 {DrawElementsType::UnsignedByte, true},
8491 {DrawElementsType::UnsignedShort, true},
8492 {DrawElementsType::UnsignedInt, supportsUint},
8493 }};
8494}
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008495
8496void StateCache::updateTransformFeedbackActiveUnpaused(Context *context)
8497{
8498 TransformFeedback *xfb = context->getGLState().getCurrentTransformFeedback();
8499 mCachedTransformFeedbackActiveUnpaused = xfb && xfb->isActive() && !xfb->isPaused();
8500}
Jamie Madillc29968b2016-01-20 11:17:23 -05008501} // namespace gl