blob: 68fa8424eb3636821d1b30a3064f0448aceedaa8 [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
Geoff Lang38f24ee2018-10-01 13:04:59 -04001606 // GL_ANGLE_request_extension
1607 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
1608 *params = static_cast<GLint>(mRequestableExtensionStrings.size());
1609 break;
1610
Jamie Madill231c7f52017-04-26 13:45:37 -04001611 // GL_KHR_debug
1612 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1613 *params = mExtensions.maxDebugMessageLength;
1614 break;
1615 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1616 *params = mExtensions.maxDebugLoggedMessages;
1617 break;
1618 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1619 *params = mExtensions.maxDebugGroupStackDepth;
1620 break;
1621 case GL_MAX_LABEL_LENGTH:
1622 *params = mExtensions.maxLabelLength;
1623 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001624
Martin Radeve5285d22017-07-14 16:23:53 +03001625 // GL_ANGLE_multiview
1626 case GL_MAX_VIEWS_ANGLE:
1627 *params = mExtensions.maxViews;
1628 break;
1629
Jamie Madill231c7f52017-04-26 13:45:37 -04001630 // GL_EXT_disjoint_timer_query
1631 case GL_GPU_DISJOINT_EXT:
1632 *params = mImplementation->getGPUDisjoint();
1633 break;
1634 case GL_MAX_FRAMEBUFFER_WIDTH:
1635 *params = mCaps.maxFramebufferWidth;
1636 break;
1637 case GL_MAX_FRAMEBUFFER_HEIGHT:
1638 *params = mCaps.maxFramebufferHeight;
1639 break;
1640 case GL_MAX_FRAMEBUFFER_SAMPLES:
1641 *params = mCaps.maxFramebufferSamples;
1642 break;
1643 case GL_MAX_SAMPLE_MASK_WORDS:
1644 *params = mCaps.maxSampleMaskWords;
1645 break;
1646 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1647 *params = mCaps.maxColorTextureSamples;
1648 break;
1649 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1650 *params = mCaps.maxDepthTextureSamples;
1651 break;
1652 case GL_MAX_INTEGER_SAMPLES:
1653 *params = mCaps.maxIntegerSamples;
1654 break;
1655 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1656 *params = mCaps.maxVertexAttribRelativeOffset;
1657 break;
1658 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1659 *params = mCaps.maxVertexAttribBindings;
1660 break;
1661 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1662 *params = mCaps.maxVertexAttribStride;
1663 break;
1664 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001665 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001666 break;
1667 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001668 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001669 break;
1670 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001671 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001672 break;
1673 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001674 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001675 break;
1676 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001677 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001678 break;
1679 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001680 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001681 break;
1682 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001683 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001684 break;
1685 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001686 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001687 break;
1688 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1689 *params = mCaps.minProgramTextureGatherOffset;
1690 break;
1691 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1692 *params = mCaps.maxProgramTextureGatherOffset;
1693 break;
1694 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1695 *params = mCaps.maxComputeWorkGroupInvocations;
1696 break;
1697 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001698 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001699 break;
1700 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001701 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001702 break;
1703 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1704 *params = mCaps.maxComputeSharedMemorySize;
1705 break;
1706 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001707 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001708 break;
1709 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001710 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001711 break;
1712 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001713 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001714 break;
1715 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001716 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001717 break;
1718 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001719 *params =
1720 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001721 break;
1722 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001723 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001724 break;
1725 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1726 *params = mCaps.maxCombinedShaderOutputResources;
1727 break;
1728 case GL_MAX_UNIFORM_LOCATIONS:
1729 *params = mCaps.maxUniformLocations;
1730 break;
1731 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1732 *params = mCaps.maxAtomicCounterBufferBindings;
1733 break;
1734 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1735 *params = mCaps.maxAtomicCounterBufferSize;
1736 break;
1737 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1738 *params = mCaps.maxCombinedAtomicCounterBuffers;
1739 break;
1740 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1741 *params = mCaps.maxCombinedAtomicCounters;
1742 break;
1743 case GL_MAX_IMAGE_UNITS:
1744 *params = mCaps.maxImageUnits;
1745 break;
1746 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1747 *params = mCaps.maxCombinedImageUniforms;
1748 break;
1749 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1750 *params = mCaps.maxShaderStorageBufferBindings;
1751 break;
1752 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1753 *params = mCaps.maxCombinedShaderStorageBlocks;
1754 break;
1755 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1756 *params = mCaps.shaderStorageBufferOffsetAlignment;
1757 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001758
1759 // GL_EXT_geometry_shader
1760 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1761 *params = mCaps.maxFramebufferLayers;
1762 break;
1763 case GL_LAYER_PROVOKING_VERTEX_EXT:
1764 *params = mCaps.layerProvokingVertex;
1765 break;
1766 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001767 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001768 break;
1769 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001770 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001771 break;
1772 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001773 *params =
1774 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001775 break;
1776 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1777 *params = mCaps.maxGeometryInputComponents;
1778 break;
1779 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1780 *params = mCaps.maxGeometryOutputComponents;
1781 break;
1782 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1783 *params = mCaps.maxGeometryOutputVertices;
1784 break;
1785 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1786 *params = mCaps.maxGeometryTotalOutputComponents;
1787 break;
1788 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1789 *params = mCaps.maxGeometryShaderInvocations;
1790 break;
1791 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001792 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001793 break;
1794 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001795 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001796 break;
1797 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001798 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001799 break;
1800 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001801 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001802 break;
1803 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001804 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001805 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001806 // GLES1 emulation: Caps queries
1807 case GL_MAX_TEXTURE_UNITS:
1808 *params = mCaps.maxMultitextureUnits;
1809 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001810 case GL_MAX_MODELVIEW_STACK_DEPTH:
1811 *params = mCaps.maxModelviewMatrixStackDepth;
1812 break;
1813 case GL_MAX_PROJECTION_STACK_DEPTH:
1814 *params = mCaps.maxProjectionMatrixStackDepth;
1815 break;
1816 case GL_MAX_TEXTURE_STACK_DEPTH:
1817 *params = mCaps.maxTextureMatrixStackDepth;
1818 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001819 case GL_MAX_LIGHTS:
1820 *params = mCaps.maxLights;
1821 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001822 case GL_MAX_CLIP_PLANES:
1823 *params = mCaps.maxClipPlanes;
1824 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001825 // GLES1 emulation: Vertex attribute queries
1826 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1827 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1828 case GL_COLOR_ARRAY_BUFFER_BINDING:
1829 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1830 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1831 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1832 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1833 break;
1834 case GL_VERTEX_ARRAY_STRIDE:
1835 case GL_NORMAL_ARRAY_STRIDE:
1836 case GL_COLOR_ARRAY_STRIDE:
1837 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1838 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1839 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1840 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1841 break;
1842 case GL_VERTEX_ARRAY_SIZE:
1843 case GL_COLOR_ARRAY_SIZE:
1844 case GL_TEXTURE_COORD_ARRAY_SIZE:
1845 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1846 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1847 break;
1848 case GL_VERTEX_ARRAY_TYPE:
1849 case GL_COLOR_ARRAY_TYPE:
1850 case GL_NORMAL_ARRAY_TYPE:
1851 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1852 case GL_TEXTURE_COORD_ARRAY_TYPE:
1853 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1854 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1855 break;
1856
jchen1082af6202018-06-22 10:59:52 +08001857 // GL_KHR_parallel_shader_compile
1858 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1859 *params = mGLState.getMaxShaderCompilerThreads();
1860 break;
1861
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001862 // GL_EXT_blend_func_extended
1863 case GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT:
1864 *params = mExtensions.maxDualSourceDrawBuffers;
1865 break;
1866
Jamie Madill231c7f52017-04-26 13:45:37 -04001867 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001868 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001869 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001870 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001871}
1872
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001873void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001874{
Shannon Woods53a94a82014-06-24 15:20:36 -04001875 // Queries about context capabilities and maximums are answered by Context.
1876 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001877 switch (pname)
1878 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001879 case GL_MAX_ELEMENT_INDEX:
1880 *params = mCaps.maxElementIndex;
1881 break;
1882 case GL_MAX_UNIFORM_BLOCK_SIZE:
1883 *params = mCaps.maxUniformBlockSize;
1884 break;
1885 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001886 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001887 break;
1888 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001889 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001890 break;
1891 case GL_MAX_SERVER_WAIT_TIMEOUT:
1892 *params = mCaps.maxServerWaitTimeout;
1893 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001894
Jamie Madill231c7f52017-04-26 13:45:37 -04001895 // GL_EXT_disjoint_timer_query
1896 case GL_TIMESTAMP_EXT:
1897 *params = mImplementation->getTimestamp();
1898 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001899
Jamie Madill231c7f52017-04-26 13:45:37 -04001900 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1901 *params = mCaps.maxShaderStorageBlockSize;
1902 break;
1903 default:
1904 UNREACHABLE();
1905 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001906 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001907}
1908
Geoff Lang70d0f492015-12-10 17:45:46 -05001909void Context::getPointerv(GLenum pname, void **params) const
1910{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001911 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001912}
1913
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001914void Context::getPointervRobustANGLERobust(GLenum pname,
1915 GLsizei bufSize,
1916 GLsizei *length,
1917 void **params)
1918{
1919 UNIMPLEMENTED();
1920}
1921
Martin Radev66fb8202016-07-28 11:45:20 +03001922void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001923{
Shannon Woods53a94a82014-06-24 15:20:36 -04001924 // Queries about context capabilities and maximums are answered by Context.
1925 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001926
1927 GLenum nativeType;
1928 unsigned int numParams;
1929 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1930 ASSERT(queryStatus);
1931
1932 if (nativeType == GL_INT)
1933 {
1934 switch (target)
1935 {
1936 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1937 ASSERT(index < 3u);
1938 *data = mCaps.maxComputeWorkGroupCount[index];
1939 break;
1940 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1941 ASSERT(index < 3u);
1942 *data = mCaps.maxComputeWorkGroupSize[index];
1943 break;
1944 default:
1945 mGLState.getIntegeri_v(target, index, data);
1946 }
1947 }
1948 else
1949 {
1950 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1951 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001952}
1953
Brandon Jones59770802018-04-02 13:18:42 -07001954void Context::getIntegeri_vRobust(GLenum target,
1955 GLuint index,
1956 GLsizei bufSize,
1957 GLsizei *length,
1958 GLint *data)
1959{
1960 getIntegeri_v(target, index, data);
1961}
1962
Martin Radev66fb8202016-07-28 11:45:20 +03001963void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001964{
Shannon Woods53a94a82014-06-24 15:20:36 -04001965 // Queries about context capabilities and maximums are answered by Context.
1966 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001967
1968 GLenum nativeType;
1969 unsigned int numParams;
1970 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1971 ASSERT(queryStatus);
1972
1973 if (nativeType == GL_INT_64_ANGLEX)
1974 {
1975 mGLState.getInteger64i_v(target, index, data);
1976 }
1977 else
1978 {
1979 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1980 }
1981}
1982
Brandon Jones59770802018-04-02 13:18:42 -07001983void Context::getInteger64i_vRobust(GLenum target,
1984 GLuint index,
1985 GLsizei bufSize,
1986 GLsizei *length,
1987 GLint64 *data)
1988{
1989 getInteger64i_v(target, index, data);
1990}
1991
Martin Radev66fb8202016-07-28 11:45:20 +03001992void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1993{
1994 // Queries about context capabilities and maximums are answered by Context.
1995 // Queries about current GL state values are answered by State.
1996
1997 GLenum nativeType;
1998 unsigned int numParams;
1999 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
2000 ASSERT(queryStatus);
2001
2002 if (nativeType == GL_BOOL)
2003 {
2004 mGLState.getBooleani_v(target, index, data);
2005 }
2006 else
2007 {
2008 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
2009 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04002010}
2011
Brandon Jones59770802018-04-02 13:18:42 -07002012void Context::getBooleani_vRobust(GLenum target,
2013 GLuint index,
2014 GLsizei bufSize,
2015 GLsizei *length,
2016 GLboolean *data)
2017{
2018 getBooleani_v(target, index, data);
2019}
2020
Corentin Wallez336129f2017-10-17 15:55:40 -04002021void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002022{
2023 Buffer *buffer = mGLState.getTargetBuffer(target);
2024 QueryBufferParameteriv(buffer, pname, params);
2025}
2026
Brandon Jones59770802018-04-02 13:18:42 -07002027void Context::getBufferParameterivRobust(BufferBinding target,
2028 GLenum pname,
2029 GLsizei bufSize,
2030 GLsizei *length,
2031 GLint *params)
2032{
2033 getBufferParameteriv(target, pname, params);
2034}
2035
He Yunchao010e4db2017-03-03 14:22:06 +08002036void Context::getFramebufferAttachmentParameteriv(GLenum target,
2037 GLenum attachment,
2038 GLenum pname,
2039 GLint *params)
2040{
2041 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002042 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002043}
2044
Brandon Jones59770802018-04-02 13:18:42 -07002045void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2046 GLenum attachment,
2047 GLenum pname,
2048 GLsizei bufSize,
2049 GLsizei *length,
2050 GLint *params)
2051{
2052 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2053}
2054
He Yunchao010e4db2017-03-03 14:22:06 +08002055void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2056{
2057 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2058 QueryRenderbufferiv(this, renderbuffer, pname, params);
2059}
2060
Brandon Jones59770802018-04-02 13:18:42 -07002061void Context::getRenderbufferParameterivRobust(GLenum target,
2062 GLenum pname,
2063 GLsizei bufSize,
2064 GLsizei *length,
2065 GLint *params)
2066{
2067 getRenderbufferParameteriv(target, pname, params);
2068}
2069
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002070void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002071{
2072 Texture *texture = getTargetTexture(target);
2073 QueryTexParameterfv(texture, pname, params);
2074}
2075
Brandon Jones59770802018-04-02 13:18:42 -07002076void Context::getTexParameterfvRobust(TextureType target,
2077 GLenum pname,
2078 GLsizei bufSize,
2079 GLsizei *length,
2080 GLfloat *params)
2081{
2082 getTexParameterfv(target, pname, params);
2083}
2084
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002085void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002086{
2087 Texture *texture = getTargetTexture(target);
2088 QueryTexParameteriv(texture, pname, params);
2089}
Jiajia Qin5451d532017-11-16 17:16:34 +08002090
Brandon Jones59770802018-04-02 13:18:42 -07002091void Context::getTexParameterivRobust(TextureType target,
2092 GLenum pname,
2093 GLsizei bufSize,
2094 GLsizei *length,
2095 GLint *params)
2096{
2097 getTexParameteriv(target, pname, params);
2098}
2099
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002100void Context::getTexParameterIivRobust(TextureType target,
2101 GLenum pname,
2102 GLsizei bufSize,
2103 GLsizei *length,
2104 GLint *params)
2105{
2106 UNIMPLEMENTED();
2107}
2108
2109void Context::getTexParameterIuivRobust(TextureType target,
2110 GLenum pname,
2111 GLsizei bufSize,
2112 GLsizei *length,
2113 GLuint *params)
2114{
2115 UNIMPLEMENTED();
2116}
2117
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002118void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002119{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002120 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002121 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002122}
2123
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002124void Context::getTexLevelParameterivRobust(TextureTarget target,
2125 GLint level,
2126 GLenum pname,
2127 GLsizei bufSize,
2128 GLsizei *length,
2129 GLint *params)
2130{
2131 UNIMPLEMENTED();
2132}
2133
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002134void Context::getTexLevelParameterfv(TextureTarget target,
2135 GLint level,
2136 GLenum pname,
2137 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002138{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002139 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002140 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002141}
2142
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002143void Context::getTexLevelParameterfvRobust(TextureTarget target,
2144 GLint level,
2145 GLenum pname,
2146 GLsizei bufSize,
2147 GLsizei *length,
2148 GLfloat *params)
2149{
2150 UNIMPLEMENTED();
2151}
2152
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002153void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002154{
2155 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002156 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002157 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002158}
2159
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002160void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002161{
2162 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002163 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002164 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002165}
2166
Brandon Jones59770802018-04-02 13:18:42 -07002167void Context::texParameterfvRobust(TextureType target,
2168 GLenum pname,
2169 GLsizei bufSize,
2170 const GLfloat *params)
2171{
2172 texParameterfv(target, pname, params);
2173}
2174
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002175void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002176{
2177 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002178 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002179 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002180}
2181
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002182void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002183{
2184 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002185 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002186 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002187}
2188
Brandon Jones59770802018-04-02 13:18:42 -07002189void Context::texParameterivRobust(TextureType target,
2190 GLenum pname,
2191 GLsizei bufSize,
2192 const GLint *params)
2193{
2194 texParameteriv(target, pname, params);
2195}
2196
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002197void Context::texParameterIivRobust(TextureType target,
2198 GLenum pname,
2199 GLsizei bufSize,
2200 const GLint *params)
2201{
2202 UNIMPLEMENTED();
2203}
2204
2205void Context::texParameterIuivRobust(TextureType target,
2206 GLenum pname,
2207 GLsizei bufSize,
2208 const GLuint *params)
2209{
2210 UNIMPLEMENTED();
2211}
2212
Jamie Madill493f9572018-05-24 19:52:15 -04002213void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002214{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002215 // No-op if count draws no primitives for given mode
2216 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002217 {
2218 return;
2219 }
2220
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002221 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002222 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002223 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002224}
2225
Jamie Madill493f9572018-05-24 19:52:15 -04002226void Context::drawArraysInstanced(PrimitiveMode mode,
2227 GLint first,
2228 GLsizei count,
2229 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002230{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002231 // No-op if count draws no primitives for given mode
2232 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002233 {
2234 return;
2235 }
2236
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002237 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002238 ANGLE_CONTEXT_TRY(
2239 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002240 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2241 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002242}
2243
Jamie Madill493f9572018-05-24 19:52:15 -04002244void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002245{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002246 // No-op if count draws no primitives for given mode
2247 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002248 {
2249 return;
2250 }
2251
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002252 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002253 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002254}
2255
Jamie Madill493f9572018-05-24 19:52:15 -04002256void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002257 GLsizei count,
2258 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002259 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002260 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002261{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002262 // No-op if count draws no primitives for given mode
2263 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002264 {
2265 return;
2266 }
2267
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002268 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002269 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002270 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002271}
2272
Jamie Madill493f9572018-05-24 19:52:15 -04002273void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002274 GLuint start,
2275 GLuint end,
2276 GLsizei count,
2277 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002278 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002279{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002280 // No-op if count draws no primitives for given mode
2281 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002282 {
2283 return;
2284 }
2285
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002286 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002287 ANGLE_CONTEXT_TRY(
2288 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002289}
2290
Jamie Madill493f9572018-05-24 19:52:15 -04002291void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002292{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002293 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002294 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002295}
2296
Jamie Madill493f9572018-05-24 19:52:15 -04002297void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002298{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002299 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002300 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002301}
2302
Jamie Madill675fe712016-12-19 13:07:54 -05002303void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002304{
Jamie Madillafa02a22017-11-23 12:57:38 -05002305 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002306}
2307
Jamie Madill675fe712016-12-19 13:07:54 -05002308void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002309{
Jamie Madillafa02a22017-11-23 12:57:38 -05002310 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002311}
2312
Austin Kinross6ee1e782015-05-29 17:05:37 -07002313void Context::insertEventMarker(GLsizei length, const char *marker)
2314{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002315 ASSERT(mImplementation);
2316 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002317}
2318
2319void Context::pushGroupMarker(GLsizei length, const char *marker)
2320{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002321 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002322
2323 if (marker == nullptr)
2324 {
2325 // From the EXT_debug_marker spec,
2326 // "If <marker> is null then an empty string is pushed on the stack."
2327 mImplementation->pushGroupMarker(length, "");
2328 }
2329 else
2330 {
2331 mImplementation->pushGroupMarker(length, marker);
2332 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002333}
2334
2335void Context::popGroupMarker()
2336{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002337 ASSERT(mImplementation);
2338 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002339}
2340
Geoff Langd8605522016-04-13 10:19:12 -04002341void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2342{
2343 Program *programObject = getProgram(program);
2344 ASSERT(programObject);
2345
2346 programObject->bindUniformLocation(location, name);
2347}
2348
Brandon Jones59770802018-04-02 13:18:42 -07002349void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002350{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002351 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002352}
2353
Brandon Jones59770802018-04-02 13:18:42 -07002354void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002355{
2356 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2357}
2358
Brandon Jones59770802018-04-02 13:18:42 -07002359void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002360{
2361 GLfloat I[16];
2362 angle::Matrix<GLfloat>::setToIdentity(I);
2363
2364 mGLState.loadPathRenderingMatrix(matrixMode, I);
2365}
2366
2367void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2368{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002369 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002370 if (!pathObj)
2371 return;
2372
Geoff Lang9bf86f02018-07-26 11:46:34 -04002373 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002374
2375 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2376}
2377
2378void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2379{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002380 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002381 if (!pathObj)
2382 return;
2383
Geoff Lang9bf86f02018-07-26 11:46:34 -04002384 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002385
2386 mImplementation->stencilStrokePath(pathObj, reference, mask);
2387}
2388
2389void Context::coverFillPath(GLuint path, GLenum coverMode)
2390{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002391 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002392 if (!pathObj)
2393 return;
2394
Geoff Lang9bf86f02018-07-26 11:46:34 -04002395 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002396
2397 mImplementation->coverFillPath(pathObj, coverMode);
2398}
2399
2400void Context::coverStrokePath(GLuint path, GLenum coverMode)
2401{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002402 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002403 if (!pathObj)
2404 return;
2405
Geoff Lang9bf86f02018-07-26 11:46:34 -04002406 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002407
2408 mImplementation->coverStrokePath(pathObj, coverMode);
2409}
2410
2411void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2412{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002413 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002414 if (!pathObj)
2415 return;
2416
Geoff Lang9bf86f02018-07-26 11:46:34 -04002417 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002418
2419 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2420}
2421
2422void Context::stencilThenCoverStrokePath(GLuint path,
2423 GLint reference,
2424 GLuint mask,
2425 GLenum coverMode)
2426{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002427 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002428 if (!pathObj)
2429 return;
2430
Geoff Lang9bf86f02018-07-26 11:46:34 -04002431 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002432
2433 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2434}
2435
Sami Väisänend59ca052016-06-21 16:10:00 +03002436void Context::coverFillPathInstanced(GLsizei numPaths,
2437 GLenum pathNameType,
2438 const void *paths,
2439 GLuint pathBase,
2440 GLenum coverMode,
2441 GLenum transformType,
2442 const GLfloat *transformValues)
2443{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002444 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002445
Geoff Lang9bf86f02018-07-26 11:46:34 -04002446 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002447
2448 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2449}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002450
Sami Väisänend59ca052016-06-21 16:10:00 +03002451void Context::coverStrokePathInstanced(GLsizei numPaths,
2452 GLenum pathNameType,
2453 const void *paths,
2454 GLuint pathBase,
2455 GLenum coverMode,
2456 GLenum transformType,
2457 const GLfloat *transformValues)
2458{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002459 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002460
2461 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002462 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002463
2464 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2465 transformValues);
2466}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002467
Sami Väisänend59ca052016-06-21 16:10:00 +03002468void Context::stencilFillPathInstanced(GLsizei numPaths,
2469 GLenum pathNameType,
2470 const void *paths,
2471 GLuint pathBase,
2472 GLenum fillMode,
2473 GLuint mask,
2474 GLenum transformType,
2475 const GLfloat *transformValues)
2476{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002477 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002478
2479 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002480 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002481
2482 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2483 transformValues);
2484}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002485
Sami Väisänend59ca052016-06-21 16:10:00 +03002486void Context::stencilStrokePathInstanced(GLsizei numPaths,
2487 GLenum pathNameType,
2488 const void *paths,
2489 GLuint pathBase,
2490 GLint reference,
2491 GLuint mask,
2492 GLenum transformType,
2493 const GLfloat *transformValues)
2494{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002495 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002496
Geoff Lang9bf86f02018-07-26 11:46:34 -04002497 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002498
2499 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2500 transformValues);
2501}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002502
Sami Väisänend59ca052016-06-21 16:10:00 +03002503void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2504 GLenum pathNameType,
2505 const void *paths,
2506 GLuint pathBase,
2507 GLenum fillMode,
2508 GLuint mask,
2509 GLenum coverMode,
2510 GLenum transformType,
2511 const GLfloat *transformValues)
2512{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002513 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002514
Geoff Lang9bf86f02018-07-26 11:46:34 -04002515 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002516
2517 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2518 transformType, transformValues);
2519}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002520
Sami Väisänend59ca052016-06-21 16:10:00 +03002521void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2522 GLenum pathNameType,
2523 const void *paths,
2524 GLuint pathBase,
2525 GLint reference,
2526 GLuint mask,
2527 GLenum coverMode,
2528 GLenum transformType,
2529 const GLfloat *transformValues)
2530{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002531 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002532
Geoff Lang9bf86f02018-07-26 11:46:34 -04002533 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002534
2535 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2536 transformType, transformValues);
2537}
2538
Sami Väisänen46eaa942016-06-29 10:26:37 +03002539void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2540{
2541 auto *programObject = getProgram(program);
2542
2543 programObject->bindFragmentInputLocation(location, name);
2544}
2545
2546void Context::programPathFragmentInputGen(GLuint program,
2547 GLint location,
2548 GLenum genMode,
2549 GLint components,
2550 const GLfloat *coeffs)
2551{
2552 auto *programObject = getProgram(program);
2553
jchen103fd614d2018-08-13 12:21:58 +08002554 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002555}
2556
jchen1015015f72017-03-16 13:54:21 +08002557GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2558{
jchen10fd7c3b52017-03-21 15:36:03 +08002559 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002560 return QueryProgramResourceIndex(programObject, programInterface, name);
2561}
2562
jchen10fd7c3b52017-03-21 15:36:03 +08002563void Context::getProgramResourceName(GLuint program,
2564 GLenum programInterface,
2565 GLuint index,
2566 GLsizei bufSize,
2567 GLsizei *length,
2568 GLchar *name)
2569{
2570 const auto *programObject = getProgram(program);
2571 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2572}
2573
jchen10191381f2017-04-11 13:59:04 +08002574GLint Context::getProgramResourceLocation(GLuint program,
2575 GLenum programInterface,
2576 const GLchar *name)
2577{
2578 const auto *programObject = getProgram(program);
2579 return QueryProgramResourceLocation(programObject, programInterface, name);
2580}
2581
jchen10880683b2017-04-12 16:21:55 +08002582void Context::getProgramResourceiv(GLuint program,
2583 GLenum programInterface,
2584 GLuint index,
2585 GLsizei propCount,
2586 const GLenum *props,
2587 GLsizei bufSize,
2588 GLsizei *length,
2589 GLint *params)
2590{
2591 const auto *programObject = getProgram(program);
2592 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2593 length, params);
2594}
2595
jchen10d9cd7b72017-08-30 15:04:25 +08002596void Context::getProgramInterfaceiv(GLuint program,
2597 GLenum programInterface,
2598 GLenum pname,
2599 GLint *params)
2600{
2601 const auto *programObject = getProgram(program);
2602 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2603}
2604
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002605void Context::getProgramInterfaceivRobust(GLuint program,
2606 GLenum programInterface,
2607 GLenum pname,
2608 GLsizei bufSize,
2609 GLsizei *length,
2610 GLint *params)
2611{
2612 UNIMPLEMENTED();
2613}
2614
Jamie Madill306b6c12018-07-27 08:12:49 -04002615void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002616{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002617 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002618}
2619
2620// Get one of the recorded errors and clear its flag, if any.
2621// [OpenGL ES 2.0.24] section 2.5 page 13.
2622GLenum Context::getError()
2623{
Geoff Langda5777c2014-07-11 09:52:58 -04002624 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002625 {
Geoff Langda5777c2014-07-11 09:52:58 -04002626 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002627 }
Geoff Langda5777c2014-07-11 09:52:58 -04002628 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002629 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002630 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002631 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002632}
2633
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002634// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002635void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002636{
2637 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002638 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002639 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002640 mContextLostForced = true;
2641 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002642 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002643}
2644
Jamie Madillfa920eb2018-01-04 11:45:50 -05002645GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002646{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002647 // Even if the application doesn't want to know about resets, we want to know
2648 // as it will allow us to skip all the calls.
2649 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002650 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002651 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002652 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002653 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002654 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002655
2656 // EXT_robustness, section 2.6: If the reset notification behavior is
2657 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2658 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2659 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002660 }
2661
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002662 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2663 // status should be returned at least once, and GL_NO_ERROR should be returned
2664 // once the device has finished resetting.
2665 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002666 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002667 ASSERT(mResetStatus == GL_NO_ERROR);
2668 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002669
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002670 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002671 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002672 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002673 }
2674 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002675 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002676 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002677 // If markContextLost was used to mark the context lost then
2678 // assume that is not recoverable, and continue to report the
2679 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002680 mResetStatus = mImplementation->getResetStatus();
2681 }
Jamie Madill893ab082014-05-16 16:56:10 -04002682
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002683 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002684}
2685
2686bool Context::isResetNotificationEnabled()
2687{
2688 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2689}
2690
Corentin Walleze3b10e82015-05-20 11:06:25 -04002691const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002692{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002693 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002694}
2695
2696EGLenum Context::getClientType() const
2697{
2698 return mClientType;
2699}
2700
2701EGLenum Context::getRenderBuffer() const
2702{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002703 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2704 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002705 {
2706 return EGL_NONE;
2707 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002708
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002709 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002710 ASSERT(backAttachment != nullptr);
2711 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002712}
2713
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002714VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002715{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002716 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002717 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2718 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002719 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002720 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2721 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002722
Jamie Madill96a483b2017-06-27 16:49:21 -04002723 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002724 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002725
2726 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002727}
2728
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002729TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002730{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002731 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002732 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2733 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002734 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002735 transformFeedback =
2736 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002737 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002738 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002739 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002740
2741 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002742}
2743
2744bool Context::isVertexArrayGenerated(GLuint vertexArray)
2745{
Jamie Madill96a483b2017-06-27 16:49:21 -04002746 ASSERT(mVertexArrayMap.contains(0));
2747 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002748}
2749
2750bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2751{
Jamie Madill96a483b2017-06-27 16:49:21 -04002752 ASSERT(mTransformFeedbackMap.contains(0));
2753 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002754}
2755
Shannon Woods53a94a82014-06-24 15:20:36 -04002756void Context::detachTexture(GLuint texture)
2757{
2758 // Simple pass-through to State's detachTexture method, as textures do not require
2759 // allocation map management either here or in the resource manager at detach time.
2760 // Zero textures are held by the Context, and we don't attempt to request them from
2761 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002762 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002763}
2764
James Darpinian4d9d4832018-03-13 12:43:28 -07002765void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002766{
Yuly Novikov5807a532015-12-03 13:01:22 -05002767 // Simple pass-through to State's detachBuffer method, since
2768 // only buffer attachments to container objects that are bound to the current context
2769 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002770
Yuly Novikov5807a532015-12-03 13:01:22 -05002771 // [OpenGL ES 3.2] section 5.1.2 page 45:
2772 // Attachments to unbound container objects, such as
2773 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2774 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002775 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002776}
2777
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002778void Context::detachFramebuffer(GLuint framebuffer)
2779{
Shannon Woods53a94a82014-06-24 15:20:36 -04002780 // Framebuffer detachment is handled by Context, because 0 is a valid
2781 // Framebuffer object, and a pointer to it must be passed from Context
2782 // to State at binding time.
2783
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002784 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002785 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2786 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2787 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002788
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002789 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002790 {
2791 bindReadFramebuffer(0);
2792 }
2793
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002794 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002795 {
2796 bindDrawFramebuffer(0);
2797 }
2798}
2799
2800void Context::detachRenderbuffer(GLuint renderbuffer)
2801{
Jamie Madilla02315b2017-02-23 14:14:47 -05002802 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002803}
2804
Jamie Madill57a89722013-07-02 11:57:03 -04002805void Context::detachVertexArray(GLuint vertexArray)
2806{
Jamie Madill77a72f62015-04-14 11:18:32 -04002807 // Vertex array detachment is handled by Context, because 0 is a valid
2808 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002809 // binding time.
2810
Jamie Madill57a89722013-07-02 11:57:03 -04002811 // [OpenGL ES 3.0.2] section 2.10 page 43:
2812 // If a vertex array object that is currently bound is deleted, the binding
2813 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002814 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002815 {
2816 bindVertexArray(0);
2817 }
2818}
2819
Geoff Langc8058452014-02-03 12:04:11 -05002820void Context::detachTransformFeedback(GLuint transformFeedback)
2821{
Corentin Walleza2257da2016-04-19 16:43:12 -04002822 // Transform feedback detachment is handled by Context, because 0 is a valid
2823 // transform feedback, and a pointer to it must be passed from Context to State at
2824 // binding time.
2825
2826 // The OpenGL specification doesn't mention what should happen when the currently bound
2827 // transform feedback object is deleted. Since it is a container object, we treat it like
2828 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002829 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002830 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002831 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002832 }
Geoff Langc8058452014-02-03 12:04:11 -05002833}
2834
Jamie Madilldc356042013-07-19 16:36:57 -04002835void Context::detachSampler(GLuint sampler)
2836{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002837 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002838}
2839
Yunchao Hea336b902017-08-02 16:05:21 +08002840void Context::detachProgramPipeline(GLuint pipeline)
2841{
2842 mGLState.detachProgramPipeline(this, pipeline);
2843}
2844
Jamie Madill3ef140a2017-08-26 23:11:21 -04002845void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002846{
Shaodde78e82017-05-22 14:13:27 +08002847 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002848 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002849}
2850
Jamie Madille29d1672013-07-19 16:36:57 -04002851void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2852{
Geoff Langc1984ed2016-10-07 12:41:00 -04002853 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002854 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002855 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002856}
Jamie Madille29d1672013-07-19 16:36:57 -04002857
Geoff Langc1984ed2016-10-07 12:41:00 -04002858void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2859{
2860 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002861 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002862 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002863}
2864
Brandon Jones59770802018-04-02 13:18:42 -07002865void Context::samplerParameterivRobust(GLuint sampler,
2866 GLenum pname,
2867 GLsizei bufSize,
2868 const GLint *param)
2869{
2870 samplerParameteriv(sampler, pname, param);
2871}
2872
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002873void Context::samplerParameterIivRobust(GLuint sampler,
2874 GLenum pname,
2875 GLsizei bufSize,
2876 const GLint *param)
2877{
2878 UNIMPLEMENTED();
2879}
2880
2881void Context::samplerParameterIuivRobust(GLuint sampler,
2882 GLenum pname,
2883 GLsizei bufSize,
2884 const GLuint *param)
2885{
2886 UNIMPLEMENTED();
2887}
2888
Jamie Madille29d1672013-07-19 16:36:57 -04002889void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2890{
Geoff Langc1984ed2016-10-07 12:41:00 -04002891 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002892 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002893 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002894}
2895
Geoff Langc1984ed2016-10-07 12:41:00 -04002896void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002897{
Geoff Langc1984ed2016-10-07 12:41:00 -04002898 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002899 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002900 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002901}
2902
Brandon Jones59770802018-04-02 13:18:42 -07002903void Context::samplerParameterfvRobust(GLuint sampler,
2904 GLenum pname,
2905 GLsizei bufSize,
2906 const GLfloat *param)
2907{
2908 samplerParameterfv(sampler, pname, param);
2909}
2910
Geoff Langc1984ed2016-10-07 12:41:00 -04002911void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002912{
Geoff Langc1984ed2016-10-07 12:41:00 -04002913 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002914 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002915 QuerySamplerParameteriv(samplerObject, pname, params);
2916}
Jamie Madill9675b802013-07-19 16:36:59 -04002917
Brandon Jones59770802018-04-02 13:18:42 -07002918void Context::getSamplerParameterivRobust(GLuint sampler,
2919 GLenum pname,
2920 GLsizei bufSize,
2921 GLsizei *length,
2922 GLint *params)
2923{
2924 getSamplerParameteriv(sampler, pname, params);
2925}
2926
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002927void Context::getSamplerParameterIivRobust(GLuint sampler,
2928 GLenum pname,
2929 GLsizei bufSize,
2930 GLsizei *length,
2931 GLint *params)
2932{
2933 UNIMPLEMENTED();
2934}
2935
2936void Context::getSamplerParameterIuivRobust(GLuint sampler,
2937 GLenum pname,
2938 GLsizei bufSize,
2939 GLsizei *length,
2940 GLuint *params)
2941{
2942 UNIMPLEMENTED();
2943}
2944
Geoff Langc1984ed2016-10-07 12:41:00 -04002945void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2946{
2947 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002948 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002949 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002950}
2951
Brandon Jones59770802018-04-02 13:18:42 -07002952void Context::getSamplerParameterfvRobust(GLuint sampler,
2953 GLenum pname,
2954 GLsizei bufSize,
2955 GLsizei *length,
2956 GLfloat *params)
2957{
2958 getSamplerParameterfv(sampler, pname, params);
2959}
2960
Olli Etuahof0fee072016-03-30 15:11:58 +03002961void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2962{
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 Etuaho4ebd8f32018-09-20 11:12:46 +03003553 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3554 // that the backend doesn't need to take this case into account.
Olli Etuahodbce1f82018-09-19 15:32:17 +03003555 if (buffer == GL_DEPTH && !getGLState().getDrawFramebuffer()->getDepthbuffer())
3556 {
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003557 return;
3558 }
3559 if (buffer == GL_COLOR && !getGLState().getDrawFramebuffer()->getColorbuffer(drawbuffer))
3560 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003561 return;
3562 }
Geoff Langd4fff502017-09-22 11:28:28 -04003563 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3564 ANGLE_CONTEXT_TRY(
3565 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003566}
3567
3568void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3569{
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003570 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3571 // that the backend doesn't need to take this case into account.
3572 if (buffer == GL_COLOR && !getGLState().getDrawFramebuffer()->getColorbuffer(drawbuffer))
3573 {
3574 return;
3575 }
Geoff Langd4fff502017-09-22 11:28:28 -04003576 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3577 ANGLE_CONTEXT_TRY(
3578 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003579}
3580
3581void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3582{
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003583 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3584 // that the backend doesn't need to take this case into account.
Olli Etuahodbce1f82018-09-19 15:32:17 +03003585 if (buffer == GL_STENCIL && !getGLState().getDrawFramebuffer()->getStencilbuffer())
3586 {
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003587 return;
3588 }
3589 if (buffer == GL_COLOR && !getGLState().getDrawFramebuffer()->getColorbuffer(drawbuffer))
3590 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003591 return;
3592 }
Geoff Langd4fff502017-09-22 11:28:28 -04003593 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3594 ANGLE_CONTEXT_TRY(
3595 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003596}
3597
3598void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3599{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003600 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003601 ASSERT(framebufferObject);
3602
3603 // If a buffer is not present, the clear has no effect
3604 if (framebufferObject->getDepthbuffer() == nullptr &&
3605 framebufferObject->getStencilbuffer() == nullptr)
3606 {
3607 return;
3608 }
3609
Geoff Langd4fff502017-09-22 11:28:28 -04003610 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3611 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003612}
3613
3614void Context::readPixels(GLint x,
3615 GLint y,
3616 GLsizei width,
3617 GLsizei height,
3618 GLenum format,
3619 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003620 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003621{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003622 if (width == 0 || height == 0)
3623 {
3624 return;
3625 }
3626
Jamie Madillbc918e72018-03-08 09:47:21 -05003627 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003628
Jamie Madillb6664922017-07-25 12:55:04 -04003629 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3630 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003631
3632 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003633 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003634}
3635
Brandon Jones59770802018-04-02 13:18:42 -07003636void Context::readPixelsRobust(GLint x,
3637 GLint y,
3638 GLsizei width,
3639 GLsizei height,
3640 GLenum format,
3641 GLenum type,
3642 GLsizei bufSize,
3643 GLsizei *length,
3644 GLsizei *columns,
3645 GLsizei *rows,
3646 void *pixels)
3647{
3648 readPixels(x, y, width, height, format, type, pixels);
3649}
3650
3651void Context::readnPixelsRobust(GLint x,
3652 GLint y,
3653 GLsizei width,
3654 GLsizei height,
3655 GLenum format,
3656 GLenum type,
3657 GLsizei bufSize,
3658 GLsizei *length,
3659 GLsizei *columns,
3660 GLsizei *rows,
3661 void *data)
3662{
3663 readPixels(x, y, width, height, format, type, data);
3664}
3665
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003666void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003667 GLint level,
3668 GLenum internalformat,
3669 GLint x,
3670 GLint y,
3671 GLsizei width,
3672 GLsizei height,
3673 GLint border)
3674{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003675 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003676 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003677
Jamie Madillc29968b2016-01-20 11:17:23 -05003678 Rectangle sourceArea(x, y, width, height);
3679
Jamie Madill05b35b22017-10-03 09:01:44 -04003680 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003681 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003682 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003683}
3684
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003685void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003686 GLint level,
3687 GLint xoffset,
3688 GLint yoffset,
3689 GLint x,
3690 GLint y,
3691 GLsizei width,
3692 GLsizei height)
3693{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003694 if (width == 0 || height == 0)
3695 {
3696 return;
3697 }
3698
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003699 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003700 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003701
Jamie Madillc29968b2016-01-20 11:17:23 -05003702 Offset destOffset(xoffset, yoffset, 0);
3703 Rectangle sourceArea(x, y, width, height);
3704
Jamie Madill05b35b22017-10-03 09:01:44 -04003705 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003706 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003707 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003708}
3709
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003710void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003711 GLint level,
3712 GLint xoffset,
3713 GLint yoffset,
3714 GLint zoffset,
3715 GLint x,
3716 GLint y,
3717 GLsizei width,
3718 GLsizei height)
3719{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003720 if (width == 0 || height == 0)
3721 {
3722 return;
3723 }
3724
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003725 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003726 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003727
Jamie Madillc29968b2016-01-20 11:17:23 -05003728 Offset destOffset(xoffset, yoffset, zoffset);
3729 Rectangle sourceArea(x, y, width, height);
3730
Jamie Madill05b35b22017-10-03 09:01:44 -04003731 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3732 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003733 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3734 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003735}
3736
3737void Context::framebufferTexture2D(GLenum target,
3738 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003739 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003740 GLuint texture,
3741 GLint level)
3742{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003743 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003744 ASSERT(framebuffer);
3745
3746 if (texture != 0)
3747 {
3748 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003749 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003750 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003751 }
3752 else
3753 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003754 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003755 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003756
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003757 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003758}
3759
3760void Context::framebufferRenderbuffer(GLenum target,
3761 GLenum attachment,
3762 GLenum renderbuffertarget,
3763 GLuint renderbuffer)
3764{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003765 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003766 ASSERT(framebuffer);
3767
3768 if (renderbuffer != 0)
3769 {
3770 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003771
Jamie Madillcc129372018-04-12 09:13:18 -04003772 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003773 renderbufferObject);
3774 }
3775 else
3776 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003777 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003778 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003779
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003780 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003781}
3782
3783void Context::framebufferTextureLayer(GLenum target,
3784 GLenum attachment,
3785 GLuint texture,
3786 GLint level,
3787 GLint layer)
3788{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003789 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003790 ASSERT(framebuffer);
3791
3792 if (texture != 0)
3793 {
3794 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003795 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003796 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003797 }
3798 else
3799 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003800 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003801 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003802
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003803 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003804}
3805
Brandon Jones59770802018-04-02 13:18:42 -07003806void Context::framebufferTextureMultiviewLayered(GLenum target,
3807 GLenum attachment,
3808 GLuint texture,
3809 GLint level,
3810 GLint baseViewIndex,
3811 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003812{
Martin Radev82ef7742017-08-08 17:44:58 +03003813 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3814 ASSERT(framebuffer);
3815
3816 if (texture != 0)
3817 {
3818 Texture *textureObj = getTexture(texture);
3819
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003820 ImageIndex index;
3821 if (textureObj->getType() == TextureType::_2DArray)
3822 {
3823 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3824 }
3825 else
3826 {
3827 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3828 ASSERT(level == 0);
3829 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3830 }
Martin Radev82ef7742017-08-08 17:44:58 +03003831 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3832 numViews, baseViewIndex);
3833 }
3834 else
3835 {
3836 framebuffer->resetAttachment(this, attachment);
3837 }
3838
3839 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003840}
3841
Brandon Jones59770802018-04-02 13:18:42 -07003842void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3843 GLenum attachment,
3844 GLuint texture,
3845 GLint level,
3846 GLsizei numViews,
3847 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003848{
Martin Radev5dae57b2017-07-14 16:15:55 +03003849 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3850 ASSERT(framebuffer);
3851
3852 if (texture != 0)
3853 {
3854 Texture *textureObj = getTexture(texture);
3855
3856 ImageIndex index = ImageIndex::Make2D(level);
3857 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3858 textureObj, numViews, viewportOffsets);
3859 }
3860 else
3861 {
3862 framebuffer->resetAttachment(this, attachment);
3863 }
3864
3865 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003866}
3867
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003868void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3869{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003870 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3871 ASSERT(framebuffer);
3872
3873 if (texture != 0)
3874 {
3875 Texture *textureObj = getTexture(texture);
3876
3877 ImageIndex index = ImageIndex::MakeFromType(
3878 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3879 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3880 }
3881 else
3882 {
3883 framebuffer->resetAttachment(this, attachment);
3884 }
3885
3886 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003887}
3888
Jamie Madillc29968b2016-01-20 11:17:23 -05003889void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3890{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003891 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003892 ASSERT(framebuffer);
3893 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003894 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04003895 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003896}
3897
3898void Context::readBuffer(GLenum mode)
3899{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003900 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003901 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003902 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003903}
3904
3905void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3906{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003907 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003908 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003909
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003910 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003911 ASSERT(framebuffer);
3912
3913 // The specification isn't clear what should be done when the framebuffer isn't complete.
3914 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003915 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003916}
3917
3918void Context::invalidateFramebuffer(GLenum target,
3919 GLsizei numAttachments,
3920 const GLenum *attachments)
3921{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003922 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003923 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003924
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003925 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003926 ASSERT(framebuffer);
3927
Jamie Madill427064d2018-04-13 16:20:34 -04003928 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003929 {
Jamie Madill437fa652016-05-03 15:13:24 -04003930 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003931 }
Jamie Madill437fa652016-05-03 15:13:24 -04003932
Jamie Madill4928b7c2017-06-20 12:57:39 -04003933 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003934}
3935
3936void Context::invalidateSubFramebuffer(GLenum target,
3937 GLsizei numAttachments,
3938 const GLenum *attachments,
3939 GLint x,
3940 GLint y,
3941 GLsizei width,
3942 GLsizei height)
3943{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003944 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003945 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003946
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003947 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003948 ASSERT(framebuffer);
3949
Jamie Madill427064d2018-04-13 16:20:34 -04003950 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003951 {
Jamie Madill437fa652016-05-03 15:13:24 -04003952 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003953 }
Jamie Madill437fa652016-05-03 15:13:24 -04003954
3955 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003956 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003957}
3958
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003959void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003960 GLint level,
3961 GLint internalformat,
3962 GLsizei width,
3963 GLsizei height,
3964 GLint border,
3965 GLenum format,
3966 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003967 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003968{
Jamie Madillbc918e72018-03-08 09:47:21 -05003969 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003970
3971 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003972 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003973 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003974 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003975}
3976
Brandon Jones59770802018-04-02 13:18:42 -07003977void Context::texImage2DRobust(TextureTarget target,
3978 GLint level,
3979 GLint internalformat,
3980 GLsizei width,
3981 GLsizei height,
3982 GLint border,
3983 GLenum format,
3984 GLenum type,
3985 GLsizei bufSize,
3986 const void *pixels)
3987{
3988 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3989}
3990
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003991void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003992 GLint level,
3993 GLint internalformat,
3994 GLsizei width,
3995 GLsizei height,
3996 GLsizei depth,
3997 GLint border,
3998 GLenum format,
3999 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004000 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004001{
Jamie Madillbc918e72018-03-08 09:47:21 -05004002 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004003
4004 Extents size(width, height, depth);
4005 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004006 handleError(texture->setImage(this, mGLState.getUnpackState(),
4007 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004008 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004009}
4010
Brandon Jones59770802018-04-02 13:18:42 -07004011void Context::texImage3DRobust(TextureType target,
4012 GLint level,
4013 GLint internalformat,
4014 GLsizei width,
4015 GLsizei height,
4016 GLsizei depth,
4017 GLint border,
4018 GLenum format,
4019 GLenum type,
4020 GLsizei bufSize,
4021 const void *pixels)
4022{
4023 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4024}
4025
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004026void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004027 GLint level,
4028 GLint xoffset,
4029 GLint yoffset,
4030 GLsizei width,
4031 GLsizei height,
4032 GLenum format,
4033 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004034 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004035{
4036 // Zero sized uploads are valid but no-ops
4037 if (width == 0 || height == 0)
4038 {
4039 return;
4040 }
4041
Jamie Madillbc918e72018-03-08 09:47:21 -05004042 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004043
4044 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004045 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004046
4047 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4048
4049 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target, level,
4050 area, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004051}
4052
Brandon Jones59770802018-04-02 13:18:42 -07004053void Context::texSubImage2DRobust(TextureTarget target,
4054 GLint level,
4055 GLint xoffset,
4056 GLint yoffset,
4057 GLsizei width,
4058 GLsizei height,
4059 GLenum format,
4060 GLenum type,
4061 GLsizei bufSize,
4062 const void *pixels)
4063{
4064 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4065}
4066
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004067void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004068 GLint level,
4069 GLint xoffset,
4070 GLint yoffset,
4071 GLint zoffset,
4072 GLsizei width,
4073 GLsizei height,
4074 GLsizei depth,
4075 GLenum format,
4076 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004077 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004078{
4079 // Zero sized uploads are valid but no-ops
4080 if (width == 0 || height == 0 || depth == 0)
4081 {
4082 return;
4083 }
4084
Jamie Madillbc918e72018-03-08 09:47:21 -05004085 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004086
4087 Box area(xoffset, yoffset, zoffset, width, height, depth);
4088 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004089
4090 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4091
4092 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004093 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004094 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004095}
4096
Brandon Jones59770802018-04-02 13:18:42 -07004097void Context::texSubImage3DRobust(TextureType target,
4098 GLint level,
4099 GLint xoffset,
4100 GLint yoffset,
4101 GLint zoffset,
4102 GLsizei width,
4103 GLsizei height,
4104 GLsizei depth,
4105 GLenum format,
4106 GLenum type,
4107 GLsizei bufSize,
4108 const void *pixels)
4109{
4110 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4111 pixels);
4112}
4113
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004114void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004115 GLint level,
4116 GLenum internalformat,
4117 GLsizei width,
4118 GLsizei height,
4119 GLint border,
4120 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004121 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004122{
Jamie Madillbc918e72018-03-08 09:47:21 -05004123 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004124
4125 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004126 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004127 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4128 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004129 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004130}
4131
Brandon Jones59770802018-04-02 13:18:42 -07004132void Context::compressedTexImage2DRobust(TextureTarget target,
4133 GLint level,
4134 GLenum internalformat,
4135 GLsizei width,
4136 GLsizei height,
4137 GLint border,
4138 GLsizei imageSize,
4139 GLsizei dataSize,
4140 const GLvoid *data)
4141{
4142 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4143}
4144
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004145void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004146 GLint level,
4147 GLenum internalformat,
4148 GLsizei width,
4149 GLsizei height,
4150 GLsizei depth,
4151 GLint border,
4152 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004153 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004154{
Jamie Madillbc918e72018-03-08 09:47:21 -05004155 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004156
4157 Extents size(width, height, depth);
4158 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004159 handleError(texture->setCompressedImage(
4160 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004161 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004162}
4163
Brandon Jones59770802018-04-02 13:18:42 -07004164void Context::compressedTexImage3DRobust(TextureType target,
4165 GLint level,
4166 GLenum internalformat,
4167 GLsizei width,
4168 GLsizei height,
4169 GLsizei depth,
4170 GLint border,
4171 GLsizei imageSize,
4172 GLsizei dataSize,
4173 const GLvoid *data)
4174{
4175 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4176 data);
4177}
4178
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004179void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004180 GLint level,
4181 GLint xoffset,
4182 GLint yoffset,
4183 GLsizei width,
4184 GLsizei height,
4185 GLenum format,
4186 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004187 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004188{
Jamie Madillbc918e72018-03-08 09:47:21 -05004189 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004190
4191 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004192 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004193 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4194 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004195 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004196}
4197
Brandon Jones59770802018-04-02 13:18:42 -07004198void Context::compressedTexSubImage2DRobust(TextureTarget target,
4199 GLint level,
4200 GLint xoffset,
4201 GLint yoffset,
4202 GLsizei width,
4203 GLsizei height,
4204 GLenum format,
4205 GLsizei imageSize,
4206 GLsizei dataSize,
4207 const GLvoid *data)
4208{
4209 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4210 data);
4211}
4212
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004213void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004214 GLint level,
4215 GLint xoffset,
4216 GLint yoffset,
4217 GLint zoffset,
4218 GLsizei width,
4219 GLsizei height,
4220 GLsizei depth,
4221 GLenum format,
4222 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004223 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004224{
4225 // Zero sized uploads are valid but no-ops
4226 if (width == 0 || height == 0)
4227 {
4228 return;
4229 }
4230
Jamie Madillbc918e72018-03-08 09:47:21 -05004231 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004232
4233 Box area(xoffset, yoffset, zoffset, width, height, depth);
4234 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004235 handleError(texture->setCompressedSubImage(
4236 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004237 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004238}
4239
Brandon Jones59770802018-04-02 13:18:42 -07004240void Context::compressedTexSubImage3DRobust(TextureType target,
4241 GLint level,
4242 GLint xoffset,
4243 GLint yoffset,
4244 GLint zoffset,
4245 GLsizei width,
4246 GLsizei height,
4247 GLsizei depth,
4248 GLenum format,
4249 GLsizei imageSize,
4250 GLsizei dataSize,
4251 const GLvoid *data)
4252{
4253 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4254 imageSize, data);
4255}
4256
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004257void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004258{
4259 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004260 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004261}
4262
Jamie Madill007530e2017-12-28 14:27:04 -05004263void Context::copyTexture(GLuint sourceId,
4264 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004265 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004266 GLuint destId,
4267 GLint destLevel,
4268 GLint internalFormat,
4269 GLenum destType,
4270 GLboolean unpackFlipY,
4271 GLboolean unpackPremultiplyAlpha,
4272 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004273{
Jamie Madillbc918e72018-03-08 09:47:21 -05004274 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004275
4276 gl::Texture *sourceTexture = getTexture(sourceId);
4277 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004278 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4279 sourceLevel, ConvertToBool(unpackFlipY),
4280 ConvertToBool(unpackPremultiplyAlpha),
4281 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004282}
4283
Jamie Madill007530e2017-12-28 14:27:04 -05004284void Context::copySubTexture(GLuint sourceId,
4285 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004286 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004287 GLuint destId,
4288 GLint destLevel,
4289 GLint xoffset,
4290 GLint yoffset,
4291 GLint x,
4292 GLint y,
4293 GLsizei width,
4294 GLsizei height,
4295 GLboolean unpackFlipY,
4296 GLboolean unpackPremultiplyAlpha,
4297 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004298{
4299 // Zero sized copies are valid but no-ops
4300 if (width == 0 || height == 0)
4301 {
4302 return;
4303 }
4304
Jamie Madillbc918e72018-03-08 09:47:21 -05004305 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004306
4307 gl::Texture *sourceTexture = getTexture(sourceId);
4308 gl::Texture *destTexture = getTexture(destId);
4309 Offset offset(xoffset, yoffset, 0);
4310 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004311 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4312 ConvertToBool(unpackFlipY),
4313 ConvertToBool(unpackPremultiplyAlpha),
4314 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004315}
4316
Jamie Madill007530e2017-12-28 14:27:04 -05004317void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004318{
Jamie Madillbc918e72018-03-08 09:47:21 -05004319 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004320
4321 gl::Texture *sourceTexture = getTexture(sourceId);
4322 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004323 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004324}
4325
Corentin Wallez336129f2017-10-17 15:55:40 -04004326void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004327{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004328 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004329 ASSERT(buffer);
4330
Geoff Lang496c02d2016-10-20 11:38:11 -07004331 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004332}
4333
Brandon Jones59770802018-04-02 13:18:42 -07004334void Context::getBufferPointervRobust(BufferBinding target,
4335 GLenum pname,
4336 GLsizei bufSize,
4337 GLsizei *length,
4338 void **params)
4339{
4340 getBufferPointerv(target, pname, params);
4341}
4342
Corentin Wallez336129f2017-10-17 15:55:40 -04004343void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004344{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004345 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004346 ASSERT(buffer);
4347
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004348 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004349 if (error.isError())
4350 {
Jamie Madill437fa652016-05-03 15:13:24 -04004351 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004352 return nullptr;
4353 }
4354
4355 return buffer->getMapPointer();
4356}
4357
Corentin Wallez336129f2017-10-17 15:55:40 -04004358GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004359{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004360 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004361 ASSERT(buffer);
4362
4363 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004364 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004365 if (error.isError())
4366 {
Jamie Madill437fa652016-05-03 15:13:24 -04004367 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004368 return GL_FALSE;
4369 }
4370
4371 return result;
4372}
4373
Corentin Wallez336129f2017-10-17 15:55:40 -04004374void *Context::mapBufferRange(BufferBinding target,
4375 GLintptr offset,
4376 GLsizeiptr length,
4377 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004378{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004379 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004380 ASSERT(buffer);
4381
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004382 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004383 if (error.isError())
4384 {
Jamie Madill437fa652016-05-03 15:13:24 -04004385 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004386 return nullptr;
4387 }
4388
4389 return buffer->getMapPointer();
4390}
4391
Corentin Wallez336129f2017-10-17 15:55:40 -04004392void Context::flushMappedBufferRange(BufferBinding /*target*/,
4393 GLintptr /*offset*/,
4394 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004395{
4396 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4397}
4398
Jamie Madillbc918e72018-03-08 09:47:21 -05004399Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004400{
Geoff Langa8cb2872018-03-09 16:09:40 -05004401 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004402}
4403
Jamie Madillbc918e72018-03-08 09:47:21 -05004404Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004405{
Geoff Langa8cb2872018-03-09 16:09:40 -05004406 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004407}
4408
Jamie Madillbc918e72018-03-08 09:47:21 -05004409Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004410{
Geoff Langa8cb2872018-03-09 16:09:40 -05004411 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004412}
4413
Geoff Lang9bf86f02018-07-26 11:46:34 -04004414Error Context::syncStateForPathOperation()
4415{
4416 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4417
4418 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4419 ANGLE_TRY(syncDirtyBits());
4420
4421 return NoError();
4422}
4423
Jiajia Qin5451d532017-11-16 17:16:34 +08004424void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4425{
4426 UNIMPLEMENTED();
4427}
4428
Jamie Madillc20ab272016-06-09 07:20:46 -07004429void Context::activeTexture(GLenum texture)
4430{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004431 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004432}
4433
Jamie Madill876429b2017-04-20 15:46:24 -04004434void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004435{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004436 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004437}
4438
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004439void Context::blendEquation(GLenum mode)
4440{
4441 mGLState.setBlendEquation(mode, mode);
4442}
4443
Jamie Madillc20ab272016-06-09 07:20:46 -07004444void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4445{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004446 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004447}
4448
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004449void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4450{
4451 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4452}
4453
Jamie Madillc20ab272016-06-09 07:20:46 -07004454void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4455{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004456 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004457}
4458
Jamie Madill876429b2017-04-20 15:46:24 -04004459void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004460{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004461 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004462}
4463
Jamie Madill876429b2017-04-20 15:46:24 -04004464void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004465{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004466 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004467}
4468
4469void Context::clearStencil(GLint s)
4470{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004471 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004472}
4473
4474void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4475{
Geoff Lang92019432017-11-20 13:09:34 -05004476 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4477 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004478}
4479
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004480void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004481{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004482 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004483}
4484
4485void Context::depthFunc(GLenum func)
4486{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004487 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004488}
4489
4490void Context::depthMask(GLboolean flag)
4491{
Geoff Lang92019432017-11-20 13:09:34 -05004492 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004493}
4494
Jamie Madill876429b2017-04-20 15:46:24 -04004495void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004496{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004497 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004498}
4499
4500void Context::disable(GLenum cap)
4501{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004502 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004503 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004504}
4505
4506void Context::disableVertexAttribArray(GLuint index)
4507{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004508 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004509 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004510}
4511
4512void Context::enable(GLenum cap)
4513{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004514 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004515 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004516}
4517
4518void Context::enableVertexAttribArray(GLuint index)
4519{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004520 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004521 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004522}
4523
4524void Context::frontFace(GLenum mode)
4525{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004526 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004527}
4528
4529void Context::hint(GLenum target, GLenum mode)
4530{
4531 switch (target)
4532 {
4533 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004534 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004535 break;
4536
4537 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004538 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004539 break;
4540
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004541 case GL_PERSPECTIVE_CORRECTION_HINT:
4542 case GL_POINT_SMOOTH_HINT:
4543 case GL_LINE_SMOOTH_HINT:
4544 case GL_FOG_HINT:
4545 mGLState.gles1().setHint(target, mode);
4546 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004547 default:
4548 UNREACHABLE();
4549 return;
4550 }
4551}
4552
4553void Context::lineWidth(GLfloat width)
4554{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004555 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004556}
4557
4558void Context::pixelStorei(GLenum pname, GLint param)
4559{
4560 switch (pname)
4561 {
4562 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004563 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004564 break;
4565
4566 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004567 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004568 break;
4569
4570 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004571 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004572 break;
4573
4574 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004575 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004576 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004577 break;
4578
4579 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004580 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004581 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004582 break;
4583
4584 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004585 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004586 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004587 break;
4588
4589 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004590 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004591 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004592 break;
4593
4594 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004595 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004596 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004597 break;
4598
4599 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004600 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004601 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004602 break;
4603
4604 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004605 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004606 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004607 break;
4608
4609 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004610 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004611 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004612 break;
4613
4614 default:
4615 UNREACHABLE();
4616 return;
4617 }
4618}
4619
4620void Context::polygonOffset(GLfloat factor, GLfloat units)
4621{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004622 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004623}
4624
Jamie Madill876429b2017-04-20 15:46:24 -04004625void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004626{
Geoff Lang92019432017-11-20 13:09:34 -05004627 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004628}
4629
Jiawei Shaodb342272017-09-27 10:21:45 +08004630void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4631{
4632 mGLState.setSampleMaskParams(maskNumber, mask);
4633}
4634
Jamie Madillc20ab272016-06-09 07:20:46 -07004635void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4636{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004637 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004638}
4639
4640void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4641{
4642 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4643 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004644 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004645 }
4646
4647 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4648 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004649 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004650 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004651
4652 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004653}
4654
4655void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4656{
4657 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4658 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004659 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004660 }
4661
4662 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4663 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004664 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004665 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004666
4667 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004668}
4669
4670void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4671{
4672 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4673 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004674 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004675 }
4676
4677 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4678 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004679 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004680 }
4681}
4682
4683void Context::vertexAttrib1f(GLuint index, GLfloat x)
4684{
4685 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004686 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004687 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004688}
4689
4690void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4691{
4692 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004693 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004694 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004695}
4696
4697void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4698{
4699 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004700 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004701 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004702}
4703
4704void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4705{
4706 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004707 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004708 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004709}
4710
4711void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4712{
4713 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004714 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004715 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004716}
4717
4718void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4719{
4720 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004721 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004722 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004723}
4724
4725void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4726{
4727 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004728 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004729 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004730}
4731
4732void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4733{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004734 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004735 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004736}
4737
4738void Context::vertexAttribPointer(GLuint index,
4739 GLint size,
4740 GLenum type,
4741 GLboolean normalized,
4742 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004743 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004744{
Corentin Wallez336129f2017-10-17 15:55:40 -04004745 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004746 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004747 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004748}
4749
Shao80957d92017-02-20 21:25:59 +08004750void Context::vertexAttribFormat(GLuint attribIndex,
4751 GLint size,
4752 GLenum type,
4753 GLboolean normalized,
4754 GLuint relativeOffset)
4755{
Geoff Lang92019432017-11-20 13:09:34 -05004756 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004757 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004758 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004759}
4760
4761void Context::vertexAttribIFormat(GLuint attribIndex,
4762 GLint size,
4763 GLenum type,
4764 GLuint relativeOffset)
4765{
4766 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004767 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004768}
4769
4770void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4771{
Shaodde78e82017-05-22 14:13:27 +08004772 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004773 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004774}
4775
Jiajia Qin5451d532017-11-16 17:16:34 +08004776void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004777{
4778 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004779 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004780}
4781
Jamie Madillc20ab272016-06-09 07:20:46 -07004782void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4783{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004784 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004785}
4786
4787void Context::vertexAttribIPointer(GLuint index,
4788 GLint size,
4789 GLenum type,
4790 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004791 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004792{
Corentin Wallez336129f2017-10-17 15:55:40 -04004793 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4794 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004795 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004796}
4797
4798void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4799{
4800 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004801 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004802 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004803}
4804
4805void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4806{
4807 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004808 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004809 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004810}
4811
4812void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4813{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004814 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004815 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004816}
4817
4818void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4819{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004820 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004821 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004822}
4823
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004824void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4825{
4826 const VertexAttribCurrentValueData &currentValues =
4827 getGLState().getVertexAttribCurrentValue(index);
4828 const VertexArray *vao = getGLState().getVertexArray();
4829 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4830 currentValues, pname, params);
4831}
4832
Brandon Jones59770802018-04-02 13:18:42 -07004833void Context::getVertexAttribivRobust(GLuint index,
4834 GLenum pname,
4835 GLsizei bufSize,
4836 GLsizei *length,
4837 GLint *params)
4838{
4839 getVertexAttribiv(index, pname, params);
4840}
4841
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004842void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4843{
4844 const VertexAttribCurrentValueData &currentValues =
4845 getGLState().getVertexAttribCurrentValue(index);
4846 const VertexArray *vao = getGLState().getVertexArray();
4847 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4848 currentValues, pname, params);
4849}
4850
Brandon Jones59770802018-04-02 13:18:42 -07004851void Context::getVertexAttribfvRobust(GLuint index,
4852 GLenum pname,
4853 GLsizei bufSize,
4854 GLsizei *length,
4855 GLfloat *params)
4856{
4857 getVertexAttribfv(index, pname, params);
4858}
4859
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004860void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4861{
4862 const VertexAttribCurrentValueData &currentValues =
4863 getGLState().getVertexAttribCurrentValue(index);
4864 const VertexArray *vao = getGLState().getVertexArray();
4865 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4866 currentValues, pname, params);
4867}
4868
Brandon Jones59770802018-04-02 13:18:42 -07004869void Context::getVertexAttribIivRobust(GLuint index,
4870 GLenum pname,
4871 GLsizei bufSize,
4872 GLsizei *length,
4873 GLint *params)
4874{
4875 getVertexAttribIiv(index, pname, params);
4876}
4877
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004878void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4879{
4880 const VertexAttribCurrentValueData &currentValues =
4881 getGLState().getVertexAttribCurrentValue(index);
4882 const VertexArray *vao = getGLState().getVertexArray();
4883 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4884 currentValues, pname, params);
4885}
4886
Brandon Jones59770802018-04-02 13:18:42 -07004887void Context::getVertexAttribIuivRobust(GLuint index,
4888 GLenum pname,
4889 GLsizei bufSize,
4890 GLsizei *length,
4891 GLuint *params)
4892{
4893 getVertexAttribIuiv(index, pname, params);
4894}
4895
Jamie Madill876429b2017-04-20 15:46:24 -04004896void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004897{
4898 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4899 QueryVertexAttribPointerv(attrib, pname, pointer);
4900}
4901
Brandon Jones59770802018-04-02 13:18:42 -07004902void Context::getVertexAttribPointervRobust(GLuint index,
4903 GLenum pname,
4904 GLsizei bufSize,
4905 GLsizei *length,
4906 void **pointer)
4907{
4908 getVertexAttribPointerv(index, pname, pointer);
4909}
4910
Jamie Madillc20ab272016-06-09 07:20:46 -07004911void Context::debugMessageControl(GLenum source,
4912 GLenum type,
4913 GLenum severity,
4914 GLsizei count,
4915 const GLuint *ids,
4916 GLboolean enabled)
4917{
4918 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004919 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004920 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004921}
4922
4923void Context::debugMessageInsert(GLenum source,
4924 GLenum type,
4925 GLuint id,
4926 GLenum severity,
4927 GLsizei length,
4928 const GLchar *buf)
4929{
4930 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004931 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004932}
4933
4934void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4935{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004936 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004937}
4938
4939GLuint Context::getDebugMessageLog(GLuint count,
4940 GLsizei bufSize,
4941 GLenum *sources,
4942 GLenum *types,
4943 GLuint *ids,
4944 GLenum *severities,
4945 GLsizei *lengths,
4946 GLchar *messageLog)
4947{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004948 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4949 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004950}
4951
4952void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4953{
4954 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004955 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004956 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004957}
4958
4959void Context::popDebugGroup()
4960{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004961 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004962 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004963}
4964
Corentin Wallez336129f2017-10-17 15:55:40 -04004965void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004966{
4967 Buffer *buffer = mGLState.getTargetBuffer(target);
4968 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004969 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004970}
4971
Corentin Wallez336129f2017-10-17 15:55:40 -04004972void Context::bufferSubData(BufferBinding target,
4973 GLintptr offset,
4974 GLsizeiptr size,
4975 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004976{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06004977 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04004978 {
4979 return;
4980 }
4981
4982 Buffer *buffer = mGLState.getTargetBuffer(target);
4983 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004984 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004985}
4986
Jamie Madillef300b12016-10-07 15:12:09 -04004987void Context::attachShader(GLuint program, GLuint shader)
4988{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004989 Program *programObject = mState.mShaderPrograms->getProgram(program);
4990 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004991 ASSERT(programObject && shaderObject);
4992 programObject->attachShader(shaderObject);
4993}
4994
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004995const Workarounds &Context::getWorkarounds() const
4996{
4997 return mWorkarounds;
4998}
4999
Corentin Wallez336129f2017-10-17 15:55:40 -04005000void Context::copyBufferSubData(BufferBinding readTarget,
5001 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005002 GLintptr readOffset,
5003 GLintptr writeOffset,
5004 GLsizeiptr size)
5005{
5006 // if size is zero, the copy is a successful no-op
5007 if (size == 0)
5008 {
5009 return;
5010 }
5011
5012 // TODO(jmadill): cache these.
5013 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
5014 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
5015
Jamie Madill5f56ddb2017-01-13 17:29:55 -05005016 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005017}
5018
Jamie Madill01a80ee2016-11-07 12:06:18 -05005019void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5020{
5021 Program *programObject = getProgram(program);
5022 // TODO(jmadill): Re-use this from the validation if possible.
5023 ASSERT(programObject);
5024 programObject->bindAttributeLocation(index, name);
5025}
5026
Corentin Wallez336129f2017-10-17 15:55:40 -04005027void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005028{
Corentin Wallez336129f2017-10-17 15:55:40 -04005029 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5030 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04005031 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005032}
5033
Corentin Wallez336129f2017-10-17 15:55:40 -04005034void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005035{
5036 bindBufferRange(target, index, buffer, 0, 0);
5037}
5038
Corentin Wallez336129f2017-10-17 15:55:40 -04005039void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005040 GLuint index,
5041 GLuint buffer,
5042 GLintptr offset,
5043 GLsizeiptr size)
5044{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005045 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5046 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
5047 if (target == BufferBinding::Uniform)
5048 {
5049 mUniformBufferObserverBindings[index].bind(object ? object->getImplementation() : nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04005050 mStateCache.onUniformBufferStateChange(this);
5051 }
5052 else
5053 {
5054 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005055 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005056}
5057
Jamie Madill01a80ee2016-11-07 12:06:18 -05005058void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5059{
5060 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5061 {
5062 bindReadFramebuffer(framebuffer);
5063 }
5064
5065 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5066 {
5067 bindDrawFramebuffer(framebuffer);
5068 }
5069}
5070
5071void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5072{
5073 ASSERT(target == GL_RENDERBUFFER);
5074 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005075 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005076 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005077}
5078
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005079void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005080 GLsizei samples,
5081 GLenum internalformat,
5082 GLsizei width,
5083 GLsizei height,
5084 GLboolean fixedsamplelocations)
5085{
5086 Extents size(width, height, 1);
5087 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005088 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5089 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005090}
5091
Olli Etuaho89664842018-08-24 14:45:36 +03005092void Context::texStorage3DMultisample(TextureType target,
5093 GLsizei samples,
5094 GLenum internalformat,
5095 GLsizei width,
5096 GLsizei height,
5097 GLsizei depth,
5098 GLboolean fixedsamplelocations)
5099{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005100 Extents size(width, height, depth);
5101 Texture *texture = getTargetTexture(target);
5102 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5103 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005104}
5105
JiangYizhoubddc46b2016-12-09 09:50:51 +08005106void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5107{
JiangYizhou5b03f472017-01-09 10:22:53 +08005108 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5109 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005110 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005111 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005112
5113 switch (pname)
5114 {
5115 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04005116 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005117 break;
5118 default:
5119 UNREACHABLE();
5120 }
5121}
5122
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005123void Context::getMultisamplefvRobust(GLenum pname,
5124 GLuint index,
5125 GLsizei bufSize,
5126 GLsizei *length,
5127 GLfloat *val)
5128{
5129 UNIMPLEMENTED();
5130}
5131
Jamie Madille8fb6402017-02-14 17:56:40 -05005132void Context::renderbufferStorage(GLenum target,
5133 GLenum internalformat,
5134 GLsizei width,
5135 GLsizei height)
5136{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005137 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5138 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5139
Jamie Madille8fb6402017-02-14 17:56:40 -05005140 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04005141 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005142}
5143
5144void Context::renderbufferStorageMultisample(GLenum target,
5145 GLsizei samples,
5146 GLenum internalformat,
5147 GLsizei width,
5148 GLsizei height)
5149{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005150 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5151 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005152
5153 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005154 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005155 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005156}
5157
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005158void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5159{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005160 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04005161 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005162}
5163
JiangYizhoue18e6392017-02-20 10:32:23 +08005164void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5165{
5166 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5167 QueryFramebufferParameteriv(framebuffer, pname, params);
5168}
5169
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005170void Context::getFramebufferParameterivRobust(GLenum target,
5171 GLenum pname,
5172 GLsizei bufSize,
5173 GLsizei *length,
5174 GLint *params)
5175{
5176 UNIMPLEMENTED();
5177}
5178
Jiajia Qin5451d532017-11-16 17:16:34 +08005179void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005180{
5181 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005182 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005183}
5184
Jamie Madilldec86232018-07-11 09:01:18 -04005185bool Context::getScratchBuffer(size_t requstedSizeBytes,
5186 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005187{
Jamie Madilldec86232018-07-11 09:01:18 -04005188 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005189}
5190
Jamie Madilldec86232018-07-11 09:01:18 -04005191bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5192 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005193{
Jamie Madilldec86232018-07-11 09:01:18 -04005194 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005195}
5196
Xinghua Cao10a4d432017-11-28 14:46:26 +08005197Error Context::prepareForDispatch()
5198{
Geoff Langa8cb2872018-03-09 16:09:40 -05005199 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005200
5201 if (isRobustResourceInitEnabled())
5202 {
5203 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5204 }
5205
5206 return NoError();
5207}
5208
Xinghua Cao2b396592017-03-29 15:36:04 +08005209void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5210{
5211 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5212 {
5213 return;
5214 }
5215
Xinghua Cao10a4d432017-11-28 14:46:26 +08005216 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005217 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005218}
5219
Jiajia Qin5451d532017-11-16 17:16:34 +08005220void Context::dispatchComputeIndirect(GLintptr indirect)
5221{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005222 ANGLE_CONTEXT_TRY(prepareForDispatch());
5223 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005224}
5225
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005226void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005227 GLsizei levels,
5228 GLenum internalFormat,
5229 GLsizei width,
5230 GLsizei height)
5231{
5232 Extents size(width, height, 1);
5233 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005234 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005235}
5236
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005237void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005238 GLsizei levels,
5239 GLenum internalFormat,
5240 GLsizei width,
5241 GLsizei height,
5242 GLsizei depth)
5243{
5244 Extents size(width, height, depth);
5245 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005246 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005247}
5248
Jiajia Qin5451d532017-11-16 17:16:34 +08005249void Context::memoryBarrier(GLbitfield barriers)
5250{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005251 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005252}
5253
5254void Context::memoryBarrierByRegion(GLbitfield barriers)
5255{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005256 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005257}
5258
Jamie Madillc1d770e2017-04-13 17:31:24 -04005259GLenum Context::checkFramebufferStatus(GLenum target)
5260{
5261 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5262 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005263 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005264}
5265
5266void Context::compileShader(GLuint shader)
5267{
5268 Shader *shaderObject = GetValidShader(this, shader);
5269 if (!shaderObject)
5270 {
5271 return;
5272 }
5273 shaderObject->compile(this);
5274}
5275
5276void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5277{
5278 for (int i = 0; i < n; i++)
5279 {
5280 deleteBuffer(buffers[i]);
5281 }
5282}
5283
5284void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5285{
5286 for (int i = 0; i < n; i++)
5287 {
5288 if (framebuffers[i] != 0)
5289 {
5290 deleteFramebuffer(framebuffers[i]);
5291 }
5292 }
5293}
5294
5295void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5296{
5297 for (int i = 0; i < n; i++)
5298 {
5299 deleteRenderbuffer(renderbuffers[i]);
5300 }
5301}
5302
5303void Context::deleteTextures(GLsizei n, const GLuint *textures)
5304{
5305 for (int i = 0; i < n; i++)
5306 {
5307 if (textures[i] != 0)
5308 {
5309 deleteTexture(textures[i]);
5310 }
5311 }
5312}
5313
5314void Context::detachShader(GLuint program, GLuint shader)
5315{
5316 Program *programObject = getProgram(program);
5317 ASSERT(programObject);
5318
5319 Shader *shaderObject = getShader(shader);
5320 ASSERT(shaderObject);
5321
5322 programObject->detachShader(this, shaderObject);
5323}
5324
5325void Context::genBuffers(GLsizei n, GLuint *buffers)
5326{
5327 for (int i = 0; i < n; i++)
5328 {
5329 buffers[i] = createBuffer();
5330 }
5331}
5332
5333void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5334{
5335 for (int i = 0; i < n; i++)
5336 {
5337 framebuffers[i] = createFramebuffer();
5338 }
5339}
5340
5341void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5342{
5343 for (int i = 0; i < n; i++)
5344 {
5345 renderbuffers[i] = createRenderbuffer();
5346 }
5347}
5348
5349void Context::genTextures(GLsizei n, GLuint *textures)
5350{
5351 for (int i = 0; i < n; i++)
5352 {
5353 textures[i] = createTexture();
5354 }
5355}
5356
5357void Context::getActiveAttrib(GLuint program,
5358 GLuint index,
5359 GLsizei bufsize,
5360 GLsizei *length,
5361 GLint *size,
5362 GLenum *type,
5363 GLchar *name)
5364{
5365 Program *programObject = getProgram(program);
5366 ASSERT(programObject);
5367 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5368}
5369
5370void Context::getActiveUniform(GLuint program,
5371 GLuint index,
5372 GLsizei bufsize,
5373 GLsizei *length,
5374 GLint *size,
5375 GLenum *type,
5376 GLchar *name)
5377{
5378 Program *programObject = getProgram(program);
5379 ASSERT(programObject);
5380 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5381}
5382
5383void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5384{
5385 Program *programObject = getProgram(program);
5386 ASSERT(programObject);
5387 programObject->getAttachedShaders(maxcount, count, shaders);
5388}
5389
5390GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5391{
5392 Program *programObject = getProgram(program);
5393 ASSERT(programObject);
5394 return programObject->getAttributeLocation(name);
5395}
5396
5397void Context::getBooleanv(GLenum pname, GLboolean *params)
5398{
5399 GLenum nativeType;
5400 unsigned int numParams = 0;
5401 getQueryParameterInfo(pname, &nativeType, &numParams);
5402
5403 if (nativeType == GL_BOOL)
5404 {
5405 getBooleanvImpl(pname, params);
5406 }
5407 else
5408 {
5409 CastStateValues(this, nativeType, pname, numParams, params);
5410 }
5411}
5412
Brandon Jones59770802018-04-02 13:18:42 -07005413void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5414{
5415 getBooleanv(pname, params);
5416}
5417
Jamie Madillc1d770e2017-04-13 17:31:24 -04005418void Context::getFloatv(GLenum pname, GLfloat *params)
5419{
5420 GLenum nativeType;
5421 unsigned int numParams = 0;
5422 getQueryParameterInfo(pname, &nativeType, &numParams);
5423
5424 if (nativeType == GL_FLOAT)
5425 {
5426 getFloatvImpl(pname, params);
5427 }
5428 else
5429 {
5430 CastStateValues(this, nativeType, pname, numParams, params);
5431 }
5432}
5433
Brandon Jones59770802018-04-02 13:18:42 -07005434void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5435{
5436 getFloatv(pname, params);
5437}
5438
Jamie Madillc1d770e2017-04-13 17:31:24 -04005439void Context::getIntegerv(GLenum pname, GLint *params)
5440{
5441 GLenum nativeType;
5442 unsigned int numParams = 0;
5443 getQueryParameterInfo(pname, &nativeType, &numParams);
5444
5445 if (nativeType == GL_INT)
5446 {
5447 getIntegervImpl(pname, params);
5448 }
5449 else
5450 {
5451 CastStateValues(this, nativeType, pname, numParams, params);
5452 }
5453}
5454
Brandon Jones59770802018-04-02 13:18:42 -07005455void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5456{
5457 getIntegerv(pname, data);
5458}
5459
Jamie Madillc1d770e2017-04-13 17:31:24 -04005460void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5461{
5462 Program *programObject = getProgram(program);
5463 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005464 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005465}
5466
Brandon Jones59770802018-04-02 13:18:42 -07005467void Context::getProgramivRobust(GLuint program,
5468 GLenum pname,
5469 GLsizei bufSize,
5470 GLsizei *length,
5471 GLint *params)
5472{
5473 getProgramiv(program, pname, params);
5474}
5475
Jiajia Qin5451d532017-11-16 17:16:34 +08005476void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5477{
5478 UNIMPLEMENTED();
5479}
5480
Jamie Madillbe849e42017-05-02 15:49:00 -04005481void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005482{
5483 Program *programObject = getProgram(program);
5484 ASSERT(programObject);
5485 programObject->getInfoLog(bufsize, length, infolog);
5486}
5487
Jiajia Qin5451d532017-11-16 17:16:34 +08005488void Context::getProgramPipelineInfoLog(GLuint pipeline,
5489 GLsizei bufSize,
5490 GLsizei *length,
5491 GLchar *infoLog)
5492{
5493 UNIMPLEMENTED();
5494}
5495
Jamie Madillc1d770e2017-04-13 17:31:24 -04005496void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5497{
5498 Shader *shaderObject = getShader(shader);
5499 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005500 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005501}
5502
Brandon Jones59770802018-04-02 13:18:42 -07005503void Context::getShaderivRobust(GLuint shader,
5504 GLenum pname,
5505 GLsizei bufSize,
5506 GLsizei *length,
5507 GLint *params)
5508{
5509 getShaderiv(shader, pname, params);
5510}
5511
Jamie Madillc1d770e2017-04-13 17:31:24 -04005512void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5513{
5514 Shader *shaderObject = getShader(shader);
5515 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005516 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005517}
5518
5519void Context::getShaderPrecisionFormat(GLenum shadertype,
5520 GLenum precisiontype,
5521 GLint *range,
5522 GLint *precision)
5523{
5524 // TODO(jmadill): Compute shaders.
5525
5526 switch (shadertype)
5527 {
5528 case GL_VERTEX_SHADER:
5529 switch (precisiontype)
5530 {
5531 case GL_LOW_FLOAT:
5532 mCaps.vertexLowpFloat.get(range, precision);
5533 break;
5534 case GL_MEDIUM_FLOAT:
5535 mCaps.vertexMediumpFloat.get(range, precision);
5536 break;
5537 case GL_HIGH_FLOAT:
5538 mCaps.vertexHighpFloat.get(range, precision);
5539 break;
5540
5541 case GL_LOW_INT:
5542 mCaps.vertexLowpInt.get(range, precision);
5543 break;
5544 case GL_MEDIUM_INT:
5545 mCaps.vertexMediumpInt.get(range, precision);
5546 break;
5547 case GL_HIGH_INT:
5548 mCaps.vertexHighpInt.get(range, precision);
5549 break;
5550
5551 default:
5552 UNREACHABLE();
5553 return;
5554 }
5555 break;
5556
5557 case GL_FRAGMENT_SHADER:
5558 switch (precisiontype)
5559 {
5560 case GL_LOW_FLOAT:
5561 mCaps.fragmentLowpFloat.get(range, precision);
5562 break;
5563 case GL_MEDIUM_FLOAT:
5564 mCaps.fragmentMediumpFloat.get(range, precision);
5565 break;
5566 case GL_HIGH_FLOAT:
5567 mCaps.fragmentHighpFloat.get(range, precision);
5568 break;
5569
5570 case GL_LOW_INT:
5571 mCaps.fragmentLowpInt.get(range, precision);
5572 break;
5573 case GL_MEDIUM_INT:
5574 mCaps.fragmentMediumpInt.get(range, precision);
5575 break;
5576 case GL_HIGH_INT:
5577 mCaps.fragmentHighpInt.get(range, precision);
5578 break;
5579
5580 default:
5581 UNREACHABLE();
5582 return;
5583 }
5584 break;
5585
5586 default:
5587 UNREACHABLE();
5588 return;
5589 }
5590}
5591
5592void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5593{
5594 Shader *shaderObject = getShader(shader);
5595 ASSERT(shaderObject);
5596 shaderObject->getSource(bufsize, length, source);
5597}
5598
5599void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5600{
5601 Program *programObject = getProgram(program);
5602 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005603 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005604}
5605
Brandon Jones59770802018-04-02 13:18:42 -07005606void Context::getUniformfvRobust(GLuint program,
5607 GLint location,
5608 GLsizei bufSize,
5609 GLsizei *length,
5610 GLfloat *params)
5611{
5612 getUniformfv(program, location, params);
5613}
5614
Jamie Madillc1d770e2017-04-13 17:31:24 -04005615void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5616{
5617 Program *programObject = getProgram(program);
5618 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005619 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005620}
5621
Brandon Jones59770802018-04-02 13:18:42 -07005622void Context::getUniformivRobust(GLuint program,
5623 GLint location,
5624 GLsizei bufSize,
5625 GLsizei *length,
5626 GLint *params)
5627{
5628 getUniformiv(program, location, params);
5629}
5630
Jamie Madillc1d770e2017-04-13 17:31:24 -04005631GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5632{
5633 Program *programObject = getProgram(program);
5634 ASSERT(programObject);
5635 return programObject->getUniformLocation(name);
5636}
5637
5638GLboolean Context::isBuffer(GLuint buffer)
5639{
5640 if (buffer == 0)
5641 {
5642 return GL_FALSE;
5643 }
5644
5645 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5646}
5647
5648GLboolean Context::isEnabled(GLenum cap)
5649{
5650 return mGLState.getEnableFeature(cap);
5651}
5652
5653GLboolean Context::isFramebuffer(GLuint framebuffer)
5654{
5655 if (framebuffer == 0)
5656 {
5657 return GL_FALSE;
5658 }
5659
5660 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5661}
5662
5663GLboolean Context::isProgram(GLuint program)
5664{
5665 if (program == 0)
5666 {
5667 return GL_FALSE;
5668 }
5669
5670 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5671}
5672
5673GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5674{
5675 if (renderbuffer == 0)
5676 {
5677 return GL_FALSE;
5678 }
5679
5680 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5681}
5682
5683GLboolean Context::isShader(GLuint shader)
5684{
5685 if (shader == 0)
5686 {
5687 return GL_FALSE;
5688 }
5689
5690 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5691}
5692
5693GLboolean Context::isTexture(GLuint texture)
5694{
5695 if (texture == 0)
5696 {
5697 return GL_FALSE;
5698 }
5699
5700 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5701}
5702
5703void Context::linkProgram(GLuint program)
5704{
5705 Program *programObject = getProgram(program);
5706 ASSERT(programObject);
5707 handleError(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005708
5709 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5710 // don't need to worry that:
5711 // 1. Draw calls after link use the new executable code or the old one depending on the link
5712 // result.
5713 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5714 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5715 // ProgramD3D.
5716 if (programObject->isInUse())
5717 {
5718 // isLinked() which forces to resolve linking, will be called.
5719 mGLState.onProgramExecutableChange(programObject);
5720 mStateCache.onProgramExecutableChange(this);
5721 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005722}
5723
5724void Context::releaseShaderCompiler()
5725{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005726 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005727}
5728
5729void Context::shaderBinary(GLsizei n,
5730 const GLuint *shaders,
5731 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005732 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005733 GLsizei length)
5734{
5735 // No binary shader formats are supported.
5736 UNIMPLEMENTED();
5737}
5738
5739void Context::shaderSource(GLuint shader,
5740 GLsizei count,
5741 const GLchar *const *string,
5742 const GLint *length)
5743{
5744 Shader *shaderObject = getShader(shader);
5745 ASSERT(shaderObject);
5746 shaderObject->setSource(count, string, length);
5747}
5748
5749void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5750{
5751 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5752}
5753
5754void Context::stencilMask(GLuint mask)
5755{
5756 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5757}
5758
5759void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5760{
5761 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5762}
5763
5764void Context::uniform1f(GLint location, GLfloat x)
5765{
5766 Program *program = mGLState.getProgram();
5767 program->setUniform1fv(location, 1, &x);
5768}
5769
5770void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5771{
5772 Program *program = mGLState.getProgram();
5773 program->setUniform1fv(location, count, v);
5774}
5775
Jamie Madill7e4eff12018-08-08 15:49:26 -04005776void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005777{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005778 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04005779 {
5780 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04005781 mStateCache.onActiveTextureChange(this);
Jamie Madill81c2e252017-09-09 23:32:46 -04005782 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005783}
5784
Jamie Madill7e4eff12018-08-08 15:49:26 -04005785void Context::uniform1i(GLint location, GLint x)
5786{
5787 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
5788}
5789
Jamie Madillc1d770e2017-04-13 17:31:24 -04005790void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5791{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005792 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005793}
5794
5795void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5796{
5797 GLfloat xy[2] = {x, y};
5798 Program *program = mGLState.getProgram();
5799 program->setUniform2fv(location, 1, xy);
5800}
5801
5802void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5803{
5804 Program *program = mGLState.getProgram();
5805 program->setUniform2fv(location, count, v);
5806}
5807
5808void Context::uniform2i(GLint location, GLint x, GLint y)
5809{
5810 GLint xy[2] = {x, y};
5811 Program *program = mGLState.getProgram();
5812 program->setUniform2iv(location, 1, xy);
5813}
5814
5815void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5816{
5817 Program *program = mGLState.getProgram();
5818 program->setUniform2iv(location, count, v);
5819}
5820
5821void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5822{
5823 GLfloat xyz[3] = {x, y, z};
5824 Program *program = mGLState.getProgram();
5825 program->setUniform3fv(location, 1, xyz);
5826}
5827
5828void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5829{
5830 Program *program = mGLState.getProgram();
5831 program->setUniform3fv(location, count, v);
5832}
5833
5834void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5835{
5836 GLint xyz[3] = {x, y, z};
5837 Program *program = mGLState.getProgram();
5838 program->setUniform3iv(location, 1, xyz);
5839}
5840
5841void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5842{
5843 Program *program = mGLState.getProgram();
5844 program->setUniform3iv(location, count, v);
5845}
5846
5847void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5848{
5849 GLfloat xyzw[4] = {x, y, z, w};
5850 Program *program = mGLState.getProgram();
5851 program->setUniform4fv(location, 1, xyzw);
5852}
5853
5854void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5855{
5856 Program *program = mGLState.getProgram();
5857 program->setUniform4fv(location, count, v);
5858}
5859
5860void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5861{
5862 GLint xyzw[4] = {x, y, z, w};
5863 Program *program = mGLState.getProgram();
5864 program->setUniform4iv(location, 1, xyzw);
5865}
5866
5867void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5868{
5869 Program *program = mGLState.getProgram();
5870 program->setUniform4iv(location, count, v);
5871}
5872
5873void Context::uniformMatrix2fv(GLint location,
5874 GLsizei count,
5875 GLboolean transpose,
5876 const GLfloat *value)
5877{
5878 Program *program = mGLState.getProgram();
5879 program->setUniformMatrix2fv(location, count, transpose, value);
5880}
5881
5882void Context::uniformMatrix3fv(GLint location,
5883 GLsizei count,
5884 GLboolean transpose,
5885 const GLfloat *value)
5886{
5887 Program *program = mGLState.getProgram();
5888 program->setUniformMatrix3fv(location, count, transpose, value);
5889}
5890
5891void Context::uniformMatrix4fv(GLint location,
5892 GLsizei count,
5893 GLboolean transpose,
5894 const GLfloat *value)
5895{
5896 Program *program = mGLState.getProgram();
5897 program->setUniformMatrix4fv(location, count, transpose, value);
5898}
5899
5900void Context::validateProgram(GLuint program)
5901{
5902 Program *programObject = getProgram(program);
5903 ASSERT(programObject);
5904 programObject->validate(mCaps);
5905}
5906
Jiajia Qin5451d532017-11-16 17:16:34 +08005907void Context::validateProgramPipeline(GLuint pipeline)
5908{
5909 UNIMPLEMENTED();
5910}
5911
Jamie Madilld04908b2017-06-09 14:15:35 -04005912void Context::getProgramBinary(GLuint program,
5913 GLsizei bufSize,
5914 GLsizei *length,
5915 GLenum *binaryFormat,
5916 void *binary)
5917{
5918 Program *programObject = getProgram(program);
5919 ASSERT(programObject != nullptr);
5920
5921 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5922}
5923
5924void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5925{
5926 Program *programObject = getProgram(program);
5927 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005928
Jamie Madilld04908b2017-06-09 14:15:35 -04005929 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madillc43cdad2018-08-08 15:49:25 -04005930 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04005931 if (programObject->isInUse())
5932 {
5933 mGLState.setObjectDirty(GL_PROGRAM);
5934 }
Jamie Madilld04908b2017-06-09 14:15:35 -04005935}
5936
Jamie Madillff325f12017-08-26 15:06:05 -04005937void Context::uniform1ui(GLint location, GLuint v0)
5938{
5939 Program *program = mGLState.getProgram();
5940 program->setUniform1uiv(location, 1, &v0);
5941}
5942
5943void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5944{
5945 Program *program = mGLState.getProgram();
5946 const GLuint xy[] = {v0, v1};
5947 program->setUniform2uiv(location, 1, xy);
5948}
5949
5950void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5951{
5952 Program *program = mGLState.getProgram();
5953 const GLuint xyz[] = {v0, v1, v2};
5954 program->setUniform3uiv(location, 1, xyz);
5955}
5956
5957void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5958{
5959 Program *program = mGLState.getProgram();
5960 const GLuint xyzw[] = {v0, v1, v2, v3};
5961 program->setUniform4uiv(location, 1, xyzw);
5962}
5963
5964void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5965{
5966 Program *program = mGLState.getProgram();
5967 program->setUniform1uiv(location, count, value);
5968}
5969void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5970{
5971 Program *program = mGLState.getProgram();
5972 program->setUniform2uiv(location, count, value);
5973}
5974
5975void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5976{
5977 Program *program = mGLState.getProgram();
5978 program->setUniform3uiv(location, count, value);
5979}
5980
5981void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5982{
5983 Program *program = mGLState.getProgram();
5984 program->setUniform4uiv(location, count, value);
5985}
5986
Jamie Madillf0e04492017-08-26 15:28:42 -04005987void Context::genQueries(GLsizei n, GLuint *ids)
5988{
5989 for (GLsizei i = 0; i < n; i++)
5990 {
5991 GLuint handle = mQueryHandleAllocator.allocate();
5992 mQueryMap.assign(handle, nullptr);
5993 ids[i] = handle;
5994 }
5995}
5996
5997void Context::deleteQueries(GLsizei n, const GLuint *ids)
5998{
5999 for (int i = 0; i < n; i++)
6000 {
6001 GLuint query = ids[i];
6002
6003 Query *queryObject = nullptr;
6004 if (mQueryMap.erase(query, &queryObject))
6005 {
6006 mQueryHandleAllocator.release(query);
6007 if (queryObject)
6008 {
6009 queryObject->release(this);
6010 }
6011 }
6012 }
6013}
6014
6015GLboolean Context::isQuery(GLuint id)
6016{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006017 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006018}
6019
Jamie Madillc8c95812017-08-26 18:40:09 -04006020void Context::uniformMatrix2x3fv(GLint location,
6021 GLsizei count,
6022 GLboolean transpose,
6023 const GLfloat *value)
6024{
6025 Program *program = mGLState.getProgram();
6026 program->setUniformMatrix2x3fv(location, count, transpose, value);
6027}
6028
6029void Context::uniformMatrix3x2fv(GLint location,
6030 GLsizei count,
6031 GLboolean transpose,
6032 const GLfloat *value)
6033{
6034 Program *program = mGLState.getProgram();
6035 program->setUniformMatrix3x2fv(location, count, transpose, value);
6036}
6037
6038void Context::uniformMatrix2x4fv(GLint location,
6039 GLsizei count,
6040 GLboolean transpose,
6041 const GLfloat *value)
6042{
6043 Program *program = mGLState.getProgram();
6044 program->setUniformMatrix2x4fv(location, count, transpose, value);
6045}
6046
6047void Context::uniformMatrix4x2fv(GLint location,
6048 GLsizei count,
6049 GLboolean transpose,
6050 const GLfloat *value)
6051{
6052 Program *program = mGLState.getProgram();
6053 program->setUniformMatrix4x2fv(location, count, transpose, value);
6054}
6055
6056void Context::uniformMatrix3x4fv(GLint location,
6057 GLsizei count,
6058 GLboolean transpose,
6059 const GLfloat *value)
6060{
6061 Program *program = mGLState.getProgram();
6062 program->setUniformMatrix3x4fv(location, count, transpose, value);
6063}
6064
6065void Context::uniformMatrix4x3fv(GLint location,
6066 GLsizei count,
6067 GLboolean transpose,
6068 const GLfloat *value)
6069{
6070 Program *program = mGLState.getProgram();
6071 program->setUniformMatrix4x3fv(location, count, transpose, value);
6072}
6073
Jamie Madilld7576732017-08-26 18:49:50 -04006074void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6075{
6076 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6077 {
6078 GLuint vertexArray = arrays[arrayIndex];
6079
6080 if (arrays[arrayIndex] != 0)
6081 {
6082 VertexArray *vertexArrayObject = nullptr;
6083 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6084 {
6085 if (vertexArrayObject != nullptr)
6086 {
6087 detachVertexArray(vertexArray);
6088 vertexArrayObject->onDestroy(this);
6089 }
6090
6091 mVertexArrayHandleAllocator.release(vertexArray);
6092 }
6093 }
6094 }
6095}
6096
6097void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6098{
6099 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6100 {
6101 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6102 mVertexArrayMap.assign(vertexArray, nullptr);
6103 arrays[arrayIndex] = vertexArray;
6104 }
6105}
6106
6107bool Context::isVertexArray(GLuint array)
6108{
6109 if (array == 0)
6110 {
6111 return GL_FALSE;
6112 }
6113
6114 VertexArray *vao = getVertexArray(array);
6115 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6116}
6117
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006118void Context::endTransformFeedback()
6119{
6120 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6121 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006122 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006123}
6124
6125void Context::transformFeedbackVaryings(GLuint program,
6126 GLsizei count,
6127 const GLchar *const *varyings,
6128 GLenum bufferMode)
6129{
6130 Program *programObject = getProgram(program);
6131 ASSERT(programObject);
6132 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6133}
6134
6135void Context::getTransformFeedbackVarying(GLuint program,
6136 GLuint index,
6137 GLsizei bufSize,
6138 GLsizei *length,
6139 GLsizei *size,
6140 GLenum *type,
6141 GLchar *name)
6142{
6143 Program *programObject = getProgram(program);
6144 ASSERT(programObject);
6145 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6146}
6147
6148void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6149{
6150 for (int i = 0; i < n; i++)
6151 {
6152 GLuint transformFeedback = ids[i];
6153 if (transformFeedback == 0)
6154 {
6155 continue;
6156 }
6157
6158 TransformFeedback *transformFeedbackObject = nullptr;
6159 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6160 {
6161 if (transformFeedbackObject != nullptr)
6162 {
6163 detachTransformFeedback(transformFeedback);
6164 transformFeedbackObject->release(this);
6165 }
6166
6167 mTransformFeedbackHandleAllocator.release(transformFeedback);
6168 }
6169 }
6170}
6171
6172void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6173{
6174 for (int i = 0; i < n; i++)
6175 {
6176 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6177 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6178 ids[i] = transformFeedback;
6179 }
6180}
6181
6182bool Context::isTransformFeedback(GLuint id)
6183{
6184 if (id == 0)
6185 {
6186 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6187 // returns FALSE
6188 return GL_FALSE;
6189 }
6190
6191 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6192 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6193}
6194
6195void Context::pauseTransformFeedback()
6196{
6197 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6198 transformFeedback->pause();
6199}
6200
6201void Context::resumeTransformFeedback()
6202{
6203 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6204 transformFeedback->resume();
6205}
6206
Jamie Madill12e957f2017-08-26 21:42:26 -04006207void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6208{
6209 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006210 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006211}
6212
Brandon Jones59770802018-04-02 13:18:42 -07006213void Context::getUniformuivRobust(GLuint program,
6214 GLint location,
6215 GLsizei bufSize,
6216 GLsizei *length,
6217 GLuint *params)
6218{
6219 getUniformuiv(program, location, params);
6220}
6221
Jamie Madill12e957f2017-08-26 21:42:26 -04006222GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6223{
6224 const Program *programObject = getProgram(program);
6225 return programObject->getFragDataLocation(name);
6226}
6227
6228void Context::getUniformIndices(GLuint program,
6229 GLsizei uniformCount,
6230 const GLchar *const *uniformNames,
6231 GLuint *uniformIndices)
6232{
6233 const Program *programObject = getProgram(program);
6234 if (!programObject->isLinked())
6235 {
6236 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6237 {
6238 uniformIndices[uniformId] = GL_INVALID_INDEX;
6239 }
6240 }
6241 else
6242 {
6243 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6244 {
6245 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6246 }
6247 }
6248}
6249
6250void Context::getActiveUniformsiv(GLuint program,
6251 GLsizei uniformCount,
6252 const GLuint *uniformIndices,
6253 GLenum pname,
6254 GLint *params)
6255{
6256 const Program *programObject = getProgram(program);
6257 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6258 {
6259 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006260 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006261 }
6262}
6263
6264GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6265{
6266 const Program *programObject = getProgram(program);
6267 return programObject->getUniformBlockIndex(uniformBlockName);
6268}
6269
6270void Context::getActiveUniformBlockiv(GLuint program,
6271 GLuint uniformBlockIndex,
6272 GLenum pname,
6273 GLint *params)
6274{
6275 const Program *programObject = getProgram(program);
6276 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6277}
6278
Brandon Jones59770802018-04-02 13:18:42 -07006279void Context::getActiveUniformBlockivRobust(GLuint program,
6280 GLuint uniformBlockIndex,
6281 GLenum pname,
6282 GLsizei bufSize,
6283 GLsizei *length,
6284 GLint *params)
6285{
6286 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6287}
6288
Jamie Madill12e957f2017-08-26 21:42:26 -04006289void Context::getActiveUniformBlockName(GLuint program,
6290 GLuint uniformBlockIndex,
6291 GLsizei bufSize,
6292 GLsizei *length,
6293 GLchar *uniformBlockName)
6294{
6295 const Program *programObject = getProgram(program);
6296 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6297}
6298
6299void Context::uniformBlockBinding(GLuint program,
6300 GLuint uniformBlockIndex,
6301 GLuint uniformBlockBinding)
6302{
6303 Program *programObject = getProgram(program);
6304 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006305
6306 if (programObject->isInUse())
6307 {
6308 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006309 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006310 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006311}
6312
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006313GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6314{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006315 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6316 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006317
Jamie Madill70b5bb02017-08-28 13:32:37 -04006318 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006319 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006320 if (error.isError())
6321 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006322 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006323 handleError(error);
6324 return nullptr;
6325 }
6326
Jamie Madill70b5bb02017-08-28 13:32:37 -04006327 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006328}
6329
6330GLboolean Context::isSync(GLsync sync)
6331{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006332 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006333}
6334
6335GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6336{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006337 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006338
6339 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006340 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006341 return result;
6342}
6343
6344void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6345{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006346 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006347 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006348}
6349
6350void Context::getInteger64v(GLenum pname, GLint64 *params)
6351{
6352 GLenum nativeType = GL_NONE;
6353 unsigned int numParams = 0;
6354 getQueryParameterInfo(pname, &nativeType, &numParams);
6355
6356 if (nativeType == GL_INT_64_ANGLEX)
6357 {
6358 getInteger64vImpl(pname, params);
6359 }
6360 else
6361 {
6362 CastStateValues(this, nativeType, pname, numParams, params);
6363 }
6364}
6365
Brandon Jones59770802018-04-02 13:18:42 -07006366void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6367{
6368 getInteger64v(pname, data);
6369}
6370
Corentin Wallez336129f2017-10-17 15:55:40 -04006371void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006372{
6373 Buffer *buffer = mGLState.getTargetBuffer(target);
6374 QueryBufferParameteri64v(buffer, pname, params);
6375}
6376
Brandon Jones59770802018-04-02 13:18:42 -07006377void Context::getBufferParameteri64vRobust(BufferBinding target,
6378 GLenum pname,
6379 GLsizei bufSize,
6380 GLsizei *length,
6381 GLint64 *params)
6382{
6383 getBufferParameteri64v(target, pname, params);
6384}
6385
Jamie Madill3ef140a2017-08-26 23:11:21 -04006386void Context::genSamplers(GLsizei count, GLuint *samplers)
6387{
6388 for (int i = 0; i < count; i++)
6389 {
6390 samplers[i] = mState.mSamplers->createSampler();
6391 }
6392}
6393
6394void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6395{
6396 for (int i = 0; i < count; i++)
6397 {
6398 GLuint sampler = samplers[i];
6399
6400 if (mState.mSamplers->getSampler(sampler))
6401 {
6402 detachSampler(sampler);
6403 }
6404
6405 mState.mSamplers->deleteObject(this, sampler);
6406 }
6407}
6408
6409void Context::getInternalformativ(GLenum target,
6410 GLenum internalformat,
6411 GLenum pname,
6412 GLsizei bufSize,
6413 GLint *params)
6414{
6415 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6416 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6417}
6418
Brandon Jones59770802018-04-02 13:18:42 -07006419void Context::getInternalformativRobust(GLenum target,
6420 GLenum internalformat,
6421 GLenum pname,
6422 GLsizei bufSize,
6423 GLsizei *length,
6424 GLint *params)
6425{
6426 getInternalformativ(target, internalformat, pname, bufSize, params);
6427}
6428
Jiajia Qin5451d532017-11-16 17:16:34 +08006429void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6430{
6431 programUniform1iv(program, location, 1, &v0);
6432}
6433
6434void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6435{
6436 GLint xy[2] = {v0, v1};
6437 programUniform2iv(program, location, 1, xy);
6438}
6439
6440void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6441{
6442 GLint xyz[3] = {v0, v1, v2};
6443 programUniform3iv(program, location, 1, xyz);
6444}
6445
6446void Context::programUniform4i(GLuint program,
6447 GLint location,
6448 GLint v0,
6449 GLint v1,
6450 GLint v2,
6451 GLint v3)
6452{
6453 GLint xyzw[4] = {v0, v1, v2, v3};
6454 programUniform4iv(program, location, 1, xyzw);
6455}
6456
6457void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6458{
6459 programUniform1uiv(program, location, 1, &v0);
6460}
6461
6462void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6463{
6464 GLuint xy[2] = {v0, v1};
6465 programUniform2uiv(program, location, 1, xy);
6466}
6467
6468void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6469{
6470 GLuint xyz[3] = {v0, v1, v2};
6471 programUniform3uiv(program, location, 1, xyz);
6472}
6473
6474void Context::programUniform4ui(GLuint program,
6475 GLint location,
6476 GLuint v0,
6477 GLuint v1,
6478 GLuint v2,
6479 GLuint v3)
6480{
6481 GLuint xyzw[4] = {v0, v1, v2, v3};
6482 programUniform4uiv(program, location, 1, xyzw);
6483}
6484
6485void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6486{
6487 programUniform1fv(program, location, 1, &v0);
6488}
6489
6490void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6491{
6492 GLfloat xy[2] = {v0, v1};
6493 programUniform2fv(program, location, 1, xy);
6494}
6495
6496void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6497{
6498 GLfloat xyz[3] = {v0, v1, v2};
6499 programUniform3fv(program, location, 1, xyz);
6500}
6501
6502void Context::programUniform4f(GLuint program,
6503 GLint location,
6504 GLfloat v0,
6505 GLfloat v1,
6506 GLfloat v2,
6507 GLfloat v3)
6508{
6509 GLfloat xyzw[4] = {v0, v1, v2, v3};
6510 programUniform4fv(program, location, 1, xyzw);
6511}
6512
Jamie Madill81c2e252017-09-09 23:32:46 -04006513void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6514{
6515 Program *programObject = getProgram(program);
6516 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006517 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006518}
6519
Jiajia Qin5451d532017-11-16 17:16:34 +08006520void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6521{
6522 Program *programObject = getProgram(program);
6523 ASSERT(programObject);
6524 programObject->setUniform2iv(location, count, value);
6525}
6526
6527void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6528{
6529 Program *programObject = getProgram(program);
6530 ASSERT(programObject);
6531 programObject->setUniform3iv(location, count, value);
6532}
6533
6534void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6535{
6536 Program *programObject = getProgram(program);
6537 ASSERT(programObject);
6538 programObject->setUniform4iv(location, count, value);
6539}
6540
6541void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6542{
6543 Program *programObject = getProgram(program);
6544 ASSERT(programObject);
6545 programObject->setUniform1uiv(location, count, value);
6546}
6547
6548void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6549{
6550 Program *programObject = getProgram(program);
6551 ASSERT(programObject);
6552 programObject->setUniform2uiv(location, count, value);
6553}
6554
6555void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6556{
6557 Program *programObject = getProgram(program);
6558 ASSERT(programObject);
6559 programObject->setUniform3uiv(location, count, value);
6560}
6561
6562void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6563{
6564 Program *programObject = getProgram(program);
6565 ASSERT(programObject);
6566 programObject->setUniform4uiv(location, count, value);
6567}
6568
6569void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6570{
6571 Program *programObject = getProgram(program);
6572 ASSERT(programObject);
6573 programObject->setUniform1fv(location, count, value);
6574}
6575
6576void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6577{
6578 Program *programObject = getProgram(program);
6579 ASSERT(programObject);
6580 programObject->setUniform2fv(location, count, value);
6581}
6582
6583void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6584{
6585 Program *programObject = getProgram(program);
6586 ASSERT(programObject);
6587 programObject->setUniform3fv(location, count, value);
6588}
6589
6590void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6591{
6592 Program *programObject = getProgram(program);
6593 ASSERT(programObject);
6594 programObject->setUniform4fv(location, count, value);
6595}
6596
6597void Context::programUniformMatrix2fv(GLuint program,
6598 GLint location,
6599 GLsizei count,
6600 GLboolean transpose,
6601 const GLfloat *value)
6602{
6603 Program *programObject = getProgram(program);
6604 ASSERT(programObject);
6605 programObject->setUniformMatrix2fv(location, count, transpose, value);
6606}
6607
6608void Context::programUniformMatrix3fv(GLuint program,
6609 GLint location,
6610 GLsizei count,
6611 GLboolean transpose,
6612 const GLfloat *value)
6613{
6614 Program *programObject = getProgram(program);
6615 ASSERT(programObject);
6616 programObject->setUniformMatrix3fv(location, count, transpose, value);
6617}
6618
6619void Context::programUniformMatrix4fv(GLuint program,
6620 GLint location,
6621 GLsizei count,
6622 GLboolean transpose,
6623 const GLfloat *value)
6624{
6625 Program *programObject = getProgram(program);
6626 ASSERT(programObject);
6627 programObject->setUniformMatrix4fv(location, count, transpose, value);
6628}
6629
6630void Context::programUniformMatrix2x3fv(GLuint program,
6631 GLint location,
6632 GLsizei count,
6633 GLboolean transpose,
6634 const GLfloat *value)
6635{
6636 Program *programObject = getProgram(program);
6637 ASSERT(programObject);
6638 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6639}
6640
6641void Context::programUniformMatrix3x2fv(GLuint program,
6642 GLint location,
6643 GLsizei count,
6644 GLboolean transpose,
6645 const GLfloat *value)
6646{
6647 Program *programObject = getProgram(program);
6648 ASSERT(programObject);
6649 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6650}
6651
6652void Context::programUniformMatrix2x4fv(GLuint program,
6653 GLint location,
6654 GLsizei count,
6655 GLboolean transpose,
6656 const GLfloat *value)
6657{
6658 Program *programObject = getProgram(program);
6659 ASSERT(programObject);
6660 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6661}
6662
6663void Context::programUniformMatrix4x2fv(GLuint program,
6664 GLint location,
6665 GLsizei count,
6666 GLboolean transpose,
6667 const GLfloat *value)
6668{
6669 Program *programObject = getProgram(program);
6670 ASSERT(programObject);
6671 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6672}
6673
6674void Context::programUniformMatrix3x4fv(GLuint program,
6675 GLint location,
6676 GLsizei count,
6677 GLboolean transpose,
6678 const GLfloat *value)
6679{
6680 Program *programObject = getProgram(program);
6681 ASSERT(programObject);
6682 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6683}
6684
6685void Context::programUniformMatrix4x3fv(GLuint program,
6686 GLint location,
6687 GLsizei count,
6688 GLboolean transpose,
6689 const GLfloat *value)
6690{
6691 Program *programObject = getProgram(program);
6692 ASSERT(programObject);
6693 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6694}
6695
Jamie Madill81c2e252017-09-09 23:32:46 -04006696void Context::onTextureChange(const Texture *texture)
6697{
6698 // Conservatively assume all textures are dirty.
6699 // TODO(jmadill): More fine-grained update.
6700 mGLState.setObjectDirty(GL_TEXTURE);
6701}
6702
James Darpiniane8a93c62018-01-04 18:02:24 -08006703bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6704{
6705 return mGLState.isCurrentTransformFeedback(tf);
6706}
James Darpiniane8a93c62018-01-04 18:02:24 -08006707
Yunchao Hea336b902017-08-02 16:05:21 +08006708void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6709{
6710 for (int i = 0; i < count; i++)
6711 {
6712 pipelines[i] = createProgramPipeline();
6713 }
6714}
6715
6716void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6717{
6718 for (int i = 0; i < count; i++)
6719 {
6720 if (pipelines[i] != 0)
6721 {
6722 deleteProgramPipeline(pipelines[i]);
6723 }
6724 }
6725}
6726
6727GLboolean Context::isProgramPipeline(GLuint pipeline)
6728{
6729 if (pipeline == 0)
6730 {
6731 return GL_FALSE;
6732 }
6733
6734 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6735}
6736
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006737void Context::finishFenceNV(GLuint fence)
6738{
6739 FenceNV *fenceObject = getFenceNV(fence);
6740
6741 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006742 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006743}
6744
6745void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6746{
6747 FenceNV *fenceObject = getFenceNV(fence);
6748
6749 ASSERT(fenceObject && fenceObject->isSet());
6750
6751 switch (pname)
6752 {
6753 case GL_FENCE_STATUS_NV:
6754 {
6755 // GL_NV_fence spec:
6756 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6757 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6758 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6759 GLboolean status = GL_TRUE;
6760 if (fenceObject->getStatus() != GL_TRUE)
6761 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006762 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006763 }
6764 *params = status;
6765 break;
6766 }
6767
6768 case GL_FENCE_CONDITION_NV:
6769 {
6770 *params = static_cast<GLint>(fenceObject->getCondition());
6771 break;
6772 }
6773
6774 default:
6775 UNREACHABLE();
6776 }
6777}
6778
6779void Context::getTranslatedShaderSource(GLuint shader,
6780 GLsizei bufsize,
6781 GLsizei *length,
6782 GLchar *source)
6783{
6784 Shader *shaderObject = getShader(shader);
6785 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006786 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006787}
6788
6789void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6790{
6791 Program *programObject = getProgram(program);
6792 ASSERT(programObject);
6793
6794 programObject->getUniformfv(this, location, params);
6795}
6796
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006797void Context::getnUniformfvRobust(GLuint program,
6798 GLint location,
6799 GLsizei bufSize,
6800 GLsizei *length,
6801 GLfloat *params)
6802{
6803 UNIMPLEMENTED();
6804}
6805
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006806void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6807{
6808 Program *programObject = getProgram(program);
6809 ASSERT(programObject);
6810
6811 programObject->getUniformiv(this, location, params);
6812}
6813
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006814void Context::getnUniformivRobust(GLuint program,
6815 GLint location,
6816 GLsizei bufSize,
6817 GLsizei *length,
6818 GLint *params)
6819{
6820 UNIMPLEMENTED();
6821}
6822
6823void Context::getnUniformuivRobust(GLuint program,
6824 GLint location,
6825 GLsizei bufSize,
6826 GLsizei *length,
6827 GLuint *params)
6828{
6829 UNIMPLEMENTED();
6830}
6831
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006832GLboolean Context::isFenceNV(GLuint fence)
6833{
6834 FenceNV *fenceObject = getFenceNV(fence);
6835
6836 if (fenceObject == nullptr)
6837 {
6838 return GL_FALSE;
6839 }
6840
6841 // GL_NV_fence spec:
6842 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6843 // existing fence.
6844 return fenceObject->isSet();
6845}
6846
6847void Context::readnPixels(GLint x,
6848 GLint y,
6849 GLsizei width,
6850 GLsizei height,
6851 GLenum format,
6852 GLenum type,
6853 GLsizei bufSize,
6854 void *data)
6855{
6856 return readPixels(x, y, width, height, format, type, data);
6857}
6858
Jamie Madill007530e2017-12-28 14:27:04 -05006859void Context::setFenceNV(GLuint fence, GLenum condition)
6860{
6861 ASSERT(condition == GL_ALL_COMPLETED_NV);
6862
6863 FenceNV *fenceObject = getFenceNV(fence);
6864 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006865 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006866}
6867
6868GLboolean Context::testFenceNV(GLuint fence)
6869{
6870 FenceNV *fenceObject = getFenceNV(fence);
6871
6872 ASSERT(fenceObject != nullptr);
6873 ASSERT(fenceObject->isSet() == GL_TRUE);
6874
6875 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006876 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006877 if (error.isError())
6878 {
6879 handleError(error);
6880 return GL_TRUE;
6881 }
6882
6883 return result;
6884}
6885
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006886void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006887{
6888 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006889 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006890 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006891}
6892
Jamie Madillfa920eb2018-01-04 11:45:50 -05006893void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006894{
6895 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006896 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006897 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6898}
6899
Jamie Madillfa920eb2018-01-04 11:45:50 -05006900void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6901{
6902 UNIMPLEMENTED();
6903}
6904
Jamie Madill5b772312018-03-08 20:28:32 -05006905bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6906{
6907 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6908 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6909 // to the fact that it is stored internally as a float, and so would require conversion
6910 // if returned from Context::getIntegerv. Since this conversion is already implemented
6911 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6912 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6913 // application.
6914 switch (pname)
6915 {
6916 case GL_COMPRESSED_TEXTURE_FORMATS:
6917 {
6918 *type = GL_INT;
6919 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6920 return true;
6921 }
6922 case GL_SHADER_BINARY_FORMATS:
6923 {
6924 *type = GL_INT;
6925 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6926 return true;
6927 }
6928
6929 case GL_MAX_VERTEX_ATTRIBS:
6930 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6931 case GL_MAX_VARYING_VECTORS:
6932 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6933 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6934 case GL_MAX_TEXTURE_IMAGE_UNITS:
6935 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6936 case GL_MAX_RENDERBUFFER_SIZE:
6937 case GL_NUM_SHADER_BINARY_FORMATS:
6938 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6939 case GL_ARRAY_BUFFER_BINDING:
6940 case GL_FRAMEBUFFER_BINDING:
6941 case GL_RENDERBUFFER_BINDING:
6942 case GL_CURRENT_PROGRAM:
6943 case GL_PACK_ALIGNMENT:
6944 case GL_UNPACK_ALIGNMENT:
6945 case GL_GENERATE_MIPMAP_HINT:
6946 case GL_RED_BITS:
6947 case GL_GREEN_BITS:
6948 case GL_BLUE_BITS:
6949 case GL_ALPHA_BITS:
6950 case GL_DEPTH_BITS:
6951 case GL_STENCIL_BITS:
6952 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6953 case GL_CULL_FACE_MODE:
6954 case GL_FRONT_FACE:
6955 case GL_ACTIVE_TEXTURE:
6956 case GL_STENCIL_FUNC:
6957 case GL_STENCIL_VALUE_MASK:
6958 case GL_STENCIL_REF:
6959 case GL_STENCIL_FAIL:
6960 case GL_STENCIL_PASS_DEPTH_FAIL:
6961 case GL_STENCIL_PASS_DEPTH_PASS:
6962 case GL_STENCIL_BACK_FUNC:
6963 case GL_STENCIL_BACK_VALUE_MASK:
6964 case GL_STENCIL_BACK_REF:
6965 case GL_STENCIL_BACK_FAIL:
6966 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6967 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6968 case GL_DEPTH_FUNC:
6969 case GL_BLEND_SRC_RGB:
6970 case GL_BLEND_SRC_ALPHA:
6971 case GL_BLEND_DST_RGB:
6972 case GL_BLEND_DST_ALPHA:
6973 case GL_BLEND_EQUATION_RGB:
6974 case GL_BLEND_EQUATION_ALPHA:
6975 case GL_STENCIL_WRITEMASK:
6976 case GL_STENCIL_BACK_WRITEMASK:
6977 case GL_STENCIL_CLEAR_VALUE:
6978 case GL_SUBPIXEL_BITS:
6979 case GL_MAX_TEXTURE_SIZE:
6980 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6981 case GL_SAMPLE_BUFFERS:
6982 case GL_SAMPLES:
6983 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6984 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6985 case GL_TEXTURE_BINDING_2D:
6986 case GL_TEXTURE_BINDING_CUBE_MAP:
6987 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6988 {
6989 *type = GL_INT;
6990 *numParams = 1;
6991 return true;
6992 }
6993 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6994 {
6995 if (!getExtensions().packReverseRowOrder)
6996 {
6997 return false;
6998 }
6999 *type = GL_INT;
7000 *numParams = 1;
7001 return true;
7002 }
7003 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7004 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7005 {
7006 if (!getExtensions().textureRectangle)
7007 {
7008 return false;
7009 }
7010 *type = GL_INT;
7011 *numParams = 1;
7012 return true;
7013 }
7014 case GL_MAX_DRAW_BUFFERS_EXT:
7015 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7016 {
7017 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7018 {
7019 return false;
7020 }
7021 *type = GL_INT;
7022 *numParams = 1;
7023 return true;
7024 }
7025 case GL_MAX_VIEWPORT_DIMS:
7026 {
7027 *type = GL_INT;
7028 *numParams = 2;
7029 return true;
7030 }
7031 case GL_VIEWPORT:
7032 case GL_SCISSOR_BOX:
7033 {
7034 *type = GL_INT;
7035 *numParams = 4;
7036 return true;
7037 }
7038 case GL_SHADER_COMPILER:
7039 case GL_SAMPLE_COVERAGE_INVERT:
7040 case GL_DEPTH_WRITEMASK:
7041 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7042 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7043 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7044 // bool-natural
7045 case GL_SAMPLE_COVERAGE:
7046 case GL_SCISSOR_TEST:
7047 case GL_STENCIL_TEST:
7048 case GL_DEPTH_TEST:
7049 case GL_BLEND:
7050 case GL_DITHER:
7051 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7052 {
7053 *type = GL_BOOL;
7054 *numParams = 1;
7055 return true;
7056 }
7057 case GL_COLOR_WRITEMASK:
7058 {
7059 *type = GL_BOOL;
7060 *numParams = 4;
7061 return true;
7062 }
7063 case GL_POLYGON_OFFSET_FACTOR:
7064 case GL_POLYGON_OFFSET_UNITS:
7065 case GL_SAMPLE_COVERAGE_VALUE:
7066 case GL_DEPTH_CLEAR_VALUE:
7067 case GL_LINE_WIDTH:
7068 {
7069 *type = GL_FLOAT;
7070 *numParams = 1;
7071 return true;
7072 }
7073 case GL_ALIASED_LINE_WIDTH_RANGE:
7074 case GL_ALIASED_POINT_SIZE_RANGE:
7075 case GL_DEPTH_RANGE:
7076 {
7077 *type = GL_FLOAT;
7078 *numParams = 2;
7079 return true;
7080 }
7081 case GL_COLOR_CLEAR_VALUE:
7082 case GL_BLEND_COLOR:
7083 {
7084 *type = GL_FLOAT;
7085 *numParams = 4;
7086 return true;
7087 }
7088 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7089 if (!getExtensions().textureFilterAnisotropic)
7090 {
7091 return false;
7092 }
7093 *type = GL_FLOAT;
7094 *numParams = 1;
7095 return true;
7096 case GL_TIMESTAMP_EXT:
7097 if (!getExtensions().disjointTimerQuery)
7098 {
7099 return false;
7100 }
7101 *type = GL_INT_64_ANGLEX;
7102 *numParams = 1;
7103 return true;
7104 case GL_GPU_DISJOINT_EXT:
7105 if (!getExtensions().disjointTimerQuery)
7106 {
7107 return false;
7108 }
7109 *type = GL_INT;
7110 *numParams = 1;
7111 return true;
7112 case GL_COVERAGE_MODULATION_CHROMIUM:
7113 if (!getExtensions().framebufferMixedSamples)
7114 {
7115 return false;
7116 }
7117 *type = GL_INT;
7118 *numParams = 1;
7119 return true;
7120 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7121 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7122 {
7123 return false;
7124 }
7125 *type = GL_INT;
7126 *numParams = 1;
7127 return true;
7128 }
7129
7130 if (getExtensions().debug)
7131 {
7132 switch (pname)
7133 {
7134 case GL_DEBUG_LOGGED_MESSAGES:
7135 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7136 case GL_DEBUG_GROUP_STACK_DEPTH:
7137 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7138 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7139 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7140 case GL_MAX_LABEL_LENGTH:
7141 *type = GL_INT;
7142 *numParams = 1;
7143 return true;
7144
7145 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7146 case GL_DEBUG_OUTPUT:
7147 *type = GL_BOOL;
7148 *numParams = 1;
7149 return true;
7150 }
7151 }
7152
7153 if (getExtensions().multisampleCompatibility)
7154 {
7155 switch (pname)
7156 {
7157 case GL_MULTISAMPLE_EXT:
7158 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7159 *type = GL_BOOL;
7160 *numParams = 1;
7161 return true;
7162 }
7163 }
7164
7165 if (getExtensions().pathRendering)
7166 {
7167 switch (pname)
7168 {
7169 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7170 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7171 *type = GL_FLOAT;
7172 *numParams = 16;
7173 return true;
7174 }
7175 }
7176
7177 if (getExtensions().bindGeneratesResource)
7178 {
7179 switch (pname)
7180 {
7181 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7182 *type = GL_BOOL;
7183 *numParams = 1;
7184 return true;
7185 }
7186 }
7187
7188 if (getExtensions().clientArrays)
7189 {
7190 switch (pname)
7191 {
7192 case GL_CLIENT_ARRAYS_ANGLE:
7193 *type = GL_BOOL;
7194 *numParams = 1;
7195 return true;
7196 }
7197 }
7198
7199 if (getExtensions().sRGBWriteControl)
7200 {
7201 switch (pname)
7202 {
7203 case GL_FRAMEBUFFER_SRGB_EXT:
7204 *type = GL_BOOL;
7205 *numParams = 1;
7206 return true;
7207 }
7208 }
7209
7210 if (getExtensions().robustResourceInitialization &&
7211 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7212 {
7213 *type = GL_BOOL;
7214 *numParams = 1;
7215 return true;
7216 }
7217
7218 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7219 {
7220 *type = GL_BOOL;
7221 *numParams = 1;
7222 return true;
7223 }
7224
jchen1082af6202018-06-22 10:59:52 +08007225 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7226 {
7227 *type = GL_INT;
7228 *numParams = 1;
7229 return true;
7230 }
7231
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007232 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7233 {
7234 *type = GL_INT;
7235 *numParams = 1;
7236 return true;
7237 }
7238
Jamie Madill5b772312018-03-08 20:28:32 -05007239 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7240 switch (pname)
7241 {
7242 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7243 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7244 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7245 {
7246 return false;
7247 }
7248 *type = GL_INT;
7249 *numParams = 1;
7250 return true;
7251
7252 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7253 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7254 {
7255 return false;
7256 }
7257 *type = GL_INT;
7258 *numParams = 1;
7259 return true;
7260
7261 case GL_PROGRAM_BINARY_FORMATS_OES:
7262 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7263 {
7264 return false;
7265 }
7266 *type = GL_INT;
7267 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7268 return true;
7269
7270 case GL_PACK_ROW_LENGTH:
7271 case GL_PACK_SKIP_ROWS:
7272 case GL_PACK_SKIP_PIXELS:
7273 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7274 {
7275 return false;
7276 }
7277 *type = GL_INT;
7278 *numParams = 1;
7279 return true;
7280 case GL_UNPACK_ROW_LENGTH:
7281 case GL_UNPACK_SKIP_ROWS:
7282 case GL_UNPACK_SKIP_PIXELS:
7283 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7284 {
7285 return false;
7286 }
7287 *type = GL_INT;
7288 *numParams = 1;
7289 return true;
7290 case GL_VERTEX_ARRAY_BINDING:
7291 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7292 {
7293 return false;
7294 }
7295 *type = GL_INT;
7296 *numParams = 1;
7297 return true;
7298 case GL_PIXEL_PACK_BUFFER_BINDING:
7299 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7300 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7301 {
7302 return false;
7303 }
7304 *type = GL_INT;
7305 *numParams = 1;
7306 return true;
7307 case GL_MAX_SAMPLES:
7308 {
7309 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7310 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7311 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7312 {
7313 return false;
7314 }
7315 *type = GL_INT;
7316 *numParams = 1;
7317 return true;
7318
7319 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7320 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7321 {
7322 return false;
7323 }
7324 *type = GL_INT;
7325 *numParams = 1;
7326 return true;
7327 }
7328 }
7329
7330 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7331 {
7332 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7333 {
7334 return false;
7335 }
7336 *type = GL_INT;
7337 *numParams = 1;
7338 return true;
7339 }
7340
7341 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7342 {
7343 *type = GL_INT;
7344 *numParams = 1;
7345 return true;
7346 }
7347
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007348 if (getClientVersion() < Version(2, 0))
7349 {
7350 switch (pname)
7351 {
7352 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007353 case GL_CLIENT_ACTIVE_TEXTURE:
7354 case GL_MATRIX_MODE:
7355 case GL_MAX_TEXTURE_UNITS:
7356 case GL_MAX_MODELVIEW_STACK_DEPTH:
7357 case GL_MAX_PROJECTION_STACK_DEPTH:
7358 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007359 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007360 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007361 case GL_VERTEX_ARRAY_STRIDE:
7362 case GL_NORMAL_ARRAY_STRIDE:
7363 case GL_COLOR_ARRAY_STRIDE:
7364 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7365 case GL_VERTEX_ARRAY_SIZE:
7366 case GL_COLOR_ARRAY_SIZE:
7367 case GL_TEXTURE_COORD_ARRAY_SIZE:
7368 case GL_VERTEX_ARRAY_TYPE:
7369 case GL_NORMAL_ARRAY_TYPE:
7370 case GL_COLOR_ARRAY_TYPE:
7371 case GL_TEXTURE_COORD_ARRAY_TYPE:
7372 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7373 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7374 case GL_COLOR_ARRAY_BUFFER_BINDING:
7375 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7376 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7377 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7378 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007379 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007380 case GL_MODELVIEW_STACK_DEPTH:
7381 case GL_PROJECTION_STACK_DEPTH:
7382 case GL_TEXTURE_STACK_DEPTH:
7383 case GL_LOGIC_OP_MODE:
7384 case GL_BLEND_SRC:
7385 case GL_BLEND_DST:
7386 case GL_PERSPECTIVE_CORRECTION_HINT:
7387 case GL_POINT_SMOOTH_HINT:
7388 case GL_LINE_SMOOTH_HINT:
7389 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007390 *type = GL_INT;
7391 *numParams = 1;
7392 return true;
7393 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007394 case GL_FOG_DENSITY:
7395 case GL_FOG_START:
7396 case GL_FOG_END:
7397 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007398 case GL_POINT_SIZE:
7399 case GL_POINT_SIZE_MIN:
7400 case GL_POINT_SIZE_MAX:
7401 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007402 *type = GL_FLOAT;
7403 *numParams = 1;
7404 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007405 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007406 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007407 *type = GL_FLOAT;
7408 *numParams = 2;
7409 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007410 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007411 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007412 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007413 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007414 *type = GL_FLOAT;
7415 *numParams = 4;
7416 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007417 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007418 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007419 *type = GL_FLOAT;
7420 *numParams = 3;
7421 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007422 case GL_MODELVIEW_MATRIX:
7423 case GL_PROJECTION_MATRIX:
7424 case GL_TEXTURE_MATRIX:
7425 *type = GL_FLOAT;
7426 *numParams = 16;
7427 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007428 case GL_LIGHT_MODEL_TWO_SIDE:
7429 *type = GL_BOOL;
7430 *numParams = 1;
7431 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007432 }
7433 }
7434
Jamie Madill5b772312018-03-08 20:28:32 -05007435 if (getClientVersion() < Version(3, 0))
7436 {
7437 return false;
7438 }
7439
7440 // Check for ES3.0+ parameter names
7441 switch (pname)
7442 {
7443 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7444 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7445 case GL_UNIFORM_BUFFER_BINDING:
7446 case GL_TRANSFORM_FEEDBACK_BINDING:
7447 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7448 case GL_COPY_READ_BUFFER_BINDING:
7449 case GL_COPY_WRITE_BUFFER_BINDING:
7450 case GL_SAMPLER_BINDING:
7451 case GL_READ_BUFFER:
7452 case GL_TEXTURE_BINDING_3D:
7453 case GL_TEXTURE_BINDING_2D_ARRAY:
7454 case GL_MAX_3D_TEXTURE_SIZE:
7455 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7456 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7457 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7458 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7459 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7460 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7461 case GL_MAX_VARYING_COMPONENTS:
7462 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7463 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7464 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7465 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7466 case GL_NUM_EXTENSIONS:
7467 case GL_MAJOR_VERSION:
7468 case GL_MINOR_VERSION:
7469 case GL_MAX_ELEMENTS_INDICES:
7470 case GL_MAX_ELEMENTS_VERTICES:
7471 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7472 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7473 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7474 case GL_UNPACK_IMAGE_HEIGHT:
7475 case GL_UNPACK_SKIP_IMAGES:
7476 {
7477 *type = GL_INT;
7478 *numParams = 1;
7479 return true;
7480 }
7481
7482 case GL_MAX_ELEMENT_INDEX:
7483 case GL_MAX_UNIFORM_BLOCK_SIZE:
7484 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7485 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7486 case GL_MAX_SERVER_WAIT_TIMEOUT:
7487 {
7488 *type = GL_INT_64_ANGLEX;
7489 *numParams = 1;
7490 return true;
7491 }
7492
7493 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7494 case GL_TRANSFORM_FEEDBACK_PAUSED:
7495 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7496 case GL_RASTERIZER_DISCARD:
7497 {
7498 *type = GL_BOOL;
7499 *numParams = 1;
7500 return true;
7501 }
7502
7503 case GL_MAX_TEXTURE_LOD_BIAS:
7504 {
7505 *type = GL_FLOAT;
7506 *numParams = 1;
7507 return true;
7508 }
7509 }
7510
7511 if (getExtensions().requestExtension)
7512 {
7513 switch (pname)
7514 {
7515 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7516 *type = GL_INT;
7517 *numParams = 1;
7518 return true;
7519 }
7520 }
7521
7522 if (getClientVersion() < Version(3, 1))
7523 {
7524 return false;
7525 }
7526
7527 switch (pname)
7528 {
7529 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7530 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7531 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7532 case GL_MAX_FRAMEBUFFER_WIDTH:
7533 case GL_MAX_FRAMEBUFFER_HEIGHT:
7534 case GL_MAX_FRAMEBUFFER_SAMPLES:
7535 case GL_MAX_SAMPLE_MASK_WORDS:
7536 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7537 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7538 case GL_MAX_INTEGER_SAMPLES:
7539 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7540 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7541 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7542 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7543 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7544 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7545 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7546 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7547 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7548 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7549 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7550 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7551 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7552 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7553 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7554 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7555 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7556 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7557 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7558 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7559 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7560 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7561 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7562 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7563 case GL_MAX_UNIFORM_LOCATIONS:
7564 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7565 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7566 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7567 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7568 case GL_MAX_IMAGE_UNITS:
7569 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7570 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7571 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7572 case GL_SHADER_STORAGE_BUFFER_BINDING:
7573 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7574 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007575 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007576 *type = GL_INT;
7577 *numParams = 1;
7578 return true;
7579 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7580 *type = GL_INT_64_ANGLEX;
7581 *numParams = 1;
7582 return true;
7583 case GL_SAMPLE_MASK:
7584 *type = GL_BOOL;
7585 *numParams = 1;
7586 return true;
7587 }
7588
7589 if (getExtensions().geometryShader)
7590 {
7591 switch (pname)
7592 {
7593 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7594 case GL_LAYER_PROVOKING_VERTEX_EXT:
7595 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7596 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7597 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7598 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7599 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7600 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7601 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7602 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7603 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7604 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7605 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7606 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7607 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7608 *type = GL_INT;
7609 *numParams = 1;
7610 return true;
7611 }
7612 }
7613
7614 return false;
7615}
7616
7617bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7618{
7619 if (getClientVersion() < Version(3, 0))
7620 {
7621 return false;
7622 }
7623
7624 switch (target)
7625 {
7626 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7627 case GL_UNIFORM_BUFFER_BINDING:
7628 {
7629 *type = GL_INT;
7630 *numParams = 1;
7631 return true;
7632 }
7633 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7634 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7635 case GL_UNIFORM_BUFFER_START:
7636 case GL_UNIFORM_BUFFER_SIZE:
7637 {
7638 *type = GL_INT_64_ANGLEX;
7639 *numParams = 1;
7640 return true;
7641 }
7642 }
7643
7644 if (getClientVersion() < Version(3, 1))
7645 {
7646 return false;
7647 }
7648
7649 switch (target)
7650 {
7651 case GL_IMAGE_BINDING_LAYERED:
7652 {
7653 *type = GL_BOOL;
7654 *numParams = 1;
7655 return true;
7656 }
7657 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7658 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7659 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7660 case GL_SHADER_STORAGE_BUFFER_BINDING:
7661 case GL_VERTEX_BINDING_BUFFER:
7662 case GL_VERTEX_BINDING_DIVISOR:
7663 case GL_VERTEX_BINDING_OFFSET:
7664 case GL_VERTEX_BINDING_STRIDE:
7665 case GL_SAMPLE_MASK_VALUE:
7666 case GL_IMAGE_BINDING_NAME:
7667 case GL_IMAGE_BINDING_LEVEL:
7668 case GL_IMAGE_BINDING_LAYER:
7669 case GL_IMAGE_BINDING_ACCESS:
7670 case GL_IMAGE_BINDING_FORMAT:
7671 {
7672 *type = GL_INT;
7673 *numParams = 1;
7674 return true;
7675 }
7676 case GL_ATOMIC_COUNTER_BUFFER_START:
7677 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7678 case GL_SHADER_STORAGE_BUFFER_START:
7679 case GL_SHADER_STORAGE_BUFFER_SIZE:
7680 {
7681 *type = GL_INT_64_ANGLEX;
7682 *numParams = 1;
7683 return true;
7684 }
7685 }
7686
7687 return false;
7688}
7689
7690Program *Context::getProgram(GLuint handle) const
7691{
7692 return mState.mShaderPrograms->getProgram(handle);
7693}
7694
7695Shader *Context::getShader(GLuint handle) const
7696{
7697 return mState.mShaderPrograms->getShader(handle);
7698}
7699
7700bool Context::isTextureGenerated(GLuint texture) const
7701{
7702 return mState.mTextures->isHandleGenerated(texture);
7703}
7704
Jamie Madill5b772312018-03-08 20:28:32 -05007705bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7706{
7707 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7708}
7709
7710bool Context::isFramebufferGenerated(GLuint framebuffer) const
7711{
7712 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7713}
7714
7715bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7716{
7717 return mState.mPipelines->isHandleGenerated(pipeline);
7718}
7719
7720bool Context::usingDisplayTextureShareGroup() const
7721{
7722 return mDisplayTextureShareGroup;
7723}
7724
7725GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7726{
7727 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7728 internalformat == GL_DEPTH_STENCIL
7729 ? GL_DEPTH24_STENCIL8
7730 : internalformat;
7731}
7732
jchen1082af6202018-06-22 10:59:52 +08007733void Context::maxShaderCompilerThreads(GLuint count)
7734{
jchen107ae70d82018-07-06 13:47:01 +08007735 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08007736 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007737 // A count of zero specifies a request for no parallel compiling or linking.
7738 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7739 {
7740 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7741 }
7742 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007743}
7744
Jamie Madill2eb65032018-07-30 10:25:57 -04007745bool Context::isGLES1() const
7746{
7747 return mState.getClientVersion() < Version(2, 0);
7748}
7749
Jamie Madilla11819d2018-07-30 10:26:01 -04007750void Context::onSubjectStateChange(const Context *context,
7751 angle::SubjectIndex index,
7752 angle::SubjectMessage message)
7753{
Jamie Madilla11819d2018-07-30 10:26:01 -04007754 switch (index)
7755 {
7756 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007757 switch (message)
7758 {
7759 case angle::SubjectMessage::CONTENTS_CHANGED:
7760 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
7761 mStateCache.onVertexArrayBufferContentsChange(this);
7762 break;
7763 case angle::SubjectMessage::RESOURCE_MAPPED:
7764 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7765 case angle::SubjectMessage::BINDING_CHANGED:
7766 mStateCache.onVertexArrayBufferStateChange(this);
7767 break;
7768 default:
7769 break;
7770 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007771 break;
7772
7773 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007774 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7775 {
7776 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
7777 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007778 break;
7779
7780 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007781 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7782 {
7783 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
7784 }
7785 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04007786 break;
7787
7788 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04007789 if (index < kTextureMaxSubjectIndex)
7790 {
7791 mGLState.onActiveTextureStateChange(index);
Jamie Madilld84b6732018-09-06 15:54:35 -04007792 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007793 }
Jamie Madille25b8002018-09-20 13:39:49 -04007794 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04007795 {
Jamie Madill6d32cef2018-08-14 02:34:28 -04007796 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04007797 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007798 }
Jamie Madille25b8002018-09-20 13:39:49 -04007799 else
7800 {
7801 ASSERT(index < kSamplerMaxSubjectIndex);
7802 mGLState.setSamplerDirty(index - kSampler0SubjectIndex);
7803 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007804 break;
7805 }
7806}
7807
Jamie Madill6b873dd2018-07-12 23:56:30 -04007808// ErrorSet implementation.
7809ErrorSet::ErrorSet(Context *context) : mContext(context)
7810{
7811}
7812
7813ErrorSet::~ErrorSet() = default;
7814
Jamie Madill306b6c12018-07-27 08:12:49 -04007815void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007816{
7817 // This internal enum is used to filter internal errors that are already handled.
7818 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7819 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7820 {
7821 return;
7822 }
7823
7824 if (ANGLE_UNLIKELY(error.isError()))
7825 {
7826 GLenum code = error.getCode();
7827 mErrors.insert(code);
7828 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7829 {
7830 mContext->markContextLost();
7831 }
7832
7833 ASSERT(!error.getMessage().empty());
7834 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7835 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7836 error.getMessage());
7837 }
7838}
7839
7840bool ErrorSet::empty() const
7841{
7842 return mErrors.empty();
7843}
7844
7845GLenum ErrorSet::popError()
7846{
7847 ASSERT(!empty());
7848 GLenum error = *mErrors.begin();
7849 mErrors.erase(mErrors.begin());
7850 return error;
7851}
Jamie Madilldc358af2018-07-31 11:22:13 -04007852
7853// StateCache implementation.
Jamie Madill16e28fd2018-09-12 11:03:05 -04007854StateCache::StateCache(Context *context)
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007855 : mCachedHasAnyEnabledClientAttrib(false),
7856 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04007857 mCachedInstancedVertexElementLimit(0),
7858 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madilldc358af2018-07-31 11:22:13 -04007859{
Jamie Madill16e28fd2018-09-12 11:03:05 -04007860 updateValidDrawModes(context);
Jamie Madilldc358af2018-07-31 11:22:13 -04007861}
7862
7863StateCache::~StateCache() = default;
7864
7865void StateCache::updateActiveAttribsMask(Context *context)
7866{
7867 bool isGLES1 = context->isGLES1();
7868 const State &glState = context->getGLState();
7869
7870 if (!isGLES1 && !glState.getProgram())
7871 {
7872 mCachedActiveBufferedAttribsMask = AttributesMask();
7873 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04007874 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04007875 return;
7876 }
7877
7878 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7879 : glState.getProgram()->getActiveAttribLocationsMask();
7880
7881 const VertexArray *vao = glState.getVertexArray();
7882 ASSERT(vao);
7883
7884 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7885 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04007886 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007887
Jamie Madill0a17e482018-08-31 17:19:11 -04007888 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
7889 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04007890 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007891 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7892}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007893
7894void StateCache::updateVertexElementLimits(Context *context)
7895{
7896 const VertexArray *vao = context->getGLState().getVertexArray();
7897
7898 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7899 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7900
7901 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
7902 // If there are no buffered attributes then we should not limit the draw call count.
7903 if (!vao || !mCachedActiveBufferedAttribsMask.any())
7904 {
7905 return;
7906 }
7907
7908 const auto &vertexAttribs = vao->getVertexAttributes();
7909 const auto &vertexBindings = vao->getVertexBindings();
7910
7911 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
7912 {
7913 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
7914 ASSERT(attrib.enabled);
7915
7916 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
7917 ASSERT(context->isGLES1() ||
7918 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
7919
7920 GLint64 limit = attrib.getCachedElementLimit();
7921 if (binding.getDivisor() > 0)
7922 {
7923 mCachedInstancedVertexElementLimit =
7924 std::min(mCachedInstancedVertexElementLimit, limit);
7925 }
7926 else
7927 {
7928 mCachedNonInstancedVertexElementLimit =
7929 std::min(mCachedNonInstancedVertexElementLimit, limit);
7930 }
7931 }
7932}
Jamie Madillc43cdad2018-08-08 15:49:25 -04007933
Jamie Madilld84b6732018-09-06 15:54:35 -04007934void StateCache::updateBasicDrawStatesError()
7935{
7936 mCachedBasicDrawStatesError = kInvalidPointer;
7937}
7938
7939intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
7940{
7941 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
7942 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
7943 return mCachedBasicDrawStatesError;
7944}
7945
Jamie Madillc43cdad2018-08-08 15:49:25 -04007946void StateCache::onVertexArrayBindingChange(Context *context)
7947{
7948 updateActiveAttribsMask(context);
7949 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007950 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007951}
7952
7953void StateCache::onProgramExecutableChange(Context *context)
7954{
7955 updateActiveAttribsMask(context);
7956 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007957 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04007958 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04007959}
7960
Jamie Madilld84b6732018-09-06 15:54:35 -04007961void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04007962{
7963 updateVertexElementLimits(context);
7964}
7965
Jamie Madilld84b6732018-09-06 15:54:35 -04007966void StateCache::onVertexArrayBufferContentsChange(Context *context)
7967{
7968 updateVertexElementLimits(context);
7969 updateBasicDrawStatesError();
7970}
7971
Jamie Madillc43cdad2018-08-08 15:49:25 -04007972void StateCache::onVertexArrayStateChange(Context *context)
7973{
7974 updateActiveAttribsMask(context);
7975 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007976 updateBasicDrawStatesError();
7977}
7978
7979void StateCache::onVertexArrayBufferStateChange(Context *context)
7980{
7981 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007982}
7983
7984void StateCache::onGLES1ClientStateChange(Context *context)
7985{
7986 updateActiveAttribsMask(context);
7987}
Jamie Madilld84b6732018-09-06 15:54:35 -04007988
7989void StateCache::onDrawFramebufferChange(Context *context)
7990{
7991 updateBasicDrawStatesError();
7992}
7993
7994void StateCache::onContextCapChange(Context *context)
7995{
7996 updateBasicDrawStatesError();
7997}
7998
7999void StateCache::onStencilStateChange(Context *context)
8000{
8001 updateBasicDrawStatesError();
8002}
8003
8004void StateCache::onDefaultVertexAttributeChange(Context *context)
8005{
8006 updateBasicDrawStatesError();
8007}
8008
8009void StateCache::onActiveTextureChange(Context *context)
8010{
8011 updateBasicDrawStatesError();
8012}
8013
8014void StateCache::onQueryChange(Context *context)
8015{
8016 updateBasicDrawStatesError();
8017}
8018
8019void StateCache::onTransformFeedbackChange(Context *context)
8020{
8021 updateBasicDrawStatesError();
8022}
8023
8024void StateCache::onUniformBufferStateChange(Context *context)
8025{
8026 updateBasicDrawStatesError();
8027}
8028
8029void StateCache::onBufferBindingChange(Context *context)
8030{
8031 updateBasicDrawStatesError();
8032}
Jamie Madill526a6f62018-09-12 11:03:05 -04008033
8034void StateCache::updateValidDrawModes(Context *context)
8035{
8036 Program *program = context->getGLState().getProgram();
8037 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8038 {
8039 mCachedValidDrawModes = {{
8040 true, /* Points */
8041 true, /* Lines */
8042 true, /* LineLoop */
8043 true, /* LineStrip */
8044 true, /* Triangles */
8045 true, /* TriangleStrip */
8046 true, /* TriangleFan */
8047 false, /* LinesAdjacency */
8048 false, /* LineStripAdjacency */
8049 false, /* TrianglesAdjacency */
8050 false, /* TriangleStripAdjacency */
8051 false, /* InvalidEnum */
8052 }};
8053 }
8054 else
8055 {
8056 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8057
8058 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
8059
8060 mCachedValidDrawModes = {{
8061 gsMode == PrimitiveMode::Points, /* Points */
8062 gsMode == PrimitiveMode::Lines, /* Lines */
8063 gsMode == PrimitiveMode::Lines, /* LineLoop */
8064 gsMode == PrimitiveMode::Lines, /* LineStrip */
8065 gsMode == PrimitiveMode::Triangles, /* Triangles */
8066 gsMode == PrimitiveMode::Triangles, /* TriangleStrip */
8067 gsMode == PrimitiveMode::Triangles, /* TriangleFan */
8068 gsMode == PrimitiveMode::LinesAdjacency, /* LinesAdjacency */
8069 gsMode == PrimitiveMode::LinesAdjacency, /* LineStripAdjacency */
8070 gsMode == PrimitiveMode::TrianglesAdjacency, /* TrianglesAdjacency */
8071 gsMode == PrimitiveMode::TrianglesAdjacency, /* TriangleStripAdjacency */
8072 false, /* InvalidEnum */
8073 }};
8074 }
8075}
Jamie Madillc29968b2016-01-20 11:17:23 -05008076} // namespace gl