blob: 1837199c6d66cec49bfc95c3ca6c0825279ba421 [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:
1027 return getProgram(name);
1028 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 Madill6c1f6712017-02-14 19:08:04 -05001181 mGLState.setProgram(this, getProgram(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
Jamie Madill231c7f52017-04-26 13:45:37 -04001606 // GL_KHR_debug
1607 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1608 *params = mExtensions.maxDebugMessageLength;
1609 break;
1610 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1611 *params = mExtensions.maxDebugLoggedMessages;
1612 break;
1613 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1614 *params = mExtensions.maxDebugGroupStackDepth;
1615 break;
1616 case GL_MAX_LABEL_LENGTH:
1617 *params = mExtensions.maxLabelLength;
1618 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001619
Martin Radeve5285d22017-07-14 16:23:53 +03001620 // GL_ANGLE_multiview
1621 case GL_MAX_VIEWS_ANGLE:
1622 *params = mExtensions.maxViews;
1623 break;
1624
Jamie Madill231c7f52017-04-26 13:45:37 -04001625 // GL_EXT_disjoint_timer_query
1626 case GL_GPU_DISJOINT_EXT:
1627 *params = mImplementation->getGPUDisjoint();
1628 break;
1629 case GL_MAX_FRAMEBUFFER_WIDTH:
1630 *params = mCaps.maxFramebufferWidth;
1631 break;
1632 case GL_MAX_FRAMEBUFFER_HEIGHT:
1633 *params = mCaps.maxFramebufferHeight;
1634 break;
1635 case GL_MAX_FRAMEBUFFER_SAMPLES:
1636 *params = mCaps.maxFramebufferSamples;
1637 break;
1638 case GL_MAX_SAMPLE_MASK_WORDS:
1639 *params = mCaps.maxSampleMaskWords;
1640 break;
1641 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1642 *params = mCaps.maxColorTextureSamples;
1643 break;
1644 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1645 *params = mCaps.maxDepthTextureSamples;
1646 break;
1647 case GL_MAX_INTEGER_SAMPLES:
1648 *params = mCaps.maxIntegerSamples;
1649 break;
1650 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1651 *params = mCaps.maxVertexAttribRelativeOffset;
1652 break;
1653 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1654 *params = mCaps.maxVertexAttribBindings;
1655 break;
1656 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1657 *params = mCaps.maxVertexAttribStride;
1658 break;
1659 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001660 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001661 break;
1662 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001663 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001664 break;
1665 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001666 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001667 break;
1668 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001669 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001670 break;
1671 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001672 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001673 break;
1674 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001675 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001676 break;
1677 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001678 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001679 break;
1680 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001681 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001682 break;
1683 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1684 *params = mCaps.minProgramTextureGatherOffset;
1685 break;
1686 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1687 *params = mCaps.maxProgramTextureGatherOffset;
1688 break;
1689 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1690 *params = mCaps.maxComputeWorkGroupInvocations;
1691 break;
1692 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001693 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001694 break;
1695 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001696 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001697 break;
1698 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1699 *params = mCaps.maxComputeSharedMemorySize;
1700 break;
1701 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001702 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001703 break;
1704 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001705 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001706 break;
1707 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001708 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001709 break;
1710 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001711 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001712 break;
1713 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001714 *params =
1715 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001716 break;
1717 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001718 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001719 break;
1720 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1721 *params = mCaps.maxCombinedShaderOutputResources;
1722 break;
1723 case GL_MAX_UNIFORM_LOCATIONS:
1724 *params = mCaps.maxUniformLocations;
1725 break;
1726 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1727 *params = mCaps.maxAtomicCounterBufferBindings;
1728 break;
1729 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1730 *params = mCaps.maxAtomicCounterBufferSize;
1731 break;
1732 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1733 *params = mCaps.maxCombinedAtomicCounterBuffers;
1734 break;
1735 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1736 *params = mCaps.maxCombinedAtomicCounters;
1737 break;
1738 case GL_MAX_IMAGE_UNITS:
1739 *params = mCaps.maxImageUnits;
1740 break;
1741 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1742 *params = mCaps.maxCombinedImageUniforms;
1743 break;
1744 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1745 *params = mCaps.maxShaderStorageBufferBindings;
1746 break;
1747 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1748 *params = mCaps.maxCombinedShaderStorageBlocks;
1749 break;
1750 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1751 *params = mCaps.shaderStorageBufferOffsetAlignment;
1752 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001753
1754 // GL_EXT_geometry_shader
1755 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1756 *params = mCaps.maxFramebufferLayers;
1757 break;
1758 case GL_LAYER_PROVOKING_VERTEX_EXT:
1759 *params = mCaps.layerProvokingVertex;
1760 break;
1761 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001762 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001763 break;
1764 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001765 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001766 break;
1767 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001768 *params =
1769 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001770 break;
1771 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1772 *params = mCaps.maxGeometryInputComponents;
1773 break;
1774 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1775 *params = mCaps.maxGeometryOutputComponents;
1776 break;
1777 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1778 *params = mCaps.maxGeometryOutputVertices;
1779 break;
1780 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1781 *params = mCaps.maxGeometryTotalOutputComponents;
1782 break;
1783 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1784 *params = mCaps.maxGeometryShaderInvocations;
1785 break;
1786 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001787 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001788 break;
1789 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001790 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001791 break;
1792 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001793 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001794 break;
1795 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001796 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001797 break;
1798 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001799 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001800 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001801 // GLES1 emulation: Caps queries
1802 case GL_MAX_TEXTURE_UNITS:
1803 *params = mCaps.maxMultitextureUnits;
1804 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001805 case GL_MAX_MODELVIEW_STACK_DEPTH:
1806 *params = mCaps.maxModelviewMatrixStackDepth;
1807 break;
1808 case GL_MAX_PROJECTION_STACK_DEPTH:
1809 *params = mCaps.maxProjectionMatrixStackDepth;
1810 break;
1811 case GL_MAX_TEXTURE_STACK_DEPTH:
1812 *params = mCaps.maxTextureMatrixStackDepth;
1813 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001814 case GL_MAX_LIGHTS:
1815 *params = mCaps.maxLights;
1816 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001817 case GL_MAX_CLIP_PLANES:
1818 *params = mCaps.maxClipPlanes;
1819 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001820 // GLES1 emulation: Vertex attribute queries
1821 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1822 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1823 case GL_COLOR_ARRAY_BUFFER_BINDING:
1824 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1825 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1826 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1827 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1828 break;
1829 case GL_VERTEX_ARRAY_STRIDE:
1830 case GL_NORMAL_ARRAY_STRIDE:
1831 case GL_COLOR_ARRAY_STRIDE:
1832 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1833 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1834 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1835 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1836 break;
1837 case GL_VERTEX_ARRAY_SIZE:
1838 case GL_COLOR_ARRAY_SIZE:
1839 case GL_TEXTURE_COORD_ARRAY_SIZE:
1840 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1841 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1842 break;
1843 case GL_VERTEX_ARRAY_TYPE:
1844 case GL_COLOR_ARRAY_TYPE:
1845 case GL_NORMAL_ARRAY_TYPE:
1846 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1847 case GL_TEXTURE_COORD_ARRAY_TYPE:
1848 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1849 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1850 break;
1851
jchen1082af6202018-06-22 10:59:52 +08001852 // GL_KHR_parallel_shader_compile
1853 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1854 *params = mGLState.getMaxShaderCompilerThreads();
1855 break;
1856
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001857 // GL_EXT_blend_func_extended
1858 case GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT:
1859 *params = mExtensions.maxDualSourceDrawBuffers;
1860 break;
1861
Jamie Madill231c7f52017-04-26 13:45:37 -04001862 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001863 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001864 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001865 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001866}
1867
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001868void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001869{
Shannon Woods53a94a82014-06-24 15:20:36 -04001870 // Queries about context capabilities and maximums are answered by Context.
1871 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001872 switch (pname)
1873 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001874 case GL_MAX_ELEMENT_INDEX:
1875 *params = mCaps.maxElementIndex;
1876 break;
1877 case GL_MAX_UNIFORM_BLOCK_SIZE:
1878 *params = mCaps.maxUniformBlockSize;
1879 break;
1880 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001881 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001882 break;
1883 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001884 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001885 break;
1886 case GL_MAX_SERVER_WAIT_TIMEOUT:
1887 *params = mCaps.maxServerWaitTimeout;
1888 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001889
Jamie Madill231c7f52017-04-26 13:45:37 -04001890 // GL_EXT_disjoint_timer_query
1891 case GL_TIMESTAMP_EXT:
1892 *params = mImplementation->getTimestamp();
1893 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001894
Jamie Madill231c7f52017-04-26 13:45:37 -04001895 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1896 *params = mCaps.maxShaderStorageBlockSize;
1897 break;
1898 default:
1899 UNREACHABLE();
1900 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001901 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001902}
1903
Geoff Lang70d0f492015-12-10 17:45:46 -05001904void Context::getPointerv(GLenum pname, void **params) const
1905{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001906 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001907}
1908
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001909void Context::getPointervRobustANGLERobust(GLenum pname,
1910 GLsizei bufSize,
1911 GLsizei *length,
1912 void **params)
1913{
1914 UNIMPLEMENTED();
1915}
1916
Martin Radev66fb8202016-07-28 11:45:20 +03001917void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001918{
Shannon Woods53a94a82014-06-24 15:20:36 -04001919 // Queries about context capabilities and maximums are answered by Context.
1920 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001921
1922 GLenum nativeType;
1923 unsigned int numParams;
1924 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1925 ASSERT(queryStatus);
1926
1927 if (nativeType == GL_INT)
1928 {
1929 switch (target)
1930 {
1931 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1932 ASSERT(index < 3u);
1933 *data = mCaps.maxComputeWorkGroupCount[index];
1934 break;
1935 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1936 ASSERT(index < 3u);
1937 *data = mCaps.maxComputeWorkGroupSize[index];
1938 break;
1939 default:
1940 mGLState.getIntegeri_v(target, index, data);
1941 }
1942 }
1943 else
1944 {
1945 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1946 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001947}
1948
Brandon Jones59770802018-04-02 13:18:42 -07001949void Context::getIntegeri_vRobust(GLenum target,
1950 GLuint index,
1951 GLsizei bufSize,
1952 GLsizei *length,
1953 GLint *data)
1954{
1955 getIntegeri_v(target, index, data);
1956}
1957
Martin Radev66fb8202016-07-28 11:45:20 +03001958void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001959{
Shannon Woods53a94a82014-06-24 15:20:36 -04001960 // Queries about context capabilities and maximums are answered by Context.
1961 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001962
1963 GLenum nativeType;
1964 unsigned int numParams;
1965 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1966 ASSERT(queryStatus);
1967
1968 if (nativeType == GL_INT_64_ANGLEX)
1969 {
1970 mGLState.getInteger64i_v(target, index, data);
1971 }
1972 else
1973 {
1974 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1975 }
1976}
1977
Brandon Jones59770802018-04-02 13:18:42 -07001978void Context::getInteger64i_vRobust(GLenum target,
1979 GLuint index,
1980 GLsizei bufSize,
1981 GLsizei *length,
1982 GLint64 *data)
1983{
1984 getInteger64i_v(target, index, data);
1985}
1986
Martin Radev66fb8202016-07-28 11:45:20 +03001987void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1988{
1989 // Queries about context capabilities and maximums are answered by Context.
1990 // Queries about current GL state values are answered by State.
1991
1992 GLenum nativeType;
1993 unsigned int numParams;
1994 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1995 ASSERT(queryStatus);
1996
1997 if (nativeType == GL_BOOL)
1998 {
1999 mGLState.getBooleani_v(target, index, data);
2000 }
2001 else
2002 {
2003 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
2004 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04002005}
2006
Brandon Jones59770802018-04-02 13:18:42 -07002007void Context::getBooleani_vRobust(GLenum target,
2008 GLuint index,
2009 GLsizei bufSize,
2010 GLsizei *length,
2011 GLboolean *data)
2012{
2013 getBooleani_v(target, index, data);
2014}
2015
Corentin Wallez336129f2017-10-17 15:55:40 -04002016void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002017{
2018 Buffer *buffer = mGLState.getTargetBuffer(target);
2019 QueryBufferParameteriv(buffer, pname, params);
2020}
2021
Brandon Jones59770802018-04-02 13:18:42 -07002022void Context::getBufferParameterivRobust(BufferBinding target,
2023 GLenum pname,
2024 GLsizei bufSize,
2025 GLsizei *length,
2026 GLint *params)
2027{
2028 getBufferParameteriv(target, pname, params);
2029}
2030
He Yunchao010e4db2017-03-03 14:22:06 +08002031void Context::getFramebufferAttachmentParameteriv(GLenum target,
2032 GLenum attachment,
2033 GLenum pname,
2034 GLint *params)
2035{
2036 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002037 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002038}
2039
Brandon Jones59770802018-04-02 13:18:42 -07002040void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2041 GLenum attachment,
2042 GLenum pname,
2043 GLsizei bufSize,
2044 GLsizei *length,
2045 GLint *params)
2046{
2047 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2048}
2049
He Yunchao010e4db2017-03-03 14:22:06 +08002050void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2051{
2052 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2053 QueryRenderbufferiv(this, renderbuffer, pname, params);
2054}
2055
Brandon Jones59770802018-04-02 13:18:42 -07002056void Context::getRenderbufferParameterivRobust(GLenum target,
2057 GLenum pname,
2058 GLsizei bufSize,
2059 GLsizei *length,
2060 GLint *params)
2061{
2062 getRenderbufferParameteriv(target, pname, params);
2063}
2064
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002065void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002066{
2067 Texture *texture = getTargetTexture(target);
2068 QueryTexParameterfv(texture, pname, params);
2069}
2070
Brandon Jones59770802018-04-02 13:18:42 -07002071void Context::getTexParameterfvRobust(TextureType target,
2072 GLenum pname,
2073 GLsizei bufSize,
2074 GLsizei *length,
2075 GLfloat *params)
2076{
2077 getTexParameterfv(target, pname, params);
2078}
2079
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002080void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002081{
2082 Texture *texture = getTargetTexture(target);
2083 QueryTexParameteriv(texture, pname, params);
2084}
Jiajia Qin5451d532017-11-16 17:16:34 +08002085
Brandon Jones59770802018-04-02 13:18:42 -07002086void Context::getTexParameterivRobust(TextureType target,
2087 GLenum pname,
2088 GLsizei bufSize,
2089 GLsizei *length,
2090 GLint *params)
2091{
2092 getTexParameteriv(target, pname, params);
2093}
2094
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002095void Context::getTexParameterIivRobust(TextureType target,
2096 GLenum pname,
2097 GLsizei bufSize,
2098 GLsizei *length,
2099 GLint *params)
2100{
2101 UNIMPLEMENTED();
2102}
2103
2104void Context::getTexParameterIuivRobust(TextureType target,
2105 GLenum pname,
2106 GLsizei bufSize,
2107 GLsizei *length,
2108 GLuint *params)
2109{
2110 UNIMPLEMENTED();
2111}
2112
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002113void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002114{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002115 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002116 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002117}
2118
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002119void Context::getTexLevelParameterivRobust(TextureTarget target,
2120 GLint level,
2121 GLenum pname,
2122 GLsizei bufSize,
2123 GLsizei *length,
2124 GLint *params)
2125{
2126 UNIMPLEMENTED();
2127}
2128
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002129void Context::getTexLevelParameterfv(TextureTarget target,
2130 GLint level,
2131 GLenum pname,
2132 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002133{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002134 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002135 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002136}
2137
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002138void Context::getTexLevelParameterfvRobust(TextureTarget target,
2139 GLint level,
2140 GLenum pname,
2141 GLsizei bufSize,
2142 GLsizei *length,
2143 GLfloat *params)
2144{
2145 UNIMPLEMENTED();
2146}
2147
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002148void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002149{
2150 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002151 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002152 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002153}
2154
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002155void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002156{
2157 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002158 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002159 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002160}
2161
Brandon Jones59770802018-04-02 13:18:42 -07002162void Context::texParameterfvRobust(TextureType target,
2163 GLenum pname,
2164 GLsizei bufSize,
2165 const GLfloat *params)
2166{
2167 texParameterfv(target, pname, params);
2168}
2169
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002170void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002171{
2172 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002173 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002174 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002175}
2176
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002177void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002178{
2179 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002180 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002181 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002182}
2183
Brandon Jones59770802018-04-02 13:18:42 -07002184void Context::texParameterivRobust(TextureType target,
2185 GLenum pname,
2186 GLsizei bufSize,
2187 const GLint *params)
2188{
2189 texParameteriv(target, pname, params);
2190}
2191
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002192void Context::texParameterIivRobust(TextureType target,
2193 GLenum pname,
2194 GLsizei bufSize,
2195 const GLint *params)
2196{
2197 UNIMPLEMENTED();
2198}
2199
2200void Context::texParameterIuivRobust(TextureType target,
2201 GLenum pname,
2202 GLsizei bufSize,
2203 const GLuint *params)
2204{
2205 UNIMPLEMENTED();
2206}
2207
Jamie Madill493f9572018-05-24 19:52:15 -04002208void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002209{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002210 // No-op if count draws no primitives for given mode
2211 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002212 {
2213 return;
2214 }
2215
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002216 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002217 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002218 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002219}
2220
Jamie Madill493f9572018-05-24 19:52:15 -04002221void Context::drawArraysInstanced(PrimitiveMode mode,
2222 GLint first,
2223 GLsizei count,
2224 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002225{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002226 // No-op if count draws no primitives for given mode
2227 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002228 {
2229 return;
2230 }
2231
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002232 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002233 ANGLE_CONTEXT_TRY(
2234 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002235 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2236 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002237}
2238
Jamie Madill493f9572018-05-24 19:52:15 -04002239void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002240{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002241 // No-op if count draws no primitives for given mode
2242 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002243 {
2244 return;
2245 }
2246
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002247 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002248 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002249}
2250
Jamie Madill493f9572018-05-24 19:52:15 -04002251void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002252 GLsizei count,
2253 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002254 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002255 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002256{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002257 // No-op if count draws no primitives for given mode
2258 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002259 {
2260 return;
2261 }
2262
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002263 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002264 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002265 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002266}
2267
Jamie Madill493f9572018-05-24 19:52:15 -04002268void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002269 GLuint start,
2270 GLuint end,
2271 GLsizei count,
2272 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002273 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002274{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002275 // No-op if count draws no primitives for given mode
2276 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002277 {
2278 return;
2279 }
2280
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002281 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002282 ANGLE_CONTEXT_TRY(
2283 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002284}
2285
Jamie Madill493f9572018-05-24 19:52:15 -04002286void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002287{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002288 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002289 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002290}
2291
Jamie Madill493f9572018-05-24 19:52:15 -04002292void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002293{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002294 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002295 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002296}
2297
Jamie Madill675fe712016-12-19 13:07:54 -05002298void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002299{
Jamie Madillafa02a22017-11-23 12:57:38 -05002300 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002301}
2302
Jamie Madill675fe712016-12-19 13:07:54 -05002303void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002304{
Jamie Madillafa02a22017-11-23 12:57:38 -05002305 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002306}
2307
Austin Kinross6ee1e782015-05-29 17:05:37 -07002308void Context::insertEventMarker(GLsizei length, const char *marker)
2309{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002310 ASSERT(mImplementation);
2311 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002312}
2313
2314void Context::pushGroupMarker(GLsizei length, const char *marker)
2315{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002316 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002317
2318 if (marker == nullptr)
2319 {
2320 // From the EXT_debug_marker spec,
2321 // "If <marker> is null then an empty string is pushed on the stack."
2322 mImplementation->pushGroupMarker(length, "");
2323 }
2324 else
2325 {
2326 mImplementation->pushGroupMarker(length, marker);
2327 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002328}
2329
2330void Context::popGroupMarker()
2331{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002332 ASSERT(mImplementation);
2333 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002334}
2335
Geoff Langd8605522016-04-13 10:19:12 -04002336void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2337{
2338 Program *programObject = getProgram(program);
2339 ASSERT(programObject);
2340
2341 programObject->bindUniformLocation(location, name);
2342}
2343
Brandon Jones59770802018-04-02 13:18:42 -07002344void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002345{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002346 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002347}
2348
Brandon Jones59770802018-04-02 13:18:42 -07002349void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002350{
2351 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2352}
2353
Brandon Jones59770802018-04-02 13:18:42 -07002354void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002355{
2356 GLfloat I[16];
2357 angle::Matrix<GLfloat>::setToIdentity(I);
2358
2359 mGLState.loadPathRenderingMatrix(matrixMode, I);
2360}
2361
2362void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2363{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002364 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002365 if (!pathObj)
2366 return;
2367
Geoff Lang9bf86f02018-07-26 11:46:34 -04002368 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002369
2370 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2371}
2372
2373void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2374{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002375 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002376 if (!pathObj)
2377 return;
2378
Geoff Lang9bf86f02018-07-26 11:46:34 -04002379 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002380
2381 mImplementation->stencilStrokePath(pathObj, reference, mask);
2382}
2383
2384void Context::coverFillPath(GLuint path, GLenum coverMode)
2385{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002386 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002387 if (!pathObj)
2388 return;
2389
Geoff Lang9bf86f02018-07-26 11:46:34 -04002390 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002391
2392 mImplementation->coverFillPath(pathObj, coverMode);
2393}
2394
2395void Context::coverStrokePath(GLuint path, GLenum coverMode)
2396{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002397 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002398 if (!pathObj)
2399 return;
2400
Geoff Lang9bf86f02018-07-26 11:46:34 -04002401 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002402
2403 mImplementation->coverStrokePath(pathObj, coverMode);
2404}
2405
2406void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2407{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002408 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002409 if (!pathObj)
2410 return;
2411
Geoff Lang9bf86f02018-07-26 11:46:34 -04002412 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002413
2414 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2415}
2416
2417void Context::stencilThenCoverStrokePath(GLuint path,
2418 GLint reference,
2419 GLuint mask,
2420 GLenum coverMode)
2421{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002422 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002423 if (!pathObj)
2424 return;
2425
Geoff Lang9bf86f02018-07-26 11:46:34 -04002426 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002427
2428 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2429}
2430
Sami Väisänend59ca052016-06-21 16:10:00 +03002431void Context::coverFillPathInstanced(GLsizei numPaths,
2432 GLenum pathNameType,
2433 const void *paths,
2434 GLuint pathBase,
2435 GLenum coverMode,
2436 GLenum transformType,
2437 const GLfloat *transformValues)
2438{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002439 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002440
Geoff Lang9bf86f02018-07-26 11:46:34 -04002441 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002442
2443 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2444}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002445
Sami Väisänend59ca052016-06-21 16:10:00 +03002446void Context::coverStrokePathInstanced(GLsizei numPaths,
2447 GLenum pathNameType,
2448 const void *paths,
2449 GLuint pathBase,
2450 GLenum coverMode,
2451 GLenum transformType,
2452 const GLfloat *transformValues)
2453{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002454 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002455
2456 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002457 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002458
2459 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2460 transformValues);
2461}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002462
Sami Väisänend59ca052016-06-21 16:10:00 +03002463void Context::stencilFillPathInstanced(GLsizei numPaths,
2464 GLenum pathNameType,
2465 const void *paths,
2466 GLuint pathBase,
2467 GLenum fillMode,
2468 GLuint mask,
2469 GLenum transformType,
2470 const GLfloat *transformValues)
2471{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002472 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002473
2474 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002475 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002476
2477 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2478 transformValues);
2479}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002480
Sami Väisänend59ca052016-06-21 16:10:00 +03002481void Context::stencilStrokePathInstanced(GLsizei numPaths,
2482 GLenum pathNameType,
2483 const void *paths,
2484 GLuint pathBase,
2485 GLint reference,
2486 GLuint mask,
2487 GLenum transformType,
2488 const GLfloat *transformValues)
2489{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002490 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002491
Geoff Lang9bf86f02018-07-26 11:46:34 -04002492 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002493
2494 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2495 transformValues);
2496}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002497
Sami Väisänend59ca052016-06-21 16:10:00 +03002498void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2499 GLenum pathNameType,
2500 const void *paths,
2501 GLuint pathBase,
2502 GLenum fillMode,
2503 GLuint mask,
2504 GLenum coverMode,
2505 GLenum transformType,
2506 const GLfloat *transformValues)
2507{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002508 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002509
Geoff Lang9bf86f02018-07-26 11:46:34 -04002510 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002511
2512 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2513 transformType, transformValues);
2514}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002515
Sami Väisänend59ca052016-06-21 16:10:00 +03002516void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2517 GLenum pathNameType,
2518 const void *paths,
2519 GLuint pathBase,
2520 GLint reference,
2521 GLuint mask,
2522 GLenum coverMode,
2523 GLenum transformType,
2524 const GLfloat *transformValues)
2525{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002526 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002527
Geoff Lang9bf86f02018-07-26 11:46:34 -04002528 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002529
2530 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2531 transformType, transformValues);
2532}
2533
Sami Väisänen46eaa942016-06-29 10:26:37 +03002534void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2535{
2536 auto *programObject = getProgram(program);
2537
2538 programObject->bindFragmentInputLocation(location, name);
2539}
2540
2541void Context::programPathFragmentInputGen(GLuint program,
2542 GLint location,
2543 GLenum genMode,
2544 GLint components,
2545 const GLfloat *coeffs)
2546{
2547 auto *programObject = getProgram(program);
2548
jchen103fd614d2018-08-13 12:21:58 +08002549 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002550}
2551
jchen1015015f72017-03-16 13:54:21 +08002552GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2553{
jchen10fd7c3b52017-03-21 15:36:03 +08002554 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002555 return QueryProgramResourceIndex(programObject, programInterface, name);
2556}
2557
jchen10fd7c3b52017-03-21 15:36:03 +08002558void Context::getProgramResourceName(GLuint program,
2559 GLenum programInterface,
2560 GLuint index,
2561 GLsizei bufSize,
2562 GLsizei *length,
2563 GLchar *name)
2564{
2565 const auto *programObject = getProgram(program);
2566 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2567}
2568
jchen10191381f2017-04-11 13:59:04 +08002569GLint Context::getProgramResourceLocation(GLuint program,
2570 GLenum programInterface,
2571 const GLchar *name)
2572{
2573 const auto *programObject = getProgram(program);
2574 return QueryProgramResourceLocation(programObject, programInterface, name);
2575}
2576
jchen10880683b2017-04-12 16:21:55 +08002577void Context::getProgramResourceiv(GLuint program,
2578 GLenum programInterface,
2579 GLuint index,
2580 GLsizei propCount,
2581 const GLenum *props,
2582 GLsizei bufSize,
2583 GLsizei *length,
2584 GLint *params)
2585{
2586 const auto *programObject = getProgram(program);
2587 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2588 length, params);
2589}
2590
jchen10d9cd7b72017-08-30 15:04:25 +08002591void Context::getProgramInterfaceiv(GLuint program,
2592 GLenum programInterface,
2593 GLenum pname,
2594 GLint *params)
2595{
2596 const auto *programObject = getProgram(program);
2597 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2598}
2599
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002600void Context::getProgramInterfaceivRobust(GLuint program,
2601 GLenum programInterface,
2602 GLenum pname,
2603 GLsizei bufSize,
2604 GLsizei *length,
2605 GLint *params)
2606{
2607 UNIMPLEMENTED();
2608}
2609
Jamie Madill306b6c12018-07-27 08:12:49 -04002610void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002611{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002612 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002613}
2614
2615// Get one of the recorded errors and clear its flag, if any.
2616// [OpenGL ES 2.0.24] section 2.5 page 13.
2617GLenum Context::getError()
2618{
Geoff Langda5777c2014-07-11 09:52:58 -04002619 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002620 {
Geoff Langda5777c2014-07-11 09:52:58 -04002621 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002622 }
Geoff Langda5777c2014-07-11 09:52:58 -04002623 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002624 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002625 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002626 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002627}
2628
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002629// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002630void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002631{
2632 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002633 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002634 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002635 mContextLostForced = true;
2636 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002637 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002638}
2639
Jamie Madillfa920eb2018-01-04 11:45:50 -05002640GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002641{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002642 // Even if the application doesn't want to know about resets, we want to know
2643 // as it will allow us to skip all the calls.
2644 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002645 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002646 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002647 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002648 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002649 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002650
2651 // EXT_robustness, section 2.6: If the reset notification behavior is
2652 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2653 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2654 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002655 }
2656
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002657 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2658 // status should be returned at least once, and GL_NO_ERROR should be returned
2659 // once the device has finished resetting.
2660 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002661 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002662 ASSERT(mResetStatus == GL_NO_ERROR);
2663 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002664
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002665 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002666 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002667 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002668 }
2669 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002670 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002671 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002672 // If markContextLost was used to mark the context lost then
2673 // assume that is not recoverable, and continue to report the
2674 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002675 mResetStatus = mImplementation->getResetStatus();
2676 }
Jamie Madill893ab082014-05-16 16:56:10 -04002677
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002678 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002679}
2680
2681bool Context::isResetNotificationEnabled()
2682{
2683 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2684}
2685
Corentin Walleze3b10e82015-05-20 11:06:25 -04002686const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002687{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002688 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002689}
2690
2691EGLenum Context::getClientType() const
2692{
2693 return mClientType;
2694}
2695
2696EGLenum Context::getRenderBuffer() const
2697{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002698 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2699 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002700 {
2701 return EGL_NONE;
2702 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002703
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002704 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002705 ASSERT(backAttachment != nullptr);
2706 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002707}
2708
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002709VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002710{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002711 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002712 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2713 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002714 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002715 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2716 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002717
Jamie Madill96a483b2017-06-27 16:49:21 -04002718 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002719 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002720
2721 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002722}
2723
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002724TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002725{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002726 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002727 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2728 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002729 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002730 transformFeedback =
2731 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002732 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002733 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002734 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002735
2736 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002737}
2738
2739bool Context::isVertexArrayGenerated(GLuint vertexArray)
2740{
Jamie Madill96a483b2017-06-27 16:49:21 -04002741 ASSERT(mVertexArrayMap.contains(0));
2742 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002743}
2744
2745bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2746{
Jamie Madill96a483b2017-06-27 16:49:21 -04002747 ASSERT(mTransformFeedbackMap.contains(0));
2748 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002749}
2750
Shannon Woods53a94a82014-06-24 15:20:36 -04002751void Context::detachTexture(GLuint texture)
2752{
2753 // Simple pass-through to State's detachTexture method, as textures do not require
2754 // allocation map management either here or in the resource manager at detach time.
2755 // Zero textures are held by the Context, and we don't attempt to request them from
2756 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002757 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002758}
2759
James Darpinian4d9d4832018-03-13 12:43:28 -07002760void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002761{
Yuly Novikov5807a532015-12-03 13:01:22 -05002762 // Simple pass-through to State's detachBuffer method, since
2763 // only buffer attachments to container objects that are bound to the current context
2764 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002765
Yuly Novikov5807a532015-12-03 13:01:22 -05002766 // [OpenGL ES 3.2] section 5.1.2 page 45:
2767 // Attachments to unbound container objects, such as
2768 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2769 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002770 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002771}
2772
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002773void Context::detachFramebuffer(GLuint framebuffer)
2774{
Shannon Woods53a94a82014-06-24 15:20:36 -04002775 // Framebuffer detachment is handled by Context, because 0 is a valid
2776 // Framebuffer object, and a pointer to it must be passed from Context
2777 // to State at binding time.
2778
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002779 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002780 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2781 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2782 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002783
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002784 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002785 {
2786 bindReadFramebuffer(0);
2787 }
2788
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002789 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002790 {
2791 bindDrawFramebuffer(0);
2792 }
2793}
2794
2795void Context::detachRenderbuffer(GLuint renderbuffer)
2796{
Jamie Madilla02315b2017-02-23 14:14:47 -05002797 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002798}
2799
Jamie Madill57a89722013-07-02 11:57:03 -04002800void Context::detachVertexArray(GLuint vertexArray)
2801{
Jamie Madill77a72f62015-04-14 11:18:32 -04002802 // Vertex array detachment is handled by Context, because 0 is a valid
2803 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002804 // binding time.
2805
Jamie Madill57a89722013-07-02 11:57:03 -04002806 // [OpenGL ES 3.0.2] section 2.10 page 43:
2807 // If a vertex array object that is currently bound is deleted, the binding
2808 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002809 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002810 {
2811 bindVertexArray(0);
2812 }
2813}
2814
Geoff Langc8058452014-02-03 12:04:11 -05002815void Context::detachTransformFeedback(GLuint transformFeedback)
2816{
Corentin Walleza2257da2016-04-19 16:43:12 -04002817 // Transform feedback detachment is handled by Context, because 0 is a valid
2818 // transform feedback, and a pointer to it must be passed from Context to State at
2819 // binding time.
2820
2821 // The OpenGL specification doesn't mention what should happen when the currently bound
2822 // transform feedback object is deleted. Since it is a container object, we treat it like
2823 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002824 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002825 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002826 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002827 }
Geoff Langc8058452014-02-03 12:04:11 -05002828}
2829
Jamie Madilldc356042013-07-19 16:36:57 -04002830void Context::detachSampler(GLuint sampler)
2831{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002832 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002833}
2834
Yunchao Hea336b902017-08-02 16:05:21 +08002835void Context::detachProgramPipeline(GLuint pipeline)
2836{
2837 mGLState.detachProgramPipeline(this, pipeline);
2838}
2839
Jamie Madill3ef140a2017-08-26 23:11:21 -04002840void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002841{
Shaodde78e82017-05-22 14:13:27 +08002842 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002843 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002844}
2845
Jamie Madille29d1672013-07-19 16:36:57 -04002846void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2847{
Geoff Langc1984ed2016-10-07 12:41:00 -04002848 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002849 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002850 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002851}
Jamie Madille29d1672013-07-19 16:36:57 -04002852
Geoff Langc1984ed2016-10-07 12:41:00 -04002853void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2854{
2855 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002856 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002857 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002858}
2859
Brandon Jones59770802018-04-02 13:18:42 -07002860void Context::samplerParameterivRobust(GLuint sampler,
2861 GLenum pname,
2862 GLsizei bufSize,
2863 const GLint *param)
2864{
2865 samplerParameteriv(sampler, pname, param);
2866}
2867
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002868void Context::samplerParameterIivRobust(GLuint sampler,
2869 GLenum pname,
2870 GLsizei bufSize,
2871 const GLint *param)
2872{
2873 UNIMPLEMENTED();
2874}
2875
2876void Context::samplerParameterIuivRobust(GLuint sampler,
2877 GLenum pname,
2878 GLsizei bufSize,
2879 const GLuint *param)
2880{
2881 UNIMPLEMENTED();
2882}
2883
Jamie Madille29d1672013-07-19 16:36:57 -04002884void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2885{
Geoff Langc1984ed2016-10-07 12:41:00 -04002886 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002887 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002888 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002889}
2890
Geoff Langc1984ed2016-10-07 12:41:00 -04002891void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002892{
Geoff Langc1984ed2016-10-07 12:41:00 -04002893 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002894 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002895 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002896}
2897
Brandon Jones59770802018-04-02 13:18:42 -07002898void Context::samplerParameterfvRobust(GLuint sampler,
2899 GLenum pname,
2900 GLsizei bufSize,
2901 const GLfloat *param)
2902{
2903 samplerParameterfv(sampler, pname, param);
2904}
2905
Geoff Langc1984ed2016-10-07 12:41:00 -04002906void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002907{
Geoff Langc1984ed2016-10-07 12:41:00 -04002908 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002909 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002910 QuerySamplerParameteriv(samplerObject, pname, params);
2911}
Jamie Madill9675b802013-07-19 16:36:59 -04002912
Brandon Jones59770802018-04-02 13:18:42 -07002913void Context::getSamplerParameterivRobust(GLuint sampler,
2914 GLenum pname,
2915 GLsizei bufSize,
2916 GLsizei *length,
2917 GLint *params)
2918{
2919 getSamplerParameteriv(sampler, pname, params);
2920}
2921
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002922void Context::getSamplerParameterIivRobust(GLuint sampler,
2923 GLenum pname,
2924 GLsizei bufSize,
2925 GLsizei *length,
2926 GLint *params)
2927{
2928 UNIMPLEMENTED();
2929}
2930
2931void Context::getSamplerParameterIuivRobust(GLuint sampler,
2932 GLenum pname,
2933 GLsizei bufSize,
2934 GLsizei *length,
2935 GLuint *params)
2936{
2937 UNIMPLEMENTED();
2938}
2939
Geoff Langc1984ed2016-10-07 12:41:00 -04002940void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2941{
2942 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002943 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002944 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002945}
2946
Brandon Jones59770802018-04-02 13:18:42 -07002947void Context::getSamplerParameterfvRobust(GLuint sampler,
2948 GLenum pname,
2949 GLsizei bufSize,
2950 GLsizei *length,
2951 GLfloat *params)
2952{
2953 getSamplerParameterfv(sampler, pname, params);
2954}
2955
Olli Etuahof0fee072016-03-30 15:11:58 +03002956void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2957{
2958 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002959 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002960}
2961
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002962void Context::initRendererString()
2963{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002964 std::ostringstream rendererString;
2965 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002966 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002967 rendererString << ")";
2968
Geoff Langcec35902014-04-16 10:52:36 -04002969 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002970}
2971
Geoff Langc339c4e2016-11-29 10:37:36 -05002972void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002973{
Geoff Langc339c4e2016-11-29 10:37:36 -05002974 const Version &clientVersion = getClientVersion();
2975
2976 std::ostringstream versionString;
2977 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2978 << ANGLE_VERSION_STRING << ")";
2979 mVersionString = MakeStaticString(versionString.str());
2980
2981 std::ostringstream shadingLanguageVersionString;
2982 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2983 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2984 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2985 << ")";
2986 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002987}
2988
Geoff Langcec35902014-04-16 10:52:36 -04002989void Context::initExtensionStrings()
2990{
Geoff Langc339c4e2016-11-29 10:37:36 -05002991 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2992 std::ostringstream combinedStringStream;
2993 std::copy(strings.begin(), strings.end(),
2994 std::ostream_iterator<const char *>(combinedStringStream, " "));
2995 return MakeStaticString(combinedStringStream.str());
2996 };
2997
2998 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002999 for (const auto &extensionString : mExtensions.getStrings())
3000 {
3001 mExtensionStrings.push_back(MakeStaticString(extensionString));
3002 }
Geoff Langc339c4e2016-11-29 10:37:36 -05003003 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003004
Geoff Langc339c4e2016-11-29 10:37:36 -05003005 mRequestableExtensionStrings.clear();
3006 for (const auto &extensionInfo : GetExtensionInfoMap())
3007 {
3008 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003009 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003010 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003011 {
3012 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3013 }
3014 }
3015 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003016}
3017
Geoff Langc339c4e2016-11-29 10:37:36 -05003018const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003019{
Geoff Langc339c4e2016-11-29 10:37:36 -05003020 switch (name)
3021 {
3022 case GL_VENDOR:
3023 return reinterpret_cast<const GLubyte *>("Google Inc.");
3024
3025 case GL_RENDERER:
3026 return reinterpret_cast<const GLubyte *>(mRendererString);
3027
3028 case GL_VERSION:
3029 return reinterpret_cast<const GLubyte *>(mVersionString);
3030
3031 case GL_SHADING_LANGUAGE_VERSION:
3032 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3033
3034 case GL_EXTENSIONS:
3035 return reinterpret_cast<const GLubyte *>(mExtensionString);
3036
3037 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3038 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3039
3040 default:
3041 UNREACHABLE();
3042 return nullptr;
3043 }
Geoff Langcec35902014-04-16 10:52:36 -04003044}
3045
Geoff Langc339c4e2016-11-29 10:37:36 -05003046const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003047{
Geoff Langc339c4e2016-11-29 10:37:36 -05003048 switch (name)
3049 {
3050 case GL_EXTENSIONS:
3051 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3052
3053 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3054 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3055
3056 default:
3057 UNREACHABLE();
3058 return nullptr;
3059 }
Geoff Langcec35902014-04-16 10:52:36 -04003060}
3061
3062size_t Context::getExtensionStringCount() const
3063{
3064 return mExtensionStrings.size();
3065}
3066
Geoff Lang111a99e2017-10-17 10:58:41 -04003067bool Context::isExtensionRequestable(const char *name)
3068{
3069 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3070 auto extension = extensionInfos.find(name);
3071
Geoff Lang111a99e2017-10-17 10:58:41 -04003072 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003073 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003074}
3075
Geoff Langc339c4e2016-11-29 10:37:36 -05003076void Context::requestExtension(const char *name)
3077{
3078 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3079 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3080 const auto &extension = extensionInfos.at(name);
3081 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003082 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003083
3084 if (mExtensions.*(extension.ExtensionsMember))
3085 {
3086 // Extension already enabled
3087 return;
3088 }
3089
3090 mExtensions.*(extension.ExtensionsMember) = true;
3091 updateCaps();
3092 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003093
Jamie Madill2f348d22017-06-05 10:50:59 -04003094 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3095 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003096
Jamie Madill81c2e252017-09-09 23:32:46 -04003097 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3098 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003099 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003100 for (auto &zeroTexture : mZeroTextures)
3101 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003102 if (zeroTexture.get() != nullptr)
3103 {
3104 zeroTexture->signalDirty(this, InitState::Initialized);
3105 }
Geoff Lang9aded172017-04-05 11:07:56 -04003106 }
3107
Jamie Madillb983a4b2018-08-01 11:34:51 -04003108 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003109}
3110
3111size_t Context::getRequestableExtensionStringCount() const
3112{
3113 return mRequestableExtensionStrings.size();
3114}
3115
Jamie Madill493f9572018-05-24 19:52:15 -04003116void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003117{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003118 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003119 ASSERT(transformFeedback != nullptr);
3120 ASSERT(!transformFeedback->isPaused());
3121
Jamie Madill6c1f6712017-02-14 19:08:04 -05003122 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Jamie Madilld84b6732018-09-06 15:54:35 -04003123 mStateCache.onTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003124}
3125
3126bool Context::hasActiveTransformFeedback(GLuint program) const
3127{
3128 for (auto pair : mTransformFeedbackMap)
3129 {
3130 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3131 {
3132 return true;
3133 }
3134 }
3135 return false;
3136}
3137
Geoff Lang33f11fb2018-05-07 13:42:47 -04003138Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003139{
3140 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3141
jchen1082af6202018-06-22 10:59:52 +08003142 // Explicitly enable GL_KHR_parallel_shader_compile
3143 supportedExtensions.parallelShaderCompile = true;
3144
Geoff Langb0f917f2017-12-05 13:41:54 -05003145 if (getClientVersion() < ES_2_0)
3146 {
3147 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003148 supportedExtensions.pointSizeArray = true;
3149 supportedExtensions.textureCubeMap = true;
3150 supportedExtensions.pointSprite = true;
3151 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003152 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003153 }
3154
3155 if (getClientVersion() < ES_3_0)
3156 {
3157 // Disable ES3+ extensions
3158 supportedExtensions.colorBufferFloat = false;
3159 supportedExtensions.eglImageExternalEssl3 = false;
3160 supportedExtensions.textureNorm16 = false;
3161 supportedExtensions.multiview = false;
3162 supportedExtensions.maxViews = 1u;
3163 }
3164
3165 if (getClientVersion() < ES_3_1)
3166 {
3167 // Disable ES3.1+ extensions
3168 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003169
3170 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3171 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003172 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003173 }
3174
3175 if (getClientVersion() > ES_2_0)
3176 {
3177 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3178 // supportedExtensions.sRGB = false;
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03003179
3180 // EXT_blend_func_extended is only implemented against GLES2 now
3181 // TODO(http://anglebug.com/1085): remove this limitation once GLES3 binding API for the
3182 // outputs is in place.
3183 supportedExtensions.blendFuncExtended = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003184 }
3185
3186 // Some extensions are always available because they are implemented in the GL layer.
3187 supportedExtensions.bindUniformLocation = true;
3188 supportedExtensions.vertexArrayObject = true;
3189 supportedExtensions.bindGeneratesResource = true;
3190 supportedExtensions.clientArrays = true;
3191 supportedExtensions.requestExtension = true;
3192
3193 // Enable the no error extension if the context was created with the flag.
3194 supportedExtensions.noError = mSkipValidation;
3195
3196 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003197 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003198
3199 // Explicitly enable GL_KHR_debug
3200 supportedExtensions.debug = true;
3201 supportedExtensions.maxDebugMessageLength = 1024;
3202 supportedExtensions.maxDebugLoggedMessages = 1024;
3203 supportedExtensions.maxDebugGroupStackDepth = 1024;
3204 supportedExtensions.maxLabelLength = 1024;
3205
3206 // Explicitly enable GL_ANGLE_robust_client_memory
3207 supportedExtensions.robustClientMemory = true;
3208
3209 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003210 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003211
3212 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3213 // supports it.
3214 supportedExtensions.robustBufferAccessBehavior =
3215 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3216
3217 // Enable the cache control query unconditionally.
3218 supportedExtensions.programCacheControl = true;
3219
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003220 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003221 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003222 {
3223 // GL_ANGLE_explicit_context_gles1
3224 supportedExtensions.explicitContextGles1 = true;
3225 // GL_ANGLE_explicit_context
3226 supportedExtensions.explicitContext = true;
3227 }
3228
Geoff Langb0f917f2017-12-05 13:41:54 -05003229 return supportedExtensions;
3230}
3231
Geoff Lang33f11fb2018-05-07 13:42:47 -04003232void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003233{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003234 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003235
Geoff Lang33f11fb2018-05-07 13:42:47 -04003236 mSupportedExtensions = generateSupportedExtensions();
3237 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003238
3239 mLimitations = mImplementation->getNativeLimitations();
3240
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003241 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3242 if (getClientVersion() < Version(2, 0))
3243 {
3244 mCaps.maxMultitextureUnits = 4;
3245 mCaps.maxClipPlanes = 6;
3246 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003247 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3248 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3249 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003250 mCaps.minSmoothPointSize = 1.0f;
3251 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003252 mCaps.minSmoothLineWidth = 1.0f;
3253 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003254 }
3255
Luc Ferronad2ae932018-06-11 15:31:17 -04003256 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003257 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003258
Luc Ferronad2ae932018-06-11 15:31:17 -04003259 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3260
Jamie Madill0f80ed82017-09-19 00:24:56 -04003261 if (getClientVersion() < ES_3_1)
3262 {
3263 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3264 }
3265 else
3266 {
3267 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3268 }
Geoff Lang301d1612014-07-09 10:34:37 -04003269
Jiawei Shao54aafe52018-04-27 14:54:57 +08003270 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3271 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003272 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3273
Jamie Madill0f80ed82017-09-19 00:24:56 -04003274 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3275 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3276
3277 // Limit textures as well, so we can use fast bitsets with texture bindings.
3278 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003279 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3280 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3281 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3282 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003283
Jiawei Shaodb342272017-09-27 10:21:45 +08003284 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3285
Geoff Langc287ea62016-09-16 14:46:51 -04003286 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003287 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003288 for (const auto &extensionInfo : GetExtensionInfoMap())
3289 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003290 // If the user has requested that extensions start disabled and they are requestable,
3291 // disable them.
3292 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003293 {
3294 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3295 }
3296 }
3297
3298 // Generate texture caps
3299 updateCaps();
3300}
3301
3302void Context::updateCaps()
3303{
Geoff Lang900013c2014-07-07 11:32:19 -04003304 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003305 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003306
Jamie Madill7b62cf92017-11-02 15:20:49 -04003307 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003308 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003309 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003310 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003311
Geoff Lang0d8b7242015-09-09 14:56:53 -04003312 // Update the format caps based on the client version and extensions.
3313 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3314 // ES3.
3315 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003316 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003317 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003318 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003319 formatCaps.textureAttachment =
3320 formatCaps.textureAttachment &&
3321 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3322 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3323 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003324
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003325 // OpenGL ES does not support multisampling with non-rendererable formats
3326 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003327 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003328 (getClientVersion() < ES_3_1 &&
3329 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003330 {
Geoff Langd87878e2014-09-19 15:42:59 -04003331 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003332 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003333 else
3334 {
3335 // We may have limited the max samples for some required renderbuffer formats due to
3336 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3337 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3338
3339 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3340 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3341 // exception of signed and unsigned integer formats."
3342 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3343 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3344 {
3345 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3346 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3347 }
3348
3349 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3350 if (getClientVersion() >= ES_3_1)
3351 {
3352 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3353 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3354 // the exception that the signed and unsigned integer formats are required only to
3355 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3356 // multisamples, which must be at least one."
3357 if (formatInfo.componentType == GL_INT ||
3358 formatInfo.componentType == GL_UNSIGNED_INT)
3359 {
3360 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3361 }
3362
3363 // GLES 3.1 section 19.3.1.
3364 if (formatCaps.texturable)
3365 {
3366 if (formatInfo.depthBits > 0)
3367 {
3368 mCaps.maxDepthTextureSamples =
3369 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3370 }
3371 else if (formatInfo.redBits > 0)
3372 {
3373 mCaps.maxColorTextureSamples =
3374 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3375 }
3376 }
3377 }
3378 }
Geoff Langd87878e2014-09-19 15:42:59 -04003379
3380 if (formatCaps.texturable && formatInfo.compressed)
3381 {
Geoff Langca271392017-04-05 12:30:00 -04003382 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003383 }
3384
Geoff Langca271392017-04-05 12:30:00 -04003385 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003386 }
Jamie Madill32447362017-06-28 14:53:52 -04003387
3388 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003389 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003390 {
3391 mMemoryProgramCache = nullptr;
3392 }
Corentin Walleze4477002017-12-01 14:39:58 -05003393
3394 // Compute which buffer types are allowed
3395 mValidBufferBindings.reset();
3396 mValidBufferBindings.set(BufferBinding::ElementArray);
3397 mValidBufferBindings.set(BufferBinding::Array);
3398
3399 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3400 {
3401 mValidBufferBindings.set(BufferBinding::PixelPack);
3402 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3403 }
3404
3405 if (getClientVersion() >= ES_3_0)
3406 {
3407 mValidBufferBindings.set(BufferBinding::CopyRead);
3408 mValidBufferBindings.set(BufferBinding::CopyWrite);
3409 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3410 mValidBufferBindings.set(BufferBinding::Uniform);
3411 }
3412
3413 if (getClientVersion() >= ES_3_1)
3414 {
3415 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3416 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3417 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3418 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3419 }
jchen107ae70d82018-07-06 13:47:01 +08003420
3421 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Geoff Lang493daf52014-07-03 13:38:44 -04003422}
3423
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003424void Context::initWorkarounds()
3425{
Jamie Madill761b02c2017-06-23 16:27:06 -04003426 // Apply back-end workarounds.
3427 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3428
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003429 // Lose the context upon out of memory error if the application is
3430 // expecting to watch for those events.
3431 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3432}
3433
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003434// Return true if the draw is a no-op, else return false.
3435// A no-op draw occurs if the count of vertices is less than the minimum required to
3436// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3437bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3438{
3439 return count < kMinimumPrimitiveCounts[mode];
3440}
3441
3442bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3443{
3444 return (instanceCount == 0) || noopDraw(mode, count);
3445}
3446
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003447Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003448{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003449 if (mGLES1Renderer)
3450 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003451 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003452 }
3453
Geoff Lang9bf86f02018-07-26 11:46:34 -04003454 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003455
3456 if (isRobustResourceInitEnabled())
3457 {
3458 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3459 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3460 }
3461
Geoff Langa8cb2872018-03-09 16:09:40 -05003462 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003463 return NoError();
3464}
3465
3466Error Context::prepareForClear(GLbitfield mask)
3467{
Geoff Langa8cb2872018-03-09 16:09:40 -05003468 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003469 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003470 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003471 return NoError();
3472}
3473
3474Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3475{
Geoff Langa8cb2872018-03-09 16:09:40 -05003476 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003477 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3478 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003479 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003480 return NoError();
3481}
3482
Geoff Langa8cb2872018-03-09 16:09:40 -05003483Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003484{
Geoff Langa8cb2872018-03-09 16:09:40 -05003485 ANGLE_TRY(syncDirtyObjects(objectMask));
3486 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003487 return NoError();
3488}
3489
Geoff Langa8cb2872018-03-09 16:09:40 -05003490Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003491{
3492 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003493 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003494 mGLState.clearDirtyBits();
3495 return NoError();
3496}
3497
Geoff Langa8cb2872018-03-09 16:09:40 -05003498Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003499{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003500 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003501 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003502 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003503 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003504}
Jamie Madillc29968b2016-01-20 11:17:23 -05003505
Geoff Langa8cb2872018-03-09 16:09:40 -05003506Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003507{
3508 return mGLState.syncDirtyObjects(this, objectMask);
3509}
3510
Jamie Madillc29968b2016-01-20 11:17:23 -05003511void Context::blitFramebuffer(GLint srcX0,
3512 GLint srcY0,
3513 GLint srcX1,
3514 GLint srcY1,
3515 GLint dstX0,
3516 GLint dstY0,
3517 GLint dstX1,
3518 GLint dstY1,
3519 GLbitfield mask,
3520 GLenum filter)
3521{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003522 if (mask == 0)
3523 {
3524 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3525 // buffers are copied.
3526 return;
3527 }
3528
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003529 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003530 ASSERT(drawFramebuffer);
3531
3532 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3533 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3534
Jamie Madillbc918e72018-03-08 09:47:21 -05003535 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003536
Jamie Madillc564c072017-06-01 12:45:42 -04003537 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003538}
Jamie Madillc29968b2016-01-20 11:17:23 -05003539
3540void Context::clear(GLbitfield mask)
3541{
Geoff Langd4fff502017-09-22 11:28:28 -04003542 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3543 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003544}
3545
3546void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3547{
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003548 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3549 // that the backend doesn't need to take this case into account.
Olli Etuahodbce1f82018-09-19 15:32:17 +03003550 if (buffer == GL_DEPTH && !getGLState().getDrawFramebuffer()->getDepthbuffer())
3551 {
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003552 return;
3553 }
3554 if (buffer == GL_COLOR && !getGLState().getDrawFramebuffer()->getColorbuffer(drawbuffer))
3555 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003556 return;
3557 }
Geoff Langd4fff502017-09-22 11:28:28 -04003558 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3559 ANGLE_CONTEXT_TRY(
3560 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003561}
3562
3563void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3564{
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003565 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3566 // that the backend doesn't need to take this case into account.
3567 if (buffer == GL_COLOR && !getGLState().getDrawFramebuffer()->getColorbuffer(drawbuffer))
3568 {
3569 return;
3570 }
Geoff Langd4fff502017-09-22 11:28:28 -04003571 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3572 ANGLE_CONTEXT_TRY(
3573 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003574}
3575
3576void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3577{
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003578 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3579 // that the backend doesn't need to take this case into account.
Olli Etuahodbce1f82018-09-19 15:32:17 +03003580 if (buffer == GL_STENCIL && !getGLState().getDrawFramebuffer()->getStencilbuffer())
3581 {
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003582 return;
3583 }
3584 if (buffer == GL_COLOR && !getGLState().getDrawFramebuffer()->getColorbuffer(drawbuffer))
3585 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003586 return;
3587 }
Geoff Langd4fff502017-09-22 11:28:28 -04003588 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3589 ANGLE_CONTEXT_TRY(
3590 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003591}
3592
3593void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3594{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003595 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003596 ASSERT(framebufferObject);
3597
3598 // If a buffer is not present, the clear has no effect
3599 if (framebufferObject->getDepthbuffer() == nullptr &&
3600 framebufferObject->getStencilbuffer() == nullptr)
3601 {
3602 return;
3603 }
3604
Geoff Langd4fff502017-09-22 11:28:28 -04003605 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3606 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003607}
3608
3609void Context::readPixels(GLint x,
3610 GLint y,
3611 GLsizei width,
3612 GLsizei height,
3613 GLenum format,
3614 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003615 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003616{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003617 if (width == 0 || height == 0)
3618 {
3619 return;
3620 }
3621
Jamie Madillbc918e72018-03-08 09:47:21 -05003622 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003623
Jamie Madillb6664922017-07-25 12:55:04 -04003624 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3625 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003626
3627 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003628 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003629}
3630
Brandon Jones59770802018-04-02 13:18:42 -07003631void Context::readPixelsRobust(GLint x,
3632 GLint y,
3633 GLsizei width,
3634 GLsizei height,
3635 GLenum format,
3636 GLenum type,
3637 GLsizei bufSize,
3638 GLsizei *length,
3639 GLsizei *columns,
3640 GLsizei *rows,
3641 void *pixels)
3642{
3643 readPixels(x, y, width, height, format, type, pixels);
3644}
3645
3646void Context::readnPixelsRobust(GLint x,
3647 GLint y,
3648 GLsizei width,
3649 GLsizei height,
3650 GLenum format,
3651 GLenum type,
3652 GLsizei bufSize,
3653 GLsizei *length,
3654 GLsizei *columns,
3655 GLsizei *rows,
3656 void *data)
3657{
3658 readPixels(x, y, width, height, format, type, data);
3659}
3660
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003661void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003662 GLint level,
3663 GLenum internalformat,
3664 GLint x,
3665 GLint y,
3666 GLsizei width,
3667 GLsizei height,
3668 GLint border)
3669{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003670 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003671 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003672
Jamie Madillc29968b2016-01-20 11:17:23 -05003673 Rectangle sourceArea(x, y, width, height);
3674
Jamie Madill05b35b22017-10-03 09:01:44 -04003675 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003676 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003677 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003678}
3679
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003680void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003681 GLint level,
3682 GLint xoffset,
3683 GLint yoffset,
3684 GLint x,
3685 GLint y,
3686 GLsizei width,
3687 GLsizei height)
3688{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003689 if (width == 0 || height == 0)
3690 {
3691 return;
3692 }
3693
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003694 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003695 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003696
Jamie Madillc29968b2016-01-20 11:17:23 -05003697 Offset destOffset(xoffset, yoffset, 0);
3698 Rectangle sourceArea(x, y, width, height);
3699
Jamie Madill05b35b22017-10-03 09:01:44 -04003700 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003701 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003702 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003703}
3704
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003705void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003706 GLint level,
3707 GLint xoffset,
3708 GLint yoffset,
3709 GLint zoffset,
3710 GLint x,
3711 GLint y,
3712 GLsizei width,
3713 GLsizei height)
3714{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003715 if (width == 0 || height == 0)
3716 {
3717 return;
3718 }
3719
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003720 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003721 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003722
Jamie Madillc29968b2016-01-20 11:17:23 -05003723 Offset destOffset(xoffset, yoffset, zoffset);
3724 Rectangle sourceArea(x, y, width, height);
3725
Jamie Madill05b35b22017-10-03 09:01:44 -04003726 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3727 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003728 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3729 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003730}
3731
3732void Context::framebufferTexture2D(GLenum target,
3733 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003734 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003735 GLuint texture,
3736 GLint level)
3737{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003738 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003739 ASSERT(framebuffer);
3740
3741 if (texture != 0)
3742 {
3743 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003744 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003745 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003746 }
3747 else
3748 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003749 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003750 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003751
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003752 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003753}
3754
3755void Context::framebufferRenderbuffer(GLenum target,
3756 GLenum attachment,
3757 GLenum renderbuffertarget,
3758 GLuint renderbuffer)
3759{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003760 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003761 ASSERT(framebuffer);
3762
3763 if (renderbuffer != 0)
3764 {
3765 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003766
Jamie Madillcc129372018-04-12 09:13:18 -04003767 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003768 renderbufferObject);
3769 }
3770 else
3771 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003772 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003773 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003774
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003775 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003776}
3777
3778void Context::framebufferTextureLayer(GLenum target,
3779 GLenum attachment,
3780 GLuint texture,
3781 GLint level,
3782 GLint layer)
3783{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003784 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003785 ASSERT(framebuffer);
3786
3787 if (texture != 0)
3788 {
3789 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003790 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003791 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003792 }
3793 else
3794 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003795 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003796 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003797
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003798 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003799}
3800
Brandon Jones59770802018-04-02 13:18:42 -07003801void Context::framebufferTextureMultiviewLayered(GLenum target,
3802 GLenum attachment,
3803 GLuint texture,
3804 GLint level,
3805 GLint baseViewIndex,
3806 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003807{
Martin Radev82ef7742017-08-08 17:44:58 +03003808 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3809 ASSERT(framebuffer);
3810
3811 if (texture != 0)
3812 {
3813 Texture *textureObj = getTexture(texture);
3814
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003815 ImageIndex index;
3816 if (textureObj->getType() == TextureType::_2DArray)
3817 {
3818 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3819 }
3820 else
3821 {
3822 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3823 ASSERT(level == 0);
3824 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3825 }
Martin Radev82ef7742017-08-08 17:44:58 +03003826 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3827 numViews, baseViewIndex);
3828 }
3829 else
3830 {
3831 framebuffer->resetAttachment(this, attachment);
3832 }
3833
3834 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003835}
3836
Brandon Jones59770802018-04-02 13:18:42 -07003837void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3838 GLenum attachment,
3839 GLuint texture,
3840 GLint level,
3841 GLsizei numViews,
3842 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003843{
Martin Radev5dae57b2017-07-14 16:15:55 +03003844 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3845 ASSERT(framebuffer);
3846
3847 if (texture != 0)
3848 {
3849 Texture *textureObj = getTexture(texture);
3850
3851 ImageIndex index = ImageIndex::Make2D(level);
3852 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3853 textureObj, numViews, viewportOffsets);
3854 }
3855 else
3856 {
3857 framebuffer->resetAttachment(this, attachment);
3858 }
3859
3860 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003861}
3862
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003863void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3864{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003865 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3866 ASSERT(framebuffer);
3867
3868 if (texture != 0)
3869 {
3870 Texture *textureObj = getTexture(texture);
3871
3872 ImageIndex index = ImageIndex::MakeFromType(
3873 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3874 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3875 }
3876 else
3877 {
3878 framebuffer->resetAttachment(this, attachment);
3879 }
3880
3881 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003882}
3883
Jamie Madillc29968b2016-01-20 11:17:23 -05003884void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3885{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003886 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003887 ASSERT(framebuffer);
3888 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003889 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04003890 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003891}
3892
3893void Context::readBuffer(GLenum mode)
3894{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003895 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003896 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003897 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003898}
3899
3900void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3901{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003902 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003903 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003904
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003905 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003906 ASSERT(framebuffer);
3907
3908 // The specification isn't clear what should be done when the framebuffer isn't complete.
3909 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003910 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003911}
3912
3913void Context::invalidateFramebuffer(GLenum target,
3914 GLsizei numAttachments,
3915 const GLenum *attachments)
3916{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003917 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003918 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003919
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003920 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003921 ASSERT(framebuffer);
3922
Jamie Madill427064d2018-04-13 16:20:34 -04003923 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003924 {
Jamie Madill437fa652016-05-03 15:13:24 -04003925 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003926 }
Jamie Madill437fa652016-05-03 15:13:24 -04003927
Jamie Madill4928b7c2017-06-20 12:57:39 -04003928 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003929}
3930
3931void Context::invalidateSubFramebuffer(GLenum target,
3932 GLsizei numAttachments,
3933 const GLenum *attachments,
3934 GLint x,
3935 GLint y,
3936 GLsizei width,
3937 GLsizei height)
3938{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003939 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003940 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003941
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003942 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003943 ASSERT(framebuffer);
3944
Jamie Madill427064d2018-04-13 16:20:34 -04003945 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003946 {
Jamie Madill437fa652016-05-03 15:13:24 -04003947 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003948 }
Jamie Madill437fa652016-05-03 15:13:24 -04003949
3950 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003951 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003952}
3953
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003954void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003955 GLint level,
3956 GLint internalformat,
3957 GLsizei width,
3958 GLsizei height,
3959 GLint border,
3960 GLenum format,
3961 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003962 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003963{
Jamie Madillbc918e72018-03-08 09:47:21 -05003964 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003965
3966 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003967 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003968 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003969 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003970}
3971
Brandon Jones59770802018-04-02 13:18:42 -07003972void Context::texImage2DRobust(TextureTarget target,
3973 GLint level,
3974 GLint internalformat,
3975 GLsizei width,
3976 GLsizei height,
3977 GLint border,
3978 GLenum format,
3979 GLenum type,
3980 GLsizei bufSize,
3981 const void *pixels)
3982{
3983 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3984}
3985
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003986void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003987 GLint level,
3988 GLint internalformat,
3989 GLsizei width,
3990 GLsizei height,
3991 GLsizei depth,
3992 GLint border,
3993 GLenum format,
3994 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003995 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003996{
Jamie Madillbc918e72018-03-08 09:47:21 -05003997 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003998
3999 Extents size(width, height, depth);
4000 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004001 handleError(texture->setImage(this, mGLState.getUnpackState(),
4002 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004003 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004004}
4005
Brandon Jones59770802018-04-02 13:18:42 -07004006void Context::texImage3DRobust(TextureType target,
4007 GLint level,
4008 GLint internalformat,
4009 GLsizei width,
4010 GLsizei height,
4011 GLsizei depth,
4012 GLint border,
4013 GLenum format,
4014 GLenum type,
4015 GLsizei bufSize,
4016 const void *pixels)
4017{
4018 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4019}
4020
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004021void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004022 GLint level,
4023 GLint xoffset,
4024 GLint yoffset,
4025 GLsizei width,
4026 GLsizei height,
4027 GLenum format,
4028 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004029 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004030{
4031 // Zero sized uploads are valid but no-ops
4032 if (width == 0 || height == 0)
4033 {
4034 return;
4035 }
4036
Jamie Madillbc918e72018-03-08 09:47:21 -05004037 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004038
4039 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004040 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004041
4042 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4043
4044 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target, level,
4045 area, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004046}
4047
Brandon Jones59770802018-04-02 13:18:42 -07004048void Context::texSubImage2DRobust(TextureTarget target,
4049 GLint level,
4050 GLint xoffset,
4051 GLint yoffset,
4052 GLsizei width,
4053 GLsizei height,
4054 GLenum format,
4055 GLenum type,
4056 GLsizei bufSize,
4057 const void *pixels)
4058{
4059 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4060}
4061
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004062void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004063 GLint level,
4064 GLint xoffset,
4065 GLint yoffset,
4066 GLint zoffset,
4067 GLsizei width,
4068 GLsizei height,
4069 GLsizei depth,
4070 GLenum format,
4071 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004072 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004073{
4074 // Zero sized uploads are valid but no-ops
4075 if (width == 0 || height == 0 || depth == 0)
4076 {
4077 return;
4078 }
4079
Jamie Madillbc918e72018-03-08 09:47:21 -05004080 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004081
4082 Box area(xoffset, yoffset, zoffset, width, height, depth);
4083 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004084
4085 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4086
4087 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004088 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004089 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004090}
4091
Brandon Jones59770802018-04-02 13:18:42 -07004092void Context::texSubImage3DRobust(TextureType target,
4093 GLint level,
4094 GLint xoffset,
4095 GLint yoffset,
4096 GLint zoffset,
4097 GLsizei width,
4098 GLsizei height,
4099 GLsizei depth,
4100 GLenum format,
4101 GLenum type,
4102 GLsizei bufSize,
4103 const void *pixels)
4104{
4105 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4106 pixels);
4107}
4108
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004109void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004110 GLint level,
4111 GLenum internalformat,
4112 GLsizei width,
4113 GLsizei height,
4114 GLint border,
4115 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004116 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004117{
Jamie Madillbc918e72018-03-08 09:47:21 -05004118 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004119
4120 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004121 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004122 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4123 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004124 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004125}
4126
Brandon Jones59770802018-04-02 13:18:42 -07004127void Context::compressedTexImage2DRobust(TextureTarget target,
4128 GLint level,
4129 GLenum internalformat,
4130 GLsizei width,
4131 GLsizei height,
4132 GLint border,
4133 GLsizei imageSize,
4134 GLsizei dataSize,
4135 const GLvoid *data)
4136{
4137 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4138}
4139
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004140void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004141 GLint level,
4142 GLenum internalformat,
4143 GLsizei width,
4144 GLsizei height,
4145 GLsizei depth,
4146 GLint border,
4147 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004148 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004149{
Jamie Madillbc918e72018-03-08 09:47:21 -05004150 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004151
4152 Extents size(width, height, depth);
4153 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004154 handleError(texture->setCompressedImage(
4155 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004156 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004157}
4158
Brandon Jones59770802018-04-02 13:18:42 -07004159void Context::compressedTexImage3DRobust(TextureType target,
4160 GLint level,
4161 GLenum internalformat,
4162 GLsizei width,
4163 GLsizei height,
4164 GLsizei depth,
4165 GLint border,
4166 GLsizei imageSize,
4167 GLsizei dataSize,
4168 const GLvoid *data)
4169{
4170 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4171 data);
4172}
4173
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004174void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004175 GLint level,
4176 GLint xoffset,
4177 GLint yoffset,
4178 GLsizei width,
4179 GLsizei height,
4180 GLenum format,
4181 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004182 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004183{
Jamie Madillbc918e72018-03-08 09:47:21 -05004184 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004185
4186 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004187 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004188 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4189 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004190 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004191}
4192
Brandon Jones59770802018-04-02 13:18:42 -07004193void Context::compressedTexSubImage2DRobust(TextureTarget target,
4194 GLint level,
4195 GLint xoffset,
4196 GLint yoffset,
4197 GLsizei width,
4198 GLsizei height,
4199 GLenum format,
4200 GLsizei imageSize,
4201 GLsizei dataSize,
4202 const GLvoid *data)
4203{
4204 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4205 data);
4206}
4207
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004208void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004209 GLint level,
4210 GLint xoffset,
4211 GLint yoffset,
4212 GLint zoffset,
4213 GLsizei width,
4214 GLsizei height,
4215 GLsizei depth,
4216 GLenum format,
4217 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004218 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004219{
4220 // Zero sized uploads are valid but no-ops
4221 if (width == 0 || height == 0)
4222 {
4223 return;
4224 }
4225
Jamie Madillbc918e72018-03-08 09:47:21 -05004226 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004227
4228 Box area(xoffset, yoffset, zoffset, width, height, depth);
4229 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004230 handleError(texture->setCompressedSubImage(
4231 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004232 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004233}
4234
Brandon Jones59770802018-04-02 13:18:42 -07004235void Context::compressedTexSubImage3DRobust(TextureType target,
4236 GLint level,
4237 GLint xoffset,
4238 GLint yoffset,
4239 GLint zoffset,
4240 GLsizei width,
4241 GLsizei height,
4242 GLsizei depth,
4243 GLenum format,
4244 GLsizei imageSize,
4245 GLsizei dataSize,
4246 const GLvoid *data)
4247{
4248 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4249 imageSize, data);
4250}
4251
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004252void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004253{
4254 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004255 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004256}
4257
Jamie Madill007530e2017-12-28 14:27:04 -05004258void Context::copyTexture(GLuint sourceId,
4259 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004260 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004261 GLuint destId,
4262 GLint destLevel,
4263 GLint internalFormat,
4264 GLenum destType,
4265 GLboolean unpackFlipY,
4266 GLboolean unpackPremultiplyAlpha,
4267 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004268{
Jamie Madillbc918e72018-03-08 09:47:21 -05004269 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004270
4271 gl::Texture *sourceTexture = getTexture(sourceId);
4272 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004273 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4274 sourceLevel, ConvertToBool(unpackFlipY),
4275 ConvertToBool(unpackPremultiplyAlpha),
4276 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004277}
4278
Jamie Madill007530e2017-12-28 14:27:04 -05004279void Context::copySubTexture(GLuint sourceId,
4280 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004281 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004282 GLuint destId,
4283 GLint destLevel,
4284 GLint xoffset,
4285 GLint yoffset,
4286 GLint x,
4287 GLint y,
4288 GLsizei width,
4289 GLsizei height,
4290 GLboolean unpackFlipY,
4291 GLboolean unpackPremultiplyAlpha,
4292 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004293{
4294 // Zero sized copies are valid but no-ops
4295 if (width == 0 || height == 0)
4296 {
4297 return;
4298 }
4299
Jamie Madillbc918e72018-03-08 09:47:21 -05004300 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004301
4302 gl::Texture *sourceTexture = getTexture(sourceId);
4303 gl::Texture *destTexture = getTexture(destId);
4304 Offset offset(xoffset, yoffset, 0);
4305 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004306 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4307 ConvertToBool(unpackFlipY),
4308 ConvertToBool(unpackPremultiplyAlpha),
4309 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004310}
4311
Jamie Madill007530e2017-12-28 14:27:04 -05004312void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004313{
Jamie Madillbc918e72018-03-08 09:47:21 -05004314 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004315
4316 gl::Texture *sourceTexture = getTexture(sourceId);
4317 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004318 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004319}
4320
Corentin Wallez336129f2017-10-17 15:55:40 -04004321void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004322{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004323 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004324 ASSERT(buffer);
4325
Geoff Lang496c02d2016-10-20 11:38:11 -07004326 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004327}
4328
Brandon Jones59770802018-04-02 13:18:42 -07004329void Context::getBufferPointervRobust(BufferBinding target,
4330 GLenum pname,
4331 GLsizei bufSize,
4332 GLsizei *length,
4333 void **params)
4334{
4335 getBufferPointerv(target, pname, params);
4336}
4337
Corentin Wallez336129f2017-10-17 15:55:40 -04004338void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004339{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004340 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004341 ASSERT(buffer);
4342
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004343 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004344 if (error.isError())
4345 {
Jamie Madill437fa652016-05-03 15:13:24 -04004346 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004347 return nullptr;
4348 }
4349
4350 return buffer->getMapPointer();
4351}
4352
Corentin Wallez336129f2017-10-17 15:55:40 -04004353GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004354{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004355 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004356 ASSERT(buffer);
4357
4358 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004359 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004360 if (error.isError())
4361 {
Jamie Madill437fa652016-05-03 15:13:24 -04004362 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004363 return GL_FALSE;
4364 }
4365
4366 return result;
4367}
4368
Corentin Wallez336129f2017-10-17 15:55:40 -04004369void *Context::mapBufferRange(BufferBinding target,
4370 GLintptr offset,
4371 GLsizeiptr length,
4372 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004373{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004374 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004375 ASSERT(buffer);
4376
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004377 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004378 if (error.isError())
4379 {
Jamie Madill437fa652016-05-03 15:13:24 -04004380 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004381 return nullptr;
4382 }
4383
4384 return buffer->getMapPointer();
4385}
4386
Corentin Wallez336129f2017-10-17 15:55:40 -04004387void Context::flushMappedBufferRange(BufferBinding /*target*/,
4388 GLintptr /*offset*/,
4389 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004390{
4391 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4392}
4393
Jamie Madillbc918e72018-03-08 09:47:21 -05004394Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004395{
Geoff Langa8cb2872018-03-09 16:09:40 -05004396 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004397}
4398
Jamie Madillbc918e72018-03-08 09:47:21 -05004399Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004400{
Geoff Langa8cb2872018-03-09 16:09:40 -05004401 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004402}
4403
Jamie Madillbc918e72018-03-08 09:47:21 -05004404Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004405{
Geoff Langa8cb2872018-03-09 16:09:40 -05004406 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004407}
4408
Geoff Lang9bf86f02018-07-26 11:46:34 -04004409Error Context::syncStateForPathOperation()
4410{
4411 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4412
4413 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4414 ANGLE_TRY(syncDirtyBits());
4415
4416 return NoError();
4417}
4418
Jiajia Qin5451d532017-11-16 17:16:34 +08004419void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4420{
4421 UNIMPLEMENTED();
4422}
4423
Jamie Madillc20ab272016-06-09 07:20:46 -07004424void Context::activeTexture(GLenum texture)
4425{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004426 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004427}
4428
Jamie Madill876429b2017-04-20 15:46:24 -04004429void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004430{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004431 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004432}
4433
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004434void Context::blendEquation(GLenum mode)
4435{
4436 mGLState.setBlendEquation(mode, mode);
4437}
4438
Jamie Madillc20ab272016-06-09 07:20:46 -07004439void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4440{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004441 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004442}
4443
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004444void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4445{
4446 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4447}
4448
Jamie Madillc20ab272016-06-09 07:20:46 -07004449void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4450{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004451 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004452}
4453
Jamie Madill876429b2017-04-20 15:46:24 -04004454void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004455{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004456 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004457}
4458
Jamie Madill876429b2017-04-20 15:46:24 -04004459void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004460{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004461 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004462}
4463
4464void Context::clearStencil(GLint s)
4465{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004466 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004467}
4468
4469void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4470{
Geoff Lang92019432017-11-20 13:09:34 -05004471 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4472 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004473}
4474
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004475void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004476{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004477 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004478}
4479
4480void Context::depthFunc(GLenum func)
4481{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004482 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004483}
4484
4485void Context::depthMask(GLboolean flag)
4486{
Geoff Lang92019432017-11-20 13:09:34 -05004487 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004488}
4489
Jamie Madill876429b2017-04-20 15:46:24 -04004490void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004491{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004492 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004493}
4494
4495void Context::disable(GLenum cap)
4496{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004497 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004498 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004499}
4500
4501void Context::disableVertexAttribArray(GLuint index)
4502{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004503 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004504 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004505}
4506
4507void Context::enable(GLenum cap)
4508{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004509 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004510 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004511}
4512
4513void Context::enableVertexAttribArray(GLuint index)
4514{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004515 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004516 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004517}
4518
4519void Context::frontFace(GLenum mode)
4520{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004521 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004522}
4523
4524void Context::hint(GLenum target, GLenum mode)
4525{
4526 switch (target)
4527 {
4528 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004529 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004530 break;
4531
4532 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004533 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004534 break;
4535
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004536 case GL_PERSPECTIVE_CORRECTION_HINT:
4537 case GL_POINT_SMOOTH_HINT:
4538 case GL_LINE_SMOOTH_HINT:
4539 case GL_FOG_HINT:
4540 mGLState.gles1().setHint(target, mode);
4541 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004542 default:
4543 UNREACHABLE();
4544 return;
4545 }
4546}
4547
4548void Context::lineWidth(GLfloat width)
4549{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004550 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004551}
4552
4553void Context::pixelStorei(GLenum pname, GLint param)
4554{
4555 switch (pname)
4556 {
4557 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004558 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004559 break;
4560
4561 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004562 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004563 break;
4564
4565 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004566 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004567 break;
4568
4569 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004570 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004571 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004572 break;
4573
4574 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004575 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004576 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004577 break;
4578
4579 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004580 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004581 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004582 break;
4583
4584 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004585 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004586 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004587 break;
4588
4589 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004590 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004591 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004592 break;
4593
4594 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004595 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004596 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004597 break;
4598
4599 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004600 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004601 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004602 break;
4603
4604 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004605 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004606 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004607 break;
4608
4609 default:
4610 UNREACHABLE();
4611 return;
4612 }
4613}
4614
4615void Context::polygonOffset(GLfloat factor, GLfloat units)
4616{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004617 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004618}
4619
Jamie Madill876429b2017-04-20 15:46:24 -04004620void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004621{
Geoff Lang92019432017-11-20 13:09:34 -05004622 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004623}
4624
Jiawei Shaodb342272017-09-27 10:21:45 +08004625void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4626{
4627 mGLState.setSampleMaskParams(maskNumber, mask);
4628}
4629
Jamie Madillc20ab272016-06-09 07:20:46 -07004630void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4631{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004632 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004633}
4634
4635void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4636{
4637 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4638 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004639 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004640 }
4641
4642 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4643 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004644 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004645 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004646
4647 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004648}
4649
4650void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4651{
4652 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4653 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004654 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004655 }
4656
4657 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4658 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004659 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004660 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004661
4662 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004663}
4664
4665void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4666{
4667 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4668 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004669 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004670 }
4671
4672 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4673 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004674 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004675 }
4676}
4677
4678void Context::vertexAttrib1f(GLuint index, GLfloat x)
4679{
4680 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004681 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004682 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004683}
4684
4685void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4686{
4687 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004688 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004689 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004690}
4691
4692void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4693{
4694 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004695 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004696 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004697}
4698
4699void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4700{
4701 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004702 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004703 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004704}
4705
4706void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4707{
4708 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004709 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004710 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004711}
4712
4713void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4714{
4715 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004716 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004717 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004718}
4719
4720void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4721{
4722 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004723 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004724 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004725}
4726
4727void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4728{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004729 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004730 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004731}
4732
4733void Context::vertexAttribPointer(GLuint index,
4734 GLint size,
4735 GLenum type,
4736 GLboolean normalized,
4737 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004738 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004739{
Corentin Wallez336129f2017-10-17 15:55:40 -04004740 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004741 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004742 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004743}
4744
Shao80957d92017-02-20 21:25:59 +08004745void Context::vertexAttribFormat(GLuint attribIndex,
4746 GLint size,
4747 GLenum type,
4748 GLboolean normalized,
4749 GLuint relativeOffset)
4750{
Geoff Lang92019432017-11-20 13:09:34 -05004751 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004752 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004753 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004754}
4755
4756void Context::vertexAttribIFormat(GLuint attribIndex,
4757 GLint size,
4758 GLenum type,
4759 GLuint relativeOffset)
4760{
4761 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004762 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004763}
4764
4765void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4766{
Shaodde78e82017-05-22 14:13:27 +08004767 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004768 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004769}
4770
Jiajia Qin5451d532017-11-16 17:16:34 +08004771void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004772{
4773 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004774 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004775}
4776
Jamie Madillc20ab272016-06-09 07:20:46 -07004777void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4778{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004779 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004780}
4781
4782void Context::vertexAttribIPointer(GLuint index,
4783 GLint size,
4784 GLenum type,
4785 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004786 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004787{
Corentin Wallez336129f2017-10-17 15:55:40 -04004788 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4789 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004790 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004791}
4792
4793void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4794{
4795 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004796 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004797 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004798}
4799
4800void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4801{
4802 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004803 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004804 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004805}
4806
4807void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4808{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004809 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004810 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004811}
4812
4813void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4814{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004815 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004816 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004817}
4818
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004819void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4820{
4821 const VertexAttribCurrentValueData &currentValues =
4822 getGLState().getVertexAttribCurrentValue(index);
4823 const VertexArray *vao = getGLState().getVertexArray();
4824 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4825 currentValues, pname, params);
4826}
4827
Brandon Jones59770802018-04-02 13:18:42 -07004828void Context::getVertexAttribivRobust(GLuint index,
4829 GLenum pname,
4830 GLsizei bufSize,
4831 GLsizei *length,
4832 GLint *params)
4833{
4834 getVertexAttribiv(index, pname, params);
4835}
4836
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004837void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4838{
4839 const VertexAttribCurrentValueData &currentValues =
4840 getGLState().getVertexAttribCurrentValue(index);
4841 const VertexArray *vao = getGLState().getVertexArray();
4842 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4843 currentValues, pname, params);
4844}
4845
Brandon Jones59770802018-04-02 13:18:42 -07004846void Context::getVertexAttribfvRobust(GLuint index,
4847 GLenum pname,
4848 GLsizei bufSize,
4849 GLsizei *length,
4850 GLfloat *params)
4851{
4852 getVertexAttribfv(index, pname, params);
4853}
4854
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004855void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4856{
4857 const VertexAttribCurrentValueData &currentValues =
4858 getGLState().getVertexAttribCurrentValue(index);
4859 const VertexArray *vao = getGLState().getVertexArray();
4860 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4861 currentValues, pname, params);
4862}
4863
Brandon Jones59770802018-04-02 13:18:42 -07004864void Context::getVertexAttribIivRobust(GLuint index,
4865 GLenum pname,
4866 GLsizei bufSize,
4867 GLsizei *length,
4868 GLint *params)
4869{
4870 getVertexAttribIiv(index, pname, params);
4871}
4872
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004873void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4874{
4875 const VertexAttribCurrentValueData &currentValues =
4876 getGLState().getVertexAttribCurrentValue(index);
4877 const VertexArray *vao = getGLState().getVertexArray();
4878 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4879 currentValues, pname, params);
4880}
4881
Brandon Jones59770802018-04-02 13:18:42 -07004882void Context::getVertexAttribIuivRobust(GLuint index,
4883 GLenum pname,
4884 GLsizei bufSize,
4885 GLsizei *length,
4886 GLuint *params)
4887{
4888 getVertexAttribIuiv(index, pname, params);
4889}
4890
Jamie Madill876429b2017-04-20 15:46:24 -04004891void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004892{
4893 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4894 QueryVertexAttribPointerv(attrib, pname, pointer);
4895}
4896
Brandon Jones59770802018-04-02 13:18:42 -07004897void Context::getVertexAttribPointervRobust(GLuint index,
4898 GLenum pname,
4899 GLsizei bufSize,
4900 GLsizei *length,
4901 void **pointer)
4902{
4903 getVertexAttribPointerv(index, pname, pointer);
4904}
4905
Jamie Madillc20ab272016-06-09 07:20:46 -07004906void Context::debugMessageControl(GLenum source,
4907 GLenum type,
4908 GLenum severity,
4909 GLsizei count,
4910 const GLuint *ids,
4911 GLboolean enabled)
4912{
4913 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004914 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004915 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004916}
4917
4918void Context::debugMessageInsert(GLenum source,
4919 GLenum type,
4920 GLuint id,
4921 GLenum severity,
4922 GLsizei length,
4923 const GLchar *buf)
4924{
4925 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004926 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004927}
4928
4929void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4930{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004931 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004932}
4933
4934GLuint Context::getDebugMessageLog(GLuint count,
4935 GLsizei bufSize,
4936 GLenum *sources,
4937 GLenum *types,
4938 GLuint *ids,
4939 GLenum *severities,
4940 GLsizei *lengths,
4941 GLchar *messageLog)
4942{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004943 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4944 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004945}
4946
4947void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4948{
4949 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004950 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004951 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004952}
4953
4954void Context::popDebugGroup()
4955{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004956 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004957 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004958}
4959
Corentin Wallez336129f2017-10-17 15:55:40 -04004960void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004961{
4962 Buffer *buffer = mGLState.getTargetBuffer(target);
4963 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004964 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004965}
4966
Corentin Wallez336129f2017-10-17 15:55:40 -04004967void Context::bufferSubData(BufferBinding target,
4968 GLintptr offset,
4969 GLsizeiptr size,
4970 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004971{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06004972 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04004973 {
4974 return;
4975 }
4976
4977 Buffer *buffer = mGLState.getTargetBuffer(target);
4978 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004979 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004980}
4981
Jamie Madillef300b12016-10-07 15:12:09 -04004982void Context::attachShader(GLuint program, GLuint shader)
4983{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004984 Program *programObject = mState.mShaderPrograms->getProgram(program);
4985 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004986 ASSERT(programObject && shaderObject);
4987 programObject->attachShader(shaderObject);
4988}
4989
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004990const Workarounds &Context::getWorkarounds() const
4991{
4992 return mWorkarounds;
4993}
4994
Corentin Wallez336129f2017-10-17 15:55:40 -04004995void Context::copyBufferSubData(BufferBinding readTarget,
4996 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004997 GLintptr readOffset,
4998 GLintptr writeOffset,
4999 GLsizeiptr size)
5000{
5001 // if size is zero, the copy is a successful no-op
5002 if (size == 0)
5003 {
5004 return;
5005 }
5006
5007 // TODO(jmadill): cache these.
5008 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
5009 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
5010
Jamie Madill5f56ddb2017-01-13 17:29:55 -05005011 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005012}
5013
Jamie Madill01a80ee2016-11-07 12:06:18 -05005014void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5015{
5016 Program *programObject = getProgram(program);
5017 // TODO(jmadill): Re-use this from the validation if possible.
5018 ASSERT(programObject);
5019 programObject->bindAttributeLocation(index, name);
5020}
5021
Corentin Wallez336129f2017-10-17 15:55:40 -04005022void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005023{
Corentin Wallez336129f2017-10-17 15:55:40 -04005024 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5025 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04005026 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005027}
5028
Corentin Wallez336129f2017-10-17 15:55:40 -04005029void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005030{
5031 bindBufferRange(target, index, buffer, 0, 0);
5032}
5033
Corentin Wallez336129f2017-10-17 15:55:40 -04005034void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005035 GLuint index,
5036 GLuint buffer,
5037 GLintptr offset,
5038 GLsizeiptr size)
5039{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005040 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5041 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
5042 if (target == BufferBinding::Uniform)
5043 {
5044 mUniformBufferObserverBindings[index].bind(object ? object->getImplementation() : nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04005045 mStateCache.onUniformBufferStateChange(this);
5046 }
5047 else
5048 {
5049 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005050 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005051}
5052
Jamie Madill01a80ee2016-11-07 12:06:18 -05005053void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5054{
5055 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5056 {
5057 bindReadFramebuffer(framebuffer);
5058 }
5059
5060 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5061 {
5062 bindDrawFramebuffer(framebuffer);
5063 }
5064}
5065
5066void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5067{
5068 ASSERT(target == GL_RENDERBUFFER);
5069 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005070 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005071 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005072}
5073
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005074void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005075 GLsizei samples,
5076 GLenum internalformat,
5077 GLsizei width,
5078 GLsizei height,
5079 GLboolean fixedsamplelocations)
5080{
5081 Extents size(width, height, 1);
5082 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005083 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5084 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005085}
5086
Olli Etuaho89664842018-08-24 14:45:36 +03005087void Context::texStorage3DMultisample(TextureType target,
5088 GLsizei samples,
5089 GLenum internalformat,
5090 GLsizei width,
5091 GLsizei height,
5092 GLsizei depth,
5093 GLboolean fixedsamplelocations)
5094{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005095 Extents size(width, height, depth);
5096 Texture *texture = getTargetTexture(target);
5097 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5098 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005099}
5100
JiangYizhoubddc46b2016-12-09 09:50:51 +08005101void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5102{
JiangYizhou5b03f472017-01-09 10:22:53 +08005103 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5104 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005105 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005106 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005107
5108 switch (pname)
5109 {
5110 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04005111 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005112 break;
5113 default:
5114 UNREACHABLE();
5115 }
5116}
5117
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005118void Context::getMultisamplefvRobust(GLenum pname,
5119 GLuint index,
5120 GLsizei bufSize,
5121 GLsizei *length,
5122 GLfloat *val)
5123{
5124 UNIMPLEMENTED();
5125}
5126
Jamie Madille8fb6402017-02-14 17:56:40 -05005127void Context::renderbufferStorage(GLenum target,
5128 GLenum internalformat,
5129 GLsizei width,
5130 GLsizei height)
5131{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005132 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5133 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5134
Jamie Madille8fb6402017-02-14 17:56:40 -05005135 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04005136 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005137}
5138
5139void Context::renderbufferStorageMultisample(GLenum target,
5140 GLsizei samples,
5141 GLenum internalformat,
5142 GLsizei width,
5143 GLsizei height)
5144{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005145 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5146 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005147
5148 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005149 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005150 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005151}
5152
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005153void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5154{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005155 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04005156 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005157}
5158
JiangYizhoue18e6392017-02-20 10:32:23 +08005159void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5160{
5161 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5162 QueryFramebufferParameteriv(framebuffer, pname, params);
5163}
5164
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005165void Context::getFramebufferParameterivRobust(GLenum target,
5166 GLenum pname,
5167 GLsizei bufSize,
5168 GLsizei *length,
5169 GLint *params)
5170{
5171 UNIMPLEMENTED();
5172}
5173
Jiajia Qin5451d532017-11-16 17:16:34 +08005174void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005175{
5176 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005177 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005178}
5179
Jamie Madilldec86232018-07-11 09:01:18 -04005180bool Context::getScratchBuffer(size_t requstedSizeBytes,
5181 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005182{
Jamie Madilldec86232018-07-11 09:01:18 -04005183 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005184}
5185
Jamie Madilldec86232018-07-11 09:01:18 -04005186bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5187 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005188{
Jamie Madilldec86232018-07-11 09:01:18 -04005189 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005190}
5191
Xinghua Cao10a4d432017-11-28 14:46:26 +08005192Error Context::prepareForDispatch()
5193{
Geoff Langa8cb2872018-03-09 16:09:40 -05005194 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005195
5196 if (isRobustResourceInitEnabled())
5197 {
5198 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5199 }
5200
5201 return NoError();
5202}
5203
Xinghua Cao2b396592017-03-29 15:36:04 +08005204void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5205{
5206 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5207 {
5208 return;
5209 }
5210
Xinghua Cao10a4d432017-11-28 14:46:26 +08005211 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005212 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005213}
5214
Jiajia Qin5451d532017-11-16 17:16:34 +08005215void Context::dispatchComputeIndirect(GLintptr indirect)
5216{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005217 ANGLE_CONTEXT_TRY(prepareForDispatch());
5218 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005219}
5220
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005221void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005222 GLsizei levels,
5223 GLenum internalFormat,
5224 GLsizei width,
5225 GLsizei height)
5226{
5227 Extents size(width, height, 1);
5228 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005229 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005230}
5231
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005232void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005233 GLsizei levels,
5234 GLenum internalFormat,
5235 GLsizei width,
5236 GLsizei height,
5237 GLsizei depth)
5238{
5239 Extents size(width, height, depth);
5240 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005241 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005242}
5243
Jiajia Qin5451d532017-11-16 17:16:34 +08005244void Context::memoryBarrier(GLbitfield barriers)
5245{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005246 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005247}
5248
5249void Context::memoryBarrierByRegion(GLbitfield barriers)
5250{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005251 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005252}
5253
Jamie Madillc1d770e2017-04-13 17:31:24 -04005254GLenum Context::checkFramebufferStatus(GLenum target)
5255{
5256 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5257 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005258 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005259}
5260
5261void Context::compileShader(GLuint shader)
5262{
5263 Shader *shaderObject = GetValidShader(this, shader);
5264 if (!shaderObject)
5265 {
5266 return;
5267 }
5268 shaderObject->compile(this);
5269}
5270
5271void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5272{
5273 for (int i = 0; i < n; i++)
5274 {
5275 deleteBuffer(buffers[i]);
5276 }
5277}
5278
5279void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5280{
5281 for (int i = 0; i < n; i++)
5282 {
5283 if (framebuffers[i] != 0)
5284 {
5285 deleteFramebuffer(framebuffers[i]);
5286 }
5287 }
5288}
5289
5290void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5291{
5292 for (int i = 0; i < n; i++)
5293 {
5294 deleteRenderbuffer(renderbuffers[i]);
5295 }
5296}
5297
5298void Context::deleteTextures(GLsizei n, const GLuint *textures)
5299{
5300 for (int i = 0; i < n; i++)
5301 {
5302 if (textures[i] != 0)
5303 {
5304 deleteTexture(textures[i]);
5305 }
5306 }
5307}
5308
5309void Context::detachShader(GLuint program, GLuint shader)
5310{
5311 Program *programObject = getProgram(program);
5312 ASSERT(programObject);
5313
5314 Shader *shaderObject = getShader(shader);
5315 ASSERT(shaderObject);
5316
5317 programObject->detachShader(this, shaderObject);
5318}
5319
5320void Context::genBuffers(GLsizei n, GLuint *buffers)
5321{
5322 for (int i = 0; i < n; i++)
5323 {
5324 buffers[i] = createBuffer();
5325 }
5326}
5327
5328void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5329{
5330 for (int i = 0; i < n; i++)
5331 {
5332 framebuffers[i] = createFramebuffer();
5333 }
5334}
5335
5336void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5337{
5338 for (int i = 0; i < n; i++)
5339 {
5340 renderbuffers[i] = createRenderbuffer();
5341 }
5342}
5343
5344void Context::genTextures(GLsizei n, GLuint *textures)
5345{
5346 for (int i = 0; i < n; i++)
5347 {
5348 textures[i] = createTexture();
5349 }
5350}
5351
5352void Context::getActiveAttrib(GLuint program,
5353 GLuint index,
5354 GLsizei bufsize,
5355 GLsizei *length,
5356 GLint *size,
5357 GLenum *type,
5358 GLchar *name)
5359{
5360 Program *programObject = getProgram(program);
5361 ASSERT(programObject);
5362 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5363}
5364
5365void Context::getActiveUniform(GLuint program,
5366 GLuint index,
5367 GLsizei bufsize,
5368 GLsizei *length,
5369 GLint *size,
5370 GLenum *type,
5371 GLchar *name)
5372{
5373 Program *programObject = getProgram(program);
5374 ASSERT(programObject);
5375 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5376}
5377
5378void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5379{
5380 Program *programObject = getProgram(program);
5381 ASSERT(programObject);
5382 programObject->getAttachedShaders(maxcount, count, shaders);
5383}
5384
5385GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5386{
5387 Program *programObject = getProgram(program);
5388 ASSERT(programObject);
5389 return programObject->getAttributeLocation(name);
5390}
5391
5392void Context::getBooleanv(GLenum pname, GLboolean *params)
5393{
5394 GLenum nativeType;
5395 unsigned int numParams = 0;
5396 getQueryParameterInfo(pname, &nativeType, &numParams);
5397
5398 if (nativeType == GL_BOOL)
5399 {
5400 getBooleanvImpl(pname, params);
5401 }
5402 else
5403 {
5404 CastStateValues(this, nativeType, pname, numParams, params);
5405 }
5406}
5407
Brandon Jones59770802018-04-02 13:18:42 -07005408void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5409{
5410 getBooleanv(pname, params);
5411}
5412
Jamie Madillc1d770e2017-04-13 17:31:24 -04005413void Context::getFloatv(GLenum pname, GLfloat *params)
5414{
5415 GLenum nativeType;
5416 unsigned int numParams = 0;
5417 getQueryParameterInfo(pname, &nativeType, &numParams);
5418
5419 if (nativeType == GL_FLOAT)
5420 {
5421 getFloatvImpl(pname, params);
5422 }
5423 else
5424 {
5425 CastStateValues(this, nativeType, pname, numParams, params);
5426 }
5427}
5428
Brandon Jones59770802018-04-02 13:18:42 -07005429void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5430{
5431 getFloatv(pname, params);
5432}
5433
Jamie Madillc1d770e2017-04-13 17:31:24 -04005434void Context::getIntegerv(GLenum pname, GLint *params)
5435{
5436 GLenum nativeType;
5437 unsigned int numParams = 0;
5438 getQueryParameterInfo(pname, &nativeType, &numParams);
5439
5440 if (nativeType == GL_INT)
5441 {
5442 getIntegervImpl(pname, params);
5443 }
5444 else
5445 {
5446 CastStateValues(this, nativeType, pname, numParams, params);
5447 }
5448}
5449
Brandon Jones59770802018-04-02 13:18:42 -07005450void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5451{
5452 getIntegerv(pname, data);
5453}
5454
Jamie Madillc1d770e2017-04-13 17:31:24 -04005455void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5456{
5457 Program *programObject = getProgram(program);
5458 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005459 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005460}
5461
Brandon Jones59770802018-04-02 13:18:42 -07005462void Context::getProgramivRobust(GLuint program,
5463 GLenum pname,
5464 GLsizei bufSize,
5465 GLsizei *length,
5466 GLint *params)
5467{
5468 getProgramiv(program, pname, params);
5469}
5470
Jiajia Qin5451d532017-11-16 17:16:34 +08005471void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5472{
5473 UNIMPLEMENTED();
5474}
5475
Jamie Madillbe849e42017-05-02 15:49:00 -04005476void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005477{
5478 Program *programObject = getProgram(program);
5479 ASSERT(programObject);
5480 programObject->getInfoLog(bufsize, length, infolog);
5481}
5482
Jiajia Qin5451d532017-11-16 17:16:34 +08005483void Context::getProgramPipelineInfoLog(GLuint pipeline,
5484 GLsizei bufSize,
5485 GLsizei *length,
5486 GLchar *infoLog)
5487{
5488 UNIMPLEMENTED();
5489}
5490
Jamie Madillc1d770e2017-04-13 17:31:24 -04005491void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5492{
5493 Shader *shaderObject = getShader(shader);
5494 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005495 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005496}
5497
Brandon Jones59770802018-04-02 13:18:42 -07005498void Context::getShaderivRobust(GLuint shader,
5499 GLenum pname,
5500 GLsizei bufSize,
5501 GLsizei *length,
5502 GLint *params)
5503{
5504 getShaderiv(shader, pname, params);
5505}
5506
Jamie Madillc1d770e2017-04-13 17:31:24 -04005507void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5508{
5509 Shader *shaderObject = getShader(shader);
5510 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005511 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005512}
5513
5514void Context::getShaderPrecisionFormat(GLenum shadertype,
5515 GLenum precisiontype,
5516 GLint *range,
5517 GLint *precision)
5518{
5519 // TODO(jmadill): Compute shaders.
5520
5521 switch (shadertype)
5522 {
5523 case GL_VERTEX_SHADER:
5524 switch (precisiontype)
5525 {
5526 case GL_LOW_FLOAT:
5527 mCaps.vertexLowpFloat.get(range, precision);
5528 break;
5529 case GL_MEDIUM_FLOAT:
5530 mCaps.vertexMediumpFloat.get(range, precision);
5531 break;
5532 case GL_HIGH_FLOAT:
5533 mCaps.vertexHighpFloat.get(range, precision);
5534 break;
5535
5536 case GL_LOW_INT:
5537 mCaps.vertexLowpInt.get(range, precision);
5538 break;
5539 case GL_MEDIUM_INT:
5540 mCaps.vertexMediumpInt.get(range, precision);
5541 break;
5542 case GL_HIGH_INT:
5543 mCaps.vertexHighpInt.get(range, precision);
5544 break;
5545
5546 default:
5547 UNREACHABLE();
5548 return;
5549 }
5550 break;
5551
5552 case GL_FRAGMENT_SHADER:
5553 switch (precisiontype)
5554 {
5555 case GL_LOW_FLOAT:
5556 mCaps.fragmentLowpFloat.get(range, precision);
5557 break;
5558 case GL_MEDIUM_FLOAT:
5559 mCaps.fragmentMediumpFloat.get(range, precision);
5560 break;
5561 case GL_HIGH_FLOAT:
5562 mCaps.fragmentHighpFloat.get(range, precision);
5563 break;
5564
5565 case GL_LOW_INT:
5566 mCaps.fragmentLowpInt.get(range, precision);
5567 break;
5568 case GL_MEDIUM_INT:
5569 mCaps.fragmentMediumpInt.get(range, precision);
5570 break;
5571 case GL_HIGH_INT:
5572 mCaps.fragmentHighpInt.get(range, precision);
5573 break;
5574
5575 default:
5576 UNREACHABLE();
5577 return;
5578 }
5579 break;
5580
5581 default:
5582 UNREACHABLE();
5583 return;
5584 }
5585}
5586
5587void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5588{
5589 Shader *shaderObject = getShader(shader);
5590 ASSERT(shaderObject);
5591 shaderObject->getSource(bufsize, length, source);
5592}
5593
5594void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5595{
5596 Program *programObject = getProgram(program);
5597 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005598 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005599}
5600
Brandon Jones59770802018-04-02 13:18:42 -07005601void Context::getUniformfvRobust(GLuint program,
5602 GLint location,
5603 GLsizei bufSize,
5604 GLsizei *length,
5605 GLfloat *params)
5606{
5607 getUniformfv(program, location, params);
5608}
5609
Jamie Madillc1d770e2017-04-13 17:31:24 -04005610void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5611{
5612 Program *programObject = getProgram(program);
5613 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005614 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005615}
5616
Brandon Jones59770802018-04-02 13:18:42 -07005617void Context::getUniformivRobust(GLuint program,
5618 GLint location,
5619 GLsizei bufSize,
5620 GLsizei *length,
5621 GLint *params)
5622{
5623 getUniformiv(program, location, params);
5624}
5625
Jamie Madillc1d770e2017-04-13 17:31:24 -04005626GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5627{
5628 Program *programObject = getProgram(program);
5629 ASSERT(programObject);
5630 return programObject->getUniformLocation(name);
5631}
5632
5633GLboolean Context::isBuffer(GLuint buffer)
5634{
5635 if (buffer == 0)
5636 {
5637 return GL_FALSE;
5638 }
5639
5640 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5641}
5642
5643GLboolean Context::isEnabled(GLenum cap)
5644{
5645 return mGLState.getEnableFeature(cap);
5646}
5647
5648GLboolean Context::isFramebuffer(GLuint framebuffer)
5649{
5650 if (framebuffer == 0)
5651 {
5652 return GL_FALSE;
5653 }
5654
5655 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5656}
5657
5658GLboolean Context::isProgram(GLuint program)
5659{
5660 if (program == 0)
5661 {
5662 return GL_FALSE;
5663 }
5664
5665 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5666}
5667
5668GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5669{
5670 if (renderbuffer == 0)
5671 {
5672 return GL_FALSE;
5673 }
5674
5675 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5676}
5677
5678GLboolean Context::isShader(GLuint shader)
5679{
5680 if (shader == 0)
5681 {
5682 return GL_FALSE;
5683 }
5684
5685 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5686}
5687
5688GLboolean Context::isTexture(GLuint texture)
5689{
5690 if (texture == 0)
5691 {
5692 return GL_FALSE;
5693 }
5694
5695 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5696}
5697
5698void Context::linkProgram(GLuint program)
5699{
5700 Program *programObject = getProgram(program);
5701 ASSERT(programObject);
5702 handleError(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005703
5704 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5705 // don't need to worry that:
5706 // 1. Draw calls after link use the new executable code or the old one depending on the link
5707 // result.
5708 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5709 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5710 // ProgramD3D.
5711 if (programObject->isInUse())
5712 {
5713 // isLinked() which forces to resolve linking, will be called.
5714 mGLState.onProgramExecutableChange(programObject);
5715 mStateCache.onProgramExecutableChange(this);
5716 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005717}
5718
5719void Context::releaseShaderCompiler()
5720{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005721 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005722}
5723
5724void Context::shaderBinary(GLsizei n,
5725 const GLuint *shaders,
5726 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005727 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005728 GLsizei length)
5729{
5730 // No binary shader formats are supported.
5731 UNIMPLEMENTED();
5732}
5733
5734void Context::shaderSource(GLuint shader,
5735 GLsizei count,
5736 const GLchar *const *string,
5737 const GLint *length)
5738{
5739 Shader *shaderObject = getShader(shader);
5740 ASSERT(shaderObject);
5741 shaderObject->setSource(count, string, length);
5742}
5743
5744void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5745{
5746 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5747}
5748
5749void Context::stencilMask(GLuint mask)
5750{
5751 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5752}
5753
5754void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5755{
5756 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5757}
5758
5759void Context::uniform1f(GLint location, GLfloat x)
5760{
5761 Program *program = mGLState.getProgram();
5762 program->setUniform1fv(location, 1, &x);
5763}
5764
5765void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5766{
5767 Program *program = mGLState.getProgram();
5768 program->setUniform1fv(location, count, v);
5769}
5770
Jamie Madill7e4eff12018-08-08 15:49:26 -04005771void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005772{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005773 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04005774 {
5775 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04005776 mStateCache.onActiveTextureChange(this);
Jamie Madill81c2e252017-09-09 23:32:46 -04005777 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005778}
5779
Jamie Madill7e4eff12018-08-08 15:49:26 -04005780void Context::uniform1i(GLint location, GLint x)
5781{
5782 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
5783}
5784
Jamie Madillc1d770e2017-04-13 17:31:24 -04005785void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5786{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005787 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005788}
5789
5790void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5791{
5792 GLfloat xy[2] = {x, y};
5793 Program *program = mGLState.getProgram();
5794 program->setUniform2fv(location, 1, xy);
5795}
5796
5797void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5798{
5799 Program *program = mGLState.getProgram();
5800 program->setUniform2fv(location, count, v);
5801}
5802
5803void Context::uniform2i(GLint location, GLint x, GLint y)
5804{
5805 GLint xy[2] = {x, y};
5806 Program *program = mGLState.getProgram();
5807 program->setUniform2iv(location, 1, xy);
5808}
5809
5810void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5811{
5812 Program *program = mGLState.getProgram();
5813 program->setUniform2iv(location, count, v);
5814}
5815
5816void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5817{
5818 GLfloat xyz[3] = {x, y, z};
5819 Program *program = mGLState.getProgram();
5820 program->setUniform3fv(location, 1, xyz);
5821}
5822
5823void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5824{
5825 Program *program = mGLState.getProgram();
5826 program->setUniform3fv(location, count, v);
5827}
5828
5829void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5830{
5831 GLint xyz[3] = {x, y, z};
5832 Program *program = mGLState.getProgram();
5833 program->setUniform3iv(location, 1, xyz);
5834}
5835
5836void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5837{
5838 Program *program = mGLState.getProgram();
5839 program->setUniform3iv(location, count, v);
5840}
5841
5842void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5843{
5844 GLfloat xyzw[4] = {x, y, z, w};
5845 Program *program = mGLState.getProgram();
5846 program->setUniform4fv(location, 1, xyzw);
5847}
5848
5849void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5850{
5851 Program *program = mGLState.getProgram();
5852 program->setUniform4fv(location, count, v);
5853}
5854
5855void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5856{
5857 GLint xyzw[4] = {x, y, z, w};
5858 Program *program = mGLState.getProgram();
5859 program->setUniform4iv(location, 1, xyzw);
5860}
5861
5862void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5863{
5864 Program *program = mGLState.getProgram();
5865 program->setUniform4iv(location, count, v);
5866}
5867
5868void Context::uniformMatrix2fv(GLint location,
5869 GLsizei count,
5870 GLboolean transpose,
5871 const GLfloat *value)
5872{
5873 Program *program = mGLState.getProgram();
5874 program->setUniformMatrix2fv(location, count, transpose, value);
5875}
5876
5877void Context::uniformMatrix3fv(GLint location,
5878 GLsizei count,
5879 GLboolean transpose,
5880 const GLfloat *value)
5881{
5882 Program *program = mGLState.getProgram();
5883 program->setUniformMatrix3fv(location, count, transpose, value);
5884}
5885
5886void Context::uniformMatrix4fv(GLint location,
5887 GLsizei count,
5888 GLboolean transpose,
5889 const GLfloat *value)
5890{
5891 Program *program = mGLState.getProgram();
5892 program->setUniformMatrix4fv(location, count, transpose, value);
5893}
5894
5895void Context::validateProgram(GLuint program)
5896{
5897 Program *programObject = getProgram(program);
5898 ASSERT(programObject);
5899 programObject->validate(mCaps);
5900}
5901
Jiajia Qin5451d532017-11-16 17:16:34 +08005902void Context::validateProgramPipeline(GLuint pipeline)
5903{
5904 UNIMPLEMENTED();
5905}
5906
Jamie Madilld04908b2017-06-09 14:15:35 -04005907void Context::getProgramBinary(GLuint program,
5908 GLsizei bufSize,
5909 GLsizei *length,
5910 GLenum *binaryFormat,
5911 void *binary)
5912{
5913 Program *programObject = getProgram(program);
5914 ASSERT(programObject != nullptr);
5915
5916 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5917}
5918
5919void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5920{
5921 Program *programObject = getProgram(program);
5922 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005923
Jamie Madilld04908b2017-06-09 14:15:35 -04005924 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madillc43cdad2018-08-08 15:49:25 -04005925 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04005926 if (programObject->isInUse())
5927 {
5928 mGLState.setObjectDirty(GL_PROGRAM);
5929 }
Jamie Madilld04908b2017-06-09 14:15:35 -04005930}
5931
Jamie Madillff325f12017-08-26 15:06:05 -04005932void Context::uniform1ui(GLint location, GLuint v0)
5933{
5934 Program *program = mGLState.getProgram();
5935 program->setUniform1uiv(location, 1, &v0);
5936}
5937
5938void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5939{
5940 Program *program = mGLState.getProgram();
5941 const GLuint xy[] = {v0, v1};
5942 program->setUniform2uiv(location, 1, xy);
5943}
5944
5945void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5946{
5947 Program *program = mGLState.getProgram();
5948 const GLuint xyz[] = {v0, v1, v2};
5949 program->setUniform3uiv(location, 1, xyz);
5950}
5951
5952void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5953{
5954 Program *program = mGLState.getProgram();
5955 const GLuint xyzw[] = {v0, v1, v2, v3};
5956 program->setUniform4uiv(location, 1, xyzw);
5957}
5958
5959void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5960{
5961 Program *program = mGLState.getProgram();
5962 program->setUniform1uiv(location, count, value);
5963}
5964void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5965{
5966 Program *program = mGLState.getProgram();
5967 program->setUniform2uiv(location, count, value);
5968}
5969
5970void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5971{
5972 Program *program = mGLState.getProgram();
5973 program->setUniform3uiv(location, count, value);
5974}
5975
5976void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5977{
5978 Program *program = mGLState.getProgram();
5979 program->setUniform4uiv(location, count, value);
5980}
5981
Jamie Madillf0e04492017-08-26 15:28:42 -04005982void Context::genQueries(GLsizei n, GLuint *ids)
5983{
5984 for (GLsizei i = 0; i < n; i++)
5985 {
5986 GLuint handle = mQueryHandleAllocator.allocate();
5987 mQueryMap.assign(handle, nullptr);
5988 ids[i] = handle;
5989 }
5990}
5991
5992void Context::deleteQueries(GLsizei n, const GLuint *ids)
5993{
5994 for (int i = 0; i < n; i++)
5995 {
5996 GLuint query = ids[i];
5997
5998 Query *queryObject = nullptr;
5999 if (mQueryMap.erase(query, &queryObject))
6000 {
6001 mQueryHandleAllocator.release(query);
6002 if (queryObject)
6003 {
6004 queryObject->release(this);
6005 }
6006 }
6007 }
6008}
6009
6010GLboolean Context::isQuery(GLuint id)
6011{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006012 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006013}
6014
Jamie Madillc8c95812017-08-26 18:40:09 -04006015void Context::uniformMatrix2x3fv(GLint location,
6016 GLsizei count,
6017 GLboolean transpose,
6018 const GLfloat *value)
6019{
6020 Program *program = mGLState.getProgram();
6021 program->setUniformMatrix2x3fv(location, count, transpose, value);
6022}
6023
6024void Context::uniformMatrix3x2fv(GLint location,
6025 GLsizei count,
6026 GLboolean transpose,
6027 const GLfloat *value)
6028{
6029 Program *program = mGLState.getProgram();
6030 program->setUniformMatrix3x2fv(location, count, transpose, value);
6031}
6032
6033void Context::uniformMatrix2x4fv(GLint location,
6034 GLsizei count,
6035 GLboolean transpose,
6036 const GLfloat *value)
6037{
6038 Program *program = mGLState.getProgram();
6039 program->setUniformMatrix2x4fv(location, count, transpose, value);
6040}
6041
6042void Context::uniformMatrix4x2fv(GLint location,
6043 GLsizei count,
6044 GLboolean transpose,
6045 const GLfloat *value)
6046{
6047 Program *program = mGLState.getProgram();
6048 program->setUniformMatrix4x2fv(location, count, transpose, value);
6049}
6050
6051void Context::uniformMatrix3x4fv(GLint location,
6052 GLsizei count,
6053 GLboolean transpose,
6054 const GLfloat *value)
6055{
6056 Program *program = mGLState.getProgram();
6057 program->setUniformMatrix3x4fv(location, count, transpose, value);
6058}
6059
6060void Context::uniformMatrix4x3fv(GLint location,
6061 GLsizei count,
6062 GLboolean transpose,
6063 const GLfloat *value)
6064{
6065 Program *program = mGLState.getProgram();
6066 program->setUniformMatrix4x3fv(location, count, transpose, value);
6067}
6068
Jamie Madilld7576732017-08-26 18:49:50 -04006069void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6070{
6071 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6072 {
6073 GLuint vertexArray = arrays[arrayIndex];
6074
6075 if (arrays[arrayIndex] != 0)
6076 {
6077 VertexArray *vertexArrayObject = nullptr;
6078 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6079 {
6080 if (vertexArrayObject != nullptr)
6081 {
6082 detachVertexArray(vertexArray);
6083 vertexArrayObject->onDestroy(this);
6084 }
6085
6086 mVertexArrayHandleAllocator.release(vertexArray);
6087 }
6088 }
6089 }
6090}
6091
6092void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6093{
6094 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6095 {
6096 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6097 mVertexArrayMap.assign(vertexArray, nullptr);
6098 arrays[arrayIndex] = vertexArray;
6099 }
6100}
6101
6102bool Context::isVertexArray(GLuint array)
6103{
6104 if (array == 0)
6105 {
6106 return GL_FALSE;
6107 }
6108
6109 VertexArray *vao = getVertexArray(array);
6110 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6111}
6112
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006113void Context::endTransformFeedback()
6114{
6115 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6116 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006117 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006118}
6119
6120void Context::transformFeedbackVaryings(GLuint program,
6121 GLsizei count,
6122 const GLchar *const *varyings,
6123 GLenum bufferMode)
6124{
6125 Program *programObject = getProgram(program);
6126 ASSERT(programObject);
6127 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6128}
6129
6130void Context::getTransformFeedbackVarying(GLuint program,
6131 GLuint index,
6132 GLsizei bufSize,
6133 GLsizei *length,
6134 GLsizei *size,
6135 GLenum *type,
6136 GLchar *name)
6137{
6138 Program *programObject = getProgram(program);
6139 ASSERT(programObject);
6140 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6141}
6142
6143void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6144{
6145 for (int i = 0; i < n; i++)
6146 {
6147 GLuint transformFeedback = ids[i];
6148 if (transformFeedback == 0)
6149 {
6150 continue;
6151 }
6152
6153 TransformFeedback *transformFeedbackObject = nullptr;
6154 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6155 {
6156 if (transformFeedbackObject != nullptr)
6157 {
6158 detachTransformFeedback(transformFeedback);
6159 transformFeedbackObject->release(this);
6160 }
6161
6162 mTransformFeedbackHandleAllocator.release(transformFeedback);
6163 }
6164 }
6165}
6166
6167void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6168{
6169 for (int i = 0; i < n; i++)
6170 {
6171 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6172 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6173 ids[i] = transformFeedback;
6174 }
6175}
6176
6177bool Context::isTransformFeedback(GLuint id)
6178{
6179 if (id == 0)
6180 {
6181 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6182 // returns FALSE
6183 return GL_FALSE;
6184 }
6185
6186 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6187 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6188}
6189
6190void Context::pauseTransformFeedback()
6191{
6192 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6193 transformFeedback->pause();
6194}
6195
6196void Context::resumeTransformFeedback()
6197{
6198 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6199 transformFeedback->resume();
6200}
6201
Jamie Madill12e957f2017-08-26 21:42:26 -04006202void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6203{
6204 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006205 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006206}
6207
Brandon Jones59770802018-04-02 13:18:42 -07006208void Context::getUniformuivRobust(GLuint program,
6209 GLint location,
6210 GLsizei bufSize,
6211 GLsizei *length,
6212 GLuint *params)
6213{
6214 getUniformuiv(program, location, params);
6215}
6216
Jamie Madill12e957f2017-08-26 21:42:26 -04006217GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6218{
6219 const Program *programObject = getProgram(program);
6220 return programObject->getFragDataLocation(name);
6221}
6222
6223void Context::getUniformIndices(GLuint program,
6224 GLsizei uniformCount,
6225 const GLchar *const *uniformNames,
6226 GLuint *uniformIndices)
6227{
6228 const Program *programObject = getProgram(program);
6229 if (!programObject->isLinked())
6230 {
6231 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6232 {
6233 uniformIndices[uniformId] = GL_INVALID_INDEX;
6234 }
6235 }
6236 else
6237 {
6238 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6239 {
6240 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6241 }
6242 }
6243}
6244
6245void Context::getActiveUniformsiv(GLuint program,
6246 GLsizei uniformCount,
6247 const GLuint *uniformIndices,
6248 GLenum pname,
6249 GLint *params)
6250{
6251 const Program *programObject = getProgram(program);
6252 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6253 {
6254 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006255 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006256 }
6257}
6258
6259GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6260{
6261 const Program *programObject = getProgram(program);
6262 return programObject->getUniformBlockIndex(uniformBlockName);
6263}
6264
6265void Context::getActiveUniformBlockiv(GLuint program,
6266 GLuint uniformBlockIndex,
6267 GLenum pname,
6268 GLint *params)
6269{
6270 const Program *programObject = getProgram(program);
6271 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6272}
6273
Brandon Jones59770802018-04-02 13:18:42 -07006274void Context::getActiveUniformBlockivRobust(GLuint program,
6275 GLuint uniformBlockIndex,
6276 GLenum pname,
6277 GLsizei bufSize,
6278 GLsizei *length,
6279 GLint *params)
6280{
6281 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6282}
6283
Jamie Madill12e957f2017-08-26 21:42:26 -04006284void Context::getActiveUniformBlockName(GLuint program,
6285 GLuint uniformBlockIndex,
6286 GLsizei bufSize,
6287 GLsizei *length,
6288 GLchar *uniformBlockName)
6289{
6290 const Program *programObject = getProgram(program);
6291 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6292}
6293
6294void Context::uniformBlockBinding(GLuint program,
6295 GLuint uniformBlockIndex,
6296 GLuint uniformBlockBinding)
6297{
6298 Program *programObject = getProgram(program);
6299 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006300
6301 if (programObject->isInUse())
6302 {
6303 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006304 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006305 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006306}
6307
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006308GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6309{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006310 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6311 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006312
Jamie Madill70b5bb02017-08-28 13:32:37 -04006313 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006314 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006315 if (error.isError())
6316 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006317 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006318 handleError(error);
6319 return nullptr;
6320 }
6321
Jamie Madill70b5bb02017-08-28 13:32:37 -04006322 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006323}
6324
6325GLboolean Context::isSync(GLsync sync)
6326{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006327 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006328}
6329
6330GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6331{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006332 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006333
6334 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006335 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006336 return result;
6337}
6338
6339void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6340{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006341 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006342 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006343}
6344
6345void Context::getInteger64v(GLenum pname, GLint64 *params)
6346{
6347 GLenum nativeType = GL_NONE;
6348 unsigned int numParams = 0;
6349 getQueryParameterInfo(pname, &nativeType, &numParams);
6350
6351 if (nativeType == GL_INT_64_ANGLEX)
6352 {
6353 getInteger64vImpl(pname, params);
6354 }
6355 else
6356 {
6357 CastStateValues(this, nativeType, pname, numParams, params);
6358 }
6359}
6360
Brandon Jones59770802018-04-02 13:18:42 -07006361void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6362{
6363 getInteger64v(pname, data);
6364}
6365
Corentin Wallez336129f2017-10-17 15:55:40 -04006366void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006367{
6368 Buffer *buffer = mGLState.getTargetBuffer(target);
6369 QueryBufferParameteri64v(buffer, pname, params);
6370}
6371
Brandon Jones59770802018-04-02 13:18:42 -07006372void Context::getBufferParameteri64vRobust(BufferBinding target,
6373 GLenum pname,
6374 GLsizei bufSize,
6375 GLsizei *length,
6376 GLint64 *params)
6377{
6378 getBufferParameteri64v(target, pname, params);
6379}
6380
Jamie Madill3ef140a2017-08-26 23:11:21 -04006381void Context::genSamplers(GLsizei count, GLuint *samplers)
6382{
6383 for (int i = 0; i < count; i++)
6384 {
6385 samplers[i] = mState.mSamplers->createSampler();
6386 }
6387}
6388
6389void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6390{
6391 for (int i = 0; i < count; i++)
6392 {
6393 GLuint sampler = samplers[i];
6394
6395 if (mState.mSamplers->getSampler(sampler))
6396 {
6397 detachSampler(sampler);
6398 }
6399
6400 mState.mSamplers->deleteObject(this, sampler);
6401 }
6402}
6403
6404void Context::getInternalformativ(GLenum target,
6405 GLenum internalformat,
6406 GLenum pname,
6407 GLsizei bufSize,
6408 GLint *params)
6409{
6410 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6411 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6412}
6413
Brandon Jones59770802018-04-02 13:18:42 -07006414void Context::getInternalformativRobust(GLenum target,
6415 GLenum internalformat,
6416 GLenum pname,
6417 GLsizei bufSize,
6418 GLsizei *length,
6419 GLint *params)
6420{
6421 getInternalformativ(target, internalformat, pname, bufSize, params);
6422}
6423
Jiajia Qin5451d532017-11-16 17:16:34 +08006424void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6425{
6426 programUniform1iv(program, location, 1, &v0);
6427}
6428
6429void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6430{
6431 GLint xy[2] = {v0, v1};
6432 programUniform2iv(program, location, 1, xy);
6433}
6434
6435void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6436{
6437 GLint xyz[3] = {v0, v1, v2};
6438 programUniform3iv(program, location, 1, xyz);
6439}
6440
6441void Context::programUniform4i(GLuint program,
6442 GLint location,
6443 GLint v0,
6444 GLint v1,
6445 GLint v2,
6446 GLint v3)
6447{
6448 GLint xyzw[4] = {v0, v1, v2, v3};
6449 programUniform4iv(program, location, 1, xyzw);
6450}
6451
6452void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6453{
6454 programUniform1uiv(program, location, 1, &v0);
6455}
6456
6457void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6458{
6459 GLuint xy[2] = {v0, v1};
6460 programUniform2uiv(program, location, 1, xy);
6461}
6462
6463void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6464{
6465 GLuint xyz[3] = {v0, v1, v2};
6466 programUniform3uiv(program, location, 1, xyz);
6467}
6468
6469void Context::programUniform4ui(GLuint program,
6470 GLint location,
6471 GLuint v0,
6472 GLuint v1,
6473 GLuint v2,
6474 GLuint v3)
6475{
6476 GLuint xyzw[4] = {v0, v1, v2, v3};
6477 programUniform4uiv(program, location, 1, xyzw);
6478}
6479
6480void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6481{
6482 programUniform1fv(program, location, 1, &v0);
6483}
6484
6485void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6486{
6487 GLfloat xy[2] = {v0, v1};
6488 programUniform2fv(program, location, 1, xy);
6489}
6490
6491void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6492{
6493 GLfloat xyz[3] = {v0, v1, v2};
6494 programUniform3fv(program, location, 1, xyz);
6495}
6496
6497void Context::programUniform4f(GLuint program,
6498 GLint location,
6499 GLfloat v0,
6500 GLfloat v1,
6501 GLfloat v2,
6502 GLfloat v3)
6503{
6504 GLfloat xyzw[4] = {v0, v1, v2, v3};
6505 programUniform4fv(program, location, 1, xyzw);
6506}
6507
Jamie Madill81c2e252017-09-09 23:32:46 -04006508void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6509{
6510 Program *programObject = getProgram(program);
6511 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006512 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006513}
6514
Jiajia Qin5451d532017-11-16 17:16:34 +08006515void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6516{
6517 Program *programObject = getProgram(program);
6518 ASSERT(programObject);
6519 programObject->setUniform2iv(location, count, value);
6520}
6521
6522void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6523{
6524 Program *programObject = getProgram(program);
6525 ASSERT(programObject);
6526 programObject->setUniform3iv(location, count, value);
6527}
6528
6529void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6530{
6531 Program *programObject = getProgram(program);
6532 ASSERT(programObject);
6533 programObject->setUniform4iv(location, count, value);
6534}
6535
6536void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6537{
6538 Program *programObject = getProgram(program);
6539 ASSERT(programObject);
6540 programObject->setUniform1uiv(location, count, value);
6541}
6542
6543void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6544{
6545 Program *programObject = getProgram(program);
6546 ASSERT(programObject);
6547 programObject->setUniform2uiv(location, count, value);
6548}
6549
6550void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6551{
6552 Program *programObject = getProgram(program);
6553 ASSERT(programObject);
6554 programObject->setUniform3uiv(location, count, value);
6555}
6556
6557void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6558{
6559 Program *programObject = getProgram(program);
6560 ASSERT(programObject);
6561 programObject->setUniform4uiv(location, count, value);
6562}
6563
6564void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6565{
6566 Program *programObject = getProgram(program);
6567 ASSERT(programObject);
6568 programObject->setUniform1fv(location, count, value);
6569}
6570
6571void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6572{
6573 Program *programObject = getProgram(program);
6574 ASSERT(programObject);
6575 programObject->setUniform2fv(location, count, value);
6576}
6577
6578void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6579{
6580 Program *programObject = getProgram(program);
6581 ASSERT(programObject);
6582 programObject->setUniform3fv(location, count, value);
6583}
6584
6585void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6586{
6587 Program *programObject = getProgram(program);
6588 ASSERT(programObject);
6589 programObject->setUniform4fv(location, count, value);
6590}
6591
6592void Context::programUniformMatrix2fv(GLuint program,
6593 GLint location,
6594 GLsizei count,
6595 GLboolean transpose,
6596 const GLfloat *value)
6597{
6598 Program *programObject = getProgram(program);
6599 ASSERT(programObject);
6600 programObject->setUniformMatrix2fv(location, count, transpose, value);
6601}
6602
6603void Context::programUniformMatrix3fv(GLuint program,
6604 GLint location,
6605 GLsizei count,
6606 GLboolean transpose,
6607 const GLfloat *value)
6608{
6609 Program *programObject = getProgram(program);
6610 ASSERT(programObject);
6611 programObject->setUniformMatrix3fv(location, count, transpose, value);
6612}
6613
6614void Context::programUniformMatrix4fv(GLuint program,
6615 GLint location,
6616 GLsizei count,
6617 GLboolean transpose,
6618 const GLfloat *value)
6619{
6620 Program *programObject = getProgram(program);
6621 ASSERT(programObject);
6622 programObject->setUniformMatrix4fv(location, count, transpose, value);
6623}
6624
6625void Context::programUniformMatrix2x3fv(GLuint program,
6626 GLint location,
6627 GLsizei count,
6628 GLboolean transpose,
6629 const GLfloat *value)
6630{
6631 Program *programObject = getProgram(program);
6632 ASSERT(programObject);
6633 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6634}
6635
6636void Context::programUniformMatrix3x2fv(GLuint program,
6637 GLint location,
6638 GLsizei count,
6639 GLboolean transpose,
6640 const GLfloat *value)
6641{
6642 Program *programObject = getProgram(program);
6643 ASSERT(programObject);
6644 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6645}
6646
6647void Context::programUniformMatrix2x4fv(GLuint program,
6648 GLint location,
6649 GLsizei count,
6650 GLboolean transpose,
6651 const GLfloat *value)
6652{
6653 Program *programObject = getProgram(program);
6654 ASSERT(programObject);
6655 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6656}
6657
6658void Context::programUniformMatrix4x2fv(GLuint program,
6659 GLint location,
6660 GLsizei count,
6661 GLboolean transpose,
6662 const GLfloat *value)
6663{
6664 Program *programObject = getProgram(program);
6665 ASSERT(programObject);
6666 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6667}
6668
6669void Context::programUniformMatrix3x4fv(GLuint program,
6670 GLint location,
6671 GLsizei count,
6672 GLboolean transpose,
6673 const GLfloat *value)
6674{
6675 Program *programObject = getProgram(program);
6676 ASSERT(programObject);
6677 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6678}
6679
6680void Context::programUniformMatrix4x3fv(GLuint program,
6681 GLint location,
6682 GLsizei count,
6683 GLboolean transpose,
6684 const GLfloat *value)
6685{
6686 Program *programObject = getProgram(program);
6687 ASSERT(programObject);
6688 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6689}
6690
Jamie Madill81c2e252017-09-09 23:32:46 -04006691void Context::onTextureChange(const Texture *texture)
6692{
6693 // Conservatively assume all textures are dirty.
6694 // TODO(jmadill): More fine-grained update.
6695 mGLState.setObjectDirty(GL_TEXTURE);
6696}
6697
James Darpiniane8a93c62018-01-04 18:02:24 -08006698bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6699{
6700 return mGLState.isCurrentTransformFeedback(tf);
6701}
James Darpiniane8a93c62018-01-04 18:02:24 -08006702
Yunchao Hea336b902017-08-02 16:05:21 +08006703void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6704{
6705 for (int i = 0; i < count; i++)
6706 {
6707 pipelines[i] = createProgramPipeline();
6708 }
6709}
6710
6711void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6712{
6713 for (int i = 0; i < count; i++)
6714 {
6715 if (pipelines[i] != 0)
6716 {
6717 deleteProgramPipeline(pipelines[i]);
6718 }
6719 }
6720}
6721
6722GLboolean Context::isProgramPipeline(GLuint pipeline)
6723{
6724 if (pipeline == 0)
6725 {
6726 return GL_FALSE;
6727 }
6728
6729 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6730}
6731
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006732void Context::finishFenceNV(GLuint fence)
6733{
6734 FenceNV *fenceObject = getFenceNV(fence);
6735
6736 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006737 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006738}
6739
6740void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6741{
6742 FenceNV *fenceObject = getFenceNV(fence);
6743
6744 ASSERT(fenceObject && fenceObject->isSet());
6745
6746 switch (pname)
6747 {
6748 case GL_FENCE_STATUS_NV:
6749 {
6750 // GL_NV_fence spec:
6751 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6752 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6753 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6754 GLboolean status = GL_TRUE;
6755 if (fenceObject->getStatus() != GL_TRUE)
6756 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006757 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006758 }
6759 *params = status;
6760 break;
6761 }
6762
6763 case GL_FENCE_CONDITION_NV:
6764 {
6765 *params = static_cast<GLint>(fenceObject->getCondition());
6766 break;
6767 }
6768
6769 default:
6770 UNREACHABLE();
6771 }
6772}
6773
6774void Context::getTranslatedShaderSource(GLuint shader,
6775 GLsizei bufsize,
6776 GLsizei *length,
6777 GLchar *source)
6778{
6779 Shader *shaderObject = getShader(shader);
6780 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006781 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006782}
6783
6784void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6785{
6786 Program *programObject = getProgram(program);
6787 ASSERT(programObject);
6788
6789 programObject->getUniformfv(this, location, params);
6790}
6791
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006792void Context::getnUniformfvRobust(GLuint program,
6793 GLint location,
6794 GLsizei bufSize,
6795 GLsizei *length,
6796 GLfloat *params)
6797{
6798 UNIMPLEMENTED();
6799}
6800
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006801void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6802{
6803 Program *programObject = getProgram(program);
6804 ASSERT(programObject);
6805
6806 programObject->getUniformiv(this, location, params);
6807}
6808
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006809void Context::getnUniformivRobust(GLuint program,
6810 GLint location,
6811 GLsizei bufSize,
6812 GLsizei *length,
6813 GLint *params)
6814{
6815 UNIMPLEMENTED();
6816}
6817
6818void Context::getnUniformuivRobust(GLuint program,
6819 GLint location,
6820 GLsizei bufSize,
6821 GLsizei *length,
6822 GLuint *params)
6823{
6824 UNIMPLEMENTED();
6825}
6826
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006827GLboolean Context::isFenceNV(GLuint fence)
6828{
6829 FenceNV *fenceObject = getFenceNV(fence);
6830
6831 if (fenceObject == nullptr)
6832 {
6833 return GL_FALSE;
6834 }
6835
6836 // GL_NV_fence spec:
6837 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6838 // existing fence.
6839 return fenceObject->isSet();
6840}
6841
6842void Context::readnPixels(GLint x,
6843 GLint y,
6844 GLsizei width,
6845 GLsizei height,
6846 GLenum format,
6847 GLenum type,
6848 GLsizei bufSize,
6849 void *data)
6850{
6851 return readPixels(x, y, width, height, format, type, data);
6852}
6853
Jamie Madill007530e2017-12-28 14:27:04 -05006854void Context::setFenceNV(GLuint fence, GLenum condition)
6855{
6856 ASSERT(condition == GL_ALL_COMPLETED_NV);
6857
6858 FenceNV *fenceObject = getFenceNV(fence);
6859 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006860 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006861}
6862
6863GLboolean Context::testFenceNV(GLuint fence)
6864{
6865 FenceNV *fenceObject = getFenceNV(fence);
6866
6867 ASSERT(fenceObject != nullptr);
6868 ASSERT(fenceObject->isSet() == GL_TRUE);
6869
6870 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006871 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006872 if (error.isError())
6873 {
6874 handleError(error);
6875 return GL_TRUE;
6876 }
6877
6878 return result;
6879}
6880
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006881void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006882{
6883 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006884 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006885 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006886}
6887
Jamie Madillfa920eb2018-01-04 11:45:50 -05006888void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006889{
6890 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006891 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006892 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6893}
6894
Jamie Madillfa920eb2018-01-04 11:45:50 -05006895void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6896{
6897 UNIMPLEMENTED();
6898}
6899
Jamie Madill5b772312018-03-08 20:28:32 -05006900bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6901{
6902 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6903 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6904 // to the fact that it is stored internally as a float, and so would require conversion
6905 // if returned from Context::getIntegerv. Since this conversion is already implemented
6906 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6907 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6908 // application.
6909 switch (pname)
6910 {
6911 case GL_COMPRESSED_TEXTURE_FORMATS:
6912 {
6913 *type = GL_INT;
6914 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6915 return true;
6916 }
6917 case GL_SHADER_BINARY_FORMATS:
6918 {
6919 *type = GL_INT;
6920 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6921 return true;
6922 }
6923
6924 case GL_MAX_VERTEX_ATTRIBS:
6925 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6926 case GL_MAX_VARYING_VECTORS:
6927 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6928 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6929 case GL_MAX_TEXTURE_IMAGE_UNITS:
6930 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6931 case GL_MAX_RENDERBUFFER_SIZE:
6932 case GL_NUM_SHADER_BINARY_FORMATS:
6933 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6934 case GL_ARRAY_BUFFER_BINDING:
6935 case GL_FRAMEBUFFER_BINDING:
6936 case GL_RENDERBUFFER_BINDING:
6937 case GL_CURRENT_PROGRAM:
6938 case GL_PACK_ALIGNMENT:
6939 case GL_UNPACK_ALIGNMENT:
6940 case GL_GENERATE_MIPMAP_HINT:
6941 case GL_RED_BITS:
6942 case GL_GREEN_BITS:
6943 case GL_BLUE_BITS:
6944 case GL_ALPHA_BITS:
6945 case GL_DEPTH_BITS:
6946 case GL_STENCIL_BITS:
6947 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6948 case GL_CULL_FACE_MODE:
6949 case GL_FRONT_FACE:
6950 case GL_ACTIVE_TEXTURE:
6951 case GL_STENCIL_FUNC:
6952 case GL_STENCIL_VALUE_MASK:
6953 case GL_STENCIL_REF:
6954 case GL_STENCIL_FAIL:
6955 case GL_STENCIL_PASS_DEPTH_FAIL:
6956 case GL_STENCIL_PASS_DEPTH_PASS:
6957 case GL_STENCIL_BACK_FUNC:
6958 case GL_STENCIL_BACK_VALUE_MASK:
6959 case GL_STENCIL_BACK_REF:
6960 case GL_STENCIL_BACK_FAIL:
6961 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6962 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6963 case GL_DEPTH_FUNC:
6964 case GL_BLEND_SRC_RGB:
6965 case GL_BLEND_SRC_ALPHA:
6966 case GL_BLEND_DST_RGB:
6967 case GL_BLEND_DST_ALPHA:
6968 case GL_BLEND_EQUATION_RGB:
6969 case GL_BLEND_EQUATION_ALPHA:
6970 case GL_STENCIL_WRITEMASK:
6971 case GL_STENCIL_BACK_WRITEMASK:
6972 case GL_STENCIL_CLEAR_VALUE:
6973 case GL_SUBPIXEL_BITS:
6974 case GL_MAX_TEXTURE_SIZE:
6975 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6976 case GL_SAMPLE_BUFFERS:
6977 case GL_SAMPLES:
6978 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6979 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6980 case GL_TEXTURE_BINDING_2D:
6981 case GL_TEXTURE_BINDING_CUBE_MAP:
6982 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6983 {
6984 *type = GL_INT;
6985 *numParams = 1;
6986 return true;
6987 }
6988 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6989 {
6990 if (!getExtensions().packReverseRowOrder)
6991 {
6992 return false;
6993 }
6994 *type = GL_INT;
6995 *numParams = 1;
6996 return true;
6997 }
6998 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6999 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7000 {
7001 if (!getExtensions().textureRectangle)
7002 {
7003 return false;
7004 }
7005 *type = GL_INT;
7006 *numParams = 1;
7007 return true;
7008 }
7009 case GL_MAX_DRAW_BUFFERS_EXT:
7010 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7011 {
7012 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7013 {
7014 return false;
7015 }
7016 *type = GL_INT;
7017 *numParams = 1;
7018 return true;
7019 }
7020 case GL_MAX_VIEWPORT_DIMS:
7021 {
7022 *type = GL_INT;
7023 *numParams = 2;
7024 return true;
7025 }
7026 case GL_VIEWPORT:
7027 case GL_SCISSOR_BOX:
7028 {
7029 *type = GL_INT;
7030 *numParams = 4;
7031 return true;
7032 }
7033 case GL_SHADER_COMPILER:
7034 case GL_SAMPLE_COVERAGE_INVERT:
7035 case GL_DEPTH_WRITEMASK:
7036 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7037 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7038 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7039 // bool-natural
7040 case GL_SAMPLE_COVERAGE:
7041 case GL_SCISSOR_TEST:
7042 case GL_STENCIL_TEST:
7043 case GL_DEPTH_TEST:
7044 case GL_BLEND:
7045 case GL_DITHER:
7046 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7047 {
7048 *type = GL_BOOL;
7049 *numParams = 1;
7050 return true;
7051 }
7052 case GL_COLOR_WRITEMASK:
7053 {
7054 *type = GL_BOOL;
7055 *numParams = 4;
7056 return true;
7057 }
7058 case GL_POLYGON_OFFSET_FACTOR:
7059 case GL_POLYGON_OFFSET_UNITS:
7060 case GL_SAMPLE_COVERAGE_VALUE:
7061 case GL_DEPTH_CLEAR_VALUE:
7062 case GL_LINE_WIDTH:
7063 {
7064 *type = GL_FLOAT;
7065 *numParams = 1;
7066 return true;
7067 }
7068 case GL_ALIASED_LINE_WIDTH_RANGE:
7069 case GL_ALIASED_POINT_SIZE_RANGE:
7070 case GL_DEPTH_RANGE:
7071 {
7072 *type = GL_FLOAT;
7073 *numParams = 2;
7074 return true;
7075 }
7076 case GL_COLOR_CLEAR_VALUE:
7077 case GL_BLEND_COLOR:
7078 {
7079 *type = GL_FLOAT;
7080 *numParams = 4;
7081 return true;
7082 }
7083 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7084 if (!getExtensions().textureFilterAnisotropic)
7085 {
7086 return false;
7087 }
7088 *type = GL_FLOAT;
7089 *numParams = 1;
7090 return true;
7091 case GL_TIMESTAMP_EXT:
7092 if (!getExtensions().disjointTimerQuery)
7093 {
7094 return false;
7095 }
7096 *type = GL_INT_64_ANGLEX;
7097 *numParams = 1;
7098 return true;
7099 case GL_GPU_DISJOINT_EXT:
7100 if (!getExtensions().disjointTimerQuery)
7101 {
7102 return false;
7103 }
7104 *type = GL_INT;
7105 *numParams = 1;
7106 return true;
7107 case GL_COVERAGE_MODULATION_CHROMIUM:
7108 if (!getExtensions().framebufferMixedSamples)
7109 {
7110 return false;
7111 }
7112 *type = GL_INT;
7113 *numParams = 1;
7114 return true;
7115 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7116 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7117 {
7118 return false;
7119 }
7120 *type = GL_INT;
7121 *numParams = 1;
7122 return true;
7123 }
7124
7125 if (getExtensions().debug)
7126 {
7127 switch (pname)
7128 {
7129 case GL_DEBUG_LOGGED_MESSAGES:
7130 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7131 case GL_DEBUG_GROUP_STACK_DEPTH:
7132 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7133 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7134 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7135 case GL_MAX_LABEL_LENGTH:
7136 *type = GL_INT;
7137 *numParams = 1;
7138 return true;
7139
7140 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7141 case GL_DEBUG_OUTPUT:
7142 *type = GL_BOOL;
7143 *numParams = 1;
7144 return true;
7145 }
7146 }
7147
7148 if (getExtensions().multisampleCompatibility)
7149 {
7150 switch (pname)
7151 {
7152 case GL_MULTISAMPLE_EXT:
7153 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7154 *type = GL_BOOL;
7155 *numParams = 1;
7156 return true;
7157 }
7158 }
7159
7160 if (getExtensions().pathRendering)
7161 {
7162 switch (pname)
7163 {
7164 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7165 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7166 *type = GL_FLOAT;
7167 *numParams = 16;
7168 return true;
7169 }
7170 }
7171
7172 if (getExtensions().bindGeneratesResource)
7173 {
7174 switch (pname)
7175 {
7176 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7177 *type = GL_BOOL;
7178 *numParams = 1;
7179 return true;
7180 }
7181 }
7182
7183 if (getExtensions().clientArrays)
7184 {
7185 switch (pname)
7186 {
7187 case GL_CLIENT_ARRAYS_ANGLE:
7188 *type = GL_BOOL;
7189 *numParams = 1;
7190 return true;
7191 }
7192 }
7193
7194 if (getExtensions().sRGBWriteControl)
7195 {
7196 switch (pname)
7197 {
7198 case GL_FRAMEBUFFER_SRGB_EXT:
7199 *type = GL_BOOL;
7200 *numParams = 1;
7201 return true;
7202 }
7203 }
7204
7205 if (getExtensions().robustResourceInitialization &&
7206 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7207 {
7208 *type = GL_BOOL;
7209 *numParams = 1;
7210 return true;
7211 }
7212
7213 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7214 {
7215 *type = GL_BOOL;
7216 *numParams = 1;
7217 return true;
7218 }
7219
jchen1082af6202018-06-22 10:59:52 +08007220 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7221 {
7222 *type = GL_INT;
7223 *numParams = 1;
7224 return true;
7225 }
7226
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007227 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7228 {
7229 *type = GL_INT;
7230 *numParams = 1;
7231 return true;
7232 }
7233
Jamie Madill5b772312018-03-08 20:28:32 -05007234 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7235 switch (pname)
7236 {
7237 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7238 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7239 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7240 {
7241 return false;
7242 }
7243 *type = GL_INT;
7244 *numParams = 1;
7245 return true;
7246
7247 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7248 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7249 {
7250 return false;
7251 }
7252 *type = GL_INT;
7253 *numParams = 1;
7254 return true;
7255
7256 case GL_PROGRAM_BINARY_FORMATS_OES:
7257 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7258 {
7259 return false;
7260 }
7261 *type = GL_INT;
7262 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7263 return true;
7264
7265 case GL_PACK_ROW_LENGTH:
7266 case GL_PACK_SKIP_ROWS:
7267 case GL_PACK_SKIP_PIXELS:
7268 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7269 {
7270 return false;
7271 }
7272 *type = GL_INT;
7273 *numParams = 1;
7274 return true;
7275 case GL_UNPACK_ROW_LENGTH:
7276 case GL_UNPACK_SKIP_ROWS:
7277 case GL_UNPACK_SKIP_PIXELS:
7278 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7279 {
7280 return false;
7281 }
7282 *type = GL_INT;
7283 *numParams = 1;
7284 return true;
7285 case GL_VERTEX_ARRAY_BINDING:
7286 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7287 {
7288 return false;
7289 }
7290 *type = GL_INT;
7291 *numParams = 1;
7292 return true;
7293 case GL_PIXEL_PACK_BUFFER_BINDING:
7294 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7295 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7296 {
7297 return false;
7298 }
7299 *type = GL_INT;
7300 *numParams = 1;
7301 return true;
7302 case GL_MAX_SAMPLES:
7303 {
7304 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7305 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7306 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7307 {
7308 return false;
7309 }
7310 *type = GL_INT;
7311 *numParams = 1;
7312 return true;
7313
7314 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7315 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7316 {
7317 return false;
7318 }
7319 *type = GL_INT;
7320 *numParams = 1;
7321 return true;
7322 }
7323 }
7324
7325 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7326 {
7327 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7328 {
7329 return false;
7330 }
7331 *type = GL_INT;
7332 *numParams = 1;
7333 return true;
7334 }
7335
7336 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7337 {
7338 *type = GL_INT;
7339 *numParams = 1;
7340 return true;
7341 }
7342
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007343 if (getClientVersion() < Version(2, 0))
7344 {
7345 switch (pname)
7346 {
7347 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007348 case GL_CLIENT_ACTIVE_TEXTURE:
7349 case GL_MATRIX_MODE:
7350 case GL_MAX_TEXTURE_UNITS:
7351 case GL_MAX_MODELVIEW_STACK_DEPTH:
7352 case GL_MAX_PROJECTION_STACK_DEPTH:
7353 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007354 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007355 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007356 case GL_VERTEX_ARRAY_STRIDE:
7357 case GL_NORMAL_ARRAY_STRIDE:
7358 case GL_COLOR_ARRAY_STRIDE:
7359 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7360 case GL_VERTEX_ARRAY_SIZE:
7361 case GL_COLOR_ARRAY_SIZE:
7362 case GL_TEXTURE_COORD_ARRAY_SIZE:
7363 case GL_VERTEX_ARRAY_TYPE:
7364 case GL_NORMAL_ARRAY_TYPE:
7365 case GL_COLOR_ARRAY_TYPE:
7366 case GL_TEXTURE_COORD_ARRAY_TYPE:
7367 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7368 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7369 case GL_COLOR_ARRAY_BUFFER_BINDING:
7370 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7371 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7372 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7373 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007374 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007375 case GL_MODELVIEW_STACK_DEPTH:
7376 case GL_PROJECTION_STACK_DEPTH:
7377 case GL_TEXTURE_STACK_DEPTH:
7378 case GL_LOGIC_OP_MODE:
7379 case GL_BLEND_SRC:
7380 case GL_BLEND_DST:
7381 case GL_PERSPECTIVE_CORRECTION_HINT:
7382 case GL_POINT_SMOOTH_HINT:
7383 case GL_LINE_SMOOTH_HINT:
7384 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007385 *type = GL_INT;
7386 *numParams = 1;
7387 return true;
7388 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007389 case GL_FOG_DENSITY:
7390 case GL_FOG_START:
7391 case GL_FOG_END:
7392 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007393 case GL_POINT_SIZE:
7394 case GL_POINT_SIZE_MIN:
7395 case GL_POINT_SIZE_MAX:
7396 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007397 *type = GL_FLOAT;
7398 *numParams = 1;
7399 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007400 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007401 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007402 *type = GL_FLOAT;
7403 *numParams = 2;
7404 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007405 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007406 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007407 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007408 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007409 *type = GL_FLOAT;
7410 *numParams = 4;
7411 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007412 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007413 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007414 *type = GL_FLOAT;
7415 *numParams = 3;
7416 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007417 case GL_MODELVIEW_MATRIX:
7418 case GL_PROJECTION_MATRIX:
7419 case GL_TEXTURE_MATRIX:
7420 *type = GL_FLOAT;
7421 *numParams = 16;
7422 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007423 case GL_LIGHT_MODEL_TWO_SIDE:
7424 *type = GL_BOOL;
7425 *numParams = 1;
7426 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007427 }
7428 }
7429
Jamie Madill5b772312018-03-08 20:28:32 -05007430 if (getClientVersion() < Version(3, 0))
7431 {
7432 return false;
7433 }
7434
7435 // Check for ES3.0+ parameter names
7436 switch (pname)
7437 {
7438 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7439 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7440 case GL_UNIFORM_BUFFER_BINDING:
7441 case GL_TRANSFORM_FEEDBACK_BINDING:
7442 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7443 case GL_COPY_READ_BUFFER_BINDING:
7444 case GL_COPY_WRITE_BUFFER_BINDING:
7445 case GL_SAMPLER_BINDING:
7446 case GL_READ_BUFFER:
7447 case GL_TEXTURE_BINDING_3D:
7448 case GL_TEXTURE_BINDING_2D_ARRAY:
7449 case GL_MAX_3D_TEXTURE_SIZE:
7450 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7451 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7452 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7453 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7454 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7455 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7456 case GL_MAX_VARYING_COMPONENTS:
7457 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7458 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7459 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7460 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7461 case GL_NUM_EXTENSIONS:
7462 case GL_MAJOR_VERSION:
7463 case GL_MINOR_VERSION:
7464 case GL_MAX_ELEMENTS_INDICES:
7465 case GL_MAX_ELEMENTS_VERTICES:
7466 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7467 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7468 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7469 case GL_UNPACK_IMAGE_HEIGHT:
7470 case GL_UNPACK_SKIP_IMAGES:
7471 {
7472 *type = GL_INT;
7473 *numParams = 1;
7474 return true;
7475 }
7476
7477 case GL_MAX_ELEMENT_INDEX:
7478 case GL_MAX_UNIFORM_BLOCK_SIZE:
7479 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7480 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7481 case GL_MAX_SERVER_WAIT_TIMEOUT:
7482 {
7483 *type = GL_INT_64_ANGLEX;
7484 *numParams = 1;
7485 return true;
7486 }
7487
7488 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7489 case GL_TRANSFORM_FEEDBACK_PAUSED:
7490 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7491 case GL_RASTERIZER_DISCARD:
7492 {
7493 *type = GL_BOOL;
7494 *numParams = 1;
7495 return true;
7496 }
7497
7498 case GL_MAX_TEXTURE_LOD_BIAS:
7499 {
7500 *type = GL_FLOAT;
7501 *numParams = 1;
7502 return true;
7503 }
7504 }
7505
7506 if (getExtensions().requestExtension)
7507 {
7508 switch (pname)
7509 {
7510 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7511 *type = GL_INT;
7512 *numParams = 1;
7513 return true;
7514 }
7515 }
7516
7517 if (getClientVersion() < Version(3, 1))
7518 {
7519 return false;
7520 }
7521
7522 switch (pname)
7523 {
7524 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7525 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7526 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7527 case GL_MAX_FRAMEBUFFER_WIDTH:
7528 case GL_MAX_FRAMEBUFFER_HEIGHT:
7529 case GL_MAX_FRAMEBUFFER_SAMPLES:
7530 case GL_MAX_SAMPLE_MASK_WORDS:
7531 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7532 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7533 case GL_MAX_INTEGER_SAMPLES:
7534 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7535 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7536 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7537 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7538 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7539 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7540 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7541 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7542 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7543 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7544 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7545 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7546 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7547 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7548 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7549 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7550 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7551 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7552 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7553 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7554 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7555 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7556 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7557 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7558 case GL_MAX_UNIFORM_LOCATIONS:
7559 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7560 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7561 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7562 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7563 case GL_MAX_IMAGE_UNITS:
7564 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7565 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7566 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7567 case GL_SHADER_STORAGE_BUFFER_BINDING:
7568 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7569 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007570 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007571 *type = GL_INT;
7572 *numParams = 1;
7573 return true;
7574 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7575 *type = GL_INT_64_ANGLEX;
7576 *numParams = 1;
7577 return true;
7578 case GL_SAMPLE_MASK:
7579 *type = GL_BOOL;
7580 *numParams = 1;
7581 return true;
7582 }
7583
7584 if (getExtensions().geometryShader)
7585 {
7586 switch (pname)
7587 {
7588 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7589 case GL_LAYER_PROVOKING_VERTEX_EXT:
7590 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7591 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7592 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7593 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7594 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7595 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7596 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7597 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7598 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7599 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7600 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7601 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7602 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7603 *type = GL_INT;
7604 *numParams = 1;
7605 return true;
7606 }
7607 }
7608
7609 return false;
7610}
7611
7612bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7613{
7614 if (getClientVersion() < Version(3, 0))
7615 {
7616 return false;
7617 }
7618
7619 switch (target)
7620 {
7621 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7622 case GL_UNIFORM_BUFFER_BINDING:
7623 {
7624 *type = GL_INT;
7625 *numParams = 1;
7626 return true;
7627 }
7628 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7629 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7630 case GL_UNIFORM_BUFFER_START:
7631 case GL_UNIFORM_BUFFER_SIZE:
7632 {
7633 *type = GL_INT_64_ANGLEX;
7634 *numParams = 1;
7635 return true;
7636 }
7637 }
7638
7639 if (getClientVersion() < Version(3, 1))
7640 {
7641 return false;
7642 }
7643
7644 switch (target)
7645 {
7646 case GL_IMAGE_BINDING_LAYERED:
7647 {
7648 *type = GL_BOOL;
7649 *numParams = 1;
7650 return true;
7651 }
7652 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7653 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7654 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7655 case GL_SHADER_STORAGE_BUFFER_BINDING:
7656 case GL_VERTEX_BINDING_BUFFER:
7657 case GL_VERTEX_BINDING_DIVISOR:
7658 case GL_VERTEX_BINDING_OFFSET:
7659 case GL_VERTEX_BINDING_STRIDE:
7660 case GL_SAMPLE_MASK_VALUE:
7661 case GL_IMAGE_BINDING_NAME:
7662 case GL_IMAGE_BINDING_LEVEL:
7663 case GL_IMAGE_BINDING_LAYER:
7664 case GL_IMAGE_BINDING_ACCESS:
7665 case GL_IMAGE_BINDING_FORMAT:
7666 {
7667 *type = GL_INT;
7668 *numParams = 1;
7669 return true;
7670 }
7671 case GL_ATOMIC_COUNTER_BUFFER_START:
7672 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7673 case GL_SHADER_STORAGE_BUFFER_START:
7674 case GL_SHADER_STORAGE_BUFFER_SIZE:
7675 {
7676 *type = GL_INT_64_ANGLEX;
7677 *numParams = 1;
7678 return true;
7679 }
7680 }
7681
7682 return false;
7683}
7684
7685Program *Context::getProgram(GLuint handle) const
7686{
7687 return mState.mShaderPrograms->getProgram(handle);
7688}
7689
7690Shader *Context::getShader(GLuint handle) const
7691{
7692 return mState.mShaderPrograms->getShader(handle);
7693}
7694
7695bool Context::isTextureGenerated(GLuint texture) const
7696{
7697 return mState.mTextures->isHandleGenerated(texture);
7698}
7699
Jamie Madill5b772312018-03-08 20:28:32 -05007700bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7701{
7702 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7703}
7704
7705bool Context::isFramebufferGenerated(GLuint framebuffer) const
7706{
7707 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7708}
7709
7710bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7711{
7712 return mState.mPipelines->isHandleGenerated(pipeline);
7713}
7714
7715bool Context::usingDisplayTextureShareGroup() const
7716{
7717 return mDisplayTextureShareGroup;
7718}
7719
7720GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7721{
7722 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7723 internalformat == GL_DEPTH_STENCIL
7724 ? GL_DEPTH24_STENCIL8
7725 : internalformat;
7726}
7727
jchen1082af6202018-06-22 10:59:52 +08007728void Context::maxShaderCompilerThreads(GLuint count)
7729{
jchen107ae70d82018-07-06 13:47:01 +08007730 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08007731 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007732 // A count of zero specifies a request for no parallel compiling or linking.
7733 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7734 {
7735 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7736 }
7737 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007738}
7739
Jamie Madill2eb65032018-07-30 10:25:57 -04007740bool Context::isGLES1() const
7741{
7742 return mState.getClientVersion() < Version(2, 0);
7743}
7744
Jamie Madilla11819d2018-07-30 10:26:01 -04007745void Context::onSubjectStateChange(const Context *context,
7746 angle::SubjectIndex index,
7747 angle::SubjectMessage message)
7748{
Jamie Madilla11819d2018-07-30 10:26:01 -04007749 switch (index)
7750 {
7751 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007752 switch (message)
7753 {
7754 case angle::SubjectMessage::CONTENTS_CHANGED:
7755 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
7756 mStateCache.onVertexArrayBufferContentsChange(this);
7757 break;
7758 case angle::SubjectMessage::RESOURCE_MAPPED:
7759 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7760 case angle::SubjectMessage::BINDING_CHANGED:
7761 mStateCache.onVertexArrayBufferStateChange(this);
7762 break;
7763 default:
7764 break;
7765 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007766 break;
7767
7768 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007769 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7770 {
7771 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
7772 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007773 break;
7774
7775 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007776 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7777 {
7778 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
7779 }
7780 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04007781 break;
7782
7783 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04007784 if (index < kTextureMaxSubjectIndex)
7785 {
7786 mGLState.onActiveTextureStateChange(index);
Jamie Madilld84b6732018-09-06 15:54:35 -04007787 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007788 }
Jamie Madille25b8002018-09-20 13:39:49 -04007789 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04007790 {
Jamie Madill6d32cef2018-08-14 02:34:28 -04007791 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04007792 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007793 }
Jamie Madille25b8002018-09-20 13:39:49 -04007794 else
7795 {
7796 ASSERT(index < kSamplerMaxSubjectIndex);
7797 mGLState.setSamplerDirty(index - kSampler0SubjectIndex);
7798 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007799 break;
7800 }
7801}
7802
Jamie Madill6b873dd2018-07-12 23:56:30 -04007803// ErrorSet implementation.
7804ErrorSet::ErrorSet(Context *context) : mContext(context)
7805{
7806}
7807
7808ErrorSet::~ErrorSet() = default;
7809
Jamie Madill306b6c12018-07-27 08:12:49 -04007810void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007811{
7812 // This internal enum is used to filter internal errors that are already handled.
7813 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7814 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7815 {
7816 return;
7817 }
7818
7819 if (ANGLE_UNLIKELY(error.isError()))
7820 {
7821 GLenum code = error.getCode();
7822 mErrors.insert(code);
7823 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7824 {
7825 mContext->markContextLost();
7826 }
7827
7828 ASSERT(!error.getMessage().empty());
7829 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7830 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7831 error.getMessage());
7832 }
7833}
7834
7835bool ErrorSet::empty() const
7836{
7837 return mErrors.empty();
7838}
7839
7840GLenum ErrorSet::popError()
7841{
7842 ASSERT(!empty());
7843 GLenum error = *mErrors.begin();
7844 mErrors.erase(mErrors.begin());
7845 return error;
7846}
Jamie Madilldc358af2018-07-31 11:22:13 -04007847
7848// StateCache implementation.
Jamie Madill16e28fd2018-09-12 11:03:05 -04007849StateCache::StateCache(Context *context)
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007850 : mCachedHasAnyEnabledClientAttrib(false),
7851 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04007852 mCachedInstancedVertexElementLimit(0),
7853 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madilldc358af2018-07-31 11:22:13 -04007854{
Jamie Madill16e28fd2018-09-12 11:03:05 -04007855 updateValidDrawModes(context);
Jamie Madilldc358af2018-07-31 11:22:13 -04007856}
7857
7858StateCache::~StateCache() = default;
7859
7860void StateCache::updateActiveAttribsMask(Context *context)
7861{
7862 bool isGLES1 = context->isGLES1();
7863 const State &glState = context->getGLState();
7864
7865 if (!isGLES1 && !glState.getProgram())
7866 {
7867 mCachedActiveBufferedAttribsMask = AttributesMask();
7868 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04007869 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04007870 return;
7871 }
7872
7873 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7874 : glState.getProgram()->getActiveAttribLocationsMask();
7875
7876 const VertexArray *vao = glState.getVertexArray();
7877 ASSERT(vao);
7878
7879 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7880 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04007881 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007882
Jamie Madill0a17e482018-08-31 17:19:11 -04007883 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
7884 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04007885 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007886 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7887}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007888
7889void StateCache::updateVertexElementLimits(Context *context)
7890{
7891 const VertexArray *vao = context->getGLState().getVertexArray();
7892
7893 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7894 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7895
7896 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
7897 // If there are no buffered attributes then we should not limit the draw call count.
7898 if (!vao || !mCachedActiveBufferedAttribsMask.any())
7899 {
7900 return;
7901 }
7902
7903 const auto &vertexAttribs = vao->getVertexAttributes();
7904 const auto &vertexBindings = vao->getVertexBindings();
7905
7906 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
7907 {
7908 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
7909 ASSERT(attrib.enabled);
7910
7911 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
7912 ASSERT(context->isGLES1() ||
7913 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
7914
7915 GLint64 limit = attrib.getCachedElementLimit();
7916 if (binding.getDivisor() > 0)
7917 {
7918 mCachedInstancedVertexElementLimit =
7919 std::min(mCachedInstancedVertexElementLimit, limit);
7920 }
7921 else
7922 {
7923 mCachedNonInstancedVertexElementLimit =
7924 std::min(mCachedNonInstancedVertexElementLimit, limit);
7925 }
7926 }
7927}
Jamie Madillc43cdad2018-08-08 15:49:25 -04007928
Jamie Madilld84b6732018-09-06 15:54:35 -04007929void StateCache::updateBasicDrawStatesError()
7930{
7931 mCachedBasicDrawStatesError = kInvalidPointer;
7932}
7933
7934intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
7935{
7936 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
7937 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
7938 return mCachedBasicDrawStatesError;
7939}
7940
Jamie Madillc43cdad2018-08-08 15:49:25 -04007941void StateCache::onVertexArrayBindingChange(Context *context)
7942{
7943 updateActiveAttribsMask(context);
7944 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007945 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007946}
7947
7948void StateCache::onProgramExecutableChange(Context *context)
7949{
7950 updateActiveAttribsMask(context);
7951 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007952 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04007953 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04007954}
7955
Jamie Madilld84b6732018-09-06 15:54:35 -04007956void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04007957{
7958 updateVertexElementLimits(context);
7959}
7960
Jamie Madilld84b6732018-09-06 15:54:35 -04007961void StateCache::onVertexArrayBufferContentsChange(Context *context)
7962{
7963 updateVertexElementLimits(context);
7964 updateBasicDrawStatesError();
7965}
7966
Jamie Madillc43cdad2018-08-08 15:49:25 -04007967void StateCache::onVertexArrayStateChange(Context *context)
7968{
7969 updateActiveAttribsMask(context);
7970 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007971 updateBasicDrawStatesError();
7972}
7973
7974void StateCache::onVertexArrayBufferStateChange(Context *context)
7975{
7976 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007977}
7978
7979void StateCache::onGLES1ClientStateChange(Context *context)
7980{
7981 updateActiveAttribsMask(context);
7982}
Jamie Madilld84b6732018-09-06 15:54:35 -04007983
7984void StateCache::onDrawFramebufferChange(Context *context)
7985{
7986 updateBasicDrawStatesError();
7987}
7988
7989void StateCache::onContextCapChange(Context *context)
7990{
7991 updateBasicDrawStatesError();
7992}
7993
7994void StateCache::onStencilStateChange(Context *context)
7995{
7996 updateBasicDrawStatesError();
7997}
7998
7999void StateCache::onDefaultVertexAttributeChange(Context *context)
8000{
8001 updateBasicDrawStatesError();
8002}
8003
8004void StateCache::onActiveTextureChange(Context *context)
8005{
8006 updateBasicDrawStatesError();
8007}
8008
8009void StateCache::onQueryChange(Context *context)
8010{
8011 updateBasicDrawStatesError();
8012}
8013
8014void StateCache::onTransformFeedbackChange(Context *context)
8015{
8016 updateBasicDrawStatesError();
8017}
8018
8019void StateCache::onUniformBufferStateChange(Context *context)
8020{
8021 updateBasicDrawStatesError();
8022}
8023
8024void StateCache::onBufferBindingChange(Context *context)
8025{
8026 updateBasicDrawStatesError();
8027}
Jamie Madill526a6f62018-09-12 11:03:05 -04008028
8029void StateCache::updateValidDrawModes(Context *context)
8030{
8031 Program *program = context->getGLState().getProgram();
8032 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8033 {
8034 mCachedValidDrawModes = {{
8035 true, /* Points */
8036 true, /* Lines */
8037 true, /* LineLoop */
8038 true, /* LineStrip */
8039 true, /* Triangles */
8040 true, /* TriangleStrip */
8041 true, /* TriangleFan */
8042 false, /* LinesAdjacency */
8043 false, /* LineStripAdjacency */
8044 false, /* TrianglesAdjacency */
8045 false, /* TriangleStripAdjacency */
8046 false, /* InvalidEnum */
8047 }};
8048 }
8049 else
8050 {
8051 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8052
8053 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
8054
8055 mCachedValidDrawModes = {{
8056 gsMode == PrimitiveMode::Points, /* Points */
8057 gsMode == PrimitiveMode::Lines, /* Lines */
8058 gsMode == PrimitiveMode::Lines, /* LineLoop */
8059 gsMode == PrimitiveMode::Lines, /* LineStrip */
8060 gsMode == PrimitiveMode::Triangles, /* Triangles */
8061 gsMode == PrimitiveMode::Triangles, /* TriangleStrip */
8062 gsMode == PrimitiveMode::Triangles, /* TriangleFan */
8063 gsMode == PrimitiveMode::LinesAdjacency, /* LinesAdjacency */
8064 gsMode == PrimitiveMode::LinesAdjacency, /* LineStripAdjacency */
8065 gsMode == PrimitiveMode::TrianglesAdjacency, /* TrianglesAdjacency */
8066 gsMode == PrimitiveMode::TrianglesAdjacency, /* TriangleStripAdjacency */
8067 false, /* InvalidEnum */
8068 }};
8069 }
8070}
Jamie Madillc29968b2016-01-20 11:17:23 -05008071} // namespace gl