blob: ec165477ed76b471bdd9488f19ab8211df746615 [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 Etuahodbce1f82018-09-19 15:32:17 +03003548 if (buffer == GL_DEPTH && !getGLState().getDrawFramebuffer()->getDepthbuffer())
3549 {
3550 // It's not an error to try to clear a non-existent depth buffer, but it's a no-op.
3551 return;
3552 }
Geoff Langd4fff502017-09-22 11:28:28 -04003553 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3554 ANGLE_CONTEXT_TRY(
3555 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003556}
3557
3558void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3559{
Geoff Langd4fff502017-09-22 11:28:28 -04003560 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3561 ANGLE_CONTEXT_TRY(
3562 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003563}
3564
3565void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3566{
Olli Etuahodbce1f82018-09-19 15:32:17 +03003567 if (buffer == GL_STENCIL && !getGLState().getDrawFramebuffer()->getStencilbuffer())
3568 {
3569 // It's not an error to try to clear a non-existent stencil buffer, but it's a no-op.
3570 return;
3571 }
Geoff Langd4fff502017-09-22 11:28:28 -04003572 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3573 ANGLE_CONTEXT_TRY(
3574 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003575}
3576
3577void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3578{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003579 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003580 ASSERT(framebufferObject);
3581
3582 // If a buffer is not present, the clear has no effect
3583 if (framebufferObject->getDepthbuffer() == nullptr &&
3584 framebufferObject->getStencilbuffer() == nullptr)
3585 {
3586 return;
3587 }
3588
Geoff Langd4fff502017-09-22 11:28:28 -04003589 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3590 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003591}
3592
3593void Context::readPixels(GLint x,
3594 GLint y,
3595 GLsizei width,
3596 GLsizei height,
3597 GLenum format,
3598 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003599 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003600{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003601 if (width == 0 || height == 0)
3602 {
3603 return;
3604 }
3605
Jamie Madillbc918e72018-03-08 09:47:21 -05003606 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003607
Jamie Madillb6664922017-07-25 12:55:04 -04003608 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3609 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003610
3611 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003612 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003613}
3614
Brandon Jones59770802018-04-02 13:18:42 -07003615void Context::readPixelsRobust(GLint x,
3616 GLint y,
3617 GLsizei width,
3618 GLsizei height,
3619 GLenum format,
3620 GLenum type,
3621 GLsizei bufSize,
3622 GLsizei *length,
3623 GLsizei *columns,
3624 GLsizei *rows,
3625 void *pixels)
3626{
3627 readPixels(x, y, width, height, format, type, pixels);
3628}
3629
3630void Context::readnPixelsRobust(GLint x,
3631 GLint y,
3632 GLsizei width,
3633 GLsizei height,
3634 GLenum format,
3635 GLenum type,
3636 GLsizei bufSize,
3637 GLsizei *length,
3638 GLsizei *columns,
3639 GLsizei *rows,
3640 void *data)
3641{
3642 readPixels(x, y, width, height, format, type, data);
3643}
3644
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003645void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003646 GLint level,
3647 GLenum internalformat,
3648 GLint x,
3649 GLint y,
3650 GLsizei width,
3651 GLsizei height,
3652 GLint border)
3653{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003654 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003655 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003656
Jamie Madillc29968b2016-01-20 11:17:23 -05003657 Rectangle sourceArea(x, y, width, height);
3658
Jamie Madill05b35b22017-10-03 09:01:44 -04003659 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003660 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003661 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003662}
3663
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003664void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003665 GLint level,
3666 GLint xoffset,
3667 GLint yoffset,
3668 GLint x,
3669 GLint y,
3670 GLsizei width,
3671 GLsizei height)
3672{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003673 if (width == 0 || height == 0)
3674 {
3675 return;
3676 }
3677
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003678 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003679 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003680
Jamie Madillc29968b2016-01-20 11:17:23 -05003681 Offset destOffset(xoffset, yoffset, 0);
3682 Rectangle sourceArea(x, y, width, height);
3683
Jamie Madill05b35b22017-10-03 09:01:44 -04003684 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003685 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003686 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003687}
3688
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003689void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003690 GLint level,
3691 GLint xoffset,
3692 GLint yoffset,
3693 GLint zoffset,
3694 GLint x,
3695 GLint y,
3696 GLsizei width,
3697 GLsizei height)
3698{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003699 if (width == 0 || height == 0)
3700 {
3701 return;
3702 }
3703
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003704 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003705 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003706
Jamie Madillc29968b2016-01-20 11:17:23 -05003707 Offset destOffset(xoffset, yoffset, zoffset);
3708 Rectangle sourceArea(x, y, width, height);
3709
Jamie Madill05b35b22017-10-03 09:01:44 -04003710 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3711 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003712 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3713 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003714}
3715
3716void Context::framebufferTexture2D(GLenum target,
3717 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003718 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003719 GLuint texture,
3720 GLint level)
3721{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003722 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003723 ASSERT(framebuffer);
3724
3725 if (texture != 0)
3726 {
3727 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003728 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003729 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003730 }
3731 else
3732 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003733 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003734 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003735
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003736 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003737}
3738
3739void Context::framebufferRenderbuffer(GLenum target,
3740 GLenum attachment,
3741 GLenum renderbuffertarget,
3742 GLuint renderbuffer)
3743{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003744 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003745 ASSERT(framebuffer);
3746
3747 if (renderbuffer != 0)
3748 {
3749 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003750
Jamie Madillcc129372018-04-12 09:13:18 -04003751 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003752 renderbufferObject);
3753 }
3754 else
3755 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003756 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003757 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003758
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003759 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003760}
3761
3762void Context::framebufferTextureLayer(GLenum target,
3763 GLenum attachment,
3764 GLuint texture,
3765 GLint level,
3766 GLint layer)
3767{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003768 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003769 ASSERT(framebuffer);
3770
3771 if (texture != 0)
3772 {
3773 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003774 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003775 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003776 }
3777 else
3778 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003779 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003780 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003781
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003782 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003783}
3784
Brandon Jones59770802018-04-02 13:18:42 -07003785void Context::framebufferTextureMultiviewLayered(GLenum target,
3786 GLenum attachment,
3787 GLuint texture,
3788 GLint level,
3789 GLint baseViewIndex,
3790 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003791{
Martin Radev82ef7742017-08-08 17:44:58 +03003792 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3793 ASSERT(framebuffer);
3794
3795 if (texture != 0)
3796 {
3797 Texture *textureObj = getTexture(texture);
3798
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003799 ImageIndex index;
3800 if (textureObj->getType() == TextureType::_2DArray)
3801 {
3802 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3803 }
3804 else
3805 {
3806 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3807 ASSERT(level == 0);
3808 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3809 }
Martin Radev82ef7742017-08-08 17:44:58 +03003810 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3811 numViews, baseViewIndex);
3812 }
3813 else
3814 {
3815 framebuffer->resetAttachment(this, attachment);
3816 }
3817
3818 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003819}
3820
Brandon Jones59770802018-04-02 13:18:42 -07003821void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3822 GLenum attachment,
3823 GLuint texture,
3824 GLint level,
3825 GLsizei numViews,
3826 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003827{
Martin Radev5dae57b2017-07-14 16:15:55 +03003828 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3829 ASSERT(framebuffer);
3830
3831 if (texture != 0)
3832 {
3833 Texture *textureObj = getTexture(texture);
3834
3835 ImageIndex index = ImageIndex::Make2D(level);
3836 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3837 textureObj, numViews, viewportOffsets);
3838 }
3839 else
3840 {
3841 framebuffer->resetAttachment(this, attachment);
3842 }
3843
3844 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003845}
3846
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003847void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3848{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003849 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3850 ASSERT(framebuffer);
3851
3852 if (texture != 0)
3853 {
3854 Texture *textureObj = getTexture(texture);
3855
3856 ImageIndex index = ImageIndex::MakeFromType(
3857 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3858 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3859 }
3860 else
3861 {
3862 framebuffer->resetAttachment(this, attachment);
3863 }
3864
3865 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003866}
3867
Jamie Madillc29968b2016-01-20 11:17:23 -05003868void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3869{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003870 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003871 ASSERT(framebuffer);
3872 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003873 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04003874 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003875}
3876
3877void Context::readBuffer(GLenum mode)
3878{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003879 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003880 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003881 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003882}
3883
3884void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3885{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003886 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003887 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003888
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003889 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003890 ASSERT(framebuffer);
3891
3892 // The specification isn't clear what should be done when the framebuffer isn't complete.
3893 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003894 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003895}
3896
3897void Context::invalidateFramebuffer(GLenum target,
3898 GLsizei numAttachments,
3899 const GLenum *attachments)
3900{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003901 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003902 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003903
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003904 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003905 ASSERT(framebuffer);
3906
Jamie Madill427064d2018-04-13 16:20:34 -04003907 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003908 {
Jamie Madill437fa652016-05-03 15:13:24 -04003909 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003910 }
Jamie Madill437fa652016-05-03 15:13:24 -04003911
Jamie Madill4928b7c2017-06-20 12:57:39 -04003912 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003913}
3914
3915void Context::invalidateSubFramebuffer(GLenum target,
3916 GLsizei numAttachments,
3917 const GLenum *attachments,
3918 GLint x,
3919 GLint y,
3920 GLsizei width,
3921 GLsizei height)
3922{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003923 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003924 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003925
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003926 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003927 ASSERT(framebuffer);
3928
Jamie Madill427064d2018-04-13 16:20:34 -04003929 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003930 {
Jamie Madill437fa652016-05-03 15:13:24 -04003931 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003932 }
Jamie Madill437fa652016-05-03 15:13:24 -04003933
3934 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003935 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003936}
3937
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003938void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003939 GLint level,
3940 GLint internalformat,
3941 GLsizei width,
3942 GLsizei height,
3943 GLint border,
3944 GLenum format,
3945 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003946 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003947{
Jamie Madillbc918e72018-03-08 09:47:21 -05003948 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003949
3950 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003951 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003952 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003953 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003954}
3955
Brandon Jones59770802018-04-02 13:18:42 -07003956void Context::texImage2DRobust(TextureTarget target,
3957 GLint level,
3958 GLint internalformat,
3959 GLsizei width,
3960 GLsizei height,
3961 GLint border,
3962 GLenum format,
3963 GLenum type,
3964 GLsizei bufSize,
3965 const void *pixels)
3966{
3967 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3968}
3969
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003970void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003971 GLint level,
3972 GLint internalformat,
3973 GLsizei width,
3974 GLsizei height,
3975 GLsizei depth,
3976 GLint border,
3977 GLenum format,
3978 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003979 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003980{
Jamie Madillbc918e72018-03-08 09:47:21 -05003981 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003982
3983 Extents size(width, height, depth);
3984 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003985 handleError(texture->setImage(this, mGLState.getUnpackState(),
3986 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003987 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003988}
3989
Brandon Jones59770802018-04-02 13:18:42 -07003990void Context::texImage3DRobust(TextureType target,
3991 GLint level,
3992 GLint internalformat,
3993 GLsizei width,
3994 GLsizei height,
3995 GLsizei depth,
3996 GLint border,
3997 GLenum format,
3998 GLenum type,
3999 GLsizei bufSize,
4000 const void *pixels)
4001{
4002 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4003}
4004
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004005void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004006 GLint level,
4007 GLint xoffset,
4008 GLint yoffset,
4009 GLsizei width,
4010 GLsizei height,
4011 GLenum format,
4012 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004013 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004014{
4015 // Zero sized uploads are valid but no-ops
4016 if (width == 0 || height == 0)
4017 {
4018 return;
4019 }
4020
Jamie Madillbc918e72018-03-08 09:47:21 -05004021 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004022
4023 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004024 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004025
4026 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4027
4028 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target, level,
4029 area, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004030}
4031
Brandon Jones59770802018-04-02 13:18:42 -07004032void Context::texSubImage2DRobust(TextureTarget target,
4033 GLint level,
4034 GLint xoffset,
4035 GLint yoffset,
4036 GLsizei width,
4037 GLsizei height,
4038 GLenum format,
4039 GLenum type,
4040 GLsizei bufSize,
4041 const void *pixels)
4042{
4043 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4044}
4045
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004046void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004047 GLint level,
4048 GLint xoffset,
4049 GLint yoffset,
4050 GLint zoffset,
4051 GLsizei width,
4052 GLsizei height,
4053 GLsizei depth,
4054 GLenum format,
4055 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004056 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004057{
4058 // Zero sized uploads are valid but no-ops
4059 if (width == 0 || height == 0 || depth == 0)
4060 {
4061 return;
4062 }
4063
Jamie Madillbc918e72018-03-08 09:47:21 -05004064 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004065
4066 Box area(xoffset, yoffset, zoffset, width, height, depth);
4067 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004068
4069 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4070
4071 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004072 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004073 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004074}
4075
Brandon Jones59770802018-04-02 13:18:42 -07004076void Context::texSubImage3DRobust(TextureType target,
4077 GLint level,
4078 GLint xoffset,
4079 GLint yoffset,
4080 GLint zoffset,
4081 GLsizei width,
4082 GLsizei height,
4083 GLsizei depth,
4084 GLenum format,
4085 GLenum type,
4086 GLsizei bufSize,
4087 const void *pixels)
4088{
4089 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4090 pixels);
4091}
4092
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004093void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004094 GLint level,
4095 GLenum internalformat,
4096 GLsizei width,
4097 GLsizei height,
4098 GLint border,
4099 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004100 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004101{
Jamie Madillbc918e72018-03-08 09:47:21 -05004102 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004103
4104 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004105 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004106 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4107 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004108 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004109}
4110
Brandon Jones59770802018-04-02 13:18:42 -07004111void Context::compressedTexImage2DRobust(TextureTarget target,
4112 GLint level,
4113 GLenum internalformat,
4114 GLsizei width,
4115 GLsizei height,
4116 GLint border,
4117 GLsizei imageSize,
4118 GLsizei dataSize,
4119 const GLvoid *data)
4120{
4121 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4122}
4123
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004124void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004125 GLint level,
4126 GLenum internalformat,
4127 GLsizei width,
4128 GLsizei height,
4129 GLsizei depth,
4130 GLint border,
4131 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004132 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004133{
Jamie Madillbc918e72018-03-08 09:47:21 -05004134 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004135
4136 Extents size(width, height, depth);
4137 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004138 handleError(texture->setCompressedImage(
4139 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004140 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004141}
4142
Brandon Jones59770802018-04-02 13:18:42 -07004143void Context::compressedTexImage3DRobust(TextureType target,
4144 GLint level,
4145 GLenum internalformat,
4146 GLsizei width,
4147 GLsizei height,
4148 GLsizei depth,
4149 GLint border,
4150 GLsizei imageSize,
4151 GLsizei dataSize,
4152 const GLvoid *data)
4153{
4154 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4155 data);
4156}
4157
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004158void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004159 GLint level,
4160 GLint xoffset,
4161 GLint yoffset,
4162 GLsizei width,
4163 GLsizei height,
4164 GLenum format,
4165 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004166 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004167{
Jamie Madillbc918e72018-03-08 09:47:21 -05004168 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004169
4170 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004171 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004172 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4173 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004174 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004175}
4176
Brandon Jones59770802018-04-02 13:18:42 -07004177void Context::compressedTexSubImage2DRobust(TextureTarget target,
4178 GLint level,
4179 GLint xoffset,
4180 GLint yoffset,
4181 GLsizei width,
4182 GLsizei height,
4183 GLenum format,
4184 GLsizei imageSize,
4185 GLsizei dataSize,
4186 const GLvoid *data)
4187{
4188 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4189 data);
4190}
4191
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004192void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004193 GLint level,
4194 GLint xoffset,
4195 GLint yoffset,
4196 GLint zoffset,
4197 GLsizei width,
4198 GLsizei height,
4199 GLsizei depth,
4200 GLenum format,
4201 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004202 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004203{
4204 // Zero sized uploads are valid but no-ops
4205 if (width == 0 || height == 0)
4206 {
4207 return;
4208 }
4209
Jamie Madillbc918e72018-03-08 09:47:21 -05004210 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004211
4212 Box area(xoffset, yoffset, zoffset, width, height, depth);
4213 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004214 handleError(texture->setCompressedSubImage(
4215 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004216 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004217}
4218
Brandon Jones59770802018-04-02 13:18:42 -07004219void Context::compressedTexSubImage3DRobust(TextureType target,
4220 GLint level,
4221 GLint xoffset,
4222 GLint yoffset,
4223 GLint zoffset,
4224 GLsizei width,
4225 GLsizei height,
4226 GLsizei depth,
4227 GLenum format,
4228 GLsizei imageSize,
4229 GLsizei dataSize,
4230 const GLvoid *data)
4231{
4232 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4233 imageSize, data);
4234}
4235
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004236void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004237{
4238 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004239 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004240}
4241
Jamie Madill007530e2017-12-28 14:27:04 -05004242void Context::copyTexture(GLuint sourceId,
4243 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004244 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004245 GLuint destId,
4246 GLint destLevel,
4247 GLint internalFormat,
4248 GLenum destType,
4249 GLboolean unpackFlipY,
4250 GLboolean unpackPremultiplyAlpha,
4251 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004252{
Jamie Madillbc918e72018-03-08 09:47:21 -05004253 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004254
4255 gl::Texture *sourceTexture = getTexture(sourceId);
4256 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004257 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4258 sourceLevel, ConvertToBool(unpackFlipY),
4259 ConvertToBool(unpackPremultiplyAlpha),
4260 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004261}
4262
Jamie Madill007530e2017-12-28 14:27:04 -05004263void Context::copySubTexture(GLuint sourceId,
4264 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004265 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004266 GLuint destId,
4267 GLint destLevel,
4268 GLint xoffset,
4269 GLint yoffset,
4270 GLint x,
4271 GLint y,
4272 GLsizei width,
4273 GLsizei height,
4274 GLboolean unpackFlipY,
4275 GLboolean unpackPremultiplyAlpha,
4276 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004277{
4278 // Zero sized copies are valid but no-ops
4279 if (width == 0 || height == 0)
4280 {
4281 return;
4282 }
4283
Jamie Madillbc918e72018-03-08 09:47:21 -05004284 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004285
4286 gl::Texture *sourceTexture = getTexture(sourceId);
4287 gl::Texture *destTexture = getTexture(destId);
4288 Offset offset(xoffset, yoffset, 0);
4289 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004290 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4291 ConvertToBool(unpackFlipY),
4292 ConvertToBool(unpackPremultiplyAlpha),
4293 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004294}
4295
Jamie Madill007530e2017-12-28 14:27:04 -05004296void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004297{
Jamie Madillbc918e72018-03-08 09:47:21 -05004298 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004299
4300 gl::Texture *sourceTexture = getTexture(sourceId);
4301 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004302 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004303}
4304
Corentin Wallez336129f2017-10-17 15:55:40 -04004305void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004306{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004307 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004308 ASSERT(buffer);
4309
Geoff Lang496c02d2016-10-20 11:38:11 -07004310 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004311}
4312
Brandon Jones59770802018-04-02 13:18:42 -07004313void Context::getBufferPointervRobust(BufferBinding target,
4314 GLenum pname,
4315 GLsizei bufSize,
4316 GLsizei *length,
4317 void **params)
4318{
4319 getBufferPointerv(target, pname, params);
4320}
4321
Corentin Wallez336129f2017-10-17 15:55:40 -04004322void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004323{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004324 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004325 ASSERT(buffer);
4326
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004327 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004328 if (error.isError())
4329 {
Jamie Madill437fa652016-05-03 15:13:24 -04004330 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004331 return nullptr;
4332 }
4333
4334 return buffer->getMapPointer();
4335}
4336
Corentin Wallez336129f2017-10-17 15:55:40 -04004337GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004338{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004339 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004340 ASSERT(buffer);
4341
4342 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004343 Error error = buffer->unmap(this, &result);
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 GL_FALSE;
4348 }
4349
4350 return result;
4351}
4352
Corentin Wallez336129f2017-10-17 15:55:40 -04004353void *Context::mapBufferRange(BufferBinding target,
4354 GLintptr offset,
4355 GLsizeiptr length,
4356 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004357{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004358 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004359 ASSERT(buffer);
4360
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004361 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004362 if (error.isError())
4363 {
Jamie Madill437fa652016-05-03 15:13:24 -04004364 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004365 return nullptr;
4366 }
4367
4368 return buffer->getMapPointer();
4369}
4370
Corentin Wallez336129f2017-10-17 15:55:40 -04004371void Context::flushMappedBufferRange(BufferBinding /*target*/,
4372 GLintptr /*offset*/,
4373 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004374{
4375 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4376}
4377
Jamie Madillbc918e72018-03-08 09:47:21 -05004378Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004379{
Geoff Langa8cb2872018-03-09 16:09:40 -05004380 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004381}
4382
Jamie Madillbc918e72018-03-08 09:47:21 -05004383Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004384{
Geoff Langa8cb2872018-03-09 16:09:40 -05004385 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004386}
4387
Jamie Madillbc918e72018-03-08 09:47:21 -05004388Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004389{
Geoff Langa8cb2872018-03-09 16:09:40 -05004390 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004391}
4392
Geoff Lang9bf86f02018-07-26 11:46:34 -04004393Error Context::syncStateForPathOperation()
4394{
4395 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4396
4397 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4398 ANGLE_TRY(syncDirtyBits());
4399
4400 return NoError();
4401}
4402
Jiajia Qin5451d532017-11-16 17:16:34 +08004403void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4404{
4405 UNIMPLEMENTED();
4406}
4407
Jamie Madillc20ab272016-06-09 07:20:46 -07004408void Context::activeTexture(GLenum texture)
4409{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004410 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004411}
4412
Jamie Madill876429b2017-04-20 15:46:24 -04004413void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004414{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004415 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004416}
4417
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004418void Context::blendEquation(GLenum mode)
4419{
4420 mGLState.setBlendEquation(mode, mode);
4421}
4422
Jamie Madillc20ab272016-06-09 07:20:46 -07004423void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4424{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004425 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004426}
4427
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004428void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4429{
4430 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4431}
4432
Jamie Madillc20ab272016-06-09 07:20:46 -07004433void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4434{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004435 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004436}
4437
Jamie Madill876429b2017-04-20 15:46:24 -04004438void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004439{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004440 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004441}
4442
Jamie Madill876429b2017-04-20 15:46:24 -04004443void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004444{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004445 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004446}
4447
4448void Context::clearStencil(GLint s)
4449{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004450 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004451}
4452
4453void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4454{
Geoff Lang92019432017-11-20 13:09:34 -05004455 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4456 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004457}
4458
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004459void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004460{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004461 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004462}
4463
4464void Context::depthFunc(GLenum func)
4465{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004466 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004467}
4468
4469void Context::depthMask(GLboolean flag)
4470{
Geoff Lang92019432017-11-20 13:09:34 -05004471 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004472}
4473
Jamie Madill876429b2017-04-20 15:46:24 -04004474void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004475{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004476 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004477}
4478
4479void Context::disable(GLenum cap)
4480{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004481 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004482 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004483}
4484
4485void Context::disableVertexAttribArray(GLuint index)
4486{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004487 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004488 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004489}
4490
4491void Context::enable(GLenum cap)
4492{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004493 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004494 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004495}
4496
4497void Context::enableVertexAttribArray(GLuint index)
4498{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004499 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004500 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004501}
4502
4503void Context::frontFace(GLenum mode)
4504{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004505 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004506}
4507
4508void Context::hint(GLenum target, GLenum mode)
4509{
4510 switch (target)
4511 {
4512 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004513 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004514 break;
4515
4516 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004517 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004518 break;
4519
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004520 case GL_PERSPECTIVE_CORRECTION_HINT:
4521 case GL_POINT_SMOOTH_HINT:
4522 case GL_LINE_SMOOTH_HINT:
4523 case GL_FOG_HINT:
4524 mGLState.gles1().setHint(target, mode);
4525 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004526 default:
4527 UNREACHABLE();
4528 return;
4529 }
4530}
4531
4532void Context::lineWidth(GLfloat width)
4533{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004534 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004535}
4536
4537void Context::pixelStorei(GLenum pname, GLint param)
4538{
4539 switch (pname)
4540 {
4541 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004542 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004543 break;
4544
4545 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004546 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004547 break;
4548
4549 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004550 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004551 break;
4552
4553 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004554 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004555 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004556 break;
4557
4558 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004559 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004560 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004561 break;
4562
4563 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004564 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004565 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004566 break;
4567
4568 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004569 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004570 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004571 break;
4572
4573 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004574 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004575 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004576 break;
4577
4578 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004579 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004580 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004581 break;
4582
4583 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004584 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004585 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004586 break;
4587
4588 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004589 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004590 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004591 break;
4592
4593 default:
4594 UNREACHABLE();
4595 return;
4596 }
4597}
4598
4599void Context::polygonOffset(GLfloat factor, GLfloat units)
4600{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004601 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004602}
4603
Jamie Madill876429b2017-04-20 15:46:24 -04004604void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004605{
Geoff Lang92019432017-11-20 13:09:34 -05004606 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004607}
4608
Jiawei Shaodb342272017-09-27 10:21:45 +08004609void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4610{
4611 mGLState.setSampleMaskParams(maskNumber, mask);
4612}
4613
Jamie Madillc20ab272016-06-09 07:20:46 -07004614void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4615{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004616 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004617}
4618
4619void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4620{
4621 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4622 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004623 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004624 }
4625
4626 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4627 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004628 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004629 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004630
4631 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004632}
4633
4634void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4635{
4636 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4637 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004638 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004639 }
4640
4641 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4642 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004643 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004644 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004645
4646 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004647}
4648
4649void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4650{
4651 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4652 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004653 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004654 }
4655
4656 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4657 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004658 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004659 }
4660}
4661
4662void Context::vertexAttrib1f(GLuint index, GLfloat x)
4663{
4664 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004665 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004666 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004667}
4668
4669void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4670{
4671 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004672 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004673 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004674}
4675
4676void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4677{
4678 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004679 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004680 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004681}
4682
4683void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4684{
4685 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004686 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004687 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004688}
4689
4690void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4691{
4692 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004693 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004694 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004695}
4696
4697void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4698{
4699 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004700 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004701 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004702}
4703
4704void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4705{
4706 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004707 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004708 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004709}
4710
4711void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4712{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004713 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004714 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004715}
4716
4717void Context::vertexAttribPointer(GLuint index,
4718 GLint size,
4719 GLenum type,
4720 GLboolean normalized,
4721 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004722 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004723{
Corentin Wallez336129f2017-10-17 15:55:40 -04004724 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004725 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004726 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004727}
4728
Shao80957d92017-02-20 21:25:59 +08004729void Context::vertexAttribFormat(GLuint attribIndex,
4730 GLint size,
4731 GLenum type,
4732 GLboolean normalized,
4733 GLuint relativeOffset)
4734{
Geoff Lang92019432017-11-20 13:09:34 -05004735 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004736 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004737 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004738}
4739
4740void Context::vertexAttribIFormat(GLuint attribIndex,
4741 GLint size,
4742 GLenum type,
4743 GLuint relativeOffset)
4744{
4745 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004746 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004747}
4748
4749void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4750{
Shaodde78e82017-05-22 14:13:27 +08004751 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004752 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004753}
4754
Jiajia Qin5451d532017-11-16 17:16:34 +08004755void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004756{
4757 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004758 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004759}
4760
Jamie Madillc20ab272016-06-09 07:20:46 -07004761void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4762{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004763 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004764}
4765
4766void Context::vertexAttribIPointer(GLuint index,
4767 GLint size,
4768 GLenum type,
4769 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004770 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004771{
Corentin Wallez336129f2017-10-17 15:55:40 -04004772 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4773 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004774 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004775}
4776
4777void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4778{
4779 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004780 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004781 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004782}
4783
4784void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4785{
4786 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004787 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004788 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004789}
4790
4791void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4792{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004793 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004794 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004795}
4796
4797void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4798{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004799 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004800 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004801}
4802
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004803void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4804{
4805 const VertexAttribCurrentValueData &currentValues =
4806 getGLState().getVertexAttribCurrentValue(index);
4807 const VertexArray *vao = getGLState().getVertexArray();
4808 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4809 currentValues, pname, params);
4810}
4811
Brandon Jones59770802018-04-02 13:18:42 -07004812void Context::getVertexAttribivRobust(GLuint index,
4813 GLenum pname,
4814 GLsizei bufSize,
4815 GLsizei *length,
4816 GLint *params)
4817{
4818 getVertexAttribiv(index, pname, params);
4819}
4820
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004821void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4822{
4823 const VertexAttribCurrentValueData &currentValues =
4824 getGLState().getVertexAttribCurrentValue(index);
4825 const VertexArray *vao = getGLState().getVertexArray();
4826 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4827 currentValues, pname, params);
4828}
4829
Brandon Jones59770802018-04-02 13:18:42 -07004830void Context::getVertexAttribfvRobust(GLuint index,
4831 GLenum pname,
4832 GLsizei bufSize,
4833 GLsizei *length,
4834 GLfloat *params)
4835{
4836 getVertexAttribfv(index, pname, params);
4837}
4838
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004839void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4840{
4841 const VertexAttribCurrentValueData &currentValues =
4842 getGLState().getVertexAttribCurrentValue(index);
4843 const VertexArray *vao = getGLState().getVertexArray();
4844 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4845 currentValues, pname, params);
4846}
4847
Brandon Jones59770802018-04-02 13:18:42 -07004848void Context::getVertexAttribIivRobust(GLuint index,
4849 GLenum pname,
4850 GLsizei bufSize,
4851 GLsizei *length,
4852 GLint *params)
4853{
4854 getVertexAttribIiv(index, pname, params);
4855}
4856
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004857void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4858{
4859 const VertexAttribCurrentValueData &currentValues =
4860 getGLState().getVertexAttribCurrentValue(index);
4861 const VertexArray *vao = getGLState().getVertexArray();
4862 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4863 currentValues, pname, params);
4864}
4865
Brandon Jones59770802018-04-02 13:18:42 -07004866void Context::getVertexAttribIuivRobust(GLuint index,
4867 GLenum pname,
4868 GLsizei bufSize,
4869 GLsizei *length,
4870 GLuint *params)
4871{
4872 getVertexAttribIuiv(index, pname, params);
4873}
4874
Jamie Madill876429b2017-04-20 15:46:24 -04004875void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004876{
4877 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4878 QueryVertexAttribPointerv(attrib, pname, pointer);
4879}
4880
Brandon Jones59770802018-04-02 13:18:42 -07004881void Context::getVertexAttribPointervRobust(GLuint index,
4882 GLenum pname,
4883 GLsizei bufSize,
4884 GLsizei *length,
4885 void **pointer)
4886{
4887 getVertexAttribPointerv(index, pname, pointer);
4888}
4889
Jamie Madillc20ab272016-06-09 07:20:46 -07004890void Context::debugMessageControl(GLenum source,
4891 GLenum type,
4892 GLenum severity,
4893 GLsizei count,
4894 const GLuint *ids,
4895 GLboolean enabled)
4896{
4897 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004898 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004899 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004900}
4901
4902void Context::debugMessageInsert(GLenum source,
4903 GLenum type,
4904 GLuint id,
4905 GLenum severity,
4906 GLsizei length,
4907 const GLchar *buf)
4908{
4909 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004910 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004911}
4912
4913void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4914{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004915 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004916}
4917
4918GLuint Context::getDebugMessageLog(GLuint count,
4919 GLsizei bufSize,
4920 GLenum *sources,
4921 GLenum *types,
4922 GLuint *ids,
4923 GLenum *severities,
4924 GLsizei *lengths,
4925 GLchar *messageLog)
4926{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004927 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4928 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004929}
4930
4931void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4932{
4933 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004934 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004935 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004936}
4937
4938void Context::popDebugGroup()
4939{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004940 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004941 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004942}
4943
Corentin Wallez336129f2017-10-17 15:55:40 -04004944void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004945{
4946 Buffer *buffer = mGLState.getTargetBuffer(target);
4947 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004948 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004949}
4950
Corentin Wallez336129f2017-10-17 15:55:40 -04004951void Context::bufferSubData(BufferBinding target,
4952 GLintptr offset,
4953 GLsizeiptr size,
4954 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004955{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06004956 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04004957 {
4958 return;
4959 }
4960
4961 Buffer *buffer = mGLState.getTargetBuffer(target);
4962 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004963 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004964}
4965
Jamie Madillef300b12016-10-07 15:12:09 -04004966void Context::attachShader(GLuint program, GLuint shader)
4967{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004968 Program *programObject = mState.mShaderPrograms->getProgram(program);
4969 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004970 ASSERT(programObject && shaderObject);
4971 programObject->attachShader(shaderObject);
4972}
4973
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004974const Workarounds &Context::getWorkarounds() const
4975{
4976 return mWorkarounds;
4977}
4978
Corentin Wallez336129f2017-10-17 15:55:40 -04004979void Context::copyBufferSubData(BufferBinding readTarget,
4980 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004981 GLintptr readOffset,
4982 GLintptr writeOffset,
4983 GLsizeiptr size)
4984{
4985 // if size is zero, the copy is a successful no-op
4986 if (size == 0)
4987 {
4988 return;
4989 }
4990
4991 // TODO(jmadill): cache these.
4992 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4993 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4994
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004995 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004996}
4997
Jamie Madill01a80ee2016-11-07 12:06:18 -05004998void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4999{
5000 Program *programObject = getProgram(program);
5001 // TODO(jmadill): Re-use this from the validation if possible.
5002 ASSERT(programObject);
5003 programObject->bindAttributeLocation(index, name);
5004}
5005
Corentin Wallez336129f2017-10-17 15:55:40 -04005006void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005007{
Corentin Wallez336129f2017-10-17 15:55:40 -04005008 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5009 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04005010 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005011}
5012
Corentin Wallez336129f2017-10-17 15:55:40 -04005013void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005014{
5015 bindBufferRange(target, index, buffer, 0, 0);
5016}
5017
Corentin Wallez336129f2017-10-17 15:55:40 -04005018void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005019 GLuint index,
5020 GLuint buffer,
5021 GLintptr offset,
5022 GLsizeiptr size)
5023{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005024 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5025 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
5026 if (target == BufferBinding::Uniform)
5027 {
5028 mUniformBufferObserverBindings[index].bind(object ? object->getImplementation() : nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04005029 mStateCache.onUniformBufferStateChange(this);
5030 }
5031 else
5032 {
5033 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005034 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005035}
5036
Jamie Madill01a80ee2016-11-07 12:06:18 -05005037void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5038{
5039 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5040 {
5041 bindReadFramebuffer(framebuffer);
5042 }
5043
5044 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5045 {
5046 bindDrawFramebuffer(framebuffer);
5047 }
5048}
5049
5050void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5051{
5052 ASSERT(target == GL_RENDERBUFFER);
5053 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005054 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005055 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005056}
5057
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005058void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005059 GLsizei samples,
5060 GLenum internalformat,
5061 GLsizei width,
5062 GLsizei height,
5063 GLboolean fixedsamplelocations)
5064{
5065 Extents size(width, height, 1);
5066 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005067 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5068 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005069}
5070
Olli Etuaho89664842018-08-24 14:45:36 +03005071void Context::texStorage3DMultisample(TextureType target,
5072 GLsizei samples,
5073 GLenum internalformat,
5074 GLsizei width,
5075 GLsizei height,
5076 GLsizei depth,
5077 GLboolean fixedsamplelocations)
5078{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005079 Extents size(width, height, depth);
5080 Texture *texture = getTargetTexture(target);
5081 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5082 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005083}
5084
JiangYizhoubddc46b2016-12-09 09:50:51 +08005085void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5086{
JiangYizhou5b03f472017-01-09 10:22:53 +08005087 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5088 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005089 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005090 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005091
5092 switch (pname)
5093 {
5094 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04005095 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005096 break;
5097 default:
5098 UNREACHABLE();
5099 }
5100}
5101
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005102void Context::getMultisamplefvRobust(GLenum pname,
5103 GLuint index,
5104 GLsizei bufSize,
5105 GLsizei *length,
5106 GLfloat *val)
5107{
5108 UNIMPLEMENTED();
5109}
5110
Jamie Madille8fb6402017-02-14 17:56:40 -05005111void Context::renderbufferStorage(GLenum target,
5112 GLenum internalformat,
5113 GLsizei width,
5114 GLsizei height)
5115{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005116 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5117 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5118
Jamie Madille8fb6402017-02-14 17:56:40 -05005119 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04005120 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005121}
5122
5123void Context::renderbufferStorageMultisample(GLenum target,
5124 GLsizei samples,
5125 GLenum internalformat,
5126 GLsizei width,
5127 GLsizei height)
5128{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005129 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5130 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005131
5132 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005133 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005134 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005135}
5136
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005137void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5138{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005139 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04005140 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005141}
5142
JiangYizhoue18e6392017-02-20 10:32:23 +08005143void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5144{
5145 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5146 QueryFramebufferParameteriv(framebuffer, pname, params);
5147}
5148
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005149void Context::getFramebufferParameterivRobust(GLenum target,
5150 GLenum pname,
5151 GLsizei bufSize,
5152 GLsizei *length,
5153 GLint *params)
5154{
5155 UNIMPLEMENTED();
5156}
5157
Jiajia Qin5451d532017-11-16 17:16:34 +08005158void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005159{
5160 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005161 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005162}
5163
Jamie Madilldec86232018-07-11 09:01:18 -04005164bool Context::getScratchBuffer(size_t requstedSizeBytes,
5165 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005166{
Jamie Madilldec86232018-07-11 09:01:18 -04005167 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005168}
5169
Jamie Madilldec86232018-07-11 09:01:18 -04005170bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5171 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005172{
Jamie Madilldec86232018-07-11 09:01:18 -04005173 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005174}
5175
Xinghua Cao10a4d432017-11-28 14:46:26 +08005176Error Context::prepareForDispatch()
5177{
Geoff Langa8cb2872018-03-09 16:09:40 -05005178 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005179
5180 if (isRobustResourceInitEnabled())
5181 {
5182 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5183 }
5184
5185 return NoError();
5186}
5187
Xinghua Cao2b396592017-03-29 15:36:04 +08005188void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5189{
5190 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5191 {
5192 return;
5193 }
5194
Xinghua Cao10a4d432017-11-28 14:46:26 +08005195 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005196 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005197}
5198
Jiajia Qin5451d532017-11-16 17:16:34 +08005199void Context::dispatchComputeIndirect(GLintptr indirect)
5200{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005201 ANGLE_CONTEXT_TRY(prepareForDispatch());
5202 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005203}
5204
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005205void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005206 GLsizei levels,
5207 GLenum internalFormat,
5208 GLsizei width,
5209 GLsizei height)
5210{
5211 Extents size(width, height, 1);
5212 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005213 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005214}
5215
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005216void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005217 GLsizei levels,
5218 GLenum internalFormat,
5219 GLsizei width,
5220 GLsizei height,
5221 GLsizei depth)
5222{
5223 Extents size(width, height, depth);
5224 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005225 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005226}
5227
Jiajia Qin5451d532017-11-16 17:16:34 +08005228void Context::memoryBarrier(GLbitfield barriers)
5229{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005230 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005231}
5232
5233void Context::memoryBarrierByRegion(GLbitfield barriers)
5234{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005235 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005236}
5237
Jamie Madillc1d770e2017-04-13 17:31:24 -04005238GLenum Context::checkFramebufferStatus(GLenum target)
5239{
5240 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5241 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005242 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005243}
5244
5245void Context::compileShader(GLuint shader)
5246{
5247 Shader *shaderObject = GetValidShader(this, shader);
5248 if (!shaderObject)
5249 {
5250 return;
5251 }
5252 shaderObject->compile(this);
5253}
5254
5255void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5256{
5257 for (int i = 0; i < n; i++)
5258 {
5259 deleteBuffer(buffers[i]);
5260 }
5261}
5262
5263void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5264{
5265 for (int i = 0; i < n; i++)
5266 {
5267 if (framebuffers[i] != 0)
5268 {
5269 deleteFramebuffer(framebuffers[i]);
5270 }
5271 }
5272}
5273
5274void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5275{
5276 for (int i = 0; i < n; i++)
5277 {
5278 deleteRenderbuffer(renderbuffers[i]);
5279 }
5280}
5281
5282void Context::deleteTextures(GLsizei n, const GLuint *textures)
5283{
5284 for (int i = 0; i < n; i++)
5285 {
5286 if (textures[i] != 0)
5287 {
5288 deleteTexture(textures[i]);
5289 }
5290 }
5291}
5292
5293void Context::detachShader(GLuint program, GLuint shader)
5294{
5295 Program *programObject = getProgram(program);
5296 ASSERT(programObject);
5297
5298 Shader *shaderObject = getShader(shader);
5299 ASSERT(shaderObject);
5300
5301 programObject->detachShader(this, shaderObject);
5302}
5303
5304void Context::genBuffers(GLsizei n, GLuint *buffers)
5305{
5306 for (int i = 0; i < n; i++)
5307 {
5308 buffers[i] = createBuffer();
5309 }
5310}
5311
5312void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5313{
5314 for (int i = 0; i < n; i++)
5315 {
5316 framebuffers[i] = createFramebuffer();
5317 }
5318}
5319
5320void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5321{
5322 for (int i = 0; i < n; i++)
5323 {
5324 renderbuffers[i] = createRenderbuffer();
5325 }
5326}
5327
5328void Context::genTextures(GLsizei n, GLuint *textures)
5329{
5330 for (int i = 0; i < n; i++)
5331 {
5332 textures[i] = createTexture();
5333 }
5334}
5335
5336void Context::getActiveAttrib(GLuint program,
5337 GLuint index,
5338 GLsizei bufsize,
5339 GLsizei *length,
5340 GLint *size,
5341 GLenum *type,
5342 GLchar *name)
5343{
5344 Program *programObject = getProgram(program);
5345 ASSERT(programObject);
5346 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5347}
5348
5349void Context::getActiveUniform(GLuint program,
5350 GLuint index,
5351 GLsizei bufsize,
5352 GLsizei *length,
5353 GLint *size,
5354 GLenum *type,
5355 GLchar *name)
5356{
5357 Program *programObject = getProgram(program);
5358 ASSERT(programObject);
5359 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5360}
5361
5362void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5363{
5364 Program *programObject = getProgram(program);
5365 ASSERT(programObject);
5366 programObject->getAttachedShaders(maxcount, count, shaders);
5367}
5368
5369GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5370{
5371 Program *programObject = getProgram(program);
5372 ASSERT(programObject);
5373 return programObject->getAttributeLocation(name);
5374}
5375
5376void Context::getBooleanv(GLenum pname, GLboolean *params)
5377{
5378 GLenum nativeType;
5379 unsigned int numParams = 0;
5380 getQueryParameterInfo(pname, &nativeType, &numParams);
5381
5382 if (nativeType == GL_BOOL)
5383 {
5384 getBooleanvImpl(pname, params);
5385 }
5386 else
5387 {
5388 CastStateValues(this, nativeType, pname, numParams, params);
5389 }
5390}
5391
Brandon Jones59770802018-04-02 13:18:42 -07005392void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5393{
5394 getBooleanv(pname, params);
5395}
5396
Jamie Madillc1d770e2017-04-13 17:31:24 -04005397void Context::getFloatv(GLenum pname, GLfloat *params)
5398{
5399 GLenum nativeType;
5400 unsigned int numParams = 0;
5401 getQueryParameterInfo(pname, &nativeType, &numParams);
5402
5403 if (nativeType == GL_FLOAT)
5404 {
5405 getFloatvImpl(pname, params);
5406 }
5407 else
5408 {
5409 CastStateValues(this, nativeType, pname, numParams, params);
5410 }
5411}
5412
Brandon Jones59770802018-04-02 13:18:42 -07005413void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5414{
5415 getFloatv(pname, params);
5416}
5417
Jamie Madillc1d770e2017-04-13 17:31:24 -04005418void Context::getIntegerv(GLenum pname, GLint *params)
5419{
5420 GLenum nativeType;
5421 unsigned int numParams = 0;
5422 getQueryParameterInfo(pname, &nativeType, &numParams);
5423
5424 if (nativeType == GL_INT)
5425 {
5426 getIntegervImpl(pname, params);
5427 }
5428 else
5429 {
5430 CastStateValues(this, nativeType, pname, numParams, params);
5431 }
5432}
5433
Brandon Jones59770802018-04-02 13:18:42 -07005434void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5435{
5436 getIntegerv(pname, data);
5437}
5438
Jamie Madillc1d770e2017-04-13 17:31:24 -04005439void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5440{
5441 Program *programObject = getProgram(program);
5442 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005443 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005444}
5445
Brandon Jones59770802018-04-02 13:18:42 -07005446void Context::getProgramivRobust(GLuint program,
5447 GLenum pname,
5448 GLsizei bufSize,
5449 GLsizei *length,
5450 GLint *params)
5451{
5452 getProgramiv(program, pname, params);
5453}
5454
Jiajia Qin5451d532017-11-16 17:16:34 +08005455void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5456{
5457 UNIMPLEMENTED();
5458}
5459
Jamie Madillbe849e42017-05-02 15:49:00 -04005460void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005461{
5462 Program *programObject = getProgram(program);
5463 ASSERT(programObject);
5464 programObject->getInfoLog(bufsize, length, infolog);
5465}
5466
Jiajia Qin5451d532017-11-16 17:16:34 +08005467void Context::getProgramPipelineInfoLog(GLuint pipeline,
5468 GLsizei bufSize,
5469 GLsizei *length,
5470 GLchar *infoLog)
5471{
5472 UNIMPLEMENTED();
5473}
5474
Jamie Madillc1d770e2017-04-13 17:31:24 -04005475void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5476{
5477 Shader *shaderObject = getShader(shader);
5478 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005479 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005480}
5481
Brandon Jones59770802018-04-02 13:18:42 -07005482void Context::getShaderivRobust(GLuint shader,
5483 GLenum pname,
5484 GLsizei bufSize,
5485 GLsizei *length,
5486 GLint *params)
5487{
5488 getShaderiv(shader, pname, params);
5489}
5490
Jamie Madillc1d770e2017-04-13 17:31:24 -04005491void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5492{
5493 Shader *shaderObject = getShader(shader);
5494 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005495 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005496}
5497
5498void Context::getShaderPrecisionFormat(GLenum shadertype,
5499 GLenum precisiontype,
5500 GLint *range,
5501 GLint *precision)
5502{
5503 // TODO(jmadill): Compute shaders.
5504
5505 switch (shadertype)
5506 {
5507 case GL_VERTEX_SHADER:
5508 switch (precisiontype)
5509 {
5510 case GL_LOW_FLOAT:
5511 mCaps.vertexLowpFloat.get(range, precision);
5512 break;
5513 case GL_MEDIUM_FLOAT:
5514 mCaps.vertexMediumpFloat.get(range, precision);
5515 break;
5516 case GL_HIGH_FLOAT:
5517 mCaps.vertexHighpFloat.get(range, precision);
5518 break;
5519
5520 case GL_LOW_INT:
5521 mCaps.vertexLowpInt.get(range, precision);
5522 break;
5523 case GL_MEDIUM_INT:
5524 mCaps.vertexMediumpInt.get(range, precision);
5525 break;
5526 case GL_HIGH_INT:
5527 mCaps.vertexHighpInt.get(range, precision);
5528 break;
5529
5530 default:
5531 UNREACHABLE();
5532 return;
5533 }
5534 break;
5535
5536 case GL_FRAGMENT_SHADER:
5537 switch (precisiontype)
5538 {
5539 case GL_LOW_FLOAT:
5540 mCaps.fragmentLowpFloat.get(range, precision);
5541 break;
5542 case GL_MEDIUM_FLOAT:
5543 mCaps.fragmentMediumpFloat.get(range, precision);
5544 break;
5545 case GL_HIGH_FLOAT:
5546 mCaps.fragmentHighpFloat.get(range, precision);
5547 break;
5548
5549 case GL_LOW_INT:
5550 mCaps.fragmentLowpInt.get(range, precision);
5551 break;
5552 case GL_MEDIUM_INT:
5553 mCaps.fragmentMediumpInt.get(range, precision);
5554 break;
5555 case GL_HIGH_INT:
5556 mCaps.fragmentHighpInt.get(range, precision);
5557 break;
5558
5559 default:
5560 UNREACHABLE();
5561 return;
5562 }
5563 break;
5564
5565 default:
5566 UNREACHABLE();
5567 return;
5568 }
5569}
5570
5571void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5572{
5573 Shader *shaderObject = getShader(shader);
5574 ASSERT(shaderObject);
5575 shaderObject->getSource(bufsize, length, source);
5576}
5577
5578void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5579{
5580 Program *programObject = getProgram(program);
5581 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005582 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005583}
5584
Brandon Jones59770802018-04-02 13:18:42 -07005585void Context::getUniformfvRobust(GLuint program,
5586 GLint location,
5587 GLsizei bufSize,
5588 GLsizei *length,
5589 GLfloat *params)
5590{
5591 getUniformfv(program, location, params);
5592}
5593
Jamie Madillc1d770e2017-04-13 17:31:24 -04005594void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5595{
5596 Program *programObject = getProgram(program);
5597 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005598 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005599}
5600
Brandon Jones59770802018-04-02 13:18:42 -07005601void Context::getUniformivRobust(GLuint program,
5602 GLint location,
5603 GLsizei bufSize,
5604 GLsizei *length,
5605 GLint *params)
5606{
5607 getUniformiv(program, location, params);
5608}
5609
Jamie Madillc1d770e2017-04-13 17:31:24 -04005610GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5611{
5612 Program *programObject = getProgram(program);
5613 ASSERT(programObject);
5614 return programObject->getUniformLocation(name);
5615}
5616
5617GLboolean Context::isBuffer(GLuint buffer)
5618{
5619 if (buffer == 0)
5620 {
5621 return GL_FALSE;
5622 }
5623
5624 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5625}
5626
5627GLboolean Context::isEnabled(GLenum cap)
5628{
5629 return mGLState.getEnableFeature(cap);
5630}
5631
5632GLboolean Context::isFramebuffer(GLuint framebuffer)
5633{
5634 if (framebuffer == 0)
5635 {
5636 return GL_FALSE;
5637 }
5638
5639 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5640}
5641
5642GLboolean Context::isProgram(GLuint program)
5643{
5644 if (program == 0)
5645 {
5646 return GL_FALSE;
5647 }
5648
5649 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5650}
5651
5652GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5653{
5654 if (renderbuffer == 0)
5655 {
5656 return GL_FALSE;
5657 }
5658
5659 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5660}
5661
5662GLboolean Context::isShader(GLuint shader)
5663{
5664 if (shader == 0)
5665 {
5666 return GL_FALSE;
5667 }
5668
5669 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5670}
5671
5672GLboolean Context::isTexture(GLuint texture)
5673{
5674 if (texture == 0)
5675 {
5676 return GL_FALSE;
5677 }
5678
5679 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5680}
5681
5682void Context::linkProgram(GLuint program)
5683{
5684 Program *programObject = getProgram(program);
5685 ASSERT(programObject);
5686 handleError(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005687
5688 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5689 // don't need to worry that:
5690 // 1. Draw calls after link use the new executable code or the old one depending on the link
5691 // result.
5692 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5693 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5694 // ProgramD3D.
5695 if (programObject->isInUse())
5696 {
5697 // isLinked() which forces to resolve linking, will be called.
5698 mGLState.onProgramExecutableChange(programObject);
5699 mStateCache.onProgramExecutableChange(this);
5700 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005701}
5702
5703void Context::releaseShaderCompiler()
5704{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005705 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005706}
5707
5708void Context::shaderBinary(GLsizei n,
5709 const GLuint *shaders,
5710 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005711 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005712 GLsizei length)
5713{
5714 // No binary shader formats are supported.
5715 UNIMPLEMENTED();
5716}
5717
5718void Context::shaderSource(GLuint shader,
5719 GLsizei count,
5720 const GLchar *const *string,
5721 const GLint *length)
5722{
5723 Shader *shaderObject = getShader(shader);
5724 ASSERT(shaderObject);
5725 shaderObject->setSource(count, string, length);
5726}
5727
5728void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5729{
5730 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5731}
5732
5733void Context::stencilMask(GLuint mask)
5734{
5735 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5736}
5737
5738void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5739{
5740 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5741}
5742
5743void Context::uniform1f(GLint location, GLfloat x)
5744{
5745 Program *program = mGLState.getProgram();
5746 program->setUniform1fv(location, 1, &x);
5747}
5748
5749void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5750{
5751 Program *program = mGLState.getProgram();
5752 program->setUniform1fv(location, count, v);
5753}
5754
Jamie Madill7e4eff12018-08-08 15:49:26 -04005755void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005756{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005757 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04005758 {
5759 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04005760 mStateCache.onActiveTextureChange(this);
Jamie Madill81c2e252017-09-09 23:32:46 -04005761 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005762}
5763
Jamie Madill7e4eff12018-08-08 15:49:26 -04005764void Context::uniform1i(GLint location, GLint x)
5765{
5766 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
5767}
5768
Jamie Madillc1d770e2017-04-13 17:31:24 -04005769void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5770{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005771 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005772}
5773
5774void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5775{
5776 GLfloat xy[2] = {x, y};
5777 Program *program = mGLState.getProgram();
5778 program->setUniform2fv(location, 1, xy);
5779}
5780
5781void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5782{
5783 Program *program = mGLState.getProgram();
5784 program->setUniform2fv(location, count, v);
5785}
5786
5787void Context::uniform2i(GLint location, GLint x, GLint y)
5788{
5789 GLint xy[2] = {x, y};
5790 Program *program = mGLState.getProgram();
5791 program->setUniform2iv(location, 1, xy);
5792}
5793
5794void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5795{
5796 Program *program = mGLState.getProgram();
5797 program->setUniform2iv(location, count, v);
5798}
5799
5800void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5801{
5802 GLfloat xyz[3] = {x, y, z};
5803 Program *program = mGLState.getProgram();
5804 program->setUniform3fv(location, 1, xyz);
5805}
5806
5807void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5808{
5809 Program *program = mGLState.getProgram();
5810 program->setUniform3fv(location, count, v);
5811}
5812
5813void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5814{
5815 GLint xyz[3] = {x, y, z};
5816 Program *program = mGLState.getProgram();
5817 program->setUniform3iv(location, 1, xyz);
5818}
5819
5820void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5821{
5822 Program *program = mGLState.getProgram();
5823 program->setUniform3iv(location, count, v);
5824}
5825
5826void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5827{
5828 GLfloat xyzw[4] = {x, y, z, w};
5829 Program *program = mGLState.getProgram();
5830 program->setUniform4fv(location, 1, xyzw);
5831}
5832
5833void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5834{
5835 Program *program = mGLState.getProgram();
5836 program->setUniform4fv(location, count, v);
5837}
5838
5839void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5840{
5841 GLint xyzw[4] = {x, y, z, w};
5842 Program *program = mGLState.getProgram();
5843 program->setUniform4iv(location, 1, xyzw);
5844}
5845
5846void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5847{
5848 Program *program = mGLState.getProgram();
5849 program->setUniform4iv(location, count, v);
5850}
5851
5852void Context::uniformMatrix2fv(GLint location,
5853 GLsizei count,
5854 GLboolean transpose,
5855 const GLfloat *value)
5856{
5857 Program *program = mGLState.getProgram();
5858 program->setUniformMatrix2fv(location, count, transpose, value);
5859}
5860
5861void Context::uniformMatrix3fv(GLint location,
5862 GLsizei count,
5863 GLboolean transpose,
5864 const GLfloat *value)
5865{
5866 Program *program = mGLState.getProgram();
5867 program->setUniformMatrix3fv(location, count, transpose, value);
5868}
5869
5870void Context::uniformMatrix4fv(GLint location,
5871 GLsizei count,
5872 GLboolean transpose,
5873 const GLfloat *value)
5874{
5875 Program *program = mGLState.getProgram();
5876 program->setUniformMatrix4fv(location, count, transpose, value);
5877}
5878
5879void Context::validateProgram(GLuint program)
5880{
5881 Program *programObject = getProgram(program);
5882 ASSERT(programObject);
5883 programObject->validate(mCaps);
5884}
5885
Jiajia Qin5451d532017-11-16 17:16:34 +08005886void Context::validateProgramPipeline(GLuint pipeline)
5887{
5888 UNIMPLEMENTED();
5889}
5890
Jamie Madilld04908b2017-06-09 14:15:35 -04005891void Context::getProgramBinary(GLuint program,
5892 GLsizei bufSize,
5893 GLsizei *length,
5894 GLenum *binaryFormat,
5895 void *binary)
5896{
5897 Program *programObject = getProgram(program);
5898 ASSERT(programObject != nullptr);
5899
5900 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5901}
5902
5903void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5904{
5905 Program *programObject = getProgram(program);
5906 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005907
Jamie Madilld04908b2017-06-09 14:15:35 -04005908 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madillc43cdad2018-08-08 15:49:25 -04005909 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04005910 if (programObject->isInUse())
5911 {
5912 mGLState.setObjectDirty(GL_PROGRAM);
5913 }
Jamie Madilld04908b2017-06-09 14:15:35 -04005914}
5915
Jamie Madillff325f12017-08-26 15:06:05 -04005916void Context::uniform1ui(GLint location, GLuint v0)
5917{
5918 Program *program = mGLState.getProgram();
5919 program->setUniform1uiv(location, 1, &v0);
5920}
5921
5922void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5923{
5924 Program *program = mGLState.getProgram();
5925 const GLuint xy[] = {v0, v1};
5926 program->setUniform2uiv(location, 1, xy);
5927}
5928
5929void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5930{
5931 Program *program = mGLState.getProgram();
5932 const GLuint xyz[] = {v0, v1, v2};
5933 program->setUniform3uiv(location, 1, xyz);
5934}
5935
5936void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5937{
5938 Program *program = mGLState.getProgram();
5939 const GLuint xyzw[] = {v0, v1, v2, v3};
5940 program->setUniform4uiv(location, 1, xyzw);
5941}
5942
5943void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5944{
5945 Program *program = mGLState.getProgram();
5946 program->setUniform1uiv(location, count, value);
5947}
5948void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5949{
5950 Program *program = mGLState.getProgram();
5951 program->setUniform2uiv(location, count, value);
5952}
5953
5954void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5955{
5956 Program *program = mGLState.getProgram();
5957 program->setUniform3uiv(location, count, value);
5958}
5959
5960void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5961{
5962 Program *program = mGLState.getProgram();
5963 program->setUniform4uiv(location, count, value);
5964}
5965
Jamie Madillf0e04492017-08-26 15:28:42 -04005966void Context::genQueries(GLsizei n, GLuint *ids)
5967{
5968 for (GLsizei i = 0; i < n; i++)
5969 {
5970 GLuint handle = mQueryHandleAllocator.allocate();
5971 mQueryMap.assign(handle, nullptr);
5972 ids[i] = handle;
5973 }
5974}
5975
5976void Context::deleteQueries(GLsizei n, const GLuint *ids)
5977{
5978 for (int i = 0; i < n; i++)
5979 {
5980 GLuint query = ids[i];
5981
5982 Query *queryObject = nullptr;
5983 if (mQueryMap.erase(query, &queryObject))
5984 {
5985 mQueryHandleAllocator.release(query);
5986 if (queryObject)
5987 {
5988 queryObject->release(this);
5989 }
5990 }
5991 }
5992}
5993
5994GLboolean Context::isQuery(GLuint id)
5995{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005996 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005997}
5998
Jamie Madillc8c95812017-08-26 18:40:09 -04005999void Context::uniformMatrix2x3fv(GLint location,
6000 GLsizei count,
6001 GLboolean transpose,
6002 const GLfloat *value)
6003{
6004 Program *program = mGLState.getProgram();
6005 program->setUniformMatrix2x3fv(location, count, transpose, value);
6006}
6007
6008void Context::uniformMatrix3x2fv(GLint location,
6009 GLsizei count,
6010 GLboolean transpose,
6011 const GLfloat *value)
6012{
6013 Program *program = mGLState.getProgram();
6014 program->setUniformMatrix3x2fv(location, count, transpose, value);
6015}
6016
6017void Context::uniformMatrix2x4fv(GLint location,
6018 GLsizei count,
6019 GLboolean transpose,
6020 const GLfloat *value)
6021{
6022 Program *program = mGLState.getProgram();
6023 program->setUniformMatrix2x4fv(location, count, transpose, value);
6024}
6025
6026void Context::uniformMatrix4x2fv(GLint location,
6027 GLsizei count,
6028 GLboolean transpose,
6029 const GLfloat *value)
6030{
6031 Program *program = mGLState.getProgram();
6032 program->setUniformMatrix4x2fv(location, count, transpose, value);
6033}
6034
6035void Context::uniformMatrix3x4fv(GLint location,
6036 GLsizei count,
6037 GLboolean transpose,
6038 const GLfloat *value)
6039{
6040 Program *program = mGLState.getProgram();
6041 program->setUniformMatrix3x4fv(location, count, transpose, value);
6042}
6043
6044void Context::uniformMatrix4x3fv(GLint location,
6045 GLsizei count,
6046 GLboolean transpose,
6047 const GLfloat *value)
6048{
6049 Program *program = mGLState.getProgram();
6050 program->setUniformMatrix4x3fv(location, count, transpose, value);
6051}
6052
Jamie Madilld7576732017-08-26 18:49:50 -04006053void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6054{
6055 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6056 {
6057 GLuint vertexArray = arrays[arrayIndex];
6058
6059 if (arrays[arrayIndex] != 0)
6060 {
6061 VertexArray *vertexArrayObject = nullptr;
6062 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6063 {
6064 if (vertexArrayObject != nullptr)
6065 {
6066 detachVertexArray(vertexArray);
6067 vertexArrayObject->onDestroy(this);
6068 }
6069
6070 mVertexArrayHandleAllocator.release(vertexArray);
6071 }
6072 }
6073 }
6074}
6075
6076void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6077{
6078 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6079 {
6080 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6081 mVertexArrayMap.assign(vertexArray, nullptr);
6082 arrays[arrayIndex] = vertexArray;
6083 }
6084}
6085
6086bool Context::isVertexArray(GLuint array)
6087{
6088 if (array == 0)
6089 {
6090 return GL_FALSE;
6091 }
6092
6093 VertexArray *vao = getVertexArray(array);
6094 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6095}
6096
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006097void Context::endTransformFeedback()
6098{
6099 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6100 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006101 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006102}
6103
6104void Context::transformFeedbackVaryings(GLuint program,
6105 GLsizei count,
6106 const GLchar *const *varyings,
6107 GLenum bufferMode)
6108{
6109 Program *programObject = getProgram(program);
6110 ASSERT(programObject);
6111 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6112}
6113
6114void Context::getTransformFeedbackVarying(GLuint program,
6115 GLuint index,
6116 GLsizei bufSize,
6117 GLsizei *length,
6118 GLsizei *size,
6119 GLenum *type,
6120 GLchar *name)
6121{
6122 Program *programObject = getProgram(program);
6123 ASSERT(programObject);
6124 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6125}
6126
6127void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6128{
6129 for (int i = 0; i < n; i++)
6130 {
6131 GLuint transformFeedback = ids[i];
6132 if (transformFeedback == 0)
6133 {
6134 continue;
6135 }
6136
6137 TransformFeedback *transformFeedbackObject = nullptr;
6138 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6139 {
6140 if (transformFeedbackObject != nullptr)
6141 {
6142 detachTransformFeedback(transformFeedback);
6143 transformFeedbackObject->release(this);
6144 }
6145
6146 mTransformFeedbackHandleAllocator.release(transformFeedback);
6147 }
6148 }
6149}
6150
6151void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6152{
6153 for (int i = 0; i < n; i++)
6154 {
6155 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6156 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6157 ids[i] = transformFeedback;
6158 }
6159}
6160
6161bool Context::isTransformFeedback(GLuint id)
6162{
6163 if (id == 0)
6164 {
6165 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6166 // returns FALSE
6167 return GL_FALSE;
6168 }
6169
6170 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6171 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6172}
6173
6174void Context::pauseTransformFeedback()
6175{
6176 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6177 transformFeedback->pause();
6178}
6179
6180void Context::resumeTransformFeedback()
6181{
6182 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6183 transformFeedback->resume();
6184}
6185
Jamie Madill12e957f2017-08-26 21:42:26 -04006186void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6187{
6188 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006189 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006190}
6191
Brandon Jones59770802018-04-02 13:18:42 -07006192void Context::getUniformuivRobust(GLuint program,
6193 GLint location,
6194 GLsizei bufSize,
6195 GLsizei *length,
6196 GLuint *params)
6197{
6198 getUniformuiv(program, location, params);
6199}
6200
Jamie Madill12e957f2017-08-26 21:42:26 -04006201GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6202{
6203 const Program *programObject = getProgram(program);
6204 return programObject->getFragDataLocation(name);
6205}
6206
6207void Context::getUniformIndices(GLuint program,
6208 GLsizei uniformCount,
6209 const GLchar *const *uniformNames,
6210 GLuint *uniformIndices)
6211{
6212 const Program *programObject = getProgram(program);
6213 if (!programObject->isLinked())
6214 {
6215 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6216 {
6217 uniformIndices[uniformId] = GL_INVALID_INDEX;
6218 }
6219 }
6220 else
6221 {
6222 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6223 {
6224 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6225 }
6226 }
6227}
6228
6229void Context::getActiveUniformsiv(GLuint program,
6230 GLsizei uniformCount,
6231 const GLuint *uniformIndices,
6232 GLenum pname,
6233 GLint *params)
6234{
6235 const Program *programObject = getProgram(program);
6236 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6237 {
6238 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006239 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006240 }
6241}
6242
6243GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6244{
6245 const Program *programObject = getProgram(program);
6246 return programObject->getUniformBlockIndex(uniformBlockName);
6247}
6248
6249void Context::getActiveUniformBlockiv(GLuint program,
6250 GLuint uniformBlockIndex,
6251 GLenum pname,
6252 GLint *params)
6253{
6254 const Program *programObject = getProgram(program);
6255 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6256}
6257
Brandon Jones59770802018-04-02 13:18:42 -07006258void Context::getActiveUniformBlockivRobust(GLuint program,
6259 GLuint uniformBlockIndex,
6260 GLenum pname,
6261 GLsizei bufSize,
6262 GLsizei *length,
6263 GLint *params)
6264{
6265 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6266}
6267
Jamie Madill12e957f2017-08-26 21:42:26 -04006268void Context::getActiveUniformBlockName(GLuint program,
6269 GLuint uniformBlockIndex,
6270 GLsizei bufSize,
6271 GLsizei *length,
6272 GLchar *uniformBlockName)
6273{
6274 const Program *programObject = getProgram(program);
6275 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6276}
6277
6278void Context::uniformBlockBinding(GLuint program,
6279 GLuint uniformBlockIndex,
6280 GLuint uniformBlockBinding)
6281{
6282 Program *programObject = getProgram(program);
6283 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006284
6285 if (programObject->isInUse())
6286 {
6287 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006288 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006289 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006290}
6291
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006292GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6293{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006294 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6295 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006296
Jamie Madill70b5bb02017-08-28 13:32:37 -04006297 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006298 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006299 if (error.isError())
6300 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006301 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006302 handleError(error);
6303 return nullptr;
6304 }
6305
Jamie Madill70b5bb02017-08-28 13:32:37 -04006306 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006307}
6308
6309GLboolean Context::isSync(GLsync sync)
6310{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006311 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006312}
6313
6314GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6315{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006316 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006317
6318 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006319 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006320 return result;
6321}
6322
6323void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6324{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006325 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006326 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006327}
6328
6329void Context::getInteger64v(GLenum pname, GLint64 *params)
6330{
6331 GLenum nativeType = GL_NONE;
6332 unsigned int numParams = 0;
6333 getQueryParameterInfo(pname, &nativeType, &numParams);
6334
6335 if (nativeType == GL_INT_64_ANGLEX)
6336 {
6337 getInteger64vImpl(pname, params);
6338 }
6339 else
6340 {
6341 CastStateValues(this, nativeType, pname, numParams, params);
6342 }
6343}
6344
Brandon Jones59770802018-04-02 13:18:42 -07006345void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6346{
6347 getInteger64v(pname, data);
6348}
6349
Corentin Wallez336129f2017-10-17 15:55:40 -04006350void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006351{
6352 Buffer *buffer = mGLState.getTargetBuffer(target);
6353 QueryBufferParameteri64v(buffer, pname, params);
6354}
6355
Brandon Jones59770802018-04-02 13:18:42 -07006356void Context::getBufferParameteri64vRobust(BufferBinding target,
6357 GLenum pname,
6358 GLsizei bufSize,
6359 GLsizei *length,
6360 GLint64 *params)
6361{
6362 getBufferParameteri64v(target, pname, params);
6363}
6364
Jamie Madill3ef140a2017-08-26 23:11:21 -04006365void Context::genSamplers(GLsizei count, GLuint *samplers)
6366{
6367 for (int i = 0; i < count; i++)
6368 {
6369 samplers[i] = mState.mSamplers->createSampler();
6370 }
6371}
6372
6373void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6374{
6375 for (int i = 0; i < count; i++)
6376 {
6377 GLuint sampler = samplers[i];
6378
6379 if (mState.mSamplers->getSampler(sampler))
6380 {
6381 detachSampler(sampler);
6382 }
6383
6384 mState.mSamplers->deleteObject(this, sampler);
6385 }
6386}
6387
6388void Context::getInternalformativ(GLenum target,
6389 GLenum internalformat,
6390 GLenum pname,
6391 GLsizei bufSize,
6392 GLint *params)
6393{
6394 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6395 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6396}
6397
Brandon Jones59770802018-04-02 13:18:42 -07006398void Context::getInternalformativRobust(GLenum target,
6399 GLenum internalformat,
6400 GLenum pname,
6401 GLsizei bufSize,
6402 GLsizei *length,
6403 GLint *params)
6404{
6405 getInternalformativ(target, internalformat, pname, bufSize, params);
6406}
6407
Jiajia Qin5451d532017-11-16 17:16:34 +08006408void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6409{
6410 programUniform1iv(program, location, 1, &v0);
6411}
6412
6413void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6414{
6415 GLint xy[2] = {v0, v1};
6416 programUniform2iv(program, location, 1, xy);
6417}
6418
6419void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6420{
6421 GLint xyz[3] = {v0, v1, v2};
6422 programUniform3iv(program, location, 1, xyz);
6423}
6424
6425void Context::programUniform4i(GLuint program,
6426 GLint location,
6427 GLint v0,
6428 GLint v1,
6429 GLint v2,
6430 GLint v3)
6431{
6432 GLint xyzw[4] = {v0, v1, v2, v3};
6433 programUniform4iv(program, location, 1, xyzw);
6434}
6435
6436void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6437{
6438 programUniform1uiv(program, location, 1, &v0);
6439}
6440
6441void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6442{
6443 GLuint xy[2] = {v0, v1};
6444 programUniform2uiv(program, location, 1, xy);
6445}
6446
6447void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6448{
6449 GLuint xyz[3] = {v0, v1, v2};
6450 programUniform3uiv(program, location, 1, xyz);
6451}
6452
6453void Context::programUniform4ui(GLuint program,
6454 GLint location,
6455 GLuint v0,
6456 GLuint v1,
6457 GLuint v2,
6458 GLuint v3)
6459{
6460 GLuint xyzw[4] = {v0, v1, v2, v3};
6461 programUniform4uiv(program, location, 1, xyzw);
6462}
6463
6464void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6465{
6466 programUniform1fv(program, location, 1, &v0);
6467}
6468
6469void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6470{
6471 GLfloat xy[2] = {v0, v1};
6472 programUniform2fv(program, location, 1, xy);
6473}
6474
6475void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6476{
6477 GLfloat xyz[3] = {v0, v1, v2};
6478 programUniform3fv(program, location, 1, xyz);
6479}
6480
6481void Context::programUniform4f(GLuint program,
6482 GLint location,
6483 GLfloat v0,
6484 GLfloat v1,
6485 GLfloat v2,
6486 GLfloat v3)
6487{
6488 GLfloat xyzw[4] = {v0, v1, v2, v3};
6489 programUniform4fv(program, location, 1, xyzw);
6490}
6491
Jamie Madill81c2e252017-09-09 23:32:46 -04006492void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6493{
6494 Program *programObject = getProgram(program);
6495 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006496 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006497}
6498
Jiajia Qin5451d532017-11-16 17:16:34 +08006499void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6500{
6501 Program *programObject = getProgram(program);
6502 ASSERT(programObject);
6503 programObject->setUniform2iv(location, count, value);
6504}
6505
6506void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6507{
6508 Program *programObject = getProgram(program);
6509 ASSERT(programObject);
6510 programObject->setUniform3iv(location, count, value);
6511}
6512
6513void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6514{
6515 Program *programObject = getProgram(program);
6516 ASSERT(programObject);
6517 programObject->setUniform4iv(location, count, value);
6518}
6519
6520void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6521{
6522 Program *programObject = getProgram(program);
6523 ASSERT(programObject);
6524 programObject->setUniform1uiv(location, count, value);
6525}
6526
6527void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6528{
6529 Program *programObject = getProgram(program);
6530 ASSERT(programObject);
6531 programObject->setUniform2uiv(location, count, value);
6532}
6533
6534void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6535{
6536 Program *programObject = getProgram(program);
6537 ASSERT(programObject);
6538 programObject->setUniform3uiv(location, count, value);
6539}
6540
6541void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6542{
6543 Program *programObject = getProgram(program);
6544 ASSERT(programObject);
6545 programObject->setUniform4uiv(location, count, value);
6546}
6547
6548void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6549{
6550 Program *programObject = getProgram(program);
6551 ASSERT(programObject);
6552 programObject->setUniform1fv(location, count, value);
6553}
6554
6555void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6556{
6557 Program *programObject = getProgram(program);
6558 ASSERT(programObject);
6559 programObject->setUniform2fv(location, count, value);
6560}
6561
6562void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6563{
6564 Program *programObject = getProgram(program);
6565 ASSERT(programObject);
6566 programObject->setUniform3fv(location, count, value);
6567}
6568
6569void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6570{
6571 Program *programObject = getProgram(program);
6572 ASSERT(programObject);
6573 programObject->setUniform4fv(location, count, value);
6574}
6575
6576void Context::programUniformMatrix2fv(GLuint program,
6577 GLint location,
6578 GLsizei count,
6579 GLboolean transpose,
6580 const GLfloat *value)
6581{
6582 Program *programObject = getProgram(program);
6583 ASSERT(programObject);
6584 programObject->setUniformMatrix2fv(location, count, transpose, value);
6585}
6586
6587void Context::programUniformMatrix3fv(GLuint program,
6588 GLint location,
6589 GLsizei count,
6590 GLboolean transpose,
6591 const GLfloat *value)
6592{
6593 Program *programObject = getProgram(program);
6594 ASSERT(programObject);
6595 programObject->setUniformMatrix3fv(location, count, transpose, value);
6596}
6597
6598void Context::programUniformMatrix4fv(GLuint program,
6599 GLint location,
6600 GLsizei count,
6601 GLboolean transpose,
6602 const GLfloat *value)
6603{
6604 Program *programObject = getProgram(program);
6605 ASSERT(programObject);
6606 programObject->setUniformMatrix4fv(location, count, transpose, value);
6607}
6608
6609void Context::programUniformMatrix2x3fv(GLuint program,
6610 GLint location,
6611 GLsizei count,
6612 GLboolean transpose,
6613 const GLfloat *value)
6614{
6615 Program *programObject = getProgram(program);
6616 ASSERT(programObject);
6617 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6618}
6619
6620void Context::programUniformMatrix3x2fv(GLuint program,
6621 GLint location,
6622 GLsizei count,
6623 GLboolean transpose,
6624 const GLfloat *value)
6625{
6626 Program *programObject = getProgram(program);
6627 ASSERT(programObject);
6628 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6629}
6630
6631void Context::programUniformMatrix2x4fv(GLuint program,
6632 GLint location,
6633 GLsizei count,
6634 GLboolean transpose,
6635 const GLfloat *value)
6636{
6637 Program *programObject = getProgram(program);
6638 ASSERT(programObject);
6639 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6640}
6641
6642void Context::programUniformMatrix4x2fv(GLuint program,
6643 GLint location,
6644 GLsizei count,
6645 GLboolean transpose,
6646 const GLfloat *value)
6647{
6648 Program *programObject = getProgram(program);
6649 ASSERT(programObject);
6650 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6651}
6652
6653void Context::programUniformMatrix3x4fv(GLuint program,
6654 GLint location,
6655 GLsizei count,
6656 GLboolean transpose,
6657 const GLfloat *value)
6658{
6659 Program *programObject = getProgram(program);
6660 ASSERT(programObject);
6661 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6662}
6663
6664void Context::programUniformMatrix4x3fv(GLuint program,
6665 GLint location,
6666 GLsizei count,
6667 GLboolean transpose,
6668 const GLfloat *value)
6669{
6670 Program *programObject = getProgram(program);
6671 ASSERT(programObject);
6672 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6673}
6674
Jamie Madill81c2e252017-09-09 23:32:46 -04006675void Context::onTextureChange(const Texture *texture)
6676{
6677 // Conservatively assume all textures are dirty.
6678 // TODO(jmadill): More fine-grained update.
6679 mGLState.setObjectDirty(GL_TEXTURE);
6680}
6681
James Darpiniane8a93c62018-01-04 18:02:24 -08006682bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6683{
6684 return mGLState.isCurrentTransformFeedback(tf);
6685}
James Darpiniane8a93c62018-01-04 18:02:24 -08006686
Yunchao Hea336b902017-08-02 16:05:21 +08006687void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6688{
6689 for (int i = 0; i < count; i++)
6690 {
6691 pipelines[i] = createProgramPipeline();
6692 }
6693}
6694
6695void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6696{
6697 for (int i = 0; i < count; i++)
6698 {
6699 if (pipelines[i] != 0)
6700 {
6701 deleteProgramPipeline(pipelines[i]);
6702 }
6703 }
6704}
6705
6706GLboolean Context::isProgramPipeline(GLuint pipeline)
6707{
6708 if (pipeline == 0)
6709 {
6710 return GL_FALSE;
6711 }
6712
6713 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6714}
6715
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006716void Context::finishFenceNV(GLuint fence)
6717{
6718 FenceNV *fenceObject = getFenceNV(fence);
6719
6720 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006721 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006722}
6723
6724void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6725{
6726 FenceNV *fenceObject = getFenceNV(fence);
6727
6728 ASSERT(fenceObject && fenceObject->isSet());
6729
6730 switch (pname)
6731 {
6732 case GL_FENCE_STATUS_NV:
6733 {
6734 // GL_NV_fence spec:
6735 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6736 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6737 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6738 GLboolean status = GL_TRUE;
6739 if (fenceObject->getStatus() != GL_TRUE)
6740 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006741 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006742 }
6743 *params = status;
6744 break;
6745 }
6746
6747 case GL_FENCE_CONDITION_NV:
6748 {
6749 *params = static_cast<GLint>(fenceObject->getCondition());
6750 break;
6751 }
6752
6753 default:
6754 UNREACHABLE();
6755 }
6756}
6757
6758void Context::getTranslatedShaderSource(GLuint shader,
6759 GLsizei bufsize,
6760 GLsizei *length,
6761 GLchar *source)
6762{
6763 Shader *shaderObject = getShader(shader);
6764 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006765 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006766}
6767
6768void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6769{
6770 Program *programObject = getProgram(program);
6771 ASSERT(programObject);
6772
6773 programObject->getUniformfv(this, location, params);
6774}
6775
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006776void Context::getnUniformfvRobust(GLuint program,
6777 GLint location,
6778 GLsizei bufSize,
6779 GLsizei *length,
6780 GLfloat *params)
6781{
6782 UNIMPLEMENTED();
6783}
6784
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006785void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6786{
6787 Program *programObject = getProgram(program);
6788 ASSERT(programObject);
6789
6790 programObject->getUniformiv(this, location, params);
6791}
6792
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006793void Context::getnUniformivRobust(GLuint program,
6794 GLint location,
6795 GLsizei bufSize,
6796 GLsizei *length,
6797 GLint *params)
6798{
6799 UNIMPLEMENTED();
6800}
6801
6802void Context::getnUniformuivRobust(GLuint program,
6803 GLint location,
6804 GLsizei bufSize,
6805 GLsizei *length,
6806 GLuint *params)
6807{
6808 UNIMPLEMENTED();
6809}
6810
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006811GLboolean Context::isFenceNV(GLuint fence)
6812{
6813 FenceNV *fenceObject = getFenceNV(fence);
6814
6815 if (fenceObject == nullptr)
6816 {
6817 return GL_FALSE;
6818 }
6819
6820 // GL_NV_fence spec:
6821 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6822 // existing fence.
6823 return fenceObject->isSet();
6824}
6825
6826void Context::readnPixels(GLint x,
6827 GLint y,
6828 GLsizei width,
6829 GLsizei height,
6830 GLenum format,
6831 GLenum type,
6832 GLsizei bufSize,
6833 void *data)
6834{
6835 return readPixels(x, y, width, height, format, type, data);
6836}
6837
Jamie Madill007530e2017-12-28 14:27:04 -05006838void Context::setFenceNV(GLuint fence, GLenum condition)
6839{
6840 ASSERT(condition == GL_ALL_COMPLETED_NV);
6841
6842 FenceNV *fenceObject = getFenceNV(fence);
6843 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006844 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006845}
6846
6847GLboolean Context::testFenceNV(GLuint fence)
6848{
6849 FenceNV *fenceObject = getFenceNV(fence);
6850
6851 ASSERT(fenceObject != nullptr);
6852 ASSERT(fenceObject->isSet() == GL_TRUE);
6853
6854 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006855 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006856 if (error.isError())
6857 {
6858 handleError(error);
6859 return GL_TRUE;
6860 }
6861
6862 return result;
6863}
6864
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006865void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006866{
6867 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006868 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006869 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006870}
6871
Jamie Madillfa920eb2018-01-04 11:45:50 -05006872void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006873{
6874 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006875 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006876 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6877}
6878
Jamie Madillfa920eb2018-01-04 11:45:50 -05006879void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6880{
6881 UNIMPLEMENTED();
6882}
6883
Jamie Madill5b772312018-03-08 20:28:32 -05006884bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6885{
6886 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6887 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6888 // to the fact that it is stored internally as a float, and so would require conversion
6889 // if returned from Context::getIntegerv. Since this conversion is already implemented
6890 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6891 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6892 // application.
6893 switch (pname)
6894 {
6895 case GL_COMPRESSED_TEXTURE_FORMATS:
6896 {
6897 *type = GL_INT;
6898 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6899 return true;
6900 }
6901 case GL_SHADER_BINARY_FORMATS:
6902 {
6903 *type = GL_INT;
6904 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6905 return true;
6906 }
6907
6908 case GL_MAX_VERTEX_ATTRIBS:
6909 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6910 case GL_MAX_VARYING_VECTORS:
6911 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6912 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6913 case GL_MAX_TEXTURE_IMAGE_UNITS:
6914 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6915 case GL_MAX_RENDERBUFFER_SIZE:
6916 case GL_NUM_SHADER_BINARY_FORMATS:
6917 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6918 case GL_ARRAY_BUFFER_BINDING:
6919 case GL_FRAMEBUFFER_BINDING:
6920 case GL_RENDERBUFFER_BINDING:
6921 case GL_CURRENT_PROGRAM:
6922 case GL_PACK_ALIGNMENT:
6923 case GL_UNPACK_ALIGNMENT:
6924 case GL_GENERATE_MIPMAP_HINT:
6925 case GL_RED_BITS:
6926 case GL_GREEN_BITS:
6927 case GL_BLUE_BITS:
6928 case GL_ALPHA_BITS:
6929 case GL_DEPTH_BITS:
6930 case GL_STENCIL_BITS:
6931 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6932 case GL_CULL_FACE_MODE:
6933 case GL_FRONT_FACE:
6934 case GL_ACTIVE_TEXTURE:
6935 case GL_STENCIL_FUNC:
6936 case GL_STENCIL_VALUE_MASK:
6937 case GL_STENCIL_REF:
6938 case GL_STENCIL_FAIL:
6939 case GL_STENCIL_PASS_DEPTH_FAIL:
6940 case GL_STENCIL_PASS_DEPTH_PASS:
6941 case GL_STENCIL_BACK_FUNC:
6942 case GL_STENCIL_BACK_VALUE_MASK:
6943 case GL_STENCIL_BACK_REF:
6944 case GL_STENCIL_BACK_FAIL:
6945 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6946 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6947 case GL_DEPTH_FUNC:
6948 case GL_BLEND_SRC_RGB:
6949 case GL_BLEND_SRC_ALPHA:
6950 case GL_BLEND_DST_RGB:
6951 case GL_BLEND_DST_ALPHA:
6952 case GL_BLEND_EQUATION_RGB:
6953 case GL_BLEND_EQUATION_ALPHA:
6954 case GL_STENCIL_WRITEMASK:
6955 case GL_STENCIL_BACK_WRITEMASK:
6956 case GL_STENCIL_CLEAR_VALUE:
6957 case GL_SUBPIXEL_BITS:
6958 case GL_MAX_TEXTURE_SIZE:
6959 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6960 case GL_SAMPLE_BUFFERS:
6961 case GL_SAMPLES:
6962 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6963 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6964 case GL_TEXTURE_BINDING_2D:
6965 case GL_TEXTURE_BINDING_CUBE_MAP:
6966 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6967 {
6968 *type = GL_INT;
6969 *numParams = 1;
6970 return true;
6971 }
6972 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6973 {
6974 if (!getExtensions().packReverseRowOrder)
6975 {
6976 return false;
6977 }
6978 *type = GL_INT;
6979 *numParams = 1;
6980 return true;
6981 }
6982 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6983 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6984 {
6985 if (!getExtensions().textureRectangle)
6986 {
6987 return false;
6988 }
6989 *type = GL_INT;
6990 *numParams = 1;
6991 return true;
6992 }
6993 case GL_MAX_DRAW_BUFFERS_EXT:
6994 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6995 {
6996 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6997 {
6998 return false;
6999 }
7000 *type = GL_INT;
7001 *numParams = 1;
7002 return true;
7003 }
7004 case GL_MAX_VIEWPORT_DIMS:
7005 {
7006 *type = GL_INT;
7007 *numParams = 2;
7008 return true;
7009 }
7010 case GL_VIEWPORT:
7011 case GL_SCISSOR_BOX:
7012 {
7013 *type = GL_INT;
7014 *numParams = 4;
7015 return true;
7016 }
7017 case GL_SHADER_COMPILER:
7018 case GL_SAMPLE_COVERAGE_INVERT:
7019 case GL_DEPTH_WRITEMASK:
7020 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7021 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7022 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7023 // bool-natural
7024 case GL_SAMPLE_COVERAGE:
7025 case GL_SCISSOR_TEST:
7026 case GL_STENCIL_TEST:
7027 case GL_DEPTH_TEST:
7028 case GL_BLEND:
7029 case GL_DITHER:
7030 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7031 {
7032 *type = GL_BOOL;
7033 *numParams = 1;
7034 return true;
7035 }
7036 case GL_COLOR_WRITEMASK:
7037 {
7038 *type = GL_BOOL;
7039 *numParams = 4;
7040 return true;
7041 }
7042 case GL_POLYGON_OFFSET_FACTOR:
7043 case GL_POLYGON_OFFSET_UNITS:
7044 case GL_SAMPLE_COVERAGE_VALUE:
7045 case GL_DEPTH_CLEAR_VALUE:
7046 case GL_LINE_WIDTH:
7047 {
7048 *type = GL_FLOAT;
7049 *numParams = 1;
7050 return true;
7051 }
7052 case GL_ALIASED_LINE_WIDTH_RANGE:
7053 case GL_ALIASED_POINT_SIZE_RANGE:
7054 case GL_DEPTH_RANGE:
7055 {
7056 *type = GL_FLOAT;
7057 *numParams = 2;
7058 return true;
7059 }
7060 case GL_COLOR_CLEAR_VALUE:
7061 case GL_BLEND_COLOR:
7062 {
7063 *type = GL_FLOAT;
7064 *numParams = 4;
7065 return true;
7066 }
7067 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7068 if (!getExtensions().textureFilterAnisotropic)
7069 {
7070 return false;
7071 }
7072 *type = GL_FLOAT;
7073 *numParams = 1;
7074 return true;
7075 case GL_TIMESTAMP_EXT:
7076 if (!getExtensions().disjointTimerQuery)
7077 {
7078 return false;
7079 }
7080 *type = GL_INT_64_ANGLEX;
7081 *numParams = 1;
7082 return true;
7083 case GL_GPU_DISJOINT_EXT:
7084 if (!getExtensions().disjointTimerQuery)
7085 {
7086 return false;
7087 }
7088 *type = GL_INT;
7089 *numParams = 1;
7090 return true;
7091 case GL_COVERAGE_MODULATION_CHROMIUM:
7092 if (!getExtensions().framebufferMixedSamples)
7093 {
7094 return false;
7095 }
7096 *type = GL_INT;
7097 *numParams = 1;
7098 return true;
7099 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7100 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7101 {
7102 return false;
7103 }
7104 *type = GL_INT;
7105 *numParams = 1;
7106 return true;
7107 }
7108
7109 if (getExtensions().debug)
7110 {
7111 switch (pname)
7112 {
7113 case GL_DEBUG_LOGGED_MESSAGES:
7114 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7115 case GL_DEBUG_GROUP_STACK_DEPTH:
7116 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7117 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7118 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7119 case GL_MAX_LABEL_LENGTH:
7120 *type = GL_INT;
7121 *numParams = 1;
7122 return true;
7123
7124 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7125 case GL_DEBUG_OUTPUT:
7126 *type = GL_BOOL;
7127 *numParams = 1;
7128 return true;
7129 }
7130 }
7131
7132 if (getExtensions().multisampleCompatibility)
7133 {
7134 switch (pname)
7135 {
7136 case GL_MULTISAMPLE_EXT:
7137 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7138 *type = GL_BOOL;
7139 *numParams = 1;
7140 return true;
7141 }
7142 }
7143
7144 if (getExtensions().pathRendering)
7145 {
7146 switch (pname)
7147 {
7148 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7149 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7150 *type = GL_FLOAT;
7151 *numParams = 16;
7152 return true;
7153 }
7154 }
7155
7156 if (getExtensions().bindGeneratesResource)
7157 {
7158 switch (pname)
7159 {
7160 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7161 *type = GL_BOOL;
7162 *numParams = 1;
7163 return true;
7164 }
7165 }
7166
7167 if (getExtensions().clientArrays)
7168 {
7169 switch (pname)
7170 {
7171 case GL_CLIENT_ARRAYS_ANGLE:
7172 *type = GL_BOOL;
7173 *numParams = 1;
7174 return true;
7175 }
7176 }
7177
7178 if (getExtensions().sRGBWriteControl)
7179 {
7180 switch (pname)
7181 {
7182 case GL_FRAMEBUFFER_SRGB_EXT:
7183 *type = GL_BOOL;
7184 *numParams = 1;
7185 return true;
7186 }
7187 }
7188
7189 if (getExtensions().robustResourceInitialization &&
7190 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7191 {
7192 *type = GL_BOOL;
7193 *numParams = 1;
7194 return true;
7195 }
7196
7197 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7198 {
7199 *type = GL_BOOL;
7200 *numParams = 1;
7201 return true;
7202 }
7203
jchen1082af6202018-06-22 10:59:52 +08007204 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7205 {
7206 *type = GL_INT;
7207 *numParams = 1;
7208 return true;
7209 }
7210
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007211 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7212 {
7213 *type = GL_INT;
7214 *numParams = 1;
7215 return true;
7216 }
7217
Jamie Madill5b772312018-03-08 20:28:32 -05007218 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7219 switch (pname)
7220 {
7221 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7222 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7223 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7224 {
7225 return false;
7226 }
7227 *type = GL_INT;
7228 *numParams = 1;
7229 return true;
7230
7231 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7232 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7233 {
7234 return false;
7235 }
7236 *type = GL_INT;
7237 *numParams = 1;
7238 return true;
7239
7240 case GL_PROGRAM_BINARY_FORMATS_OES:
7241 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7242 {
7243 return false;
7244 }
7245 *type = GL_INT;
7246 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7247 return true;
7248
7249 case GL_PACK_ROW_LENGTH:
7250 case GL_PACK_SKIP_ROWS:
7251 case GL_PACK_SKIP_PIXELS:
7252 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7253 {
7254 return false;
7255 }
7256 *type = GL_INT;
7257 *numParams = 1;
7258 return true;
7259 case GL_UNPACK_ROW_LENGTH:
7260 case GL_UNPACK_SKIP_ROWS:
7261 case GL_UNPACK_SKIP_PIXELS:
7262 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7263 {
7264 return false;
7265 }
7266 *type = GL_INT;
7267 *numParams = 1;
7268 return true;
7269 case GL_VERTEX_ARRAY_BINDING:
7270 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7271 {
7272 return false;
7273 }
7274 *type = GL_INT;
7275 *numParams = 1;
7276 return true;
7277 case GL_PIXEL_PACK_BUFFER_BINDING:
7278 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7279 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7280 {
7281 return false;
7282 }
7283 *type = GL_INT;
7284 *numParams = 1;
7285 return true;
7286 case GL_MAX_SAMPLES:
7287 {
7288 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7289 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7290 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7291 {
7292 return false;
7293 }
7294 *type = GL_INT;
7295 *numParams = 1;
7296 return true;
7297
7298 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7299 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7300 {
7301 return false;
7302 }
7303 *type = GL_INT;
7304 *numParams = 1;
7305 return true;
7306 }
7307 }
7308
7309 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7310 {
7311 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7312 {
7313 return false;
7314 }
7315 *type = GL_INT;
7316 *numParams = 1;
7317 return true;
7318 }
7319
7320 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7321 {
7322 *type = GL_INT;
7323 *numParams = 1;
7324 return true;
7325 }
7326
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007327 if (getClientVersion() < Version(2, 0))
7328 {
7329 switch (pname)
7330 {
7331 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007332 case GL_CLIENT_ACTIVE_TEXTURE:
7333 case GL_MATRIX_MODE:
7334 case GL_MAX_TEXTURE_UNITS:
7335 case GL_MAX_MODELVIEW_STACK_DEPTH:
7336 case GL_MAX_PROJECTION_STACK_DEPTH:
7337 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007338 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007339 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007340 case GL_VERTEX_ARRAY_STRIDE:
7341 case GL_NORMAL_ARRAY_STRIDE:
7342 case GL_COLOR_ARRAY_STRIDE:
7343 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7344 case GL_VERTEX_ARRAY_SIZE:
7345 case GL_COLOR_ARRAY_SIZE:
7346 case GL_TEXTURE_COORD_ARRAY_SIZE:
7347 case GL_VERTEX_ARRAY_TYPE:
7348 case GL_NORMAL_ARRAY_TYPE:
7349 case GL_COLOR_ARRAY_TYPE:
7350 case GL_TEXTURE_COORD_ARRAY_TYPE:
7351 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7352 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7353 case GL_COLOR_ARRAY_BUFFER_BINDING:
7354 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7355 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7356 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7357 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007358 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007359 case GL_MODELVIEW_STACK_DEPTH:
7360 case GL_PROJECTION_STACK_DEPTH:
7361 case GL_TEXTURE_STACK_DEPTH:
7362 case GL_LOGIC_OP_MODE:
7363 case GL_BLEND_SRC:
7364 case GL_BLEND_DST:
7365 case GL_PERSPECTIVE_CORRECTION_HINT:
7366 case GL_POINT_SMOOTH_HINT:
7367 case GL_LINE_SMOOTH_HINT:
7368 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007369 *type = GL_INT;
7370 *numParams = 1;
7371 return true;
7372 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007373 case GL_FOG_DENSITY:
7374 case GL_FOG_START:
7375 case GL_FOG_END:
7376 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007377 case GL_POINT_SIZE:
7378 case GL_POINT_SIZE_MIN:
7379 case GL_POINT_SIZE_MAX:
7380 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007381 *type = GL_FLOAT;
7382 *numParams = 1;
7383 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007384 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007385 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007386 *type = GL_FLOAT;
7387 *numParams = 2;
7388 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007389 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007390 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007391 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007392 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007393 *type = GL_FLOAT;
7394 *numParams = 4;
7395 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007396 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007397 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007398 *type = GL_FLOAT;
7399 *numParams = 3;
7400 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007401 case GL_MODELVIEW_MATRIX:
7402 case GL_PROJECTION_MATRIX:
7403 case GL_TEXTURE_MATRIX:
7404 *type = GL_FLOAT;
7405 *numParams = 16;
7406 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007407 case GL_LIGHT_MODEL_TWO_SIDE:
7408 *type = GL_BOOL;
7409 *numParams = 1;
7410 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007411 }
7412 }
7413
Jamie Madill5b772312018-03-08 20:28:32 -05007414 if (getClientVersion() < Version(3, 0))
7415 {
7416 return false;
7417 }
7418
7419 // Check for ES3.0+ parameter names
7420 switch (pname)
7421 {
7422 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7423 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7424 case GL_UNIFORM_BUFFER_BINDING:
7425 case GL_TRANSFORM_FEEDBACK_BINDING:
7426 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7427 case GL_COPY_READ_BUFFER_BINDING:
7428 case GL_COPY_WRITE_BUFFER_BINDING:
7429 case GL_SAMPLER_BINDING:
7430 case GL_READ_BUFFER:
7431 case GL_TEXTURE_BINDING_3D:
7432 case GL_TEXTURE_BINDING_2D_ARRAY:
7433 case GL_MAX_3D_TEXTURE_SIZE:
7434 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7435 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7436 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7437 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7438 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7439 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7440 case GL_MAX_VARYING_COMPONENTS:
7441 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7442 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7443 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7444 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7445 case GL_NUM_EXTENSIONS:
7446 case GL_MAJOR_VERSION:
7447 case GL_MINOR_VERSION:
7448 case GL_MAX_ELEMENTS_INDICES:
7449 case GL_MAX_ELEMENTS_VERTICES:
7450 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7451 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7452 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7453 case GL_UNPACK_IMAGE_HEIGHT:
7454 case GL_UNPACK_SKIP_IMAGES:
7455 {
7456 *type = GL_INT;
7457 *numParams = 1;
7458 return true;
7459 }
7460
7461 case GL_MAX_ELEMENT_INDEX:
7462 case GL_MAX_UNIFORM_BLOCK_SIZE:
7463 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7464 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7465 case GL_MAX_SERVER_WAIT_TIMEOUT:
7466 {
7467 *type = GL_INT_64_ANGLEX;
7468 *numParams = 1;
7469 return true;
7470 }
7471
7472 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7473 case GL_TRANSFORM_FEEDBACK_PAUSED:
7474 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7475 case GL_RASTERIZER_DISCARD:
7476 {
7477 *type = GL_BOOL;
7478 *numParams = 1;
7479 return true;
7480 }
7481
7482 case GL_MAX_TEXTURE_LOD_BIAS:
7483 {
7484 *type = GL_FLOAT;
7485 *numParams = 1;
7486 return true;
7487 }
7488 }
7489
7490 if (getExtensions().requestExtension)
7491 {
7492 switch (pname)
7493 {
7494 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7495 *type = GL_INT;
7496 *numParams = 1;
7497 return true;
7498 }
7499 }
7500
7501 if (getClientVersion() < Version(3, 1))
7502 {
7503 return false;
7504 }
7505
7506 switch (pname)
7507 {
7508 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7509 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7510 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7511 case GL_MAX_FRAMEBUFFER_WIDTH:
7512 case GL_MAX_FRAMEBUFFER_HEIGHT:
7513 case GL_MAX_FRAMEBUFFER_SAMPLES:
7514 case GL_MAX_SAMPLE_MASK_WORDS:
7515 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7516 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7517 case GL_MAX_INTEGER_SAMPLES:
7518 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7519 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7520 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7521 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7522 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7523 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7524 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7525 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7526 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7527 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7528 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7529 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7530 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7531 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7532 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7533 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7534 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7535 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7536 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7537 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7538 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7539 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7540 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7541 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7542 case GL_MAX_UNIFORM_LOCATIONS:
7543 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7544 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7545 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7546 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7547 case GL_MAX_IMAGE_UNITS:
7548 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7549 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7550 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7551 case GL_SHADER_STORAGE_BUFFER_BINDING:
7552 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7553 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007554 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007555 *type = GL_INT;
7556 *numParams = 1;
7557 return true;
7558 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7559 *type = GL_INT_64_ANGLEX;
7560 *numParams = 1;
7561 return true;
7562 case GL_SAMPLE_MASK:
7563 *type = GL_BOOL;
7564 *numParams = 1;
7565 return true;
7566 }
7567
7568 if (getExtensions().geometryShader)
7569 {
7570 switch (pname)
7571 {
7572 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7573 case GL_LAYER_PROVOKING_VERTEX_EXT:
7574 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7575 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7576 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7577 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7578 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7579 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7580 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7581 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7582 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7583 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7584 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7585 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7586 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7587 *type = GL_INT;
7588 *numParams = 1;
7589 return true;
7590 }
7591 }
7592
7593 return false;
7594}
7595
7596bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7597{
7598 if (getClientVersion() < Version(3, 0))
7599 {
7600 return false;
7601 }
7602
7603 switch (target)
7604 {
7605 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7606 case GL_UNIFORM_BUFFER_BINDING:
7607 {
7608 *type = GL_INT;
7609 *numParams = 1;
7610 return true;
7611 }
7612 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7613 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7614 case GL_UNIFORM_BUFFER_START:
7615 case GL_UNIFORM_BUFFER_SIZE:
7616 {
7617 *type = GL_INT_64_ANGLEX;
7618 *numParams = 1;
7619 return true;
7620 }
7621 }
7622
7623 if (getClientVersion() < Version(3, 1))
7624 {
7625 return false;
7626 }
7627
7628 switch (target)
7629 {
7630 case GL_IMAGE_BINDING_LAYERED:
7631 {
7632 *type = GL_BOOL;
7633 *numParams = 1;
7634 return true;
7635 }
7636 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7637 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7638 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7639 case GL_SHADER_STORAGE_BUFFER_BINDING:
7640 case GL_VERTEX_BINDING_BUFFER:
7641 case GL_VERTEX_BINDING_DIVISOR:
7642 case GL_VERTEX_BINDING_OFFSET:
7643 case GL_VERTEX_BINDING_STRIDE:
7644 case GL_SAMPLE_MASK_VALUE:
7645 case GL_IMAGE_BINDING_NAME:
7646 case GL_IMAGE_BINDING_LEVEL:
7647 case GL_IMAGE_BINDING_LAYER:
7648 case GL_IMAGE_BINDING_ACCESS:
7649 case GL_IMAGE_BINDING_FORMAT:
7650 {
7651 *type = GL_INT;
7652 *numParams = 1;
7653 return true;
7654 }
7655 case GL_ATOMIC_COUNTER_BUFFER_START:
7656 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7657 case GL_SHADER_STORAGE_BUFFER_START:
7658 case GL_SHADER_STORAGE_BUFFER_SIZE:
7659 {
7660 *type = GL_INT_64_ANGLEX;
7661 *numParams = 1;
7662 return true;
7663 }
7664 }
7665
7666 return false;
7667}
7668
7669Program *Context::getProgram(GLuint handle) const
7670{
7671 return mState.mShaderPrograms->getProgram(handle);
7672}
7673
7674Shader *Context::getShader(GLuint handle) const
7675{
7676 return mState.mShaderPrograms->getShader(handle);
7677}
7678
7679bool Context::isTextureGenerated(GLuint texture) const
7680{
7681 return mState.mTextures->isHandleGenerated(texture);
7682}
7683
Jamie Madill5b772312018-03-08 20:28:32 -05007684bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7685{
7686 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7687}
7688
7689bool Context::isFramebufferGenerated(GLuint framebuffer) const
7690{
7691 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7692}
7693
7694bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7695{
7696 return mState.mPipelines->isHandleGenerated(pipeline);
7697}
7698
7699bool Context::usingDisplayTextureShareGroup() const
7700{
7701 return mDisplayTextureShareGroup;
7702}
7703
7704GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7705{
7706 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7707 internalformat == GL_DEPTH_STENCIL
7708 ? GL_DEPTH24_STENCIL8
7709 : internalformat;
7710}
7711
jchen1082af6202018-06-22 10:59:52 +08007712void Context::maxShaderCompilerThreads(GLuint count)
7713{
jchen107ae70d82018-07-06 13:47:01 +08007714 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08007715 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007716 // A count of zero specifies a request for no parallel compiling or linking.
7717 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7718 {
7719 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7720 }
7721 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007722}
7723
Jamie Madill2eb65032018-07-30 10:25:57 -04007724bool Context::isGLES1() const
7725{
7726 return mState.getClientVersion() < Version(2, 0);
7727}
7728
Jamie Madilla11819d2018-07-30 10:26:01 -04007729void Context::onSubjectStateChange(const Context *context,
7730 angle::SubjectIndex index,
7731 angle::SubjectMessage message)
7732{
Jamie Madilla11819d2018-07-30 10:26:01 -04007733 switch (index)
7734 {
7735 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007736 switch (message)
7737 {
7738 case angle::SubjectMessage::CONTENTS_CHANGED:
7739 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
7740 mStateCache.onVertexArrayBufferContentsChange(this);
7741 break;
7742 case angle::SubjectMessage::RESOURCE_MAPPED:
7743 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7744 case angle::SubjectMessage::BINDING_CHANGED:
7745 mStateCache.onVertexArrayBufferStateChange(this);
7746 break;
7747 default:
7748 break;
7749 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007750 break;
7751
7752 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007753 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7754 {
7755 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
7756 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007757 break;
7758
7759 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007760 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7761 {
7762 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
7763 }
7764 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04007765 break;
7766
7767 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04007768 if (index < kTextureMaxSubjectIndex)
7769 {
7770 mGLState.onActiveTextureStateChange(index);
Jamie Madilld84b6732018-09-06 15:54:35 -04007771 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007772 }
Jamie Madille25b8002018-09-20 13:39:49 -04007773 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04007774 {
Jamie Madill6d32cef2018-08-14 02:34:28 -04007775 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04007776 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007777 }
Jamie Madille25b8002018-09-20 13:39:49 -04007778 else
7779 {
7780 ASSERT(index < kSamplerMaxSubjectIndex);
7781 mGLState.setSamplerDirty(index - kSampler0SubjectIndex);
7782 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007783 break;
7784 }
7785}
7786
Jamie Madill6b873dd2018-07-12 23:56:30 -04007787// ErrorSet implementation.
7788ErrorSet::ErrorSet(Context *context) : mContext(context)
7789{
7790}
7791
7792ErrorSet::~ErrorSet() = default;
7793
Jamie Madill306b6c12018-07-27 08:12:49 -04007794void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007795{
7796 // This internal enum is used to filter internal errors that are already handled.
7797 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7798 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7799 {
7800 return;
7801 }
7802
7803 if (ANGLE_UNLIKELY(error.isError()))
7804 {
7805 GLenum code = error.getCode();
7806 mErrors.insert(code);
7807 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7808 {
7809 mContext->markContextLost();
7810 }
7811
7812 ASSERT(!error.getMessage().empty());
7813 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7814 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7815 error.getMessage());
7816 }
7817}
7818
7819bool ErrorSet::empty() const
7820{
7821 return mErrors.empty();
7822}
7823
7824GLenum ErrorSet::popError()
7825{
7826 ASSERT(!empty());
7827 GLenum error = *mErrors.begin();
7828 mErrors.erase(mErrors.begin());
7829 return error;
7830}
Jamie Madilldc358af2018-07-31 11:22:13 -04007831
7832// StateCache implementation.
Jamie Madill16e28fd2018-09-12 11:03:05 -04007833StateCache::StateCache(Context *context)
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007834 : mCachedHasAnyEnabledClientAttrib(false),
7835 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04007836 mCachedInstancedVertexElementLimit(0),
7837 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madilldc358af2018-07-31 11:22:13 -04007838{
Jamie Madill16e28fd2018-09-12 11:03:05 -04007839 updateValidDrawModes(context);
Jamie Madilldc358af2018-07-31 11:22:13 -04007840}
7841
7842StateCache::~StateCache() = default;
7843
7844void StateCache::updateActiveAttribsMask(Context *context)
7845{
7846 bool isGLES1 = context->isGLES1();
7847 const State &glState = context->getGLState();
7848
7849 if (!isGLES1 && !glState.getProgram())
7850 {
7851 mCachedActiveBufferedAttribsMask = AttributesMask();
7852 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04007853 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04007854 return;
7855 }
7856
7857 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7858 : glState.getProgram()->getActiveAttribLocationsMask();
7859
7860 const VertexArray *vao = glState.getVertexArray();
7861 ASSERT(vao);
7862
7863 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7864 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04007865 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007866
Jamie Madill0a17e482018-08-31 17:19:11 -04007867 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
7868 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04007869 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007870 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7871}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007872
7873void StateCache::updateVertexElementLimits(Context *context)
7874{
7875 const VertexArray *vao = context->getGLState().getVertexArray();
7876
7877 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7878 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7879
7880 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
7881 // If there are no buffered attributes then we should not limit the draw call count.
7882 if (!vao || !mCachedActiveBufferedAttribsMask.any())
7883 {
7884 return;
7885 }
7886
7887 const auto &vertexAttribs = vao->getVertexAttributes();
7888 const auto &vertexBindings = vao->getVertexBindings();
7889
7890 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
7891 {
7892 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
7893 ASSERT(attrib.enabled);
7894
7895 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
7896 ASSERT(context->isGLES1() ||
7897 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
7898
7899 GLint64 limit = attrib.getCachedElementLimit();
7900 if (binding.getDivisor() > 0)
7901 {
7902 mCachedInstancedVertexElementLimit =
7903 std::min(mCachedInstancedVertexElementLimit, limit);
7904 }
7905 else
7906 {
7907 mCachedNonInstancedVertexElementLimit =
7908 std::min(mCachedNonInstancedVertexElementLimit, limit);
7909 }
7910 }
7911}
Jamie Madillc43cdad2018-08-08 15:49:25 -04007912
Jamie Madilld84b6732018-09-06 15:54:35 -04007913void StateCache::updateBasicDrawStatesError()
7914{
7915 mCachedBasicDrawStatesError = kInvalidPointer;
7916}
7917
7918intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
7919{
7920 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
7921 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
7922 return mCachedBasicDrawStatesError;
7923}
7924
Jamie Madillc43cdad2018-08-08 15:49:25 -04007925void StateCache::onVertexArrayBindingChange(Context *context)
7926{
7927 updateActiveAttribsMask(context);
7928 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007929 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007930}
7931
7932void StateCache::onProgramExecutableChange(Context *context)
7933{
7934 updateActiveAttribsMask(context);
7935 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007936 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04007937 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04007938}
7939
Jamie Madilld84b6732018-09-06 15:54:35 -04007940void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04007941{
7942 updateVertexElementLimits(context);
7943}
7944
Jamie Madilld84b6732018-09-06 15:54:35 -04007945void StateCache::onVertexArrayBufferContentsChange(Context *context)
7946{
7947 updateVertexElementLimits(context);
7948 updateBasicDrawStatesError();
7949}
7950
Jamie Madillc43cdad2018-08-08 15:49:25 -04007951void StateCache::onVertexArrayStateChange(Context *context)
7952{
7953 updateActiveAttribsMask(context);
7954 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007955 updateBasicDrawStatesError();
7956}
7957
7958void StateCache::onVertexArrayBufferStateChange(Context *context)
7959{
7960 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007961}
7962
7963void StateCache::onGLES1ClientStateChange(Context *context)
7964{
7965 updateActiveAttribsMask(context);
7966}
Jamie Madilld84b6732018-09-06 15:54:35 -04007967
7968void StateCache::onDrawFramebufferChange(Context *context)
7969{
7970 updateBasicDrawStatesError();
7971}
7972
7973void StateCache::onContextCapChange(Context *context)
7974{
7975 updateBasicDrawStatesError();
7976}
7977
7978void StateCache::onStencilStateChange(Context *context)
7979{
7980 updateBasicDrawStatesError();
7981}
7982
7983void StateCache::onDefaultVertexAttributeChange(Context *context)
7984{
7985 updateBasicDrawStatesError();
7986}
7987
7988void StateCache::onActiveTextureChange(Context *context)
7989{
7990 updateBasicDrawStatesError();
7991}
7992
7993void StateCache::onQueryChange(Context *context)
7994{
7995 updateBasicDrawStatesError();
7996}
7997
7998void StateCache::onTransformFeedbackChange(Context *context)
7999{
8000 updateBasicDrawStatesError();
8001}
8002
8003void StateCache::onUniformBufferStateChange(Context *context)
8004{
8005 updateBasicDrawStatesError();
8006}
8007
8008void StateCache::onBufferBindingChange(Context *context)
8009{
8010 updateBasicDrawStatesError();
8011}
Jamie Madill526a6f62018-09-12 11:03:05 -04008012
8013void StateCache::updateValidDrawModes(Context *context)
8014{
8015 Program *program = context->getGLState().getProgram();
8016 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8017 {
8018 mCachedValidDrawModes = {{
8019 true, /* Points */
8020 true, /* Lines */
8021 true, /* LineLoop */
8022 true, /* LineStrip */
8023 true, /* Triangles */
8024 true, /* TriangleStrip */
8025 true, /* TriangleFan */
8026 false, /* LinesAdjacency */
8027 false, /* LineStripAdjacency */
8028 false, /* TrianglesAdjacency */
8029 false, /* TriangleStripAdjacency */
8030 false, /* InvalidEnum */
8031 }};
8032 }
8033 else
8034 {
8035 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8036
8037 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
8038
8039 mCachedValidDrawModes = {{
8040 gsMode == PrimitiveMode::Points, /* Points */
8041 gsMode == PrimitiveMode::Lines, /* Lines */
8042 gsMode == PrimitiveMode::Lines, /* LineLoop */
8043 gsMode == PrimitiveMode::Lines, /* LineStrip */
8044 gsMode == PrimitiveMode::Triangles, /* Triangles */
8045 gsMode == PrimitiveMode::Triangles, /* TriangleStrip */
8046 gsMode == PrimitiveMode::Triangles, /* TriangleFan */
8047 gsMode == PrimitiveMode::LinesAdjacency, /* LinesAdjacency */
8048 gsMode == PrimitiveMode::LinesAdjacency, /* LineStripAdjacency */
8049 gsMode == PrimitiveMode::TrianglesAdjacency, /* TrianglesAdjacency */
8050 gsMode == PrimitiveMode::TrianglesAdjacency, /* TriangleStripAdjacency */
8051 false, /* InvalidEnum */
8052 }};
8053 }
8054}
Jamie Madillc29968b2016-01-20 11:17:23 -05008055} // namespace gl