blob: f1efed8db9de1a84c479fd45016e458d4f670afe [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
Geoff Langf6db0982015-08-25 13:04:00 -040050namespace
51{
52
Jamie Madillb6664922017-07-25 12:55:04 -040053#define ANGLE_HANDLE_ERR(X) \
54 handleError(X); \
55 return;
56#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
57
Ian Ewell3ffd78b2016-01-22 16:09:42 -050058template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050059std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030060 GLsizei numPaths,
61 const void *paths,
62 GLuint pathBase)
63{
64 std::vector<gl::Path *> ret;
65 ret.reserve(numPaths);
66
67 const auto *nameArray = static_cast<const T *>(paths);
68
69 for (GLsizei i = 0; i < numPaths; ++i)
70 {
71 const GLuint pathName = nameArray[i] + pathBase;
72
73 ret.push_back(resourceManager.getPath(pathName));
74 }
75
76 return ret;
77}
78
Geoff Lang4ddf5af2016-12-01 14:30:44 -050079std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030080 GLsizei numPaths,
81 GLenum pathNameType,
82 const void *paths,
83 GLuint pathBase)
84{
85 switch (pathNameType)
86 {
87 case GL_UNSIGNED_BYTE:
88 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
89
90 case GL_BYTE:
91 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
92
93 case GL_UNSIGNED_SHORT:
94 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
95
96 case GL_SHORT:
97 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
98
99 case GL_UNSIGNED_INT:
100 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
101
102 case GL_INT:
103 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
104 }
105
106 UNREACHABLE();
107 return std::vector<gl::Path *>();
108}
109
110template <typename T>
Jamie Madill5188a272018-07-25 10:53:56 -0400111gl::Error GetQueryObjectParameter(const gl::Context *context,
112 gl::Query *query,
113 GLenum pname,
114 T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500115{
Geoff Lang2186c382016-10-14 10:54:54 -0400116 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500117
118 switch (pname)
119 {
120 case GL_QUERY_RESULT_EXT:
Jamie Madill5188a272018-07-25 10:53:56 -0400121 return query->getResult(context, params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500122 case GL_QUERY_RESULT_AVAILABLE_EXT:
123 {
124 bool available;
Jamie Madill5188a272018-07-25 10:53:56 -0400125 gl::Error error = query->isResultAvailable(context, &available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500126 if (!error.isError())
127 {
jchen10a99ed552017-09-22 08:10:32 +0800128 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500129 }
130 return error;
131 }
132 default:
133 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500134 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500135 }
136}
137
Jamie Madill09463932018-04-04 05:26:59 -0400138void MarkTransformFeedbackBufferUsage(const gl::Context *context,
139 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700140 GLsizei count,
141 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400142{
Geoff Lang1a683462015-09-29 15:09:59 -0400143 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400144 {
Jamie Madill09463932018-04-04 05:26:59 -0400145 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400146 }
147}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148
149// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500151{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500153}
154
Martin Radev1be913c2016-07-11 17:59:16 +0300155EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
156{
157 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
158}
159
Geoff Langeb66a6e2016-10-31 13:06:12 -0400160gl::Version GetClientVersion(const egl::AttributeMap &attribs)
161{
162 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
163}
164
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165GLenum GetResetStrategy(const egl::AttributeMap &attribs)
166{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800167 EGLAttrib attrib =
168 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500169 switch (attrib)
170 {
171 case EGL_NO_RESET_NOTIFICATION:
172 return GL_NO_RESET_NOTIFICATION_EXT;
173 case EGL_LOSE_CONTEXT_ON_RESET:
174 return GL_LOSE_CONTEXT_ON_RESET_EXT;
175 default:
176 UNREACHABLE();
177 return GL_NONE;
178 }
179}
180
181bool GetRobustAccess(const egl::AttributeMap &attribs)
182{
Geoff Lang077f20a2016-11-01 10:08:02 -0400183 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
184 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
185 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500186}
187
188bool GetDebug(const egl::AttributeMap &attribs)
189{
Geoff Lang077f20a2016-11-01 10:08:02 -0400190 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
191 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500192}
193
194bool GetNoError(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Langc287ea62016-09-16 14:46:51 -0400199bool GetWebGLContext(const egl::AttributeMap &attribs)
200{
Jamie Madill4230d482018-09-14 10:14:45 -0400201 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
Geoff Langc287ea62016-09-16 14:46:51 -0400202}
203
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400204bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
205{
206 // If the context is WebGL, extensions are disabled by default
207 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
208 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
209}
210
Geoff Langf41a7152016-09-19 15:11:17 -0400211bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
212{
Jamie Madill4230d482018-09-14 10:14:45 -0400213 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
Geoff Langf41a7152016-09-19 15:11:17 -0400214}
215
Geoff Langfeb8c682017-02-13 16:07:35 -0500216bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
217{
218 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
219}
220
Geoff Langb433e872017-10-05 14:01:47 -0400221bool GetRobustResourceInit(const egl::AttributeMap &attribs)
222{
223 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
224}
225
Martin Radev9d901792016-07-15 15:58:58 +0300226std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
227{
228 std::string labelName;
229 if (label != nullptr)
230 {
231 size_t labelLength = length < 0 ? strlen(label) : length;
232 labelName = std::string(label, labelLength);
233 }
234 return labelName;
235}
236
237void GetObjectLabelBase(const std::string &objectLabel,
238 GLsizei bufSize,
239 GLsizei *length,
240 GLchar *label)
241{
242 size_t writeLength = objectLabel.length();
243 if (label != nullptr && bufSize > 0)
244 {
245 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
246 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
247 label[writeLength] = '\0';
248 }
249
250 if (length != nullptr)
251 {
252 *length = static_cast<GLsizei>(writeLength);
253 }
254}
255
Jamie Madill0f80ed82017-09-19 00:24:56 -0400256template <typename CapT, typename MaxT>
257void LimitCap(CapT *cap, MaxT maximum)
258{
259 *cap = std::min(*cap, static_cast<CapT>(maximum));
260}
261
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600262constexpr angle::PackedEnumMap<gl::PrimitiveMode, GLsizei> kMinimumPrimitiveCounts = {{
Jamie Madill526a6f62018-09-12 11:03:05 -0400263 1, /* Points */
264 2, /* Lines */
265 2, /* LineLoop */
266 2, /* LineStrip */
267 3, /* Triangles */
268 3, /* TriangleStrip */
269 3, /* TriangleFan */
270 2, /* LinesAdjacency */
271 2, /* LineStripAdjacency */
272 3, /* TrianglesAdjacency */
273 3, /* TriangleStripAdjacency */
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600274}};
275// Indices above are code-gen'd so make sure they don't change
276// if any of these static asserts are hit, must update kMinimumPrimitiveCounts abouve
277static_assert(static_cast<gl::PrimitiveMode>(0) == gl::PrimitiveMode::Points,
278 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
279static_assert(static_cast<gl::PrimitiveMode>(1) == gl::PrimitiveMode::Lines,
280 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
281static_assert(static_cast<gl::PrimitiveMode>(2) == gl::PrimitiveMode::LineLoop,
282 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
283static_assert(static_cast<gl::PrimitiveMode>(3) == gl::PrimitiveMode::LineStrip,
284 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
285static_assert(static_cast<gl::PrimitiveMode>(4) == gl::PrimitiveMode::Triangles,
286 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
287static_assert(static_cast<gl::PrimitiveMode>(5) == gl::PrimitiveMode::TriangleStrip,
288 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
289static_assert(static_cast<gl::PrimitiveMode>(6) == gl::PrimitiveMode::TriangleFan,
290 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
291static_assert(static_cast<gl::PrimitiveMode>(7) == gl::PrimitiveMode::LinesAdjacency,
292 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
293static_assert(static_cast<gl::PrimitiveMode>(8) == gl::PrimitiveMode::LineStripAdjacency,
294 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
295static_assert(static_cast<gl::PrimitiveMode>(9) == gl::PrimitiveMode::TrianglesAdjacency,
296 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
297static_assert(static_cast<gl::PrimitiveMode>(10) == gl::PrimitiveMode::TriangleStripAdjacency,
298 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
299static_assert(static_cast<gl::PrimitiveMode>(11) == gl::PrimitiveMode::EnumCount,
300 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
301
Jamie Madill6d32cef2018-08-14 02:34:28 -0400302enum SubjectIndexes : angle::SubjectIndex
303{
304 kTexture0SubjectIndex = 0,
305 kTextureMaxSubjectIndex = kTexture0SubjectIndex + gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
306 kUniformBuffer0SubjectIndex = kTextureMaxSubjectIndex,
307 kUniformBufferMaxSubjectIndex =
308 kUniformBuffer0SubjectIndex + gl::IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS,
Jamie Madille25b8002018-09-20 13:39:49 -0400309 kSampler0SubjectIndex = kUniformBufferMaxSubjectIndex,
310 kSamplerMaxSubjectIndex = kSampler0SubjectIndex + gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
311 kVertexArraySubjectIndex = kSamplerMaxSubjectIndex,
Jamie Madill6d32cef2018-08-14 02:34:28 -0400312 kReadFramebufferSubjectIndex,
313 kDrawFramebufferSubjectIndex
314};
Geoff Langf6db0982015-08-25 13:04:00 -0400315} // anonymous namespace
316
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000317namespace gl
318{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000319
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400320Context::Context(rx::EGLImplFactory *implFactory,
321 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400322 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500323 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400324 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500325 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700326 const egl::DisplayExtensions &displayExtensions,
327 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500328 : mState(reinterpret_cast<ContextID>(this),
329 shareContext ? &shareContext->mState : nullptr,
330 shareTextures,
331 GetClientVersion(attribs),
332 &mGLState,
333 mCaps,
334 mTextureCaps,
335 mExtensions,
336 mLimitations),
337 mSkipValidation(GetNoError(attribs)),
338 mDisplayTextureShareGroup(shareTextures != nullptr),
339 mSavedArgsType(nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400340 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400341 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400342 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400343 mGLState(GetDebug(attribs),
344 GetBindGeneratesResource(attribs),
345 GetClientArraysEnabled(attribs),
346 GetRobustResourceInit(attribs),
347 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400348 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500349 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400350 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500351 mHasBeenCurrent(false),
352 mContextLost(false),
353 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700354 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500355 mResetStrategy(GetResetStrategy(attribs)),
356 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400357 mSurfacelessSupported(displayExtensions.surfacelessContext),
358 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400359 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
360 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500361 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400362 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400363 mMemoryProgramCache(memoryProgramCache),
Jamie Madill16e28fd2018-09-12 11:03:05 -0400364 mStateCache(this),
Jamie Madilla11819d2018-07-30 10:26:01 -0400365 mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
366 mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
367 mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400368 mScratchBuffer(1000u),
jchen107ae70d82018-07-06 13:47:01 +0800369 mZeroFilledBuffer(1000u),
370 mThreadPool(nullptr)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000371{
Jamie Madill5b772312018-03-08 20:28:32 -0500372 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400373 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
374 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Jamie Madill6d32cef2018-08-14 02:34:28 -0400375
376 for (angle::SubjectIndex uboIndex = kUniformBuffer0SubjectIndex;
377 uboIndex < kUniformBufferMaxSubjectIndex; ++uboIndex)
378 {
379 mUniformBufferObserverBindings.emplace_back(this, uboIndex);
380 }
Jamie Madille25b8002018-09-20 13:39:49 -0400381
382 for (angle::SubjectIndex samplerIndex = kSampler0SubjectIndex;
383 samplerIndex < kSamplerMaxSubjectIndex; ++samplerIndex)
384 {
385 mSamplerObserverBindings.emplace_back(this, samplerIndex);
386 }
Geoff Lang33f11fb2018-05-07 13:42:47 -0400387}
Jamie Madill5b772312018-03-08 20:28:32 -0500388
Geoff Lang33f11fb2018-05-07 13:42:47 -0400389void Context::initialize()
390{
391 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400392
Geoff Lang33f11fb2018-05-07 13:42:47 -0400393 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700394 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400395
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400396 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100397
Shannon Woods53a94a82014-06-24 15:20:36 -0400398 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400399
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000400 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400401 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000402 // and cube map texture state vectors respectively associated with them.
403 // In order that access to these initial textures not be lost, they are treated as texture
404 // objects all of whose names are 0.
405
Corentin Wallez99d492c2018-02-27 15:17:10 -0500406 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800407 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500408
Corentin Wallez99d492c2018-02-27 15:17:10 -0500409 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800410 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400411
Geoff Langeb66a6e2016-10-31 13:06:12 -0400412 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400413 {
414 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500415 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800416 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400417
Corentin Wallez99d492c2018-02-27 15:17:10 -0500418 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800419 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400420 }
Geoff Lang3b573612016-10-31 14:08:10 -0400421 if (getClientVersion() >= Version(3, 1))
422 {
Olli Etuahod310a432018-08-24 15:40:23 +0300423 // TODO(http://anglebug.com/2775): These could also be enabled via extension
Geoff Lang3b573612016-10-31 14:08:10 -0400424 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500425 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800426 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Olli Etuahod310a432018-08-24 15:40:23 +0300427 Texture *zeroTexture2DMultisampleArray =
428 new Texture(mImplementation.get(), 0, TextureType::_2DMultisampleArray);
429 mZeroTextures[TextureType::_2DMultisampleArray].set(this, zeroTexture2DMultisampleArray);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800430
Jiajia Qin6eafb042016-12-27 17:04:07 +0800431 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
432 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800433 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800434 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800435
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800436 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
437 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400438 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800439 }
Geoff Lang3b573612016-10-31 14:08:10 -0400440 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000441
Geoff Langb0f917f2017-12-05 13:41:54 -0500442 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400443 {
444 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500445 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800446 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400447 }
448
Geoff Langb0f917f2017-12-05 13:41:54 -0500449 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400450 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500451 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800452 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400453 }
454
Jamie Madill4928b7c2017-06-20 12:57:39 -0400455 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500456
Jamie Madill57a89722013-07-02 11:57:03 -0400457 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000458
Geoff Langeb66a6e2016-10-31 13:06:12 -0400459 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400460 {
461 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
462 // In the initial state, a default transform feedback object is bound and treated as
463 // a transform feedback object with a name of zero. That object is bound any time
464 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400465 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400466 }
Geoff Langc8058452014-02-03 12:04:11 -0500467
Corentin Wallez336129f2017-10-17 15:55:40 -0400468 for (auto type : angle::AllEnums<BufferBinding>())
469 {
470 bindBuffer(type, 0);
471 }
472
473 bindRenderbuffer(GL_RENDERBUFFER, 0);
474
475 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
476 {
477 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
478 }
479
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700480 // Initialize GLES1 renderer if appropriate.
481 if (getClientVersion() < Version(2, 0))
482 {
483 mGLES1Renderer.reset(new GLES1Renderer());
484 }
485
Jamie Madillad9f24e2016-02-12 09:27:24 -0500486 // Initialize dirty bit masks
Geoff Lang9bf86f02018-07-26 11:46:34 -0400487 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
488 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
489 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400490 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400491 mDrawDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400492
493 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
494 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
495 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madille25b8002018-09-20 13:39:49 -0400496 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400497
Jamie Madillc67323a2017-11-02 23:11:41 -0400498 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500499 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500500 // No dirty objects.
501
502 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400503 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500504 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400505 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500506 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
507
508 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
509 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
510 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
511 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
512 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
513 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
514 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
515 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
516 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
517 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
518 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400519 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500520 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
521
522 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
523 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700524 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400525 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
526 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500527 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
528 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400529
Xinghua Cao10a4d432017-11-28 14:46:26 +0800530 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
jchen1099118c12018-09-10 16:28:51 +0800531 mComputeDirtyBits.set(State::DIRTY_BIT_UNIFORM_BUFFER_BINDINGS);
532 mComputeDirtyBits.set(State::DIRTY_BIT_ATOMIC_COUNTER_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800533 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
534 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
535 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
536 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
jchen1099118c12018-09-10 16:28:51 +0800537 mComputeDirtyBits.set(State::DIRTY_BIT_IMAGE_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800538 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800539 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400540 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400541 mComputeDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800542
Jamie Madillb4927eb2018-07-16 11:39:46 -0400543 mImplementation->setErrorSet(&mErrors);
544
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400545 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000546}
547
Jamie Madill4928b7c2017-06-20 12:57:39 -0400548egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000549{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700550 if (mGLES1Renderer)
551 {
552 mGLES1Renderer->onDestroy(this, &mGLState);
553 }
554
Jamie Madille7b3fe22018-04-05 09:42:46 -0400555 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400556 ANGLE_TRY(releaseSurface(display));
557
Corentin Wallez80b24112015-08-25 16:41:57 -0400558 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000559 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400560 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000561 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400562 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000563
Corentin Wallez80b24112015-08-25 16:41:57 -0400564 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000565 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400566 if (query.second != nullptr)
567 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400568 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400569 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000570 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400571 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000572
Corentin Wallez80b24112015-08-25 16:41:57 -0400573 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400574 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400575 if (vertexArray.second)
576 {
577 vertexArray.second->onDestroy(this);
578 }
Jamie Madill57a89722013-07-02 11:57:03 -0400579 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400580 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400581
Corentin Wallez80b24112015-08-25 16:41:57 -0400582 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500583 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500584 if (transformFeedback.second != nullptr)
585 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500586 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500587 }
Geoff Langc8058452014-02-03 12:04:11 -0500588 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400589 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500590
Jamie Madill5b772312018-03-08 20:28:32 -0500591 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400592 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800593 if (zeroTexture.get() != nullptr)
594 {
595 ANGLE_TRY(zeroTexture->onDestroy(this));
596 zeroTexture.set(this, nullptr);
597 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400598 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000599
Jamie Madill2f348d22017-06-05 10:50:59 -0400600 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500601
Jamie Madill4928b7c2017-06-20 12:57:39 -0400602 mGLState.reset(this);
603
Jamie Madill6c1f6712017-02-14 19:08:04 -0500604 mState.mBuffers->release(this);
605 mState.mShaderPrograms->release(this);
606 mState.mTextures->release(this);
607 mState.mRenderbuffers->release(this);
608 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400609 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500610 mState.mPaths->release(this);
611 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800612 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400613
jchen107ae70d82018-07-06 13:47:01 +0800614 mThreadPool.reset();
615
Jamie Madill76e471e2017-10-21 09:56:01 -0400616 mImplementation->onDestroy(this);
617
Jamie Madill4928b7c2017-06-20 12:57:39 -0400618 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000619}
620
Jamie Madill70ee0f62017-02-06 16:04:20 -0500621Context::~Context()
622{
623}
624
Geoff Lang75359662018-04-11 01:42:27 -0400625void Context::setLabel(EGLLabelKHR label)
626{
627 mLabel = label;
628}
629
630EGLLabelKHR Context::getLabel() const
631{
632 return mLabel;
633}
634
Jamie Madill4928b7c2017-06-20 12:57:39 -0400635egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000636{
Jamie Madill61e16b42017-06-19 11:13:23 -0400637 mCurrentDisplay = display;
638
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000639 if (!mHasBeenCurrent)
640 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400641 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000642 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500643 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400644 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000645
Corentin Wallezc295e512017-01-27 17:47:50 -0500646 int width = 0;
647 int height = 0;
648 if (surface != nullptr)
649 {
650 width = surface->getWidth();
651 height = surface->getHeight();
652 }
653
654 mGLState.setViewportParams(0, 0, width, height);
655 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000656
657 mHasBeenCurrent = true;
658 }
659
Jamie Madill1b94d432015-08-07 13:23:23 -0400660 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700661 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400662 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400663
Jamie Madill4928b7c2017-06-20 12:57:39 -0400664 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500665
666 Framebuffer *newDefault = nullptr;
667 if (surface != nullptr)
668 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400669 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500670 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400671 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500672 }
673 else
674 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400675 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500676 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000677
Corentin Wallez37c39792015-08-20 14:19:46 -0400678 // Update default framebuffer, the binding of the previous default
679 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400680 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400681 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700682 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400683 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400684 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400685 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700686 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400687 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400688 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400689 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400690 }
Ian Ewell292f0052016-02-04 10:37:32 -0500691
692 // Notify the renderer of a context switch
Luc Ferron5396f2a2018-07-12 08:24:23 -0400693 ANGLE_TRY(mImplementation->onMakeCurrent(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400694 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000695}
696
Jamie Madill4928b7c2017-06-20 12:57:39 -0400697egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400698{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400699 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400700
Geoff Langbf7b95d2018-05-01 16:48:21 -0400701 // Remove the default framebuffer
702 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500703 {
704 mGLState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400705 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500706 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400707
708 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500709 {
710 mGLState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400711 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500712 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400713
714 if (defaultFramebuffer)
715 {
716 defaultFramebuffer->onDestroy(this);
717 delete defaultFramebuffer;
718 }
719
Corentin Wallezc295e512017-01-27 17:47:50 -0500720 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
721
722 if (mCurrentSurface)
723 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400724 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500725 mCurrentSurface = nullptr;
726 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400727
728 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400729}
730
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000731GLuint Context::createBuffer()
732{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500733 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000734}
735
736GLuint Context::createProgram()
737{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500738 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000739}
740
Jiawei Shao385b3e02018-03-21 09:43:28 +0800741GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000742{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500743 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000744}
745
746GLuint Context::createTexture()
747{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500748 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000749}
750
751GLuint Context::createRenderbuffer()
752{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500753 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000754}
755
Brandon Jones59770802018-04-02 13:18:42 -0700756GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300757{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500758 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300759 if (resultOrError.isError())
760 {
761 handleError(resultOrError.getError());
762 return 0;
763 }
764 return resultOrError.getResult();
765}
766
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000767// Returns an unused framebuffer name
768GLuint Context::createFramebuffer()
769{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500770 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000771}
772
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500773void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000774{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500775 for (int i = 0; i < n; i++)
776 {
777 GLuint handle = mFenceNVHandleAllocator.allocate();
778 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
779 fences[i] = handle;
780 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000781}
782
Yunchao Hea336b902017-08-02 16:05:21 +0800783GLuint Context::createProgramPipeline()
784{
785 return mState.mPipelines->createProgramPipeline();
786}
787
Jiawei Shao385b3e02018-03-21 09:43:28 +0800788GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800789{
790 UNIMPLEMENTED();
791 return 0u;
792}
793
James Darpinian4d9d4832018-03-13 12:43:28 -0700794void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000795{
James Darpinian4d9d4832018-03-13 12:43:28 -0700796 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
797 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000798 {
799 detachBuffer(buffer);
800 }
Jamie Madill893ab082014-05-16 16:56:10 -0400801
James Darpinian4d9d4832018-03-13 12:43:28 -0700802 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000803}
804
805void Context::deleteShader(GLuint shader)
806{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500807 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000808}
809
810void Context::deleteProgram(GLuint program)
811{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500812 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000813}
814
815void Context::deleteTexture(GLuint texture)
816{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500817 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000818 {
819 detachTexture(texture);
820 }
821
Jamie Madill6c1f6712017-02-14 19:08:04 -0500822 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000823}
824
825void Context::deleteRenderbuffer(GLuint renderbuffer)
826{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500827 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000828 {
829 detachRenderbuffer(renderbuffer);
830 }
Jamie Madill893ab082014-05-16 16:56:10 -0400831
Jamie Madill6c1f6712017-02-14 19:08:04 -0500832 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000833}
834
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400835void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400836{
837 // The spec specifies the underlying Fence object is not deleted until all current
838 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
839 // and since our API is currently designed for being called from a single thread, we can delete
840 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400841 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400842}
843
Yunchao Hea336b902017-08-02 16:05:21 +0800844void Context::deleteProgramPipeline(GLuint pipeline)
845{
846 if (mState.mPipelines->getProgramPipeline(pipeline))
847 {
848 detachProgramPipeline(pipeline);
849 }
850
851 mState.mPipelines->deleteObject(this, pipeline);
852}
853
Sami Väisänene45e53b2016-05-25 10:36:04 +0300854void Context::deletePaths(GLuint first, GLsizei range)
855{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500856 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300857}
858
Brandon Jones59770802018-04-02 13:18:42 -0700859bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300860{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500861 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300862 if (pathObj == nullptr)
863 return false;
864
865 return pathObj->hasPathData();
866}
867
Brandon Jones59770802018-04-02 13:18:42 -0700868bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300869{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500870 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300871}
872
Brandon Jones59770802018-04-02 13:18:42 -0700873void Context::pathCommands(GLuint path,
874 GLsizei numCommands,
875 const GLubyte *commands,
876 GLsizei numCoords,
877 GLenum coordType,
878 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300879{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500880 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300881
882 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
883}
884
Jamie Madill007530e2017-12-28 14:27:04 -0500885void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300886{
Jamie Madill007530e2017-12-28 14:27:04 -0500887 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300888
889 switch (pname)
890 {
891 case GL_PATH_STROKE_WIDTH_CHROMIUM:
892 pathObj->setStrokeWidth(value);
893 break;
894 case GL_PATH_END_CAPS_CHROMIUM:
895 pathObj->setEndCaps(static_cast<GLenum>(value));
896 break;
897 case GL_PATH_JOIN_STYLE_CHROMIUM:
898 pathObj->setJoinStyle(static_cast<GLenum>(value));
899 break;
900 case GL_PATH_MITER_LIMIT_CHROMIUM:
901 pathObj->setMiterLimit(value);
902 break;
903 case GL_PATH_STROKE_BOUND_CHROMIUM:
904 pathObj->setStrokeBound(value);
905 break;
906 default:
907 UNREACHABLE();
908 break;
909 }
910}
911
Jamie Madill007530e2017-12-28 14:27:04 -0500912void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300913{
Jamie Madill007530e2017-12-28 14:27:04 -0500914 // TODO(jmadill): Should use proper clamping/casting.
915 pathParameterf(path, pname, static_cast<GLfloat>(value));
916}
917
918void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
919{
920 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300921
922 switch (pname)
923 {
924 case GL_PATH_STROKE_WIDTH_CHROMIUM:
925 *value = pathObj->getStrokeWidth();
926 break;
927 case GL_PATH_END_CAPS_CHROMIUM:
928 *value = static_cast<GLfloat>(pathObj->getEndCaps());
929 break;
930 case GL_PATH_JOIN_STYLE_CHROMIUM:
931 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
932 break;
933 case GL_PATH_MITER_LIMIT_CHROMIUM:
934 *value = pathObj->getMiterLimit();
935 break;
936 case GL_PATH_STROKE_BOUND_CHROMIUM:
937 *value = pathObj->getStrokeBound();
938 break;
939 default:
940 UNREACHABLE();
941 break;
942 }
943}
944
Jamie Madill007530e2017-12-28 14:27:04 -0500945void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
946{
947 GLfloat val = 0.0f;
948 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
949 if (value)
950 *value = static_cast<GLint>(val);
951}
952
Brandon Jones59770802018-04-02 13:18:42 -0700953void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300954{
955 mGLState.setPathStencilFunc(func, ref, mask);
956}
957
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000958void Context::deleteFramebuffer(GLuint framebuffer)
959{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500960 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000961 {
962 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000963 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500964
Jamie Madill6c1f6712017-02-14 19:08:04 -0500965 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000966}
967
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500968void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000969{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500970 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000971 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500972 GLuint fence = fences[i];
973
974 FenceNV *fenceObject = nullptr;
975 if (mFenceNVMap.erase(fence, &fenceObject))
976 {
977 mFenceNVHandleAllocator.release(fence);
978 delete fenceObject;
979 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000980 }
981}
982
Geoff Lang70d0f492015-12-10 17:45:46 -0500983Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000984{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500985 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000986}
987
Geoff Lang70d0f492015-12-10 17:45:46 -0500988Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000989{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500990 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000991}
992
Jamie Madill70b5bb02017-08-28 13:32:37 -0400993Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400994{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400995 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400996}
997
Jamie Madill57a89722013-07-02 11:57:03 -0400998VertexArray *Context::getVertexArray(GLuint handle) const
999{
Jamie Madill96a483b2017-06-27 16:49:21 -04001000 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -04001001}
1002
Jamie Madilldc356042013-07-19 16:36:57 -04001003Sampler *Context::getSampler(GLuint handle) const
1004{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001005 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -04001006}
1007
Geoff Langc8058452014-02-03 12:04:11 -05001008TransformFeedback *Context::getTransformFeedback(GLuint handle) const
1009{
Jamie Madill96a483b2017-06-27 16:49:21 -04001010 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -05001011}
1012
Yunchao Hea336b902017-08-02 16:05:21 +08001013ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
1014{
1015 return mState.mPipelines->getProgramPipeline(handle);
1016}
1017
Geoff Lang75359662018-04-11 01:42:27 -04001018gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001019{
1020 switch (identifier)
1021 {
1022 case GL_BUFFER:
1023 return getBuffer(name);
1024 case GL_SHADER:
1025 return getShader(name);
1026 case GL_PROGRAM:
Jamie Madill44a6fbf2018-10-02 13:38:56 -04001027 return getProgramNoResolveLink(name);
Geoff Lang70d0f492015-12-10 17:45:46 -05001028 case GL_VERTEX_ARRAY:
1029 return getVertexArray(name);
1030 case GL_QUERY:
1031 return getQuery(name);
1032 case GL_TRANSFORM_FEEDBACK:
1033 return getTransformFeedback(name);
1034 case GL_SAMPLER:
1035 return getSampler(name);
1036 case GL_TEXTURE:
1037 return getTexture(name);
1038 case GL_RENDERBUFFER:
1039 return getRenderbuffer(name);
1040 case GL_FRAMEBUFFER:
1041 return getFramebuffer(name);
1042 default:
1043 UNREACHABLE();
1044 return nullptr;
1045 }
1046}
1047
Geoff Lang75359662018-04-11 01:42:27 -04001048gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001049{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001050 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001051}
1052
Martin Radev9d901792016-07-15 15:58:58 +03001053void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1054{
Geoff Lang75359662018-04-11 01:42:27 -04001055 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001056 ASSERT(object != nullptr);
1057
1058 std::string labelName = GetObjectLabelFromPointer(length, label);
1059 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001060
1061 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1062 // specified object is active until we do this.
1063 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001064}
1065
1066void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1067{
Geoff Lang75359662018-04-11 01:42:27 -04001068 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001069 ASSERT(object != nullptr);
1070
1071 std::string labelName = GetObjectLabelFromPointer(length, label);
1072 object->setLabel(labelName);
1073}
1074
1075void Context::getObjectLabel(GLenum identifier,
1076 GLuint name,
1077 GLsizei bufSize,
1078 GLsizei *length,
1079 GLchar *label) const
1080{
Geoff Lang75359662018-04-11 01:42:27 -04001081 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001082 ASSERT(object != nullptr);
1083
1084 const std::string &objectLabel = object->getLabel();
1085 GetObjectLabelBase(objectLabel, bufSize, length, label);
1086}
1087
1088void Context::getObjectPtrLabel(const void *ptr,
1089 GLsizei bufSize,
1090 GLsizei *length,
1091 GLchar *label) const
1092{
Geoff Lang75359662018-04-11 01:42:27 -04001093 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001094 ASSERT(object != nullptr);
1095
1096 const std::string &objectLabel = object->getLabel();
1097 GetObjectLabelBase(objectLabel, bufSize, length, label);
1098}
1099
Jamie Madilldc356042013-07-19 16:36:57 -04001100bool Context::isSampler(GLuint samplerName) const
1101{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001102 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001103}
1104
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001105void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001106{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001107 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001108
Jamie Madilldedd7b92014-11-05 16:30:36 -05001109 if (handle == 0)
1110 {
1111 texture = mZeroTextures[target].get();
1112 }
1113 else
1114 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001115 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001116 }
1117
1118 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001119 mGLState.setSamplerTexture(this, target, texture);
Jamie Madilld84b6732018-09-06 15:54:35 -04001120 mStateCache.onActiveTextureChange(this);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001121}
1122
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001123void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001124{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001125 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1126 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001127 mGLState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001128 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001129}
1130
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001131void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001132{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001133 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1134 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001135 mGLState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001136 mDrawFramebufferObserverBinding.bind(framebuffer);
Jamie Madilld84b6732018-09-06 15:54:35 -04001137 mStateCache.onDrawFramebufferChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001138}
1139
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001140void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001141{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001142 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001143 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001144 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001145 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001146}
1147
Shao80957d92017-02-20 21:25:59 +08001148void Context::bindVertexBuffer(GLuint bindingIndex,
1149 GLuint bufferHandle,
1150 GLintptr offset,
1151 GLsizei stride)
1152{
1153 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001154 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001155 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001156}
1157
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001158void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001159{
Geoff Lang76b10c92014-09-05 16:28:14 -04001160 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001161 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001162 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001163 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04001164 mSamplerObserverBindings[textureUnit].bind(sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001165}
1166
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001167void Context::bindImageTexture(GLuint unit,
1168 GLuint texture,
1169 GLint level,
1170 GLboolean layered,
1171 GLint layer,
1172 GLenum access,
1173 GLenum format)
1174{
1175 Texture *tex = mState.mTextures->getTexture(texture);
1176 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1177}
1178
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001179void Context::useProgram(GLuint program)
1180{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04001181 mGLState.setProgram(this, getProgramResolveLink(program));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001182 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001183}
1184
Jiajia Qin5451d532017-11-16 17:16:34 +08001185void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1186{
1187 UNIMPLEMENTED();
1188}
1189
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001190void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001191{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001192 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001193 TransformFeedback *transformFeedback =
1194 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001195 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Jamie Madilld84b6732018-09-06 15:54:35 -04001196 mStateCache.onTransformFeedbackChange(this);
Geoff Langc8058452014-02-03 12:04:11 -05001197}
1198
Yunchao Hea336b902017-08-02 16:05:21 +08001199void Context::bindProgramPipeline(GLuint pipelineHandle)
1200{
1201 ProgramPipeline *pipeline =
1202 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1203 mGLState.setProgramPipelineBinding(this, pipeline);
1204}
1205
Corentin Wallezad3ae902018-03-09 13:40:42 -05001206void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001207{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001208 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001209 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001210
Geoff Lang5aad9672014-09-08 11:10:42 -04001211 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001212 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001213
1214 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001215 mGLState.setActiveQuery(this, target, queryObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04001216 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001217}
1218
Corentin Wallezad3ae902018-03-09 13:40:42 -05001219void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001220{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001221 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001222 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001223
Jamie Madill5188a272018-07-25 10:53:56 -04001224 handleError(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001225
Geoff Lang5aad9672014-09-08 11:10:42 -04001226 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001227 mGLState.setActiveQuery(this, target, nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04001228 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001229}
1230
Corentin Wallezad3ae902018-03-09 13:40:42 -05001231void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001232{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001233 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001234
1235 Query *queryObject = getQuery(id, true, target);
1236 ASSERT(queryObject);
1237
Jamie Madill5188a272018-07-25 10:53:56 -04001238 handleError(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001239}
1240
Corentin Wallezad3ae902018-03-09 13:40:42 -05001241void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001242{
1243 switch (pname)
1244 {
1245 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001246 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001247 break;
1248 case GL_QUERY_COUNTER_BITS_EXT:
1249 switch (target)
1250 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001251 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001252 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1253 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001254 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001255 params[0] = getExtensions().queryCounterBitsTimestamp;
1256 break;
1257 default:
1258 UNREACHABLE();
1259 params[0] = 0;
1260 break;
1261 }
1262 break;
1263 default:
1264 UNREACHABLE();
1265 return;
1266 }
1267}
1268
Corentin Wallezad3ae902018-03-09 13:40:42 -05001269void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001270 GLenum pname,
1271 GLsizei bufSize,
1272 GLsizei *length,
1273 GLint *params)
1274{
1275 getQueryiv(target, pname, params);
1276}
1277
Geoff Lang2186c382016-10-14 10:54:54 -04001278void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001279{
Jamie Madill5188a272018-07-25 10:53:56 -04001280 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001281}
1282
Brandon Jones59770802018-04-02 13:18:42 -07001283void Context::getQueryObjectivRobust(GLuint id,
1284 GLenum pname,
1285 GLsizei bufSize,
1286 GLsizei *length,
1287 GLint *params)
1288{
1289 getQueryObjectiv(id, pname, params);
1290}
1291
Geoff Lang2186c382016-10-14 10:54:54 -04001292void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001293{
Jamie Madill5188a272018-07-25 10:53:56 -04001294 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001295}
1296
Brandon Jones59770802018-04-02 13:18:42 -07001297void Context::getQueryObjectuivRobust(GLuint id,
1298 GLenum pname,
1299 GLsizei bufSize,
1300 GLsizei *length,
1301 GLuint *params)
1302{
1303 getQueryObjectuiv(id, pname, params);
1304}
1305
Geoff Lang2186c382016-10-14 10:54:54 -04001306void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001307{
Jamie Madill5188a272018-07-25 10:53:56 -04001308 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001309}
1310
Brandon Jones59770802018-04-02 13:18:42 -07001311void Context::getQueryObjecti64vRobust(GLuint id,
1312 GLenum pname,
1313 GLsizei bufSize,
1314 GLsizei *length,
1315 GLint64 *params)
1316{
1317 getQueryObjecti64v(id, pname, params);
1318}
1319
Geoff Lang2186c382016-10-14 10:54:54 -04001320void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001321{
Jamie Madill5188a272018-07-25 10:53:56 -04001322 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001323}
1324
Brandon Jones59770802018-04-02 13:18:42 -07001325void Context::getQueryObjectui64vRobust(GLuint id,
1326 GLenum pname,
1327 GLsizei bufSize,
1328 GLsizei *length,
1329 GLuint64 *params)
1330{
1331 getQueryObjectui64v(id, pname, params);
1332}
1333
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001334Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001335{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001336 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001337}
1338
Jamie Madill2f348d22017-06-05 10:50:59 -04001339FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001340{
Jamie Madill96a483b2017-06-27 16:49:21 -04001341 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001342}
1343
Corentin Wallezad3ae902018-03-09 13:40:42 -05001344Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001345{
Jamie Madill96a483b2017-06-27 16:49:21 -04001346 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001347 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001348 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001349 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001350
1351 Query *query = mQueryMap.query(handle);
1352 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001353 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001354 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001355 query = new Query(mImplementation->createQuery(type), handle);
1356 query->addRef();
1357 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001358 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001359 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001360}
1361
Geoff Lang70d0f492015-12-10 17:45:46 -05001362Query *Context::getQuery(GLuint handle) const
1363{
Jamie Madill96a483b2017-06-27 16:49:21 -04001364 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001365}
1366
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001367Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001368{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001369 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1370 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001371}
1372
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001373Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001374{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001375 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001376}
1377
Geoff Lang492a7e42014-11-05 13:27:06 -05001378Compiler *Context::getCompiler() const
1379{
Jamie Madill2f348d22017-06-05 10:50:59 -04001380 if (mCompiler.get() == nullptr)
1381 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001382 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001383 }
1384 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001385}
1386
Jamie Madillc1d770e2017-04-13 17:31:24 -04001387void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001388{
1389 switch (pname)
1390 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001391 case GL_SHADER_COMPILER:
1392 *params = GL_TRUE;
1393 break;
1394 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1395 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1396 break;
1397 default:
1398 mGLState.getBooleanv(pname, params);
1399 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001400 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001401}
1402
Jamie Madillc1d770e2017-04-13 17:31:24 -04001403void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001404{
Shannon Woods53a94a82014-06-24 15:20:36 -04001405 // Queries about context capabilities and maximums are answered by Context.
1406 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001407 switch (pname)
1408 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001409 case GL_ALIASED_LINE_WIDTH_RANGE:
1410 params[0] = mCaps.minAliasedLineWidth;
1411 params[1] = mCaps.maxAliasedLineWidth;
1412 break;
1413 case GL_ALIASED_POINT_SIZE_RANGE:
1414 params[0] = mCaps.minAliasedPointSize;
1415 params[1] = mCaps.maxAliasedPointSize;
1416 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001417 case GL_SMOOTH_POINT_SIZE_RANGE:
1418 params[0] = mCaps.minSmoothPointSize;
1419 params[1] = mCaps.maxSmoothPointSize;
1420 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001421 case GL_SMOOTH_LINE_WIDTH_RANGE:
1422 params[0] = mCaps.minSmoothLineWidth;
1423 params[1] = mCaps.maxSmoothLineWidth;
1424 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001425 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1426 ASSERT(mExtensions.textureFilterAnisotropic);
1427 *params = mExtensions.maxTextureAnisotropy;
1428 break;
1429 case GL_MAX_TEXTURE_LOD_BIAS:
1430 *params = mCaps.maxLODBias;
1431 break;
1432
1433 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1434 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1435 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001436 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1437 // GLES1 constants for modelview/projection matrix.
1438 if (getClientVersion() < Version(2, 0))
1439 {
1440 mGLState.getFloatv(pname, params);
1441 }
1442 else
1443 {
1444 ASSERT(mExtensions.pathRendering);
1445 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1446 memcpy(params, m, 16 * sizeof(GLfloat));
1447 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001448 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001449 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001450
Jamie Madill231c7f52017-04-26 13:45:37 -04001451 default:
1452 mGLState.getFloatv(pname, params);
1453 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001454 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001455}
1456
Jamie Madillc1d770e2017-04-13 17:31:24 -04001457void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001458{
Shannon Woods53a94a82014-06-24 15:20:36 -04001459 // Queries about context capabilities and maximums are answered by Context.
1460 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001461
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001462 switch (pname)
1463 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001464 case GL_MAX_VERTEX_ATTRIBS:
1465 *params = mCaps.maxVertexAttributes;
1466 break;
1467 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1468 *params = mCaps.maxVertexUniformVectors;
1469 break;
1470 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001471 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001472 break;
1473 case GL_MAX_VARYING_VECTORS:
1474 *params = mCaps.maxVaryingVectors;
1475 break;
1476 case GL_MAX_VARYING_COMPONENTS:
1477 *params = mCaps.maxVertexOutputComponents;
1478 break;
1479 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1480 *params = mCaps.maxCombinedTextureImageUnits;
1481 break;
1482 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001483 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001484 break;
1485 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001486 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001487 break;
1488 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1489 *params = mCaps.maxFragmentUniformVectors;
1490 break;
1491 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001492 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001493 break;
1494 case GL_MAX_RENDERBUFFER_SIZE:
1495 *params = mCaps.maxRenderbufferSize;
1496 break;
1497 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1498 *params = mCaps.maxColorAttachments;
1499 break;
1500 case GL_MAX_DRAW_BUFFERS_EXT:
1501 *params = mCaps.maxDrawBuffers;
1502 break;
1503 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1504 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1505 case GL_SUBPIXEL_BITS:
1506 *params = 4;
1507 break;
1508 case GL_MAX_TEXTURE_SIZE:
1509 *params = mCaps.max2DTextureSize;
1510 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001511 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1512 *params = mCaps.maxRectangleTextureSize;
1513 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001514 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1515 *params = mCaps.maxCubeMapTextureSize;
1516 break;
1517 case GL_MAX_3D_TEXTURE_SIZE:
1518 *params = mCaps.max3DTextureSize;
1519 break;
1520 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1521 *params = mCaps.maxArrayTextureLayers;
1522 break;
1523 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1524 *params = mCaps.uniformBufferOffsetAlignment;
1525 break;
1526 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1527 *params = mCaps.maxUniformBufferBindings;
1528 break;
1529 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001530 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001531 break;
1532 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001533 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001534 break;
1535 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1536 *params = mCaps.maxCombinedTextureImageUnits;
1537 break;
1538 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1539 *params = mCaps.maxVertexOutputComponents;
1540 break;
1541 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1542 *params = mCaps.maxFragmentInputComponents;
1543 break;
1544 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1545 *params = mCaps.minProgramTexelOffset;
1546 break;
1547 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1548 *params = mCaps.maxProgramTexelOffset;
1549 break;
1550 case GL_MAJOR_VERSION:
1551 *params = getClientVersion().major;
1552 break;
1553 case GL_MINOR_VERSION:
1554 *params = getClientVersion().minor;
1555 break;
1556 case GL_MAX_ELEMENTS_INDICES:
1557 *params = mCaps.maxElementsIndices;
1558 break;
1559 case GL_MAX_ELEMENTS_VERTICES:
1560 *params = mCaps.maxElementsVertices;
1561 break;
1562 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1563 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1564 break;
1565 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1566 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1567 break;
1568 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1569 *params = mCaps.maxTransformFeedbackSeparateComponents;
1570 break;
1571 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1572 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1573 break;
1574 case GL_MAX_SAMPLES_ANGLE:
1575 *params = mCaps.maxSamples;
1576 break;
1577 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001578 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001579 params[0] = mCaps.maxViewportWidth;
1580 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001581 }
1582 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001583 case GL_COMPRESSED_TEXTURE_FORMATS:
1584 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1585 params);
1586 break;
1587 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1588 *params = mResetStrategy;
1589 break;
1590 case GL_NUM_SHADER_BINARY_FORMATS:
1591 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1592 break;
1593 case GL_SHADER_BINARY_FORMATS:
1594 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1595 break;
1596 case GL_NUM_PROGRAM_BINARY_FORMATS:
1597 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1598 break;
1599 case GL_PROGRAM_BINARY_FORMATS:
1600 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1601 break;
1602 case GL_NUM_EXTENSIONS:
1603 *params = static_cast<GLint>(mExtensionStrings.size());
1604 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001605
Geoff Lang38f24ee2018-10-01 13:04:59 -04001606 // GL_ANGLE_request_extension
1607 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
1608 *params = static_cast<GLint>(mRequestableExtensionStrings.size());
1609 break;
1610
Jamie Madill231c7f52017-04-26 13:45:37 -04001611 // GL_KHR_debug
1612 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1613 *params = mExtensions.maxDebugMessageLength;
1614 break;
1615 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1616 *params = mExtensions.maxDebugLoggedMessages;
1617 break;
1618 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1619 *params = mExtensions.maxDebugGroupStackDepth;
1620 break;
1621 case GL_MAX_LABEL_LENGTH:
1622 *params = mExtensions.maxLabelLength;
1623 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001624
Martin Radeve5285d22017-07-14 16:23:53 +03001625 // GL_ANGLE_multiview
1626 case GL_MAX_VIEWS_ANGLE:
1627 *params = mExtensions.maxViews;
1628 break;
1629
Jamie Madill231c7f52017-04-26 13:45:37 -04001630 // GL_EXT_disjoint_timer_query
1631 case GL_GPU_DISJOINT_EXT:
1632 *params = mImplementation->getGPUDisjoint();
1633 break;
1634 case GL_MAX_FRAMEBUFFER_WIDTH:
1635 *params = mCaps.maxFramebufferWidth;
1636 break;
1637 case GL_MAX_FRAMEBUFFER_HEIGHT:
1638 *params = mCaps.maxFramebufferHeight;
1639 break;
1640 case GL_MAX_FRAMEBUFFER_SAMPLES:
1641 *params = mCaps.maxFramebufferSamples;
1642 break;
1643 case GL_MAX_SAMPLE_MASK_WORDS:
1644 *params = mCaps.maxSampleMaskWords;
1645 break;
1646 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1647 *params = mCaps.maxColorTextureSamples;
1648 break;
1649 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1650 *params = mCaps.maxDepthTextureSamples;
1651 break;
1652 case GL_MAX_INTEGER_SAMPLES:
1653 *params = mCaps.maxIntegerSamples;
1654 break;
1655 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1656 *params = mCaps.maxVertexAttribRelativeOffset;
1657 break;
1658 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1659 *params = mCaps.maxVertexAttribBindings;
1660 break;
1661 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1662 *params = mCaps.maxVertexAttribStride;
1663 break;
1664 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001665 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001666 break;
1667 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001668 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001669 break;
1670 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001671 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001672 break;
1673 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001674 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001675 break;
1676 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001677 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001678 break;
1679 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001680 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001681 break;
1682 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001683 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001684 break;
1685 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001686 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001687 break;
1688 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1689 *params = mCaps.minProgramTextureGatherOffset;
1690 break;
1691 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1692 *params = mCaps.maxProgramTextureGatherOffset;
1693 break;
1694 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1695 *params = mCaps.maxComputeWorkGroupInvocations;
1696 break;
1697 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001698 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001699 break;
1700 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001701 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001702 break;
1703 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1704 *params = mCaps.maxComputeSharedMemorySize;
1705 break;
1706 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001707 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001708 break;
1709 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001710 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001711 break;
1712 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001713 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001714 break;
1715 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001716 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001717 break;
1718 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001719 *params =
1720 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001721 break;
1722 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001723 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001724 break;
1725 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1726 *params = mCaps.maxCombinedShaderOutputResources;
1727 break;
1728 case GL_MAX_UNIFORM_LOCATIONS:
1729 *params = mCaps.maxUniformLocations;
1730 break;
1731 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1732 *params = mCaps.maxAtomicCounterBufferBindings;
1733 break;
1734 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1735 *params = mCaps.maxAtomicCounterBufferSize;
1736 break;
1737 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1738 *params = mCaps.maxCombinedAtomicCounterBuffers;
1739 break;
1740 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1741 *params = mCaps.maxCombinedAtomicCounters;
1742 break;
1743 case GL_MAX_IMAGE_UNITS:
1744 *params = mCaps.maxImageUnits;
1745 break;
1746 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1747 *params = mCaps.maxCombinedImageUniforms;
1748 break;
1749 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1750 *params = mCaps.maxShaderStorageBufferBindings;
1751 break;
1752 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1753 *params = mCaps.maxCombinedShaderStorageBlocks;
1754 break;
1755 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1756 *params = mCaps.shaderStorageBufferOffsetAlignment;
1757 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001758
1759 // GL_EXT_geometry_shader
1760 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1761 *params = mCaps.maxFramebufferLayers;
1762 break;
1763 case GL_LAYER_PROVOKING_VERTEX_EXT:
1764 *params = mCaps.layerProvokingVertex;
1765 break;
1766 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001767 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001768 break;
1769 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001770 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001771 break;
1772 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001773 *params =
1774 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001775 break;
1776 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1777 *params = mCaps.maxGeometryInputComponents;
1778 break;
1779 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1780 *params = mCaps.maxGeometryOutputComponents;
1781 break;
1782 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1783 *params = mCaps.maxGeometryOutputVertices;
1784 break;
1785 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1786 *params = mCaps.maxGeometryTotalOutputComponents;
1787 break;
1788 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1789 *params = mCaps.maxGeometryShaderInvocations;
1790 break;
1791 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001792 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001793 break;
1794 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001795 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001796 break;
1797 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001798 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001799 break;
1800 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001801 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001802 break;
1803 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001804 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001805 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001806 // GLES1 emulation: Caps queries
1807 case GL_MAX_TEXTURE_UNITS:
1808 *params = mCaps.maxMultitextureUnits;
1809 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001810 case GL_MAX_MODELVIEW_STACK_DEPTH:
1811 *params = mCaps.maxModelviewMatrixStackDepth;
1812 break;
1813 case GL_MAX_PROJECTION_STACK_DEPTH:
1814 *params = mCaps.maxProjectionMatrixStackDepth;
1815 break;
1816 case GL_MAX_TEXTURE_STACK_DEPTH:
1817 *params = mCaps.maxTextureMatrixStackDepth;
1818 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001819 case GL_MAX_LIGHTS:
1820 *params = mCaps.maxLights;
1821 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001822 case GL_MAX_CLIP_PLANES:
1823 *params = mCaps.maxClipPlanes;
1824 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001825 // GLES1 emulation: Vertex attribute queries
1826 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1827 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1828 case GL_COLOR_ARRAY_BUFFER_BINDING:
1829 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1830 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1831 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1832 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1833 break;
1834 case GL_VERTEX_ARRAY_STRIDE:
1835 case GL_NORMAL_ARRAY_STRIDE:
1836 case GL_COLOR_ARRAY_STRIDE:
1837 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1838 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1839 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1840 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1841 break;
1842 case GL_VERTEX_ARRAY_SIZE:
1843 case GL_COLOR_ARRAY_SIZE:
1844 case GL_TEXTURE_COORD_ARRAY_SIZE:
1845 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1846 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1847 break;
1848 case GL_VERTEX_ARRAY_TYPE:
1849 case GL_COLOR_ARRAY_TYPE:
1850 case GL_NORMAL_ARRAY_TYPE:
1851 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1852 case GL_TEXTURE_COORD_ARRAY_TYPE:
1853 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1854 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1855 break;
1856
jchen1082af6202018-06-22 10:59:52 +08001857 // GL_KHR_parallel_shader_compile
1858 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1859 *params = mGLState.getMaxShaderCompilerThreads();
1860 break;
1861
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001862 // GL_EXT_blend_func_extended
1863 case GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT:
1864 *params = mExtensions.maxDualSourceDrawBuffers;
1865 break;
1866
Jamie Madill231c7f52017-04-26 13:45:37 -04001867 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001868 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001869 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001870 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001871}
1872
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001873void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001874{
Shannon Woods53a94a82014-06-24 15:20:36 -04001875 // Queries about context capabilities and maximums are answered by Context.
1876 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001877 switch (pname)
1878 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001879 case GL_MAX_ELEMENT_INDEX:
1880 *params = mCaps.maxElementIndex;
1881 break;
1882 case GL_MAX_UNIFORM_BLOCK_SIZE:
1883 *params = mCaps.maxUniformBlockSize;
1884 break;
1885 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001886 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001887 break;
1888 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001889 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001890 break;
1891 case GL_MAX_SERVER_WAIT_TIMEOUT:
1892 *params = mCaps.maxServerWaitTimeout;
1893 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001894
Jamie Madill231c7f52017-04-26 13:45:37 -04001895 // GL_EXT_disjoint_timer_query
1896 case GL_TIMESTAMP_EXT:
1897 *params = mImplementation->getTimestamp();
1898 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001899
Jamie Madill231c7f52017-04-26 13:45:37 -04001900 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1901 *params = mCaps.maxShaderStorageBlockSize;
1902 break;
1903 default:
1904 UNREACHABLE();
1905 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001906 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001907}
1908
Geoff Lang70d0f492015-12-10 17:45:46 -05001909void Context::getPointerv(GLenum pname, void **params) const
1910{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001911 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001912}
1913
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001914void Context::getPointervRobustANGLERobust(GLenum pname,
1915 GLsizei bufSize,
1916 GLsizei *length,
1917 void **params)
1918{
1919 UNIMPLEMENTED();
1920}
1921
Martin Radev66fb8202016-07-28 11:45:20 +03001922void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001923{
Shannon Woods53a94a82014-06-24 15:20:36 -04001924 // Queries about context capabilities and maximums are answered by Context.
1925 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001926
1927 GLenum nativeType;
1928 unsigned int numParams;
1929 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1930 ASSERT(queryStatus);
1931
1932 if (nativeType == GL_INT)
1933 {
1934 switch (target)
1935 {
1936 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1937 ASSERT(index < 3u);
1938 *data = mCaps.maxComputeWorkGroupCount[index];
1939 break;
1940 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1941 ASSERT(index < 3u);
1942 *data = mCaps.maxComputeWorkGroupSize[index];
1943 break;
1944 default:
1945 mGLState.getIntegeri_v(target, index, data);
1946 }
1947 }
1948 else
1949 {
1950 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1951 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001952}
1953
Brandon Jones59770802018-04-02 13:18:42 -07001954void Context::getIntegeri_vRobust(GLenum target,
1955 GLuint index,
1956 GLsizei bufSize,
1957 GLsizei *length,
1958 GLint *data)
1959{
1960 getIntegeri_v(target, index, data);
1961}
1962
Martin Radev66fb8202016-07-28 11:45:20 +03001963void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001964{
Shannon Woods53a94a82014-06-24 15:20:36 -04001965 // Queries about context capabilities and maximums are answered by Context.
1966 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001967
1968 GLenum nativeType;
1969 unsigned int numParams;
1970 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1971 ASSERT(queryStatus);
1972
1973 if (nativeType == GL_INT_64_ANGLEX)
1974 {
1975 mGLState.getInteger64i_v(target, index, data);
1976 }
1977 else
1978 {
1979 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1980 }
1981}
1982
Brandon Jones59770802018-04-02 13:18:42 -07001983void Context::getInteger64i_vRobust(GLenum target,
1984 GLuint index,
1985 GLsizei bufSize,
1986 GLsizei *length,
1987 GLint64 *data)
1988{
1989 getInteger64i_v(target, index, data);
1990}
1991
Martin Radev66fb8202016-07-28 11:45:20 +03001992void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1993{
1994 // Queries about context capabilities and maximums are answered by Context.
1995 // Queries about current GL state values are answered by State.
1996
1997 GLenum nativeType;
1998 unsigned int numParams;
1999 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
2000 ASSERT(queryStatus);
2001
2002 if (nativeType == GL_BOOL)
2003 {
2004 mGLState.getBooleani_v(target, index, data);
2005 }
2006 else
2007 {
2008 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
2009 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04002010}
2011
Brandon Jones59770802018-04-02 13:18:42 -07002012void Context::getBooleani_vRobust(GLenum target,
2013 GLuint index,
2014 GLsizei bufSize,
2015 GLsizei *length,
2016 GLboolean *data)
2017{
2018 getBooleani_v(target, index, data);
2019}
2020
Corentin Wallez336129f2017-10-17 15:55:40 -04002021void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002022{
2023 Buffer *buffer = mGLState.getTargetBuffer(target);
2024 QueryBufferParameteriv(buffer, pname, params);
2025}
2026
Brandon Jones59770802018-04-02 13:18:42 -07002027void Context::getBufferParameterivRobust(BufferBinding target,
2028 GLenum pname,
2029 GLsizei bufSize,
2030 GLsizei *length,
2031 GLint *params)
2032{
2033 getBufferParameteriv(target, pname, params);
2034}
2035
He Yunchao010e4db2017-03-03 14:22:06 +08002036void Context::getFramebufferAttachmentParameteriv(GLenum target,
2037 GLenum attachment,
2038 GLenum pname,
2039 GLint *params)
2040{
2041 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002042 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002043}
2044
Brandon Jones59770802018-04-02 13:18:42 -07002045void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2046 GLenum attachment,
2047 GLenum pname,
2048 GLsizei bufSize,
2049 GLsizei *length,
2050 GLint *params)
2051{
2052 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2053}
2054
He Yunchao010e4db2017-03-03 14:22:06 +08002055void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2056{
2057 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2058 QueryRenderbufferiv(this, renderbuffer, pname, params);
2059}
2060
Brandon Jones59770802018-04-02 13:18:42 -07002061void Context::getRenderbufferParameterivRobust(GLenum target,
2062 GLenum pname,
2063 GLsizei bufSize,
2064 GLsizei *length,
2065 GLint *params)
2066{
2067 getRenderbufferParameteriv(target, pname, params);
2068}
2069
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002070void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002071{
2072 Texture *texture = getTargetTexture(target);
2073 QueryTexParameterfv(texture, pname, params);
2074}
2075
Brandon Jones59770802018-04-02 13:18:42 -07002076void Context::getTexParameterfvRobust(TextureType target,
2077 GLenum pname,
2078 GLsizei bufSize,
2079 GLsizei *length,
2080 GLfloat *params)
2081{
2082 getTexParameterfv(target, pname, params);
2083}
2084
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002085void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002086{
2087 Texture *texture = getTargetTexture(target);
2088 QueryTexParameteriv(texture, pname, params);
2089}
Jiajia Qin5451d532017-11-16 17:16:34 +08002090
Brandon Jones59770802018-04-02 13:18:42 -07002091void Context::getTexParameterivRobust(TextureType target,
2092 GLenum pname,
2093 GLsizei bufSize,
2094 GLsizei *length,
2095 GLint *params)
2096{
2097 getTexParameteriv(target, pname, params);
2098}
2099
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002100void Context::getTexParameterIivRobust(TextureType target,
2101 GLenum pname,
2102 GLsizei bufSize,
2103 GLsizei *length,
2104 GLint *params)
2105{
2106 UNIMPLEMENTED();
2107}
2108
2109void Context::getTexParameterIuivRobust(TextureType target,
2110 GLenum pname,
2111 GLsizei bufSize,
2112 GLsizei *length,
2113 GLuint *params)
2114{
2115 UNIMPLEMENTED();
2116}
2117
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002118void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002119{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002120 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002121 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002122}
2123
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002124void Context::getTexLevelParameterivRobust(TextureTarget target,
2125 GLint level,
2126 GLenum pname,
2127 GLsizei bufSize,
2128 GLsizei *length,
2129 GLint *params)
2130{
2131 UNIMPLEMENTED();
2132}
2133
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002134void Context::getTexLevelParameterfv(TextureTarget target,
2135 GLint level,
2136 GLenum pname,
2137 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002138{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002139 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002140 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002141}
2142
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002143void Context::getTexLevelParameterfvRobust(TextureTarget target,
2144 GLint level,
2145 GLenum pname,
2146 GLsizei bufSize,
2147 GLsizei *length,
2148 GLfloat *params)
2149{
2150 UNIMPLEMENTED();
2151}
2152
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002153void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002154{
2155 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002156 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002157 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002158}
2159
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002160void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002161{
2162 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002163 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002164 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002165}
2166
Brandon Jones59770802018-04-02 13:18:42 -07002167void Context::texParameterfvRobust(TextureType target,
2168 GLenum pname,
2169 GLsizei bufSize,
2170 const GLfloat *params)
2171{
2172 texParameterfv(target, pname, params);
2173}
2174
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002175void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002176{
2177 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002178 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002179 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002180}
2181
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002182void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002183{
2184 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002185 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002186 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002187}
2188
Brandon Jones59770802018-04-02 13:18:42 -07002189void Context::texParameterivRobust(TextureType target,
2190 GLenum pname,
2191 GLsizei bufSize,
2192 const GLint *params)
2193{
2194 texParameteriv(target, pname, params);
2195}
2196
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002197void Context::texParameterIivRobust(TextureType target,
2198 GLenum pname,
2199 GLsizei bufSize,
2200 const GLint *params)
2201{
2202 UNIMPLEMENTED();
2203}
2204
2205void Context::texParameterIuivRobust(TextureType target,
2206 GLenum pname,
2207 GLsizei bufSize,
2208 const GLuint *params)
2209{
2210 UNIMPLEMENTED();
2211}
2212
Jamie Madill493f9572018-05-24 19:52:15 -04002213void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002214{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002215 // No-op if count draws no primitives for given mode
2216 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002217 {
2218 return;
2219 }
2220
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002221 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002222 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002223 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002224}
2225
Jamie Madill493f9572018-05-24 19:52:15 -04002226void Context::drawArraysInstanced(PrimitiveMode mode,
2227 GLint first,
2228 GLsizei count,
2229 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002230{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002231 // No-op if count draws no primitives for given mode
2232 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002233 {
2234 return;
2235 }
2236
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002237 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002238 ANGLE_CONTEXT_TRY(
2239 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002240 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2241 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002242}
2243
Jamie Madill493f9572018-05-24 19:52:15 -04002244void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002245{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002246 // No-op if count draws no primitives for given mode
2247 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002248 {
2249 return;
2250 }
2251
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002252 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002253 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002254}
2255
Jamie Madill493f9572018-05-24 19:52:15 -04002256void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002257 GLsizei count,
2258 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002259 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002260 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002261{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002262 // No-op if count draws no primitives for given mode
2263 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002264 {
2265 return;
2266 }
2267
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002268 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002269 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002270 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002271}
2272
Jamie Madill493f9572018-05-24 19:52:15 -04002273void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002274 GLuint start,
2275 GLuint end,
2276 GLsizei count,
2277 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002278 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002279{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002280 // No-op if count draws no primitives for given mode
2281 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002282 {
2283 return;
2284 }
2285
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002286 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002287 ANGLE_CONTEXT_TRY(
2288 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002289}
2290
Jamie Madill493f9572018-05-24 19:52:15 -04002291void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002292{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002293 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002294 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002295}
2296
Jamie Madill493f9572018-05-24 19:52:15 -04002297void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002298{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002299 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002300 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002301}
2302
Jamie Madill675fe712016-12-19 13:07:54 -05002303void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002304{
Jamie Madillafa02a22017-11-23 12:57:38 -05002305 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002306}
2307
Jamie Madill675fe712016-12-19 13:07:54 -05002308void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002309{
Jamie Madillafa02a22017-11-23 12:57:38 -05002310 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002311}
2312
Austin Kinross6ee1e782015-05-29 17:05:37 -07002313void Context::insertEventMarker(GLsizei length, const char *marker)
2314{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002315 ASSERT(mImplementation);
2316 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002317}
2318
2319void Context::pushGroupMarker(GLsizei length, const char *marker)
2320{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002321 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002322
2323 if (marker == nullptr)
2324 {
2325 // From the EXT_debug_marker spec,
2326 // "If <marker> is null then an empty string is pushed on the stack."
2327 mImplementation->pushGroupMarker(length, "");
2328 }
2329 else
2330 {
2331 mImplementation->pushGroupMarker(length, marker);
2332 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002333}
2334
2335void Context::popGroupMarker()
2336{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002337 ASSERT(mImplementation);
2338 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002339}
2340
Geoff Langd8605522016-04-13 10:19:12 -04002341void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2342{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002343 Program *programObject = getProgramResolveLink(program);
Geoff Langd8605522016-04-13 10:19:12 -04002344 ASSERT(programObject);
2345
2346 programObject->bindUniformLocation(location, name);
2347}
2348
Brandon Jones59770802018-04-02 13:18:42 -07002349void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002350{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002351 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002352}
2353
Brandon Jones59770802018-04-02 13:18:42 -07002354void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002355{
2356 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2357}
2358
Brandon Jones59770802018-04-02 13:18:42 -07002359void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002360{
2361 GLfloat I[16];
2362 angle::Matrix<GLfloat>::setToIdentity(I);
2363
2364 mGLState.loadPathRenderingMatrix(matrixMode, I);
2365}
2366
2367void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2368{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002369 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002370 if (!pathObj)
2371 return;
2372
Geoff Lang9bf86f02018-07-26 11:46:34 -04002373 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002374
2375 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2376}
2377
2378void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2379{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002380 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002381 if (!pathObj)
2382 return;
2383
Geoff Lang9bf86f02018-07-26 11:46:34 -04002384 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002385
2386 mImplementation->stencilStrokePath(pathObj, reference, mask);
2387}
2388
2389void Context::coverFillPath(GLuint path, GLenum coverMode)
2390{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002391 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002392 if (!pathObj)
2393 return;
2394
Geoff Lang9bf86f02018-07-26 11:46:34 -04002395 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002396
2397 mImplementation->coverFillPath(pathObj, coverMode);
2398}
2399
2400void Context::coverStrokePath(GLuint path, GLenum coverMode)
2401{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002402 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002403 if (!pathObj)
2404 return;
2405
Geoff Lang9bf86f02018-07-26 11:46:34 -04002406 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002407
2408 mImplementation->coverStrokePath(pathObj, coverMode);
2409}
2410
2411void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2412{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002413 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002414 if (!pathObj)
2415 return;
2416
Geoff Lang9bf86f02018-07-26 11:46:34 -04002417 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002418
2419 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2420}
2421
2422void Context::stencilThenCoverStrokePath(GLuint path,
2423 GLint reference,
2424 GLuint mask,
2425 GLenum coverMode)
2426{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002427 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002428 if (!pathObj)
2429 return;
2430
Geoff Lang9bf86f02018-07-26 11:46:34 -04002431 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002432
2433 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2434}
2435
Sami Väisänend59ca052016-06-21 16:10:00 +03002436void Context::coverFillPathInstanced(GLsizei numPaths,
2437 GLenum pathNameType,
2438 const void *paths,
2439 GLuint pathBase,
2440 GLenum coverMode,
2441 GLenum transformType,
2442 const GLfloat *transformValues)
2443{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002444 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002445
Geoff Lang9bf86f02018-07-26 11:46:34 -04002446 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002447
2448 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2449}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002450
Sami Väisänend59ca052016-06-21 16:10:00 +03002451void Context::coverStrokePathInstanced(GLsizei numPaths,
2452 GLenum pathNameType,
2453 const void *paths,
2454 GLuint pathBase,
2455 GLenum coverMode,
2456 GLenum transformType,
2457 const GLfloat *transformValues)
2458{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002459 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002460
2461 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002462 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002463
2464 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2465 transformValues);
2466}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002467
Sami Väisänend59ca052016-06-21 16:10:00 +03002468void Context::stencilFillPathInstanced(GLsizei numPaths,
2469 GLenum pathNameType,
2470 const void *paths,
2471 GLuint pathBase,
2472 GLenum fillMode,
2473 GLuint mask,
2474 GLenum transformType,
2475 const GLfloat *transformValues)
2476{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002477 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002478
2479 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002480 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002481
2482 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2483 transformValues);
2484}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002485
Sami Väisänend59ca052016-06-21 16:10:00 +03002486void Context::stencilStrokePathInstanced(GLsizei numPaths,
2487 GLenum pathNameType,
2488 const void *paths,
2489 GLuint pathBase,
2490 GLint reference,
2491 GLuint mask,
2492 GLenum transformType,
2493 const GLfloat *transformValues)
2494{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002495 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002496
Geoff Lang9bf86f02018-07-26 11:46:34 -04002497 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002498
2499 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2500 transformValues);
2501}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002502
Sami Väisänend59ca052016-06-21 16:10:00 +03002503void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2504 GLenum pathNameType,
2505 const void *paths,
2506 GLuint pathBase,
2507 GLenum fillMode,
2508 GLuint mask,
2509 GLenum coverMode,
2510 GLenum transformType,
2511 const GLfloat *transformValues)
2512{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002513 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002514
Geoff Lang9bf86f02018-07-26 11:46:34 -04002515 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002516
2517 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2518 transformType, transformValues);
2519}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002520
Sami Väisänend59ca052016-06-21 16:10:00 +03002521void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2522 GLenum pathNameType,
2523 const void *paths,
2524 GLuint pathBase,
2525 GLint reference,
2526 GLuint mask,
2527 GLenum coverMode,
2528 GLenum transformType,
2529 const GLfloat *transformValues)
2530{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002531 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002532
Geoff Lang9bf86f02018-07-26 11:46:34 -04002533 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002534
2535 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2536 transformType, transformValues);
2537}
2538
Sami Väisänen46eaa942016-06-29 10:26:37 +03002539void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2540{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002541 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002542
2543 programObject->bindFragmentInputLocation(location, name);
2544}
2545
2546void Context::programPathFragmentInputGen(GLuint program,
2547 GLint location,
2548 GLenum genMode,
2549 GLint components,
2550 const GLfloat *coeffs)
2551{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002552 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002553
jchen103fd614d2018-08-13 12:21:58 +08002554 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002555}
2556
jchen1015015f72017-03-16 13:54:21 +08002557GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2558{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002559 const Program *programObject = getProgramResolveLink(program);
jchen1015015f72017-03-16 13:54:21 +08002560 return QueryProgramResourceIndex(programObject, programInterface, name);
2561}
2562
jchen10fd7c3b52017-03-21 15:36:03 +08002563void Context::getProgramResourceName(GLuint program,
2564 GLenum programInterface,
2565 GLuint index,
2566 GLsizei bufSize,
2567 GLsizei *length,
2568 GLchar *name)
2569{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002570 const Program *programObject = getProgramResolveLink(program);
jchen10fd7c3b52017-03-21 15:36:03 +08002571 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2572}
2573
jchen10191381f2017-04-11 13:59:04 +08002574GLint Context::getProgramResourceLocation(GLuint program,
2575 GLenum programInterface,
2576 const GLchar *name)
2577{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002578 const Program *programObject = getProgramResolveLink(program);
jchen10191381f2017-04-11 13:59:04 +08002579 return QueryProgramResourceLocation(programObject, programInterface, name);
2580}
2581
jchen10880683b2017-04-12 16:21:55 +08002582void Context::getProgramResourceiv(GLuint program,
2583 GLenum programInterface,
2584 GLuint index,
2585 GLsizei propCount,
2586 const GLenum *props,
2587 GLsizei bufSize,
2588 GLsizei *length,
2589 GLint *params)
2590{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002591 const Program *programObject = getProgramResolveLink(program);
jchen10880683b2017-04-12 16:21:55 +08002592 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2593 length, params);
2594}
2595
jchen10d9cd7b72017-08-30 15:04:25 +08002596void Context::getProgramInterfaceiv(GLuint program,
2597 GLenum programInterface,
2598 GLenum pname,
2599 GLint *params)
2600{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002601 const Program *programObject = getProgramResolveLink(program);
jchen10d9cd7b72017-08-30 15:04:25 +08002602 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2603}
2604
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002605void Context::getProgramInterfaceivRobust(GLuint program,
2606 GLenum programInterface,
2607 GLenum pname,
2608 GLsizei bufSize,
2609 GLsizei *length,
2610 GLint *params)
2611{
2612 UNIMPLEMENTED();
2613}
2614
Jamie Madill306b6c12018-07-27 08:12:49 -04002615void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002616{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002617 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002618}
2619
2620// Get one of the recorded errors and clear its flag, if any.
2621// [OpenGL ES 2.0.24] section 2.5 page 13.
2622GLenum Context::getError()
2623{
Geoff Langda5777c2014-07-11 09:52:58 -04002624 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002625 {
Geoff Langda5777c2014-07-11 09:52:58 -04002626 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002627 }
Geoff Langda5777c2014-07-11 09:52:58 -04002628 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002629 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002630 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002631 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002632}
2633
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002634// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002635void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002636{
2637 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002638 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002639 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002640 mContextLostForced = true;
2641 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002642 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002643}
2644
Jamie Madillfa920eb2018-01-04 11:45:50 -05002645GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002646{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002647 // Even if the application doesn't want to know about resets, we want to know
2648 // as it will allow us to skip all the calls.
2649 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002650 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002651 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002652 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002653 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002654 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002655
2656 // EXT_robustness, section 2.6: If the reset notification behavior is
2657 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2658 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2659 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002660 }
2661
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002662 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2663 // status should be returned at least once, and GL_NO_ERROR should be returned
2664 // once the device has finished resetting.
2665 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002666 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002667 ASSERT(mResetStatus == GL_NO_ERROR);
2668 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002669
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002670 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002671 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002672 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002673 }
2674 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002675 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002676 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002677 // If markContextLost was used to mark the context lost then
2678 // assume that is not recoverable, and continue to report the
2679 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002680 mResetStatus = mImplementation->getResetStatus();
2681 }
Jamie Madill893ab082014-05-16 16:56:10 -04002682
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002683 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002684}
2685
2686bool Context::isResetNotificationEnabled()
2687{
2688 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2689}
2690
Corentin Walleze3b10e82015-05-20 11:06:25 -04002691const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002692{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002693 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002694}
2695
2696EGLenum Context::getClientType() const
2697{
2698 return mClientType;
2699}
2700
2701EGLenum Context::getRenderBuffer() const
2702{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002703 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2704 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002705 {
2706 return EGL_NONE;
2707 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002708
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002709 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002710 ASSERT(backAttachment != nullptr);
2711 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002712}
2713
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002714VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002715{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002716 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002717 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2718 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002719 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002720 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2721 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002722
Jamie Madill96a483b2017-06-27 16:49:21 -04002723 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002724 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002725
2726 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002727}
2728
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002729TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002730{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002731 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002732 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2733 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002734 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002735 transformFeedback =
2736 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002737 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002738 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002739 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002740
2741 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002742}
2743
2744bool Context::isVertexArrayGenerated(GLuint vertexArray)
2745{
Jamie Madill96a483b2017-06-27 16:49:21 -04002746 ASSERT(mVertexArrayMap.contains(0));
2747 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002748}
2749
2750bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2751{
Jamie Madill96a483b2017-06-27 16:49:21 -04002752 ASSERT(mTransformFeedbackMap.contains(0));
2753 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002754}
2755
Shannon Woods53a94a82014-06-24 15:20:36 -04002756void Context::detachTexture(GLuint texture)
2757{
2758 // Simple pass-through to State's detachTexture method, as textures do not require
2759 // allocation map management either here or in the resource manager at detach time.
2760 // Zero textures are held by the Context, and we don't attempt to request them from
2761 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002762 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002763}
2764
James Darpinian4d9d4832018-03-13 12:43:28 -07002765void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002766{
Yuly Novikov5807a532015-12-03 13:01:22 -05002767 // Simple pass-through to State's detachBuffer method, since
2768 // only buffer attachments to container objects that are bound to the current context
2769 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002770
Yuly Novikov5807a532015-12-03 13:01:22 -05002771 // [OpenGL ES 3.2] section 5.1.2 page 45:
2772 // Attachments to unbound container objects, such as
2773 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2774 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002775 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002776}
2777
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002778void Context::detachFramebuffer(GLuint framebuffer)
2779{
Shannon Woods53a94a82014-06-24 15:20:36 -04002780 // Framebuffer detachment is handled by Context, because 0 is a valid
2781 // Framebuffer object, and a pointer to it must be passed from Context
2782 // to State at binding time.
2783
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002784 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002785 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2786 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2787 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002788
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002789 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002790 {
2791 bindReadFramebuffer(0);
2792 }
2793
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002794 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002795 {
2796 bindDrawFramebuffer(0);
2797 }
2798}
2799
2800void Context::detachRenderbuffer(GLuint renderbuffer)
2801{
Jamie Madilla02315b2017-02-23 14:14:47 -05002802 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002803}
2804
Jamie Madill57a89722013-07-02 11:57:03 -04002805void Context::detachVertexArray(GLuint vertexArray)
2806{
Jamie Madill77a72f62015-04-14 11:18:32 -04002807 // Vertex array detachment is handled by Context, because 0 is a valid
2808 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002809 // binding time.
2810
Jamie Madill57a89722013-07-02 11:57:03 -04002811 // [OpenGL ES 3.0.2] section 2.10 page 43:
2812 // If a vertex array object that is currently bound is deleted, the binding
2813 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002814 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002815 {
2816 bindVertexArray(0);
2817 }
2818}
2819
Geoff Langc8058452014-02-03 12:04:11 -05002820void Context::detachTransformFeedback(GLuint transformFeedback)
2821{
Corentin Walleza2257da2016-04-19 16:43:12 -04002822 // Transform feedback detachment is handled by Context, because 0 is a valid
2823 // transform feedback, and a pointer to it must be passed from Context to State at
2824 // binding time.
2825
2826 // The OpenGL specification doesn't mention what should happen when the currently bound
2827 // transform feedback object is deleted. Since it is a container object, we treat it like
2828 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002829 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002830 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002831 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002832 }
Geoff Langc8058452014-02-03 12:04:11 -05002833}
2834
Jamie Madilldc356042013-07-19 16:36:57 -04002835void Context::detachSampler(GLuint sampler)
2836{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002837 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002838}
2839
Yunchao Hea336b902017-08-02 16:05:21 +08002840void Context::detachProgramPipeline(GLuint pipeline)
2841{
2842 mGLState.detachProgramPipeline(this, pipeline);
2843}
2844
Jamie Madill3ef140a2017-08-26 23:11:21 -04002845void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002846{
Shaodde78e82017-05-22 14:13:27 +08002847 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002848 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002849}
2850
Jamie Madille29d1672013-07-19 16:36:57 -04002851void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2852{
Geoff Langc1984ed2016-10-07 12:41:00 -04002853 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002854 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002855 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002856}
Jamie Madille29d1672013-07-19 16:36:57 -04002857
Geoff Langc1984ed2016-10-07 12:41:00 -04002858void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2859{
2860 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002861 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002862 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002863}
2864
Brandon Jones59770802018-04-02 13:18:42 -07002865void Context::samplerParameterivRobust(GLuint sampler,
2866 GLenum pname,
2867 GLsizei bufSize,
2868 const GLint *param)
2869{
2870 samplerParameteriv(sampler, pname, param);
2871}
2872
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002873void Context::samplerParameterIivRobust(GLuint sampler,
2874 GLenum pname,
2875 GLsizei bufSize,
2876 const GLint *param)
2877{
2878 UNIMPLEMENTED();
2879}
2880
2881void Context::samplerParameterIuivRobust(GLuint sampler,
2882 GLenum pname,
2883 GLsizei bufSize,
2884 const GLuint *param)
2885{
2886 UNIMPLEMENTED();
2887}
2888
Jamie Madille29d1672013-07-19 16:36:57 -04002889void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2890{
Geoff Langc1984ed2016-10-07 12:41:00 -04002891 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002892 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002893 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002894}
2895
Geoff Langc1984ed2016-10-07 12:41:00 -04002896void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002897{
Geoff Langc1984ed2016-10-07 12:41:00 -04002898 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002899 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002900 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002901}
2902
Brandon Jones59770802018-04-02 13:18:42 -07002903void Context::samplerParameterfvRobust(GLuint sampler,
2904 GLenum pname,
2905 GLsizei bufSize,
2906 const GLfloat *param)
2907{
2908 samplerParameterfv(sampler, pname, param);
2909}
2910
Geoff Langc1984ed2016-10-07 12:41:00 -04002911void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002912{
Geoff Langc1984ed2016-10-07 12:41:00 -04002913 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002914 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002915 QuerySamplerParameteriv(samplerObject, pname, params);
2916}
Jamie Madill9675b802013-07-19 16:36:59 -04002917
Brandon Jones59770802018-04-02 13:18:42 -07002918void Context::getSamplerParameterivRobust(GLuint sampler,
2919 GLenum pname,
2920 GLsizei bufSize,
2921 GLsizei *length,
2922 GLint *params)
2923{
2924 getSamplerParameteriv(sampler, pname, params);
2925}
2926
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002927void Context::getSamplerParameterIivRobust(GLuint sampler,
2928 GLenum pname,
2929 GLsizei bufSize,
2930 GLsizei *length,
2931 GLint *params)
2932{
2933 UNIMPLEMENTED();
2934}
2935
2936void Context::getSamplerParameterIuivRobust(GLuint sampler,
2937 GLenum pname,
2938 GLsizei bufSize,
2939 GLsizei *length,
2940 GLuint *params)
2941{
2942 UNIMPLEMENTED();
2943}
2944
Geoff Langc1984ed2016-10-07 12:41:00 -04002945void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2946{
2947 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002948 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002949 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002950}
2951
Brandon Jones59770802018-04-02 13:18:42 -07002952void Context::getSamplerParameterfvRobust(GLuint sampler,
2953 GLenum pname,
2954 GLsizei bufSize,
2955 GLsizei *length,
2956 GLfloat *params)
2957{
2958 getSamplerParameterfv(sampler, pname, params);
2959}
2960
Olli Etuahof0fee072016-03-30 15:11:58 +03002961void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2962{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002963 gl::Program *programObject = getProgramResolveLink(program);
Yunchao He61afff12017-03-14 15:34:03 +08002964 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002965}
2966
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002967void Context::initRendererString()
2968{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002969 std::ostringstream rendererString;
2970 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002971 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002972 rendererString << ")";
2973
Geoff Langcec35902014-04-16 10:52:36 -04002974 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002975}
2976
Geoff Langc339c4e2016-11-29 10:37:36 -05002977void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002978{
Geoff Langc339c4e2016-11-29 10:37:36 -05002979 const Version &clientVersion = getClientVersion();
2980
2981 std::ostringstream versionString;
2982 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2983 << ANGLE_VERSION_STRING << ")";
2984 mVersionString = MakeStaticString(versionString.str());
2985
2986 std::ostringstream shadingLanguageVersionString;
2987 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2988 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2989 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2990 << ")";
2991 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002992}
2993
Geoff Langcec35902014-04-16 10:52:36 -04002994void Context::initExtensionStrings()
2995{
Geoff Langc339c4e2016-11-29 10:37:36 -05002996 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2997 std::ostringstream combinedStringStream;
2998 std::copy(strings.begin(), strings.end(),
2999 std::ostream_iterator<const char *>(combinedStringStream, " "));
3000 return MakeStaticString(combinedStringStream.str());
3001 };
3002
3003 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003004 for (const auto &extensionString : mExtensions.getStrings())
3005 {
3006 mExtensionStrings.push_back(MakeStaticString(extensionString));
3007 }
Geoff Langc339c4e2016-11-29 10:37:36 -05003008 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003009
Geoff Langc339c4e2016-11-29 10:37:36 -05003010 mRequestableExtensionStrings.clear();
3011 for (const auto &extensionInfo : GetExtensionInfoMap())
3012 {
3013 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003014 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003015 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003016 {
3017 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3018 }
3019 }
3020 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003021}
3022
Geoff Langc339c4e2016-11-29 10:37:36 -05003023const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003024{
Geoff Langc339c4e2016-11-29 10:37:36 -05003025 switch (name)
3026 {
3027 case GL_VENDOR:
3028 return reinterpret_cast<const GLubyte *>("Google Inc.");
3029
3030 case GL_RENDERER:
3031 return reinterpret_cast<const GLubyte *>(mRendererString);
3032
3033 case GL_VERSION:
3034 return reinterpret_cast<const GLubyte *>(mVersionString);
3035
3036 case GL_SHADING_LANGUAGE_VERSION:
3037 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3038
3039 case GL_EXTENSIONS:
3040 return reinterpret_cast<const GLubyte *>(mExtensionString);
3041
3042 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3043 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3044
3045 default:
3046 UNREACHABLE();
3047 return nullptr;
3048 }
Geoff Langcec35902014-04-16 10:52:36 -04003049}
3050
Geoff Langc339c4e2016-11-29 10:37:36 -05003051const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003052{
Geoff Langc339c4e2016-11-29 10:37:36 -05003053 switch (name)
3054 {
3055 case GL_EXTENSIONS:
3056 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3057
3058 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3059 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3060
3061 default:
3062 UNREACHABLE();
3063 return nullptr;
3064 }
Geoff Langcec35902014-04-16 10:52:36 -04003065}
3066
3067size_t Context::getExtensionStringCount() const
3068{
3069 return mExtensionStrings.size();
3070}
3071
Geoff Lang111a99e2017-10-17 10:58:41 -04003072bool Context::isExtensionRequestable(const char *name)
3073{
3074 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3075 auto extension = extensionInfos.find(name);
3076
Geoff Lang111a99e2017-10-17 10:58:41 -04003077 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003078 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003079}
3080
Geoff Langc339c4e2016-11-29 10:37:36 -05003081void Context::requestExtension(const char *name)
3082{
3083 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3084 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3085 const auto &extension = extensionInfos.at(name);
3086 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003087 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003088
3089 if (mExtensions.*(extension.ExtensionsMember))
3090 {
3091 // Extension already enabled
3092 return;
3093 }
3094
3095 mExtensions.*(extension.ExtensionsMember) = true;
3096 updateCaps();
3097 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003098
Jamie Madill2f348d22017-06-05 10:50:59 -04003099 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3100 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003101
Jamie Madill81c2e252017-09-09 23:32:46 -04003102 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3103 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003104 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003105 for (auto &zeroTexture : mZeroTextures)
3106 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003107 if (zeroTexture.get() != nullptr)
3108 {
3109 zeroTexture->signalDirty(this, InitState::Initialized);
3110 }
Geoff Lang9aded172017-04-05 11:07:56 -04003111 }
3112
Jamie Madillb983a4b2018-08-01 11:34:51 -04003113 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003114}
3115
3116size_t Context::getRequestableExtensionStringCount() const
3117{
3118 return mRequestableExtensionStrings.size();
3119}
3120
Jamie Madill493f9572018-05-24 19:52:15 -04003121void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003122{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003123 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003124 ASSERT(transformFeedback != nullptr);
3125 ASSERT(!transformFeedback->isPaused());
3126
Jamie Madill6c1f6712017-02-14 19:08:04 -05003127 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Jamie Madilld84b6732018-09-06 15:54:35 -04003128 mStateCache.onTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003129}
3130
3131bool Context::hasActiveTransformFeedback(GLuint program) const
3132{
3133 for (auto pair : mTransformFeedbackMap)
3134 {
3135 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3136 {
3137 return true;
3138 }
3139 }
3140 return false;
3141}
3142
Geoff Lang33f11fb2018-05-07 13:42:47 -04003143Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003144{
3145 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3146
jchen1082af6202018-06-22 10:59:52 +08003147 // Explicitly enable GL_KHR_parallel_shader_compile
3148 supportedExtensions.parallelShaderCompile = true;
3149
Geoff Langb0f917f2017-12-05 13:41:54 -05003150 if (getClientVersion() < ES_2_0)
3151 {
3152 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003153 supportedExtensions.pointSizeArray = true;
3154 supportedExtensions.textureCubeMap = true;
3155 supportedExtensions.pointSprite = true;
3156 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003157 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003158 }
3159
3160 if (getClientVersion() < ES_3_0)
3161 {
3162 // Disable ES3+ extensions
3163 supportedExtensions.colorBufferFloat = false;
3164 supportedExtensions.eglImageExternalEssl3 = false;
3165 supportedExtensions.textureNorm16 = false;
3166 supportedExtensions.multiview = false;
3167 supportedExtensions.maxViews = 1u;
3168 }
3169
3170 if (getClientVersion() < ES_3_1)
3171 {
3172 // Disable ES3.1+ extensions
3173 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003174
3175 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3176 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003177 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003178 }
3179
3180 if (getClientVersion() > ES_2_0)
3181 {
3182 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3183 // supportedExtensions.sRGB = false;
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03003184
3185 // EXT_blend_func_extended is only implemented against GLES2 now
3186 // TODO(http://anglebug.com/1085): remove this limitation once GLES3 binding API for the
3187 // outputs is in place.
3188 supportedExtensions.blendFuncExtended = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003189 }
3190
3191 // Some extensions are always available because they are implemented in the GL layer.
3192 supportedExtensions.bindUniformLocation = true;
3193 supportedExtensions.vertexArrayObject = true;
3194 supportedExtensions.bindGeneratesResource = true;
3195 supportedExtensions.clientArrays = true;
3196 supportedExtensions.requestExtension = true;
3197
3198 // Enable the no error extension if the context was created with the flag.
3199 supportedExtensions.noError = mSkipValidation;
3200
3201 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003202 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003203
3204 // Explicitly enable GL_KHR_debug
3205 supportedExtensions.debug = true;
3206 supportedExtensions.maxDebugMessageLength = 1024;
3207 supportedExtensions.maxDebugLoggedMessages = 1024;
3208 supportedExtensions.maxDebugGroupStackDepth = 1024;
3209 supportedExtensions.maxLabelLength = 1024;
3210
3211 // Explicitly enable GL_ANGLE_robust_client_memory
3212 supportedExtensions.robustClientMemory = true;
3213
3214 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003215 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003216
3217 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3218 // supports it.
3219 supportedExtensions.robustBufferAccessBehavior =
3220 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3221
3222 // Enable the cache control query unconditionally.
3223 supportedExtensions.programCacheControl = true;
3224
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003225 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003226 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003227 {
3228 // GL_ANGLE_explicit_context_gles1
3229 supportedExtensions.explicitContextGles1 = true;
3230 // GL_ANGLE_explicit_context
3231 supportedExtensions.explicitContext = true;
3232 }
3233
Geoff Langb0f917f2017-12-05 13:41:54 -05003234 return supportedExtensions;
3235}
3236
Geoff Lang33f11fb2018-05-07 13:42:47 -04003237void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003238{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003239 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003240
Geoff Lang33f11fb2018-05-07 13:42:47 -04003241 mSupportedExtensions = generateSupportedExtensions();
3242 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003243
3244 mLimitations = mImplementation->getNativeLimitations();
3245
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003246 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3247 if (getClientVersion() < Version(2, 0))
3248 {
3249 mCaps.maxMultitextureUnits = 4;
3250 mCaps.maxClipPlanes = 6;
3251 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003252 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3253 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3254 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003255 mCaps.minSmoothPointSize = 1.0f;
3256 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003257 mCaps.minSmoothLineWidth = 1.0f;
3258 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003259 }
3260
Luc Ferronad2ae932018-06-11 15:31:17 -04003261 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003262 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003263
Luc Ferronad2ae932018-06-11 15:31:17 -04003264 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3265
Jamie Madill0f80ed82017-09-19 00:24:56 -04003266 if (getClientVersion() < ES_3_1)
3267 {
3268 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3269 }
3270 else
3271 {
3272 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3273 }
Geoff Lang301d1612014-07-09 10:34:37 -04003274
Jiawei Shao54aafe52018-04-27 14:54:57 +08003275 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3276 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003277 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3278
Jamie Madill0f80ed82017-09-19 00:24:56 -04003279 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3280 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3281
3282 // Limit textures as well, so we can use fast bitsets with texture bindings.
3283 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003284 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3285 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3286 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3287 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003288
Jiawei Shaodb342272017-09-27 10:21:45 +08003289 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3290
Geoff Langc287ea62016-09-16 14:46:51 -04003291 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003292 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003293 for (const auto &extensionInfo : GetExtensionInfoMap())
3294 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003295 // If the user has requested that extensions start disabled and they are requestable,
3296 // disable them.
3297 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003298 {
3299 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3300 }
3301 }
3302
3303 // Generate texture caps
3304 updateCaps();
3305}
3306
3307void Context::updateCaps()
3308{
Geoff Lang900013c2014-07-07 11:32:19 -04003309 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003310 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003311
Jamie Madill7b62cf92017-11-02 15:20:49 -04003312 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003313 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003314 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003315 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003316
Geoff Lang0d8b7242015-09-09 14:56:53 -04003317 // Update the format caps based on the client version and extensions.
3318 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3319 // ES3.
3320 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003321 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003322 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003323 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003324 formatCaps.textureAttachment =
3325 formatCaps.textureAttachment &&
3326 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3327 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3328 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003329
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003330 // OpenGL ES does not support multisampling with non-rendererable formats
3331 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003332 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003333 (getClientVersion() < ES_3_1 &&
3334 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003335 {
Geoff Langd87878e2014-09-19 15:42:59 -04003336 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003337 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003338 else
3339 {
3340 // We may have limited the max samples for some required renderbuffer formats due to
3341 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3342 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3343
3344 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3345 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3346 // exception of signed and unsigned integer formats."
3347 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3348 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3349 {
3350 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3351 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3352 }
3353
3354 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3355 if (getClientVersion() >= ES_3_1)
3356 {
3357 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3358 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3359 // the exception that the signed and unsigned integer formats are required only to
3360 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3361 // multisamples, which must be at least one."
3362 if (formatInfo.componentType == GL_INT ||
3363 formatInfo.componentType == GL_UNSIGNED_INT)
3364 {
3365 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3366 }
3367
3368 // GLES 3.1 section 19.3.1.
3369 if (formatCaps.texturable)
3370 {
3371 if (formatInfo.depthBits > 0)
3372 {
3373 mCaps.maxDepthTextureSamples =
3374 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3375 }
3376 else if (formatInfo.redBits > 0)
3377 {
3378 mCaps.maxColorTextureSamples =
3379 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3380 }
3381 }
3382 }
3383 }
Geoff Langd87878e2014-09-19 15:42:59 -04003384
3385 if (formatCaps.texturable && formatInfo.compressed)
3386 {
Geoff Langca271392017-04-05 12:30:00 -04003387 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003388 }
3389
Geoff Langca271392017-04-05 12:30:00 -04003390 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003391 }
Jamie Madill32447362017-06-28 14:53:52 -04003392
3393 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003394 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003395 {
3396 mMemoryProgramCache = nullptr;
3397 }
Corentin Walleze4477002017-12-01 14:39:58 -05003398
3399 // Compute which buffer types are allowed
3400 mValidBufferBindings.reset();
3401 mValidBufferBindings.set(BufferBinding::ElementArray);
3402 mValidBufferBindings.set(BufferBinding::Array);
3403
3404 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3405 {
3406 mValidBufferBindings.set(BufferBinding::PixelPack);
3407 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3408 }
3409
3410 if (getClientVersion() >= ES_3_0)
3411 {
3412 mValidBufferBindings.set(BufferBinding::CopyRead);
3413 mValidBufferBindings.set(BufferBinding::CopyWrite);
3414 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3415 mValidBufferBindings.set(BufferBinding::Uniform);
3416 }
3417
3418 if (getClientVersion() >= ES_3_1)
3419 {
3420 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3421 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3422 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3423 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3424 }
jchen107ae70d82018-07-06 13:47:01 +08003425
3426 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Geoff Lang493daf52014-07-03 13:38:44 -04003427}
3428
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003429void Context::initWorkarounds()
3430{
Jamie Madill761b02c2017-06-23 16:27:06 -04003431 // Apply back-end workarounds.
3432 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3433
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003434 // Lose the context upon out of memory error if the application is
3435 // expecting to watch for those events.
3436 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3437}
3438
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003439// Return true if the draw is a no-op, else return false.
3440// A no-op draw occurs if the count of vertices is less than the minimum required to
3441// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3442bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3443{
3444 return count < kMinimumPrimitiveCounts[mode];
3445}
3446
3447bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3448{
3449 return (instanceCount == 0) || noopDraw(mode, count);
3450}
3451
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003452Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003453{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003454 if (mGLES1Renderer)
3455 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003456 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003457 }
3458
Geoff Lang9bf86f02018-07-26 11:46:34 -04003459 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003460
3461 if (isRobustResourceInitEnabled())
3462 {
3463 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3464 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3465 }
3466
Geoff Langa8cb2872018-03-09 16:09:40 -05003467 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003468 return NoError();
3469}
3470
3471Error Context::prepareForClear(GLbitfield mask)
3472{
Geoff Langa8cb2872018-03-09 16:09:40 -05003473 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003474 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003475 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003476 return NoError();
3477}
3478
3479Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3480{
Geoff Langa8cb2872018-03-09 16:09:40 -05003481 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003482 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3483 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003484 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003485 return NoError();
3486}
3487
Geoff Langa8cb2872018-03-09 16:09:40 -05003488Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003489{
Geoff Langa8cb2872018-03-09 16:09:40 -05003490 ANGLE_TRY(syncDirtyObjects(objectMask));
3491 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003492 return NoError();
3493}
3494
Geoff Langa8cb2872018-03-09 16:09:40 -05003495Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003496{
3497 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003498 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003499 mGLState.clearDirtyBits();
3500 return NoError();
3501}
3502
Geoff Langa8cb2872018-03-09 16:09:40 -05003503Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003504{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003505 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003506 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003507 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003508 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003509}
Jamie Madillc29968b2016-01-20 11:17:23 -05003510
Geoff Langa8cb2872018-03-09 16:09:40 -05003511Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003512{
3513 return mGLState.syncDirtyObjects(this, objectMask);
3514}
3515
Jamie Madillc29968b2016-01-20 11:17:23 -05003516void Context::blitFramebuffer(GLint srcX0,
3517 GLint srcY0,
3518 GLint srcX1,
3519 GLint srcY1,
3520 GLint dstX0,
3521 GLint dstY0,
3522 GLint dstX1,
3523 GLint dstY1,
3524 GLbitfield mask,
3525 GLenum filter)
3526{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003527 if (mask == 0)
3528 {
3529 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3530 // buffers are copied.
3531 return;
3532 }
3533
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003534 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003535 ASSERT(drawFramebuffer);
3536
3537 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3538 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3539
Jamie Madillbc918e72018-03-08 09:47:21 -05003540 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003541
Jamie Madillc564c072017-06-01 12:45:42 -04003542 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003543}
Jamie Madillc29968b2016-01-20 11:17:23 -05003544
3545void Context::clear(GLbitfield mask)
3546{
Geoff Langd4fff502017-09-22 11:28:28 -04003547 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3548 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003549}
3550
3551void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3552{
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003553 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3554 // that the backend doesn't need to take this case into account.
Olli Etuahodbce1f82018-09-19 15:32:17 +03003555 if (buffer == GL_DEPTH && !getGLState().getDrawFramebuffer()->getDepthbuffer())
3556 {
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003557 return;
3558 }
3559 if (buffer == GL_COLOR && !getGLState().getDrawFramebuffer()->getColorbuffer(drawbuffer))
3560 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003561 return;
3562 }
Geoff Langd4fff502017-09-22 11:28:28 -04003563 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3564 ANGLE_CONTEXT_TRY(
3565 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003566}
3567
3568void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3569{
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003570 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3571 // that the backend doesn't need to take this case into account.
3572 if (buffer == GL_COLOR && !getGLState().getDrawFramebuffer()->getColorbuffer(drawbuffer))
3573 {
3574 return;
3575 }
Geoff Langd4fff502017-09-22 11:28:28 -04003576 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3577 ANGLE_CONTEXT_TRY(
3578 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003579}
3580
3581void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3582{
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003583 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3584 // that the backend doesn't need to take this case into account.
Olli Etuahodbce1f82018-09-19 15:32:17 +03003585 if (buffer == GL_STENCIL && !getGLState().getDrawFramebuffer()->getStencilbuffer())
3586 {
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003587 return;
3588 }
3589 if (buffer == GL_COLOR && !getGLState().getDrawFramebuffer()->getColorbuffer(drawbuffer))
3590 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003591 return;
3592 }
Geoff Langd4fff502017-09-22 11:28:28 -04003593 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3594 ANGLE_CONTEXT_TRY(
3595 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003596}
3597
3598void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3599{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003600 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003601 ASSERT(framebufferObject);
3602
3603 // If a buffer is not present, the clear has no effect
3604 if (framebufferObject->getDepthbuffer() == nullptr &&
3605 framebufferObject->getStencilbuffer() == nullptr)
3606 {
3607 return;
3608 }
3609
Geoff Langd4fff502017-09-22 11:28:28 -04003610 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3611 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003612}
3613
3614void Context::readPixels(GLint x,
3615 GLint y,
3616 GLsizei width,
3617 GLsizei height,
3618 GLenum format,
3619 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003620 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003621{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003622 if (width == 0 || height == 0)
3623 {
3624 return;
3625 }
3626
Jamie Madillbc918e72018-03-08 09:47:21 -05003627 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003628
Jamie Madillb6664922017-07-25 12:55:04 -04003629 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3630 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003631
3632 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003633 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003634}
3635
Brandon Jones59770802018-04-02 13:18:42 -07003636void Context::readPixelsRobust(GLint x,
3637 GLint y,
3638 GLsizei width,
3639 GLsizei height,
3640 GLenum format,
3641 GLenum type,
3642 GLsizei bufSize,
3643 GLsizei *length,
3644 GLsizei *columns,
3645 GLsizei *rows,
3646 void *pixels)
3647{
3648 readPixels(x, y, width, height, format, type, pixels);
3649}
3650
3651void Context::readnPixelsRobust(GLint x,
3652 GLint y,
3653 GLsizei width,
3654 GLsizei height,
3655 GLenum format,
3656 GLenum type,
3657 GLsizei bufSize,
3658 GLsizei *length,
3659 GLsizei *columns,
3660 GLsizei *rows,
3661 void *data)
3662{
3663 readPixels(x, y, width, height, format, type, data);
3664}
3665
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003666void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003667 GLint level,
3668 GLenum internalformat,
3669 GLint x,
3670 GLint y,
3671 GLsizei width,
3672 GLsizei height,
3673 GLint border)
3674{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003675 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003676 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003677
Jamie Madillc29968b2016-01-20 11:17:23 -05003678 Rectangle sourceArea(x, y, width, height);
3679
Jamie Madill05b35b22017-10-03 09:01:44 -04003680 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003681 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003682 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003683}
3684
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003685void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003686 GLint level,
3687 GLint xoffset,
3688 GLint yoffset,
3689 GLint x,
3690 GLint y,
3691 GLsizei width,
3692 GLsizei height)
3693{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003694 if (width == 0 || height == 0)
3695 {
3696 return;
3697 }
3698
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003699 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003700 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003701
Jamie Madillc29968b2016-01-20 11:17:23 -05003702 Offset destOffset(xoffset, yoffset, 0);
3703 Rectangle sourceArea(x, y, width, height);
3704
Jamie Madill05b35b22017-10-03 09:01:44 -04003705 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003706 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003707 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003708}
3709
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003710void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003711 GLint level,
3712 GLint xoffset,
3713 GLint yoffset,
3714 GLint zoffset,
3715 GLint x,
3716 GLint y,
3717 GLsizei width,
3718 GLsizei height)
3719{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003720 if (width == 0 || height == 0)
3721 {
3722 return;
3723 }
3724
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003725 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003726 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003727
Jamie Madillc29968b2016-01-20 11:17:23 -05003728 Offset destOffset(xoffset, yoffset, zoffset);
3729 Rectangle sourceArea(x, y, width, height);
3730
Jamie Madill05b35b22017-10-03 09:01:44 -04003731 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3732 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003733 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3734 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003735}
3736
3737void Context::framebufferTexture2D(GLenum target,
3738 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003739 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003740 GLuint texture,
3741 GLint level)
3742{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003743 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003744 ASSERT(framebuffer);
3745
3746 if (texture != 0)
3747 {
3748 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003749 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003750 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003751 }
3752 else
3753 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003754 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003755 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003756
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003757 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003758}
3759
3760void Context::framebufferRenderbuffer(GLenum target,
3761 GLenum attachment,
3762 GLenum renderbuffertarget,
3763 GLuint renderbuffer)
3764{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003765 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003766 ASSERT(framebuffer);
3767
3768 if (renderbuffer != 0)
3769 {
3770 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003771
Jamie Madillcc129372018-04-12 09:13:18 -04003772 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003773 renderbufferObject);
3774 }
3775 else
3776 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003777 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003778 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003779
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003780 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003781}
3782
3783void Context::framebufferTextureLayer(GLenum target,
3784 GLenum attachment,
3785 GLuint texture,
3786 GLint level,
3787 GLint layer)
3788{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003789 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003790 ASSERT(framebuffer);
3791
3792 if (texture != 0)
3793 {
3794 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003795 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003796 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003797 }
3798 else
3799 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003800 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003801 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003802
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003803 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003804}
3805
Brandon Jones59770802018-04-02 13:18:42 -07003806void Context::framebufferTextureMultiviewLayered(GLenum target,
3807 GLenum attachment,
3808 GLuint texture,
3809 GLint level,
3810 GLint baseViewIndex,
3811 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003812{
Martin Radev82ef7742017-08-08 17:44:58 +03003813 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3814 ASSERT(framebuffer);
3815
3816 if (texture != 0)
3817 {
3818 Texture *textureObj = getTexture(texture);
3819
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003820 ImageIndex index;
3821 if (textureObj->getType() == TextureType::_2DArray)
3822 {
3823 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3824 }
3825 else
3826 {
3827 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3828 ASSERT(level == 0);
3829 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3830 }
Martin Radev82ef7742017-08-08 17:44:58 +03003831 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3832 numViews, baseViewIndex);
3833 }
3834 else
3835 {
3836 framebuffer->resetAttachment(this, attachment);
3837 }
3838
3839 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003840}
3841
Brandon Jones59770802018-04-02 13:18:42 -07003842void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3843 GLenum attachment,
3844 GLuint texture,
3845 GLint level,
3846 GLsizei numViews,
3847 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003848{
Martin Radev5dae57b2017-07-14 16:15:55 +03003849 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3850 ASSERT(framebuffer);
3851
3852 if (texture != 0)
3853 {
3854 Texture *textureObj = getTexture(texture);
3855
3856 ImageIndex index = ImageIndex::Make2D(level);
3857 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3858 textureObj, numViews, viewportOffsets);
3859 }
3860 else
3861 {
3862 framebuffer->resetAttachment(this, attachment);
3863 }
3864
3865 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003866}
3867
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003868void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3869{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003870 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3871 ASSERT(framebuffer);
3872
3873 if (texture != 0)
3874 {
3875 Texture *textureObj = getTexture(texture);
3876
3877 ImageIndex index = ImageIndex::MakeFromType(
3878 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3879 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3880 }
3881 else
3882 {
3883 framebuffer->resetAttachment(this, attachment);
3884 }
3885
3886 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003887}
3888
Jamie Madillc29968b2016-01-20 11:17:23 -05003889void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3890{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003891 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003892 ASSERT(framebuffer);
3893 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003894 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04003895 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003896}
3897
3898void Context::readBuffer(GLenum mode)
3899{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003900 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003901 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003902 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003903}
3904
3905void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3906{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003907 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003908 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003909
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003910 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003911 ASSERT(framebuffer);
3912
3913 // The specification isn't clear what should be done when the framebuffer isn't complete.
3914 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003915 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003916}
3917
3918void Context::invalidateFramebuffer(GLenum target,
3919 GLsizei numAttachments,
3920 const GLenum *attachments)
3921{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003922 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003923 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003924
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003925 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003926 ASSERT(framebuffer);
3927
Jamie Madill427064d2018-04-13 16:20:34 -04003928 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003929 {
Jamie Madill437fa652016-05-03 15:13:24 -04003930 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003931 }
Jamie Madill437fa652016-05-03 15:13:24 -04003932
Jamie Madill4928b7c2017-06-20 12:57:39 -04003933 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003934}
3935
3936void Context::invalidateSubFramebuffer(GLenum target,
3937 GLsizei numAttachments,
3938 const GLenum *attachments,
3939 GLint x,
3940 GLint y,
3941 GLsizei width,
3942 GLsizei height)
3943{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003944 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003945 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003946
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003947 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003948 ASSERT(framebuffer);
3949
Jamie Madill427064d2018-04-13 16:20:34 -04003950 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003951 {
Jamie Madill437fa652016-05-03 15:13:24 -04003952 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003953 }
Jamie Madill437fa652016-05-03 15:13:24 -04003954
3955 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003956 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003957}
3958
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003959void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003960 GLint level,
3961 GLint internalformat,
3962 GLsizei width,
3963 GLsizei height,
3964 GLint border,
3965 GLenum format,
3966 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003967 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003968{
Jamie Madillbc918e72018-03-08 09:47:21 -05003969 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003970
3971 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003972 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003973 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003974 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003975}
3976
Brandon Jones59770802018-04-02 13:18:42 -07003977void Context::texImage2DRobust(TextureTarget target,
3978 GLint level,
3979 GLint internalformat,
3980 GLsizei width,
3981 GLsizei height,
3982 GLint border,
3983 GLenum format,
3984 GLenum type,
3985 GLsizei bufSize,
3986 const void *pixels)
3987{
3988 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3989}
3990
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003991void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003992 GLint level,
3993 GLint internalformat,
3994 GLsizei width,
3995 GLsizei height,
3996 GLsizei depth,
3997 GLint border,
3998 GLenum format,
3999 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004000 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004001{
Jamie Madillbc918e72018-03-08 09:47:21 -05004002 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004003
4004 Extents size(width, height, depth);
4005 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004006 handleError(texture->setImage(this, mGLState.getUnpackState(),
4007 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004008 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004009}
4010
Brandon Jones59770802018-04-02 13:18:42 -07004011void Context::texImage3DRobust(TextureType target,
4012 GLint level,
4013 GLint internalformat,
4014 GLsizei width,
4015 GLsizei height,
4016 GLsizei depth,
4017 GLint border,
4018 GLenum format,
4019 GLenum type,
4020 GLsizei bufSize,
4021 const void *pixels)
4022{
4023 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4024}
4025
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004026void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004027 GLint level,
4028 GLint xoffset,
4029 GLint yoffset,
4030 GLsizei width,
4031 GLsizei height,
4032 GLenum format,
4033 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004034 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004035{
4036 // Zero sized uploads are valid but no-ops
4037 if (width == 0 || height == 0)
4038 {
4039 return;
4040 }
4041
Jamie Madillbc918e72018-03-08 09:47:21 -05004042 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004043
4044 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004045 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004046
4047 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4048
4049 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target, level,
4050 area, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004051}
4052
Brandon Jones59770802018-04-02 13:18:42 -07004053void Context::texSubImage2DRobust(TextureTarget target,
4054 GLint level,
4055 GLint xoffset,
4056 GLint yoffset,
4057 GLsizei width,
4058 GLsizei height,
4059 GLenum format,
4060 GLenum type,
4061 GLsizei bufSize,
4062 const void *pixels)
4063{
4064 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4065}
4066
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004067void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004068 GLint level,
4069 GLint xoffset,
4070 GLint yoffset,
4071 GLint zoffset,
4072 GLsizei width,
4073 GLsizei height,
4074 GLsizei depth,
4075 GLenum format,
4076 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004077 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004078{
4079 // Zero sized uploads are valid but no-ops
4080 if (width == 0 || height == 0 || depth == 0)
4081 {
4082 return;
4083 }
4084
Jamie Madillbc918e72018-03-08 09:47:21 -05004085 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004086
4087 Box area(xoffset, yoffset, zoffset, width, height, depth);
4088 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004089
4090 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4091
4092 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004093 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004094 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004095}
4096
Brandon Jones59770802018-04-02 13:18:42 -07004097void Context::texSubImage3DRobust(TextureType target,
4098 GLint level,
4099 GLint xoffset,
4100 GLint yoffset,
4101 GLint zoffset,
4102 GLsizei width,
4103 GLsizei height,
4104 GLsizei depth,
4105 GLenum format,
4106 GLenum type,
4107 GLsizei bufSize,
4108 const void *pixels)
4109{
4110 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4111 pixels);
4112}
4113
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004114void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004115 GLint level,
4116 GLenum internalformat,
4117 GLsizei width,
4118 GLsizei height,
4119 GLint border,
4120 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004121 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004122{
Jamie Madillbc918e72018-03-08 09:47:21 -05004123 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004124
4125 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004126 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004127 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4128 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004129 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004130}
4131
Brandon Jones59770802018-04-02 13:18:42 -07004132void Context::compressedTexImage2DRobust(TextureTarget target,
4133 GLint level,
4134 GLenum internalformat,
4135 GLsizei width,
4136 GLsizei height,
4137 GLint border,
4138 GLsizei imageSize,
4139 GLsizei dataSize,
4140 const GLvoid *data)
4141{
4142 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4143}
4144
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004145void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004146 GLint level,
4147 GLenum internalformat,
4148 GLsizei width,
4149 GLsizei height,
4150 GLsizei depth,
4151 GLint border,
4152 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004153 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004154{
Jamie Madillbc918e72018-03-08 09:47:21 -05004155 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004156
4157 Extents size(width, height, depth);
4158 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004159 handleError(texture->setCompressedImage(
4160 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004161 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004162}
4163
Brandon Jones59770802018-04-02 13:18:42 -07004164void Context::compressedTexImage3DRobust(TextureType target,
4165 GLint level,
4166 GLenum internalformat,
4167 GLsizei width,
4168 GLsizei height,
4169 GLsizei depth,
4170 GLint border,
4171 GLsizei imageSize,
4172 GLsizei dataSize,
4173 const GLvoid *data)
4174{
4175 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4176 data);
4177}
4178
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004179void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004180 GLint level,
4181 GLint xoffset,
4182 GLint yoffset,
4183 GLsizei width,
4184 GLsizei height,
4185 GLenum format,
4186 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004187 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004188{
Jamie Madillbc918e72018-03-08 09:47:21 -05004189 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004190
4191 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004192 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004193 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4194 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004195 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004196}
4197
Brandon Jones59770802018-04-02 13:18:42 -07004198void Context::compressedTexSubImage2DRobust(TextureTarget target,
4199 GLint level,
4200 GLint xoffset,
4201 GLint yoffset,
4202 GLsizei width,
4203 GLsizei height,
4204 GLenum format,
4205 GLsizei imageSize,
4206 GLsizei dataSize,
4207 const GLvoid *data)
4208{
4209 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4210 data);
4211}
4212
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004213void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004214 GLint level,
4215 GLint xoffset,
4216 GLint yoffset,
4217 GLint zoffset,
4218 GLsizei width,
4219 GLsizei height,
4220 GLsizei depth,
4221 GLenum format,
4222 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004223 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004224{
4225 // Zero sized uploads are valid but no-ops
4226 if (width == 0 || height == 0)
4227 {
4228 return;
4229 }
4230
Jamie Madillbc918e72018-03-08 09:47:21 -05004231 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004232
4233 Box area(xoffset, yoffset, zoffset, width, height, depth);
4234 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004235 handleError(texture->setCompressedSubImage(
4236 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004237 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004238}
4239
Brandon Jones59770802018-04-02 13:18:42 -07004240void Context::compressedTexSubImage3DRobust(TextureType target,
4241 GLint level,
4242 GLint xoffset,
4243 GLint yoffset,
4244 GLint zoffset,
4245 GLsizei width,
4246 GLsizei height,
4247 GLsizei depth,
4248 GLenum format,
4249 GLsizei imageSize,
4250 GLsizei dataSize,
4251 const GLvoid *data)
4252{
4253 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4254 imageSize, data);
4255}
4256
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004257void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004258{
4259 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004260 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004261}
4262
Jamie Madill007530e2017-12-28 14:27:04 -05004263void Context::copyTexture(GLuint sourceId,
4264 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004265 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004266 GLuint destId,
4267 GLint destLevel,
4268 GLint internalFormat,
4269 GLenum destType,
4270 GLboolean unpackFlipY,
4271 GLboolean unpackPremultiplyAlpha,
4272 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004273{
Jamie Madillbc918e72018-03-08 09:47:21 -05004274 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004275
4276 gl::Texture *sourceTexture = getTexture(sourceId);
4277 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004278 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4279 sourceLevel, ConvertToBool(unpackFlipY),
4280 ConvertToBool(unpackPremultiplyAlpha),
4281 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004282}
4283
Jamie Madill007530e2017-12-28 14:27:04 -05004284void Context::copySubTexture(GLuint sourceId,
4285 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004286 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004287 GLuint destId,
4288 GLint destLevel,
4289 GLint xoffset,
4290 GLint yoffset,
4291 GLint x,
4292 GLint y,
4293 GLsizei width,
4294 GLsizei height,
4295 GLboolean unpackFlipY,
4296 GLboolean unpackPremultiplyAlpha,
4297 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004298{
4299 // Zero sized copies are valid but no-ops
4300 if (width == 0 || height == 0)
4301 {
4302 return;
4303 }
4304
Jamie Madillbc918e72018-03-08 09:47:21 -05004305 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004306
4307 gl::Texture *sourceTexture = getTexture(sourceId);
4308 gl::Texture *destTexture = getTexture(destId);
4309 Offset offset(xoffset, yoffset, 0);
4310 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004311 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4312 ConvertToBool(unpackFlipY),
4313 ConvertToBool(unpackPremultiplyAlpha),
4314 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004315}
4316
Jamie Madill007530e2017-12-28 14:27:04 -05004317void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004318{
Jamie Madillbc918e72018-03-08 09:47:21 -05004319 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004320
4321 gl::Texture *sourceTexture = getTexture(sourceId);
4322 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004323 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004324}
4325
Corentin Wallez336129f2017-10-17 15:55:40 -04004326void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004327{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004328 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004329 ASSERT(buffer);
4330
Geoff Lang496c02d2016-10-20 11:38:11 -07004331 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004332}
4333
Brandon Jones59770802018-04-02 13:18:42 -07004334void Context::getBufferPointervRobust(BufferBinding target,
4335 GLenum pname,
4336 GLsizei bufSize,
4337 GLsizei *length,
4338 void **params)
4339{
4340 getBufferPointerv(target, pname, params);
4341}
4342
Corentin Wallez336129f2017-10-17 15:55:40 -04004343void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004344{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004345 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004346 ASSERT(buffer);
4347
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004348 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004349 if (error.isError())
4350 {
Jamie Madill437fa652016-05-03 15:13:24 -04004351 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004352 return nullptr;
4353 }
4354
4355 return buffer->getMapPointer();
4356}
4357
Corentin Wallez336129f2017-10-17 15:55:40 -04004358GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004359{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004360 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004361 ASSERT(buffer);
4362
4363 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004364 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004365 if (error.isError())
4366 {
Jamie Madill437fa652016-05-03 15:13:24 -04004367 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004368 return GL_FALSE;
4369 }
4370
4371 return result;
4372}
4373
Corentin Wallez336129f2017-10-17 15:55:40 -04004374void *Context::mapBufferRange(BufferBinding target,
4375 GLintptr offset,
4376 GLsizeiptr length,
4377 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004378{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004379 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004380 ASSERT(buffer);
4381
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004382 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004383 if (error.isError())
4384 {
Jamie Madill437fa652016-05-03 15:13:24 -04004385 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004386 return nullptr;
4387 }
4388
4389 return buffer->getMapPointer();
4390}
4391
Corentin Wallez336129f2017-10-17 15:55:40 -04004392void Context::flushMappedBufferRange(BufferBinding /*target*/,
4393 GLintptr /*offset*/,
4394 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004395{
4396 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4397}
4398
Jamie Madillbc918e72018-03-08 09:47:21 -05004399Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004400{
Geoff Langa8cb2872018-03-09 16:09:40 -05004401 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004402}
4403
Jamie Madillbc918e72018-03-08 09:47:21 -05004404Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004405{
Geoff Langa8cb2872018-03-09 16:09:40 -05004406 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004407}
4408
Jamie Madillbc918e72018-03-08 09:47:21 -05004409Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004410{
Geoff Langa8cb2872018-03-09 16:09:40 -05004411 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004412}
4413
Geoff Lang9bf86f02018-07-26 11:46:34 -04004414Error Context::syncStateForPathOperation()
4415{
4416 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4417
4418 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4419 ANGLE_TRY(syncDirtyBits());
4420
4421 return NoError();
4422}
4423
Jiajia Qin5451d532017-11-16 17:16:34 +08004424void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4425{
4426 UNIMPLEMENTED();
4427}
4428
Jamie Madillc20ab272016-06-09 07:20:46 -07004429void Context::activeTexture(GLenum texture)
4430{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004431 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004432}
4433
Jamie Madill876429b2017-04-20 15:46:24 -04004434void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004435{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004436 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004437}
4438
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004439void Context::blendEquation(GLenum mode)
4440{
4441 mGLState.setBlendEquation(mode, mode);
4442}
4443
Jamie Madillc20ab272016-06-09 07:20:46 -07004444void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4445{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004446 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004447}
4448
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004449void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4450{
4451 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4452}
4453
Jamie Madillc20ab272016-06-09 07:20:46 -07004454void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4455{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004456 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004457}
4458
Jamie Madill876429b2017-04-20 15:46:24 -04004459void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004460{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004461 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004462}
4463
Jamie Madill876429b2017-04-20 15:46:24 -04004464void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004465{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004466 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004467}
4468
4469void Context::clearStencil(GLint s)
4470{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004471 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004472}
4473
4474void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4475{
Geoff Lang92019432017-11-20 13:09:34 -05004476 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4477 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004478}
4479
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004480void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004481{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004482 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004483}
4484
4485void Context::depthFunc(GLenum func)
4486{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004487 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004488}
4489
4490void Context::depthMask(GLboolean flag)
4491{
Geoff Lang92019432017-11-20 13:09:34 -05004492 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004493}
4494
Jamie Madill876429b2017-04-20 15:46:24 -04004495void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004496{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004497 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004498}
4499
4500void Context::disable(GLenum cap)
4501{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004502 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004503 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004504}
4505
4506void Context::disableVertexAttribArray(GLuint index)
4507{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004508 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004509 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004510}
4511
4512void Context::enable(GLenum cap)
4513{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004514 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004515 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004516}
4517
4518void Context::enableVertexAttribArray(GLuint index)
4519{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004520 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004521 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004522}
4523
4524void Context::frontFace(GLenum mode)
4525{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004526 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004527}
4528
4529void Context::hint(GLenum target, GLenum mode)
4530{
4531 switch (target)
4532 {
4533 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004534 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004535 break;
4536
4537 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004538 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004539 break;
4540
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004541 case GL_PERSPECTIVE_CORRECTION_HINT:
4542 case GL_POINT_SMOOTH_HINT:
4543 case GL_LINE_SMOOTH_HINT:
4544 case GL_FOG_HINT:
4545 mGLState.gles1().setHint(target, mode);
4546 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004547 default:
4548 UNREACHABLE();
4549 return;
4550 }
4551}
4552
4553void Context::lineWidth(GLfloat width)
4554{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004555 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004556}
4557
4558void Context::pixelStorei(GLenum pname, GLint param)
4559{
4560 switch (pname)
4561 {
4562 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004563 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004564 break;
4565
4566 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004567 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004568 break;
4569
4570 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004571 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004572 break;
4573
4574 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004575 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004576 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004577 break;
4578
4579 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004580 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004581 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004582 break;
4583
4584 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004585 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004586 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004587 break;
4588
4589 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004590 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004591 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004592 break;
4593
4594 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004595 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004596 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004597 break;
4598
4599 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004600 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004601 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004602 break;
4603
4604 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004605 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004606 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004607 break;
4608
4609 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004610 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004611 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004612 break;
4613
4614 default:
4615 UNREACHABLE();
4616 return;
4617 }
4618}
4619
4620void Context::polygonOffset(GLfloat factor, GLfloat units)
4621{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004622 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004623}
4624
Jamie Madill876429b2017-04-20 15:46:24 -04004625void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004626{
Geoff Lang92019432017-11-20 13:09:34 -05004627 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004628}
4629
Jiawei Shaodb342272017-09-27 10:21:45 +08004630void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4631{
4632 mGLState.setSampleMaskParams(maskNumber, mask);
4633}
4634
Jamie Madillc20ab272016-06-09 07:20:46 -07004635void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4636{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004637 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004638}
4639
4640void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4641{
4642 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4643 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004644 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004645 }
4646
4647 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4648 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004649 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004650 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004651
4652 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004653}
4654
4655void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4656{
4657 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4658 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004659 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004660 }
4661
4662 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4663 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004664 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004665 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004666
4667 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004668}
4669
4670void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4671{
4672 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4673 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004674 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004675 }
4676
4677 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4678 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004679 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004680 }
4681}
4682
4683void Context::vertexAttrib1f(GLuint index, GLfloat x)
4684{
4685 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004686 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004687 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004688}
4689
4690void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4691{
4692 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004693 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004694 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004695}
4696
4697void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4698{
4699 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004700 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004701 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004702}
4703
4704void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4705{
4706 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004707 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004708 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004709}
4710
4711void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4712{
4713 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004714 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004715 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004716}
4717
4718void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4719{
4720 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004721 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004722 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004723}
4724
4725void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4726{
4727 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004728 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004729 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004730}
4731
4732void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4733{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004734 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004735 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004736}
4737
4738void Context::vertexAttribPointer(GLuint index,
4739 GLint size,
4740 GLenum type,
4741 GLboolean normalized,
4742 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004743 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004744{
Corentin Wallez336129f2017-10-17 15:55:40 -04004745 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004746 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004747 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004748}
4749
Shao80957d92017-02-20 21:25:59 +08004750void Context::vertexAttribFormat(GLuint attribIndex,
4751 GLint size,
4752 GLenum type,
4753 GLboolean normalized,
4754 GLuint relativeOffset)
4755{
Geoff Lang92019432017-11-20 13:09:34 -05004756 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004757 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004758 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004759}
4760
4761void Context::vertexAttribIFormat(GLuint attribIndex,
4762 GLint size,
4763 GLenum type,
4764 GLuint relativeOffset)
4765{
4766 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004767 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004768}
4769
4770void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4771{
Shaodde78e82017-05-22 14:13:27 +08004772 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004773 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004774}
4775
Jiajia Qin5451d532017-11-16 17:16:34 +08004776void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004777{
4778 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004779 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004780}
4781
Jamie Madillc20ab272016-06-09 07:20:46 -07004782void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4783{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004784 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004785}
4786
4787void Context::vertexAttribIPointer(GLuint index,
4788 GLint size,
4789 GLenum type,
4790 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004791 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004792{
Corentin Wallez336129f2017-10-17 15:55:40 -04004793 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4794 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004795 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004796}
4797
4798void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4799{
4800 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004801 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004802 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004803}
4804
4805void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4806{
4807 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004808 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004809 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004810}
4811
4812void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4813{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004814 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004815 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004816}
4817
4818void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4819{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004820 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004821 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004822}
4823
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004824void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4825{
4826 const VertexAttribCurrentValueData &currentValues =
4827 getGLState().getVertexAttribCurrentValue(index);
4828 const VertexArray *vao = getGLState().getVertexArray();
4829 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4830 currentValues, pname, params);
4831}
4832
Brandon Jones59770802018-04-02 13:18:42 -07004833void Context::getVertexAttribivRobust(GLuint index,
4834 GLenum pname,
4835 GLsizei bufSize,
4836 GLsizei *length,
4837 GLint *params)
4838{
4839 getVertexAttribiv(index, pname, params);
4840}
4841
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004842void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4843{
4844 const VertexAttribCurrentValueData &currentValues =
4845 getGLState().getVertexAttribCurrentValue(index);
4846 const VertexArray *vao = getGLState().getVertexArray();
4847 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4848 currentValues, pname, params);
4849}
4850
Brandon Jones59770802018-04-02 13:18:42 -07004851void Context::getVertexAttribfvRobust(GLuint index,
4852 GLenum pname,
4853 GLsizei bufSize,
4854 GLsizei *length,
4855 GLfloat *params)
4856{
4857 getVertexAttribfv(index, pname, params);
4858}
4859
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004860void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4861{
4862 const VertexAttribCurrentValueData &currentValues =
4863 getGLState().getVertexAttribCurrentValue(index);
4864 const VertexArray *vao = getGLState().getVertexArray();
4865 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4866 currentValues, pname, params);
4867}
4868
Brandon Jones59770802018-04-02 13:18:42 -07004869void Context::getVertexAttribIivRobust(GLuint index,
4870 GLenum pname,
4871 GLsizei bufSize,
4872 GLsizei *length,
4873 GLint *params)
4874{
4875 getVertexAttribIiv(index, pname, params);
4876}
4877
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004878void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4879{
4880 const VertexAttribCurrentValueData &currentValues =
4881 getGLState().getVertexAttribCurrentValue(index);
4882 const VertexArray *vao = getGLState().getVertexArray();
4883 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4884 currentValues, pname, params);
4885}
4886
Brandon Jones59770802018-04-02 13:18:42 -07004887void Context::getVertexAttribIuivRobust(GLuint index,
4888 GLenum pname,
4889 GLsizei bufSize,
4890 GLsizei *length,
4891 GLuint *params)
4892{
4893 getVertexAttribIuiv(index, pname, params);
4894}
4895
Jamie Madill876429b2017-04-20 15:46:24 -04004896void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004897{
4898 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4899 QueryVertexAttribPointerv(attrib, pname, pointer);
4900}
4901
Brandon Jones59770802018-04-02 13:18:42 -07004902void Context::getVertexAttribPointervRobust(GLuint index,
4903 GLenum pname,
4904 GLsizei bufSize,
4905 GLsizei *length,
4906 void **pointer)
4907{
4908 getVertexAttribPointerv(index, pname, pointer);
4909}
4910
Jamie Madillc20ab272016-06-09 07:20:46 -07004911void Context::debugMessageControl(GLenum source,
4912 GLenum type,
4913 GLenum severity,
4914 GLsizei count,
4915 const GLuint *ids,
4916 GLboolean enabled)
4917{
4918 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004919 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004920 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004921}
4922
4923void Context::debugMessageInsert(GLenum source,
4924 GLenum type,
4925 GLuint id,
4926 GLenum severity,
4927 GLsizei length,
4928 const GLchar *buf)
4929{
4930 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004931 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004932}
4933
4934void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4935{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004936 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004937}
4938
4939GLuint Context::getDebugMessageLog(GLuint count,
4940 GLsizei bufSize,
4941 GLenum *sources,
4942 GLenum *types,
4943 GLuint *ids,
4944 GLenum *severities,
4945 GLsizei *lengths,
4946 GLchar *messageLog)
4947{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004948 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4949 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004950}
4951
4952void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4953{
4954 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004955 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004956 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004957}
4958
4959void Context::popDebugGroup()
4960{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004961 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004962 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004963}
4964
Corentin Wallez336129f2017-10-17 15:55:40 -04004965void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004966{
4967 Buffer *buffer = mGLState.getTargetBuffer(target);
4968 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004969 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004970}
4971
Corentin Wallez336129f2017-10-17 15:55:40 -04004972void Context::bufferSubData(BufferBinding target,
4973 GLintptr offset,
4974 GLsizeiptr size,
4975 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004976{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06004977 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04004978 {
4979 return;
4980 }
4981
4982 Buffer *buffer = mGLState.getTargetBuffer(target);
4983 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004984 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004985}
4986
Jamie Madillef300b12016-10-07 15:12:09 -04004987void Context::attachShader(GLuint program, GLuint shader)
4988{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004989 Program *programObject = mState.mShaderPrograms->getProgram(program);
4990 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004991 ASSERT(programObject && shaderObject);
4992 programObject->attachShader(shaderObject);
4993}
4994
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004995const Workarounds &Context::getWorkarounds() const
4996{
4997 return mWorkarounds;
4998}
4999
Corentin Wallez336129f2017-10-17 15:55:40 -04005000void Context::copyBufferSubData(BufferBinding readTarget,
5001 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005002 GLintptr readOffset,
5003 GLintptr writeOffset,
5004 GLsizeiptr size)
5005{
5006 // if size is zero, the copy is a successful no-op
5007 if (size == 0)
5008 {
5009 return;
5010 }
5011
5012 // TODO(jmadill): cache these.
5013 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
5014 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
5015
Jamie Madill5f56ddb2017-01-13 17:29:55 -05005016 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005017}
5018
Jamie Madill01a80ee2016-11-07 12:06:18 -05005019void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5020{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005021 // Ideally we could share the program query with the validation layer if possible.
5022 Program *programObject = getProgramResolveLink(program);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005023 ASSERT(programObject);
5024 programObject->bindAttributeLocation(index, name);
5025}
5026
Corentin Wallez336129f2017-10-17 15:55:40 -04005027void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005028{
Corentin Wallez336129f2017-10-17 15:55:40 -04005029 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5030 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04005031 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005032}
5033
Corentin Wallez336129f2017-10-17 15:55:40 -04005034void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005035{
5036 bindBufferRange(target, index, buffer, 0, 0);
5037}
5038
Corentin Wallez336129f2017-10-17 15:55:40 -04005039void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005040 GLuint index,
5041 GLuint buffer,
5042 GLintptr offset,
5043 GLsizeiptr size)
5044{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005045 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5046 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
5047 if (target == BufferBinding::Uniform)
5048 {
5049 mUniformBufferObserverBindings[index].bind(object ? object->getImplementation() : nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04005050 mStateCache.onUniformBufferStateChange(this);
5051 }
5052 else
5053 {
5054 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005055 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005056}
5057
Jamie Madill01a80ee2016-11-07 12:06:18 -05005058void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5059{
5060 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5061 {
5062 bindReadFramebuffer(framebuffer);
5063 }
5064
5065 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5066 {
5067 bindDrawFramebuffer(framebuffer);
5068 }
5069}
5070
5071void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5072{
5073 ASSERT(target == GL_RENDERBUFFER);
5074 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005075 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005076 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005077}
5078
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005079void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005080 GLsizei samples,
5081 GLenum internalformat,
5082 GLsizei width,
5083 GLsizei height,
5084 GLboolean fixedsamplelocations)
5085{
5086 Extents size(width, height, 1);
5087 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005088 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5089 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005090}
5091
Olli Etuaho89664842018-08-24 14:45:36 +03005092void Context::texStorage3DMultisample(TextureType target,
5093 GLsizei samples,
5094 GLenum internalformat,
5095 GLsizei width,
5096 GLsizei height,
5097 GLsizei depth,
5098 GLboolean fixedsamplelocations)
5099{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005100 Extents size(width, height, depth);
5101 Texture *texture = getTargetTexture(target);
5102 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5103 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005104}
5105
JiangYizhoubddc46b2016-12-09 09:50:51 +08005106void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5107{
JiangYizhou5b03f472017-01-09 10:22:53 +08005108 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5109 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005110 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005111 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005112
5113 switch (pname)
5114 {
5115 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04005116 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005117 break;
5118 default:
5119 UNREACHABLE();
5120 }
5121}
5122
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005123void Context::getMultisamplefvRobust(GLenum pname,
5124 GLuint index,
5125 GLsizei bufSize,
5126 GLsizei *length,
5127 GLfloat *val)
5128{
5129 UNIMPLEMENTED();
5130}
5131
Jamie Madille8fb6402017-02-14 17:56:40 -05005132void Context::renderbufferStorage(GLenum target,
5133 GLenum internalformat,
5134 GLsizei width,
5135 GLsizei height)
5136{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005137 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5138 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5139
Jamie Madille8fb6402017-02-14 17:56:40 -05005140 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04005141 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005142}
5143
5144void Context::renderbufferStorageMultisample(GLenum target,
5145 GLsizei samples,
5146 GLenum internalformat,
5147 GLsizei width,
5148 GLsizei height)
5149{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005150 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5151 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005152
5153 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005154 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005155 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005156}
5157
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005158void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5159{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005160 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04005161 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005162}
5163
JiangYizhoue18e6392017-02-20 10:32:23 +08005164void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5165{
5166 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5167 QueryFramebufferParameteriv(framebuffer, pname, params);
5168}
5169
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005170void Context::getFramebufferParameterivRobust(GLenum target,
5171 GLenum pname,
5172 GLsizei bufSize,
5173 GLsizei *length,
5174 GLint *params)
5175{
5176 UNIMPLEMENTED();
5177}
5178
Jiajia Qin5451d532017-11-16 17:16:34 +08005179void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005180{
5181 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005182 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005183}
5184
Jamie Madilldec86232018-07-11 09:01:18 -04005185bool Context::getScratchBuffer(size_t requstedSizeBytes,
5186 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005187{
Jamie Madilldec86232018-07-11 09:01:18 -04005188 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005189}
5190
Jamie Madilldec86232018-07-11 09:01:18 -04005191bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5192 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005193{
Jamie Madilldec86232018-07-11 09:01:18 -04005194 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005195}
5196
Xinghua Cao10a4d432017-11-28 14:46:26 +08005197Error Context::prepareForDispatch()
5198{
Geoff Langa8cb2872018-03-09 16:09:40 -05005199 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005200
5201 if (isRobustResourceInitEnabled())
5202 {
5203 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5204 }
5205
5206 return NoError();
5207}
5208
Xinghua Cao2b396592017-03-29 15:36:04 +08005209void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5210{
5211 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5212 {
5213 return;
5214 }
5215
Xinghua Cao10a4d432017-11-28 14:46:26 +08005216 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005217 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005218}
5219
Jiajia Qin5451d532017-11-16 17:16:34 +08005220void Context::dispatchComputeIndirect(GLintptr indirect)
5221{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005222 ANGLE_CONTEXT_TRY(prepareForDispatch());
5223 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005224}
5225
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005226void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005227 GLsizei levels,
5228 GLenum internalFormat,
5229 GLsizei width,
5230 GLsizei height)
5231{
5232 Extents size(width, height, 1);
5233 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005234 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005235}
5236
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005237void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005238 GLsizei levels,
5239 GLenum internalFormat,
5240 GLsizei width,
5241 GLsizei height,
5242 GLsizei depth)
5243{
5244 Extents size(width, height, depth);
5245 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005246 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005247}
5248
Jiajia Qin5451d532017-11-16 17:16:34 +08005249void Context::memoryBarrier(GLbitfield barriers)
5250{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005251 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005252}
5253
5254void Context::memoryBarrierByRegion(GLbitfield barriers)
5255{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005256 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005257}
5258
Jamie Madillc1d770e2017-04-13 17:31:24 -04005259GLenum Context::checkFramebufferStatus(GLenum target)
5260{
5261 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5262 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005263 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005264}
5265
5266void Context::compileShader(GLuint shader)
5267{
5268 Shader *shaderObject = GetValidShader(this, shader);
5269 if (!shaderObject)
5270 {
5271 return;
5272 }
5273 shaderObject->compile(this);
5274}
5275
5276void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5277{
5278 for (int i = 0; i < n; i++)
5279 {
5280 deleteBuffer(buffers[i]);
5281 }
5282}
5283
5284void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5285{
5286 for (int i = 0; i < n; i++)
5287 {
5288 if (framebuffers[i] != 0)
5289 {
5290 deleteFramebuffer(framebuffers[i]);
5291 }
5292 }
5293}
5294
5295void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5296{
5297 for (int i = 0; i < n; i++)
5298 {
5299 deleteRenderbuffer(renderbuffers[i]);
5300 }
5301}
5302
5303void Context::deleteTextures(GLsizei n, const GLuint *textures)
5304{
5305 for (int i = 0; i < n; i++)
5306 {
5307 if (textures[i] != 0)
5308 {
5309 deleteTexture(textures[i]);
5310 }
5311 }
5312}
5313
5314void Context::detachShader(GLuint program, GLuint shader)
5315{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005316 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005317 ASSERT(programObject);
5318
5319 Shader *shaderObject = getShader(shader);
5320 ASSERT(shaderObject);
5321
5322 programObject->detachShader(this, shaderObject);
5323}
5324
5325void Context::genBuffers(GLsizei n, GLuint *buffers)
5326{
5327 for (int i = 0; i < n; i++)
5328 {
5329 buffers[i] = createBuffer();
5330 }
5331}
5332
5333void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5334{
5335 for (int i = 0; i < n; i++)
5336 {
5337 framebuffers[i] = createFramebuffer();
5338 }
5339}
5340
5341void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5342{
5343 for (int i = 0; i < n; i++)
5344 {
5345 renderbuffers[i] = createRenderbuffer();
5346 }
5347}
5348
5349void Context::genTextures(GLsizei n, GLuint *textures)
5350{
5351 for (int i = 0; i < n; i++)
5352 {
5353 textures[i] = createTexture();
5354 }
5355}
5356
5357void Context::getActiveAttrib(GLuint program,
5358 GLuint index,
5359 GLsizei bufsize,
5360 GLsizei *length,
5361 GLint *size,
5362 GLenum *type,
5363 GLchar *name)
5364{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005365 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005366 ASSERT(programObject);
5367 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5368}
5369
5370void Context::getActiveUniform(GLuint program,
5371 GLuint index,
5372 GLsizei bufsize,
5373 GLsizei *length,
5374 GLint *size,
5375 GLenum *type,
5376 GLchar *name)
5377{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005378 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005379 ASSERT(programObject);
5380 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5381}
5382
5383void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5384{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005385 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005386 ASSERT(programObject);
5387 programObject->getAttachedShaders(maxcount, count, shaders);
5388}
5389
5390GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5391{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005392 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005393 ASSERT(programObject);
5394 return programObject->getAttributeLocation(name);
5395}
5396
5397void Context::getBooleanv(GLenum pname, GLboolean *params)
5398{
5399 GLenum nativeType;
5400 unsigned int numParams = 0;
5401 getQueryParameterInfo(pname, &nativeType, &numParams);
5402
5403 if (nativeType == GL_BOOL)
5404 {
5405 getBooleanvImpl(pname, params);
5406 }
5407 else
5408 {
5409 CastStateValues(this, nativeType, pname, numParams, params);
5410 }
5411}
5412
Brandon Jones59770802018-04-02 13:18:42 -07005413void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5414{
5415 getBooleanv(pname, params);
5416}
5417
Jamie Madillc1d770e2017-04-13 17:31:24 -04005418void Context::getFloatv(GLenum pname, GLfloat *params)
5419{
5420 GLenum nativeType;
5421 unsigned int numParams = 0;
5422 getQueryParameterInfo(pname, &nativeType, &numParams);
5423
5424 if (nativeType == GL_FLOAT)
5425 {
5426 getFloatvImpl(pname, params);
5427 }
5428 else
5429 {
5430 CastStateValues(this, nativeType, pname, numParams, params);
5431 }
5432}
5433
Brandon Jones59770802018-04-02 13:18:42 -07005434void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5435{
5436 getFloatv(pname, params);
5437}
5438
Jamie Madillc1d770e2017-04-13 17:31:24 -04005439void Context::getIntegerv(GLenum pname, GLint *params)
5440{
5441 GLenum nativeType;
5442 unsigned int numParams = 0;
5443 getQueryParameterInfo(pname, &nativeType, &numParams);
5444
5445 if (nativeType == GL_INT)
5446 {
5447 getIntegervImpl(pname, params);
5448 }
5449 else
5450 {
5451 CastStateValues(this, nativeType, pname, numParams, params);
5452 }
5453}
5454
Brandon Jones59770802018-04-02 13:18:42 -07005455void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5456{
5457 getIntegerv(pname, data);
5458}
5459
Jamie Madillc1d770e2017-04-13 17:31:24 -04005460void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5461{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005462 // Don't resolve link if checking the link completion status.
5463 Program *programObject = (pname == GL_COMPLETION_STATUS_KHR ? getProgramNoResolveLink(program)
5464 : getProgramResolveLink(program));
Jamie Madillc1d770e2017-04-13 17:31:24 -04005465 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005466 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005467}
5468
Brandon Jones59770802018-04-02 13:18:42 -07005469void Context::getProgramivRobust(GLuint program,
5470 GLenum pname,
5471 GLsizei bufSize,
5472 GLsizei *length,
5473 GLint *params)
5474{
5475 getProgramiv(program, pname, params);
5476}
5477
Jiajia Qin5451d532017-11-16 17:16:34 +08005478void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5479{
5480 UNIMPLEMENTED();
5481}
5482
Jamie Madillbe849e42017-05-02 15:49:00 -04005483void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005484{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005485 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005486 ASSERT(programObject);
5487 programObject->getInfoLog(bufsize, length, infolog);
5488}
5489
Jiajia Qin5451d532017-11-16 17:16:34 +08005490void Context::getProgramPipelineInfoLog(GLuint pipeline,
5491 GLsizei bufSize,
5492 GLsizei *length,
5493 GLchar *infoLog)
5494{
5495 UNIMPLEMENTED();
5496}
5497
Jamie Madillc1d770e2017-04-13 17:31:24 -04005498void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5499{
5500 Shader *shaderObject = getShader(shader);
5501 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005502 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005503}
5504
Brandon Jones59770802018-04-02 13:18:42 -07005505void Context::getShaderivRobust(GLuint shader,
5506 GLenum pname,
5507 GLsizei bufSize,
5508 GLsizei *length,
5509 GLint *params)
5510{
5511 getShaderiv(shader, pname, params);
5512}
5513
Jamie Madillc1d770e2017-04-13 17:31:24 -04005514void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5515{
5516 Shader *shaderObject = getShader(shader);
5517 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005518 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005519}
5520
5521void Context::getShaderPrecisionFormat(GLenum shadertype,
5522 GLenum precisiontype,
5523 GLint *range,
5524 GLint *precision)
5525{
5526 // TODO(jmadill): Compute shaders.
5527
5528 switch (shadertype)
5529 {
5530 case GL_VERTEX_SHADER:
5531 switch (precisiontype)
5532 {
5533 case GL_LOW_FLOAT:
5534 mCaps.vertexLowpFloat.get(range, precision);
5535 break;
5536 case GL_MEDIUM_FLOAT:
5537 mCaps.vertexMediumpFloat.get(range, precision);
5538 break;
5539 case GL_HIGH_FLOAT:
5540 mCaps.vertexHighpFloat.get(range, precision);
5541 break;
5542
5543 case GL_LOW_INT:
5544 mCaps.vertexLowpInt.get(range, precision);
5545 break;
5546 case GL_MEDIUM_INT:
5547 mCaps.vertexMediumpInt.get(range, precision);
5548 break;
5549 case GL_HIGH_INT:
5550 mCaps.vertexHighpInt.get(range, precision);
5551 break;
5552
5553 default:
5554 UNREACHABLE();
5555 return;
5556 }
5557 break;
5558
5559 case GL_FRAGMENT_SHADER:
5560 switch (precisiontype)
5561 {
5562 case GL_LOW_FLOAT:
5563 mCaps.fragmentLowpFloat.get(range, precision);
5564 break;
5565 case GL_MEDIUM_FLOAT:
5566 mCaps.fragmentMediumpFloat.get(range, precision);
5567 break;
5568 case GL_HIGH_FLOAT:
5569 mCaps.fragmentHighpFloat.get(range, precision);
5570 break;
5571
5572 case GL_LOW_INT:
5573 mCaps.fragmentLowpInt.get(range, precision);
5574 break;
5575 case GL_MEDIUM_INT:
5576 mCaps.fragmentMediumpInt.get(range, precision);
5577 break;
5578 case GL_HIGH_INT:
5579 mCaps.fragmentHighpInt.get(range, precision);
5580 break;
5581
5582 default:
5583 UNREACHABLE();
5584 return;
5585 }
5586 break;
5587
5588 default:
5589 UNREACHABLE();
5590 return;
5591 }
5592}
5593
5594void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5595{
5596 Shader *shaderObject = getShader(shader);
5597 ASSERT(shaderObject);
5598 shaderObject->getSource(bufsize, length, source);
5599}
5600
5601void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5602{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005603 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005604 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005605 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005606}
5607
Brandon Jones59770802018-04-02 13:18:42 -07005608void Context::getUniformfvRobust(GLuint program,
5609 GLint location,
5610 GLsizei bufSize,
5611 GLsizei *length,
5612 GLfloat *params)
5613{
5614 getUniformfv(program, location, params);
5615}
5616
Jamie Madillc1d770e2017-04-13 17:31:24 -04005617void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5618{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005619 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005620 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005621 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005622}
5623
Brandon Jones59770802018-04-02 13:18:42 -07005624void Context::getUniformivRobust(GLuint program,
5625 GLint location,
5626 GLsizei bufSize,
5627 GLsizei *length,
5628 GLint *params)
5629{
5630 getUniformiv(program, location, params);
5631}
5632
Jamie Madillc1d770e2017-04-13 17:31:24 -04005633GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5634{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005635 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005636 ASSERT(programObject);
5637 return programObject->getUniformLocation(name);
5638}
5639
5640GLboolean Context::isBuffer(GLuint buffer)
5641{
5642 if (buffer == 0)
5643 {
5644 return GL_FALSE;
5645 }
5646
5647 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5648}
5649
5650GLboolean Context::isEnabled(GLenum cap)
5651{
5652 return mGLState.getEnableFeature(cap);
5653}
5654
5655GLboolean Context::isFramebuffer(GLuint framebuffer)
5656{
5657 if (framebuffer == 0)
5658 {
5659 return GL_FALSE;
5660 }
5661
5662 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5663}
5664
5665GLboolean Context::isProgram(GLuint program)
5666{
5667 if (program == 0)
5668 {
5669 return GL_FALSE;
5670 }
5671
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005672 return (getProgramNoResolveLink(program) ? GL_TRUE : GL_FALSE);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005673}
5674
5675GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5676{
5677 if (renderbuffer == 0)
5678 {
5679 return GL_FALSE;
5680 }
5681
5682 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5683}
5684
5685GLboolean Context::isShader(GLuint shader)
5686{
5687 if (shader == 0)
5688 {
5689 return GL_FALSE;
5690 }
5691
5692 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5693}
5694
5695GLboolean Context::isTexture(GLuint texture)
5696{
5697 if (texture == 0)
5698 {
5699 return GL_FALSE;
5700 }
5701
5702 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5703}
5704
5705void Context::linkProgram(GLuint program)
5706{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005707 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005708 ASSERT(programObject);
5709 handleError(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005710
5711 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5712 // don't need to worry that:
5713 // 1. Draw calls after link use the new executable code or the old one depending on the link
5714 // result.
5715 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5716 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5717 // ProgramD3D.
5718 if (programObject->isInUse())
5719 {
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005720 programObject->resolveLink();
Jamie Madilldf836ff2018-10-01 10:36:24 -04005721 if (programObject->isLinked())
5722 {
5723 mGLState.onProgramExecutableChange(programObject);
5724 }
5725
jchen107ae70d82018-07-06 13:47:01 +08005726 mStateCache.onProgramExecutableChange(this);
5727 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005728}
5729
5730void Context::releaseShaderCompiler()
5731{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005732 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005733}
5734
5735void Context::shaderBinary(GLsizei n,
5736 const GLuint *shaders,
5737 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005738 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005739 GLsizei length)
5740{
5741 // No binary shader formats are supported.
5742 UNIMPLEMENTED();
5743}
5744
5745void Context::shaderSource(GLuint shader,
5746 GLsizei count,
5747 const GLchar *const *string,
5748 const GLint *length)
5749{
5750 Shader *shaderObject = getShader(shader);
5751 ASSERT(shaderObject);
5752 shaderObject->setSource(count, string, length);
5753}
5754
5755void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5756{
5757 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5758}
5759
5760void Context::stencilMask(GLuint mask)
5761{
5762 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5763}
5764
5765void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5766{
5767 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5768}
5769
5770void Context::uniform1f(GLint location, GLfloat x)
5771{
5772 Program *program = mGLState.getProgram();
5773 program->setUniform1fv(location, 1, &x);
5774}
5775
5776void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5777{
5778 Program *program = mGLState.getProgram();
5779 program->setUniform1fv(location, count, v);
5780}
5781
Jamie Madill7e4eff12018-08-08 15:49:26 -04005782void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005783{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005784 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04005785 {
5786 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04005787 mStateCache.onActiveTextureChange(this);
Jamie Madill81c2e252017-09-09 23:32:46 -04005788 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005789}
5790
Jamie Madill7e4eff12018-08-08 15:49:26 -04005791void Context::uniform1i(GLint location, GLint x)
5792{
5793 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
5794}
5795
Jamie Madillc1d770e2017-04-13 17:31:24 -04005796void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5797{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005798 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005799}
5800
5801void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5802{
5803 GLfloat xy[2] = {x, y};
5804 Program *program = mGLState.getProgram();
5805 program->setUniform2fv(location, 1, xy);
5806}
5807
5808void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5809{
5810 Program *program = mGLState.getProgram();
5811 program->setUniform2fv(location, count, v);
5812}
5813
5814void Context::uniform2i(GLint location, GLint x, GLint y)
5815{
5816 GLint xy[2] = {x, y};
5817 Program *program = mGLState.getProgram();
5818 program->setUniform2iv(location, 1, xy);
5819}
5820
5821void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5822{
5823 Program *program = mGLState.getProgram();
5824 program->setUniform2iv(location, count, v);
5825}
5826
5827void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5828{
5829 GLfloat xyz[3] = {x, y, z};
5830 Program *program = mGLState.getProgram();
5831 program->setUniform3fv(location, 1, xyz);
5832}
5833
5834void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5835{
5836 Program *program = mGLState.getProgram();
5837 program->setUniform3fv(location, count, v);
5838}
5839
5840void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5841{
5842 GLint xyz[3] = {x, y, z};
5843 Program *program = mGLState.getProgram();
5844 program->setUniform3iv(location, 1, xyz);
5845}
5846
5847void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5848{
5849 Program *program = mGLState.getProgram();
5850 program->setUniform3iv(location, count, v);
5851}
5852
5853void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5854{
5855 GLfloat xyzw[4] = {x, y, z, w};
5856 Program *program = mGLState.getProgram();
5857 program->setUniform4fv(location, 1, xyzw);
5858}
5859
5860void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5861{
5862 Program *program = mGLState.getProgram();
5863 program->setUniform4fv(location, count, v);
5864}
5865
5866void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5867{
5868 GLint xyzw[4] = {x, y, z, w};
5869 Program *program = mGLState.getProgram();
5870 program->setUniform4iv(location, 1, xyzw);
5871}
5872
5873void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5874{
5875 Program *program = mGLState.getProgram();
5876 program->setUniform4iv(location, count, v);
5877}
5878
5879void Context::uniformMatrix2fv(GLint location,
5880 GLsizei count,
5881 GLboolean transpose,
5882 const GLfloat *value)
5883{
5884 Program *program = mGLState.getProgram();
5885 program->setUniformMatrix2fv(location, count, transpose, value);
5886}
5887
5888void Context::uniformMatrix3fv(GLint location,
5889 GLsizei count,
5890 GLboolean transpose,
5891 const GLfloat *value)
5892{
5893 Program *program = mGLState.getProgram();
5894 program->setUniformMatrix3fv(location, count, transpose, value);
5895}
5896
5897void Context::uniformMatrix4fv(GLint location,
5898 GLsizei count,
5899 GLboolean transpose,
5900 const GLfloat *value)
5901{
5902 Program *program = mGLState.getProgram();
5903 program->setUniformMatrix4fv(location, count, transpose, value);
5904}
5905
5906void Context::validateProgram(GLuint program)
5907{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005908 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005909 ASSERT(programObject);
5910 programObject->validate(mCaps);
5911}
5912
Jiajia Qin5451d532017-11-16 17:16:34 +08005913void Context::validateProgramPipeline(GLuint pipeline)
5914{
5915 UNIMPLEMENTED();
5916}
5917
Jamie Madilld04908b2017-06-09 14:15:35 -04005918void Context::getProgramBinary(GLuint program,
5919 GLsizei bufSize,
5920 GLsizei *length,
5921 GLenum *binaryFormat,
5922 void *binary)
5923{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005924 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04005925 ASSERT(programObject != nullptr);
5926
5927 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5928}
5929
5930void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5931{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005932 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04005933 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005934
Jamie Madilld04908b2017-06-09 14:15:35 -04005935 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madill70aeda42018-08-20 12:17:40 -04005936 if (programObject->isInUse())
5937 {
Jamie Madilldf836ff2018-10-01 10:36:24 -04005938 mGLState.onProgramExecutableChange(programObject);
5939 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04005940 }
Jamie Madilld04908b2017-06-09 14:15:35 -04005941}
5942
Jamie Madillff325f12017-08-26 15:06:05 -04005943void Context::uniform1ui(GLint location, GLuint v0)
5944{
5945 Program *program = mGLState.getProgram();
5946 program->setUniform1uiv(location, 1, &v0);
5947}
5948
5949void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5950{
5951 Program *program = mGLState.getProgram();
5952 const GLuint xy[] = {v0, v1};
5953 program->setUniform2uiv(location, 1, xy);
5954}
5955
5956void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5957{
5958 Program *program = mGLState.getProgram();
5959 const GLuint xyz[] = {v0, v1, v2};
5960 program->setUniform3uiv(location, 1, xyz);
5961}
5962
5963void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5964{
5965 Program *program = mGLState.getProgram();
5966 const GLuint xyzw[] = {v0, v1, v2, v3};
5967 program->setUniform4uiv(location, 1, xyzw);
5968}
5969
5970void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5971{
5972 Program *program = mGLState.getProgram();
5973 program->setUniform1uiv(location, count, value);
5974}
5975void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5976{
5977 Program *program = mGLState.getProgram();
5978 program->setUniform2uiv(location, count, value);
5979}
5980
5981void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5982{
5983 Program *program = mGLState.getProgram();
5984 program->setUniform3uiv(location, count, value);
5985}
5986
5987void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5988{
5989 Program *program = mGLState.getProgram();
5990 program->setUniform4uiv(location, count, value);
5991}
5992
Jamie Madillf0e04492017-08-26 15:28:42 -04005993void Context::genQueries(GLsizei n, GLuint *ids)
5994{
5995 for (GLsizei i = 0; i < n; i++)
5996 {
5997 GLuint handle = mQueryHandleAllocator.allocate();
5998 mQueryMap.assign(handle, nullptr);
5999 ids[i] = handle;
6000 }
6001}
6002
6003void Context::deleteQueries(GLsizei n, const GLuint *ids)
6004{
6005 for (int i = 0; i < n; i++)
6006 {
6007 GLuint query = ids[i];
6008
6009 Query *queryObject = nullptr;
6010 if (mQueryMap.erase(query, &queryObject))
6011 {
6012 mQueryHandleAllocator.release(query);
6013 if (queryObject)
6014 {
6015 queryObject->release(this);
6016 }
6017 }
6018 }
6019}
6020
6021GLboolean Context::isQuery(GLuint id)
6022{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006023 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006024}
6025
Jamie Madillc8c95812017-08-26 18:40:09 -04006026void Context::uniformMatrix2x3fv(GLint location,
6027 GLsizei count,
6028 GLboolean transpose,
6029 const GLfloat *value)
6030{
6031 Program *program = mGLState.getProgram();
6032 program->setUniformMatrix2x3fv(location, count, transpose, value);
6033}
6034
6035void Context::uniformMatrix3x2fv(GLint location,
6036 GLsizei count,
6037 GLboolean transpose,
6038 const GLfloat *value)
6039{
6040 Program *program = mGLState.getProgram();
6041 program->setUniformMatrix3x2fv(location, count, transpose, value);
6042}
6043
6044void Context::uniformMatrix2x4fv(GLint location,
6045 GLsizei count,
6046 GLboolean transpose,
6047 const GLfloat *value)
6048{
6049 Program *program = mGLState.getProgram();
6050 program->setUniformMatrix2x4fv(location, count, transpose, value);
6051}
6052
6053void Context::uniformMatrix4x2fv(GLint location,
6054 GLsizei count,
6055 GLboolean transpose,
6056 const GLfloat *value)
6057{
6058 Program *program = mGLState.getProgram();
6059 program->setUniformMatrix4x2fv(location, count, transpose, value);
6060}
6061
6062void Context::uniformMatrix3x4fv(GLint location,
6063 GLsizei count,
6064 GLboolean transpose,
6065 const GLfloat *value)
6066{
6067 Program *program = mGLState.getProgram();
6068 program->setUniformMatrix3x4fv(location, count, transpose, value);
6069}
6070
6071void Context::uniformMatrix4x3fv(GLint location,
6072 GLsizei count,
6073 GLboolean transpose,
6074 const GLfloat *value)
6075{
6076 Program *program = mGLState.getProgram();
6077 program->setUniformMatrix4x3fv(location, count, transpose, value);
6078}
6079
Jamie Madilld7576732017-08-26 18:49:50 -04006080void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6081{
6082 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6083 {
6084 GLuint vertexArray = arrays[arrayIndex];
6085
6086 if (arrays[arrayIndex] != 0)
6087 {
6088 VertexArray *vertexArrayObject = nullptr;
6089 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6090 {
6091 if (vertexArrayObject != nullptr)
6092 {
6093 detachVertexArray(vertexArray);
6094 vertexArrayObject->onDestroy(this);
6095 }
6096
6097 mVertexArrayHandleAllocator.release(vertexArray);
6098 }
6099 }
6100 }
6101}
6102
6103void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6104{
6105 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6106 {
6107 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6108 mVertexArrayMap.assign(vertexArray, nullptr);
6109 arrays[arrayIndex] = vertexArray;
6110 }
6111}
6112
6113bool Context::isVertexArray(GLuint array)
6114{
6115 if (array == 0)
6116 {
6117 return GL_FALSE;
6118 }
6119
6120 VertexArray *vao = getVertexArray(array);
6121 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6122}
6123
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006124void Context::endTransformFeedback()
6125{
6126 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6127 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006128 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006129}
6130
6131void Context::transformFeedbackVaryings(GLuint program,
6132 GLsizei count,
6133 const GLchar *const *varyings,
6134 GLenum bufferMode)
6135{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006136 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006137 ASSERT(programObject);
6138 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6139}
6140
6141void Context::getTransformFeedbackVarying(GLuint program,
6142 GLuint index,
6143 GLsizei bufSize,
6144 GLsizei *length,
6145 GLsizei *size,
6146 GLenum *type,
6147 GLchar *name)
6148{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006149 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006150 ASSERT(programObject);
6151 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6152}
6153
6154void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6155{
6156 for (int i = 0; i < n; i++)
6157 {
6158 GLuint transformFeedback = ids[i];
6159 if (transformFeedback == 0)
6160 {
6161 continue;
6162 }
6163
6164 TransformFeedback *transformFeedbackObject = nullptr;
6165 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6166 {
6167 if (transformFeedbackObject != nullptr)
6168 {
6169 detachTransformFeedback(transformFeedback);
6170 transformFeedbackObject->release(this);
6171 }
6172
6173 mTransformFeedbackHandleAllocator.release(transformFeedback);
6174 }
6175 }
6176}
6177
6178void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6179{
6180 for (int i = 0; i < n; i++)
6181 {
6182 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6183 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6184 ids[i] = transformFeedback;
6185 }
6186}
6187
6188bool Context::isTransformFeedback(GLuint id)
6189{
6190 if (id == 0)
6191 {
6192 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6193 // returns FALSE
6194 return GL_FALSE;
6195 }
6196
6197 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6198 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6199}
6200
6201void Context::pauseTransformFeedback()
6202{
6203 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6204 transformFeedback->pause();
6205}
6206
6207void Context::resumeTransformFeedback()
6208{
6209 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6210 transformFeedback->resume();
6211}
6212
Jamie Madill12e957f2017-08-26 21:42:26 -04006213void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6214{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006215 const Program *programObject = getProgramResolveLink(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006216 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006217}
6218
Brandon Jones59770802018-04-02 13:18:42 -07006219void Context::getUniformuivRobust(GLuint program,
6220 GLint location,
6221 GLsizei bufSize,
6222 GLsizei *length,
6223 GLuint *params)
6224{
6225 getUniformuiv(program, location, params);
6226}
6227
Jamie Madill12e957f2017-08-26 21:42:26 -04006228GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6229{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006230 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006231 return programObject->getFragDataLocation(name);
6232}
6233
6234void Context::getUniformIndices(GLuint program,
6235 GLsizei uniformCount,
6236 const GLchar *const *uniformNames,
6237 GLuint *uniformIndices)
6238{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006239 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006240 if (!programObject->isLinked())
6241 {
6242 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6243 {
6244 uniformIndices[uniformId] = GL_INVALID_INDEX;
6245 }
6246 }
6247 else
6248 {
6249 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6250 {
6251 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6252 }
6253 }
6254}
6255
6256void Context::getActiveUniformsiv(GLuint program,
6257 GLsizei uniformCount,
6258 const GLuint *uniformIndices,
6259 GLenum pname,
6260 GLint *params)
6261{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006262 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006263 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6264 {
6265 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006266 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006267 }
6268}
6269
6270GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6271{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006272 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006273 return programObject->getUniformBlockIndex(uniformBlockName);
6274}
6275
6276void Context::getActiveUniformBlockiv(GLuint program,
6277 GLuint uniformBlockIndex,
6278 GLenum pname,
6279 GLint *params)
6280{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006281 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006282 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6283}
6284
Brandon Jones59770802018-04-02 13:18:42 -07006285void Context::getActiveUniformBlockivRobust(GLuint program,
6286 GLuint uniformBlockIndex,
6287 GLenum pname,
6288 GLsizei bufSize,
6289 GLsizei *length,
6290 GLint *params)
6291{
6292 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6293}
6294
Jamie Madill12e957f2017-08-26 21:42:26 -04006295void Context::getActiveUniformBlockName(GLuint program,
6296 GLuint uniformBlockIndex,
6297 GLsizei bufSize,
6298 GLsizei *length,
6299 GLchar *uniformBlockName)
6300{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006301 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006302 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6303}
6304
6305void Context::uniformBlockBinding(GLuint program,
6306 GLuint uniformBlockIndex,
6307 GLuint uniformBlockBinding)
6308{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006309 Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006310 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006311
6312 if (programObject->isInUse())
6313 {
6314 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006315 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006316 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006317}
6318
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006319GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6320{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006321 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6322 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006323
Jamie Madill70b5bb02017-08-28 13:32:37 -04006324 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006325 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006326 if (error.isError())
6327 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006328 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006329 handleError(error);
6330 return nullptr;
6331 }
6332
Jamie Madill70b5bb02017-08-28 13:32:37 -04006333 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006334}
6335
6336GLboolean Context::isSync(GLsync sync)
6337{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006338 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006339}
6340
6341GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6342{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006343 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006344
6345 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006346 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006347 return result;
6348}
6349
6350void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6351{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006352 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006353 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006354}
6355
6356void Context::getInteger64v(GLenum pname, GLint64 *params)
6357{
6358 GLenum nativeType = GL_NONE;
6359 unsigned int numParams = 0;
6360 getQueryParameterInfo(pname, &nativeType, &numParams);
6361
6362 if (nativeType == GL_INT_64_ANGLEX)
6363 {
6364 getInteger64vImpl(pname, params);
6365 }
6366 else
6367 {
6368 CastStateValues(this, nativeType, pname, numParams, params);
6369 }
6370}
6371
Brandon Jones59770802018-04-02 13:18:42 -07006372void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6373{
6374 getInteger64v(pname, data);
6375}
6376
Corentin Wallez336129f2017-10-17 15:55:40 -04006377void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006378{
6379 Buffer *buffer = mGLState.getTargetBuffer(target);
6380 QueryBufferParameteri64v(buffer, pname, params);
6381}
6382
Brandon Jones59770802018-04-02 13:18:42 -07006383void Context::getBufferParameteri64vRobust(BufferBinding target,
6384 GLenum pname,
6385 GLsizei bufSize,
6386 GLsizei *length,
6387 GLint64 *params)
6388{
6389 getBufferParameteri64v(target, pname, params);
6390}
6391
Jamie Madill3ef140a2017-08-26 23:11:21 -04006392void Context::genSamplers(GLsizei count, GLuint *samplers)
6393{
6394 for (int i = 0; i < count; i++)
6395 {
6396 samplers[i] = mState.mSamplers->createSampler();
6397 }
6398}
6399
6400void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6401{
6402 for (int i = 0; i < count; i++)
6403 {
6404 GLuint sampler = samplers[i];
6405
6406 if (mState.mSamplers->getSampler(sampler))
6407 {
6408 detachSampler(sampler);
6409 }
6410
6411 mState.mSamplers->deleteObject(this, sampler);
6412 }
6413}
6414
6415void Context::getInternalformativ(GLenum target,
6416 GLenum internalformat,
6417 GLenum pname,
6418 GLsizei bufSize,
6419 GLint *params)
6420{
6421 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6422 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6423}
6424
Brandon Jones59770802018-04-02 13:18:42 -07006425void Context::getInternalformativRobust(GLenum target,
6426 GLenum internalformat,
6427 GLenum pname,
6428 GLsizei bufSize,
6429 GLsizei *length,
6430 GLint *params)
6431{
6432 getInternalformativ(target, internalformat, pname, bufSize, params);
6433}
6434
Jiajia Qin5451d532017-11-16 17:16:34 +08006435void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6436{
6437 programUniform1iv(program, location, 1, &v0);
6438}
6439
6440void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6441{
6442 GLint xy[2] = {v0, v1};
6443 programUniform2iv(program, location, 1, xy);
6444}
6445
6446void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6447{
6448 GLint xyz[3] = {v0, v1, v2};
6449 programUniform3iv(program, location, 1, xyz);
6450}
6451
6452void Context::programUniform4i(GLuint program,
6453 GLint location,
6454 GLint v0,
6455 GLint v1,
6456 GLint v2,
6457 GLint v3)
6458{
6459 GLint xyzw[4] = {v0, v1, v2, v3};
6460 programUniform4iv(program, location, 1, xyzw);
6461}
6462
6463void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6464{
6465 programUniform1uiv(program, location, 1, &v0);
6466}
6467
6468void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6469{
6470 GLuint xy[2] = {v0, v1};
6471 programUniform2uiv(program, location, 1, xy);
6472}
6473
6474void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6475{
6476 GLuint xyz[3] = {v0, v1, v2};
6477 programUniform3uiv(program, location, 1, xyz);
6478}
6479
6480void Context::programUniform4ui(GLuint program,
6481 GLint location,
6482 GLuint v0,
6483 GLuint v1,
6484 GLuint v2,
6485 GLuint v3)
6486{
6487 GLuint xyzw[4] = {v0, v1, v2, v3};
6488 programUniform4uiv(program, location, 1, xyzw);
6489}
6490
6491void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6492{
6493 programUniform1fv(program, location, 1, &v0);
6494}
6495
6496void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6497{
6498 GLfloat xy[2] = {v0, v1};
6499 programUniform2fv(program, location, 1, xy);
6500}
6501
6502void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6503{
6504 GLfloat xyz[3] = {v0, v1, v2};
6505 programUniform3fv(program, location, 1, xyz);
6506}
6507
6508void Context::programUniform4f(GLuint program,
6509 GLint location,
6510 GLfloat v0,
6511 GLfloat v1,
6512 GLfloat v2,
6513 GLfloat v3)
6514{
6515 GLfloat xyzw[4] = {v0, v1, v2, v3};
6516 programUniform4fv(program, location, 1, xyzw);
6517}
6518
Jamie Madill81c2e252017-09-09 23:32:46 -04006519void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6520{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006521 Program *programObject = getProgramResolveLink(program);
Jamie Madill81c2e252017-09-09 23:32:46 -04006522 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006523 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006524}
6525
Jiajia Qin5451d532017-11-16 17:16:34 +08006526void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6527{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006528 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006529 ASSERT(programObject);
6530 programObject->setUniform2iv(location, count, value);
6531}
6532
6533void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6534{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006535 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006536 ASSERT(programObject);
6537 programObject->setUniform3iv(location, count, value);
6538}
6539
6540void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6541{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006542 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006543 ASSERT(programObject);
6544 programObject->setUniform4iv(location, count, value);
6545}
6546
6547void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6548{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006549 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006550 ASSERT(programObject);
6551 programObject->setUniform1uiv(location, count, value);
6552}
6553
6554void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6555{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006556 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006557 ASSERT(programObject);
6558 programObject->setUniform2uiv(location, count, value);
6559}
6560
6561void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6562{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006563 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006564 ASSERT(programObject);
6565 programObject->setUniform3uiv(location, count, value);
6566}
6567
6568void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6569{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006570 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006571 ASSERT(programObject);
6572 programObject->setUniform4uiv(location, count, value);
6573}
6574
6575void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6576{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006577 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006578 ASSERT(programObject);
6579 programObject->setUniform1fv(location, count, value);
6580}
6581
6582void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6583{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006584 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006585 ASSERT(programObject);
6586 programObject->setUniform2fv(location, count, value);
6587}
6588
6589void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6590{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006591 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006592 ASSERT(programObject);
6593 programObject->setUniform3fv(location, count, value);
6594}
6595
6596void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6597{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006598 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006599 ASSERT(programObject);
6600 programObject->setUniform4fv(location, count, value);
6601}
6602
6603void Context::programUniformMatrix2fv(GLuint program,
6604 GLint location,
6605 GLsizei count,
6606 GLboolean transpose,
6607 const GLfloat *value)
6608{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006609 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006610 ASSERT(programObject);
6611 programObject->setUniformMatrix2fv(location, count, transpose, value);
6612}
6613
6614void Context::programUniformMatrix3fv(GLuint program,
6615 GLint location,
6616 GLsizei count,
6617 GLboolean transpose,
6618 const GLfloat *value)
6619{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006620 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006621 ASSERT(programObject);
6622 programObject->setUniformMatrix3fv(location, count, transpose, value);
6623}
6624
6625void Context::programUniformMatrix4fv(GLuint program,
6626 GLint location,
6627 GLsizei count,
6628 GLboolean transpose,
6629 const GLfloat *value)
6630{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006631 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006632 ASSERT(programObject);
6633 programObject->setUniformMatrix4fv(location, count, transpose, value);
6634}
6635
6636void Context::programUniformMatrix2x3fv(GLuint program,
6637 GLint location,
6638 GLsizei count,
6639 GLboolean transpose,
6640 const GLfloat *value)
6641{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006642 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006643 ASSERT(programObject);
6644 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6645}
6646
6647void Context::programUniformMatrix3x2fv(GLuint program,
6648 GLint location,
6649 GLsizei count,
6650 GLboolean transpose,
6651 const GLfloat *value)
6652{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006653 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006654 ASSERT(programObject);
6655 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6656}
6657
6658void Context::programUniformMatrix2x4fv(GLuint program,
6659 GLint location,
6660 GLsizei count,
6661 GLboolean transpose,
6662 const GLfloat *value)
6663{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006664 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006665 ASSERT(programObject);
6666 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6667}
6668
6669void Context::programUniformMatrix4x2fv(GLuint program,
6670 GLint location,
6671 GLsizei count,
6672 GLboolean transpose,
6673 const GLfloat *value)
6674{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006675 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006676 ASSERT(programObject);
6677 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6678}
6679
6680void Context::programUniformMatrix3x4fv(GLuint program,
6681 GLint location,
6682 GLsizei count,
6683 GLboolean transpose,
6684 const GLfloat *value)
6685{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006686 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006687 ASSERT(programObject);
6688 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6689}
6690
6691void Context::programUniformMatrix4x3fv(GLuint program,
6692 GLint location,
6693 GLsizei count,
6694 GLboolean transpose,
6695 const GLfloat *value)
6696{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006697 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006698 ASSERT(programObject);
6699 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6700}
6701
Jamie Madill81c2e252017-09-09 23:32:46 -04006702void Context::onTextureChange(const Texture *texture)
6703{
6704 // Conservatively assume all textures are dirty.
6705 // TODO(jmadill): More fine-grained update.
6706 mGLState.setObjectDirty(GL_TEXTURE);
6707}
6708
James Darpiniane8a93c62018-01-04 18:02:24 -08006709bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6710{
6711 return mGLState.isCurrentTransformFeedback(tf);
6712}
James Darpiniane8a93c62018-01-04 18:02:24 -08006713
Yunchao Hea336b902017-08-02 16:05:21 +08006714void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6715{
6716 for (int i = 0; i < count; i++)
6717 {
6718 pipelines[i] = createProgramPipeline();
6719 }
6720}
6721
6722void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6723{
6724 for (int i = 0; i < count; i++)
6725 {
6726 if (pipelines[i] != 0)
6727 {
6728 deleteProgramPipeline(pipelines[i]);
6729 }
6730 }
6731}
6732
6733GLboolean Context::isProgramPipeline(GLuint pipeline)
6734{
6735 if (pipeline == 0)
6736 {
6737 return GL_FALSE;
6738 }
6739
6740 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6741}
6742
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006743void Context::finishFenceNV(GLuint fence)
6744{
6745 FenceNV *fenceObject = getFenceNV(fence);
6746
6747 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006748 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006749}
6750
6751void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6752{
6753 FenceNV *fenceObject = getFenceNV(fence);
6754
6755 ASSERT(fenceObject && fenceObject->isSet());
6756
6757 switch (pname)
6758 {
6759 case GL_FENCE_STATUS_NV:
6760 {
6761 // GL_NV_fence spec:
6762 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6763 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6764 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6765 GLboolean status = GL_TRUE;
6766 if (fenceObject->getStatus() != GL_TRUE)
6767 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006768 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006769 }
6770 *params = status;
6771 break;
6772 }
6773
6774 case GL_FENCE_CONDITION_NV:
6775 {
6776 *params = static_cast<GLint>(fenceObject->getCondition());
6777 break;
6778 }
6779
6780 default:
6781 UNREACHABLE();
6782 }
6783}
6784
6785void Context::getTranslatedShaderSource(GLuint shader,
6786 GLsizei bufsize,
6787 GLsizei *length,
6788 GLchar *source)
6789{
6790 Shader *shaderObject = getShader(shader);
6791 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006792 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006793}
6794
6795void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6796{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006797 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006798 ASSERT(programObject);
6799
6800 programObject->getUniformfv(this, location, params);
6801}
6802
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006803void Context::getnUniformfvRobust(GLuint program,
6804 GLint location,
6805 GLsizei bufSize,
6806 GLsizei *length,
6807 GLfloat *params)
6808{
6809 UNIMPLEMENTED();
6810}
6811
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006812void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6813{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006814 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006815 ASSERT(programObject);
6816
6817 programObject->getUniformiv(this, location, params);
6818}
6819
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006820void Context::getnUniformivRobust(GLuint program,
6821 GLint location,
6822 GLsizei bufSize,
6823 GLsizei *length,
6824 GLint *params)
6825{
6826 UNIMPLEMENTED();
6827}
6828
6829void Context::getnUniformuivRobust(GLuint program,
6830 GLint location,
6831 GLsizei bufSize,
6832 GLsizei *length,
6833 GLuint *params)
6834{
6835 UNIMPLEMENTED();
6836}
6837
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006838GLboolean Context::isFenceNV(GLuint fence)
6839{
6840 FenceNV *fenceObject = getFenceNV(fence);
6841
6842 if (fenceObject == nullptr)
6843 {
6844 return GL_FALSE;
6845 }
6846
6847 // GL_NV_fence spec:
6848 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6849 // existing fence.
6850 return fenceObject->isSet();
6851}
6852
6853void Context::readnPixels(GLint x,
6854 GLint y,
6855 GLsizei width,
6856 GLsizei height,
6857 GLenum format,
6858 GLenum type,
6859 GLsizei bufSize,
6860 void *data)
6861{
6862 return readPixels(x, y, width, height, format, type, data);
6863}
6864
Jamie Madill007530e2017-12-28 14:27:04 -05006865void Context::setFenceNV(GLuint fence, GLenum condition)
6866{
6867 ASSERT(condition == GL_ALL_COMPLETED_NV);
6868
6869 FenceNV *fenceObject = getFenceNV(fence);
6870 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006871 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006872}
6873
6874GLboolean Context::testFenceNV(GLuint fence)
6875{
6876 FenceNV *fenceObject = getFenceNV(fence);
6877
6878 ASSERT(fenceObject != nullptr);
6879 ASSERT(fenceObject->isSet() == GL_TRUE);
6880
6881 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006882 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006883 if (error.isError())
6884 {
6885 handleError(error);
6886 return GL_TRUE;
6887 }
6888
6889 return result;
6890}
6891
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006892void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006893{
6894 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006895 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006896 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006897}
6898
Jamie Madillfa920eb2018-01-04 11:45:50 -05006899void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006900{
6901 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006902 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006903 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6904}
6905
Jamie Madillfa920eb2018-01-04 11:45:50 -05006906void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6907{
6908 UNIMPLEMENTED();
6909}
6910
Jamie Madill5b772312018-03-08 20:28:32 -05006911bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6912{
6913 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6914 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6915 // to the fact that it is stored internally as a float, and so would require conversion
6916 // if returned from Context::getIntegerv. Since this conversion is already implemented
6917 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6918 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6919 // application.
6920 switch (pname)
6921 {
6922 case GL_COMPRESSED_TEXTURE_FORMATS:
6923 {
6924 *type = GL_INT;
6925 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6926 return true;
6927 }
6928 case GL_SHADER_BINARY_FORMATS:
6929 {
6930 *type = GL_INT;
6931 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6932 return true;
6933 }
6934
6935 case GL_MAX_VERTEX_ATTRIBS:
6936 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6937 case GL_MAX_VARYING_VECTORS:
6938 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6939 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6940 case GL_MAX_TEXTURE_IMAGE_UNITS:
6941 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6942 case GL_MAX_RENDERBUFFER_SIZE:
6943 case GL_NUM_SHADER_BINARY_FORMATS:
6944 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6945 case GL_ARRAY_BUFFER_BINDING:
6946 case GL_FRAMEBUFFER_BINDING:
6947 case GL_RENDERBUFFER_BINDING:
6948 case GL_CURRENT_PROGRAM:
6949 case GL_PACK_ALIGNMENT:
6950 case GL_UNPACK_ALIGNMENT:
6951 case GL_GENERATE_MIPMAP_HINT:
6952 case GL_RED_BITS:
6953 case GL_GREEN_BITS:
6954 case GL_BLUE_BITS:
6955 case GL_ALPHA_BITS:
6956 case GL_DEPTH_BITS:
6957 case GL_STENCIL_BITS:
6958 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6959 case GL_CULL_FACE_MODE:
6960 case GL_FRONT_FACE:
6961 case GL_ACTIVE_TEXTURE:
6962 case GL_STENCIL_FUNC:
6963 case GL_STENCIL_VALUE_MASK:
6964 case GL_STENCIL_REF:
6965 case GL_STENCIL_FAIL:
6966 case GL_STENCIL_PASS_DEPTH_FAIL:
6967 case GL_STENCIL_PASS_DEPTH_PASS:
6968 case GL_STENCIL_BACK_FUNC:
6969 case GL_STENCIL_BACK_VALUE_MASK:
6970 case GL_STENCIL_BACK_REF:
6971 case GL_STENCIL_BACK_FAIL:
6972 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6973 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6974 case GL_DEPTH_FUNC:
6975 case GL_BLEND_SRC_RGB:
6976 case GL_BLEND_SRC_ALPHA:
6977 case GL_BLEND_DST_RGB:
6978 case GL_BLEND_DST_ALPHA:
6979 case GL_BLEND_EQUATION_RGB:
6980 case GL_BLEND_EQUATION_ALPHA:
6981 case GL_STENCIL_WRITEMASK:
6982 case GL_STENCIL_BACK_WRITEMASK:
6983 case GL_STENCIL_CLEAR_VALUE:
6984 case GL_SUBPIXEL_BITS:
6985 case GL_MAX_TEXTURE_SIZE:
6986 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6987 case GL_SAMPLE_BUFFERS:
6988 case GL_SAMPLES:
6989 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6990 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6991 case GL_TEXTURE_BINDING_2D:
6992 case GL_TEXTURE_BINDING_CUBE_MAP:
6993 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6994 {
6995 *type = GL_INT;
6996 *numParams = 1;
6997 return true;
6998 }
6999 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
7000 {
7001 if (!getExtensions().packReverseRowOrder)
7002 {
7003 return false;
7004 }
7005 *type = GL_INT;
7006 *numParams = 1;
7007 return true;
7008 }
7009 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7010 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7011 {
7012 if (!getExtensions().textureRectangle)
7013 {
7014 return false;
7015 }
7016 *type = GL_INT;
7017 *numParams = 1;
7018 return true;
7019 }
7020 case GL_MAX_DRAW_BUFFERS_EXT:
7021 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7022 {
7023 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7024 {
7025 return false;
7026 }
7027 *type = GL_INT;
7028 *numParams = 1;
7029 return true;
7030 }
7031 case GL_MAX_VIEWPORT_DIMS:
7032 {
7033 *type = GL_INT;
7034 *numParams = 2;
7035 return true;
7036 }
7037 case GL_VIEWPORT:
7038 case GL_SCISSOR_BOX:
7039 {
7040 *type = GL_INT;
7041 *numParams = 4;
7042 return true;
7043 }
7044 case GL_SHADER_COMPILER:
7045 case GL_SAMPLE_COVERAGE_INVERT:
7046 case GL_DEPTH_WRITEMASK:
7047 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7048 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7049 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7050 // bool-natural
7051 case GL_SAMPLE_COVERAGE:
7052 case GL_SCISSOR_TEST:
7053 case GL_STENCIL_TEST:
7054 case GL_DEPTH_TEST:
7055 case GL_BLEND:
7056 case GL_DITHER:
7057 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7058 {
7059 *type = GL_BOOL;
7060 *numParams = 1;
7061 return true;
7062 }
7063 case GL_COLOR_WRITEMASK:
7064 {
7065 *type = GL_BOOL;
7066 *numParams = 4;
7067 return true;
7068 }
7069 case GL_POLYGON_OFFSET_FACTOR:
7070 case GL_POLYGON_OFFSET_UNITS:
7071 case GL_SAMPLE_COVERAGE_VALUE:
7072 case GL_DEPTH_CLEAR_VALUE:
7073 case GL_LINE_WIDTH:
7074 {
7075 *type = GL_FLOAT;
7076 *numParams = 1;
7077 return true;
7078 }
7079 case GL_ALIASED_LINE_WIDTH_RANGE:
7080 case GL_ALIASED_POINT_SIZE_RANGE:
7081 case GL_DEPTH_RANGE:
7082 {
7083 *type = GL_FLOAT;
7084 *numParams = 2;
7085 return true;
7086 }
7087 case GL_COLOR_CLEAR_VALUE:
7088 case GL_BLEND_COLOR:
7089 {
7090 *type = GL_FLOAT;
7091 *numParams = 4;
7092 return true;
7093 }
7094 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7095 if (!getExtensions().textureFilterAnisotropic)
7096 {
7097 return false;
7098 }
7099 *type = GL_FLOAT;
7100 *numParams = 1;
7101 return true;
7102 case GL_TIMESTAMP_EXT:
7103 if (!getExtensions().disjointTimerQuery)
7104 {
7105 return false;
7106 }
7107 *type = GL_INT_64_ANGLEX;
7108 *numParams = 1;
7109 return true;
7110 case GL_GPU_DISJOINT_EXT:
7111 if (!getExtensions().disjointTimerQuery)
7112 {
7113 return false;
7114 }
7115 *type = GL_INT;
7116 *numParams = 1;
7117 return true;
7118 case GL_COVERAGE_MODULATION_CHROMIUM:
7119 if (!getExtensions().framebufferMixedSamples)
7120 {
7121 return false;
7122 }
7123 *type = GL_INT;
7124 *numParams = 1;
7125 return true;
7126 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7127 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7128 {
7129 return false;
7130 }
7131 *type = GL_INT;
7132 *numParams = 1;
7133 return true;
7134 }
7135
7136 if (getExtensions().debug)
7137 {
7138 switch (pname)
7139 {
7140 case GL_DEBUG_LOGGED_MESSAGES:
7141 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7142 case GL_DEBUG_GROUP_STACK_DEPTH:
7143 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7144 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7145 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7146 case GL_MAX_LABEL_LENGTH:
7147 *type = GL_INT;
7148 *numParams = 1;
7149 return true;
7150
7151 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7152 case GL_DEBUG_OUTPUT:
7153 *type = GL_BOOL;
7154 *numParams = 1;
7155 return true;
7156 }
7157 }
7158
7159 if (getExtensions().multisampleCompatibility)
7160 {
7161 switch (pname)
7162 {
7163 case GL_MULTISAMPLE_EXT:
7164 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7165 *type = GL_BOOL;
7166 *numParams = 1;
7167 return true;
7168 }
7169 }
7170
7171 if (getExtensions().pathRendering)
7172 {
7173 switch (pname)
7174 {
7175 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7176 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7177 *type = GL_FLOAT;
7178 *numParams = 16;
7179 return true;
7180 }
7181 }
7182
7183 if (getExtensions().bindGeneratesResource)
7184 {
7185 switch (pname)
7186 {
7187 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7188 *type = GL_BOOL;
7189 *numParams = 1;
7190 return true;
7191 }
7192 }
7193
7194 if (getExtensions().clientArrays)
7195 {
7196 switch (pname)
7197 {
7198 case GL_CLIENT_ARRAYS_ANGLE:
7199 *type = GL_BOOL;
7200 *numParams = 1;
7201 return true;
7202 }
7203 }
7204
7205 if (getExtensions().sRGBWriteControl)
7206 {
7207 switch (pname)
7208 {
7209 case GL_FRAMEBUFFER_SRGB_EXT:
7210 *type = GL_BOOL;
7211 *numParams = 1;
7212 return true;
7213 }
7214 }
7215
7216 if (getExtensions().robustResourceInitialization &&
7217 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7218 {
7219 *type = GL_BOOL;
7220 *numParams = 1;
7221 return true;
7222 }
7223
7224 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7225 {
7226 *type = GL_BOOL;
7227 *numParams = 1;
7228 return true;
7229 }
7230
jchen1082af6202018-06-22 10:59:52 +08007231 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7232 {
7233 *type = GL_INT;
7234 *numParams = 1;
7235 return true;
7236 }
7237
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007238 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7239 {
7240 *type = GL_INT;
7241 *numParams = 1;
7242 return true;
7243 }
7244
Jamie Madill5b772312018-03-08 20:28:32 -05007245 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7246 switch (pname)
7247 {
7248 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7249 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7250 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7251 {
7252 return false;
7253 }
7254 *type = GL_INT;
7255 *numParams = 1;
7256 return true;
7257
7258 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7259 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7260 {
7261 return false;
7262 }
7263 *type = GL_INT;
7264 *numParams = 1;
7265 return true;
7266
7267 case GL_PROGRAM_BINARY_FORMATS_OES:
7268 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7269 {
7270 return false;
7271 }
7272 *type = GL_INT;
7273 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7274 return true;
7275
7276 case GL_PACK_ROW_LENGTH:
7277 case GL_PACK_SKIP_ROWS:
7278 case GL_PACK_SKIP_PIXELS:
7279 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7280 {
7281 return false;
7282 }
7283 *type = GL_INT;
7284 *numParams = 1;
7285 return true;
7286 case GL_UNPACK_ROW_LENGTH:
7287 case GL_UNPACK_SKIP_ROWS:
7288 case GL_UNPACK_SKIP_PIXELS:
7289 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7290 {
7291 return false;
7292 }
7293 *type = GL_INT;
7294 *numParams = 1;
7295 return true;
7296 case GL_VERTEX_ARRAY_BINDING:
7297 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7298 {
7299 return false;
7300 }
7301 *type = GL_INT;
7302 *numParams = 1;
7303 return true;
7304 case GL_PIXEL_PACK_BUFFER_BINDING:
7305 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7306 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7307 {
7308 return false;
7309 }
7310 *type = GL_INT;
7311 *numParams = 1;
7312 return true;
7313 case GL_MAX_SAMPLES:
7314 {
7315 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7316 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7317 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7318 {
7319 return false;
7320 }
7321 *type = GL_INT;
7322 *numParams = 1;
7323 return true;
7324
7325 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7326 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7327 {
7328 return false;
7329 }
7330 *type = GL_INT;
7331 *numParams = 1;
7332 return true;
7333 }
7334 }
7335
7336 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7337 {
7338 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7339 {
7340 return false;
7341 }
7342 *type = GL_INT;
7343 *numParams = 1;
7344 return true;
7345 }
7346
7347 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7348 {
7349 *type = GL_INT;
7350 *numParams = 1;
7351 return true;
7352 }
7353
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007354 if (getClientVersion() < Version(2, 0))
7355 {
7356 switch (pname)
7357 {
7358 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007359 case GL_CLIENT_ACTIVE_TEXTURE:
7360 case GL_MATRIX_MODE:
7361 case GL_MAX_TEXTURE_UNITS:
7362 case GL_MAX_MODELVIEW_STACK_DEPTH:
7363 case GL_MAX_PROJECTION_STACK_DEPTH:
7364 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007365 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007366 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007367 case GL_VERTEX_ARRAY_STRIDE:
7368 case GL_NORMAL_ARRAY_STRIDE:
7369 case GL_COLOR_ARRAY_STRIDE:
7370 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7371 case GL_VERTEX_ARRAY_SIZE:
7372 case GL_COLOR_ARRAY_SIZE:
7373 case GL_TEXTURE_COORD_ARRAY_SIZE:
7374 case GL_VERTEX_ARRAY_TYPE:
7375 case GL_NORMAL_ARRAY_TYPE:
7376 case GL_COLOR_ARRAY_TYPE:
7377 case GL_TEXTURE_COORD_ARRAY_TYPE:
7378 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7379 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7380 case GL_COLOR_ARRAY_BUFFER_BINDING:
7381 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7382 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7383 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7384 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007385 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007386 case GL_MODELVIEW_STACK_DEPTH:
7387 case GL_PROJECTION_STACK_DEPTH:
7388 case GL_TEXTURE_STACK_DEPTH:
7389 case GL_LOGIC_OP_MODE:
7390 case GL_BLEND_SRC:
7391 case GL_BLEND_DST:
7392 case GL_PERSPECTIVE_CORRECTION_HINT:
7393 case GL_POINT_SMOOTH_HINT:
7394 case GL_LINE_SMOOTH_HINT:
7395 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007396 *type = GL_INT;
7397 *numParams = 1;
7398 return true;
7399 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007400 case GL_FOG_DENSITY:
7401 case GL_FOG_START:
7402 case GL_FOG_END:
7403 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007404 case GL_POINT_SIZE:
7405 case GL_POINT_SIZE_MIN:
7406 case GL_POINT_SIZE_MAX:
7407 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007408 *type = GL_FLOAT;
7409 *numParams = 1;
7410 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007411 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007412 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007413 *type = GL_FLOAT;
7414 *numParams = 2;
7415 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007416 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007417 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007418 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007419 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007420 *type = GL_FLOAT;
7421 *numParams = 4;
7422 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007423 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007424 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007425 *type = GL_FLOAT;
7426 *numParams = 3;
7427 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007428 case GL_MODELVIEW_MATRIX:
7429 case GL_PROJECTION_MATRIX:
7430 case GL_TEXTURE_MATRIX:
7431 *type = GL_FLOAT;
7432 *numParams = 16;
7433 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007434 case GL_LIGHT_MODEL_TWO_SIDE:
7435 *type = GL_BOOL;
7436 *numParams = 1;
7437 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007438 }
7439 }
7440
Jamie Madill5b772312018-03-08 20:28:32 -05007441 if (getClientVersion() < Version(3, 0))
7442 {
7443 return false;
7444 }
7445
7446 // Check for ES3.0+ parameter names
7447 switch (pname)
7448 {
7449 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7450 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7451 case GL_UNIFORM_BUFFER_BINDING:
7452 case GL_TRANSFORM_FEEDBACK_BINDING:
7453 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7454 case GL_COPY_READ_BUFFER_BINDING:
7455 case GL_COPY_WRITE_BUFFER_BINDING:
7456 case GL_SAMPLER_BINDING:
7457 case GL_READ_BUFFER:
7458 case GL_TEXTURE_BINDING_3D:
7459 case GL_TEXTURE_BINDING_2D_ARRAY:
7460 case GL_MAX_3D_TEXTURE_SIZE:
7461 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7462 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7463 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7464 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7465 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7466 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7467 case GL_MAX_VARYING_COMPONENTS:
7468 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7469 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7470 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7471 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7472 case GL_NUM_EXTENSIONS:
7473 case GL_MAJOR_VERSION:
7474 case GL_MINOR_VERSION:
7475 case GL_MAX_ELEMENTS_INDICES:
7476 case GL_MAX_ELEMENTS_VERTICES:
7477 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7478 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7479 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7480 case GL_UNPACK_IMAGE_HEIGHT:
7481 case GL_UNPACK_SKIP_IMAGES:
7482 {
7483 *type = GL_INT;
7484 *numParams = 1;
7485 return true;
7486 }
7487
7488 case GL_MAX_ELEMENT_INDEX:
7489 case GL_MAX_UNIFORM_BLOCK_SIZE:
7490 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7491 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7492 case GL_MAX_SERVER_WAIT_TIMEOUT:
7493 {
7494 *type = GL_INT_64_ANGLEX;
7495 *numParams = 1;
7496 return true;
7497 }
7498
7499 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7500 case GL_TRANSFORM_FEEDBACK_PAUSED:
7501 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7502 case GL_RASTERIZER_DISCARD:
7503 {
7504 *type = GL_BOOL;
7505 *numParams = 1;
7506 return true;
7507 }
7508
7509 case GL_MAX_TEXTURE_LOD_BIAS:
7510 {
7511 *type = GL_FLOAT;
7512 *numParams = 1;
7513 return true;
7514 }
7515 }
7516
7517 if (getExtensions().requestExtension)
7518 {
7519 switch (pname)
7520 {
7521 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7522 *type = GL_INT;
7523 *numParams = 1;
7524 return true;
7525 }
7526 }
7527
7528 if (getClientVersion() < Version(3, 1))
7529 {
7530 return false;
7531 }
7532
7533 switch (pname)
7534 {
7535 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7536 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7537 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7538 case GL_MAX_FRAMEBUFFER_WIDTH:
7539 case GL_MAX_FRAMEBUFFER_HEIGHT:
7540 case GL_MAX_FRAMEBUFFER_SAMPLES:
7541 case GL_MAX_SAMPLE_MASK_WORDS:
7542 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7543 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7544 case GL_MAX_INTEGER_SAMPLES:
7545 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7546 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7547 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7548 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7549 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7550 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7551 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7552 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7553 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7554 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7555 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7556 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7557 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7558 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7559 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7560 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7561 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7562 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7563 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7564 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7565 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7566 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7567 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7568 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7569 case GL_MAX_UNIFORM_LOCATIONS:
7570 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7571 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7572 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7573 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7574 case GL_MAX_IMAGE_UNITS:
7575 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7576 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7577 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7578 case GL_SHADER_STORAGE_BUFFER_BINDING:
7579 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7580 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007581 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007582 *type = GL_INT;
7583 *numParams = 1;
7584 return true;
7585 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7586 *type = GL_INT_64_ANGLEX;
7587 *numParams = 1;
7588 return true;
7589 case GL_SAMPLE_MASK:
7590 *type = GL_BOOL;
7591 *numParams = 1;
7592 return true;
7593 }
7594
7595 if (getExtensions().geometryShader)
7596 {
7597 switch (pname)
7598 {
7599 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7600 case GL_LAYER_PROVOKING_VERTEX_EXT:
7601 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7602 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7603 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7604 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7605 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7606 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7607 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7608 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7609 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7610 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7611 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7612 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7613 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7614 *type = GL_INT;
7615 *numParams = 1;
7616 return true;
7617 }
7618 }
7619
7620 return false;
7621}
7622
7623bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7624{
7625 if (getClientVersion() < Version(3, 0))
7626 {
7627 return false;
7628 }
7629
7630 switch (target)
7631 {
7632 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7633 case GL_UNIFORM_BUFFER_BINDING:
7634 {
7635 *type = GL_INT;
7636 *numParams = 1;
7637 return true;
7638 }
7639 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7640 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7641 case GL_UNIFORM_BUFFER_START:
7642 case GL_UNIFORM_BUFFER_SIZE:
7643 {
7644 *type = GL_INT_64_ANGLEX;
7645 *numParams = 1;
7646 return true;
7647 }
7648 }
7649
7650 if (getClientVersion() < Version(3, 1))
7651 {
7652 return false;
7653 }
7654
7655 switch (target)
7656 {
7657 case GL_IMAGE_BINDING_LAYERED:
7658 {
7659 *type = GL_BOOL;
7660 *numParams = 1;
7661 return true;
7662 }
7663 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7664 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7665 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7666 case GL_SHADER_STORAGE_BUFFER_BINDING:
7667 case GL_VERTEX_BINDING_BUFFER:
7668 case GL_VERTEX_BINDING_DIVISOR:
7669 case GL_VERTEX_BINDING_OFFSET:
7670 case GL_VERTEX_BINDING_STRIDE:
7671 case GL_SAMPLE_MASK_VALUE:
7672 case GL_IMAGE_BINDING_NAME:
7673 case GL_IMAGE_BINDING_LEVEL:
7674 case GL_IMAGE_BINDING_LAYER:
7675 case GL_IMAGE_BINDING_ACCESS:
7676 case GL_IMAGE_BINDING_FORMAT:
7677 {
7678 *type = GL_INT;
7679 *numParams = 1;
7680 return true;
7681 }
7682 case GL_ATOMIC_COUNTER_BUFFER_START:
7683 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7684 case GL_SHADER_STORAGE_BUFFER_START:
7685 case GL_SHADER_STORAGE_BUFFER_SIZE:
7686 {
7687 *type = GL_INT_64_ANGLEX;
7688 *numParams = 1;
7689 return true;
7690 }
7691 }
7692
7693 return false;
7694}
7695
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007696Program *Context::getProgramResolveLink(GLuint handle) const
7697{
7698 Program *program = mState.mShaderPrograms->getProgram(handle);
7699 if (program)
7700 {
7701 program->resolveLink();
7702 }
7703 return program;
7704}
7705
7706Program *Context::getProgramNoResolveLink(GLuint handle) const
Jamie Madill5b772312018-03-08 20:28:32 -05007707{
7708 return mState.mShaderPrograms->getProgram(handle);
7709}
7710
7711Shader *Context::getShader(GLuint handle) const
7712{
7713 return mState.mShaderPrograms->getShader(handle);
7714}
7715
7716bool Context::isTextureGenerated(GLuint texture) const
7717{
7718 return mState.mTextures->isHandleGenerated(texture);
7719}
7720
Jamie Madill5b772312018-03-08 20:28:32 -05007721bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7722{
7723 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7724}
7725
7726bool Context::isFramebufferGenerated(GLuint framebuffer) const
7727{
7728 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7729}
7730
7731bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7732{
7733 return mState.mPipelines->isHandleGenerated(pipeline);
7734}
7735
7736bool Context::usingDisplayTextureShareGroup() const
7737{
7738 return mDisplayTextureShareGroup;
7739}
7740
7741GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7742{
7743 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7744 internalformat == GL_DEPTH_STENCIL
7745 ? GL_DEPTH24_STENCIL8
7746 : internalformat;
7747}
7748
jchen1082af6202018-06-22 10:59:52 +08007749void Context::maxShaderCompilerThreads(GLuint count)
7750{
jchen107ae70d82018-07-06 13:47:01 +08007751 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08007752 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007753 // A count of zero specifies a request for no parallel compiling or linking.
7754 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7755 {
7756 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7757 }
7758 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007759}
7760
Jamie Madill2eb65032018-07-30 10:25:57 -04007761bool Context::isGLES1() const
7762{
7763 return mState.getClientVersion() < Version(2, 0);
7764}
7765
Jamie Madilla11819d2018-07-30 10:26:01 -04007766void Context::onSubjectStateChange(const Context *context,
7767 angle::SubjectIndex index,
7768 angle::SubjectMessage message)
7769{
Jamie Madilla11819d2018-07-30 10:26:01 -04007770 switch (index)
7771 {
7772 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007773 switch (message)
7774 {
7775 case angle::SubjectMessage::CONTENTS_CHANGED:
7776 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
7777 mStateCache.onVertexArrayBufferContentsChange(this);
7778 break;
7779 case angle::SubjectMessage::RESOURCE_MAPPED:
7780 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7781 case angle::SubjectMessage::BINDING_CHANGED:
7782 mStateCache.onVertexArrayBufferStateChange(this);
7783 break;
7784 default:
7785 break;
7786 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007787 break;
7788
7789 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007790 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7791 {
7792 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
7793 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007794 break;
7795
7796 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007797 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7798 {
7799 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
7800 }
7801 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04007802 break;
7803
7804 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04007805 if (index < kTextureMaxSubjectIndex)
7806 {
7807 mGLState.onActiveTextureStateChange(index);
Jamie Madilld84b6732018-09-06 15:54:35 -04007808 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007809 }
Jamie Madille25b8002018-09-20 13:39:49 -04007810 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04007811 {
Jamie Madill6d32cef2018-08-14 02:34:28 -04007812 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04007813 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007814 }
Jamie Madille25b8002018-09-20 13:39:49 -04007815 else
7816 {
7817 ASSERT(index < kSamplerMaxSubjectIndex);
7818 mGLState.setSamplerDirty(index - kSampler0SubjectIndex);
7819 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007820 break;
7821 }
7822}
7823
Jamie Madill6b873dd2018-07-12 23:56:30 -04007824// ErrorSet implementation.
7825ErrorSet::ErrorSet(Context *context) : mContext(context)
7826{
7827}
7828
7829ErrorSet::~ErrorSet() = default;
7830
Jamie Madill306b6c12018-07-27 08:12:49 -04007831void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007832{
7833 // This internal enum is used to filter internal errors that are already handled.
7834 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7835 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7836 {
7837 return;
7838 }
7839
7840 if (ANGLE_UNLIKELY(error.isError()))
7841 {
7842 GLenum code = error.getCode();
7843 mErrors.insert(code);
7844 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7845 {
7846 mContext->markContextLost();
7847 }
7848
7849 ASSERT(!error.getMessage().empty());
7850 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7851 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7852 error.getMessage());
7853 }
7854}
7855
7856bool ErrorSet::empty() const
7857{
7858 return mErrors.empty();
7859}
7860
7861GLenum ErrorSet::popError()
7862{
7863 ASSERT(!empty());
7864 GLenum error = *mErrors.begin();
7865 mErrors.erase(mErrors.begin());
7866 return error;
7867}
Jamie Madilldc358af2018-07-31 11:22:13 -04007868
7869// StateCache implementation.
Jamie Madill16e28fd2018-09-12 11:03:05 -04007870StateCache::StateCache(Context *context)
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007871 : mCachedHasAnyEnabledClientAttrib(false),
7872 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04007873 mCachedInstancedVertexElementLimit(0),
7874 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madilldc358af2018-07-31 11:22:13 -04007875{
Jamie Madill16e28fd2018-09-12 11:03:05 -04007876 updateValidDrawModes(context);
Jamie Madilldc358af2018-07-31 11:22:13 -04007877}
7878
7879StateCache::~StateCache() = default;
7880
7881void StateCache::updateActiveAttribsMask(Context *context)
7882{
7883 bool isGLES1 = context->isGLES1();
7884 const State &glState = context->getGLState();
7885
7886 if (!isGLES1 && !glState.getProgram())
7887 {
7888 mCachedActiveBufferedAttribsMask = AttributesMask();
7889 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04007890 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04007891 return;
7892 }
7893
7894 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7895 : glState.getProgram()->getActiveAttribLocationsMask();
7896
7897 const VertexArray *vao = glState.getVertexArray();
7898 ASSERT(vao);
7899
7900 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7901 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04007902 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007903
Jamie Madill0a17e482018-08-31 17:19:11 -04007904 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
7905 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04007906 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007907 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7908}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007909
7910void StateCache::updateVertexElementLimits(Context *context)
7911{
7912 const VertexArray *vao = context->getGLState().getVertexArray();
7913
7914 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7915 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7916
7917 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
7918 // If there are no buffered attributes then we should not limit the draw call count.
7919 if (!vao || !mCachedActiveBufferedAttribsMask.any())
7920 {
7921 return;
7922 }
7923
7924 const auto &vertexAttribs = vao->getVertexAttributes();
7925 const auto &vertexBindings = vao->getVertexBindings();
7926
7927 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
7928 {
7929 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
7930 ASSERT(attrib.enabled);
7931
7932 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
7933 ASSERT(context->isGLES1() ||
7934 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
7935
7936 GLint64 limit = attrib.getCachedElementLimit();
7937 if (binding.getDivisor() > 0)
7938 {
7939 mCachedInstancedVertexElementLimit =
7940 std::min(mCachedInstancedVertexElementLimit, limit);
7941 }
7942 else
7943 {
7944 mCachedNonInstancedVertexElementLimit =
7945 std::min(mCachedNonInstancedVertexElementLimit, limit);
7946 }
7947 }
7948}
Jamie Madillc43cdad2018-08-08 15:49:25 -04007949
Jamie Madilld84b6732018-09-06 15:54:35 -04007950void StateCache::updateBasicDrawStatesError()
7951{
7952 mCachedBasicDrawStatesError = kInvalidPointer;
7953}
7954
7955intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
7956{
7957 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
7958 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
7959 return mCachedBasicDrawStatesError;
7960}
7961
Jamie Madillc43cdad2018-08-08 15:49:25 -04007962void StateCache::onVertexArrayBindingChange(Context *context)
7963{
7964 updateActiveAttribsMask(context);
7965 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007966 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007967}
7968
7969void StateCache::onProgramExecutableChange(Context *context)
7970{
7971 updateActiveAttribsMask(context);
7972 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007973 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04007974 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04007975}
7976
Jamie Madilld84b6732018-09-06 15:54:35 -04007977void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04007978{
7979 updateVertexElementLimits(context);
7980}
7981
Jamie Madilld84b6732018-09-06 15:54:35 -04007982void StateCache::onVertexArrayBufferContentsChange(Context *context)
7983{
7984 updateVertexElementLimits(context);
7985 updateBasicDrawStatesError();
7986}
7987
Jamie Madillc43cdad2018-08-08 15:49:25 -04007988void StateCache::onVertexArrayStateChange(Context *context)
7989{
7990 updateActiveAttribsMask(context);
7991 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007992 updateBasicDrawStatesError();
7993}
7994
7995void StateCache::onVertexArrayBufferStateChange(Context *context)
7996{
7997 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007998}
7999
8000void StateCache::onGLES1ClientStateChange(Context *context)
8001{
8002 updateActiveAttribsMask(context);
8003}
Jamie Madilld84b6732018-09-06 15:54:35 -04008004
8005void StateCache::onDrawFramebufferChange(Context *context)
8006{
8007 updateBasicDrawStatesError();
8008}
8009
8010void StateCache::onContextCapChange(Context *context)
8011{
8012 updateBasicDrawStatesError();
8013}
8014
8015void StateCache::onStencilStateChange(Context *context)
8016{
8017 updateBasicDrawStatesError();
8018}
8019
8020void StateCache::onDefaultVertexAttributeChange(Context *context)
8021{
8022 updateBasicDrawStatesError();
8023}
8024
8025void StateCache::onActiveTextureChange(Context *context)
8026{
8027 updateBasicDrawStatesError();
8028}
8029
8030void StateCache::onQueryChange(Context *context)
8031{
8032 updateBasicDrawStatesError();
8033}
8034
8035void StateCache::onTransformFeedbackChange(Context *context)
8036{
8037 updateBasicDrawStatesError();
8038}
8039
8040void StateCache::onUniformBufferStateChange(Context *context)
8041{
8042 updateBasicDrawStatesError();
8043}
8044
8045void StateCache::onBufferBindingChange(Context *context)
8046{
8047 updateBasicDrawStatesError();
8048}
Jamie Madill526a6f62018-09-12 11:03:05 -04008049
8050void StateCache::updateValidDrawModes(Context *context)
8051{
8052 Program *program = context->getGLState().getProgram();
8053 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8054 {
8055 mCachedValidDrawModes = {{
8056 true, /* Points */
8057 true, /* Lines */
8058 true, /* LineLoop */
8059 true, /* LineStrip */
8060 true, /* Triangles */
8061 true, /* TriangleStrip */
8062 true, /* TriangleFan */
8063 false, /* LinesAdjacency */
8064 false, /* LineStripAdjacency */
8065 false, /* TrianglesAdjacency */
8066 false, /* TriangleStripAdjacency */
8067 false, /* InvalidEnum */
8068 }};
8069 }
8070 else
8071 {
8072 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8073
8074 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
8075
8076 mCachedValidDrawModes = {{
8077 gsMode == PrimitiveMode::Points, /* Points */
8078 gsMode == PrimitiveMode::Lines, /* Lines */
8079 gsMode == PrimitiveMode::Lines, /* LineLoop */
8080 gsMode == PrimitiveMode::Lines, /* LineStrip */
8081 gsMode == PrimitiveMode::Triangles, /* Triangles */
8082 gsMode == PrimitiveMode::Triangles, /* TriangleStrip */
8083 gsMode == PrimitiveMode::Triangles, /* TriangleFan */
8084 gsMode == PrimitiveMode::LinesAdjacency, /* LinesAdjacency */
8085 gsMode == PrimitiveMode::LinesAdjacency, /* LineStripAdjacency */
8086 gsMode == PrimitiveMode::TrianglesAdjacency, /* TrianglesAdjacency */
8087 gsMode == PrimitiveMode::TrianglesAdjacency, /* TriangleStripAdjacency */
8088 false, /* InvalidEnum */
8089 }};
8090 }
8091}
Jamie Madillc29968b2016-01-20 11:17:23 -05008092} // namespace gl