blob: ec135625ca60d5fba6acd1eaec490619c1c45874 [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,
135 TransformFeedback *transformFeedback,
Jamie Madill956ab4d2018-10-10 16:13:03 -0400136 GLsizei count,
137 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400138{
Geoff Lang1a683462015-09-29 15:09:59 -0400139 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400140 {
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 Madill09463932018-04-04 05:26:59 -04002224 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), 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 Madill09463932018-04-04 05:26:59 -04002241 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2242 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002243}
2244
Jamie Madill8dc27f92018-11-29 11:45:44 -05002245void Context::drawElements(PrimitiveMode mode,
2246 GLsizei count,
2247 DrawElementsType type,
2248 const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002249{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002250 // No-op if count draws no primitives for given mode
2251 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002252 {
2253 return;
2254 }
2255
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002256 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002257 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002258}
2259
Jamie Madill493f9572018-05-24 19:52:15 -04002260void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002261 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002262 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002263 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002264 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002265{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002266 // No-op if count draws no primitives for given mode
2267 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002268 {
2269 return;
2270 }
2271
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002272 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002273 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002274 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002275}
2276
Jamie Madill493f9572018-05-24 19:52:15 -04002277void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002278 GLuint start,
2279 GLuint end,
2280 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002281 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002282 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002283{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002284 // No-op if count draws no primitives for given mode
2285 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002286 {
2287 return;
2288 }
2289
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002290 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002291 ANGLE_CONTEXT_TRY(
2292 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002293}
2294
Jamie Madill493f9572018-05-24 19:52:15 -04002295void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002296{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002297 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002298 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002299}
2300
Jamie Madill8dc27f92018-11-29 11:45:44 -05002301void Context::drawElementsIndirect(PrimitiveMode mode, DrawElementsType type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002302{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002303 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002304 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002305}
2306
Jamie Madill675fe712016-12-19 13:07:54 -05002307void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002308{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002309 ANGLE_CONTEXT_TRY(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002310}
2311
Jamie Madill675fe712016-12-19 13:07:54 -05002312void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002313{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002314 ANGLE_CONTEXT_TRY(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002315}
2316
Austin Kinross6ee1e782015-05-29 17:05:37 -07002317void Context::insertEventMarker(GLsizei length, const char *marker)
2318{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002319 ASSERT(mImplementation);
2320 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002321}
2322
2323void Context::pushGroupMarker(GLsizei length, const char *marker)
2324{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002325 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002326
2327 if (marker == nullptr)
2328 {
2329 // From the EXT_debug_marker spec,
2330 // "If <marker> is null then an empty string is pushed on the stack."
2331 mImplementation->pushGroupMarker(length, "");
2332 }
2333 else
2334 {
2335 mImplementation->pushGroupMarker(length, marker);
2336 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002337}
2338
2339void Context::popGroupMarker()
2340{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002341 ASSERT(mImplementation);
2342 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002343}
2344
Geoff Langd8605522016-04-13 10:19:12 -04002345void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2346{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002347 Program *programObject = getProgramResolveLink(program);
Geoff Langd8605522016-04-13 10:19:12 -04002348 ASSERT(programObject);
2349
2350 programObject->bindUniformLocation(location, name);
2351}
2352
Brandon Jones59770802018-04-02 13:18:42 -07002353void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002354{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002355 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002356}
2357
Brandon Jones59770802018-04-02 13:18:42 -07002358void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002359{
2360 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2361}
2362
Brandon Jones59770802018-04-02 13:18:42 -07002363void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002364{
2365 GLfloat I[16];
2366 angle::Matrix<GLfloat>::setToIdentity(I);
2367
2368 mGLState.loadPathRenderingMatrix(matrixMode, I);
2369}
2370
2371void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2372{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002373 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002374 if (!pathObj)
2375 return;
2376
Geoff Lang9bf86f02018-07-26 11:46:34 -04002377 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002378
2379 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2380}
2381
2382void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2383{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002384 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002385 if (!pathObj)
2386 return;
2387
Geoff Lang9bf86f02018-07-26 11:46:34 -04002388 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002389
2390 mImplementation->stencilStrokePath(pathObj, reference, mask);
2391}
2392
2393void Context::coverFillPath(GLuint path, GLenum coverMode)
2394{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002395 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002396 if (!pathObj)
2397 return;
2398
Geoff Lang9bf86f02018-07-26 11:46:34 -04002399 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002400
2401 mImplementation->coverFillPath(pathObj, coverMode);
2402}
2403
2404void Context::coverStrokePath(GLuint path, GLenum coverMode)
2405{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002406 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002407 if (!pathObj)
2408 return;
2409
Geoff Lang9bf86f02018-07-26 11:46:34 -04002410 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002411
2412 mImplementation->coverStrokePath(pathObj, coverMode);
2413}
2414
2415void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2416{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002417 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002418 if (!pathObj)
2419 return;
2420
Geoff Lang9bf86f02018-07-26 11:46:34 -04002421 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002422
2423 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2424}
2425
2426void Context::stencilThenCoverStrokePath(GLuint path,
2427 GLint reference,
2428 GLuint mask,
2429 GLenum coverMode)
2430{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002431 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002432 if (!pathObj)
2433 return;
2434
Geoff Lang9bf86f02018-07-26 11:46:34 -04002435 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002436
2437 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2438}
2439
Sami Väisänend59ca052016-06-21 16:10:00 +03002440void Context::coverFillPathInstanced(GLsizei numPaths,
2441 GLenum pathNameType,
2442 const void *paths,
2443 GLuint pathBase,
2444 GLenum coverMode,
2445 GLenum transformType,
2446 const GLfloat *transformValues)
2447{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002448 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002449
Geoff Lang9bf86f02018-07-26 11:46:34 -04002450 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002451
2452 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2453}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002454
Sami Väisänend59ca052016-06-21 16:10:00 +03002455void Context::coverStrokePathInstanced(GLsizei numPaths,
2456 GLenum pathNameType,
2457 const void *paths,
2458 GLuint pathBase,
2459 GLenum coverMode,
2460 GLenum transformType,
2461 const GLfloat *transformValues)
2462{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002463 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002464
2465 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002466 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002467
2468 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2469 transformValues);
2470}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002471
Sami Väisänend59ca052016-06-21 16:10:00 +03002472void Context::stencilFillPathInstanced(GLsizei numPaths,
2473 GLenum pathNameType,
2474 const void *paths,
2475 GLuint pathBase,
2476 GLenum fillMode,
2477 GLuint mask,
2478 GLenum transformType,
2479 const GLfloat *transformValues)
2480{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002481 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002482
2483 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002484 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002485
2486 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2487 transformValues);
2488}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002489
Sami Väisänend59ca052016-06-21 16:10:00 +03002490void Context::stencilStrokePathInstanced(GLsizei numPaths,
2491 GLenum pathNameType,
2492 const void *paths,
2493 GLuint pathBase,
2494 GLint reference,
2495 GLuint mask,
2496 GLenum transformType,
2497 const GLfloat *transformValues)
2498{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002499 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002500
Geoff Lang9bf86f02018-07-26 11:46:34 -04002501 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002502
2503 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2504 transformValues);
2505}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002506
Sami Väisänend59ca052016-06-21 16:10:00 +03002507void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2508 GLenum pathNameType,
2509 const void *paths,
2510 GLuint pathBase,
2511 GLenum fillMode,
2512 GLuint mask,
2513 GLenum coverMode,
2514 GLenum transformType,
2515 const GLfloat *transformValues)
2516{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002517 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002518
Geoff Lang9bf86f02018-07-26 11:46:34 -04002519 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002520
2521 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2522 transformType, transformValues);
2523}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002524
Sami Väisänend59ca052016-06-21 16:10:00 +03002525void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2526 GLenum pathNameType,
2527 const void *paths,
2528 GLuint pathBase,
2529 GLint reference,
2530 GLuint mask,
2531 GLenum coverMode,
2532 GLenum transformType,
2533 const GLfloat *transformValues)
2534{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002535 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002536
Geoff Lang9bf86f02018-07-26 11:46:34 -04002537 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002538
2539 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2540 transformType, transformValues);
2541}
2542
Sami Väisänen46eaa942016-06-29 10:26:37 +03002543void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2544{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002545 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002546
2547 programObject->bindFragmentInputLocation(location, name);
2548}
2549
2550void Context::programPathFragmentInputGen(GLuint program,
2551 GLint location,
2552 GLenum genMode,
2553 GLint components,
2554 const GLfloat *coeffs)
2555{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002556 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002557
jchen103fd614d2018-08-13 12:21:58 +08002558 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002559}
2560
jchen1015015f72017-03-16 13:54:21 +08002561GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2562{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002563 const Program *programObject = getProgramResolveLink(program);
jchen1015015f72017-03-16 13:54:21 +08002564 return QueryProgramResourceIndex(programObject, programInterface, name);
2565}
2566
jchen10fd7c3b52017-03-21 15:36:03 +08002567void Context::getProgramResourceName(GLuint program,
2568 GLenum programInterface,
2569 GLuint index,
2570 GLsizei bufSize,
2571 GLsizei *length,
2572 GLchar *name)
2573{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002574 const Program *programObject = getProgramResolveLink(program);
jchen10fd7c3b52017-03-21 15:36:03 +08002575 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2576}
2577
jchen10191381f2017-04-11 13:59:04 +08002578GLint Context::getProgramResourceLocation(GLuint program,
2579 GLenum programInterface,
2580 const GLchar *name)
2581{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002582 const Program *programObject = getProgramResolveLink(program);
jchen10191381f2017-04-11 13:59:04 +08002583 return QueryProgramResourceLocation(programObject, programInterface, name);
2584}
2585
jchen10880683b2017-04-12 16:21:55 +08002586void Context::getProgramResourceiv(GLuint program,
2587 GLenum programInterface,
2588 GLuint index,
2589 GLsizei propCount,
2590 const GLenum *props,
2591 GLsizei bufSize,
2592 GLsizei *length,
2593 GLint *params)
2594{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002595 const Program *programObject = getProgramResolveLink(program);
jchen10880683b2017-04-12 16:21:55 +08002596 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2597 length, params);
2598}
2599
jchen10d9cd7b72017-08-30 15:04:25 +08002600void Context::getProgramInterfaceiv(GLuint program,
2601 GLenum programInterface,
2602 GLenum pname,
2603 GLint *params)
2604{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002605 const Program *programObject = getProgramResolveLink(program);
jchen10d9cd7b72017-08-30 15:04:25 +08002606 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2607}
2608
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002609void Context::getProgramInterfaceivRobust(GLuint program,
2610 GLenum programInterface,
2611 GLenum pname,
2612 GLsizei bufSize,
2613 GLsizei *length,
2614 GLint *params)
2615{
2616 UNIMPLEMENTED();
2617}
2618
Jamie Madillabfbc0f2018-10-09 12:48:52 -04002619void Context::handleError(GLenum errorCode,
2620 const char *message,
2621 const char *file,
2622 const char *function,
2623 unsigned int line)
2624{
2625 mErrors.handleError(errorCode, message, file, function, line);
2626}
2627
Jamie Madilla139f012018-10-10 16:13:03 -04002628void Context::validationError(GLenum errorCode, const char *message)
2629{
2630 mErrors.validationError(errorCode, message);
2631}
2632
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002633// Get one of the recorded errors and clear its flag, if any.
2634// [OpenGL ES 2.0.24] section 2.5 page 13.
2635GLenum Context::getError()
2636{
Geoff Langda5777c2014-07-11 09:52:58 -04002637 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002638 {
Geoff Langda5777c2014-07-11 09:52:58 -04002639 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002640 }
Geoff Langda5777c2014-07-11 09:52:58 -04002641 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002642 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002643 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002644 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002645}
2646
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002647// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002648void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002649{
2650 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002651 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002652 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002653 mContextLostForced = true;
2654 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002655 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002656}
2657
Jamie Madillfa920eb2018-01-04 11:45:50 -05002658GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002659{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002660 // Even if the application doesn't want to know about resets, we want to know
2661 // as it will allow us to skip all the calls.
2662 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002663 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002664 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002665 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002666 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002667 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002668
2669 // EXT_robustness, section 2.6: If the reset notification behavior is
2670 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2671 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2672 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002673 }
2674
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002675 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2676 // status should be returned at least once, and GL_NO_ERROR should be returned
2677 // once the device has finished resetting.
2678 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002679 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002680 ASSERT(mResetStatus == GL_NO_ERROR);
2681 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002682
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002683 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002684 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002685 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002686 }
2687 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002688 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002689 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002690 // If markContextLost was used to mark the context lost then
2691 // assume that is not recoverable, and continue to report the
2692 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002693 mResetStatus = mImplementation->getResetStatus();
2694 }
Jamie Madill893ab082014-05-16 16:56:10 -04002695
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002696 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002697}
2698
2699bool Context::isResetNotificationEnabled()
2700{
2701 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2702}
2703
Corentin Walleze3b10e82015-05-20 11:06:25 -04002704const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002705{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002706 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002707}
2708
2709EGLenum Context::getClientType() const
2710{
2711 return mClientType;
2712}
2713
2714EGLenum Context::getRenderBuffer() const
2715{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002716 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2717 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002718 {
2719 return EGL_NONE;
2720 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002721
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002722 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002723 ASSERT(backAttachment != nullptr);
2724 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002725}
2726
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002727VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002728{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002729 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002730 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2731 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002732 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002733 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2734 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002735
Jamie Madill96a483b2017-06-27 16:49:21 -04002736 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002737 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002738
2739 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002740}
2741
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002742TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002743{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002744 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002745 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2746 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002747 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002748 transformFeedback =
2749 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002750 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002751 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002752 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002753
2754 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002755}
2756
2757bool Context::isVertexArrayGenerated(GLuint vertexArray)
2758{
Jamie Madill96a483b2017-06-27 16:49:21 -04002759 ASSERT(mVertexArrayMap.contains(0));
2760 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002761}
2762
2763bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2764{
Jamie Madill96a483b2017-06-27 16:49:21 -04002765 ASSERT(mTransformFeedbackMap.contains(0));
2766 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002767}
2768
Shannon Woods53a94a82014-06-24 15:20:36 -04002769void Context::detachTexture(GLuint texture)
2770{
2771 // Simple pass-through to State's detachTexture method, as textures do not require
2772 // allocation map management either here or in the resource manager at detach time.
2773 // Zero textures are held by the Context, and we don't attempt to request them from
2774 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002775 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002776}
2777
James Darpinian4d9d4832018-03-13 12:43:28 -07002778void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002779{
Yuly Novikov5807a532015-12-03 13:01:22 -05002780 // Simple pass-through to State's detachBuffer method, since
2781 // only buffer attachments to container objects that are bound to the current context
2782 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002783
Yuly Novikov5807a532015-12-03 13:01:22 -05002784 // [OpenGL ES 3.2] section 5.1.2 page 45:
2785 // Attachments to unbound container objects, such as
2786 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2787 // are not affected and continue to act as references on the deleted object
Geoff Lang91002262018-12-12 16:05:24 -05002788 ANGLE_CONTEXT_TRY(mGLState.detachBuffer(this, buffer));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002789}
2790
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002791void Context::detachFramebuffer(GLuint framebuffer)
2792{
Shannon Woods53a94a82014-06-24 15:20:36 -04002793 // Framebuffer detachment is handled by Context, because 0 is a valid
2794 // Framebuffer object, and a pointer to it must be passed from Context
2795 // to State at binding time.
2796
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002797 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002798 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2799 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2800 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002801
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002802 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002803 {
2804 bindReadFramebuffer(0);
2805 }
2806
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002807 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002808 {
2809 bindDrawFramebuffer(0);
2810 }
2811}
2812
2813void Context::detachRenderbuffer(GLuint renderbuffer)
2814{
Jamie Madilla02315b2017-02-23 14:14:47 -05002815 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002816}
2817
Jamie Madill57a89722013-07-02 11:57:03 -04002818void Context::detachVertexArray(GLuint vertexArray)
2819{
Jamie Madill77a72f62015-04-14 11:18:32 -04002820 // Vertex array detachment is handled by Context, because 0 is a valid
2821 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002822 // binding time.
2823
Jamie Madill57a89722013-07-02 11:57:03 -04002824 // [OpenGL ES 3.0.2] section 2.10 page 43:
2825 // If a vertex array object that is currently bound is deleted, the binding
2826 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002827 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002828 {
2829 bindVertexArray(0);
2830 }
2831}
2832
Geoff Langc8058452014-02-03 12:04:11 -05002833void Context::detachTransformFeedback(GLuint transformFeedback)
2834{
Corentin Walleza2257da2016-04-19 16:43:12 -04002835 // Transform feedback detachment is handled by Context, because 0 is a valid
2836 // transform feedback, and a pointer to it must be passed from Context to State at
2837 // binding time.
2838
2839 // The OpenGL specification doesn't mention what should happen when the currently bound
2840 // transform feedback object is deleted. Since it is a container object, we treat it like
2841 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002842 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002843 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002844 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002845 }
Geoff Langc8058452014-02-03 12:04:11 -05002846}
2847
Jamie Madilldc356042013-07-19 16:36:57 -04002848void Context::detachSampler(GLuint sampler)
2849{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002850 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002851}
2852
Yunchao Hea336b902017-08-02 16:05:21 +08002853void Context::detachProgramPipeline(GLuint pipeline)
2854{
2855 mGLState.detachProgramPipeline(this, pipeline);
2856}
2857
Jamie Madill3ef140a2017-08-26 23:11:21 -04002858void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002859{
Shaodde78e82017-05-22 14:13:27 +08002860 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002861 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002862}
2863
Jamie Madille29d1672013-07-19 16:36:57 -04002864void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2865{
Till Rathmannb8543632018-10-02 19:46:14 +02002866 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002867 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002868 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002869}
Jamie Madille29d1672013-07-19 16:36:57 -04002870
Geoff Langc1984ed2016-10-07 12:41:00 -04002871void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2872{
Till Rathmannb8543632018-10-02 19:46:14 +02002873 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002874 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002875 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002876}
2877
Till Rathmannb8543632018-10-02 19:46:14 +02002878void Context::samplerParameterIiv(GLuint sampler, GLenum pname, const GLint *param)
2879{
2880 Sampler *const samplerObject =
2881 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2882 SetSamplerParameterIiv(this, samplerObject, pname, param);
2883}
2884
2885void Context::samplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *param)
2886{
2887 Sampler *const samplerObject =
2888 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2889 SetSamplerParameterIuiv(this, samplerObject, pname, param);
2890}
2891
Brandon Jones59770802018-04-02 13:18:42 -07002892void Context::samplerParameterivRobust(GLuint sampler,
2893 GLenum pname,
2894 GLsizei bufSize,
2895 const GLint *param)
2896{
2897 samplerParameteriv(sampler, pname, param);
2898}
2899
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002900void Context::samplerParameterIivRobust(GLuint sampler,
2901 GLenum pname,
2902 GLsizei bufSize,
2903 const GLint *param)
2904{
2905 UNIMPLEMENTED();
2906}
2907
2908void Context::samplerParameterIuivRobust(GLuint sampler,
2909 GLenum pname,
2910 GLsizei bufSize,
2911 const GLuint *param)
2912{
2913 UNIMPLEMENTED();
2914}
2915
Jamie Madille29d1672013-07-19 16:36:57 -04002916void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2917{
Till Rathmannb8543632018-10-02 19:46:14 +02002918 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002919 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002920 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002921}
2922
Geoff Langc1984ed2016-10-07 12:41:00 -04002923void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002924{
Till Rathmannb8543632018-10-02 19:46:14 +02002925 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002926 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002927 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002928}
2929
Brandon Jones59770802018-04-02 13:18:42 -07002930void Context::samplerParameterfvRobust(GLuint sampler,
2931 GLenum pname,
2932 GLsizei bufSize,
2933 const GLfloat *param)
2934{
2935 samplerParameterfv(sampler, pname, param);
2936}
2937
Geoff Langc1984ed2016-10-07 12:41:00 -04002938void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002939{
Till Rathmannb8543632018-10-02 19:46:14 +02002940 const Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002941 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002942 QuerySamplerParameteriv(samplerObject, pname, params);
2943}
Jamie Madill9675b802013-07-19 16:36:59 -04002944
Till Rathmannb8543632018-10-02 19:46:14 +02002945void Context::getSamplerParameterIiv(GLuint sampler, GLenum pname, GLint *params)
2946{
2947 const Sampler *const samplerObject =
2948 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2949 QuerySamplerParameterIiv(samplerObject, pname, params);
2950}
2951
2952void Context::getSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint *params)
2953{
2954 const Sampler *const samplerObject =
2955 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2956 QuerySamplerParameterIuiv(samplerObject, pname, params);
2957}
2958
Brandon Jones59770802018-04-02 13:18:42 -07002959void Context::getSamplerParameterivRobust(GLuint sampler,
2960 GLenum pname,
2961 GLsizei bufSize,
2962 GLsizei *length,
2963 GLint *params)
2964{
2965 getSamplerParameteriv(sampler, pname, params);
2966}
2967
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002968void Context::getSamplerParameterIivRobust(GLuint sampler,
2969 GLenum pname,
2970 GLsizei bufSize,
2971 GLsizei *length,
2972 GLint *params)
2973{
2974 UNIMPLEMENTED();
2975}
2976
2977void Context::getSamplerParameterIuivRobust(GLuint sampler,
2978 GLenum pname,
2979 GLsizei bufSize,
2980 GLsizei *length,
2981 GLuint *params)
2982{
2983 UNIMPLEMENTED();
2984}
2985
Geoff Langc1984ed2016-10-07 12:41:00 -04002986void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2987{
Till Rathmannb8543632018-10-02 19:46:14 +02002988 const Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002989 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002990 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002991}
2992
Brandon Jones59770802018-04-02 13:18:42 -07002993void Context::getSamplerParameterfvRobust(GLuint sampler,
2994 GLenum pname,
2995 GLsizei bufSize,
2996 GLsizei *length,
2997 GLfloat *params)
2998{
2999 getSamplerParameterfv(sampler, pname, params);
3000}
3001
Olli Etuahof0fee072016-03-30 15:11:58 +03003002void Context::programParameteri(GLuint program, GLenum pname, GLint value)
3003{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04003004 gl::Program *programObject = getProgramResolveLink(program);
Yunchao He61afff12017-03-14 15:34:03 +08003005 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03003006}
3007
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003008void Context::initRendererString()
3009{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00003010 std::ostringstream rendererString;
3011 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003012 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00003013 rendererString << ")";
3014
Geoff Langcec35902014-04-16 10:52:36 -04003015 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003016}
3017
Geoff Langc339c4e2016-11-29 10:37:36 -05003018void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003019{
Geoff Langc339c4e2016-11-29 10:37:36 -05003020 const Version &clientVersion = getClientVersion();
3021
3022 std::ostringstream versionString;
3023 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
3024 << ANGLE_VERSION_STRING << ")";
3025 mVersionString = MakeStaticString(versionString.str());
3026
3027 std::ostringstream shadingLanguageVersionString;
3028 shadingLanguageVersionString << "OpenGL ES GLSL ES "
3029 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
3030 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
3031 << ")";
3032 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003033}
3034
Geoff Langcec35902014-04-16 10:52:36 -04003035void Context::initExtensionStrings()
3036{
Geoff Langc339c4e2016-11-29 10:37:36 -05003037 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
3038 std::ostringstream combinedStringStream;
3039 std::copy(strings.begin(), strings.end(),
3040 std::ostream_iterator<const char *>(combinedStringStream, " "));
3041 return MakeStaticString(combinedStringStream.str());
3042 };
3043
3044 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003045 for (const auto &extensionString : mExtensions.getStrings())
3046 {
3047 mExtensionStrings.push_back(MakeStaticString(extensionString));
3048 }
Geoff Langc339c4e2016-11-29 10:37:36 -05003049 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003050
Geoff Langc339c4e2016-11-29 10:37:36 -05003051 mRequestableExtensionStrings.clear();
3052 for (const auto &extensionInfo : GetExtensionInfoMap())
3053 {
3054 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003055 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003056 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003057 {
3058 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3059 }
3060 }
3061 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003062}
3063
Geoff Langc339c4e2016-11-29 10:37:36 -05003064const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003065{
Geoff Langc339c4e2016-11-29 10:37:36 -05003066 switch (name)
3067 {
3068 case GL_VENDOR:
3069 return reinterpret_cast<const GLubyte *>("Google Inc.");
3070
3071 case GL_RENDERER:
3072 return reinterpret_cast<const GLubyte *>(mRendererString);
3073
3074 case GL_VERSION:
3075 return reinterpret_cast<const GLubyte *>(mVersionString);
3076
3077 case GL_SHADING_LANGUAGE_VERSION:
3078 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3079
3080 case GL_EXTENSIONS:
3081 return reinterpret_cast<const GLubyte *>(mExtensionString);
3082
3083 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3084 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3085
3086 default:
3087 UNREACHABLE();
3088 return nullptr;
3089 }
Geoff Langcec35902014-04-16 10:52:36 -04003090}
3091
Geoff Langc339c4e2016-11-29 10:37:36 -05003092const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003093{
Geoff Langc339c4e2016-11-29 10:37:36 -05003094 switch (name)
3095 {
3096 case GL_EXTENSIONS:
3097 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3098
3099 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3100 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3101
3102 default:
3103 UNREACHABLE();
3104 return nullptr;
3105 }
Geoff Langcec35902014-04-16 10:52:36 -04003106}
3107
3108size_t Context::getExtensionStringCount() const
3109{
3110 return mExtensionStrings.size();
3111}
3112
Geoff Lang111a99e2017-10-17 10:58:41 -04003113bool Context::isExtensionRequestable(const char *name)
3114{
3115 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3116 auto extension = extensionInfos.find(name);
3117
Geoff Lang111a99e2017-10-17 10:58:41 -04003118 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003119 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003120}
3121
Geoff Langc339c4e2016-11-29 10:37:36 -05003122void Context::requestExtension(const char *name)
3123{
3124 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3125 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3126 const auto &extension = extensionInfos.at(name);
3127 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003128 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003129
3130 if (mExtensions.*(extension.ExtensionsMember))
3131 {
3132 // Extension already enabled
3133 return;
3134 }
3135
3136 mExtensions.*(extension.ExtensionsMember) = true;
3137 updateCaps();
3138 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003139
Jamie Madill2f348d22017-06-05 10:50:59 -04003140 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3141 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003142
Jamie Madill81c2e252017-09-09 23:32:46 -04003143 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3144 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003145 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003146 for (auto &zeroTexture : mZeroTextures)
3147 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003148 if (zeroTexture.get() != nullptr)
3149 {
Jamie Madille3e680c2018-12-03 17:49:08 -05003150 zeroTexture->signalDirtyStorage(this, InitState::Initialized);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003151 }
Geoff Lang9aded172017-04-05 11:07:56 -04003152 }
3153
Jamie Madillb983a4b2018-08-01 11:34:51 -04003154 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003155}
3156
3157size_t Context::getRequestableExtensionStringCount() const
3158{
3159 return mRequestableExtensionStrings.size();
3160}
3161
Jamie Madill493f9572018-05-24 19:52:15 -04003162void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003163{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003164 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003165 ASSERT(transformFeedback != nullptr);
3166 ASSERT(!transformFeedback->isPaused());
3167
Geoff Lang91002262018-12-12 16:05:24 -05003168 ANGLE_CONTEXT_TRY(transformFeedback->begin(this, primitiveMode, mGLState.getProgram()));
Jamie Madill3a256222018-12-08 09:56:39 -05003169 mStateCache.onActiveTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003170}
3171
3172bool Context::hasActiveTransformFeedback(GLuint program) const
3173{
3174 for (auto pair : mTransformFeedbackMap)
3175 {
3176 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3177 {
3178 return true;
3179 }
3180 }
3181 return false;
3182}
3183
Geoff Lang33f11fb2018-05-07 13:42:47 -04003184Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003185{
3186 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3187
jchen1082af6202018-06-22 10:59:52 +08003188 // Explicitly enable GL_KHR_parallel_shader_compile
3189 supportedExtensions.parallelShaderCompile = true;
3190
Geoff Langb0f917f2017-12-05 13:41:54 -05003191 if (getClientVersion() < ES_2_0)
3192 {
3193 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003194 supportedExtensions.pointSizeArray = true;
3195 supportedExtensions.textureCubeMap = true;
3196 supportedExtensions.pointSprite = true;
3197 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003198 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003199 }
3200
3201 if (getClientVersion() < ES_3_0)
3202 {
3203 // Disable ES3+ extensions
3204 supportedExtensions.colorBufferFloat = false;
3205 supportedExtensions.eglImageExternalEssl3 = false;
3206 supportedExtensions.textureNorm16 = false;
3207 supportedExtensions.multiview = false;
3208 supportedExtensions.maxViews = 1u;
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07003209 supportedExtensions.copyTexture3d = false;
Yizhou Jiang7818a852018-09-06 15:02:04 +08003210 supportedExtensions.textureMultisample = false;
Geoff Lang7198ebc2018-11-22 14:36:06 -05003211
3212 // Don't expose GL_EXT_texture_sRGB_decode without sRGB texture support
3213 if (!supportedExtensions.sRGB)
3214 {
3215 supportedExtensions.textureSRGBDecode = false;
3216 }
Geoff Langb0f917f2017-12-05 13:41:54 -05003217 }
3218
3219 if (getClientVersion() < ES_3_1)
3220 {
3221 // Disable ES3.1+ extensions
3222 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003223
3224 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3225 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003226 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003227 }
3228
3229 if (getClientVersion() > ES_2_0)
3230 {
3231 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3232 // supportedExtensions.sRGB = false;
3233 }
3234
3235 // Some extensions are always available because they are implemented in the GL layer.
3236 supportedExtensions.bindUniformLocation = true;
3237 supportedExtensions.vertexArrayObject = true;
3238 supportedExtensions.bindGeneratesResource = true;
3239 supportedExtensions.clientArrays = true;
3240 supportedExtensions.requestExtension = true;
Austin Eng7cf9cd22018-10-09 15:27:32 -07003241 supportedExtensions.multiDraw = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003242
3243 // Enable the no error extension if the context was created with the flag.
3244 supportedExtensions.noError = mSkipValidation;
3245
3246 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003247 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003248
3249 // Explicitly enable GL_KHR_debug
3250 supportedExtensions.debug = true;
3251 supportedExtensions.maxDebugMessageLength = 1024;
3252 supportedExtensions.maxDebugLoggedMessages = 1024;
3253 supportedExtensions.maxDebugGroupStackDepth = 1024;
3254 supportedExtensions.maxLabelLength = 1024;
3255
3256 // Explicitly enable GL_ANGLE_robust_client_memory
3257 supportedExtensions.robustClientMemory = true;
3258
3259 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003260 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003261
3262 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3263 // supports it.
3264 supportedExtensions.robustBufferAccessBehavior =
3265 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3266
3267 // Enable the cache control query unconditionally.
3268 supportedExtensions.programCacheControl = true;
3269
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003270 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003271 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003272 {
3273 // GL_ANGLE_explicit_context_gles1
3274 supportedExtensions.explicitContextGles1 = true;
3275 // GL_ANGLE_explicit_context
3276 supportedExtensions.explicitContext = true;
3277 }
3278
Geoff Lang79b91402018-10-04 15:11:30 -04003279 supportedExtensions.memorySize = true;
3280
Geoff Langb0f917f2017-12-05 13:41:54 -05003281 return supportedExtensions;
3282}
3283
Geoff Lang33f11fb2018-05-07 13:42:47 -04003284void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003285{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003286 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003287
Geoff Lang33f11fb2018-05-07 13:42:47 -04003288 mSupportedExtensions = generateSupportedExtensions();
3289 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003290
3291 mLimitations = mImplementation->getNativeLimitations();
3292
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003293 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3294 if (getClientVersion() < Version(2, 0))
3295 {
3296 mCaps.maxMultitextureUnits = 4;
3297 mCaps.maxClipPlanes = 6;
3298 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003299 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3300 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3301 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003302 mCaps.minSmoothPointSize = 1.0f;
3303 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003304 mCaps.minSmoothLineWidth = 1.0f;
3305 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003306 }
3307
Luc Ferronad2ae932018-06-11 15:31:17 -04003308 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003309 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003310
Luc Ferronad2ae932018-06-11 15:31:17 -04003311 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3312
Jamie Madill0f80ed82017-09-19 00:24:56 -04003313 if (getClientVersion() < ES_3_1)
3314 {
3315 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3316 }
3317 else
3318 {
3319 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3320 }
Geoff Lang301d1612014-07-09 10:34:37 -04003321
Jiawei Shao54aafe52018-04-27 14:54:57 +08003322 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3323 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003324 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3325
Jamie Madill0f80ed82017-09-19 00:24:56 -04003326 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3327 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3328
3329 // Limit textures as well, so we can use fast bitsets with texture bindings.
3330 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003331 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3332 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3333 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3334 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003335
Jamie Madille3e680c2018-12-03 17:49:08 -05003336 LimitCap(&mCaps.maxImageUnits, IMPLEMENTATION_MAX_IMAGE_UNITS);
3337
Jiawei Shaodb342272017-09-27 10:21:45 +08003338 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3339
Geoff Langc287ea62016-09-16 14:46:51 -04003340 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003341 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003342 for (const auto &extensionInfo : GetExtensionInfoMap())
3343 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003344 // If the user has requested that extensions start disabled and they are requestable,
3345 // disable them.
3346 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003347 {
3348 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3349 }
3350 }
3351
3352 // Generate texture caps
3353 updateCaps();
3354}
3355
3356void Context::updateCaps()
3357{
Geoff Lang900013c2014-07-07 11:32:19 -04003358 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003359 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003360
Jamie Madill7b62cf92017-11-02 15:20:49 -04003361 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003362 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003363 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003364 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003365
Geoff Lang0d8b7242015-09-09 14:56:53 -04003366 // Update the format caps based on the client version and extensions.
3367 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3368 // ES3.
3369 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003370 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003371 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003372 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003373 formatCaps.textureAttachment =
3374 formatCaps.textureAttachment &&
3375 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3376 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3377 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003378
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003379 // OpenGL ES does not support multisampling with non-rendererable formats
3380 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003381 if (!formatCaps.renderbuffer ||
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003382 (getClientVersion() < ES_3_1 && !mSupportedExtensions.textureMultisample &&
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003383 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003384 {
Geoff Langd87878e2014-09-19 15:42:59 -04003385 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003386 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003387 else
3388 {
3389 // We may have limited the max samples for some required renderbuffer formats due to
3390 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3391 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3392
3393 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3394 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3395 // exception of signed and unsigned integer formats."
3396 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3397 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3398 {
3399 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3400 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3401 }
3402
3403 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003404 if (getClientVersion() >= ES_3_1 || mSupportedExtensions.textureMultisample)
Olli Etuaho50c562d2017-06-06 14:43:30 +03003405 {
3406 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3407 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3408 // the exception that the signed and unsigned integer formats are required only to
3409 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3410 // multisamples, which must be at least one."
3411 if (formatInfo.componentType == GL_INT ||
3412 formatInfo.componentType == GL_UNSIGNED_INT)
3413 {
3414 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3415 }
3416
3417 // GLES 3.1 section 19.3.1.
3418 if (formatCaps.texturable)
3419 {
3420 if (formatInfo.depthBits > 0)
3421 {
3422 mCaps.maxDepthTextureSamples =
3423 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3424 }
3425 else if (formatInfo.redBits > 0)
3426 {
3427 mCaps.maxColorTextureSamples =
3428 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3429 }
3430 }
3431 }
3432 }
Geoff Langd87878e2014-09-19 15:42:59 -04003433
3434 if (formatCaps.texturable && formatInfo.compressed)
3435 {
Geoff Langca271392017-04-05 12:30:00 -04003436 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003437 }
3438
Geoff Langca271392017-04-05 12:30:00 -04003439 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003440 }
Jamie Madill32447362017-06-28 14:53:52 -04003441
3442 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003443 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003444 {
3445 mMemoryProgramCache = nullptr;
3446 }
Corentin Walleze4477002017-12-01 14:39:58 -05003447
3448 // Compute which buffer types are allowed
3449 mValidBufferBindings.reset();
3450 mValidBufferBindings.set(BufferBinding::ElementArray);
3451 mValidBufferBindings.set(BufferBinding::Array);
3452
3453 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3454 {
3455 mValidBufferBindings.set(BufferBinding::PixelPack);
3456 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3457 }
3458
3459 if (getClientVersion() >= ES_3_0)
3460 {
3461 mValidBufferBindings.set(BufferBinding::CopyRead);
3462 mValidBufferBindings.set(BufferBinding::CopyWrite);
3463 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3464 mValidBufferBindings.set(BufferBinding::Uniform);
3465 }
3466
3467 if (getClientVersion() >= ES_3_1)
3468 {
3469 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3470 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3471 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3472 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3473 }
jchen107ae70d82018-07-06 13:47:01 +08003474
3475 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Jamie Madillac66f982018-10-09 18:30:01 -04003476
Jamie Madillef9fcd92018-11-28 14:03:59 -05003477 // Reinitialize some dirty bits that depend on extensions.
Jamie Madill132d15c2018-11-30 15:25:38 -05003478 bool robustInit = mGLState.isRobustResourceInitEnabled();
3479 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3480 mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3481 mDrawDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
3482 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3483 mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3484 mComputeDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
Jamie Madillef9fcd92018-11-28 14:03:59 -05003485
Jamie Madillac66f982018-10-09 18:30:01 -04003486 // Reinitialize state cache after extension changes.
3487 mStateCache.initialize(this);
Geoff Lang493daf52014-07-03 13:38:44 -04003488}
3489
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003490void Context::initWorkarounds()
3491{
Jamie Madill761b02c2017-06-23 16:27:06 -04003492 // Apply back-end workarounds.
3493 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3494
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003495 // Lose the context upon out of memory error if the application is
3496 // expecting to watch for those events.
3497 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
Jamie Madilld4f07762018-10-19 19:24:07 -04003498
3499 if (mWorkarounds.syncFramebufferBindingsOnTexImage)
3500 {
3501 // Update the Framebuffer bindings on TexImage to work around an Intel bug.
3502 mTexImageDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
3503 mTexImageDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
3504 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003505}
3506
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003507// Return true if the draw is a no-op, else return false.
3508// A no-op draw occurs if the count of vertices is less than the minimum required to
3509// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3510bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3511{
3512 return count < kMinimumPrimitiveCounts[mode];
3513}
3514
3515bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3516{
3517 return (instanceCount == 0) || noopDraw(mode, count);
3518}
3519
Jamie Madill132d15c2018-11-30 15:25:38 -05003520ANGLE_INLINE angle::Result Context::syncDirtyBits()
3521{
3522 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3523 ANGLE_TRY(mImplementation->syncState(this, dirtyBits, mAllDirtyBits));
3524 mGLState.clearDirtyBits();
Jamie Madill7c985f52018-11-29 18:16:17 -05003525 return angle::Result::Continue;
Jamie Madill132d15c2018-11-30 15:25:38 -05003526}
3527
3528ANGLE_INLINE angle::Result Context::syncDirtyBits(const State::DirtyBits &bitMask)
3529{
3530 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
3531 ANGLE_TRY(mImplementation->syncState(this, dirtyBits, bitMask));
3532 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill7c985f52018-11-29 18:16:17 -05003533 return angle::Result::Continue;
Jamie Madill132d15c2018-11-30 15:25:38 -05003534}
3535
3536ANGLE_INLINE angle::Result Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
3537{
3538 return mGLState.syncDirtyObjects(this, objectMask);
3539}
3540
3541ANGLE_INLINE angle::Result Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003542{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003543 if (mGLES1Renderer)
3544 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003545 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003546 }
3547
Geoff Lang9bf86f02018-07-26 11:46:34 -04003548 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madill132d15c2018-11-30 15:25:38 -05003549 ASSERT(!isRobustResourceInitEnabled() ||
3550 !mGLState.getDrawFramebuffer()->hasResourceThatNeedsInit());
3551 return syncDirtyBits();
Geoff Langd4fff502017-09-22 11:28:28 -04003552}
3553
Jamie Madill526392d2018-11-16 09:35:14 -05003554angle::Result Context::prepareForClear(GLbitfield mask)
Geoff Langd4fff502017-09-22 11:28:28 -04003555{
Geoff Langa8cb2872018-03-09 16:09:40 -05003556 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003557 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003558 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003559 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003560}
3561
Jamie Madill526392d2018-11-16 09:35:14 -05003562angle::Result Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
Geoff Langd4fff502017-09-22 11:28:28 -04003563{
Geoff Langa8cb2872018-03-09 16:09:40 -05003564 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003565 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3566 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003567 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003568 return angle::Result::Continue;
Jamie Madill05b35b22017-10-03 09:01:44 -04003569}
3570
Jamie Madill132d15c2018-11-30 15:25:38 -05003571ANGLE_INLINE angle::Result Context::prepareForDispatch()
3572{
3573 ANGLE_TRY(syncDirtyObjects(mComputeDirtyObjects));
3574 return syncDirtyBits(mComputeDirtyBits);
3575}
3576
Jamie Madill526392d2018-11-16 09:35:14 -05003577angle::Result Context::syncState(const State::DirtyBits &bitMask,
3578 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003579{
Geoff Langa8cb2872018-03-09 16:09:40 -05003580 ANGLE_TRY(syncDirtyObjects(objectMask));
3581 ANGLE_TRY(syncDirtyBits(bitMask));
Jamie Madill7c985f52018-11-29 18:16:17 -05003582 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003583}
3584
Jamie Madillc29968b2016-01-20 11:17:23 -05003585void Context::blitFramebuffer(GLint srcX0,
3586 GLint srcY0,
3587 GLint srcX1,
3588 GLint srcY1,
3589 GLint dstX0,
3590 GLint dstY0,
3591 GLint dstX1,
3592 GLint dstY1,
3593 GLbitfield mask,
3594 GLenum filter)
3595{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003596 if (mask == 0)
3597 {
3598 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3599 // buffers are copied.
3600 return;
3601 }
3602
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003603 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003604 ASSERT(drawFramebuffer);
3605
3606 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3607 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3608
Jamie Madillbc918e72018-03-08 09:47:21 -05003609 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003610
Jamie Madill4f6592f2018-11-27 16:37:45 -05003611 ANGLE_CONTEXT_TRY(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003612}
Jamie Madillc29968b2016-01-20 11:17:23 -05003613
3614void Context::clear(GLbitfield mask)
3615{
Geoff Langd4fff502017-09-22 11:28:28 -04003616 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3617 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003618}
3619
3620void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3621{
Olli Etuaho78df3362018-10-05 16:43:27 +03003622 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3623 const FramebufferAttachment *attachment = nullptr;
3624 if (buffer == GL_DEPTH)
3625 {
3626 attachment = framebufferObject->getDepthbuffer();
3627 }
3628 if (buffer == GL_COLOR &&
3629 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3630 {
3631 attachment = framebufferObject->getColorbuffer(drawbuffer);
3632 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003633 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3634 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003635 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003636 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003637 return;
3638 }
Geoff Langd4fff502017-09-22 11:28:28 -04003639 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003640 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003641}
3642
3643void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3644{
Olli Etuaho78df3362018-10-05 16:43:27 +03003645 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3646 const FramebufferAttachment *attachment = nullptr;
3647 if (buffer == GL_COLOR &&
3648 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3649 {
3650 attachment = framebufferObject->getColorbuffer(drawbuffer);
3651 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003652 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3653 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003654 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003655 {
3656 return;
3657 }
Geoff Langd4fff502017-09-22 11:28:28 -04003658 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003659 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003660}
3661
3662void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3663{
Olli Etuaho78df3362018-10-05 16:43:27 +03003664 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3665 const FramebufferAttachment *attachment = nullptr;
3666 if (buffer == GL_STENCIL)
3667 {
3668 attachment = framebufferObject->getStencilbuffer();
3669 }
3670 if (buffer == GL_COLOR &&
3671 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3672 {
3673 attachment = framebufferObject->getColorbuffer(drawbuffer);
3674 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003675 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3676 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003677 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003678 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003679 return;
3680 }
Geoff Langd4fff502017-09-22 11:28:28 -04003681 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003682 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003683}
3684
3685void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3686{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003687 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003688 ASSERT(framebufferObject);
3689
3690 // If a buffer is not present, the clear has no effect
3691 if (framebufferObject->getDepthbuffer() == nullptr &&
3692 framebufferObject->getStencilbuffer() == nullptr)
3693 {
3694 return;
3695 }
3696
Geoff Langd4fff502017-09-22 11:28:28 -04003697 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3698 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003699}
3700
3701void Context::readPixels(GLint x,
3702 GLint y,
3703 GLsizei width,
3704 GLsizei height,
3705 GLenum format,
3706 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003707 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003708{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003709 if (width == 0 || height == 0)
3710 {
3711 return;
3712 }
3713
Jamie Madillbc918e72018-03-08 09:47:21 -05003714 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003715
Jamie Madillb6664922017-07-25 12:55:04 -04003716 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3717 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003718
3719 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003720 ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003721}
3722
Brandon Jones59770802018-04-02 13:18:42 -07003723void Context::readPixelsRobust(GLint x,
3724 GLint y,
3725 GLsizei width,
3726 GLsizei height,
3727 GLenum format,
3728 GLenum type,
3729 GLsizei bufSize,
3730 GLsizei *length,
3731 GLsizei *columns,
3732 GLsizei *rows,
3733 void *pixels)
3734{
3735 readPixels(x, y, width, height, format, type, pixels);
3736}
3737
3738void Context::readnPixelsRobust(GLint x,
3739 GLint y,
3740 GLsizei width,
3741 GLsizei height,
3742 GLenum format,
3743 GLenum type,
3744 GLsizei bufSize,
3745 GLsizei *length,
3746 GLsizei *columns,
3747 GLsizei *rows,
3748 void *data)
3749{
3750 readPixels(x, y, width, height, format, type, data);
3751}
3752
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003753void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003754 GLint level,
3755 GLenum internalformat,
3756 GLint x,
3757 GLint y,
3758 GLsizei width,
3759 GLsizei height,
3760 GLint border)
3761{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003762 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003763 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003764
Jamie Madillc29968b2016-01-20 11:17:23 -05003765 Rectangle sourceArea(x, y, width, height);
3766
Jamie Madill05b35b22017-10-03 09:01:44 -04003767 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003768 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003769 ANGLE_CONTEXT_TRY(
3770 texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003771}
3772
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003773void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003774 GLint level,
3775 GLint xoffset,
3776 GLint yoffset,
3777 GLint x,
3778 GLint y,
3779 GLsizei width,
3780 GLsizei height)
3781{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003782 if (width == 0 || height == 0)
3783 {
3784 return;
3785 }
3786
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003787 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003788 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003789
Jamie Madillc29968b2016-01-20 11:17:23 -05003790 Offset destOffset(xoffset, yoffset, 0);
3791 Rectangle sourceArea(x, y, width, height);
3792
Jamie Madill05b35b22017-10-03 09:01:44 -04003793 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003794 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003795 ANGLE_CONTEXT_TRY(
3796 texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003797}
3798
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003799void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003800 GLint level,
3801 GLint xoffset,
3802 GLint yoffset,
3803 GLint zoffset,
3804 GLint x,
3805 GLint y,
3806 GLsizei width,
3807 GLsizei height)
3808{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003809 if (width == 0 || height == 0)
3810 {
3811 return;
3812 }
3813
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003814 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003815 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003816
Jamie Madillc29968b2016-01-20 11:17:23 -05003817 Offset destOffset(xoffset, yoffset, zoffset);
3818 Rectangle sourceArea(x, y, width, height);
3819
Jamie Madill05b35b22017-10-03 09:01:44 -04003820 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3821 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003822 ANGLE_CONTEXT_TRY(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level,
3823 destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003824}
3825
3826void Context::framebufferTexture2D(GLenum target,
3827 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003828 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003829 GLuint texture,
3830 GLint level)
3831{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003832 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003833 ASSERT(framebuffer);
3834
3835 if (texture != 0)
3836 {
3837 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003838 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003839 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003840 }
3841 else
3842 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003843 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003844 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003845
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003846 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003847}
3848
3849void Context::framebufferRenderbuffer(GLenum target,
3850 GLenum attachment,
3851 GLenum renderbuffertarget,
3852 GLuint renderbuffer)
3853{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003854 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003855 ASSERT(framebuffer);
3856
3857 if (renderbuffer != 0)
3858 {
3859 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003860
Jamie Madillcc129372018-04-12 09:13:18 -04003861 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003862 renderbufferObject);
3863 }
3864 else
3865 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003866 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003867 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003868
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003869 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003870}
3871
3872void Context::framebufferTextureLayer(GLenum target,
3873 GLenum attachment,
3874 GLuint texture,
3875 GLint level,
3876 GLint layer)
3877{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003878 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003879 ASSERT(framebuffer);
3880
3881 if (texture != 0)
3882 {
3883 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003884 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003885 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003886 }
3887 else
3888 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003889 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003890 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003891
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003892 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003893}
3894
Brandon Jones59770802018-04-02 13:18:42 -07003895void Context::framebufferTextureMultiviewLayered(GLenum target,
3896 GLenum attachment,
3897 GLuint texture,
3898 GLint level,
3899 GLint baseViewIndex,
3900 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003901{
Martin Radev82ef7742017-08-08 17:44:58 +03003902 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3903 ASSERT(framebuffer);
3904
3905 if (texture != 0)
3906 {
3907 Texture *textureObj = getTexture(texture);
3908
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003909 ImageIndex index;
3910 if (textureObj->getType() == TextureType::_2DArray)
3911 {
3912 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3913 }
3914 else
3915 {
3916 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3917 ASSERT(level == 0);
3918 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3919 }
Martin Radev82ef7742017-08-08 17:44:58 +03003920 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3921 numViews, baseViewIndex);
3922 }
3923 else
3924 {
3925 framebuffer->resetAttachment(this, attachment);
3926 }
3927
3928 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003929}
3930
Brandon Jones59770802018-04-02 13:18:42 -07003931void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3932 GLenum attachment,
3933 GLuint texture,
3934 GLint level,
3935 GLsizei numViews,
3936 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003937{
Martin Radev5dae57b2017-07-14 16:15:55 +03003938 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3939 ASSERT(framebuffer);
3940
3941 if (texture != 0)
3942 {
3943 Texture *textureObj = getTexture(texture);
3944
3945 ImageIndex index = ImageIndex::Make2D(level);
3946 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3947 textureObj, numViews, viewportOffsets);
3948 }
3949 else
3950 {
3951 framebuffer->resetAttachment(this, attachment);
3952 }
3953
3954 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003955}
3956
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003957void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3958{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003959 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3960 ASSERT(framebuffer);
3961
3962 if (texture != 0)
3963 {
3964 Texture *textureObj = getTexture(texture);
3965
3966 ImageIndex index = ImageIndex::MakeFromType(
3967 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3968 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3969 }
3970 else
3971 {
3972 framebuffer->resetAttachment(this, attachment);
3973 }
3974
3975 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003976}
3977
Jamie Madillc29968b2016-01-20 11:17:23 -05003978void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3979{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003980 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003981 ASSERT(framebuffer);
3982 framebuffer->setDrawBuffers(n, bufs);
Jamie Madillef9fcd92018-11-28 14:03:59 -05003983 mGLState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04003984 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003985}
3986
3987void Context::readBuffer(GLenum mode)
3988{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003989 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003990 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003991 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003992}
3993
3994void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3995{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003996 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003997 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003998
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003999 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05004000 ASSERT(framebuffer);
4001
4002 // The specification isn't clear what should be done when the framebuffer isn't complete.
4003 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4f6592f2018-11-27 16:37:45 -05004004 ANGLE_CONTEXT_TRY(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05004005}
4006
4007void Context::invalidateFramebuffer(GLenum target,
4008 GLsizei numAttachments,
4009 const GLenum *attachments)
4010{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004011 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05004012 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004013
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004014 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05004015 ASSERT(framebuffer);
4016
Jamie Madill427064d2018-04-13 16:20:34 -04004017 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05004018 {
Jamie Madill437fa652016-05-03 15:13:24 -04004019 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05004020 }
Jamie Madill437fa652016-05-03 15:13:24 -04004021
Jamie Madill4f6592f2018-11-27 16:37:45 -05004022 ANGLE_CONTEXT_TRY(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05004023}
4024
4025void Context::invalidateSubFramebuffer(GLenum target,
4026 GLsizei numAttachments,
4027 const GLenum *attachments,
4028 GLint x,
4029 GLint y,
4030 GLsizei width,
4031 GLsizei height)
4032{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004033 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05004034 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004035
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004036 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05004037 ASSERT(framebuffer);
4038
Jamie Madill427064d2018-04-13 16:20:34 -04004039 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05004040 {
Jamie Madill437fa652016-05-03 15:13:24 -04004041 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05004042 }
Jamie Madill437fa652016-05-03 15:13:24 -04004043
4044 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004045 ANGLE_CONTEXT_TRY(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05004046}
4047
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004048void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004049 GLint level,
4050 GLint internalformat,
4051 GLsizei width,
4052 GLsizei height,
4053 GLint border,
4054 GLenum format,
4055 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004056 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004057{
Jamie Madillbc918e72018-03-08 09:47:21 -05004058 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004059
4060 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004061 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004062 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(), target, level,
4063 internalformat, size, format, type,
4064 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004065}
4066
Brandon Jones59770802018-04-02 13:18:42 -07004067void Context::texImage2DRobust(TextureTarget target,
4068 GLint level,
4069 GLint internalformat,
4070 GLsizei width,
4071 GLsizei height,
4072 GLint border,
4073 GLenum format,
4074 GLenum type,
4075 GLsizei bufSize,
4076 const void *pixels)
4077{
4078 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
4079}
4080
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004081void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004082 GLint level,
4083 GLint internalformat,
4084 GLsizei width,
4085 GLsizei height,
4086 GLsizei depth,
4087 GLint border,
4088 GLenum format,
4089 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004090 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004091{
Jamie Madillbc918e72018-03-08 09:47:21 -05004092 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004093
4094 Extents size(width, height, depth);
4095 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004096 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(),
4097 NonCubeTextureTypeToTarget(target), level, internalformat,
4098 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004099}
4100
Brandon Jones59770802018-04-02 13:18:42 -07004101void Context::texImage3DRobust(TextureType target,
4102 GLint level,
4103 GLint internalformat,
4104 GLsizei width,
4105 GLsizei height,
4106 GLsizei depth,
4107 GLint border,
4108 GLenum format,
4109 GLenum type,
4110 GLsizei bufSize,
4111 const void *pixels)
4112{
4113 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4114}
4115
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004116void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004117 GLint level,
4118 GLint xoffset,
4119 GLint yoffset,
4120 GLsizei width,
4121 GLsizei height,
4122 GLenum format,
4123 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004124 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004125{
4126 // Zero sized uploads are valid but no-ops
4127 if (width == 0 || height == 0)
4128 {
4129 return;
4130 }
4131
Jamie Madillbc918e72018-03-08 09:47:21 -05004132 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004133
4134 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004135 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004136
4137 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4138
Jamie Madill4f6592f2018-11-27 16:37:45 -05004139 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target,
4140 level, area, format, type,
4141 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004142}
4143
Brandon Jones59770802018-04-02 13:18:42 -07004144void Context::texSubImage2DRobust(TextureTarget target,
4145 GLint level,
4146 GLint xoffset,
4147 GLint yoffset,
4148 GLsizei width,
4149 GLsizei height,
4150 GLenum format,
4151 GLenum type,
4152 GLsizei bufSize,
4153 const void *pixels)
4154{
4155 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4156}
4157
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004158void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004159 GLint level,
4160 GLint xoffset,
4161 GLint yoffset,
4162 GLint zoffset,
4163 GLsizei width,
4164 GLsizei height,
4165 GLsizei depth,
4166 GLenum format,
4167 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004168 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004169{
4170 // Zero sized uploads are valid but no-ops
4171 if (width == 0 || height == 0 || depth == 0)
4172 {
4173 return;
4174 }
4175
Jamie Madillbc918e72018-03-08 09:47:21 -05004176 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004177
4178 Box area(xoffset, yoffset, zoffset, width, height, depth);
4179 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004180
4181 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4182
Jamie Madill4f6592f2018-11-27 16:37:45 -05004183 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
4184 NonCubeTextureTypeToTarget(target), level, area, format,
4185 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004186}
4187
Brandon Jones59770802018-04-02 13:18:42 -07004188void Context::texSubImage3DRobust(TextureType target,
4189 GLint level,
4190 GLint xoffset,
4191 GLint yoffset,
4192 GLint zoffset,
4193 GLsizei width,
4194 GLsizei height,
4195 GLsizei depth,
4196 GLenum format,
4197 GLenum type,
4198 GLsizei bufSize,
4199 const void *pixels)
4200{
4201 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4202 pixels);
4203}
4204
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004205void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004206 GLint level,
4207 GLenum internalformat,
4208 GLsizei width,
4209 GLsizei height,
4210 GLint border,
4211 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004212 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004213{
Jamie Madillbc918e72018-03-08 09:47:21 -05004214 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004215
4216 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004217 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004218 ANGLE_CONTEXT_TRY(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4219 internalformat, size, imageSize,
4220 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004221}
4222
Brandon Jones59770802018-04-02 13:18:42 -07004223void Context::compressedTexImage2DRobust(TextureTarget target,
4224 GLint level,
4225 GLenum internalformat,
4226 GLsizei width,
4227 GLsizei height,
4228 GLint border,
4229 GLsizei imageSize,
4230 GLsizei dataSize,
4231 const GLvoid *data)
4232{
4233 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4234}
4235
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004236void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004237 GLint level,
4238 GLenum internalformat,
4239 GLsizei width,
4240 GLsizei height,
4241 GLsizei depth,
4242 GLint border,
4243 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004244 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004245{
Jamie Madillbc918e72018-03-08 09:47:21 -05004246 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004247
4248 Extents size(width, height, depth);
4249 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004250 ANGLE_CONTEXT_TRY(texture->setCompressedImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004251 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004252 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004253}
4254
Brandon Jones59770802018-04-02 13:18:42 -07004255void Context::compressedTexImage3DRobust(TextureType target,
4256 GLint level,
4257 GLenum internalformat,
4258 GLsizei width,
4259 GLsizei height,
4260 GLsizei depth,
4261 GLint border,
4262 GLsizei imageSize,
4263 GLsizei dataSize,
4264 const GLvoid *data)
4265{
4266 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4267 data);
4268}
4269
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004270void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004271 GLint level,
4272 GLint xoffset,
4273 GLint yoffset,
4274 GLsizei width,
4275 GLsizei height,
4276 GLenum format,
4277 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004278 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004279{
Jamie Madillbc918e72018-03-08 09:47:21 -05004280 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004281
4282 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004283 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004284 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level,
4285 area, format, imageSize,
4286 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004287}
4288
Brandon Jones59770802018-04-02 13:18:42 -07004289void Context::compressedTexSubImage2DRobust(TextureTarget target,
4290 GLint level,
4291 GLint xoffset,
4292 GLint yoffset,
4293 GLsizei width,
4294 GLsizei height,
4295 GLenum format,
4296 GLsizei imageSize,
4297 GLsizei dataSize,
4298 const GLvoid *data)
4299{
4300 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4301 data);
4302}
4303
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004304void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004305 GLint level,
4306 GLint xoffset,
4307 GLint yoffset,
4308 GLint zoffset,
4309 GLsizei width,
4310 GLsizei height,
4311 GLsizei depth,
4312 GLenum format,
4313 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004314 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004315{
4316 // Zero sized uploads are valid but no-ops
4317 if (width == 0 || height == 0)
4318 {
4319 return;
4320 }
4321
Jamie Madillbc918e72018-03-08 09:47:21 -05004322 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004323
4324 Box area(xoffset, yoffset, zoffset, width, height, depth);
4325 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004326 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004327 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004328 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004329}
4330
Brandon Jones59770802018-04-02 13:18:42 -07004331void Context::compressedTexSubImage3DRobust(TextureType target,
4332 GLint level,
4333 GLint xoffset,
4334 GLint yoffset,
4335 GLint zoffset,
4336 GLsizei width,
4337 GLsizei height,
4338 GLsizei depth,
4339 GLenum format,
4340 GLsizei imageSize,
4341 GLsizei dataSize,
4342 const GLvoid *data)
4343{
4344 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4345 imageSize, data);
4346}
4347
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004348void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004349{
4350 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004351 ANGLE_CONTEXT_TRY(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004352}
4353
Jamie Madill007530e2017-12-28 14:27:04 -05004354void Context::copyTexture(GLuint sourceId,
4355 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004356 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004357 GLuint destId,
4358 GLint destLevel,
4359 GLint internalFormat,
4360 GLenum destType,
4361 GLboolean unpackFlipY,
4362 GLboolean unpackPremultiplyAlpha,
4363 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004364{
Jamie Madillbc918e72018-03-08 09:47:21 -05004365 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004366
4367 gl::Texture *sourceTexture = getTexture(sourceId);
4368 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004369 ANGLE_CONTEXT_TRY(
4370 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4371 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4372 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004373}
4374
Jamie Madill007530e2017-12-28 14:27:04 -05004375void Context::copySubTexture(GLuint sourceId,
4376 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004377 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004378 GLuint destId,
4379 GLint destLevel,
4380 GLint xoffset,
4381 GLint yoffset,
4382 GLint x,
4383 GLint y,
4384 GLsizei width,
4385 GLsizei height,
4386 GLboolean unpackFlipY,
4387 GLboolean unpackPremultiplyAlpha,
4388 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004389{
4390 // Zero sized copies are valid but no-ops
4391 if (width == 0 || height == 0)
4392 {
4393 return;
4394 }
4395
Jamie Madillbc918e72018-03-08 09:47:21 -05004396 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004397
4398 gl::Texture *sourceTexture = getTexture(sourceId);
4399 gl::Texture *destTexture = getTexture(destId);
4400 Offset offset(xoffset, yoffset, 0);
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004401 Box box(x, y, 0, width, height, 1);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004402 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4403 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4404 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4405 sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004406}
4407
4408void Context::copyTexture3D(GLuint sourceId,
4409 GLint sourceLevel,
4410 TextureTarget destTarget,
4411 GLuint destId,
4412 GLint destLevel,
4413 GLint internalFormat,
4414 GLenum destType,
4415 GLboolean unpackFlipY,
4416 GLboolean unpackPremultiplyAlpha,
4417 GLboolean unpackUnmultiplyAlpha)
4418{
4419 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4420
4421 Texture *sourceTexture = getTexture(sourceId);
4422 Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004423 ANGLE_CONTEXT_TRY(
4424 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4425 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4426 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004427}
4428
4429void Context::copySubTexture3D(GLuint sourceId,
4430 GLint sourceLevel,
4431 TextureTarget destTarget,
4432 GLuint destId,
4433 GLint destLevel,
4434 GLint xoffset,
4435 GLint yoffset,
4436 GLint zoffset,
4437 GLint x,
4438 GLint y,
4439 GLint z,
4440 GLsizei width,
4441 GLsizei height,
4442 GLsizei depth,
4443 GLboolean unpackFlipY,
4444 GLboolean unpackPremultiplyAlpha,
4445 GLboolean unpackUnmultiplyAlpha)
4446{
4447 // Zero sized copies are valid but no-ops
4448 if (width == 0 || height == 0 || depth == 0)
4449 {
4450 return;
4451 }
4452
4453 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4454
4455 Texture *sourceTexture = getTexture(sourceId);
4456 Texture *destTexture = getTexture(destId);
4457 Offset offset(xoffset, yoffset, zoffset);
4458 Box box(x, y, z, width, height, depth);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004459 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4460 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4461 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4462 sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004463}
4464
Jamie Madill007530e2017-12-28 14:27:04 -05004465void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004466{
Jamie Madillbc918e72018-03-08 09:47:21 -05004467 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004468
4469 gl::Texture *sourceTexture = getTexture(sourceId);
4470 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004471 ANGLE_CONTEXT_TRY(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004472}
4473
Corentin Wallez336129f2017-10-17 15:55:40 -04004474void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004475{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004476 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004477 ASSERT(buffer);
4478
Geoff Lang496c02d2016-10-20 11:38:11 -07004479 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004480}
4481
Brandon Jones59770802018-04-02 13:18:42 -07004482void Context::getBufferPointervRobust(BufferBinding target,
4483 GLenum pname,
4484 GLsizei bufSize,
4485 GLsizei *length,
4486 void **params)
4487{
4488 getBufferPointerv(target, pname, params);
4489}
4490
Corentin Wallez336129f2017-10-17 15:55:40 -04004491void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004492{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004493 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004494 ASSERT(buffer);
4495
Jamie Madill7c985f52018-11-29 18:16:17 -05004496 if (buffer->map(this, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004497 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004498 return nullptr;
4499 }
4500
4501 return buffer->getMapPointer();
4502}
4503
Corentin Wallez336129f2017-10-17 15:55:40 -04004504GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004505{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004506 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004507 ASSERT(buffer);
4508
4509 GLboolean result;
Jamie Madill7c985f52018-11-29 18:16:17 -05004510 if (buffer->unmap(this, &result) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004511 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004512 return GL_FALSE;
4513 }
4514
4515 return result;
4516}
4517
Corentin Wallez336129f2017-10-17 15:55:40 -04004518void *Context::mapBufferRange(BufferBinding target,
4519 GLintptr offset,
4520 GLsizeiptr length,
4521 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004522{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004523 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004524 ASSERT(buffer);
4525
Jamie Madill7c985f52018-11-29 18:16:17 -05004526 if (buffer->mapRange(this, offset, length, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004527 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004528 return nullptr;
4529 }
4530
4531 return buffer->getMapPointer();
4532}
4533
Corentin Wallez336129f2017-10-17 15:55:40 -04004534void Context::flushMappedBufferRange(BufferBinding /*target*/,
4535 GLintptr /*offset*/,
4536 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004537{
4538 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4539}
4540
Jamie Madill526392d2018-11-16 09:35:14 -05004541angle::Result Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004542{
Geoff Langa8cb2872018-03-09 16:09:40 -05004543 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004544}
4545
Jamie Madill526392d2018-11-16 09:35:14 -05004546angle::Result Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004547{
Geoff Langa8cb2872018-03-09 16:09:40 -05004548 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004549}
4550
Jamie Madill526392d2018-11-16 09:35:14 -05004551angle::Result Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004552{
Geoff Langa8cb2872018-03-09 16:09:40 -05004553 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004554}
4555
Jamie Madill526392d2018-11-16 09:35:14 -05004556angle::Result Context::syncStateForPathOperation()
Geoff Lang9bf86f02018-07-26 11:46:34 -04004557{
4558 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4559
4560 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4561 ANGLE_TRY(syncDirtyBits());
4562
Jamie Madill7c985f52018-11-29 18:16:17 -05004563 return angle::Result::Continue;
Geoff Lang9bf86f02018-07-26 11:46:34 -04004564}
4565
Jiajia Qin5451d532017-11-16 17:16:34 +08004566void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4567{
4568 UNIMPLEMENTED();
4569}
4570
Jamie Madillc20ab272016-06-09 07:20:46 -07004571void Context::activeTexture(GLenum texture)
4572{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004573 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004574}
4575
Jamie Madill876429b2017-04-20 15:46:24 -04004576void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004577{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004578 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004579}
4580
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004581void Context::blendEquation(GLenum mode)
4582{
4583 mGLState.setBlendEquation(mode, mode);
4584}
4585
Jamie Madillc20ab272016-06-09 07:20:46 -07004586void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4587{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004588 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004589}
4590
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004591void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4592{
4593 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4594}
4595
Jamie Madillc20ab272016-06-09 07:20:46 -07004596void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4597{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004598 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004599}
4600
Jamie Madill876429b2017-04-20 15:46:24 -04004601void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004602{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004603 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004604}
4605
Jamie Madill876429b2017-04-20 15:46:24 -04004606void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004607{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004608 mGLState.setDepthClearValue(clamp01(depth));
Jamie Madillc20ab272016-06-09 07:20:46 -07004609}
4610
4611void Context::clearStencil(GLint s)
4612{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004613 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004614}
4615
4616void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4617{
Geoff Lang92019432017-11-20 13:09:34 -05004618 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4619 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004620}
4621
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004622void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004623{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004624 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004625}
4626
4627void Context::depthFunc(GLenum func)
4628{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004629 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004630}
4631
4632void Context::depthMask(GLboolean flag)
4633{
Geoff Lang92019432017-11-20 13:09:34 -05004634 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004635}
4636
Jamie Madill876429b2017-04-20 15:46:24 -04004637void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004638{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004639 mGLState.setDepthRange(clamp01(zNear), clamp01(zFar));
Jamie Madillc20ab272016-06-09 07:20:46 -07004640}
4641
4642void Context::disable(GLenum cap)
4643{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004644 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004645 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004646}
4647
4648void Context::disableVertexAttribArray(GLuint index)
4649{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004650 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004651 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004652}
4653
4654void Context::enable(GLenum cap)
4655{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004656 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004657 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004658}
4659
4660void Context::enableVertexAttribArray(GLuint index)
4661{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004662 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004663 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004664}
4665
4666void Context::frontFace(GLenum mode)
4667{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004668 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004669}
4670
4671void Context::hint(GLenum target, GLenum mode)
4672{
4673 switch (target)
4674 {
4675 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004676 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004677 break;
4678
4679 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004680 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004681 break;
4682
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004683 case GL_PERSPECTIVE_CORRECTION_HINT:
4684 case GL_POINT_SMOOTH_HINT:
4685 case GL_LINE_SMOOTH_HINT:
4686 case GL_FOG_HINT:
4687 mGLState.gles1().setHint(target, mode);
4688 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004689 default:
4690 UNREACHABLE();
4691 return;
4692 }
4693}
4694
4695void Context::lineWidth(GLfloat width)
4696{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004697 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004698}
4699
4700void Context::pixelStorei(GLenum pname, GLint param)
4701{
4702 switch (pname)
4703 {
4704 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004705 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004706 break;
4707
4708 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004709 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004710 break;
4711
4712 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004713 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004714 break;
4715
4716 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004717 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004718 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004719 break;
4720
4721 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004722 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004723 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004724 break;
4725
4726 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004727 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004728 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004729 break;
4730
4731 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004732 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004733 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004734 break;
4735
4736 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004737 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004738 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004739 break;
4740
4741 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004742 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004743 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004744 break;
4745
4746 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004747 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004748 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004749 break;
4750
4751 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004752 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004753 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004754 break;
4755
4756 default:
4757 UNREACHABLE();
4758 return;
4759 }
4760}
4761
4762void Context::polygonOffset(GLfloat factor, GLfloat units)
4763{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004764 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004765}
4766
Jamie Madill876429b2017-04-20 15:46:24 -04004767void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004768{
Geoff Lang92019432017-11-20 13:09:34 -05004769 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004770}
4771
Jiawei Shaodb342272017-09-27 10:21:45 +08004772void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4773{
4774 mGLState.setSampleMaskParams(maskNumber, mask);
4775}
4776
Jamie Madillc20ab272016-06-09 07:20:46 -07004777void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4778{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004779 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004780}
4781
4782void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4783{
4784 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4785 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004786 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004787 }
4788
4789 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4790 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004791 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004792 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004793
4794 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004795}
4796
4797void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4798{
4799 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4800 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004801 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004802 }
4803
4804 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4805 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004806 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004807 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004808
4809 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004810}
4811
4812void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4813{
4814 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4815 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004816 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004817 }
4818
4819 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4820 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004821 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004822 }
4823}
4824
4825void Context::vertexAttrib1f(GLuint index, GLfloat x)
4826{
4827 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004828 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004829 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004830}
4831
4832void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4833{
4834 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004835 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004836 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004837}
4838
4839void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4840{
4841 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004842 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004843 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004844}
4845
4846void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4847{
4848 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004849 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004850 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004851}
4852
4853void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4854{
4855 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004856 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004857 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004858}
4859
4860void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4861{
4862 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004863 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004864 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004865}
4866
4867void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4868{
4869 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004870 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004871 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004872}
4873
4874void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4875{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004876 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004877 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004878}
4879
4880void Context::vertexAttribPointer(GLuint index,
4881 GLint size,
4882 GLenum type,
4883 GLboolean normalized,
4884 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004885 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004886{
Corentin Wallez336129f2017-10-17 15:55:40 -04004887 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004888 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004889 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004890}
4891
Shao80957d92017-02-20 21:25:59 +08004892void Context::vertexAttribFormat(GLuint attribIndex,
4893 GLint size,
4894 GLenum type,
4895 GLboolean normalized,
4896 GLuint relativeOffset)
4897{
Geoff Lang92019432017-11-20 13:09:34 -05004898 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004899 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004900 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004901}
4902
4903void Context::vertexAttribIFormat(GLuint attribIndex,
4904 GLint size,
4905 GLenum type,
4906 GLuint relativeOffset)
4907{
4908 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004909 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004910}
4911
4912void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4913{
Shaodde78e82017-05-22 14:13:27 +08004914 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004915 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004916}
4917
Jiajia Qin5451d532017-11-16 17:16:34 +08004918void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004919{
4920 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004921 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004922}
4923
Jamie Madillc20ab272016-06-09 07:20:46 -07004924void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4925{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004926 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004927}
4928
4929void Context::vertexAttribIPointer(GLuint index,
4930 GLint size,
4931 GLenum type,
4932 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004933 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004934{
Corentin Wallez336129f2017-10-17 15:55:40 -04004935 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4936 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004937 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004938}
4939
4940void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4941{
4942 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004943 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004944 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004945}
4946
4947void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4948{
4949 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004950 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004951 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004952}
4953
4954void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4955{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004956 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004957 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004958}
4959
4960void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4961{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004962 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004963 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004964}
4965
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004966void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4967{
4968 const VertexAttribCurrentValueData &currentValues =
4969 getGLState().getVertexAttribCurrentValue(index);
4970 const VertexArray *vao = getGLState().getVertexArray();
4971 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4972 currentValues, pname, params);
4973}
4974
Brandon Jones59770802018-04-02 13:18:42 -07004975void Context::getVertexAttribivRobust(GLuint index,
4976 GLenum pname,
4977 GLsizei bufSize,
4978 GLsizei *length,
4979 GLint *params)
4980{
4981 getVertexAttribiv(index, pname, params);
4982}
4983
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004984void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4985{
4986 const VertexAttribCurrentValueData &currentValues =
4987 getGLState().getVertexAttribCurrentValue(index);
4988 const VertexArray *vao = getGLState().getVertexArray();
4989 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4990 currentValues, pname, params);
4991}
4992
Brandon Jones59770802018-04-02 13:18:42 -07004993void Context::getVertexAttribfvRobust(GLuint index,
4994 GLenum pname,
4995 GLsizei bufSize,
4996 GLsizei *length,
4997 GLfloat *params)
4998{
4999 getVertexAttribfv(index, pname, params);
5000}
5001
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005002void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
5003{
5004 const VertexAttribCurrentValueData &currentValues =
5005 getGLState().getVertexAttribCurrentValue(index);
5006 const VertexArray *vao = getGLState().getVertexArray();
5007 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
5008 currentValues, pname, params);
5009}
5010
Brandon Jones59770802018-04-02 13:18:42 -07005011void Context::getVertexAttribIivRobust(GLuint index,
5012 GLenum pname,
5013 GLsizei bufSize,
5014 GLsizei *length,
5015 GLint *params)
5016{
5017 getVertexAttribIiv(index, pname, params);
5018}
5019
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005020void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
5021{
5022 const VertexAttribCurrentValueData &currentValues =
5023 getGLState().getVertexAttribCurrentValue(index);
5024 const VertexArray *vao = getGLState().getVertexArray();
5025 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
5026 currentValues, pname, params);
5027}
5028
Brandon Jones59770802018-04-02 13:18:42 -07005029void Context::getVertexAttribIuivRobust(GLuint index,
5030 GLenum pname,
5031 GLsizei bufSize,
5032 GLsizei *length,
5033 GLuint *params)
5034{
5035 getVertexAttribIuiv(index, pname, params);
5036}
5037
Jamie Madill876429b2017-04-20 15:46:24 -04005038void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005039{
5040 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
5041 QueryVertexAttribPointerv(attrib, pname, pointer);
5042}
5043
Brandon Jones59770802018-04-02 13:18:42 -07005044void Context::getVertexAttribPointervRobust(GLuint index,
5045 GLenum pname,
5046 GLsizei bufSize,
5047 GLsizei *length,
5048 void **pointer)
5049{
5050 getVertexAttribPointerv(index, pname, pointer);
5051}
5052
Jamie Madillc20ab272016-06-09 07:20:46 -07005053void Context::debugMessageControl(GLenum source,
5054 GLenum type,
5055 GLenum severity,
5056 GLsizei count,
5057 const GLuint *ids,
5058 GLboolean enabled)
5059{
5060 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005061 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05005062 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07005063}
5064
5065void Context::debugMessageInsert(GLenum source,
5066 GLenum type,
5067 GLuint id,
5068 GLenum severity,
5069 GLsizei length,
5070 const GLchar *buf)
5071{
5072 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005073 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07005074}
5075
5076void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
5077{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005078 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07005079}
5080
5081GLuint Context::getDebugMessageLog(GLuint count,
5082 GLsizei bufSize,
5083 GLenum *sources,
5084 GLenum *types,
5085 GLuint *ids,
5086 GLenum *severities,
5087 GLsizei *lengths,
5088 GLchar *messageLog)
5089{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005090 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
5091 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07005092}
5093
5094void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
5095{
5096 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005097 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05005098 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07005099}
5100
5101void Context::popDebugGroup()
5102{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005103 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05005104 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07005105}
5106
Corentin Wallez336129f2017-10-17 15:55:40 -04005107void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04005108{
5109 Buffer *buffer = mGLState.getTargetBuffer(target);
5110 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005111 ANGLE_CONTEXT_TRY(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04005112}
5113
Corentin Wallez336129f2017-10-17 15:55:40 -04005114void Context::bufferSubData(BufferBinding target,
5115 GLintptr offset,
5116 GLsizeiptr size,
5117 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04005118{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06005119 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04005120 {
5121 return;
5122 }
5123
5124 Buffer *buffer = mGLState.getTargetBuffer(target);
5125 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005126 ANGLE_CONTEXT_TRY(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04005127}
5128
Jamie Madillef300b12016-10-07 15:12:09 -04005129void Context::attachShader(GLuint program, GLuint shader)
5130{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05005131 Program *programObject = mState.mShaderPrograms->getProgram(program);
5132 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04005133 ASSERT(programObject && shaderObject);
5134 programObject->attachShader(shaderObject);
5135}
5136
Kenneth Russellf2f6f652016-10-05 19:53:23 -07005137const Workarounds &Context::getWorkarounds() const
5138{
5139 return mWorkarounds;
5140}
5141
Corentin Wallez336129f2017-10-17 15:55:40 -04005142void Context::copyBufferSubData(BufferBinding readTarget,
5143 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005144 GLintptr readOffset,
5145 GLintptr writeOffset,
5146 GLsizeiptr size)
5147{
5148 // if size is zero, the copy is a successful no-op
5149 if (size == 0)
5150 {
5151 return;
5152 }
5153
5154 // TODO(jmadill): cache these.
5155 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
5156 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
5157
Jamie Madill4f6592f2018-11-27 16:37:45 -05005158 ANGLE_CONTEXT_TRY(
5159 writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005160}
5161
Jamie Madill01a80ee2016-11-07 12:06:18 -05005162void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5163{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005164 // Ideally we could share the program query with the validation layer if possible.
5165 Program *programObject = getProgramResolveLink(program);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005166 ASSERT(programObject);
5167 programObject->bindAttributeLocation(index, name);
5168}
5169
Corentin Wallez336129f2017-10-17 15:55:40 -04005170void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005171{
Corentin Wallez336129f2017-10-17 15:55:40 -04005172 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5173 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04005174 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005175}
5176
Corentin Wallez336129f2017-10-17 15:55:40 -04005177void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005178{
5179 bindBufferRange(target, index, buffer, 0, 0);
5180}
5181
Corentin Wallez336129f2017-10-17 15:55:40 -04005182void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005183 GLuint index,
5184 GLuint buffer,
5185 GLintptr offset,
5186 GLsizeiptr size)
5187{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005188 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
Geoff Lang91002262018-12-12 16:05:24 -05005189 ANGLE_CONTEXT_TRY(mGLState.setIndexedBufferBinding(this, target, index, object, offset, size));
Jamie Madill6d32cef2018-08-14 02:34:28 -04005190 if (target == BufferBinding::Uniform)
5191 {
Jamie Madill472ddc82018-10-18 18:41:56 -04005192 mUniformBufferObserverBindings[index].bind(object);
Jamie Madilld84b6732018-09-06 15:54:35 -04005193 mStateCache.onUniformBufferStateChange(this);
5194 }
5195 else
5196 {
5197 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005198 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005199}
5200
Jamie Madill01a80ee2016-11-07 12:06:18 -05005201void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5202{
5203 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5204 {
5205 bindReadFramebuffer(framebuffer);
5206 }
5207
5208 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5209 {
5210 bindDrawFramebuffer(framebuffer);
5211 }
5212}
5213
5214void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5215{
5216 ASSERT(target == GL_RENDERBUFFER);
5217 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005218 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005219 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005220}
5221
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005222void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005223 GLsizei samples,
5224 GLenum internalformat,
5225 GLsizei width,
5226 GLsizei height,
5227 GLboolean fixedsamplelocations)
5228{
5229 Extents size(width, height, 1);
5230 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005231 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5232 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005233}
5234
Olli Etuaho89664842018-08-24 14:45:36 +03005235void Context::texStorage3DMultisample(TextureType target,
5236 GLsizei samples,
5237 GLenum internalformat,
5238 GLsizei width,
5239 GLsizei height,
5240 GLsizei depth,
5241 GLboolean fixedsamplelocations)
5242{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005243 Extents size(width, height, depth);
5244 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005245 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5246 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005247}
5248
JiangYizhoubddc46b2016-12-09 09:50:51 +08005249void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5250{
JiangYizhou5b03f472017-01-09 10:22:53 +08005251 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5252 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005253 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005254 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005255
5256 switch (pname)
5257 {
5258 case GL_SAMPLE_POSITION:
Jamie Madill4f6592f2018-11-27 16:37:45 -05005259 ANGLE_CONTEXT_TRY(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005260 break;
5261 default:
5262 UNREACHABLE();
5263 }
5264}
5265
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005266void Context::getMultisamplefvRobust(GLenum pname,
5267 GLuint index,
5268 GLsizei bufSize,
5269 GLsizei *length,
5270 GLfloat *val)
5271{
5272 UNIMPLEMENTED();
5273}
5274
Jamie Madille8fb6402017-02-14 17:56:40 -05005275void Context::renderbufferStorage(GLenum target,
5276 GLenum internalformat,
5277 GLsizei width,
5278 GLsizei height)
5279{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005280 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5281 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5282
Jamie Madille8fb6402017-02-14 17:56:40 -05005283 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005284 ANGLE_CONTEXT_TRY(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005285}
5286
5287void Context::renderbufferStorageMultisample(GLenum target,
5288 GLsizei samples,
5289 GLenum internalformat,
5290 GLsizei width,
5291 GLsizei height)
5292{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005293 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5294 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005295
5296 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005297 ANGLE_CONTEXT_TRY(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005298 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005299}
5300
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005301void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5302{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005303 const Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005304 ANGLE_CONTEXT_TRY(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005305}
5306
JiangYizhoue18e6392017-02-20 10:32:23 +08005307void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5308{
5309 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5310 QueryFramebufferParameteriv(framebuffer, pname, params);
5311}
5312
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005313void Context::getFramebufferParameterivRobust(GLenum target,
5314 GLenum pname,
5315 GLsizei bufSize,
5316 GLsizei *length,
5317 GLint *params)
5318{
5319 UNIMPLEMENTED();
5320}
5321
Jiajia Qin5451d532017-11-16 17:16:34 +08005322void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005323{
5324 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005325 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005326}
5327
Jamie Madilldec86232018-07-11 09:01:18 -04005328bool Context::getScratchBuffer(size_t requstedSizeBytes,
5329 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005330{
Jamie Madilldec86232018-07-11 09:01:18 -04005331 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005332}
5333
Jamie Madilldec86232018-07-11 09:01:18 -04005334bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5335 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005336{
Jamie Madilldec86232018-07-11 09:01:18 -04005337 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005338}
5339
Xinghua Cao2b396592017-03-29 15:36:04 +08005340void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5341{
5342 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5343 {
5344 return;
5345 }
5346
Xinghua Cao10a4d432017-11-28 14:46:26 +08005347 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005348 ANGLE_CONTEXT_TRY(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005349}
5350
Jiajia Qin5451d532017-11-16 17:16:34 +08005351void Context::dispatchComputeIndirect(GLintptr indirect)
5352{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005353 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005354 ANGLE_CONTEXT_TRY(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005355}
5356
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005357void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005358 GLsizei levels,
5359 GLenum internalFormat,
5360 GLsizei width,
5361 GLsizei height)
5362{
5363 Extents size(width, height, 1);
5364 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005365 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005366}
5367
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005368void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005369 GLsizei levels,
5370 GLenum internalFormat,
5371 GLsizei width,
5372 GLsizei height,
5373 GLsizei depth)
5374{
5375 Extents size(width, height, depth);
5376 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005377 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005378}
5379
Jiajia Qin5451d532017-11-16 17:16:34 +08005380void Context::memoryBarrier(GLbitfield barriers)
5381{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005382 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005383}
5384
5385void Context::memoryBarrierByRegion(GLbitfield barriers)
5386{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005387 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005388}
5389
Austin Eng1bf18ce2018-10-19 15:34:02 -07005390void Context::multiDrawArrays(PrimitiveMode mode,
5391 const GLint *firsts,
5392 const GLsizei *counts,
5393 GLsizei drawcount)
5394{
5395 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5396 Program *programObject = mGLState.getLinkedProgram(this);
5397 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5398 if (hasDrawID)
5399 {
5400 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5401 {
5402 if (noopDraw(mode, counts[drawID]))
5403 {
5404 continue;
5405 }
5406 programObject->setDrawIDUniform(drawID);
5407 ANGLE_CONTEXT_TRY(
5408 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
5409 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5410 counts[drawID], 1);
5411 }
5412 }
5413 else
5414 {
5415 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5416 {
5417 if (noopDraw(mode, counts[drawID]))
5418 {
5419 continue;
5420 }
5421 ANGLE_CONTEXT_TRY(
5422 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
5423 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5424 counts[drawID], 1);
5425 }
5426 }
5427}
5428
5429void Context::multiDrawArraysInstanced(PrimitiveMode mode,
5430 const GLint *firsts,
5431 const GLsizei *counts,
5432 const GLsizei *instanceCounts,
5433 GLsizei drawcount)
5434{
5435 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5436 Program *programObject = mGLState.getLinkedProgram(this);
5437 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5438 if (hasDrawID)
5439 {
5440 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5441 {
5442 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5443 {
5444 continue;
5445 }
5446 programObject->setDrawIDUniform(drawID);
5447 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5448 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
5449 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5450 counts[drawID], instanceCounts[drawID]);
5451 }
5452 }
5453 else
5454 {
5455 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5456 {
5457 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5458 {
5459 continue;
5460 }
5461 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5462 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
5463 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5464 counts[drawID], instanceCounts[drawID]);
5465 }
5466 }
5467}
5468
5469void Context::multiDrawElements(PrimitiveMode mode,
5470 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005471 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005472 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005473 GLsizei drawcount)
5474{
5475 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5476 Program *programObject = mGLState.getLinkedProgram(this);
5477 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5478 if (hasDrawID)
5479 {
5480 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5481 {
5482 if (noopDraw(mode, counts[drawID]))
5483 {
5484 continue;
5485 }
5486 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005487 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005488 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005489 }
5490 }
5491 else
5492 {
5493 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5494 {
5495 if (noopDraw(mode, counts[drawID]))
5496 {
5497 continue;
5498 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005499 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005500 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005501 }
5502 }
5503}
5504
5505void Context::multiDrawElementsInstanced(PrimitiveMode mode,
5506 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005507 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005508 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005509 const GLsizei *instanceCounts,
5510 GLsizei drawcount)
5511{
5512 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5513 Program *programObject = mGLState.getLinkedProgram(this);
5514 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5515 if (hasDrawID)
5516 {
5517 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5518 {
5519 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5520 {
5521 continue;
5522 }
5523 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005524 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005525 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005526 }
5527 }
5528 else
5529 {
5530 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5531 {
5532 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5533 {
5534 continue;
5535 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005536 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005537 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005538 }
5539 }
5540}
5541
Jamie Madillc1d770e2017-04-13 17:31:24 -04005542GLenum Context::checkFramebufferStatus(GLenum target)
5543{
5544 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5545 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005546 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005547}
5548
5549void Context::compileShader(GLuint shader)
5550{
5551 Shader *shaderObject = GetValidShader(this, shader);
5552 if (!shaderObject)
5553 {
5554 return;
5555 }
5556 shaderObject->compile(this);
5557}
5558
5559void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5560{
5561 for (int i = 0; i < n; i++)
5562 {
5563 deleteBuffer(buffers[i]);
5564 }
5565}
5566
5567void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5568{
5569 for (int i = 0; i < n; i++)
5570 {
5571 if (framebuffers[i] != 0)
5572 {
5573 deleteFramebuffer(framebuffers[i]);
5574 }
5575 }
5576}
5577
5578void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5579{
5580 for (int i = 0; i < n; i++)
5581 {
5582 deleteRenderbuffer(renderbuffers[i]);
5583 }
5584}
5585
5586void Context::deleteTextures(GLsizei n, const GLuint *textures)
5587{
5588 for (int i = 0; i < n; i++)
5589 {
5590 if (textures[i] != 0)
5591 {
5592 deleteTexture(textures[i]);
5593 }
5594 }
5595}
5596
5597void Context::detachShader(GLuint program, GLuint shader)
5598{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005599 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005600 ASSERT(programObject);
5601
5602 Shader *shaderObject = getShader(shader);
5603 ASSERT(shaderObject);
5604
5605 programObject->detachShader(this, shaderObject);
5606}
5607
5608void Context::genBuffers(GLsizei n, GLuint *buffers)
5609{
5610 for (int i = 0; i < n; i++)
5611 {
5612 buffers[i] = createBuffer();
5613 }
5614}
5615
5616void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5617{
5618 for (int i = 0; i < n; i++)
5619 {
5620 framebuffers[i] = createFramebuffer();
5621 }
5622}
5623
5624void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5625{
5626 for (int i = 0; i < n; i++)
5627 {
5628 renderbuffers[i] = createRenderbuffer();
5629 }
5630}
5631
5632void Context::genTextures(GLsizei n, GLuint *textures)
5633{
5634 for (int i = 0; i < n; i++)
5635 {
5636 textures[i] = createTexture();
5637 }
5638}
5639
5640void Context::getActiveAttrib(GLuint program,
5641 GLuint index,
5642 GLsizei bufsize,
5643 GLsizei *length,
5644 GLint *size,
5645 GLenum *type,
5646 GLchar *name)
5647{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005648 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005649 ASSERT(programObject);
5650 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5651}
5652
5653void Context::getActiveUniform(GLuint program,
5654 GLuint index,
5655 GLsizei bufsize,
5656 GLsizei *length,
5657 GLint *size,
5658 GLenum *type,
5659 GLchar *name)
5660{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005661 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005662 ASSERT(programObject);
5663 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5664}
5665
5666void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5667{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005668 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005669 ASSERT(programObject);
5670 programObject->getAttachedShaders(maxcount, count, shaders);
5671}
5672
5673GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5674{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005675 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005676 ASSERT(programObject);
5677 return programObject->getAttributeLocation(name);
5678}
5679
5680void Context::getBooleanv(GLenum pname, GLboolean *params)
5681{
5682 GLenum nativeType;
5683 unsigned int numParams = 0;
5684 getQueryParameterInfo(pname, &nativeType, &numParams);
5685
5686 if (nativeType == GL_BOOL)
5687 {
5688 getBooleanvImpl(pname, params);
5689 }
5690 else
5691 {
5692 CastStateValues(this, nativeType, pname, numParams, params);
5693 }
5694}
5695
Brandon Jones59770802018-04-02 13:18:42 -07005696void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5697{
5698 getBooleanv(pname, params);
5699}
5700
Jamie Madillc1d770e2017-04-13 17:31:24 -04005701void Context::getFloatv(GLenum pname, GLfloat *params)
5702{
5703 GLenum nativeType;
5704 unsigned int numParams = 0;
5705 getQueryParameterInfo(pname, &nativeType, &numParams);
5706
5707 if (nativeType == GL_FLOAT)
5708 {
5709 getFloatvImpl(pname, params);
5710 }
5711 else
5712 {
5713 CastStateValues(this, nativeType, pname, numParams, params);
5714 }
5715}
5716
Brandon Jones59770802018-04-02 13:18:42 -07005717void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5718{
5719 getFloatv(pname, params);
5720}
5721
Jamie Madillc1d770e2017-04-13 17:31:24 -04005722void Context::getIntegerv(GLenum pname, GLint *params)
5723{
5724 GLenum nativeType;
5725 unsigned int numParams = 0;
5726 getQueryParameterInfo(pname, &nativeType, &numParams);
5727
5728 if (nativeType == GL_INT)
5729 {
5730 getIntegervImpl(pname, params);
5731 }
5732 else
5733 {
5734 CastStateValues(this, nativeType, pname, numParams, params);
5735 }
5736}
5737
Brandon Jones59770802018-04-02 13:18:42 -07005738void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5739{
5740 getIntegerv(pname, data);
5741}
5742
Jamie Madillc1d770e2017-04-13 17:31:24 -04005743void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5744{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005745 // Don't resolve link if checking the link completion status.
5746 Program *programObject = (pname == GL_COMPLETION_STATUS_KHR ? getProgramNoResolveLink(program)
5747 : getProgramResolveLink(program));
Jamie Madillc1d770e2017-04-13 17:31:24 -04005748 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005749 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005750}
5751
Brandon Jones59770802018-04-02 13:18:42 -07005752void Context::getProgramivRobust(GLuint program,
5753 GLenum pname,
5754 GLsizei bufSize,
5755 GLsizei *length,
5756 GLint *params)
5757{
5758 getProgramiv(program, pname, params);
5759}
5760
Jiajia Qin5451d532017-11-16 17:16:34 +08005761void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5762{
5763 UNIMPLEMENTED();
5764}
5765
Jamie Madillbe849e42017-05-02 15:49:00 -04005766void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005767{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005768 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005769 ASSERT(programObject);
5770 programObject->getInfoLog(bufsize, length, infolog);
5771}
5772
Jiajia Qin5451d532017-11-16 17:16:34 +08005773void Context::getProgramPipelineInfoLog(GLuint pipeline,
5774 GLsizei bufSize,
5775 GLsizei *length,
5776 GLchar *infoLog)
5777{
5778 UNIMPLEMENTED();
5779}
5780
Jamie Madillc1d770e2017-04-13 17:31:24 -04005781void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5782{
5783 Shader *shaderObject = getShader(shader);
5784 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005785 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005786}
5787
Brandon Jones59770802018-04-02 13:18:42 -07005788void Context::getShaderivRobust(GLuint shader,
5789 GLenum pname,
5790 GLsizei bufSize,
5791 GLsizei *length,
5792 GLint *params)
5793{
5794 getShaderiv(shader, pname, params);
5795}
5796
Jamie Madillc1d770e2017-04-13 17:31:24 -04005797void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5798{
5799 Shader *shaderObject = getShader(shader);
5800 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005801 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005802}
5803
5804void Context::getShaderPrecisionFormat(GLenum shadertype,
5805 GLenum precisiontype,
5806 GLint *range,
5807 GLint *precision)
5808{
5809 // TODO(jmadill): Compute shaders.
5810
5811 switch (shadertype)
5812 {
5813 case GL_VERTEX_SHADER:
5814 switch (precisiontype)
5815 {
5816 case GL_LOW_FLOAT:
5817 mCaps.vertexLowpFloat.get(range, precision);
5818 break;
5819 case GL_MEDIUM_FLOAT:
5820 mCaps.vertexMediumpFloat.get(range, precision);
5821 break;
5822 case GL_HIGH_FLOAT:
5823 mCaps.vertexHighpFloat.get(range, precision);
5824 break;
5825
5826 case GL_LOW_INT:
5827 mCaps.vertexLowpInt.get(range, precision);
5828 break;
5829 case GL_MEDIUM_INT:
5830 mCaps.vertexMediumpInt.get(range, precision);
5831 break;
5832 case GL_HIGH_INT:
5833 mCaps.vertexHighpInt.get(range, precision);
5834 break;
5835
5836 default:
5837 UNREACHABLE();
5838 return;
5839 }
5840 break;
5841
5842 case GL_FRAGMENT_SHADER:
5843 switch (precisiontype)
5844 {
5845 case GL_LOW_FLOAT:
5846 mCaps.fragmentLowpFloat.get(range, precision);
5847 break;
5848 case GL_MEDIUM_FLOAT:
5849 mCaps.fragmentMediumpFloat.get(range, precision);
5850 break;
5851 case GL_HIGH_FLOAT:
5852 mCaps.fragmentHighpFloat.get(range, precision);
5853 break;
5854
5855 case GL_LOW_INT:
5856 mCaps.fragmentLowpInt.get(range, precision);
5857 break;
5858 case GL_MEDIUM_INT:
5859 mCaps.fragmentMediumpInt.get(range, precision);
5860 break;
5861 case GL_HIGH_INT:
5862 mCaps.fragmentHighpInt.get(range, precision);
5863 break;
5864
5865 default:
5866 UNREACHABLE();
5867 return;
5868 }
5869 break;
5870
5871 default:
5872 UNREACHABLE();
5873 return;
5874 }
5875}
5876
5877void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5878{
5879 Shader *shaderObject = getShader(shader);
5880 ASSERT(shaderObject);
5881 shaderObject->getSource(bufsize, length, source);
5882}
5883
5884void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5885{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005886 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005887 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005888 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005889}
5890
Brandon Jones59770802018-04-02 13:18:42 -07005891void Context::getUniformfvRobust(GLuint program,
5892 GLint location,
5893 GLsizei bufSize,
5894 GLsizei *length,
5895 GLfloat *params)
5896{
5897 getUniformfv(program, location, params);
5898}
5899
Jamie Madillc1d770e2017-04-13 17:31:24 -04005900void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5901{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005902 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005903 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005904 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005905}
5906
Brandon Jones59770802018-04-02 13:18:42 -07005907void Context::getUniformivRobust(GLuint program,
5908 GLint location,
5909 GLsizei bufSize,
5910 GLsizei *length,
5911 GLint *params)
5912{
5913 getUniformiv(program, location, params);
5914}
5915
Jamie Madillc1d770e2017-04-13 17:31:24 -04005916GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5917{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005918 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005919 ASSERT(programObject);
5920 return programObject->getUniformLocation(name);
5921}
5922
5923GLboolean Context::isBuffer(GLuint buffer)
5924{
5925 if (buffer == 0)
5926 {
5927 return GL_FALSE;
5928 }
5929
5930 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5931}
5932
5933GLboolean Context::isEnabled(GLenum cap)
5934{
5935 return mGLState.getEnableFeature(cap);
5936}
5937
5938GLboolean Context::isFramebuffer(GLuint framebuffer)
5939{
5940 if (framebuffer == 0)
5941 {
5942 return GL_FALSE;
5943 }
5944
5945 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5946}
5947
5948GLboolean Context::isProgram(GLuint program)
5949{
5950 if (program == 0)
5951 {
5952 return GL_FALSE;
5953 }
5954
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005955 return (getProgramNoResolveLink(program) ? GL_TRUE : GL_FALSE);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005956}
5957
5958GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5959{
5960 if (renderbuffer == 0)
5961 {
5962 return GL_FALSE;
5963 }
5964
5965 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5966}
5967
5968GLboolean Context::isShader(GLuint shader)
5969{
5970 if (shader == 0)
5971 {
5972 return GL_FALSE;
5973 }
5974
5975 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5976}
5977
5978GLboolean Context::isTexture(GLuint texture)
5979{
5980 if (texture == 0)
5981 {
5982 return GL_FALSE;
5983 }
5984
5985 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5986}
5987
5988void Context::linkProgram(GLuint program)
5989{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005990 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005991 ASSERT(programObject);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005992 ANGLE_CONTEXT_TRY(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005993
5994 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5995 // don't need to worry that:
5996 // 1. Draw calls after link use the new executable code or the old one depending on the link
5997 // result.
5998 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5999 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
6000 // ProgramD3D.
6001 if (programObject->isInUse())
6002 {
Jamie Madill785e8a02018-10-04 17:42:00 -04006003 programObject->resolveLink(this);
Jamie Madilldf836ff2018-10-01 10:36:24 -04006004 if (programObject->isLinked())
6005 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04006006 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006007 }
jchen107ae70d82018-07-06 13:47:01 +08006008 mStateCache.onProgramExecutableChange(this);
6009 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04006010}
6011
6012void Context::releaseShaderCompiler()
6013{
Jamie Madill4928b7c2017-06-20 12:57:39 -04006014 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006015}
6016
6017void Context::shaderBinary(GLsizei n,
6018 const GLuint *shaders,
6019 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04006020 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006021 GLsizei length)
6022{
6023 // No binary shader formats are supported.
6024 UNIMPLEMENTED();
6025}
6026
Olli Etuaho0ca09752018-09-24 11:00:50 +03006027void Context::bindFragDataLocationIndexed(GLuint program,
6028 GLuint colorNumber,
6029 GLuint index,
6030 const char *name)
6031{
6032 Program *programObject = getProgramNoResolveLink(program);
6033 programObject->bindFragmentOutputLocation(colorNumber, name);
6034 programObject->bindFragmentOutputIndex(index, name);
6035}
6036
6037void Context::bindFragDataLocation(GLuint program, GLuint colorNumber, const char *name)
6038{
6039 bindFragDataLocationIndexed(program, colorNumber, 0u, name);
6040}
6041
6042int Context::getFragDataIndex(GLuint program, const char *name)
6043{
6044 Program *programObject = getProgramResolveLink(program);
6045 return programObject->getFragDataIndex(name);
6046}
6047
6048int Context::getProgramResourceLocationIndex(GLuint program,
6049 GLenum programInterface,
6050 const char *name)
6051{
6052 Program *programObject = getProgramResolveLink(program);
6053 ASSERT(programInterface == GL_PROGRAM_OUTPUT);
6054 return programObject->getFragDataIndex(name);
6055}
6056
Jamie Madillc1d770e2017-04-13 17:31:24 -04006057void Context::shaderSource(GLuint shader,
6058 GLsizei count,
6059 const GLchar *const *string,
6060 const GLint *length)
6061{
6062 Shader *shaderObject = getShader(shader);
6063 ASSERT(shaderObject);
6064 shaderObject->setSource(count, string, length);
6065}
6066
6067void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
6068{
6069 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
6070}
6071
6072void Context::stencilMask(GLuint mask)
6073{
6074 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6075}
6076
6077void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6078{
6079 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6080}
6081
6082void Context::uniform1f(GLint location, GLfloat x)
6083{
6084 Program *program = mGLState.getProgram();
6085 program->setUniform1fv(location, 1, &x);
6086}
6087
6088void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
6089{
6090 Program *program = mGLState.getProgram();
6091 program->setUniform1fv(location, count, v);
6092}
6093
Jamie Madill7e4eff12018-08-08 15:49:26 -04006094void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006095{
Jamie Madille3e680c2018-12-03 17:49:08 -05006096 program->setUniform1iv(this, location, count, v);
6097}
6098
6099void Context::onSamplerUniformChange(size_t textureUnitIndex)
6100{
6101 mGLState.onActiveTextureChange(this, textureUnitIndex);
6102 mStateCache.onActiveTextureChange(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006103}
6104
Jamie Madill7e4eff12018-08-08 15:49:26 -04006105void Context::uniform1i(GLint location, GLint x)
6106{
6107 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
6108}
6109
Jamie Madillc1d770e2017-04-13 17:31:24 -04006110void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
6111{
Jamie Madill7e4eff12018-08-08 15:49:26 -04006112 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006113}
6114
6115void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
6116{
6117 GLfloat xy[2] = {x, y};
6118 Program *program = mGLState.getProgram();
6119 program->setUniform2fv(location, 1, xy);
6120}
6121
6122void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
6123{
6124 Program *program = mGLState.getProgram();
6125 program->setUniform2fv(location, count, v);
6126}
6127
6128void Context::uniform2i(GLint location, GLint x, GLint y)
6129{
6130 GLint xy[2] = {x, y};
6131 Program *program = mGLState.getProgram();
6132 program->setUniform2iv(location, 1, xy);
6133}
6134
6135void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
6136{
6137 Program *program = mGLState.getProgram();
6138 program->setUniform2iv(location, count, v);
6139}
6140
6141void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6142{
6143 GLfloat xyz[3] = {x, y, z};
6144 Program *program = mGLState.getProgram();
6145 program->setUniform3fv(location, 1, xyz);
6146}
6147
6148void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
6149{
6150 Program *program = mGLState.getProgram();
6151 program->setUniform3fv(location, count, v);
6152}
6153
6154void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
6155{
6156 GLint xyz[3] = {x, y, z};
6157 Program *program = mGLState.getProgram();
6158 program->setUniform3iv(location, 1, xyz);
6159}
6160
6161void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
6162{
6163 Program *program = mGLState.getProgram();
6164 program->setUniform3iv(location, count, v);
6165}
6166
6167void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6168{
6169 GLfloat xyzw[4] = {x, y, z, w};
6170 Program *program = mGLState.getProgram();
6171 program->setUniform4fv(location, 1, xyzw);
6172}
6173
6174void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
6175{
6176 Program *program = mGLState.getProgram();
6177 program->setUniform4fv(location, count, v);
6178}
6179
6180void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6181{
6182 GLint xyzw[4] = {x, y, z, w};
6183 Program *program = mGLState.getProgram();
6184 program->setUniform4iv(location, 1, xyzw);
6185}
6186
6187void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
6188{
6189 Program *program = mGLState.getProgram();
6190 program->setUniform4iv(location, count, v);
6191}
6192
6193void Context::uniformMatrix2fv(GLint location,
6194 GLsizei count,
6195 GLboolean transpose,
6196 const GLfloat *value)
6197{
6198 Program *program = mGLState.getProgram();
6199 program->setUniformMatrix2fv(location, count, transpose, value);
6200}
6201
6202void Context::uniformMatrix3fv(GLint location,
6203 GLsizei count,
6204 GLboolean transpose,
6205 const GLfloat *value)
6206{
6207 Program *program = mGLState.getProgram();
6208 program->setUniformMatrix3fv(location, count, transpose, value);
6209}
6210
6211void Context::uniformMatrix4fv(GLint location,
6212 GLsizei count,
6213 GLboolean transpose,
6214 const GLfloat *value)
6215{
6216 Program *program = mGLState.getProgram();
6217 program->setUniformMatrix4fv(location, count, transpose, value);
6218}
6219
6220void Context::validateProgram(GLuint program)
6221{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006222 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006223 ASSERT(programObject);
6224 programObject->validate(mCaps);
6225}
6226
Jiajia Qin5451d532017-11-16 17:16:34 +08006227void Context::validateProgramPipeline(GLuint pipeline)
6228{
6229 UNIMPLEMENTED();
6230}
6231
Jamie Madilld04908b2017-06-09 14:15:35 -04006232void Context::getProgramBinary(GLuint program,
6233 GLsizei bufSize,
6234 GLsizei *length,
6235 GLenum *binaryFormat,
6236 void *binary)
6237{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006238 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006239 ASSERT(programObject != nullptr);
6240
Jamie Madill4f6592f2018-11-27 16:37:45 -05006241 ANGLE_CONTEXT_TRY(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
Jamie Madilld04908b2017-06-09 14:15:35 -04006242}
6243
6244void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
6245{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006246 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006247 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04006248
Jamie Madill4f6592f2018-11-27 16:37:45 -05006249 ANGLE_CONTEXT_TRY(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madill70aeda42018-08-20 12:17:40 -04006250 if (programObject->isInUse())
6251 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04006252 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006253 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006254 }
Jamie Madilld04908b2017-06-09 14:15:35 -04006255}
6256
Jamie Madillff325f12017-08-26 15:06:05 -04006257void Context::uniform1ui(GLint location, GLuint v0)
6258{
6259 Program *program = mGLState.getProgram();
6260 program->setUniform1uiv(location, 1, &v0);
6261}
6262
6263void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
6264{
6265 Program *program = mGLState.getProgram();
6266 const GLuint xy[] = {v0, v1};
6267 program->setUniform2uiv(location, 1, xy);
6268}
6269
6270void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6271{
6272 Program *program = mGLState.getProgram();
6273 const GLuint xyz[] = {v0, v1, v2};
6274 program->setUniform3uiv(location, 1, xyz);
6275}
6276
6277void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6278{
6279 Program *program = mGLState.getProgram();
6280 const GLuint xyzw[] = {v0, v1, v2, v3};
6281 program->setUniform4uiv(location, 1, xyzw);
6282}
6283
6284void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
6285{
6286 Program *program = mGLState.getProgram();
6287 program->setUniform1uiv(location, count, value);
6288}
6289void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
6290{
6291 Program *program = mGLState.getProgram();
6292 program->setUniform2uiv(location, count, value);
6293}
6294
6295void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
6296{
6297 Program *program = mGLState.getProgram();
6298 program->setUniform3uiv(location, count, value);
6299}
6300
6301void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
6302{
6303 Program *program = mGLState.getProgram();
6304 program->setUniform4uiv(location, count, value);
6305}
6306
Jamie Madillf0e04492017-08-26 15:28:42 -04006307void Context::genQueries(GLsizei n, GLuint *ids)
6308{
6309 for (GLsizei i = 0; i < n; i++)
6310 {
6311 GLuint handle = mQueryHandleAllocator.allocate();
6312 mQueryMap.assign(handle, nullptr);
6313 ids[i] = handle;
6314 }
6315}
6316
6317void Context::deleteQueries(GLsizei n, const GLuint *ids)
6318{
6319 for (int i = 0; i < n; i++)
6320 {
6321 GLuint query = ids[i];
6322
6323 Query *queryObject = nullptr;
6324 if (mQueryMap.erase(query, &queryObject))
6325 {
6326 mQueryHandleAllocator.release(query);
6327 if (queryObject)
6328 {
6329 queryObject->release(this);
6330 }
6331 }
6332 }
6333}
6334
6335GLboolean Context::isQuery(GLuint id)
6336{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006337 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006338}
6339
Jamie Madillc8c95812017-08-26 18:40:09 -04006340void Context::uniformMatrix2x3fv(GLint location,
6341 GLsizei count,
6342 GLboolean transpose,
6343 const GLfloat *value)
6344{
6345 Program *program = mGLState.getProgram();
6346 program->setUniformMatrix2x3fv(location, count, transpose, value);
6347}
6348
6349void Context::uniformMatrix3x2fv(GLint location,
6350 GLsizei count,
6351 GLboolean transpose,
6352 const GLfloat *value)
6353{
6354 Program *program = mGLState.getProgram();
6355 program->setUniformMatrix3x2fv(location, count, transpose, value);
6356}
6357
6358void Context::uniformMatrix2x4fv(GLint location,
6359 GLsizei count,
6360 GLboolean transpose,
6361 const GLfloat *value)
6362{
6363 Program *program = mGLState.getProgram();
6364 program->setUniformMatrix2x4fv(location, count, transpose, value);
6365}
6366
6367void Context::uniformMatrix4x2fv(GLint location,
6368 GLsizei count,
6369 GLboolean transpose,
6370 const GLfloat *value)
6371{
6372 Program *program = mGLState.getProgram();
6373 program->setUniformMatrix4x2fv(location, count, transpose, value);
6374}
6375
6376void Context::uniformMatrix3x4fv(GLint location,
6377 GLsizei count,
6378 GLboolean transpose,
6379 const GLfloat *value)
6380{
6381 Program *program = mGLState.getProgram();
6382 program->setUniformMatrix3x4fv(location, count, transpose, value);
6383}
6384
6385void Context::uniformMatrix4x3fv(GLint location,
6386 GLsizei count,
6387 GLboolean transpose,
6388 const GLfloat *value)
6389{
6390 Program *program = mGLState.getProgram();
6391 program->setUniformMatrix4x3fv(location, count, transpose, value);
6392}
6393
Jamie Madilld7576732017-08-26 18:49:50 -04006394void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6395{
6396 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6397 {
6398 GLuint vertexArray = arrays[arrayIndex];
6399
6400 if (arrays[arrayIndex] != 0)
6401 {
6402 VertexArray *vertexArrayObject = nullptr;
6403 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6404 {
6405 if (vertexArrayObject != nullptr)
6406 {
6407 detachVertexArray(vertexArray);
6408 vertexArrayObject->onDestroy(this);
6409 }
6410
6411 mVertexArrayHandleAllocator.release(vertexArray);
6412 }
6413 }
6414 }
6415}
6416
6417void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6418{
6419 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6420 {
6421 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6422 mVertexArrayMap.assign(vertexArray, nullptr);
6423 arrays[arrayIndex] = vertexArray;
6424 }
6425}
6426
6427bool Context::isVertexArray(GLuint array)
6428{
6429 if (array == 0)
6430 {
6431 return GL_FALSE;
6432 }
6433
6434 VertexArray *vao = getVertexArray(array);
6435 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6436}
6437
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006438void Context::endTransformFeedback()
6439{
6440 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006441 ANGLE_CONTEXT_TRY(transformFeedback->end(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006442 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006443}
6444
6445void Context::transformFeedbackVaryings(GLuint program,
6446 GLsizei count,
6447 const GLchar *const *varyings,
6448 GLenum bufferMode)
6449{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006450 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006451 ASSERT(programObject);
6452 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6453}
6454
6455void Context::getTransformFeedbackVarying(GLuint program,
6456 GLuint index,
6457 GLsizei bufSize,
6458 GLsizei *length,
6459 GLsizei *size,
6460 GLenum *type,
6461 GLchar *name)
6462{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006463 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006464 ASSERT(programObject);
6465 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6466}
6467
6468void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6469{
6470 for (int i = 0; i < n; i++)
6471 {
6472 GLuint transformFeedback = ids[i];
6473 if (transformFeedback == 0)
6474 {
6475 continue;
6476 }
6477
6478 TransformFeedback *transformFeedbackObject = nullptr;
6479 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6480 {
6481 if (transformFeedbackObject != nullptr)
6482 {
6483 detachTransformFeedback(transformFeedback);
6484 transformFeedbackObject->release(this);
6485 }
6486
6487 mTransformFeedbackHandleAllocator.release(transformFeedback);
6488 }
6489 }
6490}
6491
6492void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6493{
6494 for (int i = 0; i < n; i++)
6495 {
6496 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6497 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6498 ids[i] = transformFeedback;
6499 }
6500}
6501
6502bool Context::isTransformFeedback(GLuint id)
6503{
6504 if (id == 0)
6505 {
6506 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6507 // returns FALSE
6508 return GL_FALSE;
6509 }
6510
6511 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6512 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6513}
6514
6515void Context::pauseTransformFeedback()
6516{
6517 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006518 ANGLE_CONTEXT_TRY(transformFeedback->pause(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006519 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006520}
6521
6522void Context::resumeTransformFeedback()
6523{
6524 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006525 ANGLE_CONTEXT_TRY(transformFeedback->resume(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006526 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006527}
6528
Jamie Madill12e957f2017-08-26 21:42:26 -04006529void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6530{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006531 const Program *programObject = getProgramResolveLink(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006532 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006533}
6534
Brandon Jones59770802018-04-02 13:18:42 -07006535void Context::getUniformuivRobust(GLuint program,
6536 GLint location,
6537 GLsizei bufSize,
6538 GLsizei *length,
6539 GLuint *params)
6540{
6541 getUniformuiv(program, location, params);
6542}
6543
Jamie Madill12e957f2017-08-26 21:42:26 -04006544GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6545{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006546 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006547 return programObject->getFragDataLocation(name);
6548}
6549
6550void Context::getUniformIndices(GLuint program,
6551 GLsizei uniformCount,
6552 const GLchar *const *uniformNames,
6553 GLuint *uniformIndices)
6554{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006555 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006556 if (!programObject->isLinked())
6557 {
6558 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6559 {
6560 uniformIndices[uniformId] = GL_INVALID_INDEX;
6561 }
6562 }
6563 else
6564 {
6565 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6566 {
6567 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6568 }
6569 }
6570}
6571
6572void Context::getActiveUniformsiv(GLuint program,
6573 GLsizei uniformCount,
6574 const GLuint *uniformIndices,
6575 GLenum pname,
6576 GLint *params)
6577{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006578 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006579 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6580 {
6581 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006582 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006583 }
6584}
6585
6586GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6587{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006588 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006589 return programObject->getUniformBlockIndex(uniformBlockName);
6590}
6591
6592void Context::getActiveUniformBlockiv(GLuint program,
6593 GLuint uniformBlockIndex,
6594 GLenum pname,
6595 GLint *params)
6596{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006597 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006598 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6599}
6600
Brandon Jones59770802018-04-02 13:18:42 -07006601void Context::getActiveUniformBlockivRobust(GLuint program,
6602 GLuint uniformBlockIndex,
6603 GLenum pname,
6604 GLsizei bufSize,
6605 GLsizei *length,
6606 GLint *params)
6607{
6608 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6609}
6610
Jamie Madill12e957f2017-08-26 21:42:26 -04006611void Context::getActiveUniformBlockName(GLuint program,
6612 GLuint uniformBlockIndex,
6613 GLsizei bufSize,
6614 GLsizei *length,
6615 GLchar *uniformBlockName)
6616{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006617 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006618 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6619}
6620
6621void Context::uniformBlockBinding(GLuint program,
6622 GLuint uniformBlockIndex,
6623 GLuint uniformBlockBinding)
6624{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006625 Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006626 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006627
Jamie Madill956ab4d2018-10-10 16:13:03 -04006628 // Note: If the Program is shared between Contexts we would be better using Observer/Subject.
Jamie Madill70aeda42018-08-20 12:17:40 -04006629 if (programObject->isInUse())
6630 {
6631 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006632 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006633 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006634}
6635
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006636GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6637{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006638 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6639 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006640
Jamie Madill70b5bb02017-08-28 13:32:37 -04006641 Sync *syncObject = getSync(syncHandle);
Jamie Madill7c985f52018-11-29 18:16:17 -05006642 if (syncObject->set(this, condition, flags) == angle::Result::Stop)
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006643 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006644 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006645 return nullptr;
6646 }
6647
Jamie Madill70b5bb02017-08-28 13:32:37 -04006648 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006649}
6650
6651GLboolean Context::isSync(GLsync sync)
6652{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006653 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006654}
6655
6656GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6657{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006658 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006659
6660 GLenum result = GL_WAIT_FAILED;
Jamie Madill7c985f52018-11-29 18:16:17 -05006661 if (syncObject->clientWait(this, flags, timeout, &result) == angle::Result::Stop)
Jamie Madill4f6592f2018-11-27 16:37:45 -05006662 {
6663 return GL_WAIT_FAILED;
6664 }
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006665 return result;
6666}
6667
6668void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6669{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006670 Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006671 ANGLE_CONTEXT_TRY(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006672}
6673
6674void Context::getInteger64v(GLenum pname, GLint64 *params)
6675{
6676 GLenum nativeType = GL_NONE;
6677 unsigned int numParams = 0;
6678 getQueryParameterInfo(pname, &nativeType, &numParams);
6679
6680 if (nativeType == GL_INT_64_ANGLEX)
6681 {
6682 getInteger64vImpl(pname, params);
6683 }
6684 else
6685 {
6686 CastStateValues(this, nativeType, pname, numParams, params);
6687 }
6688}
6689
Brandon Jones59770802018-04-02 13:18:42 -07006690void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6691{
6692 getInteger64v(pname, data);
6693}
6694
Corentin Wallez336129f2017-10-17 15:55:40 -04006695void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006696{
6697 Buffer *buffer = mGLState.getTargetBuffer(target);
6698 QueryBufferParameteri64v(buffer, pname, params);
6699}
6700
Brandon Jones59770802018-04-02 13:18:42 -07006701void Context::getBufferParameteri64vRobust(BufferBinding target,
6702 GLenum pname,
6703 GLsizei bufSize,
6704 GLsizei *length,
6705 GLint64 *params)
6706{
6707 getBufferParameteri64v(target, pname, params);
6708}
6709
Jamie Madill3ef140a2017-08-26 23:11:21 -04006710void Context::genSamplers(GLsizei count, GLuint *samplers)
6711{
6712 for (int i = 0; i < count; i++)
6713 {
6714 samplers[i] = mState.mSamplers->createSampler();
6715 }
6716}
6717
6718void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6719{
6720 for (int i = 0; i < count; i++)
6721 {
6722 GLuint sampler = samplers[i];
6723
6724 if (mState.mSamplers->getSampler(sampler))
6725 {
6726 detachSampler(sampler);
6727 }
6728
6729 mState.mSamplers->deleteObject(this, sampler);
6730 }
6731}
6732
6733void Context::getInternalformativ(GLenum target,
6734 GLenum internalformat,
6735 GLenum pname,
6736 GLsizei bufSize,
6737 GLint *params)
6738{
6739 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6740 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6741}
6742
Brandon Jones59770802018-04-02 13:18:42 -07006743void Context::getInternalformativRobust(GLenum target,
6744 GLenum internalformat,
6745 GLenum pname,
6746 GLsizei bufSize,
6747 GLsizei *length,
6748 GLint *params)
6749{
6750 getInternalformativ(target, internalformat, pname, bufSize, params);
6751}
6752
Jiajia Qin5451d532017-11-16 17:16:34 +08006753void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6754{
6755 programUniform1iv(program, location, 1, &v0);
6756}
6757
6758void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6759{
6760 GLint xy[2] = {v0, v1};
6761 programUniform2iv(program, location, 1, xy);
6762}
6763
6764void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6765{
6766 GLint xyz[3] = {v0, v1, v2};
6767 programUniform3iv(program, location, 1, xyz);
6768}
6769
6770void Context::programUniform4i(GLuint program,
6771 GLint location,
6772 GLint v0,
6773 GLint v1,
6774 GLint v2,
6775 GLint v3)
6776{
6777 GLint xyzw[4] = {v0, v1, v2, v3};
6778 programUniform4iv(program, location, 1, xyzw);
6779}
6780
6781void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6782{
6783 programUniform1uiv(program, location, 1, &v0);
6784}
6785
6786void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6787{
6788 GLuint xy[2] = {v0, v1};
6789 programUniform2uiv(program, location, 1, xy);
6790}
6791
6792void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6793{
6794 GLuint xyz[3] = {v0, v1, v2};
6795 programUniform3uiv(program, location, 1, xyz);
6796}
6797
6798void Context::programUniform4ui(GLuint program,
6799 GLint location,
6800 GLuint v0,
6801 GLuint v1,
6802 GLuint v2,
6803 GLuint v3)
6804{
6805 GLuint xyzw[4] = {v0, v1, v2, v3};
6806 programUniform4uiv(program, location, 1, xyzw);
6807}
6808
6809void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6810{
6811 programUniform1fv(program, location, 1, &v0);
6812}
6813
6814void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6815{
6816 GLfloat xy[2] = {v0, v1};
6817 programUniform2fv(program, location, 1, xy);
6818}
6819
6820void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6821{
6822 GLfloat xyz[3] = {v0, v1, v2};
6823 programUniform3fv(program, location, 1, xyz);
6824}
6825
6826void Context::programUniform4f(GLuint program,
6827 GLint location,
6828 GLfloat v0,
6829 GLfloat v1,
6830 GLfloat v2,
6831 GLfloat v3)
6832{
6833 GLfloat xyzw[4] = {v0, v1, v2, v3};
6834 programUniform4fv(program, location, 1, xyzw);
6835}
6836
Jamie Madill81c2e252017-09-09 23:32:46 -04006837void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6838{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006839 Program *programObject = getProgramResolveLink(program);
Jamie Madill81c2e252017-09-09 23:32:46 -04006840 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006841 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006842}
6843
Jiajia Qin5451d532017-11-16 17:16:34 +08006844void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6845{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006846 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006847 ASSERT(programObject);
6848 programObject->setUniform2iv(location, count, value);
6849}
6850
6851void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6852{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006853 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006854 ASSERT(programObject);
6855 programObject->setUniform3iv(location, count, value);
6856}
6857
6858void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6859{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006860 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006861 ASSERT(programObject);
6862 programObject->setUniform4iv(location, count, value);
6863}
6864
6865void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6866{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006867 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006868 ASSERT(programObject);
6869 programObject->setUniform1uiv(location, count, value);
6870}
6871
6872void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6873{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006874 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006875 ASSERT(programObject);
6876 programObject->setUniform2uiv(location, count, value);
6877}
6878
6879void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6880{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006881 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006882 ASSERT(programObject);
6883 programObject->setUniform3uiv(location, count, value);
6884}
6885
6886void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6887{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006888 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006889 ASSERT(programObject);
6890 programObject->setUniform4uiv(location, count, value);
6891}
6892
6893void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6894{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006895 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006896 ASSERT(programObject);
6897 programObject->setUniform1fv(location, count, value);
6898}
6899
6900void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6901{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006902 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006903 ASSERT(programObject);
6904 programObject->setUniform2fv(location, count, value);
6905}
6906
6907void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6908{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006909 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006910 ASSERT(programObject);
6911 programObject->setUniform3fv(location, count, value);
6912}
6913
6914void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6915{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006916 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006917 ASSERT(programObject);
6918 programObject->setUniform4fv(location, count, value);
6919}
6920
6921void Context::programUniformMatrix2fv(GLuint program,
6922 GLint location,
6923 GLsizei count,
6924 GLboolean transpose,
6925 const GLfloat *value)
6926{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006927 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006928 ASSERT(programObject);
6929 programObject->setUniformMatrix2fv(location, count, transpose, value);
6930}
6931
6932void Context::programUniformMatrix3fv(GLuint program,
6933 GLint location,
6934 GLsizei count,
6935 GLboolean transpose,
6936 const GLfloat *value)
6937{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006938 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006939 ASSERT(programObject);
6940 programObject->setUniformMatrix3fv(location, count, transpose, value);
6941}
6942
6943void Context::programUniformMatrix4fv(GLuint program,
6944 GLint location,
6945 GLsizei count,
6946 GLboolean transpose,
6947 const GLfloat *value)
6948{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006949 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006950 ASSERT(programObject);
6951 programObject->setUniformMatrix4fv(location, count, transpose, value);
6952}
6953
6954void Context::programUniformMatrix2x3fv(GLuint program,
6955 GLint location,
6956 GLsizei count,
6957 GLboolean transpose,
6958 const GLfloat *value)
6959{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006960 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006961 ASSERT(programObject);
6962 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6963}
6964
6965void Context::programUniformMatrix3x2fv(GLuint program,
6966 GLint location,
6967 GLsizei count,
6968 GLboolean transpose,
6969 const GLfloat *value)
6970{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006971 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006972 ASSERT(programObject);
6973 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6974}
6975
6976void Context::programUniformMatrix2x4fv(GLuint program,
6977 GLint location,
6978 GLsizei count,
6979 GLboolean transpose,
6980 const GLfloat *value)
6981{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006982 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006983 ASSERT(programObject);
6984 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6985}
6986
6987void Context::programUniformMatrix4x2fv(GLuint program,
6988 GLint location,
6989 GLsizei count,
6990 GLboolean transpose,
6991 const GLfloat *value)
6992{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006993 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006994 ASSERT(programObject);
6995 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6996}
6997
6998void Context::programUniformMatrix3x4fv(GLuint program,
6999 GLint location,
7000 GLsizei count,
7001 GLboolean transpose,
7002 const GLfloat *value)
7003{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007004 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08007005 ASSERT(programObject);
7006 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
7007}
7008
7009void Context::programUniformMatrix4x3fv(GLuint program,
7010 GLint location,
7011 GLsizei count,
7012 GLboolean transpose,
7013 const GLfloat *value)
7014{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007015 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08007016 ASSERT(programObject);
7017 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
7018}
7019
James Darpiniane8a93c62018-01-04 18:02:24 -08007020bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
7021{
7022 return mGLState.isCurrentTransformFeedback(tf);
7023}
James Darpiniane8a93c62018-01-04 18:02:24 -08007024
Yunchao Hea336b902017-08-02 16:05:21 +08007025void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
7026{
7027 for (int i = 0; i < count; i++)
7028 {
7029 pipelines[i] = createProgramPipeline();
7030 }
7031}
7032
7033void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
7034{
7035 for (int i = 0; i < count; i++)
7036 {
7037 if (pipelines[i] != 0)
7038 {
7039 deleteProgramPipeline(pipelines[i]);
7040 }
7041 }
7042}
7043
7044GLboolean Context::isProgramPipeline(GLuint pipeline)
7045{
7046 if (pipeline == 0)
7047 {
7048 return GL_FALSE;
7049 }
7050
7051 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
7052}
7053
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007054void Context::finishFenceNV(GLuint fence)
7055{
7056 FenceNV *fenceObject = getFenceNV(fence);
7057
7058 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madill4f6592f2018-11-27 16:37:45 -05007059 ANGLE_CONTEXT_TRY(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007060}
7061
7062void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
7063{
7064 FenceNV *fenceObject = getFenceNV(fence);
7065
7066 ASSERT(fenceObject && fenceObject->isSet());
7067
7068 switch (pname)
7069 {
7070 case GL_FENCE_STATUS_NV:
7071 {
7072 // GL_NV_fence spec:
7073 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
7074 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
7075 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
7076 GLboolean status = GL_TRUE;
7077 if (fenceObject->getStatus() != GL_TRUE)
7078 {
Jamie Madilla0691b72018-07-25 10:41:22 -04007079 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007080 }
7081 *params = status;
7082 break;
7083 }
7084
7085 case GL_FENCE_CONDITION_NV:
7086 {
7087 *params = static_cast<GLint>(fenceObject->getCondition());
7088 break;
7089 }
7090
7091 default:
7092 UNREACHABLE();
7093 }
7094}
7095
7096void Context::getTranslatedShaderSource(GLuint shader,
7097 GLsizei bufsize,
7098 GLsizei *length,
7099 GLchar *source)
7100{
7101 Shader *shaderObject = getShader(shader);
7102 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08007103 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007104}
7105
7106void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
7107{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007108 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007109 ASSERT(programObject);
7110
7111 programObject->getUniformfv(this, location, params);
7112}
7113
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007114void Context::getnUniformfvRobust(GLuint program,
7115 GLint location,
7116 GLsizei bufSize,
7117 GLsizei *length,
7118 GLfloat *params)
7119{
7120 UNIMPLEMENTED();
7121}
7122
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007123void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
7124{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007125 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007126 ASSERT(programObject);
7127
7128 programObject->getUniformiv(this, location, params);
7129}
7130
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007131void Context::getnUniformivRobust(GLuint program,
7132 GLint location,
7133 GLsizei bufSize,
7134 GLsizei *length,
7135 GLint *params)
7136{
7137 UNIMPLEMENTED();
7138}
7139
7140void Context::getnUniformuivRobust(GLuint program,
7141 GLint location,
7142 GLsizei bufSize,
7143 GLsizei *length,
7144 GLuint *params)
7145{
7146 UNIMPLEMENTED();
7147}
7148
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007149GLboolean Context::isFenceNV(GLuint fence)
7150{
7151 FenceNV *fenceObject = getFenceNV(fence);
7152
7153 if (fenceObject == nullptr)
7154 {
7155 return GL_FALSE;
7156 }
7157
7158 // GL_NV_fence spec:
7159 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
7160 // existing fence.
7161 return fenceObject->isSet();
7162}
7163
7164void Context::readnPixels(GLint x,
7165 GLint y,
7166 GLsizei width,
7167 GLsizei height,
7168 GLenum format,
7169 GLenum type,
7170 GLsizei bufSize,
7171 void *data)
7172{
7173 return readPixels(x, y, width, height, format, type, data);
7174}
7175
Jamie Madill007530e2017-12-28 14:27:04 -05007176void Context::setFenceNV(GLuint fence, GLenum condition)
7177{
7178 ASSERT(condition == GL_ALL_COMPLETED_NV);
7179
7180 FenceNV *fenceObject = getFenceNV(fence);
7181 ASSERT(fenceObject != nullptr);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007182 ANGLE_CONTEXT_TRY(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05007183}
7184
7185GLboolean Context::testFenceNV(GLuint fence)
7186{
7187 FenceNV *fenceObject = getFenceNV(fence);
7188
7189 ASSERT(fenceObject != nullptr);
7190 ASSERT(fenceObject->isSet() == GL_TRUE);
7191
7192 GLboolean result = GL_TRUE;
Jamie Madill7c985f52018-11-29 18:16:17 -05007193 if (fenceObject->test(this, &result) == angle::Result::Stop)
Jamie Madill007530e2017-12-28 14:27:04 -05007194 {
Jamie Madill007530e2017-12-28 14:27:04 -05007195 return GL_TRUE;
7196 }
7197
7198 return result;
7199}
7200
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007201void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007202{
7203 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07007204 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007205 ANGLE_CONTEXT_TRY(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007206}
7207
Jamie Madillfa920eb2018-01-04 11:45:50 -05007208void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007209{
7210 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07007211 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007212 ANGLE_CONTEXT_TRY(renderbuffer->setStorageEGLImageTarget(this, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007213}
7214
Jamie Madillfa920eb2018-01-04 11:45:50 -05007215void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
7216{
7217 UNIMPLEMENTED();
7218}
7219
Jamie Madill5b772312018-03-08 20:28:32 -05007220bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
7221{
7222 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
7223 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
7224 // to the fact that it is stored internally as a float, and so would require conversion
7225 // if returned from Context::getIntegerv. Since this conversion is already implemented
7226 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
7227 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
7228 // application.
7229 switch (pname)
7230 {
7231 case GL_COMPRESSED_TEXTURE_FORMATS:
7232 {
7233 *type = GL_INT;
7234 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
7235 return true;
7236 }
7237 case GL_SHADER_BINARY_FORMATS:
7238 {
7239 *type = GL_INT;
7240 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
7241 return true;
7242 }
7243
7244 case GL_MAX_VERTEX_ATTRIBS:
7245 case GL_MAX_VERTEX_UNIFORM_VECTORS:
7246 case GL_MAX_VARYING_VECTORS:
7247 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
7248 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
7249 case GL_MAX_TEXTURE_IMAGE_UNITS:
7250 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
7251 case GL_MAX_RENDERBUFFER_SIZE:
7252 case GL_NUM_SHADER_BINARY_FORMATS:
7253 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
7254 case GL_ARRAY_BUFFER_BINDING:
Jamie Madillef9fcd92018-11-28 14:03:59 -05007255 case GL_FRAMEBUFFER_BINDING: // GL_FRAMEBUFFER_BINDING now equivalent to
7256 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
Jamie Madill5b772312018-03-08 20:28:32 -05007257 case GL_RENDERBUFFER_BINDING:
7258 case GL_CURRENT_PROGRAM:
7259 case GL_PACK_ALIGNMENT:
7260 case GL_UNPACK_ALIGNMENT:
7261 case GL_GENERATE_MIPMAP_HINT:
7262 case GL_RED_BITS:
7263 case GL_GREEN_BITS:
7264 case GL_BLUE_BITS:
7265 case GL_ALPHA_BITS:
7266 case GL_DEPTH_BITS:
7267 case GL_STENCIL_BITS:
7268 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
7269 case GL_CULL_FACE_MODE:
7270 case GL_FRONT_FACE:
7271 case GL_ACTIVE_TEXTURE:
7272 case GL_STENCIL_FUNC:
7273 case GL_STENCIL_VALUE_MASK:
7274 case GL_STENCIL_REF:
7275 case GL_STENCIL_FAIL:
7276 case GL_STENCIL_PASS_DEPTH_FAIL:
7277 case GL_STENCIL_PASS_DEPTH_PASS:
7278 case GL_STENCIL_BACK_FUNC:
7279 case GL_STENCIL_BACK_VALUE_MASK:
7280 case GL_STENCIL_BACK_REF:
7281 case GL_STENCIL_BACK_FAIL:
7282 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
7283 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
7284 case GL_DEPTH_FUNC:
7285 case GL_BLEND_SRC_RGB:
7286 case GL_BLEND_SRC_ALPHA:
7287 case GL_BLEND_DST_RGB:
7288 case GL_BLEND_DST_ALPHA:
7289 case GL_BLEND_EQUATION_RGB:
7290 case GL_BLEND_EQUATION_ALPHA:
7291 case GL_STENCIL_WRITEMASK:
7292 case GL_STENCIL_BACK_WRITEMASK:
7293 case GL_STENCIL_CLEAR_VALUE:
7294 case GL_SUBPIXEL_BITS:
7295 case GL_MAX_TEXTURE_SIZE:
7296 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
7297 case GL_SAMPLE_BUFFERS:
7298 case GL_SAMPLES:
7299 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
7300 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
7301 case GL_TEXTURE_BINDING_2D:
7302 case GL_TEXTURE_BINDING_CUBE_MAP:
7303 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
7304 {
7305 *type = GL_INT;
7306 *numParams = 1;
7307 return true;
7308 }
7309 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
7310 {
7311 if (!getExtensions().packReverseRowOrder)
7312 {
7313 return false;
7314 }
7315 *type = GL_INT;
7316 *numParams = 1;
7317 return true;
7318 }
7319 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7320 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7321 {
7322 if (!getExtensions().textureRectangle)
7323 {
7324 return false;
7325 }
7326 *type = GL_INT;
7327 *numParams = 1;
7328 return true;
7329 }
7330 case GL_MAX_DRAW_BUFFERS_EXT:
7331 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7332 {
7333 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7334 {
7335 return false;
7336 }
7337 *type = GL_INT;
7338 *numParams = 1;
7339 return true;
7340 }
7341 case GL_MAX_VIEWPORT_DIMS:
7342 {
7343 *type = GL_INT;
7344 *numParams = 2;
7345 return true;
7346 }
7347 case GL_VIEWPORT:
7348 case GL_SCISSOR_BOX:
7349 {
7350 *type = GL_INT;
7351 *numParams = 4;
7352 return true;
7353 }
7354 case GL_SHADER_COMPILER:
7355 case GL_SAMPLE_COVERAGE_INVERT:
7356 case GL_DEPTH_WRITEMASK:
7357 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7358 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7359 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7360 // bool-natural
7361 case GL_SAMPLE_COVERAGE:
7362 case GL_SCISSOR_TEST:
7363 case GL_STENCIL_TEST:
7364 case GL_DEPTH_TEST:
7365 case GL_BLEND:
7366 case GL_DITHER:
7367 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7368 {
7369 *type = GL_BOOL;
7370 *numParams = 1;
7371 return true;
7372 }
7373 case GL_COLOR_WRITEMASK:
7374 {
7375 *type = GL_BOOL;
7376 *numParams = 4;
7377 return true;
7378 }
7379 case GL_POLYGON_OFFSET_FACTOR:
7380 case GL_POLYGON_OFFSET_UNITS:
7381 case GL_SAMPLE_COVERAGE_VALUE:
7382 case GL_DEPTH_CLEAR_VALUE:
7383 case GL_LINE_WIDTH:
7384 {
7385 *type = GL_FLOAT;
7386 *numParams = 1;
7387 return true;
7388 }
7389 case GL_ALIASED_LINE_WIDTH_RANGE:
7390 case GL_ALIASED_POINT_SIZE_RANGE:
7391 case GL_DEPTH_RANGE:
7392 {
7393 *type = GL_FLOAT;
7394 *numParams = 2;
7395 return true;
7396 }
7397 case GL_COLOR_CLEAR_VALUE:
7398 case GL_BLEND_COLOR:
7399 {
7400 *type = GL_FLOAT;
7401 *numParams = 4;
7402 return true;
7403 }
7404 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7405 if (!getExtensions().textureFilterAnisotropic)
7406 {
7407 return false;
7408 }
7409 *type = GL_FLOAT;
7410 *numParams = 1;
7411 return true;
7412 case GL_TIMESTAMP_EXT:
7413 if (!getExtensions().disjointTimerQuery)
7414 {
7415 return false;
7416 }
7417 *type = GL_INT_64_ANGLEX;
7418 *numParams = 1;
7419 return true;
7420 case GL_GPU_DISJOINT_EXT:
7421 if (!getExtensions().disjointTimerQuery)
7422 {
7423 return false;
7424 }
7425 *type = GL_INT;
7426 *numParams = 1;
7427 return true;
7428 case GL_COVERAGE_MODULATION_CHROMIUM:
7429 if (!getExtensions().framebufferMixedSamples)
7430 {
7431 return false;
7432 }
7433 *type = GL_INT;
7434 *numParams = 1;
7435 return true;
7436 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7437 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7438 {
7439 return false;
7440 }
7441 *type = GL_INT;
7442 *numParams = 1;
7443 return true;
7444 }
7445
7446 if (getExtensions().debug)
7447 {
7448 switch (pname)
7449 {
7450 case GL_DEBUG_LOGGED_MESSAGES:
7451 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7452 case GL_DEBUG_GROUP_STACK_DEPTH:
7453 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7454 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7455 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7456 case GL_MAX_LABEL_LENGTH:
7457 *type = GL_INT;
7458 *numParams = 1;
7459 return true;
7460
7461 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7462 case GL_DEBUG_OUTPUT:
7463 *type = GL_BOOL;
7464 *numParams = 1;
7465 return true;
7466 }
7467 }
7468
7469 if (getExtensions().multisampleCompatibility)
7470 {
7471 switch (pname)
7472 {
7473 case GL_MULTISAMPLE_EXT:
7474 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7475 *type = GL_BOOL;
7476 *numParams = 1;
7477 return true;
7478 }
7479 }
7480
7481 if (getExtensions().pathRendering)
7482 {
7483 switch (pname)
7484 {
7485 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7486 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7487 *type = GL_FLOAT;
7488 *numParams = 16;
7489 return true;
7490 }
7491 }
7492
7493 if (getExtensions().bindGeneratesResource)
7494 {
7495 switch (pname)
7496 {
7497 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7498 *type = GL_BOOL;
7499 *numParams = 1;
7500 return true;
7501 }
7502 }
7503
7504 if (getExtensions().clientArrays)
7505 {
7506 switch (pname)
7507 {
7508 case GL_CLIENT_ARRAYS_ANGLE:
7509 *type = GL_BOOL;
7510 *numParams = 1;
7511 return true;
7512 }
7513 }
7514
7515 if (getExtensions().sRGBWriteControl)
7516 {
7517 switch (pname)
7518 {
7519 case GL_FRAMEBUFFER_SRGB_EXT:
7520 *type = GL_BOOL;
7521 *numParams = 1;
7522 return true;
7523 }
7524 }
7525
7526 if (getExtensions().robustResourceInitialization &&
7527 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7528 {
7529 *type = GL_BOOL;
7530 *numParams = 1;
7531 return true;
7532 }
7533
7534 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7535 {
7536 *type = GL_BOOL;
7537 *numParams = 1;
7538 return true;
7539 }
7540
jchen1082af6202018-06-22 10:59:52 +08007541 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7542 {
7543 *type = GL_INT;
7544 *numParams = 1;
7545 return true;
7546 }
7547
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007548 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7549 {
7550 *type = GL_INT;
7551 *numParams = 1;
7552 return true;
7553 }
7554
Jamie Madill5b772312018-03-08 20:28:32 -05007555 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7556 switch (pname)
7557 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05007558 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE equivalent to FRAMEBUFFER_BINDING
Jamie Madill5b772312018-03-08 20:28:32 -05007559 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7560 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7561 {
7562 return false;
7563 }
7564 *type = GL_INT;
7565 *numParams = 1;
7566 return true;
7567
7568 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7569 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7570 {
7571 return false;
7572 }
7573 *type = GL_INT;
7574 *numParams = 1;
7575 return true;
7576
7577 case GL_PROGRAM_BINARY_FORMATS_OES:
7578 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7579 {
7580 return false;
7581 }
7582 *type = GL_INT;
7583 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7584 return true;
7585
7586 case GL_PACK_ROW_LENGTH:
7587 case GL_PACK_SKIP_ROWS:
7588 case GL_PACK_SKIP_PIXELS:
7589 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7590 {
7591 return false;
7592 }
7593 *type = GL_INT;
7594 *numParams = 1;
7595 return true;
7596 case GL_UNPACK_ROW_LENGTH:
7597 case GL_UNPACK_SKIP_ROWS:
7598 case GL_UNPACK_SKIP_PIXELS:
7599 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7600 {
7601 return false;
7602 }
7603 *type = GL_INT;
7604 *numParams = 1;
7605 return true;
7606 case GL_VERTEX_ARRAY_BINDING:
7607 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7608 {
7609 return false;
7610 }
7611 *type = GL_INT;
7612 *numParams = 1;
7613 return true;
7614 case GL_PIXEL_PACK_BUFFER_BINDING:
7615 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7616 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7617 {
7618 return false;
7619 }
7620 *type = GL_INT;
7621 *numParams = 1;
7622 return true;
7623 case GL_MAX_SAMPLES:
7624 {
7625 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7626 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7627 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7628 {
7629 return false;
7630 }
7631 *type = GL_INT;
7632 *numParams = 1;
7633 return true;
7634
7635 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7636 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7637 {
7638 return false;
7639 }
7640 *type = GL_INT;
7641 *numParams = 1;
7642 return true;
7643 }
7644 }
7645
7646 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7647 {
7648 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7649 {
7650 return false;
7651 }
7652 *type = GL_INT;
7653 *numParams = 1;
7654 return true;
7655 }
7656
7657 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7658 {
7659 *type = GL_INT;
7660 *numParams = 1;
7661 return true;
7662 }
7663
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007664 if (getClientVersion() < Version(2, 0))
7665 {
7666 switch (pname)
7667 {
7668 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007669 case GL_CLIENT_ACTIVE_TEXTURE:
7670 case GL_MATRIX_MODE:
7671 case GL_MAX_TEXTURE_UNITS:
7672 case GL_MAX_MODELVIEW_STACK_DEPTH:
7673 case GL_MAX_PROJECTION_STACK_DEPTH:
7674 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007675 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007676 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007677 case GL_VERTEX_ARRAY_STRIDE:
7678 case GL_NORMAL_ARRAY_STRIDE:
7679 case GL_COLOR_ARRAY_STRIDE:
7680 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7681 case GL_VERTEX_ARRAY_SIZE:
7682 case GL_COLOR_ARRAY_SIZE:
7683 case GL_TEXTURE_COORD_ARRAY_SIZE:
7684 case GL_VERTEX_ARRAY_TYPE:
7685 case GL_NORMAL_ARRAY_TYPE:
7686 case GL_COLOR_ARRAY_TYPE:
7687 case GL_TEXTURE_COORD_ARRAY_TYPE:
7688 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7689 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7690 case GL_COLOR_ARRAY_BUFFER_BINDING:
7691 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7692 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7693 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7694 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007695 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007696 case GL_MODELVIEW_STACK_DEPTH:
7697 case GL_PROJECTION_STACK_DEPTH:
7698 case GL_TEXTURE_STACK_DEPTH:
7699 case GL_LOGIC_OP_MODE:
7700 case GL_BLEND_SRC:
7701 case GL_BLEND_DST:
7702 case GL_PERSPECTIVE_CORRECTION_HINT:
7703 case GL_POINT_SMOOTH_HINT:
7704 case GL_LINE_SMOOTH_HINT:
7705 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007706 *type = GL_INT;
7707 *numParams = 1;
7708 return true;
7709 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007710 case GL_FOG_DENSITY:
7711 case GL_FOG_START:
7712 case GL_FOG_END:
7713 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007714 case GL_POINT_SIZE:
7715 case GL_POINT_SIZE_MIN:
7716 case GL_POINT_SIZE_MAX:
7717 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007718 *type = GL_FLOAT;
7719 *numParams = 1;
7720 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007721 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007722 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007723 *type = GL_FLOAT;
7724 *numParams = 2;
7725 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007726 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007727 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007728 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007729 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007730 *type = GL_FLOAT;
7731 *numParams = 4;
7732 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007733 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007734 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007735 *type = GL_FLOAT;
7736 *numParams = 3;
7737 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007738 case GL_MODELVIEW_MATRIX:
7739 case GL_PROJECTION_MATRIX:
7740 case GL_TEXTURE_MATRIX:
7741 *type = GL_FLOAT;
7742 *numParams = 16;
7743 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007744 case GL_LIGHT_MODEL_TWO_SIDE:
7745 *type = GL_BOOL;
7746 *numParams = 1;
7747 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007748 }
7749 }
7750
Jamie Madill5b772312018-03-08 20:28:32 -05007751 if (getClientVersion() < Version(3, 0))
7752 {
7753 return false;
7754 }
7755
7756 // Check for ES3.0+ parameter names
7757 switch (pname)
7758 {
7759 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7760 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7761 case GL_UNIFORM_BUFFER_BINDING:
7762 case GL_TRANSFORM_FEEDBACK_BINDING:
7763 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7764 case GL_COPY_READ_BUFFER_BINDING:
7765 case GL_COPY_WRITE_BUFFER_BINDING:
7766 case GL_SAMPLER_BINDING:
7767 case GL_READ_BUFFER:
7768 case GL_TEXTURE_BINDING_3D:
7769 case GL_TEXTURE_BINDING_2D_ARRAY:
7770 case GL_MAX_3D_TEXTURE_SIZE:
7771 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7772 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7773 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7774 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7775 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7776 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7777 case GL_MAX_VARYING_COMPONENTS:
7778 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7779 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7780 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7781 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7782 case GL_NUM_EXTENSIONS:
7783 case GL_MAJOR_VERSION:
7784 case GL_MINOR_VERSION:
7785 case GL_MAX_ELEMENTS_INDICES:
7786 case GL_MAX_ELEMENTS_VERTICES:
7787 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7788 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7789 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7790 case GL_UNPACK_IMAGE_HEIGHT:
7791 case GL_UNPACK_SKIP_IMAGES:
7792 {
7793 *type = GL_INT;
7794 *numParams = 1;
7795 return true;
7796 }
7797
7798 case GL_MAX_ELEMENT_INDEX:
7799 case GL_MAX_UNIFORM_BLOCK_SIZE:
7800 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7801 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7802 case GL_MAX_SERVER_WAIT_TIMEOUT:
7803 {
7804 *type = GL_INT_64_ANGLEX;
7805 *numParams = 1;
7806 return true;
7807 }
7808
7809 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7810 case GL_TRANSFORM_FEEDBACK_PAUSED:
7811 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7812 case GL_RASTERIZER_DISCARD:
7813 {
7814 *type = GL_BOOL;
7815 *numParams = 1;
7816 return true;
7817 }
7818
7819 case GL_MAX_TEXTURE_LOD_BIAS:
7820 {
7821 *type = GL_FLOAT;
7822 *numParams = 1;
7823 return true;
7824 }
7825 }
7826
7827 if (getExtensions().requestExtension)
7828 {
7829 switch (pname)
7830 {
7831 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7832 *type = GL_INT;
7833 *numParams = 1;
7834 return true;
7835 }
7836 }
7837
Yizhou Jiang7818a852018-09-06 15:02:04 +08007838 if (getExtensions().textureMultisample)
7839 {
7840 switch (pname)
7841 {
7842 case GL_MAX_COLOR_TEXTURE_SAMPLES_ANGLE:
7843 case GL_MAX_INTEGER_SAMPLES_ANGLE:
7844 case GL_MAX_DEPTH_TEXTURE_SAMPLES_ANGLE:
7845 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ANGLE:
Yizhou Jiang7310da32018-11-05 14:40:01 +08007846 case GL_MAX_SAMPLE_MASK_WORDS:
Yizhou Jiang7818a852018-09-06 15:02:04 +08007847 *type = GL_INT;
7848 *numParams = 1;
7849 return true;
7850 }
7851 }
7852
Jamie Madill5b772312018-03-08 20:28:32 -05007853 if (getClientVersion() < Version(3, 1))
7854 {
7855 return false;
7856 }
7857
7858 switch (pname)
7859 {
7860 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7861 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7862 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7863 case GL_MAX_FRAMEBUFFER_WIDTH:
7864 case GL_MAX_FRAMEBUFFER_HEIGHT:
7865 case GL_MAX_FRAMEBUFFER_SAMPLES:
7866 case GL_MAX_SAMPLE_MASK_WORDS:
7867 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7868 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7869 case GL_MAX_INTEGER_SAMPLES:
7870 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7871 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7872 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7873 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7874 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7875 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7876 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7877 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7878 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7879 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7880 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7881 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7882 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7883 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7884 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7885 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7886 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7887 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7888 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7889 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7890 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7891 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7892 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7893 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7894 case GL_MAX_UNIFORM_LOCATIONS:
7895 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7896 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7897 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7898 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7899 case GL_MAX_IMAGE_UNITS:
7900 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7901 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7902 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7903 case GL_SHADER_STORAGE_BUFFER_BINDING:
7904 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7905 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007906 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007907 *type = GL_INT;
7908 *numParams = 1;
7909 return true;
7910 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7911 *type = GL_INT_64_ANGLEX;
7912 *numParams = 1;
7913 return true;
7914 case GL_SAMPLE_MASK:
7915 *type = GL_BOOL;
7916 *numParams = 1;
7917 return true;
7918 }
7919
7920 if (getExtensions().geometryShader)
7921 {
7922 switch (pname)
7923 {
7924 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7925 case GL_LAYER_PROVOKING_VERTEX_EXT:
7926 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7927 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7928 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7929 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7930 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7931 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7932 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7933 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7934 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7935 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7936 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7937 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7938 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7939 *type = GL_INT;
7940 *numParams = 1;
7941 return true;
7942 }
7943 }
7944
7945 return false;
7946}
7947
7948bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7949{
7950 if (getClientVersion() < Version(3, 0))
7951 {
7952 return false;
7953 }
7954
7955 switch (target)
7956 {
7957 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7958 case GL_UNIFORM_BUFFER_BINDING:
7959 {
7960 *type = GL_INT;
7961 *numParams = 1;
7962 return true;
7963 }
7964 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7965 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7966 case GL_UNIFORM_BUFFER_START:
7967 case GL_UNIFORM_BUFFER_SIZE:
7968 {
7969 *type = GL_INT_64_ANGLEX;
7970 *numParams = 1;
7971 return true;
7972 }
7973 }
7974
7975 if (getClientVersion() < Version(3, 1))
7976 {
7977 return false;
7978 }
7979
7980 switch (target)
7981 {
7982 case GL_IMAGE_BINDING_LAYERED:
7983 {
7984 *type = GL_BOOL;
7985 *numParams = 1;
7986 return true;
7987 }
7988 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7989 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7990 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7991 case GL_SHADER_STORAGE_BUFFER_BINDING:
7992 case GL_VERTEX_BINDING_BUFFER:
7993 case GL_VERTEX_BINDING_DIVISOR:
7994 case GL_VERTEX_BINDING_OFFSET:
7995 case GL_VERTEX_BINDING_STRIDE:
7996 case GL_SAMPLE_MASK_VALUE:
7997 case GL_IMAGE_BINDING_NAME:
7998 case GL_IMAGE_BINDING_LEVEL:
7999 case GL_IMAGE_BINDING_LAYER:
8000 case GL_IMAGE_BINDING_ACCESS:
8001 case GL_IMAGE_BINDING_FORMAT:
8002 {
8003 *type = GL_INT;
8004 *numParams = 1;
8005 return true;
8006 }
8007 case GL_ATOMIC_COUNTER_BUFFER_START:
8008 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
8009 case GL_SHADER_STORAGE_BUFFER_START:
8010 case GL_SHADER_STORAGE_BUFFER_SIZE:
8011 {
8012 *type = GL_INT_64_ANGLEX;
8013 *numParams = 1;
8014 return true;
8015 }
8016 }
8017
8018 return false;
8019}
8020
Jamie Madill44a6fbf2018-10-02 13:38:56 -04008021Program *Context::getProgramNoResolveLink(GLuint handle) const
Jamie Madill5b772312018-03-08 20:28:32 -05008022{
8023 return mState.mShaderPrograms->getProgram(handle);
8024}
8025
8026Shader *Context::getShader(GLuint handle) const
8027{
8028 return mState.mShaderPrograms->getShader(handle);
8029}
8030
Jamie Madill5b772312018-03-08 20:28:32 -05008031bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
8032{
8033 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
8034}
8035
8036bool Context::isFramebufferGenerated(GLuint framebuffer) const
8037{
8038 return mState.mFramebuffers->isHandleGenerated(framebuffer);
8039}
8040
8041bool Context::isProgramPipelineGenerated(GLuint pipeline) const
8042{
8043 return mState.mPipelines->isHandleGenerated(pipeline);
8044}
8045
8046bool Context::usingDisplayTextureShareGroup() const
8047{
8048 return mDisplayTextureShareGroup;
8049}
8050
8051GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
8052{
8053 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
8054 internalformat == GL_DEPTH_STENCIL
8055 ? GL_DEPTH24_STENCIL8
8056 : internalformat;
8057}
8058
jchen1082af6202018-06-22 10:59:52 +08008059void Context::maxShaderCompilerThreads(GLuint count)
8060{
jchen107ae70d82018-07-06 13:47:01 +08008061 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08008062 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08008063 // A count of zero specifies a request for no parallel compiling or linking.
8064 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
8065 {
8066 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
8067 }
8068 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08008069}
8070
Jamie Madill2eb65032018-07-30 10:25:57 -04008071bool Context::isGLES1() const
8072{
8073 return mState.getClientVersion() < Version(2, 0);
8074}
8075
Jamie Madilla11819d2018-07-30 10:26:01 -04008076void Context::onSubjectStateChange(const Context *context,
8077 angle::SubjectIndex index,
8078 angle::SubjectMessage message)
8079{
Jamie Madilla11819d2018-07-30 10:26:01 -04008080 switch (index)
8081 {
8082 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008083 switch (message)
8084 {
8085 case angle::SubjectMessage::CONTENTS_CHANGED:
8086 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
8087 mStateCache.onVertexArrayBufferContentsChange(this);
8088 break;
8089 case angle::SubjectMessage::RESOURCE_MAPPED:
8090 case angle::SubjectMessage::RESOURCE_UNMAPPED:
8091 case angle::SubjectMessage::BINDING_CHANGED:
8092 mStateCache.onVertexArrayBufferStateChange(this);
8093 break;
8094 default:
8095 break;
8096 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008097 break;
8098
8099 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008100 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8101 {
8102 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
8103 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008104 break;
8105
8106 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008107 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8108 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05008109 mGLState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04008110 }
8111 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04008112 break;
8113
8114 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04008115 if (index < kTextureMaxSubjectIndex)
8116 {
Jamie Madille3e680c2018-12-03 17:49:08 -05008117 mGLState.onActiveTextureStateChange(this, index);
Jamie Madilld84b6732018-09-06 15:54:35 -04008118 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008119 }
Jamie Madille3e680c2018-12-03 17:49:08 -05008120 else if (index < kImageMaxSubjectIndex)
8121 {
8122 mGLState.onImageStateChange(this, index - kImage0SubjectIndex);
8123 }
Jamie Madille25b8002018-09-20 13:39:49 -04008124 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04008125 {
Jamie Madill6d32cef2018-08-14 02:34:28 -04008126 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04008127 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008128 }
Jamie Madille25b8002018-09-20 13:39:49 -04008129 else
8130 {
8131 ASSERT(index < kSamplerMaxSubjectIndex);
8132 mGLState.setSamplerDirty(index - kSampler0SubjectIndex);
8133 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008134 break;
8135 }
8136}
8137
Jamie Madill6b873dd2018-07-12 23:56:30 -04008138// ErrorSet implementation.
Jamie Madillb980c562018-11-27 11:34:27 -05008139ErrorSet::ErrorSet(Context *context) : mContext(context) {}
Jamie Madill6b873dd2018-07-12 23:56:30 -04008140
8141ErrorSet::~ErrorSet() = default;
8142
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008143void ErrorSet::handleError(GLenum errorCode,
8144 const char *message,
8145 const char *file,
8146 const char *function,
8147 unsigned int line)
8148{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008149 if (errorCode == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
8150 {
8151 mContext->markContextLost();
8152 }
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008153
Jamie Madill4f6592f2018-11-27 16:37:45 -05008154 std::stringstream errorStream;
8155 errorStream << "Error: " << gl::FmtHex(errorCode) << ", in " << file << ", " << function << ":"
8156 << line << ". " << message;
8157
Geoff Lang7139b432018-12-14 16:57:28 -05008158 std::string formattedMessage = errorStream.str();
8159
8160 // Always log a warning, this function is only called on unexpected internal errors.
8161 WARN() << formattedMessage;
8162
Jamie Madill4f6592f2018-11-27 16:37:45 -05008163 // validationError does the necessary work to process the error.
Geoff Lang7139b432018-12-14 16:57:28 -05008164 validationError(errorCode, formattedMessage.c_str());
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008165}
8166
Jamie Madilla139f012018-10-10 16:13:03 -04008167void ErrorSet::validationError(GLenum errorCode, const char *message)
8168{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008169 ASSERT(errorCode != GL_NO_ERROR);
8170 mErrors.insert(errorCode);
8171
8172 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
8173 errorCode, GL_DEBUG_SEVERITY_HIGH, message);
Jamie Madilla139f012018-10-10 16:13:03 -04008174}
8175
Jamie Madill6b873dd2018-07-12 23:56:30 -04008176bool ErrorSet::empty() const
8177{
8178 return mErrors.empty();
8179}
8180
8181GLenum ErrorSet::popError()
8182{
8183 ASSERT(!empty());
8184 GLenum error = *mErrors.begin();
8185 mErrors.erase(mErrors.begin());
8186 return error;
8187}
Jamie Madilldc358af2018-07-31 11:22:13 -04008188
8189// StateCache implementation.
Jamie Madillac66f982018-10-09 18:30:01 -04008190StateCache::StateCache()
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008191 : mCachedHasAnyEnabledClientAttrib(false),
8192 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04008193 mCachedInstancedVertexElementLimit(0),
Jamie Madill1e853262018-12-21 09:07:38 -05008194 mCachedBasicDrawStatesError(kInvalidPointer),
8195 mCachedBasicDrawElementsError(kInvalidPointer)
Jamie Madillb980c562018-11-27 11:34:27 -05008196{}
Jamie Madilldc358af2018-07-31 11:22:13 -04008197
8198StateCache::~StateCache() = default;
8199
Jamie Madillac66f982018-10-09 18:30:01 -04008200void StateCache::initialize(Context *context)
8201{
8202 updateValidDrawModes(context);
8203 updateValidBindTextureTypes(context);
Jamie Madill8dc27f92018-11-29 11:45:44 -05008204 updateValidDrawElementsTypes(context);
Jamie Madill1e853262018-12-21 09:07:38 -05008205 updateBasicDrawStatesError();
8206 updateBasicDrawElementsError();
Jamie Madillac66f982018-10-09 18:30:01 -04008207}
8208
Jamie Madilldc358af2018-07-31 11:22:13 -04008209void StateCache::updateActiveAttribsMask(Context *context)
8210{
8211 bool isGLES1 = context->isGLES1();
8212 const State &glState = context->getGLState();
8213
8214 if (!isGLES1 && !glState.getProgram())
8215 {
8216 mCachedActiveBufferedAttribsMask = AttributesMask();
8217 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04008218 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04008219 return;
8220 }
8221
8222 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
8223 : glState.getProgram()->getActiveAttribLocationsMask();
8224
8225 const VertexArray *vao = glState.getVertexArray();
8226 ASSERT(vao);
8227
8228 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
8229 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04008230 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008231
Jamie Madill0a17e482018-08-31 17:19:11 -04008232 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
8233 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04008234 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008235 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
8236}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008237
8238void StateCache::updateVertexElementLimits(Context *context)
8239{
8240 const VertexArray *vao = context->getGLState().getVertexArray();
8241
8242 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8243 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8244
8245 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
8246 // If there are no buffered attributes then we should not limit the draw call count.
8247 if (!vao || !mCachedActiveBufferedAttribsMask.any())
8248 {
8249 return;
8250 }
8251
8252 const auto &vertexAttribs = vao->getVertexAttributes();
8253 const auto &vertexBindings = vao->getVertexBindings();
8254
8255 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
8256 {
8257 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
8258 ASSERT(attrib.enabled);
8259
8260 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
8261 ASSERT(context->isGLES1() ||
8262 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
8263
8264 GLint64 limit = attrib.getCachedElementLimit();
8265 if (binding.getDivisor() > 0)
8266 {
8267 mCachedInstancedVertexElementLimit =
8268 std::min(mCachedInstancedVertexElementLimit, limit);
8269 }
8270 else
8271 {
8272 mCachedNonInstancedVertexElementLimit =
8273 std::min(mCachedNonInstancedVertexElementLimit, limit);
8274 }
8275 }
8276}
Jamie Madillc43cdad2018-08-08 15:49:25 -04008277
Jamie Madilld84b6732018-09-06 15:54:35 -04008278void StateCache::updateBasicDrawStatesError()
8279{
8280 mCachedBasicDrawStatesError = kInvalidPointer;
8281}
8282
Jamie Madill1e853262018-12-21 09:07:38 -05008283void StateCache::updateBasicDrawElementsError()
8284{
8285 mCachedBasicDrawElementsError = kInvalidPointer;
8286}
8287
Jamie Madilld84b6732018-09-06 15:54:35 -04008288intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
8289{
8290 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
8291 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
8292 return mCachedBasicDrawStatesError;
8293}
8294
Jamie Madill1e853262018-12-21 09:07:38 -05008295intptr_t StateCache::getBasicDrawElementsErrorImpl(Context *context) const
8296{
8297 ASSERT(mCachedBasicDrawElementsError == kInvalidPointer);
8298 mCachedBasicDrawElementsError = reinterpret_cast<intptr_t>(ValidateDrawElementsStates(context));
8299 return mCachedBasicDrawElementsError;
8300}
8301
Jamie Madillc43cdad2018-08-08 15:49:25 -04008302void StateCache::onVertexArrayBindingChange(Context *context)
8303{
8304 updateActiveAttribsMask(context);
8305 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008306 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008307}
8308
8309void StateCache::onProgramExecutableChange(Context *context)
8310{
8311 updateActiveAttribsMask(context);
8312 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008313 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04008314 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04008315}
8316
Jamie Madilld84b6732018-09-06 15:54:35 -04008317void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04008318{
8319 updateVertexElementLimits(context);
8320}
8321
Jamie Madilld84b6732018-09-06 15:54:35 -04008322void StateCache::onVertexArrayBufferContentsChange(Context *context)
8323{
8324 updateVertexElementLimits(context);
8325 updateBasicDrawStatesError();
8326}
8327
Jamie Madillc43cdad2018-08-08 15:49:25 -04008328void StateCache::onVertexArrayStateChange(Context *context)
8329{
8330 updateActiveAttribsMask(context);
8331 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008332 updateBasicDrawStatesError();
8333}
8334
8335void StateCache::onVertexArrayBufferStateChange(Context *context)
8336{
8337 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008338 updateBasicDrawElementsError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008339}
8340
8341void StateCache::onGLES1ClientStateChange(Context *context)
8342{
8343 updateActiveAttribsMask(context);
8344}
Jamie Madilld84b6732018-09-06 15:54:35 -04008345
8346void StateCache::onDrawFramebufferChange(Context *context)
8347{
8348 updateBasicDrawStatesError();
8349}
8350
8351void StateCache::onContextCapChange(Context *context)
8352{
8353 updateBasicDrawStatesError();
8354}
8355
8356void StateCache::onStencilStateChange(Context *context)
8357{
8358 updateBasicDrawStatesError();
8359}
8360
8361void StateCache::onDefaultVertexAttributeChange(Context *context)
8362{
8363 updateBasicDrawStatesError();
8364}
8365
8366void StateCache::onActiveTextureChange(Context *context)
8367{
8368 updateBasicDrawStatesError();
8369}
8370
8371void StateCache::onQueryChange(Context *context)
8372{
8373 updateBasicDrawStatesError();
8374}
8375
Jamie Madill3a256222018-12-08 09:56:39 -05008376void StateCache::onActiveTransformFeedbackChange(Context *context)
Jamie Madilld84b6732018-09-06 15:54:35 -04008377{
8378 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008379 updateBasicDrawElementsError();
Jamie Madill9b025062018-12-12 15:44:12 -05008380 updateValidDrawModes(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008381}
8382
8383void StateCache::onUniformBufferStateChange(Context *context)
8384{
8385 updateBasicDrawStatesError();
8386}
8387
8388void StateCache::onBufferBindingChange(Context *context)
8389{
8390 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008391 updateBasicDrawElementsError();
Jamie Madilld84b6732018-09-06 15:54:35 -04008392}
Jamie Madill526a6f62018-09-12 11:03:05 -04008393
Jamie Madill9b025062018-12-12 15:44:12 -05008394void StateCache::setValidDrawModes(bool pointsOK,
8395 bool linesOK,
8396 bool trisOK,
8397 bool lineAdjOK,
8398 bool triAdjOK)
8399{
8400 mCachedValidDrawModes[PrimitiveMode::Points] = pointsOK;
8401 mCachedValidDrawModes[PrimitiveMode::Lines] = linesOK;
8402 mCachedValidDrawModes[PrimitiveMode::LineStrip] = linesOK;
8403 mCachedValidDrawModes[PrimitiveMode::LineLoop] = linesOK;
8404 mCachedValidDrawModes[PrimitiveMode::Triangles] = trisOK;
8405 mCachedValidDrawModes[PrimitiveMode::TriangleFan] = trisOK;
8406 mCachedValidDrawModes[PrimitiveMode::TriangleStrip] = trisOK;
8407 mCachedValidDrawModes[PrimitiveMode::LinesAdjacency] = lineAdjOK;
8408 mCachedValidDrawModes[PrimitiveMode::LineStripAdjacency] = lineAdjOK;
8409 mCachedValidDrawModes[PrimitiveMode::TrianglesAdjacency] = triAdjOK;
8410 mCachedValidDrawModes[PrimitiveMode::TriangleStripAdjacency] = triAdjOK;
8411}
8412
Jamie Madill526a6f62018-09-12 11:03:05 -04008413void StateCache::updateValidDrawModes(Context *context)
8414{
Jamie Madill9b025062018-12-12 15:44:12 -05008415 const State &state = context->getGLState();
8416 Program *program = state.getProgram();
8417
8418 TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback();
8419 if (curTransformFeedback && curTransformFeedback->isActive() &&
8420 !curTransformFeedback->isPaused())
8421 {
8422 // ES Spec 3.0 validation text:
8423 // When transform feedback is active and not paused, all geometric primitives generated must
8424 // match the value of primitiveMode passed to BeginTransformFeedback. The error
8425 // INVALID_OPERATION is generated by DrawArrays and DrawArraysInstanced if mode is not
8426 // identical to primitiveMode. The error INVALID_OPERATION is also generated by
8427 // DrawElements, DrawElementsInstanced, and DrawRangeElements while transform feedback is
8428 // active and not paused, regardless of mode. Any primitive type may be used while transform
8429 // feedback is paused.
8430 if (!context->getExtensions().geometryShader)
8431 {
8432 mCachedValidDrawModes.fill(false);
8433 mCachedValidDrawModes[curTransformFeedback->getPrimitiveMode()] = true;
8434 return;
8435 }
8436
8437 // EXT_geometry_shader validation text:
8438 // When transform feedback is active and not paused, all geometric primitives generated must
8439 // be compatible with the value of <primitiveMode> passed to BeginTransformFeedback. If a
8440 // geometry shader is active, the type of primitive emitted by that shader is used instead
8441 // of the <mode> parameter passed to drawing commands for the purposes of this error check.
8442 // Any primitive type may be used while transform feedback is paused.
8443 bool pointsOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Points;
8444 bool linesOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Lines;
8445 bool trisOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Triangles;
8446
8447 setValidDrawModes(pointsOK, linesOK, trisOK, false, false);
8448 return;
8449 }
8450
Jamie Madill526a6f62018-09-12 11:03:05 -04008451 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8452 {
Jamie Madill752d2202018-11-27 13:29:48 -05008453 mCachedValidDrawModes = kValidBasicDrawModes;
Jamie Madill9b025062018-12-12 15:44:12 -05008454 return;
Jamie Madill526a6f62018-09-12 11:03:05 -04008455 }
Jamie Madill526a6f62018-09-12 11:03:05 -04008456
Jamie Madill9b025062018-12-12 15:44:12 -05008457 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8458 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
Jamie Madill526a6f62018-09-12 11:03:05 -04008459
Jamie Madill9b025062018-12-12 15:44:12 -05008460 bool pointsOK = gsMode == PrimitiveMode::Points;
8461 bool linesOK = gsMode == PrimitiveMode::Lines;
8462 bool trisOK = gsMode == PrimitiveMode::Triangles;
8463 bool lineAdjOK = gsMode == PrimitiveMode::LinesAdjacency;
8464 bool triAdjOK = gsMode == PrimitiveMode::TrianglesAdjacency;
8465
8466 setValidDrawModes(pointsOK, linesOK, trisOK, lineAdjOK, triAdjOK);
Jamie Madill526a6f62018-09-12 11:03:05 -04008467}
Jamie Madillac66f982018-10-09 18:30:01 -04008468
8469void StateCache::updateValidBindTextureTypes(Context *context)
8470{
8471 const Extensions &exts = context->getExtensions();
8472 bool isGLES3 = context->getClientMajorVersion() >= 3;
8473 bool isGLES31 = context->getClientVersion() >= Version(3, 1);
8474
8475 mCachedValidBindTextureTypes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008476 {TextureType::_2D, true},
8477 {TextureType::_2DArray, isGLES3},
8478 {TextureType::_2DMultisample, isGLES31 || exts.textureMultisample},
8479 {TextureType::_2DMultisampleArray, exts.textureStorageMultisample2DArray},
8480 {TextureType::_3D, isGLES3},
8481 {TextureType::External, exts.eglImageExternal || exts.eglStreamConsumerExternal},
8482 {TextureType::Rectangle, exts.textureRectangle},
8483 {TextureType::CubeMap, true},
Jamie Madillac66f982018-10-09 18:30:01 -04008484 }};
8485}
Jamie Madill8dc27f92018-11-29 11:45:44 -05008486
8487void StateCache::updateValidDrawElementsTypes(Context *context)
8488{
8489 bool supportsUint =
8490 (context->getClientMajorVersion() >= 3 || context->getExtensions().elementIndexUint);
8491
8492 mCachedValidDrawElementsTypes = {{
8493 {DrawElementsType::UnsignedByte, true},
8494 {DrawElementsType::UnsignedShort, true},
8495 {DrawElementsType::UnsignedInt, supportsUint},
8496 }};
8497}
Jamie Madillc29968b2016-01-20 11:17:23 -05008498} // namespace gl