blob: 54f9f13e105c415de8fbb5d550296e7d35412f43 [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Tobin Ehlisd7890bc2018-06-29 11:57:22 -060017#include "common/PackedEnums.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030018#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040019#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050020#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050021#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050022#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050023#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040024#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050025#include "libANGLE/Fence.h"
26#include "libANGLE/Framebuffer.h"
27#include "libANGLE/FramebufferAttachment.h"
Lingfeng Yang461b09a2018-04-23 09:02:09 -070028#include "libANGLE/GLES1Renderer.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030029#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080031#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050033#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050034#include "libANGLE/ResourceManager.h"
35#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050036#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050037#include "libANGLE/Texture.h"
38#include "libANGLE/TransformFeedback.h"
39#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070040#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040041#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030042#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040043#include "libANGLE/queryutils.h"
Jamie Madill6d32cef2018-08-14 02:34:28 -040044#include "libANGLE/renderer/BufferImpl.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040045#include "libANGLE/renderer/ContextImpl.h"
46#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040047#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040048#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000049
Geoff Langf6db0982015-08-25 13:04:00 -040050namespace
51{
52
Jamie Madillb6664922017-07-25 12:55:04 -040053#define ANGLE_HANDLE_ERR(X) \
54 handleError(X); \
55 return;
56#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
57
Ian Ewell3ffd78b2016-01-22 16:09:42 -050058template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050059std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030060 GLsizei numPaths,
61 const void *paths,
62 GLuint pathBase)
63{
64 std::vector<gl::Path *> ret;
65 ret.reserve(numPaths);
66
67 const auto *nameArray = static_cast<const T *>(paths);
68
69 for (GLsizei i = 0; i < numPaths; ++i)
70 {
71 const GLuint pathName = nameArray[i] + pathBase;
72
73 ret.push_back(resourceManager.getPath(pathName));
74 }
75
76 return ret;
77}
78
Geoff Lang4ddf5af2016-12-01 14:30:44 -050079std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030080 GLsizei numPaths,
81 GLenum pathNameType,
82 const void *paths,
83 GLuint pathBase)
84{
85 switch (pathNameType)
86 {
87 case GL_UNSIGNED_BYTE:
88 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
89
90 case GL_BYTE:
91 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
92
93 case GL_UNSIGNED_SHORT:
94 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
95
96 case GL_SHORT:
97 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
98
99 case GL_UNSIGNED_INT:
100 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
101
102 case GL_INT:
103 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
104 }
105
106 UNREACHABLE();
107 return std::vector<gl::Path *>();
108}
109
110template <typename T>
Jamie Madill5188a272018-07-25 10:53:56 -0400111gl::Error GetQueryObjectParameter(const gl::Context *context,
112 gl::Query *query,
113 GLenum pname,
114 T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500115{
Geoff Lang2186c382016-10-14 10:54:54 -0400116 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500117
118 switch (pname)
119 {
120 case GL_QUERY_RESULT_EXT:
Jamie Madill5188a272018-07-25 10:53:56 -0400121 return query->getResult(context, params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500122 case GL_QUERY_RESULT_AVAILABLE_EXT:
123 {
124 bool available;
Jamie Madill5188a272018-07-25 10:53:56 -0400125 gl::Error error = query->isResultAvailable(context, &available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500126 if (!error.isError())
127 {
jchen10a99ed552017-09-22 08:10:32 +0800128 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500129 }
130 return error;
131 }
132 default:
133 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500134 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500135 }
136}
137
Jamie Madill09463932018-04-04 05:26:59 -0400138void MarkTransformFeedbackBufferUsage(const gl::Context *context,
139 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700140 GLsizei count,
141 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400142{
Geoff Lang1a683462015-09-29 15:09:59 -0400143 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400144 {
Jamie Madill09463932018-04-04 05:26:59 -0400145 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400146 }
147}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148
149// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500151{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500153}
154
Martin Radev1be913c2016-07-11 17:59:16 +0300155EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
156{
157 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
158}
159
Geoff Langeb66a6e2016-10-31 13:06:12 -0400160gl::Version GetClientVersion(const egl::AttributeMap &attribs)
161{
162 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
163}
164
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165GLenum GetResetStrategy(const egl::AttributeMap &attribs)
166{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800167 EGLAttrib attrib =
168 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500169 switch (attrib)
170 {
171 case EGL_NO_RESET_NOTIFICATION:
172 return GL_NO_RESET_NOTIFICATION_EXT;
173 case EGL_LOSE_CONTEXT_ON_RESET:
174 return GL_LOSE_CONTEXT_ON_RESET_EXT;
175 default:
176 UNREACHABLE();
177 return GL_NONE;
178 }
179}
180
181bool GetRobustAccess(const egl::AttributeMap &attribs)
182{
Geoff Lang077f20a2016-11-01 10:08:02 -0400183 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
184 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
185 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500186}
187
188bool GetDebug(const egl::AttributeMap &attribs)
189{
Geoff Lang077f20a2016-11-01 10:08:02 -0400190 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
191 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500192}
193
194bool GetNoError(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Langc287ea62016-09-16 14:46:51 -0400199bool GetWebGLContext(const egl::AttributeMap &attribs)
200{
Jamie Madill4230d482018-09-14 10:14:45 -0400201 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
Geoff Langc287ea62016-09-16 14:46:51 -0400202}
203
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400204bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
205{
206 // If the context is WebGL, extensions are disabled by default
207 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
208 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
209}
210
Geoff Langf41a7152016-09-19 15:11:17 -0400211bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
212{
Jamie Madill4230d482018-09-14 10:14:45 -0400213 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
Geoff Langf41a7152016-09-19 15:11:17 -0400214}
215
Geoff Langfeb8c682017-02-13 16:07:35 -0500216bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
217{
218 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
219}
220
Geoff Langb433e872017-10-05 14:01:47 -0400221bool GetRobustResourceInit(const egl::AttributeMap &attribs)
222{
223 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
224}
225
Martin Radev9d901792016-07-15 15:58:58 +0300226std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
227{
228 std::string labelName;
229 if (label != nullptr)
230 {
231 size_t labelLength = length < 0 ? strlen(label) : length;
232 labelName = std::string(label, labelLength);
233 }
234 return labelName;
235}
236
237void GetObjectLabelBase(const std::string &objectLabel,
238 GLsizei bufSize,
239 GLsizei *length,
240 GLchar *label)
241{
242 size_t writeLength = objectLabel.length();
243 if (label != nullptr && bufSize > 0)
244 {
245 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
246 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
247 label[writeLength] = '\0';
248 }
249
250 if (length != nullptr)
251 {
252 *length = static_cast<GLsizei>(writeLength);
253 }
254}
255
Jamie Madill0f80ed82017-09-19 00:24:56 -0400256template <typename CapT, typename MaxT>
257void LimitCap(CapT *cap, MaxT maximum)
258{
259 *cap = std::min(*cap, static_cast<CapT>(maximum));
260}
261
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600262constexpr angle::PackedEnumMap<gl::PrimitiveMode, GLsizei> kMinimumPrimitiveCounts = {{
Jamie Madill526a6f62018-09-12 11:03:05 -0400263 1, /* Points */
264 2, /* Lines */
265 2, /* LineLoop */
266 2, /* LineStrip */
267 3, /* Triangles */
268 3, /* TriangleStrip */
269 3, /* TriangleFan */
270 2, /* LinesAdjacency */
271 2, /* LineStripAdjacency */
272 3, /* TrianglesAdjacency */
273 3, /* TriangleStripAdjacency */
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600274}};
275// Indices above are code-gen'd so make sure they don't change
276// if any of these static asserts are hit, must update kMinimumPrimitiveCounts abouve
277static_assert(static_cast<gl::PrimitiveMode>(0) == gl::PrimitiveMode::Points,
278 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
279static_assert(static_cast<gl::PrimitiveMode>(1) == gl::PrimitiveMode::Lines,
280 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
281static_assert(static_cast<gl::PrimitiveMode>(2) == gl::PrimitiveMode::LineLoop,
282 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
283static_assert(static_cast<gl::PrimitiveMode>(3) == gl::PrimitiveMode::LineStrip,
284 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
285static_assert(static_cast<gl::PrimitiveMode>(4) == gl::PrimitiveMode::Triangles,
286 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
287static_assert(static_cast<gl::PrimitiveMode>(5) == gl::PrimitiveMode::TriangleStrip,
288 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
289static_assert(static_cast<gl::PrimitiveMode>(6) == gl::PrimitiveMode::TriangleFan,
290 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
291static_assert(static_cast<gl::PrimitiveMode>(7) == gl::PrimitiveMode::LinesAdjacency,
292 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
293static_assert(static_cast<gl::PrimitiveMode>(8) == gl::PrimitiveMode::LineStripAdjacency,
294 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
295static_assert(static_cast<gl::PrimitiveMode>(9) == gl::PrimitiveMode::TrianglesAdjacency,
296 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
297static_assert(static_cast<gl::PrimitiveMode>(10) == gl::PrimitiveMode::TriangleStripAdjacency,
298 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
299static_assert(static_cast<gl::PrimitiveMode>(11) == gl::PrimitiveMode::EnumCount,
300 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
301
Jamie Madill6d32cef2018-08-14 02:34:28 -0400302enum SubjectIndexes : angle::SubjectIndex
303{
304 kTexture0SubjectIndex = 0,
305 kTextureMaxSubjectIndex = kTexture0SubjectIndex + gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
306 kUniformBuffer0SubjectIndex = kTextureMaxSubjectIndex,
307 kUniformBufferMaxSubjectIndex =
308 kUniformBuffer0SubjectIndex + gl::IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS,
Jamie Madille25b8002018-09-20 13:39:49 -0400309 kSampler0SubjectIndex = kUniformBufferMaxSubjectIndex,
310 kSamplerMaxSubjectIndex = kSampler0SubjectIndex + gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
311 kVertexArraySubjectIndex = kSamplerMaxSubjectIndex,
Jamie Madill6d32cef2018-08-14 02:34:28 -0400312 kReadFramebufferSubjectIndex,
313 kDrawFramebufferSubjectIndex
314};
Geoff Langf6db0982015-08-25 13:04:00 -0400315} // anonymous namespace
316
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000317namespace gl
318{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000319
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400320Context::Context(rx::EGLImplFactory *implFactory,
321 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400322 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500323 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400324 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500325 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700326 const egl::DisplayExtensions &displayExtensions,
327 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500328 : mState(reinterpret_cast<ContextID>(this),
329 shareContext ? &shareContext->mState : nullptr,
330 shareTextures,
331 GetClientVersion(attribs),
332 &mGLState,
333 mCaps,
334 mTextureCaps,
335 mExtensions,
336 mLimitations),
337 mSkipValidation(GetNoError(attribs)),
338 mDisplayTextureShareGroup(shareTextures != nullptr),
339 mSavedArgsType(nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400340 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400341 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400342 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400343 mGLState(GetDebug(attribs),
344 GetBindGeneratesResource(attribs),
345 GetClientArraysEnabled(attribs),
346 GetRobustResourceInit(attribs),
347 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400348 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500349 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400350 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500351 mHasBeenCurrent(false),
352 mContextLost(false),
353 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700354 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500355 mResetStrategy(GetResetStrategy(attribs)),
356 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400357 mSurfacelessSupported(displayExtensions.surfacelessContext),
358 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400359 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
360 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500361 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400362 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400363 mMemoryProgramCache(memoryProgramCache),
Jamie Madill16e28fd2018-09-12 11:03:05 -0400364 mStateCache(this),
Jamie Madilla11819d2018-07-30 10:26:01 -0400365 mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
366 mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
367 mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400368 mScratchBuffer(1000u),
jchen107ae70d82018-07-06 13:47:01 +0800369 mZeroFilledBuffer(1000u),
370 mThreadPool(nullptr)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000371{
Jamie Madill5b772312018-03-08 20:28:32 -0500372 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400373 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
374 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Jamie Madill6d32cef2018-08-14 02:34:28 -0400375
376 for (angle::SubjectIndex uboIndex = kUniformBuffer0SubjectIndex;
377 uboIndex < kUniformBufferMaxSubjectIndex; ++uboIndex)
378 {
379 mUniformBufferObserverBindings.emplace_back(this, uboIndex);
380 }
Jamie Madille25b8002018-09-20 13:39:49 -0400381
382 for (angle::SubjectIndex samplerIndex = kSampler0SubjectIndex;
383 samplerIndex < kSamplerMaxSubjectIndex; ++samplerIndex)
384 {
385 mSamplerObserverBindings.emplace_back(this, samplerIndex);
386 }
Geoff Lang33f11fb2018-05-07 13:42:47 -0400387}
Jamie Madill5b772312018-03-08 20:28:32 -0500388
Geoff Lang33f11fb2018-05-07 13:42:47 -0400389void Context::initialize()
390{
391 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400392
Geoff Lang33f11fb2018-05-07 13:42:47 -0400393 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700394 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400395
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400396 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100397
Shannon Woods53a94a82014-06-24 15:20:36 -0400398 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400399
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000400 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400401 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000402 // and cube map texture state vectors respectively associated with them.
403 // In order that access to these initial textures not be lost, they are treated as texture
404 // objects all of whose names are 0.
405
Corentin Wallez99d492c2018-02-27 15:17:10 -0500406 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800407 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500408
Corentin Wallez99d492c2018-02-27 15:17:10 -0500409 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800410 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400411
Geoff Langeb66a6e2016-10-31 13:06:12 -0400412 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400413 {
414 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500415 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800416 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400417
Corentin Wallez99d492c2018-02-27 15:17:10 -0500418 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800419 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400420 }
Geoff Lang3b573612016-10-31 14:08:10 -0400421 if (getClientVersion() >= Version(3, 1))
422 {
Olli Etuahod310a432018-08-24 15:40:23 +0300423 // TODO(http://anglebug.com/2775): These could also be enabled via extension
Geoff Lang3b573612016-10-31 14:08:10 -0400424 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500425 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800426 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Olli Etuahod310a432018-08-24 15:40:23 +0300427 Texture *zeroTexture2DMultisampleArray =
428 new Texture(mImplementation.get(), 0, TextureType::_2DMultisampleArray);
429 mZeroTextures[TextureType::_2DMultisampleArray].set(this, zeroTexture2DMultisampleArray);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800430
Jiajia Qin6eafb042016-12-27 17:04:07 +0800431 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
432 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800433 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800434 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800435
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800436 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
437 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400438 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800439 }
Geoff Lang3b573612016-10-31 14:08:10 -0400440 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000441
Geoff Langb0f917f2017-12-05 13:41:54 -0500442 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400443 {
444 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500445 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800446 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400447 }
448
Geoff Langb0f917f2017-12-05 13:41:54 -0500449 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400450 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500451 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800452 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400453 }
454
Jamie Madill4928b7c2017-06-20 12:57:39 -0400455 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500456
Jamie Madill57a89722013-07-02 11:57:03 -0400457 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000458
Geoff Langeb66a6e2016-10-31 13:06:12 -0400459 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400460 {
461 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
462 // In the initial state, a default transform feedback object is bound and treated as
463 // a transform feedback object with a name of zero. That object is bound any time
464 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400465 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400466 }
Geoff Langc8058452014-02-03 12:04:11 -0500467
Corentin Wallez336129f2017-10-17 15:55:40 -0400468 for (auto type : angle::AllEnums<BufferBinding>())
469 {
470 bindBuffer(type, 0);
471 }
472
473 bindRenderbuffer(GL_RENDERBUFFER, 0);
474
475 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
476 {
477 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
478 }
479
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700480 // Initialize GLES1 renderer if appropriate.
481 if (getClientVersion() < Version(2, 0))
482 {
483 mGLES1Renderer.reset(new GLES1Renderer());
484 }
485
Jamie Madillad9f24e2016-02-12 09:27:24 -0500486 // Initialize dirty bit masks
Geoff Lang9bf86f02018-07-26 11:46:34 -0400487 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
488 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
489 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400490 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400491 mDrawDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400492
493 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
494 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
495 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madille25b8002018-09-20 13:39:49 -0400496 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400497
Jamie Madillc67323a2017-11-02 23:11:41 -0400498 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500499 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500500 // No dirty objects.
501
502 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400503 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500504 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400505 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500506 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
507
508 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
509 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
510 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
511 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
512 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
513 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
514 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
515 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
516 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
517 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
518 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400519 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500520 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
521
522 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
523 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700524 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400525 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
526 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500527 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
528 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400529
Xinghua Cao10a4d432017-11-28 14:46:26 +0800530 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
jchen1099118c12018-09-10 16:28:51 +0800531 mComputeDirtyBits.set(State::DIRTY_BIT_UNIFORM_BUFFER_BINDINGS);
532 mComputeDirtyBits.set(State::DIRTY_BIT_ATOMIC_COUNTER_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800533 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
534 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
535 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
536 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
jchen1099118c12018-09-10 16:28:51 +0800537 mComputeDirtyBits.set(State::DIRTY_BIT_IMAGE_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800538 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800539 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400540 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400541 mComputeDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800542
Jamie Madillb4927eb2018-07-16 11:39:46 -0400543 mImplementation->setErrorSet(&mErrors);
544
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400545 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000546}
547
Jamie Madill4928b7c2017-06-20 12:57:39 -0400548egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000549{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700550 if (mGLES1Renderer)
551 {
552 mGLES1Renderer->onDestroy(this, &mGLState);
553 }
554
Jamie Madille7b3fe22018-04-05 09:42:46 -0400555 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400556 ANGLE_TRY(releaseSurface(display));
557
Corentin Wallez80b24112015-08-25 16:41:57 -0400558 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000559 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400560 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000561 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400562 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000563
Corentin Wallez80b24112015-08-25 16:41:57 -0400564 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000565 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400566 if (query.second != nullptr)
567 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400568 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400569 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000570 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400571 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000572
Corentin Wallez80b24112015-08-25 16:41:57 -0400573 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400574 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400575 if (vertexArray.second)
576 {
577 vertexArray.second->onDestroy(this);
578 }
Jamie Madill57a89722013-07-02 11:57:03 -0400579 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400580 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400581
Corentin Wallez80b24112015-08-25 16:41:57 -0400582 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500583 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500584 if (transformFeedback.second != nullptr)
585 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500586 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500587 }
Geoff Langc8058452014-02-03 12:04:11 -0500588 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400589 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500590
Jamie Madill5b772312018-03-08 20:28:32 -0500591 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400592 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800593 if (zeroTexture.get() != nullptr)
594 {
595 ANGLE_TRY(zeroTexture->onDestroy(this));
596 zeroTexture.set(this, nullptr);
597 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400598 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000599
Jamie Madill2f348d22017-06-05 10:50:59 -0400600 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500601
Jamie Madill4928b7c2017-06-20 12:57:39 -0400602 mGLState.reset(this);
603
Jamie Madill6c1f6712017-02-14 19:08:04 -0500604 mState.mBuffers->release(this);
605 mState.mShaderPrograms->release(this);
606 mState.mTextures->release(this);
607 mState.mRenderbuffers->release(this);
608 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400609 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500610 mState.mPaths->release(this);
611 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800612 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400613
jchen107ae70d82018-07-06 13:47:01 +0800614 mThreadPool.reset();
615
Jamie Madill76e471e2017-10-21 09:56:01 -0400616 mImplementation->onDestroy(this);
617
Jamie Madill4928b7c2017-06-20 12:57:39 -0400618 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000619}
620
Jamie Madill70ee0f62017-02-06 16:04:20 -0500621Context::~Context()
622{
623}
624
Geoff Lang75359662018-04-11 01:42:27 -0400625void Context::setLabel(EGLLabelKHR label)
626{
627 mLabel = label;
628}
629
630EGLLabelKHR Context::getLabel() const
631{
632 return mLabel;
633}
634
Jamie Madill4928b7c2017-06-20 12:57:39 -0400635egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000636{
Jamie Madill61e16b42017-06-19 11:13:23 -0400637 mCurrentDisplay = display;
638
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000639 if (!mHasBeenCurrent)
640 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400641 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000642 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500643 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400644 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000645
Corentin Wallezc295e512017-01-27 17:47:50 -0500646 int width = 0;
647 int height = 0;
648 if (surface != nullptr)
649 {
650 width = surface->getWidth();
651 height = surface->getHeight();
652 }
653
654 mGLState.setViewportParams(0, 0, width, height);
655 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000656
657 mHasBeenCurrent = true;
658 }
659
Jamie Madill1b94d432015-08-07 13:23:23 -0400660 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700661 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400662 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400663
Jamie Madill4928b7c2017-06-20 12:57:39 -0400664 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500665
666 Framebuffer *newDefault = nullptr;
667 if (surface != nullptr)
668 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400669 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500670 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400671 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500672 }
673 else
674 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400675 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500676 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000677
Corentin Wallez37c39792015-08-20 14:19:46 -0400678 // Update default framebuffer, the binding of the previous default
679 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400680 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400681 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700682 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400683 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400684 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400685 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700686 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400687 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400688 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400689 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400690 }
Ian Ewell292f0052016-02-04 10:37:32 -0500691
692 // Notify the renderer of a context switch
Luc Ferron5396f2a2018-07-12 08:24:23 -0400693 ANGLE_TRY(mImplementation->onMakeCurrent(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400694 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000695}
696
Jamie Madill4928b7c2017-06-20 12:57:39 -0400697egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400698{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400699 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400700
Geoff Langbf7b95d2018-05-01 16:48:21 -0400701 // Remove the default framebuffer
702 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500703 {
704 mGLState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400705 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500706 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400707
708 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500709 {
710 mGLState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400711 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500712 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400713
714 if (defaultFramebuffer)
715 {
716 defaultFramebuffer->onDestroy(this);
717 delete defaultFramebuffer;
718 }
719
Corentin Wallezc295e512017-01-27 17:47:50 -0500720 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
721
722 if (mCurrentSurface)
723 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400724 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500725 mCurrentSurface = nullptr;
726 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400727
728 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400729}
730
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000731GLuint Context::createBuffer()
732{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500733 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000734}
735
736GLuint Context::createProgram()
737{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500738 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000739}
740
Jiawei Shao385b3e02018-03-21 09:43:28 +0800741GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000742{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500743 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000744}
745
746GLuint Context::createTexture()
747{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500748 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000749}
750
751GLuint Context::createRenderbuffer()
752{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500753 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000754}
755
Brandon Jones59770802018-04-02 13:18:42 -0700756GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300757{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500758 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300759 if (resultOrError.isError())
760 {
761 handleError(resultOrError.getError());
762 return 0;
763 }
764 return resultOrError.getResult();
765}
766
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000767// Returns an unused framebuffer name
768GLuint Context::createFramebuffer()
769{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500770 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000771}
772
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500773void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000774{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500775 for (int i = 0; i < n; i++)
776 {
777 GLuint handle = mFenceNVHandleAllocator.allocate();
778 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
779 fences[i] = handle;
780 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000781}
782
Yunchao Hea336b902017-08-02 16:05:21 +0800783GLuint Context::createProgramPipeline()
784{
785 return mState.mPipelines->createProgramPipeline();
786}
787
Jiawei Shao385b3e02018-03-21 09:43:28 +0800788GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800789{
790 UNIMPLEMENTED();
791 return 0u;
792}
793
James Darpinian4d9d4832018-03-13 12:43:28 -0700794void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000795{
James Darpinian4d9d4832018-03-13 12:43:28 -0700796 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
797 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000798 {
799 detachBuffer(buffer);
800 }
Jamie Madill893ab082014-05-16 16:56:10 -0400801
James Darpinian4d9d4832018-03-13 12:43:28 -0700802 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000803}
804
805void Context::deleteShader(GLuint shader)
806{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500807 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000808}
809
810void Context::deleteProgram(GLuint program)
811{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500812 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000813}
814
815void Context::deleteTexture(GLuint texture)
816{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500817 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000818 {
819 detachTexture(texture);
820 }
821
Jamie Madill6c1f6712017-02-14 19:08:04 -0500822 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000823}
824
825void Context::deleteRenderbuffer(GLuint renderbuffer)
826{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500827 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000828 {
829 detachRenderbuffer(renderbuffer);
830 }
Jamie Madill893ab082014-05-16 16:56:10 -0400831
Jamie Madill6c1f6712017-02-14 19:08:04 -0500832 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000833}
834
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400835void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400836{
837 // The spec specifies the underlying Fence object is not deleted until all current
838 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
839 // and since our API is currently designed for being called from a single thread, we can delete
840 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400841 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400842}
843
Yunchao Hea336b902017-08-02 16:05:21 +0800844void Context::deleteProgramPipeline(GLuint pipeline)
845{
846 if (mState.mPipelines->getProgramPipeline(pipeline))
847 {
848 detachProgramPipeline(pipeline);
849 }
850
851 mState.mPipelines->deleteObject(this, pipeline);
852}
853
Sami Väisänene45e53b2016-05-25 10:36:04 +0300854void Context::deletePaths(GLuint first, GLsizei range)
855{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500856 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300857}
858
Brandon Jones59770802018-04-02 13:18:42 -0700859bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300860{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500861 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300862 if (pathObj == nullptr)
863 return false;
864
865 return pathObj->hasPathData();
866}
867
Brandon Jones59770802018-04-02 13:18:42 -0700868bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300869{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500870 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300871}
872
Brandon Jones59770802018-04-02 13:18:42 -0700873void Context::pathCommands(GLuint path,
874 GLsizei numCommands,
875 const GLubyte *commands,
876 GLsizei numCoords,
877 GLenum coordType,
878 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300879{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500880 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300881
882 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
883}
884
Jamie Madill007530e2017-12-28 14:27:04 -0500885void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300886{
Jamie Madill007530e2017-12-28 14:27:04 -0500887 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300888
889 switch (pname)
890 {
891 case GL_PATH_STROKE_WIDTH_CHROMIUM:
892 pathObj->setStrokeWidth(value);
893 break;
894 case GL_PATH_END_CAPS_CHROMIUM:
895 pathObj->setEndCaps(static_cast<GLenum>(value));
896 break;
897 case GL_PATH_JOIN_STYLE_CHROMIUM:
898 pathObj->setJoinStyle(static_cast<GLenum>(value));
899 break;
900 case GL_PATH_MITER_LIMIT_CHROMIUM:
901 pathObj->setMiterLimit(value);
902 break;
903 case GL_PATH_STROKE_BOUND_CHROMIUM:
904 pathObj->setStrokeBound(value);
905 break;
906 default:
907 UNREACHABLE();
908 break;
909 }
910}
911
Jamie Madill007530e2017-12-28 14:27:04 -0500912void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300913{
Jamie Madill007530e2017-12-28 14:27:04 -0500914 // TODO(jmadill): Should use proper clamping/casting.
915 pathParameterf(path, pname, static_cast<GLfloat>(value));
916}
917
918void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
919{
920 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300921
922 switch (pname)
923 {
924 case GL_PATH_STROKE_WIDTH_CHROMIUM:
925 *value = pathObj->getStrokeWidth();
926 break;
927 case GL_PATH_END_CAPS_CHROMIUM:
928 *value = static_cast<GLfloat>(pathObj->getEndCaps());
929 break;
930 case GL_PATH_JOIN_STYLE_CHROMIUM:
931 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
932 break;
933 case GL_PATH_MITER_LIMIT_CHROMIUM:
934 *value = pathObj->getMiterLimit();
935 break;
936 case GL_PATH_STROKE_BOUND_CHROMIUM:
937 *value = pathObj->getStrokeBound();
938 break;
939 default:
940 UNREACHABLE();
941 break;
942 }
943}
944
Jamie Madill007530e2017-12-28 14:27:04 -0500945void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
946{
947 GLfloat val = 0.0f;
948 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
949 if (value)
950 *value = static_cast<GLint>(val);
951}
952
Brandon Jones59770802018-04-02 13:18:42 -0700953void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300954{
955 mGLState.setPathStencilFunc(func, ref, mask);
956}
957
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000958void Context::deleteFramebuffer(GLuint framebuffer)
959{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500960 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000961 {
962 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000963 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500964
Jamie Madill6c1f6712017-02-14 19:08:04 -0500965 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000966}
967
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500968void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000969{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500970 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000971 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500972 GLuint fence = fences[i];
973
974 FenceNV *fenceObject = nullptr;
975 if (mFenceNVMap.erase(fence, &fenceObject))
976 {
977 mFenceNVHandleAllocator.release(fence);
978 delete fenceObject;
979 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000980 }
981}
982
Geoff Lang70d0f492015-12-10 17:45:46 -0500983Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000984{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500985 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000986}
987
Geoff Lang70d0f492015-12-10 17:45:46 -0500988Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000989{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500990 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000991}
992
Jamie Madill70b5bb02017-08-28 13:32:37 -0400993Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400994{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400995 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400996}
997
Jamie Madill57a89722013-07-02 11:57:03 -0400998VertexArray *Context::getVertexArray(GLuint handle) const
999{
Jamie Madill96a483b2017-06-27 16:49:21 -04001000 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -04001001}
1002
Jamie Madilldc356042013-07-19 16:36:57 -04001003Sampler *Context::getSampler(GLuint handle) const
1004{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001005 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -04001006}
1007
Geoff Langc8058452014-02-03 12:04:11 -05001008TransformFeedback *Context::getTransformFeedback(GLuint handle) const
1009{
Jamie Madill96a483b2017-06-27 16:49:21 -04001010 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -05001011}
1012
Yunchao Hea336b902017-08-02 16:05:21 +08001013ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
1014{
1015 return mState.mPipelines->getProgramPipeline(handle);
1016}
1017
Geoff Lang75359662018-04-11 01:42:27 -04001018gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001019{
1020 switch (identifier)
1021 {
1022 case GL_BUFFER:
1023 return getBuffer(name);
1024 case GL_SHADER:
1025 return getShader(name);
1026 case GL_PROGRAM:
1027 return getProgram(name);
1028 case GL_VERTEX_ARRAY:
1029 return getVertexArray(name);
1030 case GL_QUERY:
1031 return getQuery(name);
1032 case GL_TRANSFORM_FEEDBACK:
1033 return getTransformFeedback(name);
1034 case GL_SAMPLER:
1035 return getSampler(name);
1036 case GL_TEXTURE:
1037 return getTexture(name);
1038 case GL_RENDERBUFFER:
1039 return getRenderbuffer(name);
1040 case GL_FRAMEBUFFER:
1041 return getFramebuffer(name);
1042 default:
1043 UNREACHABLE();
1044 return nullptr;
1045 }
1046}
1047
Geoff Lang75359662018-04-11 01:42:27 -04001048gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001049{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001050 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001051}
1052
Martin Radev9d901792016-07-15 15:58:58 +03001053void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1054{
Geoff Lang75359662018-04-11 01:42:27 -04001055 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001056 ASSERT(object != nullptr);
1057
1058 std::string labelName = GetObjectLabelFromPointer(length, label);
1059 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001060
1061 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1062 // specified object is active until we do this.
1063 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001064}
1065
1066void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1067{
Geoff Lang75359662018-04-11 01:42:27 -04001068 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001069 ASSERT(object != nullptr);
1070
1071 std::string labelName = GetObjectLabelFromPointer(length, label);
1072 object->setLabel(labelName);
1073}
1074
1075void Context::getObjectLabel(GLenum identifier,
1076 GLuint name,
1077 GLsizei bufSize,
1078 GLsizei *length,
1079 GLchar *label) const
1080{
Geoff Lang75359662018-04-11 01:42:27 -04001081 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001082 ASSERT(object != nullptr);
1083
1084 const std::string &objectLabel = object->getLabel();
1085 GetObjectLabelBase(objectLabel, bufSize, length, label);
1086}
1087
1088void Context::getObjectPtrLabel(const void *ptr,
1089 GLsizei bufSize,
1090 GLsizei *length,
1091 GLchar *label) const
1092{
Geoff Lang75359662018-04-11 01:42:27 -04001093 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001094 ASSERT(object != nullptr);
1095
1096 const std::string &objectLabel = object->getLabel();
1097 GetObjectLabelBase(objectLabel, bufSize, length, label);
1098}
1099
Jamie Madilldc356042013-07-19 16:36:57 -04001100bool Context::isSampler(GLuint samplerName) const
1101{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001102 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001103}
1104
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001105void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001106{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001107 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001108
Jamie Madilldedd7b92014-11-05 16:30:36 -05001109 if (handle == 0)
1110 {
1111 texture = mZeroTextures[target].get();
1112 }
1113 else
1114 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001115 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001116 }
1117
1118 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001119 mGLState.setSamplerTexture(this, target, texture);
Jamie Madilld84b6732018-09-06 15:54:35 -04001120 mStateCache.onActiveTextureChange(this);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001121}
1122
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001123void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001124{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001125 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1126 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001127 mGLState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001128 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001129}
1130
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001131void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001132{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001133 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1134 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001135 mGLState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001136 mDrawFramebufferObserverBinding.bind(framebuffer);
Jamie Madilld84b6732018-09-06 15:54:35 -04001137 mStateCache.onDrawFramebufferChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001138}
1139
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001140void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001141{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001142 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001143 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001144 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001145 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001146}
1147
Shao80957d92017-02-20 21:25:59 +08001148void Context::bindVertexBuffer(GLuint bindingIndex,
1149 GLuint bufferHandle,
1150 GLintptr offset,
1151 GLsizei stride)
1152{
1153 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001154 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001155 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001156}
1157
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001158void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001159{
Geoff Lang76b10c92014-09-05 16:28:14 -04001160 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001161 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001162 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001163 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04001164 mSamplerObserverBindings[textureUnit].bind(sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001165}
1166
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001167void Context::bindImageTexture(GLuint unit,
1168 GLuint texture,
1169 GLint level,
1170 GLboolean layered,
1171 GLint layer,
1172 GLenum access,
1173 GLenum format)
1174{
1175 Texture *tex = mState.mTextures->getTexture(texture);
1176 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1177}
1178
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001179void Context::useProgram(GLuint program)
1180{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001181 mGLState.setProgram(this, getProgram(program));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001182 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001183}
1184
Jiajia Qin5451d532017-11-16 17:16:34 +08001185void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1186{
1187 UNIMPLEMENTED();
1188}
1189
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001190void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001191{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001192 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001193 TransformFeedback *transformFeedback =
1194 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001195 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Jamie Madilld84b6732018-09-06 15:54:35 -04001196 mStateCache.onTransformFeedbackChange(this);
Geoff Langc8058452014-02-03 12:04:11 -05001197}
1198
Yunchao Hea336b902017-08-02 16:05:21 +08001199void Context::bindProgramPipeline(GLuint pipelineHandle)
1200{
1201 ProgramPipeline *pipeline =
1202 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1203 mGLState.setProgramPipelineBinding(this, pipeline);
1204}
1205
Corentin Wallezad3ae902018-03-09 13:40:42 -05001206void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001207{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001208 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001209 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001210
Geoff Lang5aad9672014-09-08 11:10:42 -04001211 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001212 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001213
1214 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001215 mGLState.setActiveQuery(this, target, queryObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04001216 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001217}
1218
Corentin Wallezad3ae902018-03-09 13:40:42 -05001219void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001220{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001221 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001222 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001223
Jamie Madill5188a272018-07-25 10:53:56 -04001224 handleError(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001225
Geoff Lang5aad9672014-09-08 11:10:42 -04001226 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001227 mGLState.setActiveQuery(this, target, nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04001228 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001229}
1230
Corentin Wallezad3ae902018-03-09 13:40:42 -05001231void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001232{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001233 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001234
1235 Query *queryObject = getQuery(id, true, target);
1236 ASSERT(queryObject);
1237
Jamie Madill5188a272018-07-25 10:53:56 -04001238 handleError(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001239}
1240
Corentin Wallezad3ae902018-03-09 13:40:42 -05001241void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001242{
1243 switch (pname)
1244 {
1245 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001246 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001247 break;
1248 case GL_QUERY_COUNTER_BITS_EXT:
1249 switch (target)
1250 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001251 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001252 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1253 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001254 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001255 params[0] = getExtensions().queryCounterBitsTimestamp;
1256 break;
1257 default:
1258 UNREACHABLE();
1259 params[0] = 0;
1260 break;
1261 }
1262 break;
1263 default:
1264 UNREACHABLE();
1265 return;
1266 }
1267}
1268
Corentin Wallezad3ae902018-03-09 13:40:42 -05001269void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001270 GLenum pname,
1271 GLsizei bufSize,
1272 GLsizei *length,
1273 GLint *params)
1274{
1275 getQueryiv(target, pname, params);
1276}
1277
Geoff Lang2186c382016-10-14 10:54:54 -04001278void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001279{
Jamie Madill5188a272018-07-25 10:53:56 -04001280 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001281}
1282
Brandon Jones59770802018-04-02 13:18:42 -07001283void Context::getQueryObjectivRobust(GLuint id,
1284 GLenum pname,
1285 GLsizei bufSize,
1286 GLsizei *length,
1287 GLint *params)
1288{
1289 getQueryObjectiv(id, pname, params);
1290}
1291
Geoff Lang2186c382016-10-14 10:54:54 -04001292void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001293{
Jamie Madill5188a272018-07-25 10:53:56 -04001294 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001295}
1296
Brandon Jones59770802018-04-02 13:18:42 -07001297void Context::getQueryObjectuivRobust(GLuint id,
1298 GLenum pname,
1299 GLsizei bufSize,
1300 GLsizei *length,
1301 GLuint *params)
1302{
1303 getQueryObjectuiv(id, pname, params);
1304}
1305
Geoff Lang2186c382016-10-14 10:54:54 -04001306void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001307{
Jamie Madill5188a272018-07-25 10:53:56 -04001308 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001309}
1310
Brandon Jones59770802018-04-02 13:18:42 -07001311void Context::getQueryObjecti64vRobust(GLuint id,
1312 GLenum pname,
1313 GLsizei bufSize,
1314 GLsizei *length,
1315 GLint64 *params)
1316{
1317 getQueryObjecti64v(id, pname, params);
1318}
1319
Geoff Lang2186c382016-10-14 10:54:54 -04001320void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001321{
Jamie Madill5188a272018-07-25 10:53:56 -04001322 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001323}
1324
Brandon Jones59770802018-04-02 13:18:42 -07001325void Context::getQueryObjectui64vRobust(GLuint id,
1326 GLenum pname,
1327 GLsizei bufSize,
1328 GLsizei *length,
1329 GLuint64 *params)
1330{
1331 getQueryObjectui64v(id, pname, params);
1332}
1333
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001334Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001335{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001336 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001337}
1338
Jamie Madill2f348d22017-06-05 10:50:59 -04001339FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001340{
Jamie Madill96a483b2017-06-27 16:49:21 -04001341 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001342}
1343
Corentin Wallezad3ae902018-03-09 13:40:42 -05001344Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001345{
Jamie Madill96a483b2017-06-27 16:49:21 -04001346 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001347 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001348 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001349 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001350
1351 Query *query = mQueryMap.query(handle);
1352 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001353 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001354 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001355 query = new Query(mImplementation->createQuery(type), handle);
1356 query->addRef();
1357 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001358 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001359 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001360}
1361
Geoff Lang70d0f492015-12-10 17:45:46 -05001362Query *Context::getQuery(GLuint handle) const
1363{
Jamie Madill96a483b2017-06-27 16:49:21 -04001364 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001365}
1366
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001367Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001368{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001369 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1370 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001371}
1372
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001373Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001374{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001375 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001376}
1377
Geoff Lang492a7e42014-11-05 13:27:06 -05001378Compiler *Context::getCompiler() const
1379{
Jamie Madill2f348d22017-06-05 10:50:59 -04001380 if (mCompiler.get() == nullptr)
1381 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001382 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001383 }
1384 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001385}
1386
Jamie Madillc1d770e2017-04-13 17:31:24 -04001387void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001388{
1389 switch (pname)
1390 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001391 case GL_SHADER_COMPILER:
1392 *params = GL_TRUE;
1393 break;
1394 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1395 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1396 break;
1397 default:
1398 mGLState.getBooleanv(pname, params);
1399 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001400 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001401}
1402
Jamie Madillc1d770e2017-04-13 17:31:24 -04001403void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001404{
Shannon Woods53a94a82014-06-24 15:20:36 -04001405 // Queries about context capabilities and maximums are answered by Context.
1406 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001407 switch (pname)
1408 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001409 case GL_ALIASED_LINE_WIDTH_RANGE:
1410 params[0] = mCaps.minAliasedLineWidth;
1411 params[1] = mCaps.maxAliasedLineWidth;
1412 break;
1413 case GL_ALIASED_POINT_SIZE_RANGE:
1414 params[0] = mCaps.minAliasedPointSize;
1415 params[1] = mCaps.maxAliasedPointSize;
1416 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001417 case GL_SMOOTH_POINT_SIZE_RANGE:
1418 params[0] = mCaps.minSmoothPointSize;
1419 params[1] = mCaps.maxSmoothPointSize;
1420 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001421 case GL_SMOOTH_LINE_WIDTH_RANGE:
1422 params[0] = mCaps.minSmoothLineWidth;
1423 params[1] = mCaps.maxSmoothLineWidth;
1424 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001425 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1426 ASSERT(mExtensions.textureFilterAnisotropic);
1427 *params = mExtensions.maxTextureAnisotropy;
1428 break;
1429 case GL_MAX_TEXTURE_LOD_BIAS:
1430 *params = mCaps.maxLODBias;
1431 break;
1432
1433 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1434 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1435 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001436 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1437 // GLES1 constants for modelview/projection matrix.
1438 if (getClientVersion() < Version(2, 0))
1439 {
1440 mGLState.getFloatv(pname, params);
1441 }
1442 else
1443 {
1444 ASSERT(mExtensions.pathRendering);
1445 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1446 memcpy(params, m, 16 * sizeof(GLfloat));
1447 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001448 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001449 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001450
Jamie Madill231c7f52017-04-26 13:45:37 -04001451 default:
1452 mGLState.getFloatv(pname, params);
1453 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001454 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001455}
1456
Jamie Madillc1d770e2017-04-13 17:31:24 -04001457void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001458{
Shannon Woods53a94a82014-06-24 15:20:36 -04001459 // Queries about context capabilities and maximums are answered by Context.
1460 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001461
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001462 switch (pname)
1463 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001464 case GL_MAX_VERTEX_ATTRIBS:
1465 *params = mCaps.maxVertexAttributes;
1466 break;
1467 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1468 *params = mCaps.maxVertexUniformVectors;
1469 break;
1470 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001471 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001472 break;
1473 case GL_MAX_VARYING_VECTORS:
1474 *params = mCaps.maxVaryingVectors;
1475 break;
1476 case GL_MAX_VARYING_COMPONENTS:
1477 *params = mCaps.maxVertexOutputComponents;
1478 break;
1479 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1480 *params = mCaps.maxCombinedTextureImageUnits;
1481 break;
1482 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001483 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001484 break;
1485 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001486 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001487 break;
1488 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1489 *params = mCaps.maxFragmentUniformVectors;
1490 break;
1491 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001492 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001493 break;
1494 case GL_MAX_RENDERBUFFER_SIZE:
1495 *params = mCaps.maxRenderbufferSize;
1496 break;
1497 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1498 *params = mCaps.maxColorAttachments;
1499 break;
1500 case GL_MAX_DRAW_BUFFERS_EXT:
1501 *params = mCaps.maxDrawBuffers;
1502 break;
1503 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1504 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1505 case GL_SUBPIXEL_BITS:
1506 *params = 4;
1507 break;
1508 case GL_MAX_TEXTURE_SIZE:
1509 *params = mCaps.max2DTextureSize;
1510 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001511 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1512 *params = mCaps.maxRectangleTextureSize;
1513 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001514 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1515 *params = mCaps.maxCubeMapTextureSize;
1516 break;
1517 case GL_MAX_3D_TEXTURE_SIZE:
1518 *params = mCaps.max3DTextureSize;
1519 break;
1520 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1521 *params = mCaps.maxArrayTextureLayers;
1522 break;
1523 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1524 *params = mCaps.uniformBufferOffsetAlignment;
1525 break;
1526 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1527 *params = mCaps.maxUniformBufferBindings;
1528 break;
1529 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001530 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001531 break;
1532 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001533 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001534 break;
1535 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1536 *params = mCaps.maxCombinedTextureImageUnits;
1537 break;
1538 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1539 *params = mCaps.maxVertexOutputComponents;
1540 break;
1541 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1542 *params = mCaps.maxFragmentInputComponents;
1543 break;
1544 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1545 *params = mCaps.minProgramTexelOffset;
1546 break;
1547 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1548 *params = mCaps.maxProgramTexelOffset;
1549 break;
1550 case GL_MAJOR_VERSION:
1551 *params = getClientVersion().major;
1552 break;
1553 case GL_MINOR_VERSION:
1554 *params = getClientVersion().minor;
1555 break;
1556 case GL_MAX_ELEMENTS_INDICES:
1557 *params = mCaps.maxElementsIndices;
1558 break;
1559 case GL_MAX_ELEMENTS_VERTICES:
1560 *params = mCaps.maxElementsVertices;
1561 break;
1562 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1563 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1564 break;
1565 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1566 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1567 break;
1568 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1569 *params = mCaps.maxTransformFeedbackSeparateComponents;
1570 break;
1571 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1572 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1573 break;
1574 case GL_MAX_SAMPLES_ANGLE:
1575 *params = mCaps.maxSamples;
1576 break;
1577 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001578 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001579 params[0] = mCaps.maxViewportWidth;
1580 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001581 }
1582 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001583 case GL_COMPRESSED_TEXTURE_FORMATS:
1584 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1585 params);
1586 break;
1587 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1588 *params = mResetStrategy;
1589 break;
1590 case GL_NUM_SHADER_BINARY_FORMATS:
1591 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1592 break;
1593 case GL_SHADER_BINARY_FORMATS:
1594 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1595 break;
1596 case GL_NUM_PROGRAM_BINARY_FORMATS:
1597 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1598 break;
1599 case GL_PROGRAM_BINARY_FORMATS:
1600 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1601 break;
1602 case GL_NUM_EXTENSIONS:
1603 *params = static_cast<GLint>(mExtensionStrings.size());
1604 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001605
Jamie Madill231c7f52017-04-26 13:45:37 -04001606 // GL_KHR_debug
1607 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1608 *params = mExtensions.maxDebugMessageLength;
1609 break;
1610 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1611 *params = mExtensions.maxDebugLoggedMessages;
1612 break;
1613 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1614 *params = mExtensions.maxDebugGroupStackDepth;
1615 break;
1616 case GL_MAX_LABEL_LENGTH:
1617 *params = mExtensions.maxLabelLength;
1618 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001619
Martin Radeve5285d22017-07-14 16:23:53 +03001620 // GL_ANGLE_multiview
1621 case GL_MAX_VIEWS_ANGLE:
1622 *params = mExtensions.maxViews;
1623 break;
1624
Jamie Madill231c7f52017-04-26 13:45:37 -04001625 // GL_EXT_disjoint_timer_query
1626 case GL_GPU_DISJOINT_EXT:
1627 *params = mImplementation->getGPUDisjoint();
1628 break;
1629 case GL_MAX_FRAMEBUFFER_WIDTH:
1630 *params = mCaps.maxFramebufferWidth;
1631 break;
1632 case GL_MAX_FRAMEBUFFER_HEIGHT:
1633 *params = mCaps.maxFramebufferHeight;
1634 break;
1635 case GL_MAX_FRAMEBUFFER_SAMPLES:
1636 *params = mCaps.maxFramebufferSamples;
1637 break;
1638 case GL_MAX_SAMPLE_MASK_WORDS:
1639 *params = mCaps.maxSampleMaskWords;
1640 break;
1641 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1642 *params = mCaps.maxColorTextureSamples;
1643 break;
1644 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1645 *params = mCaps.maxDepthTextureSamples;
1646 break;
1647 case GL_MAX_INTEGER_SAMPLES:
1648 *params = mCaps.maxIntegerSamples;
1649 break;
1650 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1651 *params = mCaps.maxVertexAttribRelativeOffset;
1652 break;
1653 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1654 *params = mCaps.maxVertexAttribBindings;
1655 break;
1656 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1657 *params = mCaps.maxVertexAttribStride;
1658 break;
1659 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001660 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001661 break;
1662 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001663 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001664 break;
1665 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001666 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001667 break;
1668 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001669 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001670 break;
1671 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001672 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001673 break;
1674 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001675 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001676 break;
1677 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001678 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001679 break;
1680 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001681 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001682 break;
1683 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1684 *params = mCaps.minProgramTextureGatherOffset;
1685 break;
1686 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1687 *params = mCaps.maxProgramTextureGatherOffset;
1688 break;
1689 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1690 *params = mCaps.maxComputeWorkGroupInvocations;
1691 break;
1692 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001693 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001694 break;
1695 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001696 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001697 break;
1698 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1699 *params = mCaps.maxComputeSharedMemorySize;
1700 break;
1701 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001702 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001703 break;
1704 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001705 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001706 break;
1707 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001708 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001709 break;
1710 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001711 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001712 break;
1713 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001714 *params =
1715 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001716 break;
1717 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001718 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001719 break;
1720 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1721 *params = mCaps.maxCombinedShaderOutputResources;
1722 break;
1723 case GL_MAX_UNIFORM_LOCATIONS:
1724 *params = mCaps.maxUniformLocations;
1725 break;
1726 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1727 *params = mCaps.maxAtomicCounterBufferBindings;
1728 break;
1729 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1730 *params = mCaps.maxAtomicCounterBufferSize;
1731 break;
1732 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1733 *params = mCaps.maxCombinedAtomicCounterBuffers;
1734 break;
1735 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1736 *params = mCaps.maxCombinedAtomicCounters;
1737 break;
1738 case GL_MAX_IMAGE_UNITS:
1739 *params = mCaps.maxImageUnits;
1740 break;
1741 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1742 *params = mCaps.maxCombinedImageUniforms;
1743 break;
1744 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1745 *params = mCaps.maxShaderStorageBufferBindings;
1746 break;
1747 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1748 *params = mCaps.maxCombinedShaderStorageBlocks;
1749 break;
1750 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1751 *params = mCaps.shaderStorageBufferOffsetAlignment;
1752 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001753
1754 // GL_EXT_geometry_shader
1755 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1756 *params = mCaps.maxFramebufferLayers;
1757 break;
1758 case GL_LAYER_PROVOKING_VERTEX_EXT:
1759 *params = mCaps.layerProvokingVertex;
1760 break;
1761 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001762 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001763 break;
1764 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001765 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001766 break;
1767 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001768 *params =
1769 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001770 break;
1771 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1772 *params = mCaps.maxGeometryInputComponents;
1773 break;
1774 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1775 *params = mCaps.maxGeometryOutputComponents;
1776 break;
1777 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1778 *params = mCaps.maxGeometryOutputVertices;
1779 break;
1780 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1781 *params = mCaps.maxGeometryTotalOutputComponents;
1782 break;
1783 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1784 *params = mCaps.maxGeometryShaderInvocations;
1785 break;
1786 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001787 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001788 break;
1789 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001790 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001791 break;
1792 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001793 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001794 break;
1795 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001796 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001797 break;
1798 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001799 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001800 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001801 // GLES1 emulation: Caps queries
1802 case GL_MAX_TEXTURE_UNITS:
1803 *params = mCaps.maxMultitextureUnits;
1804 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001805 case GL_MAX_MODELVIEW_STACK_DEPTH:
1806 *params = mCaps.maxModelviewMatrixStackDepth;
1807 break;
1808 case GL_MAX_PROJECTION_STACK_DEPTH:
1809 *params = mCaps.maxProjectionMatrixStackDepth;
1810 break;
1811 case GL_MAX_TEXTURE_STACK_DEPTH:
1812 *params = mCaps.maxTextureMatrixStackDepth;
1813 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001814 case GL_MAX_LIGHTS:
1815 *params = mCaps.maxLights;
1816 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001817 case GL_MAX_CLIP_PLANES:
1818 *params = mCaps.maxClipPlanes;
1819 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001820 // GLES1 emulation: Vertex attribute queries
1821 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1822 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1823 case GL_COLOR_ARRAY_BUFFER_BINDING:
1824 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1825 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1826 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1827 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1828 break;
1829 case GL_VERTEX_ARRAY_STRIDE:
1830 case GL_NORMAL_ARRAY_STRIDE:
1831 case GL_COLOR_ARRAY_STRIDE:
1832 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1833 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1834 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1835 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1836 break;
1837 case GL_VERTEX_ARRAY_SIZE:
1838 case GL_COLOR_ARRAY_SIZE:
1839 case GL_TEXTURE_COORD_ARRAY_SIZE:
1840 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1841 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1842 break;
1843 case GL_VERTEX_ARRAY_TYPE:
1844 case GL_COLOR_ARRAY_TYPE:
1845 case GL_NORMAL_ARRAY_TYPE:
1846 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1847 case GL_TEXTURE_COORD_ARRAY_TYPE:
1848 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1849 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1850 break;
1851
jchen1082af6202018-06-22 10:59:52 +08001852 // GL_KHR_parallel_shader_compile
1853 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1854 *params = mGLState.getMaxShaderCompilerThreads();
1855 break;
1856
Jamie Madill231c7f52017-04-26 13:45:37 -04001857 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001858 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001859 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001860 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001861}
1862
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001863void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001864{
Shannon Woods53a94a82014-06-24 15:20:36 -04001865 // Queries about context capabilities and maximums are answered by Context.
1866 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001867 switch (pname)
1868 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001869 case GL_MAX_ELEMENT_INDEX:
1870 *params = mCaps.maxElementIndex;
1871 break;
1872 case GL_MAX_UNIFORM_BLOCK_SIZE:
1873 *params = mCaps.maxUniformBlockSize;
1874 break;
1875 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001876 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001877 break;
1878 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001879 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001880 break;
1881 case GL_MAX_SERVER_WAIT_TIMEOUT:
1882 *params = mCaps.maxServerWaitTimeout;
1883 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001884
Jamie Madill231c7f52017-04-26 13:45:37 -04001885 // GL_EXT_disjoint_timer_query
1886 case GL_TIMESTAMP_EXT:
1887 *params = mImplementation->getTimestamp();
1888 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001889
Jamie Madill231c7f52017-04-26 13:45:37 -04001890 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1891 *params = mCaps.maxShaderStorageBlockSize;
1892 break;
1893 default:
1894 UNREACHABLE();
1895 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001896 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001897}
1898
Geoff Lang70d0f492015-12-10 17:45:46 -05001899void Context::getPointerv(GLenum pname, void **params) const
1900{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001901 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001902}
1903
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001904void Context::getPointervRobustANGLERobust(GLenum pname,
1905 GLsizei bufSize,
1906 GLsizei *length,
1907 void **params)
1908{
1909 UNIMPLEMENTED();
1910}
1911
Martin Radev66fb8202016-07-28 11:45:20 +03001912void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001913{
Shannon Woods53a94a82014-06-24 15:20:36 -04001914 // Queries about context capabilities and maximums are answered by Context.
1915 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001916
1917 GLenum nativeType;
1918 unsigned int numParams;
1919 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1920 ASSERT(queryStatus);
1921
1922 if (nativeType == GL_INT)
1923 {
1924 switch (target)
1925 {
1926 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1927 ASSERT(index < 3u);
1928 *data = mCaps.maxComputeWorkGroupCount[index];
1929 break;
1930 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1931 ASSERT(index < 3u);
1932 *data = mCaps.maxComputeWorkGroupSize[index];
1933 break;
1934 default:
1935 mGLState.getIntegeri_v(target, index, data);
1936 }
1937 }
1938 else
1939 {
1940 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1941 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001942}
1943
Brandon Jones59770802018-04-02 13:18:42 -07001944void Context::getIntegeri_vRobust(GLenum target,
1945 GLuint index,
1946 GLsizei bufSize,
1947 GLsizei *length,
1948 GLint *data)
1949{
1950 getIntegeri_v(target, index, data);
1951}
1952
Martin Radev66fb8202016-07-28 11:45:20 +03001953void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001954{
Shannon Woods53a94a82014-06-24 15:20:36 -04001955 // Queries about context capabilities and maximums are answered by Context.
1956 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001957
1958 GLenum nativeType;
1959 unsigned int numParams;
1960 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1961 ASSERT(queryStatus);
1962
1963 if (nativeType == GL_INT_64_ANGLEX)
1964 {
1965 mGLState.getInteger64i_v(target, index, data);
1966 }
1967 else
1968 {
1969 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1970 }
1971}
1972
Brandon Jones59770802018-04-02 13:18:42 -07001973void Context::getInteger64i_vRobust(GLenum target,
1974 GLuint index,
1975 GLsizei bufSize,
1976 GLsizei *length,
1977 GLint64 *data)
1978{
1979 getInteger64i_v(target, index, data);
1980}
1981
Martin Radev66fb8202016-07-28 11:45:20 +03001982void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1983{
1984 // Queries about context capabilities and maximums are answered by Context.
1985 // Queries about current GL state values are answered by State.
1986
1987 GLenum nativeType;
1988 unsigned int numParams;
1989 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1990 ASSERT(queryStatus);
1991
1992 if (nativeType == GL_BOOL)
1993 {
1994 mGLState.getBooleani_v(target, index, data);
1995 }
1996 else
1997 {
1998 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1999 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04002000}
2001
Brandon Jones59770802018-04-02 13:18:42 -07002002void Context::getBooleani_vRobust(GLenum target,
2003 GLuint index,
2004 GLsizei bufSize,
2005 GLsizei *length,
2006 GLboolean *data)
2007{
2008 getBooleani_v(target, index, data);
2009}
2010
Corentin Wallez336129f2017-10-17 15:55:40 -04002011void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002012{
2013 Buffer *buffer = mGLState.getTargetBuffer(target);
2014 QueryBufferParameteriv(buffer, pname, params);
2015}
2016
Brandon Jones59770802018-04-02 13:18:42 -07002017void Context::getBufferParameterivRobust(BufferBinding target,
2018 GLenum pname,
2019 GLsizei bufSize,
2020 GLsizei *length,
2021 GLint *params)
2022{
2023 getBufferParameteriv(target, pname, params);
2024}
2025
He Yunchao010e4db2017-03-03 14:22:06 +08002026void Context::getFramebufferAttachmentParameteriv(GLenum target,
2027 GLenum attachment,
2028 GLenum pname,
2029 GLint *params)
2030{
2031 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002032 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002033}
2034
Brandon Jones59770802018-04-02 13:18:42 -07002035void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2036 GLenum attachment,
2037 GLenum pname,
2038 GLsizei bufSize,
2039 GLsizei *length,
2040 GLint *params)
2041{
2042 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2043}
2044
He Yunchao010e4db2017-03-03 14:22:06 +08002045void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2046{
2047 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2048 QueryRenderbufferiv(this, renderbuffer, pname, params);
2049}
2050
Brandon Jones59770802018-04-02 13:18:42 -07002051void Context::getRenderbufferParameterivRobust(GLenum target,
2052 GLenum pname,
2053 GLsizei bufSize,
2054 GLsizei *length,
2055 GLint *params)
2056{
2057 getRenderbufferParameteriv(target, pname, params);
2058}
2059
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002060void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002061{
2062 Texture *texture = getTargetTexture(target);
2063 QueryTexParameterfv(texture, pname, params);
2064}
2065
Brandon Jones59770802018-04-02 13:18:42 -07002066void Context::getTexParameterfvRobust(TextureType target,
2067 GLenum pname,
2068 GLsizei bufSize,
2069 GLsizei *length,
2070 GLfloat *params)
2071{
2072 getTexParameterfv(target, pname, params);
2073}
2074
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002075void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002076{
2077 Texture *texture = getTargetTexture(target);
2078 QueryTexParameteriv(texture, pname, params);
2079}
Jiajia Qin5451d532017-11-16 17:16:34 +08002080
Brandon Jones59770802018-04-02 13:18:42 -07002081void Context::getTexParameterivRobust(TextureType target,
2082 GLenum pname,
2083 GLsizei bufSize,
2084 GLsizei *length,
2085 GLint *params)
2086{
2087 getTexParameteriv(target, pname, params);
2088}
2089
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002090void Context::getTexParameterIivRobust(TextureType target,
2091 GLenum pname,
2092 GLsizei bufSize,
2093 GLsizei *length,
2094 GLint *params)
2095{
2096 UNIMPLEMENTED();
2097}
2098
2099void Context::getTexParameterIuivRobust(TextureType target,
2100 GLenum pname,
2101 GLsizei bufSize,
2102 GLsizei *length,
2103 GLuint *params)
2104{
2105 UNIMPLEMENTED();
2106}
2107
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002108void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002109{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002110 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002111 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002112}
2113
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002114void Context::getTexLevelParameterivRobust(TextureTarget target,
2115 GLint level,
2116 GLenum pname,
2117 GLsizei bufSize,
2118 GLsizei *length,
2119 GLint *params)
2120{
2121 UNIMPLEMENTED();
2122}
2123
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002124void Context::getTexLevelParameterfv(TextureTarget target,
2125 GLint level,
2126 GLenum pname,
2127 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002128{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002129 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002130 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002131}
2132
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002133void Context::getTexLevelParameterfvRobust(TextureTarget target,
2134 GLint level,
2135 GLenum pname,
2136 GLsizei bufSize,
2137 GLsizei *length,
2138 GLfloat *params)
2139{
2140 UNIMPLEMENTED();
2141}
2142
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002143void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002144{
2145 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002146 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002147 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002148}
2149
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002150void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002151{
2152 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002153 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002154 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002155}
2156
Brandon Jones59770802018-04-02 13:18:42 -07002157void Context::texParameterfvRobust(TextureType target,
2158 GLenum pname,
2159 GLsizei bufSize,
2160 const GLfloat *params)
2161{
2162 texParameterfv(target, pname, params);
2163}
2164
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002165void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002166{
2167 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002168 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002169 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002170}
2171
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002172void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002173{
2174 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002175 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002176 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002177}
2178
Brandon Jones59770802018-04-02 13:18:42 -07002179void Context::texParameterivRobust(TextureType target,
2180 GLenum pname,
2181 GLsizei bufSize,
2182 const GLint *params)
2183{
2184 texParameteriv(target, pname, params);
2185}
2186
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002187void Context::texParameterIivRobust(TextureType target,
2188 GLenum pname,
2189 GLsizei bufSize,
2190 const GLint *params)
2191{
2192 UNIMPLEMENTED();
2193}
2194
2195void Context::texParameterIuivRobust(TextureType target,
2196 GLenum pname,
2197 GLsizei bufSize,
2198 const GLuint *params)
2199{
2200 UNIMPLEMENTED();
2201}
2202
Jamie Madill493f9572018-05-24 19:52:15 -04002203void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002204{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002205 // No-op if count draws no primitives for given mode
2206 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002207 {
2208 return;
2209 }
2210
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002211 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002212 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002213 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002214}
2215
Jamie Madill493f9572018-05-24 19:52:15 -04002216void Context::drawArraysInstanced(PrimitiveMode mode,
2217 GLint first,
2218 GLsizei count,
2219 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002220{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002221 // No-op if count draws no primitives for given mode
2222 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002223 {
2224 return;
2225 }
2226
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002227 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002228 ANGLE_CONTEXT_TRY(
2229 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002230 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2231 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002232}
2233
Jamie Madill493f9572018-05-24 19:52:15 -04002234void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002235{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002236 // No-op if count draws no primitives for given mode
2237 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002238 {
2239 return;
2240 }
2241
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002242 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002243 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002244}
2245
Jamie Madill493f9572018-05-24 19:52:15 -04002246void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002247 GLsizei count,
2248 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002249 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002250 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002251{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002252 // No-op if count draws no primitives for given mode
2253 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002254 {
2255 return;
2256 }
2257
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002258 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002259 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002260 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002261}
2262
Jamie Madill493f9572018-05-24 19:52:15 -04002263void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002264 GLuint start,
2265 GLuint end,
2266 GLsizei count,
2267 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002268 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002269{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002270 // No-op if count draws no primitives for given mode
2271 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002272 {
2273 return;
2274 }
2275
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002276 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002277 ANGLE_CONTEXT_TRY(
2278 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002279}
2280
Jamie Madill493f9572018-05-24 19:52:15 -04002281void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002282{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002283 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002284 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002285}
2286
Jamie Madill493f9572018-05-24 19:52:15 -04002287void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002288{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002289 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002290 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002291}
2292
Jamie Madill675fe712016-12-19 13:07:54 -05002293void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002294{
Jamie Madillafa02a22017-11-23 12:57:38 -05002295 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002296}
2297
Jamie Madill675fe712016-12-19 13:07:54 -05002298void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002299{
Jamie Madillafa02a22017-11-23 12:57:38 -05002300 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002301}
2302
Austin Kinross6ee1e782015-05-29 17:05:37 -07002303void Context::insertEventMarker(GLsizei length, const char *marker)
2304{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002305 ASSERT(mImplementation);
2306 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002307}
2308
2309void Context::pushGroupMarker(GLsizei length, const char *marker)
2310{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002311 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002312
2313 if (marker == nullptr)
2314 {
2315 // From the EXT_debug_marker spec,
2316 // "If <marker> is null then an empty string is pushed on the stack."
2317 mImplementation->pushGroupMarker(length, "");
2318 }
2319 else
2320 {
2321 mImplementation->pushGroupMarker(length, marker);
2322 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002323}
2324
2325void Context::popGroupMarker()
2326{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002327 ASSERT(mImplementation);
2328 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002329}
2330
Geoff Langd8605522016-04-13 10:19:12 -04002331void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2332{
2333 Program *programObject = getProgram(program);
2334 ASSERT(programObject);
2335
2336 programObject->bindUniformLocation(location, name);
2337}
2338
Brandon Jones59770802018-04-02 13:18:42 -07002339void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002340{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002341 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002342}
2343
Brandon Jones59770802018-04-02 13:18:42 -07002344void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002345{
2346 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2347}
2348
Brandon Jones59770802018-04-02 13:18:42 -07002349void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002350{
2351 GLfloat I[16];
2352 angle::Matrix<GLfloat>::setToIdentity(I);
2353
2354 mGLState.loadPathRenderingMatrix(matrixMode, I);
2355}
2356
2357void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2358{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002359 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002360 if (!pathObj)
2361 return;
2362
Geoff Lang9bf86f02018-07-26 11:46:34 -04002363 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002364
2365 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2366}
2367
2368void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2369{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002370 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002371 if (!pathObj)
2372 return;
2373
Geoff Lang9bf86f02018-07-26 11:46:34 -04002374 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002375
2376 mImplementation->stencilStrokePath(pathObj, reference, mask);
2377}
2378
2379void Context::coverFillPath(GLuint path, GLenum coverMode)
2380{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002381 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002382 if (!pathObj)
2383 return;
2384
Geoff Lang9bf86f02018-07-26 11:46:34 -04002385 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002386
2387 mImplementation->coverFillPath(pathObj, coverMode);
2388}
2389
2390void Context::coverStrokePath(GLuint path, GLenum coverMode)
2391{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002392 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002393 if (!pathObj)
2394 return;
2395
Geoff Lang9bf86f02018-07-26 11:46:34 -04002396 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002397
2398 mImplementation->coverStrokePath(pathObj, coverMode);
2399}
2400
2401void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2402{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002403 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002404 if (!pathObj)
2405 return;
2406
Geoff Lang9bf86f02018-07-26 11:46:34 -04002407 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002408
2409 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2410}
2411
2412void Context::stencilThenCoverStrokePath(GLuint path,
2413 GLint reference,
2414 GLuint mask,
2415 GLenum coverMode)
2416{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002417 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002418 if (!pathObj)
2419 return;
2420
Geoff Lang9bf86f02018-07-26 11:46:34 -04002421 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002422
2423 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2424}
2425
Sami Väisänend59ca052016-06-21 16:10:00 +03002426void Context::coverFillPathInstanced(GLsizei numPaths,
2427 GLenum pathNameType,
2428 const void *paths,
2429 GLuint pathBase,
2430 GLenum coverMode,
2431 GLenum transformType,
2432 const GLfloat *transformValues)
2433{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002434 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002435
Geoff Lang9bf86f02018-07-26 11:46:34 -04002436 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002437
2438 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2439}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002440
Sami Väisänend59ca052016-06-21 16:10:00 +03002441void Context::coverStrokePathInstanced(GLsizei numPaths,
2442 GLenum pathNameType,
2443 const void *paths,
2444 GLuint pathBase,
2445 GLenum coverMode,
2446 GLenum transformType,
2447 const GLfloat *transformValues)
2448{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002449 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002450
2451 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002452 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002453
2454 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2455 transformValues);
2456}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002457
Sami Väisänend59ca052016-06-21 16:10:00 +03002458void Context::stencilFillPathInstanced(GLsizei numPaths,
2459 GLenum pathNameType,
2460 const void *paths,
2461 GLuint pathBase,
2462 GLenum fillMode,
2463 GLuint mask,
2464 GLenum transformType,
2465 const GLfloat *transformValues)
2466{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002467 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002468
2469 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002470 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002471
2472 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2473 transformValues);
2474}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002475
Sami Väisänend59ca052016-06-21 16:10:00 +03002476void Context::stencilStrokePathInstanced(GLsizei numPaths,
2477 GLenum pathNameType,
2478 const void *paths,
2479 GLuint pathBase,
2480 GLint reference,
2481 GLuint mask,
2482 GLenum transformType,
2483 const GLfloat *transformValues)
2484{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002485 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002486
Geoff Lang9bf86f02018-07-26 11:46:34 -04002487 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002488
2489 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2490 transformValues);
2491}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002492
Sami Väisänend59ca052016-06-21 16:10:00 +03002493void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2494 GLenum pathNameType,
2495 const void *paths,
2496 GLuint pathBase,
2497 GLenum fillMode,
2498 GLuint mask,
2499 GLenum coverMode,
2500 GLenum transformType,
2501 const GLfloat *transformValues)
2502{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002503 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002504
Geoff Lang9bf86f02018-07-26 11:46:34 -04002505 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002506
2507 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2508 transformType, transformValues);
2509}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002510
Sami Väisänend59ca052016-06-21 16:10:00 +03002511void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2512 GLenum pathNameType,
2513 const void *paths,
2514 GLuint pathBase,
2515 GLint reference,
2516 GLuint mask,
2517 GLenum coverMode,
2518 GLenum transformType,
2519 const GLfloat *transformValues)
2520{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002521 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002522
Geoff Lang9bf86f02018-07-26 11:46:34 -04002523 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002524
2525 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2526 transformType, transformValues);
2527}
2528
Sami Väisänen46eaa942016-06-29 10:26:37 +03002529void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2530{
2531 auto *programObject = getProgram(program);
2532
2533 programObject->bindFragmentInputLocation(location, name);
2534}
2535
2536void Context::programPathFragmentInputGen(GLuint program,
2537 GLint location,
2538 GLenum genMode,
2539 GLint components,
2540 const GLfloat *coeffs)
2541{
2542 auto *programObject = getProgram(program);
2543
jchen103fd614d2018-08-13 12:21:58 +08002544 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002545}
2546
jchen1015015f72017-03-16 13:54:21 +08002547GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2548{
jchen10fd7c3b52017-03-21 15:36:03 +08002549 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002550 return QueryProgramResourceIndex(programObject, programInterface, name);
2551}
2552
jchen10fd7c3b52017-03-21 15:36:03 +08002553void Context::getProgramResourceName(GLuint program,
2554 GLenum programInterface,
2555 GLuint index,
2556 GLsizei bufSize,
2557 GLsizei *length,
2558 GLchar *name)
2559{
2560 const auto *programObject = getProgram(program);
2561 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2562}
2563
jchen10191381f2017-04-11 13:59:04 +08002564GLint Context::getProgramResourceLocation(GLuint program,
2565 GLenum programInterface,
2566 const GLchar *name)
2567{
2568 const auto *programObject = getProgram(program);
2569 return QueryProgramResourceLocation(programObject, programInterface, name);
2570}
2571
jchen10880683b2017-04-12 16:21:55 +08002572void Context::getProgramResourceiv(GLuint program,
2573 GLenum programInterface,
2574 GLuint index,
2575 GLsizei propCount,
2576 const GLenum *props,
2577 GLsizei bufSize,
2578 GLsizei *length,
2579 GLint *params)
2580{
2581 const auto *programObject = getProgram(program);
2582 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2583 length, params);
2584}
2585
jchen10d9cd7b72017-08-30 15:04:25 +08002586void Context::getProgramInterfaceiv(GLuint program,
2587 GLenum programInterface,
2588 GLenum pname,
2589 GLint *params)
2590{
2591 const auto *programObject = getProgram(program);
2592 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2593}
2594
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002595void Context::getProgramInterfaceivRobust(GLuint program,
2596 GLenum programInterface,
2597 GLenum pname,
2598 GLsizei bufSize,
2599 GLsizei *length,
2600 GLint *params)
2601{
2602 UNIMPLEMENTED();
2603}
2604
Jamie Madill306b6c12018-07-27 08:12:49 -04002605void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002606{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002607 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002608}
2609
2610// Get one of the recorded errors and clear its flag, if any.
2611// [OpenGL ES 2.0.24] section 2.5 page 13.
2612GLenum Context::getError()
2613{
Geoff Langda5777c2014-07-11 09:52:58 -04002614 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002615 {
Geoff Langda5777c2014-07-11 09:52:58 -04002616 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002617 }
Geoff Langda5777c2014-07-11 09:52:58 -04002618 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002619 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002620 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002621 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002622}
2623
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002624// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002625void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002626{
2627 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002628 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002629 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002630 mContextLostForced = true;
2631 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002632 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002633}
2634
Jamie Madill427064d2018-04-13 16:20:34 -04002635bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002636{
2637 return mContextLost;
2638}
2639
Jamie Madillfa920eb2018-01-04 11:45:50 -05002640GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002641{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002642 // Even if the application doesn't want to know about resets, we want to know
2643 // as it will allow us to skip all the calls.
2644 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002645 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002646 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002647 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002648 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002649 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002650
2651 // EXT_robustness, section 2.6: If the reset notification behavior is
2652 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2653 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2654 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002655 }
2656
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002657 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2658 // status should be returned at least once, and GL_NO_ERROR should be returned
2659 // once the device has finished resetting.
2660 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002661 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002662 ASSERT(mResetStatus == GL_NO_ERROR);
2663 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002664
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002665 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002666 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002667 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002668 }
2669 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002670 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002671 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002672 // If markContextLost was used to mark the context lost then
2673 // assume that is not recoverable, and continue to report the
2674 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002675 mResetStatus = mImplementation->getResetStatus();
2676 }
Jamie Madill893ab082014-05-16 16:56:10 -04002677
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002678 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002679}
2680
2681bool Context::isResetNotificationEnabled()
2682{
2683 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2684}
2685
Corentin Walleze3b10e82015-05-20 11:06:25 -04002686const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002687{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002688 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002689}
2690
2691EGLenum Context::getClientType() const
2692{
2693 return mClientType;
2694}
2695
2696EGLenum Context::getRenderBuffer() const
2697{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002698 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2699 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002700 {
2701 return EGL_NONE;
2702 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002703
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002704 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002705 ASSERT(backAttachment != nullptr);
2706 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002707}
2708
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002709VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002710{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002711 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002712 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2713 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002714 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002715 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2716 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002717
Jamie Madill96a483b2017-06-27 16:49:21 -04002718 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002719 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002720
2721 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002722}
2723
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002724TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002725{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002726 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002727 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2728 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002729 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002730 transformFeedback =
2731 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002732 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002733 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002734 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002735
2736 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002737}
2738
2739bool Context::isVertexArrayGenerated(GLuint vertexArray)
2740{
Jamie Madill96a483b2017-06-27 16:49:21 -04002741 ASSERT(mVertexArrayMap.contains(0));
2742 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002743}
2744
2745bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2746{
Jamie Madill96a483b2017-06-27 16:49:21 -04002747 ASSERT(mTransformFeedbackMap.contains(0));
2748 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002749}
2750
Shannon Woods53a94a82014-06-24 15:20:36 -04002751void Context::detachTexture(GLuint texture)
2752{
2753 // Simple pass-through to State's detachTexture method, as textures do not require
2754 // allocation map management either here or in the resource manager at detach time.
2755 // Zero textures are held by the Context, and we don't attempt to request them from
2756 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002757 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002758}
2759
James Darpinian4d9d4832018-03-13 12:43:28 -07002760void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002761{
Yuly Novikov5807a532015-12-03 13:01:22 -05002762 // Simple pass-through to State's detachBuffer method, since
2763 // only buffer attachments to container objects that are bound to the current context
2764 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002765
Yuly Novikov5807a532015-12-03 13:01:22 -05002766 // [OpenGL ES 3.2] section 5.1.2 page 45:
2767 // Attachments to unbound container objects, such as
2768 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2769 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002770 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002771}
2772
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002773void Context::detachFramebuffer(GLuint framebuffer)
2774{
Shannon Woods53a94a82014-06-24 15:20:36 -04002775 // Framebuffer detachment is handled by Context, because 0 is a valid
2776 // Framebuffer object, and a pointer to it must be passed from Context
2777 // to State at binding time.
2778
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002779 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002780 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2781 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2782 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002783
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002784 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002785 {
2786 bindReadFramebuffer(0);
2787 }
2788
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002789 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002790 {
2791 bindDrawFramebuffer(0);
2792 }
2793}
2794
2795void Context::detachRenderbuffer(GLuint renderbuffer)
2796{
Jamie Madilla02315b2017-02-23 14:14:47 -05002797 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002798}
2799
Jamie Madill57a89722013-07-02 11:57:03 -04002800void Context::detachVertexArray(GLuint vertexArray)
2801{
Jamie Madill77a72f62015-04-14 11:18:32 -04002802 // Vertex array detachment is handled by Context, because 0 is a valid
2803 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002804 // binding time.
2805
Jamie Madill57a89722013-07-02 11:57:03 -04002806 // [OpenGL ES 3.0.2] section 2.10 page 43:
2807 // If a vertex array object that is currently bound is deleted, the binding
2808 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002809 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002810 {
2811 bindVertexArray(0);
2812 }
2813}
2814
Geoff Langc8058452014-02-03 12:04:11 -05002815void Context::detachTransformFeedback(GLuint transformFeedback)
2816{
Corentin Walleza2257da2016-04-19 16:43:12 -04002817 // Transform feedback detachment is handled by Context, because 0 is a valid
2818 // transform feedback, and a pointer to it must be passed from Context to State at
2819 // binding time.
2820
2821 // The OpenGL specification doesn't mention what should happen when the currently bound
2822 // transform feedback object is deleted. Since it is a container object, we treat it like
2823 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002824 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002825 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002826 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002827 }
Geoff Langc8058452014-02-03 12:04:11 -05002828}
2829
Jamie Madilldc356042013-07-19 16:36:57 -04002830void Context::detachSampler(GLuint sampler)
2831{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002832 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002833}
2834
Yunchao Hea336b902017-08-02 16:05:21 +08002835void Context::detachProgramPipeline(GLuint pipeline)
2836{
2837 mGLState.detachProgramPipeline(this, pipeline);
2838}
2839
Jamie Madill3ef140a2017-08-26 23:11:21 -04002840void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002841{
Shaodde78e82017-05-22 14:13:27 +08002842 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002843 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002844}
2845
Jamie Madille29d1672013-07-19 16:36:57 -04002846void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2847{
Geoff Langc1984ed2016-10-07 12:41:00 -04002848 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002849 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002850 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002851}
Jamie Madille29d1672013-07-19 16:36:57 -04002852
Geoff Langc1984ed2016-10-07 12:41:00 -04002853void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2854{
2855 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002856 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002857 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002858}
2859
Brandon Jones59770802018-04-02 13:18:42 -07002860void Context::samplerParameterivRobust(GLuint sampler,
2861 GLenum pname,
2862 GLsizei bufSize,
2863 const GLint *param)
2864{
2865 samplerParameteriv(sampler, pname, param);
2866}
2867
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002868void Context::samplerParameterIivRobust(GLuint sampler,
2869 GLenum pname,
2870 GLsizei bufSize,
2871 const GLint *param)
2872{
2873 UNIMPLEMENTED();
2874}
2875
2876void Context::samplerParameterIuivRobust(GLuint sampler,
2877 GLenum pname,
2878 GLsizei bufSize,
2879 const GLuint *param)
2880{
2881 UNIMPLEMENTED();
2882}
2883
Jamie Madille29d1672013-07-19 16:36:57 -04002884void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2885{
Geoff Langc1984ed2016-10-07 12:41:00 -04002886 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002887 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002888 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002889}
2890
Geoff Langc1984ed2016-10-07 12:41:00 -04002891void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002892{
Geoff Langc1984ed2016-10-07 12:41:00 -04002893 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002894 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002895 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002896}
2897
Brandon Jones59770802018-04-02 13:18:42 -07002898void Context::samplerParameterfvRobust(GLuint sampler,
2899 GLenum pname,
2900 GLsizei bufSize,
2901 const GLfloat *param)
2902{
2903 samplerParameterfv(sampler, pname, param);
2904}
2905
Geoff Langc1984ed2016-10-07 12:41:00 -04002906void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002907{
Geoff Langc1984ed2016-10-07 12:41:00 -04002908 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002909 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002910 QuerySamplerParameteriv(samplerObject, pname, params);
2911}
Jamie Madill9675b802013-07-19 16:36:59 -04002912
Brandon Jones59770802018-04-02 13:18:42 -07002913void Context::getSamplerParameterivRobust(GLuint sampler,
2914 GLenum pname,
2915 GLsizei bufSize,
2916 GLsizei *length,
2917 GLint *params)
2918{
2919 getSamplerParameteriv(sampler, pname, params);
2920}
2921
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002922void Context::getSamplerParameterIivRobust(GLuint sampler,
2923 GLenum pname,
2924 GLsizei bufSize,
2925 GLsizei *length,
2926 GLint *params)
2927{
2928 UNIMPLEMENTED();
2929}
2930
2931void Context::getSamplerParameterIuivRobust(GLuint sampler,
2932 GLenum pname,
2933 GLsizei bufSize,
2934 GLsizei *length,
2935 GLuint *params)
2936{
2937 UNIMPLEMENTED();
2938}
2939
Geoff Langc1984ed2016-10-07 12:41:00 -04002940void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2941{
2942 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002943 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002944 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002945}
2946
Brandon Jones59770802018-04-02 13:18:42 -07002947void Context::getSamplerParameterfvRobust(GLuint sampler,
2948 GLenum pname,
2949 GLsizei bufSize,
2950 GLsizei *length,
2951 GLfloat *params)
2952{
2953 getSamplerParameterfv(sampler, pname, params);
2954}
2955
Olli Etuahof0fee072016-03-30 15:11:58 +03002956void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2957{
2958 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002959 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002960}
2961
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002962void Context::initRendererString()
2963{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002964 std::ostringstream rendererString;
2965 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002966 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002967 rendererString << ")";
2968
Geoff Langcec35902014-04-16 10:52:36 -04002969 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002970}
2971
Geoff Langc339c4e2016-11-29 10:37:36 -05002972void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002973{
Geoff Langc339c4e2016-11-29 10:37:36 -05002974 const Version &clientVersion = getClientVersion();
2975
2976 std::ostringstream versionString;
2977 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2978 << ANGLE_VERSION_STRING << ")";
2979 mVersionString = MakeStaticString(versionString.str());
2980
2981 std::ostringstream shadingLanguageVersionString;
2982 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2983 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2984 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2985 << ")";
2986 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002987}
2988
Geoff Langcec35902014-04-16 10:52:36 -04002989void Context::initExtensionStrings()
2990{
Geoff Langc339c4e2016-11-29 10:37:36 -05002991 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2992 std::ostringstream combinedStringStream;
2993 std::copy(strings.begin(), strings.end(),
2994 std::ostream_iterator<const char *>(combinedStringStream, " "));
2995 return MakeStaticString(combinedStringStream.str());
2996 };
2997
2998 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002999 for (const auto &extensionString : mExtensions.getStrings())
3000 {
3001 mExtensionStrings.push_back(MakeStaticString(extensionString));
3002 }
Geoff Langc339c4e2016-11-29 10:37:36 -05003003 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003004
Geoff Langc339c4e2016-11-29 10:37:36 -05003005 mRequestableExtensionStrings.clear();
3006 for (const auto &extensionInfo : GetExtensionInfoMap())
3007 {
3008 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003009 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003010 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003011 {
3012 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3013 }
3014 }
3015 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003016}
3017
Geoff Langc339c4e2016-11-29 10:37:36 -05003018const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003019{
Geoff Langc339c4e2016-11-29 10:37:36 -05003020 switch (name)
3021 {
3022 case GL_VENDOR:
3023 return reinterpret_cast<const GLubyte *>("Google Inc.");
3024
3025 case GL_RENDERER:
3026 return reinterpret_cast<const GLubyte *>(mRendererString);
3027
3028 case GL_VERSION:
3029 return reinterpret_cast<const GLubyte *>(mVersionString);
3030
3031 case GL_SHADING_LANGUAGE_VERSION:
3032 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3033
3034 case GL_EXTENSIONS:
3035 return reinterpret_cast<const GLubyte *>(mExtensionString);
3036
3037 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3038 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3039
3040 default:
3041 UNREACHABLE();
3042 return nullptr;
3043 }
Geoff Langcec35902014-04-16 10:52:36 -04003044}
3045
Geoff Langc339c4e2016-11-29 10:37:36 -05003046const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003047{
Geoff Langc339c4e2016-11-29 10:37:36 -05003048 switch (name)
3049 {
3050 case GL_EXTENSIONS:
3051 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3052
3053 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3054 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3055
3056 default:
3057 UNREACHABLE();
3058 return nullptr;
3059 }
Geoff Langcec35902014-04-16 10:52:36 -04003060}
3061
3062size_t Context::getExtensionStringCount() const
3063{
3064 return mExtensionStrings.size();
3065}
3066
Geoff Lang111a99e2017-10-17 10:58:41 -04003067bool Context::isExtensionRequestable(const char *name)
3068{
3069 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3070 auto extension = extensionInfos.find(name);
3071
Geoff Lang111a99e2017-10-17 10:58:41 -04003072 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003073 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003074}
3075
Geoff Langc339c4e2016-11-29 10:37:36 -05003076void Context::requestExtension(const char *name)
3077{
3078 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3079 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3080 const auto &extension = extensionInfos.at(name);
3081 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003082 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003083
3084 if (mExtensions.*(extension.ExtensionsMember))
3085 {
3086 // Extension already enabled
3087 return;
3088 }
3089
3090 mExtensions.*(extension.ExtensionsMember) = true;
3091 updateCaps();
3092 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003093
Jamie Madill2f348d22017-06-05 10:50:59 -04003094 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3095 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003096
Jamie Madill81c2e252017-09-09 23:32:46 -04003097 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3098 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003099 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003100 for (auto &zeroTexture : mZeroTextures)
3101 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003102 if (zeroTexture.get() != nullptr)
3103 {
3104 zeroTexture->signalDirty(this, InitState::Initialized);
3105 }
Geoff Lang9aded172017-04-05 11:07:56 -04003106 }
3107
Jamie Madillb983a4b2018-08-01 11:34:51 -04003108 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003109}
3110
3111size_t Context::getRequestableExtensionStringCount() const
3112{
3113 return mRequestableExtensionStrings.size();
3114}
3115
Jamie Madill493f9572018-05-24 19:52:15 -04003116void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003117{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003118 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003119 ASSERT(transformFeedback != nullptr);
3120 ASSERT(!transformFeedback->isPaused());
3121
Jamie Madill6c1f6712017-02-14 19:08:04 -05003122 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Jamie Madilld84b6732018-09-06 15:54:35 -04003123 mStateCache.onTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003124}
3125
3126bool Context::hasActiveTransformFeedback(GLuint program) const
3127{
3128 for (auto pair : mTransformFeedbackMap)
3129 {
3130 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3131 {
3132 return true;
3133 }
3134 }
3135 return false;
3136}
3137
Geoff Lang33f11fb2018-05-07 13:42:47 -04003138Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003139{
3140 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3141
jchen1082af6202018-06-22 10:59:52 +08003142 // Explicitly enable GL_KHR_parallel_shader_compile
3143 supportedExtensions.parallelShaderCompile = true;
3144
Geoff Langb0f917f2017-12-05 13:41:54 -05003145 if (getClientVersion() < ES_2_0)
3146 {
3147 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003148 supportedExtensions.pointSizeArray = true;
3149 supportedExtensions.textureCubeMap = true;
3150 supportedExtensions.pointSprite = true;
3151 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003152 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003153 }
3154
3155 if (getClientVersion() < ES_3_0)
3156 {
3157 // Disable ES3+ extensions
3158 supportedExtensions.colorBufferFloat = false;
3159 supportedExtensions.eglImageExternalEssl3 = false;
3160 supportedExtensions.textureNorm16 = false;
3161 supportedExtensions.multiview = false;
3162 supportedExtensions.maxViews = 1u;
3163 }
3164
3165 if (getClientVersion() < ES_3_1)
3166 {
3167 // Disable ES3.1+ extensions
3168 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003169
3170 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3171 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003172 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003173 }
3174
3175 if (getClientVersion() > ES_2_0)
3176 {
3177 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3178 // supportedExtensions.sRGB = false;
3179 }
3180
3181 // Some extensions are always available because they are implemented in the GL layer.
3182 supportedExtensions.bindUniformLocation = true;
3183 supportedExtensions.vertexArrayObject = true;
3184 supportedExtensions.bindGeneratesResource = true;
3185 supportedExtensions.clientArrays = true;
3186 supportedExtensions.requestExtension = true;
3187
3188 // Enable the no error extension if the context was created with the flag.
3189 supportedExtensions.noError = mSkipValidation;
3190
3191 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003192 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003193
3194 // Explicitly enable GL_KHR_debug
3195 supportedExtensions.debug = true;
3196 supportedExtensions.maxDebugMessageLength = 1024;
3197 supportedExtensions.maxDebugLoggedMessages = 1024;
3198 supportedExtensions.maxDebugGroupStackDepth = 1024;
3199 supportedExtensions.maxLabelLength = 1024;
3200
3201 // Explicitly enable GL_ANGLE_robust_client_memory
3202 supportedExtensions.robustClientMemory = true;
3203
3204 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003205 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003206
3207 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3208 // supports it.
3209 supportedExtensions.robustBufferAccessBehavior =
3210 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3211
3212 // Enable the cache control query unconditionally.
3213 supportedExtensions.programCacheControl = true;
3214
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003215 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003216 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003217 {
3218 // GL_ANGLE_explicit_context_gles1
3219 supportedExtensions.explicitContextGles1 = true;
3220 // GL_ANGLE_explicit_context
3221 supportedExtensions.explicitContext = true;
3222 }
3223
Geoff Langb0f917f2017-12-05 13:41:54 -05003224 return supportedExtensions;
3225}
3226
Geoff Lang33f11fb2018-05-07 13:42:47 -04003227void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003228{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003229 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003230
Geoff Lang33f11fb2018-05-07 13:42:47 -04003231 mSupportedExtensions = generateSupportedExtensions();
3232 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003233
3234 mLimitations = mImplementation->getNativeLimitations();
3235
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003236 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3237 if (getClientVersion() < Version(2, 0))
3238 {
3239 mCaps.maxMultitextureUnits = 4;
3240 mCaps.maxClipPlanes = 6;
3241 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003242 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3243 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3244 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003245 mCaps.minSmoothPointSize = 1.0f;
3246 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003247 mCaps.minSmoothLineWidth = 1.0f;
3248 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003249 }
3250
Luc Ferronad2ae932018-06-11 15:31:17 -04003251 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003252 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003253
Luc Ferronad2ae932018-06-11 15:31:17 -04003254 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3255
Jamie Madill0f80ed82017-09-19 00:24:56 -04003256 if (getClientVersion() < ES_3_1)
3257 {
3258 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3259 }
3260 else
3261 {
3262 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3263 }
Geoff Lang301d1612014-07-09 10:34:37 -04003264
Jiawei Shao54aafe52018-04-27 14:54:57 +08003265 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3266 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003267 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3268
Jamie Madill0f80ed82017-09-19 00:24:56 -04003269 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3270 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3271
3272 // Limit textures as well, so we can use fast bitsets with texture bindings.
3273 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003274 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3275 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3276 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3277 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003278
Jiawei Shaodb342272017-09-27 10:21:45 +08003279 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3280
Geoff Langc287ea62016-09-16 14:46:51 -04003281 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003282 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003283 for (const auto &extensionInfo : GetExtensionInfoMap())
3284 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003285 // If the user has requested that extensions start disabled and they are requestable,
3286 // disable them.
3287 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003288 {
3289 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3290 }
3291 }
3292
3293 // Generate texture caps
3294 updateCaps();
3295}
3296
3297void Context::updateCaps()
3298{
Geoff Lang900013c2014-07-07 11:32:19 -04003299 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003300 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003301
Jamie Madill7b62cf92017-11-02 15:20:49 -04003302 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003303 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003304 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003305 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003306
Geoff Lang0d8b7242015-09-09 14:56:53 -04003307 // Update the format caps based on the client version and extensions.
3308 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3309 // ES3.
3310 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003311 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003312 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003313 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003314 formatCaps.textureAttachment =
3315 formatCaps.textureAttachment &&
3316 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3317 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3318 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003319
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003320 // OpenGL ES does not support multisampling with non-rendererable formats
3321 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003322 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003323 (getClientVersion() < ES_3_1 &&
3324 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003325 {
Geoff Langd87878e2014-09-19 15:42:59 -04003326 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003327 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003328 else
3329 {
3330 // We may have limited the max samples for some required renderbuffer formats due to
3331 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3332 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3333
3334 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3335 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3336 // exception of signed and unsigned integer formats."
3337 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3338 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3339 {
3340 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3341 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3342 }
3343
3344 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3345 if (getClientVersion() >= ES_3_1)
3346 {
3347 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3348 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3349 // the exception that the signed and unsigned integer formats are required only to
3350 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3351 // multisamples, which must be at least one."
3352 if (formatInfo.componentType == GL_INT ||
3353 formatInfo.componentType == GL_UNSIGNED_INT)
3354 {
3355 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3356 }
3357
3358 // GLES 3.1 section 19.3.1.
3359 if (formatCaps.texturable)
3360 {
3361 if (formatInfo.depthBits > 0)
3362 {
3363 mCaps.maxDepthTextureSamples =
3364 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3365 }
3366 else if (formatInfo.redBits > 0)
3367 {
3368 mCaps.maxColorTextureSamples =
3369 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3370 }
3371 }
3372 }
3373 }
Geoff Langd87878e2014-09-19 15:42:59 -04003374
3375 if (formatCaps.texturable && formatInfo.compressed)
3376 {
Geoff Langca271392017-04-05 12:30:00 -04003377 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003378 }
3379
Geoff Langca271392017-04-05 12:30:00 -04003380 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003381 }
Jamie Madill32447362017-06-28 14:53:52 -04003382
3383 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003384 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003385 {
3386 mMemoryProgramCache = nullptr;
3387 }
Corentin Walleze4477002017-12-01 14:39:58 -05003388
3389 // Compute which buffer types are allowed
3390 mValidBufferBindings.reset();
3391 mValidBufferBindings.set(BufferBinding::ElementArray);
3392 mValidBufferBindings.set(BufferBinding::Array);
3393
3394 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3395 {
3396 mValidBufferBindings.set(BufferBinding::PixelPack);
3397 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3398 }
3399
3400 if (getClientVersion() >= ES_3_0)
3401 {
3402 mValidBufferBindings.set(BufferBinding::CopyRead);
3403 mValidBufferBindings.set(BufferBinding::CopyWrite);
3404 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3405 mValidBufferBindings.set(BufferBinding::Uniform);
3406 }
3407
3408 if (getClientVersion() >= ES_3_1)
3409 {
3410 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3411 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3412 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3413 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3414 }
jchen107ae70d82018-07-06 13:47:01 +08003415
3416 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Geoff Lang493daf52014-07-03 13:38:44 -04003417}
3418
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003419void Context::initWorkarounds()
3420{
Jamie Madill761b02c2017-06-23 16:27:06 -04003421 // Apply back-end workarounds.
3422 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3423
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003424 // Lose the context upon out of memory error if the application is
3425 // expecting to watch for those events.
3426 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3427}
3428
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003429// Return true if the draw is a no-op, else return false.
3430// A no-op draw occurs if the count of vertices is less than the minimum required to
3431// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3432bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3433{
3434 return count < kMinimumPrimitiveCounts[mode];
3435}
3436
3437bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3438{
3439 return (instanceCount == 0) || noopDraw(mode, count);
3440}
3441
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003442Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003443{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003444 if (mGLES1Renderer)
3445 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003446 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003447 }
3448
Geoff Lang9bf86f02018-07-26 11:46:34 -04003449 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003450
3451 if (isRobustResourceInitEnabled())
3452 {
3453 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3454 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3455 }
3456
Geoff Langa8cb2872018-03-09 16:09:40 -05003457 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003458 return NoError();
3459}
3460
3461Error Context::prepareForClear(GLbitfield mask)
3462{
Geoff Langa8cb2872018-03-09 16:09:40 -05003463 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003464 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003465 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003466 return NoError();
3467}
3468
3469Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3470{
Geoff Langa8cb2872018-03-09 16:09:40 -05003471 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003472 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3473 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003474 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003475 return NoError();
3476}
3477
Geoff Langa8cb2872018-03-09 16:09:40 -05003478Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003479{
Geoff Langa8cb2872018-03-09 16:09:40 -05003480 ANGLE_TRY(syncDirtyObjects(objectMask));
3481 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003482 return NoError();
3483}
3484
Geoff Langa8cb2872018-03-09 16:09:40 -05003485Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003486{
3487 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003488 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003489 mGLState.clearDirtyBits();
3490 return NoError();
3491}
3492
Geoff Langa8cb2872018-03-09 16:09:40 -05003493Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003494{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003495 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003496 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003497 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003498 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003499}
Jamie Madillc29968b2016-01-20 11:17:23 -05003500
Geoff Langa8cb2872018-03-09 16:09:40 -05003501Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003502{
3503 return mGLState.syncDirtyObjects(this, objectMask);
3504}
3505
Jamie Madillc29968b2016-01-20 11:17:23 -05003506void Context::blitFramebuffer(GLint srcX0,
3507 GLint srcY0,
3508 GLint srcX1,
3509 GLint srcY1,
3510 GLint dstX0,
3511 GLint dstY0,
3512 GLint dstX1,
3513 GLint dstY1,
3514 GLbitfield mask,
3515 GLenum filter)
3516{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003517 if (mask == 0)
3518 {
3519 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3520 // buffers are copied.
3521 return;
3522 }
3523
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003524 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003525 ASSERT(drawFramebuffer);
3526
3527 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3528 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3529
Jamie Madillbc918e72018-03-08 09:47:21 -05003530 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003531
Jamie Madillc564c072017-06-01 12:45:42 -04003532 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003533}
Jamie Madillc29968b2016-01-20 11:17:23 -05003534
3535void Context::clear(GLbitfield mask)
3536{
Geoff Langd4fff502017-09-22 11:28:28 -04003537 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3538 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003539}
3540
3541void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3542{
Olli Etuahodbce1f82018-09-19 15:32:17 +03003543 if (buffer == GL_DEPTH && !getGLState().getDrawFramebuffer()->getDepthbuffer())
3544 {
3545 // It's not an error to try to clear a non-existent depth buffer, but it's a no-op.
3546 return;
3547 }
Geoff Langd4fff502017-09-22 11:28:28 -04003548 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3549 ANGLE_CONTEXT_TRY(
3550 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003551}
3552
3553void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3554{
Geoff Langd4fff502017-09-22 11:28:28 -04003555 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3556 ANGLE_CONTEXT_TRY(
3557 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003558}
3559
3560void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3561{
Olli Etuahodbce1f82018-09-19 15:32:17 +03003562 if (buffer == GL_STENCIL && !getGLState().getDrawFramebuffer()->getStencilbuffer())
3563 {
3564 // It's not an error to try to clear a non-existent stencil buffer, but it's a no-op.
3565 return;
3566 }
Geoff Langd4fff502017-09-22 11:28:28 -04003567 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3568 ANGLE_CONTEXT_TRY(
3569 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003570}
3571
3572void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3573{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003574 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003575 ASSERT(framebufferObject);
3576
3577 // If a buffer is not present, the clear has no effect
3578 if (framebufferObject->getDepthbuffer() == nullptr &&
3579 framebufferObject->getStencilbuffer() == nullptr)
3580 {
3581 return;
3582 }
3583
Geoff Langd4fff502017-09-22 11:28:28 -04003584 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3585 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003586}
3587
3588void Context::readPixels(GLint x,
3589 GLint y,
3590 GLsizei width,
3591 GLsizei height,
3592 GLenum format,
3593 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003594 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003595{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003596 if (width == 0 || height == 0)
3597 {
3598 return;
3599 }
3600
Jamie Madillbc918e72018-03-08 09:47:21 -05003601 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003602
Jamie Madillb6664922017-07-25 12:55:04 -04003603 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3604 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003605
3606 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003607 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003608}
3609
Brandon Jones59770802018-04-02 13:18:42 -07003610void Context::readPixelsRobust(GLint x,
3611 GLint y,
3612 GLsizei width,
3613 GLsizei height,
3614 GLenum format,
3615 GLenum type,
3616 GLsizei bufSize,
3617 GLsizei *length,
3618 GLsizei *columns,
3619 GLsizei *rows,
3620 void *pixels)
3621{
3622 readPixels(x, y, width, height, format, type, pixels);
3623}
3624
3625void Context::readnPixelsRobust(GLint x,
3626 GLint y,
3627 GLsizei width,
3628 GLsizei height,
3629 GLenum format,
3630 GLenum type,
3631 GLsizei bufSize,
3632 GLsizei *length,
3633 GLsizei *columns,
3634 GLsizei *rows,
3635 void *data)
3636{
3637 readPixels(x, y, width, height, format, type, data);
3638}
3639
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003640void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003641 GLint level,
3642 GLenum internalformat,
3643 GLint x,
3644 GLint y,
3645 GLsizei width,
3646 GLsizei height,
3647 GLint border)
3648{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003649 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003650 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003651
Jamie Madillc29968b2016-01-20 11:17:23 -05003652 Rectangle sourceArea(x, y, width, height);
3653
Jamie Madill05b35b22017-10-03 09:01:44 -04003654 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003655 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003656 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003657}
3658
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003659void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003660 GLint level,
3661 GLint xoffset,
3662 GLint yoffset,
3663 GLint x,
3664 GLint y,
3665 GLsizei width,
3666 GLsizei height)
3667{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003668 if (width == 0 || height == 0)
3669 {
3670 return;
3671 }
3672
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003673 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003674 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003675
Jamie Madillc29968b2016-01-20 11:17:23 -05003676 Offset destOffset(xoffset, yoffset, 0);
3677 Rectangle sourceArea(x, y, width, height);
3678
Jamie Madill05b35b22017-10-03 09:01:44 -04003679 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003680 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003681 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003682}
3683
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003684void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003685 GLint level,
3686 GLint xoffset,
3687 GLint yoffset,
3688 GLint zoffset,
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, zoffset);
3703 Rectangle sourceArea(x, y, width, height);
3704
Jamie Madill05b35b22017-10-03 09:01:44 -04003705 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3706 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003707 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3708 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003709}
3710
3711void Context::framebufferTexture2D(GLenum target,
3712 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003713 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003714 GLuint texture,
3715 GLint level)
3716{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003717 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003718 ASSERT(framebuffer);
3719
3720 if (texture != 0)
3721 {
3722 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003723 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003724 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003725 }
3726 else
3727 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003728 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003729 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003730
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003731 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003732}
3733
3734void Context::framebufferRenderbuffer(GLenum target,
3735 GLenum attachment,
3736 GLenum renderbuffertarget,
3737 GLuint renderbuffer)
3738{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003739 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003740 ASSERT(framebuffer);
3741
3742 if (renderbuffer != 0)
3743 {
3744 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003745
Jamie Madillcc129372018-04-12 09:13:18 -04003746 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003747 renderbufferObject);
3748 }
3749 else
3750 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003751 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003752 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003753
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003754 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003755}
3756
3757void Context::framebufferTextureLayer(GLenum target,
3758 GLenum attachment,
3759 GLuint texture,
3760 GLint level,
3761 GLint layer)
3762{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003763 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003764 ASSERT(framebuffer);
3765
3766 if (texture != 0)
3767 {
3768 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003769 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003770 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003771 }
3772 else
3773 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003774 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003775 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003776
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003777 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003778}
3779
Brandon Jones59770802018-04-02 13:18:42 -07003780void Context::framebufferTextureMultiviewLayered(GLenum target,
3781 GLenum attachment,
3782 GLuint texture,
3783 GLint level,
3784 GLint baseViewIndex,
3785 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003786{
Martin Radev82ef7742017-08-08 17:44:58 +03003787 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3788 ASSERT(framebuffer);
3789
3790 if (texture != 0)
3791 {
3792 Texture *textureObj = getTexture(texture);
3793
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003794 ImageIndex index;
3795 if (textureObj->getType() == TextureType::_2DArray)
3796 {
3797 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3798 }
3799 else
3800 {
3801 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3802 ASSERT(level == 0);
3803 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3804 }
Martin Radev82ef7742017-08-08 17:44:58 +03003805 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3806 numViews, baseViewIndex);
3807 }
3808 else
3809 {
3810 framebuffer->resetAttachment(this, attachment);
3811 }
3812
3813 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003814}
3815
Brandon Jones59770802018-04-02 13:18:42 -07003816void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3817 GLenum attachment,
3818 GLuint texture,
3819 GLint level,
3820 GLsizei numViews,
3821 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003822{
Martin Radev5dae57b2017-07-14 16:15:55 +03003823 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3824 ASSERT(framebuffer);
3825
3826 if (texture != 0)
3827 {
3828 Texture *textureObj = getTexture(texture);
3829
3830 ImageIndex index = ImageIndex::Make2D(level);
3831 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3832 textureObj, numViews, viewportOffsets);
3833 }
3834 else
3835 {
3836 framebuffer->resetAttachment(this, attachment);
3837 }
3838
3839 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003840}
3841
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003842void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3843{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003844 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3845 ASSERT(framebuffer);
3846
3847 if (texture != 0)
3848 {
3849 Texture *textureObj = getTexture(texture);
3850
3851 ImageIndex index = ImageIndex::MakeFromType(
3852 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3853 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3854 }
3855 else
3856 {
3857 framebuffer->resetAttachment(this, attachment);
3858 }
3859
3860 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003861}
3862
Jamie Madillc29968b2016-01-20 11:17:23 -05003863void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3864{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003865 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003866 ASSERT(framebuffer);
3867 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003868 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04003869 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003870}
3871
3872void Context::readBuffer(GLenum mode)
3873{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003874 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003875 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003876 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003877}
3878
3879void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3880{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003881 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003882 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003883
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003884 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003885 ASSERT(framebuffer);
3886
3887 // The specification isn't clear what should be done when the framebuffer isn't complete.
3888 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003889 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003890}
3891
3892void Context::invalidateFramebuffer(GLenum target,
3893 GLsizei numAttachments,
3894 const GLenum *attachments)
3895{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003896 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003897 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003898
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003899 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003900 ASSERT(framebuffer);
3901
Jamie Madill427064d2018-04-13 16:20:34 -04003902 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003903 {
Jamie Madill437fa652016-05-03 15:13:24 -04003904 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003905 }
Jamie Madill437fa652016-05-03 15:13:24 -04003906
Jamie Madill4928b7c2017-06-20 12:57:39 -04003907 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003908}
3909
3910void Context::invalidateSubFramebuffer(GLenum target,
3911 GLsizei numAttachments,
3912 const GLenum *attachments,
3913 GLint x,
3914 GLint y,
3915 GLsizei width,
3916 GLsizei height)
3917{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003918 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003919 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003920
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003921 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003922 ASSERT(framebuffer);
3923
Jamie Madill427064d2018-04-13 16:20:34 -04003924 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003925 {
Jamie Madill437fa652016-05-03 15:13:24 -04003926 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003927 }
Jamie Madill437fa652016-05-03 15:13:24 -04003928
3929 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003930 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003931}
3932
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003933void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003934 GLint level,
3935 GLint internalformat,
3936 GLsizei width,
3937 GLsizei height,
3938 GLint border,
3939 GLenum format,
3940 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003941 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003942{
Jamie Madillbc918e72018-03-08 09:47:21 -05003943 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003944
3945 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003946 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003947 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003948 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003949}
3950
Brandon Jones59770802018-04-02 13:18:42 -07003951void Context::texImage2DRobust(TextureTarget target,
3952 GLint level,
3953 GLint internalformat,
3954 GLsizei width,
3955 GLsizei height,
3956 GLint border,
3957 GLenum format,
3958 GLenum type,
3959 GLsizei bufSize,
3960 const void *pixels)
3961{
3962 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3963}
3964
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003965void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003966 GLint level,
3967 GLint internalformat,
3968 GLsizei width,
3969 GLsizei height,
3970 GLsizei depth,
3971 GLint border,
3972 GLenum format,
3973 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003974 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003975{
Jamie Madillbc918e72018-03-08 09:47:21 -05003976 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003977
3978 Extents size(width, height, depth);
3979 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003980 handleError(texture->setImage(this, mGLState.getUnpackState(),
3981 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003982 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003983}
3984
Brandon Jones59770802018-04-02 13:18:42 -07003985void Context::texImage3DRobust(TextureType target,
3986 GLint level,
3987 GLint internalformat,
3988 GLsizei width,
3989 GLsizei height,
3990 GLsizei depth,
3991 GLint border,
3992 GLenum format,
3993 GLenum type,
3994 GLsizei bufSize,
3995 const void *pixels)
3996{
3997 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3998}
3999
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004000void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004001 GLint level,
4002 GLint xoffset,
4003 GLint yoffset,
4004 GLsizei width,
4005 GLsizei height,
4006 GLenum format,
4007 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004008 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004009{
4010 // Zero sized uploads are valid but no-ops
4011 if (width == 0 || height == 0)
4012 {
4013 return;
4014 }
4015
Jamie Madillbc918e72018-03-08 09:47:21 -05004016 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004017
4018 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004019 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004020
4021 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4022
4023 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target, level,
4024 area, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004025}
4026
Brandon Jones59770802018-04-02 13:18:42 -07004027void Context::texSubImage2DRobust(TextureTarget target,
4028 GLint level,
4029 GLint xoffset,
4030 GLint yoffset,
4031 GLsizei width,
4032 GLsizei height,
4033 GLenum format,
4034 GLenum type,
4035 GLsizei bufSize,
4036 const void *pixels)
4037{
4038 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4039}
4040
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004041void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004042 GLint level,
4043 GLint xoffset,
4044 GLint yoffset,
4045 GLint zoffset,
4046 GLsizei width,
4047 GLsizei height,
4048 GLsizei depth,
4049 GLenum format,
4050 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004051 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004052{
4053 // Zero sized uploads are valid but no-ops
4054 if (width == 0 || height == 0 || depth == 0)
4055 {
4056 return;
4057 }
4058
Jamie Madillbc918e72018-03-08 09:47:21 -05004059 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004060
4061 Box area(xoffset, yoffset, zoffset, width, height, depth);
4062 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004063
4064 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4065
4066 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004067 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004068 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004069}
4070
Brandon Jones59770802018-04-02 13:18:42 -07004071void Context::texSubImage3DRobust(TextureType target,
4072 GLint level,
4073 GLint xoffset,
4074 GLint yoffset,
4075 GLint zoffset,
4076 GLsizei width,
4077 GLsizei height,
4078 GLsizei depth,
4079 GLenum format,
4080 GLenum type,
4081 GLsizei bufSize,
4082 const void *pixels)
4083{
4084 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4085 pixels);
4086}
4087
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004088void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004089 GLint level,
4090 GLenum internalformat,
4091 GLsizei width,
4092 GLsizei height,
4093 GLint border,
4094 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004095 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004096{
Jamie Madillbc918e72018-03-08 09:47:21 -05004097 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004098
4099 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004100 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004101 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4102 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004103 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004104}
4105
Brandon Jones59770802018-04-02 13:18:42 -07004106void Context::compressedTexImage2DRobust(TextureTarget target,
4107 GLint level,
4108 GLenum internalformat,
4109 GLsizei width,
4110 GLsizei height,
4111 GLint border,
4112 GLsizei imageSize,
4113 GLsizei dataSize,
4114 const GLvoid *data)
4115{
4116 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4117}
4118
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004119void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004120 GLint level,
4121 GLenum internalformat,
4122 GLsizei width,
4123 GLsizei height,
4124 GLsizei depth,
4125 GLint border,
4126 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004127 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004128{
Jamie Madillbc918e72018-03-08 09:47:21 -05004129 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004130
4131 Extents size(width, height, depth);
4132 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004133 handleError(texture->setCompressedImage(
4134 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004135 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004136}
4137
Brandon Jones59770802018-04-02 13:18:42 -07004138void Context::compressedTexImage3DRobust(TextureType target,
4139 GLint level,
4140 GLenum internalformat,
4141 GLsizei width,
4142 GLsizei height,
4143 GLsizei depth,
4144 GLint border,
4145 GLsizei imageSize,
4146 GLsizei dataSize,
4147 const GLvoid *data)
4148{
4149 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4150 data);
4151}
4152
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004153void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004154 GLint level,
4155 GLint xoffset,
4156 GLint yoffset,
4157 GLsizei width,
4158 GLsizei height,
4159 GLenum format,
4160 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004161 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004162{
Jamie Madillbc918e72018-03-08 09:47:21 -05004163 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004164
4165 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004166 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004167 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4168 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004169 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004170}
4171
Brandon Jones59770802018-04-02 13:18:42 -07004172void Context::compressedTexSubImage2DRobust(TextureTarget target,
4173 GLint level,
4174 GLint xoffset,
4175 GLint yoffset,
4176 GLsizei width,
4177 GLsizei height,
4178 GLenum format,
4179 GLsizei imageSize,
4180 GLsizei dataSize,
4181 const GLvoid *data)
4182{
4183 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4184 data);
4185}
4186
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004187void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004188 GLint level,
4189 GLint xoffset,
4190 GLint yoffset,
4191 GLint zoffset,
4192 GLsizei width,
4193 GLsizei height,
4194 GLsizei depth,
4195 GLenum format,
4196 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004197 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004198{
4199 // Zero sized uploads are valid but no-ops
4200 if (width == 0 || height == 0)
4201 {
4202 return;
4203 }
4204
Jamie Madillbc918e72018-03-08 09:47:21 -05004205 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004206
4207 Box area(xoffset, yoffset, zoffset, width, height, depth);
4208 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004209 handleError(texture->setCompressedSubImage(
4210 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004211 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004212}
4213
Brandon Jones59770802018-04-02 13:18:42 -07004214void Context::compressedTexSubImage3DRobust(TextureType target,
4215 GLint level,
4216 GLint xoffset,
4217 GLint yoffset,
4218 GLint zoffset,
4219 GLsizei width,
4220 GLsizei height,
4221 GLsizei depth,
4222 GLenum format,
4223 GLsizei imageSize,
4224 GLsizei dataSize,
4225 const GLvoid *data)
4226{
4227 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4228 imageSize, data);
4229}
4230
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004231void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004232{
4233 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004234 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004235}
4236
Jamie Madill007530e2017-12-28 14:27:04 -05004237void Context::copyTexture(GLuint sourceId,
4238 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004239 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004240 GLuint destId,
4241 GLint destLevel,
4242 GLint internalFormat,
4243 GLenum destType,
4244 GLboolean unpackFlipY,
4245 GLboolean unpackPremultiplyAlpha,
4246 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004247{
Jamie Madillbc918e72018-03-08 09:47:21 -05004248 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004249
4250 gl::Texture *sourceTexture = getTexture(sourceId);
4251 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004252 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4253 sourceLevel, ConvertToBool(unpackFlipY),
4254 ConvertToBool(unpackPremultiplyAlpha),
4255 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004256}
4257
Jamie Madill007530e2017-12-28 14:27:04 -05004258void Context::copySubTexture(GLuint sourceId,
4259 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004260 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004261 GLuint destId,
4262 GLint destLevel,
4263 GLint xoffset,
4264 GLint yoffset,
4265 GLint x,
4266 GLint y,
4267 GLsizei width,
4268 GLsizei height,
4269 GLboolean unpackFlipY,
4270 GLboolean unpackPremultiplyAlpha,
4271 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004272{
4273 // Zero sized copies are valid but no-ops
4274 if (width == 0 || height == 0)
4275 {
4276 return;
4277 }
4278
Jamie Madillbc918e72018-03-08 09:47:21 -05004279 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004280
4281 gl::Texture *sourceTexture = getTexture(sourceId);
4282 gl::Texture *destTexture = getTexture(destId);
4283 Offset offset(xoffset, yoffset, 0);
4284 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004285 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4286 ConvertToBool(unpackFlipY),
4287 ConvertToBool(unpackPremultiplyAlpha),
4288 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004289}
4290
Jamie Madill007530e2017-12-28 14:27:04 -05004291void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004292{
Jamie Madillbc918e72018-03-08 09:47:21 -05004293 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004294
4295 gl::Texture *sourceTexture = getTexture(sourceId);
4296 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004297 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004298}
4299
Corentin Wallez336129f2017-10-17 15:55:40 -04004300void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004301{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004302 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004303 ASSERT(buffer);
4304
Geoff Lang496c02d2016-10-20 11:38:11 -07004305 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004306}
4307
Brandon Jones59770802018-04-02 13:18:42 -07004308void Context::getBufferPointervRobust(BufferBinding target,
4309 GLenum pname,
4310 GLsizei bufSize,
4311 GLsizei *length,
4312 void **params)
4313{
4314 getBufferPointerv(target, pname, params);
4315}
4316
Corentin Wallez336129f2017-10-17 15:55:40 -04004317void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004318{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004319 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004320 ASSERT(buffer);
4321
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004322 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004323 if (error.isError())
4324 {
Jamie Madill437fa652016-05-03 15:13:24 -04004325 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004326 return nullptr;
4327 }
4328
4329 return buffer->getMapPointer();
4330}
4331
Corentin Wallez336129f2017-10-17 15:55:40 -04004332GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004333{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004334 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004335 ASSERT(buffer);
4336
4337 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004338 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004339 if (error.isError())
4340 {
Jamie Madill437fa652016-05-03 15:13:24 -04004341 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004342 return GL_FALSE;
4343 }
4344
4345 return result;
4346}
4347
Corentin Wallez336129f2017-10-17 15:55:40 -04004348void *Context::mapBufferRange(BufferBinding target,
4349 GLintptr offset,
4350 GLsizeiptr length,
4351 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004352{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004353 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004354 ASSERT(buffer);
4355
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004356 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004357 if (error.isError())
4358 {
Jamie Madill437fa652016-05-03 15:13:24 -04004359 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004360 return nullptr;
4361 }
4362
4363 return buffer->getMapPointer();
4364}
4365
Corentin Wallez336129f2017-10-17 15:55:40 -04004366void Context::flushMappedBufferRange(BufferBinding /*target*/,
4367 GLintptr /*offset*/,
4368 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004369{
4370 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4371}
4372
Jamie Madillbc918e72018-03-08 09:47:21 -05004373Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004374{
Geoff Langa8cb2872018-03-09 16:09:40 -05004375 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004376}
4377
Jamie Madillbc918e72018-03-08 09:47:21 -05004378Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004379{
Geoff Langa8cb2872018-03-09 16:09:40 -05004380 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004381}
4382
Jamie Madillbc918e72018-03-08 09:47:21 -05004383Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004384{
Geoff Langa8cb2872018-03-09 16:09:40 -05004385 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004386}
4387
Geoff Lang9bf86f02018-07-26 11:46:34 -04004388Error Context::syncStateForPathOperation()
4389{
4390 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4391
4392 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4393 ANGLE_TRY(syncDirtyBits());
4394
4395 return NoError();
4396}
4397
Jiajia Qin5451d532017-11-16 17:16:34 +08004398void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4399{
4400 UNIMPLEMENTED();
4401}
4402
Jamie Madillc20ab272016-06-09 07:20:46 -07004403void Context::activeTexture(GLenum texture)
4404{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004405 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004406}
4407
Jamie Madill876429b2017-04-20 15:46:24 -04004408void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004409{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004410 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004411}
4412
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004413void Context::blendEquation(GLenum mode)
4414{
4415 mGLState.setBlendEquation(mode, mode);
4416}
4417
Jamie Madillc20ab272016-06-09 07:20:46 -07004418void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4419{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004420 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004421}
4422
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004423void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4424{
4425 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4426}
4427
Jamie Madillc20ab272016-06-09 07:20:46 -07004428void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4429{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004430 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004431}
4432
Jamie Madill876429b2017-04-20 15:46:24 -04004433void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004434{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004435 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004436}
4437
Jamie Madill876429b2017-04-20 15:46:24 -04004438void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004439{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004440 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004441}
4442
4443void Context::clearStencil(GLint s)
4444{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004445 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004446}
4447
4448void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4449{
Geoff Lang92019432017-11-20 13:09:34 -05004450 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4451 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004452}
4453
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004454void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004455{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004456 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004457}
4458
4459void Context::depthFunc(GLenum func)
4460{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004461 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004462}
4463
4464void Context::depthMask(GLboolean flag)
4465{
Geoff Lang92019432017-11-20 13:09:34 -05004466 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004467}
4468
Jamie Madill876429b2017-04-20 15:46:24 -04004469void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004470{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004471 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004472}
4473
4474void Context::disable(GLenum cap)
4475{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004476 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004477 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004478}
4479
4480void Context::disableVertexAttribArray(GLuint index)
4481{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004482 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004483 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004484}
4485
4486void Context::enable(GLenum cap)
4487{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004488 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004489 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004490}
4491
4492void Context::enableVertexAttribArray(GLuint index)
4493{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004494 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004495 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004496}
4497
4498void Context::frontFace(GLenum mode)
4499{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004500 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004501}
4502
4503void Context::hint(GLenum target, GLenum mode)
4504{
4505 switch (target)
4506 {
4507 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004508 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004509 break;
4510
4511 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004512 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004513 break;
4514
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004515 case GL_PERSPECTIVE_CORRECTION_HINT:
4516 case GL_POINT_SMOOTH_HINT:
4517 case GL_LINE_SMOOTH_HINT:
4518 case GL_FOG_HINT:
4519 mGLState.gles1().setHint(target, mode);
4520 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004521 default:
4522 UNREACHABLE();
4523 return;
4524 }
4525}
4526
4527void Context::lineWidth(GLfloat width)
4528{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004529 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004530}
4531
4532void Context::pixelStorei(GLenum pname, GLint param)
4533{
4534 switch (pname)
4535 {
4536 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004537 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004538 break;
4539
4540 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004541 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004542 break;
4543
4544 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004545 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004546 break;
4547
4548 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004549 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004550 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004551 break;
4552
4553 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004554 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004555 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004556 break;
4557
4558 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004559 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004560 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004561 break;
4562
4563 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004564 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004565 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004566 break;
4567
4568 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004569 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004570 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004571 break;
4572
4573 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004574 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004575 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004576 break;
4577
4578 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004579 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004580 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004581 break;
4582
4583 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004584 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004585 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004586 break;
4587
4588 default:
4589 UNREACHABLE();
4590 return;
4591 }
4592}
4593
4594void Context::polygonOffset(GLfloat factor, GLfloat units)
4595{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004596 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004597}
4598
Jamie Madill876429b2017-04-20 15:46:24 -04004599void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004600{
Geoff Lang92019432017-11-20 13:09:34 -05004601 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004602}
4603
Jiawei Shaodb342272017-09-27 10:21:45 +08004604void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4605{
4606 mGLState.setSampleMaskParams(maskNumber, mask);
4607}
4608
Jamie Madillc20ab272016-06-09 07:20:46 -07004609void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4610{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004611 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004612}
4613
4614void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4615{
4616 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4617 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004618 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004619 }
4620
4621 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4622 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004623 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004624 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004625
4626 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004627}
4628
4629void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4630{
4631 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4632 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004633 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004634 }
4635
4636 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4637 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004638 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004639 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004640
4641 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004642}
4643
4644void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4645{
4646 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4647 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004648 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004649 }
4650
4651 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4652 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004653 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004654 }
4655}
4656
4657void Context::vertexAttrib1f(GLuint index, GLfloat x)
4658{
4659 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004660 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004661 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004662}
4663
4664void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4665{
4666 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004667 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004668 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004669}
4670
4671void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4672{
4673 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004674 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004675 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004676}
4677
4678void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4679{
4680 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004681 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004682 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004683}
4684
4685void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4686{
4687 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004688 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004689 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004690}
4691
4692void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4693{
4694 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004695 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004696 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004697}
4698
4699void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4700{
4701 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004702 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004703 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004704}
4705
4706void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4707{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004708 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004709 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004710}
4711
4712void Context::vertexAttribPointer(GLuint index,
4713 GLint size,
4714 GLenum type,
4715 GLboolean normalized,
4716 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004717 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004718{
Corentin Wallez336129f2017-10-17 15:55:40 -04004719 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004720 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004721 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004722}
4723
Shao80957d92017-02-20 21:25:59 +08004724void Context::vertexAttribFormat(GLuint attribIndex,
4725 GLint size,
4726 GLenum type,
4727 GLboolean normalized,
4728 GLuint relativeOffset)
4729{
Geoff Lang92019432017-11-20 13:09:34 -05004730 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004731 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004732 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004733}
4734
4735void Context::vertexAttribIFormat(GLuint attribIndex,
4736 GLint size,
4737 GLenum type,
4738 GLuint relativeOffset)
4739{
4740 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004741 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004742}
4743
4744void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4745{
Shaodde78e82017-05-22 14:13:27 +08004746 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004747 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004748}
4749
Jiajia Qin5451d532017-11-16 17:16:34 +08004750void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004751{
4752 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004753 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004754}
4755
Jamie Madillc20ab272016-06-09 07:20:46 -07004756void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4757{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004758 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004759}
4760
4761void Context::vertexAttribIPointer(GLuint index,
4762 GLint size,
4763 GLenum type,
4764 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004765 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004766{
Corentin Wallez336129f2017-10-17 15:55:40 -04004767 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4768 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004769 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004770}
4771
4772void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4773{
4774 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004775 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004776 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004777}
4778
4779void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4780{
4781 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004782 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004783 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004784}
4785
4786void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4787{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004788 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004789 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004790}
4791
4792void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4793{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004794 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004795 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004796}
4797
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004798void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4799{
4800 const VertexAttribCurrentValueData &currentValues =
4801 getGLState().getVertexAttribCurrentValue(index);
4802 const VertexArray *vao = getGLState().getVertexArray();
4803 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4804 currentValues, pname, params);
4805}
4806
Brandon Jones59770802018-04-02 13:18:42 -07004807void Context::getVertexAttribivRobust(GLuint index,
4808 GLenum pname,
4809 GLsizei bufSize,
4810 GLsizei *length,
4811 GLint *params)
4812{
4813 getVertexAttribiv(index, pname, params);
4814}
4815
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004816void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4817{
4818 const VertexAttribCurrentValueData &currentValues =
4819 getGLState().getVertexAttribCurrentValue(index);
4820 const VertexArray *vao = getGLState().getVertexArray();
4821 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4822 currentValues, pname, params);
4823}
4824
Brandon Jones59770802018-04-02 13:18:42 -07004825void Context::getVertexAttribfvRobust(GLuint index,
4826 GLenum pname,
4827 GLsizei bufSize,
4828 GLsizei *length,
4829 GLfloat *params)
4830{
4831 getVertexAttribfv(index, pname, params);
4832}
4833
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004834void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4835{
4836 const VertexAttribCurrentValueData &currentValues =
4837 getGLState().getVertexAttribCurrentValue(index);
4838 const VertexArray *vao = getGLState().getVertexArray();
4839 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4840 currentValues, pname, params);
4841}
4842
Brandon Jones59770802018-04-02 13:18:42 -07004843void Context::getVertexAttribIivRobust(GLuint index,
4844 GLenum pname,
4845 GLsizei bufSize,
4846 GLsizei *length,
4847 GLint *params)
4848{
4849 getVertexAttribIiv(index, pname, params);
4850}
4851
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004852void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4853{
4854 const VertexAttribCurrentValueData &currentValues =
4855 getGLState().getVertexAttribCurrentValue(index);
4856 const VertexArray *vao = getGLState().getVertexArray();
4857 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4858 currentValues, pname, params);
4859}
4860
Brandon Jones59770802018-04-02 13:18:42 -07004861void Context::getVertexAttribIuivRobust(GLuint index,
4862 GLenum pname,
4863 GLsizei bufSize,
4864 GLsizei *length,
4865 GLuint *params)
4866{
4867 getVertexAttribIuiv(index, pname, params);
4868}
4869
Jamie Madill876429b2017-04-20 15:46:24 -04004870void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004871{
4872 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4873 QueryVertexAttribPointerv(attrib, pname, pointer);
4874}
4875
Brandon Jones59770802018-04-02 13:18:42 -07004876void Context::getVertexAttribPointervRobust(GLuint index,
4877 GLenum pname,
4878 GLsizei bufSize,
4879 GLsizei *length,
4880 void **pointer)
4881{
4882 getVertexAttribPointerv(index, pname, pointer);
4883}
4884
Jamie Madillc20ab272016-06-09 07:20:46 -07004885void Context::debugMessageControl(GLenum source,
4886 GLenum type,
4887 GLenum severity,
4888 GLsizei count,
4889 const GLuint *ids,
4890 GLboolean enabled)
4891{
4892 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004893 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004894 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004895}
4896
4897void Context::debugMessageInsert(GLenum source,
4898 GLenum type,
4899 GLuint id,
4900 GLenum severity,
4901 GLsizei length,
4902 const GLchar *buf)
4903{
4904 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004905 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004906}
4907
4908void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4909{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004910 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004911}
4912
4913GLuint Context::getDebugMessageLog(GLuint count,
4914 GLsizei bufSize,
4915 GLenum *sources,
4916 GLenum *types,
4917 GLuint *ids,
4918 GLenum *severities,
4919 GLsizei *lengths,
4920 GLchar *messageLog)
4921{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004922 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4923 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004924}
4925
4926void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4927{
4928 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004929 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004930 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004931}
4932
4933void Context::popDebugGroup()
4934{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004935 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004936 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004937}
4938
Corentin Wallez336129f2017-10-17 15:55:40 -04004939void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004940{
4941 Buffer *buffer = mGLState.getTargetBuffer(target);
4942 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004943 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004944}
4945
Corentin Wallez336129f2017-10-17 15:55:40 -04004946void Context::bufferSubData(BufferBinding target,
4947 GLintptr offset,
4948 GLsizeiptr size,
4949 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004950{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06004951 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04004952 {
4953 return;
4954 }
4955
4956 Buffer *buffer = mGLState.getTargetBuffer(target);
4957 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004958 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004959}
4960
Jamie Madillef300b12016-10-07 15:12:09 -04004961void Context::attachShader(GLuint program, GLuint shader)
4962{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004963 Program *programObject = mState.mShaderPrograms->getProgram(program);
4964 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004965 ASSERT(programObject && shaderObject);
4966 programObject->attachShader(shaderObject);
4967}
4968
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004969const Workarounds &Context::getWorkarounds() const
4970{
4971 return mWorkarounds;
4972}
4973
Corentin Wallez336129f2017-10-17 15:55:40 -04004974void Context::copyBufferSubData(BufferBinding readTarget,
4975 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004976 GLintptr readOffset,
4977 GLintptr writeOffset,
4978 GLsizeiptr size)
4979{
4980 // if size is zero, the copy is a successful no-op
4981 if (size == 0)
4982 {
4983 return;
4984 }
4985
4986 // TODO(jmadill): cache these.
4987 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4988 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4989
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004990 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004991}
4992
Jamie Madill01a80ee2016-11-07 12:06:18 -05004993void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4994{
4995 Program *programObject = getProgram(program);
4996 // TODO(jmadill): Re-use this from the validation if possible.
4997 ASSERT(programObject);
4998 programObject->bindAttributeLocation(index, name);
4999}
5000
Corentin Wallez336129f2017-10-17 15:55:40 -04005001void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05005002{
Corentin Wallez336129f2017-10-17 15:55:40 -04005003 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5004 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04005005 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005006}
5007
Corentin Wallez336129f2017-10-17 15:55:40 -04005008void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005009{
5010 bindBufferRange(target, index, buffer, 0, 0);
5011}
5012
Corentin Wallez336129f2017-10-17 15:55:40 -04005013void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005014 GLuint index,
5015 GLuint buffer,
5016 GLintptr offset,
5017 GLsizeiptr size)
5018{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005019 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5020 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
5021 if (target == BufferBinding::Uniform)
5022 {
5023 mUniformBufferObserverBindings[index].bind(object ? object->getImplementation() : nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04005024 mStateCache.onUniformBufferStateChange(this);
5025 }
5026 else
5027 {
5028 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005029 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005030}
5031
Jamie Madill01a80ee2016-11-07 12:06:18 -05005032void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5033{
5034 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5035 {
5036 bindReadFramebuffer(framebuffer);
5037 }
5038
5039 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5040 {
5041 bindDrawFramebuffer(framebuffer);
5042 }
5043}
5044
5045void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5046{
5047 ASSERT(target == GL_RENDERBUFFER);
5048 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005049 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005050 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005051}
5052
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005053void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005054 GLsizei samples,
5055 GLenum internalformat,
5056 GLsizei width,
5057 GLsizei height,
5058 GLboolean fixedsamplelocations)
5059{
5060 Extents size(width, height, 1);
5061 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005062 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5063 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005064}
5065
Olli Etuaho89664842018-08-24 14:45:36 +03005066void Context::texStorage3DMultisample(TextureType target,
5067 GLsizei samples,
5068 GLenum internalformat,
5069 GLsizei width,
5070 GLsizei height,
5071 GLsizei depth,
5072 GLboolean fixedsamplelocations)
5073{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005074 Extents size(width, height, depth);
5075 Texture *texture = getTargetTexture(target);
5076 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5077 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005078}
5079
JiangYizhoubddc46b2016-12-09 09:50:51 +08005080void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5081{
JiangYizhou5b03f472017-01-09 10:22:53 +08005082 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5083 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005084 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005085 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005086
5087 switch (pname)
5088 {
5089 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04005090 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005091 break;
5092 default:
5093 UNREACHABLE();
5094 }
5095}
5096
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005097void Context::getMultisamplefvRobust(GLenum pname,
5098 GLuint index,
5099 GLsizei bufSize,
5100 GLsizei *length,
5101 GLfloat *val)
5102{
5103 UNIMPLEMENTED();
5104}
5105
Jamie Madille8fb6402017-02-14 17:56:40 -05005106void Context::renderbufferStorage(GLenum target,
5107 GLenum internalformat,
5108 GLsizei width,
5109 GLsizei height)
5110{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005111 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5112 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5113
Jamie Madille8fb6402017-02-14 17:56:40 -05005114 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04005115 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005116}
5117
5118void Context::renderbufferStorageMultisample(GLenum target,
5119 GLsizei samples,
5120 GLenum internalformat,
5121 GLsizei width,
5122 GLsizei height)
5123{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005124 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5125 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005126
5127 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005128 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005129 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005130}
5131
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005132void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5133{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005134 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04005135 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005136}
5137
JiangYizhoue18e6392017-02-20 10:32:23 +08005138void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5139{
5140 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5141 QueryFramebufferParameteriv(framebuffer, pname, params);
5142}
5143
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005144void Context::getFramebufferParameterivRobust(GLenum target,
5145 GLenum pname,
5146 GLsizei bufSize,
5147 GLsizei *length,
5148 GLint *params)
5149{
5150 UNIMPLEMENTED();
5151}
5152
Jiajia Qin5451d532017-11-16 17:16:34 +08005153void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005154{
5155 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005156 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005157}
5158
Jamie Madilldec86232018-07-11 09:01:18 -04005159bool Context::getScratchBuffer(size_t requstedSizeBytes,
5160 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005161{
Jamie Madilldec86232018-07-11 09:01:18 -04005162 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005163}
5164
Jamie Madilldec86232018-07-11 09:01:18 -04005165bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5166 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005167{
Jamie Madilldec86232018-07-11 09:01:18 -04005168 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005169}
5170
Xinghua Cao10a4d432017-11-28 14:46:26 +08005171Error Context::prepareForDispatch()
5172{
Geoff Langa8cb2872018-03-09 16:09:40 -05005173 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005174
5175 if (isRobustResourceInitEnabled())
5176 {
5177 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5178 }
5179
5180 return NoError();
5181}
5182
Xinghua Cao2b396592017-03-29 15:36:04 +08005183void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5184{
5185 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5186 {
5187 return;
5188 }
5189
Xinghua Cao10a4d432017-11-28 14:46:26 +08005190 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005191 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005192}
5193
Jiajia Qin5451d532017-11-16 17:16:34 +08005194void Context::dispatchComputeIndirect(GLintptr indirect)
5195{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005196 ANGLE_CONTEXT_TRY(prepareForDispatch());
5197 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005198}
5199
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005200void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005201 GLsizei levels,
5202 GLenum internalFormat,
5203 GLsizei width,
5204 GLsizei height)
5205{
5206 Extents size(width, height, 1);
5207 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005208 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005209}
5210
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005211void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005212 GLsizei levels,
5213 GLenum internalFormat,
5214 GLsizei width,
5215 GLsizei height,
5216 GLsizei depth)
5217{
5218 Extents size(width, height, depth);
5219 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005220 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005221}
5222
Jiajia Qin5451d532017-11-16 17:16:34 +08005223void Context::memoryBarrier(GLbitfield barriers)
5224{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005225 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005226}
5227
5228void Context::memoryBarrierByRegion(GLbitfield barriers)
5229{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005230 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005231}
5232
Jamie Madillc1d770e2017-04-13 17:31:24 -04005233GLenum Context::checkFramebufferStatus(GLenum target)
5234{
5235 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5236 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005237 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005238}
5239
5240void Context::compileShader(GLuint shader)
5241{
5242 Shader *shaderObject = GetValidShader(this, shader);
5243 if (!shaderObject)
5244 {
5245 return;
5246 }
5247 shaderObject->compile(this);
5248}
5249
5250void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5251{
5252 for (int i = 0; i < n; i++)
5253 {
5254 deleteBuffer(buffers[i]);
5255 }
5256}
5257
5258void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5259{
5260 for (int i = 0; i < n; i++)
5261 {
5262 if (framebuffers[i] != 0)
5263 {
5264 deleteFramebuffer(framebuffers[i]);
5265 }
5266 }
5267}
5268
5269void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5270{
5271 for (int i = 0; i < n; i++)
5272 {
5273 deleteRenderbuffer(renderbuffers[i]);
5274 }
5275}
5276
5277void Context::deleteTextures(GLsizei n, const GLuint *textures)
5278{
5279 for (int i = 0; i < n; i++)
5280 {
5281 if (textures[i] != 0)
5282 {
5283 deleteTexture(textures[i]);
5284 }
5285 }
5286}
5287
5288void Context::detachShader(GLuint program, GLuint shader)
5289{
5290 Program *programObject = getProgram(program);
5291 ASSERT(programObject);
5292
5293 Shader *shaderObject = getShader(shader);
5294 ASSERT(shaderObject);
5295
5296 programObject->detachShader(this, shaderObject);
5297}
5298
5299void Context::genBuffers(GLsizei n, GLuint *buffers)
5300{
5301 for (int i = 0; i < n; i++)
5302 {
5303 buffers[i] = createBuffer();
5304 }
5305}
5306
5307void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5308{
5309 for (int i = 0; i < n; i++)
5310 {
5311 framebuffers[i] = createFramebuffer();
5312 }
5313}
5314
5315void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5316{
5317 for (int i = 0; i < n; i++)
5318 {
5319 renderbuffers[i] = createRenderbuffer();
5320 }
5321}
5322
5323void Context::genTextures(GLsizei n, GLuint *textures)
5324{
5325 for (int i = 0; i < n; i++)
5326 {
5327 textures[i] = createTexture();
5328 }
5329}
5330
5331void Context::getActiveAttrib(GLuint program,
5332 GLuint index,
5333 GLsizei bufsize,
5334 GLsizei *length,
5335 GLint *size,
5336 GLenum *type,
5337 GLchar *name)
5338{
5339 Program *programObject = getProgram(program);
5340 ASSERT(programObject);
5341 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5342}
5343
5344void Context::getActiveUniform(GLuint program,
5345 GLuint index,
5346 GLsizei bufsize,
5347 GLsizei *length,
5348 GLint *size,
5349 GLenum *type,
5350 GLchar *name)
5351{
5352 Program *programObject = getProgram(program);
5353 ASSERT(programObject);
5354 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5355}
5356
5357void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5358{
5359 Program *programObject = getProgram(program);
5360 ASSERT(programObject);
5361 programObject->getAttachedShaders(maxcount, count, shaders);
5362}
5363
5364GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5365{
5366 Program *programObject = getProgram(program);
5367 ASSERT(programObject);
5368 return programObject->getAttributeLocation(name);
5369}
5370
5371void Context::getBooleanv(GLenum pname, GLboolean *params)
5372{
5373 GLenum nativeType;
5374 unsigned int numParams = 0;
5375 getQueryParameterInfo(pname, &nativeType, &numParams);
5376
5377 if (nativeType == GL_BOOL)
5378 {
5379 getBooleanvImpl(pname, params);
5380 }
5381 else
5382 {
5383 CastStateValues(this, nativeType, pname, numParams, params);
5384 }
5385}
5386
Brandon Jones59770802018-04-02 13:18:42 -07005387void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5388{
5389 getBooleanv(pname, params);
5390}
5391
Jamie Madillc1d770e2017-04-13 17:31:24 -04005392void Context::getFloatv(GLenum pname, GLfloat *params)
5393{
5394 GLenum nativeType;
5395 unsigned int numParams = 0;
5396 getQueryParameterInfo(pname, &nativeType, &numParams);
5397
5398 if (nativeType == GL_FLOAT)
5399 {
5400 getFloatvImpl(pname, params);
5401 }
5402 else
5403 {
5404 CastStateValues(this, nativeType, pname, numParams, params);
5405 }
5406}
5407
Brandon Jones59770802018-04-02 13:18:42 -07005408void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5409{
5410 getFloatv(pname, params);
5411}
5412
Jamie Madillc1d770e2017-04-13 17:31:24 -04005413void Context::getIntegerv(GLenum pname, GLint *params)
5414{
5415 GLenum nativeType;
5416 unsigned int numParams = 0;
5417 getQueryParameterInfo(pname, &nativeType, &numParams);
5418
5419 if (nativeType == GL_INT)
5420 {
5421 getIntegervImpl(pname, params);
5422 }
5423 else
5424 {
5425 CastStateValues(this, nativeType, pname, numParams, params);
5426 }
5427}
5428
Brandon Jones59770802018-04-02 13:18:42 -07005429void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5430{
5431 getIntegerv(pname, data);
5432}
5433
Jamie Madillc1d770e2017-04-13 17:31:24 -04005434void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5435{
5436 Program *programObject = getProgram(program);
5437 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005438 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005439}
5440
Brandon Jones59770802018-04-02 13:18:42 -07005441void Context::getProgramivRobust(GLuint program,
5442 GLenum pname,
5443 GLsizei bufSize,
5444 GLsizei *length,
5445 GLint *params)
5446{
5447 getProgramiv(program, pname, params);
5448}
5449
Jiajia Qin5451d532017-11-16 17:16:34 +08005450void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5451{
5452 UNIMPLEMENTED();
5453}
5454
Jamie Madillbe849e42017-05-02 15:49:00 -04005455void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005456{
5457 Program *programObject = getProgram(program);
5458 ASSERT(programObject);
5459 programObject->getInfoLog(bufsize, length, infolog);
5460}
5461
Jiajia Qin5451d532017-11-16 17:16:34 +08005462void Context::getProgramPipelineInfoLog(GLuint pipeline,
5463 GLsizei bufSize,
5464 GLsizei *length,
5465 GLchar *infoLog)
5466{
5467 UNIMPLEMENTED();
5468}
5469
Jamie Madillc1d770e2017-04-13 17:31:24 -04005470void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5471{
5472 Shader *shaderObject = getShader(shader);
5473 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005474 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005475}
5476
Brandon Jones59770802018-04-02 13:18:42 -07005477void Context::getShaderivRobust(GLuint shader,
5478 GLenum pname,
5479 GLsizei bufSize,
5480 GLsizei *length,
5481 GLint *params)
5482{
5483 getShaderiv(shader, pname, params);
5484}
5485
Jamie Madillc1d770e2017-04-13 17:31:24 -04005486void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5487{
5488 Shader *shaderObject = getShader(shader);
5489 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005490 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005491}
5492
5493void Context::getShaderPrecisionFormat(GLenum shadertype,
5494 GLenum precisiontype,
5495 GLint *range,
5496 GLint *precision)
5497{
5498 // TODO(jmadill): Compute shaders.
5499
5500 switch (shadertype)
5501 {
5502 case GL_VERTEX_SHADER:
5503 switch (precisiontype)
5504 {
5505 case GL_LOW_FLOAT:
5506 mCaps.vertexLowpFloat.get(range, precision);
5507 break;
5508 case GL_MEDIUM_FLOAT:
5509 mCaps.vertexMediumpFloat.get(range, precision);
5510 break;
5511 case GL_HIGH_FLOAT:
5512 mCaps.vertexHighpFloat.get(range, precision);
5513 break;
5514
5515 case GL_LOW_INT:
5516 mCaps.vertexLowpInt.get(range, precision);
5517 break;
5518 case GL_MEDIUM_INT:
5519 mCaps.vertexMediumpInt.get(range, precision);
5520 break;
5521 case GL_HIGH_INT:
5522 mCaps.vertexHighpInt.get(range, precision);
5523 break;
5524
5525 default:
5526 UNREACHABLE();
5527 return;
5528 }
5529 break;
5530
5531 case GL_FRAGMENT_SHADER:
5532 switch (precisiontype)
5533 {
5534 case GL_LOW_FLOAT:
5535 mCaps.fragmentLowpFloat.get(range, precision);
5536 break;
5537 case GL_MEDIUM_FLOAT:
5538 mCaps.fragmentMediumpFloat.get(range, precision);
5539 break;
5540 case GL_HIGH_FLOAT:
5541 mCaps.fragmentHighpFloat.get(range, precision);
5542 break;
5543
5544 case GL_LOW_INT:
5545 mCaps.fragmentLowpInt.get(range, precision);
5546 break;
5547 case GL_MEDIUM_INT:
5548 mCaps.fragmentMediumpInt.get(range, precision);
5549 break;
5550 case GL_HIGH_INT:
5551 mCaps.fragmentHighpInt.get(range, precision);
5552 break;
5553
5554 default:
5555 UNREACHABLE();
5556 return;
5557 }
5558 break;
5559
5560 default:
5561 UNREACHABLE();
5562 return;
5563 }
5564}
5565
5566void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5567{
5568 Shader *shaderObject = getShader(shader);
5569 ASSERT(shaderObject);
5570 shaderObject->getSource(bufsize, length, source);
5571}
5572
5573void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5574{
5575 Program *programObject = getProgram(program);
5576 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005577 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005578}
5579
Brandon Jones59770802018-04-02 13:18:42 -07005580void Context::getUniformfvRobust(GLuint program,
5581 GLint location,
5582 GLsizei bufSize,
5583 GLsizei *length,
5584 GLfloat *params)
5585{
5586 getUniformfv(program, location, params);
5587}
5588
Jamie Madillc1d770e2017-04-13 17:31:24 -04005589void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5590{
5591 Program *programObject = getProgram(program);
5592 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005593 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005594}
5595
Brandon Jones59770802018-04-02 13:18:42 -07005596void Context::getUniformivRobust(GLuint program,
5597 GLint location,
5598 GLsizei bufSize,
5599 GLsizei *length,
5600 GLint *params)
5601{
5602 getUniformiv(program, location, params);
5603}
5604
Jamie Madillc1d770e2017-04-13 17:31:24 -04005605GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5606{
5607 Program *programObject = getProgram(program);
5608 ASSERT(programObject);
5609 return programObject->getUniformLocation(name);
5610}
5611
5612GLboolean Context::isBuffer(GLuint buffer)
5613{
5614 if (buffer == 0)
5615 {
5616 return GL_FALSE;
5617 }
5618
5619 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5620}
5621
5622GLboolean Context::isEnabled(GLenum cap)
5623{
5624 return mGLState.getEnableFeature(cap);
5625}
5626
5627GLboolean Context::isFramebuffer(GLuint framebuffer)
5628{
5629 if (framebuffer == 0)
5630 {
5631 return GL_FALSE;
5632 }
5633
5634 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5635}
5636
5637GLboolean Context::isProgram(GLuint program)
5638{
5639 if (program == 0)
5640 {
5641 return GL_FALSE;
5642 }
5643
5644 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5645}
5646
5647GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5648{
5649 if (renderbuffer == 0)
5650 {
5651 return GL_FALSE;
5652 }
5653
5654 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5655}
5656
5657GLboolean Context::isShader(GLuint shader)
5658{
5659 if (shader == 0)
5660 {
5661 return GL_FALSE;
5662 }
5663
5664 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5665}
5666
5667GLboolean Context::isTexture(GLuint texture)
5668{
5669 if (texture == 0)
5670 {
5671 return GL_FALSE;
5672 }
5673
5674 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5675}
5676
5677void Context::linkProgram(GLuint program)
5678{
5679 Program *programObject = getProgram(program);
5680 ASSERT(programObject);
5681 handleError(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005682
5683 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5684 // don't need to worry that:
5685 // 1. Draw calls after link use the new executable code or the old one depending on the link
5686 // result.
5687 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5688 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5689 // ProgramD3D.
5690 if (programObject->isInUse())
5691 {
5692 // isLinked() which forces to resolve linking, will be called.
5693 mGLState.onProgramExecutableChange(programObject);
5694 mStateCache.onProgramExecutableChange(this);
5695 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005696}
5697
5698void Context::releaseShaderCompiler()
5699{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005700 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005701}
5702
5703void Context::shaderBinary(GLsizei n,
5704 const GLuint *shaders,
5705 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005706 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005707 GLsizei length)
5708{
5709 // No binary shader formats are supported.
5710 UNIMPLEMENTED();
5711}
5712
5713void Context::shaderSource(GLuint shader,
5714 GLsizei count,
5715 const GLchar *const *string,
5716 const GLint *length)
5717{
5718 Shader *shaderObject = getShader(shader);
5719 ASSERT(shaderObject);
5720 shaderObject->setSource(count, string, length);
5721}
5722
5723void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5724{
5725 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5726}
5727
5728void Context::stencilMask(GLuint mask)
5729{
5730 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5731}
5732
5733void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5734{
5735 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5736}
5737
5738void Context::uniform1f(GLint location, GLfloat x)
5739{
5740 Program *program = mGLState.getProgram();
5741 program->setUniform1fv(location, 1, &x);
5742}
5743
5744void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5745{
5746 Program *program = mGLState.getProgram();
5747 program->setUniform1fv(location, count, v);
5748}
5749
Jamie Madill7e4eff12018-08-08 15:49:26 -04005750void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005751{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005752 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04005753 {
5754 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04005755 mStateCache.onActiveTextureChange(this);
Jamie Madill81c2e252017-09-09 23:32:46 -04005756 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005757}
5758
Jamie Madill7e4eff12018-08-08 15:49:26 -04005759void Context::uniform1i(GLint location, GLint x)
5760{
5761 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
5762}
5763
Jamie Madillc1d770e2017-04-13 17:31:24 -04005764void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5765{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005766 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005767}
5768
5769void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5770{
5771 GLfloat xy[2] = {x, y};
5772 Program *program = mGLState.getProgram();
5773 program->setUniform2fv(location, 1, xy);
5774}
5775
5776void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5777{
5778 Program *program = mGLState.getProgram();
5779 program->setUniform2fv(location, count, v);
5780}
5781
5782void Context::uniform2i(GLint location, GLint x, GLint y)
5783{
5784 GLint xy[2] = {x, y};
5785 Program *program = mGLState.getProgram();
5786 program->setUniform2iv(location, 1, xy);
5787}
5788
5789void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5790{
5791 Program *program = mGLState.getProgram();
5792 program->setUniform2iv(location, count, v);
5793}
5794
5795void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5796{
5797 GLfloat xyz[3] = {x, y, z};
5798 Program *program = mGLState.getProgram();
5799 program->setUniform3fv(location, 1, xyz);
5800}
5801
5802void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5803{
5804 Program *program = mGLState.getProgram();
5805 program->setUniform3fv(location, count, v);
5806}
5807
5808void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5809{
5810 GLint xyz[3] = {x, y, z};
5811 Program *program = mGLState.getProgram();
5812 program->setUniform3iv(location, 1, xyz);
5813}
5814
5815void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5816{
5817 Program *program = mGLState.getProgram();
5818 program->setUniform3iv(location, count, v);
5819}
5820
5821void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5822{
5823 GLfloat xyzw[4] = {x, y, z, w};
5824 Program *program = mGLState.getProgram();
5825 program->setUniform4fv(location, 1, xyzw);
5826}
5827
5828void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5829{
5830 Program *program = mGLState.getProgram();
5831 program->setUniform4fv(location, count, v);
5832}
5833
5834void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5835{
5836 GLint xyzw[4] = {x, y, z, w};
5837 Program *program = mGLState.getProgram();
5838 program->setUniform4iv(location, 1, xyzw);
5839}
5840
5841void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5842{
5843 Program *program = mGLState.getProgram();
5844 program->setUniform4iv(location, count, v);
5845}
5846
5847void Context::uniformMatrix2fv(GLint location,
5848 GLsizei count,
5849 GLboolean transpose,
5850 const GLfloat *value)
5851{
5852 Program *program = mGLState.getProgram();
5853 program->setUniformMatrix2fv(location, count, transpose, value);
5854}
5855
5856void Context::uniformMatrix3fv(GLint location,
5857 GLsizei count,
5858 GLboolean transpose,
5859 const GLfloat *value)
5860{
5861 Program *program = mGLState.getProgram();
5862 program->setUniformMatrix3fv(location, count, transpose, value);
5863}
5864
5865void Context::uniformMatrix4fv(GLint location,
5866 GLsizei count,
5867 GLboolean transpose,
5868 const GLfloat *value)
5869{
5870 Program *program = mGLState.getProgram();
5871 program->setUniformMatrix4fv(location, count, transpose, value);
5872}
5873
5874void Context::validateProgram(GLuint program)
5875{
5876 Program *programObject = getProgram(program);
5877 ASSERT(programObject);
5878 programObject->validate(mCaps);
5879}
5880
Jiajia Qin5451d532017-11-16 17:16:34 +08005881void Context::validateProgramPipeline(GLuint pipeline)
5882{
5883 UNIMPLEMENTED();
5884}
5885
Jamie Madilld04908b2017-06-09 14:15:35 -04005886void Context::getProgramBinary(GLuint program,
5887 GLsizei bufSize,
5888 GLsizei *length,
5889 GLenum *binaryFormat,
5890 void *binary)
5891{
5892 Program *programObject = getProgram(program);
5893 ASSERT(programObject != nullptr);
5894
5895 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5896}
5897
5898void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5899{
5900 Program *programObject = getProgram(program);
5901 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005902
Jamie Madilld04908b2017-06-09 14:15:35 -04005903 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madillc43cdad2018-08-08 15:49:25 -04005904 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04005905 if (programObject->isInUse())
5906 {
5907 mGLState.setObjectDirty(GL_PROGRAM);
5908 }
Jamie Madilld04908b2017-06-09 14:15:35 -04005909}
5910
Jamie Madillff325f12017-08-26 15:06:05 -04005911void Context::uniform1ui(GLint location, GLuint v0)
5912{
5913 Program *program = mGLState.getProgram();
5914 program->setUniform1uiv(location, 1, &v0);
5915}
5916
5917void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5918{
5919 Program *program = mGLState.getProgram();
5920 const GLuint xy[] = {v0, v1};
5921 program->setUniform2uiv(location, 1, xy);
5922}
5923
5924void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5925{
5926 Program *program = mGLState.getProgram();
5927 const GLuint xyz[] = {v0, v1, v2};
5928 program->setUniform3uiv(location, 1, xyz);
5929}
5930
5931void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5932{
5933 Program *program = mGLState.getProgram();
5934 const GLuint xyzw[] = {v0, v1, v2, v3};
5935 program->setUniform4uiv(location, 1, xyzw);
5936}
5937
5938void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5939{
5940 Program *program = mGLState.getProgram();
5941 program->setUniform1uiv(location, count, value);
5942}
5943void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5944{
5945 Program *program = mGLState.getProgram();
5946 program->setUniform2uiv(location, count, value);
5947}
5948
5949void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5950{
5951 Program *program = mGLState.getProgram();
5952 program->setUniform3uiv(location, count, value);
5953}
5954
5955void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5956{
5957 Program *program = mGLState.getProgram();
5958 program->setUniform4uiv(location, count, value);
5959}
5960
Jamie Madillf0e04492017-08-26 15:28:42 -04005961void Context::genQueries(GLsizei n, GLuint *ids)
5962{
5963 for (GLsizei i = 0; i < n; i++)
5964 {
5965 GLuint handle = mQueryHandleAllocator.allocate();
5966 mQueryMap.assign(handle, nullptr);
5967 ids[i] = handle;
5968 }
5969}
5970
5971void Context::deleteQueries(GLsizei n, const GLuint *ids)
5972{
5973 for (int i = 0; i < n; i++)
5974 {
5975 GLuint query = ids[i];
5976
5977 Query *queryObject = nullptr;
5978 if (mQueryMap.erase(query, &queryObject))
5979 {
5980 mQueryHandleAllocator.release(query);
5981 if (queryObject)
5982 {
5983 queryObject->release(this);
5984 }
5985 }
5986 }
5987}
5988
5989GLboolean Context::isQuery(GLuint id)
5990{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005991 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005992}
5993
Jamie Madillc8c95812017-08-26 18:40:09 -04005994void Context::uniformMatrix2x3fv(GLint location,
5995 GLsizei count,
5996 GLboolean transpose,
5997 const GLfloat *value)
5998{
5999 Program *program = mGLState.getProgram();
6000 program->setUniformMatrix2x3fv(location, count, transpose, value);
6001}
6002
6003void Context::uniformMatrix3x2fv(GLint location,
6004 GLsizei count,
6005 GLboolean transpose,
6006 const GLfloat *value)
6007{
6008 Program *program = mGLState.getProgram();
6009 program->setUniformMatrix3x2fv(location, count, transpose, value);
6010}
6011
6012void Context::uniformMatrix2x4fv(GLint location,
6013 GLsizei count,
6014 GLboolean transpose,
6015 const GLfloat *value)
6016{
6017 Program *program = mGLState.getProgram();
6018 program->setUniformMatrix2x4fv(location, count, transpose, value);
6019}
6020
6021void Context::uniformMatrix4x2fv(GLint location,
6022 GLsizei count,
6023 GLboolean transpose,
6024 const GLfloat *value)
6025{
6026 Program *program = mGLState.getProgram();
6027 program->setUniformMatrix4x2fv(location, count, transpose, value);
6028}
6029
6030void Context::uniformMatrix3x4fv(GLint location,
6031 GLsizei count,
6032 GLboolean transpose,
6033 const GLfloat *value)
6034{
6035 Program *program = mGLState.getProgram();
6036 program->setUniformMatrix3x4fv(location, count, transpose, value);
6037}
6038
6039void Context::uniformMatrix4x3fv(GLint location,
6040 GLsizei count,
6041 GLboolean transpose,
6042 const GLfloat *value)
6043{
6044 Program *program = mGLState.getProgram();
6045 program->setUniformMatrix4x3fv(location, count, transpose, value);
6046}
6047
Jamie Madilld7576732017-08-26 18:49:50 -04006048void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6049{
6050 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6051 {
6052 GLuint vertexArray = arrays[arrayIndex];
6053
6054 if (arrays[arrayIndex] != 0)
6055 {
6056 VertexArray *vertexArrayObject = nullptr;
6057 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6058 {
6059 if (vertexArrayObject != nullptr)
6060 {
6061 detachVertexArray(vertexArray);
6062 vertexArrayObject->onDestroy(this);
6063 }
6064
6065 mVertexArrayHandleAllocator.release(vertexArray);
6066 }
6067 }
6068 }
6069}
6070
6071void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6072{
6073 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6074 {
6075 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6076 mVertexArrayMap.assign(vertexArray, nullptr);
6077 arrays[arrayIndex] = vertexArray;
6078 }
6079}
6080
6081bool Context::isVertexArray(GLuint array)
6082{
6083 if (array == 0)
6084 {
6085 return GL_FALSE;
6086 }
6087
6088 VertexArray *vao = getVertexArray(array);
6089 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6090}
6091
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006092void Context::endTransformFeedback()
6093{
6094 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6095 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006096 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006097}
6098
6099void Context::transformFeedbackVaryings(GLuint program,
6100 GLsizei count,
6101 const GLchar *const *varyings,
6102 GLenum bufferMode)
6103{
6104 Program *programObject = getProgram(program);
6105 ASSERT(programObject);
6106 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6107}
6108
6109void Context::getTransformFeedbackVarying(GLuint program,
6110 GLuint index,
6111 GLsizei bufSize,
6112 GLsizei *length,
6113 GLsizei *size,
6114 GLenum *type,
6115 GLchar *name)
6116{
6117 Program *programObject = getProgram(program);
6118 ASSERT(programObject);
6119 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6120}
6121
6122void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6123{
6124 for (int i = 0; i < n; i++)
6125 {
6126 GLuint transformFeedback = ids[i];
6127 if (transformFeedback == 0)
6128 {
6129 continue;
6130 }
6131
6132 TransformFeedback *transformFeedbackObject = nullptr;
6133 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6134 {
6135 if (transformFeedbackObject != nullptr)
6136 {
6137 detachTransformFeedback(transformFeedback);
6138 transformFeedbackObject->release(this);
6139 }
6140
6141 mTransformFeedbackHandleAllocator.release(transformFeedback);
6142 }
6143 }
6144}
6145
6146void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6147{
6148 for (int i = 0; i < n; i++)
6149 {
6150 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6151 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6152 ids[i] = transformFeedback;
6153 }
6154}
6155
6156bool Context::isTransformFeedback(GLuint id)
6157{
6158 if (id == 0)
6159 {
6160 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6161 // returns FALSE
6162 return GL_FALSE;
6163 }
6164
6165 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6166 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6167}
6168
6169void Context::pauseTransformFeedback()
6170{
6171 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6172 transformFeedback->pause();
6173}
6174
6175void Context::resumeTransformFeedback()
6176{
6177 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6178 transformFeedback->resume();
6179}
6180
Jamie Madill12e957f2017-08-26 21:42:26 -04006181void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6182{
6183 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006184 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006185}
6186
Brandon Jones59770802018-04-02 13:18:42 -07006187void Context::getUniformuivRobust(GLuint program,
6188 GLint location,
6189 GLsizei bufSize,
6190 GLsizei *length,
6191 GLuint *params)
6192{
6193 getUniformuiv(program, location, params);
6194}
6195
Jamie Madill12e957f2017-08-26 21:42:26 -04006196GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6197{
6198 const Program *programObject = getProgram(program);
6199 return programObject->getFragDataLocation(name);
6200}
6201
6202void Context::getUniformIndices(GLuint program,
6203 GLsizei uniformCount,
6204 const GLchar *const *uniformNames,
6205 GLuint *uniformIndices)
6206{
6207 const Program *programObject = getProgram(program);
6208 if (!programObject->isLinked())
6209 {
6210 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6211 {
6212 uniformIndices[uniformId] = GL_INVALID_INDEX;
6213 }
6214 }
6215 else
6216 {
6217 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6218 {
6219 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6220 }
6221 }
6222}
6223
6224void Context::getActiveUniformsiv(GLuint program,
6225 GLsizei uniformCount,
6226 const GLuint *uniformIndices,
6227 GLenum pname,
6228 GLint *params)
6229{
6230 const Program *programObject = getProgram(program);
6231 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6232 {
6233 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006234 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006235 }
6236}
6237
6238GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6239{
6240 const Program *programObject = getProgram(program);
6241 return programObject->getUniformBlockIndex(uniformBlockName);
6242}
6243
6244void Context::getActiveUniformBlockiv(GLuint program,
6245 GLuint uniformBlockIndex,
6246 GLenum pname,
6247 GLint *params)
6248{
6249 const Program *programObject = getProgram(program);
6250 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6251}
6252
Brandon Jones59770802018-04-02 13:18:42 -07006253void Context::getActiveUniformBlockivRobust(GLuint program,
6254 GLuint uniformBlockIndex,
6255 GLenum pname,
6256 GLsizei bufSize,
6257 GLsizei *length,
6258 GLint *params)
6259{
6260 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6261}
6262
Jamie Madill12e957f2017-08-26 21:42:26 -04006263void Context::getActiveUniformBlockName(GLuint program,
6264 GLuint uniformBlockIndex,
6265 GLsizei bufSize,
6266 GLsizei *length,
6267 GLchar *uniformBlockName)
6268{
6269 const Program *programObject = getProgram(program);
6270 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6271}
6272
6273void Context::uniformBlockBinding(GLuint program,
6274 GLuint uniformBlockIndex,
6275 GLuint uniformBlockBinding)
6276{
6277 Program *programObject = getProgram(program);
6278 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006279
6280 if (programObject->isInUse())
6281 {
6282 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006283 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006284 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006285}
6286
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006287GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6288{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006289 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6290 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006291
Jamie Madill70b5bb02017-08-28 13:32:37 -04006292 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006293 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006294 if (error.isError())
6295 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006296 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006297 handleError(error);
6298 return nullptr;
6299 }
6300
Jamie Madill70b5bb02017-08-28 13:32:37 -04006301 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006302}
6303
6304GLboolean Context::isSync(GLsync sync)
6305{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006306 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006307}
6308
6309GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6310{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006311 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006312
6313 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006314 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006315 return result;
6316}
6317
6318void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6319{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006320 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006321 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006322}
6323
6324void Context::getInteger64v(GLenum pname, GLint64 *params)
6325{
6326 GLenum nativeType = GL_NONE;
6327 unsigned int numParams = 0;
6328 getQueryParameterInfo(pname, &nativeType, &numParams);
6329
6330 if (nativeType == GL_INT_64_ANGLEX)
6331 {
6332 getInteger64vImpl(pname, params);
6333 }
6334 else
6335 {
6336 CastStateValues(this, nativeType, pname, numParams, params);
6337 }
6338}
6339
Brandon Jones59770802018-04-02 13:18:42 -07006340void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6341{
6342 getInteger64v(pname, data);
6343}
6344
Corentin Wallez336129f2017-10-17 15:55:40 -04006345void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006346{
6347 Buffer *buffer = mGLState.getTargetBuffer(target);
6348 QueryBufferParameteri64v(buffer, pname, params);
6349}
6350
Brandon Jones59770802018-04-02 13:18:42 -07006351void Context::getBufferParameteri64vRobust(BufferBinding target,
6352 GLenum pname,
6353 GLsizei bufSize,
6354 GLsizei *length,
6355 GLint64 *params)
6356{
6357 getBufferParameteri64v(target, pname, params);
6358}
6359
Jamie Madill3ef140a2017-08-26 23:11:21 -04006360void Context::genSamplers(GLsizei count, GLuint *samplers)
6361{
6362 for (int i = 0; i < count; i++)
6363 {
6364 samplers[i] = mState.mSamplers->createSampler();
6365 }
6366}
6367
6368void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6369{
6370 for (int i = 0; i < count; i++)
6371 {
6372 GLuint sampler = samplers[i];
6373
6374 if (mState.mSamplers->getSampler(sampler))
6375 {
6376 detachSampler(sampler);
6377 }
6378
6379 mState.mSamplers->deleteObject(this, sampler);
6380 }
6381}
6382
6383void Context::getInternalformativ(GLenum target,
6384 GLenum internalformat,
6385 GLenum pname,
6386 GLsizei bufSize,
6387 GLint *params)
6388{
6389 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6390 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6391}
6392
Brandon Jones59770802018-04-02 13:18:42 -07006393void Context::getInternalformativRobust(GLenum target,
6394 GLenum internalformat,
6395 GLenum pname,
6396 GLsizei bufSize,
6397 GLsizei *length,
6398 GLint *params)
6399{
6400 getInternalformativ(target, internalformat, pname, bufSize, params);
6401}
6402
Jiajia Qin5451d532017-11-16 17:16:34 +08006403void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6404{
6405 programUniform1iv(program, location, 1, &v0);
6406}
6407
6408void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6409{
6410 GLint xy[2] = {v0, v1};
6411 programUniform2iv(program, location, 1, xy);
6412}
6413
6414void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6415{
6416 GLint xyz[3] = {v0, v1, v2};
6417 programUniform3iv(program, location, 1, xyz);
6418}
6419
6420void Context::programUniform4i(GLuint program,
6421 GLint location,
6422 GLint v0,
6423 GLint v1,
6424 GLint v2,
6425 GLint v3)
6426{
6427 GLint xyzw[4] = {v0, v1, v2, v3};
6428 programUniform4iv(program, location, 1, xyzw);
6429}
6430
6431void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6432{
6433 programUniform1uiv(program, location, 1, &v0);
6434}
6435
6436void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6437{
6438 GLuint xy[2] = {v0, v1};
6439 programUniform2uiv(program, location, 1, xy);
6440}
6441
6442void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6443{
6444 GLuint xyz[3] = {v0, v1, v2};
6445 programUniform3uiv(program, location, 1, xyz);
6446}
6447
6448void Context::programUniform4ui(GLuint program,
6449 GLint location,
6450 GLuint v0,
6451 GLuint v1,
6452 GLuint v2,
6453 GLuint v3)
6454{
6455 GLuint xyzw[4] = {v0, v1, v2, v3};
6456 programUniform4uiv(program, location, 1, xyzw);
6457}
6458
6459void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6460{
6461 programUniform1fv(program, location, 1, &v0);
6462}
6463
6464void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6465{
6466 GLfloat xy[2] = {v0, v1};
6467 programUniform2fv(program, location, 1, xy);
6468}
6469
6470void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6471{
6472 GLfloat xyz[3] = {v0, v1, v2};
6473 programUniform3fv(program, location, 1, xyz);
6474}
6475
6476void Context::programUniform4f(GLuint program,
6477 GLint location,
6478 GLfloat v0,
6479 GLfloat v1,
6480 GLfloat v2,
6481 GLfloat v3)
6482{
6483 GLfloat xyzw[4] = {v0, v1, v2, v3};
6484 programUniform4fv(program, location, 1, xyzw);
6485}
6486
Jamie Madill81c2e252017-09-09 23:32:46 -04006487void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6488{
6489 Program *programObject = getProgram(program);
6490 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006491 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006492}
6493
Jiajia Qin5451d532017-11-16 17:16:34 +08006494void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6495{
6496 Program *programObject = getProgram(program);
6497 ASSERT(programObject);
6498 programObject->setUniform2iv(location, count, value);
6499}
6500
6501void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6502{
6503 Program *programObject = getProgram(program);
6504 ASSERT(programObject);
6505 programObject->setUniform3iv(location, count, value);
6506}
6507
6508void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6509{
6510 Program *programObject = getProgram(program);
6511 ASSERT(programObject);
6512 programObject->setUniform4iv(location, count, value);
6513}
6514
6515void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6516{
6517 Program *programObject = getProgram(program);
6518 ASSERT(programObject);
6519 programObject->setUniform1uiv(location, count, value);
6520}
6521
6522void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6523{
6524 Program *programObject = getProgram(program);
6525 ASSERT(programObject);
6526 programObject->setUniform2uiv(location, count, value);
6527}
6528
6529void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6530{
6531 Program *programObject = getProgram(program);
6532 ASSERT(programObject);
6533 programObject->setUniform3uiv(location, count, value);
6534}
6535
6536void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6537{
6538 Program *programObject = getProgram(program);
6539 ASSERT(programObject);
6540 programObject->setUniform4uiv(location, count, value);
6541}
6542
6543void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6544{
6545 Program *programObject = getProgram(program);
6546 ASSERT(programObject);
6547 programObject->setUniform1fv(location, count, value);
6548}
6549
6550void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6551{
6552 Program *programObject = getProgram(program);
6553 ASSERT(programObject);
6554 programObject->setUniform2fv(location, count, value);
6555}
6556
6557void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6558{
6559 Program *programObject = getProgram(program);
6560 ASSERT(programObject);
6561 programObject->setUniform3fv(location, count, value);
6562}
6563
6564void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6565{
6566 Program *programObject = getProgram(program);
6567 ASSERT(programObject);
6568 programObject->setUniform4fv(location, count, value);
6569}
6570
6571void Context::programUniformMatrix2fv(GLuint program,
6572 GLint location,
6573 GLsizei count,
6574 GLboolean transpose,
6575 const GLfloat *value)
6576{
6577 Program *programObject = getProgram(program);
6578 ASSERT(programObject);
6579 programObject->setUniformMatrix2fv(location, count, transpose, value);
6580}
6581
6582void Context::programUniformMatrix3fv(GLuint program,
6583 GLint location,
6584 GLsizei count,
6585 GLboolean transpose,
6586 const GLfloat *value)
6587{
6588 Program *programObject = getProgram(program);
6589 ASSERT(programObject);
6590 programObject->setUniformMatrix3fv(location, count, transpose, value);
6591}
6592
6593void Context::programUniformMatrix4fv(GLuint program,
6594 GLint location,
6595 GLsizei count,
6596 GLboolean transpose,
6597 const GLfloat *value)
6598{
6599 Program *programObject = getProgram(program);
6600 ASSERT(programObject);
6601 programObject->setUniformMatrix4fv(location, count, transpose, value);
6602}
6603
6604void Context::programUniformMatrix2x3fv(GLuint program,
6605 GLint location,
6606 GLsizei count,
6607 GLboolean transpose,
6608 const GLfloat *value)
6609{
6610 Program *programObject = getProgram(program);
6611 ASSERT(programObject);
6612 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6613}
6614
6615void Context::programUniformMatrix3x2fv(GLuint program,
6616 GLint location,
6617 GLsizei count,
6618 GLboolean transpose,
6619 const GLfloat *value)
6620{
6621 Program *programObject = getProgram(program);
6622 ASSERT(programObject);
6623 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6624}
6625
6626void Context::programUniformMatrix2x4fv(GLuint program,
6627 GLint location,
6628 GLsizei count,
6629 GLboolean transpose,
6630 const GLfloat *value)
6631{
6632 Program *programObject = getProgram(program);
6633 ASSERT(programObject);
6634 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6635}
6636
6637void Context::programUniformMatrix4x2fv(GLuint program,
6638 GLint location,
6639 GLsizei count,
6640 GLboolean transpose,
6641 const GLfloat *value)
6642{
6643 Program *programObject = getProgram(program);
6644 ASSERT(programObject);
6645 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6646}
6647
6648void Context::programUniformMatrix3x4fv(GLuint program,
6649 GLint location,
6650 GLsizei count,
6651 GLboolean transpose,
6652 const GLfloat *value)
6653{
6654 Program *programObject = getProgram(program);
6655 ASSERT(programObject);
6656 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6657}
6658
6659void Context::programUniformMatrix4x3fv(GLuint program,
6660 GLint location,
6661 GLsizei count,
6662 GLboolean transpose,
6663 const GLfloat *value)
6664{
6665 Program *programObject = getProgram(program);
6666 ASSERT(programObject);
6667 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6668}
6669
Jamie Madill81c2e252017-09-09 23:32:46 -04006670void Context::onTextureChange(const Texture *texture)
6671{
6672 // Conservatively assume all textures are dirty.
6673 // TODO(jmadill): More fine-grained update.
6674 mGLState.setObjectDirty(GL_TEXTURE);
6675}
6676
James Darpiniane8a93c62018-01-04 18:02:24 -08006677bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6678{
6679 return mGLState.isCurrentTransformFeedback(tf);
6680}
James Darpiniane8a93c62018-01-04 18:02:24 -08006681
Yunchao Hea336b902017-08-02 16:05:21 +08006682void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6683{
6684 for (int i = 0; i < count; i++)
6685 {
6686 pipelines[i] = createProgramPipeline();
6687 }
6688}
6689
6690void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6691{
6692 for (int i = 0; i < count; i++)
6693 {
6694 if (pipelines[i] != 0)
6695 {
6696 deleteProgramPipeline(pipelines[i]);
6697 }
6698 }
6699}
6700
6701GLboolean Context::isProgramPipeline(GLuint pipeline)
6702{
6703 if (pipeline == 0)
6704 {
6705 return GL_FALSE;
6706 }
6707
6708 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6709}
6710
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006711void Context::finishFenceNV(GLuint fence)
6712{
6713 FenceNV *fenceObject = getFenceNV(fence);
6714
6715 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006716 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006717}
6718
6719void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6720{
6721 FenceNV *fenceObject = getFenceNV(fence);
6722
6723 ASSERT(fenceObject && fenceObject->isSet());
6724
6725 switch (pname)
6726 {
6727 case GL_FENCE_STATUS_NV:
6728 {
6729 // GL_NV_fence spec:
6730 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6731 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6732 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6733 GLboolean status = GL_TRUE;
6734 if (fenceObject->getStatus() != GL_TRUE)
6735 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006736 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006737 }
6738 *params = status;
6739 break;
6740 }
6741
6742 case GL_FENCE_CONDITION_NV:
6743 {
6744 *params = static_cast<GLint>(fenceObject->getCondition());
6745 break;
6746 }
6747
6748 default:
6749 UNREACHABLE();
6750 }
6751}
6752
6753void Context::getTranslatedShaderSource(GLuint shader,
6754 GLsizei bufsize,
6755 GLsizei *length,
6756 GLchar *source)
6757{
6758 Shader *shaderObject = getShader(shader);
6759 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006760 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006761}
6762
6763void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6764{
6765 Program *programObject = getProgram(program);
6766 ASSERT(programObject);
6767
6768 programObject->getUniformfv(this, location, params);
6769}
6770
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006771void Context::getnUniformfvRobust(GLuint program,
6772 GLint location,
6773 GLsizei bufSize,
6774 GLsizei *length,
6775 GLfloat *params)
6776{
6777 UNIMPLEMENTED();
6778}
6779
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006780void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6781{
6782 Program *programObject = getProgram(program);
6783 ASSERT(programObject);
6784
6785 programObject->getUniformiv(this, location, params);
6786}
6787
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006788void Context::getnUniformivRobust(GLuint program,
6789 GLint location,
6790 GLsizei bufSize,
6791 GLsizei *length,
6792 GLint *params)
6793{
6794 UNIMPLEMENTED();
6795}
6796
6797void Context::getnUniformuivRobust(GLuint program,
6798 GLint location,
6799 GLsizei bufSize,
6800 GLsizei *length,
6801 GLuint *params)
6802{
6803 UNIMPLEMENTED();
6804}
6805
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006806GLboolean Context::isFenceNV(GLuint fence)
6807{
6808 FenceNV *fenceObject = getFenceNV(fence);
6809
6810 if (fenceObject == nullptr)
6811 {
6812 return GL_FALSE;
6813 }
6814
6815 // GL_NV_fence spec:
6816 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6817 // existing fence.
6818 return fenceObject->isSet();
6819}
6820
6821void Context::readnPixels(GLint x,
6822 GLint y,
6823 GLsizei width,
6824 GLsizei height,
6825 GLenum format,
6826 GLenum type,
6827 GLsizei bufSize,
6828 void *data)
6829{
6830 return readPixels(x, y, width, height, format, type, data);
6831}
6832
Jamie Madill007530e2017-12-28 14:27:04 -05006833void Context::setFenceNV(GLuint fence, GLenum condition)
6834{
6835 ASSERT(condition == GL_ALL_COMPLETED_NV);
6836
6837 FenceNV *fenceObject = getFenceNV(fence);
6838 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006839 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006840}
6841
6842GLboolean Context::testFenceNV(GLuint fence)
6843{
6844 FenceNV *fenceObject = getFenceNV(fence);
6845
6846 ASSERT(fenceObject != nullptr);
6847 ASSERT(fenceObject->isSet() == GL_TRUE);
6848
6849 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006850 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006851 if (error.isError())
6852 {
6853 handleError(error);
6854 return GL_TRUE;
6855 }
6856
6857 return result;
6858}
6859
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006860void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006861{
6862 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006863 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006864 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006865}
6866
Jamie Madillfa920eb2018-01-04 11:45:50 -05006867void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006868{
6869 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006870 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006871 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6872}
6873
Jamie Madillfa920eb2018-01-04 11:45:50 -05006874void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6875{
6876 UNIMPLEMENTED();
6877}
6878
Jamie Madill5b772312018-03-08 20:28:32 -05006879bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6880{
6881 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6882 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6883 // to the fact that it is stored internally as a float, and so would require conversion
6884 // if returned from Context::getIntegerv. Since this conversion is already implemented
6885 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6886 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6887 // application.
6888 switch (pname)
6889 {
6890 case GL_COMPRESSED_TEXTURE_FORMATS:
6891 {
6892 *type = GL_INT;
6893 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6894 return true;
6895 }
6896 case GL_SHADER_BINARY_FORMATS:
6897 {
6898 *type = GL_INT;
6899 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6900 return true;
6901 }
6902
6903 case GL_MAX_VERTEX_ATTRIBS:
6904 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6905 case GL_MAX_VARYING_VECTORS:
6906 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6907 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6908 case GL_MAX_TEXTURE_IMAGE_UNITS:
6909 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6910 case GL_MAX_RENDERBUFFER_SIZE:
6911 case GL_NUM_SHADER_BINARY_FORMATS:
6912 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6913 case GL_ARRAY_BUFFER_BINDING:
6914 case GL_FRAMEBUFFER_BINDING:
6915 case GL_RENDERBUFFER_BINDING:
6916 case GL_CURRENT_PROGRAM:
6917 case GL_PACK_ALIGNMENT:
6918 case GL_UNPACK_ALIGNMENT:
6919 case GL_GENERATE_MIPMAP_HINT:
6920 case GL_RED_BITS:
6921 case GL_GREEN_BITS:
6922 case GL_BLUE_BITS:
6923 case GL_ALPHA_BITS:
6924 case GL_DEPTH_BITS:
6925 case GL_STENCIL_BITS:
6926 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6927 case GL_CULL_FACE_MODE:
6928 case GL_FRONT_FACE:
6929 case GL_ACTIVE_TEXTURE:
6930 case GL_STENCIL_FUNC:
6931 case GL_STENCIL_VALUE_MASK:
6932 case GL_STENCIL_REF:
6933 case GL_STENCIL_FAIL:
6934 case GL_STENCIL_PASS_DEPTH_FAIL:
6935 case GL_STENCIL_PASS_DEPTH_PASS:
6936 case GL_STENCIL_BACK_FUNC:
6937 case GL_STENCIL_BACK_VALUE_MASK:
6938 case GL_STENCIL_BACK_REF:
6939 case GL_STENCIL_BACK_FAIL:
6940 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6941 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6942 case GL_DEPTH_FUNC:
6943 case GL_BLEND_SRC_RGB:
6944 case GL_BLEND_SRC_ALPHA:
6945 case GL_BLEND_DST_RGB:
6946 case GL_BLEND_DST_ALPHA:
6947 case GL_BLEND_EQUATION_RGB:
6948 case GL_BLEND_EQUATION_ALPHA:
6949 case GL_STENCIL_WRITEMASK:
6950 case GL_STENCIL_BACK_WRITEMASK:
6951 case GL_STENCIL_CLEAR_VALUE:
6952 case GL_SUBPIXEL_BITS:
6953 case GL_MAX_TEXTURE_SIZE:
6954 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6955 case GL_SAMPLE_BUFFERS:
6956 case GL_SAMPLES:
6957 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6958 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6959 case GL_TEXTURE_BINDING_2D:
6960 case GL_TEXTURE_BINDING_CUBE_MAP:
6961 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6962 {
6963 *type = GL_INT;
6964 *numParams = 1;
6965 return true;
6966 }
6967 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6968 {
6969 if (!getExtensions().packReverseRowOrder)
6970 {
6971 return false;
6972 }
6973 *type = GL_INT;
6974 *numParams = 1;
6975 return true;
6976 }
6977 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6978 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6979 {
6980 if (!getExtensions().textureRectangle)
6981 {
6982 return false;
6983 }
6984 *type = GL_INT;
6985 *numParams = 1;
6986 return true;
6987 }
6988 case GL_MAX_DRAW_BUFFERS_EXT:
6989 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6990 {
6991 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6992 {
6993 return false;
6994 }
6995 *type = GL_INT;
6996 *numParams = 1;
6997 return true;
6998 }
6999 case GL_MAX_VIEWPORT_DIMS:
7000 {
7001 *type = GL_INT;
7002 *numParams = 2;
7003 return true;
7004 }
7005 case GL_VIEWPORT:
7006 case GL_SCISSOR_BOX:
7007 {
7008 *type = GL_INT;
7009 *numParams = 4;
7010 return true;
7011 }
7012 case GL_SHADER_COMPILER:
7013 case GL_SAMPLE_COVERAGE_INVERT:
7014 case GL_DEPTH_WRITEMASK:
7015 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7016 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7017 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7018 // bool-natural
7019 case GL_SAMPLE_COVERAGE:
7020 case GL_SCISSOR_TEST:
7021 case GL_STENCIL_TEST:
7022 case GL_DEPTH_TEST:
7023 case GL_BLEND:
7024 case GL_DITHER:
7025 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7026 {
7027 *type = GL_BOOL;
7028 *numParams = 1;
7029 return true;
7030 }
7031 case GL_COLOR_WRITEMASK:
7032 {
7033 *type = GL_BOOL;
7034 *numParams = 4;
7035 return true;
7036 }
7037 case GL_POLYGON_OFFSET_FACTOR:
7038 case GL_POLYGON_OFFSET_UNITS:
7039 case GL_SAMPLE_COVERAGE_VALUE:
7040 case GL_DEPTH_CLEAR_VALUE:
7041 case GL_LINE_WIDTH:
7042 {
7043 *type = GL_FLOAT;
7044 *numParams = 1;
7045 return true;
7046 }
7047 case GL_ALIASED_LINE_WIDTH_RANGE:
7048 case GL_ALIASED_POINT_SIZE_RANGE:
7049 case GL_DEPTH_RANGE:
7050 {
7051 *type = GL_FLOAT;
7052 *numParams = 2;
7053 return true;
7054 }
7055 case GL_COLOR_CLEAR_VALUE:
7056 case GL_BLEND_COLOR:
7057 {
7058 *type = GL_FLOAT;
7059 *numParams = 4;
7060 return true;
7061 }
7062 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7063 if (!getExtensions().textureFilterAnisotropic)
7064 {
7065 return false;
7066 }
7067 *type = GL_FLOAT;
7068 *numParams = 1;
7069 return true;
7070 case GL_TIMESTAMP_EXT:
7071 if (!getExtensions().disjointTimerQuery)
7072 {
7073 return false;
7074 }
7075 *type = GL_INT_64_ANGLEX;
7076 *numParams = 1;
7077 return true;
7078 case GL_GPU_DISJOINT_EXT:
7079 if (!getExtensions().disjointTimerQuery)
7080 {
7081 return false;
7082 }
7083 *type = GL_INT;
7084 *numParams = 1;
7085 return true;
7086 case GL_COVERAGE_MODULATION_CHROMIUM:
7087 if (!getExtensions().framebufferMixedSamples)
7088 {
7089 return false;
7090 }
7091 *type = GL_INT;
7092 *numParams = 1;
7093 return true;
7094 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7095 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7096 {
7097 return false;
7098 }
7099 *type = GL_INT;
7100 *numParams = 1;
7101 return true;
7102 }
7103
7104 if (getExtensions().debug)
7105 {
7106 switch (pname)
7107 {
7108 case GL_DEBUG_LOGGED_MESSAGES:
7109 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7110 case GL_DEBUG_GROUP_STACK_DEPTH:
7111 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7112 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7113 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7114 case GL_MAX_LABEL_LENGTH:
7115 *type = GL_INT;
7116 *numParams = 1;
7117 return true;
7118
7119 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7120 case GL_DEBUG_OUTPUT:
7121 *type = GL_BOOL;
7122 *numParams = 1;
7123 return true;
7124 }
7125 }
7126
7127 if (getExtensions().multisampleCompatibility)
7128 {
7129 switch (pname)
7130 {
7131 case GL_MULTISAMPLE_EXT:
7132 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7133 *type = GL_BOOL;
7134 *numParams = 1;
7135 return true;
7136 }
7137 }
7138
7139 if (getExtensions().pathRendering)
7140 {
7141 switch (pname)
7142 {
7143 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7144 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7145 *type = GL_FLOAT;
7146 *numParams = 16;
7147 return true;
7148 }
7149 }
7150
7151 if (getExtensions().bindGeneratesResource)
7152 {
7153 switch (pname)
7154 {
7155 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7156 *type = GL_BOOL;
7157 *numParams = 1;
7158 return true;
7159 }
7160 }
7161
7162 if (getExtensions().clientArrays)
7163 {
7164 switch (pname)
7165 {
7166 case GL_CLIENT_ARRAYS_ANGLE:
7167 *type = GL_BOOL;
7168 *numParams = 1;
7169 return true;
7170 }
7171 }
7172
7173 if (getExtensions().sRGBWriteControl)
7174 {
7175 switch (pname)
7176 {
7177 case GL_FRAMEBUFFER_SRGB_EXT:
7178 *type = GL_BOOL;
7179 *numParams = 1;
7180 return true;
7181 }
7182 }
7183
7184 if (getExtensions().robustResourceInitialization &&
7185 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7186 {
7187 *type = GL_BOOL;
7188 *numParams = 1;
7189 return true;
7190 }
7191
7192 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7193 {
7194 *type = GL_BOOL;
7195 *numParams = 1;
7196 return true;
7197 }
7198
jchen1082af6202018-06-22 10:59:52 +08007199 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7200 {
7201 *type = GL_INT;
7202 *numParams = 1;
7203 return true;
7204 }
7205
Jamie Madill5b772312018-03-08 20:28:32 -05007206 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7207 switch (pname)
7208 {
7209 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7210 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7211 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7212 {
7213 return false;
7214 }
7215 *type = GL_INT;
7216 *numParams = 1;
7217 return true;
7218
7219 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7220 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7221 {
7222 return false;
7223 }
7224 *type = GL_INT;
7225 *numParams = 1;
7226 return true;
7227
7228 case GL_PROGRAM_BINARY_FORMATS_OES:
7229 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7230 {
7231 return false;
7232 }
7233 *type = GL_INT;
7234 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7235 return true;
7236
7237 case GL_PACK_ROW_LENGTH:
7238 case GL_PACK_SKIP_ROWS:
7239 case GL_PACK_SKIP_PIXELS:
7240 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7241 {
7242 return false;
7243 }
7244 *type = GL_INT;
7245 *numParams = 1;
7246 return true;
7247 case GL_UNPACK_ROW_LENGTH:
7248 case GL_UNPACK_SKIP_ROWS:
7249 case GL_UNPACK_SKIP_PIXELS:
7250 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7251 {
7252 return false;
7253 }
7254 *type = GL_INT;
7255 *numParams = 1;
7256 return true;
7257 case GL_VERTEX_ARRAY_BINDING:
7258 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7259 {
7260 return false;
7261 }
7262 *type = GL_INT;
7263 *numParams = 1;
7264 return true;
7265 case GL_PIXEL_PACK_BUFFER_BINDING:
7266 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7267 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7268 {
7269 return false;
7270 }
7271 *type = GL_INT;
7272 *numParams = 1;
7273 return true;
7274 case GL_MAX_SAMPLES:
7275 {
7276 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7277 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7278 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7279 {
7280 return false;
7281 }
7282 *type = GL_INT;
7283 *numParams = 1;
7284 return true;
7285
7286 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7287 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7288 {
7289 return false;
7290 }
7291 *type = GL_INT;
7292 *numParams = 1;
7293 return true;
7294 }
7295 }
7296
7297 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7298 {
7299 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7300 {
7301 return false;
7302 }
7303 *type = GL_INT;
7304 *numParams = 1;
7305 return true;
7306 }
7307
7308 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7309 {
7310 *type = GL_INT;
7311 *numParams = 1;
7312 return true;
7313 }
7314
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007315 if (getClientVersion() < Version(2, 0))
7316 {
7317 switch (pname)
7318 {
7319 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007320 case GL_CLIENT_ACTIVE_TEXTURE:
7321 case GL_MATRIX_MODE:
7322 case GL_MAX_TEXTURE_UNITS:
7323 case GL_MAX_MODELVIEW_STACK_DEPTH:
7324 case GL_MAX_PROJECTION_STACK_DEPTH:
7325 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007326 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007327 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007328 case GL_VERTEX_ARRAY_STRIDE:
7329 case GL_NORMAL_ARRAY_STRIDE:
7330 case GL_COLOR_ARRAY_STRIDE:
7331 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7332 case GL_VERTEX_ARRAY_SIZE:
7333 case GL_COLOR_ARRAY_SIZE:
7334 case GL_TEXTURE_COORD_ARRAY_SIZE:
7335 case GL_VERTEX_ARRAY_TYPE:
7336 case GL_NORMAL_ARRAY_TYPE:
7337 case GL_COLOR_ARRAY_TYPE:
7338 case GL_TEXTURE_COORD_ARRAY_TYPE:
7339 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7340 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7341 case GL_COLOR_ARRAY_BUFFER_BINDING:
7342 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7343 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7344 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7345 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007346 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007347 case GL_MODELVIEW_STACK_DEPTH:
7348 case GL_PROJECTION_STACK_DEPTH:
7349 case GL_TEXTURE_STACK_DEPTH:
7350 case GL_LOGIC_OP_MODE:
7351 case GL_BLEND_SRC:
7352 case GL_BLEND_DST:
7353 case GL_PERSPECTIVE_CORRECTION_HINT:
7354 case GL_POINT_SMOOTH_HINT:
7355 case GL_LINE_SMOOTH_HINT:
7356 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007357 *type = GL_INT;
7358 *numParams = 1;
7359 return true;
7360 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007361 case GL_FOG_DENSITY:
7362 case GL_FOG_START:
7363 case GL_FOG_END:
7364 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007365 case GL_POINT_SIZE:
7366 case GL_POINT_SIZE_MIN:
7367 case GL_POINT_SIZE_MAX:
7368 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007369 *type = GL_FLOAT;
7370 *numParams = 1;
7371 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007372 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007373 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007374 *type = GL_FLOAT;
7375 *numParams = 2;
7376 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007377 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007378 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007379 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007380 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007381 *type = GL_FLOAT;
7382 *numParams = 4;
7383 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007384 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007385 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007386 *type = GL_FLOAT;
7387 *numParams = 3;
7388 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007389 case GL_MODELVIEW_MATRIX:
7390 case GL_PROJECTION_MATRIX:
7391 case GL_TEXTURE_MATRIX:
7392 *type = GL_FLOAT;
7393 *numParams = 16;
7394 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007395 case GL_LIGHT_MODEL_TWO_SIDE:
7396 *type = GL_BOOL;
7397 *numParams = 1;
7398 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007399 }
7400 }
7401
Jamie Madill5b772312018-03-08 20:28:32 -05007402 if (getClientVersion() < Version(3, 0))
7403 {
7404 return false;
7405 }
7406
7407 // Check for ES3.0+ parameter names
7408 switch (pname)
7409 {
7410 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7411 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7412 case GL_UNIFORM_BUFFER_BINDING:
7413 case GL_TRANSFORM_FEEDBACK_BINDING:
7414 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7415 case GL_COPY_READ_BUFFER_BINDING:
7416 case GL_COPY_WRITE_BUFFER_BINDING:
7417 case GL_SAMPLER_BINDING:
7418 case GL_READ_BUFFER:
7419 case GL_TEXTURE_BINDING_3D:
7420 case GL_TEXTURE_BINDING_2D_ARRAY:
7421 case GL_MAX_3D_TEXTURE_SIZE:
7422 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7423 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7424 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7425 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7426 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7427 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7428 case GL_MAX_VARYING_COMPONENTS:
7429 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7430 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7431 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7432 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7433 case GL_NUM_EXTENSIONS:
7434 case GL_MAJOR_VERSION:
7435 case GL_MINOR_VERSION:
7436 case GL_MAX_ELEMENTS_INDICES:
7437 case GL_MAX_ELEMENTS_VERTICES:
7438 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7439 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7440 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7441 case GL_UNPACK_IMAGE_HEIGHT:
7442 case GL_UNPACK_SKIP_IMAGES:
7443 {
7444 *type = GL_INT;
7445 *numParams = 1;
7446 return true;
7447 }
7448
7449 case GL_MAX_ELEMENT_INDEX:
7450 case GL_MAX_UNIFORM_BLOCK_SIZE:
7451 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7452 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7453 case GL_MAX_SERVER_WAIT_TIMEOUT:
7454 {
7455 *type = GL_INT_64_ANGLEX;
7456 *numParams = 1;
7457 return true;
7458 }
7459
7460 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7461 case GL_TRANSFORM_FEEDBACK_PAUSED:
7462 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7463 case GL_RASTERIZER_DISCARD:
7464 {
7465 *type = GL_BOOL;
7466 *numParams = 1;
7467 return true;
7468 }
7469
7470 case GL_MAX_TEXTURE_LOD_BIAS:
7471 {
7472 *type = GL_FLOAT;
7473 *numParams = 1;
7474 return true;
7475 }
7476 }
7477
7478 if (getExtensions().requestExtension)
7479 {
7480 switch (pname)
7481 {
7482 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7483 *type = GL_INT;
7484 *numParams = 1;
7485 return true;
7486 }
7487 }
7488
7489 if (getClientVersion() < Version(3, 1))
7490 {
7491 return false;
7492 }
7493
7494 switch (pname)
7495 {
7496 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7497 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7498 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7499 case GL_MAX_FRAMEBUFFER_WIDTH:
7500 case GL_MAX_FRAMEBUFFER_HEIGHT:
7501 case GL_MAX_FRAMEBUFFER_SAMPLES:
7502 case GL_MAX_SAMPLE_MASK_WORDS:
7503 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7504 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7505 case GL_MAX_INTEGER_SAMPLES:
7506 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7507 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7508 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7509 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7510 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7511 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7512 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7513 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7514 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7515 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7516 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7517 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7518 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7519 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7520 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7521 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7522 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7523 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7524 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7525 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7526 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7527 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7528 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7529 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7530 case GL_MAX_UNIFORM_LOCATIONS:
7531 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7532 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7533 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7534 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7535 case GL_MAX_IMAGE_UNITS:
7536 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7537 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7538 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7539 case GL_SHADER_STORAGE_BUFFER_BINDING:
7540 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7541 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007542 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007543 *type = GL_INT;
7544 *numParams = 1;
7545 return true;
7546 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7547 *type = GL_INT_64_ANGLEX;
7548 *numParams = 1;
7549 return true;
7550 case GL_SAMPLE_MASK:
7551 *type = GL_BOOL;
7552 *numParams = 1;
7553 return true;
7554 }
7555
7556 if (getExtensions().geometryShader)
7557 {
7558 switch (pname)
7559 {
7560 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7561 case GL_LAYER_PROVOKING_VERTEX_EXT:
7562 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7563 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7564 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7565 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7566 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7567 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7568 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7569 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7570 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7571 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7572 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7573 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7574 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7575 *type = GL_INT;
7576 *numParams = 1;
7577 return true;
7578 }
7579 }
7580
7581 return false;
7582}
7583
7584bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7585{
7586 if (getClientVersion() < Version(3, 0))
7587 {
7588 return false;
7589 }
7590
7591 switch (target)
7592 {
7593 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7594 case GL_UNIFORM_BUFFER_BINDING:
7595 {
7596 *type = GL_INT;
7597 *numParams = 1;
7598 return true;
7599 }
7600 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7601 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7602 case GL_UNIFORM_BUFFER_START:
7603 case GL_UNIFORM_BUFFER_SIZE:
7604 {
7605 *type = GL_INT_64_ANGLEX;
7606 *numParams = 1;
7607 return true;
7608 }
7609 }
7610
7611 if (getClientVersion() < Version(3, 1))
7612 {
7613 return false;
7614 }
7615
7616 switch (target)
7617 {
7618 case GL_IMAGE_BINDING_LAYERED:
7619 {
7620 *type = GL_BOOL;
7621 *numParams = 1;
7622 return true;
7623 }
7624 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7625 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7626 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7627 case GL_SHADER_STORAGE_BUFFER_BINDING:
7628 case GL_VERTEX_BINDING_BUFFER:
7629 case GL_VERTEX_BINDING_DIVISOR:
7630 case GL_VERTEX_BINDING_OFFSET:
7631 case GL_VERTEX_BINDING_STRIDE:
7632 case GL_SAMPLE_MASK_VALUE:
7633 case GL_IMAGE_BINDING_NAME:
7634 case GL_IMAGE_BINDING_LEVEL:
7635 case GL_IMAGE_BINDING_LAYER:
7636 case GL_IMAGE_BINDING_ACCESS:
7637 case GL_IMAGE_BINDING_FORMAT:
7638 {
7639 *type = GL_INT;
7640 *numParams = 1;
7641 return true;
7642 }
7643 case GL_ATOMIC_COUNTER_BUFFER_START:
7644 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7645 case GL_SHADER_STORAGE_BUFFER_START:
7646 case GL_SHADER_STORAGE_BUFFER_SIZE:
7647 {
7648 *type = GL_INT_64_ANGLEX;
7649 *numParams = 1;
7650 return true;
7651 }
7652 }
7653
7654 return false;
7655}
7656
7657Program *Context::getProgram(GLuint handle) const
7658{
7659 return mState.mShaderPrograms->getProgram(handle);
7660}
7661
7662Shader *Context::getShader(GLuint handle) const
7663{
7664 return mState.mShaderPrograms->getShader(handle);
7665}
7666
7667bool Context::isTextureGenerated(GLuint texture) const
7668{
7669 return mState.mTextures->isHandleGenerated(texture);
7670}
7671
Jamie Madill5b772312018-03-08 20:28:32 -05007672bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7673{
7674 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7675}
7676
7677bool Context::isFramebufferGenerated(GLuint framebuffer) const
7678{
7679 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7680}
7681
7682bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7683{
7684 return mState.mPipelines->isHandleGenerated(pipeline);
7685}
7686
7687bool Context::usingDisplayTextureShareGroup() const
7688{
7689 return mDisplayTextureShareGroup;
7690}
7691
7692GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7693{
7694 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7695 internalformat == GL_DEPTH_STENCIL
7696 ? GL_DEPTH24_STENCIL8
7697 : internalformat;
7698}
7699
jchen1082af6202018-06-22 10:59:52 +08007700void Context::maxShaderCompilerThreads(GLuint count)
7701{
jchen107ae70d82018-07-06 13:47:01 +08007702 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08007703 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007704 // A count of zero specifies a request for no parallel compiling or linking.
7705 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7706 {
7707 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7708 }
7709 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007710}
7711
Jamie Madill2eb65032018-07-30 10:25:57 -04007712bool Context::isGLES1() const
7713{
7714 return mState.getClientVersion() < Version(2, 0);
7715}
7716
Jamie Madilla11819d2018-07-30 10:26:01 -04007717void Context::onSubjectStateChange(const Context *context,
7718 angle::SubjectIndex index,
7719 angle::SubjectMessage message)
7720{
Jamie Madilla11819d2018-07-30 10:26:01 -04007721 switch (index)
7722 {
7723 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007724 switch (message)
7725 {
7726 case angle::SubjectMessage::CONTENTS_CHANGED:
7727 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
7728 mStateCache.onVertexArrayBufferContentsChange(this);
7729 break;
7730 case angle::SubjectMessage::RESOURCE_MAPPED:
7731 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7732 case angle::SubjectMessage::BINDING_CHANGED:
7733 mStateCache.onVertexArrayBufferStateChange(this);
7734 break;
7735 default:
7736 break;
7737 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007738 break;
7739
7740 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007741 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7742 {
7743 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
7744 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007745 break;
7746
7747 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007748 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7749 {
7750 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
7751 }
7752 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04007753 break;
7754
7755 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04007756 if (index < kTextureMaxSubjectIndex)
7757 {
7758 mGLState.onActiveTextureStateChange(index);
Jamie Madilld84b6732018-09-06 15:54:35 -04007759 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007760 }
Jamie Madille25b8002018-09-20 13:39:49 -04007761 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04007762 {
Jamie Madill6d32cef2018-08-14 02:34:28 -04007763 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04007764 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007765 }
Jamie Madille25b8002018-09-20 13:39:49 -04007766 else
7767 {
7768 ASSERT(index < kSamplerMaxSubjectIndex);
7769 mGLState.setSamplerDirty(index - kSampler0SubjectIndex);
7770 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007771 break;
7772 }
7773}
7774
Jamie Madill6b873dd2018-07-12 23:56:30 -04007775// ErrorSet implementation.
7776ErrorSet::ErrorSet(Context *context) : mContext(context)
7777{
7778}
7779
7780ErrorSet::~ErrorSet() = default;
7781
Jamie Madill306b6c12018-07-27 08:12:49 -04007782void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007783{
7784 // This internal enum is used to filter internal errors that are already handled.
7785 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7786 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7787 {
7788 return;
7789 }
7790
7791 if (ANGLE_UNLIKELY(error.isError()))
7792 {
7793 GLenum code = error.getCode();
7794 mErrors.insert(code);
7795 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7796 {
7797 mContext->markContextLost();
7798 }
7799
7800 ASSERT(!error.getMessage().empty());
7801 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7802 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7803 error.getMessage());
7804 }
7805}
7806
7807bool ErrorSet::empty() const
7808{
7809 return mErrors.empty();
7810}
7811
7812GLenum ErrorSet::popError()
7813{
7814 ASSERT(!empty());
7815 GLenum error = *mErrors.begin();
7816 mErrors.erase(mErrors.begin());
7817 return error;
7818}
Jamie Madilldc358af2018-07-31 11:22:13 -04007819
7820// StateCache implementation.
Jamie Madill16e28fd2018-09-12 11:03:05 -04007821StateCache::StateCache(Context *context)
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007822 : mCachedHasAnyEnabledClientAttrib(false),
7823 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04007824 mCachedInstancedVertexElementLimit(0),
7825 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madilldc358af2018-07-31 11:22:13 -04007826{
Jamie Madill16e28fd2018-09-12 11:03:05 -04007827 updateValidDrawModes(context);
Jamie Madilldc358af2018-07-31 11:22:13 -04007828}
7829
7830StateCache::~StateCache() = default;
7831
7832void StateCache::updateActiveAttribsMask(Context *context)
7833{
7834 bool isGLES1 = context->isGLES1();
7835 const State &glState = context->getGLState();
7836
7837 if (!isGLES1 && !glState.getProgram())
7838 {
7839 mCachedActiveBufferedAttribsMask = AttributesMask();
7840 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04007841 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04007842 return;
7843 }
7844
7845 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7846 : glState.getProgram()->getActiveAttribLocationsMask();
7847
7848 const VertexArray *vao = glState.getVertexArray();
7849 ASSERT(vao);
7850
7851 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7852 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04007853 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007854
Jamie Madill0a17e482018-08-31 17:19:11 -04007855 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
7856 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04007857 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007858 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7859}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007860
7861void StateCache::updateVertexElementLimits(Context *context)
7862{
7863 const VertexArray *vao = context->getGLState().getVertexArray();
7864
7865 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7866 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7867
7868 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
7869 // If there are no buffered attributes then we should not limit the draw call count.
7870 if (!vao || !mCachedActiveBufferedAttribsMask.any())
7871 {
7872 return;
7873 }
7874
7875 const auto &vertexAttribs = vao->getVertexAttributes();
7876 const auto &vertexBindings = vao->getVertexBindings();
7877
7878 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
7879 {
7880 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
7881 ASSERT(attrib.enabled);
7882
7883 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
7884 ASSERT(context->isGLES1() ||
7885 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
7886
7887 GLint64 limit = attrib.getCachedElementLimit();
7888 if (binding.getDivisor() > 0)
7889 {
7890 mCachedInstancedVertexElementLimit =
7891 std::min(mCachedInstancedVertexElementLimit, limit);
7892 }
7893 else
7894 {
7895 mCachedNonInstancedVertexElementLimit =
7896 std::min(mCachedNonInstancedVertexElementLimit, limit);
7897 }
7898 }
7899}
Jamie Madillc43cdad2018-08-08 15:49:25 -04007900
Jamie Madilld84b6732018-09-06 15:54:35 -04007901void StateCache::updateBasicDrawStatesError()
7902{
7903 mCachedBasicDrawStatesError = kInvalidPointer;
7904}
7905
7906intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
7907{
7908 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
7909 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
7910 return mCachedBasicDrawStatesError;
7911}
7912
Jamie Madillc43cdad2018-08-08 15:49:25 -04007913void StateCache::onVertexArrayBindingChange(Context *context)
7914{
7915 updateActiveAttribsMask(context);
7916 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007917 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007918}
7919
7920void StateCache::onProgramExecutableChange(Context *context)
7921{
7922 updateActiveAttribsMask(context);
7923 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007924 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04007925 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04007926}
7927
Jamie Madilld84b6732018-09-06 15:54:35 -04007928void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04007929{
7930 updateVertexElementLimits(context);
7931}
7932
Jamie Madilld84b6732018-09-06 15:54:35 -04007933void StateCache::onVertexArrayBufferContentsChange(Context *context)
7934{
7935 updateVertexElementLimits(context);
7936 updateBasicDrawStatesError();
7937}
7938
Jamie Madillc43cdad2018-08-08 15:49:25 -04007939void StateCache::onVertexArrayStateChange(Context *context)
7940{
7941 updateActiveAttribsMask(context);
7942 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007943 updateBasicDrawStatesError();
7944}
7945
7946void StateCache::onVertexArrayBufferStateChange(Context *context)
7947{
7948 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007949}
7950
7951void StateCache::onGLES1ClientStateChange(Context *context)
7952{
7953 updateActiveAttribsMask(context);
7954}
Jamie Madilld84b6732018-09-06 15:54:35 -04007955
7956void StateCache::onDrawFramebufferChange(Context *context)
7957{
7958 updateBasicDrawStatesError();
7959}
7960
7961void StateCache::onContextCapChange(Context *context)
7962{
7963 updateBasicDrawStatesError();
7964}
7965
7966void StateCache::onStencilStateChange(Context *context)
7967{
7968 updateBasicDrawStatesError();
7969}
7970
7971void StateCache::onDefaultVertexAttributeChange(Context *context)
7972{
7973 updateBasicDrawStatesError();
7974}
7975
7976void StateCache::onActiveTextureChange(Context *context)
7977{
7978 updateBasicDrawStatesError();
7979}
7980
7981void StateCache::onQueryChange(Context *context)
7982{
7983 updateBasicDrawStatesError();
7984}
7985
7986void StateCache::onTransformFeedbackChange(Context *context)
7987{
7988 updateBasicDrawStatesError();
7989}
7990
7991void StateCache::onUniformBufferStateChange(Context *context)
7992{
7993 updateBasicDrawStatesError();
7994}
7995
7996void StateCache::onBufferBindingChange(Context *context)
7997{
7998 updateBasicDrawStatesError();
7999}
Jamie Madill526a6f62018-09-12 11:03:05 -04008000
8001void StateCache::updateValidDrawModes(Context *context)
8002{
8003 Program *program = context->getGLState().getProgram();
8004 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8005 {
8006 mCachedValidDrawModes = {{
8007 true, /* Points */
8008 true, /* Lines */
8009 true, /* LineLoop */
8010 true, /* LineStrip */
8011 true, /* Triangles */
8012 true, /* TriangleStrip */
8013 true, /* TriangleFan */
8014 false, /* LinesAdjacency */
8015 false, /* LineStripAdjacency */
8016 false, /* TrianglesAdjacency */
8017 false, /* TriangleStripAdjacency */
8018 false, /* InvalidEnum */
8019 }};
8020 }
8021 else
8022 {
8023 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8024
8025 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
8026
8027 mCachedValidDrawModes = {{
8028 gsMode == PrimitiveMode::Points, /* Points */
8029 gsMode == PrimitiveMode::Lines, /* Lines */
8030 gsMode == PrimitiveMode::Lines, /* LineLoop */
8031 gsMode == PrimitiveMode::Lines, /* LineStrip */
8032 gsMode == PrimitiveMode::Triangles, /* Triangles */
8033 gsMode == PrimitiveMode::Triangles, /* TriangleStrip */
8034 gsMode == PrimitiveMode::Triangles, /* TriangleFan */
8035 gsMode == PrimitiveMode::LinesAdjacency, /* LinesAdjacency */
8036 gsMode == PrimitiveMode::LinesAdjacency, /* LineStripAdjacency */
8037 gsMode == PrimitiveMode::TrianglesAdjacency, /* TrianglesAdjacency */
8038 gsMode == PrimitiveMode::TrianglesAdjacency, /* TriangleStripAdjacency */
8039 false, /* InvalidEnum */
8040 }};
8041 }
8042}
Jamie Madillc29968b2016-01-20 11:17:23 -05008043} // namespace gl