blob: 92a225e0ef6a89c905892f13202aef3b0d130e32 [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 Madill427064d2018-04-13 16:20:34 -04002640bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002641{
2642 return mContextLost;
2643}
2644
Jamie Madillfa920eb2018-01-04 11:45:50 -05002645GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002646{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002647 // Even if the application doesn't want to know about resets, we want to know
2648 // as it will allow us to skip all the calls.
2649 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002650 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002651 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002652 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002653 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002654 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002655
2656 // EXT_robustness, section 2.6: If the reset notification behavior is
2657 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2658 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2659 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002660 }
2661
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002662 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2663 // status should be returned at least once, and GL_NO_ERROR should be returned
2664 // once the device has finished resetting.
2665 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002666 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002667 ASSERT(mResetStatus == GL_NO_ERROR);
2668 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002669
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002670 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002671 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002672 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002673 }
2674 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002675 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002676 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002677 // If markContextLost was used to mark the context lost then
2678 // assume that is not recoverable, and continue to report the
2679 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002680 mResetStatus = mImplementation->getResetStatus();
2681 }
Jamie Madill893ab082014-05-16 16:56:10 -04002682
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002683 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002684}
2685
2686bool Context::isResetNotificationEnabled()
2687{
2688 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2689}
2690
Corentin Walleze3b10e82015-05-20 11:06:25 -04002691const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002692{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002693 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002694}
2695
2696EGLenum Context::getClientType() const
2697{
2698 return mClientType;
2699}
2700
2701EGLenum Context::getRenderBuffer() const
2702{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002703 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2704 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002705 {
2706 return EGL_NONE;
2707 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002708
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002709 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002710 ASSERT(backAttachment != nullptr);
2711 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002712}
2713
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002714VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002715{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002716 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002717 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2718 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002719 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002720 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2721 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002722
Jamie Madill96a483b2017-06-27 16:49:21 -04002723 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002724 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002725
2726 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002727}
2728
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002729TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002730{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002731 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002732 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2733 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002734 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002735 transformFeedback =
2736 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002737 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002738 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002739 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002740
2741 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002742}
2743
2744bool Context::isVertexArrayGenerated(GLuint vertexArray)
2745{
Jamie Madill96a483b2017-06-27 16:49:21 -04002746 ASSERT(mVertexArrayMap.contains(0));
2747 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002748}
2749
2750bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2751{
Jamie Madill96a483b2017-06-27 16:49:21 -04002752 ASSERT(mTransformFeedbackMap.contains(0));
2753 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002754}
2755
Shannon Woods53a94a82014-06-24 15:20:36 -04002756void Context::detachTexture(GLuint texture)
2757{
2758 // Simple pass-through to State's detachTexture method, as textures do not require
2759 // allocation map management either here or in the resource manager at detach time.
2760 // Zero textures are held by the Context, and we don't attempt to request them from
2761 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002762 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002763}
2764
James Darpinian4d9d4832018-03-13 12:43:28 -07002765void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002766{
Yuly Novikov5807a532015-12-03 13:01:22 -05002767 // Simple pass-through to State's detachBuffer method, since
2768 // only buffer attachments to container objects that are bound to the current context
2769 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002770
Yuly Novikov5807a532015-12-03 13:01:22 -05002771 // [OpenGL ES 3.2] section 5.1.2 page 45:
2772 // Attachments to unbound container objects, such as
2773 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2774 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002775 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002776}
2777
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002778void Context::detachFramebuffer(GLuint framebuffer)
2779{
Shannon Woods53a94a82014-06-24 15:20:36 -04002780 // Framebuffer detachment is handled by Context, because 0 is a valid
2781 // Framebuffer object, and a pointer to it must be passed from Context
2782 // to State at binding time.
2783
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002784 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002785 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2786 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2787 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002788
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002789 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002790 {
2791 bindReadFramebuffer(0);
2792 }
2793
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002794 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002795 {
2796 bindDrawFramebuffer(0);
2797 }
2798}
2799
2800void Context::detachRenderbuffer(GLuint renderbuffer)
2801{
Jamie Madilla02315b2017-02-23 14:14:47 -05002802 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002803}
2804
Jamie Madill57a89722013-07-02 11:57:03 -04002805void Context::detachVertexArray(GLuint vertexArray)
2806{
Jamie Madill77a72f62015-04-14 11:18:32 -04002807 // Vertex array detachment is handled by Context, because 0 is a valid
2808 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002809 // binding time.
2810
Jamie Madill57a89722013-07-02 11:57:03 -04002811 // [OpenGL ES 3.0.2] section 2.10 page 43:
2812 // If a vertex array object that is currently bound is deleted, the binding
2813 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002814 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002815 {
2816 bindVertexArray(0);
2817 }
2818}
2819
Geoff Langc8058452014-02-03 12:04:11 -05002820void Context::detachTransformFeedback(GLuint transformFeedback)
2821{
Corentin Walleza2257da2016-04-19 16:43:12 -04002822 // Transform feedback detachment is handled by Context, because 0 is a valid
2823 // transform feedback, and a pointer to it must be passed from Context to State at
2824 // binding time.
2825
2826 // The OpenGL specification doesn't mention what should happen when the currently bound
2827 // transform feedback object is deleted. Since it is a container object, we treat it like
2828 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002829 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002830 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002831 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002832 }
Geoff Langc8058452014-02-03 12:04:11 -05002833}
2834
Jamie Madilldc356042013-07-19 16:36:57 -04002835void Context::detachSampler(GLuint sampler)
2836{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002837 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002838}
2839
Yunchao Hea336b902017-08-02 16:05:21 +08002840void Context::detachProgramPipeline(GLuint pipeline)
2841{
2842 mGLState.detachProgramPipeline(this, pipeline);
2843}
2844
Jamie Madill3ef140a2017-08-26 23:11:21 -04002845void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002846{
Shaodde78e82017-05-22 14:13:27 +08002847 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002848 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002849}
2850
Jamie Madille29d1672013-07-19 16:36:57 -04002851void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2852{
Geoff Langc1984ed2016-10-07 12:41:00 -04002853 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002854 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002855 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002856}
Jamie Madille29d1672013-07-19 16:36:57 -04002857
Geoff Langc1984ed2016-10-07 12:41:00 -04002858void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2859{
2860 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002861 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002862 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002863}
2864
Brandon Jones59770802018-04-02 13:18:42 -07002865void Context::samplerParameterivRobust(GLuint sampler,
2866 GLenum pname,
2867 GLsizei bufSize,
2868 const GLint *param)
2869{
2870 samplerParameteriv(sampler, pname, param);
2871}
2872
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002873void Context::samplerParameterIivRobust(GLuint sampler,
2874 GLenum pname,
2875 GLsizei bufSize,
2876 const GLint *param)
2877{
2878 UNIMPLEMENTED();
2879}
2880
2881void Context::samplerParameterIuivRobust(GLuint sampler,
2882 GLenum pname,
2883 GLsizei bufSize,
2884 const GLuint *param)
2885{
2886 UNIMPLEMENTED();
2887}
2888
Jamie Madille29d1672013-07-19 16:36:57 -04002889void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2890{
Geoff Langc1984ed2016-10-07 12:41:00 -04002891 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002892 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002893 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002894}
2895
Geoff Langc1984ed2016-10-07 12:41:00 -04002896void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002897{
Geoff Langc1984ed2016-10-07 12:41:00 -04002898 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002899 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002900 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002901}
2902
Brandon Jones59770802018-04-02 13:18:42 -07002903void Context::samplerParameterfvRobust(GLuint sampler,
2904 GLenum pname,
2905 GLsizei bufSize,
2906 const GLfloat *param)
2907{
2908 samplerParameterfv(sampler, pname, param);
2909}
2910
Geoff Langc1984ed2016-10-07 12:41:00 -04002911void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002912{
Geoff Langc1984ed2016-10-07 12:41:00 -04002913 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002914 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002915 QuerySamplerParameteriv(samplerObject, pname, params);
2916}
Jamie Madill9675b802013-07-19 16:36:59 -04002917
Brandon Jones59770802018-04-02 13:18:42 -07002918void Context::getSamplerParameterivRobust(GLuint sampler,
2919 GLenum pname,
2920 GLsizei bufSize,
2921 GLsizei *length,
2922 GLint *params)
2923{
2924 getSamplerParameteriv(sampler, pname, params);
2925}
2926
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002927void Context::getSamplerParameterIivRobust(GLuint sampler,
2928 GLenum pname,
2929 GLsizei bufSize,
2930 GLsizei *length,
2931 GLint *params)
2932{
2933 UNIMPLEMENTED();
2934}
2935
2936void Context::getSamplerParameterIuivRobust(GLuint sampler,
2937 GLenum pname,
2938 GLsizei bufSize,
2939 GLsizei *length,
2940 GLuint *params)
2941{
2942 UNIMPLEMENTED();
2943}
2944
Geoff Langc1984ed2016-10-07 12:41:00 -04002945void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2946{
2947 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002948 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002949 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002950}
2951
Brandon Jones59770802018-04-02 13:18:42 -07002952void Context::getSamplerParameterfvRobust(GLuint sampler,
2953 GLenum pname,
2954 GLsizei bufSize,
2955 GLsizei *length,
2956 GLfloat *params)
2957{
2958 getSamplerParameterfv(sampler, pname, params);
2959}
2960
Olli Etuahof0fee072016-03-30 15:11:58 +03002961void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2962{
2963 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002964 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002965}
2966
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002967void Context::initRendererString()
2968{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002969 std::ostringstream rendererString;
2970 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002971 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002972 rendererString << ")";
2973
Geoff Langcec35902014-04-16 10:52:36 -04002974 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002975}
2976
Geoff Langc339c4e2016-11-29 10:37:36 -05002977void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002978{
Geoff Langc339c4e2016-11-29 10:37:36 -05002979 const Version &clientVersion = getClientVersion();
2980
2981 std::ostringstream versionString;
2982 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2983 << ANGLE_VERSION_STRING << ")";
2984 mVersionString = MakeStaticString(versionString.str());
2985
2986 std::ostringstream shadingLanguageVersionString;
2987 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2988 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2989 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2990 << ")";
2991 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002992}
2993
Geoff Langcec35902014-04-16 10:52:36 -04002994void Context::initExtensionStrings()
2995{
Geoff Langc339c4e2016-11-29 10:37:36 -05002996 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2997 std::ostringstream combinedStringStream;
2998 std::copy(strings.begin(), strings.end(),
2999 std::ostream_iterator<const char *>(combinedStringStream, " "));
3000 return MakeStaticString(combinedStringStream.str());
3001 };
3002
3003 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003004 for (const auto &extensionString : mExtensions.getStrings())
3005 {
3006 mExtensionStrings.push_back(MakeStaticString(extensionString));
3007 }
Geoff Langc339c4e2016-11-29 10:37:36 -05003008 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003009
Geoff Langc339c4e2016-11-29 10:37:36 -05003010 mRequestableExtensionStrings.clear();
3011 for (const auto &extensionInfo : GetExtensionInfoMap())
3012 {
3013 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003014 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003015 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003016 {
3017 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3018 }
3019 }
3020 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003021}
3022
Geoff Langc339c4e2016-11-29 10:37:36 -05003023const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003024{
Geoff Langc339c4e2016-11-29 10:37:36 -05003025 switch (name)
3026 {
3027 case GL_VENDOR:
3028 return reinterpret_cast<const GLubyte *>("Google Inc.");
3029
3030 case GL_RENDERER:
3031 return reinterpret_cast<const GLubyte *>(mRendererString);
3032
3033 case GL_VERSION:
3034 return reinterpret_cast<const GLubyte *>(mVersionString);
3035
3036 case GL_SHADING_LANGUAGE_VERSION:
3037 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3038
3039 case GL_EXTENSIONS:
3040 return reinterpret_cast<const GLubyte *>(mExtensionString);
3041
3042 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3043 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3044
3045 default:
3046 UNREACHABLE();
3047 return nullptr;
3048 }
Geoff Langcec35902014-04-16 10:52:36 -04003049}
3050
Geoff Langc339c4e2016-11-29 10:37:36 -05003051const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003052{
Geoff Langc339c4e2016-11-29 10:37:36 -05003053 switch (name)
3054 {
3055 case GL_EXTENSIONS:
3056 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3057
3058 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3059 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3060
3061 default:
3062 UNREACHABLE();
3063 return nullptr;
3064 }
Geoff Langcec35902014-04-16 10:52:36 -04003065}
3066
3067size_t Context::getExtensionStringCount() const
3068{
3069 return mExtensionStrings.size();
3070}
3071
Geoff Lang111a99e2017-10-17 10:58:41 -04003072bool Context::isExtensionRequestable(const char *name)
3073{
3074 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3075 auto extension = extensionInfos.find(name);
3076
Geoff Lang111a99e2017-10-17 10:58:41 -04003077 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003078 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003079}
3080
Geoff Langc339c4e2016-11-29 10:37:36 -05003081void Context::requestExtension(const char *name)
3082{
3083 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3084 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3085 const auto &extension = extensionInfos.at(name);
3086 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003087 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003088
3089 if (mExtensions.*(extension.ExtensionsMember))
3090 {
3091 // Extension already enabled
3092 return;
3093 }
3094
3095 mExtensions.*(extension.ExtensionsMember) = true;
3096 updateCaps();
3097 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003098
Jamie Madill2f348d22017-06-05 10:50:59 -04003099 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3100 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003101
Jamie Madill81c2e252017-09-09 23:32:46 -04003102 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3103 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003104 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003105 for (auto &zeroTexture : mZeroTextures)
3106 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003107 if (zeroTexture.get() != nullptr)
3108 {
3109 zeroTexture->signalDirty(this, InitState::Initialized);
3110 }
Geoff Lang9aded172017-04-05 11:07:56 -04003111 }
3112
Jamie Madillb983a4b2018-08-01 11:34:51 -04003113 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003114}
3115
3116size_t Context::getRequestableExtensionStringCount() const
3117{
3118 return mRequestableExtensionStrings.size();
3119}
3120
Jamie Madill493f9572018-05-24 19:52:15 -04003121void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003122{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003123 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003124 ASSERT(transformFeedback != nullptr);
3125 ASSERT(!transformFeedback->isPaused());
3126
Jamie Madill6c1f6712017-02-14 19:08:04 -05003127 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Jamie Madilld84b6732018-09-06 15:54:35 -04003128 mStateCache.onTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003129}
3130
3131bool Context::hasActiveTransformFeedback(GLuint program) const
3132{
3133 for (auto pair : mTransformFeedbackMap)
3134 {
3135 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3136 {
3137 return true;
3138 }
3139 }
3140 return false;
3141}
3142
Geoff Lang33f11fb2018-05-07 13:42:47 -04003143Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003144{
3145 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3146
jchen1082af6202018-06-22 10:59:52 +08003147 // Explicitly enable GL_KHR_parallel_shader_compile
3148 supportedExtensions.parallelShaderCompile = true;
3149
Geoff Langb0f917f2017-12-05 13:41:54 -05003150 if (getClientVersion() < ES_2_0)
3151 {
3152 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003153 supportedExtensions.pointSizeArray = true;
3154 supportedExtensions.textureCubeMap = true;
3155 supportedExtensions.pointSprite = true;
3156 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003157 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003158 }
3159
3160 if (getClientVersion() < ES_3_0)
3161 {
3162 // Disable ES3+ extensions
3163 supportedExtensions.colorBufferFloat = false;
3164 supportedExtensions.eglImageExternalEssl3 = false;
3165 supportedExtensions.textureNorm16 = false;
3166 supportedExtensions.multiview = false;
3167 supportedExtensions.maxViews = 1u;
3168 }
3169
3170 if (getClientVersion() < ES_3_1)
3171 {
3172 // Disable ES3.1+ extensions
3173 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003174
3175 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3176 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003177 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003178 }
3179
3180 if (getClientVersion() > ES_2_0)
3181 {
3182 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3183 // supportedExtensions.sRGB = false;
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03003184
3185 // EXT_blend_func_extended is only implemented against GLES2 now
3186 // TODO(http://anglebug.com/1085): remove this limitation once GLES3 binding API for the
3187 // outputs is in place.
3188 supportedExtensions.blendFuncExtended = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003189 }
3190
3191 // Some extensions are always available because they are implemented in the GL layer.
3192 supportedExtensions.bindUniformLocation = true;
3193 supportedExtensions.vertexArrayObject = true;
3194 supportedExtensions.bindGeneratesResource = true;
3195 supportedExtensions.clientArrays = true;
3196 supportedExtensions.requestExtension = true;
3197
3198 // Enable the no error extension if the context was created with the flag.
3199 supportedExtensions.noError = mSkipValidation;
3200
3201 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003202 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003203
3204 // Explicitly enable GL_KHR_debug
3205 supportedExtensions.debug = true;
3206 supportedExtensions.maxDebugMessageLength = 1024;
3207 supportedExtensions.maxDebugLoggedMessages = 1024;
3208 supportedExtensions.maxDebugGroupStackDepth = 1024;
3209 supportedExtensions.maxLabelLength = 1024;
3210
3211 // Explicitly enable GL_ANGLE_robust_client_memory
3212 supportedExtensions.robustClientMemory = true;
3213
3214 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003215 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003216
3217 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3218 // supports it.
3219 supportedExtensions.robustBufferAccessBehavior =
3220 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3221
3222 // Enable the cache control query unconditionally.
3223 supportedExtensions.programCacheControl = true;
3224
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003225 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003226 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003227 {
3228 // GL_ANGLE_explicit_context_gles1
3229 supportedExtensions.explicitContextGles1 = true;
3230 // GL_ANGLE_explicit_context
3231 supportedExtensions.explicitContext = true;
3232 }
3233
Geoff Langb0f917f2017-12-05 13:41:54 -05003234 return supportedExtensions;
3235}
3236
Geoff Lang33f11fb2018-05-07 13:42:47 -04003237void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003238{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003239 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003240
Geoff Lang33f11fb2018-05-07 13:42:47 -04003241 mSupportedExtensions = generateSupportedExtensions();
3242 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003243
3244 mLimitations = mImplementation->getNativeLimitations();
3245
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003246 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3247 if (getClientVersion() < Version(2, 0))
3248 {
3249 mCaps.maxMultitextureUnits = 4;
3250 mCaps.maxClipPlanes = 6;
3251 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003252 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3253 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3254 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003255 mCaps.minSmoothPointSize = 1.0f;
3256 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003257 mCaps.minSmoothLineWidth = 1.0f;
3258 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003259 }
3260
Luc Ferronad2ae932018-06-11 15:31:17 -04003261 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003262 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003263
Luc Ferronad2ae932018-06-11 15:31:17 -04003264 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3265
Jamie Madill0f80ed82017-09-19 00:24:56 -04003266 if (getClientVersion() < ES_3_1)
3267 {
3268 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3269 }
3270 else
3271 {
3272 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3273 }
Geoff Lang301d1612014-07-09 10:34:37 -04003274
Jiawei Shao54aafe52018-04-27 14:54:57 +08003275 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3276 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003277 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3278
Jamie Madill0f80ed82017-09-19 00:24:56 -04003279 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3280 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3281
3282 // Limit textures as well, so we can use fast bitsets with texture bindings.
3283 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003284 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3285 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3286 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3287 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003288
Jiawei Shaodb342272017-09-27 10:21:45 +08003289 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3290
Geoff Langc287ea62016-09-16 14:46:51 -04003291 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003292 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003293 for (const auto &extensionInfo : GetExtensionInfoMap())
3294 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003295 // If the user has requested that extensions start disabled and they are requestable,
3296 // disable them.
3297 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003298 {
3299 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3300 }
3301 }
3302
3303 // Generate texture caps
3304 updateCaps();
3305}
3306
3307void Context::updateCaps()
3308{
Geoff Lang900013c2014-07-07 11:32:19 -04003309 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003310 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003311
Jamie Madill7b62cf92017-11-02 15:20:49 -04003312 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003313 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003314 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003315 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003316
Geoff Lang0d8b7242015-09-09 14:56:53 -04003317 // Update the format caps based on the client version and extensions.
3318 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3319 // ES3.
3320 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003321 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003322 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003323 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003324 formatCaps.textureAttachment =
3325 formatCaps.textureAttachment &&
3326 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3327 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3328 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003329
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003330 // OpenGL ES does not support multisampling with non-rendererable formats
3331 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003332 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003333 (getClientVersion() < ES_3_1 &&
3334 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003335 {
Geoff Langd87878e2014-09-19 15:42:59 -04003336 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003337 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003338 else
3339 {
3340 // We may have limited the max samples for some required renderbuffer formats due to
3341 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3342 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3343
3344 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3345 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3346 // exception of signed and unsigned integer formats."
3347 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3348 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3349 {
3350 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3351 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3352 }
3353
3354 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3355 if (getClientVersion() >= ES_3_1)
3356 {
3357 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3358 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3359 // the exception that the signed and unsigned integer formats are required only to
3360 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3361 // multisamples, which must be at least one."
3362 if (formatInfo.componentType == GL_INT ||
3363 formatInfo.componentType == GL_UNSIGNED_INT)
3364 {
3365 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3366 }
3367
3368 // GLES 3.1 section 19.3.1.
3369 if (formatCaps.texturable)
3370 {
3371 if (formatInfo.depthBits > 0)
3372 {
3373 mCaps.maxDepthTextureSamples =
3374 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3375 }
3376 else if (formatInfo.redBits > 0)
3377 {
3378 mCaps.maxColorTextureSamples =
3379 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3380 }
3381 }
3382 }
3383 }
Geoff Langd87878e2014-09-19 15:42:59 -04003384
3385 if (formatCaps.texturable && formatInfo.compressed)
3386 {
Geoff Langca271392017-04-05 12:30:00 -04003387 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003388 }
3389
Geoff Langca271392017-04-05 12:30:00 -04003390 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003391 }
Jamie Madill32447362017-06-28 14:53:52 -04003392
3393 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003394 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003395 {
3396 mMemoryProgramCache = nullptr;
3397 }
Corentin Walleze4477002017-12-01 14:39:58 -05003398
3399 // Compute which buffer types are allowed
3400 mValidBufferBindings.reset();
3401 mValidBufferBindings.set(BufferBinding::ElementArray);
3402 mValidBufferBindings.set(BufferBinding::Array);
3403
3404 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3405 {
3406 mValidBufferBindings.set(BufferBinding::PixelPack);
3407 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3408 }
3409
3410 if (getClientVersion() >= ES_3_0)
3411 {
3412 mValidBufferBindings.set(BufferBinding::CopyRead);
3413 mValidBufferBindings.set(BufferBinding::CopyWrite);
3414 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3415 mValidBufferBindings.set(BufferBinding::Uniform);
3416 }
3417
3418 if (getClientVersion() >= ES_3_1)
3419 {
3420 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3421 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3422 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3423 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3424 }
jchen107ae70d82018-07-06 13:47:01 +08003425
3426 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Geoff Lang493daf52014-07-03 13:38:44 -04003427}
3428
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003429void Context::initWorkarounds()
3430{
Jamie Madill761b02c2017-06-23 16:27:06 -04003431 // Apply back-end workarounds.
3432 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3433
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003434 // Lose the context upon out of memory error if the application is
3435 // expecting to watch for those events.
3436 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3437}
3438
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003439// Return true if the draw is a no-op, else return false.
3440// A no-op draw occurs if the count of vertices is less than the minimum required to
3441// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3442bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3443{
3444 return count < kMinimumPrimitiveCounts[mode];
3445}
3446
3447bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3448{
3449 return (instanceCount == 0) || noopDraw(mode, count);
3450}
3451
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003452Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003453{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003454 if (mGLES1Renderer)
3455 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003456 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003457 }
3458
Geoff Lang9bf86f02018-07-26 11:46:34 -04003459 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003460
3461 if (isRobustResourceInitEnabled())
3462 {
3463 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3464 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3465 }
3466
Geoff Langa8cb2872018-03-09 16:09:40 -05003467 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003468 return NoError();
3469}
3470
3471Error Context::prepareForClear(GLbitfield mask)
3472{
Geoff Langa8cb2872018-03-09 16:09:40 -05003473 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003474 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003475 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003476 return NoError();
3477}
3478
3479Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3480{
Geoff Langa8cb2872018-03-09 16:09:40 -05003481 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003482 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3483 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003484 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003485 return NoError();
3486}
3487
Geoff Langa8cb2872018-03-09 16:09:40 -05003488Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003489{
Geoff Langa8cb2872018-03-09 16:09:40 -05003490 ANGLE_TRY(syncDirtyObjects(objectMask));
3491 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003492 return NoError();
3493}
3494
Geoff Langa8cb2872018-03-09 16:09:40 -05003495Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003496{
3497 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003498 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003499 mGLState.clearDirtyBits();
3500 return NoError();
3501}
3502
Geoff Langa8cb2872018-03-09 16:09:40 -05003503Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003504{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003505 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003506 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003507 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003508 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003509}
Jamie Madillc29968b2016-01-20 11:17:23 -05003510
Geoff Langa8cb2872018-03-09 16:09:40 -05003511Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003512{
3513 return mGLState.syncDirtyObjects(this, objectMask);
3514}
3515
Jamie Madillc29968b2016-01-20 11:17:23 -05003516void Context::blitFramebuffer(GLint srcX0,
3517 GLint srcY0,
3518 GLint srcX1,
3519 GLint srcY1,
3520 GLint dstX0,
3521 GLint dstY0,
3522 GLint dstX1,
3523 GLint dstY1,
3524 GLbitfield mask,
3525 GLenum filter)
3526{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003527 if (mask == 0)
3528 {
3529 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3530 // buffers are copied.
3531 return;
3532 }
3533
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003534 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003535 ASSERT(drawFramebuffer);
3536
3537 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3538 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3539
Jamie Madillbc918e72018-03-08 09:47:21 -05003540 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003541
Jamie Madillc564c072017-06-01 12:45:42 -04003542 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003543}
Jamie Madillc29968b2016-01-20 11:17:23 -05003544
3545void Context::clear(GLbitfield mask)
3546{
Geoff Langd4fff502017-09-22 11:28:28 -04003547 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3548 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003549}
3550
3551void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3552{
Olli Etuahodbce1f82018-09-19 15:32:17 +03003553 if (buffer == GL_DEPTH && !getGLState().getDrawFramebuffer()->getDepthbuffer())
3554 {
3555 // It's not an error to try to clear a non-existent depth buffer, but it's a no-op.
3556 return;
3557 }
Geoff Langd4fff502017-09-22 11:28:28 -04003558 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3559 ANGLE_CONTEXT_TRY(
3560 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003561}
3562
3563void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3564{
Geoff Langd4fff502017-09-22 11:28:28 -04003565 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3566 ANGLE_CONTEXT_TRY(
3567 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003568}
3569
3570void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3571{
Olli Etuahodbce1f82018-09-19 15:32:17 +03003572 if (buffer == GL_STENCIL && !getGLState().getDrawFramebuffer()->getStencilbuffer())
3573 {
3574 // It's not an error to try to clear a non-existent stencil buffer, but it's a no-op.
3575 return;
3576 }
Geoff Langd4fff502017-09-22 11:28:28 -04003577 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3578 ANGLE_CONTEXT_TRY(
3579 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003580}
3581
3582void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3583{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003584 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003585 ASSERT(framebufferObject);
3586
3587 // If a buffer is not present, the clear has no effect
3588 if (framebufferObject->getDepthbuffer() == nullptr &&
3589 framebufferObject->getStencilbuffer() == nullptr)
3590 {
3591 return;
3592 }
3593
Geoff Langd4fff502017-09-22 11:28:28 -04003594 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3595 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003596}
3597
3598void Context::readPixels(GLint x,
3599 GLint y,
3600 GLsizei width,
3601 GLsizei height,
3602 GLenum format,
3603 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003604 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003605{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003606 if (width == 0 || height == 0)
3607 {
3608 return;
3609 }
3610
Jamie Madillbc918e72018-03-08 09:47:21 -05003611 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003612
Jamie Madillb6664922017-07-25 12:55:04 -04003613 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3614 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003615
3616 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003617 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003618}
3619
Brandon Jones59770802018-04-02 13:18:42 -07003620void Context::readPixelsRobust(GLint x,
3621 GLint y,
3622 GLsizei width,
3623 GLsizei height,
3624 GLenum format,
3625 GLenum type,
3626 GLsizei bufSize,
3627 GLsizei *length,
3628 GLsizei *columns,
3629 GLsizei *rows,
3630 void *pixels)
3631{
3632 readPixels(x, y, width, height, format, type, pixels);
3633}
3634
3635void Context::readnPixelsRobust(GLint x,
3636 GLint y,
3637 GLsizei width,
3638 GLsizei height,
3639 GLenum format,
3640 GLenum type,
3641 GLsizei bufSize,
3642 GLsizei *length,
3643 GLsizei *columns,
3644 GLsizei *rows,
3645 void *data)
3646{
3647 readPixels(x, y, width, height, format, type, data);
3648}
3649
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003650void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003651 GLint level,
3652 GLenum internalformat,
3653 GLint x,
3654 GLint y,
3655 GLsizei width,
3656 GLsizei height,
3657 GLint border)
3658{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003659 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003660 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003661
Jamie Madillc29968b2016-01-20 11:17:23 -05003662 Rectangle sourceArea(x, y, width, height);
3663
Jamie Madill05b35b22017-10-03 09:01:44 -04003664 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003665 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003666 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003667}
3668
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003669void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003670 GLint level,
3671 GLint xoffset,
3672 GLint yoffset,
3673 GLint x,
3674 GLint y,
3675 GLsizei width,
3676 GLsizei height)
3677{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003678 if (width == 0 || height == 0)
3679 {
3680 return;
3681 }
3682
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003683 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003684 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003685
Jamie Madillc29968b2016-01-20 11:17:23 -05003686 Offset destOffset(xoffset, yoffset, 0);
3687 Rectangle sourceArea(x, y, width, height);
3688
Jamie Madill05b35b22017-10-03 09:01:44 -04003689 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003690 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003691 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003692}
3693
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003694void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003695 GLint level,
3696 GLint xoffset,
3697 GLint yoffset,
3698 GLint zoffset,
3699 GLint x,
3700 GLint y,
3701 GLsizei width,
3702 GLsizei height)
3703{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003704 if (width == 0 || height == 0)
3705 {
3706 return;
3707 }
3708
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003709 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003710 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003711
Jamie Madillc29968b2016-01-20 11:17:23 -05003712 Offset destOffset(xoffset, yoffset, zoffset);
3713 Rectangle sourceArea(x, y, width, height);
3714
Jamie Madill05b35b22017-10-03 09:01:44 -04003715 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3716 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003717 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3718 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003719}
3720
3721void Context::framebufferTexture2D(GLenum target,
3722 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003723 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003724 GLuint texture,
3725 GLint level)
3726{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003727 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003728 ASSERT(framebuffer);
3729
3730 if (texture != 0)
3731 {
3732 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003733 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003734 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003735 }
3736 else
3737 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003738 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003739 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003740
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003741 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003742}
3743
3744void Context::framebufferRenderbuffer(GLenum target,
3745 GLenum attachment,
3746 GLenum renderbuffertarget,
3747 GLuint renderbuffer)
3748{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003749 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003750 ASSERT(framebuffer);
3751
3752 if (renderbuffer != 0)
3753 {
3754 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003755
Jamie Madillcc129372018-04-12 09:13:18 -04003756 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003757 renderbufferObject);
3758 }
3759 else
3760 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003761 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003762 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003763
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003764 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003765}
3766
3767void Context::framebufferTextureLayer(GLenum target,
3768 GLenum attachment,
3769 GLuint texture,
3770 GLint level,
3771 GLint layer)
3772{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003773 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003774 ASSERT(framebuffer);
3775
3776 if (texture != 0)
3777 {
3778 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003779 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003780 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003781 }
3782 else
3783 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003784 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003785 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003786
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003787 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003788}
3789
Brandon Jones59770802018-04-02 13:18:42 -07003790void Context::framebufferTextureMultiviewLayered(GLenum target,
3791 GLenum attachment,
3792 GLuint texture,
3793 GLint level,
3794 GLint baseViewIndex,
3795 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003796{
Martin Radev82ef7742017-08-08 17:44:58 +03003797 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3798 ASSERT(framebuffer);
3799
3800 if (texture != 0)
3801 {
3802 Texture *textureObj = getTexture(texture);
3803
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003804 ImageIndex index;
3805 if (textureObj->getType() == TextureType::_2DArray)
3806 {
3807 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3808 }
3809 else
3810 {
3811 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3812 ASSERT(level == 0);
3813 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3814 }
Martin Radev82ef7742017-08-08 17:44:58 +03003815 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3816 numViews, baseViewIndex);
3817 }
3818 else
3819 {
3820 framebuffer->resetAttachment(this, attachment);
3821 }
3822
3823 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003824}
3825
Brandon Jones59770802018-04-02 13:18:42 -07003826void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3827 GLenum attachment,
3828 GLuint texture,
3829 GLint level,
3830 GLsizei numViews,
3831 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003832{
Martin Radev5dae57b2017-07-14 16:15:55 +03003833 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3834 ASSERT(framebuffer);
3835
3836 if (texture != 0)
3837 {
3838 Texture *textureObj = getTexture(texture);
3839
3840 ImageIndex index = ImageIndex::Make2D(level);
3841 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3842 textureObj, numViews, viewportOffsets);
3843 }
3844 else
3845 {
3846 framebuffer->resetAttachment(this, attachment);
3847 }
3848
3849 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003850}
3851
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003852void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3853{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003854 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3855 ASSERT(framebuffer);
3856
3857 if (texture != 0)
3858 {
3859 Texture *textureObj = getTexture(texture);
3860
3861 ImageIndex index = ImageIndex::MakeFromType(
3862 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3863 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3864 }
3865 else
3866 {
3867 framebuffer->resetAttachment(this, attachment);
3868 }
3869
3870 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003871}
3872
Jamie Madillc29968b2016-01-20 11:17:23 -05003873void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3874{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003875 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003876 ASSERT(framebuffer);
3877 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003878 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04003879 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003880}
3881
3882void Context::readBuffer(GLenum mode)
3883{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003884 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003885 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003886 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003887}
3888
3889void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3890{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003891 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003892 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003893
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003894 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003895 ASSERT(framebuffer);
3896
3897 // The specification isn't clear what should be done when the framebuffer isn't complete.
3898 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003899 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003900}
3901
3902void Context::invalidateFramebuffer(GLenum target,
3903 GLsizei numAttachments,
3904 const GLenum *attachments)
3905{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003906 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003907 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003908
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003909 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003910 ASSERT(framebuffer);
3911
Jamie Madill427064d2018-04-13 16:20:34 -04003912 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003913 {
Jamie Madill437fa652016-05-03 15:13:24 -04003914 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003915 }
Jamie Madill437fa652016-05-03 15:13:24 -04003916
Jamie Madill4928b7c2017-06-20 12:57:39 -04003917 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003918}
3919
3920void Context::invalidateSubFramebuffer(GLenum target,
3921 GLsizei numAttachments,
3922 const GLenum *attachments,
3923 GLint x,
3924 GLint y,
3925 GLsizei width,
3926 GLsizei height)
3927{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003928 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003929 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003930
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003931 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003932 ASSERT(framebuffer);
3933
Jamie Madill427064d2018-04-13 16:20:34 -04003934 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003935 {
Jamie Madill437fa652016-05-03 15:13:24 -04003936 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003937 }
Jamie Madill437fa652016-05-03 15:13:24 -04003938
3939 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003940 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003941}
3942
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003943void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003944 GLint level,
3945 GLint internalformat,
3946 GLsizei width,
3947 GLsizei height,
3948 GLint border,
3949 GLenum format,
3950 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003951 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003952{
Jamie Madillbc918e72018-03-08 09:47:21 -05003953 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003954
3955 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003956 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003957 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003958 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003959}
3960
Brandon Jones59770802018-04-02 13:18:42 -07003961void Context::texImage2DRobust(TextureTarget target,
3962 GLint level,
3963 GLint internalformat,
3964 GLsizei width,
3965 GLsizei height,
3966 GLint border,
3967 GLenum format,
3968 GLenum type,
3969 GLsizei bufSize,
3970 const void *pixels)
3971{
3972 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3973}
3974
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003975void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003976 GLint level,
3977 GLint internalformat,
3978 GLsizei width,
3979 GLsizei height,
3980 GLsizei depth,
3981 GLint border,
3982 GLenum format,
3983 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003984 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003985{
Jamie Madillbc918e72018-03-08 09:47:21 -05003986 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003987
3988 Extents size(width, height, depth);
3989 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003990 handleError(texture->setImage(this, mGLState.getUnpackState(),
3991 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003992 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003993}
3994
Brandon Jones59770802018-04-02 13:18:42 -07003995void Context::texImage3DRobust(TextureType target,
3996 GLint level,
3997 GLint internalformat,
3998 GLsizei width,
3999 GLsizei height,
4000 GLsizei depth,
4001 GLint border,
4002 GLenum format,
4003 GLenum type,
4004 GLsizei bufSize,
4005 const void *pixels)
4006{
4007 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4008}
4009
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004010void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004011 GLint level,
4012 GLint xoffset,
4013 GLint yoffset,
4014 GLsizei width,
4015 GLsizei height,
4016 GLenum format,
4017 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004018 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004019{
4020 // Zero sized uploads are valid but no-ops
4021 if (width == 0 || height == 0)
4022 {
4023 return;
4024 }
4025
Jamie Madillbc918e72018-03-08 09:47:21 -05004026 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004027
4028 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004029 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004030
4031 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4032
4033 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target, level,
4034 area, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004035}
4036
Brandon Jones59770802018-04-02 13:18:42 -07004037void Context::texSubImage2DRobust(TextureTarget target,
4038 GLint level,
4039 GLint xoffset,
4040 GLint yoffset,
4041 GLsizei width,
4042 GLsizei height,
4043 GLenum format,
4044 GLenum type,
4045 GLsizei bufSize,
4046 const void *pixels)
4047{
4048 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4049}
4050
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004051void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004052 GLint level,
4053 GLint xoffset,
4054 GLint yoffset,
4055 GLint zoffset,
4056 GLsizei width,
4057 GLsizei height,
4058 GLsizei depth,
4059 GLenum format,
4060 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004061 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004062{
4063 // Zero sized uploads are valid but no-ops
4064 if (width == 0 || height == 0 || depth == 0)
4065 {
4066 return;
4067 }
4068
Jamie Madillbc918e72018-03-08 09:47:21 -05004069 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004070
4071 Box area(xoffset, yoffset, zoffset, width, height, depth);
4072 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004073
4074 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4075
4076 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004077 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004078 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004079}
4080
Brandon Jones59770802018-04-02 13:18:42 -07004081void Context::texSubImage3DRobust(TextureType target,
4082 GLint level,
4083 GLint xoffset,
4084 GLint yoffset,
4085 GLint zoffset,
4086 GLsizei width,
4087 GLsizei height,
4088 GLsizei depth,
4089 GLenum format,
4090 GLenum type,
4091 GLsizei bufSize,
4092 const void *pixels)
4093{
4094 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4095 pixels);
4096}
4097
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004098void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004099 GLint level,
4100 GLenum internalformat,
4101 GLsizei width,
4102 GLsizei height,
4103 GLint border,
4104 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004105 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004106{
Jamie Madillbc918e72018-03-08 09:47:21 -05004107 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004108
4109 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004110 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004111 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4112 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004113 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004114}
4115
Brandon Jones59770802018-04-02 13:18:42 -07004116void Context::compressedTexImage2DRobust(TextureTarget target,
4117 GLint level,
4118 GLenum internalformat,
4119 GLsizei width,
4120 GLsizei height,
4121 GLint border,
4122 GLsizei imageSize,
4123 GLsizei dataSize,
4124 const GLvoid *data)
4125{
4126 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4127}
4128
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004129void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004130 GLint level,
4131 GLenum internalformat,
4132 GLsizei width,
4133 GLsizei height,
4134 GLsizei depth,
4135 GLint border,
4136 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004137 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004138{
Jamie Madillbc918e72018-03-08 09:47:21 -05004139 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004140
4141 Extents size(width, height, depth);
4142 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004143 handleError(texture->setCompressedImage(
4144 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004145 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004146}
4147
Brandon Jones59770802018-04-02 13:18:42 -07004148void Context::compressedTexImage3DRobust(TextureType target,
4149 GLint level,
4150 GLenum internalformat,
4151 GLsizei width,
4152 GLsizei height,
4153 GLsizei depth,
4154 GLint border,
4155 GLsizei imageSize,
4156 GLsizei dataSize,
4157 const GLvoid *data)
4158{
4159 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4160 data);
4161}
4162
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004163void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004164 GLint level,
4165 GLint xoffset,
4166 GLint yoffset,
4167 GLsizei width,
4168 GLsizei height,
4169 GLenum format,
4170 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004171 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004172{
Jamie Madillbc918e72018-03-08 09:47:21 -05004173 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004174
4175 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004176 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004177 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4178 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004179 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004180}
4181
Brandon Jones59770802018-04-02 13:18:42 -07004182void Context::compressedTexSubImage2DRobust(TextureTarget target,
4183 GLint level,
4184 GLint xoffset,
4185 GLint yoffset,
4186 GLsizei width,
4187 GLsizei height,
4188 GLenum format,
4189 GLsizei imageSize,
4190 GLsizei dataSize,
4191 const GLvoid *data)
4192{
4193 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4194 data);
4195}
4196
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004197void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004198 GLint level,
4199 GLint xoffset,
4200 GLint yoffset,
4201 GLint zoffset,
4202 GLsizei width,
4203 GLsizei height,
4204 GLsizei depth,
4205 GLenum format,
4206 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004207 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004208{
4209 // Zero sized uploads are valid but no-ops
4210 if (width == 0 || height == 0)
4211 {
4212 return;
4213 }
4214
Jamie Madillbc918e72018-03-08 09:47:21 -05004215 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004216
4217 Box area(xoffset, yoffset, zoffset, width, height, depth);
4218 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004219 handleError(texture->setCompressedSubImage(
4220 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004221 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004222}
4223
Brandon Jones59770802018-04-02 13:18:42 -07004224void Context::compressedTexSubImage3DRobust(TextureType target,
4225 GLint level,
4226 GLint xoffset,
4227 GLint yoffset,
4228 GLint zoffset,
4229 GLsizei width,
4230 GLsizei height,
4231 GLsizei depth,
4232 GLenum format,
4233 GLsizei imageSize,
4234 GLsizei dataSize,
4235 const GLvoid *data)
4236{
4237 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4238 imageSize, data);
4239}
4240
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004241void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004242{
4243 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004244 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004245}
4246
Jamie Madill007530e2017-12-28 14:27:04 -05004247void Context::copyTexture(GLuint sourceId,
4248 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004249 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004250 GLuint destId,
4251 GLint destLevel,
4252 GLint internalFormat,
4253 GLenum destType,
4254 GLboolean unpackFlipY,
4255 GLboolean unpackPremultiplyAlpha,
4256 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004257{
Jamie Madillbc918e72018-03-08 09:47:21 -05004258 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004259
4260 gl::Texture *sourceTexture = getTexture(sourceId);
4261 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004262 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4263 sourceLevel, ConvertToBool(unpackFlipY),
4264 ConvertToBool(unpackPremultiplyAlpha),
4265 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004266}
4267
Jamie Madill007530e2017-12-28 14:27:04 -05004268void Context::copySubTexture(GLuint sourceId,
4269 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004270 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004271 GLuint destId,
4272 GLint destLevel,
4273 GLint xoffset,
4274 GLint yoffset,
4275 GLint x,
4276 GLint y,
4277 GLsizei width,
4278 GLsizei height,
4279 GLboolean unpackFlipY,
4280 GLboolean unpackPremultiplyAlpha,
4281 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004282{
4283 // Zero sized copies are valid but no-ops
4284 if (width == 0 || height == 0)
4285 {
4286 return;
4287 }
4288
Jamie Madillbc918e72018-03-08 09:47:21 -05004289 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004290
4291 gl::Texture *sourceTexture = getTexture(sourceId);
4292 gl::Texture *destTexture = getTexture(destId);
4293 Offset offset(xoffset, yoffset, 0);
4294 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004295 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4296 ConvertToBool(unpackFlipY),
4297 ConvertToBool(unpackPremultiplyAlpha),
4298 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004299}
4300
Jamie Madill007530e2017-12-28 14:27:04 -05004301void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004302{
Jamie Madillbc918e72018-03-08 09:47:21 -05004303 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004304
4305 gl::Texture *sourceTexture = getTexture(sourceId);
4306 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004307 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004308}
4309
Corentin Wallez336129f2017-10-17 15:55:40 -04004310void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004311{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004312 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004313 ASSERT(buffer);
4314
Geoff Lang496c02d2016-10-20 11:38:11 -07004315 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004316}
4317
Brandon Jones59770802018-04-02 13:18:42 -07004318void Context::getBufferPointervRobust(BufferBinding target,
4319 GLenum pname,
4320 GLsizei bufSize,
4321 GLsizei *length,
4322 void **params)
4323{
4324 getBufferPointerv(target, pname, params);
4325}
4326
Corentin Wallez336129f2017-10-17 15:55:40 -04004327void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004328{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004329 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004330 ASSERT(buffer);
4331
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004332 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004333 if (error.isError())
4334 {
Jamie Madill437fa652016-05-03 15:13:24 -04004335 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004336 return nullptr;
4337 }
4338
4339 return buffer->getMapPointer();
4340}
4341
Corentin Wallez336129f2017-10-17 15:55:40 -04004342GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004343{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004344 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004345 ASSERT(buffer);
4346
4347 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004348 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004349 if (error.isError())
4350 {
Jamie Madill437fa652016-05-03 15:13:24 -04004351 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004352 return GL_FALSE;
4353 }
4354
4355 return result;
4356}
4357
Corentin Wallez336129f2017-10-17 15:55:40 -04004358void *Context::mapBufferRange(BufferBinding target,
4359 GLintptr offset,
4360 GLsizeiptr length,
4361 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004362{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004363 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004364 ASSERT(buffer);
4365
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004366 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004367 if (error.isError())
4368 {
Jamie Madill437fa652016-05-03 15:13:24 -04004369 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004370 return nullptr;
4371 }
4372
4373 return buffer->getMapPointer();
4374}
4375
Corentin Wallez336129f2017-10-17 15:55:40 -04004376void Context::flushMappedBufferRange(BufferBinding /*target*/,
4377 GLintptr /*offset*/,
4378 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004379{
4380 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4381}
4382
Jamie Madillbc918e72018-03-08 09:47:21 -05004383Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004384{
Geoff Langa8cb2872018-03-09 16:09:40 -05004385 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004386}
4387
Jamie Madillbc918e72018-03-08 09:47:21 -05004388Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004389{
Geoff Langa8cb2872018-03-09 16:09:40 -05004390 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004391}
4392
Jamie Madillbc918e72018-03-08 09:47:21 -05004393Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004394{
Geoff Langa8cb2872018-03-09 16:09:40 -05004395 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004396}
4397
Geoff Lang9bf86f02018-07-26 11:46:34 -04004398Error Context::syncStateForPathOperation()
4399{
4400 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4401
4402 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4403 ANGLE_TRY(syncDirtyBits());
4404
4405 return NoError();
4406}
4407
Jiajia Qin5451d532017-11-16 17:16:34 +08004408void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4409{
4410 UNIMPLEMENTED();
4411}
4412
Jamie Madillc20ab272016-06-09 07:20:46 -07004413void Context::activeTexture(GLenum texture)
4414{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004415 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004416}
4417
Jamie Madill876429b2017-04-20 15:46:24 -04004418void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004419{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004420 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004421}
4422
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004423void Context::blendEquation(GLenum mode)
4424{
4425 mGLState.setBlendEquation(mode, mode);
4426}
4427
Jamie Madillc20ab272016-06-09 07:20:46 -07004428void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4429{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004430 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004431}
4432
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004433void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4434{
4435 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4436}
4437
Jamie Madillc20ab272016-06-09 07:20:46 -07004438void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4439{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004440 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004441}
4442
Jamie Madill876429b2017-04-20 15:46:24 -04004443void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004444{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004445 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004446}
4447
Jamie Madill876429b2017-04-20 15:46:24 -04004448void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004449{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004450 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004451}
4452
4453void Context::clearStencil(GLint s)
4454{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004455 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004456}
4457
4458void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4459{
Geoff Lang92019432017-11-20 13:09:34 -05004460 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4461 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004462}
4463
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004464void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004465{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004466 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004467}
4468
4469void Context::depthFunc(GLenum func)
4470{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004471 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004472}
4473
4474void Context::depthMask(GLboolean flag)
4475{
Geoff Lang92019432017-11-20 13:09:34 -05004476 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004477}
4478
Jamie Madill876429b2017-04-20 15:46:24 -04004479void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004480{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004481 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004482}
4483
4484void Context::disable(GLenum cap)
4485{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004486 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004487 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004488}
4489
4490void Context::disableVertexAttribArray(GLuint index)
4491{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004492 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004493 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004494}
4495
4496void Context::enable(GLenum cap)
4497{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004498 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004499 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004500}
4501
4502void Context::enableVertexAttribArray(GLuint index)
4503{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004504 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004505 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004506}
4507
4508void Context::frontFace(GLenum mode)
4509{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004510 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004511}
4512
4513void Context::hint(GLenum target, GLenum mode)
4514{
4515 switch (target)
4516 {
4517 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004518 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004519 break;
4520
4521 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004522 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004523 break;
4524
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004525 case GL_PERSPECTIVE_CORRECTION_HINT:
4526 case GL_POINT_SMOOTH_HINT:
4527 case GL_LINE_SMOOTH_HINT:
4528 case GL_FOG_HINT:
4529 mGLState.gles1().setHint(target, mode);
4530 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004531 default:
4532 UNREACHABLE();
4533 return;
4534 }
4535}
4536
4537void Context::lineWidth(GLfloat width)
4538{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004539 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004540}
4541
4542void Context::pixelStorei(GLenum pname, GLint param)
4543{
4544 switch (pname)
4545 {
4546 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004547 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004548 break;
4549
4550 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004551 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004552 break;
4553
4554 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004555 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004556 break;
4557
4558 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004559 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004560 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004561 break;
4562
4563 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004564 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004565 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004566 break;
4567
4568 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004569 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004570 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004571 break;
4572
4573 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004574 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004575 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004576 break;
4577
4578 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004579 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004580 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004581 break;
4582
4583 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004584 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004585 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004586 break;
4587
4588 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004589 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004590 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004591 break;
4592
4593 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004594 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004595 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004596 break;
4597
4598 default:
4599 UNREACHABLE();
4600 return;
4601 }
4602}
4603
4604void Context::polygonOffset(GLfloat factor, GLfloat units)
4605{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004606 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004607}
4608
Jamie Madill876429b2017-04-20 15:46:24 -04004609void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004610{
Geoff Lang92019432017-11-20 13:09:34 -05004611 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004612}
4613
Jiawei Shaodb342272017-09-27 10:21:45 +08004614void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4615{
4616 mGLState.setSampleMaskParams(maskNumber, mask);
4617}
4618
Jamie Madillc20ab272016-06-09 07:20:46 -07004619void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4620{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004621 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004622}
4623
4624void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4625{
4626 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4627 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004628 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004629 }
4630
4631 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4632 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004633 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004634 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004635
4636 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004637}
4638
4639void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4640{
4641 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4642 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004643 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004644 }
4645
4646 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4647 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004648 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004649 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004650
4651 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004652}
4653
4654void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4655{
4656 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4657 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004658 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004659 }
4660
4661 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4662 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004663 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004664 }
4665}
4666
4667void Context::vertexAttrib1f(GLuint index, GLfloat x)
4668{
4669 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004670 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004671 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004672}
4673
4674void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4675{
4676 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004677 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004678 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004679}
4680
4681void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4682{
4683 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004684 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004685 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004686}
4687
4688void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4689{
4690 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004691 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004692 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004693}
4694
4695void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4696{
4697 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004698 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004699 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004700}
4701
4702void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4703{
4704 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004705 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004706 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004707}
4708
4709void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4710{
4711 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004712 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004713 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004714}
4715
4716void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4717{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004718 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004719 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004720}
4721
4722void Context::vertexAttribPointer(GLuint index,
4723 GLint size,
4724 GLenum type,
4725 GLboolean normalized,
4726 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004727 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004728{
Corentin Wallez336129f2017-10-17 15:55:40 -04004729 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004730 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004731 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004732}
4733
Shao80957d92017-02-20 21:25:59 +08004734void Context::vertexAttribFormat(GLuint attribIndex,
4735 GLint size,
4736 GLenum type,
4737 GLboolean normalized,
4738 GLuint relativeOffset)
4739{
Geoff Lang92019432017-11-20 13:09:34 -05004740 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004741 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004742 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004743}
4744
4745void Context::vertexAttribIFormat(GLuint attribIndex,
4746 GLint size,
4747 GLenum type,
4748 GLuint relativeOffset)
4749{
4750 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004751 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004752}
4753
4754void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4755{
Shaodde78e82017-05-22 14:13:27 +08004756 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004757 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004758}
4759
Jiajia Qin5451d532017-11-16 17:16:34 +08004760void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004761{
4762 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004763 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004764}
4765
Jamie Madillc20ab272016-06-09 07:20:46 -07004766void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4767{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004768 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004769}
4770
4771void Context::vertexAttribIPointer(GLuint index,
4772 GLint size,
4773 GLenum type,
4774 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004775 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004776{
Corentin Wallez336129f2017-10-17 15:55:40 -04004777 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4778 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004779 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004780}
4781
4782void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4783{
4784 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004785 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004786 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004787}
4788
4789void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4790{
4791 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004792 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004793 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004794}
4795
4796void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4797{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004798 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004799 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004800}
4801
4802void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4803{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004804 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004805 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004806}
4807
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004808void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4809{
4810 const VertexAttribCurrentValueData &currentValues =
4811 getGLState().getVertexAttribCurrentValue(index);
4812 const VertexArray *vao = getGLState().getVertexArray();
4813 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4814 currentValues, pname, params);
4815}
4816
Brandon Jones59770802018-04-02 13:18:42 -07004817void Context::getVertexAttribivRobust(GLuint index,
4818 GLenum pname,
4819 GLsizei bufSize,
4820 GLsizei *length,
4821 GLint *params)
4822{
4823 getVertexAttribiv(index, pname, params);
4824}
4825
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004826void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4827{
4828 const VertexAttribCurrentValueData &currentValues =
4829 getGLState().getVertexAttribCurrentValue(index);
4830 const VertexArray *vao = getGLState().getVertexArray();
4831 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4832 currentValues, pname, params);
4833}
4834
Brandon Jones59770802018-04-02 13:18:42 -07004835void Context::getVertexAttribfvRobust(GLuint index,
4836 GLenum pname,
4837 GLsizei bufSize,
4838 GLsizei *length,
4839 GLfloat *params)
4840{
4841 getVertexAttribfv(index, pname, params);
4842}
4843
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004844void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4845{
4846 const VertexAttribCurrentValueData &currentValues =
4847 getGLState().getVertexAttribCurrentValue(index);
4848 const VertexArray *vao = getGLState().getVertexArray();
4849 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4850 currentValues, pname, params);
4851}
4852
Brandon Jones59770802018-04-02 13:18:42 -07004853void Context::getVertexAttribIivRobust(GLuint index,
4854 GLenum pname,
4855 GLsizei bufSize,
4856 GLsizei *length,
4857 GLint *params)
4858{
4859 getVertexAttribIiv(index, pname, params);
4860}
4861
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004862void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4863{
4864 const VertexAttribCurrentValueData &currentValues =
4865 getGLState().getVertexAttribCurrentValue(index);
4866 const VertexArray *vao = getGLState().getVertexArray();
4867 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4868 currentValues, pname, params);
4869}
4870
Brandon Jones59770802018-04-02 13:18:42 -07004871void Context::getVertexAttribIuivRobust(GLuint index,
4872 GLenum pname,
4873 GLsizei bufSize,
4874 GLsizei *length,
4875 GLuint *params)
4876{
4877 getVertexAttribIuiv(index, pname, params);
4878}
4879
Jamie Madill876429b2017-04-20 15:46:24 -04004880void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004881{
4882 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4883 QueryVertexAttribPointerv(attrib, pname, pointer);
4884}
4885
Brandon Jones59770802018-04-02 13:18:42 -07004886void Context::getVertexAttribPointervRobust(GLuint index,
4887 GLenum pname,
4888 GLsizei bufSize,
4889 GLsizei *length,
4890 void **pointer)
4891{
4892 getVertexAttribPointerv(index, pname, pointer);
4893}
4894
Jamie Madillc20ab272016-06-09 07:20:46 -07004895void Context::debugMessageControl(GLenum source,
4896 GLenum type,
4897 GLenum severity,
4898 GLsizei count,
4899 const GLuint *ids,
4900 GLboolean enabled)
4901{
4902 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004903 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004904 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004905}
4906
4907void Context::debugMessageInsert(GLenum source,
4908 GLenum type,
4909 GLuint id,
4910 GLenum severity,
4911 GLsizei length,
4912 const GLchar *buf)
4913{
4914 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004915 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004916}
4917
4918void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4919{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004920 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004921}
4922
4923GLuint Context::getDebugMessageLog(GLuint count,
4924 GLsizei bufSize,
4925 GLenum *sources,
4926 GLenum *types,
4927 GLuint *ids,
4928 GLenum *severities,
4929 GLsizei *lengths,
4930 GLchar *messageLog)
4931{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004932 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4933 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004934}
4935
4936void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4937{
4938 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004939 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004940 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004941}
4942
4943void Context::popDebugGroup()
4944{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004945 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004946 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004947}
4948
Corentin Wallez336129f2017-10-17 15:55:40 -04004949void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004950{
4951 Buffer *buffer = mGLState.getTargetBuffer(target);
4952 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004953 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004954}
4955
Corentin Wallez336129f2017-10-17 15:55:40 -04004956void Context::bufferSubData(BufferBinding target,
4957 GLintptr offset,
4958 GLsizeiptr size,
4959 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004960{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06004961 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04004962 {
4963 return;
4964 }
4965
4966 Buffer *buffer = mGLState.getTargetBuffer(target);
4967 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004968 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004969}
4970
Jamie Madillef300b12016-10-07 15:12:09 -04004971void Context::attachShader(GLuint program, GLuint shader)
4972{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004973 Program *programObject = mState.mShaderPrograms->getProgram(program);
4974 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004975 ASSERT(programObject && shaderObject);
4976 programObject->attachShader(shaderObject);
4977}
4978
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004979const Workarounds &Context::getWorkarounds() const
4980{
4981 return mWorkarounds;
4982}
4983
Corentin Wallez336129f2017-10-17 15:55:40 -04004984void Context::copyBufferSubData(BufferBinding readTarget,
4985 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004986 GLintptr readOffset,
4987 GLintptr writeOffset,
4988 GLsizeiptr size)
4989{
4990 // if size is zero, the copy is a successful no-op
4991 if (size == 0)
4992 {
4993 return;
4994 }
4995
4996 // TODO(jmadill): cache these.
4997 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4998 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4999
Jamie Madill5f56ddb2017-01-13 17:29:55 -05005000 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005001}
5002
Jamie Madill01a80ee2016-11-07 12:06:18 -05005003void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5004{
5005 Program *programObject = getProgram(program);
5006 // TODO(jmadill): Re-use this from the validation if possible.
5007 ASSERT(programObject);
5008 programObject->bindAttributeLocation(index, name);
5009}
5010
Corentin Wallez336129f2017-10-17 15:55:40 -04005011void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005012{
Corentin Wallez336129f2017-10-17 15:55:40 -04005013 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5014 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04005015 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005016}
5017
Corentin Wallez336129f2017-10-17 15:55:40 -04005018void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005019{
5020 bindBufferRange(target, index, buffer, 0, 0);
5021}
5022
Corentin Wallez336129f2017-10-17 15:55:40 -04005023void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005024 GLuint index,
5025 GLuint buffer,
5026 GLintptr offset,
5027 GLsizeiptr size)
5028{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005029 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5030 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
5031 if (target == BufferBinding::Uniform)
5032 {
5033 mUniformBufferObserverBindings[index].bind(object ? object->getImplementation() : nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04005034 mStateCache.onUniformBufferStateChange(this);
5035 }
5036 else
5037 {
5038 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005039 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005040}
5041
Jamie Madill01a80ee2016-11-07 12:06:18 -05005042void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5043{
5044 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5045 {
5046 bindReadFramebuffer(framebuffer);
5047 }
5048
5049 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5050 {
5051 bindDrawFramebuffer(framebuffer);
5052 }
5053}
5054
5055void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5056{
5057 ASSERT(target == GL_RENDERBUFFER);
5058 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005059 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005060 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005061}
5062
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005063void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005064 GLsizei samples,
5065 GLenum internalformat,
5066 GLsizei width,
5067 GLsizei height,
5068 GLboolean fixedsamplelocations)
5069{
5070 Extents size(width, height, 1);
5071 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005072 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5073 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005074}
5075
Olli Etuaho89664842018-08-24 14:45:36 +03005076void Context::texStorage3DMultisample(TextureType target,
5077 GLsizei samples,
5078 GLenum internalformat,
5079 GLsizei width,
5080 GLsizei height,
5081 GLsizei depth,
5082 GLboolean fixedsamplelocations)
5083{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005084 Extents size(width, height, depth);
5085 Texture *texture = getTargetTexture(target);
5086 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5087 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005088}
5089
JiangYizhoubddc46b2016-12-09 09:50:51 +08005090void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5091{
JiangYizhou5b03f472017-01-09 10:22:53 +08005092 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5093 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005094 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005095 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005096
5097 switch (pname)
5098 {
5099 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04005100 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005101 break;
5102 default:
5103 UNREACHABLE();
5104 }
5105}
5106
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005107void Context::getMultisamplefvRobust(GLenum pname,
5108 GLuint index,
5109 GLsizei bufSize,
5110 GLsizei *length,
5111 GLfloat *val)
5112{
5113 UNIMPLEMENTED();
5114}
5115
Jamie Madille8fb6402017-02-14 17:56:40 -05005116void Context::renderbufferStorage(GLenum target,
5117 GLenum internalformat,
5118 GLsizei width,
5119 GLsizei height)
5120{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005121 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5122 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5123
Jamie Madille8fb6402017-02-14 17:56:40 -05005124 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04005125 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005126}
5127
5128void Context::renderbufferStorageMultisample(GLenum target,
5129 GLsizei samples,
5130 GLenum internalformat,
5131 GLsizei width,
5132 GLsizei height)
5133{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005134 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5135 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005136
5137 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005138 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005139 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005140}
5141
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005142void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5143{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005144 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04005145 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005146}
5147
JiangYizhoue18e6392017-02-20 10:32:23 +08005148void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5149{
5150 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5151 QueryFramebufferParameteriv(framebuffer, pname, params);
5152}
5153
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005154void Context::getFramebufferParameterivRobust(GLenum target,
5155 GLenum pname,
5156 GLsizei bufSize,
5157 GLsizei *length,
5158 GLint *params)
5159{
5160 UNIMPLEMENTED();
5161}
5162
Jiajia Qin5451d532017-11-16 17:16:34 +08005163void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005164{
5165 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005166 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005167}
5168
Jamie Madilldec86232018-07-11 09:01:18 -04005169bool Context::getScratchBuffer(size_t requstedSizeBytes,
5170 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005171{
Jamie Madilldec86232018-07-11 09:01:18 -04005172 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005173}
5174
Jamie Madilldec86232018-07-11 09:01:18 -04005175bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5176 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005177{
Jamie Madilldec86232018-07-11 09:01:18 -04005178 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005179}
5180
Xinghua Cao10a4d432017-11-28 14:46:26 +08005181Error Context::prepareForDispatch()
5182{
Geoff Langa8cb2872018-03-09 16:09:40 -05005183 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005184
5185 if (isRobustResourceInitEnabled())
5186 {
5187 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5188 }
5189
5190 return NoError();
5191}
5192
Xinghua Cao2b396592017-03-29 15:36:04 +08005193void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5194{
5195 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5196 {
5197 return;
5198 }
5199
Xinghua Cao10a4d432017-11-28 14:46:26 +08005200 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005201 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005202}
5203
Jiajia Qin5451d532017-11-16 17:16:34 +08005204void Context::dispatchComputeIndirect(GLintptr indirect)
5205{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005206 ANGLE_CONTEXT_TRY(prepareForDispatch());
5207 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005208}
5209
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005210void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005211 GLsizei levels,
5212 GLenum internalFormat,
5213 GLsizei width,
5214 GLsizei height)
5215{
5216 Extents size(width, height, 1);
5217 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005218 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005219}
5220
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005221void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005222 GLsizei levels,
5223 GLenum internalFormat,
5224 GLsizei width,
5225 GLsizei height,
5226 GLsizei depth)
5227{
5228 Extents size(width, height, depth);
5229 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005230 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005231}
5232
Jiajia Qin5451d532017-11-16 17:16:34 +08005233void Context::memoryBarrier(GLbitfield barriers)
5234{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005235 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005236}
5237
5238void Context::memoryBarrierByRegion(GLbitfield barriers)
5239{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005240 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005241}
5242
Jamie Madillc1d770e2017-04-13 17:31:24 -04005243GLenum Context::checkFramebufferStatus(GLenum target)
5244{
5245 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5246 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005247 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005248}
5249
5250void Context::compileShader(GLuint shader)
5251{
5252 Shader *shaderObject = GetValidShader(this, shader);
5253 if (!shaderObject)
5254 {
5255 return;
5256 }
5257 shaderObject->compile(this);
5258}
5259
5260void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5261{
5262 for (int i = 0; i < n; i++)
5263 {
5264 deleteBuffer(buffers[i]);
5265 }
5266}
5267
5268void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5269{
5270 for (int i = 0; i < n; i++)
5271 {
5272 if (framebuffers[i] != 0)
5273 {
5274 deleteFramebuffer(framebuffers[i]);
5275 }
5276 }
5277}
5278
5279void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5280{
5281 for (int i = 0; i < n; i++)
5282 {
5283 deleteRenderbuffer(renderbuffers[i]);
5284 }
5285}
5286
5287void Context::deleteTextures(GLsizei n, const GLuint *textures)
5288{
5289 for (int i = 0; i < n; i++)
5290 {
5291 if (textures[i] != 0)
5292 {
5293 deleteTexture(textures[i]);
5294 }
5295 }
5296}
5297
5298void Context::detachShader(GLuint program, GLuint shader)
5299{
5300 Program *programObject = getProgram(program);
5301 ASSERT(programObject);
5302
5303 Shader *shaderObject = getShader(shader);
5304 ASSERT(shaderObject);
5305
5306 programObject->detachShader(this, shaderObject);
5307}
5308
5309void Context::genBuffers(GLsizei n, GLuint *buffers)
5310{
5311 for (int i = 0; i < n; i++)
5312 {
5313 buffers[i] = createBuffer();
5314 }
5315}
5316
5317void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5318{
5319 for (int i = 0; i < n; i++)
5320 {
5321 framebuffers[i] = createFramebuffer();
5322 }
5323}
5324
5325void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5326{
5327 for (int i = 0; i < n; i++)
5328 {
5329 renderbuffers[i] = createRenderbuffer();
5330 }
5331}
5332
5333void Context::genTextures(GLsizei n, GLuint *textures)
5334{
5335 for (int i = 0; i < n; i++)
5336 {
5337 textures[i] = createTexture();
5338 }
5339}
5340
5341void Context::getActiveAttrib(GLuint program,
5342 GLuint index,
5343 GLsizei bufsize,
5344 GLsizei *length,
5345 GLint *size,
5346 GLenum *type,
5347 GLchar *name)
5348{
5349 Program *programObject = getProgram(program);
5350 ASSERT(programObject);
5351 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5352}
5353
5354void Context::getActiveUniform(GLuint program,
5355 GLuint index,
5356 GLsizei bufsize,
5357 GLsizei *length,
5358 GLint *size,
5359 GLenum *type,
5360 GLchar *name)
5361{
5362 Program *programObject = getProgram(program);
5363 ASSERT(programObject);
5364 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5365}
5366
5367void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5368{
5369 Program *programObject = getProgram(program);
5370 ASSERT(programObject);
5371 programObject->getAttachedShaders(maxcount, count, shaders);
5372}
5373
5374GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5375{
5376 Program *programObject = getProgram(program);
5377 ASSERT(programObject);
5378 return programObject->getAttributeLocation(name);
5379}
5380
5381void Context::getBooleanv(GLenum pname, GLboolean *params)
5382{
5383 GLenum nativeType;
5384 unsigned int numParams = 0;
5385 getQueryParameterInfo(pname, &nativeType, &numParams);
5386
5387 if (nativeType == GL_BOOL)
5388 {
5389 getBooleanvImpl(pname, params);
5390 }
5391 else
5392 {
5393 CastStateValues(this, nativeType, pname, numParams, params);
5394 }
5395}
5396
Brandon Jones59770802018-04-02 13:18:42 -07005397void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5398{
5399 getBooleanv(pname, params);
5400}
5401
Jamie Madillc1d770e2017-04-13 17:31:24 -04005402void Context::getFloatv(GLenum pname, GLfloat *params)
5403{
5404 GLenum nativeType;
5405 unsigned int numParams = 0;
5406 getQueryParameterInfo(pname, &nativeType, &numParams);
5407
5408 if (nativeType == GL_FLOAT)
5409 {
5410 getFloatvImpl(pname, params);
5411 }
5412 else
5413 {
5414 CastStateValues(this, nativeType, pname, numParams, params);
5415 }
5416}
5417
Brandon Jones59770802018-04-02 13:18:42 -07005418void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5419{
5420 getFloatv(pname, params);
5421}
5422
Jamie Madillc1d770e2017-04-13 17:31:24 -04005423void Context::getIntegerv(GLenum pname, GLint *params)
5424{
5425 GLenum nativeType;
5426 unsigned int numParams = 0;
5427 getQueryParameterInfo(pname, &nativeType, &numParams);
5428
5429 if (nativeType == GL_INT)
5430 {
5431 getIntegervImpl(pname, params);
5432 }
5433 else
5434 {
5435 CastStateValues(this, nativeType, pname, numParams, params);
5436 }
5437}
5438
Brandon Jones59770802018-04-02 13:18:42 -07005439void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5440{
5441 getIntegerv(pname, data);
5442}
5443
Jamie Madillc1d770e2017-04-13 17:31:24 -04005444void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5445{
5446 Program *programObject = getProgram(program);
5447 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005448 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005449}
5450
Brandon Jones59770802018-04-02 13:18:42 -07005451void Context::getProgramivRobust(GLuint program,
5452 GLenum pname,
5453 GLsizei bufSize,
5454 GLsizei *length,
5455 GLint *params)
5456{
5457 getProgramiv(program, pname, params);
5458}
5459
Jiajia Qin5451d532017-11-16 17:16:34 +08005460void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5461{
5462 UNIMPLEMENTED();
5463}
5464
Jamie Madillbe849e42017-05-02 15:49:00 -04005465void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005466{
5467 Program *programObject = getProgram(program);
5468 ASSERT(programObject);
5469 programObject->getInfoLog(bufsize, length, infolog);
5470}
5471
Jiajia Qin5451d532017-11-16 17:16:34 +08005472void Context::getProgramPipelineInfoLog(GLuint pipeline,
5473 GLsizei bufSize,
5474 GLsizei *length,
5475 GLchar *infoLog)
5476{
5477 UNIMPLEMENTED();
5478}
5479
Jamie Madillc1d770e2017-04-13 17:31:24 -04005480void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5481{
5482 Shader *shaderObject = getShader(shader);
5483 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005484 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005485}
5486
Brandon Jones59770802018-04-02 13:18:42 -07005487void Context::getShaderivRobust(GLuint shader,
5488 GLenum pname,
5489 GLsizei bufSize,
5490 GLsizei *length,
5491 GLint *params)
5492{
5493 getShaderiv(shader, pname, params);
5494}
5495
Jamie Madillc1d770e2017-04-13 17:31:24 -04005496void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5497{
5498 Shader *shaderObject = getShader(shader);
5499 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005500 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005501}
5502
5503void Context::getShaderPrecisionFormat(GLenum shadertype,
5504 GLenum precisiontype,
5505 GLint *range,
5506 GLint *precision)
5507{
5508 // TODO(jmadill): Compute shaders.
5509
5510 switch (shadertype)
5511 {
5512 case GL_VERTEX_SHADER:
5513 switch (precisiontype)
5514 {
5515 case GL_LOW_FLOAT:
5516 mCaps.vertexLowpFloat.get(range, precision);
5517 break;
5518 case GL_MEDIUM_FLOAT:
5519 mCaps.vertexMediumpFloat.get(range, precision);
5520 break;
5521 case GL_HIGH_FLOAT:
5522 mCaps.vertexHighpFloat.get(range, precision);
5523 break;
5524
5525 case GL_LOW_INT:
5526 mCaps.vertexLowpInt.get(range, precision);
5527 break;
5528 case GL_MEDIUM_INT:
5529 mCaps.vertexMediumpInt.get(range, precision);
5530 break;
5531 case GL_HIGH_INT:
5532 mCaps.vertexHighpInt.get(range, precision);
5533 break;
5534
5535 default:
5536 UNREACHABLE();
5537 return;
5538 }
5539 break;
5540
5541 case GL_FRAGMENT_SHADER:
5542 switch (precisiontype)
5543 {
5544 case GL_LOW_FLOAT:
5545 mCaps.fragmentLowpFloat.get(range, precision);
5546 break;
5547 case GL_MEDIUM_FLOAT:
5548 mCaps.fragmentMediumpFloat.get(range, precision);
5549 break;
5550 case GL_HIGH_FLOAT:
5551 mCaps.fragmentHighpFloat.get(range, precision);
5552 break;
5553
5554 case GL_LOW_INT:
5555 mCaps.fragmentLowpInt.get(range, precision);
5556 break;
5557 case GL_MEDIUM_INT:
5558 mCaps.fragmentMediumpInt.get(range, precision);
5559 break;
5560 case GL_HIGH_INT:
5561 mCaps.fragmentHighpInt.get(range, precision);
5562 break;
5563
5564 default:
5565 UNREACHABLE();
5566 return;
5567 }
5568 break;
5569
5570 default:
5571 UNREACHABLE();
5572 return;
5573 }
5574}
5575
5576void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5577{
5578 Shader *shaderObject = getShader(shader);
5579 ASSERT(shaderObject);
5580 shaderObject->getSource(bufsize, length, source);
5581}
5582
5583void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5584{
5585 Program *programObject = getProgram(program);
5586 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005587 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005588}
5589
Brandon Jones59770802018-04-02 13:18:42 -07005590void Context::getUniformfvRobust(GLuint program,
5591 GLint location,
5592 GLsizei bufSize,
5593 GLsizei *length,
5594 GLfloat *params)
5595{
5596 getUniformfv(program, location, params);
5597}
5598
Jamie Madillc1d770e2017-04-13 17:31:24 -04005599void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5600{
5601 Program *programObject = getProgram(program);
5602 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005603 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005604}
5605
Brandon Jones59770802018-04-02 13:18:42 -07005606void Context::getUniformivRobust(GLuint program,
5607 GLint location,
5608 GLsizei bufSize,
5609 GLsizei *length,
5610 GLint *params)
5611{
5612 getUniformiv(program, location, params);
5613}
5614
Jamie Madillc1d770e2017-04-13 17:31:24 -04005615GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5616{
5617 Program *programObject = getProgram(program);
5618 ASSERT(programObject);
5619 return programObject->getUniformLocation(name);
5620}
5621
5622GLboolean Context::isBuffer(GLuint buffer)
5623{
5624 if (buffer == 0)
5625 {
5626 return GL_FALSE;
5627 }
5628
5629 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5630}
5631
5632GLboolean Context::isEnabled(GLenum cap)
5633{
5634 return mGLState.getEnableFeature(cap);
5635}
5636
5637GLboolean Context::isFramebuffer(GLuint framebuffer)
5638{
5639 if (framebuffer == 0)
5640 {
5641 return GL_FALSE;
5642 }
5643
5644 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5645}
5646
5647GLboolean Context::isProgram(GLuint program)
5648{
5649 if (program == 0)
5650 {
5651 return GL_FALSE;
5652 }
5653
5654 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5655}
5656
5657GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5658{
5659 if (renderbuffer == 0)
5660 {
5661 return GL_FALSE;
5662 }
5663
5664 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5665}
5666
5667GLboolean Context::isShader(GLuint shader)
5668{
5669 if (shader == 0)
5670 {
5671 return GL_FALSE;
5672 }
5673
5674 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5675}
5676
5677GLboolean Context::isTexture(GLuint texture)
5678{
5679 if (texture == 0)
5680 {
5681 return GL_FALSE;
5682 }
5683
5684 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5685}
5686
5687void Context::linkProgram(GLuint program)
5688{
5689 Program *programObject = getProgram(program);
5690 ASSERT(programObject);
5691 handleError(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005692
5693 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5694 // don't need to worry that:
5695 // 1. Draw calls after link use the new executable code or the old one depending on the link
5696 // result.
5697 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5698 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5699 // ProgramD3D.
5700 if (programObject->isInUse())
5701 {
5702 // isLinked() which forces to resolve linking, will be called.
5703 mGLState.onProgramExecutableChange(programObject);
5704 mStateCache.onProgramExecutableChange(this);
5705 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005706}
5707
5708void Context::releaseShaderCompiler()
5709{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005710 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005711}
5712
5713void Context::shaderBinary(GLsizei n,
5714 const GLuint *shaders,
5715 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005716 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005717 GLsizei length)
5718{
5719 // No binary shader formats are supported.
5720 UNIMPLEMENTED();
5721}
5722
5723void Context::shaderSource(GLuint shader,
5724 GLsizei count,
5725 const GLchar *const *string,
5726 const GLint *length)
5727{
5728 Shader *shaderObject = getShader(shader);
5729 ASSERT(shaderObject);
5730 shaderObject->setSource(count, string, length);
5731}
5732
5733void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5734{
5735 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5736}
5737
5738void Context::stencilMask(GLuint mask)
5739{
5740 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5741}
5742
5743void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5744{
5745 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5746}
5747
5748void Context::uniform1f(GLint location, GLfloat x)
5749{
5750 Program *program = mGLState.getProgram();
5751 program->setUniform1fv(location, 1, &x);
5752}
5753
5754void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5755{
5756 Program *program = mGLState.getProgram();
5757 program->setUniform1fv(location, count, v);
5758}
5759
Jamie Madill7e4eff12018-08-08 15:49:26 -04005760void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005761{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005762 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04005763 {
5764 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04005765 mStateCache.onActiveTextureChange(this);
Jamie Madill81c2e252017-09-09 23:32:46 -04005766 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005767}
5768
Jamie Madill7e4eff12018-08-08 15:49:26 -04005769void Context::uniform1i(GLint location, GLint x)
5770{
5771 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
5772}
5773
Jamie Madillc1d770e2017-04-13 17:31:24 -04005774void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5775{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005776 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005777}
5778
5779void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5780{
5781 GLfloat xy[2] = {x, y};
5782 Program *program = mGLState.getProgram();
5783 program->setUniform2fv(location, 1, xy);
5784}
5785
5786void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5787{
5788 Program *program = mGLState.getProgram();
5789 program->setUniform2fv(location, count, v);
5790}
5791
5792void Context::uniform2i(GLint location, GLint x, GLint y)
5793{
5794 GLint xy[2] = {x, y};
5795 Program *program = mGLState.getProgram();
5796 program->setUniform2iv(location, 1, xy);
5797}
5798
5799void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5800{
5801 Program *program = mGLState.getProgram();
5802 program->setUniform2iv(location, count, v);
5803}
5804
5805void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5806{
5807 GLfloat xyz[3] = {x, y, z};
5808 Program *program = mGLState.getProgram();
5809 program->setUniform3fv(location, 1, xyz);
5810}
5811
5812void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5813{
5814 Program *program = mGLState.getProgram();
5815 program->setUniform3fv(location, count, v);
5816}
5817
5818void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5819{
5820 GLint xyz[3] = {x, y, z};
5821 Program *program = mGLState.getProgram();
5822 program->setUniform3iv(location, 1, xyz);
5823}
5824
5825void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5826{
5827 Program *program = mGLState.getProgram();
5828 program->setUniform3iv(location, count, v);
5829}
5830
5831void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5832{
5833 GLfloat xyzw[4] = {x, y, z, w};
5834 Program *program = mGLState.getProgram();
5835 program->setUniform4fv(location, 1, xyzw);
5836}
5837
5838void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5839{
5840 Program *program = mGLState.getProgram();
5841 program->setUniform4fv(location, count, v);
5842}
5843
5844void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5845{
5846 GLint xyzw[4] = {x, y, z, w};
5847 Program *program = mGLState.getProgram();
5848 program->setUniform4iv(location, 1, xyzw);
5849}
5850
5851void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5852{
5853 Program *program = mGLState.getProgram();
5854 program->setUniform4iv(location, count, v);
5855}
5856
5857void Context::uniformMatrix2fv(GLint location,
5858 GLsizei count,
5859 GLboolean transpose,
5860 const GLfloat *value)
5861{
5862 Program *program = mGLState.getProgram();
5863 program->setUniformMatrix2fv(location, count, transpose, value);
5864}
5865
5866void Context::uniformMatrix3fv(GLint location,
5867 GLsizei count,
5868 GLboolean transpose,
5869 const GLfloat *value)
5870{
5871 Program *program = mGLState.getProgram();
5872 program->setUniformMatrix3fv(location, count, transpose, value);
5873}
5874
5875void Context::uniformMatrix4fv(GLint location,
5876 GLsizei count,
5877 GLboolean transpose,
5878 const GLfloat *value)
5879{
5880 Program *program = mGLState.getProgram();
5881 program->setUniformMatrix4fv(location, count, transpose, value);
5882}
5883
5884void Context::validateProgram(GLuint program)
5885{
5886 Program *programObject = getProgram(program);
5887 ASSERT(programObject);
5888 programObject->validate(mCaps);
5889}
5890
Jiajia Qin5451d532017-11-16 17:16:34 +08005891void Context::validateProgramPipeline(GLuint pipeline)
5892{
5893 UNIMPLEMENTED();
5894}
5895
Jamie Madilld04908b2017-06-09 14:15:35 -04005896void Context::getProgramBinary(GLuint program,
5897 GLsizei bufSize,
5898 GLsizei *length,
5899 GLenum *binaryFormat,
5900 void *binary)
5901{
5902 Program *programObject = getProgram(program);
5903 ASSERT(programObject != nullptr);
5904
5905 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5906}
5907
5908void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5909{
5910 Program *programObject = getProgram(program);
5911 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005912
Jamie Madilld04908b2017-06-09 14:15:35 -04005913 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madillc43cdad2018-08-08 15:49:25 -04005914 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04005915 if (programObject->isInUse())
5916 {
5917 mGLState.setObjectDirty(GL_PROGRAM);
5918 }
Jamie Madilld04908b2017-06-09 14:15:35 -04005919}
5920
Jamie Madillff325f12017-08-26 15:06:05 -04005921void Context::uniform1ui(GLint location, GLuint v0)
5922{
5923 Program *program = mGLState.getProgram();
5924 program->setUniform1uiv(location, 1, &v0);
5925}
5926
5927void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5928{
5929 Program *program = mGLState.getProgram();
5930 const GLuint xy[] = {v0, v1};
5931 program->setUniform2uiv(location, 1, xy);
5932}
5933
5934void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5935{
5936 Program *program = mGLState.getProgram();
5937 const GLuint xyz[] = {v0, v1, v2};
5938 program->setUniform3uiv(location, 1, xyz);
5939}
5940
5941void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5942{
5943 Program *program = mGLState.getProgram();
5944 const GLuint xyzw[] = {v0, v1, v2, v3};
5945 program->setUniform4uiv(location, 1, xyzw);
5946}
5947
5948void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5949{
5950 Program *program = mGLState.getProgram();
5951 program->setUniform1uiv(location, count, value);
5952}
5953void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5954{
5955 Program *program = mGLState.getProgram();
5956 program->setUniform2uiv(location, count, value);
5957}
5958
5959void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5960{
5961 Program *program = mGLState.getProgram();
5962 program->setUniform3uiv(location, count, value);
5963}
5964
5965void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5966{
5967 Program *program = mGLState.getProgram();
5968 program->setUniform4uiv(location, count, value);
5969}
5970
Jamie Madillf0e04492017-08-26 15:28:42 -04005971void Context::genQueries(GLsizei n, GLuint *ids)
5972{
5973 for (GLsizei i = 0; i < n; i++)
5974 {
5975 GLuint handle = mQueryHandleAllocator.allocate();
5976 mQueryMap.assign(handle, nullptr);
5977 ids[i] = handle;
5978 }
5979}
5980
5981void Context::deleteQueries(GLsizei n, const GLuint *ids)
5982{
5983 for (int i = 0; i < n; i++)
5984 {
5985 GLuint query = ids[i];
5986
5987 Query *queryObject = nullptr;
5988 if (mQueryMap.erase(query, &queryObject))
5989 {
5990 mQueryHandleAllocator.release(query);
5991 if (queryObject)
5992 {
5993 queryObject->release(this);
5994 }
5995 }
5996 }
5997}
5998
5999GLboolean Context::isQuery(GLuint id)
6000{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006001 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006002}
6003
Jamie Madillc8c95812017-08-26 18:40:09 -04006004void Context::uniformMatrix2x3fv(GLint location,
6005 GLsizei count,
6006 GLboolean transpose,
6007 const GLfloat *value)
6008{
6009 Program *program = mGLState.getProgram();
6010 program->setUniformMatrix2x3fv(location, count, transpose, value);
6011}
6012
6013void Context::uniformMatrix3x2fv(GLint location,
6014 GLsizei count,
6015 GLboolean transpose,
6016 const GLfloat *value)
6017{
6018 Program *program = mGLState.getProgram();
6019 program->setUniformMatrix3x2fv(location, count, transpose, value);
6020}
6021
6022void Context::uniformMatrix2x4fv(GLint location,
6023 GLsizei count,
6024 GLboolean transpose,
6025 const GLfloat *value)
6026{
6027 Program *program = mGLState.getProgram();
6028 program->setUniformMatrix2x4fv(location, count, transpose, value);
6029}
6030
6031void Context::uniformMatrix4x2fv(GLint location,
6032 GLsizei count,
6033 GLboolean transpose,
6034 const GLfloat *value)
6035{
6036 Program *program = mGLState.getProgram();
6037 program->setUniformMatrix4x2fv(location, count, transpose, value);
6038}
6039
6040void Context::uniformMatrix3x4fv(GLint location,
6041 GLsizei count,
6042 GLboolean transpose,
6043 const GLfloat *value)
6044{
6045 Program *program = mGLState.getProgram();
6046 program->setUniformMatrix3x4fv(location, count, transpose, value);
6047}
6048
6049void Context::uniformMatrix4x3fv(GLint location,
6050 GLsizei count,
6051 GLboolean transpose,
6052 const GLfloat *value)
6053{
6054 Program *program = mGLState.getProgram();
6055 program->setUniformMatrix4x3fv(location, count, transpose, value);
6056}
6057
Jamie Madilld7576732017-08-26 18:49:50 -04006058void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6059{
6060 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6061 {
6062 GLuint vertexArray = arrays[arrayIndex];
6063
6064 if (arrays[arrayIndex] != 0)
6065 {
6066 VertexArray *vertexArrayObject = nullptr;
6067 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6068 {
6069 if (vertexArrayObject != nullptr)
6070 {
6071 detachVertexArray(vertexArray);
6072 vertexArrayObject->onDestroy(this);
6073 }
6074
6075 mVertexArrayHandleAllocator.release(vertexArray);
6076 }
6077 }
6078 }
6079}
6080
6081void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6082{
6083 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6084 {
6085 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6086 mVertexArrayMap.assign(vertexArray, nullptr);
6087 arrays[arrayIndex] = vertexArray;
6088 }
6089}
6090
6091bool Context::isVertexArray(GLuint array)
6092{
6093 if (array == 0)
6094 {
6095 return GL_FALSE;
6096 }
6097
6098 VertexArray *vao = getVertexArray(array);
6099 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6100}
6101
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006102void Context::endTransformFeedback()
6103{
6104 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6105 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006106 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006107}
6108
6109void Context::transformFeedbackVaryings(GLuint program,
6110 GLsizei count,
6111 const GLchar *const *varyings,
6112 GLenum bufferMode)
6113{
6114 Program *programObject = getProgram(program);
6115 ASSERT(programObject);
6116 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6117}
6118
6119void Context::getTransformFeedbackVarying(GLuint program,
6120 GLuint index,
6121 GLsizei bufSize,
6122 GLsizei *length,
6123 GLsizei *size,
6124 GLenum *type,
6125 GLchar *name)
6126{
6127 Program *programObject = getProgram(program);
6128 ASSERT(programObject);
6129 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6130}
6131
6132void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6133{
6134 for (int i = 0; i < n; i++)
6135 {
6136 GLuint transformFeedback = ids[i];
6137 if (transformFeedback == 0)
6138 {
6139 continue;
6140 }
6141
6142 TransformFeedback *transformFeedbackObject = nullptr;
6143 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6144 {
6145 if (transformFeedbackObject != nullptr)
6146 {
6147 detachTransformFeedback(transformFeedback);
6148 transformFeedbackObject->release(this);
6149 }
6150
6151 mTransformFeedbackHandleAllocator.release(transformFeedback);
6152 }
6153 }
6154}
6155
6156void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6157{
6158 for (int i = 0; i < n; i++)
6159 {
6160 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6161 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6162 ids[i] = transformFeedback;
6163 }
6164}
6165
6166bool Context::isTransformFeedback(GLuint id)
6167{
6168 if (id == 0)
6169 {
6170 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6171 // returns FALSE
6172 return GL_FALSE;
6173 }
6174
6175 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6176 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6177}
6178
6179void Context::pauseTransformFeedback()
6180{
6181 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6182 transformFeedback->pause();
6183}
6184
6185void Context::resumeTransformFeedback()
6186{
6187 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6188 transformFeedback->resume();
6189}
6190
Jamie Madill12e957f2017-08-26 21:42:26 -04006191void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6192{
6193 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006194 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006195}
6196
Brandon Jones59770802018-04-02 13:18:42 -07006197void Context::getUniformuivRobust(GLuint program,
6198 GLint location,
6199 GLsizei bufSize,
6200 GLsizei *length,
6201 GLuint *params)
6202{
6203 getUniformuiv(program, location, params);
6204}
6205
Jamie Madill12e957f2017-08-26 21:42:26 -04006206GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6207{
6208 const Program *programObject = getProgram(program);
6209 return programObject->getFragDataLocation(name);
6210}
6211
6212void Context::getUniformIndices(GLuint program,
6213 GLsizei uniformCount,
6214 const GLchar *const *uniformNames,
6215 GLuint *uniformIndices)
6216{
6217 const Program *programObject = getProgram(program);
6218 if (!programObject->isLinked())
6219 {
6220 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6221 {
6222 uniformIndices[uniformId] = GL_INVALID_INDEX;
6223 }
6224 }
6225 else
6226 {
6227 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6228 {
6229 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6230 }
6231 }
6232}
6233
6234void Context::getActiveUniformsiv(GLuint program,
6235 GLsizei uniformCount,
6236 const GLuint *uniformIndices,
6237 GLenum pname,
6238 GLint *params)
6239{
6240 const Program *programObject = getProgram(program);
6241 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6242 {
6243 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006244 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006245 }
6246}
6247
6248GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6249{
6250 const Program *programObject = getProgram(program);
6251 return programObject->getUniformBlockIndex(uniformBlockName);
6252}
6253
6254void Context::getActiveUniformBlockiv(GLuint program,
6255 GLuint uniformBlockIndex,
6256 GLenum pname,
6257 GLint *params)
6258{
6259 const Program *programObject = getProgram(program);
6260 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6261}
6262
Brandon Jones59770802018-04-02 13:18:42 -07006263void Context::getActiveUniformBlockivRobust(GLuint program,
6264 GLuint uniformBlockIndex,
6265 GLenum pname,
6266 GLsizei bufSize,
6267 GLsizei *length,
6268 GLint *params)
6269{
6270 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6271}
6272
Jamie Madill12e957f2017-08-26 21:42:26 -04006273void Context::getActiveUniformBlockName(GLuint program,
6274 GLuint uniformBlockIndex,
6275 GLsizei bufSize,
6276 GLsizei *length,
6277 GLchar *uniformBlockName)
6278{
6279 const Program *programObject = getProgram(program);
6280 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6281}
6282
6283void Context::uniformBlockBinding(GLuint program,
6284 GLuint uniformBlockIndex,
6285 GLuint uniformBlockBinding)
6286{
6287 Program *programObject = getProgram(program);
6288 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006289
6290 if (programObject->isInUse())
6291 {
6292 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006293 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006294 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006295}
6296
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006297GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6298{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006299 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6300 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006301
Jamie Madill70b5bb02017-08-28 13:32:37 -04006302 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006303 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006304 if (error.isError())
6305 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006306 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006307 handleError(error);
6308 return nullptr;
6309 }
6310
Jamie Madill70b5bb02017-08-28 13:32:37 -04006311 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006312}
6313
6314GLboolean Context::isSync(GLsync sync)
6315{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006316 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006317}
6318
6319GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6320{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006321 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006322
6323 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006324 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006325 return result;
6326}
6327
6328void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6329{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006330 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006331 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006332}
6333
6334void Context::getInteger64v(GLenum pname, GLint64 *params)
6335{
6336 GLenum nativeType = GL_NONE;
6337 unsigned int numParams = 0;
6338 getQueryParameterInfo(pname, &nativeType, &numParams);
6339
6340 if (nativeType == GL_INT_64_ANGLEX)
6341 {
6342 getInteger64vImpl(pname, params);
6343 }
6344 else
6345 {
6346 CastStateValues(this, nativeType, pname, numParams, params);
6347 }
6348}
6349
Brandon Jones59770802018-04-02 13:18:42 -07006350void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6351{
6352 getInteger64v(pname, data);
6353}
6354
Corentin Wallez336129f2017-10-17 15:55:40 -04006355void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006356{
6357 Buffer *buffer = mGLState.getTargetBuffer(target);
6358 QueryBufferParameteri64v(buffer, pname, params);
6359}
6360
Brandon Jones59770802018-04-02 13:18:42 -07006361void Context::getBufferParameteri64vRobust(BufferBinding target,
6362 GLenum pname,
6363 GLsizei bufSize,
6364 GLsizei *length,
6365 GLint64 *params)
6366{
6367 getBufferParameteri64v(target, pname, params);
6368}
6369
Jamie Madill3ef140a2017-08-26 23:11:21 -04006370void Context::genSamplers(GLsizei count, GLuint *samplers)
6371{
6372 for (int i = 0; i < count; i++)
6373 {
6374 samplers[i] = mState.mSamplers->createSampler();
6375 }
6376}
6377
6378void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6379{
6380 for (int i = 0; i < count; i++)
6381 {
6382 GLuint sampler = samplers[i];
6383
6384 if (mState.mSamplers->getSampler(sampler))
6385 {
6386 detachSampler(sampler);
6387 }
6388
6389 mState.mSamplers->deleteObject(this, sampler);
6390 }
6391}
6392
6393void Context::getInternalformativ(GLenum target,
6394 GLenum internalformat,
6395 GLenum pname,
6396 GLsizei bufSize,
6397 GLint *params)
6398{
6399 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6400 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6401}
6402
Brandon Jones59770802018-04-02 13:18:42 -07006403void Context::getInternalformativRobust(GLenum target,
6404 GLenum internalformat,
6405 GLenum pname,
6406 GLsizei bufSize,
6407 GLsizei *length,
6408 GLint *params)
6409{
6410 getInternalformativ(target, internalformat, pname, bufSize, params);
6411}
6412
Jiajia Qin5451d532017-11-16 17:16:34 +08006413void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6414{
6415 programUniform1iv(program, location, 1, &v0);
6416}
6417
6418void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6419{
6420 GLint xy[2] = {v0, v1};
6421 programUniform2iv(program, location, 1, xy);
6422}
6423
6424void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6425{
6426 GLint xyz[3] = {v0, v1, v2};
6427 programUniform3iv(program, location, 1, xyz);
6428}
6429
6430void Context::programUniform4i(GLuint program,
6431 GLint location,
6432 GLint v0,
6433 GLint v1,
6434 GLint v2,
6435 GLint v3)
6436{
6437 GLint xyzw[4] = {v0, v1, v2, v3};
6438 programUniform4iv(program, location, 1, xyzw);
6439}
6440
6441void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6442{
6443 programUniform1uiv(program, location, 1, &v0);
6444}
6445
6446void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6447{
6448 GLuint xy[2] = {v0, v1};
6449 programUniform2uiv(program, location, 1, xy);
6450}
6451
6452void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6453{
6454 GLuint xyz[3] = {v0, v1, v2};
6455 programUniform3uiv(program, location, 1, xyz);
6456}
6457
6458void Context::programUniform4ui(GLuint program,
6459 GLint location,
6460 GLuint v0,
6461 GLuint v1,
6462 GLuint v2,
6463 GLuint v3)
6464{
6465 GLuint xyzw[4] = {v0, v1, v2, v3};
6466 programUniform4uiv(program, location, 1, xyzw);
6467}
6468
6469void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6470{
6471 programUniform1fv(program, location, 1, &v0);
6472}
6473
6474void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6475{
6476 GLfloat xy[2] = {v0, v1};
6477 programUniform2fv(program, location, 1, xy);
6478}
6479
6480void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6481{
6482 GLfloat xyz[3] = {v0, v1, v2};
6483 programUniform3fv(program, location, 1, xyz);
6484}
6485
6486void Context::programUniform4f(GLuint program,
6487 GLint location,
6488 GLfloat v0,
6489 GLfloat v1,
6490 GLfloat v2,
6491 GLfloat v3)
6492{
6493 GLfloat xyzw[4] = {v0, v1, v2, v3};
6494 programUniform4fv(program, location, 1, xyzw);
6495}
6496
Jamie Madill81c2e252017-09-09 23:32:46 -04006497void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6498{
6499 Program *programObject = getProgram(program);
6500 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006501 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006502}
6503
Jiajia Qin5451d532017-11-16 17:16:34 +08006504void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6505{
6506 Program *programObject = getProgram(program);
6507 ASSERT(programObject);
6508 programObject->setUniform2iv(location, count, value);
6509}
6510
6511void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6512{
6513 Program *programObject = getProgram(program);
6514 ASSERT(programObject);
6515 programObject->setUniform3iv(location, count, value);
6516}
6517
6518void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6519{
6520 Program *programObject = getProgram(program);
6521 ASSERT(programObject);
6522 programObject->setUniform4iv(location, count, value);
6523}
6524
6525void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6526{
6527 Program *programObject = getProgram(program);
6528 ASSERT(programObject);
6529 programObject->setUniform1uiv(location, count, value);
6530}
6531
6532void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6533{
6534 Program *programObject = getProgram(program);
6535 ASSERT(programObject);
6536 programObject->setUniform2uiv(location, count, value);
6537}
6538
6539void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6540{
6541 Program *programObject = getProgram(program);
6542 ASSERT(programObject);
6543 programObject->setUniform3uiv(location, count, value);
6544}
6545
6546void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6547{
6548 Program *programObject = getProgram(program);
6549 ASSERT(programObject);
6550 programObject->setUniform4uiv(location, count, value);
6551}
6552
6553void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6554{
6555 Program *programObject = getProgram(program);
6556 ASSERT(programObject);
6557 programObject->setUniform1fv(location, count, value);
6558}
6559
6560void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6561{
6562 Program *programObject = getProgram(program);
6563 ASSERT(programObject);
6564 programObject->setUniform2fv(location, count, value);
6565}
6566
6567void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6568{
6569 Program *programObject = getProgram(program);
6570 ASSERT(programObject);
6571 programObject->setUniform3fv(location, count, value);
6572}
6573
6574void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6575{
6576 Program *programObject = getProgram(program);
6577 ASSERT(programObject);
6578 programObject->setUniform4fv(location, count, value);
6579}
6580
6581void Context::programUniformMatrix2fv(GLuint program,
6582 GLint location,
6583 GLsizei count,
6584 GLboolean transpose,
6585 const GLfloat *value)
6586{
6587 Program *programObject = getProgram(program);
6588 ASSERT(programObject);
6589 programObject->setUniformMatrix2fv(location, count, transpose, value);
6590}
6591
6592void Context::programUniformMatrix3fv(GLuint program,
6593 GLint location,
6594 GLsizei count,
6595 GLboolean transpose,
6596 const GLfloat *value)
6597{
6598 Program *programObject = getProgram(program);
6599 ASSERT(programObject);
6600 programObject->setUniformMatrix3fv(location, count, transpose, value);
6601}
6602
6603void Context::programUniformMatrix4fv(GLuint program,
6604 GLint location,
6605 GLsizei count,
6606 GLboolean transpose,
6607 const GLfloat *value)
6608{
6609 Program *programObject = getProgram(program);
6610 ASSERT(programObject);
6611 programObject->setUniformMatrix4fv(location, count, transpose, value);
6612}
6613
6614void Context::programUniformMatrix2x3fv(GLuint program,
6615 GLint location,
6616 GLsizei count,
6617 GLboolean transpose,
6618 const GLfloat *value)
6619{
6620 Program *programObject = getProgram(program);
6621 ASSERT(programObject);
6622 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6623}
6624
6625void Context::programUniformMatrix3x2fv(GLuint program,
6626 GLint location,
6627 GLsizei count,
6628 GLboolean transpose,
6629 const GLfloat *value)
6630{
6631 Program *programObject = getProgram(program);
6632 ASSERT(programObject);
6633 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6634}
6635
6636void Context::programUniformMatrix2x4fv(GLuint program,
6637 GLint location,
6638 GLsizei count,
6639 GLboolean transpose,
6640 const GLfloat *value)
6641{
6642 Program *programObject = getProgram(program);
6643 ASSERT(programObject);
6644 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6645}
6646
6647void Context::programUniformMatrix4x2fv(GLuint program,
6648 GLint location,
6649 GLsizei count,
6650 GLboolean transpose,
6651 const GLfloat *value)
6652{
6653 Program *programObject = getProgram(program);
6654 ASSERT(programObject);
6655 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6656}
6657
6658void Context::programUniformMatrix3x4fv(GLuint program,
6659 GLint location,
6660 GLsizei count,
6661 GLboolean transpose,
6662 const GLfloat *value)
6663{
6664 Program *programObject = getProgram(program);
6665 ASSERT(programObject);
6666 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6667}
6668
6669void Context::programUniformMatrix4x3fv(GLuint program,
6670 GLint location,
6671 GLsizei count,
6672 GLboolean transpose,
6673 const GLfloat *value)
6674{
6675 Program *programObject = getProgram(program);
6676 ASSERT(programObject);
6677 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6678}
6679
Jamie Madill81c2e252017-09-09 23:32:46 -04006680void Context::onTextureChange(const Texture *texture)
6681{
6682 // Conservatively assume all textures are dirty.
6683 // TODO(jmadill): More fine-grained update.
6684 mGLState.setObjectDirty(GL_TEXTURE);
6685}
6686
James Darpiniane8a93c62018-01-04 18:02:24 -08006687bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6688{
6689 return mGLState.isCurrentTransformFeedback(tf);
6690}
James Darpiniane8a93c62018-01-04 18:02:24 -08006691
Yunchao Hea336b902017-08-02 16:05:21 +08006692void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6693{
6694 for (int i = 0; i < count; i++)
6695 {
6696 pipelines[i] = createProgramPipeline();
6697 }
6698}
6699
6700void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6701{
6702 for (int i = 0; i < count; i++)
6703 {
6704 if (pipelines[i] != 0)
6705 {
6706 deleteProgramPipeline(pipelines[i]);
6707 }
6708 }
6709}
6710
6711GLboolean Context::isProgramPipeline(GLuint pipeline)
6712{
6713 if (pipeline == 0)
6714 {
6715 return GL_FALSE;
6716 }
6717
6718 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6719}
6720
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006721void Context::finishFenceNV(GLuint fence)
6722{
6723 FenceNV *fenceObject = getFenceNV(fence);
6724
6725 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006726 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006727}
6728
6729void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6730{
6731 FenceNV *fenceObject = getFenceNV(fence);
6732
6733 ASSERT(fenceObject && fenceObject->isSet());
6734
6735 switch (pname)
6736 {
6737 case GL_FENCE_STATUS_NV:
6738 {
6739 // GL_NV_fence spec:
6740 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6741 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6742 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6743 GLboolean status = GL_TRUE;
6744 if (fenceObject->getStatus() != GL_TRUE)
6745 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006746 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006747 }
6748 *params = status;
6749 break;
6750 }
6751
6752 case GL_FENCE_CONDITION_NV:
6753 {
6754 *params = static_cast<GLint>(fenceObject->getCondition());
6755 break;
6756 }
6757
6758 default:
6759 UNREACHABLE();
6760 }
6761}
6762
6763void Context::getTranslatedShaderSource(GLuint shader,
6764 GLsizei bufsize,
6765 GLsizei *length,
6766 GLchar *source)
6767{
6768 Shader *shaderObject = getShader(shader);
6769 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006770 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006771}
6772
6773void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6774{
6775 Program *programObject = getProgram(program);
6776 ASSERT(programObject);
6777
6778 programObject->getUniformfv(this, location, params);
6779}
6780
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006781void Context::getnUniformfvRobust(GLuint program,
6782 GLint location,
6783 GLsizei bufSize,
6784 GLsizei *length,
6785 GLfloat *params)
6786{
6787 UNIMPLEMENTED();
6788}
6789
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006790void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6791{
6792 Program *programObject = getProgram(program);
6793 ASSERT(programObject);
6794
6795 programObject->getUniformiv(this, location, params);
6796}
6797
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006798void Context::getnUniformivRobust(GLuint program,
6799 GLint location,
6800 GLsizei bufSize,
6801 GLsizei *length,
6802 GLint *params)
6803{
6804 UNIMPLEMENTED();
6805}
6806
6807void Context::getnUniformuivRobust(GLuint program,
6808 GLint location,
6809 GLsizei bufSize,
6810 GLsizei *length,
6811 GLuint *params)
6812{
6813 UNIMPLEMENTED();
6814}
6815
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006816GLboolean Context::isFenceNV(GLuint fence)
6817{
6818 FenceNV *fenceObject = getFenceNV(fence);
6819
6820 if (fenceObject == nullptr)
6821 {
6822 return GL_FALSE;
6823 }
6824
6825 // GL_NV_fence spec:
6826 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6827 // existing fence.
6828 return fenceObject->isSet();
6829}
6830
6831void Context::readnPixels(GLint x,
6832 GLint y,
6833 GLsizei width,
6834 GLsizei height,
6835 GLenum format,
6836 GLenum type,
6837 GLsizei bufSize,
6838 void *data)
6839{
6840 return readPixels(x, y, width, height, format, type, data);
6841}
6842
Jamie Madill007530e2017-12-28 14:27:04 -05006843void Context::setFenceNV(GLuint fence, GLenum condition)
6844{
6845 ASSERT(condition == GL_ALL_COMPLETED_NV);
6846
6847 FenceNV *fenceObject = getFenceNV(fence);
6848 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006849 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006850}
6851
6852GLboolean Context::testFenceNV(GLuint fence)
6853{
6854 FenceNV *fenceObject = getFenceNV(fence);
6855
6856 ASSERT(fenceObject != nullptr);
6857 ASSERT(fenceObject->isSet() == GL_TRUE);
6858
6859 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006860 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006861 if (error.isError())
6862 {
6863 handleError(error);
6864 return GL_TRUE;
6865 }
6866
6867 return result;
6868}
6869
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006870void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006871{
6872 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006873 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006874 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006875}
6876
Jamie Madillfa920eb2018-01-04 11:45:50 -05006877void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006878{
6879 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006880 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006881 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6882}
6883
Jamie Madillfa920eb2018-01-04 11:45:50 -05006884void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6885{
6886 UNIMPLEMENTED();
6887}
6888
Jamie Madill5b772312018-03-08 20:28:32 -05006889bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6890{
6891 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6892 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6893 // to the fact that it is stored internally as a float, and so would require conversion
6894 // if returned from Context::getIntegerv. Since this conversion is already implemented
6895 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6896 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6897 // application.
6898 switch (pname)
6899 {
6900 case GL_COMPRESSED_TEXTURE_FORMATS:
6901 {
6902 *type = GL_INT;
6903 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6904 return true;
6905 }
6906 case GL_SHADER_BINARY_FORMATS:
6907 {
6908 *type = GL_INT;
6909 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6910 return true;
6911 }
6912
6913 case GL_MAX_VERTEX_ATTRIBS:
6914 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6915 case GL_MAX_VARYING_VECTORS:
6916 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6917 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6918 case GL_MAX_TEXTURE_IMAGE_UNITS:
6919 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6920 case GL_MAX_RENDERBUFFER_SIZE:
6921 case GL_NUM_SHADER_BINARY_FORMATS:
6922 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6923 case GL_ARRAY_BUFFER_BINDING:
6924 case GL_FRAMEBUFFER_BINDING:
6925 case GL_RENDERBUFFER_BINDING:
6926 case GL_CURRENT_PROGRAM:
6927 case GL_PACK_ALIGNMENT:
6928 case GL_UNPACK_ALIGNMENT:
6929 case GL_GENERATE_MIPMAP_HINT:
6930 case GL_RED_BITS:
6931 case GL_GREEN_BITS:
6932 case GL_BLUE_BITS:
6933 case GL_ALPHA_BITS:
6934 case GL_DEPTH_BITS:
6935 case GL_STENCIL_BITS:
6936 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6937 case GL_CULL_FACE_MODE:
6938 case GL_FRONT_FACE:
6939 case GL_ACTIVE_TEXTURE:
6940 case GL_STENCIL_FUNC:
6941 case GL_STENCIL_VALUE_MASK:
6942 case GL_STENCIL_REF:
6943 case GL_STENCIL_FAIL:
6944 case GL_STENCIL_PASS_DEPTH_FAIL:
6945 case GL_STENCIL_PASS_DEPTH_PASS:
6946 case GL_STENCIL_BACK_FUNC:
6947 case GL_STENCIL_BACK_VALUE_MASK:
6948 case GL_STENCIL_BACK_REF:
6949 case GL_STENCIL_BACK_FAIL:
6950 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6951 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6952 case GL_DEPTH_FUNC:
6953 case GL_BLEND_SRC_RGB:
6954 case GL_BLEND_SRC_ALPHA:
6955 case GL_BLEND_DST_RGB:
6956 case GL_BLEND_DST_ALPHA:
6957 case GL_BLEND_EQUATION_RGB:
6958 case GL_BLEND_EQUATION_ALPHA:
6959 case GL_STENCIL_WRITEMASK:
6960 case GL_STENCIL_BACK_WRITEMASK:
6961 case GL_STENCIL_CLEAR_VALUE:
6962 case GL_SUBPIXEL_BITS:
6963 case GL_MAX_TEXTURE_SIZE:
6964 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6965 case GL_SAMPLE_BUFFERS:
6966 case GL_SAMPLES:
6967 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6968 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6969 case GL_TEXTURE_BINDING_2D:
6970 case GL_TEXTURE_BINDING_CUBE_MAP:
6971 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6972 {
6973 *type = GL_INT;
6974 *numParams = 1;
6975 return true;
6976 }
6977 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6978 {
6979 if (!getExtensions().packReverseRowOrder)
6980 {
6981 return false;
6982 }
6983 *type = GL_INT;
6984 *numParams = 1;
6985 return true;
6986 }
6987 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6988 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6989 {
6990 if (!getExtensions().textureRectangle)
6991 {
6992 return false;
6993 }
6994 *type = GL_INT;
6995 *numParams = 1;
6996 return true;
6997 }
6998 case GL_MAX_DRAW_BUFFERS_EXT:
6999 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7000 {
7001 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7002 {
7003 return false;
7004 }
7005 *type = GL_INT;
7006 *numParams = 1;
7007 return true;
7008 }
7009 case GL_MAX_VIEWPORT_DIMS:
7010 {
7011 *type = GL_INT;
7012 *numParams = 2;
7013 return true;
7014 }
7015 case GL_VIEWPORT:
7016 case GL_SCISSOR_BOX:
7017 {
7018 *type = GL_INT;
7019 *numParams = 4;
7020 return true;
7021 }
7022 case GL_SHADER_COMPILER:
7023 case GL_SAMPLE_COVERAGE_INVERT:
7024 case GL_DEPTH_WRITEMASK:
7025 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7026 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7027 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7028 // bool-natural
7029 case GL_SAMPLE_COVERAGE:
7030 case GL_SCISSOR_TEST:
7031 case GL_STENCIL_TEST:
7032 case GL_DEPTH_TEST:
7033 case GL_BLEND:
7034 case GL_DITHER:
7035 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7036 {
7037 *type = GL_BOOL;
7038 *numParams = 1;
7039 return true;
7040 }
7041 case GL_COLOR_WRITEMASK:
7042 {
7043 *type = GL_BOOL;
7044 *numParams = 4;
7045 return true;
7046 }
7047 case GL_POLYGON_OFFSET_FACTOR:
7048 case GL_POLYGON_OFFSET_UNITS:
7049 case GL_SAMPLE_COVERAGE_VALUE:
7050 case GL_DEPTH_CLEAR_VALUE:
7051 case GL_LINE_WIDTH:
7052 {
7053 *type = GL_FLOAT;
7054 *numParams = 1;
7055 return true;
7056 }
7057 case GL_ALIASED_LINE_WIDTH_RANGE:
7058 case GL_ALIASED_POINT_SIZE_RANGE:
7059 case GL_DEPTH_RANGE:
7060 {
7061 *type = GL_FLOAT;
7062 *numParams = 2;
7063 return true;
7064 }
7065 case GL_COLOR_CLEAR_VALUE:
7066 case GL_BLEND_COLOR:
7067 {
7068 *type = GL_FLOAT;
7069 *numParams = 4;
7070 return true;
7071 }
7072 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7073 if (!getExtensions().textureFilterAnisotropic)
7074 {
7075 return false;
7076 }
7077 *type = GL_FLOAT;
7078 *numParams = 1;
7079 return true;
7080 case GL_TIMESTAMP_EXT:
7081 if (!getExtensions().disjointTimerQuery)
7082 {
7083 return false;
7084 }
7085 *type = GL_INT_64_ANGLEX;
7086 *numParams = 1;
7087 return true;
7088 case GL_GPU_DISJOINT_EXT:
7089 if (!getExtensions().disjointTimerQuery)
7090 {
7091 return false;
7092 }
7093 *type = GL_INT;
7094 *numParams = 1;
7095 return true;
7096 case GL_COVERAGE_MODULATION_CHROMIUM:
7097 if (!getExtensions().framebufferMixedSamples)
7098 {
7099 return false;
7100 }
7101 *type = GL_INT;
7102 *numParams = 1;
7103 return true;
7104 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7105 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7106 {
7107 return false;
7108 }
7109 *type = GL_INT;
7110 *numParams = 1;
7111 return true;
7112 }
7113
7114 if (getExtensions().debug)
7115 {
7116 switch (pname)
7117 {
7118 case GL_DEBUG_LOGGED_MESSAGES:
7119 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7120 case GL_DEBUG_GROUP_STACK_DEPTH:
7121 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7122 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7123 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7124 case GL_MAX_LABEL_LENGTH:
7125 *type = GL_INT;
7126 *numParams = 1;
7127 return true;
7128
7129 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7130 case GL_DEBUG_OUTPUT:
7131 *type = GL_BOOL;
7132 *numParams = 1;
7133 return true;
7134 }
7135 }
7136
7137 if (getExtensions().multisampleCompatibility)
7138 {
7139 switch (pname)
7140 {
7141 case GL_MULTISAMPLE_EXT:
7142 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7143 *type = GL_BOOL;
7144 *numParams = 1;
7145 return true;
7146 }
7147 }
7148
7149 if (getExtensions().pathRendering)
7150 {
7151 switch (pname)
7152 {
7153 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7154 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7155 *type = GL_FLOAT;
7156 *numParams = 16;
7157 return true;
7158 }
7159 }
7160
7161 if (getExtensions().bindGeneratesResource)
7162 {
7163 switch (pname)
7164 {
7165 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7166 *type = GL_BOOL;
7167 *numParams = 1;
7168 return true;
7169 }
7170 }
7171
7172 if (getExtensions().clientArrays)
7173 {
7174 switch (pname)
7175 {
7176 case GL_CLIENT_ARRAYS_ANGLE:
7177 *type = GL_BOOL;
7178 *numParams = 1;
7179 return true;
7180 }
7181 }
7182
7183 if (getExtensions().sRGBWriteControl)
7184 {
7185 switch (pname)
7186 {
7187 case GL_FRAMEBUFFER_SRGB_EXT:
7188 *type = GL_BOOL;
7189 *numParams = 1;
7190 return true;
7191 }
7192 }
7193
7194 if (getExtensions().robustResourceInitialization &&
7195 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7196 {
7197 *type = GL_BOOL;
7198 *numParams = 1;
7199 return true;
7200 }
7201
7202 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7203 {
7204 *type = GL_BOOL;
7205 *numParams = 1;
7206 return true;
7207 }
7208
jchen1082af6202018-06-22 10:59:52 +08007209 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7210 {
7211 *type = GL_INT;
7212 *numParams = 1;
7213 return true;
7214 }
7215
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007216 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7217 {
7218 *type = GL_INT;
7219 *numParams = 1;
7220 return true;
7221 }
7222
Jamie Madill5b772312018-03-08 20:28:32 -05007223 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7224 switch (pname)
7225 {
7226 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7227 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7228 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7229 {
7230 return false;
7231 }
7232 *type = GL_INT;
7233 *numParams = 1;
7234 return true;
7235
7236 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7237 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7238 {
7239 return false;
7240 }
7241 *type = GL_INT;
7242 *numParams = 1;
7243 return true;
7244
7245 case GL_PROGRAM_BINARY_FORMATS_OES:
7246 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7247 {
7248 return false;
7249 }
7250 *type = GL_INT;
7251 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7252 return true;
7253
7254 case GL_PACK_ROW_LENGTH:
7255 case GL_PACK_SKIP_ROWS:
7256 case GL_PACK_SKIP_PIXELS:
7257 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7258 {
7259 return false;
7260 }
7261 *type = GL_INT;
7262 *numParams = 1;
7263 return true;
7264 case GL_UNPACK_ROW_LENGTH:
7265 case GL_UNPACK_SKIP_ROWS:
7266 case GL_UNPACK_SKIP_PIXELS:
7267 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7268 {
7269 return false;
7270 }
7271 *type = GL_INT;
7272 *numParams = 1;
7273 return true;
7274 case GL_VERTEX_ARRAY_BINDING:
7275 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7276 {
7277 return false;
7278 }
7279 *type = GL_INT;
7280 *numParams = 1;
7281 return true;
7282 case GL_PIXEL_PACK_BUFFER_BINDING:
7283 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7284 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7285 {
7286 return false;
7287 }
7288 *type = GL_INT;
7289 *numParams = 1;
7290 return true;
7291 case GL_MAX_SAMPLES:
7292 {
7293 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7294 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7295 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7296 {
7297 return false;
7298 }
7299 *type = GL_INT;
7300 *numParams = 1;
7301 return true;
7302
7303 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7304 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7305 {
7306 return false;
7307 }
7308 *type = GL_INT;
7309 *numParams = 1;
7310 return true;
7311 }
7312 }
7313
7314 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7315 {
7316 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7317 {
7318 return false;
7319 }
7320 *type = GL_INT;
7321 *numParams = 1;
7322 return true;
7323 }
7324
7325 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7326 {
7327 *type = GL_INT;
7328 *numParams = 1;
7329 return true;
7330 }
7331
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007332 if (getClientVersion() < Version(2, 0))
7333 {
7334 switch (pname)
7335 {
7336 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007337 case GL_CLIENT_ACTIVE_TEXTURE:
7338 case GL_MATRIX_MODE:
7339 case GL_MAX_TEXTURE_UNITS:
7340 case GL_MAX_MODELVIEW_STACK_DEPTH:
7341 case GL_MAX_PROJECTION_STACK_DEPTH:
7342 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007343 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007344 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007345 case GL_VERTEX_ARRAY_STRIDE:
7346 case GL_NORMAL_ARRAY_STRIDE:
7347 case GL_COLOR_ARRAY_STRIDE:
7348 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7349 case GL_VERTEX_ARRAY_SIZE:
7350 case GL_COLOR_ARRAY_SIZE:
7351 case GL_TEXTURE_COORD_ARRAY_SIZE:
7352 case GL_VERTEX_ARRAY_TYPE:
7353 case GL_NORMAL_ARRAY_TYPE:
7354 case GL_COLOR_ARRAY_TYPE:
7355 case GL_TEXTURE_COORD_ARRAY_TYPE:
7356 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7357 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7358 case GL_COLOR_ARRAY_BUFFER_BINDING:
7359 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7360 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7361 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7362 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007363 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007364 case GL_MODELVIEW_STACK_DEPTH:
7365 case GL_PROJECTION_STACK_DEPTH:
7366 case GL_TEXTURE_STACK_DEPTH:
7367 case GL_LOGIC_OP_MODE:
7368 case GL_BLEND_SRC:
7369 case GL_BLEND_DST:
7370 case GL_PERSPECTIVE_CORRECTION_HINT:
7371 case GL_POINT_SMOOTH_HINT:
7372 case GL_LINE_SMOOTH_HINT:
7373 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007374 *type = GL_INT;
7375 *numParams = 1;
7376 return true;
7377 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007378 case GL_FOG_DENSITY:
7379 case GL_FOG_START:
7380 case GL_FOG_END:
7381 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007382 case GL_POINT_SIZE:
7383 case GL_POINT_SIZE_MIN:
7384 case GL_POINT_SIZE_MAX:
7385 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007386 *type = GL_FLOAT;
7387 *numParams = 1;
7388 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007389 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007390 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007391 *type = GL_FLOAT;
7392 *numParams = 2;
7393 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007394 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007395 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007396 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007397 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007398 *type = GL_FLOAT;
7399 *numParams = 4;
7400 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007401 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007402 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007403 *type = GL_FLOAT;
7404 *numParams = 3;
7405 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007406 case GL_MODELVIEW_MATRIX:
7407 case GL_PROJECTION_MATRIX:
7408 case GL_TEXTURE_MATRIX:
7409 *type = GL_FLOAT;
7410 *numParams = 16;
7411 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007412 case GL_LIGHT_MODEL_TWO_SIDE:
7413 *type = GL_BOOL;
7414 *numParams = 1;
7415 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007416 }
7417 }
7418
Jamie Madill5b772312018-03-08 20:28:32 -05007419 if (getClientVersion() < Version(3, 0))
7420 {
7421 return false;
7422 }
7423
7424 // Check for ES3.0+ parameter names
7425 switch (pname)
7426 {
7427 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7428 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7429 case GL_UNIFORM_BUFFER_BINDING:
7430 case GL_TRANSFORM_FEEDBACK_BINDING:
7431 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7432 case GL_COPY_READ_BUFFER_BINDING:
7433 case GL_COPY_WRITE_BUFFER_BINDING:
7434 case GL_SAMPLER_BINDING:
7435 case GL_READ_BUFFER:
7436 case GL_TEXTURE_BINDING_3D:
7437 case GL_TEXTURE_BINDING_2D_ARRAY:
7438 case GL_MAX_3D_TEXTURE_SIZE:
7439 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7440 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7441 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7442 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7443 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7444 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7445 case GL_MAX_VARYING_COMPONENTS:
7446 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7447 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7448 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7449 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7450 case GL_NUM_EXTENSIONS:
7451 case GL_MAJOR_VERSION:
7452 case GL_MINOR_VERSION:
7453 case GL_MAX_ELEMENTS_INDICES:
7454 case GL_MAX_ELEMENTS_VERTICES:
7455 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7456 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7457 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7458 case GL_UNPACK_IMAGE_HEIGHT:
7459 case GL_UNPACK_SKIP_IMAGES:
7460 {
7461 *type = GL_INT;
7462 *numParams = 1;
7463 return true;
7464 }
7465
7466 case GL_MAX_ELEMENT_INDEX:
7467 case GL_MAX_UNIFORM_BLOCK_SIZE:
7468 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7469 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7470 case GL_MAX_SERVER_WAIT_TIMEOUT:
7471 {
7472 *type = GL_INT_64_ANGLEX;
7473 *numParams = 1;
7474 return true;
7475 }
7476
7477 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7478 case GL_TRANSFORM_FEEDBACK_PAUSED:
7479 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7480 case GL_RASTERIZER_DISCARD:
7481 {
7482 *type = GL_BOOL;
7483 *numParams = 1;
7484 return true;
7485 }
7486
7487 case GL_MAX_TEXTURE_LOD_BIAS:
7488 {
7489 *type = GL_FLOAT;
7490 *numParams = 1;
7491 return true;
7492 }
7493 }
7494
7495 if (getExtensions().requestExtension)
7496 {
7497 switch (pname)
7498 {
7499 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7500 *type = GL_INT;
7501 *numParams = 1;
7502 return true;
7503 }
7504 }
7505
7506 if (getClientVersion() < Version(3, 1))
7507 {
7508 return false;
7509 }
7510
7511 switch (pname)
7512 {
7513 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7514 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7515 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7516 case GL_MAX_FRAMEBUFFER_WIDTH:
7517 case GL_MAX_FRAMEBUFFER_HEIGHT:
7518 case GL_MAX_FRAMEBUFFER_SAMPLES:
7519 case GL_MAX_SAMPLE_MASK_WORDS:
7520 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7521 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7522 case GL_MAX_INTEGER_SAMPLES:
7523 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7524 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7525 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7526 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7527 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7528 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7529 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7530 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7531 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7532 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7533 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7534 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7535 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7536 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7537 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7538 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7539 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7540 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7541 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7542 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7543 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7544 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7545 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7546 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7547 case GL_MAX_UNIFORM_LOCATIONS:
7548 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7549 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7550 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7551 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7552 case GL_MAX_IMAGE_UNITS:
7553 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7554 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7555 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7556 case GL_SHADER_STORAGE_BUFFER_BINDING:
7557 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7558 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007559 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007560 *type = GL_INT;
7561 *numParams = 1;
7562 return true;
7563 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7564 *type = GL_INT_64_ANGLEX;
7565 *numParams = 1;
7566 return true;
7567 case GL_SAMPLE_MASK:
7568 *type = GL_BOOL;
7569 *numParams = 1;
7570 return true;
7571 }
7572
7573 if (getExtensions().geometryShader)
7574 {
7575 switch (pname)
7576 {
7577 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7578 case GL_LAYER_PROVOKING_VERTEX_EXT:
7579 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7580 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7581 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7582 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7583 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7584 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7585 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7586 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7587 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7588 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7589 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7590 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7591 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7592 *type = GL_INT;
7593 *numParams = 1;
7594 return true;
7595 }
7596 }
7597
7598 return false;
7599}
7600
7601bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7602{
7603 if (getClientVersion() < Version(3, 0))
7604 {
7605 return false;
7606 }
7607
7608 switch (target)
7609 {
7610 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7611 case GL_UNIFORM_BUFFER_BINDING:
7612 {
7613 *type = GL_INT;
7614 *numParams = 1;
7615 return true;
7616 }
7617 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7618 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7619 case GL_UNIFORM_BUFFER_START:
7620 case GL_UNIFORM_BUFFER_SIZE:
7621 {
7622 *type = GL_INT_64_ANGLEX;
7623 *numParams = 1;
7624 return true;
7625 }
7626 }
7627
7628 if (getClientVersion() < Version(3, 1))
7629 {
7630 return false;
7631 }
7632
7633 switch (target)
7634 {
7635 case GL_IMAGE_BINDING_LAYERED:
7636 {
7637 *type = GL_BOOL;
7638 *numParams = 1;
7639 return true;
7640 }
7641 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7642 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7643 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7644 case GL_SHADER_STORAGE_BUFFER_BINDING:
7645 case GL_VERTEX_BINDING_BUFFER:
7646 case GL_VERTEX_BINDING_DIVISOR:
7647 case GL_VERTEX_BINDING_OFFSET:
7648 case GL_VERTEX_BINDING_STRIDE:
7649 case GL_SAMPLE_MASK_VALUE:
7650 case GL_IMAGE_BINDING_NAME:
7651 case GL_IMAGE_BINDING_LEVEL:
7652 case GL_IMAGE_BINDING_LAYER:
7653 case GL_IMAGE_BINDING_ACCESS:
7654 case GL_IMAGE_BINDING_FORMAT:
7655 {
7656 *type = GL_INT;
7657 *numParams = 1;
7658 return true;
7659 }
7660 case GL_ATOMIC_COUNTER_BUFFER_START:
7661 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7662 case GL_SHADER_STORAGE_BUFFER_START:
7663 case GL_SHADER_STORAGE_BUFFER_SIZE:
7664 {
7665 *type = GL_INT_64_ANGLEX;
7666 *numParams = 1;
7667 return true;
7668 }
7669 }
7670
7671 return false;
7672}
7673
7674Program *Context::getProgram(GLuint handle) const
7675{
7676 return mState.mShaderPrograms->getProgram(handle);
7677}
7678
7679Shader *Context::getShader(GLuint handle) const
7680{
7681 return mState.mShaderPrograms->getShader(handle);
7682}
7683
7684bool Context::isTextureGenerated(GLuint texture) const
7685{
7686 return mState.mTextures->isHandleGenerated(texture);
7687}
7688
Jamie Madill5b772312018-03-08 20:28:32 -05007689bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7690{
7691 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7692}
7693
7694bool Context::isFramebufferGenerated(GLuint framebuffer) const
7695{
7696 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7697}
7698
7699bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7700{
7701 return mState.mPipelines->isHandleGenerated(pipeline);
7702}
7703
7704bool Context::usingDisplayTextureShareGroup() const
7705{
7706 return mDisplayTextureShareGroup;
7707}
7708
7709GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7710{
7711 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7712 internalformat == GL_DEPTH_STENCIL
7713 ? GL_DEPTH24_STENCIL8
7714 : internalformat;
7715}
7716
jchen1082af6202018-06-22 10:59:52 +08007717void Context::maxShaderCompilerThreads(GLuint count)
7718{
jchen107ae70d82018-07-06 13:47:01 +08007719 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08007720 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007721 // A count of zero specifies a request for no parallel compiling or linking.
7722 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7723 {
7724 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7725 }
7726 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007727}
7728
Jamie Madill2eb65032018-07-30 10:25:57 -04007729bool Context::isGLES1() const
7730{
7731 return mState.getClientVersion() < Version(2, 0);
7732}
7733
Jamie Madilla11819d2018-07-30 10:26:01 -04007734void Context::onSubjectStateChange(const Context *context,
7735 angle::SubjectIndex index,
7736 angle::SubjectMessage message)
7737{
Jamie Madilla11819d2018-07-30 10:26:01 -04007738 switch (index)
7739 {
7740 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007741 switch (message)
7742 {
7743 case angle::SubjectMessage::CONTENTS_CHANGED:
7744 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
7745 mStateCache.onVertexArrayBufferContentsChange(this);
7746 break;
7747 case angle::SubjectMessage::RESOURCE_MAPPED:
7748 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7749 case angle::SubjectMessage::BINDING_CHANGED:
7750 mStateCache.onVertexArrayBufferStateChange(this);
7751 break;
7752 default:
7753 break;
7754 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007755 break;
7756
7757 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007758 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7759 {
7760 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
7761 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007762 break;
7763
7764 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007765 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7766 {
7767 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
7768 }
7769 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04007770 break;
7771
7772 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04007773 if (index < kTextureMaxSubjectIndex)
7774 {
7775 mGLState.onActiveTextureStateChange(index);
Jamie Madilld84b6732018-09-06 15:54:35 -04007776 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007777 }
Jamie Madille25b8002018-09-20 13:39:49 -04007778 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04007779 {
Jamie Madill6d32cef2018-08-14 02:34:28 -04007780 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04007781 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007782 }
Jamie Madille25b8002018-09-20 13:39:49 -04007783 else
7784 {
7785 ASSERT(index < kSamplerMaxSubjectIndex);
7786 mGLState.setSamplerDirty(index - kSampler0SubjectIndex);
7787 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007788 break;
7789 }
7790}
7791
Jamie Madill6b873dd2018-07-12 23:56:30 -04007792// ErrorSet implementation.
7793ErrorSet::ErrorSet(Context *context) : mContext(context)
7794{
7795}
7796
7797ErrorSet::~ErrorSet() = default;
7798
Jamie Madill306b6c12018-07-27 08:12:49 -04007799void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007800{
7801 // This internal enum is used to filter internal errors that are already handled.
7802 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7803 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7804 {
7805 return;
7806 }
7807
7808 if (ANGLE_UNLIKELY(error.isError()))
7809 {
7810 GLenum code = error.getCode();
7811 mErrors.insert(code);
7812 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7813 {
7814 mContext->markContextLost();
7815 }
7816
7817 ASSERT(!error.getMessage().empty());
7818 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7819 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7820 error.getMessage());
7821 }
7822}
7823
7824bool ErrorSet::empty() const
7825{
7826 return mErrors.empty();
7827}
7828
7829GLenum ErrorSet::popError()
7830{
7831 ASSERT(!empty());
7832 GLenum error = *mErrors.begin();
7833 mErrors.erase(mErrors.begin());
7834 return error;
7835}
Jamie Madilldc358af2018-07-31 11:22:13 -04007836
7837// StateCache implementation.
Jamie Madill16e28fd2018-09-12 11:03:05 -04007838StateCache::StateCache(Context *context)
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007839 : mCachedHasAnyEnabledClientAttrib(false),
7840 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04007841 mCachedInstancedVertexElementLimit(0),
7842 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madilldc358af2018-07-31 11:22:13 -04007843{
Jamie Madill16e28fd2018-09-12 11:03:05 -04007844 updateValidDrawModes(context);
Jamie Madilldc358af2018-07-31 11:22:13 -04007845}
7846
7847StateCache::~StateCache() = default;
7848
7849void StateCache::updateActiveAttribsMask(Context *context)
7850{
7851 bool isGLES1 = context->isGLES1();
7852 const State &glState = context->getGLState();
7853
7854 if (!isGLES1 && !glState.getProgram())
7855 {
7856 mCachedActiveBufferedAttribsMask = AttributesMask();
7857 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04007858 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04007859 return;
7860 }
7861
7862 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7863 : glState.getProgram()->getActiveAttribLocationsMask();
7864
7865 const VertexArray *vao = glState.getVertexArray();
7866 ASSERT(vao);
7867
7868 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7869 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04007870 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007871
Jamie Madill0a17e482018-08-31 17:19:11 -04007872 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
7873 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04007874 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007875 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7876}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007877
7878void StateCache::updateVertexElementLimits(Context *context)
7879{
7880 const VertexArray *vao = context->getGLState().getVertexArray();
7881
7882 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7883 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7884
7885 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
7886 // If there are no buffered attributes then we should not limit the draw call count.
7887 if (!vao || !mCachedActiveBufferedAttribsMask.any())
7888 {
7889 return;
7890 }
7891
7892 const auto &vertexAttribs = vao->getVertexAttributes();
7893 const auto &vertexBindings = vao->getVertexBindings();
7894
7895 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
7896 {
7897 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
7898 ASSERT(attrib.enabled);
7899
7900 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
7901 ASSERT(context->isGLES1() ||
7902 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
7903
7904 GLint64 limit = attrib.getCachedElementLimit();
7905 if (binding.getDivisor() > 0)
7906 {
7907 mCachedInstancedVertexElementLimit =
7908 std::min(mCachedInstancedVertexElementLimit, limit);
7909 }
7910 else
7911 {
7912 mCachedNonInstancedVertexElementLimit =
7913 std::min(mCachedNonInstancedVertexElementLimit, limit);
7914 }
7915 }
7916}
Jamie Madillc43cdad2018-08-08 15:49:25 -04007917
Jamie Madilld84b6732018-09-06 15:54:35 -04007918void StateCache::updateBasicDrawStatesError()
7919{
7920 mCachedBasicDrawStatesError = kInvalidPointer;
7921}
7922
7923intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
7924{
7925 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
7926 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
7927 return mCachedBasicDrawStatesError;
7928}
7929
Jamie Madillc43cdad2018-08-08 15:49:25 -04007930void StateCache::onVertexArrayBindingChange(Context *context)
7931{
7932 updateActiveAttribsMask(context);
7933 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007934 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007935}
7936
7937void StateCache::onProgramExecutableChange(Context *context)
7938{
7939 updateActiveAttribsMask(context);
7940 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007941 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04007942 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04007943}
7944
Jamie Madilld84b6732018-09-06 15:54:35 -04007945void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04007946{
7947 updateVertexElementLimits(context);
7948}
7949
Jamie Madilld84b6732018-09-06 15:54:35 -04007950void StateCache::onVertexArrayBufferContentsChange(Context *context)
7951{
7952 updateVertexElementLimits(context);
7953 updateBasicDrawStatesError();
7954}
7955
Jamie Madillc43cdad2018-08-08 15:49:25 -04007956void StateCache::onVertexArrayStateChange(Context *context)
7957{
7958 updateActiveAttribsMask(context);
7959 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007960 updateBasicDrawStatesError();
7961}
7962
7963void StateCache::onVertexArrayBufferStateChange(Context *context)
7964{
7965 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007966}
7967
7968void StateCache::onGLES1ClientStateChange(Context *context)
7969{
7970 updateActiveAttribsMask(context);
7971}
Jamie Madilld84b6732018-09-06 15:54:35 -04007972
7973void StateCache::onDrawFramebufferChange(Context *context)
7974{
7975 updateBasicDrawStatesError();
7976}
7977
7978void StateCache::onContextCapChange(Context *context)
7979{
7980 updateBasicDrawStatesError();
7981}
7982
7983void StateCache::onStencilStateChange(Context *context)
7984{
7985 updateBasicDrawStatesError();
7986}
7987
7988void StateCache::onDefaultVertexAttributeChange(Context *context)
7989{
7990 updateBasicDrawStatesError();
7991}
7992
7993void StateCache::onActiveTextureChange(Context *context)
7994{
7995 updateBasicDrawStatesError();
7996}
7997
7998void StateCache::onQueryChange(Context *context)
7999{
8000 updateBasicDrawStatesError();
8001}
8002
8003void StateCache::onTransformFeedbackChange(Context *context)
8004{
8005 updateBasicDrawStatesError();
8006}
8007
8008void StateCache::onUniformBufferStateChange(Context *context)
8009{
8010 updateBasicDrawStatesError();
8011}
8012
8013void StateCache::onBufferBindingChange(Context *context)
8014{
8015 updateBasicDrawStatesError();
8016}
Jamie Madill526a6f62018-09-12 11:03:05 -04008017
8018void StateCache::updateValidDrawModes(Context *context)
8019{
8020 Program *program = context->getGLState().getProgram();
8021 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8022 {
8023 mCachedValidDrawModes = {{
8024 true, /* Points */
8025 true, /* Lines */
8026 true, /* LineLoop */
8027 true, /* LineStrip */
8028 true, /* Triangles */
8029 true, /* TriangleStrip */
8030 true, /* TriangleFan */
8031 false, /* LinesAdjacency */
8032 false, /* LineStripAdjacency */
8033 false, /* TrianglesAdjacency */
8034 false, /* TriangleStripAdjacency */
8035 false, /* InvalidEnum */
8036 }};
8037 }
8038 else
8039 {
8040 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8041
8042 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
8043
8044 mCachedValidDrawModes = {{
8045 gsMode == PrimitiveMode::Points, /* Points */
8046 gsMode == PrimitiveMode::Lines, /* Lines */
8047 gsMode == PrimitiveMode::Lines, /* LineLoop */
8048 gsMode == PrimitiveMode::Lines, /* LineStrip */
8049 gsMode == PrimitiveMode::Triangles, /* Triangles */
8050 gsMode == PrimitiveMode::Triangles, /* TriangleStrip */
8051 gsMode == PrimitiveMode::Triangles, /* TriangleFan */
8052 gsMode == PrimitiveMode::LinesAdjacency, /* LinesAdjacency */
8053 gsMode == PrimitiveMode::LinesAdjacency, /* LineStripAdjacency */
8054 gsMode == PrimitiveMode::TrianglesAdjacency, /* TrianglesAdjacency */
8055 gsMode == PrimitiveMode::TrianglesAdjacency, /* TriangleStripAdjacency */
8056 false, /* InvalidEnum */
8057 }};
8058 }
8059}
Jamie Madillc29968b2016-01-20 11:17:23 -05008060} // namespace gl