blob: f9b1fe7f763f56d10d62330b3908c543ef1ecf3d [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,
309 kVertexArraySubjectIndex = kUniformBufferMaxSubjectIndex,
310 kReadFramebufferSubjectIndex,
311 kDrawFramebufferSubjectIndex
312};
Geoff Langf6db0982015-08-25 13:04:00 -0400313} // anonymous namespace
314
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000315namespace gl
316{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000317
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400318Context::Context(rx::EGLImplFactory *implFactory,
319 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400320 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500321 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400322 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500323 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700324 const egl::DisplayExtensions &displayExtensions,
325 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500326 : mState(reinterpret_cast<ContextID>(this),
327 shareContext ? &shareContext->mState : nullptr,
328 shareTextures,
329 GetClientVersion(attribs),
330 &mGLState,
331 mCaps,
332 mTextureCaps,
333 mExtensions,
334 mLimitations),
335 mSkipValidation(GetNoError(attribs)),
336 mDisplayTextureShareGroup(shareTextures != nullptr),
337 mSavedArgsType(nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400338 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400339 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400340 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400341 mGLState(GetDebug(attribs),
342 GetBindGeneratesResource(attribs),
343 GetClientArraysEnabled(attribs),
344 GetRobustResourceInit(attribs),
345 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400346 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500347 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400348 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500349 mHasBeenCurrent(false),
350 mContextLost(false),
351 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700352 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500353 mResetStrategy(GetResetStrategy(attribs)),
354 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400355 mSurfacelessSupported(displayExtensions.surfacelessContext),
356 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400357 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
358 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500359 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400360 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400361 mMemoryProgramCache(memoryProgramCache),
Jamie Madill16e28fd2018-09-12 11:03:05 -0400362 mStateCache(this),
Jamie Madilla11819d2018-07-30 10:26:01 -0400363 mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
364 mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
365 mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400366 mScratchBuffer(1000u),
jchen107ae70d82018-07-06 13:47:01 +0800367 mZeroFilledBuffer(1000u),
368 mThreadPool(nullptr)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000369{
Jamie Madill5b772312018-03-08 20:28:32 -0500370 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400371 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
372 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Jamie Madill6d32cef2018-08-14 02:34:28 -0400373
374 for (angle::SubjectIndex uboIndex = kUniformBuffer0SubjectIndex;
375 uboIndex < kUniformBufferMaxSubjectIndex; ++uboIndex)
376 {
377 mUniformBufferObserverBindings.emplace_back(this, uboIndex);
378 }
Geoff Lang33f11fb2018-05-07 13:42:47 -0400379}
Jamie Madill5b772312018-03-08 20:28:32 -0500380
Geoff Lang33f11fb2018-05-07 13:42:47 -0400381void Context::initialize()
382{
383 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400384
Geoff Lang33f11fb2018-05-07 13:42:47 -0400385 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700386 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400387
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400388 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100389
Shannon Woods53a94a82014-06-24 15:20:36 -0400390 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400391
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000392 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400393 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000394 // and cube map texture state vectors respectively associated with them.
395 // In order that access to these initial textures not be lost, they are treated as texture
396 // objects all of whose names are 0.
397
Corentin Wallez99d492c2018-02-27 15:17:10 -0500398 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800399 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500400
Corentin Wallez99d492c2018-02-27 15:17:10 -0500401 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800402 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400403
Geoff Langeb66a6e2016-10-31 13:06:12 -0400404 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400405 {
406 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500407 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800408 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400409
Corentin Wallez99d492c2018-02-27 15:17:10 -0500410 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800411 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400412 }
Geoff Lang3b573612016-10-31 14:08:10 -0400413 if (getClientVersion() >= Version(3, 1))
414 {
Olli Etuahod310a432018-08-24 15:40:23 +0300415 // TODO(http://anglebug.com/2775): These could also be enabled via extension
Geoff Lang3b573612016-10-31 14:08:10 -0400416 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500417 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800418 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Olli Etuahod310a432018-08-24 15:40:23 +0300419 Texture *zeroTexture2DMultisampleArray =
420 new Texture(mImplementation.get(), 0, TextureType::_2DMultisampleArray);
421 mZeroTextures[TextureType::_2DMultisampleArray].set(this, zeroTexture2DMultisampleArray);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800422
Jiajia Qin6eafb042016-12-27 17:04:07 +0800423 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
424 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800425 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800426 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800427
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800428 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
429 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400430 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800431 }
Geoff Lang3b573612016-10-31 14:08:10 -0400432 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000433
Geoff Langb0f917f2017-12-05 13:41:54 -0500434 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400435 {
436 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500437 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800438 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400439 }
440
Geoff Langb0f917f2017-12-05 13:41:54 -0500441 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400442 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500443 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800444 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400445 }
446
Jamie Madill4928b7c2017-06-20 12:57:39 -0400447 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500448
Jamie Madill57a89722013-07-02 11:57:03 -0400449 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000450
Geoff Langeb66a6e2016-10-31 13:06:12 -0400451 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400452 {
453 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
454 // In the initial state, a default transform feedback object is bound and treated as
455 // a transform feedback object with a name of zero. That object is bound any time
456 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400457 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400458 }
Geoff Langc8058452014-02-03 12:04:11 -0500459
Corentin Wallez336129f2017-10-17 15:55:40 -0400460 for (auto type : angle::AllEnums<BufferBinding>())
461 {
462 bindBuffer(type, 0);
463 }
464
465 bindRenderbuffer(GL_RENDERBUFFER, 0);
466
467 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
468 {
469 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
470 }
471
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700472 // Initialize GLES1 renderer if appropriate.
473 if (getClientVersion() < Version(2, 0))
474 {
475 mGLES1Renderer.reset(new GLES1Renderer());
476 }
477
Jamie Madillad9f24e2016-02-12 09:27:24 -0500478 // Initialize dirty bit masks
Geoff Lang9bf86f02018-07-26 11:46:34 -0400479 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
480 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
481 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400482 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400483
484 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
485 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
486 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
487
Jamie Madillc67323a2017-11-02 23:11:41 -0400488 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500489 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500490 // No dirty objects.
491
492 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400493 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500494 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400495 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500496 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
497
498 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
499 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
500 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
501 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
502 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
503 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
504 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
505 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
506 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
507 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
508 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400509 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500510 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
511
512 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
513 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700514 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400515 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
516 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500517 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
518 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400519
Xinghua Cao10a4d432017-11-28 14:46:26 +0800520 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
jchen1099118c12018-09-10 16:28:51 +0800521 mComputeDirtyBits.set(State::DIRTY_BIT_UNIFORM_BUFFER_BINDINGS);
522 mComputeDirtyBits.set(State::DIRTY_BIT_ATOMIC_COUNTER_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800523 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
524 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
525 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
526 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
jchen1099118c12018-09-10 16:28:51 +0800527 mComputeDirtyBits.set(State::DIRTY_BIT_IMAGE_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800528 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800529 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400530 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800531
Jamie Madillb4927eb2018-07-16 11:39:46 -0400532 mImplementation->setErrorSet(&mErrors);
533
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400534 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000535}
536
Jamie Madill4928b7c2017-06-20 12:57:39 -0400537egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000538{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700539 if (mGLES1Renderer)
540 {
541 mGLES1Renderer->onDestroy(this, &mGLState);
542 }
543
Jamie Madille7b3fe22018-04-05 09:42:46 -0400544 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400545 ANGLE_TRY(releaseSurface(display));
546
Corentin Wallez80b24112015-08-25 16:41:57 -0400547 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000548 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400549 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000550 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400551 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000552
Corentin Wallez80b24112015-08-25 16:41:57 -0400553 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000554 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400555 if (query.second != nullptr)
556 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400557 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400558 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000559 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400560 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000561
Corentin Wallez80b24112015-08-25 16:41:57 -0400562 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400563 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400564 if (vertexArray.second)
565 {
566 vertexArray.second->onDestroy(this);
567 }
Jamie Madill57a89722013-07-02 11:57:03 -0400568 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400569 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400570
Corentin Wallez80b24112015-08-25 16:41:57 -0400571 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500572 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500573 if (transformFeedback.second != nullptr)
574 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500575 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500576 }
Geoff Langc8058452014-02-03 12:04:11 -0500577 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400578 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500579
Jamie Madill5b772312018-03-08 20:28:32 -0500580 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400581 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800582 if (zeroTexture.get() != nullptr)
583 {
584 ANGLE_TRY(zeroTexture->onDestroy(this));
585 zeroTexture.set(this, nullptr);
586 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400587 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000588
Jamie Madill2f348d22017-06-05 10:50:59 -0400589 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500590
Jamie Madill4928b7c2017-06-20 12:57:39 -0400591 mGLState.reset(this);
592
Jamie Madill6c1f6712017-02-14 19:08:04 -0500593 mState.mBuffers->release(this);
594 mState.mShaderPrograms->release(this);
595 mState.mTextures->release(this);
596 mState.mRenderbuffers->release(this);
597 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400598 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500599 mState.mPaths->release(this);
600 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800601 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400602
jchen107ae70d82018-07-06 13:47:01 +0800603 mThreadPool.reset();
604
Jamie Madill76e471e2017-10-21 09:56:01 -0400605 mImplementation->onDestroy(this);
606
Jamie Madill4928b7c2017-06-20 12:57:39 -0400607 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000608}
609
Jamie Madill70ee0f62017-02-06 16:04:20 -0500610Context::~Context()
611{
612}
613
Geoff Lang75359662018-04-11 01:42:27 -0400614void Context::setLabel(EGLLabelKHR label)
615{
616 mLabel = label;
617}
618
619EGLLabelKHR Context::getLabel() const
620{
621 return mLabel;
622}
623
Jamie Madill4928b7c2017-06-20 12:57:39 -0400624egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000625{
Jamie Madill61e16b42017-06-19 11:13:23 -0400626 mCurrentDisplay = display;
627
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000628 if (!mHasBeenCurrent)
629 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400630 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000631 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500632 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400633 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000634
Corentin Wallezc295e512017-01-27 17:47:50 -0500635 int width = 0;
636 int height = 0;
637 if (surface != nullptr)
638 {
639 width = surface->getWidth();
640 height = surface->getHeight();
641 }
642
643 mGLState.setViewportParams(0, 0, width, height);
644 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000645
646 mHasBeenCurrent = true;
647 }
648
Jamie Madill1b94d432015-08-07 13:23:23 -0400649 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700650 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400651 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400652
Jamie Madill4928b7c2017-06-20 12:57:39 -0400653 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500654
655 Framebuffer *newDefault = nullptr;
656 if (surface != nullptr)
657 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400658 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500659 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400660 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500661 }
662 else
663 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400664 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500665 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000666
Corentin Wallez37c39792015-08-20 14:19:46 -0400667 // Update default framebuffer, the binding of the previous default
668 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400669 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400670 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700671 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400672 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400673 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400674 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700675 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400676 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400677 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400678 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400679 }
Ian Ewell292f0052016-02-04 10:37:32 -0500680
681 // Notify the renderer of a context switch
Luc Ferron5396f2a2018-07-12 08:24:23 -0400682 ANGLE_TRY(mImplementation->onMakeCurrent(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400683 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000684}
685
Jamie Madill4928b7c2017-06-20 12:57:39 -0400686egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400687{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400688 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400689
Geoff Langbf7b95d2018-05-01 16:48:21 -0400690 // Remove the default framebuffer
691 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500692 {
693 mGLState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400694 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500695 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400696
697 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500698 {
699 mGLState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400700 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500701 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400702
703 if (defaultFramebuffer)
704 {
705 defaultFramebuffer->onDestroy(this);
706 delete defaultFramebuffer;
707 }
708
Corentin Wallezc295e512017-01-27 17:47:50 -0500709 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
710
711 if (mCurrentSurface)
712 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400713 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500714 mCurrentSurface = nullptr;
715 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400716
717 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400718}
719
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000720GLuint Context::createBuffer()
721{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500722 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000723}
724
725GLuint Context::createProgram()
726{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500727 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000728}
729
Jiawei Shao385b3e02018-03-21 09:43:28 +0800730GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000731{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500732 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000733}
734
735GLuint Context::createTexture()
736{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500737 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000738}
739
740GLuint Context::createRenderbuffer()
741{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500742 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000743}
744
Brandon Jones59770802018-04-02 13:18:42 -0700745GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300746{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500747 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300748 if (resultOrError.isError())
749 {
750 handleError(resultOrError.getError());
751 return 0;
752 }
753 return resultOrError.getResult();
754}
755
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000756// Returns an unused framebuffer name
757GLuint Context::createFramebuffer()
758{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500759 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000760}
761
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500762void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000763{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500764 for (int i = 0; i < n; i++)
765 {
766 GLuint handle = mFenceNVHandleAllocator.allocate();
767 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
768 fences[i] = handle;
769 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000770}
771
Yunchao Hea336b902017-08-02 16:05:21 +0800772GLuint Context::createProgramPipeline()
773{
774 return mState.mPipelines->createProgramPipeline();
775}
776
Jiawei Shao385b3e02018-03-21 09:43:28 +0800777GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800778{
779 UNIMPLEMENTED();
780 return 0u;
781}
782
James Darpinian4d9d4832018-03-13 12:43:28 -0700783void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000784{
James Darpinian4d9d4832018-03-13 12:43:28 -0700785 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
786 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000787 {
788 detachBuffer(buffer);
789 }
Jamie Madill893ab082014-05-16 16:56:10 -0400790
James Darpinian4d9d4832018-03-13 12:43:28 -0700791 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000792}
793
794void Context::deleteShader(GLuint shader)
795{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500796 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000797}
798
799void Context::deleteProgram(GLuint program)
800{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500801 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000802}
803
804void Context::deleteTexture(GLuint texture)
805{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500806 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000807 {
808 detachTexture(texture);
809 }
810
Jamie Madill6c1f6712017-02-14 19:08:04 -0500811 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000812}
813
814void Context::deleteRenderbuffer(GLuint renderbuffer)
815{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500816 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000817 {
818 detachRenderbuffer(renderbuffer);
819 }
Jamie Madill893ab082014-05-16 16:56:10 -0400820
Jamie Madill6c1f6712017-02-14 19:08:04 -0500821 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000822}
823
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400824void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400825{
826 // The spec specifies the underlying Fence object is not deleted until all current
827 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
828 // and since our API is currently designed for being called from a single thread, we can delete
829 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400830 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400831}
832
Yunchao Hea336b902017-08-02 16:05:21 +0800833void Context::deleteProgramPipeline(GLuint pipeline)
834{
835 if (mState.mPipelines->getProgramPipeline(pipeline))
836 {
837 detachProgramPipeline(pipeline);
838 }
839
840 mState.mPipelines->deleteObject(this, pipeline);
841}
842
Sami Väisänene45e53b2016-05-25 10:36:04 +0300843void Context::deletePaths(GLuint first, GLsizei range)
844{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500845 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300846}
847
Brandon Jones59770802018-04-02 13:18:42 -0700848bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300849{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500850 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300851 if (pathObj == nullptr)
852 return false;
853
854 return pathObj->hasPathData();
855}
856
Brandon Jones59770802018-04-02 13:18:42 -0700857bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300858{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500859 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300860}
861
Brandon Jones59770802018-04-02 13:18:42 -0700862void Context::pathCommands(GLuint path,
863 GLsizei numCommands,
864 const GLubyte *commands,
865 GLsizei numCoords,
866 GLenum coordType,
867 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300868{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500869 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300870
871 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
872}
873
Jamie Madill007530e2017-12-28 14:27:04 -0500874void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300875{
Jamie Madill007530e2017-12-28 14:27:04 -0500876 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300877
878 switch (pname)
879 {
880 case GL_PATH_STROKE_WIDTH_CHROMIUM:
881 pathObj->setStrokeWidth(value);
882 break;
883 case GL_PATH_END_CAPS_CHROMIUM:
884 pathObj->setEndCaps(static_cast<GLenum>(value));
885 break;
886 case GL_PATH_JOIN_STYLE_CHROMIUM:
887 pathObj->setJoinStyle(static_cast<GLenum>(value));
888 break;
889 case GL_PATH_MITER_LIMIT_CHROMIUM:
890 pathObj->setMiterLimit(value);
891 break;
892 case GL_PATH_STROKE_BOUND_CHROMIUM:
893 pathObj->setStrokeBound(value);
894 break;
895 default:
896 UNREACHABLE();
897 break;
898 }
899}
900
Jamie Madill007530e2017-12-28 14:27:04 -0500901void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300902{
Jamie Madill007530e2017-12-28 14:27:04 -0500903 // TODO(jmadill): Should use proper clamping/casting.
904 pathParameterf(path, pname, static_cast<GLfloat>(value));
905}
906
907void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
908{
909 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300910
911 switch (pname)
912 {
913 case GL_PATH_STROKE_WIDTH_CHROMIUM:
914 *value = pathObj->getStrokeWidth();
915 break;
916 case GL_PATH_END_CAPS_CHROMIUM:
917 *value = static_cast<GLfloat>(pathObj->getEndCaps());
918 break;
919 case GL_PATH_JOIN_STYLE_CHROMIUM:
920 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
921 break;
922 case GL_PATH_MITER_LIMIT_CHROMIUM:
923 *value = pathObj->getMiterLimit();
924 break;
925 case GL_PATH_STROKE_BOUND_CHROMIUM:
926 *value = pathObj->getStrokeBound();
927 break;
928 default:
929 UNREACHABLE();
930 break;
931 }
932}
933
Jamie Madill007530e2017-12-28 14:27:04 -0500934void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
935{
936 GLfloat val = 0.0f;
937 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
938 if (value)
939 *value = static_cast<GLint>(val);
940}
941
Brandon Jones59770802018-04-02 13:18:42 -0700942void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300943{
944 mGLState.setPathStencilFunc(func, ref, mask);
945}
946
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000947void Context::deleteFramebuffer(GLuint framebuffer)
948{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500949 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000950 {
951 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000952 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500953
Jamie Madill6c1f6712017-02-14 19:08:04 -0500954 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000955}
956
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500957void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000958{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500959 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000960 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500961 GLuint fence = fences[i];
962
963 FenceNV *fenceObject = nullptr;
964 if (mFenceNVMap.erase(fence, &fenceObject))
965 {
966 mFenceNVHandleAllocator.release(fence);
967 delete fenceObject;
968 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000969 }
970}
971
Geoff Lang70d0f492015-12-10 17:45:46 -0500972Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000973{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500974 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000975}
976
Geoff Lang70d0f492015-12-10 17:45:46 -0500977Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000978{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500979 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000980}
981
Jamie Madill70b5bb02017-08-28 13:32:37 -0400982Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400983{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400984 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400985}
986
Jamie Madill57a89722013-07-02 11:57:03 -0400987VertexArray *Context::getVertexArray(GLuint handle) const
988{
Jamie Madill96a483b2017-06-27 16:49:21 -0400989 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400990}
991
Jamie Madilldc356042013-07-19 16:36:57 -0400992Sampler *Context::getSampler(GLuint handle) const
993{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500994 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400995}
996
Geoff Langc8058452014-02-03 12:04:11 -0500997TransformFeedback *Context::getTransformFeedback(GLuint handle) const
998{
Jamie Madill96a483b2017-06-27 16:49:21 -0400999 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -05001000}
1001
Yunchao Hea336b902017-08-02 16:05:21 +08001002ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
1003{
1004 return mState.mPipelines->getProgramPipeline(handle);
1005}
1006
Geoff Lang75359662018-04-11 01:42:27 -04001007gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001008{
1009 switch (identifier)
1010 {
1011 case GL_BUFFER:
1012 return getBuffer(name);
1013 case GL_SHADER:
1014 return getShader(name);
1015 case GL_PROGRAM:
1016 return getProgram(name);
1017 case GL_VERTEX_ARRAY:
1018 return getVertexArray(name);
1019 case GL_QUERY:
1020 return getQuery(name);
1021 case GL_TRANSFORM_FEEDBACK:
1022 return getTransformFeedback(name);
1023 case GL_SAMPLER:
1024 return getSampler(name);
1025 case GL_TEXTURE:
1026 return getTexture(name);
1027 case GL_RENDERBUFFER:
1028 return getRenderbuffer(name);
1029 case GL_FRAMEBUFFER:
1030 return getFramebuffer(name);
1031 default:
1032 UNREACHABLE();
1033 return nullptr;
1034 }
1035}
1036
Geoff Lang75359662018-04-11 01:42:27 -04001037gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001038{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001039 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001040}
1041
Martin Radev9d901792016-07-15 15:58:58 +03001042void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1043{
Geoff Lang75359662018-04-11 01:42:27 -04001044 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001045 ASSERT(object != nullptr);
1046
1047 std::string labelName = GetObjectLabelFromPointer(length, label);
1048 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001049
1050 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1051 // specified object is active until we do this.
1052 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001053}
1054
1055void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1056{
Geoff Lang75359662018-04-11 01:42:27 -04001057 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001058 ASSERT(object != nullptr);
1059
1060 std::string labelName = GetObjectLabelFromPointer(length, label);
1061 object->setLabel(labelName);
1062}
1063
1064void Context::getObjectLabel(GLenum identifier,
1065 GLuint name,
1066 GLsizei bufSize,
1067 GLsizei *length,
1068 GLchar *label) const
1069{
Geoff Lang75359662018-04-11 01:42:27 -04001070 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001071 ASSERT(object != nullptr);
1072
1073 const std::string &objectLabel = object->getLabel();
1074 GetObjectLabelBase(objectLabel, bufSize, length, label);
1075}
1076
1077void Context::getObjectPtrLabel(const void *ptr,
1078 GLsizei bufSize,
1079 GLsizei *length,
1080 GLchar *label) const
1081{
Geoff Lang75359662018-04-11 01:42:27 -04001082 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001083 ASSERT(object != nullptr);
1084
1085 const std::string &objectLabel = object->getLabel();
1086 GetObjectLabelBase(objectLabel, bufSize, length, label);
1087}
1088
Jamie Madilldc356042013-07-19 16:36:57 -04001089bool Context::isSampler(GLuint samplerName) const
1090{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001091 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001092}
1093
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001094void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001095{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001096 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001097
Jamie Madilldedd7b92014-11-05 16:30:36 -05001098 if (handle == 0)
1099 {
1100 texture = mZeroTextures[target].get();
1101 }
1102 else
1103 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001104 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001105 }
1106
1107 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001108 mGLState.setSamplerTexture(this, target, texture);
Jamie Madilld84b6732018-09-06 15:54:35 -04001109 mStateCache.onActiveTextureChange(this);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001110}
1111
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001112void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001113{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001114 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1115 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001116 mGLState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001117 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001118}
1119
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001120void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001121{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001122 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1123 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001124 mGLState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001125 mDrawFramebufferObserverBinding.bind(framebuffer);
Jamie Madilld84b6732018-09-06 15:54:35 -04001126 mStateCache.onDrawFramebufferChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001127}
1128
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001129void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001130{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001131 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001132 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001133 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001134 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001135}
1136
Shao80957d92017-02-20 21:25:59 +08001137void Context::bindVertexBuffer(GLuint bindingIndex,
1138 GLuint bufferHandle,
1139 GLintptr offset,
1140 GLsizei stride)
1141{
1142 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001143 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001144 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001145}
1146
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001147void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001148{
Geoff Lang76b10c92014-09-05 16:28:14 -04001149 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001150 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001151 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001152 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001153}
1154
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001155void Context::bindImageTexture(GLuint unit,
1156 GLuint texture,
1157 GLint level,
1158 GLboolean layered,
1159 GLint layer,
1160 GLenum access,
1161 GLenum format)
1162{
1163 Texture *tex = mState.mTextures->getTexture(texture);
1164 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1165}
1166
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001167void Context::useProgram(GLuint program)
1168{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001169 mGLState.setProgram(this, getProgram(program));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001170 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001171}
1172
Jiajia Qin5451d532017-11-16 17:16:34 +08001173void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1174{
1175 UNIMPLEMENTED();
1176}
1177
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001178void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001179{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001180 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001181 TransformFeedback *transformFeedback =
1182 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001183 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Jamie Madilld84b6732018-09-06 15:54:35 -04001184 mStateCache.onTransformFeedbackChange(this);
Geoff Langc8058452014-02-03 12:04:11 -05001185}
1186
Yunchao Hea336b902017-08-02 16:05:21 +08001187void Context::bindProgramPipeline(GLuint pipelineHandle)
1188{
1189 ProgramPipeline *pipeline =
1190 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1191 mGLState.setProgramPipelineBinding(this, pipeline);
1192}
1193
Corentin Wallezad3ae902018-03-09 13:40:42 -05001194void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001195{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001196 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001197 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001198
Geoff Lang5aad9672014-09-08 11:10:42 -04001199 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001200 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001201
1202 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001203 mGLState.setActiveQuery(this, target, queryObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04001204 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001205}
1206
Corentin Wallezad3ae902018-03-09 13:40:42 -05001207void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001208{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001209 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001210 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001211
Jamie Madill5188a272018-07-25 10:53:56 -04001212 handleError(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001213
Geoff Lang5aad9672014-09-08 11:10:42 -04001214 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001215 mGLState.setActiveQuery(this, target, nullptr);
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::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001220{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001221 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001222
1223 Query *queryObject = getQuery(id, true, target);
1224 ASSERT(queryObject);
1225
Jamie Madill5188a272018-07-25 10:53:56 -04001226 handleError(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001227}
1228
Corentin Wallezad3ae902018-03-09 13:40:42 -05001229void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001230{
1231 switch (pname)
1232 {
1233 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001234 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001235 break;
1236 case GL_QUERY_COUNTER_BITS_EXT:
1237 switch (target)
1238 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001239 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001240 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1241 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001242 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001243 params[0] = getExtensions().queryCounterBitsTimestamp;
1244 break;
1245 default:
1246 UNREACHABLE();
1247 params[0] = 0;
1248 break;
1249 }
1250 break;
1251 default:
1252 UNREACHABLE();
1253 return;
1254 }
1255}
1256
Corentin Wallezad3ae902018-03-09 13:40:42 -05001257void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001258 GLenum pname,
1259 GLsizei bufSize,
1260 GLsizei *length,
1261 GLint *params)
1262{
1263 getQueryiv(target, pname, params);
1264}
1265
Geoff Lang2186c382016-10-14 10:54:54 -04001266void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001267{
Jamie Madill5188a272018-07-25 10:53:56 -04001268 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001269}
1270
Brandon Jones59770802018-04-02 13:18:42 -07001271void Context::getQueryObjectivRobust(GLuint id,
1272 GLenum pname,
1273 GLsizei bufSize,
1274 GLsizei *length,
1275 GLint *params)
1276{
1277 getQueryObjectiv(id, pname, params);
1278}
1279
Geoff Lang2186c382016-10-14 10:54:54 -04001280void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001281{
Jamie Madill5188a272018-07-25 10:53:56 -04001282 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001283}
1284
Brandon Jones59770802018-04-02 13:18:42 -07001285void Context::getQueryObjectuivRobust(GLuint id,
1286 GLenum pname,
1287 GLsizei bufSize,
1288 GLsizei *length,
1289 GLuint *params)
1290{
1291 getQueryObjectuiv(id, pname, params);
1292}
1293
Geoff Lang2186c382016-10-14 10:54:54 -04001294void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001295{
Jamie Madill5188a272018-07-25 10:53:56 -04001296 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001297}
1298
Brandon Jones59770802018-04-02 13:18:42 -07001299void Context::getQueryObjecti64vRobust(GLuint id,
1300 GLenum pname,
1301 GLsizei bufSize,
1302 GLsizei *length,
1303 GLint64 *params)
1304{
1305 getQueryObjecti64v(id, pname, params);
1306}
1307
Geoff Lang2186c382016-10-14 10:54:54 -04001308void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001309{
Jamie Madill5188a272018-07-25 10:53:56 -04001310 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001311}
1312
Brandon Jones59770802018-04-02 13:18:42 -07001313void Context::getQueryObjectui64vRobust(GLuint id,
1314 GLenum pname,
1315 GLsizei bufSize,
1316 GLsizei *length,
1317 GLuint64 *params)
1318{
1319 getQueryObjectui64v(id, pname, params);
1320}
1321
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001322Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001323{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001324 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001325}
1326
Jamie Madill2f348d22017-06-05 10:50:59 -04001327FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001328{
Jamie Madill96a483b2017-06-27 16:49:21 -04001329 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001330}
1331
Corentin Wallezad3ae902018-03-09 13:40:42 -05001332Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001333{
Jamie Madill96a483b2017-06-27 16:49:21 -04001334 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001335 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001336 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001337 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001338
1339 Query *query = mQueryMap.query(handle);
1340 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001341 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001342 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001343 query = new Query(mImplementation->createQuery(type), handle);
1344 query->addRef();
1345 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001346 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001347 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001348}
1349
Geoff Lang70d0f492015-12-10 17:45:46 -05001350Query *Context::getQuery(GLuint handle) const
1351{
Jamie Madill96a483b2017-06-27 16:49:21 -04001352 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001353}
1354
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001355Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001356{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001357 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1358 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001359}
1360
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001361Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001362{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001363 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001364}
1365
Geoff Lang492a7e42014-11-05 13:27:06 -05001366Compiler *Context::getCompiler() const
1367{
Jamie Madill2f348d22017-06-05 10:50:59 -04001368 if (mCompiler.get() == nullptr)
1369 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001370 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001371 }
1372 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001373}
1374
Jamie Madillc1d770e2017-04-13 17:31:24 -04001375void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001376{
1377 switch (pname)
1378 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001379 case GL_SHADER_COMPILER:
1380 *params = GL_TRUE;
1381 break;
1382 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1383 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1384 break;
1385 default:
1386 mGLState.getBooleanv(pname, params);
1387 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001388 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001389}
1390
Jamie Madillc1d770e2017-04-13 17:31:24 -04001391void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001392{
Shannon Woods53a94a82014-06-24 15:20:36 -04001393 // Queries about context capabilities and maximums are answered by Context.
1394 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001395 switch (pname)
1396 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001397 case GL_ALIASED_LINE_WIDTH_RANGE:
1398 params[0] = mCaps.minAliasedLineWidth;
1399 params[1] = mCaps.maxAliasedLineWidth;
1400 break;
1401 case GL_ALIASED_POINT_SIZE_RANGE:
1402 params[0] = mCaps.minAliasedPointSize;
1403 params[1] = mCaps.maxAliasedPointSize;
1404 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001405 case GL_SMOOTH_POINT_SIZE_RANGE:
1406 params[0] = mCaps.minSmoothPointSize;
1407 params[1] = mCaps.maxSmoothPointSize;
1408 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001409 case GL_SMOOTH_LINE_WIDTH_RANGE:
1410 params[0] = mCaps.minSmoothLineWidth;
1411 params[1] = mCaps.maxSmoothLineWidth;
1412 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001413 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1414 ASSERT(mExtensions.textureFilterAnisotropic);
1415 *params = mExtensions.maxTextureAnisotropy;
1416 break;
1417 case GL_MAX_TEXTURE_LOD_BIAS:
1418 *params = mCaps.maxLODBias;
1419 break;
1420
1421 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1422 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1423 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001424 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1425 // GLES1 constants for modelview/projection matrix.
1426 if (getClientVersion() < Version(2, 0))
1427 {
1428 mGLState.getFloatv(pname, params);
1429 }
1430 else
1431 {
1432 ASSERT(mExtensions.pathRendering);
1433 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1434 memcpy(params, m, 16 * sizeof(GLfloat));
1435 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001436 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001437 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001438
Jamie Madill231c7f52017-04-26 13:45:37 -04001439 default:
1440 mGLState.getFloatv(pname, params);
1441 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001442 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001443}
1444
Jamie Madillc1d770e2017-04-13 17:31:24 -04001445void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001446{
Shannon Woods53a94a82014-06-24 15:20:36 -04001447 // Queries about context capabilities and maximums are answered by Context.
1448 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001449
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001450 switch (pname)
1451 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001452 case GL_MAX_VERTEX_ATTRIBS:
1453 *params = mCaps.maxVertexAttributes;
1454 break;
1455 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1456 *params = mCaps.maxVertexUniformVectors;
1457 break;
1458 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001459 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001460 break;
1461 case GL_MAX_VARYING_VECTORS:
1462 *params = mCaps.maxVaryingVectors;
1463 break;
1464 case GL_MAX_VARYING_COMPONENTS:
1465 *params = mCaps.maxVertexOutputComponents;
1466 break;
1467 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1468 *params = mCaps.maxCombinedTextureImageUnits;
1469 break;
1470 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001471 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001472 break;
1473 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001474 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001475 break;
1476 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1477 *params = mCaps.maxFragmentUniformVectors;
1478 break;
1479 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001480 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001481 break;
1482 case GL_MAX_RENDERBUFFER_SIZE:
1483 *params = mCaps.maxRenderbufferSize;
1484 break;
1485 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1486 *params = mCaps.maxColorAttachments;
1487 break;
1488 case GL_MAX_DRAW_BUFFERS_EXT:
1489 *params = mCaps.maxDrawBuffers;
1490 break;
1491 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1492 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1493 case GL_SUBPIXEL_BITS:
1494 *params = 4;
1495 break;
1496 case GL_MAX_TEXTURE_SIZE:
1497 *params = mCaps.max2DTextureSize;
1498 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001499 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1500 *params = mCaps.maxRectangleTextureSize;
1501 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001502 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1503 *params = mCaps.maxCubeMapTextureSize;
1504 break;
1505 case GL_MAX_3D_TEXTURE_SIZE:
1506 *params = mCaps.max3DTextureSize;
1507 break;
1508 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1509 *params = mCaps.maxArrayTextureLayers;
1510 break;
1511 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1512 *params = mCaps.uniformBufferOffsetAlignment;
1513 break;
1514 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1515 *params = mCaps.maxUniformBufferBindings;
1516 break;
1517 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001518 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001519 break;
1520 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001521 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001522 break;
1523 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1524 *params = mCaps.maxCombinedTextureImageUnits;
1525 break;
1526 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1527 *params = mCaps.maxVertexOutputComponents;
1528 break;
1529 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1530 *params = mCaps.maxFragmentInputComponents;
1531 break;
1532 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1533 *params = mCaps.minProgramTexelOffset;
1534 break;
1535 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1536 *params = mCaps.maxProgramTexelOffset;
1537 break;
1538 case GL_MAJOR_VERSION:
1539 *params = getClientVersion().major;
1540 break;
1541 case GL_MINOR_VERSION:
1542 *params = getClientVersion().minor;
1543 break;
1544 case GL_MAX_ELEMENTS_INDICES:
1545 *params = mCaps.maxElementsIndices;
1546 break;
1547 case GL_MAX_ELEMENTS_VERTICES:
1548 *params = mCaps.maxElementsVertices;
1549 break;
1550 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1551 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1552 break;
1553 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1554 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1555 break;
1556 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1557 *params = mCaps.maxTransformFeedbackSeparateComponents;
1558 break;
1559 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1560 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1561 break;
1562 case GL_MAX_SAMPLES_ANGLE:
1563 *params = mCaps.maxSamples;
1564 break;
1565 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001566 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001567 params[0] = mCaps.maxViewportWidth;
1568 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001569 }
1570 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001571 case GL_COMPRESSED_TEXTURE_FORMATS:
1572 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1573 params);
1574 break;
1575 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1576 *params = mResetStrategy;
1577 break;
1578 case GL_NUM_SHADER_BINARY_FORMATS:
1579 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1580 break;
1581 case GL_SHADER_BINARY_FORMATS:
1582 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1583 break;
1584 case GL_NUM_PROGRAM_BINARY_FORMATS:
1585 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1586 break;
1587 case GL_PROGRAM_BINARY_FORMATS:
1588 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1589 break;
1590 case GL_NUM_EXTENSIONS:
1591 *params = static_cast<GLint>(mExtensionStrings.size());
1592 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001593
Jamie Madill231c7f52017-04-26 13:45:37 -04001594 // GL_KHR_debug
1595 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1596 *params = mExtensions.maxDebugMessageLength;
1597 break;
1598 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1599 *params = mExtensions.maxDebugLoggedMessages;
1600 break;
1601 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1602 *params = mExtensions.maxDebugGroupStackDepth;
1603 break;
1604 case GL_MAX_LABEL_LENGTH:
1605 *params = mExtensions.maxLabelLength;
1606 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001607
Martin Radeve5285d22017-07-14 16:23:53 +03001608 // GL_ANGLE_multiview
1609 case GL_MAX_VIEWS_ANGLE:
1610 *params = mExtensions.maxViews;
1611 break;
1612
Jamie Madill231c7f52017-04-26 13:45:37 -04001613 // GL_EXT_disjoint_timer_query
1614 case GL_GPU_DISJOINT_EXT:
1615 *params = mImplementation->getGPUDisjoint();
1616 break;
1617 case GL_MAX_FRAMEBUFFER_WIDTH:
1618 *params = mCaps.maxFramebufferWidth;
1619 break;
1620 case GL_MAX_FRAMEBUFFER_HEIGHT:
1621 *params = mCaps.maxFramebufferHeight;
1622 break;
1623 case GL_MAX_FRAMEBUFFER_SAMPLES:
1624 *params = mCaps.maxFramebufferSamples;
1625 break;
1626 case GL_MAX_SAMPLE_MASK_WORDS:
1627 *params = mCaps.maxSampleMaskWords;
1628 break;
1629 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1630 *params = mCaps.maxColorTextureSamples;
1631 break;
1632 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1633 *params = mCaps.maxDepthTextureSamples;
1634 break;
1635 case GL_MAX_INTEGER_SAMPLES:
1636 *params = mCaps.maxIntegerSamples;
1637 break;
1638 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1639 *params = mCaps.maxVertexAttribRelativeOffset;
1640 break;
1641 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1642 *params = mCaps.maxVertexAttribBindings;
1643 break;
1644 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1645 *params = mCaps.maxVertexAttribStride;
1646 break;
1647 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001648 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001649 break;
1650 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001651 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001652 break;
1653 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001654 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001655 break;
1656 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001657 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001658 break;
1659 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001660 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001661 break;
1662 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001663 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001664 break;
1665 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001666 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001667 break;
1668 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001669 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001670 break;
1671 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1672 *params = mCaps.minProgramTextureGatherOffset;
1673 break;
1674 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1675 *params = mCaps.maxProgramTextureGatherOffset;
1676 break;
1677 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1678 *params = mCaps.maxComputeWorkGroupInvocations;
1679 break;
1680 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001681 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001682 break;
1683 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001684 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001685 break;
1686 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1687 *params = mCaps.maxComputeSharedMemorySize;
1688 break;
1689 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001690 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001691 break;
1692 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001693 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001694 break;
1695 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001696 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001697 break;
1698 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001699 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001700 break;
1701 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001702 *params =
1703 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001704 break;
1705 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001706 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001707 break;
1708 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1709 *params = mCaps.maxCombinedShaderOutputResources;
1710 break;
1711 case GL_MAX_UNIFORM_LOCATIONS:
1712 *params = mCaps.maxUniformLocations;
1713 break;
1714 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1715 *params = mCaps.maxAtomicCounterBufferBindings;
1716 break;
1717 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1718 *params = mCaps.maxAtomicCounterBufferSize;
1719 break;
1720 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1721 *params = mCaps.maxCombinedAtomicCounterBuffers;
1722 break;
1723 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1724 *params = mCaps.maxCombinedAtomicCounters;
1725 break;
1726 case GL_MAX_IMAGE_UNITS:
1727 *params = mCaps.maxImageUnits;
1728 break;
1729 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1730 *params = mCaps.maxCombinedImageUniforms;
1731 break;
1732 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1733 *params = mCaps.maxShaderStorageBufferBindings;
1734 break;
1735 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1736 *params = mCaps.maxCombinedShaderStorageBlocks;
1737 break;
1738 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1739 *params = mCaps.shaderStorageBufferOffsetAlignment;
1740 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001741
1742 // GL_EXT_geometry_shader
1743 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1744 *params = mCaps.maxFramebufferLayers;
1745 break;
1746 case GL_LAYER_PROVOKING_VERTEX_EXT:
1747 *params = mCaps.layerProvokingVertex;
1748 break;
1749 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001750 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001751 break;
1752 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001753 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001754 break;
1755 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001756 *params =
1757 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001758 break;
1759 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1760 *params = mCaps.maxGeometryInputComponents;
1761 break;
1762 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1763 *params = mCaps.maxGeometryOutputComponents;
1764 break;
1765 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1766 *params = mCaps.maxGeometryOutputVertices;
1767 break;
1768 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1769 *params = mCaps.maxGeometryTotalOutputComponents;
1770 break;
1771 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1772 *params = mCaps.maxGeometryShaderInvocations;
1773 break;
1774 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001775 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001776 break;
1777 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001778 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001779 break;
1780 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001781 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001782 break;
1783 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001784 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001785 break;
1786 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001787 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001788 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001789 // GLES1 emulation: Caps queries
1790 case GL_MAX_TEXTURE_UNITS:
1791 *params = mCaps.maxMultitextureUnits;
1792 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001793 case GL_MAX_MODELVIEW_STACK_DEPTH:
1794 *params = mCaps.maxModelviewMatrixStackDepth;
1795 break;
1796 case GL_MAX_PROJECTION_STACK_DEPTH:
1797 *params = mCaps.maxProjectionMatrixStackDepth;
1798 break;
1799 case GL_MAX_TEXTURE_STACK_DEPTH:
1800 *params = mCaps.maxTextureMatrixStackDepth;
1801 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001802 case GL_MAX_LIGHTS:
1803 *params = mCaps.maxLights;
1804 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001805 case GL_MAX_CLIP_PLANES:
1806 *params = mCaps.maxClipPlanes;
1807 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001808 // GLES1 emulation: Vertex attribute queries
1809 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1810 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1811 case GL_COLOR_ARRAY_BUFFER_BINDING:
1812 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1813 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1814 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1815 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1816 break;
1817 case GL_VERTEX_ARRAY_STRIDE:
1818 case GL_NORMAL_ARRAY_STRIDE:
1819 case GL_COLOR_ARRAY_STRIDE:
1820 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1821 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1822 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1823 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1824 break;
1825 case GL_VERTEX_ARRAY_SIZE:
1826 case GL_COLOR_ARRAY_SIZE:
1827 case GL_TEXTURE_COORD_ARRAY_SIZE:
1828 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1829 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1830 break;
1831 case GL_VERTEX_ARRAY_TYPE:
1832 case GL_COLOR_ARRAY_TYPE:
1833 case GL_NORMAL_ARRAY_TYPE:
1834 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1835 case GL_TEXTURE_COORD_ARRAY_TYPE:
1836 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1837 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1838 break;
1839
jchen1082af6202018-06-22 10:59:52 +08001840 // GL_KHR_parallel_shader_compile
1841 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1842 *params = mGLState.getMaxShaderCompilerThreads();
1843 break;
1844
Jamie Madill231c7f52017-04-26 13:45:37 -04001845 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001846 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001847 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001848 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001849}
1850
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001851void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001852{
Shannon Woods53a94a82014-06-24 15:20:36 -04001853 // Queries about context capabilities and maximums are answered by Context.
1854 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001855 switch (pname)
1856 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001857 case GL_MAX_ELEMENT_INDEX:
1858 *params = mCaps.maxElementIndex;
1859 break;
1860 case GL_MAX_UNIFORM_BLOCK_SIZE:
1861 *params = mCaps.maxUniformBlockSize;
1862 break;
1863 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001864 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001865 break;
1866 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001867 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001868 break;
1869 case GL_MAX_SERVER_WAIT_TIMEOUT:
1870 *params = mCaps.maxServerWaitTimeout;
1871 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001872
Jamie Madill231c7f52017-04-26 13:45:37 -04001873 // GL_EXT_disjoint_timer_query
1874 case GL_TIMESTAMP_EXT:
1875 *params = mImplementation->getTimestamp();
1876 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001877
Jamie Madill231c7f52017-04-26 13:45:37 -04001878 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1879 *params = mCaps.maxShaderStorageBlockSize;
1880 break;
1881 default:
1882 UNREACHABLE();
1883 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001884 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001885}
1886
Geoff Lang70d0f492015-12-10 17:45:46 -05001887void Context::getPointerv(GLenum pname, void **params) const
1888{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001889 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001890}
1891
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001892void Context::getPointervRobustANGLERobust(GLenum pname,
1893 GLsizei bufSize,
1894 GLsizei *length,
1895 void **params)
1896{
1897 UNIMPLEMENTED();
1898}
1899
Martin Radev66fb8202016-07-28 11:45:20 +03001900void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001901{
Shannon Woods53a94a82014-06-24 15:20:36 -04001902 // Queries about context capabilities and maximums are answered by Context.
1903 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001904
1905 GLenum nativeType;
1906 unsigned int numParams;
1907 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1908 ASSERT(queryStatus);
1909
1910 if (nativeType == GL_INT)
1911 {
1912 switch (target)
1913 {
1914 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1915 ASSERT(index < 3u);
1916 *data = mCaps.maxComputeWorkGroupCount[index];
1917 break;
1918 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1919 ASSERT(index < 3u);
1920 *data = mCaps.maxComputeWorkGroupSize[index];
1921 break;
1922 default:
1923 mGLState.getIntegeri_v(target, index, data);
1924 }
1925 }
1926 else
1927 {
1928 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1929 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001930}
1931
Brandon Jones59770802018-04-02 13:18:42 -07001932void Context::getIntegeri_vRobust(GLenum target,
1933 GLuint index,
1934 GLsizei bufSize,
1935 GLsizei *length,
1936 GLint *data)
1937{
1938 getIntegeri_v(target, index, data);
1939}
1940
Martin Radev66fb8202016-07-28 11:45:20 +03001941void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001942{
Shannon Woods53a94a82014-06-24 15:20:36 -04001943 // Queries about context capabilities and maximums are answered by Context.
1944 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001945
1946 GLenum nativeType;
1947 unsigned int numParams;
1948 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1949 ASSERT(queryStatus);
1950
1951 if (nativeType == GL_INT_64_ANGLEX)
1952 {
1953 mGLState.getInteger64i_v(target, index, data);
1954 }
1955 else
1956 {
1957 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1958 }
1959}
1960
Brandon Jones59770802018-04-02 13:18:42 -07001961void Context::getInteger64i_vRobust(GLenum target,
1962 GLuint index,
1963 GLsizei bufSize,
1964 GLsizei *length,
1965 GLint64 *data)
1966{
1967 getInteger64i_v(target, index, data);
1968}
1969
Martin Radev66fb8202016-07-28 11:45:20 +03001970void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1971{
1972 // Queries about context capabilities and maximums are answered by Context.
1973 // Queries about current GL state values are answered by State.
1974
1975 GLenum nativeType;
1976 unsigned int numParams;
1977 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1978 ASSERT(queryStatus);
1979
1980 if (nativeType == GL_BOOL)
1981 {
1982 mGLState.getBooleani_v(target, index, data);
1983 }
1984 else
1985 {
1986 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1987 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001988}
1989
Brandon Jones59770802018-04-02 13:18:42 -07001990void Context::getBooleani_vRobust(GLenum target,
1991 GLuint index,
1992 GLsizei bufSize,
1993 GLsizei *length,
1994 GLboolean *data)
1995{
1996 getBooleani_v(target, index, data);
1997}
1998
Corentin Wallez336129f2017-10-17 15:55:40 -04001999void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002000{
2001 Buffer *buffer = mGLState.getTargetBuffer(target);
2002 QueryBufferParameteriv(buffer, pname, params);
2003}
2004
Brandon Jones59770802018-04-02 13:18:42 -07002005void Context::getBufferParameterivRobust(BufferBinding target,
2006 GLenum pname,
2007 GLsizei bufSize,
2008 GLsizei *length,
2009 GLint *params)
2010{
2011 getBufferParameteriv(target, pname, params);
2012}
2013
He Yunchao010e4db2017-03-03 14:22:06 +08002014void Context::getFramebufferAttachmentParameteriv(GLenum target,
2015 GLenum attachment,
2016 GLenum pname,
2017 GLint *params)
2018{
2019 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002020 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002021}
2022
Brandon Jones59770802018-04-02 13:18:42 -07002023void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2024 GLenum attachment,
2025 GLenum pname,
2026 GLsizei bufSize,
2027 GLsizei *length,
2028 GLint *params)
2029{
2030 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2031}
2032
He Yunchao010e4db2017-03-03 14:22:06 +08002033void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2034{
2035 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2036 QueryRenderbufferiv(this, renderbuffer, pname, params);
2037}
2038
Brandon Jones59770802018-04-02 13:18:42 -07002039void Context::getRenderbufferParameterivRobust(GLenum target,
2040 GLenum pname,
2041 GLsizei bufSize,
2042 GLsizei *length,
2043 GLint *params)
2044{
2045 getRenderbufferParameteriv(target, pname, params);
2046}
2047
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002048void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002049{
2050 Texture *texture = getTargetTexture(target);
2051 QueryTexParameterfv(texture, pname, params);
2052}
2053
Brandon Jones59770802018-04-02 13:18:42 -07002054void Context::getTexParameterfvRobust(TextureType target,
2055 GLenum pname,
2056 GLsizei bufSize,
2057 GLsizei *length,
2058 GLfloat *params)
2059{
2060 getTexParameterfv(target, pname, params);
2061}
2062
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002063void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002064{
2065 Texture *texture = getTargetTexture(target);
2066 QueryTexParameteriv(texture, pname, params);
2067}
Jiajia Qin5451d532017-11-16 17:16:34 +08002068
Brandon Jones59770802018-04-02 13:18:42 -07002069void Context::getTexParameterivRobust(TextureType target,
2070 GLenum pname,
2071 GLsizei bufSize,
2072 GLsizei *length,
2073 GLint *params)
2074{
2075 getTexParameteriv(target, pname, params);
2076}
2077
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002078void Context::getTexParameterIivRobust(TextureType target,
2079 GLenum pname,
2080 GLsizei bufSize,
2081 GLsizei *length,
2082 GLint *params)
2083{
2084 UNIMPLEMENTED();
2085}
2086
2087void Context::getTexParameterIuivRobust(TextureType target,
2088 GLenum pname,
2089 GLsizei bufSize,
2090 GLsizei *length,
2091 GLuint *params)
2092{
2093 UNIMPLEMENTED();
2094}
2095
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002096void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002097{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002098 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002099 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002100}
2101
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002102void Context::getTexLevelParameterivRobust(TextureTarget target,
2103 GLint level,
2104 GLenum pname,
2105 GLsizei bufSize,
2106 GLsizei *length,
2107 GLint *params)
2108{
2109 UNIMPLEMENTED();
2110}
2111
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002112void Context::getTexLevelParameterfv(TextureTarget target,
2113 GLint level,
2114 GLenum pname,
2115 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002116{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002117 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002118 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002119}
2120
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002121void Context::getTexLevelParameterfvRobust(TextureTarget target,
2122 GLint level,
2123 GLenum pname,
2124 GLsizei bufSize,
2125 GLsizei *length,
2126 GLfloat *params)
2127{
2128 UNIMPLEMENTED();
2129}
2130
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002131void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002132{
2133 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002134 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002135 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002136}
2137
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002138void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002139{
2140 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002141 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002142 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002143}
2144
Brandon Jones59770802018-04-02 13:18:42 -07002145void Context::texParameterfvRobust(TextureType target,
2146 GLenum pname,
2147 GLsizei bufSize,
2148 const GLfloat *params)
2149{
2150 texParameterfv(target, pname, params);
2151}
2152
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002153void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002154{
2155 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002156 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002157 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002158}
2159
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002160void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002161{
2162 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002163 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002164 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002165}
2166
Brandon Jones59770802018-04-02 13:18:42 -07002167void Context::texParameterivRobust(TextureType target,
2168 GLenum pname,
2169 GLsizei bufSize,
2170 const GLint *params)
2171{
2172 texParameteriv(target, pname, params);
2173}
2174
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002175void Context::texParameterIivRobust(TextureType target,
2176 GLenum pname,
2177 GLsizei bufSize,
2178 const GLint *params)
2179{
2180 UNIMPLEMENTED();
2181}
2182
2183void Context::texParameterIuivRobust(TextureType target,
2184 GLenum pname,
2185 GLsizei bufSize,
2186 const GLuint *params)
2187{
2188 UNIMPLEMENTED();
2189}
2190
Jamie Madill493f9572018-05-24 19:52:15 -04002191void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002192{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002193 // No-op if count draws no primitives for given mode
2194 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002195 {
2196 return;
2197 }
2198
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002199 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002200 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002201 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002202}
2203
Jamie Madill493f9572018-05-24 19:52:15 -04002204void Context::drawArraysInstanced(PrimitiveMode mode,
2205 GLint first,
2206 GLsizei count,
2207 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002208{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002209 // No-op if count draws no primitives for given mode
2210 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002211 {
2212 return;
2213 }
2214
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002215 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002216 ANGLE_CONTEXT_TRY(
2217 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002218 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2219 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002220}
2221
Jamie Madill493f9572018-05-24 19:52:15 -04002222void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002223{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002224 // No-op if count draws no primitives for given mode
2225 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002226 {
2227 return;
2228 }
2229
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002230 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002231 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002232}
2233
Jamie Madill493f9572018-05-24 19:52:15 -04002234void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002235 GLsizei count,
2236 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002237 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002238 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002239{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002240 // No-op if count draws no primitives for given mode
2241 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002242 {
2243 return;
2244 }
2245
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002246 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002247 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002248 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002249}
2250
Jamie Madill493f9572018-05-24 19:52:15 -04002251void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002252 GLuint start,
2253 GLuint end,
2254 GLsizei count,
2255 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002256 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002257{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002258 // No-op if count draws no primitives for given mode
2259 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002260 {
2261 return;
2262 }
2263
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002264 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002265 ANGLE_CONTEXT_TRY(
2266 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002267}
2268
Jamie Madill493f9572018-05-24 19:52:15 -04002269void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002270{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002271 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002272 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002273}
2274
Jamie Madill493f9572018-05-24 19:52:15 -04002275void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002276{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002277 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002278 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002279}
2280
Jamie Madill675fe712016-12-19 13:07:54 -05002281void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002282{
Jamie Madillafa02a22017-11-23 12:57:38 -05002283 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002284}
2285
Jamie Madill675fe712016-12-19 13:07:54 -05002286void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002287{
Jamie Madillafa02a22017-11-23 12:57:38 -05002288 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002289}
2290
Austin Kinross6ee1e782015-05-29 17:05:37 -07002291void Context::insertEventMarker(GLsizei length, const char *marker)
2292{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002293 ASSERT(mImplementation);
2294 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002295}
2296
2297void Context::pushGroupMarker(GLsizei length, const char *marker)
2298{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002299 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002300
2301 if (marker == nullptr)
2302 {
2303 // From the EXT_debug_marker spec,
2304 // "If <marker> is null then an empty string is pushed on the stack."
2305 mImplementation->pushGroupMarker(length, "");
2306 }
2307 else
2308 {
2309 mImplementation->pushGroupMarker(length, marker);
2310 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002311}
2312
2313void Context::popGroupMarker()
2314{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002315 ASSERT(mImplementation);
2316 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002317}
2318
Geoff Langd8605522016-04-13 10:19:12 -04002319void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2320{
2321 Program *programObject = getProgram(program);
2322 ASSERT(programObject);
2323
2324 programObject->bindUniformLocation(location, name);
2325}
2326
Brandon Jones59770802018-04-02 13:18:42 -07002327void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002328{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002329 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002330}
2331
Brandon Jones59770802018-04-02 13:18:42 -07002332void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002333{
2334 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2335}
2336
Brandon Jones59770802018-04-02 13:18:42 -07002337void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002338{
2339 GLfloat I[16];
2340 angle::Matrix<GLfloat>::setToIdentity(I);
2341
2342 mGLState.loadPathRenderingMatrix(matrixMode, I);
2343}
2344
2345void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2346{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002347 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002348 if (!pathObj)
2349 return;
2350
Geoff Lang9bf86f02018-07-26 11:46:34 -04002351 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002352
2353 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2354}
2355
2356void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2357{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002358 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002359 if (!pathObj)
2360 return;
2361
Geoff Lang9bf86f02018-07-26 11:46:34 -04002362 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002363
2364 mImplementation->stencilStrokePath(pathObj, reference, mask);
2365}
2366
2367void Context::coverFillPath(GLuint path, GLenum coverMode)
2368{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002369 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002370 if (!pathObj)
2371 return;
2372
Geoff Lang9bf86f02018-07-26 11:46:34 -04002373 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002374
2375 mImplementation->coverFillPath(pathObj, coverMode);
2376}
2377
2378void Context::coverStrokePath(GLuint path, GLenum coverMode)
2379{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002380 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002381 if (!pathObj)
2382 return;
2383
Geoff Lang9bf86f02018-07-26 11:46:34 -04002384 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002385
2386 mImplementation->coverStrokePath(pathObj, coverMode);
2387}
2388
2389void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2390{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002391 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002392 if (!pathObj)
2393 return;
2394
Geoff Lang9bf86f02018-07-26 11:46:34 -04002395 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002396
2397 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2398}
2399
2400void Context::stencilThenCoverStrokePath(GLuint path,
2401 GLint reference,
2402 GLuint mask,
2403 GLenum coverMode)
2404{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002405 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002406 if (!pathObj)
2407 return;
2408
Geoff Lang9bf86f02018-07-26 11:46:34 -04002409 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002410
2411 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2412}
2413
Sami Väisänend59ca052016-06-21 16:10:00 +03002414void Context::coverFillPathInstanced(GLsizei numPaths,
2415 GLenum pathNameType,
2416 const void *paths,
2417 GLuint pathBase,
2418 GLenum coverMode,
2419 GLenum transformType,
2420 const GLfloat *transformValues)
2421{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002422 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002423
Geoff Lang9bf86f02018-07-26 11:46:34 -04002424 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002425
2426 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2427}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002428
Sami Väisänend59ca052016-06-21 16:10:00 +03002429void Context::coverStrokePathInstanced(GLsizei numPaths,
2430 GLenum pathNameType,
2431 const void *paths,
2432 GLuint pathBase,
2433 GLenum coverMode,
2434 GLenum transformType,
2435 const GLfloat *transformValues)
2436{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002437 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002438
2439 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002440 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002441
2442 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2443 transformValues);
2444}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002445
Sami Väisänend59ca052016-06-21 16:10:00 +03002446void Context::stencilFillPathInstanced(GLsizei numPaths,
2447 GLenum pathNameType,
2448 const void *paths,
2449 GLuint pathBase,
2450 GLenum fillMode,
2451 GLuint mask,
2452 GLenum transformType,
2453 const GLfloat *transformValues)
2454{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002455 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002456
2457 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002458 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002459
2460 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2461 transformValues);
2462}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002463
Sami Väisänend59ca052016-06-21 16:10:00 +03002464void Context::stencilStrokePathInstanced(GLsizei numPaths,
2465 GLenum pathNameType,
2466 const void *paths,
2467 GLuint pathBase,
2468 GLint reference,
2469 GLuint mask,
2470 GLenum transformType,
2471 const GLfloat *transformValues)
2472{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002473 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002474
Geoff Lang9bf86f02018-07-26 11:46:34 -04002475 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002476
2477 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2478 transformValues);
2479}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002480
Sami Väisänend59ca052016-06-21 16:10:00 +03002481void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2482 GLenum pathNameType,
2483 const void *paths,
2484 GLuint pathBase,
2485 GLenum fillMode,
2486 GLuint mask,
2487 GLenum coverMode,
2488 GLenum transformType,
2489 const GLfloat *transformValues)
2490{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002491 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002492
Geoff Lang9bf86f02018-07-26 11:46:34 -04002493 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002494
2495 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2496 transformType, transformValues);
2497}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002498
Sami Väisänend59ca052016-06-21 16:10:00 +03002499void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2500 GLenum pathNameType,
2501 const void *paths,
2502 GLuint pathBase,
2503 GLint reference,
2504 GLuint mask,
2505 GLenum coverMode,
2506 GLenum transformType,
2507 const GLfloat *transformValues)
2508{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002509 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002510
Geoff Lang9bf86f02018-07-26 11:46:34 -04002511 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002512
2513 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2514 transformType, transformValues);
2515}
2516
Sami Väisänen46eaa942016-06-29 10:26:37 +03002517void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2518{
2519 auto *programObject = getProgram(program);
2520
2521 programObject->bindFragmentInputLocation(location, name);
2522}
2523
2524void Context::programPathFragmentInputGen(GLuint program,
2525 GLint location,
2526 GLenum genMode,
2527 GLint components,
2528 const GLfloat *coeffs)
2529{
2530 auto *programObject = getProgram(program);
2531
jchen103fd614d2018-08-13 12:21:58 +08002532 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002533}
2534
jchen1015015f72017-03-16 13:54:21 +08002535GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2536{
jchen10fd7c3b52017-03-21 15:36:03 +08002537 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002538 return QueryProgramResourceIndex(programObject, programInterface, name);
2539}
2540
jchen10fd7c3b52017-03-21 15:36:03 +08002541void Context::getProgramResourceName(GLuint program,
2542 GLenum programInterface,
2543 GLuint index,
2544 GLsizei bufSize,
2545 GLsizei *length,
2546 GLchar *name)
2547{
2548 const auto *programObject = getProgram(program);
2549 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2550}
2551
jchen10191381f2017-04-11 13:59:04 +08002552GLint Context::getProgramResourceLocation(GLuint program,
2553 GLenum programInterface,
2554 const GLchar *name)
2555{
2556 const auto *programObject = getProgram(program);
2557 return QueryProgramResourceLocation(programObject, programInterface, name);
2558}
2559
jchen10880683b2017-04-12 16:21:55 +08002560void Context::getProgramResourceiv(GLuint program,
2561 GLenum programInterface,
2562 GLuint index,
2563 GLsizei propCount,
2564 const GLenum *props,
2565 GLsizei bufSize,
2566 GLsizei *length,
2567 GLint *params)
2568{
2569 const auto *programObject = getProgram(program);
2570 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2571 length, params);
2572}
2573
jchen10d9cd7b72017-08-30 15:04:25 +08002574void Context::getProgramInterfaceiv(GLuint program,
2575 GLenum programInterface,
2576 GLenum pname,
2577 GLint *params)
2578{
2579 const auto *programObject = getProgram(program);
2580 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2581}
2582
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002583void Context::getProgramInterfaceivRobust(GLuint program,
2584 GLenum programInterface,
2585 GLenum pname,
2586 GLsizei bufSize,
2587 GLsizei *length,
2588 GLint *params)
2589{
2590 UNIMPLEMENTED();
2591}
2592
Jamie Madill306b6c12018-07-27 08:12:49 -04002593void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002594{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002595 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002596}
2597
2598// Get one of the recorded errors and clear its flag, if any.
2599// [OpenGL ES 2.0.24] section 2.5 page 13.
2600GLenum Context::getError()
2601{
Geoff Langda5777c2014-07-11 09:52:58 -04002602 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002603 {
Geoff Langda5777c2014-07-11 09:52:58 -04002604 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002605 }
Geoff Langda5777c2014-07-11 09:52:58 -04002606 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002607 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002608 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002609 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002610}
2611
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002612// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002613void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002614{
2615 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002616 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002617 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002618 mContextLostForced = true;
2619 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002620 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002621}
2622
Jamie Madill427064d2018-04-13 16:20:34 -04002623bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002624{
2625 return mContextLost;
2626}
2627
Jamie Madillfa920eb2018-01-04 11:45:50 -05002628GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002629{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002630 // Even if the application doesn't want to know about resets, we want to know
2631 // as it will allow us to skip all the calls.
2632 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002633 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002634 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002635 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002636 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002637 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002638
2639 // EXT_robustness, section 2.6: If the reset notification behavior is
2640 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2641 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2642 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002643 }
2644
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002645 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2646 // status should be returned at least once, and GL_NO_ERROR should be returned
2647 // once the device has finished resetting.
2648 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002649 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002650 ASSERT(mResetStatus == GL_NO_ERROR);
2651 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002652
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002653 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002654 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002655 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002656 }
2657 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002658 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002659 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002660 // If markContextLost was used to mark the context lost then
2661 // assume that is not recoverable, and continue to report the
2662 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002663 mResetStatus = mImplementation->getResetStatus();
2664 }
Jamie Madill893ab082014-05-16 16:56:10 -04002665
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002666 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002667}
2668
2669bool Context::isResetNotificationEnabled()
2670{
2671 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2672}
2673
Corentin Walleze3b10e82015-05-20 11:06:25 -04002674const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002675{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002676 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002677}
2678
2679EGLenum Context::getClientType() const
2680{
2681 return mClientType;
2682}
2683
2684EGLenum Context::getRenderBuffer() const
2685{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002686 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2687 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002688 {
2689 return EGL_NONE;
2690 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002691
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002692 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002693 ASSERT(backAttachment != nullptr);
2694 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002695}
2696
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002697VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002698{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002699 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002700 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2701 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002702 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002703 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2704 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002705
Jamie Madill96a483b2017-06-27 16:49:21 -04002706 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002707 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002708
2709 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002710}
2711
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002712TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002713{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002714 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002715 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2716 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002717 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002718 transformFeedback =
2719 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002720 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002721 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002722 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002723
2724 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002725}
2726
2727bool Context::isVertexArrayGenerated(GLuint vertexArray)
2728{
Jamie Madill96a483b2017-06-27 16:49:21 -04002729 ASSERT(mVertexArrayMap.contains(0));
2730 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002731}
2732
2733bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2734{
Jamie Madill96a483b2017-06-27 16:49:21 -04002735 ASSERT(mTransformFeedbackMap.contains(0));
2736 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002737}
2738
Shannon Woods53a94a82014-06-24 15:20:36 -04002739void Context::detachTexture(GLuint texture)
2740{
2741 // Simple pass-through to State's detachTexture method, as textures do not require
2742 // allocation map management either here or in the resource manager at detach time.
2743 // Zero textures are held by the Context, and we don't attempt to request them from
2744 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002745 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002746}
2747
James Darpinian4d9d4832018-03-13 12:43:28 -07002748void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002749{
Yuly Novikov5807a532015-12-03 13:01:22 -05002750 // Simple pass-through to State's detachBuffer method, since
2751 // only buffer attachments to container objects that are bound to the current context
2752 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002753
Yuly Novikov5807a532015-12-03 13:01:22 -05002754 // [OpenGL ES 3.2] section 5.1.2 page 45:
2755 // Attachments to unbound container objects, such as
2756 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2757 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002758 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002759}
2760
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002761void Context::detachFramebuffer(GLuint framebuffer)
2762{
Shannon Woods53a94a82014-06-24 15:20:36 -04002763 // Framebuffer detachment is handled by Context, because 0 is a valid
2764 // Framebuffer object, and a pointer to it must be passed from Context
2765 // to State at binding time.
2766
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002767 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002768 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2769 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2770 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002771
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002772 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002773 {
2774 bindReadFramebuffer(0);
2775 }
2776
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002777 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002778 {
2779 bindDrawFramebuffer(0);
2780 }
2781}
2782
2783void Context::detachRenderbuffer(GLuint renderbuffer)
2784{
Jamie Madilla02315b2017-02-23 14:14:47 -05002785 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002786}
2787
Jamie Madill57a89722013-07-02 11:57:03 -04002788void Context::detachVertexArray(GLuint vertexArray)
2789{
Jamie Madill77a72f62015-04-14 11:18:32 -04002790 // Vertex array detachment is handled by Context, because 0 is a valid
2791 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002792 // binding time.
2793
Jamie Madill57a89722013-07-02 11:57:03 -04002794 // [OpenGL ES 3.0.2] section 2.10 page 43:
2795 // If a vertex array object that is currently bound is deleted, the binding
2796 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002797 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002798 {
2799 bindVertexArray(0);
2800 }
2801}
2802
Geoff Langc8058452014-02-03 12:04:11 -05002803void Context::detachTransformFeedback(GLuint transformFeedback)
2804{
Corentin Walleza2257da2016-04-19 16:43:12 -04002805 // Transform feedback detachment is handled by Context, because 0 is a valid
2806 // transform feedback, and a pointer to it must be passed from Context to State at
2807 // binding time.
2808
2809 // The OpenGL specification doesn't mention what should happen when the currently bound
2810 // transform feedback object is deleted. Since it is a container object, we treat it like
2811 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002812 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002813 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002814 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002815 }
Geoff Langc8058452014-02-03 12:04:11 -05002816}
2817
Jamie Madilldc356042013-07-19 16:36:57 -04002818void Context::detachSampler(GLuint sampler)
2819{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002820 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002821}
2822
Yunchao Hea336b902017-08-02 16:05:21 +08002823void Context::detachProgramPipeline(GLuint pipeline)
2824{
2825 mGLState.detachProgramPipeline(this, pipeline);
2826}
2827
Jamie Madill3ef140a2017-08-26 23:11:21 -04002828void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002829{
Shaodde78e82017-05-22 14:13:27 +08002830 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002831 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002832}
2833
Jamie Madille29d1672013-07-19 16:36:57 -04002834void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2835{
Geoff Langc1984ed2016-10-07 12:41:00 -04002836 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002837 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002838 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002839 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002840}
Jamie Madille29d1672013-07-19 16:36:57 -04002841
Geoff Langc1984ed2016-10-07 12:41:00 -04002842void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2843{
2844 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002845 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002846 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002847 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002848}
2849
Brandon Jones59770802018-04-02 13:18:42 -07002850void Context::samplerParameterivRobust(GLuint sampler,
2851 GLenum pname,
2852 GLsizei bufSize,
2853 const GLint *param)
2854{
2855 samplerParameteriv(sampler, pname, param);
2856}
2857
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002858void Context::samplerParameterIivRobust(GLuint sampler,
2859 GLenum pname,
2860 GLsizei bufSize,
2861 const GLint *param)
2862{
2863 UNIMPLEMENTED();
2864}
2865
2866void Context::samplerParameterIuivRobust(GLuint sampler,
2867 GLenum pname,
2868 GLsizei bufSize,
2869 const GLuint *param)
2870{
2871 UNIMPLEMENTED();
2872}
2873
Jamie Madille29d1672013-07-19 16:36:57 -04002874void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2875{
Geoff Langc1984ed2016-10-07 12:41:00 -04002876 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002877 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002878 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002879 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002880}
2881
Geoff Langc1984ed2016-10-07 12:41:00 -04002882void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002883{
Geoff Langc1984ed2016-10-07 12:41:00 -04002884 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002885 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002886 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002887 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002888}
2889
Brandon Jones59770802018-04-02 13:18:42 -07002890void Context::samplerParameterfvRobust(GLuint sampler,
2891 GLenum pname,
2892 GLsizei bufSize,
2893 const GLfloat *param)
2894{
2895 samplerParameterfv(sampler, pname, param);
2896}
2897
Geoff Langc1984ed2016-10-07 12:41:00 -04002898void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002899{
Geoff Langc1984ed2016-10-07 12:41:00 -04002900 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002901 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002902 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002903 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002904}
Jamie Madill9675b802013-07-19 16:36:59 -04002905
Brandon Jones59770802018-04-02 13:18:42 -07002906void Context::getSamplerParameterivRobust(GLuint sampler,
2907 GLenum pname,
2908 GLsizei bufSize,
2909 GLsizei *length,
2910 GLint *params)
2911{
2912 getSamplerParameteriv(sampler, pname, params);
2913}
2914
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002915void Context::getSamplerParameterIivRobust(GLuint sampler,
2916 GLenum pname,
2917 GLsizei bufSize,
2918 GLsizei *length,
2919 GLint *params)
2920{
2921 UNIMPLEMENTED();
2922}
2923
2924void Context::getSamplerParameterIuivRobust(GLuint sampler,
2925 GLenum pname,
2926 GLsizei bufSize,
2927 GLsizei *length,
2928 GLuint *params)
2929{
2930 UNIMPLEMENTED();
2931}
2932
Geoff Langc1984ed2016-10-07 12:41:00 -04002933void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2934{
2935 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002936 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002937 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002938 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002939}
2940
Brandon Jones59770802018-04-02 13:18:42 -07002941void Context::getSamplerParameterfvRobust(GLuint sampler,
2942 GLenum pname,
2943 GLsizei bufSize,
2944 GLsizei *length,
2945 GLfloat *params)
2946{
2947 getSamplerParameterfv(sampler, pname, params);
2948}
2949
Olli Etuahof0fee072016-03-30 15:11:58 +03002950void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2951{
2952 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002953 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002954}
2955
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002956void Context::initRendererString()
2957{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002958 std::ostringstream rendererString;
2959 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002960 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002961 rendererString << ")";
2962
Geoff Langcec35902014-04-16 10:52:36 -04002963 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002964}
2965
Geoff Langc339c4e2016-11-29 10:37:36 -05002966void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002967{
Geoff Langc339c4e2016-11-29 10:37:36 -05002968 const Version &clientVersion = getClientVersion();
2969
2970 std::ostringstream versionString;
2971 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2972 << ANGLE_VERSION_STRING << ")";
2973 mVersionString = MakeStaticString(versionString.str());
2974
2975 std::ostringstream shadingLanguageVersionString;
2976 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2977 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2978 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2979 << ")";
2980 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002981}
2982
Geoff Langcec35902014-04-16 10:52:36 -04002983void Context::initExtensionStrings()
2984{
Geoff Langc339c4e2016-11-29 10:37:36 -05002985 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2986 std::ostringstream combinedStringStream;
2987 std::copy(strings.begin(), strings.end(),
2988 std::ostream_iterator<const char *>(combinedStringStream, " "));
2989 return MakeStaticString(combinedStringStream.str());
2990 };
2991
2992 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002993 for (const auto &extensionString : mExtensions.getStrings())
2994 {
2995 mExtensionStrings.push_back(MakeStaticString(extensionString));
2996 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002997 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002998
Geoff Langc339c4e2016-11-29 10:37:36 -05002999 mRequestableExtensionStrings.clear();
3000 for (const auto &extensionInfo : GetExtensionInfoMap())
3001 {
3002 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003003 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003004 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003005 {
3006 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3007 }
3008 }
3009 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003010}
3011
Geoff Langc339c4e2016-11-29 10:37:36 -05003012const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003013{
Geoff Langc339c4e2016-11-29 10:37:36 -05003014 switch (name)
3015 {
3016 case GL_VENDOR:
3017 return reinterpret_cast<const GLubyte *>("Google Inc.");
3018
3019 case GL_RENDERER:
3020 return reinterpret_cast<const GLubyte *>(mRendererString);
3021
3022 case GL_VERSION:
3023 return reinterpret_cast<const GLubyte *>(mVersionString);
3024
3025 case GL_SHADING_LANGUAGE_VERSION:
3026 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3027
3028 case GL_EXTENSIONS:
3029 return reinterpret_cast<const GLubyte *>(mExtensionString);
3030
3031 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3032 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3033
3034 default:
3035 UNREACHABLE();
3036 return nullptr;
3037 }
Geoff Langcec35902014-04-16 10:52:36 -04003038}
3039
Geoff Langc339c4e2016-11-29 10:37:36 -05003040const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003041{
Geoff Langc339c4e2016-11-29 10:37:36 -05003042 switch (name)
3043 {
3044 case GL_EXTENSIONS:
3045 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3046
3047 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3048 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3049
3050 default:
3051 UNREACHABLE();
3052 return nullptr;
3053 }
Geoff Langcec35902014-04-16 10:52:36 -04003054}
3055
3056size_t Context::getExtensionStringCount() const
3057{
3058 return mExtensionStrings.size();
3059}
3060
Geoff Lang111a99e2017-10-17 10:58:41 -04003061bool Context::isExtensionRequestable(const char *name)
3062{
3063 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3064 auto extension = extensionInfos.find(name);
3065
Geoff Lang111a99e2017-10-17 10:58:41 -04003066 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003067 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003068}
3069
Geoff Langc339c4e2016-11-29 10:37:36 -05003070void Context::requestExtension(const char *name)
3071{
3072 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3073 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3074 const auto &extension = extensionInfos.at(name);
3075 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003076 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003077
3078 if (mExtensions.*(extension.ExtensionsMember))
3079 {
3080 // Extension already enabled
3081 return;
3082 }
3083
3084 mExtensions.*(extension.ExtensionsMember) = true;
3085 updateCaps();
3086 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003087
Jamie Madill2f348d22017-06-05 10:50:59 -04003088 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3089 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003090
Jamie Madill81c2e252017-09-09 23:32:46 -04003091 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3092 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003093 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003094 for (auto &zeroTexture : mZeroTextures)
3095 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003096 if (zeroTexture.get() != nullptr)
3097 {
3098 zeroTexture->signalDirty(this, InitState::Initialized);
3099 }
Geoff Lang9aded172017-04-05 11:07:56 -04003100 }
3101
Jamie Madillb983a4b2018-08-01 11:34:51 -04003102 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003103}
3104
3105size_t Context::getRequestableExtensionStringCount() const
3106{
3107 return mRequestableExtensionStrings.size();
3108}
3109
Jamie Madill493f9572018-05-24 19:52:15 -04003110void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003111{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003112 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003113 ASSERT(transformFeedback != nullptr);
3114 ASSERT(!transformFeedback->isPaused());
3115
Jamie Madill6c1f6712017-02-14 19:08:04 -05003116 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Jamie Madilld84b6732018-09-06 15:54:35 -04003117 mStateCache.onTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003118}
3119
3120bool Context::hasActiveTransformFeedback(GLuint program) const
3121{
3122 for (auto pair : mTransformFeedbackMap)
3123 {
3124 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3125 {
3126 return true;
3127 }
3128 }
3129 return false;
3130}
3131
Geoff Lang33f11fb2018-05-07 13:42:47 -04003132Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003133{
3134 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3135
jchen1082af6202018-06-22 10:59:52 +08003136 // Explicitly enable GL_KHR_parallel_shader_compile
3137 supportedExtensions.parallelShaderCompile = true;
3138
Geoff Langb0f917f2017-12-05 13:41:54 -05003139 if (getClientVersion() < ES_2_0)
3140 {
3141 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003142 supportedExtensions.pointSizeArray = true;
3143 supportedExtensions.textureCubeMap = true;
3144 supportedExtensions.pointSprite = true;
3145 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003146 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003147 }
3148
3149 if (getClientVersion() < ES_3_0)
3150 {
3151 // Disable ES3+ extensions
3152 supportedExtensions.colorBufferFloat = false;
3153 supportedExtensions.eglImageExternalEssl3 = false;
3154 supportedExtensions.textureNorm16 = false;
3155 supportedExtensions.multiview = false;
3156 supportedExtensions.maxViews = 1u;
3157 }
3158
3159 if (getClientVersion() < ES_3_1)
3160 {
3161 // Disable ES3.1+ extensions
3162 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003163
3164 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3165 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003166 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003167 }
3168
3169 if (getClientVersion() > ES_2_0)
3170 {
3171 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3172 // supportedExtensions.sRGB = false;
3173 }
3174
3175 // Some extensions are always available because they are implemented in the GL layer.
3176 supportedExtensions.bindUniformLocation = true;
3177 supportedExtensions.vertexArrayObject = true;
3178 supportedExtensions.bindGeneratesResource = true;
3179 supportedExtensions.clientArrays = true;
3180 supportedExtensions.requestExtension = true;
3181
3182 // Enable the no error extension if the context was created with the flag.
3183 supportedExtensions.noError = mSkipValidation;
3184
3185 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003186 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003187
3188 // Explicitly enable GL_KHR_debug
3189 supportedExtensions.debug = true;
3190 supportedExtensions.maxDebugMessageLength = 1024;
3191 supportedExtensions.maxDebugLoggedMessages = 1024;
3192 supportedExtensions.maxDebugGroupStackDepth = 1024;
3193 supportedExtensions.maxLabelLength = 1024;
3194
3195 // Explicitly enable GL_ANGLE_robust_client_memory
3196 supportedExtensions.robustClientMemory = true;
3197
3198 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003199 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003200
3201 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3202 // supports it.
3203 supportedExtensions.robustBufferAccessBehavior =
3204 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3205
3206 // Enable the cache control query unconditionally.
3207 supportedExtensions.programCacheControl = true;
3208
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003209 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003210 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003211 {
3212 // GL_ANGLE_explicit_context_gles1
3213 supportedExtensions.explicitContextGles1 = true;
3214 // GL_ANGLE_explicit_context
3215 supportedExtensions.explicitContext = true;
3216 }
3217
Geoff Langb0f917f2017-12-05 13:41:54 -05003218 return supportedExtensions;
3219}
3220
Geoff Lang33f11fb2018-05-07 13:42:47 -04003221void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003222{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003223 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003224
Geoff Lang33f11fb2018-05-07 13:42:47 -04003225 mSupportedExtensions = generateSupportedExtensions();
3226 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003227
3228 mLimitations = mImplementation->getNativeLimitations();
3229
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003230 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3231 if (getClientVersion() < Version(2, 0))
3232 {
3233 mCaps.maxMultitextureUnits = 4;
3234 mCaps.maxClipPlanes = 6;
3235 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003236 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3237 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3238 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003239 mCaps.minSmoothPointSize = 1.0f;
3240 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003241 mCaps.minSmoothLineWidth = 1.0f;
3242 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003243 }
3244
Luc Ferronad2ae932018-06-11 15:31:17 -04003245 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003246 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003247
Luc Ferronad2ae932018-06-11 15:31:17 -04003248 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3249
Jamie Madill0f80ed82017-09-19 00:24:56 -04003250 if (getClientVersion() < ES_3_1)
3251 {
3252 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3253 }
3254 else
3255 {
3256 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3257 }
Geoff Lang301d1612014-07-09 10:34:37 -04003258
Jiawei Shao54aafe52018-04-27 14:54:57 +08003259 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3260 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003261 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3262
Jamie Madill0f80ed82017-09-19 00:24:56 -04003263 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3264 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3265
3266 // Limit textures as well, so we can use fast bitsets with texture bindings.
3267 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003268 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3269 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3270 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3271 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003272
Jiawei Shaodb342272017-09-27 10:21:45 +08003273 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3274
Geoff Langc287ea62016-09-16 14:46:51 -04003275 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003276 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003277 for (const auto &extensionInfo : GetExtensionInfoMap())
3278 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003279 // If the user has requested that extensions start disabled and they are requestable,
3280 // disable them.
3281 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003282 {
3283 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3284 }
3285 }
3286
3287 // Generate texture caps
3288 updateCaps();
3289}
3290
3291void Context::updateCaps()
3292{
Geoff Lang900013c2014-07-07 11:32:19 -04003293 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003294 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003295
Jamie Madill7b62cf92017-11-02 15:20:49 -04003296 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003297 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003298 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003299 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003300
Geoff Lang0d8b7242015-09-09 14:56:53 -04003301 // Update the format caps based on the client version and extensions.
3302 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3303 // ES3.
3304 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003305 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003306 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003307 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003308 formatCaps.textureAttachment =
3309 formatCaps.textureAttachment &&
3310 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3311 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3312 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003313
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003314 // OpenGL ES does not support multisampling with non-rendererable formats
3315 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003316 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003317 (getClientVersion() < ES_3_1 &&
3318 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003319 {
Geoff Langd87878e2014-09-19 15:42:59 -04003320 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003321 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003322 else
3323 {
3324 // We may have limited the max samples for some required renderbuffer formats due to
3325 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3326 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3327
3328 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3329 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3330 // exception of signed and unsigned integer formats."
3331 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3332 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3333 {
3334 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3335 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3336 }
3337
3338 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3339 if (getClientVersion() >= ES_3_1)
3340 {
3341 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3342 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3343 // the exception that the signed and unsigned integer formats are required only to
3344 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3345 // multisamples, which must be at least one."
3346 if (formatInfo.componentType == GL_INT ||
3347 formatInfo.componentType == GL_UNSIGNED_INT)
3348 {
3349 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3350 }
3351
3352 // GLES 3.1 section 19.3.1.
3353 if (formatCaps.texturable)
3354 {
3355 if (formatInfo.depthBits > 0)
3356 {
3357 mCaps.maxDepthTextureSamples =
3358 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3359 }
3360 else if (formatInfo.redBits > 0)
3361 {
3362 mCaps.maxColorTextureSamples =
3363 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3364 }
3365 }
3366 }
3367 }
Geoff Langd87878e2014-09-19 15:42:59 -04003368
3369 if (formatCaps.texturable && formatInfo.compressed)
3370 {
Geoff Langca271392017-04-05 12:30:00 -04003371 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003372 }
3373
Geoff Langca271392017-04-05 12:30:00 -04003374 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003375 }
Jamie Madill32447362017-06-28 14:53:52 -04003376
3377 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003378 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003379 {
3380 mMemoryProgramCache = nullptr;
3381 }
Corentin Walleze4477002017-12-01 14:39:58 -05003382
3383 // Compute which buffer types are allowed
3384 mValidBufferBindings.reset();
3385 mValidBufferBindings.set(BufferBinding::ElementArray);
3386 mValidBufferBindings.set(BufferBinding::Array);
3387
3388 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3389 {
3390 mValidBufferBindings.set(BufferBinding::PixelPack);
3391 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3392 }
3393
3394 if (getClientVersion() >= ES_3_0)
3395 {
3396 mValidBufferBindings.set(BufferBinding::CopyRead);
3397 mValidBufferBindings.set(BufferBinding::CopyWrite);
3398 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3399 mValidBufferBindings.set(BufferBinding::Uniform);
3400 }
3401
3402 if (getClientVersion() >= ES_3_1)
3403 {
3404 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3405 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3406 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3407 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3408 }
jchen107ae70d82018-07-06 13:47:01 +08003409
3410 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Geoff Lang493daf52014-07-03 13:38:44 -04003411}
3412
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003413void Context::initWorkarounds()
3414{
Jamie Madill761b02c2017-06-23 16:27:06 -04003415 // Apply back-end workarounds.
3416 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3417
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003418 // Lose the context upon out of memory error if the application is
3419 // expecting to watch for those events.
3420 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3421}
3422
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003423// Return true if the draw is a no-op, else return false.
3424// A no-op draw occurs if the count of vertices is less than the minimum required to
3425// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3426bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3427{
3428 return count < kMinimumPrimitiveCounts[mode];
3429}
3430
3431bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3432{
3433 return (instanceCount == 0) || noopDraw(mode, count);
3434}
3435
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003436Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003437{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003438 if (mGLES1Renderer)
3439 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003440 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003441 }
3442
Geoff Lang9bf86f02018-07-26 11:46:34 -04003443 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003444
3445 if (isRobustResourceInitEnabled())
3446 {
3447 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3448 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3449 }
3450
Geoff Langa8cb2872018-03-09 16:09:40 -05003451 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003452 return NoError();
3453}
3454
3455Error Context::prepareForClear(GLbitfield mask)
3456{
Geoff Langa8cb2872018-03-09 16:09:40 -05003457 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003458 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003459 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003460 return NoError();
3461}
3462
3463Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3464{
Geoff Langa8cb2872018-03-09 16:09:40 -05003465 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003466 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3467 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003468 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003469 return NoError();
3470}
3471
Geoff Langa8cb2872018-03-09 16:09:40 -05003472Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003473{
Geoff Langa8cb2872018-03-09 16:09:40 -05003474 ANGLE_TRY(syncDirtyObjects(objectMask));
3475 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003476 return NoError();
3477}
3478
Geoff Langa8cb2872018-03-09 16:09:40 -05003479Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003480{
3481 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003482 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003483 mGLState.clearDirtyBits();
3484 return NoError();
3485}
3486
Geoff Langa8cb2872018-03-09 16:09:40 -05003487Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003488{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003489 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003490 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003491 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003492 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003493}
Jamie Madillc29968b2016-01-20 11:17:23 -05003494
Geoff Langa8cb2872018-03-09 16:09:40 -05003495Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003496{
3497 return mGLState.syncDirtyObjects(this, objectMask);
3498}
3499
Jamie Madillc29968b2016-01-20 11:17:23 -05003500void Context::blitFramebuffer(GLint srcX0,
3501 GLint srcY0,
3502 GLint srcX1,
3503 GLint srcY1,
3504 GLint dstX0,
3505 GLint dstY0,
3506 GLint dstX1,
3507 GLint dstY1,
3508 GLbitfield mask,
3509 GLenum filter)
3510{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003511 if (mask == 0)
3512 {
3513 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3514 // buffers are copied.
3515 return;
3516 }
3517
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003518 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003519 ASSERT(drawFramebuffer);
3520
3521 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3522 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3523
Jamie Madillbc918e72018-03-08 09:47:21 -05003524 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003525
Jamie Madillc564c072017-06-01 12:45:42 -04003526 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003527}
Jamie Madillc29968b2016-01-20 11:17:23 -05003528
3529void Context::clear(GLbitfield mask)
3530{
Geoff Langd4fff502017-09-22 11:28:28 -04003531 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3532 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003533}
3534
3535void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3536{
Olli Etuahodbce1f82018-09-19 15:32:17 +03003537 if (buffer == GL_DEPTH && !getGLState().getDrawFramebuffer()->getDepthbuffer())
3538 {
3539 // It's not an error to try to clear a non-existent depth buffer, but it's a no-op.
3540 return;
3541 }
Geoff Langd4fff502017-09-22 11:28:28 -04003542 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3543 ANGLE_CONTEXT_TRY(
3544 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003545}
3546
3547void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3548{
Geoff Langd4fff502017-09-22 11:28:28 -04003549 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3550 ANGLE_CONTEXT_TRY(
3551 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003552}
3553
3554void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3555{
Olli Etuahodbce1f82018-09-19 15:32:17 +03003556 if (buffer == GL_STENCIL && !getGLState().getDrawFramebuffer()->getStencilbuffer())
3557 {
3558 // It's not an error to try to clear a non-existent stencil buffer, but it's a no-op.
3559 return;
3560 }
Geoff Langd4fff502017-09-22 11:28:28 -04003561 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3562 ANGLE_CONTEXT_TRY(
3563 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003564}
3565
3566void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3567{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003568 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003569 ASSERT(framebufferObject);
3570
3571 // If a buffer is not present, the clear has no effect
3572 if (framebufferObject->getDepthbuffer() == nullptr &&
3573 framebufferObject->getStencilbuffer() == nullptr)
3574 {
3575 return;
3576 }
3577
Geoff Langd4fff502017-09-22 11:28:28 -04003578 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3579 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003580}
3581
3582void Context::readPixels(GLint x,
3583 GLint y,
3584 GLsizei width,
3585 GLsizei height,
3586 GLenum format,
3587 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003588 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003589{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003590 if (width == 0 || height == 0)
3591 {
3592 return;
3593 }
3594
Jamie Madillbc918e72018-03-08 09:47:21 -05003595 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003596
Jamie Madillb6664922017-07-25 12:55:04 -04003597 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3598 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003599
3600 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003601 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003602}
3603
Brandon Jones59770802018-04-02 13:18:42 -07003604void Context::readPixelsRobust(GLint x,
3605 GLint y,
3606 GLsizei width,
3607 GLsizei height,
3608 GLenum format,
3609 GLenum type,
3610 GLsizei bufSize,
3611 GLsizei *length,
3612 GLsizei *columns,
3613 GLsizei *rows,
3614 void *pixels)
3615{
3616 readPixels(x, y, width, height, format, type, pixels);
3617}
3618
3619void Context::readnPixelsRobust(GLint x,
3620 GLint y,
3621 GLsizei width,
3622 GLsizei height,
3623 GLenum format,
3624 GLenum type,
3625 GLsizei bufSize,
3626 GLsizei *length,
3627 GLsizei *columns,
3628 GLsizei *rows,
3629 void *data)
3630{
3631 readPixels(x, y, width, height, format, type, data);
3632}
3633
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003634void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003635 GLint level,
3636 GLenum internalformat,
3637 GLint x,
3638 GLint y,
3639 GLsizei width,
3640 GLsizei height,
3641 GLint border)
3642{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003643 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003644 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003645
Jamie Madillc29968b2016-01-20 11:17:23 -05003646 Rectangle sourceArea(x, y, width, height);
3647
Jamie Madill05b35b22017-10-03 09:01:44 -04003648 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003649 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003650 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003651}
3652
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003653void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003654 GLint level,
3655 GLint xoffset,
3656 GLint yoffset,
3657 GLint x,
3658 GLint y,
3659 GLsizei width,
3660 GLsizei height)
3661{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003662 if (width == 0 || height == 0)
3663 {
3664 return;
3665 }
3666
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003667 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003668 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003669
Jamie Madillc29968b2016-01-20 11:17:23 -05003670 Offset destOffset(xoffset, yoffset, 0);
3671 Rectangle sourceArea(x, y, width, height);
3672
Jamie Madill05b35b22017-10-03 09:01:44 -04003673 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003674 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003675 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003676}
3677
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003678void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003679 GLint level,
3680 GLint xoffset,
3681 GLint yoffset,
3682 GLint zoffset,
3683 GLint x,
3684 GLint y,
3685 GLsizei width,
3686 GLsizei height)
3687{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003688 if (width == 0 || height == 0)
3689 {
3690 return;
3691 }
3692
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003693 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003694 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003695
Jamie Madillc29968b2016-01-20 11:17:23 -05003696 Offset destOffset(xoffset, yoffset, zoffset);
3697 Rectangle sourceArea(x, y, width, height);
3698
Jamie Madill05b35b22017-10-03 09:01:44 -04003699 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3700 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003701 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3702 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003703}
3704
3705void Context::framebufferTexture2D(GLenum target,
3706 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003707 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003708 GLuint texture,
3709 GLint level)
3710{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003711 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003712 ASSERT(framebuffer);
3713
3714 if (texture != 0)
3715 {
3716 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003717 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003718 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003719 }
3720 else
3721 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003722 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003723 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003724
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003725 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003726}
3727
3728void Context::framebufferRenderbuffer(GLenum target,
3729 GLenum attachment,
3730 GLenum renderbuffertarget,
3731 GLuint renderbuffer)
3732{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003733 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003734 ASSERT(framebuffer);
3735
3736 if (renderbuffer != 0)
3737 {
3738 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003739
Jamie Madillcc129372018-04-12 09:13:18 -04003740 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003741 renderbufferObject);
3742 }
3743 else
3744 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003745 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003746 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003747
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003748 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003749}
3750
3751void Context::framebufferTextureLayer(GLenum target,
3752 GLenum attachment,
3753 GLuint texture,
3754 GLint level,
3755 GLint layer)
3756{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003757 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003758 ASSERT(framebuffer);
3759
3760 if (texture != 0)
3761 {
3762 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003763 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003764 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003765 }
3766 else
3767 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003768 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003769 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003770
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003771 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003772}
3773
Brandon Jones59770802018-04-02 13:18:42 -07003774void Context::framebufferTextureMultiviewLayered(GLenum target,
3775 GLenum attachment,
3776 GLuint texture,
3777 GLint level,
3778 GLint baseViewIndex,
3779 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003780{
Martin Radev82ef7742017-08-08 17:44:58 +03003781 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3782 ASSERT(framebuffer);
3783
3784 if (texture != 0)
3785 {
3786 Texture *textureObj = getTexture(texture);
3787
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003788 ImageIndex index;
3789 if (textureObj->getType() == TextureType::_2DArray)
3790 {
3791 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3792 }
3793 else
3794 {
3795 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3796 ASSERT(level == 0);
3797 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3798 }
Martin Radev82ef7742017-08-08 17:44:58 +03003799 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3800 numViews, baseViewIndex);
3801 }
3802 else
3803 {
3804 framebuffer->resetAttachment(this, attachment);
3805 }
3806
3807 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003808}
3809
Brandon Jones59770802018-04-02 13:18:42 -07003810void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3811 GLenum attachment,
3812 GLuint texture,
3813 GLint level,
3814 GLsizei numViews,
3815 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003816{
Martin Radev5dae57b2017-07-14 16:15:55 +03003817 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3818 ASSERT(framebuffer);
3819
3820 if (texture != 0)
3821 {
3822 Texture *textureObj = getTexture(texture);
3823
3824 ImageIndex index = ImageIndex::Make2D(level);
3825 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3826 textureObj, numViews, viewportOffsets);
3827 }
3828 else
3829 {
3830 framebuffer->resetAttachment(this, attachment);
3831 }
3832
3833 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003834}
3835
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003836void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3837{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003838 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3839 ASSERT(framebuffer);
3840
3841 if (texture != 0)
3842 {
3843 Texture *textureObj = getTexture(texture);
3844
3845 ImageIndex index = ImageIndex::MakeFromType(
3846 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3847 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3848 }
3849 else
3850 {
3851 framebuffer->resetAttachment(this, attachment);
3852 }
3853
3854 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003855}
3856
Jamie Madillc29968b2016-01-20 11:17:23 -05003857void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3858{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003859 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003860 ASSERT(framebuffer);
3861 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003862 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04003863 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003864}
3865
3866void Context::readBuffer(GLenum mode)
3867{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003868 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003869 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003870 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003871}
3872
3873void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3874{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003875 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003876 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003877
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003878 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003879 ASSERT(framebuffer);
3880
3881 // The specification isn't clear what should be done when the framebuffer isn't complete.
3882 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003883 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003884}
3885
3886void Context::invalidateFramebuffer(GLenum target,
3887 GLsizei numAttachments,
3888 const GLenum *attachments)
3889{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003890 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003891 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003892
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003893 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003894 ASSERT(framebuffer);
3895
Jamie Madill427064d2018-04-13 16:20:34 -04003896 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003897 {
Jamie Madill437fa652016-05-03 15:13:24 -04003898 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003899 }
Jamie Madill437fa652016-05-03 15:13:24 -04003900
Jamie Madill4928b7c2017-06-20 12:57:39 -04003901 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003902}
3903
3904void Context::invalidateSubFramebuffer(GLenum target,
3905 GLsizei numAttachments,
3906 const GLenum *attachments,
3907 GLint x,
3908 GLint y,
3909 GLsizei width,
3910 GLsizei height)
3911{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003912 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003913 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003914
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003915 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003916 ASSERT(framebuffer);
3917
Jamie Madill427064d2018-04-13 16:20:34 -04003918 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003919 {
Jamie Madill437fa652016-05-03 15:13:24 -04003920 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003921 }
Jamie Madill437fa652016-05-03 15:13:24 -04003922
3923 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003924 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003925}
3926
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003927void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003928 GLint level,
3929 GLint internalformat,
3930 GLsizei width,
3931 GLsizei height,
3932 GLint border,
3933 GLenum format,
3934 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003935 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003936{
Jamie Madillbc918e72018-03-08 09:47:21 -05003937 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003938
3939 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003940 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003941 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003942 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003943}
3944
Brandon Jones59770802018-04-02 13:18:42 -07003945void Context::texImage2DRobust(TextureTarget target,
3946 GLint level,
3947 GLint internalformat,
3948 GLsizei width,
3949 GLsizei height,
3950 GLint border,
3951 GLenum format,
3952 GLenum type,
3953 GLsizei bufSize,
3954 const void *pixels)
3955{
3956 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3957}
3958
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003959void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003960 GLint level,
3961 GLint internalformat,
3962 GLsizei width,
3963 GLsizei height,
3964 GLsizei depth,
3965 GLint border,
3966 GLenum format,
3967 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003968 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003969{
Jamie Madillbc918e72018-03-08 09:47:21 -05003970 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003971
3972 Extents size(width, height, depth);
3973 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003974 handleError(texture->setImage(this, mGLState.getUnpackState(),
3975 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003976 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003977}
3978
Brandon Jones59770802018-04-02 13:18:42 -07003979void Context::texImage3DRobust(TextureType target,
3980 GLint level,
3981 GLint internalformat,
3982 GLsizei width,
3983 GLsizei height,
3984 GLsizei depth,
3985 GLint border,
3986 GLenum format,
3987 GLenum type,
3988 GLsizei bufSize,
3989 const void *pixels)
3990{
3991 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3992}
3993
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003994void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003995 GLint level,
3996 GLint xoffset,
3997 GLint yoffset,
3998 GLsizei width,
3999 GLsizei height,
4000 GLenum format,
4001 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004002 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004003{
4004 // Zero sized uploads are valid but no-ops
4005 if (width == 0 || height == 0)
4006 {
4007 return;
4008 }
4009
Jamie Madillbc918e72018-03-08 09:47:21 -05004010 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004011
4012 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004013 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004014
4015 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4016
4017 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target, level,
4018 area, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004019}
4020
Brandon Jones59770802018-04-02 13:18:42 -07004021void Context::texSubImage2DRobust(TextureTarget target,
4022 GLint level,
4023 GLint xoffset,
4024 GLint yoffset,
4025 GLsizei width,
4026 GLsizei height,
4027 GLenum format,
4028 GLenum type,
4029 GLsizei bufSize,
4030 const void *pixels)
4031{
4032 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4033}
4034
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004035void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004036 GLint level,
4037 GLint xoffset,
4038 GLint yoffset,
4039 GLint zoffset,
4040 GLsizei width,
4041 GLsizei height,
4042 GLsizei depth,
4043 GLenum format,
4044 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004045 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004046{
4047 // Zero sized uploads are valid but no-ops
4048 if (width == 0 || height == 0 || depth == 0)
4049 {
4050 return;
4051 }
4052
Jamie Madillbc918e72018-03-08 09:47:21 -05004053 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004054
4055 Box area(xoffset, yoffset, zoffset, width, height, depth);
4056 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004057
4058 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4059
4060 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004061 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004062 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004063}
4064
Brandon Jones59770802018-04-02 13:18:42 -07004065void Context::texSubImage3DRobust(TextureType target,
4066 GLint level,
4067 GLint xoffset,
4068 GLint yoffset,
4069 GLint zoffset,
4070 GLsizei width,
4071 GLsizei height,
4072 GLsizei depth,
4073 GLenum format,
4074 GLenum type,
4075 GLsizei bufSize,
4076 const void *pixels)
4077{
4078 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4079 pixels);
4080}
4081
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004082void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004083 GLint level,
4084 GLenum internalformat,
4085 GLsizei width,
4086 GLsizei height,
4087 GLint border,
4088 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004089 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004090{
Jamie Madillbc918e72018-03-08 09:47:21 -05004091 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004092
4093 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004094 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004095 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4096 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004097 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004098}
4099
Brandon Jones59770802018-04-02 13:18:42 -07004100void Context::compressedTexImage2DRobust(TextureTarget target,
4101 GLint level,
4102 GLenum internalformat,
4103 GLsizei width,
4104 GLsizei height,
4105 GLint border,
4106 GLsizei imageSize,
4107 GLsizei dataSize,
4108 const GLvoid *data)
4109{
4110 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4111}
4112
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004113void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004114 GLint level,
4115 GLenum internalformat,
4116 GLsizei width,
4117 GLsizei height,
4118 GLsizei depth,
4119 GLint border,
4120 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004121 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004122{
Jamie Madillbc918e72018-03-08 09:47:21 -05004123 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004124
4125 Extents size(width, height, depth);
4126 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004127 handleError(texture->setCompressedImage(
4128 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004129 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004130}
4131
Brandon Jones59770802018-04-02 13:18:42 -07004132void Context::compressedTexImage3DRobust(TextureType target,
4133 GLint level,
4134 GLenum internalformat,
4135 GLsizei width,
4136 GLsizei height,
4137 GLsizei depth,
4138 GLint border,
4139 GLsizei imageSize,
4140 GLsizei dataSize,
4141 const GLvoid *data)
4142{
4143 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4144 data);
4145}
4146
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004147void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004148 GLint level,
4149 GLint xoffset,
4150 GLint yoffset,
4151 GLsizei width,
4152 GLsizei height,
4153 GLenum format,
4154 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004155 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004156{
Jamie Madillbc918e72018-03-08 09:47:21 -05004157 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004158
4159 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004160 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004161 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4162 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004163 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004164}
4165
Brandon Jones59770802018-04-02 13:18:42 -07004166void Context::compressedTexSubImage2DRobust(TextureTarget target,
4167 GLint level,
4168 GLint xoffset,
4169 GLint yoffset,
4170 GLsizei width,
4171 GLsizei height,
4172 GLenum format,
4173 GLsizei imageSize,
4174 GLsizei dataSize,
4175 const GLvoid *data)
4176{
4177 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4178 data);
4179}
4180
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004181void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004182 GLint level,
4183 GLint xoffset,
4184 GLint yoffset,
4185 GLint zoffset,
4186 GLsizei width,
4187 GLsizei height,
4188 GLsizei depth,
4189 GLenum format,
4190 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004191 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004192{
4193 // Zero sized uploads are valid but no-ops
4194 if (width == 0 || height == 0)
4195 {
4196 return;
4197 }
4198
Jamie Madillbc918e72018-03-08 09:47:21 -05004199 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004200
4201 Box area(xoffset, yoffset, zoffset, width, height, depth);
4202 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004203 handleError(texture->setCompressedSubImage(
4204 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004205 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004206}
4207
Brandon Jones59770802018-04-02 13:18:42 -07004208void Context::compressedTexSubImage3DRobust(TextureType target,
4209 GLint level,
4210 GLint xoffset,
4211 GLint yoffset,
4212 GLint zoffset,
4213 GLsizei width,
4214 GLsizei height,
4215 GLsizei depth,
4216 GLenum format,
4217 GLsizei imageSize,
4218 GLsizei dataSize,
4219 const GLvoid *data)
4220{
4221 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4222 imageSize, data);
4223}
4224
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004225void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004226{
4227 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004228 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004229}
4230
Jamie Madill007530e2017-12-28 14:27:04 -05004231void Context::copyTexture(GLuint sourceId,
4232 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004233 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004234 GLuint destId,
4235 GLint destLevel,
4236 GLint internalFormat,
4237 GLenum destType,
4238 GLboolean unpackFlipY,
4239 GLboolean unpackPremultiplyAlpha,
4240 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004241{
Jamie Madillbc918e72018-03-08 09:47:21 -05004242 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004243
4244 gl::Texture *sourceTexture = getTexture(sourceId);
4245 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004246 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4247 sourceLevel, ConvertToBool(unpackFlipY),
4248 ConvertToBool(unpackPremultiplyAlpha),
4249 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004250}
4251
Jamie Madill007530e2017-12-28 14:27:04 -05004252void Context::copySubTexture(GLuint sourceId,
4253 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004254 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004255 GLuint destId,
4256 GLint destLevel,
4257 GLint xoffset,
4258 GLint yoffset,
4259 GLint x,
4260 GLint y,
4261 GLsizei width,
4262 GLsizei height,
4263 GLboolean unpackFlipY,
4264 GLboolean unpackPremultiplyAlpha,
4265 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004266{
4267 // Zero sized copies are valid but no-ops
4268 if (width == 0 || height == 0)
4269 {
4270 return;
4271 }
4272
Jamie Madillbc918e72018-03-08 09:47:21 -05004273 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004274
4275 gl::Texture *sourceTexture = getTexture(sourceId);
4276 gl::Texture *destTexture = getTexture(destId);
4277 Offset offset(xoffset, yoffset, 0);
4278 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004279 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4280 ConvertToBool(unpackFlipY),
4281 ConvertToBool(unpackPremultiplyAlpha),
4282 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004283}
4284
Jamie Madill007530e2017-12-28 14:27:04 -05004285void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004286{
Jamie Madillbc918e72018-03-08 09:47:21 -05004287 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004288
4289 gl::Texture *sourceTexture = getTexture(sourceId);
4290 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004291 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004292}
4293
Corentin Wallez336129f2017-10-17 15:55:40 -04004294void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004295{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004296 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004297 ASSERT(buffer);
4298
Geoff Lang496c02d2016-10-20 11:38:11 -07004299 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004300}
4301
Brandon Jones59770802018-04-02 13:18:42 -07004302void Context::getBufferPointervRobust(BufferBinding target,
4303 GLenum pname,
4304 GLsizei bufSize,
4305 GLsizei *length,
4306 void **params)
4307{
4308 getBufferPointerv(target, pname, params);
4309}
4310
Corentin Wallez336129f2017-10-17 15:55:40 -04004311void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004312{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004313 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004314 ASSERT(buffer);
4315
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004316 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004317 if (error.isError())
4318 {
Jamie Madill437fa652016-05-03 15:13:24 -04004319 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004320 return nullptr;
4321 }
4322
4323 return buffer->getMapPointer();
4324}
4325
Corentin Wallez336129f2017-10-17 15:55:40 -04004326GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004327{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004328 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004329 ASSERT(buffer);
4330
4331 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004332 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004333 if (error.isError())
4334 {
Jamie Madill437fa652016-05-03 15:13:24 -04004335 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004336 return GL_FALSE;
4337 }
4338
4339 return result;
4340}
4341
Corentin Wallez336129f2017-10-17 15:55:40 -04004342void *Context::mapBufferRange(BufferBinding target,
4343 GLintptr offset,
4344 GLsizeiptr length,
4345 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004346{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004347 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004348 ASSERT(buffer);
4349
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004350 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004351 if (error.isError())
4352 {
Jamie Madill437fa652016-05-03 15:13:24 -04004353 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004354 return nullptr;
4355 }
4356
4357 return buffer->getMapPointer();
4358}
4359
Corentin Wallez336129f2017-10-17 15:55:40 -04004360void Context::flushMappedBufferRange(BufferBinding /*target*/,
4361 GLintptr /*offset*/,
4362 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004363{
4364 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4365}
4366
Jamie Madillbc918e72018-03-08 09:47:21 -05004367Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004368{
Geoff Langa8cb2872018-03-09 16:09:40 -05004369 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004370}
4371
Jamie Madillbc918e72018-03-08 09:47:21 -05004372Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004373{
Geoff Langa8cb2872018-03-09 16:09:40 -05004374 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004375}
4376
Jamie Madillbc918e72018-03-08 09:47:21 -05004377Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004378{
Geoff Langa8cb2872018-03-09 16:09:40 -05004379 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004380}
4381
Geoff Lang9bf86f02018-07-26 11:46:34 -04004382Error Context::syncStateForPathOperation()
4383{
4384 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4385
4386 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4387 ANGLE_TRY(syncDirtyBits());
4388
4389 return NoError();
4390}
4391
Jiajia Qin5451d532017-11-16 17:16:34 +08004392void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4393{
4394 UNIMPLEMENTED();
4395}
4396
Jamie Madillc20ab272016-06-09 07:20:46 -07004397void Context::activeTexture(GLenum texture)
4398{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004399 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004400}
4401
Jamie Madill876429b2017-04-20 15:46:24 -04004402void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004403{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004404 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004405}
4406
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004407void Context::blendEquation(GLenum mode)
4408{
4409 mGLState.setBlendEquation(mode, mode);
4410}
4411
Jamie Madillc20ab272016-06-09 07:20:46 -07004412void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4413{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004414 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004415}
4416
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004417void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4418{
4419 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4420}
4421
Jamie Madillc20ab272016-06-09 07:20:46 -07004422void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4423{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004424 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004425}
4426
Jamie Madill876429b2017-04-20 15:46:24 -04004427void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004428{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004429 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004430}
4431
Jamie Madill876429b2017-04-20 15:46:24 -04004432void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004433{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004434 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004435}
4436
4437void Context::clearStencil(GLint s)
4438{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004439 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004440}
4441
4442void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4443{
Geoff Lang92019432017-11-20 13:09:34 -05004444 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4445 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004446}
4447
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004448void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004449{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004450 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004451}
4452
4453void Context::depthFunc(GLenum func)
4454{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004455 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004456}
4457
4458void Context::depthMask(GLboolean flag)
4459{
Geoff Lang92019432017-11-20 13:09:34 -05004460 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004461}
4462
Jamie Madill876429b2017-04-20 15:46:24 -04004463void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004464{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004465 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004466}
4467
4468void Context::disable(GLenum cap)
4469{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004470 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004471 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004472}
4473
4474void Context::disableVertexAttribArray(GLuint index)
4475{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004476 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004477 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004478}
4479
4480void Context::enable(GLenum cap)
4481{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004482 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004483 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004484}
4485
4486void Context::enableVertexAttribArray(GLuint index)
4487{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004488 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004489 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004490}
4491
4492void Context::frontFace(GLenum mode)
4493{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004494 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004495}
4496
4497void Context::hint(GLenum target, GLenum mode)
4498{
4499 switch (target)
4500 {
4501 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004502 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004503 break;
4504
4505 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004506 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004507 break;
4508
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004509 case GL_PERSPECTIVE_CORRECTION_HINT:
4510 case GL_POINT_SMOOTH_HINT:
4511 case GL_LINE_SMOOTH_HINT:
4512 case GL_FOG_HINT:
4513 mGLState.gles1().setHint(target, mode);
4514 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004515 default:
4516 UNREACHABLE();
4517 return;
4518 }
4519}
4520
4521void Context::lineWidth(GLfloat width)
4522{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004523 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004524}
4525
4526void Context::pixelStorei(GLenum pname, GLint param)
4527{
4528 switch (pname)
4529 {
4530 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004531 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004532 break;
4533
4534 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004535 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004536 break;
4537
4538 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004539 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004540 break;
4541
4542 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004543 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004544 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004545 break;
4546
4547 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004548 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004549 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004550 break;
4551
4552 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004553 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004554 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004555 break;
4556
4557 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004558 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004559 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004560 break;
4561
4562 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004563 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004564 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004565 break;
4566
4567 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004568 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004569 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004570 break;
4571
4572 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004573 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004574 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004575 break;
4576
4577 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004578 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004579 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004580 break;
4581
4582 default:
4583 UNREACHABLE();
4584 return;
4585 }
4586}
4587
4588void Context::polygonOffset(GLfloat factor, GLfloat units)
4589{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004590 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004591}
4592
Jamie Madill876429b2017-04-20 15:46:24 -04004593void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004594{
Geoff Lang92019432017-11-20 13:09:34 -05004595 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004596}
4597
Jiawei Shaodb342272017-09-27 10:21:45 +08004598void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4599{
4600 mGLState.setSampleMaskParams(maskNumber, mask);
4601}
4602
Jamie Madillc20ab272016-06-09 07:20:46 -07004603void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4604{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004605 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004606}
4607
4608void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4609{
4610 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4611 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004612 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004613 }
4614
4615 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4616 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004617 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004618 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004619
4620 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004621}
4622
4623void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4624{
4625 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4626 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004627 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004628 }
4629
4630 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4631 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004632 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004633 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004634
4635 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004636}
4637
4638void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4639{
4640 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4641 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004642 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004643 }
4644
4645 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4646 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004647 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004648 }
4649}
4650
4651void Context::vertexAttrib1f(GLuint index, GLfloat x)
4652{
4653 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004654 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004655 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004656}
4657
4658void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4659{
4660 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004661 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004662 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004663}
4664
4665void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4666{
4667 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004668 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004669 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004670}
4671
4672void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4673{
4674 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004675 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004676 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004677}
4678
4679void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4680{
4681 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004682 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004683 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004684}
4685
4686void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4687{
4688 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004689 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004690 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004691}
4692
4693void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4694{
4695 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004696 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004697 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004698}
4699
4700void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4701{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004702 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004703 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004704}
4705
4706void Context::vertexAttribPointer(GLuint index,
4707 GLint size,
4708 GLenum type,
4709 GLboolean normalized,
4710 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004711 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004712{
Corentin Wallez336129f2017-10-17 15:55:40 -04004713 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004714 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004715 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004716}
4717
Shao80957d92017-02-20 21:25:59 +08004718void Context::vertexAttribFormat(GLuint attribIndex,
4719 GLint size,
4720 GLenum type,
4721 GLboolean normalized,
4722 GLuint relativeOffset)
4723{
Geoff Lang92019432017-11-20 13:09:34 -05004724 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004725 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004726 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004727}
4728
4729void Context::vertexAttribIFormat(GLuint attribIndex,
4730 GLint size,
4731 GLenum type,
4732 GLuint relativeOffset)
4733{
4734 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004735 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004736}
4737
4738void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4739{
Shaodde78e82017-05-22 14:13:27 +08004740 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004741 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004742}
4743
Jiajia Qin5451d532017-11-16 17:16:34 +08004744void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004745{
4746 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004747 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004748}
4749
Jamie Madillc20ab272016-06-09 07:20:46 -07004750void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4751{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004752 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004753}
4754
4755void Context::vertexAttribIPointer(GLuint index,
4756 GLint size,
4757 GLenum type,
4758 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004759 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004760{
Corentin Wallez336129f2017-10-17 15:55:40 -04004761 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4762 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004763 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004764}
4765
4766void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4767{
4768 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004769 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004770 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004771}
4772
4773void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4774{
4775 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004776 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004777 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004778}
4779
4780void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4781{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004782 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004783 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004784}
4785
4786void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4787{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004788 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004789 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004790}
4791
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004792void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4793{
4794 const VertexAttribCurrentValueData &currentValues =
4795 getGLState().getVertexAttribCurrentValue(index);
4796 const VertexArray *vao = getGLState().getVertexArray();
4797 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4798 currentValues, pname, params);
4799}
4800
Brandon Jones59770802018-04-02 13:18:42 -07004801void Context::getVertexAttribivRobust(GLuint index,
4802 GLenum pname,
4803 GLsizei bufSize,
4804 GLsizei *length,
4805 GLint *params)
4806{
4807 getVertexAttribiv(index, pname, params);
4808}
4809
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004810void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4811{
4812 const VertexAttribCurrentValueData &currentValues =
4813 getGLState().getVertexAttribCurrentValue(index);
4814 const VertexArray *vao = getGLState().getVertexArray();
4815 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4816 currentValues, pname, params);
4817}
4818
Brandon Jones59770802018-04-02 13:18:42 -07004819void Context::getVertexAttribfvRobust(GLuint index,
4820 GLenum pname,
4821 GLsizei bufSize,
4822 GLsizei *length,
4823 GLfloat *params)
4824{
4825 getVertexAttribfv(index, pname, params);
4826}
4827
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004828void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4829{
4830 const VertexAttribCurrentValueData &currentValues =
4831 getGLState().getVertexAttribCurrentValue(index);
4832 const VertexArray *vao = getGLState().getVertexArray();
4833 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4834 currentValues, pname, params);
4835}
4836
Brandon Jones59770802018-04-02 13:18:42 -07004837void Context::getVertexAttribIivRobust(GLuint index,
4838 GLenum pname,
4839 GLsizei bufSize,
4840 GLsizei *length,
4841 GLint *params)
4842{
4843 getVertexAttribIiv(index, pname, params);
4844}
4845
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004846void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4847{
4848 const VertexAttribCurrentValueData &currentValues =
4849 getGLState().getVertexAttribCurrentValue(index);
4850 const VertexArray *vao = getGLState().getVertexArray();
4851 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4852 currentValues, pname, params);
4853}
4854
Brandon Jones59770802018-04-02 13:18:42 -07004855void Context::getVertexAttribIuivRobust(GLuint index,
4856 GLenum pname,
4857 GLsizei bufSize,
4858 GLsizei *length,
4859 GLuint *params)
4860{
4861 getVertexAttribIuiv(index, pname, params);
4862}
4863
Jamie Madill876429b2017-04-20 15:46:24 -04004864void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004865{
4866 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4867 QueryVertexAttribPointerv(attrib, pname, pointer);
4868}
4869
Brandon Jones59770802018-04-02 13:18:42 -07004870void Context::getVertexAttribPointervRobust(GLuint index,
4871 GLenum pname,
4872 GLsizei bufSize,
4873 GLsizei *length,
4874 void **pointer)
4875{
4876 getVertexAttribPointerv(index, pname, pointer);
4877}
4878
Jamie Madillc20ab272016-06-09 07:20:46 -07004879void Context::debugMessageControl(GLenum source,
4880 GLenum type,
4881 GLenum severity,
4882 GLsizei count,
4883 const GLuint *ids,
4884 GLboolean enabled)
4885{
4886 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004887 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004888 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004889}
4890
4891void Context::debugMessageInsert(GLenum source,
4892 GLenum type,
4893 GLuint id,
4894 GLenum severity,
4895 GLsizei length,
4896 const GLchar *buf)
4897{
4898 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004899 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004900}
4901
4902void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4903{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004904 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004905}
4906
4907GLuint Context::getDebugMessageLog(GLuint count,
4908 GLsizei bufSize,
4909 GLenum *sources,
4910 GLenum *types,
4911 GLuint *ids,
4912 GLenum *severities,
4913 GLsizei *lengths,
4914 GLchar *messageLog)
4915{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004916 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4917 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004918}
4919
4920void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4921{
4922 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004923 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004924 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004925}
4926
4927void Context::popDebugGroup()
4928{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004929 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004930 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004931}
4932
Corentin Wallez336129f2017-10-17 15:55:40 -04004933void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004934{
4935 Buffer *buffer = mGLState.getTargetBuffer(target);
4936 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004937 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004938}
4939
Corentin Wallez336129f2017-10-17 15:55:40 -04004940void Context::bufferSubData(BufferBinding target,
4941 GLintptr offset,
4942 GLsizeiptr size,
4943 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004944{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06004945 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04004946 {
4947 return;
4948 }
4949
4950 Buffer *buffer = mGLState.getTargetBuffer(target);
4951 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004952 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004953}
4954
Jamie Madillef300b12016-10-07 15:12:09 -04004955void Context::attachShader(GLuint program, GLuint shader)
4956{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004957 Program *programObject = mState.mShaderPrograms->getProgram(program);
4958 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004959 ASSERT(programObject && shaderObject);
4960 programObject->attachShader(shaderObject);
4961}
4962
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004963const Workarounds &Context::getWorkarounds() const
4964{
4965 return mWorkarounds;
4966}
4967
Corentin Wallez336129f2017-10-17 15:55:40 -04004968void Context::copyBufferSubData(BufferBinding readTarget,
4969 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004970 GLintptr readOffset,
4971 GLintptr writeOffset,
4972 GLsizeiptr size)
4973{
4974 // if size is zero, the copy is a successful no-op
4975 if (size == 0)
4976 {
4977 return;
4978 }
4979
4980 // TODO(jmadill): cache these.
4981 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4982 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4983
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004984 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004985}
4986
Jamie Madill01a80ee2016-11-07 12:06:18 -05004987void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4988{
4989 Program *programObject = getProgram(program);
4990 // TODO(jmadill): Re-use this from the validation if possible.
4991 ASSERT(programObject);
4992 programObject->bindAttributeLocation(index, name);
4993}
4994
Corentin Wallez336129f2017-10-17 15:55:40 -04004995void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004996{
Corentin Wallez336129f2017-10-17 15:55:40 -04004997 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4998 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04004999 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005000}
5001
Corentin Wallez336129f2017-10-17 15:55:40 -04005002void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005003{
5004 bindBufferRange(target, index, buffer, 0, 0);
5005}
5006
Corentin Wallez336129f2017-10-17 15:55:40 -04005007void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005008 GLuint index,
5009 GLuint buffer,
5010 GLintptr offset,
5011 GLsizeiptr size)
5012{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005013 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5014 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
5015 if (target == BufferBinding::Uniform)
5016 {
5017 mUniformBufferObserverBindings[index].bind(object ? object->getImplementation() : nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04005018 mStateCache.onUniformBufferStateChange(this);
5019 }
5020 else
5021 {
5022 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005023 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005024}
5025
Jamie Madill01a80ee2016-11-07 12:06:18 -05005026void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5027{
5028 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5029 {
5030 bindReadFramebuffer(framebuffer);
5031 }
5032
5033 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5034 {
5035 bindDrawFramebuffer(framebuffer);
5036 }
5037}
5038
5039void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5040{
5041 ASSERT(target == GL_RENDERBUFFER);
5042 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005043 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005044 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005045}
5046
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005047void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005048 GLsizei samples,
5049 GLenum internalformat,
5050 GLsizei width,
5051 GLsizei height,
5052 GLboolean fixedsamplelocations)
5053{
5054 Extents size(width, height, 1);
5055 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005056 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5057 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005058}
5059
Olli Etuaho89664842018-08-24 14:45:36 +03005060void Context::texStorage3DMultisample(TextureType target,
5061 GLsizei samples,
5062 GLenum internalformat,
5063 GLsizei width,
5064 GLsizei height,
5065 GLsizei depth,
5066 GLboolean fixedsamplelocations)
5067{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005068 Extents size(width, height, depth);
5069 Texture *texture = getTargetTexture(target);
5070 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5071 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005072}
5073
JiangYizhoubddc46b2016-12-09 09:50:51 +08005074void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5075{
JiangYizhou5b03f472017-01-09 10:22:53 +08005076 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5077 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005078 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005079 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005080
5081 switch (pname)
5082 {
5083 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04005084 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005085 break;
5086 default:
5087 UNREACHABLE();
5088 }
5089}
5090
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005091void Context::getMultisamplefvRobust(GLenum pname,
5092 GLuint index,
5093 GLsizei bufSize,
5094 GLsizei *length,
5095 GLfloat *val)
5096{
5097 UNIMPLEMENTED();
5098}
5099
Jamie Madille8fb6402017-02-14 17:56:40 -05005100void Context::renderbufferStorage(GLenum target,
5101 GLenum internalformat,
5102 GLsizei width,
5103 GLsizei height)
5104{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005105 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5106 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5107
Jamie Madille8fb6402017-02-14 17:56:40 -05005108 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04005109 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005110}
5111
5112void Context::renderbufferStorageMultisample(GLenum target,
5113 GLsizei samples,
5114 GLenum internalformat,
5115 GLsizei width,
5116 GLsizei height)
5117{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005118 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5119 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005120
5121 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005122 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005123 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005124}
5125
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005126void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5127{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005128 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04005129 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005130}
5131
JiangYizhoue18e6392017-02-20 10:32:23 +08005132void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5133{
5134 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5135 QueryFramebufferParameteriv(framebuffer, pname, params);
5136}
5137
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005138void Context::getFramebufferParameterivRobust(GLenum target,
5139 GLenum pname,
5140 GLsizei bufSize,
5141 GLsizei *length,
5142 GLint *params)
5143{
5144 UNIMPLEMENTED();
5145}
5146
Jiajia Qin5451d532017-11-16 17:16:34 +08005147void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005148{
5149 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005150 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005151}
5152
Jamie Madilldec86232018-07-11 09:01:18 -04005153bool Context::getScratchBuffer(size_t requstedSizeBytes,
5154 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005155{
Jamie Madilldec86232018-07-11 09:01:18 -04005156 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005157}
5158
Jamie Madilldec86232018-07-11 09:01:18 -04005159bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5160 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005161{
Jamie Madilldec86232018-07-11 09:01:18 -04005162 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005163}
5164
Xinghua Cao10a4d432017-11-28 14:46:26 +08005165Error Context::prepareForDispatch()
5166{
Geoff Langa8cb2872018-03-09 16:09:40 -05005167 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005168
5169 if (isRobustResourceInitEnabled())
5170 {
5171 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5172 }
5173
5174 return NoError();
5175}
5176
Xinghua Cao2b396592017-03-29 15:36:04 +08005177void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5178{
5179 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5180 {
5181 return;
5182 }
5183
Xinghua Cao10a4d432017-11-28 14:46:26 +08005184 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005185 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005186}
5187
Jiajia Qin5451d532017-11-16 17:16:34 +08005188void Context::dispatchComputeIndirect(GLintptr indirect)
5189{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005190 ANGLE_CONTEXT_TRY(prepareForDispatch());
5191 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005192}
5193
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005194void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005195 GLsizei levels,
5196 GLenum internalFormat,
5197 GLsizei width,
5198 GLsizei height)
5199{
5200 Extents size(width, height, 1);
5201 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005202 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005203}
5204
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005205void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005206 GLsizei levels,
5207 GLenum internalFormat,
5208 GLsizei width,
5209 GLsizei height,
5210 GLsizei depth)
5211{
5212 Extents size(width, height, depth);
5213 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005214 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005215}
5216
Jiajia Qin5451d532017-11-16 17:16:34 +08005217void Context::memoryBarrier(GLbitfield barriers)
5218{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005219 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005220}
5221
5222void Context::memoryBarrierByRegion(GLbitfield barriers)
5223{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005224 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005225}
5226
Jamie Madillc1d770e2017-04-13 17:31:24 -04005227GLenum Context::checkFramebufferStatus(GLenum target)
5228{
5229 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5230 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005231 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005232}
5233
5234void Context::compileShader(GLuint shader)
5235{
5236 Shader *shaderObject = GetValidShader(this, shader);
5237 if (!shaderObject)
5238 {
5239 return;
5240 }
5241 shaderObject->compile(this);
5242}
5243
5244void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5245{
5246 for (int i = 0; i < n; i++)
5247 {
5248 deleteBuffer(buffers[i]);
5249 }
5250}
5251
5252void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5253{
5254 for (int i = 0; i < n; i++)
5255 {
5256 if (framebuffers[i] != 0)
5257 {
5258 deleteFramebuffer(framebuffers[i]);
5259 }
5260 }
5261}
5262
5263void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5264{
5265 for (int i = 0; i < n; i++)
5266 {
5267 deleteRenderbuffer(renderbuffers[i]);
5268 }
5269}
5270
5271void Context::deleteTextures(GLsizei n, const GLuint *textures)
5272{
5273 for (int i = 0; i < n; i++)
5274 {
5275 if (textures[i] != 0)
5276 {
5277 deleteTexture(textures[i]);
5278 }
5279 }
5280}
5281
5282void Context::detachShader(GLuint program, GLuint shader)
5283{
5284 Program *programObject = getProgram(program);
5285 ASSERT(programObject);
5286
5287 Shader *shaderObject = getShader(shader);
5288 ASSERT(shaderObject);
5289
5290 programObject->detachShader(this, shaderObject);
5291}
5292
5293void Context::genBuffers(GLsizei n, GLuint *buffers)
5294{
5295 for (int i = 0; i < n; i++)
5296 {
5297 buffers[i] = createBuffer();
5298 }
5299}
5300
5301void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5302{
5303 for (int i = 0; i < n; i++)
5304 {
5305 framebuffers[i] = createFramebuffer();
5306 }
5307}
5308
5309void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5310{
5311 for (int i = 0; i < n; i++)
5312 {
5313 renderbuffers[i] = createRenderbuffer();
5314 }
5315}
5316
5317void Context::genTextures(GLsizei n, GLuint *textures)
5318{
5319 for (int i = 0; i < n; i++)
5320 {
5321 textures[i] = createTexture();
5322 }
5323}
5324
5325void Context::getActiveAttrib(GLuint program,
5326 GLuint index,
5327 GLsizei bufsize,
5328 GLsizei *length,
5329 GLint *size,
5330 GLenum *type,
5331 GLchar *name)
5332{
5333 Program *programObject = getProgram(program);
5334 ASSERT(programObject);
5335 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5336}
5337
5338void Context::getActiveUniform(GLuint program,
5339 GLuint index,
5340 GLsizei bufsize,
5341 GLsizei *length,
5342 GLint *size,
5343 GLenum *type,
5344 GLchar *name)
5345{
5346 Program *programObject = getProgram(program);
5347 ASSERT(programObject);
5348 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5349}
5350
5351void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5352{
5353 Program *programObject = getProgram(program);
5354 ASSERT(programObject);
5355 programObject->getAttachedShaders(maxcount, count, shaders);
5356}
5357
5358GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5359{
5360 Program *programObject = getProgram(program);
5361 ASSERT(programObject);
5362 return programObject->getAttributeLocation(name);
5363}
5364
5365void Context::getBooleanv(GLenum pname, GLboolean *params)
5366{
5367 GLenum nativeType;
5368 unsigned int numParams = 0;
5369 getQueryParameterInfo(pname, &nativeType, &numParams);
5370
5371 if (nativeType == GL_BOOL)
5372 {
5373 getBooleanvImpl(pname, params);
5374 }
5375 else
5376 {
5377 CastStateValues(this, nativeType, pname, numParams, params);
5378 }
5379}
5380
Brandon Jones59770802018-04-02 13:18:42 -07005381void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5382{
5383 getBooleanv(pname, params);
5384}
5385
Jamie Madillc1d770e2017-04-13 17:31:24 -04005386void Context::getFloatv(GLenum pname, GLfloat *params)
5387{
5388 GLenum nativeType;
5389 unsigned int numParams = 0;
5390 getQueryParameterInfo(pname, &nativeType, &numParams);
5391
5392 if (nativeType == GL_FLOAT)
5393 {
5394 getFloatvImpl(pname, params);
5395 }
5396 else
5397 {
5398 CastStateValues(this, nativeType, pname, numParams, params);
5399 }
5400}
5401
Brandon Jones59770802018-04-02 13:18:42 -07005402void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5403{
5404 getFloatv(pname, params);
5405}
5406
Jamie Madillc1d770e2017-04-13 17:31:24 -04005407void Context::getIntegerv(GLenum pname, GLint *params)
5408{
5409 GLenum nativeType;
5410 unsigned int numParams = 0;
5411 getQueryParameterInfo(pname, &nativeType, &numParams);
5412
5413 if (nativeType == GL_INT)
5414 {
5415 getIntegervImpl(pname, params);
5416 }
5417 else
5418 {
5419 CastStateValues(this, nativeType, pname, numParams, params);
5420 }
5421}
5422
Brandon Jones59770802018-04-02 13:18:42 -07005423void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5424{
5425 getIntegerv(pname, data);
5426}
5427
Jamie Madillc1d770e2017-04-13 17:31:24 -04005428void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5429{
5430 Program *programObject = getProgram(program);
5431 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005432 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005433}
5434
Brandon Jones59770802018-04-02 13:18:42 -07005435void Context::getProgramivRobust(GLuint program,
5436 GLenum pname,
5437 GLsizei bufSize,
5438 GLsizei *length,
5439 GLint *params)
5440{
5441 getProgramiv(program, pname, params);
5442}
5443
Jiajia Qin5451d532017-11-16 17:16:34 +08005444void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5445{
5446 UNIMPLEMENTED();
5447}
5448
Jamie Madillbe849e42017-05-02 15:49:00 -04005449void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005450{
5451 Program *programObject = getProgram(program);
5452 ASSERT(programObject);
5453 programObject->getInfoLog(bufsize, length, infolog);
5454}
5455
Jiajia Qin5451d532017-11-16 17:16:34 +08005456void Context::getProgramPipelineInfoLog(GLuint pipeline,
5457 GLsizei bufSize,
5458 GLsizei *length,
5459 GLchar *infoLog)
5460{
5461 UNIMPLEMENTED();
5462}
5463
Jamie Madillc1d770e2017-04-13 17:31:24 -04005464void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5465{
5466 Shader *shaderObject = getShader(shader);
5467 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005468 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005469}
5470
Brandon Jones59770802018-04-02 13:18:42 -07005471void Context::getShaderivRobust(GLuint shader,
5472 GLenum pname,
5473 GLsizei bufSize,
5474 GLsizei *length,
5475 GLint *params)
5476{
5477 getShaderiv(shader, pname, params);
5478}
5479
Jamie Madillc1d770e2017-04-13 17:31:24 -04005480void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5481{
5482 Shader *shaderObject = getShader(shader);
5483 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005484 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005485}
5486
5487void Context::getShaderPrecisionFormat(GLenum shadertype,
5488 GLenum precisiontype,
5489 GLint *range,
5490 GLint *precision)
5491{
5492 // TODO(jmadill): Compute shaders.
5493
5494 switch (shadertype)
5495 {
5496 case GL_VERTEX_SHADER:
5497 switch (precisiontype)
5498 {
5499 case GL_LOW_FLOAT:
5500 mCaps.vertexLowpFloat.get(range, precision);
5501 break;
5502 case GL_MEDIUM_FLOAT:
5503 mCaps.vertexMediumpFloat.get(range, precision);
5504 break;
5505 case GL_HIGH_FLOAT:
5506 mCaps.vertexHighpFloat.get(range, precision);
5507 break;
5508
5509 case GL_LOW_INT:
5510 mCaps.vertexLowpInt.get(range, precision);
5511 break;
5512 case GL_MEDIUM_INT:
5513 mCaps.vertexMediumpInt.get(range, precision);
5514 break;
5515 case GL_HIGH_INT:
5516 mCaps.vertexHighpInt.get(range, precision);
5517 break;
5518
5519 default:
5520 UNREACHABLE();
5521 return;
5522 }
5523 break;
5524
5525 case GL_FRAGMENT_SHADER:
5526 switch (precisiontype)
5527 {
5528 case GL_LOW_FLOAT:
5529 mCaps.fragmentLowpFloat.get(range, precision);
5530 break;
5531 case GL_MEDIUM_FLOAT:
5532 mCaps.fragmentMediumpFloat.get(range, precision);
5533 break;
5534 case GL_HIGH_FLOAT:
5535 mCaps.fragmentHighpFloat.get(range, precision);
5536 break;
5537
5538 case GL_LOW_INT:
5539 mCaps.fragmentLowpInt.get(range, precision);
5540 break;
5541 case GL_MEDIUM_INT:
5542 mCaps.fragmentMediumpInt.get(range, precision);
5543 break;
5544 case GL_HIGH_INT:
5545 mCaps.fragmentHighpInt.get(range, precision);
5546 break;
5547
5548 default:
5549 UNREACHABLE();
5550 return;
5551 }
5552 break;
5553
5554 default:
5555 UNREACHABLE();
5556 return;
5557 }
5558}
5559
5560void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5561{
5562 Shader *shaderObject = getShader(shader);
5563 ASSERT(shaderObject);
5564 shaderObject->getSource(bufsize, length, source);
5565}
5566
5567void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5568{
5569 Program *programObject = getProgram(program);
5570 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005571 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005572}
5573
Brandon Jones59770802018-04-02 13:18:42 -07005574void Context::getUniformfvRobust(GLuint program,
5575 GLint location,
5576 GLsizei bufSize,
5577 GLsizei *length,
5578 GLfloat *params)
5579{
5580 getUniformfv(program, location, params);
5581}
5582
Jamie Madillc1d770e2017-04-13 17:31:24 -04005583void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5584{
5585 Program *programObject = getProgram(program);
5586 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005587 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005588}
5589
Brandon Jones59770802018-04-02 13:18:42 -07005590void Context::getUniformivRobust(GLuint program,
5591 GLint location,
5592 GLsizei bufSize,
5593 GLsizei *length,
5594 GLint *params)
5595{
5596 getUniformiv(program, location, params);
5597}
5598
Jamie Madillc1d770e2017-04-13 17:31:24 -04005599GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5600{
5601 Program *programObject = getProgram(program);
5602 ASSERT(programObject);
5603 return programObject->getUniformLocation(name);
5604}
5605
5606GLboolean Context::isBuffer(GLuint buffer)
5607{
5608 if (buffer == 0)
5609 {
5610 return GL_FALSE;
5611 }
5612
5613 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5614}
5615
5616GLboolean Context::isEnabled(GLenum cap)
5617{
5618 return mGLState.getEnableFeature(cap);
5619}
5620
5621GLboolean Context::isFramebuffer(GLuint framebuffer)
5622{
5623 if (framebuffer == 0)
5624 {
5625 return GL_FALSE;
5626 }
5627
5628 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5629}
5630
5631GLboolean Context::isProgram(GLuint program)
5632{
5633 if (program == 0)
5634 {
5635 return GL_FALSE;
5636 }
5637
5638 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5639}
5640
5641GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5642{
5643 if (renderbuffer == 0)
5644 {
5645 return GL_FALSE;
5646 }
5647
5648 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5649}
5650
5651GLboolean Context::isShader(GLuint shader)
5652{
5653 if (shader == 0)
5654 {
5655 return GL_FALSE;
5656 }
5657
5658 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5659}
5660
5661GLboolean Context::isTexture(GLuint texture)
5662{
5663 if (texture == 0)
5664 {
5665 return GL_FALSE;
5666 }
5667
5668 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5669}
5670
5671void Context::linkProgram(GLuint program)
5672{
5673 Program *programObject = getProgram(program);
5674 ASSERT(programObject);
5675 handleError(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005676
5677 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5678 // don't need to worry that:
5679 // 1. Draw calls after link use the new executable code or the old one depending on the link
5680 // result.
5681 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5682 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5683 // ProgramD3D.
5684 if (programObject->isInUse())
5685 {
5686 // isLinked() which forces to resolve linking, will be called.
5687 mGLState.onProgramExecutableChange(programObject);
5688 mStateCache.onProgramExecutableChange(this);
5689 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005690}
5691
5692void Context::releaseShaderCompiler()
5693{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005694 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005695}
5696
5697void Context::shaderBinary(GLsizei n,
5698 const GLuint *shaders,
5699 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005700 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005701 GLsizei length)
5702{
5703 // No binary shader formats are supported.
5704 UNIMPLEMENTED();
5705}
5706
5707void Context::shaderSource(GLuint shader,
5708 GLsizei count,
5709 const GLchar *const *string,
5710 const GLint *length)
5711{
5712 Shader *shaderObject = getShader(shader);
5713 ASSERT(shaderObject);
5714 shaderObject->setSource(count, string, length);
5715}
5716
5717void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5718{
5719 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5720}
5721
5722void Context::stencilMask(GLuint mask)
5723{
5724 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5725}
5726
5727void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5728{
5729 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5730}
5731
5732void Context::uniform1f(GLint location, GLfloat x)
5733{
5734 Program *program = mGLState.getProgram();
5735 program->setUniform1fv(location, 1, &x);
5736}
5737
5738void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5739{
5740 Program *program = mGLState.getProgram();
5741 program->setUniform1fv(location, count, v);
5742}
5743
Jamie Madill7e4eff12018-08-08 15:49:26 -04005744void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005745{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005746 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04005747 {
5748 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04005749 mStateCache.onActiveTextureChange(this);
Jamie Madill81c2e252017-09-09 23:32:46 -04005750 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005751}
5752
Jamie Madill7e4eff12018-08-08 15:49:26 -04005753void Context::uniform1i(GLint location, GLint x)
5754{
5755 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
5756}
5757
Jamie Madillc1d770e2017-04-13 17:31:24 -04005758void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5759{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005760 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005761}
5762
5763void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5764{
5765 GLfloat xy[2] = {x, y};
5766 Program *program = mGLState.getProgram();
5767 program->setUniform2fv(location, 1, xy);
5768}
5769
5770void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5771{
5772 Program *program = mGLState.getProgram();
5773 program->setUniform2fv(location, count, v);
5774}
5775
5776void Context::uniform2i(GLint location, GLint x, GLint y)
5777{
5778 GLint xy[2] = {x, y};
5779 Program *program = mGLState.getProgram();
5780 program->setUniform2iv(location, 1, xy);
5781}
5782
5783void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5784{
5785 Program *program = mGLState.getProgram();
5786 program->setUniform2iv(location, count, v);
5787}
5788
5789void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5790{
5791 GLfloat xyz[3] = {x, y, z};
5792 Program *program = mGLState.getProgram();
5793 program->setUniform3fv(location, 1, xyz);
5794}
5795
5796void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5797{
5798 Program *program = mGLState.getProgram();
5799 program->setUniform3fv(location, count, v);
5800}
5801
5802void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5803{
5804 GLint xyz[3] = {x, y, z};
5805 Program *program = mGLState.getProgram();
5806 program->setUniform3iv(location, 1, xyz);
5807}
5808
5809void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5810{
5811 Program *program = mGLState.getProgram();
5812 program->setUniform3iv(location, count, v);
5813}
5814
5815void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5816{
5817 GLfloat xyzw[4] = {x, y, z, w};
5818 Program *program = mGLState.getProgram();
5819 program->setUniform4fv(location, 1, xyzw);
5820}
5821
5822void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5823{
5824 Program *program = mGLState.getProgram();
5825 program->setUniform4fv(location, count, v);
5826}
5827
5828void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5829{
5830 GLint xyzw[4] = {x, y, z, w};
5831 Program *program = mGLState.getProgram();
5832 program->setUniform4iv(location, 1, xyzw);
5833}
5834
5835void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5836{
5837 Program *program = mGLState.getProgram();
5838 program->setUniform4iv(location, count, v);
5839}
5840
5841void Context::uniformMatrix2fv(GLint location,
5842 GLsizei count,
5843 GLboolean transpose,
5844 const GLfloat *value)
5845{
5846 Program *program = mGLState.getProgram();
5847 program->setUniformMatrix2fv(location, count, transpose, value);
5848}
5849
5850void Context::uniformMatrix3fv(GLint location,
5851 GLsizei count,
5852 GLboolean transpose,
5853 const GLfloat *value)
5854{
5855 Program *program = mGLState.getProgram();
5856 program->setUniformMatrix3fv(location, count, transpose, value);
5857}
5858
5859void Context::uniformMatrix4fv(GLint location,
5860 GLsizei count,
5861 GLboolean transpose,
5862 const GLfloat *value)
5863{
5864 Program *program = mGLState.getProgram();
5865 program->setUniformMatrix4fv(location, count, transpose, value);
5866}
5867
5868void Context::validateProgram(GLuint program)
5869{
5870 Program *programObject = getProgram(program);
5871 ASSERT(programObject);
5872 programObject->validate(mCaps);
5873}
5874
Jiajia Qin5451d532017-11-16 17:16:34 +08005875void Context::validateProgramPipeline(GLuint pipeline)
5876{
5877 UNIMPLEMENTED();
5878}
5879
Jamie Madilld04908b2017-06-09 14:15:35 -04005880void Context::getProgramBinary(GLuint program,
5881 GLsizei bufSize,
5882 GLsizei *length,
5883 GLenum *binaryFormat,
5884 void *binary)
5885{
5886 Program *programObject = getProgram(program);
5887 ASSERT(programObject != nullptr);
5888
5889 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5890}
5891
5892void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5893{
5894 Program *programObject = getProgram(program);
5895 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005896
Jamie Madilld04908b2017-06-09 14:15:35 -04005897 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madillc43cdad2018-08-08 15:49:25 -04005898 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04005899 if (programObject->isInUse())
5900 {
5901 mGLState.setObjectDirty(GL_PROGRAM);
5902 }
Jamie Madilld04908b2017-06-09 14:15:35 -04005903}
5904
Jamie Madillff325f12017-08-26 15:06:05 -04005905void Context::uniform1ui(GLint location, GLuint v0)
5906{
5907 Program *program = mGLState.getProgram();
5908 program->setUniform1uiv(location, 1, &v0);
5909}
5910
5911void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5912{
5913 Program *program = mGLState.getProgram();
5914 const GLuint xy[] = {v0, v1};
5915 program->setUniform2uiv(location, 1, xy);
5916}
5917
5918void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5919{
5920 Program *program = mGLState.getProgram();
5921 const GLuint xyz[] = {v0, v1, v2};
5922 program->setUniform3uiv(location, 1, xyz);
5923}
5924
5925void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5926{
5927 Program *program = mGLState.getProgram();
5928 const GLuint xyzw[] = {v0, v1, v2, v3};
5929 program->setUniform4uiv(location, 1, xyzw);
5930}
5931
5932void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5933{
5934 Program *program = mGLState.getProgram();
5935 program->setUniform1uiv(location, count, value);
5936}
5937void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5938{
5939 Program *program = mGLState.getProgram();
5940 program->setUniform2uiv(location, count, value);
5941}
5942
5943void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5944{
5945 Program *program = mGLState.getProgram();
5946 program->setUniform3uiv(location, count, value);
5947}
5948
5949void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5950{
5951 Program *program = mGLState.getProgram();
5952 program->setUniform4uiv(location, count, value);
5953}
5954
Jamie Madillf0e04492017-08-26 15:28:42 -04005955void Context::genQueries(GLsizei n, GLuint *ids)
5956{
5957 for (GLsizei i = 0; i < n; i++)
5958 {
5959 GLuint handle = mQueryHandleAllocator.allocate();
5960 mQueryMap.assign(handle, nullptr);
5961 ids[i] = handle;
5962 }
5963}
5964
5965void Context::deleteQueries(GLsizei n, const GLuint *ids)
5966{
5967 for (int i = 0; i < n; i++)
5968 {
5969 GLuint query = ids[i];
5970
5971 Query *queryObject = nullptr;
5972 if (mQueryMap.erase(query, &queryObject))
5973 {
5974 mQueryHandleAllocator.release(query);
5975 if (queryObject)
5976 {
5977 queryObject->release(this);
5978 }
5979 }
5980 }
5981}
5982
5983GLboolean Context::isQuery(GLuint id)
5984{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005985 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005986}
5987
Jamie Madillc8c95812017-08-26 18:40:09 -04005988void Context::uniformMatrix2x3fv(GLint location,
5989 GLsizei count,
5990 GLboolean transpose,
5991 const GLfloat *value)
5992{
5993 Program *program = mGLState.getProgram();
5994 program->setUniformMatrix2x3fv(location, count, transpose, value);
5995}
5996
5997void Context::uniformMatrix3x2fv(GLint location,
5998 GLsizei count,
5999 GLboolean transpose,
6000 const GLfloat *value)
6001{
6002 Program *program = mGLState.getProgram();
6003 program->setUniformMatrix3x2fv(location, count, transpose, value);
6004}
6005
6006void Context::uniformMatrix2x4fv(GLint location,
6007 GLsizei count,
6008 GLboolean transpose,
6009 const GLfloat *value)
6010{
6011 Program *program = mGLState.getProgram();
6012 program->setUniformMatrix2x4fv(location, count, transpose, value);
6013}
6014
6015void Context::uniformMatrix4x2fv(GLint location,
6016 GLsizei count,
6017 GLboolean transpose,
6018 const GLfloat *value)
6019{
6020 Program *program = mGLState.getProgram();
6021 program->setUniformMatrix4x2fv(location, count, transpose, value);
6022}
6023
6024void Context::uniformMatrix3x4fv(GLint location,
6025 GLsizei count,
6026 GLboolean transpose,
6027 const GLfloat *value)
6028{
6029 Program *program = mGLState.getProgram();
6030 program->setUniformMatrix3x4fv(location, count, transpose, value);
6031}
6032
6033void Context::uniformMatrix4x3fv(GLint location,
6034 GLsizei count,
6035 GLboolean transpose,
6036 const GLfloat *value)
6037{
6038 Program *program = mGLState.getProgram();
6039 program->setUniformMatrix4x3fv(location, count, transpose, value);
6040}
6041
Jamie Madilld7576732017-08-26 18:49:50 -04006042void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6043{
6044 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6045 {
6046 GLuint vertexArray = arrays[arrayIndex];
6047
6048 if (arrays[arrayIndex] != 0)
6049 {
6050 VertexArray *vertexArrayObject = nullptr;
6051 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6052 {
6053 if (vertexArrayObject != nullptr)
6054 {
6055 detachVertexArray(vertexArray);
6056 vertexArrayObject->onDestroy(this);
6057 }
6058
6059 mVertexArrayHandleAllocator.release(vertexArray);
6060 }
6061 }
6062 }
6063}
6064
6065void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6066{
6067 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6068 {
6069 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6070 mVertexArrayMap.assign(vertexArray, nullptr);
6071 arrays[arrayIndex] = vertexArray;
6072 }
6073}
6074
6075bool Context::isVertexArray(GLuint array)
6076{
6077 if (array == 0)
6078 {
6079 return GL_FALSE;
6080 }
6081
6082 VertexArray *vao = getVertexArray(array);
6083 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6084}
6085
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006086void Context::endTransformFeedback()
6087{
6088 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6089 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006090 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006091}
6092
6093void Context::transformFeedbackVaryings(GLuint program,
6094 GLsizei count,
6095 const GLchar *const *varyings,
6096 GLenum bufferMode)
6097{
6098 Program *programObject = getProgram(program);
6099 ASSERT(programObject);
6100 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6101}
6102
6103void Context::getTransformFeedbackVarying(GLuint program,
6104 GLuint index,
6105 GLsizei bufSize,
6106 GLsizei *length,
6107 GLsizei *size,
6108 GLenum *type,
6109 GLchar *name)
6110{
6111 Program *programObject = getProgram(program);
6112 ASSERT(programObject);
6113 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6114}
6115
6116void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6117{
6118 for (int i = 0; i < n; i++)
6119 {
6120 GLuint transformFeedback = ids[i];
6121 if (transformFeedback == 0)
6122 {
6123 continue;
6124 }
6125
6126 TransformFeedback *transformFeedbackObject = nullptr;
6127 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6128 {
6129 if (transformFeedbackObject != nullptr)
6130 {
6131 detachTransformFeedback(transformFeedback);
6132 transformFeedbackObject->release(this);
6133 }
6134
6135 mTransformFeedbackHandleAllocator.release(transformFeedback);
6136 }
6137 }
6138}
6139
6140void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6141{
6142 for (int i = 0; i < n; i++)
6143 {
6144 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6145 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6146 ids[i] = transformFeedback;
6147 }
6148}
6149
6150bool Context::isTransformFeedback(GLuint id)
6151{
6152 if (id == 0)
6153 {
6154 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6155 // returns FALSE
6156 return GL_FALSE;
6157 }
6158
6159 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6160 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6161}
6162
6163void Context::pauseTransformFeedback()
6164{
6165 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6166 transformFeedback->pause();
6167}
6168
6169void Context::resumeTransformFeedback()
6170{
6171 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6172 transformFeedback->resume();
6173}
6174
Jamie Madill12e957f2017-08-26 21:42:26 -04006175void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6176{
6177 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006178 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006179}
6180
Brandon Jones59770802018-04-02 13:18:42 -07006181void Context::getUniformuivRobust(GLuint program,
6182 GLint location,
6183 GLsizei bufSize,
6184 GLsizei *length,
6185 GLuint *params)
6186{
6187 getUniformuiv(program, location, params);
6188}
6189
Jamie Madill12e957f2017-08-26 21:42:26 -04006190GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6191{
6192 const Program *programObject = getProgram(program);
6193 return programObject->getFragDataLocation(name);
6194}
6195
6196void Context::getUniformIndices(GLuint program,
6197 GLsizei uniformCount,
6198 const GLchar *const *uniformNames,
6199 GLuint *uniformIndices)
6200{
6201 const Program *programObject = getProgram(program);
6202 if (!programObject->isLinked())
6203 {
6204 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6205 {
6206 uniformIndices[uniformId] = GL_INVALID_INDEX;
6207 }
6208 }
6209 else
6210 {
6211 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6212 {
6213 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6214 }
6215 }
6216}
6217
6218void Context::getActiveUniformsiv(GLuint program,
6219 GLsizei uniformCount,
6220 const GLuint *uniformIndices,
6221 GLenum pname,
6222 GLint *params)
6223{
6224 const Program *programObject = getProgram(program);
6225 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6226 {
6227 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006228 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006229 }
6230}
6231
6232GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6233{
6234 const Program *programObject = getProgram(program);
6235 return programObject->getUniformBlockIndex(uniformBlockName);
6236}
6237
6238void Context::getActiveUniformBlockiv(GLuint program,
6239 GLuint uniformBlockIndex,
6240 GLenum pname,
6241 GLint *params)
6242{
6243 const Program *programObject = getProgram(program);
6244 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6245}
6246
Brandon Jones59770802018-04-02 13:18:42 -07006247void Context::getActiveUniformBlockivRobust(GLuint program,
6248 GLuint uniformBlockIndex,
6249 GLenum pname,
6250 GLsizei bufSize,
6251 GLsizei *length,
6252 GLint *params)
6253{
6254 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6255}
6256
Jamie Madill12e957f2017-08-26 21:42:26 -04006257void Context::getActiveUniformBlockName(GLuint program,
6258 GLuint uniformBlockIndex,
6259 GLsizei bufSize,
6260 GLsizei *length,
6261 GLchar *uniformBlockName)
6262{
6263 const Program *programObject = getProgram(program);
6264 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6265}
6266
6267void Context::uniformBlockBinding(GLuint program,
6268 GLuint uniformBlockIndex,
6269 GLuint uniformBlockBinding)
6270{
6271 Program *programObject = getProgram(program);
6272 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006273
6274 if (programObject->isInUse())
6275 {
6276 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006277 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006278 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006279}
6280
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006281GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6282{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006283 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6284 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006285
Jamie Madill70b5bb02017-08-28 13:32:37 -04006286 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006287 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006288 if (error.isError())
6289 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006290 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006291 handleError(error);
6292 return nullptr;
6293 }
6294
Jamie Madill70b5bb02017-08-28 13:32:37 -04006295 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006296}
6297
6298GLboolean Context::isSync(GLsync sync)
6299{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006300 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006301}
6302
6303GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6304{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006305 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006306
6307 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006308 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006309 return result;
6310}
6311
6312void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6313{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006314 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006315 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006316}
6317
6318void Context::getInteger64v(GLenum pname, GLint64 *params)
6319{
6320 GLenum nativeType = GL_NONE;
6321 unsigned int numParams = 0;
6322 getQueryParameterInfo(pname, &nativeType, &numParams);
6323
6324 if (nativeType == GL_INT_64_ANGLEX)
6325 {
6326 getInteger64vImpl(pname, params);
6327 }
6328 else
6329 {
6330 CastStateValues(this, nativeType, pname, numParams, params);
6331 }
6332}
6333
Brandon Jones59770802018-04-02 13:18:42 -07006334void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6335{
6336 getInteger64v(pname, data);
6337}
6338
Corentin Wallez336129f2017-10-17 15:55:40 -04006339void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006340{
6341 Buffer *buffer = mGLState.getTargetBuffer(target);
6342 QueryBufferParameteri64v(buffer, pname, params);
6343}
6344
Brandon Jones59770802018-04-02 13:18:42 -07006345void Context::getBufferParameteri64vRobust(BufferBinding target,
6346 GLenum pname,
6347 GLsizei bufSize,
6348 GLsizei *length,
6349 GLint64 *params)
6350{
6351 getBufferParameteri64v(target, pname, params);
6352}
6353
Jamie Madill3ef140a2017-08-26 23:11:21 -04006354void Context::genSamplers(GLsizei count, GLuint *samplers)
6355{
6356 for (int i = 0; i < count; i++)
6357 {
6358 samplers[i] = mState.mSamplers->createSampler();
6359 }
6360}
6361
6362void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6363{
6364 for (int i = 0; i < count; i++)
6365 {
6366 GLuint sampler = samplers[i];
6367
6368 if (mState.mSamplers->getSampler(sampler))
6369 {
6370 detachSampler(sampler);
6371 }
6372
6373 mState.mSamplers->deleteObject(this, sampler);
6374 }
6375}
6376
6377void Context::getInternalformativ(GLenum target,
6378 GLenum internalformat,
6379 GLenum pname,
6380 GLsizei bufSize,
6381 GLint *params)
6382{
6383 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6384 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6385}
6386
Brandon Jones59770802018-04-02 13:18:42 -07006387void Context::getInternalformativRobust(GLenum target,
6388 GLenum internalformat,
6389 GLenum pname,
6390 GLsizei bufSize,
6391 GLsizei *length,
6392 GLint *params)
6393{
6394 getInternalformativ(target, internalformat, pname, bufSize, params);
6395}
6396
Jiajia Qin5451d532017-11-16 17:16:34 +08006397void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6398{
6399 programUniform1iv(program, location, 1, &v0);
6400}
6401
6402void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6403{
6404 GLint xy[2] = {v0, v1};
6405 programUniform2iv(program, location, 1, xy);
6406}
6407
6408void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6409{
6410 GLint xyz[3] = {v0, v1, v2};
6411 programUniform3iv(program, location, 1, xyz);
6412}
6413
6414void Context::programUniform4i(GLuint program,
6415 GLint location,
6416 GLint v0,
6417 GLint v1,
6418 GLint v2,
6419 GLint v3)
6420{
6421 GLint xyzw[4] = {v0, v1, v2, v3};
6422 programUniform4iv(program, location, 1, xyzw);
6423}
6424
6425void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6426{
6427 programUniform1uiv(program, location, 1, &v0);
6428}
6429
6430void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6431{
6432 GLuint xy[2] = {v0, v1};
6433 programUniform2uiv(program, location, 1, xy);
6434}
6435
6436void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6437{
6438 GLuint xyz[3] = {v0, v1, v2};
6439 programUniform3uiv(program, location, 1, xyz);
6440}
6441
6442void Context::programUniform4ui(GLuint program,
6443 GLint location,
6444 GLuint v0,
6445 GLuint v1,
6446 GLuint v2,
6447 GLuint v3)
6448{
6449 GLuint xyzw[4] = {v0, v1, v2, v3};
6450 programUniform4uiv(program, location, 1, xyzw);
6451}
6452
6453void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6454{
6455 programUniform1fv(program, location, 1, &v0);
6456}
6457
6458void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6459{
6460 GLfloat xy[2] = {v0, v1};
6461 programUniform2fv(program, location, 1, xy);
6462}
6463
6464void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6465{
6466 GLfloat xyz[3] = {v0, v1, v2};
6467 programUniform3fv(program, location, 1, xyz);
6468}
6469
6470void Context::programUniform4f(GLuint program,
6471 GLint location,
6472 GLfloat v0,
6473 GLfloat v1,
6474 GLfloat v2,
6475 GLfloat v3)
6476{
6477 GLfloat xyzw[4] = {v0, v1, v2, v3};
6478 programUniform4fv(program, location, 1, xyzw);
6479}
6480
Jamie Madill81c2e252017-09-09 23:32:46 -04006481void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6482{
6483 Program *programObject = getProgram(program);
6484 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006485 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006486}
6487
Jiajia Qin5451d532017-11-16 17:16:34 +08006488void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6489{
6490 Program *programObject = getProgram(program);
6491 ASSERT(programObject);
6492 programObject->setUniform2iv(location, count, value);
6493}
6494
6495void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6496{
6497 Program *programObject = getProgram(program);
6498 ASSERT(programObject);
6499 programObject->setUniform3iv(location, count, value);
6500}
6501
6502void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6503{
6504 Program *programObject = getProgram(program);
6505 ASSERT(programObject);
6506 programObject->setUniform4iv(location, count, value);
6507}
6508
6509void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6510{
6511 Program *programObject = getProgram(program);
6512 ASSERT(programObject);
6513 programObject->setUniform1uiv(location, count, value);
6514}
6515
6516void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6517{
6518 Program *programObject = getProgram(program);
6519 ASSERT(programObject);
6520 programObject->setUniform2uiv(location, count, value);
6521}
6522
6523void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6524{
6525 Program *programObject = getProgram(program);
6526 ASSERT(programObject);
6527 programObject->setUniform3uiv(location, count, value);
6528}
6529
6530void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6531{
6532 Program *programObject = getProgram(program);
6533 ASSERT(programObject);
6534 programObject->setUniform4uiv(location, count, value);
6535}
6536
6537void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6538{
6539 Program *programObject = getProgram(program);
6540 ASSERT(programObject);
6541 programObject->setUniform1fv(location, count, value);
6542}
6543
6544void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6545{
6546 Program *programObject = getProgram(program);
6547 ASSERT(programObject);
6548 programObject->setUniform2fv(location, count, value);
6549}
6550
6551void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6552{
6553 Program *programObject = getProgram(program);
6554 ASSERT(programObject);
6555 programObject->setUniform3fv(location, count, value);
6556}
6557
6558void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6559{
6560 Program *programObject = getProgram(program);
6561 ASSERT(programObject);
6562 programObject->setUniform4fv(location, count, value);
6563}
6564
6565void Context::programUniformMatrix2fv(GLuint program,
6566 GLint location,
6567 GLsizei count,
6568 GLboolean transpose,
6569 const GLfloat *value)
6570{
6571 Program *programObject = getProgram(program);
6572 ASSERT(programObject);
6573 programObject->setUniformMatrix2fv(location, count, transpose, value);
6574}
6575
6576void Context::programUniformMatrix3fv(GLuint program,
6577 GLint location,
6578 GLsizei count,
6579 GLboolean transpose,
6580 const GLfloat *value)
6581{
6582 Program *programObject = getProgram(program);
6583 ASSERT(programObject);
6584 programObject->setUniformMatrix3fv(location, count, transpose, value);
6585}
6586
6587void Context::programUniformMatrix4fv(GLuint program,
6588 GLint location,
6589 GLsizei count,
6590 GLboolean transpose,
6591 const GLfloat *value)
6592{
6593 Program *programObject = getProgram(program);
6594 ASSERT(programObject);
6595 programObject->setUniformMatrix4fv(location, count, transpose, value);
6596}
6597
6598void Context::programUniformMatrix2x3fv(GLuint program,
6599 GLint location,
6600 GLsizei count,
6601 GLboolean transpose,
6602 const GLfloat *value)
6603{
6604 Program *programObject = getProgram(program);
6605 ASSERT(programObject);
6606 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6607}
6608
6609void Context::programUniformMatrix3x2fv(GLuint program,
6610 GLint location,
6611 GLsizei count,
6612 GLboolean transpose,
6613 const GLfloat *value)
6614{
6615 Program *programObject = getProgram(program);
6616 ASSERT(programObject);
6617 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6618}
6619
6620void Context::programUniformMatrix2x4fv(GLuint program,
6621 GLint location,
6622 GLsizei count,
6623 GLboolean transpose,
6624 const GLfloat *value)
6625{
6626 Program *programObject = getProgram(program);
6627 ASSERT(programObject);
6628 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6629}
6630
6631void Context::programUniformMatrix4x2fv(GLuint program,
6632 GLint location,
6633 GLsizei count,
6634 GLboolean transpose,
6635 const GLfloat *value)
6636{
6637 Program *programObject = getProgram(program);
6638 ASSERT(programObject);
6639 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6640}
6641
6642void Context::programUniformMatrix3x4fv(GLuint program,
6643 GLint location,
6644 GLsizei count,
6645 GLboolean transpose,
6646 const GLfloat *value)
6647{
6648 Program *programObject = getProgram(program);
6649 ASSERT(programObject);
6650 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6651}
6652
6653void Context::programUniformMatrix4x3fv(GLuint program,
6654 GLint location,
6655 GLsizei count,
6656 GLboolean transpose,
6657 const GLfloat *value)
6658{
6659 Program *programObject = getProgram(program);
6660 ASSERT(programObject);
6661 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6662}
6663
Jamie Madill81c2e252017-09-09 23:32:46 -04006664void Context::onTextureChange(const Texture *texture)
6665{
6666 // Conservatively assume all textures are dirty.
6667 // TODO(jmadill): More fine-grained update.
6668 mGLState.setObjectDirty(GL_TEXTURE);
6669}
6670
James Darpiniane8a93c62018-01-04 18:02:24 -08006671bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6672{
6673 return mGLState.isCurrentTransformFeedback(tf);
6674}
James Darpiniane8a93c62018-01-04 18:02:24 -08006675
Yunchao Hea336b902017-08-02 16:05:21 +08006676void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6677{
6678 for (int i = 0; i < count; i++)
6679 {
6680 pipelines[i] = createProgramPipeline();
6681 }
6682}
6683
6684void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6685{
6686 for (int i = 0; i < count; i++)
6687 {
6688 if (pipelines[i] != 0)
6689 {
6690 deleteProgramPipeline(pipelines[i]);
6691 }
6692 }
6693}
6694
6695GLboolean Context::isProgramPipeline(GLuint pipeline)
6696{
6697 if (pipeline == 0)
6698 {
6699 return GL_FALSE;
6700 }
6701
6702 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6703}
6704
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006705void Context::finishFenceNV(GLuint fence)
6706{
6707 FenceNV *fenceObject = getFenceNV(fence);
6708
6709 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006710 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006711}
6712
6713void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6714{
6715 FenceNV *fenceObject = getFenceNV(fence);
6716
6717 ASSERT(fenceObject && fenceObject->isSet());
6718
6719 switch (pname)
6720 {
6721 case GL_FENCE_STATUS_NV:
6722 {
6723 // GL_NV_fence spec:
6724 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6725 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6726 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6727 GLboolean status = GL_TRUE;
6728 if (fenceObject->getStatus() != GL_TRUE)
6729 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006730 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006731 }
6732 *params = status;
6733 break;
6734 }
6735
6736 case GL_FENCE_CONDITION_NV:
6737 {
6738 *params = static_cast<GLint>(fenceObject->getCondition());
6739 break;
6740 }
6741
6742 default:
6743 UNREACHABLE();
6744 }
6745}
6746
6747void Context::getTranslatedShaderSource(GLuint shader,
6748 GLsizei bufsize,
6749 GLsizei *length,
6750 GLchar *source)
6751{
6752 Shader *shaderObject = getShader(shader);
6753 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006754 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006755}
6756
6757void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6758{
6759 Program *programObject = getProgram(program);
6760 ASSERT(programObject);
6761
6762 programObject->getUniformfv(this, location, params);
6763}
6764
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006765void Context::getnUniformfvRobust(GLuint program,
6766 GLint location,
6767 GLsizei bufSize,
6768 GLsizei *length,
6769 GLfloat *params)
6770{
6771 UNIMPLEMENTED();
6772}
6773
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006774void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6775{
6776 Program *programObject = getProgram(program);
6777 ASSERT(programObject);
6778
6779 programObject->getUniformiv(this, location, params);
6780}
6781
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006782void Context::getnUniformivRobust(GLuint program,
6783 GLint location,
6784 GLsizei bufSize,
6785 GLsizei *length,
6786 GLint *params)
6787{
6788 UNIMPLEMENTED();
6789}
6790
6791void Context::getnUniformuivRobust(GLuint program,
6792 GLint location,
6793 GLsizei bufSize,
6794 GLsizei *length,
6795 GLuint *params)
6796{
6797 UNIMPLEMENTED();
6798}
6799
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006800GLboolean Context::isFenceNV(GLuint fence)
6801{
6802 FenceNV *fenceObject = getFenceNV(fence);
6803
6804 if (fenceObject == nullptr)
6805 {
6806 return GL_FALSE;
6807 }
6808
6809 // GL_NV_fence spec:
6810 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6811 // existing fence.
6812 return fenceObject->isSet();
6813}
6814
6815void Context::readnPixels(GLint x,
6816 GLint y,
6817 GLsizei width,
6818 GLsizei height,
6819 GLenum format,
6820 GLenum type,
6821 GLsizei bufSize,
6822 void *data)
6823{
6824 return readPixels(x, y, width, height, format, type, data);
6825}
6826
Jamie Madill007530e2017-12-28 14:27:04 -05006827void Context::setFenceNV(GLuint fence, GLenum condition)
6828{
6829 ASSERT(condition == GL_ALL_COMPLETED_NV);
6830
6831 FenceNV *fenceObject = getFenceNV(fence);
6832 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006833 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006834}
6835
6836GLboolean Context::testFenceNV(GLuint fence)
6837{
6838 FenceNV *fenceObject = getFenceNV(fence);
6839
6840 ASSERT(fenceObject != nullptr);
6841 ASSERT(fenceObject->isSet() == GL_TRUE);
6842
6843 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006844 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006845 if (error.isError())
6846 {
6847 handleError(error);
6848 return GL_TRUE;
6849 }
6850
6851 return result;
6852}
6853
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006854void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006855{
6856 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006857 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006858 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006859}
6860
Jamie Madillfa920eb2018-01-04 11:45:50 -05006861void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006862{
6863 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006864 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006865 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6866}
6867
Jamie Madillfa920eb2018-01-04 11:45:50 -05006868void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6869{
6870 UNIMPLEMENTED();
6871}
6872
Jamie Madill5b772312018-03-08 20:28:32 -05006873bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6874{
6875 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6876 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6877 // to the fact that it is stored internally as a float, and so would require conversion
6878 // if returned from Context::getIntegerv. Since this conversion is already implemented
6879 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6880 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6881 // application.
6882 switch (pname)
6883 {
6884 case GL_COMPRESSED_TEXTURE_FORMATS:
6885 {
6886 *type = GL_INT;
6887 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6888 return true;
6889 }
6890 case GL_SHADER_BINARY_FORMATS:
6891 {
6892 *type = GL_INT;
6893 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6894 return true;
6895 }
6896
6897 case GL_MAX_VERTEX_ATTRIBS:
6898 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6899 case GL_MAX_VARYING_VECTORS:
6900 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6901 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6902 case GL_MAX_TEXTURE_IMAGE_UNITS:
6903 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6904 case GL_MAX_RENDERBUFFER_SIZE:
6905 case GL_NUM_SHADER_BINARY_FORMATS:
6906 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6907 case GL_ARRAY_BUFFER_BINDING:
6908 case GL_FRAMEBUFFER_BINDING:
6909 case GL_RENDERBUFFER_BINDING:
6910 case GL_CURRENT_PROGRAM:
6911 case GL_PACK_ALIGNMENT:
6912 case GL_UNPACK_ALIGNMENT:
6913 case GL_GENERATE_MIPMAP_HINT:
6914 case GL_RED_BITS:
6915 case GL_GREEN_BITS:
6916 case GL_BLUE_BITS:
6917 case GL_ALPHA_BITS:
6918 case GL_DEPTH_BITS:
6919 case GL_STENCIL_BITS:
6920 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6921 case GL_CULL_FACE_MODE:
6922 case GL_FRONT_FACE:
6923 case GL_ACTIVE_TEXTURE:
6924 case GL_STENCIL_FUNC:
6925 case GL_STENCIL_VALUE_MASK:
6926 case GL_STENCIL_REF:
6927 case GL_STENCIL_FAIL:
6928 case GL_STENCIL_PASS_DEPTH_FAIL:
6929 case GL_STENCIL_PASS_DEPTH_PASS:
6930 case GL_STENCIL_BACK_FUNC:
6931 case GL_STENCIL_BACK_VALUE_MASK:
6932 case GL_STENCIL_BACK_REF:
6933 case GL_STENCIL_BACK_FAIL:
6934 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6935 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6936 case GL_DEPTH_FUNC:
6937 case GL_BLEND_SRC_RGB:
6938 case GL_BLEND_SRC_ALPHA:
6939 case GL_BLEND_DST_RGB:
6940 case GL_BLEND_DST_ALPHA:
6941 case GL_BLEND_EQUATION_RGB:
6942 case GL_BLEND_EQUATION_ALPHA:
6943 case GL_STENCIL_WRITEMASK:
6944 case GL_STENCIL_BACK_WRITEMASK:
6945 case GL_STENCIL_CLEAR_VALUE:
6946 case GL_SUBPIXEL_BITS:
6947 case GL_MAX_TEXTURE_SIZE:
6948 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6949 case GL_SAMPLE_BUFFERS:
6950 case GL_SAMPLES:
6951 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6952 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6953 case GL_TEXTURE_BINDING_2D:
6954 case GL_TEXTURE_BINDING_CUBE_MAP:
6955 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6956 {
6957 *type = GL_INT;
6958 *numParams = 1;
6959 return true;
6960 }
6961 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6962 {
6963 if (!getExtensions().packReverseRowOrder)
6964 {
6965 return false;
6966 }
6967 *type = GL_INT;
6968 *numParams = 1;
6969 return true;
6970 }
6971 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6972 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6973 {
6974 if (!getExtensions().textureRectangle)
6975 {
6976 return false;
6977 }
6978 *type = GL_INT;
6979 *numParams = 1;
6980 return true;
6981 }
6982 case GL_MAX_DRAW_BUFFERS_EXT:
6983 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6984 {
6985 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6986 {
6987 return false;
6988 }
6989 *type = GL_INT;
6990 *numParams = 1;
6991 return true;
6992 }
6993 case GL_MAX_VIEWPORT_DIMS:
6994 {
6995 *type = GL_INT;
6996 *numParams = 2;
6997 return true;
6998 }
6999 case GL_VIEWPORT:
7000 case GL_SCISSOR_BOX:
7001 {
7002 *type = GL_INT;
7003 *numParams = 4;
7004 return true;
7005 }
7006 case GL_SHADER_COMPILER:
7007 case GL_SAMPLE_COVERAGE_INVERT:
7008 case GL_DEPTH_WRITEMASK:
7009 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7010 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7011 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7012 // bool-natural
7013 case GL_SAMPLE_COVERAGE:
7014 case GL_SCISSOR_TEST:
7015 case GL_STENCIL_TEST:
7016 case GL_DEPTH_TEST:
7017 case GL_BLEND:
7018 case GL_DITHER:
7019 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7020 {
7021 *type = GL_BOOL;
7022 *numParams = 1;
7023 return true;
7024 }
7025 case GL_COLOR_WRITEMASK:
7026 {
7027 *type = GL_BOOL;
7028 *numParams = 4;
7029 return true;
7030 }
7031 case GL_POLYGON_OFFSET_FACTOR:
7032 case GL_POLYGON_OFFSET_UNITS:
7033 case GL_SAMPLE_COVERAGE_VALUE:
7034 case GL_DEPTH_CLEAR_VALUE:
7035 case GL_LINE_WIDTH:
7036 {
7037 *type = GL_FLOAT;
7038 *numParams = 1;
7039 return true;
7040 }
7041 case GL_ALIASED_LINE_WIDTH_RANGE:
7042 case GL_ALIASED_POINT_SIZE_RANGE:
7043 case GL_DEPTH_RANGE:
7044 {
7045 *type = GL_FLOAT;
7046 *numParams = 2;
7047 return true;
7048 }
7049 case GL_COLOR_CLEAR_VALUE:
7050 case GL_BLEND_COLOR:
7051 {
7052 *type = GL_FLOAT;
7053 *numParams = 4;
7054 return true;
7055 }
7056 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7057 if (!getExtensions().textureFilterAnisotropic)
7058 {
7059 return false;
7060 }
7061 *type = GL_FLOAT;
7062 *numParams = 1;
7063 return true;
7064 case GL_TIMESTAMP_EXT:
7065 if (!getExtensions().disjointTimerQuery)
7066 {
7067 return false;
7068 }
7069 *type = GL_INT_64_ANGLEX;
7070 *numParams = 1;
7071 return true;
7072 case GL_GPU_DISJOINT_EXT:
7073 if (!getExtensions().disjointTimerQuery)
7074 {
7075 return false;
7076 }
7077 *type = GL_INT;
7078 *numParams = 1;
7079 return true;
7080 case GL_COVERAGE_MODULATION_CHROMIUM:
7081 if (!getExtensions().framebufferMixedSamples)
7082 {
7083 return false;
7084 }
7085 *type = GL_INT;
7086 *numParams = 1;
7087 return true;
7088 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7089 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7090 {
7091 return false;
7092 }
7093 *type = GL_INT;
7094 *numParams = 1;
7095 return true;
7096 }
7097
7098 if (getExtensions().debug)
7099 {
7100 switch (pname)
7101 {
7102 case GL_DEBUG_LOGGED_MESSAGES:
7103 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7104 case GL_DEBUG_GROUP_STACK_DEPTH:
7105 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7106 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7107 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7108 case GL_MAX_LABEL_LENGTH:
7109 *type = GL_INT;
7110 *numParams = 1;
7111 return true;
7112
7113 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7114 case GL_DEBUG_OUTPUT:
7115 *type = GL_BOOL;
7116 *numParams = 1;
7117 return true;
7118 }
7119 }
7120
7121 if (getExtensions().multisampleCompatibility)
7122 {
7123 switch (pname)
7124 {
7125 case GL_MULTISAMPLE_EXT:
7126 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7127 *type = GL_BOOL;
7128 *numParams = 1;
7129 return true;
7130 }
7131 }
7132
7133 if (getExtensions().pathRendering)
7134 {
7135 switch (pname)
7136 {
7137 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7138 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7139 *type = GL_FLOAT;
7140 *numParams = 16;
7141 return true;
7142 }
7143 }
7144
7145 if (getExtensions().bindGeneratesResource)
7146 {
7147 switch (pname)
7148 {
7149 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7150 *type = GL_BOOL;
7151 *numParams = 1;
7152 return true;
7153 }
7154 }
7155
7156 if (getExtensions().clientArrays)
7157 {
7158 switch (pname)
7159 {
7160 case GL_CLIENT_ARRAYS_ANGLE:
7161 *type = GL_BOOL;
7162 *numParams = 1;
7163 return true;
7164 }
7165 }
7166
7167 if (getExtensions().sRGBWriteControl)
7168 {
7169 switch (pname)
7170 {
7171 case GL_FRAMEBUFFER_SRGB_EXT:
7172 *type = GL_BOOL;
7173 *numParams = 1;
7174 return true;
7175 }
7176 }
7177
7178 if (getExtensions().robustResourceInitialization &&
7179 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7180 {
7181 *type = GL_BOOL;
7182 *numParams = 1;
7183 return true;
7184 }
7185
7186 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7187 {
7188 *type = GL_BOOL;
7189 *numParams = 1;
7190 return true;
7191 }
7192
jchen1082af6202018-06-22 10:59:52 +08007193 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7194 {
7195 *type = GL_INT;
7196 *numParams = 1;
7197 return true;
7198 }
7199
Jamie Madill5b772312018-03-08 20:28:32 -05007200 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7201 switch (pname)
7202 {
7203 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7204 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7205 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7206 {
7207 return false;
7208 }
7209 *type = GL_INT;
7210 *numParams = 1;
7211 return true;
7212
7213 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7214 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7215 {
7216 return false;
7217 }
7218 *type = GL_INT;
7219 *numParams = 1;
7220 return true;
7221
7222 case GL_PROGRAM_BINARY_FORMATS_OES:
7223 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7224 {
7225 return false;
7226 }
7227 *type = GL_INT;
7228 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7229 return true;
7230
7231 case GL_PACK_ROW_LENGTH:
7232 case GL_PACK_SKIP_ROWS:
7233 case GL_PACK_SKIP_PIXELS:
7234 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7235 {
7236 return false;
7237 }
7238 *type = GL_INT;
7239 *numParams = 1;
7240 return true;
7241 case GL_UNPACK_ROW_LENGTH:
7242 case GL_UNPACK_SKIP_ROWS:
7243 case GL_UNPACK_SKIP_PIXELS:
7244 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7245 {
7246 return false;
7247 }
7248 *type = GL_INT;
7249 *numParams = 1;
7250 return true;
7251 case GL_VERTEX_ARRAY_BINDING:
7252 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7253 {
7254 return false;
7255 }
7256 *type = GL_INT;
7257 *numParams = 1;
7258 return true;
7259 case GL_PIXEL_PACK_BUFFER_BINDING:
7260 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7261 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7262 {
7263 return false;
7264 }
7265 *type = GL_INT;
7266 *numParams = 1;
7267 return true;
7268 case GL_MAX_SAMPLES:
7269 {
7270 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7271 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7272 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7273 {
7274 return false;
7275 }
7276 *type = GL_INT;
7277 *numParams = 1;
7278 return true;
7279
7280 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7281 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7282 {
7283 return false;
7284 }
7285 *type = GL_INT;
7286 *numParams = 1;
7287 return true;
7288 }
7289 }
7290
7291 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7292 {
7293 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7294 {
7295 return false;
7296 }
7297 *type = GL_INT;
7298 *numParams = 1;
7299 return true;
7300 }
7301
7302 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7303 {
7304 *type = GL_INT;
7305 *numParams = 1;
7306 return true;
7307 }
7308
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007309 if (getClientVersion() < Version(2, 0))
7310 {
7311 switch (pname)
7312 {
7313 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007314 case GL_CLIENT_ACTIVE_TEXTURE:
7315 case GL_MATRIX_MODE:
7316 case GL_MAX_TEXTURE_UNITS:
7317 case GL_MAX_MODELVIEW_STACK_DEPTH:
7318 case GL_MAX_PROJECTION_STACK_DEPTH:
7319 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007320 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007321 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007322 case GL_VERTEX_ARRAY_STRIDE:
7323 case GL_NORMAL_ARRAY_STRIDE:
7324 case GL_COLOR_ARRAY_STRIDE:
7325 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7326 case GL_VERTEX_ARRAY_SIZE:
7327 case GL_COLOR_ARRAY_SIZE:
7328 case GL_TEXTURE_COORD_ARRAY_SIZE:
7329 case GL_VERTEX_ARRAY_TYPE:
7330 case GL_NORMAL_ARRAY_TYPE:
7331 case GL_COLOR_ARRAY_TYPE:
7332 case GL_TEXTURE_COORD_ARRAY_TYPE:
7333 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7334 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7335 case GL_COLOR_ARRAY_BUFFER_BINDING:
7336 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7337 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7338 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7339 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007340 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007341 case GL_MODELVIEW_STACK_DEPTH:
7342 case GL_PROJECTION_STACK_DEPTH:
7343 case GL_TEXTURE_STACK_DEPTH:
7344 case GL_LOGIC_OP_MODE:
7345 case GL_BLEND_SRC:
7346 case GL_BLEND_DST:
7347 case GL_PERSPECTIVE_CORRECTION_HINT:
7348 case GL_POINT_SMOOTH_HINT:
7349 case GL_LINE_SMOOTH_HINT:
7350 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007351 *type = GL_INT;
7352 *numParams = 1;
7353 return true;
7354 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007355 case GL_FOG_DENSITY:
7356 case GL_FOG_START:
7357 case GL_FOG_END:
7358 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007359 case GL_POINT_SIZE:
7360 case GL_POINT_SIZE_MIN:
7361 case GL_POINT_SIZE_MAX:
7362 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007363 *type = GL_FLOAT;
7364 *numParams = 1;
7365 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007366 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007367 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007368 *type = GL_FLOAT;
7369 *numParams = 2;
7370 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007371 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007372 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007373 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007374 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007375 *type = GL_FLOAT;
7376 *numParams = 4;
7377 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007378 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007379 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007380 *type = GL_FLOAT;
7381 *numParams = 3;
7382 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007383 case GL_MODELVIEW_MATRIX:
7384 case GL_PROJECTION_MATRIX:
7385 case GL_TEXTURE_MATRIX:
7386 *type = GL_FLOAT;
7387 *numParams = 16;
7388 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007389 case GL_LIGHT_MODEL_TWO_SIDE:
7390 *type = GL_BOOL;
7391 *numParams = 1;
7392 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007393 }
7394 }
7395
Jamie Madill5b772312018-03-08 20:28:32 -05007396 if (getClientVersion() < Version(3, 0))
7397 {
7398 return false;
7399 }
7400
7401 // Check for ES3.0+ parameter names
7402 switch (pname)
7403 {
7404 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7405 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7406 case GL_UNIFORM_BUFFER_BINDING:
7407 case GL_TRANSFORM_FEEDBACK_BINDING:
7408 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7409 case GL_COPY_READ_BUFFER_BINDING:
7410 case GL_COPY_WRITE_BUFFER_BINDING:
7411 case GL_SAMPLER_BINDING:
7412 case GL_READ_BUFFER:
7413 case GL_TEXTURE_BINDING_3D:
7414 case GL_TEXTURE_BINDING_2D_ARRAY:
7415 case GL_MAX_3D_TEXTURE_SIZE:
7416 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7417 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7418 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7419 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7420 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7421 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7422 case GL_MAX_VARYING_COMPONENTS:
7423 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7424 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7425 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7426 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7427 case GL_NUM_EXTENSIONS:
7428 case GL_MAJOR_VERSION:
7429 case GL_MINOR_VERSION:
7430 case GL_MAX_ELEMENTS_INDICES:
7431 case GL_MAX_ELEMENTS_VERTICES:
7432 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7433 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7434 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7435 case GL_UNPACK_IMAGE_HEIGHT:
7436 case GL_UNPACK_SKIP_IMAGES:
7437 {
7438 *type = GL_INT;
7439 *numParams = 1;
7440 return true;
7441 }
7442
7443 case GL_MAX_ELEMENT_INDEX:
7444 case GL_MAX_UNIFORM_BLOCK_SIZE:
7445 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7446 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7447 case GL_MAX_SERVER_WAIT_TIMEOUT:
7448 {
7449 *type = GL_INT_64_ANGLEX;
7450 *numParams = 1;
7451 return true;
7452 }
7453
7454 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7455 case GL_TRANSFORM_FEEDBACK_PAUSED:
7456 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7457 case GL_RASTERIZER_DISCARD:
7458 {
7459 *type = GL_BOOL;
7460 *numParams = 1;
7461 return true;
7462 }
7463
7464 case GL_MAX_TEXTURE_LOD_BIAS:
7465 {
7466 *type = GL_FLOAT;
7467 *numParams = 1;
7468 return true;
7469 }
7470 }
7471
7472 if (getExtensions().requestExtension)
7473 {
7474 switch (pname)
7475 {
7476 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7477 *type = GL_INT;
7478 *numParams = 1;
7479 return true;
7480 }
7481 }
7482
7483 if (getClientVersion() < Version(3, 1))
7484 {
7485 return false;
7486 }
7487
7488 switch (pname)
7489 {
7490 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7491 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7492 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7493 case GL_MAX_FRAMEBUFFER_WIDTH:
7494 case GL_MAX_FRAMEBUFFER_HEIGHT:
7495 case GL_MAX_FRAMEBUFFER_SAMPLES:
7496 case GL_MAX_SAMPLE_MASK_WORDS:
7497 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7498 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7499 case GL_MAX_INTEGER_SAMPLES:
7500 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7501 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7502 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7503 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7504 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7505 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7506 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7507 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7508 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7509 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7510 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7511 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7512 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7513 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7514 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7515 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7516 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7517 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7518 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7519 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7520 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7521 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7522 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7523 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7524 case GL_MAX_UNIFORM_LOCATIONS:
7525 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7526 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7527 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7528 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7529 case GL_MAX_IMAGE_UNITS:
7530 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7531 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7532 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7533 case GL_SHADER_STORAGE_BUFFER_BINDING:
7534 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7535 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007536 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007537 *type = GL_INT;
7538 *numParams = 1;
7539 return true;
7540 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7541 *type = GL_INT_64_ANGLEX;
7542 *numParams = 1;
7543 return true;
7544 case GL_SAMPLE_MASK:
7545 *type = GL_BOOL;
7546 *numParams = 1;
7547 return true;
7548 }
7549
7550 if (getExtensions().geometryShader)
7551 {
7552 switch (pname)
7553 {
7554 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7555 case GL_LAYER_PROVOKING_VERTEX_EXT:
7556 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7557 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7558 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7559 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7560 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7561 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7562 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7563 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7564 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7565 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7566 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7567 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7568 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7569 *type = GL_INT;
7570 *numParams = 1;
7571 return true;
7572 }
7573 }
7574
7575 return false;
7576}
7577
7578bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7579{
7580 if (getClientVersion() < Version(3, 0))
7581 {
7582 return false;
7583 }
7584
7585 switch (target)
7586 {
7587 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7588 case GL_UNIFORM_BUFFER_BINDING:
7589 {
7590 *type = GL_INT;
7591 *numParams = 1;
7592 return true;
7593 }
7594 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7595 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7596 case GL_UNIFORM_BUFFER_START:
7597 case GL_UNIFORM_BUFFER_SIZE:
7598 {
7599 *type = GL_INT_64_ANGLEX;
7600 *numParams = 1;
7601 return true;
7602 }
7603 }
7604
7605 if (getClientVersion() < Version(3, 1))
7606 {
7607 return false;
7608 }
7609
7610 switch (target)
7611 {
7612 case GL_IMAGE_BINDING_LAYERED:
7613 {
7614 *type = GL_BOOL;
7615 *numParams = 1;
7616 return true;
7617 }
7618 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7619 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7620 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7621 case GL_SHADER_STORAGE_BUFFER_BINDING:
7622 case GL_VERTEX_BINDING_BUFFER:
7623 case GL_VERTEX_BINDING_DIVISOR:
7624 case GL_VERTEX_BINDING_OFFSET:
7625 case GL_VERTEX_BINDING_STRIDE:
7626 case GL_SAMPLE_MASK_VALUE:
7627 case GL_IMAGE_BINDING_NAME:
7628 case GL_IMAGE_BINDING_LEVEL:
7629 case GL_IMAGE_BINDING_LAYER:
7630 case GL_IMAGE_BINDING_ACCESS:
7631 case GL_IMAGE_BINDING_FORMAT:
7632 {
7633 *type = GL_INT;
7634 *numParams = 1;
7635 return true;
7636 }
7637 case GL_ATOMIC_COUNTER_BUFFER_START:
7638 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7639 case GL_SHADER_STORAGE_BUFFER_START:
7640 case GL_SHADER_STORAGE_BUFFER_SIZE:
7641 {
7642 *type = GL_INT_64_ANGLEX;
7643 *numParams = 1;
7644 return true;
7645 }
7646 }
7647
7648 return false;
7649}
7650
7651Program *Context::getProgram(GLuint handle) const
7652{
7653 return mState.mShaderPrograms->getProgram(handle);
7654}
7655
7656Shader *Context::getShader(GLuint handle) const
7657{
7658 return mState.mShaderPrograms->getShader(handle);
7659}
7660
7661bool Context::isTextureGenerated(GLuint texture) const
7662{
7663 return mState.mTextures->isHandleGenerated(texture);
7664}
7665
Jamie Madill5b772312018-03-08 20:28:32 -05007666bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7667{
7668 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7669}
7670
7671bool Context::isFramebufferGenerated(GLuint framebuffer) const
7672{
7673 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7674}
7675
7676bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7677{
7678 return mState.mPipelines->isHandleGenerated(pipeline);
7679}
7680
7681bool Context::usingDisplayTextureShareGroup() const
7682{
7683 return mDisplayTextureShareGroup;
7684}
7685
7686GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7687{
7688 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7689 internalformat == GL_DEPTH_STENCIL
7690 ? GL_DEPTH24_STENCIL8
7691 : internalformat;
7692}
7693
jchen1082af6202018-06-22 10:59:52 +08007694void Context::maxShaderCompilerThreads(GLuint count)
7695{
jchen107ae70d82018-07-06 13:47:01 +08007696 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08007697 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007698 // A count of zero specifies a request for no parallel compiling or linking.
7699 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7700 {
7701 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7702 }
7703 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007704}
7705
Jamie Madill2eb65032018-07-30 10:25:57 -04007706bool Context::isGLES1() const
7707{
7708 return mState.getClientVersion() < Version(2, 0);
7709}
7710
Jamie Madilla11819d2018-07-30 10:26:01 -04007711void Context::onSubjectStateChange(const Context *context,
7712 angle::SubjectIndex index,
7713 angle::SubjectMessage message)
7714{
Jamie Madilla11819d2018-07-30 10:26:01 -04007715 switch (index)
7716 {
7717 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007718 switch (message)
7719 {
7720 case angle::SubjectMessage::CONTENTS_CHANGED:
7721 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
7722 mStateCache.onVertexArrayBufferContentsChange(this);
7723 break;
7724 case angle::SubjectMessage::RESOURCE_MAPPED:
7725 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7726 case angle::SubjectMessage::BINDING_CHANGED:
7727 mStateCache.onVertexArrayBufferStateChange(this);
7728 break;
7729 default:
7730 break;
7731 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007732 break;
7733
7734 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007735 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7736 {
7737 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
7738 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007739 break;
7740
7741 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007742 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7743 {
7744 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
7745 }
7746 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04007747 break;
7748
7749 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04007750 if (index < kTextureMaxSubjectIndex)
7751 {
7752 mGLState.onActiveTextureStateChange(index);
Jamie Madilld84b6732018-09-06 15:54:35 -04007753 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007754 }
7755 else
7756 {
7757 ASSERT(index < kUniformBufferMaxSubjectIndex);
7758 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04007759 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007760 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007761 break;
7762 }
7763}
7764
Jamie Madill6b873dd2018-07-12 23:56:30 -04007765// ErrorSet implementation.
7766ErrorSet::ErrorSet(Context *context) : mContext(context)
7767{
7768}
7769
7770ErrorSet::~ErrorSet() = default;
7771
Jamie Madill306b6c12018-07-27 08:12:49 -04007772void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007773{
7774 // This internal enum is used to filter internal errors that are already handled.
7775 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7776 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7777 {
7778 return;
7779 }
7780
7781 if (ANGLE_UNLIKELY(error.isError()))
7782 {
7783 GLenum code = error.getCode();
7784 mErrors.insert(code);
7785 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7786 {
7787 mContext->markContextLost();
7788 }
7789
7790 ASSERT(!error.getMessage().empty());
7791 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7792 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7793 error.getMessage());
7794 }
7795}
7796
7797bool ErrorSet::empty() const
7798{
7799 return mErrors.empty();
7800}
7801
7802GLenum ErrorSet::popError()
7803{
7804 ASSERT(!empty());
7805 GLenum error = *mErrors.begin();
7806 mErrors.erase(mErrors.begin());
7807 return error;
7808}
Jamie Madilldc358af2018-07-31 11:22:13 -04007809
7810// StateCache implementation.
Jamie Madill16e28fd2018-09-12 11:03:05 -04007811StateCache::StateCache(Context *context)
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007812 : mCachedHasAnyEnabledClientAttrib(false),
7813 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04007814 mCachedInstancedVertexElementLimit(0),
7815 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madilldc358af2018-07-31 11:22:13 -04007816{
Jamie Madill16e28fd2018-09-12 11:03:05 -04007817 updateValidDrawModes(context);
Jamie Madilldc358af2018-07-31 11:22:13 -04007818}
7819
7820StateCache::~StateCache() = default;
7821
7822void StateCache::updateActiveAttribsMask(Context *context)
7823{
7824 bool isGLES1 = context->isGLES1();
7825 const State &glState = context->getGLState();
7826
7827 if (!isGLES1 && !glState.getProgram())
7828 {
7829 mCachedActiveBufferedAttribsMask = AttributesMask();
7830 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04007831 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04007832 return;
7833 }
7834
7835 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7836 : glState.getProgram()->getActiveAttribLocationsMask();
7837
7838 const VertexArray *vao = glState.getVertexArray();
7839 ASSERT(vao);
7840
7841 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7842 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04007843 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007844
Jamie Madill0a17e482018-08-31 17:19:11 -04007845 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
7846 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04007847 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007848 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7849}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007850
7851void StateCache::updateVertexElementLimits(Context *context)
7852{
7853 const VertexArray *vao = context->getGLState().getVertexArray();
7854
7855 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7856 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7857
7858 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
7859 // If there are no buffered attributes then we should not limit the draw call count.
7860 if (!vao || !mCachedActiveBufferedAttribsMask.any())
7861 {
7862 return;
7863 }
7864
7865 const auto &vertexAttribs = vao->getVertexAttributes();
7866 const auto &vertexBindings = vao->getVertexBindings();
7867
7868 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
7869 {
7870 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
7871 ASSERT(attrib.enabled);
7872
7873 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
7874 ASSERT(context->isGLES1() ||
7875 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
7876
7877 GLint64 limit = attrib.getCachedElementLimit();
7878 if (binding.getDivisor() > 0)
7879 {
7880 mCachedInstancedVertexElementLimit =
7881 std::min(mCachedInstancedVertexElementLimit, limit);
7882 }
7883 else
7884 {
7885 mCachedNonInstancedVertexElementLimit =
7886 std::min(mCachedNonInstancedVertexElementLimit, limit);
7887 }
7888 }
7889}
Jamie Madillc43cdad2018-08-08 15:49:25 -04007890
Jamie Madilld84b6732018-09-06 15:54:35 -04007891void StateCache::updateBasicDrawStatesError()
7892{
7893 mCachedBasicDrawStatesError = kInvalidPointer;
7894}
7895
7896intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
7897{
7898 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
7899 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
7900 return mCachedBasicDrawStatesError;
7901}
7902
Jamie Madillc43cdad2018-08-08 15:49:25 -04007903void StateCache::onVertexArrayBindingChange(Context *context)
7904{
7905 updateActiveAttribsMask(context);
7906 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007907 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007908}
7909
7910void StateCache::onProgramExecutableChange(Context *context)
7911{
7912 updateActiveAttribsMask(context);
7913 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007914 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04007915 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04007916}
7917
Jamie Madilld84b6732018-09-06 15:54:35 -04007918void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04007919{
7920 updateVertexElementLimits(context);
7921}
7922
Jamie Madilld84b6732018-09-06 15:54:35 -04007923void StateCache::onVertexArrayBufferContentsChange(Context *context)
7924{
7925 updateVertexElementLimits(context);
7926 updateBasicDrawStatesError();
7927}
7928
Jamie Madillc43cdad2018-08-08 15:49:25 -04007929void StateCache::onVertexArrayStateChange(Context *context)
7930{
7931 updateActiveAttribsMask(context);
7932 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007933 updateBasicDrawStatesError();
7934}
7935
7936void StateCache::onVertexArrayBufferStateChange(Context *context)
7937{
7938 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007939}
7940
7941void StateCache::onGLES1ClientStateChange(Context *context)
7942{
7943 updateActiveAttribsMask(context);
7944}
Jamie Madilld84b6732018-09-06 15:54:35 -04007945
7946void StateCache::onDrawFramebufferChange(Context *context)
7947{
7948 updateBasicDrawStatesError();
7949}
7950
7951void StateCache::onContextCapChange(Context *context)
7952{
7953 updateBasicDrawStatesError();
7954}
7955
7956void StateCache::onStencilStateChange(Context *context)
7957{
7958 updateBasicDrawStatesError();
7959}
7960
7961void StateCache::onDefaultVertexAttributeChange(Context *context)
7962{
7963 updateBasicDrawStatesError();
7964}
7965
7966void StateCache::onActiveTextureChange(Context *context)
7967{
7968 updateBasicDrawStatesError();
7969}
7970
7971void StateCache::onQueryChange(Context *context)
7972{
7973 updateBasicDrawStatesError();
7974}
7975
7976void StateCache::onTransformFeedbackChange(Context *context)
7977{
7978 updateBasicDrawStatesError();
7979}
7980
7981void StateCache::onUniformBufferStateChange(Context *context)
7982{
7983 updateBasicDrawStatesError();
7984}
7985
7986void StateCache::onBufferBindingChange(Context *context)
7987{
7988 updateBasicDrawStatesError();
7989}
Jamie Madill526a6f62018-09-12 11:03:05 -04007990
7991void StateCache::updateValidDrawModes(Context *context)
7992{
7993 Program *program = context->getGLState().getProgram();
7994 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
7995 {
7996 mCachedValidDrawModes = {{
7997 true, /* Points */
7998 true, /* Lines */
7999 true, /* LineLoop */
8000 true, /* LineStrip */
8001 true, /* Triangles */
8002 true, /* TriangleStrip */
8003 true, /* TriangleFan */
8004 false, /* LinesAdjacency */
8005 false, /* LineStripAdjacency */
8006 false, /* TrianglesAdjacency */
8007 false, /* TriangleStripAdjacency */
8008 false, /* InvalidEnum */
8009 }};
8010 }
8011 else
8012 {
8013 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8014
8015 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
8016
8017 mCachedValidDrawModes = {{
8018 gsMode == PrimitiveMode::Points, /* Points */
8019 gsMode == PrimitiveMode::Lines, /* Lines */
8020 gsMode == PrimitiveMode::Lines, /* LineLoop */
8021 gsMode == PrimitiveMode::Lines, /* LineStrip */
8022 gsMode == PrimitiveMode::Triangles, /* Triangles */
8023 gsMode == PrimitiveMode::Triangles, /* TriangleStrip */
8024 gsMode == PrimitiveMode::Triangles, /* TriangleFan */
8025 gsMode == PrimitiveMode::LinesAdjacency, /* LinesAdjacency */
8026 gsMode == PrimitiveMode::LinesAdjacency, /* LineStripAdjacency */
8027 gsMode == PrimitiveMode::TrianglesAdjacency, /* TrianglesAdjacency */
8028 gsMode == PrimitiveMode::TrianglesAdjacency, /* TriangleStripAdjacency */
8029 false, /* InvalidEnum */
8030 }};
8031 }
8032}
Jamie Madillc29968b2016-01-20 11:17:23 -05008033} // namespace gl