blob: cb1c678fc1e2fc69e43237b47b93e4657a946228 [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{
Geoff Langd4fff502017-09-22 11:28:28 -04003537 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3538 ANGLE_CONTEXT_TRY(
3539 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003540}
3541
3542void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3543{
Geoff Langd4fff502017-09-22 11:28:28 -04003544 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3545 ANGLE_CONTEXT_TRY(
3546 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003547}
3548
3549void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3550{
Geoff Langd4fff502017-09-22 11:28:28 -04003551 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3552 ANGLE_CONTEXT_TRY(
3553 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003554}
3555
3556void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3557{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003558 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003559 ASSERT(framebufferObject);
3560
3561 // If a buffer is not present, the clear has no effect
3562 if (framebufferObject->getDepthbuffer() == nullptr &&
3563 framebufferObject->getStencilbuffer() == nullptr)
3564 {
3565 return;
3566 }
3567
Geoff Langd4fff502017-09-22 11:28:28 -04003568 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3569 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003570}
3571
3572void Context::readPixels(GLint x,
3573 GLint y,
3574 GLsizei width,
3575 GLsizei height,
3576 GLenum format,
3577 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003578 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003579{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003580 if (width == 0 || height == 0)
3581 {
3582 return;
3583 }
3584
Jamie Madillbc918e72018-03-08 09:47:21 -05003585 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003586
Jamie Madillb6664922017-07-25 12:55:04 -04003587 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3588 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003589
3590 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003591 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003592}
3593
Brandon Jones59770802018-04-02 13:18:42 -07003594void Context::readPixelsRobust(GLint x,
3595 GLint y,
3596 GLsizei width,
3597 GLsizei height,
3598 GLenum format,
3599 GLenum type,
3600 GLsizei bufSize,
3601 GLsizei *length,
3602 GLsizei *columns,
3603 GLsizei *rows,
3604 void *pixels)
3605{
3606 readPixels(x, y, width, height, format, type, pixels);
3607}
3608
3609void Context::readnPixelsRobust(GLint x,
3610 GLint y,
3611 GLsizei width,
3612 GLsizei height,
3613 GLenum format,
3614 GLenum type,
3615 GLsizei bufSize,
3616 GLsizei *length,
3617 GLsizei *columns,
3618 GLsizei *rows,
3619 void *data)
3620{
3621 readPixels(x, y, width, height, format, type, data);
3622}
3623
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003624void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003625 GLint level,
3626 GLenum internalformat,
3627 GLint x,
3628 GLint y,
3629 GLsizei width,
3630 GLsizei height,
3631 GLint border)
3632{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003633 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003634 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003635
Jamie Madillc29968b2016-01-20 11:17:23 -05003636 Rectangle sourceArea(x, y, width, height);
3637
Jamie Madill05b35b22017-10-03 09:01:44 -04003638 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003639 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003640 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003641}
3642
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003643void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003644 GLint level,
3645 GLint xoffset,
3646 GLint yoffset,
3647 GLint x,
3648 GLint y,
3649 GLsizei width,
3650 GLsizei height)
3651{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003652 if (width == 0 || height == 0)
3653 {
3654 return;
3655 }
3656
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003657 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003658 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003659
Jamie Madillc29968b2016-01-20 11:17:23 -05003660 Offset destOffset(xoffset, yoffset, 0);
3661 Rectangle sourceArea(x, y, width, height);
3662
Jamie Madill05b35b22017-10-03 09:01:44 -04003663 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003664 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003665 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003666}
3667
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003668void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003669 GLint level,
3670 GLint xoffset,
3671 GLint yoffset,
3672 GLint zoffset,
3673 GLint x,
3674 GLint y,
3675 GLsizei width,
3676 GLsizei height)
3677{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003678 if (width == 0 || height == 0)
3679 {
3680 return;
3681 }
3682
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003683 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003684 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003685
Jamie Madillc29968b2016-01-20 11:17:23 -05003686 Offset destOffset(xoffset, yoffset, zoffset);
3687 Rectangle sourceArea(x, y, width, height);
3688
Jamie Madill05b35b22017-10-03 09:01:44 -04003689 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3690 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003691 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3692 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003693}
3694
3695void Context::framebufferTexture2D(GLenum target,
3696 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003697 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003698 GLuint texture,
3699 GLint level)
3700{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003701 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003702 ASSERT(framebuffer);
3703
3704 if (texture != 0)
3705 {
3706 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003707 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003708 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003709 }
3710 else
3711 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003712 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003713 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003714
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003715 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003716}
3717
3718void Context::framebufferRenderbuffer(GLenum target,
3719 GLenum attachment,
3720 GLenum renderbuffertarget,
3721 GLuint renderbuffer)
3722{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003723 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003724 ASSERT(framebuffer);
3725
3726 if (renderbuffer != 0)
3727 {
3728 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003729
Jamie Madillcc129372018-04-12 09:13:18 -04003730 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003731 renderbufferObject);
3732 }
3733 else
3734 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003735 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003736 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003737
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003738 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003739}
3740
3741void Context::framebufferTextureLayer(GLenum target,
3742 GLenum attachment,
3743 GLuint texture,
3744 GLint level,
3745 GLint layer)
3746{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003747 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003748 ASSERT(framebuffer);
3749
3750 if (texture != 0)
3751 {
3752 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003753 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003754 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003755 }
3756 else
3757 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003758 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003759 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003760
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003761 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003762}
3763
Brandon Jones59770802018-04-02 13:18:42 -07003764void Context::framebufferTextureMultiviewLayered(GLenum target,
3765 GLenum attachment,
3766 GLuint texture,
3767 GLint level,
3768 GLint baseViewIndex,
3769 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003770{
Martin Radev82ef7742017-08-08 17:44:58 +03003771 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3772 ASSERT(framebuffer);
3773
3774 if (texture != 0)
3775 {
3776 Texture *textureObj = getTexture(texture);
3777
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003778 ImageIndex index;
3779 if (textureObj->getType() == TextureType::_2DArray)
3780 {
3781 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3782 }
3783 else
3784 {
3785 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3786 ASSERT(level == 0);
3787 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3788 }
Martin Radev82ef7742017-08-08 17:44:58 +03003789 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3790 numViews, baseViewIndex);
3791 }
3792 else
3793 {
3794 framebuffer->resetAttachment(this, attachment);
3795 }
3796
3797 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003798}
3799
Brandon Jones59770802018-04-02 13:18:42 -07003800void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3801 GLenum attachment,
3802 GLuint texture,
3803 GLint level,
3804 GLsizei numViews,
3805 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003806{
Martin Radev5dae57b2017-07-14 16:15:55 +03003807 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3808 ASSERT(framebuffer);
3809
3810 if (texture != 0)
3811 {
3812 Texture *textureObj = getTexture(texture);
3813
3814 ImageIndex index = ImageIndex::Make2D(level);
3815 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3816 textureObj, numViews, viewportOffsets);
3817 }
3818 else
3819 {
3820 framebuffer->resetAttachment(this, attachment);
3821 }
3822
3823 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003824}
3825
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003826void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3827{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003828 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3829 ASSERT(framebuffer);
3830
3831 if (texture != 0)
3832 {
3833 Texture *textureObj = getTexture(texture);
3834
3835 ImageIndex index = ImageIndex::MakeFromType(
3836 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3837 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3838 }
3839 else
3840 {
3841 framebuffer->resetAttachment(this, attachment);
3842 }
3843
3844 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003845}
3846
Jamie Madillc29968b2016-01-20 11:17:23 -05003847void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3848{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003849 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003850 ASSERT(framebuffer);
3851 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003852 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04003853 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003854}
3855
3856void Context::readBuffer(GLenum mode)
3857{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003858 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003859 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003860 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003861}
3862
3863void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3864{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003865 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003866 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003867
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003868 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003869 ASSERT(framebuffer);
3870
3871 // The specification isn't clear what should be done when the framebuffer isn't complete.
3872 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003873 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003874}
3875
3876void Context::invalidateFramebuffer(GLenum target,
3877 GLsizei numAttachments,
3878 const GLenum *attachments)
3879{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003880 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003881 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003882
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003883 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003884 ASSERT(framebuffer);
3885
Jamie Madill427064d2018-04-13 16:20:34 -04003886 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003887 {
Jamie Madill437fa652016-05-03 15:13:24 -04003888 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003889 }
Jamie Madill437fa652016-05-03 15:13:24 -04003890
Jamie Madill4928b7c2017-06-20 12:57:39 -04003891 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003892}
3893
3894void Context::invalidateSubFramebuffer(GLenum target,
3895 GLsizei numAttachments,
3896 const GLenum *attachments,
3897 GLint x,
3898 GLint y,
3899 GLsizei width,
3900 GLsizei height)
3901{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003902 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003903 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003904
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003905 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003906 ASSERT(framebuffer);
3907
Jamie Madill427064d2018-04-13 16:20:34 -04003908 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003909 {
Jamie Madill437fa652016-05-03 15:13:24 -04003910 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003911 }
Jamie Madill437fa652016-05-03 15:13:24 -04003912
3913 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003914 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003915}
3916
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003917void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003918 GLint level,
3919 GLint internalformat,
3920 GLsizei width,
3921 GLsizei height,
3922 GLint border,
3923 GLenum format,
3924 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003925 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003926{
Jamie Madillbc918e72018-03-08 09:47:21 -05003927 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003928
3929 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003930 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003931 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003932 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003933}
3934
Brandon Jones59770802018-04-02 13:18:42 -07003935void Context::texImage2DRobust(TextureTarget target,
3936 GLint level,
3937 GLint internalformat,
3938 GLsizei width,
3939 GLsizei height,
3940 GLint border,
3941 GLenum format,
3942 GLenum type,
3943 GLsizei bufSize,
3944 const void *pixels)
3945{
3946 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3947}
3948
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003949void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003950 GLint level,
3951 GLint internalformat,
3952 GLsizei width,
3953 GLsizei height,
3954 GLsizei depth,
3955 GLint border,
3956 GLenum format,
3957 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003958 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003959{
Jamie Madillbc918e72018-03-08 09:47:21 -05003960 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003961
3962 Extents size(width, height, depth);
3963 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003964 handleError(texture->setImage(this, mGLState.getUnpackState(),
3965 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003966 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003967}
3968
Brandon Jones59770802018-04-02 13:18:42 -07003969void Context::texImage3DRobust(TextureType target,
3970 GLint level,
3971 GLint internalformat,
3972 GLsizei width,
3973 GLsizei height,
3974 GLsizei depth,
3975 GLint border,
3976 GLenum format,
3977 GLenum type,
3978 GLsizei bufSize,
3979 const void *pixels)
3980{
3981 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3982}
3983
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003984void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003985 GLint level,
3986 GLint xoffset,
3987 GLint yoffset,
3988 GLsizei width,
3989 GLsizei height,
3990 GLenum format,
3991 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003992 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003993{
3994 // Zero sized uploads are valid but no-ops
3995 if (width == 0 || height == 0)
3996 {
3997 return;
3998 }
3999
Jamie Madillbc918e72018-03-08 09:47:21 -05004000 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004001
4002 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004003 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004004
4005 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4006
4007 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target, level,
4008 area, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004009}
4010
Brandon Jones59770802018-04-02 13:18:42 -07004011void Context::texSubImage2DRobust(TextureTarget target,
4012 GLint level,
4013 GLint xoffset,
4014 GLint yoffset,
4015 GLsizei width,
4016 GLsizei height,
4017 GLenum format,
4018 GLenum type,
4019 GLsizei bufSize,
4020 const void *pixels)
4021{
4022 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4023}
4024
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004025void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004026 GLint level,
4027 GLint xoffset,
4028 GLint yoffset,
4029 GLint zoffset,
4030 GLsizei width,
4031 GLsizei height,
4032 GLsizei depth,
4033 GLenum format,
4034 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004035 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004036{
4037 // Zero sized uploads are valid but no-ops
4038 if (width == 0 || height == 0 || depth == 0)
4039 {
4040 return;
4041 }
4042
Jamie Madillbc918e72018-03-08 09:47:21 -05004043 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004044
4045 Box area(xoffset, yoffset, zoffset, width, height, depth);
4046 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004047
4048 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4049
4050 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004051 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004052 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004053}
4054
Brandon Jones59770802018-04-02 13:18:42 -07004055void Context::texSubImage3DRobust(TextureType target,
4056 GLint level,
4057 GLint xoffset,
4058 GLint yoffset,
4059 GLint zoffset,
4060 GLsizei width,
4061 GLsizei height,
4062 GLsizei depth,
4063 GLenum format,
4064 GLenum type,
4065 GLsizei bufSize,
4066 const void *pixels)
4067{
4068 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4069 pixels);
4070}
4071
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004072void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004073 GLint level,
4074 GLenum internalformat,
4075 GLsizei width,
4076 GLsizei height,
4077 GLint border,
4078 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004079 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004080{
Jamie Madillbc918e72018-03-08 09:47:21 -05004081 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004082
4083 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004084 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004085 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4086 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004087 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004088}
4089
Brandon Jones59770802018-04-02 13:18:42 -07004090void Context::compressedTexImage2DRobust(TextureTarget target,
4091 GLint level,
4092 GLenum internalformat,
4093 GLsizei width,
4094 GLsizei height,
4095 GLint border,
4096 GLsizei imageSize,
4097 GLsizei dataSize,
4098 const GLvoid *data)
4099{
4100 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4101}
4102
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004103void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004104 GLint level,
4105 GLenum internalformat,
4106 GLsizei width,
4107 GLsizei height,
4108 GLsizei depth,
4109 GLint border,
4110 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004111 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004112{
Jamie Madillbc918e72018-03-08 09:47:21 -05004113 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004114
4115 Extents size(width, height, depth);
4116 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004117 handleError(texture->setCompressedImage(
4118 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004119 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004120}
4121
Brandon Jones59770802018-04-02 13:18:42 -07004122void Context::compressedTexImage3DRobust(TextureType target,
4123 GLint level,
4124 GLenum internalformat,
4125 GLsizei width,
4126 GLsizei height,
4127 GLsizei depth,
4128 GLint border,
4129 GLsizei imageSize,
4130 GLsizei dataSize,
4131 const GLvoid *data)
4132{
4133 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4134 data);
4135}
4136
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004137void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004138 GLint level,
4139 GLint xoffset,
4140 GLint yoffset,
4141 GLsizei width,
4142 GLsizei height,
4143 GLenum format,
4144 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004145 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004146{
Jamie Madillbc918e72018-03-08 09:47:21 -05004147 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004148
4149 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004150 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004151 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4152 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004153 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004154}
4155
Brandon Jones59770802018-04-02 13:18:42 -07004156void Context::compressedTexSubImage2DRobust(TextureTarget target,
4157 GLint level,
4158 GLint xoffset,
4159 GLint yoffset,
4160 GLsizei width,
4161 GLsizei height,
4162 GLenum format,
4163 GLsizei imageSize,
4164 GLsizei dataSize,
4165 const GLvoid *data)
4166{
4167 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4168 data);
4169}
4170
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004171void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004172 GLint level,
4173 GLint xoffset,
4174 GLint yoffset,
4175 GLint zoffset,
4176 GLsizei width,
4177 GLsizei height,
4178 GLsizei depth,
4179 GLenum format,
4180 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004181 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004182{
4183 // Zero sized uploads are valid but no-ops
4184 if (width == 0 || height == 0)
4185 {
4186 return;
4187 }
4188
Jamie Madillbc918e72018-03-08 09:47:21 -05004189 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004190
4191 Box area(xoffset, yoffset, zoffset, width, height, depth);
4192 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004193 handleError(texture->setCompressedSubImage(
4194 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004195 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004196}
4197
Brandon Jones59770802018-04-02 13:18:42 -07004198void Context::compressedTexSubImage3DRobust(TextureType target,
4199 GLint level,
4200 GLint xoffset,
4201 GLint yoffset,
4202 GLint zoffset,
4203 GLsizei width,
4204 GLsizei height,
4205 GLsizei depth,
4206 GLenum format,
4207 GLsizei imageSize,
4208 GLsizei dataSize,
4209 const GLvoid *data)
4210{
4211 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4212 imageSize, data);
4213}
4214
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004215void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004216{
4217 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004218 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004219}
4220
Jamie Madill007530e2017-12-28 14:27:04 -05004221void Context::copyTexture(GLuint sourceId,
4222 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004223 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004224 GLuint destId,
4225 GLint destLevel,
4226 GLint internalFormat,
4227 GLenum destType,
4228 GLboolean unpackFlipY,
4229 GLboolean unpackPremultiplyAlpha,
4230 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004231{
Jamie Madillbc918e72018-03-08 09:47:21 -05004232 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004233
4234 gl::Texture *sourceTexture = getTexture(sourceId);
4235 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004236 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4237 sourceLevel, ConvertToBool(unpackFlipY),
4238 ConvertToBool(unpackPremultiplyAlpha),
4239 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004240}
4241
Jamie Madill007530e2017-12-28 14:27:04 -05004242void Context::copySubTexture(GLuint sourceId,
4243 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004244 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004245 GLuint destId,
4246 GLint destLevel,
4247 GLint xoffset,
4248 GLint yoffset,
4249 GLint x,
4250 GLint y,
4251 GLsizei width,
4252 GLsizei height,
4253 GLboolean unpackFlipY,
4254 GLboolean unpackPremultiplyAlpha,
4255 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004256{
4257 // Zero sized copies are valid but no-ops
4258 if (width == 0 || height == 0)
4259 {
4260 return;
4261 }
4262
Jamie Madillbc918e72018-03-08 09:47:21 -05004263 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004264
4265 gl::Texture *sourceTexture = getTexture(sourceId);
4266 gl::Texture *destTexture = getTexture(destId);
4267 Offset offset(xoffset, yoffset, 0);
4268 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004269 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4270 ConvertToBool(unpackFlipY),
4271 ConvertToBool(unpackPremultiplyAlpha),
4272 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004273}
4274
Jamie Madill007530e2017-12-28 14:27:04 -05004275void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004276{
Jamie Madillbc918e72018-03-08 09:47:21 -05004277 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004278
4279 gl::Texture *sourceTexture = getTexture(sourceId);
4280 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004281 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004282}
4283
Corentin Wallez336129f2017-10-17 15:55:40 -04004284void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004285{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004286 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004287 ASSERT(buffer);
4288
Geoff Lang496c02d2016-10-20 11:38:11 -07004289 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004290}
4291
Brandon Jones59770802018-04-02 13:18:42 -07004292void Context::getBufferPointervRobust(BufferBinding target,
4293 GLenum pname,
4294 GLsizei bufSize,
4295 GLsizei *length,
4296 void **params)
4297{
4298 getBufferPointerv(target, pname, params);
4299}
4300
Corentin Wallez336129f2017-10-17 15:55:40 -04004301void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004302{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004303 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004304 ASSERT(buffer);
4305
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004306 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004307 if (error.isError())
4308 {
Jamie Madill437fa652016-05-03 15:13:24 -04004309 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004310 return nullptr;
4311 }
4312
4313 return buffer->getMapPointer();
4314}
4315
Corentin Wallez336129f2017-10-17 15:55:40 -04004316GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004317{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004318 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004319 ASSERT(buffer);
4320
4321 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004322 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004323 if (error.isError())
4324 {
Jamie Madill437fa652016-05-03 15:13:24 -04004325 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004326 return GL_FALSE;
4327 }
4328
4329 return result;
4330}
4331
Corentin Wallez336129f2017-10-17 15:55:40 -04004332void *Context::mapBufferRange(BufferBinding target,
4333 GLintptr offset,
4334 GLsizeiptr length,
4335 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004336{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004337 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004338 ASSERT(buffer);
4339
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004340 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004341 if (error.isError())
4342 {
Jamie Madill437fa652016-05-03 15:13:24 -04004343 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004344 return nullptr;
4345 }
4346
4347 return buffer->getMapPointer();
4348}
4349
Corentin Wallez336129f2017-10-17 15:55:40 -04004350void Context::flushMappedBufferRange(BufferBinding /*target*/,
4351 GLintptr /*offset*/,
4352 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004353{
4354 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4355}
4356
Jamie Madillbc918e72018-03-08 09:47:21 -05004357Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004358{
Geoff Langa8cb2872018-03-09 16:09:40 -05004359 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004360}
4361
Jamie Madillbc918e72018-03-08 09:47:21 -05004362Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004363{
Geoff Langa8cb2872018-03-09 16:09:40 -05004364 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004365}
4366
Jamie Madillbc918e72018-03-08 09:47:21 -05004367Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004368{
Geoff Langa8cb2872018-03-09 16:09:40 -05004369 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004370}
4371
Geoff Lang9bf86f02018-07-26 11:46:34 -04004372Error Context::syncStateForPathOperation()
4373{
4374 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4375
4376 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4377 ANGLE_TRY(syncDirtyBits());
4378
4379 return NoError();
4380}
4381
Jiajia Qin5451d532017-11-16 17:16:34 +08004382void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4383{
4384 UNIMPLEMENTED();
4385}
4386
Jamie Madillc20ab272016-06-09 07:20:46 -07004387void Context::activeTexture(GLenum texture)
4388{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004389 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004390}
4391
Jamie Madill876429b2017-04-20 15:46:24 -04004392void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004393{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004394 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004395}
4396
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004397void Context::blendEquation(GLenum mode)
4398{
4399 mGLState.setBlendEquation(mode, mode);
4400}
4401
Jamie Madillc20ab272016-06-09 07:20:46 -07004402void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4403{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004404 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004405}
4406
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004407void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4408{
4409 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4410}
4411
Jamie Madillc20ab272016-06-09 07:20:46 -07004412void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4413{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004414 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004415}
4416
Jamie Madill876429b2017-04-20 15:46:24 -04004417void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004418{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004419 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004420}
4421
Jamie Madill876429b2017-04-20 15:46:24 -04004422void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004423{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004424 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004425}
4426
4427void Context::clearStencil(GLint s)
4428{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004429 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004430}
4431
4432void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4433{
Geoff Lang92019432017-11-20 13:09:34 -05004434 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4435 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004436}
4437
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004438void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004439{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004440 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004441}
4442
4443void Context::depthFunc(GLenum func)
4444{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004445 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004446}
4447
4448void Context::depthMask(GLboolean flag)
4449{
Geoff Lang92019432017-11-20 13:09:34 -05004450 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004451}
4452
Jamie Madill876429b2017-04-20 15:46:24 -04004453void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004454{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004455 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004456}
4457
4458void Context::disable(GLenum cap)
4459{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004460 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004461 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004462}
4463
4464void Context::disableVertexAttribArray(GLuint index)
4465{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004466 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004467 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004468}
4469
4470void Context::enable(GLenum cap)
4471{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004472 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004473 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004474}
4475
4476void Context::enableVertexAttribArray(GLuint index)
4477{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004478 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004479 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004480}
4481
4482void Context::frontFace(GLenum mode)
4483{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004484 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004485}
4486
4487void Context::hint(GLenum target, GLenum mode)
4488{
4489 switch (target)
4490 {
4491 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004492 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004493 break;
4494
4495 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004496 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004497 break;
4498
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004499 case GL_PERSPECTIVE_CORRECTION_HINT:
4500 case GL_POINT_SMOOTH_HINT:
4501 case GL_LINE_SMOOTH_HINT:
4502 case GL_FOG_HINT:
4503 mGLState.gles1().setHint(target, mode);
4504 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004505 default:
4506 UNREACHABLE();
4507 return;
4508 }
4509}
4510
4511void Context::lineWidth(GLfloat width)
4512{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004513 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004514}
4515
4516void Context::pixelStorei(GLenum pname, GLint param)
4517{
4518 switch (pname)
4519 {
4520 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004521 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004522 break;
4523
4524 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004525 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004526 break;
4527
4528 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004529 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004530 break;
4531
4532 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004533 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004534 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004535 break;
4536
4537 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004538 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004539 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004540 break;
4541
4542 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004543 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004544 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004545 break;
4546
4547 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004548 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004549 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004550 break;
4551
4552 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004553 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004554 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004555 break;
4556
4557 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004558 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004559 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004560 break;
4561
4562 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004563 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004564 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004565 break;
4566
4567 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004568 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004569 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004570 break;
4571
4572 default:
4573 UNREACHABLE();
4574 return;
4575 }
4576}
4577
4578void Context::polygonOffset(GLfloat factor, GLfloat units)
4579{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004580 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004581}
4582
Jamie Madill876429b2017-04-20 15:46:24 -04004583void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004584{
Geoff Lang92019432017-11-20 13:09:34 -05004585 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004586}
4587
Jiawei Shaodb342272017-09-27 10:21:45 +08004588void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4589{
4590 mGLState.setSampleMaskParams(maskNumber, mask);
4591}
4592
Jamie Madillc20ab272016-06-09 07:20:46 -07004593void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4594{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004595 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004596}
4597
4598void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4599{
4600 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4601 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004602 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004603 }
4604
4605 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4606 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004607 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004608 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004609
4610 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004611}
4612
4613void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4614{
4615 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4616 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004617 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004618 }
4619
4620 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4621 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004622 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004623 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004624
4625 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004626}
4627
4628void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4629{
4630 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4631 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004632 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004633 }
4634
4635 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4636 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004637 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004638 }
4639}
4640
4641void Context::vertexAttrib1f(GLuint index, GLfloat x)
4642{
4643 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004644 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004645 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004646}
4647
4648void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4649{
4650 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004651 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004652 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004653}
4654
4655void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4656{
4657 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004658 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004659 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004660}
4661
4662void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4663{
4664 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004665 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004666 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004667}
4668
4669void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4670{
4671 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004672 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004673 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004674}
4675
4676void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4677{
4678 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004679 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004680 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004681}
4682
4683void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4684{
4685 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004686 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004687 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004688}
4689
4690void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4691{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004692 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004693 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004694}
4695
4696void Context::vertexAttribPointer(GLuint index,
4697 GLint size,
4698 GLenum type,
4699 GLboolean normalized,
4700 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004701 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004702{
Corentin Wallez336129f2017-10-17 15:55:40 -04004703 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004704 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004705 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004706}
4707
Shao80957d92017-02-20 21:25:59 +08004708void Context::vertexAttribFormat(GLuint attribIndex,
4709 GLint size,
4710 GLenum type,
4711 GLboolean normalized,
4712 GLuint relativeOffset)
4713{
Geoff Lang92019432017-11-20 13:09:34 -05004714 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004715 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004716 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004717}
4718
4719void Context::vertexAttribIFormat(GLuint attribIndex,
4720 GLint size,
4721 GLenum type,
4722 GLuint relativeOffset)
4723{
4724 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004725 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004726}
4727
4728void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4729{
Shaodde78e82017-05-22 14:13:27 +08004730 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004731 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004732}
4733
Jiajia Qin5451d532017-11-16 17:16:34 +08004734void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004735{
4736 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004737 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004738}
4739
Jamie Madillc20ab272016-06-09 07:20:46 -07004740void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4741{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004742 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004743}
4744
4745void Context::vertexAttribIPointer(GLuint index,
4746 GLint size,
4747 GLenum type,
4748 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004749 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004750{
Corentin Wallez336129f2017-10-17 15:55:40 -04004751 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4752 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004753 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004754}
4755
4756void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4757{
4758 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004759 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004760 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004761}
4762
4763void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4764{
4765 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004766 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004767 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004768}
4769
4770void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4771{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004772 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004773 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004774}
4775
4776void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4777{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004778 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004779 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004780}
4781
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004782void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4783{
4784 const VertexAttribCurrentValueData &currentValues =
4785 getGLState().getVertexAttribCurrentValue(index);
4786 const VertexArray *vao = getGLState().getVertexArray();
4787 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4788 currentValues, pname, params);
4789}
4790
Brandon Jones59770802018-04-02 13:18:42 -07004791void Context::getVertexAttribivRobust(GLuint index,
4792 GLenum pname,
4793 GLsizei bufSize,
4794 GLsizei *length,
4795 GLint *params)
4796{
4797 getVertexAttribiv(index, pname, params);
4798}
4799
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004800void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4801{
4802 const VertexAttribCurrentValueData &currentValues =
4803 getGLState().getVertexAttribCurrentValue(index);
4804 const VertexArray *vao = getGLState().getVertexArray();
4805 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4806 currentValues, pname, params);
4807}
4808
Brandon Jones59770802018-04-02 13:18:42 -07004809void Context::getVertexAttribfvRobust(GLuint index,
4810 GLenum pname,
4811 GLsizei bufSize,
4812 GLsizei *length,
4813 GLfloat *params)
4814{
4815 getVertexAttribfv(index, pname, params);
4816}
4817
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004818void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4819{
4820 const VertexAttribCurrentValueData &currentValues =
4821 getGLState().getVertexAttribCurrentValue(index);
4822 const VertexArray *vao = getGLState().getVertexArray();
4823 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4824 currentValues, pname, params);
4825}
4826
Brandon Jones59770802018-04-02 13:18:42 -07004827void Context::getVertexAttribIivRobust(GLuint index,
4828 GLenum pname,
4829 GLsizei bufSize,
4830 GLsizei *length,
4831 GLint *params)
4832{
4833 getVertexAttribIiv(index, pname, params);
4834}
4835
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004836void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4837{
4838 const VertexAttribCurrentValueData &currentValues =
4839 getGLState().getVertexAttribCurrentValue(index);
4840 const VertexArray *vao = getGLState().getVertexArray();
4841 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4842 currentValues, pname, params);
4843}
4844
Brandon Jones59770802018-04-02 13:18:42 -07004845void Context::getVertexAttribIuivRobust(GLuint index,
4846 GLenum pname,
4847 GLsizei bufSize,
4848 GLsizei *length,
4849 GLuint *params)
4850{
4851 getVertexAttribIuiv(index, pname, params);
4852}
4853
Jamie Madill876429b2017-04-20 15:46:24 -04004854void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004855{
4856 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4857 QueryVertexAttribPointerv(attrib, pname, pointer);
4858}
4859
Brandon Jones59770802018-04-02 13:18:42 -07004860void Context::getVertexAttribPointervRobust(GLuint index,
4861 GLenum pname,
4862 GLsizei bufSize,
4863 GLsizei *length,
4864 void **pointer)
4865{
4866 getVertexAttribPointerv(index, pname, pointer);
4867}
4868
Jamie Madillc20ab272016-06-09 07:20:46 -07004869void Context::debugMessageControl(GLenum source,
4870 GLenum type,
4871 GLenum severity,
4872 GLsizei count,
4873 const GLuint *ids,
4874 GLboolean enabled)
4875{
4876 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004877 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004878 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004879}
4880
4881void Context::debugMessageInsert(GLenum source,
4882 GLenum type,
4883 GLuint id,
4884 GLenum severity,
4885 GLsizei length,
4886 const GLchar *buf)
4887{
4888 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004889 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004890}
4891
4892void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4893{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004894 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004895}
4896
4897GLuint Context::getDebugMessageLog(GLuint count,
4898 GLsizei bufSize,
4899 GLenum *sources,
4900 GLenum *types,
4901 GLuint *ids,
4902 GLenum *severities,
4903 GLsizei *lengths,
4904 GLchar *messageLog)
4905{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004906 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4907 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004908}
4909
4910void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4911{
4912 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004913 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004914 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004915}
4916
4917void Context::popDebugGroup()
4918{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004919 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004920 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004921}
4922
Corentin Wallez336129f2017-10-17 15:55:40 -04004923void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004924{
4925 Buffer *buffer = mGLState.getTargetBuffer(target);
4926 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004927 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004928}
4929
Corentin Wallez336129f2017-10-17 15:55:40 -04004930void Context::bufferSubData(BufferBinding target,
4931 GLintptr offset,
4932 GLsizeiptr size,
4933 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004934{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06004935 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04004936 {
4937 return;
4938 }
4939
4940 Buffer *buffer = mGLState.getTargetBuffer(target);
4941 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004942 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004943}
4944
Jamie Madillef300b12016-10-07 15:12:09 -04004945void Context::attachShader(GLuint program, GLuint shader)
4946{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004947 Program *programObject = mState.mShaderPrograms->getProgram(program);
4948 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004949 ASSERT(programObject && shaderObject);
4950 programObject->attachShader(shaderObject);
4951}
4952
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004953const Workarounds &Context::getWorkarounds() const
4954{
4955 return mWorkarounds;
4956}
4957
Corentin Wallez336129f2017-10-17 15:55:40 -04004958void Context::copyBufferSubData(BufferBinding readTarget,
4959 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004960 GLintptr readOffset,
4961 GLintptr writeOffset,
4962 GLsizeiptr size)
4963{
4964 // if size is zero, the copy is a successful no-op
4965 if (size == 0)
4966 {
4967 return;
4968 }
4969
4970 // TODO(jmadill): cache these.
4971 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4972 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4973
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004974 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004975}
4976
Jamie Madill01a80ee2016-11-07 12:06:18 -05004977void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4978{
4979 Program *programObject = getProgram(program);
4980 // TODO(jmadill): Re-use this from the validation if possible.
4981 ASSERT(programObject);
4982 programObject->bindAttributeLocation(index, name);
4983}
4984
Corentin Wallez336129f2017-10-17 15:55:40 -04004985void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004986{
Corentin Wallez336129f2017-10-17 15:55:40 -04004987 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4988 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04004989 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004990}
4991
Corentin Wallez336129f2017-10-17 15:55:40 -04004992void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004993{
4994 bindBufferRange(target, index, buffer, 0, 0);
4995}
4996
Corentin Wallez336129f2017-10-17 15:55:40 -04004997void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004998 GLuint index,
4999 GLuint buffer,
5000 GLintptr offset,
5001 GLsizeiptr size)
5002{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005003 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5004 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
5005 if (target == BufferBinding::Uniform)
5006 {
5007 mUniformBufferObserverBindings[index].bind(object ? object->getImplementation() : nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04005008 mStateCache.onUniformBufferStateChange(this);
5009 }
5010 else
5011 {
5012 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005013 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005014}
5015
Jamie Madill01a80ee2016-11-07 12:06:18 -05005016void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5017{
5018 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5019 {
5020 bindReadFramebuffer(framebuffer);
5021 }
5022
5023 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5024 {
5025 bindDrawFramebuffer(framebuffer);
5026 }
5027}
5028
5029void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5030{
5031 ASSERT(target == GL_RENDERBUFFER);
5032 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005033 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005034 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005035}
5036
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005037void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005038 GLsizei samples,
5039 GLenum internalformat,
5040 GLsizei width,
5041 GLsizei height,
5042 GLboolean fixedsamplelocations)
5043{
5044 Extents size(width, height, 1);
5045 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005046 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5047 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005048}
5049
Olli Etuaho89664842018-08-24 14:45:36 +03005050void Context::texStorage3DMultisample(TextureType target,
5051 GLsizei samples,
5052 GLenum internalformat,
5053 GLsizei width,
5054 GLsizei height,
5055 GLsizei depth,
5056 GLboolean fixedsamplelocations)
5057{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005058 Extents size(width, height, depth);
5059 Texture *texture = getTargetTexture(target);
5060 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5061 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005062}
5063
JiangYizhoubddc46b2016-12-09 09:50:51 +08005064void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5065{
JiangYizhou5b03f472017-01-09 10:22:53 +08005066 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5067 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005068 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005069 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005070
5071 switch (pname)
5072 {
5073 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04005074 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005075 break;
5076 default:
5077 UNREACHABLE();
5078 }
5079}
5080
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005081void Context::getMultisamplefvRobust(GLenum pname,
5082 GLuint index,
5083 GLsizei bufSize,
5084 GLsizei *length,
5085 GLfloat *val)
5086{
5087 UNIMPLEMENTED();
5088}
5089
Jamie Madille8fb6402017-02-14 17:56:40 -05005090void Context::renderbufferStorage(GLenum target,
5091 GLenum internalformat,
5092 GLsizei width,
5093 GLsizei height)
5094{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005095 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5096 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5097
Jamie Madille8fb6402017-02-14 17:56:40 -05005098 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04005099 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005100}
5101
5102void Context::renderbufferStorageMultisample(GLenum target,
5103 GLsizei samples,
5104 GLenum internalformat,
5105 GLsizei width,
5106 GLsizei height)
5107{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005108 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5109 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005110
5111 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005112 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005113 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005114}
5115
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005116void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5117{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005118 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04005119 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005120}
5121
JiangYizhoue18e6392017-02-20 10:32:23 +08005122void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5123{
5124 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5125 QueryFramebufferParameteriv(framebuffer, pname, params);
5126}
5127
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005128void Context::getFramebufferParameterivRobust(GLenum target,
5129 GLenum pname,
5130 GLsizei bufSize,
5131 GLsizei *length,
5132 GLint *params)
5133{
5134 UNIMPLEMENTED();
5135}
5136
Jiajia Qin5451d532017-11-16 17:16:34 +08005137void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005138{
5139 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005140 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005141}
5142
Jamie Madilldec86232018-07-11 09:01:18 -04005143bool Context::getScratchBuffer(size_t requstedSizeBytes,
5144 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005145{
Jamie Madilldec86232018-07-11 09:01:18 -04005146 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005147}
5148
Jamie Madilldec86232018-07-11 09:01:18 -04005149bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5150 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005151{
Jamie Madilldec86232018-07-11 09:01:18 -04005152 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005153}
5154
Xinghua Cao10a4d432017-11-28 14:46:26 +08005155Error Context::prepareForDispatch()
5156{
Geoff Langa8cb2872018-03-09 16:09:40 -05005157 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005158
5159 if (isRobustResourceInitEnabled())
5160 {
5161 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5162 }
5163
5164 return NoError();
5165}
5166
Xinghua Cao2b396592017-03-29 15:36:04 +08005167void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5168{
5169 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5170 {
5171 return;
5172 }
5173
Xinghua Cao10a4d432017-11-28 14:46:26 +08005174 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005175 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005176}
5177
Jiajia Qin5451d532017-11-16 17:16:34 +08005178void Context::dispatchComputeIndirect(GLintptr indirect)
5179{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005180 ANGLE_CONTEXT_TRY(prepareForDispatch());
5181 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005182}
5183
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005184void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005185 GLsizei levels,
5186 GLenum internalFormat,
5187 GLsizei width,
5188 GLsizei height)
5189{
5190 Extents size(width, height, 1);
5191 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005192 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005193}
5194
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005195void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005196 GLsizei levels,
5197 GLenum internalFormat,
5198 GLsizei width,
5199 GLsizei height,
5200 GLsizei depth)
5201{
5202 Extents size(width, height, depth);
5203 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005204 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005205}
5206
Jiajia Qin5451d532017-11-16 17:16:34 +08005207void Context::memoryBarrier(GLbitfield barriers)
5208{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005209 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005210}
5211
5212void Context::memoryBarrierByRegion(GLbitfield barriers)
5213{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005214 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005215}
5216
Jamie Madillc1d770e2017-04-13 17:31:24 -04005217GLenum Context::checkFramebufferStatus(GLenum target)
5218{
5219 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5220 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005221 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005222}
5223
5224void Context::compileShader(GLuint shader)
5225{
5226 Shader *shaderObject = GetValidShader(this, shader);
5227 if (!shaderObject)
5228 {
5229 return;
5230 }
5231 shaderObject->compile(this);
5232}
5233
5234void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5235{
5236 for (int i = 0; i < n; i++)
5237 {
5238 deleteBuffer(buffers[i]);
5239 }
5240}
5241
5242void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5243{
5244 for (int i = 0; i < n; i++)
5245 {
5246 if (framebuffers[i] != 0)
5247 {
5248 deleteFramebuffer(framebuffers[i]);
5249 }
5250 }
5251}
5252
5253void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5254{
5255 for (int i = 0; i < n; i++)
5256 {
5257 deleteRenderbuffer(renderbuffers[i]);
5258 }
5259}
5260
5261void Context::deleteTextures(GLsizei n, const GLuint *textures)
5262{
5263 for (int i = 0; i < n; i++)
5264 {
5265 if (textures[i] != 0)
5266 {
5267 deleteTexture(textures[i]);
5268 }
5269 }
5270}
5271
5272void Context::detachShader(GLuint program, GLuint shader)
5273{
5274 Program *programObject = getProgram(program);
5275 ASSERT(programObject);
5276
5277 Shader *shaderObject = getShader(shader);
5278 ASSERT(shaderObject);
5279
5280 programObject->detachShader(this, shaderObject);
5281}
5282
5283void Context::genBuffers(GLsizei n, GLuint *buffers)
5284{
5285 for (int i = 0; i < n; i++)
5286 {
5287 buffers[i] = createBuffer();
5288 }
5289}
5290
5291void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5292{
5293 for (int i = 0; i < n; i++)
5294 {
5295 framebuffers[i] = createFramebuffer();
5296 }
5297}
5298
5299void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5300{
5301 for (int i = 0; i < n; i++)
5302 {
5303 renderbuffers[i] = createRenderbuffer();
5304 }
5305}
5306
5307void Context::genTextures(GLsizei n, GLuint *textures)
5308{
5309 for (int i = 0; i < n; i++)
5310 {
5311 textures[i] = createTexture();
5312 }
5313}
5314
5315void Context::getActiveAttrib(GLuint program,
5316 GLuint index,
5317 GLsizei bufsize,
5318 GLsizei *length,
5319 GLint *size,
5320 GLenum *type,
5321 GLchar *name)
5322{
5323 Program *programObject = getProgram(program);
5324 ASSERT(programObject);
5325 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5326}
5327
5328void Context::getActiveUniform(GLuint program,
5329 GLuint index,
5330 GLsizei bufsize,
5331 GLsizei *length,
5332 GLint *size,
5333 GLenum *type,
5334 GLchar *name)
5335{
5336 Program *programObject = getProgram(program);
5337 ASSERT(programObject);
5338 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5339}
5340
5341void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5342{
5343 Program *programObject = getProgram(program);
5344 ASSERT(programObject);
5345 programObject->getAttachedShaders(maxcount, count, shaders);
5346}
5347
5348GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5349{
5350 Program *programObject = getProgram(program);
5351 ASSERT(programObject);
5352 return programObject->getAttributeLocation(name);
5353}
5354
5355void Context::getBooleanv(GLenum pname, GLboolean *params)
5356{
5357 GLenum nativeType;
5358 unsigned int numParams = 0;
5359 getQueryParameterInfo(pname, &nativeType, &numParams);
5360
5361 if (nativeType == GL_BOOL)
5362 {
5363 getBooleanvImpl(pname, params);
5364 }
5365 else
5366 {
5367 CastStateValues(this, nativeType, pname, numParams, params);
5368 }
5369}
5370
Brandon Jones59770802018-04-02 13:18:42 -07005371void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5372{
5373 getBooleanv(pname, params);
5374}
5375
Jamie Madillc1d770e2017-04-13 17:31:24 -04005376void Context::getFloatv(GLenum pname, GLfloat *params)
5377{
5378 GLenum nativeType;
5379 unsigned int numParams = 0;
5380 getQueryParameterInfo(pname, &nativeType, &numParams);
5381
5382 if (nativeType == GL_FLOAT)
5383 {
5384 getFloatvImpl(pname, params);
5385 }
5386 else
5387 {
5388 CastStateValues(this, nativeType, pname, numParams, params);
5389 }
5390}
5391
Brandon Jones59770802018-04-02 13:18:42 -07005392void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5393{
5394 getFloatv(pname, params);
5395}
5396
Jamie Madillc1d770e2017-04-13 17:31:24 -04005397void Context::getIntegerv(GLenum pname, GLint *params)
5398{
5399 GLenum nativeType;
5400 unsigned int numParams = 0;
5401 getQueryParameterInfo(pname, &nativeType, &numParams);
5402
5403 if (nativeType == GL_INT)
5404 {
5405 getIntegervImpl(pname, params);
5406 }
5407 else
5408 {
5409 CastStateValues(this, nativeType, pname, numParams, params);
5410 }
5411}
5412
Brandon Jones59770802018-04-02 13:18:42 -07005413void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5414{
5415 getIntegerv(pname, data);
5416}
5417
Jamie Madillc1d770e2017-04-13 17:31:24 -04005418void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5419{
5420 Program *programObject = getProgram(program);
5421 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005422 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005423}
5424
Brandon Jones59770802018-04-02 13:18:42 -07005425void Context::getProgramivRobust(GLuint program,
5426 GLenum pname,
5427 GLsizei bufSize,
5428 GLsizei *length,
5429 GLint *params)
5430{
5431 getProgramiv(program, pname, params);
5432}
5433
Jiajia Qin5451d532017-11-16 17:16:34 +08005434void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5435{
5436 UNIMPLEMENTED();
5437}
5438
Jamie Madillbe849e42017-05-02 15:49:00 -04005439void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005440{
5441 Program *programObject = getProgram(program);
5442 ASSERT(programObject);
5443 programObject->getInfoLog(bufsize, length, infolog);
5444}
5445
Jiajia Qin5451d532017-11-16 17:16:34 +08005446void Context::getProgramPipelineInfoLog(GLuint pipeline,
5447 GLsizei bufSize,
5448 GLsizei *length,
5449 GLchar *infoLog)
5450{
5451 UNIMPLEMENTED();
5452}
5453
Jamie Madillc1d770e2017-04-13 17:31:24 -04005454void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5455{
5456 Shader *shaderObject = getShader(shader);
5457 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005458 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005459}
5460
Brandon Jones59770802018-04-02 13:18:42 -07005461void Context::getShaderivRobust(GLuint shader,
5462 GLenum pname,
5463 GLsizei bufSize,
5464 GLsizei *length,
5465 GLint *params)
5466{
5467 getShaderiv(shader, pname, params);
5468}
5469
Jamie Madillc1d770e2017-04-13 17:31:24 -04005470void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5471{
5472 Shader *shaderObject = getShader(shader);
5473 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005474 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005475}
5476
5477void Context::getShaderPrecisionFormat(GLenum shadertype,
5478 GLenum precisiontype,
5479 GLint *range,
5480 GLint *precision)
5481{
5482 // TODO(jmadill): Compute shaders.
5483
5484 switch (shadertype)
5485 {
5486 case GL_VERTEX_SHADER:
5487 switch (precisiontype)
5488 {
5489 case GL_LOW_FLOAT:
5490 mCaps.vertexLowpFloat.get(range, precision);
5491 break;
5492 case GL_MEDIUM_FLOAT:
5493 mCaps.vertexMediumpFloat.get(range, precision);
5494 break;
5495 case GL_HIGH_FLOAT:
5496 mCaps.vertexHighpFloat.get(range, precision);
5497 break;
5498
5499 case GL_LOW_INT:
5500 mCaps.vertexLowpInt.get(range, precision);
5501 break;
5502 case GL_MEDIUM_INT:
5503 mCaps.vertexMediumpInt.get(range, precision);
5504 break;
5505 case GL_HIGH_INT:
5506 mCaps.vertexHighpInt.get(range, precision);
5507 break;
5508
5509 default:
5510 UNREACHABLE();
5511 return;
5512 }
5513 break;
5514
5515 case GL_FRAGMENT_SHADER:
5516 switch (precisiontype)
5517 {
5518 case GL_LOW_FLOAT:
5519 mCaps.fragmentLowpFloat.get(range, precision);
5520 break;
5521 case GL_MEDIUM_FLOAT:
5522 mCaps.fragmentMediumpFloat.get(range, precision);
5523 break;
5524 case GL_HIGH_FLOAT:
5525 mCaps.fragmentHighpFloat.get(range, precision);
5526 break;
5527
5528 case GL_LOW_INT:
5529 mCaps.fragmentLowpInt.get(range, precision);
5530 break;
5531 case GL_MEDIUM_INT:
5532 mCaps.fragmentMediumpInt.get(range, precision);
5533 break;
5534 case GL_HIGH_INT:
5535 mCaps.fragmentHighpInt.get(range, precision);
5536 break;
5537
5538 default:
5539 UNREACHABLE();
5540 return;
5541 }
5542 break;
5543
5544 default:
5545 UNREACHABLE();
5546 return;
5547 }
5548}
5549
5550void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5551{
5552 Shader *shaderObject = getShader(shader);
5553 ASSERT(shaderObject);
5554 shaderObject->getSource(bufsize, length, source);
5555}
5556
5557void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5558{
5559 Program *programObject = getProgram(program);
5560 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005561 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005562}
5563
Brandon Jones59770802018-04-02 13:18:42 -07005564void Context::getUniformfvRobust(GLuint program,
5565 GLint location,
5566 GLsizei bufSize,
5567 GLsizei *length,
5568 GLfloat *params)
5569{
5570 getUniformfv(program, location, params);
5571}
5572
Jamie Madillc1d770e2017-04-13 17:31:24 -04005573void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5574{
5575 Program *programObject = getProgram(program);
5576 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005577 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005578}
5579
Brandon Jones59770802018-04-02 13:18:42 -07005580void Context::getUniformivRobust(GLuint program,
5581 GLint location,
5582 GLsizei bufSize,
5583 GLsizei *length,
5584 GLint *params)
5585{
5586 getUniformiv(program, location, params);
5587}
5588
Jamie Madillc1d770e2017-04-13 17:31:24 -04005589GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5590{
5591 Program *programObject = getProgram(program);
5592 ASSERT(programObject);
5593 return programObject->getUniformLocation(name);
5594}
5595
5596GLboolean Context::isBuffer(GLuint buffer)
5597{
5598 if (buffer == 0)
5599 {
5600 return GL_FALSE;
5601 }
5602
5603 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5604}
5605
5606GLboolean Context::isEnabled(GLenum cap)
5607{
5608 return mGLState.getEnableFeature(cap);
5609}
5610
5611GLboolean Context::isFramebuffer(GLuint framebuffer)
5612{
5613 if (framebuffer == 0)
5614 {
5615 return GL_FALSE;
5616 }
5617
5618 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5619}
5620
5621GLboolean Context::isProgram(GLuint program)
5622{
5623 if (program == 0)
5624 {
5625 return GL_FALSE;
5626 }
5627
5628 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5629}
5630
5631GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5632{
5633 if (renderbuffer == 0)
5634 {
5635 return GL_FALSE;
5636 }
5637
5638 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5639}
5640
5641GLboolean Context::isShader(GLuint shader)
5642{
5643 if (shader == 0)
5644 {
5645 return GL_FALSE;
5646 }
5647
5648 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5649}
5650
5651GLboolean Context::isTexture(GLuint texture)
5652{
5653 if (texture == 0)
5654 {
5655 return GL_FALSE;
5656 }
5657
5658 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5659}
5660
5661void Context::linkProgram(GLuint program)
5662{
5663 Program *programObject = getProgram(program);
5664 ASSERT(programObject);
5665 handleError(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005666
5667 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5668 // don't need to worry that:
5669 // 1. Draw calls after link use the new executable code or the old one depending on the link
5670 // result.
5671 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5672 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5673 // ProgramD3D.
5674 if (programObject->isInUse())
5675 {
5676 // isLinked() which forces to resolve linking, will be called.
5677 mGLState.onProgramExecutableChange(programObject);
5678 mStateCache.onProgramExecutableChange(this);
5679 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005680}
5681
5682void Context::releaseShaderCompiler()
5683{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005684 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005685}
5686
5687void Context::shaderBinary(GLsizei n,
5688 const GLuint *shaders,
5689 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005690 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005691 GLsizei length)
5692{
5693 // No binary shader formats are supported.
5694 UNIMPLEMENTED();
5695}
5696
5697void Context::shaderSource(GLuint shader,
5698 GLsizei count,
5699 const GLchar *const *string,
5700 const GLint *length)
5701{
5702 Shader *shaderObject = getShader(shader);
5703 ASSERT(shaderObject);
5704 shaderObject->setSource(count, string, length);
5705}
5706
5707void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5708{
5709 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5710}
5711
5712void Context::stencilMask(GLuint mask)
5713{
5714 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5715}
5716
5717void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5718{
5719 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5720}
5721
5722void Context::uniform1f(GLint location, GLfloat x)
5723{
5724 Program *program = mGLState.getProgram();
5725 program->setUniform1fv(location, 1, &x);
5726}
5727
5728void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5729{
5730 Program *program = mGLState.getProgram();
5731 program->setUniform1fv(location, count, v);
5732}
5733
Jamie Madill7e4eff12018-08-08 15:49:26 -04005734void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005735{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005736 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04005737 {
5738 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04005739 mStateCache.onActiveTextureChange(this);
Jamie Madill81c2e252017-09-09 23:32:46 -04005740 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005741}
5742
Jamie Madill7e4eff12018-08-08 15:49:26 -04005743void Context::uniform1i(GLint location, GLint x)
5744{
5745 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
5746}
5747
Jamie Madillc1d770e2017-04-13 17:31:24 -04005748void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5749{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005750 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005751}
5752
5753void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5754{
5755 GLfloat xy[2] = {x, y};
5756 Program *program = mGLState.getProgram();
5757 program->setUniform2fv(location, 1, xy);
5758}
5759
5760void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5761{
5762 Program *program = mGLState.getProgram();
5763 program->setUniform2fv(location, count, v);
5764}
5765
5766void Context::uniform2i(GLint location, GLint x, GLint y)
5767{
5768 GLint xy[2] = {x, y};
5769 Program *program = mGLState.getProgram();
5770 program->setUniform2iv(location, 1, xy);
5771}
5772
5773void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5774{
5775 Program *program = mGLState.getProgram();
5776 program->setUniform2iv(location, count, v);
5777}
5778
5779void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5780{
5781 GLfloat xyz[3] = {x, y, z};
5782 Program *program = mGLState.getProgram();
5783 program->setUniform3fv(location, 1, xyz);
5784}
5785
5786void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5787{
5788 Program *program = mGLState.getProgram();
5789 program->setUniform3fv(location, count, v);
5790}
5791
5792void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5793{
5794 GLint xyz[3] = {x, y, z};
5795 Program *program = mGLState.getProgram();
5796 program->setUniform3iv(location, 1, xyz);
5797}
5798
5799void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5800{
5801 Program *program = mGLState.getProgram();
5802 program->setUniform3iv(location, count, v);
5803}
5804
5805void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5806{
5807 GLfloat xyzw[4] = {x, y, z, w};
5808 Program *program = mGLState.getProgram();
5809 program->setUniform4fv(location, 1, xyzw);
5810}
5811
5812void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5813{
5814 Program *program = mGLState.getProgram();
5815 program->setUniform4fv(location, count, v);
5816}
5817
5818void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5819{
5820 GLint xyzw[4] = {x, y, z, w};
5821 Program *program = mGLState.getProgram();
5822 program->setUniform4iv(location, 1, xyzw);
5823}
5824
5825void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5826{
5827 Program *program = mGLState.getProgram();
5828 program->setUniform4iv(location, count, v);
5829}
5830
5831void Context::uniformMatrix2fv(GLint location,
5832 GLsizei count,
5833 GLboolean transpose,
5834 const GLfloat *value)
5835{
5836 Program *program = mGLState.getProgram();
5837 program->setUniformMatrix2fv(location, count, transpose, value);
5838}
5839
5840void Context::uniformMatrix3fv(GLint location,
5841 GLsizei count,
5842 GLboolean transpose,
5843 const GLfloat *value)
5844{
5845 Program *program = mGLState.getProgram();
5846 program->setUniformMatrix3fv(location, count, transpose, value);
5847}
5848
5849void Context::uniformMatrix4fv(GLint location,
5850 GLsizei count,
5851 GLboolean transpose,
5852 const GLfloat *value)
5853{
5854 Program *program = mGLState.getProgram();
5855 program->setUniformMatrix4fv(location, count, transpose, value);
5856}
5857
5858void Context::validateProgram(GLuint program)
5859{
5860 Program *programObject = getProgram(program);
5861 ASSERT(programObject);
5862 programObject->validate(mCaps);
5863}
5864
Jiajia Qin5451d532017-11-16 17:16:34 +08005865void Context::validateProgramPipeline(GLuint pipeline)
5866{
5867 UNIMPLEMENTED();
5868}
5869
Jamie Madilld04908b2017-06-09 14:15:35 -04005870void Context::getProgramBinary(GLuint program,
5871 GLsizei bufSize,
5872 GLsizei *length,
5873 GLenum *binaryFormat,
5874 void *binary)
5875{
5876 Program *programObject = getProgram(program);
5877 ASSERT(programObject != nullptr);
5878
5879 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5880}
5881
5882void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5883{
5884 Program *programObject = getProgram(program);
5885 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005886
Jamie Madilld04908b2017-06-09 14:15:35 -04005887 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madillc43cdad2018-08-08 15:49:25 -04005888 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04005889 if (programObject->isInUse())
5890 {
5891 mGLState.setObjectDirty(GL_PROGRAM);
5892 }
Jamie Madilld04908b2017-06-09 14:15:35 -04005893}
5894
Jamie Madillff325f12017-08-26 15:06:05 -04005895void Context::uniform1ui(GLint location, GLuint v0)
5896{
5897 Program *program = mGLState.getProgram();
5898 program->setUniform1uiv(location, 1, &v0);
5899}
5900
5901void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5902{
5903 Program *program = mGLState.getProgram();
5904 const GLuint xy[] = {v0, v1};
5905 program->setUniform2uiv(location, 1, xy);
5906}
5907
5908void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5909{
5910 Program *program = mGLState.getProgram();
5911 const GLuint xyz[] = {v0, v1, v2};
5912 program->setUniform3uiv(location, 1, xyz);
5913}
5914
5915void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5916{
5917 Program *program = mGLState.getProgram();
5918 const GLuint xyzw[] = {v0, v1, v2, v3};
5919 program->setUniform4uiv(location, 1, xyzw);
5920}
5921
5922void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5923{
5924 Program *program = mGLState.getProgram();
5925 program->setUniform1uiv(location, count, value);
5926}
5927void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5928{
5929 Program *program = mGLState.getProgram();
5930 program->setUniform2uiv(location, count, value);
5931}
5932
5933void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5934{
5935 Program *program = mGLState.getProgram();
5936 program->setUniform3uiv(location, count, value);
5937}
5938
5939void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5940{
5941 Program *program = mGLState.getProgram();
5942 program->setUniform4uiv(location, count, value);
5943}
5944
Jamie Madillf0e04492017-08-26 15:28:42 -04005945void Context::genQueries(GLsizei n, GLuint *ids)
5946{
5947 for (GLsizei i = 0; i < n; i++)
5948 {
5949 GLuint handle = mQueryHandleAllocator.allocate();
5950 mQueryMap.assign(handle, nullptr);
5951 ids[i] = handle;
5952 }
5953}
5954
5955void Context::deleteQueries(GLsizei n, const GLuint *ids)
5956{
5957 for (int i = 0; i < n; i++)
5958 {
5959 GLuint query = ids[i];
5960
5961 Query *queryObject = nullptr;
5962 if (mQueryMap.erase(query, &queryObject))
5963 {
5964 mQueryHandleAllocator.release(query);
5965 if (queryObject)
5966 {
5967 queryObject->release(this);
5968 }
5969 }
5970 }
5971}
5972
5973GLboolean Context::isQuery(GLuint id)
5974{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005975 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005976}
5977
Jamie Madillc8c95812017-08-26 18:40:09 -04005978void Context::uniformMatrix2x3fv(GLint location,
5979 GLsizei count,
5980 GLboolean transpose,
5981 const GLfloat *value)
5982{
5983 Program *program = mGLState.getProgram();
5984 program->setUniformMatrix2x3fv(location, count, transpose, value);
5985}
5986
5987void Context::uniformMatrix3x2fv(GLint location,
5988 GLsizei count,
5989 GLboolean transpose,
5990 const GLfloat *value)
5991{
5992 Program *program = mGLState.getProgram();
5993 program->setUniformMatrix3x2fv(location, count, transpose, value);
5994}
5995
5996void Context::uniformMatrix2x4fv(GLint location,
5997 GLsizei count,
5998 GLboolean transpose,
5999 const GLfloat *value)
6000{
6001 Program *program = mGLState.getProgram();
6002 program->setUniformMatrix2x4fv(location, count, transpose, value);
6003}
6004
6005void Context::uniformMatrix4x2fv(GLint location,
6006 GLsizei count,
6007 GLboolean transpose,
6008 const GLfloat *value)
6009{
6010 Program *program = mGLState.getProgram();
6011 program->setUniformMatrix4x2fv(location, count, transpose, value);
6012}
6013
6014void Context::uniformMatrix3x4fv(GLint location,
6015 GLsizei count,
6016 GLboolean transpose,
6017 const GLfloat *value)
6018{
6019 Program *program = mGLState.getProgram();
6020 program->setUniformMatrix3x4fv(location, count, transpose, value);
6021}
6022
6023void Context::uniformMatrix4x3fv(GLint location,
6024 GLsizei count,
6025 GLboolean transpose,
6026 const GLfloat *value)
6027{
6028 Program *program = mGLState.getProgram();
6029 program->setUniformMatrix4x3fv(location, count, transpose, value);
6030}
6031
Jamie Madilld7576732017-08-26 18:49:50 -04006032void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6033{
6034 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6035 {
6036 GLuint vertexArray = arrays[arrayIndex];
6037
6038 if (arrays[arrayIndex] != 0)
6039 {
6040 VertexArray *vertexArrayObject = nullptr;
6041 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6042 {
6043 if (vertexArrayObject != nullptr)
6044 {
6045 detachVertexArray(vertexArray);
6046 vertexArrayObject->onDestroy(this);
6047 }
6048
6049 mVertexArrayHandleAllocator.release(vertexArray);
6050 }
6051 }
6052 }
6053}
6054
6055void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6056{
6057 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6058 {
6059 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6060 mVertexArrayMap.assign(vertexArray, nullptr);
6061 arrays[arrayIndex] = vertexArray;
6062 }
6063}
6064
6065bool Context::isVertexArray(GLuint array)
6066{
6067 if (array == 0)
6068 {
6069 return GL_FALSE;
6070 }
6071
6072 VertexArray *vao = getVertexArray(array);
6073 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6074}
6075
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006076void Context::endTransformFeedback()
6077{
6078 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6079 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006080 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006081}
6082
6083void Context::transformFeedbackVaryings(GLuint program,
6084 GLsizei count,
6085 const GLchar *const *varyings,
6086 GLenum bufferMode)
6087{
6088 Program *programObject = getProgram(program);
6089 ASSERT(programObject);
6090 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6091}
6092
6093void Context::getTransformFeedbackVarying(GLuint program,
6094 GLuint index,
6095 GLsizei bufSize,
6096 GLsizei *length,
6097 GLsizei *size,
6098 GLenum *type,
6099 GLchar *name)
6100{
6101 Program *programObject = getProgram(program);
6102 ASSERT(programObject);
6103 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6104}
6105
6106void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6107{
6108 for (int i = 0; i < n; i++)
6109 {
6110 GLuint transformFeedback = ids[i];
6111 if (transformFeedback == 0)
6112 {
6113 continue;
6114 }
6115
6116 TransformFeedback *transformFeedbackObject = nullptr;
6117 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6118 {
6119 if (transformFeedbackObject != nullptr)
6120 {
6121 detachTransformFeedback(transformFeedback);
6122 transformFeedbackObject->release(this);
6123 }
6124
6125 mTransformFeedbackHandleAllocator.release(transformFeedback);
6126 }
6127 }
6128}
6129
6130void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6131{
6132 for (int i = 0; i < n; i++)
6133 {
6134 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6135 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6136 ids[i] = transformFeedback;
6137 }
6138}
6139
6140bool Context::isTransformFeedback(GLuint id)
6141{
6142 if (id == 0)
6143 {
6144 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6145 // returns FALSE
6146 return GL_FALSE;
6147 }
6148
6149 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6150 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6151}
6152
6153void Context::pauseTransformFeedback()
6154{
6155 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6156 transformFeedback->pause();
6157}
6158
6159void Context::resumeTransformFeedback()
6160{
6161 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6162 transformFeedback->resume();
6163}
6164
Jamie Madill12e957f2017-08-26 21:42:26 -04006165void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6166{
6167 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006168 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006169}
6170
Brandon Jones59770802018-04-02 13:18:42 -07006171void Context::getUniformuivRobust(GLuint program,
6172 GLint location,
6173 GLsizei bufSize,
6174 GLsizei *length,
6175 GLuint *params)
6176{
6177 getUniformuiv(program, location, params);
6178}
6179
Jamie Madill12e957f2017-08-26 21:42:26 -04006180GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6181{
6182 const Program *programObject = getProgram(program);
6183 return programObject->getFragDataLocation(name);
6184}
6185
6186void Context::getUniformIndices(GLuint program,
6187 GLsizei uniformCount,
6188 const GLchar *const *uniformNames,
6189 GLuint *uniformIndices)
6190{
6191 const Program *programObject = getProgram(program);
6192 if (!programObject->isLinked())
6193 {
6194 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6195 {
6196 uniformIndices[uniformId] = GL_INVALID_INDEX;
6197 }
6198 }
6199 else
6200 {
6201 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6202 {
6203 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6204 }
6205 }
6206}
6207
6208void Context::getActiveUniformsiv(GLuint program,
6209 GLsizei uniformCount,
6210 const GLuint *uniformIndices,
6211 GLenum pname,
6212 GLint *params)
6213{
6214 const Program *programObject = getProgram(program);
6215 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6216 {
6217 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006218 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006219 }
6220}
6221
6222GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6223{
6224 const Program *programObject = getProgram(program);
6225 return programObject->getUniformBlockIndex(uniformBlockName);
6226}
6227
6228void Context::getActiveUniformBlockiv(GLuint program,
6229 GLuint uniformBlockIndex,
6230 GLenum pname,
6231 GLint *params)
6232{
6233 const Program *programObject = getProgram(program);
6234 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6235}
6236
Brandon Jones59770802018-04-02 13:18:42 -07006237void Context::getActiveUniformBlockivRobust(GLuint program,
6238 GLuint uniformBlockIndex,
6239 GLenum pname,
6240 GLsizei bufSize,
6241 GLsizei *length,
6242 GLint *params)
6243{
6244 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6245}
6246
Jamie Madill12e957f2017-08-26 21:42:26 -04006247void Context::getActiveUniformBlockName(GLuint program,
6248 GLuint uniformBlockIndex,
6249 GLsizei bufSize,
6250 GLsizei *length,
6251 GLchar *uniformBlockName)
6252{
6253 const Program *programObject = getProgram(program);
6254 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6255}
6256
6257void Context::uniformBlockBinding(GLuint program,
6258 GLuint uniformBlockIndex,
6259 GLuint uniformBlockBinding)
6260{
6261 Program *programObject = getProgram(program);
6262 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006263
6264 if (programObject->isInUse())
6265 {
6266 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006267 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006268 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006269}
6270
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006271GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6272{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006273 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6274 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006275
Jamie Madill70b5bb02017-08-28 13:32:37 -04006276 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006277 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006278 if (error.isError())
6279 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006280 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006281 handleError(error);
6282 return nullptr;
6283 }
6284
Jamie Madill70b5bb02017-08-28 13:32:37 -04006285 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006286}
6287
6288GLboolean Context::isSync(GLsync sync)
6289{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006290 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006291}
6292
6293GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6294{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006295 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006296
6297 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006298 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006299 return result;
6300}
6301
6302void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6303{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006304 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006305 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006306}
6307
6308void Context::getInteger64v(GLenum pname, GLint64 *params)
6309{
6310 GLenum nativeType = GL_NONE;
6311 unsigned int numParams = 0;
6312 getQueryParameterInfo(pname, &nativeType, &numParams);
6313
6314 if (nativeType == GL_INT_64_ANGLEX)
6315 {
6316 getInteger64vImpl(pname, params);
6317 }
6318 else
6319 {
6320 CastStateValues(this, nativeType, pname, numParams, params);
6321 }
6322}
6323
Brandon Jones59770802018-04-02 13:18:42 -07006324void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6325{
6326 getInteger64v(pname, data);
6327}
6328
Corentin Wallez336129f2017-10-17 15:55:40 -04006329void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006330{
6331 Buffer *buffer = mGLState.getTargetBuffer(target);
6332 QueryBufferParameteri64v(buffer, pname, params);
6333}
6334
Brandon Jones59770802018-04-02 13:18:42 -07006335void Context::getBufferParameteri64vRobust(BufferBinding target,
6336 GLenum pname,
6337 GLsizei bufSize,
6338 GLsizei *length,
6339 GLint64 *params)
6340{
6341 getBufferParameteri64v(target, pname, params);
6342}
6343
Jamie Madill3ef140a2017-08-26 23:11:21 -04006344void Context::genSamplers(GLsizei count, GLuint *samplers)
6345{
6346 for (int i = 0; i < count; i++)
6347 {
6348 samplers[i] = mState.mSamplers->createSampler();
6349 }
6350}
6351
6352void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6353{
6354 for (int i = 0; i < count; i++)
6355 {
6356 GLuint sampler = samplers[i];
6357
6358 if (mState.mSamplers->getSampler(sampler))
6359 {
6360 detachSampler(sampler);
6361 }
6362
6363 mState.mSamplers->deleteObject(this, sampler);
6364 }
6365}
6366
6367void Context::getInternalformativ(GLenum target,
6368 GLenum internalformat,
6369 GLenum pname,
6370 GLsizei bufSize,
6371 GLint *params)
6372{
6373 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6374 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6375}
6376
Brandon Jones59770802018-04-02 13:18:42 -07006377void Context::getInternalformativRobust(GLenum target,
6378 GLenum internalformat,
6379 GLenum pname,
6380 GLsizei bufSize,
6381 GLsizei *length,
6382 GLint *params)
6383{
6384 getInternalformativ(target, internalformat, pname, bufSize, params);
6385}
6386
Jiajia Qin5451d532017-11-16 17:16:34 +08006387void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6388{
6389 programUniform1iv(program, location, 1, &v0);
6390}
6391
6392void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6393{
6394 GLint xy[2] = {v0, v1};
6395 programUniform2iv(program, location, 1, xy);
6396}
6397
6398void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6399{
6400 GLint xyz[3] = {v0, v1, v2};
6401 programUniform3iv(program, location, 1, xyz);
6402}
6403
6404void Context::programUniform4i(GLuint program,
6405 GLint location,
6406 GLint v0,
6407 GLint v1,
6408 GLint v2,
6409 GLint v3)
6410{
6411 GLint xyzw[4] = {v0, v1, v2, v3};
6412 programUniform4iv(program, location, 1, xyzw);
6413}
6414
6415void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6416{
6417 programUniform1uiv(program, location, 1, &v0);
6418}
6419
6420void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6421{
6422 GLuint xy[2] = {v0, v1};
6423 programUniform2uiv(program, location, 1, xy);
6424}
6425
6426void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6427{
6428 GLuint xyz[3] = {v0, v1, v2};
6429 programUniform3uiv(program, location, 1, xyz);
6430}
6431
6432void Context::programUniform4ui(GLuint program,
6433 GLint location,
6434 GLuint v0,
6435 GLuint v1,
6436 GLuint v2,
6437 GLuint v3)
6438{
6439 GLuint xyzw[4] = {v0, v1, v2, v3};
6440 programUniform4uiv(program, location, 1, xyzw);
6441}
6442
6443void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6444{
6445 programUniform1fv(program, location, 1, &v0);
6446}
6447
6448void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6449{
6450 GLfloat xy[2] = {v0, v1};
6451 programUniform2fv(program, location, 1, xy);
6452}
6453
6454void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6455{
6456 GLfloat xyz[3] = {v0, v1, v2};
6457 programUniform3fv(program, location, 1, xyz);
6458}
6459
6460void Context::programUniform4f(GLuint program,
6461 GLint location,
6462 GLfloat v0,
6463 GLfloat v1,
6464 GLfloat v2,
6465 GLfloat v3)
6466{
6467 GLfloat xyzw[4] = {v0, v1, v2, v3};
6468 programUniform4fv(program, location, 1, xyzw);
6469}
6470
Jamie Madill81c2e252017-09-09 23:32:46 -04006471void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6472{
6473 Program *programObject = getProgram(program);
6474 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006475 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006476}
6477
Jiajia Qin5451d532017-11-16 17:16:34 +08006478void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6479{
6480 Program *programObject = getProgram(program);
6481 ASSERT(programObject);
6482 programObject->setUniform2iv(location, count, value);
6483}
6484
6485void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6486{
6487 Program *programObject = getProgram(program);
6488 ASSERT(programObject);
6489 programObject->setUniform3iv(location, count, value);
6490}
6491
6492void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6493{
6494 Program *programObject = getProgram(program);
6495 ASSERT(programObject);
6496 programObject->setUniform4iv(location, count, value);
6497}
6498
6499void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6500{
6501 Program *programObject = getProgram(program);
6502 ASSERT(programObject);
6503 programObject->setUniform1uiv(location, count, value);
6504}
6505
6506void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6507{
6508 Program *programObject = getProgram(program);
6509 ASSERT(programObject);
6510 programObject->setUniform2uiv(location, count, value);
6511}
6512
6513void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6514{
6515 Program *programObject = getProgram(program);
6516 ASSERT(programObject);
6517 programObject->setUniform3uiv(location, count, value);
6518}
6519
6520void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6521{
6522 Program *programObject = getProgram(program);
6523 ASSERT(programObject);
6524 programObject->setUniform4uiv(location, count, value);
6525}
6526
6527void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6528{
6529 Program *programObject = getProgram(program);
6530 ASSERT(programObject);
6531 programObject->setUniform1fv(location, count, value);
6532}
6533
6534void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6535{
6536 Program *programObject = getProgram(program);
6537 ASSERT(programObject);
6538 programObject->setUniform2fv(location, count, value);
6539}
6540
6541void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6542{
6543 Program *programObject = getProgram(program);
6544 ASSERT(programObject);
6545 programObject->setUniform3fv(location, count, value);
6546}
6547
6548void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6549{
6550 Program *programObject = getProgram(program);
6551 ASSERT(programObject);
6552 programObject->setUniform4fv(location, count, value);
6553}
6554
6555void Context::programUniformMatrix2fv(GLuint program,
6556 GLint location,
6557 GLsizei count,
6558 GLboolean transpose,
6559 const GLfloat *value)
6560{
6561 Program *programObject = getProgram(program);
6562 ASSERT(programObject);
6563 programObject->setUniformMatrix2fv(location, count, transpose, value);
6564}
6565
6566void Context::programUniformMatrix3fv(GLuint program,
6567 GLint location,
6568 GLsizei count,
6569 GLboolean transpose,
6570 const GLfloat *value)
6571{
6572 Program *programObject = getProgram(program);
6573 ASSERT(programObject);
6574 programObject->setUniformMatrix3fv(location, count, transpose, value);
6575}
6576
6577void Context::programUniformMatrix4fv(GLuint program,
6578 GLint location,
6579 GLsizei count,
6580 GLboolean transpose,
6581 const GLfloat *value)
6582{
6583 Program *programObject = getProgram(program);
6584 ASSERT(programObject);
6585 programObject->setUniformMatrix4fv(location, count, transpose, value);
6586}
6587
6588void Context::programUniformMatrix2x3fv(GLuint program,
6589 GLint location,
6590 GLsizei count,
6591 GLboolean transpose,
6592 const GLfloat *value)
6593{
6594 Program *programObject = getProgram(program);
6595 ASSERT(programObject);
6596 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6597}
6598
6599void Context::programUniformMatrix3x2fv(GLuint program,
6600 GLint location,
6601 GLsizei count,
6602 GLboolean transpose,
6603 const GLfloat *value)
6604{
6605 Program *programObject = getProgram(program);
6606 ASSERT(programObject);
6607 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6608}
6609
6610void Context::programUniformMatrix2x4fv(GLuint program,
6611 GLint location,
6612 GLsizei count,
6613 GLboolean transpose,
6614 const GLfloat *value)
6615{
6616 Program *programObject = getProgram(program);
6617 ASSERT(programObject);
6618 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6619}
6620
6621void Context::programUniformMatrix4x2fv(GLuint program,
6622 GLint location,
6623 GLsizei count,
6624 GLboolean transpose,
6625 const GLfloat *value)
6626{
6627 Program *programObject = getProgram(program);
6628 ASSERT(programObject);
6629 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6630}
6631
6632void Context::programUniformMatrix3x4fv(GLuint program,
6633 GLint location,
6634 GLsizei count,
6635 GLboolean transpose,
6636 const GLfloat *value)
6637{
6638 Program *programObject = getProgram(program);
6639 ASSERT(programObject);
6640 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6641}
6642
6643void Context::programUniformMatrix4x3fv(GLuint program,
6644 GLint location,
6645 GLsizei count,
6646 GLboolean transpose,
6647 const GLfloat *value)
6648{
6649 Program *programObject = getProgram(program);
6650 ASSERT(programObject);
6651 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6652}
6653
Jamie Madill81c2e252017-09-09 23:32:46 -04006654void Context::onTextureChange(const Texture *texture)
6655{
6656 // Conservatively assume all textures are dirty.
6657 // TODO(jmadill): More fine-grained update.
6658 mGLState.setObjectDirty(GL_TEXTURE);
6659}
6660
James Darpiniane8a93c62018-01-04 18:02:24 -08006661bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6662{
6663 return mGLState.isCurrentTransformFeedback(tf);
6664}
James Darpiniane8a93c62018-01-04 18:02:24 -08006665
Yunchao Hea336b902017-08-02 16:05:21 +08006666void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6667{
6668 for (int i = 0; i < count; i++)
6669 {
6670 pipelines[i] = createProgramPipeline();
6671 }
6672}
6673
6674void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6675{
6676 for (int i = 0; i < count; i++)
6677 {
6678 if (pipelines[i] != 0)
6679 {
6680 deleteProgramPipeline(pipelines[i]);
6681 }
6682 }
6683}
6684
6685GLboolean Context::isProgramPipeline(GLuint pipeline)
6686{
6687 if (pipeline == 0)
6688 {
6689 return GL_FALSE;
6690 }
6691
6692 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6693}
6694
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006695void Context::finishFenceNV(GLuint fence)
6696{
6697 FenceNV *fenceObject = getFenceNV(fence);
6698
6699 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006700 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006701}
6702
6703void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6704{
6705 FenceNV *fenceObject = getFenceNV(fence);
6706
6707 ASSERT(fenceObject && fenceObject->isSet());
6708
6709 switch (pname)
6710 {
6711 case GL_FENCE_STATUS_NV:
6712 {
6713 // GL_NV_fence spec:
6714 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6715 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6716 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6717 GLboolean status = GL_TRUE;
6718 if (fenceObject->getStatus() != GL_TRUE)
6719 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006720 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006721 }
6722 *params = status;
6723 break;
6724 }
6725
6726 case GL_FENCE_CONDITION_NV:
6727 {
6728 *params = static_cast<GLint>(fenceObject->getCondition());
6729 break;
6730 }
6731
6732 default:
6733 UNREACHABLE();
6734 }
6735}
6736
6737void Context::getTranslatedShaderSource(GLuint shader,
6738 GLsizei bufsize,
6739 GLsizei *length,
6740 GLchar *source)
6741{
6742 Shader *shaderObject = getShader(shader);
6743 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006744 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006745}
6746
6747void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6748{
6749 Program *programObject = getProgram(program);
6750 ASSERT(programObject);
6751
6752 programObject->getUniformfv(this, location, params);
6753}
6754
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006755void Context::getnUniformfvRobust(GLuint program,
6756 GLint location,
6757 GLsizei bufSize,
6758 GLsizei *length,
6759 GLfloat *params)
6760{
6761 UNIMPLEMENTED();
6762}
6763
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006764void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6765{
6766 Program *programObject = getProgram(program);
6767 ASSERT(programObject);
6768
6769 programObject->getUniformiv(this, location, params);
6770}
6771
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006772void Context::getnUniformivRobust(GLuint program,
6773 GLint location,
6774 GLsizei bufSize,
6775 GLsizei *length,
6776 GLint *params)
6777{
6778 UNIMPLEMENTED();
6779}
6780
6781void Context::getnUniformuivRobust(GLuint program,
6782 GLint location,
6783 GLsizei bufSize,
6784 GLsizei *length,
6785 GLuint *params)
6786{
6787 UNIMPLEMENTED();
6788}
6789
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006790GLboolean Context::isFenceNV(GLuint fence)
6791{
6792 FenceNV *fenceObject = getFenceNV(fence);
6793
6794 if (fenceObject == nullptr)
6795 {
6796 return GL_FALSE;
6797 }
6798
6799 // GL_NV_fence spec:
6800 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6801 // existing fence.
6802 return fenceObject->isSet();
6803}
6804
6805void Context::readnPixels(GLint x,
6806 GLint y,
6807 GLsizei width,
6808 GLsizei height,
6809 GLenum format,
6810 GLenum type,
6811 GLsizei bufSize,
6812 void *data)
6813{
6814 return readPixels(x, y, width, height, format, type, data);
6815}
6816
Jamie Madill007530e2017-12-28 14:27:04 -05006817void Context::setFenceNV(GLuint fence, GLenum condition)
6818{
6819 ASSERT(condition == GL_ALL_COMPLETED_NV);
6820
6821 FenceNV *fenceObject = getFenceNV(fence);
6822 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006823 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006824}
6825
6826GLboolean Context::testFenceNV(GLuint fence)
6827{
6828 FenceNV *fenceObject = getFenceNV(fence);
6829
6830 ASSERT(fenceObject != nullptr);
6831 ASSERT(fenceObject->isSet() == GL_TRUE);
6832
6833 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006834 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006835 if (error.isError())
6836 {
6837 handleError(error);
6838 return GL_TRUE;
6839 }
6840
6841 return result;
6842}
6843
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006844void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006845{
6846 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006847 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006848 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006849}
6850
Jamie Madillfa920eb2018-01-04 11:45:50 -05006851void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006852{
6853 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006854 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006855 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6856}
6857
Jamie Madillfa920eb2018-01-04 11:45:50 -05006858void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6859{
6860 UNIMPLEMENTED();
6861}
6862
Jamie Madill5b772312018-03-08 20:28:32 -05006863bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6864{
6865 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6866 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6867 // to the fact that it is stored internally as a float, and so would require conversion
6868 // if returned from Context::getIntegerv. Since this conversion is already implemented
6869 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6870 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6871 // application.
6872 switch (pname)
6873 {
6874 case GL_COMPRESSED_TEXTURE_FORMATS:
6875 {
6876 *type = GL_INT;
6877 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6878 return true;
6879 }
6880 case GL_SHADER_BINARY_FORMATS:
6881 {
6882 *type = GL_INT;
6883 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6884 return true;
6885 }
6886
6887 case GL_MAX_VERTEX_ATTRIBS:
6888 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6889 case GL_MAX_VARYING_VECTORS:
6890 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6891 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6892 case GL_MAX_TEXTURE_IMAGE_UNITS:
6893 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6894 case GL_MAX_RENDERBUFFER_SIZE:
6895 case GL_NUM_SHADER_BINARY_FORMATS:
6896 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6897 case GL_ARRAY_BUFFER_BINDING:
6898 case GL_FRAMEBUFFER_BINDING:
6899 case GL_RENDERBUFFER_BINDING:
6900 case GL_CURRENT_PROGRAM:
6901 case GL_PACK_ALIGNMENT:
6902 case GL_UNPACK_ALIGNMENT:
6903 case GL_GENERATE_MIPMAP_HINT:
6904 case GL_RED_BITS:
6905 case GL_GREEN_BITS:
6906 case GL_BLUE_BITS:
6907 case GL_ALPHA_BITS:
6908 case GL_DEPTH_BITS:
6909 case GL_STENCIL_BITS:
6910 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6911 case GL_CULL_FACE_MODE:
6912 case GL_FRONT_FACE:
6913 case GL_ACTIVE_TEXTURE:
6914 case GL_STENCIL_FUNC:
6915 case GL_STENCIL_VALUE_MASK:
6916 case GL_STENCIL_REF:
6917 case GL_STENCIL_FAIL:
6918 case GL_STENCIL_PASS_DEPTH_FAIL:
6919 case GL_STENCIL_PASS_DEPTH_PASS:
6920 case GL_STENCIL_BACK_FUNC:
6921 case GL_STENCIL_BACK_VALUE_MASK:
6922 case GL_STENCIL_BACK_REF:
6923 case GL_STENCIL_BACK_FAIL:
6924 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6925 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6926 case GL_DEPTH_FUNC:
6927 case GL_BLEND_SRC_RGB:
6928 case GL_BLEND_SRC_ALPHA:
6929 case GL_BLEND_DST_RGB:
6930 case GL_BLEND_DST_ALPHA:
6931 case GL_BLEND_EQUATION_RGB:
6932 case GL_BLEND_EQUATION_ALPHA:
6933 case GL_STENCIL_WRITEMASK:
6934 case GL_STENCIL_BACK_WRITEMASK:
6935 case GL_STENCIL_CLEAR_VALUE:
6936 case GL_SUBPIXEL_BITS:
6937 case GL_MAX_TEXTURE_SIZE:
6938 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6939 case GL_SAMPLE_BUFFERS:
6940 case GL_SAMPLES:
6941 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6942 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6943 case GL_TEXTURE_BINDING_2D:
6944 case GL_TEXTURE_BINDING_CUBE_MAP:
6945 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6946 {
6947 *type = GL_INT;
6948 *numParams = 1;
6949 return true;
6950 }
6951 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6952 {
6953 if (!getExtensions().packReverseRowOrder)
6954 {
6955 return false;
6956 }
6957 *type = GL_INT;
6958 *numParams = 1;
6959 return true;
6960 }
6961 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6962 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6963 {
6964 if (!getExtensions().textureRectangle)
6965 {
6966 return false;
6967 }
6968 *type = GL_INT;
6969 *numParams = 1;
6970 return true;
6971 }
6972 case GL_MAX_DRAW_BUFFERS_EXT:
6973 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6974 {
6975 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6976 {
6977 return false;
6978 }
6979 *type = GL_INT;
6980 *numParams = 1;
6981 return true;
6982 }
6983 case GL_MAX_VIEWPORT_DIMS:
6984 {
6985 *type = GL_INT;
6986 *numParams = 2;
6987 return true;
6988 }
6989 case GL_VIEWPORT:
6990 case GL_SCISSOR_BOX:
6991 {
6992 *type = GL_INT;
6993 *numParams = 4;
6994 return true;
6995 }
6996 case GL_SHADER_COMPILER:
6997 case GL_SAMPLE_COVERAGE_INVERT:
6998 case GL_DEPTH_WRITEMASK:
6999 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7000 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7001 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7002 // bool-natural
7003 case GL_SAMPLE_COVERAGE:
7004 case GL_SCISSOR_TEST:
7005 case GL_STENCIL_TEST:
7006 case GL_DEPTH_TEST:
7007 case GL_BLEND:
7008 case GL_DITHER:
7009 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7010 {
7011 *type = GL_BOOL;
7012 *numParams = 1;
7013 return true;
7014 }
7015 case GL_COLOR_WRITEMASK:
7016 {
7017 *type = GL_BOOL;
7018 *numParams = 4;
7019 return true;
7020 }
7021 case GL_POLYGON_OFFSET_FACTOR:
7022 case GL_POLYGON_OFFSET_UNITS:
7023 case GL_SAMPLE_COVERAGE_VALUE:
7024 case GL_DEPTH_CLEAR_VALUE:
7025 case GL_LINE_WIDTH:
7026 {
7027 *type = GL_FLOAT;
7028 *numParams = 1;
7029 return true;
7030 }
7031 case GL_ALIASED_LINE_WIDTH_RANGE:
7032 case GL_ALIASED_POINT_SIZE_RANGE:
7033 case GL_DEPTH_RANGE:
7034 {
7035 *type = GL_FLOAT;
7036 *numParams = 2;
7037 return true;
7038 }
7039 case GL_COLOR_CLEAR_VALUE:
7040 case GL_BLEND_COLOR:
7041 {
7042 *type = GL_FLOAT;
7043 *numParams = 4;
7044 return true;
7045 }
7046 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7047 if (!getExtensions().textureFilterAnisotropic)
7048 {
7049 return false;
7050 }
7051 *type = GL_FLOAT;
7052 *numParams = 1;
7053 return true;
7054 case GL_TIMESTAMP_EXT:
7055 if (!getExtensions().disjointTimerQuery)
7056 {
7057 return false;
7058 }
7059 *type = GL_INT_64_ANGLEX;
7060 *numParams = 1;
7061 return true;
7062 case GL_GPU_DISJOINT_EXT:
7063 if (!getExtensions().disjointTimerQuery)
7064 {
7065 return false;
7066 }
7067 *type = GL_INT;
7068 *numParams = 1;
7069 return true;
7070 case GL_COVERAGE_MODULATION_CHROMIUM:
7071 if (!getExtensions().framebufferMixedSamples)
7072 {
7073 return false;
7074 }
7075 *type = GL_INT;
7076 *numParams = 1;
7077 return true;
7078 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7079 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7080 {
7081 return false;
7082 }
7083 *type = GL_INT;
7084 *numParams = 1;
7085 return true;
7086 }
7087
7088 if (getExtensions().debug)
7089 {
7090 switch (pname)
7091 {
7092 case GL_DEBUG_LOGGED_MESSAGES:
7093 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7094 case GL_DEBUG_GROUP_STACK_DEPTH:
7095 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7096 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7097 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7098 case GL_MAX_LABEL_LENGTH:
7099 *type = GL_INT;
7100 *numParams = 1;
7101 return true;
7102
7103 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7104 case GL_DEBUG_OUTPUT:
7105 *type = GL_BOOL;
7106 *numParams = 1;
7107 return true;
7108 }
7109 }
7110
7111 if (getExtensions().multisampleCompatibility)
7112 {
7113 switch (pname)
7114 {
7115 case GL_MULTISAMPLE_EXT:
7116 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7117 *type = GL_BOOL;
7118 *numParams = 1;
7119 return true;
7120 }
7121 }
7122
7123 if (getExtensions().pathRendering)
7124 {
7125 switch (pname)
7126 {
7127 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7128 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7129 *type = GL_FLOAT;
7130 *numParams = 16;
7131 return true;
7132 }
7133 }
7134
7135 if (getExtensions().bindGeneratesResource)
7136 {
7137 switch (pname)
7138 {
7139 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7140 *type = GL_BOOL;
7141 *numParams = 1;
7142 return true;
7143 }
7144 }
7145
7146 if (getExtensions().clientArrays)
7147 {
7148 switch (pname)
7149 {
7150 case GL_CLIENT_ARRAYS_ANGLE:
7151 *type = GL_BOOL;
7152 *numParams = 1;
7153 return true;
7154 }
7155 }
7156
7157 if (getExtensions().sRGBWriteControl)
7158 {
7159 switch (pname)
7160 {
7161 case GL_FRAMEBUFFER_SRGB_EXT:
7162 *type = GL_BOOL;
7163 *numParams = 1;
7164 return true;
7165 }
7166 }
7167
7168 if (getExtensions().robustResourceInitialization &&
7169 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7170 {
7171 *type = GL_BOOL;
7172 *numParams = 1;
7173 return true;
7174 }
7175
7176 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7177 {
7178 *type = GL_BOOL;
7179 *numParams = 1;
7180 return true;
7181 }
7182
jchen1082af6202018-06-22 10:59:52 +08007183 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7184 {
7185 *type = GL_INT;
7186 *numParams = 1;
7187 return true;
7188 }
7189
Jamie Madill5b772312018-03-08 20:28:32 -05007190 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7191 switch (pname)
7192 {
7193 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7194 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7195 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7196 {
7197 return false;
7198 }
7199 *type = GL_INT;
7200 *numParams = 1;
7201 return true;
7202
7203 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7204 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7205 {
7206 return false;
7207 }
7208 *type = GL_INT;
7209 *numParams = 1;
7210 return true;
7211
7212 case GL_PROGRAM_BINARY_FORMATS_OES:
7213 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7214 {
7215 return false;
7216 }
7217 *type = GL_INT;
7218 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7219 return true;
7220
7221 case GL_PACK_ROW_LENGTH:
7222 case GL_PACK_SKIP_ROWS:
7223 case GL_PACK_SKIP_PIXELS:
7224 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7225 {
7226 return false;
7227 }
7228 *type = GL_INT;
7229 *numParams = 1;
7230 return true;
7231 case GL_UNPACK_ROW_LENGTH:
7232 case GL_UNPACK_SKIP_ROWS:
7233 case GL_UNPACK_SKIP_PIXELS:
7234 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7235 {
7236 return false;
7237 }
7238 *type = GL_INT;
7239 *numParams = 1;
7240 return true;
7241 case GL_VERTEX_ARRAY_BINDING:
7242 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7243 {
7244 return false;
7245 }
7246 *type = GL_INT;
7247 *numParams = 1;
7248 return true;
7249 case GL_PIXEL_PACK_BUFFER_BINDING:
7250 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7251 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7252 {
7253 return false;
7254 }
7255 *type = GL_INT;
7256 *numParams = 1;
7257 return true;
7258 case GL_MAX_SAMPLES:
7259 {
7260 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7261 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7262 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7263 {
7264 return false;
7265 }
7266 *type = GL_INT;
7267 *numParams = 1;
7268 return true;
7269
7270 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7271 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7272 {
7273 return false;
7274 }
7275 *type = GL_INT;
7276 *numParams = 1;
7277 return true;
7278 }
7279 }
7280
7281 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7282 {
7283 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7284 {
7285 return false;
7286 }
7287 *type = GL_INT;
7288 *numParams = 1;
7289 return true;
7290 }
7291
7292 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7293 {
7294 *type = GL_INT;
7295 *numParams = 1;
7296 return true;
7297 }
7298
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007299 if (getClientVersion() < Version(2, 0))
7300 {
7301 switch (pname)
7302 {
7303 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007304 case GL_CLIENT_ACTIVE_TEXTURE:
7305 case GL_MATRIX_MODE:
7306 case GL_MAX_TEXTURE_UNITS:
7307 case GL_MAX_MODELVIEW_STACK_DEPTH:
7308 case GL_MAX_PROJECTION_STACK_DEPTH:
7309 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007310 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007311 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007312 case GL_VERTEX_ARRAY_STRIDE:
7313 case GL_NORMAL_ARRAY_STRIDE:
7314 case GL_COLOR_ARRAY_STRIDE:
7315 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7316 case GL_VERTEX_ARRAY_SIZE:
7317 case GL_COLOR_ARRAY_SIZE:
7318 case GL_TEXTURE_COORD_ARRAY_SIZE:
7319 case GL_VERTEX_ARRAY_TYPE:
7320 case GL_NORMAL_ARRAY_TYPE:
7321 case GL_COLOR_ARRAY_TYPE:
7322 case GL_TEXTURE_COORD_ARRAY_TYPE:
7323 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7324 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7325 case GL_COLOR_ARRAY_BUFFER_BINDING:
7326 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7327 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7328 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7329 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007330 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007331 case GL_MODELVIEW_STACK_DEPTH:
7332 case GL_PROJECTION_STACK_DEPTH:
7333 case GL_TEXTURE_STACK_DEPTH:
7334 case GL_LOGIC_OP_MODE:
7335 case GL_BLEND_SRC:
7336 case GL_BLEND_DST:
7337 case GL_PERSPECTIVE_CORRECTION_HINT:
7338 case GL_POINT_SMOOTH_HINT:
7339 case GL_LINE_SMOOTH_HINT:
7340 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007341 *type = GL_INT;
7342 *numParams = 1;
7343 return true;
7344 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007345 case GL_FOG_DENSITY:
7346 case GL_FOG_START:
7347 case GL_FOG_END:
7348 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007349 case GL_POINT_SIZE:
7350 case GL_POINT_SIZE_MIN:
7351 case GL_POINT_SIZE_MAX:
7352 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007353 *type = GL_FLOAT;
7354 *numParams = 1;
7355 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007356 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007357 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007358 *type = GL_FLOAT;
7359 *numParams = 2;
7360 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007361 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007362 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007363 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007364 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007365 *type = GL_FLOAT;
7366 *numParams = 4;
7367 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007368 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007369 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007370 *type = GL_FLOAT;
7371 *numParams = 3;
7372 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007373 case GL_MODELVIEW_MATRIX:
7374 case GL_PROJECTION_MATRIX:
7375 case GL_TEXTURE_MATRIX:
7376 *type = GL_FLOAT;
7377 *numParams = 16;
7378 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007379 case GL_LIGHT_MODEL_TWO_SIDE:
7380 *type = GL_BOOL;
7381 *numParams = 1;
7382 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007383 }
7384 }
7385
Jamie Madill5b772312018-03-08 20:28:32 -05007386 if (getClientVersion() < Version(3, 0))
7387 {
7388 return false;
7389 }
7390
7391 // Check for ES3.0+ parameter names
7392 switch (pname)
7393 {
7394 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7395 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7396 case GL_UNIFORM_BUFFER_BINDING:
7397 case GL_TRANSFORM_FEEDBACK_BINDING:
7398 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7399 case GL_COPY_READ_BUFFER_BINDING:
7400 case GL_COPY_WRITE_BUFFER_BINDING:
7401 case GL_SAMPLER_BINDING:
7402 case GL_READ_BUFFER:
7403 case GL_TEXTURE_BINDING_3D:
7404 case GL_TEXTURE_BINDING_2D_ARRAY:
7405 case GL_MAX_3D_TEXTURE_SIZE:
7406 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7407 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7408 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7409 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7410 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7411 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7412 case GL_MAX_VARYING_COMPONENTS:
7413 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7414 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7415 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7416 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7417 case GL_NUM_EXTENSIONS:
7418 case GL_MAJOR_VERSION:
7419 case GL_MINOR_VERSION:
7420 case GL_MAX_ELEMENTS_INDICES:
7421 case GL_MAX_ELEMENTS_VERTICES:
7422 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7423 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7424 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7425 case GL_UNPACK_IMAGE_HEIGHT:
7426 case GL_UNPACK_SKIP_IMAGES:
7427 {
7428 *type = GL_INT;
7429 *numParams = 1;
7430 return true;
7431 }
7432
7433 case GL_MAX_ELEMENT_INDEX:
7434 case GL_MAX_UNIFORM_BLOCK_SIZE:
7435 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7436 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7437 case GL_MAX_SERVER_WAIT_TIMEOUT:
7438 {
7439 *type = GL_INT_64_ANGLEX;
7440 *numParams = 1;
7441 return true;
7442 }
7443
7444 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7445 case GL_TRANSFORM_FEEDBACK_PAUSED:
7446 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7447 case GL_RASTERIZER_DISCARD:
7448 {
7449 *type = GL_BOOL;
7450 *numParams = 1;
7451 return true;
7452 }
7453
7454 case GL_MAX_TEXTURE_LOD_BIAS:
7455 {
7456 *type = GL_FLOAT;
7457 *numParams = 1;
7458 return true;
7459 }
7460 }
7461
7462 if (getExtensions().requestExtension)
7463 {
7464 switch (pname)
7465 {
7466 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7467 *type = GL_INT;
7468 *numParams = 1;
7469 return true;
7470 }
7471 }
7472
7473 if (getClientVersion() < Version(3, 1))
7474 {
7475 return false;
7476 }
7477
7478 switch (pname)
7479 {
7480 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7481 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7482 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7483 case GL_MAX_FRAMEBUFFER_WIDTH:
7484 case GL_MAX_FRAMEBUFFER_HEIGHT:
7485 case GL_MAX_FRAMEBUFFER_SAMPLES:
7486 case GL_MAX_SAMPLE_MASK_WORDS:
7487 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7488 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7489 case GL_MAX_INTEGER_SAMPLES:
7490 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7491 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7492 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7493 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7494 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7495 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7496 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7497 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7498 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7499 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7500 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7501 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7502 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7503 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7504 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7505 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7506 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7507 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7508 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7509 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7510 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7511 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7512 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7513 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7514 case GL_MAX_UNIFORM_LOCATIONS:
7515 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7516 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7517 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7518 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7519 case GL_MAX_IMAGE_UNITS:
7520 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7521 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7522 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7523 case GL_SHADER_STORAGE_BUFFER_BINDING:
7524 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7525 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007526 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007527 *type = GL_INT;
7528 *numParams = 1;
7529 return true;
7530 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7531 *type = GL_INT_64_ANGLEX;
7532 *numParams = 1;
7533 return true;
7534 case GL_SAMPLE_MASK:
7535 *type = GL_BOOL;
7536 *numParams = 1;
7537 return true;
7538 }
7539
7540 if (getExtensions().geometryShader)
7541 {
7542 switch (pname)
7543 {
7544 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7545 case GL_LAYER_PROVOKING_VERTEX_EXT:
7546 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7547 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7548 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7549 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7550 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7551 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7552 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7553 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7554 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7555 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7556 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7557 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7558 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7559 *type = GL_INT;
7560 *numParams = 1;
7561 return true;
7562 }
7563 }
7564
7565 return false;
7566}
7567
7568bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7569{
7570 if (getClientVersion() < Version(3, 0))
7571 {
7572 return false;
7573 }
7574
7575 switch (target)
7576 {
7577 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7578 case GL_UNIFORM_BUFFER_BINDING:
7579 {
7580 *type = GL_INT;
7581 *numParams = 1;
7582 return true;
7583 }
7584 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7585 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7586 case GL_UNIFORM_BUFFER_START:
7587 case GL_UNIFORM_BUFFER_SIZE:
7588 {
7589 *type = GL_INT_64_ANGLEX;
7590 *numParams = 1;
7591 return true;
7592 }
7593 }
7594
7595 if (getClientVersion() < Version(3, 1))
7596 {
7597 return false;
7598 }
7599
7600 switch (target)
7601 {
7602 case GL_IMAGE_BINDING_LAYERED:
7603 {
7604 *type = GL_BOOL;
7605 *numParams = 1;
7606 return true;
7607 }
7608 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7609 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7610 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7611 case GL_SHADER_STORAGE_BUFFER_BINDING:
7612 case GL_VERTEX_BINDING_BUFFER:
7613 case GL_VERTEX_BINDING_DIVISOR:
7614 case GL_VERTEX_BINDING_OFFSET:
7615 case GL_VERTEX_BINDING_STRIDE:
7616 case GL_SAMPLE_MASK_VALUE:
7617 case GL_IMAGE_BINDING_NAME:
7618 case GL_IMAGE_BINDING_LEVEL:
7619 case GL_IMAGE_BINDING_LAYER:
7620 case GL_IMAGE_BINDING_ACCESS:
7621 case GL_IMAGE_BINDING_FORMAT:
7622 {
7623 *type = GL_INT;
7624 *numParams = 1;
7625 return true;
7626 }
7627 case GL_ATOMIC_COUNTER_BUFFER_START:
7628 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7629 case GL_SHADER_STORAGE_BUFFER_START:
7630 case GL_SHADER_STORAGE_BUFFER_SIZE:
7631 {
7632 *type = GL_INT_64_ANGLEX;
7633 *numParams = 1;
7634 return true;
7635 }
7636 }
7637
7638 return false;
7639}
7640
7641Program *Context::getProgram(GLuint handle) const
7642{
7643 return mState.mShaderPrograms->getProgram(handle);
7644}
7645
7646Shader *Context::getShader(GLuint handle) const
7647{
7648 return mState.mShaderPrograms->getShader(handle);
7649}
7650
7651bool Context::isTextureGenerated(GLuint texture) const
7652{
7653 return mState.mTextures->isHandleGenerated(texture);
7654}
7655
Jamie Madill5b772312018-03-08 20:28:32 -05007656bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7657{
7658 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7659}
7660
7661bool Context::isFramebufferGenerated(GLuint framebuffer) const
7662{
7663 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7664}
7665
7666bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7667{
7668 return mState.mPipelines->isHandleGenerated(pipeline);
7669}
7670
7671bool Context::usingDisplayTextureShareGroup() const
7672{
7673 return mDisplayTextureShareGroup;
7674}
7675
7676GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7677{
7678 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7679 internalformat == GL_DEPTH_STENCIL
7680 ? GL_DEPTH24_STENCIL8
7681 : internalformat;
7682}
7683
jchen1082af6202018-06-22 10:59:52 +08007684void Context::maxShaderCompilerThreads(GLuint count)
7685{
jchen107ae70d82018-07-06 13:47:01 +08007686 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08007687 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007688 // A count of zero specifies a request for no parallel compiling or linking.
7689 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7690 {
7691 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7692 }
7693 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007694}
7695
Jamie Madill2eb65032018-07-30 10:25:57 -04007696bool Context::isGLES1() const
7697{
7698 return mState.getClientVersion() < Version(2, 0);
7699}
7700
Jamie Madilla11819d2018-07-30 10:26:01 -04007701void Context::onSubjectStateChange(const Context *context,
7702 angle::SubjectIndex index,
7703 angle::SubjectMessage message)
7704{
Jamie Madilla11819d2018-07-30 10:26:01 -04007705 switch (index)
7706 {
7707 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007708 switch (message)
7709 {
7710 case angle::SubjectMessage::CONTENTS_CHANGED:
7711 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
7712 mStateCache.onVertexArrayBufferContentsChange(this);
7713 break;
7714 case angle::SubjectMessage::RESOURCE_MAPPED:
7715 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7716 case angle::SubjectMessage::BINDING_CHANGED:
7717 mStateCache.onVertexArrayBufferStateChange(this);
7718 break;
7719 default:
7720 break;
7721 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007722 break;
7723
7724 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007725 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7726 {
7727 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
7728 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007729 break;
7730
7731 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007732 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7733 {
7734 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
7735 }
7736 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04007737 break;
7738
7739 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04007740 if (index < kTextureMaxSubjectIndex)
7741 {
7742 mGLState.onActiveTextureStateChange(index);
Jamie Madilld84b6732018-09-06 15:54:35 -04007743 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007744 }
7745 else
7746 {
7747 ASSERT(index < kUniformBufferMaxSubjectIndex);
7748 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04007749 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007750 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007751 break;
7752 }
7753}
7754
Jamie Madill6b873dd2018-07-12 23:56:30 -04007755// ErrorSet implementation.
7756ErrorSet::ErrorSet(Context *context) : mContext(context)
7757{
7758}
7759
7760ErrorSet::~ErrorSet() = default;
7761
Jamie Madill306b6c12018-07-27 08:12:49 -04007762void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007763{
7764 // This internal enum is used to filter internal errors that are already handled.
7765 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7766 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7767 {
7768 return;
7769 }
7770
7771 if (ANGLE_UNLIKELY(error.isError()))
7772 {
7773 GLenum code = error.getCode();
7774 mErrors.insert(code);
7775 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7776 {
7777 mContext->markContextLost();
7778 }
7779
7780 ASSERT(!error.getMessage().empty());
7781 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7782 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7783 error.getMessage());
7784 }
7785}
7786
7787bool ErrorSet::empty() const
7788{
7789 return mErrors.empty();
7790}
7791
7792GLenum ErrorSet::popError()
7793{
7794 ASSERT(!empty());
7795 GLenum error = *mErrors.begin();
7796 mErrors.erase(mErrors.begin());
7797 return error;
7798}
Jamie Madilldc358af2018-07-31 11:22:13 -04007799
7800// StateCache implementation.
Jamie Madill16e28fd2018-09-12 11:03:05 -04007801StateCache::StateCache(Context *context)
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007802 : mCachedHasAnyEnabledClientAttrib(false),
7803 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04007804 mCachedInstancedVertexElementLimit(0),
7805 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madilldc358af2018-07-31 11:22:13 -04007806{
Jamie Madill16e28fd2018-09-12 11:03:05 -04007807 updateValidDrawModes(context);
Jamie Madilldc358af2018-07-31 11:22:13 -04007808}
7809
7810StateCache::~StateCache() = default;
7811
7812void StateCache::updateActiveAttribsMask(Context *context)
7813{
7814 bool isGLES1 = context->isGLES1();
7815 const State &glState = context->getGLState();
7816
7817 if (!isGLES1 && !glState.getProgram())
7818 {
7819 mCachedActiveBufferedAttribsMask = AttributesMask();
7820 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04007821 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04007822 return;
7823 }
7824
7825 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7826 : glState.getProgram()->getActiveAttribLocationsMask();
7827
7828 const VertexArray *vao = glState.getVertexArray();
7829 ASSERT(vao);
7830
7831 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7832 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04007833 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007834
Jamie Madill0a17e482018-08-31 17:19:11 -04007835 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
7836 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04007837 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007838 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7839}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007840
7841void StateCache::updateVertexElementLimits(Context *context)
7842{
7843 const VertexArray *vao = context->getGLState().getVertexArray();
7844
7845 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7846 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7847
7848 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
7849 // If there are no buffered attributes then we should not limit the draw call count.
7850 if (!vao || !mCachedActiveBufferedAttribsMask.any())
7851 {
7852 return;
7853 }
7854
7855 const auto &vertexAttribs = vao->getVertexAttributes();
7856 const auto &vertexBindings = vao->getVertexBindings();
7857
7858 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
7859 {
7860 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
7861 ASSERT(attrib.enabled);
7862
7863 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
7864 ASSERT(context->isGLES1() ||
7865 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
7866
7867 GLint64 limit = attrib.getCachedElementLimit();
7868 if (binding.getDivisor() > 0)
7869 {
7870 mCachedInstancedVertexElementLimit =
7871 std::min(mCachedInstancedVertexElementLimit, limit);
7872 }
7873 else
7874 {
7875 mCachedNonInstancedVertexElementLimit =
7876 std::min(mCachedNonInstancedVertexElementLimit, limit);
7877 }
7878 }
7879}
Jamie Madillc43cdad2018-08-08 15:49:25 -04007880
Jamie Madilld84b6732018-09-06 15:54:35 -04007881void StateCache::updateBasicDrawStatesError()
7882{
7883 mCachedBasicDrawStatesError = kInvalidPointer;
7884}
7885
7886intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
7887{
7888 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
7889 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
7890 return mCachedBasicDrawStatesError;
7891}
7892
Jamie Madillc43cdad2018-08-08 15:49:25 -04007893void StateCache::onVertexArrayBindingChange(Context *context)
7894{
7895 updateActiveAttribsMask(context);
7896 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007897 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007898}
7899
7900void StateCache::onProgramExecutableChange(Context *context)
7901{
7902 updateActiveAttribsMask(context);
7903 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007904 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04007905 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04007906}
7907
Jamie Madilld84b6732018-09-06 15:54:35 -04007908void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04007909{
7910 updateVertexElementLimits(context);
7911}
7912
Jamie Madilld84b6732018-09-06 15:54:35 -04007913void StateCache::onVertexArrayBufferContentsChange(Context *context)
7914{
7915 updateVertexElementLimits(context);
7916 updateBasicDrawStatesError();
7917}
7918
Jamie Madillc43cdad2018-08-08 15:49:25 -04007919void StateCache::onVertexArrayStateChange(Context *context)
7920{
7921 updateActiveAttribsMask(context);
7922 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007923 updateBasicDrawStatesError();
7924}
7925
7926void StateCache::onVertexArrayBufferStateChange(Context *context)
7927{
7928 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007929}
7930
7931void StateCache::onGLES1ClientStateChange(Context *context)
7932{
7933 updateActiveAttribsMask(context);
7934}
Jamie Madilld84b6732018-09-06 15:54:35 -04007935
7936void StateCache::onDrawFramebufferChange(Context *context)
7937{
7938 updateBasicDrawStatesError();
7939}
7940
7941void StateCache::onContextCapChange(Context *context)
7942{
7943 updateBasicDrawStatesError();
7944}
7945
7946void StateCache::onStencilStateChange(Context *context)
7947{
7948 updateBasicDrawStatesError();
7949}
7950
7951void StateCache::onDefaultVertexAttributeChange(Context *context)
7952{
7953 updateBasicDrawStatesError();
7954}
7955
7956void StateCache::onActiveTextureChange(Context *context)
7957{
7958 updateBasicDrawStatesError();
7959}
7960
7961void StateCache::onQueryChange(Context *context)
7962{
7963 updateBasicDrawStatesError();
7964}
7965
7966void StateCache::onTransformFeedbackChange(Context *context)
7967{
7968 updateBasicDrawStatesError();
7969}
7970
7971void StateCache::onUniformBufferStateChange(Context *context)
7972{
7973 updateBasicDrawStatesError();
7974}
7975
7976void StateCache::onBufferBindingChange(Context *context)
7977{
7978 updateBasicDrawStatesError();
7979}
Jamie Madill526a6f62018-09-12 11:03:05 -04007980
7981void StateCache::updateValidDrawModes(Context *context)
7982{
7983 Program *program = context->getGLState().getProgram();
7984 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
7985 {
7986 mCachedValidDrawModes = {{
7987 true, /* Points */
7988 true, /* Lines */
7989 true, /* LineLoop */
7990 true, /* LineStrip */
7991 true, /* Triangles */
7992 true, /* TriangleStrip */
7993 true, /* TriangleFan */
7994 false, /* LinesAdjacency */
7995 false, /* LineStripAdjacency */
7996 false, /* TrianglesAdjacency */
7997 false, /* TriangleStripAdjacency */
7998 false, /* InvalidEnum */
7999 }};
8000 }
8001 else
8002 {
8003 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8004
8005 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
8006
8007 mCachedValidDrawModes = {{
8008 gsMode == PrimitiveMode::Points, /* Points */
8009 gsMode == PrimitiveMode::Lines, /* Lines */
8010 gsMode == PrimitiveMode::Lines, /* LineLoop */
8011 gsMode == PrimitiveMode::Lines, /* LineStrip */
8012 gsMode == PrimitiveMode::Triangles, /* Triangles */
8013 gsMode == PrimitiveMode::Triangles, /* TriangleStrip */
8014 gsMode == PrimitiveMode::Triangles, /* TriangleFan */
8015 gsMode == PrimitiveMode::LinesAdjacency, /* LinesAdjacency */
8016 gsMode == PrimitiveMode::LinesAdjacency, /* LineStripAdjacency */
8017 gsMode == PrimitiveMode::TrianglesAdjacency, /* TrianglesAdjacency */
8018 gsMode == PrimitiveMode::TrianglesAdjacency, /* TriangleStripAdjacency */
8019 false, /* InvalidEnum */
8020 }};
8021 }
8022}
Jamie Madillc29968b2016-01-20 11:17:23 -05008023} // namespace gl