blob: 9cd96324e5bb3f769a54b9c2a26817a1d1689834 [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);
Jamie Madilld84b6732018-09-06 15:54:35 -04001179 mStateCache.onTransformFeedbackChange(this);
Geoff Langc8058452014-02-03 12:04:11 -05001180}
1181
Yunchao Hea336b902017-08-02 16:05:21 +08001182void Context::bindProgramPipeline(GLuint pipelineHandle)
1183{
1184 ProgramPipeline *pipeline =
1185 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1186 mGLState.setProgramPipelineBinding(this, pipeline);
1187}
1188
Corentin Wallezad3ae902018-03-09 13:40:42 -05001189void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001190{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001191 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001192 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001193
Geoff Lang5aad9672014-09-08 11:10:42 -04001194 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001195 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001196
1197 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001198 mGLState.setActiveQuery(this, target, queryObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04001199 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001200}
1201
Corentin Wallezad3ae902018-03-09 13:40:42 -05001202void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001203{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001204 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001205 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001206
Jamie Madill4f6592f2018-11-27 16:37:45 -05001207 // Intentionally don't call try here. We don't want an early return.
1208 (void)(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001209
Geoff Lang5aad9672014-09-08 11:10:42 -04001210 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001211 mGLState.setActiveQuery(this, target, nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04001212 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001213}
1214
Corentin Wallezad3ae902018-03-09 13:40:42 -05001215void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001216{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001217 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001218
1219 Query *queryObject = getQuery(id, true, target);
1220 ASSERT(queryObject);
1221
Jamie Madill4f6592f2018-11-27 16:37:45 -05001222 ANGLE_CONTEXT_TRY(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001223}
1224
Corentin Wallezad3ae902018-03-09 13:40:42 -05001225void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001226{
1227 switch (pname)
1228 {
1229 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001230 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001231 break;
1232 case GL_QUERY_COUNTER_BITS_EXT:
1233 switch (target)
1234 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001235 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001236 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1237 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001238 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001239 params[0] = getExtensions().queryCounterBitsTimestamp;
1240 break;
1241 default:
1242 UNREACHABLE();
1243 params[0] = 0;
1244 break;
1245 }
1246 break;
1247 default:
1248 UNREACHABLE();
1249 return;
1250 }
1251}
1252
Corentin Wallezad3ae902018-03-09 13:40:42 -05001253void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001254 GLenum pname,
1255 GLsizei bufSize,
1256 GLsizei *length,
1257 GLint *params)
1258{
1259 getQueryiv(target, pname, params);
1260}
1261
Geoff Lang2186c382016-10-14 10:54:54 -04001262void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001263{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001264 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001265}
1266
Brandon Jones59770802018-04-02 13:18:42 -07001267void Context::getQueryObjectivRobust(GLuint id,
1268 GLenum pname,
1269 GLsizei bufSize,
1270 GLsizei *length,
1271 GLint *params)
1272{
1273 getQueryObjectiv(id, pname, params);
1274}
1275
Geoff Lang2186c382016-10-14 10:54:54 -04001276void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001277{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001278 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001279}
1280
Brandon Jones59770802018-04-02 13:18:42 -07001281void Context::getQueryObjectuivRobust(GLuint id,
1282 GLenum pname,
1283 GLsizei bufSize,
1284 GLsizei *length,
1285 GLuint *params)
1286{
1287 getQueryObjectuiv(id, pname, params);
1288}
1289
Geoff Lang2186c382016-10-14 10:54:54 -04001290void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001291{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001292 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001293}
1294
Brandon Jones59770802018-04-02 13:18:42 -07001295void Context::getQueryObjecti64vRobust(GLuint id,
1296 GLenum pname,
1297 GLsizei bufSize,
1298 GLsizei *length,
1299 GLint64 *params)
1300{
1301 getQueryObjecti64v(id, pname, params);
1302}
1303
Geoff Lang2186c382016-10-14 10:54:54 -04001304void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001305{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001306 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001307}
1308
Brandon Jones59770802018-04-02 13:18:42 -07001309void Context::getQueryObjectui64vRobust(GLuint id,
1310 GLenum pname,
1311 GLsizei bufSize,
1312 GLsizei *length,
1313 GLuint64 *params)
1314{
1315 getQueryObjectui64v(id, pname, params);
1316}
1317
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001318Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001319{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001320 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001321}
1322
Jamie Madill2f348d22017-06-05 10:50:59 -04001323FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001324{
Jamie Madill96a483b2017-06-27 16:49:21 -04001325 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001326}
1327
Corentin Wallezad3ae902018-03-09 13:40:42 -05001328Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001329{
Jamie Madill96a483b2017-06-27 16:49:21 -04001330 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001331 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001332 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001333 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001334
1335 Query *query = mQueryMap.query(handle);
1336 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001337 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001338 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001339 query = new Query(mImplementation->createQuery(type), handle);
1340 query->addRef();
1341 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001342 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001343 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001344}
1345
Geoff Lang70d0f492015-12-10 17:45:46 -05001346Query *Context::getQuery(GLuint handle) const
1347{
Jamie Madill96a483b2017-06-27 16:49:21 -04001348 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001349}
1350
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001351Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001352{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001353 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1354 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001355}
1356
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001357Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001358{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001359 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001360}
1361
Geoff Lang492a7e42014-11-05 13:27:06 -05001362Compiler *Context::getCompiler() const
1363{
Jamie Madill2f348d22017-06-05 10:50:59 -04001364 if (mCompiler.get() == nullptr)
1365 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001366 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001367 }
1368 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001369}
1370
Jamie Madillc1d770e2017-04-13 17:31:24 -04001371void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001372{
1373 switch (pname)
1374 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001375 case GL_SHADER_COMPILER:
1376 *params = GL_TRUE;
1377 break;
1378 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1379 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1380 break;
1381 default:
1382 mGLState.getBooleanv(pname, params);
1383 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001384 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001385}
1386
Jamie Madillc1d770e2017-04-13 17:31:24 -04001387void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001388{
Shannon Woods53a94a82014-06-24 15:20:36 -04001389 // Queries about context capabilities and maximums are answered by Context.
1390 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001391 switch (pname)
1392 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001393 case GL_ALIASED_LINE_WIDTH_RANGE:
1394 params[0] = mCaps.minAliasedLineWidth;
1395 params[1] = mCaps.maxAliasedLineWidth;
1396 break;
1397 case GL_ALIASED_POINT_SIZE_RANGE:
1398 params[0] = mCaps.minAliasedPointSize;
1399 params[1] = mCaps.maxAliasedPointSize;
1400 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001401 case GL_SMOOTH_POINT_SIZE_RANGE:
1402 params[0] = mCaps.minSmoothPointSize;
1403 params[1] = mCaps.maxSmoothPointSize;
1404 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001405 case GL_SMOOTH_LINE_WIDTH_RANGE:
1406 params[0] = mCaps.minSmoothLineWidth;
1407 params[1] = mCaps.maxSmoothLineWidth;
1408 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001409 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1410 ASSERT(mExtensions.textureFilterAnisotropic);
1411 *params = mExtensions.maxTextureAnisotropy;
1412 break;
1413 case GL_MAX_TEXTURE_LOD_BIAS:
1414 *params = mCaps.maxLODBias;
1415 break;
1416
1417 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1418 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1419 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001420 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1421 // GLES1 constants for modelview/projection matrix.
1422 if (getClientVersion() < Version(2, 0))
1423 {
1424 mGLState.getFloatv(pname, params);
1425 }
1426 else
1427 {
1428 ASSERT(mExtensions.pathRendering);
1429 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1430 memcpy(params, m, 16 * sizeof(GLfloat));
1431 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001432 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001433 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001434
Jamie Madill231c7f52017-04-26 13:45:37 -04001435 default:
1436 mGLState.getFloatv(pname, params);
1437 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001438 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001439}
1440
Jamie Madillc1d770e2017-04-13 17:31:24 -04001441void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001442{
Shannon Woods53a94a82014-06-24 15:20:36 -04001443 // Queries about context capabilities and maximums are answered by Context.
1444 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001445
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001446 switch (pname)
1447 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001448 case GL_MAX_VERTEX_ATTRIBS:
1449 *params = mCaps.maxVertexAttributes;
1450 break;
1451 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1452 *params = mCaps.maxVertexUniformVectors;
1453 break;
1454 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001455 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001456 break;
1457 case GL_MAX_VARYING_VECTORS:
1458 *params = mCaps.maxVaryingVectors;
1459 break;
1460 case GL_MAX_VARYING_COMPONENTS:
1461 *params = mCaps.maxVertexOutputComponents;
1462 break;
1463 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1464 *params = mCaps.maxCombinedTextureImageUnits;
1465 break;
1466 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001467 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001468 break;
1469 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001470 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001471 break;
1472 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1473 *params = mCaps.maxFragmentUniformVectors;
1474 break;
1475 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001476 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001477 break;
1478 case GL_MAX_RENDERBUFFER_SIZE:
1479 *params = mCaps.maxRenderbufferSize;
1480 break;
1481 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1482 *params = mCaps.maxColorAttachments;
1483 break;
1484 case GL_MAX_DRAW_BUFFERS_EXT:
1485 *params = mCaps.maxDrawBuffers;
1486 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001487 case GL_SUBPIXEL_BITS:
1488 *params = 4;
1489 break;
1490 case GL_MAX_TEXTURE_SIZE:
1491 *params = mCaps.max2DTextureSize;
1492 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001493 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1494 *params = mCaps.maxRectangleTextureSize;
1495 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001496 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1497 *params = mCaps.maxCubeMapTextureSize;
1498 break;
1499 case GL_MAX_3D_TEXTURE_SIZE:
1500 *params = mCaps.max3DTextureSize;
1501 break;
1502 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1503 *params = mCaps.maxArrayTextureLayers;
1504 break;
1505 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1506 *params = mCaps.uniformBufferOffsetAlignment;
1507 break;
1508 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1509 *params = mCaps.maxUniformBufferBindings;
1510 break;
1511 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001512 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001513 break;
1514 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001515 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001516 break;
1517 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1518 *params = mCaps.maxCombinedTextureImageUnits;
1519 break;
1520 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1521 *params = mCaps.maxVertexOutputComponents;
1522 break;
1523 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1524 *params = mCaps.maxFragmentInputComponents;
1525 break;
1526 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1527 *params = mCaps.minProgramTexelOffset;
1528 break;
1529 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1530 *params = mCaps.maxProgramTexelOffset;
1531 break;
1532 case GL_MAJOR_VERSION:
1533 *params = getClientVersion().major;
1534 break;
1535 case GL_MINOR_VERSION:
1536 *params = getClientVersion().minor;
1537 break;
1538 case GL_MAX_ELEMENTS_INDICES:
1539 *params = mCaps.maxElementsIndices;
1540 break;
1541 case GL_MAX_ELEMENTS_VERTICES:
1542 *params = mCaps.maxElementsVertices;
1543 break;
1544 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1545 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1546 break;
1547 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1548 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1549 break;
1550 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1551 *params = mCaps.maxTransformFeedbackSeparateComponents;
1552 break;
1553 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1554 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1555 break;
1556 case GL_MAX_SAMPLES_ANGLE:
1557 *params = mCaps.maxSamples;
1558 break;
1559 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001560 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001561 params[0] = mCaps.maxViewportWidth;
1562 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001563 }
1564 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001565 case GL_COMPRESSED_TEXTURE_FORMATS:
1566 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1567 params);
1568 break;
1569 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1570 *params = mResetStrategy;
1571 break;
1572 case GL_NUM_SHADER_BINARY_FORMATS:
1573 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1574 break;
1575 case GL_SHADER_BINARY_FORMATS:
1576 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1577 break;
1578 case GL_NUM_PROGRAM_BINARY_FORMATS:
1579 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1580 break;
1581 case GL_PROGRAM_BINARY_FORMATS:
1582 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1583 break;
1584 case GL_NUM_EXTENSIONS:
1585 *params = static_cast<GLint>(mExtensionStrings.size());
1586 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001587
Geoff Lang38f24ee2018-10-01 13:04:59 -04001588 // GL_ANGLE_request_extension
1589 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
1590 *params = static_cast<GLint>(mRequestableExtensionStrings.size());
1591 break;
1592
Jamie Madill231c7f52017-04-26 13:45:37 -04001593 // GL_KHR_debug
1594 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1595 *params = mExtensions.maxDebugMessageLength;
1596 break;
1597 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1598 *params = mExtensions.maxDebugLoggedMessages;
1599 break;
1600 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1601 *params = mExtensions.maxDebugGroupStackDepth;
1602 break;
1603 case GL_MAX_LABEL_LENGTH:
1604 *params = mExtensions.maxLabelLength;
1605 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001606
Martin Radeve5285d22017-07-14 16:23:53 +03001607 // GL_ANGLE_multiview
1608 case GL_MAX_VIEWS_ANGLE:
1609 *params = mExtensions.maxViews;
1610 break;
1611
Jamie Madill231c7f52017-04-26 13:45:37 -04001612 // GL_EXT_disjoint_timer_query
1613 case GL_GPU_DISJOINT_EXT:
1614 *params = mImplementation->getGPUDisjoint();
1615 break;
1616 case GL_MAX_FRAMEBUFFER_WIDTH:
1617 *params = mCaps.maxFramebufferWidth;
1618 break;
1619 case GL_MAX_FRAMEBUFFER_HEIGHT:
1620 *params = mCaps.maxFramebufferHeight;
1621 break;
1622 case GL_MAX_FRAMEBUFFER_SAMPLES:
1623 *params = mCaps.maxFramebufferSamples;
1624 break;
1625 case GL_MAX_SAMPLE_MASK_WORDS:
1626 *params = mCaps.maxSampleMaskWords;
1627 break;
1628 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1629 *params = mCaps.maxColorTextureSamples;
1630 break;
1631 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1632 *params = mCaps.maxDepthTextureSamples;
1633 break;
1634 case GL_MAX_INTEGER_SAMPLES:
1635 *params = mCaps.maxIntegerSamples;
1636 break;
1637 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1638 *params = mCaps.maxVertexAttribRelativeOffset;
1639 break;
1640 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1641 *params = mCaps.maxVertexAttribBindings;
1642 break;
1643 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1644 *params = mCaps.maxVertexAttribStride;
1645 break;
1646 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001647 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001648 break;
1649 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001650 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001651 break;
1652 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001653 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001654 break;
1655 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001656 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001657 break;
1658 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001659 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001660 break;
1661 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001662 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001663 break;
1664 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001665 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001666 break;
1667 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001668 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001669 break;
1670 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1671 *params = mCaps.minProgramTextureGatherOffset;
1672 break;
1673 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1674 *params = mCaps.maxProgramTextureGatherOffset;
1675 break;
1676 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1677 *params = mCaps.maxComputeWorkGroupInvocations;
1678 break;
1679 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001680 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001681 break;
1682 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001683 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001684 break;
1685 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1686 *params = mCaps.maxComputeSharedMemorySize;
1687 break;
1688 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001689 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001690 break;
1691 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001692 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001693 break;
1694 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001695 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001696 break;
1697 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001698 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001699 break;
1700 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001701 *params =
1702 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001703 break;
1704 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001705 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001706 break;
1707 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1708 *params = mCaps.maxCombinedShaderOutputResources;
1709 break;
1710 case GL_MAX_UNIFORM_LOCATIONS:
1711 *params = mCaps.maxUniformLocations;
1712 break;
1713 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1714 *params = mCaps.maxAtomicCounterBufferBindings;
1715 break;
1716 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1717 *params = mCaps.maxAtomicCounterBufferSize;
1718 break;
1719 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1720 *params = mCaps.maxCombinedAtomicCounterBuffers;
1721 break;
1722 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1723 *params = mCaps.maxCombinedAtomicCounters;
1724 break;
1725 case GL_MAX_IMAGE_UNITS:
1726 *params = mCaps.maxImageUnits;
1727 break;
1728 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1729 *params = mCaps.maxCombinedImageUniforms;
1730 break;
1731 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1732 *params = mCaps.maxShaderStorageBufferBindings;
1733 break;
1734 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1735 *params = mCaps.maxCombinedShaderStorageBlocks;
1736 break;
1737 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1738 *params = mCaps.shaderStorageBufferOffsetAlignment;
1739 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001740
1741 // GL_EXT_geometry_shader
1742 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1743 *params = mCaps.maxFramebufferLayers;
1744 break;
1745 case GL_LAYER_PROVOKING_VERTEX_EXT:
1746 *params = mCaps.layerProvokingVertex;
1747 break;
1748 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001749 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001750 break;
1751 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001752 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001753 break;
1754 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001755 *params =
1756 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001757 break;
1758 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1759 *params = mCaps.maxGeometryInputComponents;
1760 break;
1761 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1762 *params = mCaps.maxGeometryOutputComponents;
1763 break;
1764 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1765 *params = mCaps.maxGeometryOutputVertices;
1766 break;
1767 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1768 *params = mCaps.maxGeometryTotalOutputComponents;
1769 break;
1770 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1771 *params = mCaps.maxGeometryShaderInvocations;
1772 break;
1773 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001774 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001775 break;
1776 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001777 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001778 break;
1779 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001780 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001781 break;
1782 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001783 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001784 break;
1785 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001786 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001787 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001788 // GLES1 emulation: Caps queries
1789 case GL_MAX_TEXTURE_UNITS:
1790 *params = mCaps.maxMultitextureUnits;
1791 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001792 case GL_MAX_MODELVIEW_STACK_DEPTH:
1793 *params = mCaps.maxModelviewMatrixStackDepth;
1794 break;
1795 case GL_MAX_PROJECTION_STACK_DEPTH:
1796 *params = mCaps.maxProjectionMatrixStackDepth;
1797 break;
1798 case GL_MAX_TEXTURE_STACK_DEPTH:
1799 *params = mCaps.maxTextureMatrixStackDepth;
1800 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001801 case GL_MAX_LIGHTS:
1802 *params = mCaps.maxLights;
1803 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001804 case GL_MAX_CLIP_PLANES:
1805 *params = mCaps.maxClipPlanes;
1806 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001807 // GLES1 emulation: Vertex attribute queries
1808 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1809 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1810 case GL_COLOR_ARRAY_BUFFER_BINDING:
1811 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1812 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1813 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1814 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1815 break;
1816 case GL_VERTEX_ARRAY_STRIDE:
1817 case GL_NORMAL_ARRAY_STRIDE:
1818 case GL_COLOR_ARRAY_STRIDE:
1819 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1820 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1821 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1822 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1823 break;
1824 case GL_VERTEX_ARRAY_SIZE:
1825 case GL_COLOR_ARRAY_SIZE:
1826 case GL_TEXTURE_COORD_ARRAY_SIZE:
1827 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1828 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1829 break;
1830 case GL_VERTEX_ARRAY_TYPE:
1831 case GL_COLOR_ARRAY_TYPE:
1832 case GL_NORMAL_ARRAY_TYPE:
1833 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1834 case GL_TEXTURE_COORD_ARRAY_TYPE:
1835 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1836 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1837 break;
1838
jchen1082af6202018-06-22 10:59:52 +08001839 // GL_KHR_parallel_shader_compile
1840 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1841 *params = mGLState.getMaxShaderCompilerThreads();
1842 break;
1843
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001844 // GL_EXT_blend_func_extended
1845 case GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT:
1846 *params = mExtensions.maxDualSourceDrawBuffers;
1847 break;
1848
Jamie Madill231c7f52017-04-26 13:45:37 -04001849 default:
Jamie Madill4f6592f2018-11-27 16:37:45 -05001850 ANGLE_CONTEXT_TRY(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001851 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001852 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001853}
1854
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001855void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001856{
Shannon Woods53a94a82014-06-24 15:20:36 -04001857 // Queries about context capabilities and maximums are answered by Context.
1858 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001859 switch (pname)
1860 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001861 case GL_MAX_ELEMENT_INDEX:
1862 *params = mCaps.maxElementIndex;
1863 break;
1864 case GL_MAX_UNIFORM_BLOCK_SIZE:
1865 *params = mCaps.maxUniformBlockSize;
1866 break;
1867 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001868 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001869 break;
1870 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001871 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001872 break;
1873 case GL_MAX_SERVER_WAIT_TIMEOUT:
1874 *params = mCaps.maxServerWaitTimeout;
1875 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001876
Jamie Madill231c7f52017-04-26 13:45:37 -04001877 // GL_EXT_disjoint_timer_query
1878 case GL_TIMESTAMP_EXT:
1879 *params = mImplementation->getTimestamp();
1880 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001881
Jamie Madill231c7f52017-04-26 13:45:37 -04001882 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1883 *params = mCaps.maxShaderStorageBlockSize;
1884 break;
1885 default:
1886 UNREACHABLE();
1887 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001888 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001889}
1890
Geoff Lang70d0f492015-12-10 17:45:46 -05001891void Context::getPointerv(GLenum pname, void **params) const
1892{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001893 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001894}
1895
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001896void Context::getPointervRobustANGLERobust(GLenum pname,
1897 GLsizei bufSize,
1898 GLsizei *length,
1899 void **params)
1900{
1901 UNIMPLEMENTED();
1902}
1903
Martin Radev66fb8202016-07-28 11:45:20 +03001904void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001905{
Shannon Woods53a94a82014-06-24 15:20:36 -04001906 // Queries about context capabilities and maximums are answered by Context.
1907 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001908
1909 GLenum nativeType;
1910 unsigned int numParams;
1911 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1912 ASSERT(queryStatus);
1913
1914 if (nativeType == GL_INT)
1915 {
1916 switch (target)
1917 {
1918 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1919 ASSERT(index < 3u);
1920 *data = mCaps.maxComputeWorkGroupCount[index];
1921 break;
1922 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1923 ASSERT(index < 3u);
1924 *data = mCaps.maxComputeWorkGroupSize[index];
1925 break;
1926 default:
1927 mGLState.getIntegeri_v(target, index, data);
1928 }
1929 }
1930 else
1931 {
1932 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1933 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001934}
1935
Brandon Jones59770802018-04-02 13:18:42 -07001936void Context::getIntegeri_vRobust(GLenum target,
1937 GLuint index,
1938 GLsizei bufSize,
1939 GLsizei *length,
1940 GLint *data)
1941{
1942 getIntegeri_v(target, index, data);
1943}
1944
Martin Radev66fb8202016-07-28 11:45:20 +03001945void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001946{
Shannon Woods53a94a82014-06-24 15:20:36 -04001947 // Queries about context capabilities and maximums are answered by Context.
1948 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001949
1950 GLenum nativeType;
1951 unsigned int numParams;
1952 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1953 ASSERT(queryStatus);
1954
1955 if (nativeType == GL_INT_64_ANGLEX)
1956 {
1957 mGLState.getInteger64i_v(target, index, data);
1958 }
1959 else
1960 {
1961 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1962 }
1963}
1964
Brandon Jones59770802018-04-02 13:18:42 -07001965void Context::getInteger64i_vRobust(GLenum target,
1966 GLuint index,
1967 GLsizei bufSize,
1968 GLsizei *length,
1969 GLint64 *data)
1970{
1971 getInteger64i_v(target, index, data);
1972}
1973
Martin Radev66fb8202016-07-28 11:45:20 +03001974void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1975{
1976 // Queries about context capabilities and maximums are answered by Context.
1977 // Queries about current GL state values are answered by State.
1978
1979 GLenum nativeType;
1980 unsigned int numParams;
1981 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1982 ASSERT(queryStatus);
1983
1984 if (nativeType == GL_BOOL)
1985 {
1986 mGLState.getBooleani_v(target, index, data);
1987 }
1988 else
1989 {
1990 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1991 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001992}
1993
Brandon Jones59770802018-04-02 13:18:42 -07001994void Context::getBooleani_vRobust(GLenum target,
1995 GLuint index,
1996 GLsizei bufSize,
1997 GLsizei *length,
1998 GLboolean *data)
1999{
2000 getBooleani_v(target, index, data);
2001}
2002
Corentin Wallez336129f2017-10-17 15:55:40 -04002003void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002004{
2005 Buffer *buffer = mGLState.getTargetBuffer(target);
2006 QueryBufferParameteriv(buffer, pname, params);
2007}
2008
Brandon Jones59770802018-04-02 13:18:42 -07002009void Context::getBufferParameterivRobust(BufferBinding target,
2010 GLenum pname,
2011 GLsizei bufSize,
2012 GLsizei *length,
2013 GLint *params)
2014{
2015 getBufferParameteriv(target, pname, params);
2016}
2017
He Yunchao010e4db2017-03-03 14:22:06 +08002018void Context::getFramebufferAttachmentParameteriv(GLenum target,
2019 GLenum attachment,
2020 GLenum pname,
2021 GLint *params)
2022{
2023 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002024 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002025}
2026
Brandon Jones59770802018-04-02 13:18:42 -07002027void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2028 GLenum attachment,
2029 GLenum pname,
2030 GLsizei bufSize,
2031 GLsizei *length,
2032 GLint *params)
2033{
2034 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2035}
2036
He Yunchao010e4db2017-03-03 14:22:06 +08002037void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2038{
2039 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2040 QueryRenderbufferiv(this, renderbuffer, pname, params);
2041}
2042
Brandon Jones59770802018-04-02 13:18:42 -07002043void Context::getRenderbufferParameterivRobust(GLenum target,
2044 GLenum pname,
2045 GLsizei bufSize,
2046 GLsizei *length,
2047 GLint *params)
2048{
2049 getRenderbufferParameteriv(target, pname, params);
2050}
2051
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002052void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002053{
Till Rathmannb8543632018-10-02 19:46:14 +02002054 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002055 QueryTexParameterfv(texture, pname, params);
2056}
2057
Brandon Jones59770802018-04-02 13:18:42 -07002058void Context::getTexParameterfvRobust(TextureType target,
2059 GLenum pname,
2060 GLsizei bufSize,
2061 GLsizei *length,
2062 GLfloat *params)
2063{
2064 getTexParameterfv(target, pname, params);
2065}
2066
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002067void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002068{
Till Rathmannb8543632018-10-02 19:46:14 +02002069 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002070 QueryTexParameteriv(texture, pname, params);
2071}
Jiajia Qin5451d532017-11-16 17:16:34 +08002072
Till Rathmannb8543632018-10-02 19:46:14 +02002073void Context::getTexParameterIiv(TextureType target, GLenum pname, GLint *params)
2074{
2075 const Texture *const texture = getTargetTexture(target);
2076 QueryTexParameterIiv(texture, pname, params);
2077}
2078
2079void Context::getTexParameterIuiv(TextureType target, GLenum pname, GLuint *params)
2080{
2081 const Texture *const texture = getTargetTexture(target);
2082 QueryTexParameterIuiv(texture, pname, params);
2083}
2084
Brandon Jones59770802018-04-02 13:18:42 -07002085void Context::getTexParameterivRobust(TextureType target,
2086 GLenum pname,
2087 GLsizei bufSize,
2088 GLsizei *length,
2089 GLint *params)
2090{
2091 getTexParameteriv(target, pname, params);
2092}
2093
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002094void Context::getTexParameterIivRobust(TextureType target,
2095 GLenum pname,
2096 GLsizei bufSize,
2097 GLsizei *length,
2098 GLint *params)
2099{
2100 UNIMPLEMENTED();
2101}
2102
2103void Context::getTexParameterIuivRobust(TextureType target,
2104 GLenum pname,
2105 GLsizei bufSize,
2106 GLsizei *length,
2107 GLuint *params)
2108{
2109 UNIMPLEMENTED();
2110}
2111
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002112void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002113{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002114 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002115 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002116}
2117
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002118void Context::getTexLevelParameterivRobust(TextureTarget target,
2119 GLint level,
2120 GLenum pname,
2121 GLsizei bufSize,
2122 GLsizei *length,
2123 GLint *params)
2124{
2125 UNIMPLEMENTED();
2126}
2127
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002128void Context::getTexLevelParameterfv(TextureTarget target,
2129 GLint level,
2130 GLenum pname,
2131 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002132{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002133 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002134 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002135}
2136
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002137void Context::getTexLevelParameterfvRobust(TextureTarget target,
2138 GLint level,
2139 GLenum pname,
2140 GLsizei bufSize,
2141 GLsizei *length,
2142 GLfloat *params)
2143{
2144 UNIMPLEMENTED();
2145}
2146
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002147void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002148{
Till Rathmannb8543632018-10-02 19:46:14 +02002149 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002150 SetTexParameterf(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002151}
2152
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002153void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002154{
Till Rathmannb8543632018-10-02 19:46:14 +02002155 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002156 SetTexParameterfv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002157}
2158
Brandon Jones59770802018-04-02 13:18:42 -07002159void Context::texParameterfvRobust(TextureType target,
2160 GLenum pname,
2161 GLsizei bufSize,
2162 const GLfloat *params)
2163{
2164 texParameterfv(target, pname, params);
2165}
2166
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002167void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002168{
Till Rathmannb8543632018-10-02 19:46:14 +02002169 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002170 SetTexParameteri(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002171}
2172
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002173void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002174{
Till Rathmannb8543632018-10-02 19:46:14 +02002175 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002176 SetTexParameteriv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002177}
2178
Till Rathmannb8543632018-10-02 19:46:14 +02002179void Context::texParameterIiv(TextureType target, GLenum pname, const GLint *params)
2180{
2181 Texture *const texture = getTargetTexture(target);
2182 SetTexParameterIiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002183}
2184
2185void Context::texParameterIuiv(TextureType target, GLenum pname, const GLuint *params)
2186{
2187 Texture *const texture = getTargetTexture(target);
2188 SetTexParameterIuiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002189}
2190
Brandon Jones59770802018-04-02 13:18:42 -07002191void Context::texParameterivRobust(TextureType target,
2192 GLenum pname,
2193 GLsizei bufSize,
2194 const GLint *params)
2195{
2196 texParameteriv(target, pname, params);
2197}
2198
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002199void Context::texParameterIivRobust(TextureType target,
2200 GLenum pname,
2201 GLsizei bufSize,
2202 const GLint *params)
2203{
2204 UNIMPLEMENTED();
2205}
2206
2207void Context::texParameterIuivRobust(TextureType target,
2208 GLenum pname,
2209 GLsizei bufSize,
2210 const GLuint *params)
2211{
2212 UNIMPLEMENTED();
2213}
2214
Jamie Madill493f9572018-05-24 19:52:15 -04002215void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002216{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002217 // No-op if count draws no primitives for given mode
2218 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002219 {
2220 return;
2221 }
2222
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002223 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002224 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002225 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002226}
2227
Jamie Madill493f9572018-05-24 19:52:15 -04002228void Context::drawArraysInstanced(PrimitiveMode mode,
2229 GLint first,
2230 GLsizei count,
2231 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002232{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002233 // No-op if count draws no primitives for given mode
2234 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002235 {
2236 return;
2237 }
2238
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002239 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002240 ANGLE_CONTEXT_TRY(
2241 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002242 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2243 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002244}
2245
Jamie Madill8dc27f92018-11-29 11:45:44 -05002246void Context::drawElements(PrimitiveMode mode,
2247 GLsizei count,
2248 DrawElementsType type,
2249 const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002250{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002251 // No-op if count draws no primitives for given mode
2252 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002253 {
2254 return;
2255 }
2256
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002257 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002258 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002259}
2260
Jamie Madill493f9572018-05-24 19:52:15 -04002261void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002262 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002263 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002264 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002265 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002266{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002267 // No-op if count draws no primitives for given mode
2268 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002269 {
2270 return;
2271 }
2272
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002273 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002274 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002275 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002276}
2277
Jamie Madill493f9572018-05-24 19:52:15 -04002278void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002279 GLuint start,
2280 GLuint end,
2281 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002282 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002283 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002284{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002285 // No-op if count draws no primitives for given mode
2286 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002287 {
2288 return;
2289 }
2290
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002291 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002292 ANGLE_CONTEXT_TRY(
2293 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002294}
2295
Jamie Madill493f9572018-05-24 19:52:15 -04002296void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002297{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002298 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002299 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002300}
2301
Jamie Madill8dc27f92018-11-29 11:45:44 -05002302void Context::drawElementsIndirect(PrimitiveMode mode, DrawElementsType type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002303{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002304 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002305 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002306}
2307
Jamie Madill675fe712016-12-19 13:07:54 -05002308void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002309{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002310 ANGLE_CONTEXT_TRY(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002311}
2312
Jamie Madill675fe712016-12-19 13:07:54 -05002313void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002314{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002315 ANGLE_CONTEXT_TRY(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002316}
2317
Austin Kinross6ee1e782015-05-29 17:05:37 -07002318void Context::insertEventMarker(GLsizei length, const char *marker)
2319{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002320 ASSERT(mImplementation);
2321 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002322}
2323
2324void Context::pushGroupMarker(GLsizei length, const char *marker)
2325{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002326 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002327
2328 if (marker == nullptr)
2329 {
2330 // From the EXT_debug_marker spec,
2331 // "If <marker> is null then an empty string is pushed on the stack."
2332 mImplementation->pushGroupMarker(length, "");
2333 }
2334 else
2335 {
2336 mImplementation->pushGroupMarker(length, marker);
2337 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002338}
2339
2340void Context::popGroupMarker()
2341{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002342 ASSERT(mImplementation);
2343 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002344}
2345
Geoff Langd8605522016-04-13 10:19:12 -04002346void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2347{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002348 Program *programObject = getProgramResolveLink(program);
Geoff Langd8605522016-04-13 10:19:12 -04002349 ASSERT(programObject);
2350
2351 programObject->bindUniformLocation(location, name);
2352}
2353
Brandon Jones59770802018-04-02 13:18:42 -07002354void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002355{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002356 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002357}
2358
Brandon Jones59770802018-04-02 13:18:42 -07002359void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002360{
2361 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2362}
2363
Brandon Jones59770802018-04-02 13:18:42 -07002364void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002365{
2366 GLfloat I[16];
2367 angle::Matrix<GLfloat>::setToIdentity(I);
2368
2369 mGLState.loadPathRenderingMatrix(matrixMode, I);
2370}
2371
2372void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2373{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002374 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002375 if (!pathObj)
2376 return;
2377
Geoff Lang9bf86f02018-07-26 11:46:34 -04002378 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002379
2380 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2381}
2382
2383void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2384{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002385 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002386 if (!pathObj)
2387 return;
2388
Geoff Lang9bf86f02018-07-26 11:46:34 -04002389 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002390
2391 mImplementation->stencilStrokePath(pathObj, reference, mask);
2392}
2393
2394void Context::coverFillPath(GLuint path, GLenum coverMode)
2395{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002396 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002397 if (!pathObj)
2398 return;
2399
Geoff Lang9bf86f02018-07-26 11:46:34 -04002400 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002401
2402 mImplementation->coverFillPath(pathObj, coverMode);
2403}
2404
2405void Context::coverStrokePath(GLuint path, GLenum coverMode)
2406{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002407 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002408 if (!pathObj)
2409 return;
2410
Geoff Lang9bf86f02018-07-26 11:46:34 -04002411 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002412
2413 mImplementation->coverStrokePath(pathObj, coverMode);
2414}
2415
2416void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2417{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002418 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002419 if (!pathObj)
2420 return;
2421
Geoff Lang9bf86f02018-07-26 11:46:34 -04002422 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002423
2424 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2425}
2426
2427void Context::stencilThenCoverStrokePath(GLuint path,
2428 GLint reference,
2429 GLuint mask,
2430 GLenum coverMode)
2431{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002432 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002433 if (!pathObj)
2434 return;
2435
Geoff Lang9bf86f02018-07-26 11:46:34 -04002436 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002437
2438 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2439}
2440
Sami Väisänend59ca052016-06-21 16:10:00 +03002441void Context::coverFillPathInstanced(GLsizei numPaths,
2442 GLenum pathNameType,
2443 const void *paths,
2444 GLuint pathBase,
2445 GLenum coverMode,
2446 GLenum transformType,
2447 const GLfloat *transformValues)
2448{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002449 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002450
Geoff Lang9bf86f02018-07-26 11:46:34 -04002451 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002452
2453 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2454}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002455
Sami Väisänend59ca052016-06-21 16:10:00 +03002456void Context::coverStrokePathInstanced(GLsizei numPaths,
2457 GLenum pathNameType,
2458 const void *paths,
2459 GLuint pathBase,
2460 GLenum coverMode,
2461 GLenum transformType,
2462 const GLfloat *transformValues)
2463{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002464 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002465
2466 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002467 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002468
2469 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2470 transformValues);
2471}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002472
Sami Väisänend59ca052016-06-21 16:10:00 +03002473void Context::stencilFillPathInstanced(GLsizei numPaths,
2474 GLenum pathNameType,
2475 const void *paths,
2476 GLuint pathBase,
2477 GLenum fillMode,
2478 GLuint mask,
2479 GLenum transformType,
2480 const GLfloat *transformValues)
2481{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002482 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002483
2484 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002485 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002486
2487 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2488 transformValues);
2489}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002490
Sami Väisänend59ca052016-06-21 16:10:00 +03002491void Context::stencilStrokePathInstanced(GLsizei numPaths,
2492 GLenum pathNameType,
2493 const void *paths,
2494 GLuint pathBase,
2495 GLint reference,
2496 GLuint mask,
2497 GLenum transformType,
2498 const GLfloat *transformValues)
2499{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002500 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002501
Geoff Lang9bf86f02018-07-26 11:46:34 -04002502 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002503
2504 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2505 transformValues);
2506}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002507
Sami Väisänend59ca052016-06-21 16:10:00 +03002508void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2509 GLenum pathNameType,
2510 const void *paths,
2511 GLuint pathBase,
2512 GLenum fillMode,
2513 GLuint mask,
2514 GLenum coverMode,
2515 GLenum transformType,
2516 const GLfloat *transformValues)
2517{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002518 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002519
Geoff Lang9bf86f02018-07-26 11:46:34 -04002520 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002521
2522 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2523 transformType, transformValues);
2524}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002525
Sami Väisänend59ca052016-06-21 16:10:00 +03002526void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2527 GLenum pathNameType,
2528 const void *paths,
2529 GLuint pathBase,
2530 GLint reference,
2531 GLuint mask,
2532 GLenum coverMode,
2533 GLenum transformType,
2534 const GLfloat *transformValues)
2535{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002536 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002537
Geoff Lang9bf86f02018-07-26 11:46:34 -04002538 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002539
2540 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2541 transformType, transformValues);
2542}
2543
Sami Väisänen46eaa942016-06-29 10:26:37 +03002544void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2545{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002546 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002547
2548 programObject->bindFragmentInputLocation(location, name);
2549}
2550
2551void Context::programPathFragmentInputGen(GLuint program,
2552 GLint location,
2553 GLenum genMode,
2554 GLint components,
2555 const GLfloat *coeffs)
2556{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002557 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002558
jchen103fd614d2018-08-13 12:21:58 +08002559 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002560}
2561
jchen1015015f72017-03-16 13:54:21 +08002562GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2563{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002564 const Program *programObject = getProgramResolveLink(program);
jchen1015015f72017-03-16 13:54:21 +08002565 return QueryProgramResourceIndex(programObject, programInterface, name);
2566}
2567
jchen10fd7c3b52017-03-21 15:36:03 +08002568void Context::getProgramResourceName(GLuint program,
2569 GLenum programInterface,
2570 GLuint index,
2571 GLsizei bufSize,
2572 GLsizei *length,
2573 GLchar *name)
2574{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002575 const Program *programObject = getProgramResolveLink(program);
jchen10fd7c3b52017-03-21 15:36:03 +08002576 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2577}
2578
jchen10191381f2017-04-11 13:59:04 +08002579GLint Context::getProgramResourceLocation(GLuint program,
2580 GLenum programInterface,
2581 const GLchar *name)
2582{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002583 const Program *programObject = getProgramResolveLink(program);
jchen10191381f2017-04-11 13:59:04 +08002584 return QueryProgramResourceLocation(programObject, programInterface, name);
2585}
2586
jchen10880683b2017-04-12 16:21:55 +08002587void Context::getProgramResourceiv(GLuint program,
2588 GLenum programInterface,
2589 GLuint index,
2590 GLsizei propCount,
2591 const GLenum *props,
2592 GLsizei bufSize,
2593 GLsizei *length,
2594 GLint *params)
2595{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002596 const Program *programObject = getProgramResolveLink(program);
jchen10880683b2017-04-12 16:21:55 +08002597 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2598 length, params);
2599}
2600
jchen10d9cd7b72017-08-30 15:04:25 +08002601void Context::getProgramInterfaceiv(GLuint program,
2602 GLenum programInterface,
2603 GLenum pname,
2604 GLint *params)
2605{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002606 const Program *programObject = getProgramResolveLink(program);
jchen10d9cd7b72017-08-30 15:04:25 +08002607 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2608}
2609
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002610void Context::getProgramInterfaceivRobust(GLuint program,
2611 GLenum programInterface,
2612 GLenum pname,
2613 GLsizei bufSize,
2614 GLsizei *length,
2615 GLint *params)
2616{
2617 UNIMPLEMENTED();
2618}
2619
Jamie Madillabfbc0f2018-10-09 12:48:52 -04002620void Context::handleError(GLenum errorCode,
2621 const char *message,
2622 const char *file,
2623 const char *function,
2624 unsigned int line)
2625{
2626 mErrors.handleError(errorCode, message, file, function, line);
2627}
2628
Jamie Madilla139f012018-10-10 16:13:03 -04002629void Context::validationError(GLenum errorCode, const char *message)
2630{
2631 mErrors.validationError(errorCode, message);
2632}
2633
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002634// Get one of the recorded errors and clear its flag, if any.
2635// [OpenGL ES 2.0.24] section 2.5 page 13.
2636GLenum Context::getError()
2637{
Geoff Langda5777c2014-07-11 09:52:58 -04002638 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002639 {
Geoff Langda5777c2014-07-11 09:52:58 -04002640 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002641 }
Geoff Langda5777c2014-07-11 09:52:58 -04002642 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002643 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002644 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002645 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002646}
2647
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002648// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002649void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002650{
2651 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002652 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002653 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002654 mContextLostForced = true;
2655 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002656 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002657}
2658
Jamie Madillfa920eb2018-01-04 11:45:50 -05002659GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002660{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002661 // Even if the application doesn't want to know about resets, we want to know
2662 // as it will allow us to skip all the calls.
2663 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002664 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002665 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002666 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002667 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002668 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002669
2670 // EXT_robustness, section 2.6: If the reset notification behavior is
2671 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2672 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2673 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002674 }
2675
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002676 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2677 // status should be returned at least once, and GL_NO_ERROR should be returned
2678 // once the device has finished resetting.
2679 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002680 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002681 ASSERT(mResetStatus == GL_NO_ERROR);
2682 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002683
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002684 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002685 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002686 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002687 }
2688 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002689 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002690 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002691 // If markContextLost was used to mark the context lost then
2692 // assume that is not recoverable, and continue to report the
2693 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002694 mResetStatus = mImplementation->getResetStatus();
2695 }
Jamie Madill893ab082014-05-16 16:56:10 -04002696
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002697 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002698}
2699
2700bool Context::isResetNotificationEnabled()
2701{
2702 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2703}
2704
Corentin Walleze3b10e82015-05-20 11:06:25 -04002705const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002706{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002707 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002708}
2709
2710EGLenum Context::getClientType() const
2711{
2712 return mClientType;
2713}
2714
2715EGLenum Context::getRenderBuffer() const
2716{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002717 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2718 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002719 {
2720 return EGL_NONE;
2721 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002722
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002723 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002724 ASSERT(backAttachment != nullptr);
2725 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002726}
2727
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002728VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002729{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002730 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002731 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2732 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002733 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002734 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2735 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002736
Jamie Madill96a483b2017-06-27 16:49:21 -04002737 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002738 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002739
2740 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002741}
2742
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002743TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002744{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002745 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002746 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2747 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002748 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002749 transformFeedback =
2750 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002751 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002752 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002753 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002754
2755 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002756}
2757
2758bool Context::isVertexArrayGenerated(GLuint vertexArray)
2759{
Jamie Madill96a483b2017-06-27 16:49:21 -04002760 ASSERT(mVertexArrayMap.contains(0));
2761 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002762}
2763
2764bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2765{
Jamie Madill96a483b2017-06-27 16:49:21 -04002766 ASSERT(mTransformFeedbackMap.contains(0));
2767 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002768}
2769
Shannon Woods53a94a82014-06-24 15:20:36 -04002770void Context::detachTexture(GLuint texture)
2771{
2772 // Simple pass-through to State's detachTexture method, as textures do not require
2773 // allocation map management either here or in the resource manager at detach time.
2774 // Zero textures are held by the Context, and we don't attempt to request them from
2775 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002776 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002777}
2778
James Darpinian4d9d4832018-03-13 12:43:28 -07002779void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002780{
Yuly Novikov5807a532015-12-03 13:01:22 -05002781 // Simple pass-through to State's detachBuffer method, since
2782 // only buffer attachments to container objects that are bound to the current context
2783 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002784
Yuly Novikov5807a532015-12-03 13:01:22 -05002785 // [OpenGL ES 3.2] section 5.1.2 page 45:
2786 // Attachments to unbound container objects, such as
2787 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2788 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002789 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002790}
2791
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002792void Context::detachFramebuffer(GLuint framebuffer)
2793{
Shannon Woods53a94a82014-06-24 15:20:36 -04002794 // Framebuffer detachment is handled by Context, because 0 is a valid
2795 // Framebuffer object, and a pointer to it must be passed from Context
2796 // to State at binding time.
2797
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002798 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002799 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2800 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2801 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002802
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002803 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002804 {
2805 bindReadFramebuffer(0);
2806 }
2807
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002808 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002809 {
2810 bindDrawFramebuffer(0);
2811 }
2812}
2813
2814void Context::detachRenderbuffer(GLuint renderbuffer)
2815{
Jamie Madilla02315b2017-02-23 14:14:47 -05002816 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002817}
2818
Jamie Madill57a89722013-07-02 11:57:03 -04002819void Context::detachVertexArray(GLuint vertexArray)
2820{
Jamie Madill77a72f62015-04-14 11:18:32 -04002821 // Vertex array detachment is handled by Context, because 0 is a valid
2822 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002823 // binding time.
2824
Jamie Madill57a89722013-07-02 11:57:03 -04002825 // [OpenGL ES 3.0.2] section 2.10 page 43:
2826 // If a vertex array object that is currently bound is deleted, the binding
2827 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002828 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002829 {
2830 bindVertexArray(0);
2831 }
2832}
2833
Geoff Langc8058452014-02-03 12:04:11 -05002834void Context::detachTransformFeedback(GLuint transformFeedback)
2835{
Corentin Walleza2257da2016-04-19 16:43:12 -04002836 // Transform feedback detachment is handled by Context, because 0 is a valid
2837 // transform feedback, and a pointer to it must be passed from Context to State at
2838 // binding time.
2839
2840 // The OpenGL specification doesn't mention what should happen when the currently bound
2841 // transform feedback object is deleted. Since it is a container object, we treat it like
2842 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002843 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002844 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002845 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002846 }
Geoff Langc8058452014-02-03 12:04:11 -05002847}
2848
Jamie Madilldc356042013-07-19 16:36:57 -04002849void Context::detachSampler(GLuint sampler)
2850{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002851 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002852}
2853
Yunchao Hea336b902017-08-02 16:05:21 +08002854void Context::detachProgramPipeline(GLuint pipeline)
2855{
2856 mGLState.detachProgramPipeline(this, pipeline);
2857}
2858
Jamie Madill3ef140a2017-08-26 23:11:21 -04002859void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002860{
Shaodde78e82017-05-22 14:13:27 +08002861 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002862 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002863}
2864
Jamie Madille29d1672013-07-19 16:36:57 -04002865void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2866{
Till Rathmannb8543632018-10-02 19:46:14 +02002867 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002868 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002869 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002870}
Jamie Madille29d1672013-07-19 16:36:57 -04002871
Geoff Langc1984ed2016-10-07 12:41:00 -04002872void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2873{
Till Rathmannb8543632018-10-02 19:46:14 +02002874 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002875 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002876 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002877}
2878
Till Rathmannb8543632018-10-02 19:46:14 +02002879void Context::samplerParameterIiv(GLuint sampler, GLenum pname, const GLint *param)
2880{
2881 Sampler *const samplerObject =
2882 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2883 SetSamplerParameterIiv(this, samplerObject, pname, param);
2884}
2885
2886void Context::samplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *param)
2887{
2888 Sampler *const samplerObject =
2889 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2890 SetSamplerParameterIuiv(this, samplerObject, pname, param);
2891}
2892
Brandon Jones59770802018-04-02 13:18:42 -07002893void Context::samplerParameterivRobust(GLuint sampler,
2894 GLenum pname,
2895 GLsizei bufSize,
2896 const GLint *param)
2897{
2898 samplerParameteriv(sampler, pname, param);
2899}
2900
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002901void Context::samplerParameterIivRobust(GLuint sampler,
2902 GLenum pname,
2903 GLsizei bufSize,
2904 const GLint *param)
2905{
2906 UNIMPLEMENTED();
2907}
2908
2909void Context::samplerParameterIuivRobust(GLuint sampler,
2910 GLenum pname,
2911 GLsizei bufSize,
2912 const GLuint *param)
2913{
2914 UNIMPLEMENTED();
2915}
2916
Jamie Madille29d1672013-07-19 16:36:57 -04002917void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2918{
Till Rathmannb8543632018-10-02 19:46:14 +02002919 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002920 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002921 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002922}
2923
Geoff Langc1984ed2016-10-07 12:41:00 -04002924void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002925{
Till Rathmannb8543632018-10-02 19:46:14 +02002926 Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002927 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002928 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002929}
2930
Brandon Jones59770802018-04-02 13:18:42 -07002931void Context::samplerParameterfvRobust(GLuint sampler,
2932 GLenum pname,
2933 GLsizei bufSize,
2934 const GLfloat *param)
2935{
2936 samplerParameterfv(sampler, pname, param);
2937}
2938
Geoff Langc1984ed2016-10-07 12:41:00 -04002939void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002940{
Till Rathmannb8543632018-10-02 19:46:14 +02002941 const Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002942 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002943 QuerySamplerParameteriv(samplerObject, pname, params);
2944}
Jamie Madill9675b802013-07-19 16:36:59 -04002945
Till Rathmannb8543632018-10-02 19:46:14 +02002946void Context::getSamplerParameterIiv(GLuint sampler, GLenum pname, GLint *params)
2947{
2948 const Sampler *const samplerObject =
2949 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2950 QuerySamplerParameterIiv(samplerObject, pname, params);
2951}
2952
2953void Context::getSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint *params)
2954{
2955 const Sampler *const samplerObject =
2956 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
2957 QuerySamplerParameterIuiv(samplerObject, pname, params);
2958}
2959
Brandon Jones59770802018-04-02 13:18:42 -07002960void Context::getSamplerParameterivRobust(GLuint sampler,
2961 GLenum pname,
2962 GLsizei bufSize,
2963 GLsizei *length,
2964 GLint *params)
2965{
2966 getSamplerParameteriv(sampler, pname, params);
2967}
2968
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002969void Context::getSamplerParameterIivRobust(GLuint sampler,
2970 GLenum pname,
2971 GLsizei bufSize,
2972 GLsizei *length,
2973 GLint *params)
2974{
2975 UNIMPLEMENTED();
2976}
2977
2978void Context::getSamplerParameterIuivRobust(GLuint sampler,
2979 GLenum pname,
2980 GLsizei bufSize,
2981 GLsizei *length,
2982 GLuint *params)
2983{
2984 UNIMPLEMENTED();
2985}
2986
Geoff Langc1984ed2016-10-07 12:41:00 -04002987void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2988{
Till Rathmannb8543632018-10-02 19:46:14 +02002989 const Sampler *const samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002990 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002991 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002992}
2993
Brandon Jones59770802018-04-02 13:18:42 -07002994void Context::getSamplerParameterfvRobust(GLuint sampler,
2995 GLenum pname,
2996 GLsizei bufSize,
2997 GLsizei *length,
2998 GLfloat *params)
2999{
3000 getSamplerParameterfv(sampler, pname, params);
3001}
3002
Olli Etuahof0fee072016-03-30 15:11:58 +03003003void Context::programParameteri(GLuint program, GLenum pname, GLint value)
3004{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04003005 gl::Program *programObject = getProgramResolveLink(program);
Yunchao He61afff12017-03-14 15:34:03 +08003006 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03003007}
3008
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003009void Context::initRendererString()
3010{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00003011 std::ostringstream rendererString;
3012 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003013 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00003014 rendererString << ")";
3015
Geoff Langcec35902014-04-16 10:52:36 -04003016 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003017}
3018
Geoff Langc339c4e2016-11-29 10:37:36 -05003019void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003020{
Geoff Langc339c4e2016-11-29 10:37:36 -05003021 const Version &clientVersion = getClientVersion();
3022
3023 std::ostringstream versionString;
3024 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
3025 << ANGLE_VERSION_STRING << ")";
3026 mVersionString = MakeStaticString(versionString.str());
3027
3028 std::ostringstream shadingLanguageVersionString;
3029 shadingLanguageVersionString << "OpenGL ES GLSL ES "
3030 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
3031 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
3032 << ")";
3033 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003034}
3035
Geoff Langcec35902014-04-16 10:52:36 -04003036void Context::initExtensionStrings()
3037{
Geoff Langc339c4e2016-11-29 10:37:36 -05003038 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
3039 std::ostringstream combinedStringStream;
3040 std::copy(strings.begin(), strings.end(),
3041 std::ostream_iterator<const char *>(combinedStringStream, " "));
3042 return MakeStaticString(combinedStringStream.str());
3043 };
3044
3045 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003046 for (const auto &extensionString : mExtensions.getStrings())
3047 {
3048 mExtensionStrings.push_back(MakeStaticString(extensionString));
3049 }
Geoff Langc339c4e2016-11-29 10:37:36 -05003050 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003051
Geoff Langc339c4e2016-11-29 10:37:36 -05003052 mRequestableExtensionStrings.clear();
3053 for (const auto &extensionInfo : GetExtensionInfoMap())
3054 {
3055 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003056 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003057 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003058 {
3059 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3060 }
3061 }
3062 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003063}
3064
Geoff Langc339c4e2016-11-29 10:37:36 -05003065const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003066{
Geoff Langc339c4e2016-11-29 10:37:36 -05003067 switch (name)
3068 {
3069 case GL_VENDOR:
3070 return reinterpret_cast<const GLubyte *>("Google Inc.");
3071
3072 case GL_RENDERER:
3073 return reinterpret_cast<const GLubyte *>(mRendererString);
3074
3075 case GL_VERSION:
3076 return reinterpret_cast<const GLubyte *>(mVersionString);
3077
3078 case GL_SHADING_LANGUAGE_VERSION:
3079 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3080
3081 case GL_EXTENSIONS:
3082 return reinterpret_cast<const GLubyte *>(mExtensionString);
3083
3084 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3085 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3086
3087 default:
3088 UNREACHABLE();
3089 return nullptr;
3090 }
Geoff Langcec35902014-04-16 10:52:36 -04003091}
3092
Geoff Langc339c4e2016-11-29 10:37:36 -05003093const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003094{
Geoff Langc339c4e2016-11-29 10:37:36 -05003095 switch (name)
3096 {
3097 case GL_EXTENSIONS:
3098 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3099
3100 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3101 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3102
3103 default:
3104 UNREACHABLE();
3105 return nullptr;
3106 }
Geoff Langcec35902014-04-16 10:52:36 -04003107}
3108
3109size_t Context::getExtensionStringCount() const
3110{
3111 return mExtensionStrings.size();
3112}
3113
Geoff Lang111a99e2017-10-17 10:58:41 -04003114bool Context::isExtensionRequestable(const char *name)
3115{
3116 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3117 auto extension = extensionInfos.find(name);
3118
Geoff Lang111a99e2017-10-17 10:58:41 -04003119 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003120 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003121}
3122
Geoff Langc339c4e2016-11-29 10:37:36 -05003123void Context::requestExtension(const char *name)
3124{
3125 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3126 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3127 const auto &extension = extensionInfos.at(name);
3128 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003129 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003130
3131 if (mExtensions.*(extension.ExtensionsMember))
3132 {
3133 // Extension already enabled
3134 return;
3135 }
3136
3137 mExtensions.*(extension.ExtensionsMember) = true;
3138 updateCaps();
3139 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003140
Jamie Madill2f348d22017-06-05 10:50:59 -04003141 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3142 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003143
Jamie Madill81c2e252017-09-09 23:32:46 -04003144 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3145 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003146 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003147 for (auto &zeroTexture : mZeroTextures)
3148 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003149 if (zeroTexture.get() != nullptr)
3150 {
Jamie Madille3e680c2018-12-03 17:49:08 -05003151 zeroTexture->signalDirtyStorage(this, InitState::Initialized);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003152 }
Geoff Lang9aded172017-04-05 11:07:56 -04003153 }
3154
Jamie Madillb983a4b2018-08-01 11:34:51 -04003155 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003156}
3157
3158size_t Context::getRequestableExtensionStringCount() const
3159{
3160 return mRequestableExtensionStrings.size();
3161}
3162
Jamie Madill493f9572018-05-24 19:52:15 -04003163void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003164{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003165 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003166 ASSERT(transformFeedback != nullptr);
3167 ASSERT(!transformFeedback->isPaused());
3168
Jamie Madill6c1f6712017-02-14 19:08:04 -05003169 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Jamie Madilld84b6732018-09-06 15:54:35 -04003170 mStateCache.onTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003171}
3172
3173bool Context::hasActiveTransformFeedback(GLuint program) const
3174{
3175 for (auto pair : mTransformFeedbackMap)
3176 {
3177 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3178 {
3179 return true;
3180 }
3181 }
3182 return false;
3183}
3184
Geoff Lang33f11fb2018-05-07 13:42:47 -04003185Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003186{
3187 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3188
jchen1082af6202018-06-22 10:59:52 +08003189 // Explicitly enable GL_KHR_parallel_shader_compile
3190 supportedExtensions.parallelShaderCompile = true;
3191
Geoff Langb0f917f2017-12-05 13:41:54 -05003192 if (getClientVersion() < ES_2_0)
3193 {
3194 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003195 supportedExtensions.pointSizeArray = true;
3196 supportedExtensions.textureCubeMap = true;
3197 supportedExtensions.pointSprite = true;
3198 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003199 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003200 }
3201
3202 if (getClientVersion() < ES_3_0)
3203 {
3204 // Disable ES3+ extensions
3205 supportedExtensions.colorBufferFloat = false;
3206 supportedExtensions.eglImageExternalEssl3 = false;
3207 supportedExtensions.textureNorm16 = false;
3208 supportedExtensions.multiview = false;
3209 supportedExtensions.maxViews = 1u;
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07003210 supportedExtensions.copyTexture3d = false;
Yizhou Jiang7818a852018-09-06 15:02:04 +08003211 supportedExtensions.textureMultisample = false;
Geoff Lang7198ebc2018-11-22 14:36:06 -05003212
3213 // Don't expose GL_EXT_texture_sRGB_decode without sRGB texture support
3214 if (!supportedExtensions.sRGB)
3215 {
3216 supportedExtensions.textureSRGBDecode = false;
3217 }
Geoff Langb0f917f2017-12-05 13:41:54 -05003218 }
3219
3220 if (getClientVersion() < ES_3_1)
3221 {
3222 // Disable ES3.1+ extensions
3223 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003224
3225 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3226 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003227 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003228 }
3229
3230 if (getClientVersion() > ES_2_0)
3231 {
3232 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3233 // supportedExtensions.sRGB = false;
3234 }
3235
3236 // Some extensions are always available because they are implemented in the GL layer.
3237 supportedExtensions.bindUniformLocation = true;
3238 supportedExtensions.vertexArrayObject = true;
3239 supportedExtensions.bindGeneratesResource = true;
3240 supportedExtensions.clientArrays = true;
3241 supportedExtensions.requestExtension = true;
Austin Eng7cf9cd22018-10-09 15:27:32 -07003242 supportedExtensions.multiDraw = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003243
3244 // Enable the no error extension if the context was created with the flag.
3245 supportedExtensions.noError = mSkipValidation;
3246
3247 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003248 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003249
3250 // Explicitly enable GL_KHR_debug
3251 supportedExtensions.debug = true;
3252 supportedExtensions.maxDebugMessageLength = 1024;
3253 supportedExtensions.maxDebugLoggedMessages = 1024;
3254 supportedExtensions.maxDebugGroupStackDepth = 1024;
3255 supportedExtensions.maxLabelLength = 1024;
3256
3257 // Explicitly enable GL_ANGLE_robust_client_memory
3258 supportedExtensions.robustClientMemory = true;
3259
3260 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003261 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003262
3263 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3264 // supports it.
3265 supportedExtensions.robustBufferAccessBehavior =
3266 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3267
3268 // Enable the cache control query unconditionally.
3269 supportedExtensions.programCacheControl = true;
3270
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003271 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003272 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003273 {
3274 // GL_ANGLE_explicit_context_gles1
3275 supportedExtensions.explicitContextGles1 = true;
3276 // GL_ANGLE_explicit_context
3277 supportedExtensions.explicitContext = true;
3278 }
3279
Geoff Lang79b91402018-10-04 15:11:30 -04003280 supportedExtensions.memorySize = true;
3281
Geoff Langb0f917f2017-12-05 13:41:54 -05003282 return supportedExtensions;
3283}
3284
Geoff Lang33f11fb2018-05-07 13:42:47 -04003285void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003286{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003287 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003288
Geoff Lang33f11fb2018-05-07 13:42:47 -04003289 mSupportedExtensions = generateSupportedExtensions();
3290 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003291
3292 mLimitations = mImplementation->getNativeLimitations();
3293
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003294 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3295 if (getClientVersion() < Version(2, 0))
3296 {
3297 mCaps.maxMultitextureUnits = 4;
3298 mCaps.maxClipPlanes = 6;
3299 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003300 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3301 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3302 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003303 mCaps.minSmoothPointSize = 1.0f;
3304 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003305 mCaps.minSmoothLineWidth = 1.0f;
3306 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003307 }
3308
Luc Ferronad2ae932018-06-11 15:31:17 -04003309 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003310 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003311
Luc Ferronad2ae932018-06-11 15:31:17 -04003312 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3313
Jamie Madill0f80ed82017-09-19 00:24:56 -04003314 if (getClientVersion() < ES_3_1)
3315 {
3316 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3317 }
3318 else
3319 {
3320 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3321 }
Geoff Lang301d1612014-07-09 10:34:37 -04003322
Jiawei Shao54aafe52018-04-27 14:54:57 +08003323 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3324 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003325 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3326
Jamie Madill0f80ed82017-09-19 00:24:56 -04003327 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3328 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3329
3330 // Limit textures as well, so we can use fast bitsets with texture bindings.
3331 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003332 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3333 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3334 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3335 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003336
Jamie Madille3e680c2018-12-03 17:49:08 -05003337 LimitCap(&mCaps.maxImageUnits, IMPLEMENTATION_MAX_IMAGE_UNITS);
3338
Jiawei Shaodb342272017-09-27 10:21:45 +08003339 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3340
Geoff Langc287ea62016-09-16 14:46:51 -04003341 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003342 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003343 for (const auto &extensionInfo : GetExtensionInfoMap())
3344 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003345 // If the user has requested that extensions start disabled and they are requestable,
3346 // disable them.
3347 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003348 {
3349 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3350 }
3351 }
3352
3353 // Generate texture caps
3354 updateCaps();
3355}
3356
3357void Context::updateCaps()
3358{
Geoff Lang900013c2014-07-07 11:32:19 -04003359 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003360 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003361
Jamie Madill7b62cf92017-11-02 15:20:49 -04003362 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003363 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003364 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003365 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003366
Geoff Lang0d8b7242015-09-09 14:56:53 -04003367 // Update the format caps based on the client version and extensions.
3368 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3369 // ES3.
3370 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003371 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003372 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003373 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003374 formatCaps.textureAttachment =
3375 formatCaps.textureAttachment &&
3376 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3377 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3378 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003379
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003380 // OpenGL ES does not support multisampling with non-rendererable formats
3381 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003382 if (!formatCaps.renderbuffer ||
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003383 (getClientVersion() < ES_3_1 && !mSupportedExtensions.textureMultisample &&
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003384 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003385 {
Geoff Langd87878e2014-09-19 15:42:59 -04003386 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003387 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003388 else
3389 {
3390 // We may have limited the max samples for some required renderbuffer formats due to
3391 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3392 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3393
3394 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3395 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3396 // exception of signed and unsigned integer formats."
3397 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3398 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3399 {
3400 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3401 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3402 }
3403
3404 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003405 if (getClientVersion() >= ES_3_1 || mSupportedExtensions.textureMultisample)
Olli Etuaho50c562d2017-06-06 14:43:30 +03003406 {
3407 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3408 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3409 // the exception that the signed and unsigned integer formats are required only to
3410 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3411 // multisamples, which must be at least one."
3412 if (formatInfo.componentType == GL_INT ||
3413 formatInfo.componentType == GL_UNSIGNED_INT)
3414 {
3415 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3416 }
3417
3418 // GLES 3.1 section 19.3.1.
3419 if (formatCaps.texturable)
3420 {
3421 if (formatInfo.depthBits > 0)
3422 {
3423 mCaps.maxDepthTextureSamples =
3424 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3425 }
3426 else if (formatInfo.redBits > 0)
3427 {
3428 mCaps.maxColorTextureSamples =
3429 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3430 }
3431 }
3432 }
3433 }
Geoff Langd87878e2014-09-19 15:42:59 -04003434
3435 if (formatCaps.texturable && formatInfo.compressed)
3436 {
Geoff Langca271392017-04-05 12:30:00 -04003437 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003438 }
3439
Geoff Langca271392017-04-05 12:30:00 -04003440 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003441 }
Jamie Madill32447362017-06-28 14:53:52 -04003442
3443 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003444 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003445 {
3446 mMemoryProgramCache = nullptr;
3447 }
Corentin Walleze4477002017-12-01 14:39:58 -05003448
3449 // Compute which buffer types are allowed
3450 mValidBufferBindings.reset();
3451 mValidBufferBindings.set(BufferBinding::ElementArray);
3452 mValidBufferBindings.set(BufferBinding::Array);
3453
3454 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3455 {
3456 mValidBufferBindings.set(BufferBinding::PixelPack);
3457 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3458 }
3459
3460 if (getClientVersion() >= ES_3_0)
3461 {
3462 mValidBufferBindings.set(BufferBinding::CopyRead);
3463 mValidBufferBindings.set(BufferBinding::CopyWrite);
3464 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3465 mValidBufferBindings.set(BufferBinding::Uniform);
3466 }
3467
3468 if (getClientVersion() >= ES_3_1)
3469 {
3470 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3471 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3472 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3473 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3474 }
jchen107ae70d82018-07-06 13:47:01 +08003475
3476 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Jamie Madillac66f982018-10-09 18:30:01 -04003477
Jamie Madillef9fcd92018-11-28 14:03:59 -05003478 // Reinitialize some dirty bits that depend on extensions.
Jamie Madill132d15c2018-11-30 15:25:38 -05003479 bool robustInit = mGLState.isRobustResourceInitEnabled();
3480 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3481 mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3482 mDrawDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
3483 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3484 mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3485 mComputeDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
Jamie Madillef9fcd92018-11-28 14:03:59 -05003486
Jamie Madillac66f982018-10-09 18:30:01 -04003487 // Reinitialize state cache after extension changes.
3488 mStateCache.initialize(this);
Geoff Lang493daf52014-07-03 13:38:44 -04003489}
3490
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003491void Context::initWorkarounds()
3492{
Jamie Madill761b02c2017-06-23 16:27:06 -04003493 // Apply back-end workarounds.
3494 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3495
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003496 // Lose the context upon out of memory error if the application is
3497 // expecting to watch for those events.
3498 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
Jamie Madilld4f07762018-10-19 19:24:07 -04003499
3500 if (mWorkarounds.syncFramebufferBindingsOnTexImage)
3501 {
3502 // Update the Framebuffer bindings on TexImage to work around an Intel bug.
3503 mTexImageDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
3504 mTexImageDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
3505 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003506}
3507
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003508// Return true if the draw is a no-op, else return false.
3509// A no-op draw occurs if the count of vertices is less than the minimum required to
3510// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3511bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3512{
3513 return count < kMinimumPrimitiveCounts[mode];
3514}
3515
3516bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3517{
3518 return (instanceCount == 0) || noopDraw(mode, count);
3519}
3520
Jamie Madill132d15c2018-11-30 15:25:38 -05003521ANGLE_INLINE angle::Result Context::syncDirtyBits()
3522{
3523 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3524 ANGLE_TRY(mImplementation->syncState(this, dirtyBits, mAllDirtyBits));
3525 mGLState.clearDirtyBits();
Jamie Madill7c985f52018-11-29 18:16:17 -05003526 return angle::Result::Continue;
Jamie Madill132d15c2018-11-30 15:25:38 -05003527}
3528
3529ANGLE_INLINE angle::Result Context::syncDirtyBits(const State::DirtyBits &bitMask)
3530{
3531 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
3532 ANGLE_TRY(mImplementation->syncState(this, dirtyBits, bitMask));
3533 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill7c985f52018-11-29 18:16:17 -05003534 return angle::Result::Continue;
Jamie Madill132d15c2018-11-30 15:25:38 -05003535}
3536
3537ANGLE_INLINE angle::Result Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
3538{
3539 return mGLState.syncDirtyObjects(this, objectMask);
3540}
3541
3542ANGLE_INLINE angle::Result Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003543{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003544 if (mGLES1Renderer)
3545 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003546 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003547 }
3548
Geoff Lang9bf86f02018-07-26 11:46:34 -04003549 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madill132d15c2018-11-30 15:25:38 -05003550 ASSERT(!isRobustResourceInitEnabled() ||
3551 !mGLState.getDrawFramebuffer()->hasResourceThatNeedsInit());
3552 return syncDirtyBits();
Geoff Langd4fff502017-09-22 11:28:28 -04003553}
3554
Jamie Madill526392d2018-11-16 09:35:14 -05003555angle::Result Context::prepareForClear(GLbitfield mask)
Geoff Langd4fff502017-09-22 11:28:28 -04003556{
Geoff Langa8cb2872018-03-09 16:09:40 -05003557 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003558 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003559 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003560 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003561}
3562
Jamie Madill526392d2018-11-16 09:35:14 -05003563angle::Result Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
Geoff Langd4fff502017-09-22 11:28:28 -04003564{
Geoff Langa8cb2872018-03-09 16:09:40 -05003565 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003566 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3567 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003568 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003569 return angle::Result::Continue;
Jamie Madill05b35b22017-10-03 09:01:44 -04003570}
3571
Jamie Madill132d15c2018-11-30 15:25:38 -05003572ANGLE_INLINE angle::Result Context::prepareForDispatch()
3573{
3574 ANGLE_TRY(syncDirtyObjects(mComputeDirtyObjects));
3575 return syncDirtyBits(mComputeDirtyBits);
3576}
3577
Jamie Madill526392d2018-11-16 09:35:14 -05003578angle::Result Context::syncState(const State::DirtyBits &bitMask,
3579 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003580{
Geoff Langa8cb2872018-03-09 16:09:40 -05003581 ANGLE_TRY(syncDirtyObjects(objectMask));
3582 ANGLE_TRY(syncDirtyBits(bitMask));
Jamie Madill7c985f52018-11-29 18:16:17 -05003583 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003584}
3585
Jamie Madillc29968b2016-01-20 11:17:23 -05003586void Context::blitFramebuffer(GLint srcX0,
3587 GLint srcY0,
3588 GLint srcX1,
3589 GLint srcY1,
3590 GLint dstX0,
3591 GLint dstY0,
3592 GLint dstX1,
3593 GLint dstY1,
3594 GLbitfield mask,
3595 GLenum filter)
3596{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003597 if (mask == 0)
3598 {
3599 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3600 // buffers are copied.
3601 return;
3602 }
3603
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003604 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003605 ASSERT(drawFramebuffer);
3606
3607 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3608 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3609
Jamie Madillbc918e72018-03-08 09:47:21 -05003610 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003611
Jamie Madill4f6592f2018-11-27 16:37:45 -05003612 ANGLE_CONTEXT_TRY(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003613}
Jamie Madillc29968b2016-01-20 11:17:23 -05003614
3615void Context::clear(GLbitfield mask)
3616{
Geoff Langd4fff502017-09-22 11:28:28 -04003617 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3618 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003619}
3620
3621void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3622{
Olli Etuaho78df3362018-10-05 16:43:27 +03003623 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3624 const FramebufferAttachment *attachment = nullptr;
3625 if (buffer == GL_DEPTH)
3626 {
3627 attachment = framebufferObject->getDepthbuffer();
3628 }
3629 if (buffer == GL_COLOR &&
3630 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3631 {
3632 attachment = framebufferObject->getColorbuffer(drawbuffer);
3633 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003634 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3635 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003636 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003637 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003638 return;
3639 }
Geoff Langd4fff502017-09-22 11:28:28 -04003640 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003641 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003642}
3643
3644void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3645{
Olli Etuaho78df3362018-10-05 16:43:27 +03003646 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3647 const FramebufferAttachment *attachment = nullptr;
3648 if (buffer == GL_COLOR &&
3649 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3650 {
3651 attachment = framebufferObject->getColorbuffer(drawbuffer);
3652 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003653 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3654 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003655 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003656 {
3657 return;
3658 }
Geoff Langd4fff502017-09-22 11:28:28 -04003659 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003660 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003661}
3662
3663void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3664{
Olli Etuaho78df3362018-10-05 16:43:27 +03003665 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
3666 const FramebufferAttachment *attachment = nullptr;
3667 if (buffer == GL_STENCIL)
3668 {
3669 attachment = framebufferObject->getStencilbuffer();
3670 }
3671 if (buffer == GL_COLOR &&
3672 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3673 {
3674 attachment = framebufferObject->getColorbuffer(drawbuffer);
3675 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003676 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3677 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003678 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003679 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003680 return;
3681 }
Geoff Langd4fff502017-09-22 11:28:28 -04003682 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003683 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003684}
3685
3686void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3687{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003688 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003689 ASSERT(framebufferObject);
3690
3691 // If a buffer is not present, the clear has no effect
3692 if (framebufferObject->getDepthbuffer() == nullptr &&
3693 framebufferObject->getStencilbuffer() == nullptr)
3694 {
3695 return;
3696 }
3697
Geoff Langd4fff502017-09-22 11:28:28 -04003698 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3699 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003700}
3701
3702void Context::readPixels(GLint x,
3703 GLint y,
3704 GLsizei width,
3705 GLsizei height,
3706 GLenum format,
3707 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003708 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003709{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003710 if (width == 0 || height == 0)
3711 {
3712 return;
3713 }
3714
Jamie Madillbc918e72018-03-08 09:47:21 -05003715 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003716
Jamie Madillb6664922017-07-25 12:55:04 -04003717 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3718 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003719
3720 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003721 ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003722}
3723
Brandon Jones59770802018-04-02 13:18:42 -07003724void Context::readPixelsRobust(GLint x,
3725 GLint y,
3726 GLsizei width,
3727 GLsizei height,
3728 GLenum format,
3729 GLenum type,
3730 GLsizei bufSize,
3731 GLsizei *length,
3732 GLsizei *columns,
3733 GLsizei *rows,
3734 void *pixels)
3735{
3736 readPixels(x, y, width, height, format, type, pixels);
3737}
3738
3739void Context::readnPixelsRobust(GLint x,
3740 GLint y,
3741 GLsizei width,
3742 GLsizei height,
3743 GLenum format,
3744 GLenum type,
3745 GLsizei bufSize,
3746 GLsizei *length,
3747 GLsizei *columns,
3748 GLsizei *rows,
3749 void *data)
3750{
3751 readPixels(x, y, width, height, format, type, data);
3752}
3753
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003754void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003755 GLint level,
3756 GLenum internalformat,
3757 GLint x,
3758 GLint y,
3759 GLsizei width,
3760 GLsizei height,
3761 GLint border)
3762{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003763 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003764 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003765
Jamie Madillc29968b2016-01-20 11:17:23 -05003766 Rectangle sourceArea(x, y, width, height);
3767
Jamie Madill05b35b22017-10-03 09:01:44 -04003768 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003769 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003770 ANGLE_CONTEXT_TRY(
3771 texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003772}
3773
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003774void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003775 GLint level,
3776 GLint xoffset,
3777 GLint yoffset,
3778 GLint x,
3779 GLint y,
3780 GLsizei width,
3781 GLsizei height)
3782{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003783 if (width == 0 || height == 0)
3784 {
3785 return;
3786 }
3787
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003788 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003789 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003790
Jamie Madillc29968b2016-01-20 11:17:23 -05003791 Offset destOffset(xoffset, yoffset, 0);
3792 Rectangle sourceArea(x, y, width, height);
3793
Jamie Madill05b35b22017-10-03 09:01:44 -04003794 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003795 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003796 ANGLE_CONTEXT_TRY(
3797 texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003798}
3799
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003800void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003801 GLint level,
3802 GLint xoffset,
3803 GLint yoffset,
3804 GLint zoffset,
3805 GLint x,
3806 GLint y,
3807 GLsizei width,
3808 GLsizei height)
3809{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003810 if (width == 0 || height == 0)
3811 {
3812 return;
3813 }
3814
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003815 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003816 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003817
Jamie Madillc29968b2016-01-20 11:17:23 -05003818 Offset destOffset(xoffset, yoffset, zoffset);
3819 Rectangle sourceArea(x, y, width, height);
3820
Jamie Madill05b35b22017-10-03 09:01:44 -04003821 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3822 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003823 ANGLE_CONTEXT_TRY(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level,
3824 destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003825}
3826
3827void Context::framebufferTexture2D(GLenum target,
3828 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003829 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003830 GLuint texture,
3831 GLint level)
3832{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003833 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003834 ASSERT(framebuffer);
3835
3836 if (texture != 0)
3837 {
3838 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003839 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003840 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003841 }
3842 else
3843 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003844 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003845 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003846
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003847 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003848}
3849
3850void Context::framebufferRenderbuffer(GLenum target,
3851 GLenum attachment,
3852 GLenum renderbuffertarget,
3853 GLuint renderbuffer)
3854{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003855 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003856 ASSERT(framebuffer);
3857
3858 if (renderbuffer != 0)
3859 {
3860 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003861
Jamie Madillcc129372018-04-12 09:13:18 -04003862 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003863 renderbufferObject);
3864 }
3865 else
3866 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003867 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003868 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003869
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003870 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003871}
3872
3873void Context::framebufferTextureLayer(GLenum target,
3874 GLenum attachment,
3875 GLuint texture,
3876 GLint level,
3877 GLint layer)
3878{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003879 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003880 ASSERT(framebuffer);
3881
3882 if (texture != 0)
3883 {
3884 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003885 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003886 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003887 }
3888 else
3889 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003890 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003891 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003892
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003893 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003894}
3895
Brandon Jones59770802018-04-02 13:18:42 -07003896void Context::framebufferTextureMultiviewLayered(GLenum target,
3897 GLenum attachment,
3898 GLuint texture,
3899 GLint level,
3900 GLint baseViewIndex,
3901 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003902{
Martin Radev82ef7742017-08-08 17:44:58 +03003903 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3904 ASSERT(framebuffer);
3905
3906 if (texture != 0)
3907 {
3908 Texture *textureObj = getTexture(texture);
3909
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003910 ImageIndex index;
3911 if (textureObj->getType() == TextureType::_2DArray)
3912 {
3913 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3914 }
3915 else
3916 {
3917 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3918 ASSERT(level == 0);
3919 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3920 }
Martin Radev82ef7742017-08-08 17:44:58 +03003921 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3922 numViews, baseViewIndex);
3923 }
3924 else
3925 {
3926 framebuffer->resetAttachment(this, attachment);
3927 }
3928
3929 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003930}
3931
Brandon Jones59770802018-04-02 13:18:42 -07003932void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3933 GLenum attachment,
3934 GLuint texture,
3935 GLint level,
3936 GLsizei numViews,
3937 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003938{
Martin Radev5dae57b2017-07-14 16:15:55 +03003939 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3940 ASSERT(framebuffer);
3941
3942 if (texture != 0)
3943 {
3944 Texture *textureObj = getTexture(texture);
3945
3946 ImageIndex index = ImageIndex::Make2D(level);
3947 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3948 textureObj, numViews, viewportOffsets);
3949 }
3950 else
3951 {
3952 framebuffer->resetAttachment(this, attachment);
3953 }
3954
3955 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003956}
3957
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003958void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3959{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003960 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3961 ASSERT(framebuffer);
3962
3963 if (texture != 0)
3964 {
3965 Texture *textureObj = getTexture(texture);
3966
3967 ImageIndex index = ImageIndex::MakeFromType(
3968 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3969 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3970 }
3971 else
3972 {
3973 framebuffer->resetAttachment(this, attachment);
3974 }
3975
3976 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003977}
3978
Jamie Madillc29968b2016-01-20 11:17:23 -05003979void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3980{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003981 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003982 ASSERT(framebuffer);
3983 framebuffer->setDrawBuffers(n, bufs);
Jamie Madillef9fcd92018-11-28 14:03:59 -05003984 mGLState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04003985 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003986}
3987
3988void Context::readBuffer(GLenum mode)
3989{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003990 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003991 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003992 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003993}
3994
3995void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3996{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003997 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003998 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003999
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004000 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05004001 ASSERT(framebuffer);
4002
4003 // The specification isn't clear what should be done when the framebuffer isn't complete.
4004 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4f6592f2018-11-27 16:37:45 -05004005 ANGLE_CONTEXT_TRY(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05004006}
4007
4008void Context::invalidateFramebuffer(GLenum target,
4009 GLsizei numAttachments,
4010 const GLenum *attachments)
4011{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004012 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05004013 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004014
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004015 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05004016 ASSERT(framebuffer);
4017
Jamie Madill427064d2018-04-13 16:20:34 -04004018 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05004019 {
Jamie Madill437fa652016-05-03 15:13:24 -04004020 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05004021 }
Jamie Madill437fa652016-05-03 15:13:24 -04004022
Jamie Madill4f6592f2018-11-27 16:37:45 -05004023 ANGLE_CONTEXT_TRY(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05004024}
4025
4026void Context::invalidateSubFramebuffer(GLenum target,
4027 GLsizei numAttachments,
4028 const GLenum *attachments,
4029 GLint x,
4030 GLint y,
4031 GLsizei width,
4032 GLsizei height)
4033{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004034 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05004035 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05004036
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004037 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05004038 ASSERT(framebuffer);
4039
Jamie Madill427064d2018-04-13 16:20:34 -04004040 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05004041 {
Jamie Madill437fa652016-05-03 15:13:24 -04004042 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05004043 }
Jamie Madill437fa652016-05-03 15:13:24 -04004044
4045 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004046 ANGLE_CONTEXT_TRY(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05004047}
4048
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004049void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004050 GLint level,
4051 GLint internalformat,
4052 GLsizei width,
4053 GLsizei height,
4054 GLint border,
4055 GLenum format,
4056 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004057 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004058{
Jamie Madillbc918e72018-03-08 09:47:21 -05004059 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004060
4061 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004062 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004063 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(), target, level,
4064 internalformat, size, format, type,
4065 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004066}
4067
Brandon Jones59770802018-04-02 13:18:42 -07004068void Context::texImage2DRobust(TextureTarget target,
4069 GLint level,
4070 GLint internalformat,
4071 GLsizei width,
4072 GLsizei height,
4073 GLint border,
4074 GLenum format,
4075 GLenum type,
4076 GLsizei bufSize,
4077 const void *pixels)
4078{
4079 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
4080}
4081
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004082void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004083 GLint level,
4084 GLint internalformat,
4085 GLsizei width,
4086 GLsizei height,
4087 GLsizei depth,
4088 GLint border,
4089 GLenum format,
4090 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004091 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004092{
Jamie Madillbc918e72018-03-08 09:47:21 -05004093 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004094
4095 Extents size(width, height, depth);
4096 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004097 ANGLE_CONTEXT_TRY(texture->setImage(this, mGLState.getUnpackState(),
4098 NonCubeTextureTypeToTarget(target), level, internalformat,
4099 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004100}
4101
Brandon Jones59770802018-04-02 13:18:42 -07004102void Context::texImage3DRobust(TextureType target,
4103 GLint level,
4104 GLint internalformat,
4105 GLsizei width,
4106 GLsizei height,
4107 GLsizei depth,
4108 GLint border,
4109 GLenum format,
4110 GLenum type,
4111 GLsizei bufSize,
4112 const void *pixels)
4113{
4114 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4115}
4116
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004117void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004118 GLint level,
4119 GLint xoffset,
4120 GLint yoffset,
4121 GLsizei width,
4122 GLsizei height,
4123 GLenum format,
4124 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004125 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004126{
4127 // Zero sized uploads are valid but no-ops
4128 if (width == 0 || height == 0)
4129 {
4130 return;
4131 }
4132
Jamie Madillbc918e72018-03-08 09:47:21 -05004133 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004134
4135 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004136 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004137
4138 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4139
Jamie Madill4f6592f2018-11-27 16:37:45 -05004140 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target,
4141 level, area, format, type,
4142 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004143}
4144
Brandon Jones59770802018-04-02 13:18:42 -07004145void Context::texSubImage2DRobust(TextureTarget target,
4146 GLint level,
4147 GLint xoffset,
4148 GLint yoffset,
4149 GLsizei width,
4150 GLsizei height,
4151 GLenum format,
4152 GLenum type,
4153 GLsizei bufSize,
4154 const void *pixels)
4155{
4156 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4157}
4158
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004159void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004160 GLint level,
4161 GLint xoffset,
4162 GLint yoffset,
4163 GLint zoffset,
4164 GLsizei width,
4165 GLsizei height,
4166 GLsizei depth,
4167 GLenum format,
4168 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004169 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004170{
4171 // Zero sized uploads are valid but no-ops
4172 if (width == 0 || height == 0 || depth == 0)
4173 {
4174 return;
4175 }
4176
Jamie Madillbc918e72018-03-08 09:47:21 -05004177 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004178
4179 Box area(xoffset, yoffset, zoffset, width, height, depth);
4180 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004181
4182 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4183
Jamie Madill4f6592f2018-11-27 16:37:45 -05004184 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
4185 NonCubeTextureTypeToTarget(target), level, area, format,
4186 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004187}
4188
Brandon Jones59770802018-04-02 13:18:42 -07004189void Context::texSubImage3DRobust(TextureType target,
4190 GLint level,
4191 GLint xoffset,
4192 GLint yoffset,
4193 GLint zoffset,
4194 GLsizei width,
4195 GLsizei height,
4196 GLsizei depth,
4197 GLenum format,
4198 GLenum type,
4199 GLsizei bufSize,
4200 const void *pixels)
4201{
4202 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4203 pixels);
4204}
4205
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004206void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004207 GLint level,
4208 GLenum internalformat,
4209 GLsizei width,
4210 GLsizei height,
4211 GLint border,
4212 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004213 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004214{
Jamie Madillbc918e72018-03-08 09:47:21 -05004215 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004216
4217 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004218 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004219 ANGLE_CONTEXT_TRY(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4220 internalformat, size, imageSize,
4221 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004222}
4223
Brandon Jones59770802018-04-02 13:18:42 -07004224void Context::compressedTexImage2DRobust(TextureTarget target,
4225 GLint level,
4226 GLenum internalformat,
4227 GLsizei width,
4228 GLsizei height,
4229 GLint border,
4230 GLsizei imageSize,
4231 GLsizei dataSize,
4232 const GLvoid *data)
4233{
4234 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4235}
4236
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004237void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004238 GLint level,
4239 GLenum internalformat,
4240 GLsizei width,
4241 GLsizei height,
4242 GLsizei depth,
4243 GLint border,
4244 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004245 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004246{
Jamie Madillbc918e72018-03-08 09:47:21 -05004247 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004248
4249 Extents size(width, height, depth);
4250 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004251 ANGLE_CONTEXT_TRY(texture->setCompressedImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004252 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004253 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004254}
4255
Brandon Jones59770802018-04-02 13:18:42 -07004256void Context::compressedTexImage3DRobust(TextureType target,
4257 GLint level,
4258 GLenum internalformat,
4259 GLsizei width,
4260 GLsizei height,
4261 GLsizei depth,
4262 GLint border,
4263 GLsizei imageSize,
4264 GLsizei dataSize,
4265 const GLvoid *data)
4266{
4267 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4268 data);
4269}
4270
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004271void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004272 GLint level,
4273 GLint xoffset,
4274 GLint yoffset,
4275 GLsizei width,
4276 GLsizei height,
4277 GLenum format,
4278 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004279 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004280{
Jamie Madillbc918e72018-03-08 09:47:21 -05004281 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004282
4283 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004284 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05004285 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level,
4286 area, format, imageSize,
4287 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004288}
4289
Brandon Jones59770802018-04-02 13:18:42 -07004290void Context::compressedTexSubImage2DRobust(TextureTarget target,
4291 GLint level,
4292 GLint xoffset,
4293 GLint yoffset,
4294 GLsizei width,
4295 GLsizei height,
4296 GLenum format,
4297 GLsizei imageSize,
4298 GLsizei dataSize,
4299 const GLvoid *data)
4300{
4301 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4302 data);
4303}
4304
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004305void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004306 GLint level,
4307 GLint xoffset,
4308 GLint yoffset,
4309 GLint zoffset,
4310 GLsizei width,
4311 GLsizei height,
4312 GLsizei depth,
4313 GLenum format,
4314 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004315 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004316{
4317 // Zero sized uploads are valid but no-ops
4318 if (width == 0 || height == 0)
4319 {
4320 return;
4321 }
4322
Jamie Madillbc918e72018-03-08 09:47:21 -05004323 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004324
4325 Box area(xoffset, yoffset, zoffset, width, height, depth);
4326 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004327 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(
Corentin Wallez99d492c2018-02-27 15:17:10 -05004328 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004329 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004330}
4331
Brandon Jones59770802018-04-02 13:18:42 -07004332void Context::compressedTexSubImage3DRobust(TextureType target,
4333 GLint level,
4334 GLint xoffset,
4335 GLint yoffset,
4336 GLint zoffset,
4337 GLsizei width,
4338 GLsizei height,
4339 GLsizei depth,
4340 GLenum format,
4341 GLsizei imageSize,
4342 GLsizei dataSize,
4343 const GLvoid *data)
4344{
4345 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4346 imageSize, data);
4347}
4348
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004349void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004350{
4351 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004352 ANGLE_CONTEXT_TRY(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004353}
4354
Jamie Madill007530e2017-12-28 14:27:04 -05004355void Context::copyTexture(GLuint sourceId,
4356 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004357 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004358 GLuint destId,
4359 GLint destLevel,
4360 GLint internalFormat,
4361 GLenum destType,
4362 GLboolean unpackFlipY,
4363 GLboolean unpackPremultiplyAlpha,
4364 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004365{
Jamie Madillbc918e72018-03-08 09:47:21 -05004366 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004367
4368 gl::Texture *sourceTexture = getTexture(sourceId);
4369 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004370 ANGLE_CONTEXT_TRY(
4371 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4372 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4373 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004374}
4375
Jamie Madill007530e2017-12-28 14:27:04 -05004376void Context::copySubTexture(GLuint sourceId,
4377 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004378 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004379 GLuint destId,
4380 GLint destLevel,
4381 GLint xoffset,
4382 GLint yoffset,
4383 GLint x,
4384 GLint y,
4385 GLsizei width,
4386 GLsizei height,
4387 GLboolean unpackFlipY,
4388 GLboolean unpackPremultiplyAlpha,
4389 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004390{
4391 // Zero sized copies are valid but no-ops
4392 if (width == 0 || height == 0)
4393 {
4394 return;
4395 }
4396
Jamie Madillbc918e72018-03-08 09:47:21 -05004397 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004398
4399 gl::Texture *sourceTexture = getTexture(sourceId);
4400 gl::Texture *destTexture = getTexture(destId);
4401 Offset offset(xoffset, yoffset, 0);
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004402 Box box(x, y, 0, width, height, 1);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004403 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4404 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4405 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4406 sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004407}
4408
4409void Context::copyTexture3D(GLuint sourceId,
4410 GLint sourceLevel,
4411 TextureTarget destTarget,
4412 GLuint destId,
4413 GLint destLevel,
4414 GLint internalFormat,
4415 GLenum destType,
4416 GLboolean unpackFlipY,
4417 GLboolean unpackPremultiplyAlpha,
4418 GLboolean unpackUnmultiplyAlpha)
4419{
4420 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4421
4422 Texture *sourceTexture = getTexture(sourceId);
4423 Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004424 ANGLE_CONTEXT_TRY(
4425 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4426 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4427 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004428}
4429
4430void Context::copySubTexture3D(GLuint sourceId,
4431 GLint sourceLevel,
4432 TextureTarget destTarget,
4433 GLuint destId,
4434 GLint destLevel,
4435 GLint xoffset,
4436 GLint yoffset,
4437 GLint zoffset,
4438 GLint x,
4439 GLint y,
4440 GLint z,
4441 GLsizei width,
4442 GLsizei height,
4443 GLsizei depth,
4444 GLboolean unpackFlipY,
4445 GLboolean unpackPremultiplyAlpha,
4446 GLboolean unpackUnmultiplyAlpha)
4447{
4448 // Zero sized copies are valid but no-ops
4449 if (width == 0 || height == 0 || depth == 0)
4450 {
4451 return;
4452 }
4453
4454 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4455
4456 Texture *sourceTexture = getTexture(sourceId);
4457 Texture *destTexture = getTexture(destId);
4458 Offset offset(xoffset, yoffset, zoffset);
4459 Box box(x, y, z, width, height, depth);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004460 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4461 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4462 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4463 sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004464}
4465
Jamie Madill007530e2017-12-28 14:27:04 -05004466void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004467{
Jamie Madillbc918e72018-03-08 09:47:21 -05004468 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004469
4470 gl::Texture *sourceTexture = getTexture(sourceId);
4471 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004472 ANGLE_CONTEXT_TRY(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004473}
4474
Corentin Wallez336129f2017-10-17 15:55:40 -04004475void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004476{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004477 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004478 ASSERT(buffer);
4479
Geoff Lang496c02d2016-10-20 11:38:11 -07004480 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004481}
4482
Brandon Jones59770802018-04-02 13:18:42 -07004483void Context::getBufferPointervRobust(BufferBinding target,
4484 GLenum pname,
4485 GLsizei bufSize,
4486 GLsizei *length,
4487 void **params)
4488{
4489 getBufferPointerv(target, pname, params);
4490}
4491
Corentin Wallez336129f2017-10-17 15:55:40 -04004492void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004493{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004494 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004495 ASSERT(buffer);
4496
Jamie Madill7c985f52018-11-29 18:16:17 -05004497 if (buffer->map(this, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004498 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004499 return nullptr;
4500 }
4501
4502 return buffer->getMapPointer();
4503}
4504
Corentin Wallez336129f2017-10-17 15:55:40 -04004505GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004506{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004507 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004508 ASSERT(buffer);
4509
4510 GLboolean result;
Jamie Madill7c985f52018-11-29 18:16:17 -05004511 if (buffer->unmap(this, &result) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004512 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004513 return GL_FALSE;
4514 }
4515
4516 return result;
4517}
4518
Corentin Wallez336129f2017-10-17 15:55:40 -04004519void *Context::mapBufferRange(BufferBinding target,
4520 GLintptr offset,
4521 GLsizeiptr length,
4522 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004523{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004524 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004525 ASSERT(buffer);
4526
Jamie Madill7c985f52018-11-29 18:16:17 -05004527 if (buffer->mapRange(this, offset, length, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004528 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004529 return nullptr;
4530 }
4531
4532 return buffer->getMapPointer();
4533}
4534
Corentin Wallez336129f2017-10-17 15:55:40 -04004535void Context::flushMappedBufferRange(BufferBinding /*target*/,
4536 GLintptr /*offset*/,
4537 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004538{
4539 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4540}
4541
Jamie Madill526392d2018-11-16 09:35:14 -05004542angle::Result Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004543{
Geoff Langa8cb2872018-03-09 16:09:40 -05004544 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004545}
4546
Jamie Madill526392d2018-11-16 09:35:14 -05004547angle::Result Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004548{
Geoff Langa8cb2872018-03-09 16:09:40 -05004549 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004550}
4551
Jamie Madill526392d2018-11-16 09:35:14 -05004552angle::Result Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004553{
Geoff Langa8cb2872018-03-09 16:09:40 -05004554 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004555}
4556
Jamie Madill526392d2018-11-16 09:35:14 -05004557angle::Result Context::syncStateForPathOperation()
Geoff Lang9bf86f02018-07-26 11:46:34 -04004558{
4559 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4560
4561 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4562 ANGLE_TRY(syncDirtyBits());
4563
Jamie Madill7c985f52018-11-29 18:16:17 -05004564 return angle::Result::Continue;
Geoff Lang9bf86f02018-07-26 11:46:34 -04004565}
4566
Jiajia Qin5451d532017-11-16 17:16:34 +08004567void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4568{
4569 UNIMPLEMENTED();
4570}
4571
Jamie Madillc20ab272016-06-09 07:20:46 -07004572void Context::activeTexture(GLenum texture)
4573{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004574 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004575}
4576
Jamie Madill876429b2017-04-20 15:46:24 -04004577void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004578{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004579 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004580}
4581
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004582void Context::blendEquation(GLenum mode)
4583{
4584 mGLState.setBlendEquation(mode, mode);
4585}
4586
Jamie Madillc20ab272016-06-09 07:20:46 -07004587void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4588{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004589 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004590}
4591
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004592void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4593{
4594 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4595}
4596
Jamie Madillc20ab272016-06-09 07:20:46 -07004597void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4598{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004599 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004600}
4601
Jamie Madill876429b2017-04-20 15:46:24 -04004602void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004603{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004604 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004605}
4606
Jamie Madill876429b2017-04-20 15:46:24 -04004607void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004608{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004609 mGLState.setDepthClearValue(clamp01(depth));
Jamie Madillc20ab272016-06-09 07:20:46 -07004610}
4611
4612void Context::clearStencil(GLint s)
4613{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004614 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004615}
4616
4617void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4618{
Geoff Lang92019432017-11-20 13:09:34 -05004619 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4620 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004621}
4622
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004623void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004624{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004625 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004626}
4627
4628void Context::depthFunc(GLenum func)
4629{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004630 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004631}
4632
4633void Context::depthMask(GLboolean flag)
4634{
Geoff Lang92019432017-11-20 13:09:34 -05004635 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004636}
4637
Jamie Madill876429b2017-04-20 15:46:24 -04004638void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004639{
Joonatan Saarhelo945dea32018-10-17 20:49:06 +03004640 mGLState.setDepthRange(clamp01(zNear), clamp01(zFar));
Jamie Madillc20ab272016-06-09 07:20:46 -07004641}
4642
4643void Context::disable(GLenum cap)
4644{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004645 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004646 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004647}
4648
4649void Context::disableVertexAttribArray(GLuint index)
4650{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004651 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004652 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004653}
4654
4655void Context::enable(GLenum cap)
4656{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004657 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004658 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004659}
4660
4661void Context::enableVertexAttribArray(GLuint index)
4662{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004663 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004664 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004665}
4666
4667void Context::frontFace(GLenum mode)
4668{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004669 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004670}
4671
4672void Context::hint(GLenum target, GLenum mode)
4673{
4674 switch (target)
4675 {
4676 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004677 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004678 break;
4679
4680 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004681 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004682 break;
4683
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004684 case GL_PERSPECTIVE_CORRECTION_HINT:
4685 case GL_POINT_SMOOTH_HINT:
4686 case GL_LINE_SMOOTH_HINT:
4687 case GL_FOG_HINT:
4688 mGLState.gles1().setHint(target, mode);
4689 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004690 default:
4691 UNREACHABLE();
4692 return;
4693 }
4694}
4695
4696void Context::lineWidth(GLfloat width)
4697{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004698 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004699}
4700
4701void Context::pixelStorei(GLenum pname, GLint param)
4702{
4703 switch (pname)
4704 {
4705 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004706 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004707 break;
4708
4709 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004710 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004711 break;
4712
4713 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004714 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004715 break;
4716
4717 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004718 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004719 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004720 break;
4721
4722 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004723 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004724 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004725 break;
4726
4727 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004728 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004729 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004730 break;
4731
4732 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004733 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004734 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004735 break;
4736
4737 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004738 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004739 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004740 break;
4741
4742 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004743 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004744 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004745 break;
4746
4747 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004748 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004749 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004750 break;
4751
4752 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004753 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004754 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004755 break;
4756
4757 default:
4758 UNREACHABLE();
4759 return;
4760 }
4761}
4762
4763void Context::polygonOffset(GLfloat factor, GLfloat units)
4764{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004765 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004766}
4767
Jamie Madill876429b2017-04-20 15:46:24 -04004768void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004769{
Geoff Lang92019432017-11-20 13:09:34 -05004770 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004771}
4772
Jiawei Shaodb342272017-09-27 10:21:45 +08004773void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4774{
4775 mGLState.setSampleMaskParams(maskNumber, mask);
4776}
4777
Jamie Madillc20ab272016-06-09 07:20:46 -07004778void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4779{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004780 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004781}
4782
4783void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4784{
4785 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4786 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004787 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004788 }
4789
4790 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4791 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004792 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004793 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004794
4795 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004796}
4797
4798void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4799{
4800 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4801 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004802 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004803 }
4804
4805 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4806 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004807 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004808 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004809
4810 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004811}
4812
4813void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4814{
4815 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4816 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004817 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004818 }
4819
4820 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4821 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004822 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004823 }
4824}
4825
4826void Context::vertexAttrib1f(GLuint index, GLfloat x)
4827{
4828 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004829 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004830 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004831}
4832
4833void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4834{
4835 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004836 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004837 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004838}
4839
4840void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4841{
4842 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004843 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004844 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004845}
4846
4847void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4848{
4849 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004850 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004851 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004852}
4853
4854void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4855{
4856 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004857 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004858 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004859}
4860
4861void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4862{
4863 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004864 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004865 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004866}
4867
4868void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4869{
4870 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004871 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004872 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004873}
4874
4875void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4876{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004877 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004878 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004879}
4880
4881void Context::vertexAttribPointer(GLuint index,
4882 GLint size,
4883 GLenum type,
4884 GLboolean normalized,
4885 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004886 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004887{
Corentin Wallez336129f2017-10-17 15:55:40 -04004888 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004889 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004890 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004891}
4892
Shao80957d92017-02-20 21:25:59 +08004893void Context::vertexAttribFormat(GLuint attribIndex,
4894 GLint size,
4895 GLenum type,
4896 GLboolean normalized,
4897 GLuint relativeOffset)
4898{
Geoff Lang92019432017-11-20 13:09:34 -05004899 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004900 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004901 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004902}
4903
4904void Context::vertexAttribIFormat(GLuint attribIndex,
4905 GLint size,
4906 GLenum type,
4907 GLuint relativeOffset)
4908{
4909 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004910 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004911}
4912
4913void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4914{
Shaodde78e82017-05-22 14:13:27 +08004915 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004916 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004917}
4918
Jiajia Qin5451d532017-11-16 17:16:34 +08004919void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004920{
4921 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004922 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004923}
4924
Jamie Madillc20ab272016-06-09 07:20:46 -07004925void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4926{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004927 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004928}
4929
4930void Context::vertexAttribIPointer(GLuint index,
4931 GLint size,
4932 GLenum type,
4933 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004934 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004935{
Corentin Wallez336129f2017-10-17 15:55:40 -04004936 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4937 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004938 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004939}
4940
4941void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4942{
4943 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004944 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004945 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004946}
4947
4948void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4949{
4950 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004951 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004952 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004953}
4954
4955void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4956{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004957 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004958 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004959}
4960
4961void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4962{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004963 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004964 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004965}
4966
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004967void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4968{
4969 const VertexAttribCurrentValueData &currentValues =
4970 getGLState().getVertexAttribCurrentValue(index);
4971 const VertexArray *vao = getGLState().getVertexArray();
4972 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4973 currentValues, pname, params);
4974}
4975
Brandon Jones59770802018-04-02 13:18:42 -07004976void Context::getVertexAttribivRobust(GLuint index,
4977 GLenum pname,
4978 GLsizei bufSize,
4979 GLsizei *length,
4980 GLint *params)
4981{
4982 getVertexAttribiv(index, pname, params);
4983}
4984
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004985void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4986{
4987 const VertexAttribCurrentValueData &currentValues =
4988 getGLState().getVertexAttribCurrentValue(index);
4989 const VertexArray *vao = getGLState().getVertexArray();
4990 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4991 currentValues, pname, params);
4992}
4993
Brandon Jones59770802018-04-02 13:18:42 -07004994void Context::getVertexAttribfvRobust(GLuint index,
4995 GLenum pname,
4996 GLsizei bufSize,
4997 GLsizei *length,
4998 GLfloat *params)
4999{
5000 getVertexAttribfv(index, pname, params);
5001}
5002
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005003void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
5004{
5005 const VertexAttribCurrentValueData &currentValues =
5006 getGLState().getVertexAttribCurrentValue(index);
5007 const VertexArray *vao = getGLState().getVertexArray();
5008 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
5009 currentValues, pname, params);
5010}
5011
Brandon Jones59770802018-04-02 13:18:42 -07005012void Context::getVertexAttribIivRobust(GLuint index,
5013 GLenum pname,
5014 GLsizei bufSize,
5015 GLsizei *length,
5016 GLint *params)
5017{
5018 getVertexAttribIiv(index, pname, params);
5019}
5020
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005021void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
5022{
5023 const VertexAttribCurrentValueData &currentValues =
5024 getGLState().getVertexAttribCurrentValue(index);
5025 const VertexArray *vao = getGLState().getVertexArray();
5026 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
5027 currentValues, pname, params);
5028}
5029
Brandon Jones59770802018-04-02 13:18:42 -07005030void Context::getVertexAttribIuivRobust(GLuint index,
5031 GLenum pname,
5032 GLsizei bufSize,
5033 GLsizei *length,
5034 GLuint *params)
5035{
5036 getVertexAttribIuiv(index, pname, params);
5037}
5038
Jamie Madill876429b2017-04-20 15:46:24 -04005039void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08005040{
5041 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
5042 QueryVertexAttribPointerv(attrib, pname, pointer);
5043}
5044
Brandon Jones59770802018-04-02 13:18:42 -07005045void Context::getVertexAttribPointervRobust(GLuint index,
5046 GLenum pname,
5047 GLsizei bufSize,
5048 GLsizei *length,
5049 void **pointer)
5050{
5051 getVertexAttribPointerv(index, pname, pointer);
5052}
5053
Jamie Madillc20ab272016-06-09 07:20:46 -07005054void Context::debugMessageControl(GLenum source,
5055 GLenum type,
5056 GLenum severity,
5057 GLsizei count,
5058 const GLuint *ids,
5059 GLboolean enabled)
5060{
5061 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005062 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05005063 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07005064}
5065
5066void Context::debugMessageInsert(GLenum source,
5067 GLenum type,
5068 GLuint id,
5069 GLenum severity,
5070 GLsizei length,
5071 const GLchar *buf)
5072{
5073 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005074 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07005075}
5076
5077void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
5078{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005079 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07005080}
5081
5082GLuint Context::getDebugMessageLog(GLuint count,
5083 GLsizei bufSize,
5084 GLenum *sources,
5085 GLenum *types,
5086 GLuint *ids,
5087 GLenum *severities,
5088 GLsizei *lengths,
5089 GLchar *messageLog)
5090{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005091 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
5092 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07005093}
5094
5095void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
5096{
5097 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005098 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05005099 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07005100}
5101
5102void Context::popDebugGroup()
5103{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07005104 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05005105 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07005106}
5107
Corentin Wallez336129f2017-10-17 15:55:40 -04005108void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04005109{
5110 Buffer *buffer = mGLState.getTargetBuffer(target);
5111 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005112 ANGLE_CONTEXT_TRY(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04005113}
5114
Corentin Wallez336129f2017-10-17 15:55:40 -04005115void Context::bufferSubData(BufferBinding target,
5116 GLintptr offset,
5117 GLsizeiptr size,
5118 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04005119{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06005120 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04005121 {
5122 return;
5123 }
5124
5125 Buffer *buffer = mGLState.getTargetBuffer(target);
5126 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005127 ANGLE_CONTEXT_TRY(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04005128}
5129
Jamie Madillef300b12016-10-07 15:12:09 -04005130void Context::attachShader(GLuint program, GLuint shader)
5131{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05005132 Program *programObject = mState.mShaderPrograms->getProgram(program);
5133 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04005134 ASSERT(programObject && shaderObject);
5135 programObject->attachShader(shaderObject);
5136}
5137
Kenneth Russellf2f6f652016-10-05 19:53:23 -07005138const Workarounds &Context::getWorkarounds() const
5139{
5140 return mWorkarounds;
5141}
5142
Corentin Wallez336129f2017-10-17 15:55:40 -04005143void Context::copyBufferSubData(BufferBinding readTarget,
5144 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005145 GLintptr readOffset,
5146 GLintptr writeOffset,
5147 GLsizeiptr size)
5148{
5149 // if size is zero, the copy is a successful no-op
5150 if (size == 0)
5151 {
5152 return;
5153 }
5154
5155 // TODO(jmadill): cache these.
5156 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
5157 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
5158
Jamie Madill4f6592f2018-11-27 16:37:45 -05005159 ANGLE_CONTEXT_TRY(
5160 writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005161}
5162
Jamie Madill01a80ee2016-11-07 12:06:18 -05005163void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5164{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005165 // Ideally we could share the program query with the validation layer if possible.
5166 Program *programObject = getProgramResolveLink(program);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005167 ASSERT(programObject);
5168 programObject->bindAttributeLocation(index, name);
5169}
5170
Corentin Wallez336129f2017-10-17 15:55:40 -04005171void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005172{
Corentin Wallez336129f2017-10-17 15:55:40 -04005173 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5174 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04005175 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005176}
5177
Corentin Wallez336129f2017-10-17 15:55:40 -04005178void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005179{
5180 bindBufferRange(target, index, buffer, 0, 0);
5181}
5182
Corentin Wallez336129f2017-10-17 15:55:40 -04005183void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005184 GLuint index,
5185 GLuint buffer,
5186 GLintptr offset,
5187 GLsizeiptr size)
5188{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005189 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5190 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
5191 if (target == BufferBinding::Uniform)
5192 {
Jamie Madill472ddc82018-10-18 18:41:56 -04005193 mUniformBufferObserverBindings[index].bind(object);
Jamie Madilld84b6732018-09-06 15:54:35 -04005194 mStateCache.onUniformBufferStateChange(this);
5195 }
5196 else
5197 {
5198 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005199 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005200}
5201
Jamie Madill01a80ee2016-11-07 12:06:18 -05005202void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5203{
5204 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5205 {
5206 bindReadFramebuffer(framebuffer);
5207 }
5208
5209 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5210 {
5211 bindDrawFramebuffer(framebuffer);
5212 }
5213}
5214
5215void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5216{
5217 ASSERT(target == GL_RENDERBUFFER);
5218 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005219 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005220 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005221}
5222
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005223void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005224 GLsizei samples,
5225 GLenum internalformat,
5226 GLsizei width,
5227 GLsizei height,
5228 GLboolean fixedsamplelocations)
5229{
5230 Extents size(width, height, 1);
5231 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005232 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5233 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005234}
5235
Olli Etuaho89664842018-08-24 14:45:36 +03005236void Context::texStorage3DMultisample(TextureType target,
5237 GLsizei samples,
5238 GLenum internalformat,
5239 GLsizei width,
5240 GLsizei height,
5241 GLsizei depth,
5242 GLboolean fixedsamplelocations)
5243{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005244 Extents size(width, height, depth);
5245 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005246 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5247 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005248}
5249
JiangYizhoubddc46b2016-12-09 09:50:51 +08005250void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5251{
JiangYizhou5b03f472017-01-09 10:22:53 +08005252 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5253 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005254 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005255 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005256
5257 switch (pname)
5258 {
5259 case GL_SAMPLE_POSITION:
Jamie Madill4f6592f2018-11-27 16:37:45 -05005260 ANGLE_CONTEXT_TRY(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005261 break;
5262 default:
5263 UNREACHABLE();
5264 }
5265}
5266
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005267void Context::getMultisamplefvRobust(GLenum pname,
5268 GLuint index,
5269 GLsizei bufSize,
5270 GLsizei *length,
5271 GLfloat *val)
5272{
5273 UNIMPLEMENTED();
5274}
5275
Jamie Madille8fb6402017-02-14 17:56:40 -05005276void Context::renderbufferStorage(GLenum target,
5277 GLenum internalformat,
5278 GLsizei width,
5279 GLsizei height)
5280{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005281 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5282 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5283
Jamie Madille8fb6402017-02-14 17:56:40 -05005284 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005285 ANGLE_CONTEXT_TRY(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005286}
5287
5288void Context::renderbufferStorageMultisample(GLenum target,
5289 GLsizei samples,
5290 GLenum internalformat,
5291 GLsizei width,
5292 GLsizei height)
5293{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005294 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5295 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005296
5297 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005298 ANGLE_CONTEXT_TRY(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005299 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005300}
5301
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005302void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5303{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005304 const Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005305 ANGLE_CONTEXT_TRY(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005306}
5307
JiangYizhoue18e6392017-02-20 10:32:23 +08005308void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5309{
5310 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5311 QueryFramebufferParameteriv(framebuffer, pname, params);
5312}
5313
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005314void Context::getFramebufferParameterivRobust(GLenum target,
5315 GLenum pname,
5316 GLsizei bufSize,
5317 GLsizei *length,
5318 GLint *params)
5319{
5320 UNIMPLEMENTED();
5321}
5322
Jiajia Qin5451d532017-11-16 17:16:34 +08005323void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005324{
5325 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005326 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005327}
5328
Jamie Madilldec86232018-07-11 09:01:18 -04005329bool Context::getScratchBuffer(size_t requstedSizeBytes,
5330 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005331{
Jamie Madilldec86232018-07-11 09:01:18 -04005332 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005333}
5334
Jamie Madilldec86232018-07-11 09:01:18 -04005335bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5336 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005337{
Jamie Madilldec86232018-07-11 09:01:18 -04005338 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005339}
5340
Xinghua Cao2b396592017-03-29 15:36:04 +08005341void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5342{
5343 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5344 {
5345 return;
5346 }
5347
Xinghua Cao10a4d432017-11-28 14:46:26 +08005348 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005349 ANGLE_CONTEXT_TRY(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005350}
5351
Jiajia Qin5451d532017-11-16 17:16:34 +08005352void Context::dispatchComputeIndirect(GLintptr indirect)
5353{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005354 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005355 ANGLE_CONTEXT_TRY(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005356}
5357
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005358void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005359 GLsizei levels,
5360 GLenum internalFormat,
5361 GLsizei width,
5362 GLsizei height)
5363{
5364 Extents size(width, height, 1);
5365 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005366 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005367}
5368
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005369void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005370 GLsizei levels,
5371 GLenum internalFormat,
5372 GLsizei width,
5373 GLsizei height,
5374 GLsizei depth)
5375{
5376 Extents size(width, height, depth);
5377 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005378 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005379}
5380
Jiajia Qin5451d532017-11-16 17:16:34 +08005381void Context::memoryBarrier(GLbitfield barriers)
5382{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005383 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005384}
5385
5386void Context::memoryBarrierByRegion(GLbitfield barriers)
5387{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005388 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005389}
5390
Austin Eng1bf18ce2018-10-19 15:34:02 -07005391void Context::multiDrawArrays(PrimitiveMode mode,
5392 const GLint *firsts,
5393 const GLsizei *counts,
5394 GLsizei drawcount)
5395{
5396 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5397 Program *programObject = mGLState.getLinkedProgram(this);
5398 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5399 if (hasDrawID)
5400 {
5401 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5402 {
5403 if (noopDraw(mode, counts[drawID]))
5404 {
5405 continue;
5406 }
5407 programObject->setDrawIDUniform(drawID);
5408 ANGLE_CONTEXT_TRY(
5409 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
5410 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5411 counts[drawID], 1);
5412 }
5413 }
5414 else
5415 {
5416 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5417 {
5418 if (noopDraw(mode, counts[drawID]))
5419 {
5420 continue;
5421 }
5422 ANGLE_CONTEXT_TRY(
5423 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
5424 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5425 counts[drawID], 1);
5426 }
5427 }
5428}
5429
5430void Context::multiDrawArraysInstanced(PrimitiveMode mode,
5431 const GLint *firsts,
5432 const GLsizei *counts,
5433 const GLsizei *instanceCounts,
5434 GLsizei drawcount)
5435{
5436 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5437 Program *programObject = mGLState.getLinkedProgram(this);
5438 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5439 if (hasDrawID)
5440 {
5441 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5442 {
5443 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5444 {
5445 continue;
5446 }
5447 programObject->setDrawIDUniform(drawID);
5448 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5449 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
5450 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5451 counts[drawID], instanceCounts[drawID]);
5452 }
5453 }
5454 else
5455 {
5456 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5457 {
5458 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5459 {
5460 continue;
5461 }
5462 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5463 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
5464 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(),
5465 counts[drawID], instanceCounts[drawID]);
5466 }
5467 }
5468}
5469
5470void Context::multiDrawElements(PrimitiveMode mode,
5471 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005472 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005473 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005474 GLsizei drawcount)
5475{
5476 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5477 Program *programObject = mGLState.getLinkedProgram(this);
5478 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5479 if (hasDrawID)
5480 {
5481 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5482 {
5483 if (noopDraw(mode, counts[drawID]))
5484 {
5485 continue;
5486 }
5487 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005488 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005489 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005490 }
5491 }
5492 else
5493 {
5494 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5495 {
5496 if (noopDraw(mode, counts[drawID]))
5497 {
5498 continue;
5499 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005500 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005501 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005502 }
5503 }
5504}
5505
5506void Context::multiDrawElementsInstanced(PrimitiveMode mode,
5507 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005508 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005509 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005510 const GLsizei *instanceCounts,
5511 GLsizei drawcount)
5512{
5513 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
5514 Program *programObject = mGLState.getLinkedProgram(this);
5515 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5516 if (hasDrawID)
5517 {
5518 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5519 {
5520 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5521 {
5522 continue;
5523 }
5524 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005525 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005526 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005527 }
5528 }
5529 else
5530 {
5531 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5532 {
5533 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5534 {
5535 continue;
5536 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005537 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005538 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005539 }
5540 }
5541}
5542
Jamie Madillc1d770e2017-04-13 17:31:24 -04005543GLenum Context::checkFramebufferStatus(GLenum target)
5544{
5545 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5546 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005547 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005548}
5549
5550void Context::compileShader(GLuint shader)
5551{
5552 Shader *shaderObject = GetValidShader(this, shader);
5553 if (!shaderObject)
5554 {
5555 return;
5556 }
5557 shaderObject->compile(this);
5558}
5559
5560void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5561{
5562 for (int i = 0; i < n; i++)
5563 {
5564 deleteBuffer(buffers[i]);
5565 }
5566}
5567
5568void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5569{
5570 for (int i = 0; i < n; i++)
5571 {
5572 if (framebuffers[i] != 0)
5573 {
5574 deleteFramebuffer(framebuffers[i]);
5575 }
5576 }
5577}
5578
5579void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5580{
5581 for (int i = 0; i < n; i++)
5582 {
5583 deleteRenderbuffer(renderbuffers[i]);
5584 }
5585}
5586
5587void Context::deleteTextures(GLsizei n, const GLuint *textures)
5588{
5589 for (int i = 0; i < n; i++)
5590 {
5591 if (textures[i] != 0)
5592 {
5593 deleteTexture(textures[i]);
5594 }
5595 }
5596}
5597
5598void Context::detachShader(GLuint program, GLuint shader)
5599{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005600 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005601 ASSERT(programObject);
5602
5603 Shader *shaderObject = getShader(shader);
5604 ASSERT(shaderObject);
5605
5606 programObject->detachShader(this, shaderObject);
5607}
5608
5609void Context::genBuffers(GLsizei n, GLuint *buffers)
5610{
5611 for (int i = 0; i < n; i++)
5612 {
5613 buffers[i] = createBuffer();
5614 }
5615}
5616
5617void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5618{
5619 for (int i = 0; i < n; i++)
5620 {
5621 framebuffers[i] = createFramebuffer();
5622 }
5623}
5624
5625void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5626{
5627 for (int i = 0; i < n; i++)
5628 {
5629 renderbuffers[i] = createRenderbuffer();
5630 }
5631}
5632
5633void Context::genTextures(GLsizei n, GLuint *textures)
5634{
5635 for (int i = 0; i < n; i++)
5636 {
5637 textures[i] = createTexture();
5638 }
5639}
5640
5641void Context::getActiveAttrib(GLuint program,
5642 GLuint index,
5643 GLsizei bufsize,
5644 GLsizei *length,
5645 GLint *size,
5646 GLenum *type,
5647 GLchar *name)
5648{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005649 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005650 ASSERT(programObject);
5651 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5652}
5653
5654void Context::getActiveUniform(GLuint program,
5655 GLuint index,
5656 GLsizei bufsize,
5657 GLsizei *length,
5658 GLint *size,
5659 GLenum *type,
5660 GLchar *name)
5661{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005662 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005663 ASSERT(programObject);
5664 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5665}
5666
5667void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5668{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005669 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005670 ASSERT(programObject);
5671 programObject->getAttachedShaders(maxcount, count, shaders);
5672}
5673
5674GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5675{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005676 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005677 ASSERT(programObject);
5678 return programObject->getAttributeLocation(name);
5679}
5680
5681void Context::getBooleanv(GLenum pname, GLboolean *params)
5682{
5683 GLenum nativeType;
5684 unsigned int numParams = 0;
5685 getQueryParameterInfo(pname, &nativeType, &numParams);
5686
5687 if (nativeType == GL_BOOL)
5688 {
5689 getBooleanvImpl(pname, params);
5690 }
5691 else
5692 {
5693 CastStateValues(this, nativeType, pname, numParams, params);
5694 }
5695}
5696
Brandon Jones59770802018-04-02 13:18:42 -07005697void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5698{
5699 getBooleanv(pname, params);
5700}
5701
Jamie Madillc1d770e2017-04-13 17:31:24 -04005702void Context::getFloatv(GLenum pname, GLfloat *params)
5703{
5704 GLenum nativeType;
5705 unsigned int numParams = 0;
5706 getQueryParameterInfo(pname, &nativeType, &numParams);
5707
5708 if (nativeType == GL_FLOAT)
5709 {
5710 getFloatvImpl(pname, params);
5711 }
5712 else
5713 {
5714 CastStateValues(this, nativeType, pname, numParams, params);
5715 }
5716}
5717
Brandon Jones59770802018-04-02 13:18:42 -07005718void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5719{
5720 getFloatv(pname, params);
5721}
5722
Jamie Madillc1d770e2017-04-13 17:31:24 -04005723void Context::getIntegerv(GLenum pname, GLint *params)
5724{
5725 GLenum nativeType;
5726 unsigned int numParams = 0;
5727 getQueryParameterInfo(pname, &nativeType, &numParams);
5728
5729 if (nativeType == GL_INT)
5730 {
5731 getIntegervImpl(pname, params);
5732 }
5733 else
5734 {
5735 CastStateValues(this, nativeType, pname, numParams, params);
5736 }
5737}
5738
Brandon Jones59770802018-04-02 13:18:42 -07005739void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5740{
5741 getIntegerv(pname, data);
5742}
5743
Jamie Madillc1d770e2017-04-13 17:31:24 -04005744void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5745{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005746 // Don't resolve link if checking the link completion status.
5747 Program *programObject = (pname == GL_COMPLETION_STATUS_KHR ? getProgramNoResolveLink(program)
5748 : getProgramResolveLink(program));
Jamie Madillc1d770e2017-04-13 17:31:24 -04005749 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005750 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005751}
5752
Brandon Jones59770802018-04-02 13:18:42 -07005753void Context::getProgramivRobust(GLuint program,
5754 GLenum pname,
5755 GLsizei bufSize,
5756 GLsizei *length,
5757 GLint *params)
5758{
5759 getProgramiv(program, pname, params);
5760}
5761
Jiajia Qin5451d532017-11-16 17:16:34 +08005762void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5763{
5764 UNIMPLEMENTED();
5765}
5766
Jamie Madillbe849e42017-05-02 15:49:00 -04005767void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005768{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005769 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005770 ASSERT(programObject);
5771 programObject->getInfoLog(bufsize, length, infolog);
5772}
5773
Jiajia Qin5451d532017-11-16 17:16:34 +08005774void Context::getProgramPipelineInfoLog(GLuint pipeline,
5775 GLsizei bufSize,
5776 GLsizei *length,
5777 GLchar *infoLog)
5778{
5779 UNIMPLEMENTED();
5780}
5781
Jamie Madillc1d770e2017-04-13 17:31:24 -04005782void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5783{
5784 Shader *shaderObject = getShader(shader);
5785 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005786 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005787}
5788
Brandon Jones59770802018-04-02 13:18:42 -07005789void Context::getShaderivRobust(GLuint shader,
5790 GLenum pname,
5791 GLsizei bufSize,
5792 GLsizei *length,
5793 GLint *params)
5794{
5795 getShaderiv(shader, pname, params);
5796}
5797
Jamie Madillc1d770e2017-04-13 17:31:24 -04005798void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5799{
5800 Shader *shaderObject = getShader(shader);
5801 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005802 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005803}
5804
5805void Context::getShaderPrecisionFormat(GLenum shadertype,
5806 GLenum precisiontype,
5807 GLint *range,
5808 GLint *precision)
5809{
5810 // TODO(jmadill): Compute shaders.
5811
5812 switch (shadertype)
5813 {
5814 case GL_VERTEX_SHADER:
5815 switch (precisiontype)
5816 {
5817 case GL_LOW_FLOAT:
5818 mCaps.vertexLowpFloat.get(range, precision);
5819 break;
5820 case GL_MEDIUM_FLOAT:
5821 mCaps.vertexMediumpFloat.get(range, precision);
5822 break;
5823 case GL_HIGH_FLOAT:
5824 mCaps.vertexHighpFloat.get(range, precision);
5825 break;
5826
5827 case GL_LOW_INT:
5828 mCaps.vertexLowpInt.get(range, precision);
5829 break;
5830 case GL_MEDIUM_INT:
5831 mCaps.vertexMediumpInt.get(range, precision);
5832 break;
5833 case GL_HIGH_INT:
5834 mCaps.vertexHighpInt.get(range, precision);
5835 break;
5836
5837 default:
5838 UNREACHABLE();
5839 return;
5840 }
5841 break;
5842
5843 case GL_FRAGMENT_SHADER:
5844 switch (precisiontype)
5845 {
5846 case GL_LOW_FLOAT:
5847 mCaps.fragmentLowpFloat.get(range, precision);
5848 break;
5849 case GL_MEDIUM_FLOAT:
5850 mCaps.fragmentMediumpFloat.get(range, precision);
5851 break;
5852 case GL_HIGH_FLOAT:
5853 mCaps.fragmentHighpFloat.get(range, precision);
5854 break;
5855
5856 case GL_LOW_INT:
5857 mCaps.fragmentLowpInt.get(range, precision);
5858 break;
5859 case GL_MEDIUM_INT:
5860 mCaps.fragmentMediumpInt.get(range, precision);
5861 break;
5862 case GL_HIGH_INT:
5863 mCaps.fragmentHighpInt.get(range, precision);
5864 break;
5865
5866 default:
5867 UNREACHABLE();
5868 return;
5869 }
5870 break;
5871
5872 default:
5873 UNREACHABLE();
5874 return;
5875 }
5876}
5877
5878void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5879{
5880 Shader *shaderObject = getShader(shader);
5881 ASSERT(shaderObject);
5882 shaderObject->getSource(bufsize, length, source);
5883}
5884
5885void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5886{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005887 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005888 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005889 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005890}
5891
Brandon Jones59770802018-04-02 13:18:42 -07005892void Context::getUniformfvRobust(GLuint program,
5893 GLint location,
5894 GLsizei bufSize,
5895 GLsizei *length,
5896 GLfloat *params)
5897{
5898 getUniformfv(program, location, params);
5899}
5900
Jamie Madillc1d770e2017-04-13 17:31:24 -04005901void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5902{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005903 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005904 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005905 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005906}
5907
Brandon Jones59770802018-04-02 13:18:42 -07005908void Context::getUniformivRobust(GLuint program,
5909 GLint location,
5910 GLsizei bufSize,
5911 GLsizei *length,
5912 GLint *params)
5913{
5914 getUniformiv(program, location, params);
5915}
5916
Jamie Madillc1d770e2017-04-13 17:31:24 -04005917GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5918{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005919 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005920 ASSERT(programObject);
5921 return programObject->getUniformLocation(name);
5922}
5923
5924GLboolean Context::isBuffer(GLuint buffer)
5925{
5926 if (buffer == 0)
5927 {
5928 return GL_FALSE;
5929 }
5930
5931 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5932}
5933
5934GLboolean Context::isEnabled(GLenum cap)
5935{
5936 return mGLState.getEnableFeature(cap);
5937}
5938
5939GLboolean Context::isFramebuffer(GLuint framebuffer)
5940{
5941 if (framebuffer == 0)
5942 {
5943 return GL_FALSE;
5944 }
5945
5946 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5947}
5948
5949GLboolean Context::isProgram(GLuint program)
5950{
5951 if (program == 0)
5952 {
5953 return GL_FALSE;
5954 }
5955
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005956 return (getProgramNoResolveLink(program) ? GL_TRUE : GL_FALSE);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005957}
5958
5959GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5960{
5961 if (renderbuffer == 0)
5962 {
5963 return GL_FALSE;
5964 }
5965
5966 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5967}
5968
5969GLboolean Context::isShader(GLuint shader)
5970{
5971 if (shader == 0)
5972 {
5973 return GL_FALSE;
5974 }
5975
5976 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5977}
5978
5979GLboolean Context::isTexture(GLuint texture)
5980{
5981 if (texture == 0)
5982 {
5983 return GL_FALSE;
5984 }
5985
5986 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5987}
5988
5989void Context::linkProgram(GLuint program)
5990{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005991 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005992 ASSERT(programObject);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005993 ANGLE_CONTEXT_TRY(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005994
5995 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5996 // don't need to worry that:
5997 // 1. Draw calls after link use the new executable code or the old one depending on the link
5998 // result.
5999 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
6000 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
6001 // ProgramD3D.
6002 if (programObject->isInUse())
6003 {
Jamie Madill785e8a02018-10-04 17:42:00 -04006004 programObject->resolveLink(this);
Jamie Madilldf836ff2018-10-01 10:36:24 -04006005 if (programObject->isLinked())
6006 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04006007 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006008 }
jchen107ae70d82018-07-06 13:47:01 +08006009 mStateCache.onProgramExecutableChange(this);
6010 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04006011}
6012
6013void Context::releaseShaderCompiler()
6014{
Jamie Madill4928b7c2017-06-20 12:57:39 -04006015 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006016}
6017
6018void Context::shaderBinary(GLsizei n,
6019 const GLuint *shaders,
6020 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04006021 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04006022 GLsizei length)
6023{
6024 // No binary shader formats are supported.
6025 UNIMPLEMENTED();
6026}
6027
Olli Etuaho0ca09752018-09-24 11:00:50 +03006028void Context::bindFragDataLocationIndexed(GLuint program,
6029 GLuint colorNumber,
6030 GLuint index,
6031 const char *name)
6032{
6033 Program *programObject = getProgramNoResolveLink(program);
6034 programObject->bindFragmentOutputLocation(colorNumber, name);
6035 programObject->bindFragmentOutputIndex(index, name);
6036}
6037
6038void Context::bindFragDataLocation(GLuint program, GLuint colorNumber, const char *name)
6039{
6040 bindFragDataLocationIndexed(program, colorNumber, 0u, name);
6041}
6042
6043int Context::getFragDataIndex(GLuint program, const char *name)
6044{
6045 Program *programObject = getProgramResolveLink(program);
6046 return programObject->getFragDataIndex(name);
6047}
6048
6049int Context::getProgramResourceLocationIndex(GLuint program,
6050 GLenum programInterface,
6051 const char *name)
6052{
6053 Program *programObject = getProgramResolveLink(program);
6054 ASSERT(programInterface == GL_PROGRAM_OUTPUT);
6055 return programObject->getFragDataIndex(name);
6056}
6057
Jamie Madillc1d770e2017-04-13 17:31:24 -04006058void Context::shaderSource(GLuint shader,
6059 GLsizei count,
6060 const GLchar *const *string,
6061 const GLint *length)
6062{
6063 Shader *shaderObject = getShader(shader);
6064 ASSERT(shaderObject);
6065 shaderObject->setSource(count, string, length);
6066}
6067
6068void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
6069{
6070 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
6071}
6072
6073void Context::stencilMask(GLuint mask)
6074{
6075 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
6076}
6077
6078void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
6079{
6080 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
6081}
6082
6083void Context::uniform1f(GLint location, GLfloat x)
6084{
6085 Program *program = mGLState.getProgram();
6086 program->setUniform1fv(location, 1, &x);
6087}
6088
6089void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
6090{
6091 Program *program = mGLState.getProgram();
6092 program->setUniform1fv(location, count, v);
6093}
6094
Jamie Madill7e4eff12018-08-08 15:49:26 -04006095void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006096{
Jamie Madille3e680c2018-12-03 17:49:08 -05006097 program->setUniform1iv(this, location, count, v);
6098}
6099
6100void Context::onSamplerUniformChange(size_t textureUnitIndex)
6101{
6102 mGLState.onActiveTextureChange(this, textureUnitIndex);
6103 mStateCache.onActiveTextureChange(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006104}
6105
Jamie Madill7e4eff12018-08-08 15:49:26 -04006106void Context::uniform1i(GLint location, GLint x)
6107{
6108 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
6109}
6110
Jamie Madillc1d770e2017-04-13 17:31:24 -04006111void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
6112{
Jamie Madill7e4eff12018-08-08 15:49:26 -04006113 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006114}
6115
6116void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
6117{
6118 GLfloat xy[2] = {x, y};
6119 Program *program = mGLState.getProgram();
6120 program->setUniform2fv(location, 1, xy);
6121}
6122
6123void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
6124{
6125 Program *program = mGLState.getProgram();
6126 program->setUniform2fv(location, count, v);
6127}
6128
6129void Context::uniform2i(GLint location, GLint x, GLint y)
6130{
6131 GLint xy[2] = {x, y};
6132 Program *program = mGLState.getProgram();
6133 program->setUniform2iv(location, 1, xy);
6134}
6135
6136void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
6137{
6138 Program *program = mGLState.getProgram();
6139 program->setUniform2iv(location, count, v);
6140}
6141
6142void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6143{
6144 GLfloat xyz[3] = {x, y, z};
6145 Program *program = mGLState.getProgram();
6146 program->setUniform3fv(location, 1, xyz);
6147}
6148
6149void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
6150{
6151 Program *program = mGLState.getProgram();
6152 program->setUniform3fv(location, count, v);
6153}
6154
6155void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
6156{
6157 GLint xyz[3] = {x, y, z};
6158 Program *program = mGLState.getProgram();
6159 program->setUniform3iv(location, 1, xyz);
6160}
6161
6162void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
6163{
6164 Program *program = mGLState.getProgram();
6165 program->setUniform3iv(location, count, v);
6166}
6167
6168void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6169{
6170 GLfloat xyzw[4] = {x, y, z, w};
6171 Program *program = mGLState.getProgram();
6172 program->setUniform4fv(location, 1, xyzw);
6173}
6174
6175void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
6176{
6177 Program *program = mGLState.getProgram();
6178 program->setUniform4fv(location, count, v);
6179}
6180
6181void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6182{
6183 GLint xyzw[4] = {x, y, z, w};
6184 Program *program = mGLState.getProgram();
6185 program->setUniform4iv(location, 1, xyzw);
6186}
6187
6188void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
6189{
6190 Program *program = mGLState.getProgram();
6191 program->setUniform4iv(location, count, v);
6192}
6193
6194void Context::uniformMatrix2fv(GLint location,
6195 GLsizei count,
6196 GLboolean transpose,
6197 const GLfloat *value)
6198{
6199 Program *program = mGLState.getProgram();
6200 program->setUniformMatrix2fv(location, count, transpose, value);
6201}
6202
6203void Context::uniformMatrix3fv(GLint location,
6204 GLsizei count,
6205 GLboolean transpose,
6206 const GLfloat *value)
6207{
6208 Program *program = mGLState.getProgram();
6209 program->setUniformMatrix3fv(location, count, transpose, value);
6210}
6211
6212void Context::uniformMatrix4fv(GLint location,
6213 GLsizei count,
6214 GLboolean transpose,
6215 const GLfloat *value)
6216{
6217 Program *program = mGLState.getProgram();
6218 program->setUniformMatrix4fv(location, count, transpose, value);
6219}
6220
6221void Context::validateProgram(GLuint program)
6222{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006223 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006224 ASSERT(programObject);
6225 programObject->validate(mCaps);
6226}
6227
Jiajia Qin5451d532017-11-16 17:16:34 +08006228void Context::validateProgramPipeline(GLuint pipeline)
6229{
6230 UNIMPLEMENTED();
6231}
6232
Jamie Madilld04908b2017-06-09 14:15:35 -04006233void Context::getProgramBinary(GLuint program,
6234 GLsizei bufSize,
6235 GLsizei *length,
6236 GLenum *binaryFormat,
6237 void *binary)
6238{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006239 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006240 ASSERT(programObject != nullptr);
6241
Jamie Madill4f6592f2018-11-27 16:37:45 -05006242 ANGLE_CONTEXT_TRY(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
Jamie Madilld04908b2017-06-09 14:15:35 -04006243}
6244
6245void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
6246{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006247 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006248 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04006249
Jamie Madill4f6592f2018-11-27 16:37:45 -05006250 ANGLE_CONTEXT_TRY(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madill70aeda42018-08-20 12:17:40 -04006251 if (programObject->isInUse())
6252 {
Jamie Madille3bb6b72018-10-03 17:51:15 -04006253 ANGLE_CONTEXT_TRY(mGLState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006254 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006255 }
Jamie Madilld04908b2017-06-09 14:15:35 -04006256}
6257
Jamie Madillff325f12017-08-26 15:06:05 -04006258void Context::uniform1ui(GLint location, GLuint v0)
6259{
6260 Program *program = mGLState.getProgram();
6261 program->setUniform1uiv(location, 1, &v0);
6262}
6263
6264void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
6265{
6266 Program *program = mGLState.getProgram();
6267 const GLuint xy[] = {v0, v1};
6268 program->setUniform2uiv(location, 1, xy);
6269}
6270
6271void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6272{
6273 Program *program = mGLState.getProgram();
6274 const GLuint xyz[] = {v0, v1, v2};
6275 program->setUniform3uiv(location, 1, xyz);
6276}
6277
6278void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6279{
6280 Program *program = mGLState.getProgram();
6281 const GLuint xyzw[] = {v0, v1, v2, v3};
6282 program->setUniform4uiv(location, 1, xyzw);
6283}
6284
6285void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
6286{
6287 Program *program = mGLState.getProgram();
6288 program->setUniform1uiv(location, count, value);
6289}
6290void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
6291{
6292 Program *program = mGLState.getProgram();
6293 program->setUniform2uiv(location, count, value);
6294}
6295
6296void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
6297{
6298 Program *program = mGLState.getProgram();
6299 program->setUniform3uiv(location, count, value);
6300}
6301
6302void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
6303{
6304 Program *program = mGLState.getProgram();
6305 program->setUniform4uiv(location, count, value);
6306}
6307
Jamie Madillf0e04492017-08-26 15:28:42 -04006308void Context::genQueries(GLsizei n, GLuint *ids)
6309{
6310 for (GLsizei i = 0; i < n; i++)
6311 {
6312 GLuint handle = mQueryHandleAllocator.allocate();
6313 mQueryMap.assign(handle, nullptr);
6314 ids[i] = handle;
6315 }
6316}
6317
6318void Context::deleteQueries(GLsizei n, const GLuint *ids)
6319{
6320 for (int i = 0; i < n; i++)
6321 {
6322 GLuint query = ids[i];
6323
6324 Query *queryObject = nullptr;
6325 if (mQueryMap.erase(query, &queryObject))
6326 {
6327 mQueryHandleAllocator.release(query);
6328 if (queryObject)
6329 {
6330 queryObject->release(this);
6331 }
6332 }
6333 }
6334}
6335
6336GLboolean Context::isQuery(GLuint id)
6337{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006338 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006339}
6340
Jamie Madillc8c95812017-08-26 18:40:09 -04006341void Context::uniformMatrix2x3fv(GLint location,
6342 GLsizei count,
6343 GLboolean transpose,
6344 const GLfloat *value)
6345{
6346 Program *program = mGLState.getProgram();
6347 program->setUniformMatrix2x3fv(location, count, transpose, value);
6348}
6349
6350void Context::uniformMatrix3x2fv(GLint location,
6351 GLsizei count,
6352 GLboolean transpose,
6353 const GLfloat *value)
6354{
6355 Program *program = mGLState.getProgram();
6356 program->setUniformMatrix3x2fv(location, count, transpose, value);
6357}
6358
6359void Context::uniformMatrix2x4fv(GLint location,
6360 GLsizei count,
6361 GLboolean transpose,
6362 const GLfloat *value)
6363{
6364 Program *program = mGLState.getProgram();
6365 program->setUniformMatrix2x4fv(location, count, transpose, value);
6366}
6367
6368void Context::uniformMatrix4x2fv(GLint location,
6369 GLsizei count,
6370 GLboolean transpose,
6371 const GLfloat *value)
6372{
6373 Program *program = mGLState.getProgram();
6374 program->setUniformMatrix4x2fv(location, count, transpose, value);
6375}
6376
6377void Context::uniformMatrix3x4fv(GLint location,
6378 GLsizei count,
6379 GLboolean transpose,
6380 const GLfloat *value)
6381{
6382 Program *program = mGLState.getProgram();
6383 program->setUniformMatrix3x4fv(location, count, transpose, value);
6384}
6385
6386void Context::uniformMatrix4x3fv(GLint location,
6387 GLsizei count,
6388 GLboolean transpose,
6389 const GLfloat *value)
6390{
6391 Program *program = mGLState.getProgram();
6392 program->setUniformMatrix4x3fv(location, count, transpose, value);
6393}
6394
Jamie Madilld7576732017-08-26 18:49:50 -04006395void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6396{
6397 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6398 {
6399 GLuint vertexArray = arrays[arrayIndex];
6400
6401 if (arrays[arrayIndex] != 0)
6402 {
6403 VertexArray *vertexArrayObject = nullptr;
6404 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6405 {
6406 if (vertexArrayObject != nullptr)
6407 {
6408 detachVertexArray(vertexArray);
6409 vertexArrayObject->onDestroy(this);
6410 }
6411
6412 mVertexArrayHandleAllocator.release(vertexArray);
6413 }
6414 }
6415 }
6416}
6417
6418void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6419{
6420 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6421 {
6422 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6423 mVertexArrayMap.assign(vertexArray, nullptr);
6424 arrays[arrayIndex] = vertexArray;
6425 }
6426}
6427
6428bool Context::isVertexArray(GLuint array)
6429{
6430 if (array == 0)
6431 {
6432 return GL_FALSE;
6433 }
6434
6435 VertexArray *vao = getVertexArray(array);
6436 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6437}
6438
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006439void Context::endTransformFeedback()
6440{
6441 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6442 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006443 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006444}
6445
6446void Context::transformFeedbackVaryings(GLuint program,
6447 GLsizei count,
6448 const GLchar *const *varyings,
6449 GLenum bufferMode)
6450{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006451 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006452 ASSERT(programObject);
6453 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6454}
6455
6456void Context::getTransformFeedbackVarying(GLuint program,
6457 GLuint index,
6458 GLsizei bufSize,
6459 GLsizei *length,
6460 GLsizei *size,
6461 GLenum *type,
6462 GLchar *name)
6463{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006464 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006465 ASSERT(programObject);
6466 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6467}
6468
6469void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6470{
6471 for (int i = 0; i < n; i++)
6472 {
6473 GLuint transformFeedback = ids[i];
6474 if (transformFeedback == 0)
6475 {
6476 continue;
6477 }
6478
6479 TransformFeedback *transformFeedbackObject = nullptr;
6480 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6481 {
6482 if (transformFeedbackObject != nullptr)
6483 {
6484 detachTransformFeedback(transformFeedback);
6485 transformFeedbackObject->release(this);
6486 }
6487
6488 mTransformFeedbackHandleAllocator.release(transformFeedback);
6489 }
6490 }
6491}
6492
6493void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6494{
6495 for (int i = 0; i < n; i++)
6496 {
6497 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6498 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6499 ids[i] = transformFeedback;
6500 }
6501}
6502
6503bool Context::isTransformFeedback(GLuint id)
6504{
6505 if (id == 0)
6506 {
6507 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6508 // returns FALSE
6509 return GL_FALSE;
6510 }
6511
6512 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6513 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6514}
6515
6516void Context::pauseTransformFeedback()
6517{
6518 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6519 transformFeedback->pause();
6520}
6521
6522void Context::resumeTransformFeedback()
6523{
6524 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6525 transformFeedback->resume();
6526}
6527
Jamie Madill12e957f2017-08-26 21:42:26 -04006528void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6529{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006530 const Program *programObject = getProgramResolveLink(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006531 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006532}
6533
Brandon Jones59770802018-04-02 13:18:42 -07006534void Context::getUniformuivRobust(GLuint program,
6535 GLint location,
6536 GLsizei bufSize,
6537 GLsizei *length,
6538 GLuint *params)
6539{
6540 getUniformuiv(program, location, params);
6541}
6542
Jamie Madill12e957f2017-08-26 21:42:26 -04006543GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6544{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006545 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006546 return programObject->getFragDataLocation(name);
6547}
6548
6549void Context::getUniformIndices(GLuint program,
6550 GLsizei uniformCount,
6551 const GLchar *const *uniformNames,
6552 GLuint *uniformIndices)
6553{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006554 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006555 if (!programObject->isLinked())
6556 {
6557 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6558 {
6559 uniformIndices[uniformId] = GL_INVALID_INDEX;
6560 }
6561 }
6562 else
6563 {
6564 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6565 {
6566 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6567 }
6568 }
6569}
6570
6571void Context::getActiveUniformsiv(GLuint program,
6572 GLsizei uniformCount,
6573 const GLuint *uniformIndices,
6574 GLenum pname,
6575 GLint *params)
6576{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006577 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006578 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6579 {
6580 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006581 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006582 }
6583}
6584
6585GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6586{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006587 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006588 return programObject->getUniformBlockIndex(uniformBlockName);
6589}
6590
6591void Context::getActiveUniformBlockiv(GLuint program,
6592 GLuint uniformBlockIndex,
6593 GLenum pname,
6594 GLint *params)
6595{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006596 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006597 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6598}
6599
Brandon Jones59770802018-04-02 13:18:42 -07006600void Context::getActiveUniformBlockivRobust(GLuint program,
6601 GLuint uniformBlockIndex,
6602 GLenum pname,
6603 GLsizei bufSize,
6604 GLsizei *length,
6605 GLint *params)
6606{
6607 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6608}
6609
Jamie Madill12e957f2017-08-26 21:42:26 -04006610void Context::getActiveUniformBlockName(GLuint program,
6611 GLuint uniformBlockIndex,
6612 GLsizei bufSize,
6613 GLsizei *length,
6614 GLchar *uniformBlockName)
6615{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006616 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006617 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6618}
6619
6620void Context::uniformBlockBinding(GLuint program,
6621 GLuint uniformBlockIndex,
6622 GLuint uniformBlockBinding)
6623{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006624 Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006625 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006626
Jamie Madill956ab4d2018-10-10 16:13:03 -04006627 // Note: If the Program is shared between Contexts we would be better using Observer/Subject.
Jamie Madill70aeda42018-08-20 12:17:40 -04006628 if (programObject->isInUse())
6629 {
6630 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006631 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006632 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006633}
6634
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006635GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6636{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006637 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6638 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006639
Jamie Madill70b5bb02017-08-28 13:32:37 -04006640 Sync *syncObject = getSync(syncHandle);
Jamie Madill7c985f52018-11-29 18:16:17 -05006641 if (syncObject->set(this, condition, flags) == angle::Result::Stop)
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006642 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006643 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006644 return nullptr;
6645 }
6646
Jamie Madill70b5bb02017-08-28 13:32:37 -04006647 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006648}
6649
6650GLboolean Context::isSync(GLsync sync)
6651{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006652 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006653}
6654
6655GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6656{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006657 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006658
6659 GLenum result = GL_WAIT_FAILED;
Jamie Madill7c985f52018-11-29 18:16:17 -05006660 if (syncObject->clientWait(this, flags, timeout, &result) == angle::Result::Stop)
Jamie Madill4f6592f2018-11-27 16:37:45 -05006661 {
6662 return GL_WAIT_FAILED;
6663 }
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006664 return result;
6665}
6666
6667void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6668{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006669 Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006670 ANGLE_CONTEXT_TRY(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006671}
6672
6673void Context::getInteger64v(GLenum pname, GLint64 *params)
6674{
6675 GLenum nativeType = GL_NONE;
6676 unsigned int numParams = 0;
6677 getQueryParameterInfo(pname, &nativeType, &numParams);
6678
6679 if (nativeType == GL_INT_64_ANGLEX)
6680 {
6681 getInteger64vImpl(pname, params);
6682 }
6683 else
6684 {
6685 CastStateValues(this, nativeType, pname, numParams, params);
6686 }
6687}
6688
Brandon Jones59770802018-04-02 13:18:42 -07006689void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6690{
6691 getInteger64v(pname, data);
6692}
6693
Corentin Wallez336129f2017-10-17 15:55:40 -04006694void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006695{
6696 Buffer *buffer = mGLState.getTargetBuffer(target);
6697 QueryBufferParameteri64v(buffer, pname, params);
6698}
6699
Brandon Jones59770802018-04-02 13:18:42 -07006700void Context::getBufferParameteri64vRobust(BufferBinding target,
6701 GLenum pname,
6702 GLsizei bufSize,
6703 GLsizei *length,
6704 GLint64 *params)
6705{
6706 getBufferParameteri64v(target, pname, params);
6707}
6708
Jamie Madill3ef140a2017-08-26 23:11:21 -04006709void Context::genSamplers(GLsizei count, GLuint *samplers)
6710{
6711 for (int i = 0; i < count; i++)
6712 {
6713 samplers[i] = mState.mSamplers->createSampler();
6714 }
6715}
6716
6717void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6718{
6719 for (int i = 0; i < count; i++)
6720 {
6721 GLuint sampler = samplers[i];
6722
6723 if (mState.mSamplers->getSampler(sampler))
6724 {
6725 detachSampler(sampler);
6726 }
6727
6728 mState.mSamplers->deleteObject(this, sampler);
6729 }
6730}
6731
6732void Context::getInternalformativ(GLenum target,
6733 GLenum internalformat,
6734 GLenum pname,
6735 GLsizei bufSize,
6736 GLint *params)
6737{
6738 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6739 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6740}
6741
Brandon Jones59770802018-04-02 13:18:42 -07006742void Context::getInternalformativRobust(GLenum target,
6743 GLenum internalformat,
6744 GLenum pname,
6745 GLsizei bufSize,
6746 GLsizei *length,
6747 GLint *params)
6748{
6749 getInternalformativ(target, internalformat, pname, bufSize, params);
6750}
6751
Jiajia Qin5451d532017-11-16 17:16:34 +08006752void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6753{
6754 programUniform1iv(program, location, 1, &v0);
6755}
6756
6757void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6758{
6759 GLint xy[2] = {v0, v1};
6760 programUniform2iv(program, location, 1, xy);
6761}
6762
6763void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6764{
6765 GLint xyz[3] = {v0, v1, v2};
6766 programUniform3iv(program, location, 1, xyz);
6767}
6768
6769void Context::programUniform4i(GLuint program,
6770 GLint location,
6771 GLint v0,
6772 GLint v1,
6773 GLint v2,
6774 GLint v3)
6775{
6776 GLint xyzw[4] = {v0, v1, v2, v3};
6777 programUniform4iv(program, location, 1, xyzw);
6778}
6779
6780void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6781{
6782 programUniform1uiv(program, location, 1, &v0);
6783}
6784
6785void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6786{
6787 GLuint xy[2] = {v0, v1};
6788 programUniform2uiv(program, location, 1, xy);
6789}
6790
6791void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6792{
6793 GLuint xyz[3] = {v0, v1, v2};
6794 programUniform3uiv(program, location, 1, xyz);
6795}
6796
6797void Context::programUniform4ui(GLuint program,
6798 GLint location,
6799 GLuint v0,
6800 GLuint v1,
6801 GLuint v2,
6802 GLuint v3)
6803{
6804 GLuint xyzw[4] = {v0, v1, v2, v3};
6805 programUniform4uiv(program, location, 1, xyzw);
6806}
6807
6808void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6809{
6810 programUniform1fv(program, location, 1, &v0);
6811}
6812
6813void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6814{
6815 GLfloat xy[2] = {v0, v1};
6816 programUniform2fv(program, location, 1, xy);
6817}
6818
6819void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6820{
6821 GLfloat xyz[3] = {v0, v1, v2};
6822 programUniform3fv(program, location, 1, xyz);
6823}
6824
6825void Context::programUniform4f(GLuint program,
6826 GLint location,
6827 GLfloat v0,
6828 GLfloat v1,
6829 GLfloat v2,
6830 GLfloat v3)
6831{
6832 GLfloat xyzw[4] = {v0, v1, v2, v3};
6833 programUniform4fv(program, location, 1, xyzw);
6834}
6835
Jamie Madill81c2e252017-09-09 23:32:46 -04006836void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6837{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006838 Program *programObject = getProgramResolveLink(program);
Jamie Madill81c2e252017-09-09 23:32:46 -04006839 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006840 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006841}
6842
Jiajia Qin5451d532017-11-16 17:16:34 +08006843void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6844{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006845 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006846 ASSERT(programObject);
6847 programObject->setUniform2iv(location, count, value);
6848}
6849
6850void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6851{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006852 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006853 ASSERT(programObject);
6854 programObject->setUniform3iv(location, count, value);
6855}
6856
6857void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6858{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006859 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006860 ASSERT(programObject);
6861 programObject->setUniform4iv(location, count, value);
6862}
6863
6864void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6865{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006866 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006867 ASSERT(programObject);
6868 programObject->setUniform1uiv(location, count, value);
6869}
6870
6871void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6872{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006873 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006874 ASSERT(programObject);
6875 programObject->setUniform2uiv(location, count, value);
6876}
6877
6878void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6879{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006880 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006881 ASSERT(programObject);
6882 programObject->setUniform3uiv(location, count, value);
6883}
6884
6885void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6886{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006887 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006888 ASSERT(programObject);
6889 programObject->setUniform4uiv(location, count, value);
6890}
6891
6892void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6893{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006894 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006895 ASSERT(programObject);
6896 programObject->setUniform1fv(location, count, value);
6897}
6898
6899void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6900{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006901 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006902 ASSERT(programObject);
6903 programObject->setUniform2fv(location, count, value);
6904}
6905
6906void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6907{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006908 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006909 ASSERT(programObject);
6910 programObject->setUniform3fv(location, count, value);
6911}
6912
6913void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6914{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006915 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006916 ASSERT(programObject);
6917 programObject->setUniform4fv(location, count, value);
6918}
6919
6920void Context::programUniformMatrix2fv(GLuint program,
6921 GLint location,
6922 GLsizei count,
6923 GLboolean transpose,
6924 const GLfloat *value)
6925{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006926 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006927 ASSERT(programObject);
6928 programObject->setUniformMatrix2fv(location, count, transpose, value);
6929}
6930
6931void Context::programUniformMatrix3fv(GLuint program,
6932 GLint location,
6933 GLsizei count,
6934 GLboolean transpose,
6935 const GLfloat *value)
6936{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006937 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006938 ASSERT(programObject);
6939 programObject->setUniformMatrix3fv(location, count, transpose, value);
6940}
6941
6942void Context::programUniformMatrix4fv(GLuint program,
6943 GLint location,
6944 GLsizei count,
6945 GLboolean transpose,
6946 const GLfloat *value)
6947{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006948 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006949 ASSERT(programObject);
6950 programObject->setUniformMatrix4fv(location, count, transpose, value);
6951}
6952
6953void Context::programUniformMatrix2x3fv(GLuint program,
6954 GLint location,
6955 GLsizei count,
6956 GLboolean transpose,
6957 const GLfloat *value)
6958{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006959 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006960 ASSERT(programObject);
6961 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6962}
6963
6964void Context::programUniformMatrix3x2fv(GLuint program,
6965 GLint location,
6966 GLsizei count,
6967 GLboolean transpose,
6968 const GLfloat *value)
6969{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006970 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006971 ASSERT(programObject);
6972 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6973}
6974
6975void Context::programUniformMatrix2x4fv(GLuint program,
6976 GLint location,
6977 GLsizei count,
6978 GLboolean transpose,
6979 const GLfloat *value)
6980{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006981 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006982 ASSERT(programObject);
6983 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6984}
6985
6986void Context::programUniformMatrix4x2fv(GLuint program,
6987 GLint location,
6988 GLsizei count,
6989 GLboolean transpose,
6990 const GLfloat *value)
6991{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006992 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006993 ASSERT(programObject);
6994 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6995}
6996
6997void Context::programUniformMatrix3x4fv(GLuint program,
6998 GLint location,
6999 GLsizei count,
7000 GLboolean transpose,
7001 const GLfloat *value)
7002{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007003 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08007004 ASSERT(programObject);
7005 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
7006}
7007
7008void Context::programUniformMatrix4x3fv(GLuint program,
7009 GLint location,
7010 GLsizei count,
7011 GLboolean transpose,
7012 const GLfloat *value)
7013{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007014 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08007015 ASSERT(programObject);
7016 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
7017}
7018
James Darpiniane8a93c62018-01-04 18:02:24 -08007019bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
7020{
7021 return mGLState.isCurrentTransformFeedback(tf);
7022}
James Darpiniane8a93c62018-01-04 18:02:24 -08007023
Yunchao Hea336b902017-08-02 16:05:21 +08007024void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
7025{
7026 for (int i = 0; i < count; i++)
7027 {
7028 pipelines[i] = createProgramPipeline();
7029 }
7030}
7031
7032void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
7033{
7034 for (int i = 0; i < count; i++)
7035 {
7036 if (pipelines[i] != 0)
7037 {
7038 deleteProgramPipeline(pipelines[i]);
7039 }
7040 }
7041}
7042
7043GLboolean Context::isProgramPipeline(GLuint pipeline)
7044{
7045 if (pipeline == 0)
7046 {
7047 return GL_FALSE;
7048 }
7049
7050 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
7051}
7052
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007053void Context::finishFenceNV(GLuint fence)
7054{
7055 FenceNV *fenceObject = getFenceNV(fence);
7056
7057 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madill4f6592f2018-11-27 16:37:45 -05007058 ANGLE_CONTEXT_TRY(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007059}
7060
7061void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
7062{
7063 FenceNV *fenceObject = getFenceNV(fence);
7064
7065 ASSERT(fenceObject && fenceObject->isSet());
7066
7067 switch (pname)
7068 {
7069 case GL_FENCE_STATUS_NV:
7070 {
7071 // GL_NV_fence spec:
7072 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
7073 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
7074 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
7075 GLboolean status = GL_TRUE;
7076 if (fenceObject->getStatus() != GL_TRUE)
7077 {
Jamie Madilla0691b72018-07-25 10:41:22 -04007078 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007079 }
7080 *params = status;
7081 break;
7082 }
7083
7084 case GL_FENCE_CONDITION_NV:
7085 {
7086 *params = static_cast<GLint>(fenceObject->getCondition());
7087 break;
7088 }
7089
7090 default:
7091 UNREACHABLE();
7092 }
7093}
7094
7095void Context::getTranslatedShaderSource(GLuint shader,
7096 GLsizei bufsize,
7097 GLsizei *length,
7098 GLchar *source)
7099{
7100 Shader *shaderObject = getShader(shader);
7101 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08007102 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007103}
7104
7105void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
7106{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007107 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007108 ASSERT(programObject);
7109
7110 programObject->getUniformfv(this, location, params);
7111}
7112
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007113void Context::getnUniformfvRobust(GLuint program,
7114 GLint location,
7115 GLsizei bufSize,
7116 GLsizei *length,
7117 GLfloat *params)
7118{
7119 UNIMPLEMENTED();
7120}
7121
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007122void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
7123{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007124 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007125 ASSERT(programObject);
7126
7127 programObject->getUniformiv(this, location, params);
7128}
7129
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007130void Context::getnUniformivRobust(GLuint program,
7131 GLint location,
7132 GLsizei bufSize,
7133 GLsizei *length,
7134 GLint *params)
7135{
7136 UNIMPLEMENTED();
7137}
7138
7139void Context::getnUniformuivRobust(GLuint program,
7140 GLint location,
7141 GLsizei bufSize,
7142 GLsizei *length,
7143 GLuint *params)
7144{
7145 UNIMPLEMENTED();
7146}
7147
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007148GLboolean Context::isFenceNV(GLuint fence)
7149{
7150 FenceNV *fenceObject = getFenceNV(fence);
7151
7152 if (fenceObject == nullptr)
7153 {
7154 return GL_FALSE;
7155 }
7156
7157 // GL_NV_fence spec:
7158 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
7159 // existing fence.
7160 return fenceObject->isSet();
7161}
7162
7163void Context::readnPixels(GLint x,
7164 GLint y,
7165 GLsizei width,
7166 GLsizei height,
7167 GLenum format,
7168 GLenum type,
7169 GLsizei bufSize,
7170 void *data)
7171{
7172 return readPixels(x, y, width, height, format, type, data);
7173}
7174
Jamie Madill007530e2017-12-28 14:27:04 -05007175void Context::setFenceNV(GLuint fence, GLenum condition)
7176{
7177 ASSERT(condition == GL_ALL_COMPLETED_NV);
7178
7179 FenceNV *fenceObject = getFenceNV(fence);
7180 ASSERT(fenceObject != nullptr);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007181 ANGLE_CONTEXT_TRY(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05007182}
7183
7184GLboolean Context::testFenceNV(GLuint fence)
7185{
7186 FenceNV *fenceObject = getFenceNV(fence);
7187
7188 ASSERT(fenceObject != nullptr);
7189 ASSERT(fenceObject->isSet() == GL_TRUE);
7190
7191 GLboolean result = GL_TRUE;
Jamie Madill7c985f52018-11-29 18:16:17 -05007192 if (fenceObject->test(this, &result) == angle::Result::Stop)
Jamie Madill007530e2017-12-28 14:27:04 -05007193 {
Jamie Madill007530e2017-12-28 14:27:04 -05007194 return GL_TRUE;
7195 }
7196
7197 return result;
7198}
7199
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007200void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007201{
7202 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07007203 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007204 ANGLE_CONTEXT_TRY(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007205}
7206
Jamie Madillfa920eb2018-01-04 11:45:50 -05007207void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007208{
7209 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07007210 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007211 ANGLE_CONTEXT_TRY(renderbuffer->setStorageEGLImageTarget(this, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007212}
7213
Jamie Madillfa920eb2018-01-04 11:45:50 -05007214void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
7215{
7216 UNIMPLEMENTED();
7217}
7218
Jamie Madill5b772312018-03-08 20:28:32 -05007219bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
7220{
7221 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
7222 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
7223 // to the fact that it is stored internally as a float, and so would require conversion
7224 // if returned from Context::getIntegerv. Since this conversion is already implemented
7225 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
7226 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
7227 // application.
7228 switch (pname)
7229 {
7230 case GL_COMPRESSED_TEXTURE_FORMATS:
7231 {
7232 *type = GL_INT;
7233 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
7234 return true;
7235 }
7236 case GL_SHADER_BINARY_FORMATS:
7237 {
7238 *type = GL_INT;
7239 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
7240 return true;
7241 }
7242
7243 case GL_MAX_VERTEX_ATTRIBS:
7244 case GL_MAX_VERTEX_UNIFORM_VECTORS:
7245 case GL_MAX_VARYING_VECTORS:
7246 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
7247 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
7248 case GL_MAX_TEXTURE_IMAGE_UNITS:
7249 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
7250 case GL_MAX_RENDERBUFFER_SIZE:
7251 case GL_NUM_SHADER_BINARY_FORMATS:
7252 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
7253 case GL_ARRAY_BUFFER_BINDING:
Jamie Madillef9fcd92018-11-28 14:03:59 -05007254 case GL_FRAMEBUFFER_BINDING: // GL_FRAMEBUFFER_BINDING now equivalent to
7255 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
Jamie Madill5b772312018-03-08 20:28:32 -05007256 case GL_RENDERBUFFER_BINDING:
7257 case GL_CURRENT_PROGRAM:
7258 case GL_PACK_ALIGNMENT:
7259 case GL_UNPACK_ALIGNMENT:
7260 case GL_GENERATE_MIPMAP_HINT:
7261 case GL_RED_BITS:
7262 case GL_GREEN_BITS:
7263 case GL_BLUE_BITS:
7264 case GL_ALPHA_BITS:
7265 case GL_DEPTH_BITS:
7266 case GL_STENCIL_BITS:
7267 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
7268 case GL_CULL_FACE_MODE:
7269 case GL_FRONT_FACE:
7270 case GL_ACTIVE_TEXTURE:
7271 case GL_STENCIL_FUNC:
7272 case GL_STENCIL_VALUE_MASK:
7273 case GL_STENCIL_REF:
7274 case GL_STENCIL_FAIL:
7275 case GL_STENCIL_PASS_DEPTH_FAIL:
7276 case GL_STENCIL_PASS_DEPTH_PASS:
7277 case GL_STENCIL_BACK_FUNC:
7278 case GL_STENCIL_BACK_VALUE_MASK:
7279 case GL_STENCIL_BACK_REF:
7280 case GL_STENCIL_BACK_FAIL:
7281 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
7282 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
7283 case GL_DEPTH_FUNC:
7284 case GL_BLEND_SRC_RGB:
7285 case GL_BLEND_SRC_ALPHA:
7286 case GL_BLEND_DST_RGB:
7287 case GL_BLEND_DST_ALPHA:
7288 case GL_BLEND_EQUATION_RGB:
7289 case GL_BLEND_EQUATION_ALPHA:
7290 case GL_STENCIL_WRITEMASK:
7291 case GL_STENCIL_BACK_WRITEMASK:
7292 case GL_STENCIL_CLEAR_VALUE:
7293 case GL_SUBPIXEL_BITS:
7294 case GL_MAX_TEXTURE_SIZE:
7295 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
7296 case GL_SAMPLE_BUFFERS:
7297 case GL_SAMPLES:
7298 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
7299 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
7300 case GL_TEXTURE_BINDING_2D:
7301 case GL_TEXTURE_BINDING_CUBE_MAP:
7302 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
7303 {
7304 *type = GL_INT;
7305 *numParams = 1;
7306 return true;
7307 }
7308 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
7309 {
7310 if (!getExtensions().packReverseRowOrder)
7311 {
7312 return false;
7313 }
7314 *type = GL_INT;
7315 *numParams = 1;
7316 return true;
7317 }
7318 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7319 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7320 {
7321 if (!getExtensions().textureRectangle)
7322 {
7323 return false;
7324 }
7325 *type = GL_INT;
7326 *numParams = 1;
7327 return true;
7328 }
7329 case GL_MAX_DRAW_BUFFERS_EXT:
7330 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7331 {
7332 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7333 {
7334 return false;
7335 }
7336 *type = GL_INT;
7337 *numParams = 1;
7338 return true;
7339 }
7340 case GL_MAX_VIEWPORT_DIMS:
7341 {
7342 *type = GL_INT;
7343 *numParams = 2;
7344 return true;
7345 }
7346 case GL_VIEWPORT:
7347 case GL_SCISSOR_BOX:
7348 {
7349 *type = GL_INT;
7350 *numParams = 4;
7351 return true;
7352 }
7353 case GL_SHADER_COMPILER:
7354 case GL_SAMPLE_COVERAGE_INVERT:
7355 case GL_DEPTH_WRITEMASK:
7356 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7357 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7358 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7359 // bool-natural
7360 case GL_SAMPLE_COVERAGE:
7361 case GL_SCISSOR_TEST:
7362 case GL_STENCIL_TEST:
7363 case GL_DEPTH_TEST:
7364 case GL_BLEND:
7365 case GL_DITHER:
7366 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7367 {
7368 *type = GL_BOOL;
7369 *numParams = 1;
7370 return true;
7371 }
7372 case GL_COLOR_WRITEMASK:
7373 {
7374 *type = GL_BOOL;
7375 *numParams = 4;
7376 return true;
7377 }
7378 case GL_POLYGON_OFFSET_FACTOR:
7379 case GL_POLYGON_OFFSET_UNITS:
7380 case GL_SAMPLE_COVERAGE_VALUE:
7381 case GL_DEPTH_CLEAR_VALUE:
7382 case GL_LINE_WIDTH:
7383 {
7384 *type = GL_FLOAT;
7385 *numParams = 1;
7386 return true;
7387 }
7388 case GL_ALIASED_LINE_WIDTH_RANGE:
7389 case GL_ALIASED_POINT_SIZE_RANGE:
7390 case GL_DEPTH_RANGE:
7391 {
7392 *type = GL_FLOAT;
7393 *numParams = 2;
7394 return true;
7395 }
7396 case GL_COLOR_CLEAR_VALUE:
7397 case GL_BLEND_COLOR:
7398 {
7399 *type = GL_FLOAT;
7400 *numParams = 4;
7401 return true;
7402 }
7403 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7404 if (!getExtensions().textureFilterAnisotropic)
7405 {
7406 return false;
7407 }
7408 *type = GL_FLOAT;
7409 *numParams = 1;
7410 return true;
7411 case GL_TIMESTAMP_EXT:
7412 if (!getExtensions().disjointTimerQuery)
7413 {
7414 return false;
7415 }
7416 *type = GL_INT_64_ANGLEX;
7417 *numParams = 1;
7418 return true;
7419 case GL_GPU_DISJOINT_EXT:
7420 if (!getExtensions().disjointTimerQuery)
7421 {
7422 return false;
7423 }
7424 *type = GL_INT;
7425 *numParams = 1;
7426 return true;
7427 case GL_COVERAGE_MODULATION_CHROMIUM:
7428 if (!getExtensions().framebufferMixedSamples)
7429 {
7430 return false;
7431 }
7432 *type = GL_INT;
7433 *numParams = 1;
7434 return true;
7435 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7436 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7437 {
7438 return false;
7439 }
7440 *type = GL_INT;
7441 *numParams = 1;
7442 return true;
7443 }
7444
7445 if (getExtensions().debug)
7446 {
7447 switch (pname)
7448 {
7449 case GL_DEBUG_LOGGED_MESSAGES:
7450 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7451 case GL_DEBUG_GROUP_STACK_DEPTH:
7452 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7453 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7454 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7455 case GL_MAX_LABEL_LENGTH:
7456 *type = GL_INT;
7457 *numParams = 1;
7458 return true;
7459
7460 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7461 case GL_DEBUG_OUTPUT:
7462 *type = GL_BOOL;
7463 *numParams = 1;
7464 return true;
7465 }
7466 }
7467
7468 if (getExtensions().multisampleCompatibility)
7469 {
7470 switch (pname)
7471 {
7472 case GL_MULTISAMPLE_EXT:
7473 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7474 *type = GL_BOOL;
7475 *numParams = 1;
7476 return true;
7477 }
7478 }
7479
7480 if (getExtensions().pathRendering)
7481 {
7482 switch (pname)
7483 {
7484 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7485 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7486 *type = GL_FLOAT;
7487 *numParams = 16;
7488 return true;
7489 }
7490 }
7491
7492 if (getExtensions().bindGeneratesResource)
7493 {
7494 switch (pname)
7495 {
7496 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7497 *type = GL_BOOL;
7498 *numParams = 1;
7499 return true;
7500 }
7501 }
7502
7503 if (getExtensions().clientArrays)
7504 {
7505 switch (pname)
7506 {
7507 case GL_CLIENT_ARRAYS_ANGLE:
7508 *type = GL_BOOL;
7509 *numParams = 1;
7510 return true;
7511 }
7512 }
7513
7514 if (getExtensions().sRGBWriteControl)
7515 {
7516 switch (pname)
7517 {
7518 case GL_FRAMEBUFFER_SRGB_EXT:
7519 *type = GL_BOOL;
7520 *numParams = 1;
7521 return true;
7522 }
7523 }
7524
7525 if (getExtensions().robustResourceInitialization &&
7526 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7527 {
7528 *type = GL_BOOL;
7529 *numParams = 1;
7530 return true;
7531 }
7532
7533 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7534 {
7535 *type = GL_BOOL;
7536 *numParams = 1;
7537 return true;
7538 }
7539
jchen1082af6202018-06-22 10:59:52 +08007540 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7541 {
7542 *type = GL_INT;
7543 *numParams = 1;
7544 return true;
7545 }
7546
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007547 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7548 {
7549 *type = GL_INT;
7550 *numParams = 1;
7551 return true;
7552 }
7553
Jamie Madill5b772312018-03-08 20:28:32 -05007554 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7555 switch (pname)
7556 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05007557 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE equivalent to FRAMEBUFFER_BINDING
Jamie Madill5b772312018-03-08 20:28:32 -05007558 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7559 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7560 {
7561 return false;
7562 }
7563 *type = GL_INT;
7564 *numParams = 1;
7565 return true;
7566
7567 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7568 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7569 {
7570 return false;
7571 }
7572 *type = GL_INT;
7573 *numParams = 1;
7574 return true;
7575
7576 case GL_PROGRAM_BINARY_FORMATS_OES:
7577 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7578 {
7579 return false;
7580 }
7581 *type = GL_INT;
7582 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7583 return true;
7584
7585 case GL_PACK_ROW_LENGTH:
7586 case GL_PACK_SKIP_ROWS:
7587 case GL_PACK_SKIP_PIXELS:
7588 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7589 {
7590 return false;
7591 }
7592 *type = GL_INT;
7593 *numParams = 1;
7594 return true;
7595 case GL_UNPACK_ROW_LENGTH:
7596 case GL_UNPACK_SKIP_ROWS:
7597 case GL_UNPACK_SKIP_PIXELS:
7598 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7599 {
7600 return false;
7601 }
7602 *type = GL_INT;
7603 *numParams = 1;
7604 return true;
7605 case GL_VERTEX_ARRAY_BINDING:
7606 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7607 {
7608 return false;
7609 }
7610 *type = GL_INT;
7611 *numParams = 1;
7612 return true;
7613 case GL_PIXEL_PACK_BUFFER_BINDING:
7614 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7615 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7616 {
7617 return false;
7618 }
7619 *type = GL_INT;
7620 *numParams = 1;
7621 return true;
7622 case GL_MAX_SAMPLES:
7623 {
7624 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7625 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7626 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7627 {
7628 return false;
7629 }
7630 *type = GL_INT;
7631 *numParams = 1;
7632 return true;
7633
7634 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7635 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7636 {
7637 return false;
7638 }
7639 *type = GL_INT;
7640 *numParams = 1;
7641 return true;
7642 }
7643 }
7644
7645 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7646 {
7647 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7648 {
7649 return false;
7650 }
7651 *type = GL_INT;
7652 *numParams = 1;
7653 return true;
7654 }
7655
7656 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7657 {
7658 *type = GL_INT;
7659 *numParams = 1;
7660 return true;
7661 }
7662
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007663 if (getClientVersion() < Version(2, 0))
7664 {
7665 switch (pname)
7666 {
7667 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007668 case GL_CLIENT_ACTIVE_TEXTURE:
7669 case GL_MATRIX_MODE:
7670 case GL_MAX_TEXTURE_UNITS:
7671 case GL_MAX_MODELVIEW_STACK_DEPTH:
7672 case GL_MAX_PROJECTION_STACK_DEPTH:
7673 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007674 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007675 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007676 case GL_VERTEX_ARRAY_STRIDE:
7677 case GL_NORMAL_ARRAY_STRIDE:
7678 case GL_COLOR_ARRAY_STRIDE:
7679 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7680 case GL_VERTEX_ARRAY_SIZE:
7681 case GL_COLOR_ARRAY_SIZE:
7682 case GL_TEXTURE_COORD_ARRAY_SIZE:
7683 case GL_VERTEX_ARRAY_TYPE:
7684 case GL_NORMAL_ARRAY_TYPE:
7685 case GL_COLOR_ARRAY_TYPE:
7686 case GL_TEXTURE_COORD_ARRAY_TYPE:
7687 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7688 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7689 case GL_COLOR_ARRAY_BUFFER_BINDING:
7690 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7691 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7692 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7693 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007694 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007695 case GL_MODELVIEW_STACK_DEPTH:
7696 case GL_PROJECTION_STACK_DEPTH:
7697 case GL_TEXTURE_STACK_DEPTH:
7698 case GL_LOGIC_OP_MODE:
7699 case GL_BLEND_SRC:
7700 case GL_BLEND_DST:
7701 case GL_PERSPECTIVE_CORRECTION_HINT:
7702 case GL_POINT_SMOOTH_HINT:
7703 case GL_LINE_SMOOTH_HINT:
7704 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007705 *type = GL_INT;
7706 *numParams = 1;
7707 return true;
7708 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007709 case GL_FOG_DENSITY:
7710 case GL_FOG_START:
7711 case GL_FOG_END:
7712 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007713 case GL_POINT_SIZE:
7714 case GL_POINT_SIZE_MIN:
7715 case GL_POINT_SIZE_MAX:
7716 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007717 *type = GL_FLOAT;
7718 *numParams = 1;
7719 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007720 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007721 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007722 *type = GL_FLOAT;
7723 *numParams = 2;
7724 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007725 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007726 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007727 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007728 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007729 *type = GL_FLOAT;
7730 *numParams = 4;
7731 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007732 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007733 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007734 *type = GL_FLOAT;
7735 *numParams = 3;
7736 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007737 case GL_MODELVIEW_MATRIX:
7738 case GL_PROJECTION_MATRIX:
7739 case GL_TEXTURE_MATRIX:
7740 *type = GL_FLOAT;
7741 *numParams = 16;
7742 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007743 case GL_LIGHT_MODEL_TWO_SIDE:
7744 *type = GL_BOOL;
7745 *numParams = 1;
7746 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007747 }
7748 }
7749
Jamie Madill5b772312018-03-08 20:28:32 -05007750 if (getClientVersion() < Version(3, 0))
7751 {
7752 return false;
7753 }
7754
7755 // Check for ES3.0+ parameter names
7756 switch (pname)
7757 {
7758 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7759 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7760 case GL_UNIFORM_BUFFER_BINDING:
7761 case GL_TRANSFORM_FEEDBACK_BINDING:
7762 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7763 case GL_COPY_READ_BUFFER_BINDING:
7764 case GL_COPY_WRITE_BUFFER_BINDING:
7765 case GL_SAMPLER_BINDING:
7766 case GL_READ_BUFFER:
7767 case GL_TEXTURE_BINDING_3D:
7768 case GL_TEXTURE_BINDING_2D_ARRAY:
7769 case GL_MAX_3D_TEXTURE_SIZE:
7770 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7771 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7772 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7773 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7774 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7775 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7776 case GL_MAX_VARYING_COMPONENTS:
7777 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7778 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7779 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7780 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7781 case GL_NUM_EXTENSIONS:
7782 case GL_MAJOR_VERSION:
7783 case GL_MINOR_VERSION:
7784 case GL_MAX_ELEMENTS_INDICES:
7785 case GL_MAX_ELEMENTS_VERTICES:
7786 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7787 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7788 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7789 case GL_UNPACK_IMAGE_HEIGHT:
7790 case GL_UNPACK_SKIP_IMAGES:
7791 {
7792 *type = GL_INT;
7793 *numParams = 1;
7794 return true;
7795 }
7796
7797 case GL_MAX_ELEMENT_INDEX:
7798 case GL_MAX_UNIFORM_BLOCK_SIZE:
7799 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7800 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7801 case GL_MAX_SERVER_WAIT_TIMEOUT:
7802 {
7803 *type = GL_INT_64_ANGLEX;
7804 *numParams = 1;
7805 return true;
7806 }
7807
7808 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7809 case GL_TRANSFORM_FEEDBACK_PAUSED:
7810 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7811 case GL_RASTERIZER_DISCARD:
7812 {
7813 *type = GL_BOOL;
7814 *numParams = 1;
7815 return true;
7816 }
7817
7818 case GL_MAX_TEXTURE_LOD_BIAS:
7819 {
7820 *type = GL_FLOAT;
7821 *numParams = 1;
7822 return true;
7823 }
7824 }
7825
7826 if (getExtensions().requestExtension)
7827 {
7828 switch (pname)
7829 {
7830 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7831 *type = GL_INT;
7832 *numParams = 1;
7833 return true;
7834 }
7835 }
7836
Yizhou Jiang7818a852018-09-06 15:02:04 +08007837 if (getExtensions().textureMultisample)
7838 {
7839 switch (pname)
7840 {
7841 case GL_MAX_COLOR_TEXTURE_SAMPLES_ANGLE:
7842 case GL_MAX_INTEGER_SAMPLES_ANGLE:
7843 case GL_MAX_DEPTH_TEXTURE_SAMPLES_ANGLE:
7844 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ANGLE:
Yizhou Jiang7310da32018-11-05 14:40:01 +08007845 case GL_MAX_SAMPLE_MASK_WORDS:
Yizhou Jiang7818a852018-09-06 15:02:04 +08007846 *type = GL_INT;
7847 *numParams = 1;
7848 return true;
7849 }
7850 }
7851
Jamie Madill5b772312018-03-08 20:28:32 -05007852 if (getClientVersion() < Version(3, 1))
7853 {
7854 return false;
7855 }
7856
7857 switch (pname)
7858 {
7859 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7860 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7861 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7862 case GL_MAX_FRAMEBUFFER_WIDTH:
7863 case GL_MAX_FRAMEBUFFER_HEIGHT:
7864 case GL_MAX_FRAMEBUFFER_SAMPLES:
7865 case GL_MAX_SAMPLE_MASK_WORDS:
7866 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7867 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7868 case GL_MAX_INTEGER_SAMPLES:
7869 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7870 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7871 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7872 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7873 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7874 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7875 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7876 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7877 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7878 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7879 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7880 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7881 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7882 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7883 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7884 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7885 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7886 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7887 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7888 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7889 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7890 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7891 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7892 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7893 case GL_MAX_UNIFORM_LOCATIONS:
7894 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7895 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7896 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7897 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7898 case GL_MAX_IMAGE_UNITS:
7899 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7900 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7901 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7902 case GL_SHADER_STORAGE_BUFFER_BINDING:
7903 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7904 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007905 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007906 *type = GL_INT;
7907 *numParams = 1;
7908 return true;
7909 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7910 *type = GL_INT_64_ANGLEX;
7911 *numParams = 1;
7912 return true;
7913 case GL_SAMPLE_MASK:
7914 *type = GL_BOOL;
7915 *numParams = 1;
7916 return true;
7917 }
7918
7919 if (getExtensions().geometryShader)
7920 {
7921 switch (pname)
7922 {
7923 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7924 case GL_LAYER_PROVOKING_VERTEX_EXT:
7925 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7926 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7927 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7928 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7929 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7930 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7931 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7932 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7933 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7934 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7935 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7936 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7937 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7938 *type = GL_INT;
7939 *numParams = 1;
7940 return true;
7941 }
7942 }
7943
7944 return false;
7945}
7946
7947bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7948{
7949 if (getClientVersion() < Version(3, 0))
7950 {
7951 return false;
7952 }
7953
7954 switch (target)
7955 {
7956 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7957 case GL_UNIFORM_BUFFER_BINDING:
7958 {
7959 *type = GL_INT;
7960 *numParams = 1;
7961 return true;
7962 }
7963 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7964 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7965 case GL_UNIFORM_BUFFER_START:
7966 case GL_UNIFORM_BUFFER_SIZE:
7967 {
7968 *type = GL_INT_64_ANGLEX;
7969 *numParams = 1;
7970 return true;
7971 }
7972 }
7973
7974 if (getClientVersion() < Version(3, 1))
7975 {
7976 return false;
7977 }
7978
7979 switch (target)
7980 {
7981 case GL_IMAGE_BINDING_LAYERED:
7982 {
7983 *type = GL_BOOL;
7984 *numParams = 1;
7985 return true;
7986 }
7987 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7988 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7989 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7990 case GL_SHADER_STORAGE_BUFFER_BINDING:
7991 case GL_VERTEX_BINDING_BUFFER:
7992 case GL_VERTEX_BINDING_DIVISOR:
7993 case GL_VERTEX_BINDING_OFFSET:
7994 case GL_VERTEX_BINDING_STRIDE:
7995 case GL_SAMPLE_MASK_VALUE:
7996 case GL_IMAGE_BINDING_NAME:
7997 case GL_IMAGE_BINDING_LEVEL:
7998 case GL_IMAGE_BINDING_LAYER:
7999 case GL_IMAGE_BINDING_ACCESS:
8000 case GL_IMAGE_BINDING_FORMAT:
8001 {
8002 *type = GL_INT;
8003 *numParams = 1;
8004 return true;
8005 }
8006 case GL_ATOMIC_COUNTER_BUFFER_START:
8007 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
8008 case GL_SHADER_STORAGE_BUFFER_START:
8009 case GL_SHADER_STORAGE_BUFFER_SIZE:
8010 {
8011 *type = GL_INT_64_ANGLEX;
8012 *numParams = 1;
8013 return true;
8014 }
8015 }
8016
8017 return false;
8018}
8019
Jamie Madill44a6fbf2018-10-02 13:38:56 -04008020Program *Context::getProgramNoResolveLink(GLuint handle) const
Jamie Madill5b772312018-03-08 20:28:32 -05008021{
8022 return mState.mShaderPrograms->getProgram(handle);
8023}
8024
8025Shader *Context::getShader(GLuint handle) const
8026{
8027 return mState.mShaderPrograms->getShader(handle);
8028}
8029
Jamie Madill5b772312018-03-08 20:28:32 -05008030bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
8031{
8032 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
8033}
8034
8035bool Context::isFramebufferGenerated(GLuint framebuffer) const
8036{
8037 return mState.mFramebuffers->isHandleGenerated(framebuffer);
8038}
8039
8040bool Context::isProgramPipelineGenerated(GLuint pipeline) const
8041{
8042 return mState.mPipelines->isHandleGenerated(pipeline);
8043}
8044
8045bool Context::usingDisplayTextureShareGroup() const
8046{
8047 return mDisplayTextureShareGroup;
8048}
8049
8050GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
8051{
8052 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
8053 internalformat == GL_DEPTH_STENCIL
8054 ? GL_DEPTH24_STENCIL8
8055 : internalformat;
8056}
8057
jchen1082af6202018-06-22 10:59:52 +08008058void Context::maxShaderCompilerThreads(GLuint count)
8059{
jchen107ae70d82018-07-06 13:47:01 +08008060 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08008061 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08008062 // A count of zero specifies a request for no parallel compiling or linking.
8063 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
8064 {
8065 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
8066 }
8067 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08008068}
8069
Jamie Madill2eb65032018-07-30 10:25:57 -04008070bool Context::isGLES1() const
8071{
8072 return mState.getClientVersion() < Version(2, 0);
8073}
8074
Jamie Madilla11819d2018-07-30 10:26:01 -04008075void Context::onSubjectStateChange(const Context *context,
8076 angle::SubjectIndex index,
8077 angle::SubjectMessage message)
8078{
Jamie Madilla11819d2018-07-30 10:26:01 -04008079 switch (index)
8080 {
8081 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008082 switch (message)
8083 {
8084 case angle::SubjectMessage::CONTENTS_CHANGED:
8085 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
8086 mStateCache.onVertexArrayBufferContentsChange(this);
8087 break;
8088 case angle::SubjectMessage::RESOURCE_MAPPED:
8089 case angle::SubjectMessage::RESOURCE_UNMAPPED:
8090 case angle::SubjectMessage::BINDING_CHANGED:
8091 mStateCache.onVertexArrayBufferStateChange(this);
8092 break;
8093 default:
8094 break;
8095 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008096 break;
8097
8098 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008099 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8100 {
8101 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
8102 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008103 break;
8104
8105 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008106 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8107 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05008108 mGLState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04008109 }
8110 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04008111 break;
8112
8113 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04008114 if (index < kTextureMaxSubjectIndex)
8115 {
Jamie Madille3e680c2018-12-03 17:49:08 -05008116 mGLState.onActiveTextureStateChange(this, index);
Jamie Madilld84b6732018-09-06 15:54:35 -04008117 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008118 }
Jamie Madille3e680c2018-12-03 17:49:08 -05008119 else if (index < kImageMaxSubjectIndex)
8120 {
8121 mGLState.onImageStateChange(this, index - kImage0SubjectIndex);
8122 }
Jamie Madille25b8002018-09-20 13:39:49 -04008123 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04008124 {
Jamie Madill6d32cef2018-08-14 02:34:28 -04008125 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04008126 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008127 }
Jamie Madille25b8002018-09-20 13:39:49 -04008128 else
8129 {
8130 ASSERT(index < kSamplerMaxSubjectIndex);
8131 mGLState.setSamplerDirty(index - kSampler0SubjectIndex);
8132 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008133 break;
8134 }
8135}
8136
Jamie Madill6b873dd2018-07-12 23:56:30 -04008137// ErrorSet implementation.
Jamie Madillb980c562018-11-27 11:34:27 -05008138ErrorSet::ErrorSet(Context *context) : mContext(context) {}
Jamie Madill6b873dd2018-07-12 23:56:30 -04008139
8140ErrorSet::~ErrorSet() = default;
8141
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008142void ErrorSet::handleError(GLenum errorCode,
8143 const char *message,
8144 const char *file,
8145 const char *function,
8146 unsigned int line)
8147{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008148 if (errorCode == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
8149 {
8150 mContext->markContextLost();
8151 }
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008152
Jamie Madill4f6592f2018-11-27 16:37:45 -05008153 std::stringstream errorStream;
8154 errorStream << "Error: " << gl::FmtHex(errorCode) << ", in " << file << ", " << function << ":"
8155 << line << ". " << message;
8156
8157 // validationError does the necessary work to process the error.
8158 validationError(errorCode, errorStream.str().c_str());
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008159}
8160
Jamie Madilla139f012018-10-10 16:13:03 -04008161void ErrorSet::validationError(GLenum errorCode, const char *message)
8162{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008163 ASSERT(errorCode != GL_NO_ERROR);
8164 mErrors.insert(errorCode);
8165
8166 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
8167 errorCode, GL_DEBUG_SEVERITY_HIGH, message);
Jamie Madilla139f012018-10-10 16:13:03 -04008168}
8169
Jamie Madill6b873dd2018-07-12 23:56:30 -04008170bool ErrorSet::empty() const
8171{
8172 return mErrors.empty();
8173}
8174
8175GLenum ErrorSet::popError()
8176{
8177 ASSERT(!empty());
8178 GLenum error = *mErrors.begin();
8179 mErrors.erase(mErrors.begin());
8180 return error;
8181}
Jamie Madilldc358af2018-07-31 11:22:13 -04008182
8183// StateCache implementation.
Jamie Madillac66f982018-10-09 18:30:01 -04008184StateCache::StateCache()
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008185 : mCachedHasAnyEnabledClientAttrib(false),
8186 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04008187 mCachedInstancedVertexElementLimit(0),
8188 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madillb980c562018-11-27 11:34:27 -05008189{}
Jamie Madilldc358af2018-07-31 11:22:13 -04008190
8191StateCache::~StateCache() = default;
8192
Jamie Madillac66f982018-10-09 18:30:01 -04008193void StateCache::initialize(Context *context)
8194{
8195 updateValidDrawModes(context);
8196 updateValidBindTextureTypes(context);
Jamie Madill8dc27f92018-11-29 11:45:44 -05008197 updateValidDrawElementsTypes(context);
Jamie Madillac66f982018-10-09 18:30:01 -04008198}
8199
Jamie Madilldc358af2018-07-31 11:22:13 -04008200void StateCache::updateActiveAttribsMask(Context *context)
8201{
8202 bool isGLES1 = context->isGLES1();
8203 const State &glState = context->getGLState();
8204
8205 if (!isGLES1 && !glState.getProgram())
8206 {
8207 mCachedActiveBufferedAttribsMask = AttributesMask();
8208 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04008209 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04008210 return;
8211 }
8212
8213 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
8214 : glState.getProgram()->getActiveAttribLocationsMask();
8215
8216 const VertexArray *vao = glState.getVertexArray();
8217 ASSERT(vao);
8218
8219 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
8220 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04008221 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008222
Jamie Madill0a17e482018-08-31 17:19:11 -04008223 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
8224 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04008225 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008226 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
8227}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008228
8229void StateCache::updateVertexElementLimits(Context *context)
8230{
8231 const VertexArray *vao = context->getGLState().getVertexArray();
8232
8233 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8234 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8235
8236 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
8237 // If there are no buffered attributes then we should not limit the draw call count.
8238 if (!vao || !mCachedActiveBufferedAttribsMask.any())
8239 {
8240 return;
8241 }
8242
8243 const auto &vertexAttribs = vao->getVertexAttributes();
8244 const auto &vertexBindings = vao->getVertexBindings();
8245
8246 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
8247 {
8248 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
8249 ASSERT(attrib.enabled);
8250
8251 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
8252 ASSERT(context->isGLES1() ||
8253 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
8254
8255 GLint64 limit = attrib.getCachedElementLimit();
8256 if (binding.getDivisor() > 0)
8257 {
8258 mCachedInstancedVertexElementLimit =
8259 std::min(mCachedInstancedVertexElementLimit, limit);
8260 }
8261 else
8262 {
8263 mCachedNonInstancedVertexElementLimit =
8264 std::min(mCachedNonInstancedVertexElementLimit, limit);
8265 }
8266 }
8267}
Jamie Madillc43cdad2018-08-08 15:49:25 -04008268
Jamie Madilld84b6732018-09-06 15:54:35 -04008269void StateCache::updateBasicDrawStatesError()
8270{
8271 mCachedBasicDrawStatesError = kInvalidPointer;
8272}
8273
8274intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
8275{
8276 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
8277 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
8278 return mCachedBasicDrawStatesError;
8279}
8280
Jamie Madillc43cdad2018-08-08 15:49:25 -04008281void StateCache::onVertexArrayBindingChange(Context *context)
8282{
8283 updateActiveAttribsMask(context);
8284 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008285 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008286}
8287
8288void StateCache::onProgramExecutableChange(Context *context)
8289{
8290 updateActiveAttribsMask(context);
8291 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008292 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04008293 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04008294}
8295
Jamie Madilld84b6732018-09-06 15:54:35 -04008296void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04008297{
8298 updateVertexElementLimits(context);
8299}
8300
Jamie Madilld84b6732018-09-06 15:54:35 -04008301void StateCache::onVertexArrayBufferContentsChange(Context *context)
8302{
8303 updateVertexElementLimits(context);
8304 updateBasicDrawStatesError();
8305}
8306
Jamie Madillc43cdad2018-08-08 15:49:25 -04008307void StateCache::onVertexArrayStateChange(Context *context)
8308{
8309 updateActiveAttribsMask(context);
8310 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008311 updateBasicDrawStatesError();
8312}
8313
8314void StateCache::onVertexArrayBufferStateChange(Context *context)
8315{
8316 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008317}
8318
8319void StateCache::onGLES1ClientStateChange(Context *context)
8320{
8321 updateActiveAttribsMask(context);
8322}
Jamie Madilld84b6732018-09-06 15:54:35 -04008323
8324void StateCache::onDrawFramebufferChange(Context *context)
8325{
8326 updateBasicDrawStatesError();
8327}
8328
8329void StateCache::onContextCapChange(Context *context)
8330{
8331 updateBasicDrawStatesError();
8332}
8333
8334void StateCache::onStencilStateChange(Context *context)
8335{
8336 updateBasicDrawStatesError();
8337}
8338
8339void StateCache::onDefaultVertexAttributeChange(Context *context)
8340{
8341 updateBasicDrawStatesError();
8342}
8343
8344void StateCache::onActiveTextureChange(Context *context)
8345{
8346 updateBasicDrawStatesError();
8347}
8348
8349void StateCache::onQueryChange(Context *context)
8350{
8351 updateBasicDrawStatesError();
8352}
8353
8354void StateCache::onTransformFeedbackChange(Context *context)
8355{
8356 updateBasicDrawStatesError();
8357}
8358
8359void StateCache::onUniformBufferStateChange(Context *context)
8360{
8361 updateBasicDrawStatesError();
8362}
8363
8364void StateCache::onBufferBindingChange(Context *context)
8365{
8366 updateBasicDrawStatesError();
8367}
Jamie Madill526a6f62018-09-12 11:03:05 -04008368
8369void StateCache::updateValidDrawModes(Context *context)
8370{
8371 Program *program = context->getGLState().getProgram();
8372 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8373 {
Jamie Madill752d2202018-11-27 13:29:48 -05008374 mCachedValidDrawModes = kValidBasicDrawModes;
Jamie Madill526a6f62018-09-12 11:03:05 -04008375 }
8376 else
8377 {
8378 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8379
8380 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
8381
8382 mCachedValidDrawModes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008383 {PrimitiveMode::Points, gsMode == PrimitiveMode::Points},
8384 {PrimitiveMode::Lines, gsMode == PrimitiveMode::Lines},
8385 {PrimitiveMode::LineLoop, gsMode == PrimitiveMode::Lines},
8386 {PrimitiveMode::LineStrip, gsMode == PrimitiveMode::Lines},
8387 {PrimitiveMode::Triangles, gsMode == PrimitiveMode::Triangles},
8388 {PrimitiveMode::TriangleStrip, gsMode == PrimitiveMode::Triangles},
8389 {PrimitiveMode::TriangleFan, gsMode == PrimitiveMode::Triangles},
8390 {PrimitiveMode::LinesAdjacency, gsMode == PrimitiveMode::LinesAdjacency},
8391 {PrimitiveMode::LineStripAdjacency, gsMode == PrimitiveMode::LinesAdjacency},
8392 {PrimitiveMode::TrianglesAdjacency, gsMode == PrimitiveMode::TrianglesAdjacency},
8393 {PrimitiveMode::TriangleStripAdjacency, gsMode == PrimitiveMode::TrianglesAdjacency},
Jamie Madill526a6f62018-09-12 11:03:05 -04008394 }};
8395 }
8396}
Jamie Madillac66f982018-10-09 18:30:01 -04008397
8398void StateCache::updateValidBindTextureTypes(Context *context)
8399{
8400 const Extensions &exts = context->getExtensions();
8401 bool isGLES3 = context->getClientMajorVersion() >= 3;
8402 bool isGLES31 = context->getClientVersion() >= Version(3, 1);
8403
8404 mCachedValidBindTextureTypes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008405 {TextureType::_2D, true},
8406 {TextureType::_2DArray, isGLES3},
8407 {TextureType::_2DMultisample, isGLES31 || exts.textureMultisample},
8408 {TextureType::_2DMultisampleArray, exts.textureStorageMultisample2DArray},
8409 {TextureType::_3D, isGLES3},
8410 {TextureType::External, exts.eglImageExternal || exts.eglStreamConsumerExternal},
8411 {TextureType::Rectangle, exts.textureRectangle},
8412 {TextureType::CubeMap, true},
Jamie Madillac66f982018-10-09 18:30:01 -04008413 }};
8414}
Jamie Madill8dc27f92018-11-29 11:45:44 -05008415
8416void StateCache::updateValidDrawElementsTypes(Context *context)
8417{
8418 bool supportsUint =
8419 (context->getClientMajorVersion() >= 3 || context->getExtensions().elementIndexUint);
8420
8421 mCachedValidDrawElementsTypes = {{
8422 {DrawElementsType::UnsignedByte, true},
8423 {DrawElementsType::UnsignedShort, true},
8424 {DrawElementsType::UnsignedInt, supportsUint},
8425 }};
8426}
Jamie Madillc29968b2016-01-20 11:17:23 -05008427} // namespace gl