blob: f20d64e0b7e5670e2b7d0000e35d48cf13baf827 [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 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
521 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
522 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
523 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
524 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
525 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800526 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800527 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400528 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800529
Jamie Madillb4927eb2018-07-16 11:39:46 -0400530 mImplementation->setErrorSet(&mErrors);
531
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400532 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000533}
534
Jamie Madill4928b7c2017-06-20 12:57:39 -0400535egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000536{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700537 if (mGLES1Renderer)
538 {
539 mGLES1Renderer->onDestroy(this, &mGLState);
540 }
541
Jamie Madille7b3fe22018-04-05 09:42:46 -0400542 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400543 ANGLE_TRY(releaseSurface(display));
544
Corentin Wallez80b24112015-08-25 16:41:57 -0400545 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000546 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400547 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000548 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400549 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000550
Corentin Wallez80b24112015-08-25 16:41:57 -0400551 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000552 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400553 if (query.second != nullptr)
554 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400555 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400556 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000557 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400558 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000559
Corentin Wallez80b24112015-08-25 16:41:57 -0400560 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400561 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400562 if (vertexArray.second)
563 {
564 vertexArray.second->onDestroy(this);
565 }
Jamie Madill57a89722013-07-02 11:57:03 -0400566 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400567 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400568
Corentin Wallez80b24112015-08-25 16:41:57 -0400569 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500570 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500571 if (transformFeedback.second != nullptr)
572 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500573 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500574 }
Geoff Langc8058452014-02-03 12:04:11 -0500575 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400576 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500577
Jamie Madill5b772312018-03-08 20:28:32 -0500578 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400579 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800580 if (zeroTexture.get() != nullptr)
581 {
582 ANGLE_TRY(zeroTexture->onDestroy(this));
583 zeroTexture.set(this, nullptr);
584 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400585 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000586
Jamie Madill2f348d22017-06-05 10:50:59 -0400587 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500588
Jamie Madill4928b7c2017-06-20 12:57:39 -0400589 mGLState.reset(this);
590
Jamie Madill6c1f6712017-02-14 19:08:04 -0500591 mState.mBuffers->release(this);
592 mState.mShaderPrograms->release(this);
593 mState.mTextures->release(this);
594 mState.mRenderbuffers->release(this);
595 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400596 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500597 mState.mPaths->release(this);
598 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800599 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400600
jchen107ae70d82018-07-06 13:47:01 +0800601 mThreadPool.reset();
602
Jamie Madill76e471e2017-10-21 09:56:01 -0400603 mImplementation->onDestroy(this);
604
Jamie Madill4928b7c2017-06-20 12:57:39 -0400605 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000606}
607
Jamie Madill70ee0f62017-02-06 16:04:20 -0500608Context::~Context()
609{
610}
611
Geoff Lang75359662018-04-11 01:42:27 -0400612void Context::setLabel(EGLLabelKHR label)
613{
614 mLabel = label;
615}
616
617EGLLabelKHR Context::getLabel() const
618{
619 return mLabel;
620}
621
Jamie Madill4928b7c2017-06-20 12:57:39 -0400622egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000623{
Jamie Madill61e16b42017-06-19 11:13:23 -0400624 mCurrentDisplay = display;
625
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000626 if (!mHasBeenCurrent)
627 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400628 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000629 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500630 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400631 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000632
Corentin Wallezc295e512017-01-27 17:47:50 -0500633 int width = 0;
634 int height = 0;
635 if (surface != nullptr)
636 {
637 width = surface->getWidth();
638 height = surface->getHeight();
639 }
640
641 mGLState.setViewportParams(0, 0, width, height);
642 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643
644 mHasBeenCurrent = true;
645 }
646
Jamie Madill1b94d432015-08-07 13:23:23 -0400647 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700648 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400649 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400650
Jamie Madill4928b7c2017-06-20 12:57:39 -0400651 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500652
653 Framebuffer *newDefault = nullptr;
654 if (surface != nullptr)
655 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400656 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500657 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400658 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500659 }
660 else
661 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400662 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500663 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000664
Corentin Wallez37c39792015-08-20 14:19:46 -0400665 // Update default framebuffer, the binding of the previous default
666 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400667 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400668 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700669 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400670 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400671 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400672 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700673 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400674 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400675 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400676 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400677 }
Ian Ewell292f0052016-02-04 10:37:32 -0500678
679 // Notify the renderer of a context switch
Luc Ferron5396f2a2018-07-12 08:24:23 -0400680 ANGLE_TRY(mImplementation->onMakeCurrent(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400681 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000682}
683
Jamie Madill4928b7c2017-06-20 12:57:39 -0400684egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400685{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400686 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400687
Geoff Langbf7b95d2018-05-01 16:48:21 -0400688 // Remove the default framebuffer
689 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500690 {
691 mGLState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400692 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500693 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400694
695 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500696 {
697 mGLState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400698 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500699 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400700
701 if (defaultFramebuffer)
702 {
703 defaultFramebuffer->onDestroy(this);
704 delete defaultFramebuffer;
705 }
706
Corentin Wallezc295e512017-01-27 17:47:50 -0500707 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
708
709 if (mCurrentSurface)
710 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400711 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500712 mCurrentSurface = nullptr;
713 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400714
715 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400716}
717
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000718GLuint Context::createBuffer()
719{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500720 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000721}
722
723GLuint Context::createProgram()
724{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500725 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000726}
727
Jiawei Shao385b3e02018-03-21 09:43:28 +0800728GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000729{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500730 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000731}
732
733GLuint Context::createTexture()
734{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500735 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000736}
737
738GLuint Context::createRenderbuffer()
739{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500740 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000741}
742
Brandon Jones59770802018-04-02 13:18:42 -0700743GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300744{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500745 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300746 if (resultOrError.isError())
747 {
748 handleError(resultOrError.getError());
749 return 0;
750 }
751 return resultOrError.getResult();
752}
753
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000754// Returns an unused framebuffer name
755GLuint Context::createFramebuffer()
756{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500757 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000758}
759
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500760void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000761{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500762 for (int i = 0; i < n; i++)
763 {
764 GLuint handle = mFenceNVHandleAllocator.allocate();
765 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
766 fences[i] = handle;
767 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000768}
769
Yunchao Hea336b902017-08-02 16:05:21 +0800770GLuint Context::createProgramPipeline()
771{
772 return mState.mPipelines->createProgramPipeline();
773}
774
Jiawei Shao385b3e02018-03-21 09:43:28 +0800775GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800776{
777 UNIMPLEMENTED();
778 return 0u;
779}
780
James Darpinian4d9d4832018-03-13 12:43:28 -0700781void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000782{
James Darpinian4d9d4832018-03-13 12:43:28 -0700783 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
784 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000785 {
786 detachBuffer(buffer);
787 }
Jamie Madill893ab082014-05-16 16:56:10 -0400788
James Darpinian4d9d4832018-03-13 12:43:28 -0700789 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000790}
791
792void Context::deleteShader(GLuint shader)
793{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500794 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000795}
796
797void Context::deleteProgram(GLuint program)
798{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500799 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000800}
801
802void Context::deleteTexture(GLuint texture)
803{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500804 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000805 {
806 detachTexture(texture);
807 }
808
Jamie Madill6c1f6712017-02-14 19:08:04 -0500809 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000810}
811
812void Context::deleteRenderbuffer(GLuint renderbuffer)
813{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500814 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000815 {
816 detachRenderbuffer(renderbuffer);
817 }
Jamie Madill893ab082014-05-16 16:56:10 -0400818
Jamie Madill6c1f6712017-02-14 19:08:04 -0500819 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000820}
821
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400822void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400823{
824 // The spec specifies the underlying Fence object is not deleted until all current
825 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
826 // and since our API is currently designed for being called from a single thread, we can delete
827 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400828 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400829}
830
Yunchao Hea336b902017-08-02 16:05:21 +0800831void Context::deleteProgramPipeline(GLuint pipeline)
832{
833 if (mState.mPipelines->getProgramPipeline(pipeline))
834 {
835 detachProgramPipeline(pipeline);
836 }
837
838 mState.mPipelines->deleteObject(this, pipeline);
839}
840
Sami Väisänene45e53b2016-05-25 10:36:04 +0300841void Context::deletePaths(GLuint first, GLsizei range)
842{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500843 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300844}
845
Brandon Jones59770802018-04-02 13:18:42 -0700846bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300847{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500848 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300849 if (pathObj == nullptr)
850 return false;
851
852 return pathObj->hasPathData();
853}
854
Brandon Jones59770802018-04-02 13:18:42 -0700855bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300856{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500857 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300858}
859
Brandon Jones59770802018-04-02 13:18:42 -0700860void Context::pathCommands(GLuint path,
861 GLsizei numCommands,
862 const GLubyte *commands,
863 GLsizei numCoords,
864 GLenum coordType,
865 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300866{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500867 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300868
869 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
870}
871
Jamie Madill007530e2017-12-28 14:27:04 -0500872void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300873{
Jamie Madill007530e2017-12-28 14:27:04 -0500874 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300875
876 switch (pname)
877 {
878 case GL_PATH_STROKE_WIDTH_CHROMIUM:
879 pathObj->setStrokeWidth(value);
880 break;
881 case GL_PATH_END_CAPS_CHROMIUM:
882 pathObj->setEndCaps(static_cast<GLenum>(value));
883 break;
884 case GL_PATH_JOIN_STYLE_CHROMIUM:
885 pathObj->setJoinStyle(static_cast<GLenum>(value));
886 break;
887 case GL_PATH_MITER_LIMIT_CHROMIUM:
888 pathObj->setMiterLimit(value);
889 break;
890 case GL_PATH_STROKE_BOUND_CHROMIUM:
891 pathObj->setStrokeBound(value);
892 break;
893 default:
894 UNREACHABLE();
895 break;
896 }
897}
898
Jamie Madill007530e2017-12-28 14:27:04 -0500899void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300900{
Jamie Madill007530e2017-12-28 14:27:04 -0500901 // TODO(jmadill): Should use proper clamping/casting.
902 pathParameterf(path, pname, static_cast<GLfloat>(value));
903}
904
905void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
906{
907 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300908
909 switch (pname)
910 {
911 case GL_PATH_STROKE_WIDTH_CHROMIUM:
912 *value = pathObj->getStrokeWidth();
913 break;
914 case GL_PATH_END_CAPS_CHROMIUM:
915 *value = static_cast<GLfloat>(pathObj->getEndCaps());
916 break;
917 case GL_PATH_JOIN_STYLE_CHROMIUM:
918 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
919 break;
920 case GL_PATH_MITER_LIMIT_CHROMIUM:
921 *value = pathObj->getMiterLimit();
922 break;
923 case GL_PATH_STROKE_BOUND_CHROMIUM:
924 *value = pathObj->getStrokeBound();
925 break;
926 default:
927 UNREACHABLE();
928 break;
929 }
930}
931
Jamie Madill007530e2017-12-28 14:27:04 -0500932void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
933{
934 GLfloat val = 0.0f;
935 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
936 if (value)
937 *value = static_cast<GLint>(val);
938}
939
Brandon Jones59770802018-04-02 13:18:42 -0700940void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300941{
942 mGLState.setPathStencilFunc(func, ref, mask);
943}
944
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000945void Context::deleteFramebuffer(GLuint framebuffer)
946{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500947 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000948 {
949 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000950 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500951
Jamie Madill6c1f6712017-02-14 19:08:04 -0500952 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000953}
954
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500955void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000956{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500957 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000958 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500959 GLuint fence = fences[i];
960
961 FenceNV *fenceObject = nullptr;
962 if (mFenceNVMap.erase(fence, &fenceObject))
963 {
964 mFenceNVHandleAllocator.release(fence);
965 delete fenceObject;
966 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000967 }
968}
969
Geoff Lang70d0f492015-12-10 17:45:46 -0500970Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000971{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500972 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000973}
974
Geoff Lang70d0f492015-12-10 17:45:46 -0500975Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000976{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500977 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000978}
979
Jamie Madill70b5bb02017-08-28 13:32:37 -0400980Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400981{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400982 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400983}
984
Jamie Madill57a89722013-07-02 11:57:03 -0400985VertexArray *Context::getVertexArray(GLuint handle) const
986{
Jamie Madill96a483b2017-06-27 16:49:21 -0400987 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400988}
989
Jamie Madilldc356042013-07-19 16:36:57 -0400990Sampler *Context::getSampler(GLuint handle) const
991{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500992 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400993}
994
Geoff Langc8058452014-02-03 12:04:11 -0500995TransformFeedback *Context::getTransformFeedback(GLuint handle) const
996{
Jamie Madill96a483b2017-06-27 16:49:21 -0400997 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500998}
999
Yunchao Hea336b902017-08-02 16:05:21 +08001000ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
1001{
1002 return mState.mPipelines->getProgramPipeline(handle);
1003}
1004
Geoff Lang75359662018-04-11 01:42:27 -04001005gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001006{
1007 switch (identifier)
1008 {
1009 case GL_BUFFER:
1010 return getBuffer(name);
1011 case GL_SHADER:
1012 return getShader(name);
1013 case GL_PROGRAM:
1014 return getProgram(name);
1015 case GL_VERTEX_ARRAY:
1016 return getVertexArray(name);
1017 case GL_QUERY:
1018 return getQuery(name);
1019 case GL_TRANSFORM_FEEDBACK:
1020 return getTransformFeedback(name);
1021 case GL_SAMPLER:
1022 return getSampler(name);
1023 case GL_TEXTURE:
1024 return getTexture(name);
1025 case GL_RENDERBUFFER:
1026 return getRenderbuffer(name);
1027 case GL_FRAMEBUFFER:
1028 return getFramebuffer(name);
1029 default:
1030 UNREACHABLE();
1031 return nullptr;
1032 }
1033}
1034
Geoff Lang75359662018-04-11 01:42:27 -04001035gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001036{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001037 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001038}
1039
Martin Radev9d901792016-07-15 15:58:58 +03001040void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1041{
Geoff Lang75359662018-04-11 01:42:27 -04001042 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001043 ASSERT(object != nullptr);
1044
1045 std::string labelName = GetObjectLabelFromPointer(length, label);
1046 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001047
1048 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1049 // specified object is active until we do this.
1050 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001051}
1052
1053void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1054{
Geoff Lang75359662018-04-11 01:42:27 -04001055 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001056 ASSERT(object != nullptr);
1057
1058 std::string labelName = GetObjectLabelFromPointer(length, label);
1059 object->setLabel(labelName);
1060}
1061
1062void Context::getObjectLabel(GLenum identifier,
1063 GLuint name,
1064 GLsizei bufSize,
1065 GLsizei *length,
1066 GLchar *label) const
1067{
Geoff Lang75359662018-04-11 01:42:27 -04001068 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001069 ASSERT(object != nullptr);
1070
1071 const std::string &objectLabel = object->getLabel();
1072 GetObjectLabelBase(objectLabel, bufSize, length, label);
1073}
1074
1075void Context::getObjectPtrLabel(const void *ptr,
1076 GLsizei bufSize,
1077 GLsizei *length,
1078 GLchar *label) const
1079{
Geoff Lang75359662018-04-11 01:42:27 -04001080 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001081 ASSERT(object != nullptr);
1082
1083 const std::string &objectLabel = object->getLabel();
1084 GetObjectLabelBase(objectLabel, bufSize, length, label);
1085}
1086
Jamie Madilldc356042013-07-19 16:36:57 -04001087bool Context::isSampler(GLuint samplerName) const
1088{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001089 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001090}
1091
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001092void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001093{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001094 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001095
Jamie Madilldedd7b92014-11-05 16:30:36 -05001096 if (handle == 0)
1097 {
1098 texture = mZeroTextures[target].get();
1099 }
1100 else
1101 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001102 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001103 }
1104
1105 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001106 mGLState.setSamplerTexture(this, target, texture);
Jamie Madilld84b6732018-09-06 15:54:35 -04001107 mStateCache.onActiveTextureChange(this);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001108}
1109
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001110void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001111{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001112 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1113 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001114 mGLState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001115 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001116}
1117
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001118void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001119{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001120 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1121 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001122 mGLState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001123 mDrawFramebufferObserverBinding.bind(framebuffer);
Jamie Madilld84b6732018-09-06 15:54:35 -04001124 mStateCache.onDrawFramebufferChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001125}
1126
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001127void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001128{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001129 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001130 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001131 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001132 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001133}
1134
Shao80957d92017-02-20 21:25:59 +08001135void Context::bindVertexBuffer(GLuint bindingIndex,
1136 GLuint bufferHandle,
1137 GLintptr offset,
1138 GLsizei stride)
1139{
1140 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001141 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001142 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001143}
1144
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001145void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001146{
Geoff Lang76b10c92014-09-05 16:28:14 -04001147 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001148 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001149 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001150 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001151}
1152
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001153void Context::bindImageTexture(GLuint unit,
1154 GLuint texture,
1155 GLint level,
1156 GLboolean layered,
1157 GLint layer,
1158 GLenum access,
1159 GLenum format)
1160{
1161 Texture *tex = mState.mTextures->getTexture(texture);
1162 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1163}
1164
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001165void Context::useProgram(GLuint program)
1166{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001167 mGLState.setProgram(this, getProgram(program));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001168 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001169}
1170
Jiajia Qin5451d532017-11-16 17:16:34 +08001171void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1172{
1173 UNIMPLEMENTED();
1174}
1175
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001176void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001177{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001178 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001179 TransformFeedback *transformFeedback =
1180 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001181 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Jamie Madilld84b6732018-09-06 15:54:35 -04001182 mStateCache.onTransformFeedbackChange(this);
Geoff Langc8058452014-02-03 12:04:11 -05001183}
1184
Yunchao Hea336b902017-08-02 16:05:21 +08001185void Context::bindProgramPipeline(GLuint pipelineHandle)
1186{
1187 ProgramPipeline *pipeline =
1188 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1189 mGLState.setProgramPipelineBinding(this, pipeline);
1190}
1191
Corentin Wallezad3ae902018-03-09 13:40:42 -05001192void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001193{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001194 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001195 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001196
Geoff Lang5aad9672014-09-08 11:10:42 -04001197 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001198 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001199
1200 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001201 mGLState.setActiveQuery(this, target, queryObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04001202 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001203}
1204
Corentin Wallezad3ae902018-03-09 13:40:42 -05001205void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001206{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001207 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001208 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001209
Jamie Madill5188a272018-07-25 10:53:56 -04001210 handleError(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001211
Geoff Lang5aad9672014-09-08 11:10:42 -04001212 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001213 mGLState.setActiveQuery(this, target, nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04001214 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001215}
1216
Corentin Wallezad3ae902018-03-09 13:40:42 -05001217void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001218{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001219 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001220
1221 Query *queryObject = getQuery(id, true, target);
1222 ASSERT(queryObject);
1223
Jamie Madill5188a272018-07-25 10:53:56 -04001224 handleError(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001225}
1226
Corentin Wallezad3ae902018-03-09 13:40:42 -05001227void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001228{
1229 switch (pname)
1230 {
1231 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001232 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001233 break;
1234 case GL_QUERY_COUNTER_BITS_EXT:
1235 switch (target)
1236 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001237 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001238 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1239 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001240 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001241 params[0] = getExtensions().queryCounterBitsTimestamp;
1242 break;
1243 default:
1244 UNREACHABLE();
1245 params[0] = 0;
1246 break;
1247 }
1248 break;
1249 default:
1250 UNREACHABLE();
1251 return;
1252 }
1253}
1254
Corentin Wallezad3ae902018-03-09 13:40:42 -05001255void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001256 GLenum pname,
1257 GLsizei bufSize,
1258 GLsizei *length,
1259 GLint *params)
1260{
1261 getQueryiv(target, pname, params);
1262}
1263
Geoff Lang2186c382016-10-14 10:54:54 -04001264void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001265{
Jamie Madill5188a272018-07-25 10:53:56 -04001266 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001267}
1268
Brandon Jones59770802018-04-02 13:18:42 -07001269void Context::getQueryObjectivRobust(GLuint id,
1270 GLenum pname,
1271 GLsizei bufSize,
1272 GLsizei *length,
1273 GLint *params)
1274{
1275 getQueryObjectiv(id, pname, params);
1276}
1277
Geoff Lang2186c382016-10-14 10:54:54 -04001278void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001279{
Jamie Madill5188a272018-07-25 10:53:56 -04001280 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001281}
1282
Brandon Jones59770802018-04-02 13:18:42 -07001283void Context::getQueryObjectuivRobust(GLuint id,
1284 GLenum pname,
1285 GLsizei bufSize,
1286 GLsizei *length,
1287 GLuint *params)
1288{
1289 getQueryObjectuiv(id, pname, params);
1290}
1291
Geoff Lang2186c382016-10-14 10:54:54 -04001292void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001293{
Jamie Madill5188a272018-07-25 10:53:56 -04001294 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001295}
1296
Brandon Jones59770802018-04-02 13:18:42 -07001297void Context::getQueryObjecti64vRobust(GLuint id,
1298 GLenum pname,
1299 GLsizei bufSize,
1300 GLsizei *length,
1301 GLint64 *params)
1302{
1303 getQueryObjecti64v(id, pname, params);
1304}
1305
Geoff Lang2186c382016-10-14 10:54:54 -04001306void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001307{
Jamie Madill5188a272018-07-25 10:53:56 -04001308 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001309}
1310
Brandon Jones59770802018-04-02 13:18:42 -07001311void Context::getQueryObjectui64vRobust(GLuint id,
1312 GLenum pname,
1313 GLsizei bufSize,
1314 GLsizei *length,
1315 GLuint64 *params)
1316{
1317 getQueryObjectui64v(id, pname, params);
1318}
1319
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001320Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001321{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001322 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001323}
1324
Jamie Madill2f348d22017-06-05 10:50:59 -04001325FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001326{
Jamie Madill96a483b2017-06-27 16:49:21 -04001327 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001328}
1329
Corentin Wallezad3ae902018-03-09 13:40:42 -05001330Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001331{
Jamie Madill96a483b2017-06-27 16:49:21 -04001332 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001333 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001334 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001335 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001336
1337 Query *query = mQueryMap.query(handle);
1338 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001339 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001340 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001341 query = new Query(mImplementation->createQuery(type), handle);
1342 query->addRef();
1343 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001344 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001345 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001346}
1347
Geoff Lang70d0f492015-12-10 17:45:46 -05001348Query *Context::getQuery(GLuint handle) const
1349{
Jamie Madill96a483b2017-06-27 16:49:21 -04001350 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001351}
1352
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001353Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001354{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001355 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1356 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001357}
1358
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001359Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001360{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001361 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001362}
1363
Geoff Lang492a7e42014-11-05 13:27:06 -05001364Compiler *Context::getCompiler() const
1365{
Jamie Madill2f348d22017-06-05 10:50:59 -04001366 if (mCompiler.get() == nullptr)
1367 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001368 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001369 }
1370 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001371}
1372
Jamie Madillc1d770e2017-04-13 17:31:24 -04001373void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001374{
1375 switch (pname)
1376 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001377 case GL_SHADER_COMPILER:
1378 *params = GL_TRUE;
1379 break;
1380 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1381 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1382 break;
1383 default:
1384 mGLState.getBooleanv(pname, params);
1385 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001386 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001387}
1388
Jamie Madillc1d770e2017-04-13 17:31:24 -04001389void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001390{
Shannon Woods53a94a82014-06-24 15:20:36 -04001391 // Queries about context capabilities and maximums are answered by Context.
1392 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001393 switch (pname)
1394 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001395 case GL_ALIASED_LINE_WIDTH_RANGE:
1396 params[0] = mCaps.minAliasedLineWidth;
1397 params[1] = mCaps.maxAliasedLineWidth;
1398 break;
1399 case GL_ALIASED_POINT_SIZE_RANGE:
1400 params[0] = mCaps.minAliasedPointSize;
1401 params[1] = mCaps.maxAliasedPointSize;
1402 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001403 case GL_SMOOTH_POINT_SIZE_RANGE:
1404 params[0] = mCaps.minSmoothPointSize;
1405 params[1] = mCaps.maxSmoothPointSize;
1406 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001407 case GL_SMOOTH_LINE_WIDTH_RANGE:
1408 params[0] = mCaps.minSmoothLineWidth;
1409 params[1] = mCaps.maxSmoothLineWidth;
1410 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001411 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1412 ASSERT(mExtensions.textureFilterAnisotropic);
1413 *params = mExtensions.maxTextureAnisotropy;
1414 break;
1415 case GL_MAX_TEXTURE_LOD_BIAS:
1416 *params = mCaps.maxLODBias;
1417 break;
1418
1419 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1420 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1421 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001422 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1423 // GLES1 constants for modelview/projection matrix.
1424 if (getClientVersion() < Version(2, 0))
1425 {
1426 mGLState.getFloatv(pname, params);
1427 }
1428 else
1429 {
1430 ASSERT(mExtensions.pathRendering);
1431 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1432 memcpy(params, m, 16 * sizeof(GLfloat));
1433 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001434 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001435 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001436
Jamie Madill231c7f52017-04-26 13:45:37 -04001437 default:
1438 mGLState.getFloatv(pname, params);
1439 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001440 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001441}
1442
Jamie Madillc1d770e2017-04-13 17:31:24 -04001443void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001444{
Shannon Woods53a94a82014-06-24 15:20:36 -04001445 // Queries about context capabilities and maximums are answered by Context.
1446 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001447
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001448 switch (pname)
1449 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001450 case GL_MAX_VERTEX_ATTRIBS:
1451 *params = mCaps.maxVertexAttributes;
1452 break;
1453 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1454 *params = mCaps.maxVertexUniformVectors;
1455 break;
1456 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001457 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001458 break;
1459 case GL_MAX_VARYING_VECTORS:
1460 *params = mCaps.maxVaryingVectors;
1461 break;
1462 case GL_MAX_VARYING_COMPONENTS:
1463 *params = mCaps.maxVertexOutputComponents;
1464 break;
1465 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1466 *params = mCaps.maxCombinedTextureImageUnits;
1467 break;
1468 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001469 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001470 break;
1471 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001472 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001473 break;
1474 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1475 *params = mCaps.maxFragmentUniformVectors;
1476 break;
1477 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001478 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001479 break;
1480 case GL_MAX_RENDERBUFFER_SIZE:
1481 *params = mCaps.maxRenderbufferSize;
1482 break;
1483 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1484 *params = mCaps.maxColorAttachments;
1485 break;
1486 case GL_MAX_DRAW_BUFFERS_EXT:
1487 *params = mCaps.maxDrawBuffers;
1488 break;
1489 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1490 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1491 case GL_SUBPIXEL_BITS:
1492 *params = 4;
1493 break;
1494 case GL_MAX_TEXTURE_SIZE:
1495 *params = mCaps.max2DTextureSize;
1496 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001497 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1498 *params = mCaps.maxRectangleTextureSize;
1499 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001500 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1501 *params = mCaps.maxCubeMapTextureSize;
1502 break;
1503 case GL_MAX_3D_TEXTURE_SIZE:
1504 *params = mCaps.max3DTextureSize;
1505 break;
1506 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1507 *params = mCaps.maxArrayTextureLayers;
1508 break;
1509 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1510 *params = mCaps.uniformBufferOffsetAlignment;
1511 break;
1512 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1513 *params = mCaps.maxUniformBufferBindings;
1514 break;
1515 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001516 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001517 break;
1518 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001519 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001520 break;
1521 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1522 *params = mCaps.maxCombinedTextureImageUnits;
1523 break;
1524 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1525 *params = mCaps.maxVertexOutputComponents;
1526 break;
1527 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1528 *params = mCaps.maxFragmentInputComponents;
1529 break;
1530 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1531 *params = mCaps.minProgramTexelOffset;
1532 break;
1533 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1534 *params = mCaps.maxProgramTexelOffset;
1535 break;
1536 case GL_MAJOR_VERSION:
1537 *params = getClientVersion().major;
1538 break;
1539 case GL_MINOR_VERSION:
1540 *params = getClientVersion().minor;
1541 break;
1542 case GL_MAX_ELEMENTS_INDICES:
1543 *params = mCaps.maxElementsIndices;
1544 break;
1545 case GL_MAX_ELEMENTS_VERTICES:
1546 *params = mCaps.maxElementsVertices;
1547 break;
1548 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1549 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1550 break;
1551 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1552 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1553 break;
1554 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1555 *params = mCaps.maxTransformFeedbackSeparateComponents;
1556 break;
1557 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1558 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1559 break;
1560 case GL_MAX_SAMPLES_ANGLE:
1561 *params = mCaps.maxSamples;
1562 break;
1563 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001564 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001565 params[0] = mCaps.maxViewportWidth;
1566 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001567 }
1568 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001569 case GL_COMPRESSED_TEXTURE_FORMATS:
1570 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1571 params);
1572 break;
1573 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1574 *params = mResetStrategy;
1575 break;
1576 case GL_NUM_SHADER_BINARY_FORMATS:
1577 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1578 break;
1579 case GL_SHADER_BINARY_FORMATS:
1580 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1581 break;
1582 case GL_NUM_PROGRAM_BINARY_FORMATS:
1583 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1584 break;
1585 case GL_PROGRAM_BINARY_FORMATS:
1586 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1587 break;
1588 case GL_NUM_EXTENSIONS:
1589 *params = static_cast<GLint>(mExtensionStrings.size());
1590 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001591
Jamie Madill231c7f52017-04-26 13:45:37 -04001592 // GL_KHR_debug
1593 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1594 *params = mExtensions.maxDebugMessageLength;
1595 break;
1596 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1597 *params = mExtensions.maxDebugLoggedMessages;
1598 break;
1599 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1600 *params = mExtensions.maxDebugGroupStackDepth;
1601 break;
1602 case GL_MAX_LABEL_LENGTH:
1603 *params = mExtensions.maxLabelLength;
1604 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001605
Martin Radeve5285d22017-07-14 16:23:53 +03001606 // GL_ANGLE_multiview
1607 case GL_MAX_VIEWS_ANGLE:
1608 *params = mExtensions.maxViews;
1609 break;
1610
Jamie Madill231c7f52017-04-26 13:45:37 -04001611 // GL_EXT_disjoint_timer_query
1612 case GL_GPU_DISJOINT_EXT:
1613 *params = mImplementation->getGPUDisjoint();
1614 break;
1615 case GL_MAX_FRAMEBUFFER_WIDTH:
1616 *params = mCaps.maxFramebufferWidth;
1617 break;
1618 case GL_MAX_FRAMEBUFFER_HEIGHT:
1619 *params = mCaps.maxFramebufferHeight;
1620 break;
1621 case GL_MAX_FRAMEBUFFER_SAMPLES:
1622 *params = mCaps.maxFramebufferSamples;
1623 break;
1624 case GL_MAX_SAMPLE_MASK_WORDS:
1625 *params = mCaps.maxSampleMaskWords;
1626 break;
1627 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1628 *params = mCaps.maxColorTextureSamples;
1629 break;
1630 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1631 *params = mCaps.maxDepthTextureSamples;
1632 break;
1633 case GL_MAX_INTEGER_SAMPLES:
1634 *params = mCaps.maxIntegerSamples;
1635 break;
1636 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1637 *params = mCaps.maxVertexAttribRelativeOffset;
1638 break;
1639 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1640 *params = mCaps.maxVertexAttribBindings;
1641 break;
1642 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1643 *params = mCaps.maxVertexAttribStride;
1644 break;
1645 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001646 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001647 break;
1648 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001649 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001650 break;
1651 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001652 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001653 break;
1654 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001655 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001656 break;
1657 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001658 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001659 break;
1660 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001661 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001662 break;
1663 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001664 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001665 break;
1666 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001667 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001668 break;
1669 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1670 *params = mCaps.minProgramTextureGatherOffset;
1671 break;
1672 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1673 *params = mCaps.maxProgramTextureGatherOffset;
1674 break;
1675 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1676 *params = mCaps.maxComputeWorkGroupInvocations;
1677 break;
1678 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001679 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001680 break;
1681 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001682 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001683 break;
1684 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1685 *params = mCaps.maxComputeSharedMemorySize;
1686 break;
1687 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001688 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001689 break;
1690 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001691 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001692 break;
1693 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001694 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001695 break;
1696 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001697 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001698 break;
1699 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001700 *params =
1701 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001702 break;
1703 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001704 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001705 break;
1706 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1707 *params = mCaps.maxCombinedShaderOutputResources;
1708 break;
1709 case GL_MAX_UNIFORM_LOCATIONS:
1710 *params = mCaps.maxUniformLocations;
1711 break;
1712 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1713 *params = mCaps.maxAtomicCounterBufferBindings;
1714 break;
1715 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1716 *params = mCaps.maxAtomicCounterBufferSize;
1717 break;
1718 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1719 *params = mCaps.maxCombinedAtomicCounterBuffers;
1720 break;
1721 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1722 *params = mCaps.maxCombinedAtomicCounters;
1723 break;
1724 case GL_MAX_IMAGE_UNITS:
1725 *params = mCaps.maxImageUnits;
1726 break;
1727 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1728 *params = mCaps.maxCombinedImageUniforms;
1729 break;
1730 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1731 *params = mCaps.maxShaderStorageBufferBindings;
1732 break;
1733 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1734 *params = mCaps.maxCombinedShaderStorageBlocks;
1735 break;
1736 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1737 *params = mCaps.shaderStorageBufferOffsetAlignment;
1738 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001739
1740 // GL_EXT_geometry_shader
1741 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1742 *params = mCaps.maxFramebufferLayers;
1743 break;
1744 case GL_LAYER_PROVOKING_VERTEX_EXT:
1745 *params = mCaps.layerProvokingVertex;
1746 break;
1747 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001748 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001749 break;
1750 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001751 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001752 break;
1753 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001754 *params =
1755 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001756 break;
1757 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1758 *params = mCaps.maxGeometryInputComponents;
1759 break;
1760 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1761 *params = mCaps.maxGeometryOutputComponents;
1762 break;
1763 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1764 *params = mCaps.maxGeometryOutputVertices;
1765 break;
1766 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1767 *params = mCaps.maxGeometryTotalOutputComponents;
1768 break;
1769 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1770 *params = mCaps.maxGeometryShaderInvocations;
1771 break;
1772 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001773 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001774 break;
1775 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001776 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001777 break;
1778 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001779 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001780 break;
1781 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001782 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001783 break;
1784 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001785 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001786 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001787 // GLES1 emulation: Caps queries
1788 case GL_MAX_TEXTURE_UNITS:
1789 *params = mCaps.maxMultitextureUnits;
1790 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001791 case GL_MAX_MODELVIEW_STACK_DEPTH:
1792 *params = mCaps.maxModelviewMatrixStackDepth;
1793 break;
1794 case GL_MAX_PROJECTION_STACK_DEPTH:
1795 *params = mCaps.maxProjectionMatrixStackDepth;
1796 break;
1797 case GL_MAX_TEXTURE_STACK_DEPTH:
1798 *params = mCaps.maxTextureMatrixStackDepth;
1799 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001800 case GL_MAX_LIGHTS:
1801 *params = mCaps.maxLights;
1802 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001803 case GL_MAX_CLIP_PLANES:
1804 *params = mCaps.maxClipPlanes;
1805 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001806 // GLES1 emulation: Vertex attribute queries
1807 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1808 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1809 case GL_COLOR_ARRAY_BUFFER_BINDING:
1810 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1811 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1812 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1813 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1814 break;
1815 case GL_VERTEX_ARRAY_STRIDE:
1816 case GL_NORMAL_ARRAY_STRIDE:
1817 case GL_COLOR_ARRAY_STRIDE:
1818 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1819 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1820 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1821 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1822 break;
1823 case GL_VERTEX_ARRAY_SIZE:
1824 case GL_COLOR_ARRAY_SIZE:
1825 case GL_TEXTURE_COORD_ARRAY_SIZE:
1826 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1827 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1828 break;
1829 case GL_VERTEX_ARRAY_TYPE:
1830 case GL_COLOR_ARRAY_TYPE:
1831 case GL_NORMAL_ARRAY_TYPE:
1832 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1833 case GL_TEXTURE_COORD_ARRAY_TYPE:
1834 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1835 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1836 break;
1837
jchen1082af6202018-06-22 10:59:52 +08001838 // GL_KHR_parallel_shader_compile
1839 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1840 *params = mGLState.getMaxShaderCompilerThreads();
1841 break;
1842
Jamie Madill231c7f52017-04-26 13:45:37 -04001843 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001844 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001845 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001846 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001847}
1848
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001849void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001850{
Shannon Woods53a94a82014-06-24 15:20:36 -04001851 // Queries about context capabilities and maximums are answered by Context.
1852 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001853 switch (pname)
1854 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001855 case GL_MAX_ELEMENT_INDEX:
1856 *params = mCaps.maxElementIndex;
1857 break;
1858 case GL_MAX_UNIFORM_BLOCK_SIZE:
1859 *params = mCaps.maxUniformBlockSize;
1860 break;
1861 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001862 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001863 break;
1864 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001865 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001866 break;
1867 case GL_MAX_SERVER_WAIT_TIMEOUT:
1868 *params = mCaps.maxServerWaitTimeout;
1869 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001870
Jamie Madill231c7f52017-04-26 13:45:37 -04001871 // GL_EXT_disjoint_timer_query
1872 case GL_TIMESTAMP_EXT:
1873 *params = mImplementation->getTimestamp();
1874 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001875
Jamie Madill231c7f52017-04-26 13:45:37 -04001876 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1877 *params = mCaps.maxShaderStorageBlockSize;
1878 break;
1879 default:
1880 UNREACHABLE();
1881 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001882 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001883}
1884
Geoff Lang70d0f492015-12-10 17:45:46 -05001885void Context::getPointerv(GLenum pname, void **params) const
1886{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001887 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001888}
1889
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001890void Context::getPointervRobustANGLERobust(GLenum pname,
1891 GLsizei bufSize,
1892 GLsizei *length,
1893 void **params)
1894{
1895 UNIMPLEMENTED();
1896}
1897
Martin Radev66fb8202016-07-28 11:45:20 +03001898void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001899{
Shannon Woods53a94a82014-06-24 15:20:36 -04001900 // Queries about context capabilities and maximums are answered by Context.
1901 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001902
1903 GLenum nativeType;
1904 unsigned int numParams;
1905 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1906 ASSERT(queryStatus);
1907
1908 if (nativeType == GL_INT)
1909 {
1910 switch (target)
1911 {
1912 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1913 ASSERT(index < 3u);
1914 *data = mCaps.maxComputeWorkGroupCount[index];
1915 break;
1916 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1917 ASSERT(index < 3u);
1918 *data = mCaps.maxComputeWorkGroupSize[index];
1919 break;
1920 default:
1921 mGLState.getIntegeri_v(target, index, data);
1922 }
1923 }
1924 else
1925 {
1926 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1927 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001928}
1929
Brandon Jones59770802018-04-02 13:18:42 -07001930void Context::getIntegeri_vRobust(GLenum target,
1931 GLuint index,
1932 GLsizei bufSize,
1933 GLsizei *length,
1934 GLint *data)
1935{
1936 getIntegeri_v(target, index, data);
1937}
1938
Martin Radev66fb8202016-07-28 11:45:20 +03001939void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001940{
Shannon Woods53a94a82014-06-24 15:20:36 -04001941 // Queries about context capabilities and maximums are answered by Context.
1942 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001943
1944 GLenum nativeType;
1945 unsigned int numParams;
1946 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1947 ASSERT(queryStatus);
1948
1949 if (nativeType == GL_INT_64_ANGLEX)
1950 {
1951 mGLState.getInteger64i_v(target, index, data);
1952 }
1953 else
1954 {
1955 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1956 }
1957}
1958
Brandon Jones59770802018-04-02 13:18:42 -07001959void Context::getInteger64i_vRobust(GLenum target,
1960 GLuint index,
1961 GLsizei bufSize,
1962 GLsizei *length,
1963 GLint64 *data)
1964{
1965 getInteger64i_v(target, index, data);
1966}
1967
Martin Radev66fb8202016-07-28 11:45:20 +03001968void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1969{
1970 // Queries about context capabilities and maximums are answered by Context.
1971 // Queries about current GL state values are answered by State.
1972
1973 GLenum nativeType;
1974 unsigned int numParams;
1975 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1976 ASSERT(queryStatus);
1977
1978 if (nativeType == GL_BOOL)
1979 {
1980 mGLState.getBooleani_v(target, index, data);
1981 }
1982 else
1983 {
1984 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1985 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001986}
1987
Brandon Jones59770802018-04-02 13:18:42 -07001988void Context::getBooleani_vRobust(GLenum target,
1989 GLuint index,
1990 GLsizei bufSize,
1991 GLsizei *length,
1992 GLboolean *data)
1993{
1994 getBooleani_v(target, index, data);
1995}
1996
Corentin Wallez336129f2017-10-17 15:55:40 -04001997void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001998{
1999 Buffer *buffer = mGLState.getTargetBuffer(target);
2000 QueryBufferParameteriv(buffer, pname, params);
2001}
2002
Brandon Jones59770802018-04-02 13:18:42 -07002003void Context::getBufferParameterivRobust(BufferBinding target,
2004 GLenum pname,
2005 GLsizei bufSize,
2006 GLsizei *length,
2007 GLint *params)
2008{
2009 getBufferParameteriv(target, pname, params);
2010}
2011
He Yunchao010e4db2017-03-03 14:22:06 +08002012void Context::getFramebufferAttachmentParameteriv(GLenum target,
2013 GLenum attachment,
2014 GLenum pname,
2015 GLint *params)
2016{
2017 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002018 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002019}
2020
Brandon Jones59770802018-04-02 13:18:42 -07002021void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2022 GLenum attachment,
2023 GLenum pname,
2024 GLsizei bufSize,
2025 GLsizei *length,
2026 GLint *params)
2027{
2028 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2029}
2030
He Yunchao010e4db2017-03-03 14:22:06 +08002031void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2032{
2033 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2034 QueryRenderbufferiv(this, renderbuffer, pname, params);
2035}
2036
Brandon Jones59770802018-04-02 13:18:42 -07002037void Context::getRenderbufferParameterivRobust(GLenum target,
2038 GLenum pname,
2039 GLsizei bufSize,
2040 GLsizei *length,
2041 GLint *params)
2042{
2043 getRenderbufferParameteriv(target, pname, params);
2044}
2045
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002046void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002047{
2048 Texture *texture = getTargetTexture(target);
2049 QueryTexParameterfv(texture, pname, params);
2050}
2051
Brandon Jones59770802018-04-02 13:18:42 -07002052void Context::getTexParameterfvRobust(TextureType target,
2053 GLenum pname,
2054 GLsizei bufSize,
2055 GLsizei *length,
2056 GLfloat *params)
2057{
2058 getTexParameterfv(target, pname, params);
2059}
2060
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002061void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002062{
2063 Texture *texture = getTargetTexture(target);
2064 QueryTexParameteriv(texture, pname, params);
2065}
Jiajia Qin5451d532017-11-16 17:16:34 +08002066
Brandon Jones59770802018-04-02 13:18:42 -07002067void Context::getTexParameterivRobust(TextureType target,
2068 GLenum pname,
2069 GLsizei bufSize,
2070 GLsizei *length,
2071 GLint *params)
2072{
2073 getTexParameteriv(target, pname, params);
2074}
2075
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002076void Context::getTexParameterIivRobust(TextureType target,
2077 GLenum pname,
2078 GLsizei bufSize,
2079 GLsizei *length,
2080 GLint *params)
2081{
2082 UNIMPLEMENTED();
2083}
2084
2085void Context::getTexParameterIuivRobust(TextureType target,
2086 GLenum pname,
2087 GLsizei bufSize,
2088 GLsizei *length,
2089 GLuint *params)
2090{
2091 UNIMPLEMENTED();
2092}
2093
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002094void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002095{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002096 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002097 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002098}
2099
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002100void Context::getTexLevelParameterivRobust(TextureTarget target,
2101 GLint level,
2102 GLenum pname,
2103 GLsizei bufSize,
2104 GLsizei *length,
2105 GLint *params)
2106{
2107 UNIMPLEMENTED();
2108}
2109
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002110void Context::getTexLevelParameterfv(TextureTarget target,
2111 GLint level,
2112 GLenum pname,
2113 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002114{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002115 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002116 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002117}
2118
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002119void Context::getTexLevelParameterfvRobust(TextureTarget target,
2120 GLint level,
2121 GLenum pname,
2122 GLsizei bufSize,
2123 GLsizei *length,
2124 GLfloat *params)
2125{
2126 UNIMPLEMENTED();
2127}
2128
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002129void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002130{
2131 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002132 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002133 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002134}
2135
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002136void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002137{
2138 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002139 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002140 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002141}
2142
Brandon Jones59770802018-04-02 13:18:42 -07002143void Context::texParameterfvRobust(TextureType target,
2144 GLenum pname,
2145 GLsizei bufSize,
2146 const GLfloat *params)
2147{
2148 texParameterfv(target, pname, params);
2149}
2150
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002151void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002152{
2153 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002154 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002155 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002156}
2157
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002158void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002159{
2160 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002161 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002162 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002163}
2164
Brandon Jones59770802018-04-02 13:18:42 -07002165void Context::texParameterivRobust(TextureType target,
2166 GLenum pname,
2167 GLsizei bufSize,
2168 const GLint *params)
2169{
2170 texParameteriv(target, pname, params);
2171}
2172
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002173void Context::texParameterIivRobust(TextureType target,
2174 GLenum pname,
2175 GLsizei bufSize,
2176 const GLint *params)
2177{
2178 UNIMPLEMENTED();
2179}
2180
2181void Context::texParameterIuivRobust(TextureType target,
2182 GLenum pname,
2183 GLsizei bufSize,
2184 const GLuint *params)
2185{
2186 UNIMPLEMENTED();
2187}
2188
Jamie Madill493f9572018-05-24 19:52:15 -04002189void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002190{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002191 // No-op if count draws no primitives for given mode
2192 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002193 {
2194 return;
2195 }
2196
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002197 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002198 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002199 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002200}
2201
Jamie Madill493f9572018-05-24 19:52:15 -04002202void Context::drawArraysInstanced(PrimitiveMode mode,
2203 GLint first,
2204 GLsizei count,
2205 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002206{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002207 // No-op if count draws no primitives for given mode
2208 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002209 {
2210 return;
2211 }
2212
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002213 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002214 ANGLE_CONTEXT_TRY(
2215 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002216 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2217 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002218}
2219
Jamie Madill493f9572018-05-24 19:52:15 -04002220void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002221{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002222 // No-op if count draws no primitives for given mode
2223 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002224 {
2225 return;
2226 }
2227
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002228 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002229 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002230}
2231
Jamie Madill493f9572018-05-24 19:52:15 -04002232void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002233 GLsizei count,
2234 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002235 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002236 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002237{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002238 // No-op if count draws no primitives for given mode
2239 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002240 {
2241 return;
2242 }
2243
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002244 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002245 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002246 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002247}
2248
Jamie Madill493f9572018-05-24 19:52:15 -04002249void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002250 GLuint start,
2251 GLuint end,
2252 GLsizei count,
2253 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002254 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002255{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002256 // No-op if count draws no primitives for given mode
2257 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002258 {
2259 return;
2260 }
2261
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002262 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002263 ANGLE_CONTEXT_TRY(
2264 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002265}
2266
Jamie Madill493f9572018-05-24 19:52:15 -04002267void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002268{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002269 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002270 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002271}
2272
Jamie Madill493f9572018-05-24 19:52:15 -04002273void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002274{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002275 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002276 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002277}
2278
Jamie Madill675fe712016-12-19 13:07:54 -05002279void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002280{
Jamie Madillafa02a22017-11-23 12:57:38 -05002281 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002282}
2283
Jamie Madill675fe712016-12-19 13:07:54 -05002284void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002285{
Jamie Madillafa02a22017-11-23 12:57:38 -05002286 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002287}
2288
Austin Kinross6ee1e782015-05-29 17:05:37 -07002289void Context::insertEventMarker(GLsizei length, const char *marker)
2290{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002291 ASSERT(mImplementation);
2292 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002293}
2294
2295void Context::pushGroupMarker(GLsizei length, const char *marker)
2296{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002297 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002298
2299 if (marker == nullptr)
2300 {
2301 // From the EXT_debug_marker spec,
2302 // "If <marker> is null then an empty string is pushed on the stack."
2303 mImplementation->pushGroupMarker(length, "");
2304 }
2305 else
2306 {
2307 mImplementation->pushGroupMarker(length, marker);
2308 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002309}
2310
2311void Context::popGroupMarker()
2312{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002313 ASSERT(mImplementation);
2314 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002315}
2316
Geoff Langd8605522016-04-13 10:19:12 -04002317void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2318{
2319 Program *programObject = getProgram(program);
2320 ASSERT(programObject);
2321
2322 programObject->bindUniformLocation(location, name);
2323}
2324
Brandon Jones59770802018-04-02 13:18:42 -07002325void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002326{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002327 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002328}
2329
Brandon Jones59770802018-04-02 13:18:42 -07002330void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002331{
2332 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2333}
2334
Brandon Jones59770802018-04-02 13:18:42 -07002335void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002336{
2337 GLfloat I[16];
2338 angle::Matrix<GLfloat>::setToIdentity(I);
2339
2340 mGLState.loadPathRenderingMatrix(matrixMode, I);
2341}
2342
2343void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2344{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002345 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002346 if (!pathObj)
2347 return;
2348
Geoff Lang9bf86f02018-07-26 11:46:34 -04002349 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002350
2351 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2352}
2353
2354void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2355{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002356 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002357 if (!pathObj)
2358 return;
2359
Geoff Lang9bf86f02018-07-26 11:46:34 -04002360 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002361
2362 mImplementation->stencilStrokePath(pathObj, reference, mask);
2363}
2364
2365void Context::coverFillPath(GLuint path, GLenum coverMode)
2366{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002367 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002368 if (!pathObj)
2369 return;
2370
Geoff Lang9bf86f02018-07-26 11:46:34 -04002371 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002372
2373 mImplementation->coverFillPath(pathObj, coverMode);
2374}
2375
2376void Context::coverStrokePath(GLuint path, GLenum coverMode)
2377{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002378 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002379 if (!pathObj)
2380 return;
2381
Geoff Lang9bf86f02018-07-26 11:46:34 -04002382 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002383
2384 mImplementation->coverStrokePath(pathObj, coverMode);
2385}
2386
2387void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2388{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002389 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002390 if (!pathObj)
2391 return;
2392
Geoff Lang9bf86f02018-07-26 11:46:34 -04002393 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002394
2395 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2396}
2397
2398void Context::stencilThenCoverStrokePath(GLuint path,
2399 GLint reference,
2400 GLuint mask,
2401 GLenum coverMode)
2402{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002403 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002404 if (!pathObj)
2405 return;
2406
Geoff Lang9bf86f02018-07-26 11:46:34 -04002407 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002408
2409 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2410}
2411
Sami Väisänend59ca052016-06-21 16:10:00 +03002412void Context::coverFillPathInstanced(GLsizei numPaths,
2413 GLenum pathNameType,
2414 const void *paths,
2415 GLuint pathBase,
2416 GLenum coverMode,
2417 GLenum transformType,
2418 const GLfloat *transformValues)
2419{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002420 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002421
Geoff Lang9bf86f02018-07-26 11:46:34 -04002422 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002423
2424 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2425}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002426
Sami Väisänend59ca052016-06-21 16:10:00 +03002427void Context::coverStrokePathInstanced(GLsizei numPaths,
2428 GLenum pathNameType,
2429 const void *paths,
2430 GLuint pathBase,
2431 GLenum coverMode,
2432 GLenum transformType,
2433 const GLfloat *transformValues)
2434{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002435 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002436
2437 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002438 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002439
2440 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2441 transformValues);
2442}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002443
Sami Väisänend59ca052016-06-21 16:10:00 +03002444void Context::stencilFillPathInstanced(GLsizei numPaths,
2445 GLenum pathNameType,
2446 const void *paths,
2447 GLuint pathBase,
2448 GLenum fillMode,
2449 GLuint mask,
2450 GLenum transformType,
2451 const GLfloat *transformValues)
2452{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002453 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002454
2455 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002456 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002457
2458 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2459 transformValues);
2460}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002461
Sami Väisänend59ca052016-06-21 16:10:00 +03002462void Context::stencilStrokePathInstanced(GLsizei numPaths,
2463 GLenum pathNameType,
2464 const void *paths,
2465 GLuint pathBase,
2466 GLint reference,
2467 GLuint mask,
2468 GLenum transformType,
2469 const GLfloat *transformValues)
2470{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002471 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002472
Geoff Lang9bf86f02018-07-26 11:46:34 -04002473 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002474
2475 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2476 transformValues);
2477}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002478
Sami Väisänend59ca052016-06-21 16:10:00 +03002479void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2480 GLenum pathNameType,
2481 const void *paths,
2482 GLuint pathBase,
2483 GLenum fillMode,
2484 GLuint mask,
2485 GLenum coverMode,
2486 GLenum transformType,
2487 const GLfloat *transformValues)
2488{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002489 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002490
Geoff Lang9bf86f02018-07-26 11:46:34 -04002491 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002492
2493 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2494 transformType, transformValues);
2495}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002496
Sami Väisänend59ca052016-06-21 16:10:00 +03002497void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2498 GLenum pathNameType,
2499 const void *paths,
2500 GLuint pathBase,
2501 GLint reference,
2502 GLuint mask,
2503 GLenum coverMode,
2504 GLenum transformType,
2505 const GLfloat *transformValues)
2506{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002507 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002508
Geoff Lang9bf86f02018-07-26 11:46:34 -04002509 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002510
2511 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2512 transformType, transformValues);
2513}
2514
Sami Väisänen46eaa942016-06-29 10:26:37 +03002515void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2516{
2517 auto *programObject = getProgram(program);
2518
2519 programObject->bindFragmentInputLocation(location, name);
2520}
2521
2522void Context::programPathFragmentInputGen(GLuint program,
2523 GLint location,
2524 GLenum genMode,
2525 GLint components,
2526 const GLfloat *coeffs)
2527{
2528 auto *programObject = getProgram(program);
2529
jchen103fd614d2018-08-13 12:21:58 +08002530 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002531}
2532
jchen1015015f72017-03-16 13:54:21 +08002533GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2534{
jchen10fd7c3b52017-03-21 15:36:03 +08002535 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002536 return QueryProgramResourceIndex(programObject, programInterface, name);
2537}
2538
jchen10fd7c3b52017-03-21 15:36:03 +08002539void Context::getProgramResourceName(GLuint program,
2540 GLenum programInterface,
2541 GLuint index,
2542 GLsizei bufSize,
2543 GLsizei *length,
2544 GLchar *name)
2545{
2546 const auto *programObject = getProgram(program);
2547 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2548}
2549
jchen10191381f2017-04-11 13:59:04 +08002550GLint Context::getProgramResourceLocation(GLuint program,
2551 GLenum programInterface,
2552 const GLchar *name)
2553{
2554 const auto *programObject = getProgram(program);
2555 return QueryProgramResourceLocation(programObject, programInterface, name);
2556}
2557
jchen10880683b2017-04-12 16:21:55 +08002558void Context::getProgramResourceiv(GLuint program,
2559 GLenum programInterface,
2560 GLuint index,
2561 GLsizei propCount,
2562 const GLenum *props,
2563 GLsizei bufSize,
2564 GLsizei *length,
2565 GLint *params)
2566{
2567 const auto *programObject = getProgram(program);
2568 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2569 length, params);
2570}
2571
jchen10d9cd7b72017-08-30 15:04:25 +08002572void Context::getProgramInterfaceiv(GLuint program,
2573 GLenum programInterface,
2574 GLenum pname,
2575 GLint *params)
2576{
2577 const auto *programObject = getProgram(program);
2578 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2579}
2580
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002581void Context::getProgramInterfaceivRobust(GLuint program,
2582 GLenum programInterface,
2583 GLenum pname,
2584 GLsizei bufSize,
2585 GLsizei *length,
2586 GLint *params)
2587{
2588 UNIMPLEMENTED();
2589}
2590
Jamie Madill306b6c12018-07-27 08:12:49 -04002591void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002592{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002593 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002594}
2595
2596// Get one of the recorded errors and clear its flag, if any.
2597// [OpenGL ES 2.0.24] section 2.5 page 13.
2598GLenum Context::getError()
2599{
Geoff Langda5777c2014-07-11 09:52:58 -04002600 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002601 {
Geoff Langda5777c2014-07-11 09:52:58 -04002602 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002603 }
Geoff Langda5777c2014-07-11 09:52:58 -04002604 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002605 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002606 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002607 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002608}
2609
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002610// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002611void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002612{
2613 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002614 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002615 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002616 mContextLostForced = true;
2617 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002618 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002619}
2620
Jamie Madill427064d2018-04-13 16:20:34 -04002621bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002622{
2623 return mContextLost;
2624}
2625
Jamie Madillfa920eb2018-01-04 11:45:50 -05002626GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002627{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002628 // Even if the application doesn't want to know about resets, we want to know
2629 // as it will allow us to skip all the calls.
2630 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002631 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002632 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002633 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002634 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002635 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002636
2637 // EXT_robustness, section 2.6: If the reset notification behavior is
2638 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2639 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2640 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002641 }
2642
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002643 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2644 // status should be returned at least once, and GL_NO_ERROR should be returned
2645 // once the device has finished resetting.
2646 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002647 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002648 ASSERT(mResetStatus == GL_NO_ERROR);
2649 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002650
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002651 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002652 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002653 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002654 }
2655 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002656 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002657 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002658 // If markContextLost was used to mark the context lost then
2659 // assume that is not recoverable, and continue to report the
2660 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002661 mResetStatus = mImplementation->getResetStatus();
2662 }
Jamie Madill893ab082014-05-16 16:56:10 -04002663
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002664 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002665}
2666
2667bool Context::isResetNotificationEnabled()
2668{
2669 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2670}
2671
Corentin Walleze3b10e82015-05-20 11:06:25 -04002672const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002673{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002674 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002675}
2676
2677EGLenum Context::getClientType() const
2678{
2679 return mClientType;
2680}
2681
2682EGLenum Context::getRenderBuffer() const
2683{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002684 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2685 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002686 {
2687 return EGL_NONE;
2688 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002689
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002690 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002691 ASSERT(backAttachment != nullptr);
2692 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002693}
2694
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002695VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002696{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002697 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002698 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2699 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002700 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002701 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2702 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002703
Jamie Madill96a483b2017-06-27 16:49:21 -04002704 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002705 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002706
2707 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002708}
2709
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002710TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002711{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002712 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002713 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2714 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002715 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002716 transformFeedback =
2717 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002718 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002719 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002720 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002721
2722 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002723}
2724
2725bool Context::isVertexArrayGenerated(GLuint vertexArray)
2726{
Jamie Madill96a483b2017-06-27 16:49:21 -04002727 ASSERT(mVertexArrayMap.contains(0));
2728 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002729}
2730
2731bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2732{
Jamie Madill96a483b2017-06-27 16:49:21 -04002733 ASSERT(mTransformFeedbackMap.contains(0));
2734 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002735}
2736
Shannon Woods53a94a82014-06-24 15:20:36 -04002737void Context::detachTexture(GLuint texture)
2738{
2739 // Simple pass-through to State's detachTexture method, as textures do not require
2740 // allocation map management either here or in the resource manager at detach time.
2741 // Zero textures are held by the Context, and we don't attempt to request them from
2742 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002743 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002744}
2745
James Darpinian4d9d4832018-03-13 12:43:28 -07002746void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002747{
Yuly Novikov5807a532015-12-03 13:01:22 -05002748 // Simple pass-through to State's detachBuffer method, since
2749 // only buffer attachments to container objects that are bound to the current context
2750 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002751
Yuly Novikov5807a532015-12-03 13:01:22 -05002752 // [OpenGL ES 3.2] section 5.1.2 page 45:
2753 // Attachments to unbound container objects, such as
2754 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2755 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002756 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002757}
2758
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002759void Context::detachFramebuffer(GLuint framebuffer)
2760{
Shannon Woods53a94a82014-06-24 15:20:36 -04002761 // Framebuffer detachment is handled by Context, because 0 is a valid
2762 // Framebuffer object, and a pointer to it must be passed from Context
2763 // to State at binding time.
2764
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002765 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002766 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2767 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2768 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002769
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002770 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002771 {
2772 bindReadFramebuffer(0);
2773 }
2774
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002775 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002776 {
2777 bindDrawFramebuffer(0);
2778 }
2779}
2780
2781void Context::detachRenderbuffer(GLuint renderbuffer)
2782{
Jamie Madilla02315b2017-02-23 14:14:47 -05002783 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002784}
2785
Jamie Madill57a89722013-07-02 11:57:03 -04002786void Context::detachVertexArray(GLuint vertexArray)
2787{
Jamie Madill77a72f62015-04-14 11:18:32 -04002788 // Vertex array detachment is handled by Context, because 0 is a valid
2789 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002790 // binding time.
2791
Jamie Madill57a89722013-07-02 11:57:03 -04002792 // [OpenGL ES 3.0.2] section 2.10 page 43:
2793 // If a vertex array object that is currently bound is deleted, the binding
2794 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002795 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002796 {
2797 bindVertexArray(0);
2798 }
2799}
2800
Geoff Langc8058452014-02-03 12:04:11 -05002801void Context::detachTransformFeedback(GLuint transformFeedback)
2802{
Corentin Walleza2257da2016-04-19 16:43:12 -04002803 // Transform feedback detachment is handled by Context, because 0 is a valid
2804 // transform feedback, and a pointer to it must be passed from Context to State at
2805 // binding time.
2806
2807 // The OpenGL specification doesn't mention what should happen when the currently bound
2808 // transform feedback object is deleted. Since it is a container object, we treat it like
2809 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002810 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002811 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002812 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002813 }
Geoff Langc8058452014-02-03 12:04:11 -05002814}
2815
Jamie Madilldc356042013-07-19 16:36:57 -04002816void Context::detachSampler(GLuint sampler)
2817{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002818 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002819}
2820
Yunchao Hea336b902017-08-02 16:05:21 +08002821void Context::detachProgramPipeline(GLuint pipeline)
2822{
2823 mGLState.detachProgramPipeline(this, pipeline);
2824}
2825
Jamie Madill3ef140a2017-08-26 23:11:21 -04002826void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002827{
Shaodde78e82017-05-22 14:13:27 +08002828 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002829 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002830}
2831
Jamie Madille29d1672013-07-19 16:36:57 -04002832void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2833{
Geoff Langc1984ed2016-10-07 12:41:00 -04002834 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002835 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002836 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002837 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002838}
Jamie Madille29d1672013-07-19 16:36:57 -04002839
Geoff Langc1984ed2016-10-07 12:41:00 -04002840void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2841{
2842 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002843 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002844 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002845 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002846}
2847
Brandon Jones59770802018-04-02 13:18:42 -07002848void Context::samplerParameterivRobust(GLuint sampler,
2849 GLenum pname,
2850 GLsizei bufSize,
2851 const GLint *param)
2852{
2853 samplerParameteriv(sampler, pname, param);
2854}
2855
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002856void Context::samplerParameterIivRobust(GLuint sampler,
2857 GLenum pname,
2858 GLsizei bufSize,
2859 const GLint *param)
2860{
2861 UNIMPLEMENTED();
2862}
2863
2864void Context::samplerParameterIuivRobust(GLuint sampler,
2865 GLenum pname,
2866 GLsizei bufSize,
2867 const GLuint *param)
2868{
2869 UNIMPLEMENTED();
2870}
2871
Jamie Madille29d1672013-07-19 16:36:57 -04002872void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2873{
Geoff Langc1984ed2016-10-07 12:41:00 -04002874 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002875 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002876 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002877 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002878}
2879
Geoff Langc1984ed2016-10-07 12:41:00 -04002880void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002881{
Geoff Langc1984ed2016-10-07 12:41:00 -04002882 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002883 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002884 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002885 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002886}
2887
Brandon Jones59770802018-04-02 13:18:42 -07002888void Context::samplerParameterfvRobust(GLuint sampler,
2889 GLenum pname,
2890 GLsizei bufSize,
2891 const GLfloat *param)
2892{
2893 samplerParameterfv(sampler, pname, param);
2894}
2895
Geoff Langc1984ed2016-10-07 12:41:00 -04002896void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002897{
Geoff Langc1984ed2016-10-07 12:41:00 -04002898 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002899 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002900 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002901 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002902}
Jamie Madill9675b802013-07-19 16:36:59 -04002903
Brandon Jones59770802018-04-02 13:18:42 -07002904void Context::getSamplerParameterivRobust(GLuint sampler,
2905 GLenum pname,
2906 GLsizei bufSize,
2907 GLsizei *length,
2908 GLint *params)
2909{
2910 getSamplerParameteriv(sampler, pname, params);
2911}
2912
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002913void Context::getSamplerParameterIivRobust(GLuint sampler,
2914 GLenum pname,
2915 GLsizei bufSize,
2916 GLsizei *length,
2917 GLint *params)
2918{
2919 UNIMPLEMENTED();
2920}
2921
2922void Context::getSamplerParameterIuivRobust(GLuint sampler,
2923 GLenum pname,
2924 GLsizei bufSize,
2925 GLsizei *length,
2926 GLuint *params)
2927{
2928 UNIMPLEMENTED();
2929}
2930
Geoff Langc1984ed2016-10-07 12:41:00 -04002931void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2932{
2933 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002934 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002935 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002936 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002937}
2938
Brandon Jones59770802018-04-02 13:18:42 -07002939void Context::getSamplerParameterfvRobust(GLuint sampler,
2940 GLenum pname,
2941 GLsizei bufSize,
2942 GLsizei *length,
2943 GLfloat *params)
2944{
2945 getSamplerParameterfv(sampler, pname, params);
2946}
2947
Olli Etuahof0fee072016-03-30 15:11:58 +03002948void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2949{
2950 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002951 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002952}
2953
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002954void Context::initRendererString()
2955{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002956 std::ostringstream rendererString;
2957 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002958 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002959 rendererString << ")";
2960
Geoff Langcec35902014-04-16 10:52:36 -04002961 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002962}
2963
Geoff Langc339c4e2016-11-29 10:37:36 -05002964void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002965{
Geoff Langc339c4e2016-11-29 10:37:36 -05002966 const Version &clientVersion = getClientVersion();
2967
2968 std::ostringstream versionString;
2969 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2970 << ANGLE_VERSION_STRING << ")";
2971 mVersionString = MakeStaticString(versionString.str());
2972
2973 std::ostringstream shadingLanguageVersionString;
2974 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2975 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2976 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2977 << ")";
2978 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002979}
2980
Geoff Langcec35902014-04-16 10:52:36 -04002981void Context::initExtensionStrings()
2982{
Geoff Langc339c4e2016-11-29 10:37:36 -05002983 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2984 std::ostringstream combinedStringStream;
2985 std::copy(strings.begin(), strings.end(),
2986 std::ostream_iterator<const char *>(combinedStringStream, " "));
2987 return MakeStaticString(combinedStringStream.str());
2988 };
2989
2990 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002991 for (const auto &extensionString : mExtensions.getStrings())
2992 {
2993 mExtensionStrings.push_back(MakeStaticString(extensionString));
2994 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002995 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002996
Geoff Langc339c4e2016-11-29 10:37:36 -05002997 mRequestableExtensionStrings.clear();
2998 for (const auto &extensionInfo : GetExtensionInfoMap())
2999 {
3000 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003001 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003002 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003003 {
3004 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3005 }
3006 }
3007 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003008}
3009
Geoff Langc339c4e2016-11-29 10:37:36 -05003010const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003011{
Geoff Langc339c4e2016-11-29 10:37:36 -05003012 switch (name)
3013 {
3014 case GL_VENDOR:
3015 return reinterpret_cast<const GLubyte *>("Google Inc.");
3016
3017 case GL_RENDERER:
3018 return reinterpret_cast<const GLubyte *>(mRendererString);
3019
3020 case GL_VERSION:
3021 return reinterpret_cast<const GLubyte *>(mVersionString);
3022
3023 case GL_SHADING_LANGUAGE_VERSION:
3024 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3025
3026 case GL_EXTENSIONS:
3027 return reinterpret_cast<const GLubyte *>(mExtensionString);
3028
3029 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3030 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3031
3032 default:
3033 UNREACHABLE();
3034 return nullptr;
3035 }
Geoff Langcec35902014-04-16 10:52:36 -04003036}
3037
Geoff Langc339c4e2016-11-29 10:37:36 -05003038const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003039{
Geoff Langc339c4e2016-11-29 10:37:36 -05003040 switch (name)
3041 {
3042 case GL_EXTENSIONS:
3043 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3044
3045 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3046 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3047
3048 default:
3049 UNREACHABLE();
3050 return nullptr;
3051 }
Geoff Langcec35902014-04-16 10:52:36 -04003052}
3053
3054size_t Context::getExtensionStringCount() const
3055{
3056 return mExtensionStrings.size();
3057}
3058
Geoff Lang111a99e2017-10-17 10:58:41 -04003059bool Context::isExtensionRequestable(const char *name)
3060{
3061 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3062 auto extension = extensionInfos.find(name);
3063
Geoff Lang111a99e2017-10-17 10:58:41 -04003064 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003065 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003066}
3067
Geoff Langc339c4e2016-11-29 10:37:36 -05003068void Context::requestExtension(const char *name)
3069{
3070 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3071 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3072 const auto &extension = extensionInfos.at(name);
3073 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003074 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003075
3076 if (mExtensions.*(extension.ExtensionsMember))
3077 {
3078 // Extension already enabled
3079 return;
3080 }
3081
3082 mExtensions.*(extension.ExtensionsMember) = true;
3083 updateCaps();
3084 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003085
Jamie Madill2f348d22017-06-05 10:50:59 -04003086 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3087 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003088
Jamie Madill81c2e252017-09-09 23:32:46 -04003089 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3090 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003091 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003092 for (auto &zeroTexture : mZeroTextures)
3093 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003094 if (zeroTexture.get() != nullptr)
3095 {
3096 zeroTexture->signalDirty(this, InitState::Initialized);
3097 }
Geoff Lang9aded172017-04-05 11:07:56 -04003098 }
3099
Jamie Madillb983a4b2018-08-01 11:34:51 -04003100 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003101}
3102
3103size_t Context::getRequestableExtensionStringCount() const
3104{
3105 return mRequestableExtensionStrings.size();
3106}
3107
Jamie Madill493f9572018-05-24 19:52:15 -04003108void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003109{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003110 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003111 ASSERT(transformFeedback != nullptr);
3112 ASSERT(!transformFeedback->isPaused());
3113
Jamie Madill6c1f6712017-02-14 19:08:04 -05003114 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Jamie Madilld84b6732018-09-06 15:54:35 -04003115 mStateCache.onTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003116}
3117
3118bool Context::hasActiveTransformFeedback(GLuint program) const
3119{
3120 for (auto pair : mTransformFeedbackMap)
3121 {
3122 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3123 {
3124 return true;
3125 }
3126 }
3127 return false;
3128}
3129
Geoff Lang33f11fb2018-05-07 13:42:47 -04003130Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003131{
3132 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3133
jchen1082af6202018-06-22 10:59:52 +08003134 // Explicitly enable GL_KHR_parallel_shader_compile
3135 supportedExtensions.parallelShaderCompile = true;
3136
Geoff Langb0f917f2017-12-05 13:41:54 -05003137 if (getClientVersion() < ES_2_0)
3138 {
3139 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003140 supportedExtensions.pointSizeArray = true;
3141 supportedExtensions.textureCubeMap = true;
3142 supportedExtensions.pointSprite = true;
3143 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003144 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003145 }
3146
3147 if (getClientVersion() < ES_3_0)
3148 {
3149 // Disable ES3+ extensions
3150 supportedExtensions.colorBufferFloat = false;
3151 supportedExtensions.eglImageExternalEssl3 = false;
3152 supportedExtensions.textureNorm16 = false;
3153 supportedExtensions.multiview = false;
3154 supportedExtensions.maxViews = 1u;
3155 }
3156
3157 if (getClientVersion() < ES_3_1)
3158 {
3159 // Disable ES3.1+ extensions
3160 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003161
3162 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3163 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003164 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003165 }
3166
3167 if (getClientVersion() > ES_2_0)
3168 {
3169 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3170 // supportedExtensions.sRGB = false;
3171 }
3172
3173 // Some extensions are always available because they are implemented in the GL layer.
3174 supportedExtensions.bindUniformLocation = true;
3175 supportedExtensions.vertexArrayObject = true;
3176 supportedExtensions.bindGeneratesResource = true;
3177 supportedExtensions.clientArrays = true;
3178 supportedExtensions.requestExtension = true;
3179
3180 // Enable the no error extension if the context was created with the flag.
3181 supportedExtensions.noError = mSkipValidation;
3182
3183 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003184 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003185
3186 // Explicitly enable GL_KHR_debug
3187 supportedExtensions.debug = true;
3188 supportedExtensions.maxDebugMessageLength = 1024;
3189 supportedExtensions.maxDebugLoggedMessages = 1024;
3190 supportedExtensions.maxDebugGroupStackDepth = 1024;
3191 supportedExtensions.maxLabelLength = 1024;
3192
3193 // Explicitly enable GL_ANGLE_robust_client_memory
3194 supportedExtensions.robustClientMemory = true;
3195
3196 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003197 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003198
3199 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3200 // supports it.
3201 supportedExtensions.robustBufferAccessBehavior =
3202 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3203
3204 // Enable the cache control query unconditionally.
3205 supportedExtensions.programCacheControl = true;
3206
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003207 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003208 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003209 {
3210 // GL_ANGLE_explicit_context_gles1
3211 supportedExtensions.explicitContextGles1 = true;
3212 // GL_ANGLE_explicit_context
3213 supportedExtensions.explicitContext = true;
3214 }
3215
Geoff Langb0f917f2017-12-05 13:41:54 -05003216 return supportedExtensions;
3217}
3218
Geoff Lang33f11fb2018-05-07 13:42:47 -04003219void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003220{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003221 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003222
Geoff Lang33f11fb2018-05-07 13:42:47 -04003223 mSupportedExtensions = generateSupportedExtensions();
3224 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003225
3226 mLimitations = mImplementation->getNativeLimitations();
3227
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003228 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3229 if (getClientVersion() < Version(2, 0))
3230 {
3231 mCaps.maxMultitextureUnits = 4;
3232 mCaps.maxClipPlanes = 6;
3233 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003234 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3235 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3236 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003237 mCaps.minSmoothPointSize = 1.0f;
3238 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003239 mCaps.minSmoothLineWidth = 1.0f;
3240 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003241 }
3242
Luc Ferronad2ae932018-06-11 15:31:17 -04003243 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003244 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003245
Luc Ferronad2ae932018-06-11 15:31:17 -04003246 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3247
Jamie Madill0f80ed82017-09-19 00:24:56 -04003248 if (getClientVersion() < ES_3_1)
3249 {
3250 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3251 }
3252 else
3253 {
3254 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3255 }
Geoff Lang301d1612014-07-09 10:34:37 -04003256
Jiawei Shao54aafe52018-04-27 14:54:57 +08003257 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3258 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003259 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3260
Jamie Madill0f80ed82017-09-19 00:24:56 -04003261 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3262 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3263
3264 // Limit textures as well, so we can use fast bitsets with texture bindings.
3265 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003266 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3267 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3268 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3269 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003270
Jiawei Shaodb342272017-09-27 10:21:45 +08003271 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3272
Geoff Langc287ea62016-09-16 14:46:51 -04003273 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003274 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003275 for (const auto &extensionInfo : GetExtensionInfoMap())
3276 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003277 // If the user has requested that extensions start disabled and they are requestable,
3278 // disable them.
3279 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003280 {
3281 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3282 }
3283 }
3284
3285 // Generate texture caps
3286 updateCaps();
3287}
3288
3289void Context::updateCaps()
3290{
Geoff Lang900013c2014-07-07 11:32:19 -04003291 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003292 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003293
Jamie Madill7b62cf92017-11-02 15:20:49 -04003294 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003295 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003296 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003297 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003298
Geoff Lang0d8b7242015-09-09 14:56:53 -04003299 // Update the format caps based on the client version and extensions.
3300 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3301 // ES3.
3302 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003303 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003304 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003305 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003306 formatCaps.textureAttachment =
3307 formatCaps.textureAttachment &&
3308 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3309 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3310 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003311
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003312 // OpenGL ES does not support multisampling with non-rendererable formats
3313 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003314 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003315 (getClientVersion() < ES_3_1 &&
3316 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003317 {
Geoff Langd87878e2014-09-19 15:42:59 -04003318 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003319 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003320 else
3321 {
3322 // We may have limited the max samples for some required renderbuffer formats due to
3323 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3324 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3325
3326 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3327 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3328 // exception of signed and unsigned integer formats."
3329 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3330 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3331 {
3332 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3333 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3334 }
3335
3336 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3337 if (getClientVersion() >= ES_3_1)
3338 {
3339 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3340 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3341 // the exception that the signed and unsigned integer formats are required only to
3342 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3343 // multisamples, which must be at least one."
3344 if (formatInfo.componentType == GL_INT ||
3345 formatInfo.componentType == GL_UNSIGNED_INT)
3346 {
3347 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3348 }
3349
3350 // GLES 3.1 section 19.3.1.
3351 if (formatCaps.texturable)
3352 {
3353 if (formatInfo.depthBits > 0)
3354 {
3355 mCaps.maxDepthTextureSamples =
3356 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3357 }
3358 else if (formatInfo.redBits > 0)
3359 {
3360 mCaps.maxColorTextureSamples =
3361 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3362 }
3363 }
3364 }
3365 }
Geoff Langd87878e2014-09-19 15:42:59 -04003366
3367 if (formatCaps.texturable && formatInfo.compressed)
3368 {
Geoff Langca271392017-04-05 12:30:00 -04003369 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003370 }
3371
Geoff Langca271392017-04-05 12:30:00 -04003372 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003373 }
Jamie Madill32447362017-06-28 14:53:52 -04003374
3375 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003376 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003377 {
3378 mMemoryProgramCache = nullptr;
3379 }
Corentin Walleze4477002017-12-01 14:39:58 -05003380
3381 // Compute which buffer types are allowed
3382 mValidBufferBindings.reset();
3383 mValidBufferBindings.set(BufferBinding::ElementArray);
3384 mValidBufferBindings.set(BufferBinding::Array);
3385
3386 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3387 {
3388 mValidBufferBindings.set(BufferBinding::PixelPack);
3389 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3390 }
3391
3392 if (getClientVersion() >= ES_3_0)
3393 {
3394 mValidBufferBindings.set(BufferBinding::CopyRead);
3395 mValidBufferBindings.set(BufferBinding::CopyWrite);
3396 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3397 mValidBufferBindings.set(BufferBinding::Uniform);
3398 }
3399
3400 if (getClientVersion() >= ES_3_1)
3401 {
3402 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3403 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3404 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3405 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3406 }
jchen107ae70d82018-07-06 13:47:01 +08003407
3408 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Geoff Lang493daf52014-07-03 13:38:44 -04003409}
3410
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003411void Context::initWorkarounds()
3412{
Jamie Madill761b02c2017-06-23 16:27:06 -04003413 // Apply back-end workarounds.
3414 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3415
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003416 // Lose the context upon out of memory error if the application is
3417 // expecting to watch for those events.
3418 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3419}
3420
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003421// Return true if the draw is a no-op, else return false.
3422// A no-op draw occurs if the count of vertices is less than the minimum required to
3423// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3424bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3425{
3426 return count < kMinimumPrimitiveCounts[mode];
3427}
3428
3429bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3430{
3431 return (instanceCount == 0) || noopDraw(mode, count);
3432}
3433
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003434Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003435{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003436 if (mGLES1Renderer)
3437 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003438 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003439 }
3440
Geoff Lang9bf86f02018-07-26 11:46:34 -04003441 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003442
3443 if (isRobustResourceInitEnabled())
3444 {
3445 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3446 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3447 }
3448
Geoff Langa8cb2872018-03-09 16:09:40 -05003449 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003450 return NoError();
3451}
3452
3453Error Context::prepareForClear(GLbitfield mask)
3454{
Geoff Langa8cb2872018-03-09 16:09:40 -05003455 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003456 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003457 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003458 return NoError();
3459}
3460
3461Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3462{
Geoff Langa8cb2872018-03-09 16:09:40 -05003463 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003464 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3465 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003466 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003467 return NoError();
3468}
3469
Geoff Langa8cb2872018-03-09 16:09:40 -05003470Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003471{
Geoff Langa8cb2872018-03-09 16:09:40 -05003472 ANGLE_TRY(syncDirtyObjects(objectMask));
3473 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003474 return NoError();
3475}
3476
Geoff Langa8cb2872018-03-09 16:09:40 -05003477Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003478{
3479 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003480 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003481 mGLState.clearDirtyBits();
3482 return NoError();
3483}
3484
Geoff Langa8cb2872018-03-09 16:09:40 -05003485Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003486{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003487 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003488 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003489 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003490 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003491}
Jamie Madillc29968b2016-01-20 11:17:23 -05003492
Geoff Langa8cb2872018-03-09 16:09:40 -05003493Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003494{
3495 return mGLState.syncDirtyObjects(this, objectMask);
3496}
3497
Jamie Madillc29968b2016-01-20 11:17:23 -05003498void Context::blitFramebuffer(GLint srcX0,
3499 GLint srcY0,
3500 GLint srcX1,
3501 GLint srcY1,
3502 GLint dstX0,
3503 GLint dstY0,
3504 GLint dstX1,
3505 GLint dstY1,
3506 GLbitfield mask,
3507 GLenum filter)
3508{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003509 if (mask == 0)
3510 {
3511 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3512 // buffers are copied.
3513 return;
3514 }
3515
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003516 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003517 ASSERT(drawFramebuffer);
3518
3519 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3520 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3521
Jamie Madillbc918e72018-03-08 09:47:21 -05003522 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003523
Jamie Madillc564c072017-06-01 12:45:42 -04003524 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003525}
Jamie Madillc29968b2016-01-20 11:17:23 -05003526
3527void Context::clear(GLbitfield mask)
3528{
Geoff Langd4fff502017-09-22 11:28:28 -04003529 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3530 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003531}
3532
3533void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3534{
Geoff Langd4fff502017-09-22 11:28:28 -04003535 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3536 ANGLE_CONTEXT_TRY(
3537 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003538}
3539
3540void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3541{
Geoff Langd4fff502017-09-22 11:28:28 -04003542 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3543 ANGLE_CONTEXT_TRY(
3544 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003545}
3546
3547void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3548{
Geoff Langd4fff502017-09-22 11:28:28 -04003549 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3550 ANGLE_CONTEXT_TRY(
3551 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003552}
3553
3554void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3555{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003556 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003557 ASSERT(framebufferObject);
3558
3559 // If a buffer is not present, the clear has no effect
3560 if (framebufferObject->getDepthbuffer() == nullptr &&
3561 framebufferObject->getStencilbuffer() == nullptr)
3562 {
3563 return;
3564 }
3565
Geoff Langd4fff502017-09-22 11:28:28 -04003566 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3567 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003568}
3569
3570void Context::readPixels(GLint x,
3571 GLint y,
3572 GLsizei width,
3573 GLsizei height,
3574 GLenum format,
3575 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003576 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003577{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003578 if (width == 0 || height == 0)
3579 {
3580 return;
3581 }
3582
Jamie Madillbc918e72018-03-08 09:47:21 -05003583 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003584
Jamie Madillb6664922017-07-25 12:55:04 -04003585 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3586 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003587
3588 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003589 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003590}
3591
Brandon Jones59770802018-04-02 13:18:42 -07003592void Context::readPixelsRobust(GLint x,
3593 GLint y,
3594 GLsizei width,
3595 GLsizei height,
3596 GLenum format,
3597 GLenum type,
3598 GLsizei bufSize,
3599 GLsizei *length,
3600 GLsizei *columns,
3601 GLsizei *rows,
3602 void *pixels)
3603{
3604 readPixels(x, y, width, height, format, type, pixels);
3605}
3606
3607void Context::readnPixelsRobust(GLint x,
3608 GLint y,
3609 GLsizei width,
3610 GLsizei height,
3611 GLenum format,
3612 GLenum type,
3613 GLsizei bufSize,
3614 GLsizei *length,
3615 GLsizei *columns,
3616 GLsizei *rows,
3617 void *data)
3618{
3619 readPixels(x, y, width, height, format, type, data);
3620}
3621
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003622void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003623 GLint level,
3624 GLenum internalformat,
3625 GLint x,
3626 GLint y,
3627 GLsizei width,
3628 GLsizei height,
3629 GLint border)
3630{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003631 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003632 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003633
Jamie Madillc29968b2016-01-20 11:17:23 -05003634 Rectangle sourceArea(x, y, width, height);
3635
Jamie Madill05b35b22017-10-03 09:01:44 -04003636 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003637 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003638 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003639}
3640
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003641void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003642 GLint level,
3643 GLint xoffset,
3644 GLint yoffset,
3645 GLint x,
3646 GLint y,
3647 GLsizei width,
3648 GLsizei height)
3649{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003650 if (width == 0 || height == 0)
3651 {
3652 return;
3653 }
3654
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003655 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003656 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003657
Jamie Madillc29968b2016-01-20 11:17:23 -05003658 Offset destOffset(xoffset, yoffset, 0);
3659 Rectangle sourceArea(x, y, width, height);
3660
Jamie Madill05b35b22017-10-03 09:01:44 -04003661 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003662 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003663 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003664}
3665
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003666void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003667 GLint level,
3668 GLint xoffset,
3669 GLint yoffset,
3670 GLint zoffset,
3671 GLint x,
3672 GLint y,
3673 GLsizei width,
3674 GLsizei height)
3675{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003676 if (width == 0 || height == 0)
3677 {
3678 return;
3679 }
3680
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003681 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003682 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003683
Jamie Madillc29968b2016-01-20 11:17:23 -05003684 Offset destOffset(xoffset, yoffset, zoffset);
3685 Rectangle sourceArea(x, y, width, height);
3686
Jamie Madill05b35b22017-10-03 09:01:44 -04003687 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3688 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003689 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3690 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003691}
3692
3693void Context::framebufferTexture2D(GLenum target,
3694 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003695 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003696 GLuint texture,
3697 GLint level)
3698{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003699 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003700 ASSERT(framebuffer);
3701
3702 if (texture != 0)
3703 {
3704 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003705 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003706 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003707 }
3708 else
3709 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003710 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003711 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003712
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003713 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003714}
3715
3716void Context::framebufferRenderbuffer(GLenum target,
3717 GLenum attachment,
3718 GLenum renderbuffertarget,
3719 GLuint renderbuffer)
3720{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003721 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003722 ASSERT(framebuffer);
3723
3724 if (renderbuffer != 0)
3725 {
3726 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003727
Jamie Madillcc129372018-04-12 09:13:18 -04003728 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003729 renderbufferObject);
3730 }
3731 else
3732 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003733 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003734 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003735
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003736 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003737}
3738
3739void Context::framebufferTextureLayer(GLenum target,
3740 GLenum attachment,
3741 GLuint texture,
3742 GLint level,
3743 GLint layer)
3744{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003745 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003746 ASSERT(framebuffer);
3747
3748 if (texture != 0)
3749 {
3750 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003751 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003752 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003753 }
3754 else
3755 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003756 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003757 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003758
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003759 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003760}
3761
Brandon Jones59770802018-04-02 13:18:42 -07003762void Context::framebufferTextureMultiviewLayered(GLenum target,
3763 GLenum attachment,
3764 GLuint texture,
3765 GLint level,
3766 GLint baseViewIndex,
3767 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003768{
Martin Radev82ef7742017-08-08 17:44:58 +03003769 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3770 ASSERT(framebuffer);
3771
3772 if (texture != 0)
3773 {
3774 Texture *textureObj = getTexture(texture);
3775
Martin Radev18b75ba2017-08-15 15:50:40 +03003776 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003777 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3778 numViews, baseViewIndex);
3779 }
3780 else
3781 {
3782 framebuffer->resetAttachment(this, attachment);
3783 }
3784
3785 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003786}
3787
Brandon Jones59770802018-04-02 13:18:42 -07003788void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3789 GLenum attachment,
3790 GLuint texture,
3791 GLint level,
3792 GLsizei numViews,
3793 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003794{
Martin Radev5dae57b2017-07-14 16:15:55 +03003795 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3796 ASSERT(framebuffer);
3797
3798 if (texture != 0)
3799 {
3800 Texture *textureObj = getTexture(texture);
3801
3802 ImageIndex index = ImageIndex::Make2D(level);
3803 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3804 textureObj, numViews, viewportOffsets);
3805 }
3806 else
3807 {
3808 framebuffer->resetAttachment(this, attachment);
3809 }
3810
3811 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003812}
3813
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003814void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3815{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003816 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3817 ASSERT(framebuffer);
3818
3819 if (texture != 0)
3820 {
3821 Texture *textureObj = getTexture(texture);
3822
3823 ImageIndex index = ImageIndex::MakeFromType(
3824 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3825 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3826 }
3827 else
3828 {
3829 framebuffer->resetAttachment(this, attachment);
3830 }
3831
3832 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003833}
3834
Jamie Madillc29968b2016-01-20 11:17:23 -05003835void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3836{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003837 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003838 ASSERT(framebuffer);
3839 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003840 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04003841 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003842}
3843
3844void Context::readBuffer(GLenum mode)
3845{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003846 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003847 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003848 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003849}
3850
3851void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3852{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003853 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003854 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003855
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003856 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003857 ASSERT(framebuffer);
3858
3859 // The specification isn't clear what should be done when the framebuffer isn't complete.
3860 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003861 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003862}
3863
3864void Context::invalidateFramebuffer(GLenum target,
3865 GLsizei numAttachments,
3866 const GLenum *attachments)
3867{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003868 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003869 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003870
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003871 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003872 ASSERT(framebuffer);
3873
Jamie Madill427064d2018-04-13 16:20:34 -04003874 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003875 {
Jamie Madill437fa652016-05-03 15:13:24 -04003876 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003877 }
Jamie Madill437fa652016-05-03 15:13:24 -04003878
Jamie Madill4928b7c2017-06-20 12:57:39 -04003879 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003880}
3881
3882void Context::invalidateSubFramebuffer(GLenum target,
3883 GLsizei numAttachments,
3884 const GLenum *attachments,
3885 GLint x,
3886 GLint y,
3887 GLsizei width,
3888 GLsizei height)
3889{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003890 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003891 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003892
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003893 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003894 ASSERT(framebuffer);
3895
Jamie Madill427064d2018-04-13 16:20:34 -04003896 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003897 {
Jamie Madill437fa652016-05-03 15:13:24 -04003898 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003899 }
Jamie Madill437fa652016-05-03 15:13:24 -04003900
3901 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003902 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003903}
3904
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003905void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003906 GLint level,
3907 GLint internalformat,
3908 GLsizei width,
3909 GLsizei height,
3910 GLint border,
3911 GLenum format,
3912 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003913 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003914{
Jamie Madillbc918e72018-03-08 09:47:21 -05003915 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003916
3917 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003918 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003919 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003920 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003921}
3922
Brandon Jones59770802018-04-02 13:18:42 -07003923void Context::texImage2DRobust(TextureTarget target,
3924 GLint level,
3925 GLint internalformat,
3926 GLsizei width,
3927 GLsizei height,
3928 GLint border,
3929 GLenum format,
3930 GLenum type,
3931 GLsizei bufSize,
3932 const void *pixels)
3933{
3934 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3935}
3936
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003937void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003938 GLint level,
3939 GLint internalformat,
3940 GLsizei width,
3941 GLsizei height,
3942 GLsizei depth,
3943 GLint border,
3944 GLenum format,
3945 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003946 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003947{
Jamie Madillbc918e72018-03-08 09:47:21 -05003948 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003949
3950 Extents size(width, height, depth);
3951 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003952 handleError(texture->setImage(this, mGLState.getUnpackState(),
3953 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003954 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003955}
3956
Brandon Jones59770802018-04-02 13:18:42 -07003957void Context::texImage3DRobust(TextureType target,
3958 GLint level,
3959 GLint internalformat,
3960 GLsizei width,
3961 GLsizei height,
3962 GLsizei depth,
3963 GLint border,
3964 GLenum format,
3965 GLenum type,
3966 GLsizei bufSize,
3967 const void *pixels)
3968{
3969 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3970}
3971
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003972void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003973 GLint level,
3974 GLint xoffset,
3975 GLint yoffset,
3976 GLsizei width,
3977 GLsizei height,
3978 GLenum format,
3979 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003980 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003981{
3982 // Zero sized uploads are valid but no-ops
3983 if (width == 0 || height == 0)
3984 {
3985 return;
3986 }
3987
Jamie Madillbc918e72018-03-08 09:47:21 -05003988 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003989
3990 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003991 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04003992
3993 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
3994
3995 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target, level,
3996 area, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003997}
3998
Brandon Jones59770802018-04-02 13:18:42 -07003999void Context::texSubImage2DRobust(TextureTarget target,
4000 GLint level,
4001 GLint xoffset,
4002 GLint yoffset,
4003 GLsizei width,
4004 GLsizei height,
4005 GLenum format,
4006 GLenum type,
4007 GLsizei bufSize,
4008 const void *pixels)
4009{
4010 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4011}
4012
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004013void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004014 GLint level,
4015 GLint xoffset,
4016 GLint yoffset,
4017 GLint zoffset,
4018 GLsizei width,
4019 GLsizei height,
4020 GLsizei depth,
4021 GLenum format,
4022 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004023 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004024{
4025 // Zero sized uploads are valid but no-ops
4026 if (width == 0 || height == 0 || depth == 0)
4027 {
4028 return;
4029 }
4030
Jamie Madillbc918e72018-03-08 09:47:21 -05004031 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004032
4033 Box area(xoffset, yoffset, zoffset, width, height, depth);
4034 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004035
4036 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4037
4038 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004039 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004040 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004041}
4042
Brandon Jones59770802018-04-02 13:18:42 -07004043void Context::texSubImage3DRobust(TextureType target,
4044 GLint level,
4045 GLint xoffset,
4046 GLint yoffset,
4047 GLint zoffset,
4048 GLsizei width,
4049 GLsizei height,
4050 GLsizei depth,
4051 GLenum format,
4052 GLenum type,
4053 GLsizei bufSize,
4054 const void *pixels)
4055{
4056 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4057 pixels);
4058}
4059
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004060void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004061 GLint level,
4062 GLenum internalformat,
4063 GLsizei width,
4064 GLsizei height,
4065 GLint border,
4066 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004067 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004068{
Jamie Madillbc918e72018-03-08 09:47:21 -05004069 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004070
4071 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004072 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004073 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4074 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004075 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004076}
4077
Brandon Jones59770802018-04-02 13:18:42 -07004078void Context::compressedTexImage2DRobust(TextureTarget target,
4079 GLint level,
4080 GLenum internalformat,
4081 GLsizei width,
4082 GLsizei height,
4083 GLint border,
4084 GLsizei imageSize,
4085 GLsizei dataSize,
4086 const GLvoid *data)
4087{
4088 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4089}
4090
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004091void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004092 GLint level,
4093 GLenum internalformat,
4094 GLsizei width,
4095 GLsizei height,
4096 GLsizei depth,
4097 GLint border,
4098 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004099 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004100{
Jamie Madillbc918e72018-03-08 09:47:21 -05004101 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004102
4103 Extents size(width, height, depth);
4104 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004105 handleError(texture->setCompressedImage(
4106 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004107 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004108}
4109
Brandon Jones59770802018-04-02 13:18:42 -07004110void Context::compressedTexImage3DRobust(TextureType target,
4111 GLint level,
4112 GLenum internalformat,
4113 GLsizei width,
4114 GLsizei height,
4115 GLsizei depth,
4116 GLint border,
4117 GLsizei imageSize,
4118 GLsizei dataSize,
4119 const GLvoid *data)
4120{
4121 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4122 data);
4123}
4124
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004125void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004126 GLint level,
4127 GLint xoffset,
4128 GLint yoffset,
4129 GLsizei width,
4130 GLsizei height,
4131 GLenum format,
4132 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004133 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004134{
Jamie Madillbc918e72018-03-08 09:47:21 -05004135 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004136
4137 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004138 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004139 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4140 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004141 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004142}
4143
Brandon Jones59770802018-04-02 13:18:42 -07004144void Context::compressedTexSubImage2DRobust(TextureTarget target,
4145 GLint level,
4146 GLint xoffset,
4147 GLint yoffset,
4148 GLsizei width,
4149 GLsizei height,
4150 GLenum format,
4151 GLsizei imageSize,
4152 GLsizei dataSize,
4153 const GLvoid *data)
4154{
4155 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4156 data);
4157}
4158
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004159void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004160 GLint level,
4161 GLint xoffset,
4162 GLint yoffset,
4163 GLint zoffset,
4164 GLsizei width,
4165 GLsizei height,
4166 GLsizei depth,
4167 GLenum format,
4168 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004169 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004170{
4171 // Zero sized uploads are valid but no-ops
4172 if (width == 0 || height == 0)
4173 {
4174 return;
4175 }
4176
Jamie Madillbc918e72018-03-08 09:47:21 -05004177 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004178
4179 Box area(xoffset, yoffset, zoffset, width, height, depth);
4180 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004181 handleError(texture->setCompressedSubImage(
4182 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004183 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004184}
4185
Brandon Jones59770802018-04-02 13:18:42 -07004186void Context::compressedTexSubImage3DRobust(TextureType target,
4187 GLint level,
4188 GLint xoffset,
4189 GLint yoffset,
4190 GLint zoffset,
4191 GLsizei width,
4192 GLsizei height,
4193 GLsizei depth,
4194 GLenum format,
4195 GLsizei imageSize,
4196 GLsizei dataSize,
4197 const GLvoid *data)
4198{
4199 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4200 imageSize, data);
4201}
4202
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004203void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004204{
4205 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004206 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004207}
4208
Jamie Madill007530e2017-12-28 14:27:04 -05004209void Context::copyTexture(GLuint sourceId,
4210 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004211 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004212 GLuint destId,
4213 GLint destLevel,
4214 GLint internalFormat,
4215 GLenum destType,
4216 GLboolean unpackFlipY,
4217 GLboolean unpackPremultiplyAlpha,
4218 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004219{
Jamie Madillbc918e72018-03-08 09:47:21 -05004220 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004221
4222 gl::Texture *sourceTexture = getTexture(sourceId);
4223 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004224 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4225 sourceLevel, ConvertToBool(unpackFlipY),
4226 ConvertToBool(unpackPremultiplyAlpha),
4227 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004228}
4229
Jamie Madill007530e2017-12-28 14:27:04 -05004230void Context::copySubTexture(GLuint sourceId,
4231 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004232 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004233 GLuint destId,
4234 GLint destLevel,
4235 GLint xoffset,
4236 GLint yoffset,
4237 GLint x,
4238 GLint y,
4239 GLsizei width,
4240 GLsizei height,
4241 GLboolean unpackFlipY,
4242 GLboolean unpackPremultiplyAlpha,
4243 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004244{
4245 // Zero sized copies are valid but no-ops
4246 if (width == 0 || height == 0)
4247 {
4248 return;
4249 }
4250
Jamie Madillbc918e72018-03-08 09:47:21 -05004251 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004252
4253 gl::Texture *sourceTexture = getTexture(sourceId);
4254 gl::Texture *destTexture = getTexture(destId);
4255 Offset offset(xoffset, yoffset, 0);
4256 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004257 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4258 ConvertToBool(unpackFlipY),
4259 ConvertToBool(unpackPremultiplyAlpha),
4260 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004261}
4262
Jamie Madill007530e2017-12-28 14:27:04 -05004263void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004264{
Jamie Madillbc918e72018-03-08 09:47:21 -05004265 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004266
4267 gl::Texture *sourceTexture = getTexture(sourceId);
4268 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004269 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004270}
4271
Corentin Wallez336129f2017-10-17 15:55:40 -04004272void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004273{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004274 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004275 ASSERT(buffer);
4276
Geoff Lang496c02d2016-10-20 11:38:11 -07004277 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004278}
4279
Brandon Jones59770802018-04-02 13:18:42 -07004280void Context::getBufferPointervRobust(BufferBinding target,
4281 GLenum pname,
4282 GLsizei bufSize,
4283 GLsizei *length,
4284 void **params)
4285{
4286 getBufferPointerv(target, pname, params);
4287}
4288
Corentin Wallez336129f2017-10-17 15:55:40 -04004289void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004290{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004291 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004292 ASSERT(buffer);
4293
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004294 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004295 if (error.isError())
4296 {
Jamie Madill437fa652016-05-03 15:13:24 -04004297 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004298 return nullptr;
4299 }
4300
4301 return buffer->getMapPointer();
4302}
4303
Corentin Wallez336129f2017-10-17 15:55:40 -04004304GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004305{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004306 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004307 ASSERT(buffer);
4308
4309 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004310 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004311 if (error.isError())
4312 {
Jamie Madill437fa652016-05-03 15:13:24 -04004313 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004314 return GL_FALSE;
4315 }
4316
4317 return result;
4318}
4319
Corentin Wallez336129f2017-10-17 15:55:40 -04004320void *Context::mapBufferRange(BufferBinding target,
4321 GLintptr offset,
4322 GLsizeiptr length,
4323 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004324{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004325 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004326 ASSERT(buffer);
4327
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004328 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004329 if (error.isError())
4330 {
Jamie Madill437fa652016-05-03 15:13:24 -04004331 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004332 return nullptr;
4333 }
4334
4335 return buffer->getMapPointer();
4336}
4337
Corentin Wallez336129f2017-10-17 15:55:40 -04004338void Context::flushMappedBufferRange(BufferBinding /*target*/,
4339 GLintptr /*offset*/,
4340 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004341{
4342 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4343}
4344
Jamie Madillbc918e72018-03-08 09:47:21 -05004345Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004346{
Geoff Langa8cb2872018-03-09 16:09:40 -05004347 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004348}
4349
Jamie Madillbc918e72018-03-08 09:47:21 -05004350Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004351{
Geoff Langa8cb2872018-03-09 16:09:40 -05004352 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004353}
4354
Jamie Madillbc918e72018-03-08 09:47:21 -05004355Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004356{
Geoff Langa8cb2872018-03-09 16:09:40 -05004357 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004358}
4359
Geoff Lang9bf86f02018-07-26 11:46:34 -04004360Error Context::syncStateForPathOperation()
4361{
4362 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4363
4364 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4365 ANGLE_TRY(syncDirtyBits());
4366
4367 return NoError();
4368}
4369
Jiajia Qin5451d532017-11-16 17:16:34 +08004370void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4371{
4372 UNIMPLEMENTED();
4373}
4374
Jamie Madillc20ab272016-06-09 07:20:46 -07004375void Context::activeTexture(GLenum texture)
4376{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004377 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004378}
4379
Jamie Madill876429b2017-04-20 15:46:24 -04004380void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004381{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004382 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004383}
4384
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004385void Context::blendEquation(GLenum mode)
4386{
4387 mGLState.setBlendEquation(mode, mode);
4388}
4389
Jamie Madillc20ab272016-06-09 07:20:46 -07004390void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4391{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004392 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004393}
4394
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004395void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4396{
4397 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4398}
4399
Jamie Madillc20ab272016-06-09 07:20:46 -07004400void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4401{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004402 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004403}
4404
Jamie Madill876429b2017-04-20 15:46:24 -04004405void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004406{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004407 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004408}
4409
Jamie Madill876429b2017-04-20 15:46:24 -04004410void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004411{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004412 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004413}
4414
4415void Context::clearStencil(GLint s)
4416{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004417 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004418}
4419
4420void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4421{
Geoff Lang92019432017-11-20 13:09:34 -05004422 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4423 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004424}
4425
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004426void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004427{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004428 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004429}
4430
4431void Context::depthFunc(GLenum func)
4432{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004433 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004434}
4435
4436void Context::depthMask(GLboolean flag)
4437{
Geoff Lang92019432017-11-20 13:09:34 -05004438 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004439}
4440
Jamie Madill876429b2017-04-20 15:46:24 -04004441void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004442{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004443 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004444}
4445
4446void Context::disable(GLenum cap)
4447{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004448 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004449 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004450}
4451
4452void Context::disableVertexAttribArray(GLuint index)
4453{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004454 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004455 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004456}
4457
4458void Context::enable(GLenum cap)
4459{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004460 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004461 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004462}
4463
4464void Context::enableVertexAttribArray(GLuint index)
4465{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004466 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004467 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004468}
4469
4470void Context::frontFace(GLenum mode)
4471{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004472 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004473}
4474
4475void Context::hint(GLenum target, GLenum mode)
4476{
4477 switch (target)
4478 {
4479 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004480 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004481 break;
4482
4483 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004484 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004485 break;
4486
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004487 case GL_PERSPECTIVE_CORRECTION_HINT:
4488 case GL_POINT_SMOOTH_HINT:
4489 case GL_LINE_SMOOTH_HINT:
4490 case GL_FOG_HINT:
4491 mGLState.gles1().setHint(target, mode);
4492 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004493 default:
4494 UNREACHABLE();
4495 return;
4496 }
4497}
4498
4499void Context::lineWidth(GLfloat width)
4500{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004501 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004502}
4503
4504void Context::pixelStorei(GLenum pname, GLint param)
4505{
4506 switch (pname)
4507 {
4508 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004509 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004510 break;
4511
4512 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004513 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004514 break;
4515
4516 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004517 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004518 break;
4519
4520 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004521 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004522 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004523 break;
4524
4525 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004526 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004527 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004528 break;
4529
4530 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004531 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004532 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004533 break;
4534
4535 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004536 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004537 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004538 break;
4539
4540 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004541 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004542 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004543 break;
4544
4545 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004546 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004547 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004548 break;
4549
4550 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004551 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004552 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004553 break;
4554
4555 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004556 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004557 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004558 break;
4559
4560 default:
4561 UNREACHABLE();
4562 return;
4563 }
4564}
4565
4566void Context::polygonOffset(GLfloat factor, GLfloat units)
4567{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004568 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004569}
4570
Jamie Madill876429b2017-04-20 15:46:24 -04004571void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004572{
Geoff Lang92019432017-11-20 13:09:34 -05004573 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004574}
4575
Jiawei Shaodb342272017-09-27 10:21:45 +08004576void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4577{
4578 mGLState.setSampleMaskParams(maskNumber, mask);
4579}
4580
Jamie Madillc20ab272016-06-09 07:20:46 -07004581void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4582{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004583 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004584}
4585
4586void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4587{
4588 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4589 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004590 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004591 }
4592
4593 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4594 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004595 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004596 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004597
4598 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004599}
4600
4601void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4602{
4603 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4604 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004605 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004606 }
4607
4608 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4609 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004610 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004611 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004612
4613 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004614}
4615
4616void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4617{
4618 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4619 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004620 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004621 }
4622
4623 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4624 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004625 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004626 }
4627}
4628
4629void Context::vertexAttrib1f(GLuint index, GLfloat x)
4630{
4631 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004632 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004633 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004634}
4635
4636void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4637{
4638 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004639 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004640 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004641}
4642
4643void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4644{
4645 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004646 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004647 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004648}
4649
4650void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4651{
4652 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004653 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004654 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004655}
4656
4657void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4658{
4659 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004660 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004661 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004662}
4663
4664void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4665{
4666 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004667 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004668 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004669}
4670
4671void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4672{
4673 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004674 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004675 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004676}
4677
4678void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4679{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004680 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004681 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004682}
4683
4684void Context::vertexAttribPointer(GLuint index,
4685 GLint size,
4686 GLenum type,
4687 GLboolean normalized,
4688 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004689 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004690{
Corentin Wallez336129f2017-10-17 15:55:40 -04004691 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004692 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004693 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004694}
4695
Shao80957d92017-02-20 21:25:59 +08004696void Context::vertexAttribFormat(GLuint attribIndex,
4697 GLint size,
4698 GLenum type,
4699 GLboolean normalized,
4700 GLuint relativeOffset)
4701{
Geoff Lang92019432017-11-20 13:09:34 -05004702 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004703 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004704 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004705}
4706
4707void Context::vertexAttribIFormat(GLuint attribIndex,
4708 GLint size,
4709 GLenum type,
4710 GLuint relativeOffset)
4711{
4712 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004713 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004714}
4715
4716void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4717{
Shaodde78e82017-05-22 14:13:27 +08004718 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004719 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004720}
4721
Jiajia Qin5451d532017-11-16 17:16:34 +08004722void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004723{
4724 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004725 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004726}
4727
Jamie Madillc20ab272016-06-09 07:20:46 -07004728void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4729{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004730 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004731}
4732
4733void Context::vertexAttribIPointer(GLuint index,
4734 GLint size,
4735 GLenum type,
4736 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004737 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004738{
Corentin Wallez336129f2017-10-17 15:55:40 -04004739 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4740 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004741 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004742}
4743
4744void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4745{
4746 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004747 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004748 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004749}
4750
4751void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4752{
4753 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004754 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004755 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004756}
4757
4758void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4759{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004760 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004761 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004762}
4763
4764void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4765{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004766 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004767 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004768}
4769
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004770void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4771{
4772 const VertexAttribCurrentValueData &currentValues =
4773 getGLState().getVertexAttribCurrentValue(index);
4774 const VertexArray *vao = getGLState().getVertexArray();
4775 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4776 currentValues, pname, params);
4777}
4778
Brandon Jones59770802018-04-02 13:18:42 -07004779void Context::getVertexAttribivRobust(GLuint index,
4780 GLenum pname,
4781 GLsizei bufSize,
4782 GLsizei *length,
4783 GLint *params)
4784{
4785 getVertexAttribiv(index, pname, params);
4786}
4787
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004788void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4789{
4790 const VertexAttribCurrentValueData &currentValues =
4791 getGLState().getVertexAttribCurrentValue(index);
4792 const VertexArray *vao = getGLState().getVertexArray();
4793 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4794 currentValues, pname, params);
4795}
4796
Brandon Jones59770802018-04-02 13:18:42 -07004797void Context::getVertexAttribfvRobust(GLuint index,
4798 GLenum pname,
4799 GLsizei bufSize,
4800 GLsizei *length,
4801 GLfloat *params)
4802{
4803 getVertexAttribfv(index, pname, params);
4804}
4805
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004806void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4807{
4808 const VertexAttribCurrentValueData &currentValues =
4809 getGLState().getVertexAttribCurrentValue(index);
4810 const VertexArray *vao = getGLState().getVertexArray();
4811 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4812 currentValues, pname, params);
4813}
4814
Brandon Jones59770802018-04-02 13:18:42 -07004815void Context::getVertexAttribIivRobust(GLuint index,
4816 GLenum pname,
4817 GLsizei bufSize,
4818 GLsizei *length,
4819 GLint *params)
4820{
4821 getVertexAttribIiv(index, pname, params);
4822}
4823
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004824void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4825{
4826 const VertexAttribCurrentValueData &currentValues =
4827 getGLState().getVertexAttribCurrentValue(index);
4828 const VertexArray *vao = getGLState().getVertexArray();
4829 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4830 currentValues, pname, params);
4831}
4832
Brandon Jones59770802018-04-02 13:18:42 -07004833void Context::getVertexAttribIuivRobust(GLuint index,
4834 GLenum pname,
4835 GLsizei bufSize,
4836 GLsizei *length,
4837 GLuint *params)
4838{
4839 getVertexAttribIuiv(index, pname, params);
4840}
4841
Jamie Madill876429b2017-04-20 15:46:24 -04004842void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004843{
4844 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4845 QueryVertexAttribPointerv(attrib, pname, pointer);
4846}
4847
Brandon Jones59770802018-04-02 13:18:42 -07004848void Context::getVertexAttribPointervRobust(GLuint index,
4849 GLenum pname,
4850 GLsizei bufSize,
4851 GLsizei *length,
4852 void **pointer)
4853{
4854 getVertexAttribPointerv(index, pname, pointer);
4855}
4856
Jamie Madillc20ab272016-06-09 07:20:46 -07004857void Context::debugMessageControl(GLenum source,
4858 GLenum type,
4859 GLenum severity,
4860 GLsizei count,
4861 const GLuint *ids,
4862 GLboolean enabled)
4863{
4864 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004865 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004866 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004867}
4868
4869void Context::debugMessageInsert(GLenum source,
4870 GLenum type,
4871 GLuint id,
4872 GLenum severity,
4873 GLsizei length,
4874 const GLchar *buf)
4875{
4876 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004877 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004878}
4879
4880void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4881{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004882 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004883}
4884
4885GLuint Context::getDebugMessageLog(GLuint count,
4886 GLsizei bufSize,
4887 GLenum *sources,
4888 GLenum *types,
4889 GLuint *ids,
4890 GLenum *severities,
4891 GLsizei *lengths,
4892 GLchar *messageLog)
4893{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004894 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4895 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004896}
4897
4898void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4899{
4900 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004901 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004902 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004903}
4904
4905void Context::popDebugGroup()
4906{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004907 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004908 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004909}
4910
Corentin Wallez336129f2017-10-17 15:55:40 -04004911void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004912{
4913 Buffer *buffer = mGLState.getTargetBuffer(target);
4914 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004915 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004916}
4917
Corentin Wallez336129f2017-10-17 15:55:40 -04004918void Context::bufferSubData(BufferBinding target,
4919 GLintptr offset,
4920 GLsizeiptr size,
4921 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004922{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06004923 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04004924 {
4925 return;
4926 }
4927
4928 Buffer *buffer = mGLState.getTargetBuffer(target);
4929 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004930 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004931}
4932
Jamie Madillef300b12016-10-07 15:12:09 -04004933void Context::attachShader(GLuint program, GLuint shader)
4934{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004935 Program *programObject = mState.mShaderPrograms->getProgram(program);
4936 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004937 ASSERT(programObject && shaderObject);
4938 programObject->attachShader(shaderObject);
4939}
4940
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004941const Workarounds &Context::getWorkarounds() const
4942{
4943 return mWorkarounds;
4944}
4945
Corentin Wallez336129f2017-10-17 15:55:40 -04004946void Context::copyBufferSubData(BufferBinding readTarget,
4947 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004948 GLintptr readOffset,
4949 GLintptr writeOffset,
4950 GLsizeiptr size)
4951{
4952 // if size is zero, the copy is a successful no-op
4953 if (size == 0)
4954 {
4955 return;
4956 }
4957
4958 // TODO(jmadill): cache these.
4959 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4960 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4961
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004962 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004963}
4964
Jamie Madill01a80ee2016-11-07 12:06:18 -05004965void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4966{
4967 Program *programObject = getProgram(program);
4968 // TODO(jmadill): Re-use this from the validation if possible.
4969 ASSERT(programObject);
4970 programObject->bindAttributeLocation(index, name);
4971}
4972
Corentin Wallez336129f2017-10-17 15:55:40 -04004973void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004974{
Corentin Wallez336129f2017-10-17 15:55:40 -04004975 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4976 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04004977 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004978}
4979
Corentin Wallez336129f2017-10-17 15:55:40 -04004980void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004981{
4982 bindBufferRange(target, index, buffer, 0, 0);
4983}
4984
Corentin Wallez336129f2017-10-17 15:55:40 -04004985void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004986 GLuint index,
4987 GLuint buffer,
4988 GLintptr offset,
4989 GLsizeiptr size)
4990{
Jamie Madill6d32cef2018-08-14 02:34:28 -04004991 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4992 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
4993 if (target == BufferBinding::Uniform)
4994 {
4995 mUniformBufferObserverBindings[index].bind(object ? object->getImplementation() : nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04004996 mStateCache.onUniformBufferStateChange(this);
4997 }
4998 else
4999 {
5000 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005001 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005002}
5003
Jamie Madill01a80ee2016-11-07 12:06:18 -05005004void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5005{
5006 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5007 {
5008 bindReadFramebuffer(framebuffer);
5009 }
5010
5011 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5012 {
5013 bindDrawFramebuffer(framebuffer);
5014 }
5015}
5016
5017void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5018{
5019 ASSERT(target == GL_RENDERBUFFER);
5020 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005021 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005022 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005023}
5024
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005025void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005026 GLsizei samples,
5027 GLenum internalformat,
5028 GLsizei width,
5029 GLsizei height,
5030 GLboolean fixedsamplelocations)
5031{
5032 Extents size(width, height, 1);
5033 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005034 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5035 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005036}
5037
Olli Etuaho89664842018-08-24 14:45:36 +03005038void Context::texStorage3DMultisample(TextureType target,
5039 GLsizei samples,
5040 GLenum internalformat,
5041 GLsizei width,
5042 GLsizei height,
5043 GLsizei depth,
5044 GLboolean fixedsamplelocations)
5045{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005046 Extents size(width, height, depth);
5047 Texture *texture = getTargetTexture(target);
5048 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5049 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005050}
5051
JiangYizhoubddc46b2016-12-09 09:50:51 +08005052void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5053{
JiangYizhou5b03f472017-01-09 10:22:53 +08005054 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5055 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005056 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005057 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005058
5059 switch (pname)
5060 {
5061 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04005062 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005063 break;
5064 default:
5065 UNREACHABLE();
5066 }
5067}
5068
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005069void Context::getMultisamplefvRobust(GLenum pname,
5070 GLuint index,
5071 GLsizei bufSize,
5072 GLsizei *length,
5073 GLfloat *val)
5074{
5075 UNIMPLEMENTED();
5076}
5077
Jamie Madille8fb6402017-02-14 17:56:40 -05005078void Context::renderbufferStorage(GLenum target,
5079 GLenum internalformat,
5080 GLsizei width,
5081 GLsizei height)
5082{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005083 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5084 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5085
Jamie Madille8fb6402017-02-14 17:56:40 -05005086 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04005087 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005088}
5089
5090void Context::renderbufferStorageMultisample(GLenum target,
5091 GLsizei samples,
5092 GLenum internalformat,
5093 GLsizei width,
5094 GLsizei height)
5095{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005096 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5097 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005098
5099 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005100 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005101 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005102}
5103
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005104void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5105{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005106 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04005107 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005108}
5109
JiangYizhoue18e6392017-02-20 10:32:23 +08005110void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5111{
5112 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5113 QueryFramebufferParameteriv(framebuffer, pname, params);
5114}
5115
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005116void Context::getFramebufferParameterivRobust(GLenum target,
5117 GLenum pname,
5118 GLsizei bufSize,
5119 GLsizei *length,
5120 GLint *params)
5121{
5122 UNIMPLEMENTED();
5123}
5124
Jiajia Qin5451d532017-11-16 17:16:34 +08005125void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005126{
5127 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005128 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005129}
5130
Jamie Madilldec86232018-07-11 09:01:18 -04005131bool Context::getScratchBuffer(size_t requstedSizeBytes,
5132 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005133{
Jamie Madilldec86232018-07-11 09:01:18 -04005134 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005135}
5136
Jamie Madilldec86232018-07-11 09:01:18 -04005137bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5138 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005139{
Jamie Madilldec86232018-07-11 09:01:18 -04005140 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005141}
5142
Xinghua Cao10a4d432017-11-28 14:46:26 +08005143Error Context::prepareForDispatch()
5144{
Geoff Langa8cb2872018-03-09 16:09:40 -05005145 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005146
5147 if (isRobustResourceInitEnabled())
5148 {
5149 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5150 }
5151
5152 return NoError();
5153}
5154
Xinghua Cao2b396592017-03-29 15:36:04 +08005155void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5156{
5157 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5158 {
5159 return;
5160 }
5161
Xinghua Cao10a4d432017-11-28 14:46:26 +08005162 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005163 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005164}
5165
Jiajia Qin5451d532017-11-16 17:16:34 +08005166void Context::dispatchComputeIndirect(GLintptr indirect)
5167{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005168 ANGLE_CONTEXT_TRY(prepareForDispatch());
5169 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005170}
5171
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005172void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005173 GLsizei levels,
5174 GLenum internalFormat,
5175 GLsizei width,
5176 GLsizei height)
5177{
5178 Extents size(width, height, 1);
5179 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005180 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005181}
5182
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005183void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005184 GLsizei levels,
5185 GLenum internalFormat,
5186 GLsizei width,
5187 GLsizei height,
5188 GLsizei depth)
5189{
5190 Extents size(width, height, depth);
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
Jiajia Qin5451d532017-11-16 17:16:34 +08005195void Context::memoryBarrier(GLbitfield barriers)
5196{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005197 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005198}
5199
5200void Context::memoryBarrierByRegion(GLbitfield barriers)
5201{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005202 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005203}
5204
Jamie Madillc1d770e2017-04-13 17:31:24 -04005205GLenum Context::checkFramebufferStatus(GLenum target)
5206{
5207 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5208 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005209 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005210}
5211
5212void Context::compileShader(GLuint shader)
5213{
5214 Shader *shaderObject = GetValidShader(this, shader);
5215 if (!shaderObject)
5216 {
5217 return;
5218 }
5219 shaderObject->compile(this);
5220}
5221
5222void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5223{
5224 for (int i = 0; i < n; i++)
5225 {
5226 deleteBuffer(buffers[i]);
5227 }
5228}
5229
5230void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5231{
5232 for (int i = 0; i < n; i++)
5233 {
5234 if (framebuffers[i] != 0)
5235 {
5236 deleteFramebuffer(framebuffers[i]);
5237 }
5238 }
5239}
5240
5241void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5242{
5243 for (int i = 0; i < n; i++)
5244 {
5245 deleteRenderbuffer(renderbuffers[i]);
5246 }
5247}
5248
5249void Context::deleteTextures(GLsizei n, const GLuint *textures)
5250{
5251 for (int i = 0; i < n; i++)
5252 {
5253 if (textures[i] != 0)
5254 {
5255 deleteTexture(textures[i]);
5256 }
5257 }
5258}
5259
5260void Context::detachShader(GLuint program, GLuint shader)
5261{
5262 Program *programObject = getProgram(program);
5263 ASSERT(programObject);
5264
5265 Shader *shaderObject = getShader(shader);
5266 ASSERT(shaderObject);
5267
5268 programObject->detachShader(this, shaderObject);
5269}
5270
5271void Context::genBuffers(GLsizei n, GLuint *buffers)
5272{
5273 for (int i = 0; i < n; i++)
5274 {
5275 buffers[i] = createBuffer();
5276 }
5277}
5278
5279void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5280{
5281 for (int i = 0; i < n; i++)
5282 {
5283 framebuffers[i] = createFramebuffer();
5284 }
5285}
5286
5287void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5288{
5289 for (int i = 0; i < n; i++)
5290 {
5291 renderbuffers[i] = createRenderbuffer();
5292 }
5293}
5294
5295void Context::genTextures(GLsizei n, GLuint *textures)
5296{
5297 for (int i = 0; i < n; i++)
5298 {
5299 textures[i] = createTexture();
5300 }
5301}
5302
5303void Context::getActiveAttrib(GLuint program,
5304 GLuint index,
5305 GLsizei bufsize,
5306 GLsizei *length,
5307 GLint *size,
5308 GLenum *type,
5309 GLchar *name)
5310{
5311 Program *programObject = getProgram(program);
5312 ASSERT(programObject);
5313 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5314}
5315
5316void Context::getActiveUniform(GLuint program,
5317 GLuint index,
5318 GLsizei bufsize,
5319 GLsizei *length,
5320 GLint *size,
5321 GLenum *type,
5322 GLchar *name)
5323{
5324 Program *programObject = getProgram(program);
5325 ASSERT(programObject);
5326 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5327}
5328
5329void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5330{
5331 Program *programObject = getProgram(program);
5332 ASSERT(programObject);
5333 programObject->getAttachedShaders(maxcount, count, shaders);
5334}
5335
5336GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5337{
5338 Program *programObject = getProgram(program);
5339 ASSERT(programObject);
5340 return programObject->getAttributeLocation(name);
5341}
5342
5343void Context::getBooleanv(GLenum pname, GLboolean *params)
5344{
5345 GLenum nativeType;
5346 unsigned int numParams = 0;
5347 getQueryParameterInfo(pname, &nativeType, &numParams);
5348
5349 if (nativeType == GL_BOOL)
5350 {
5351 getBooleanvImpl(pname, params);
5352 }
5353 else
5354 {
5355 CastStateValues(this, nativeType, pname, numParams, params);
5356 }
5357}
5358
Brandon Jones59770802018-04-02 13:18:42 -07005359void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5360{
5361 getBooleanv(pname, params);
5362}
5363
Jamie Madillc1d770e2017-04-13 17:31:24 -04005364void Context::getFloatv(GLenum pname, GLfloat *params)
5365{
5366 GLenum nativeType;
5367 unsigned int numParams = 0;
5368 getQueryParameterInfo(pname, &nativeType, &numParams);
5369
5370 if (nativeType == GL_FLOAT)
5371 {
5372 getFloatvImpl(pname, params);
5373 }
5374 else
5375 {
5376 CastStateValues(this, nativeType, pname, numParams, params);
5377 }
5378}
5379
Brandon Jones59770802018-04-02 13:18:42 -07005380void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5381{
5382 getFloatv(pname, params);
5383}
5384
Jamie Madillc1d770e2017-04-13 17:31:24 -04005385void Context::getIntegerv(GLenum pname, GLint *params)
5386{
5387 GLenum nativeType;
5388 unsigned int numParams = 0;
5389 getQueryParameterInfo(pname, &nativeType, &numParams);
5390
5391 if (nativeType == GL_INT)
5392 {
5393 getIntegervImpl(pname, params);
5394 }
5395 else
5396 {
5397 CastStateValues(this, nativeType, pname, numParams, params);
5398 }
5399}
5400
Brandon Jones59770802018-04-02 13:18:42 -07005401void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5402{
5403 getIntegerv(pname, data);
5404}
5405
Jamie Madillc1d770e2017-04-13 17:31:24 -04005406void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5407{
5408 Program *programObject = getProgram(program);
5409 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005410 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005411}
5412
Brandon Jones59770802018-04-02 13:18:42 -07005413void Context::getProgramivRobust(GLuint program,
5414 GLenum pname,
5415 GLsizei bufSize,
5416 GLsizei *length,
5417 GLint *params)
5418{
5419 getProgramiv(program, pname, params);
5420}
5421
Jiajia Qin5451d532017-11-16 17:16:34 +08005422void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5423{
5424 UNIMPLEMENTED();
5425}
5426
Jamie Madillbe849e42017-05-02 15:49:00 -04005427void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005428{
5429 Program *programObject = getProgram(program);
5430 ASSERT(programObject);
5431 programObject->getInfoLog(bufsize, length, infolog);
5432}
5433
Jiajia Qin5451d532017-11-16 17:16:34 +08005434void Context::getProgramPipelineInfoLog(GLuint pipeline,
5435 GLsizei bufSize,
5436 GLsizei *length,
5437 GLchar *infoLog)
5438{
5439 UNIMPLEMENTED();
5440}
5441
Jamie Madillc1d770e2017-04-13 17:31:24 -04005442void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5443{
5444 Shader *shaderObject = getShader(shader);
5445 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005446 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005447}
5448
Brandon Jones59770802018-04-02 13:18:42 -07005449void Context::getShaderivRobust(GLuint shader,
5450 GLenum pname,
5451 GLsizei bufSize,
5452 GLsizei *length,
5453 GLint *params)
5454{
5455 getShaderiv(shader, pname, params);
5456}
5457
Jamie Madillc1d770e2017-04-13 17:31:24 -04005458void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5459{
5460 Shader *shaderObject = getShader(shader);
5461 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005462 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005463}
5464
5465void Context::getShaderPrecisionFormat(GLenum shadertype,
5466 GLenum precisiontype,
5467 GLint *range,
5468 GLint *precision)
5469{
5470 // TODO(jmadill): Compute shaders.
5471
5472 switch (shadertype)
5473 {
5474 case GL_VERTEX_SHADER:
5475 switch (precisiontype)
5476 {
5477 case GL_LOW_FLOAT:
5478 mCaps.vertexLowpFloat.get(range, precision);
5479 break;
5480 case GL_MEDIUM_FLOAT:
5481 mCaps.vertexMediumpFloat.get(range, precision);
5482 break;
5483 case GL_HIGH_FLOAT:
5484 mCaps.vertexHighpFloat.get(range, precision);
5485 break;
5486
5487 case GL_LOW_INT:
5488 mCaps.vertexLowpInt.get(range, precision);
5489 break;
5490 case GL_MEDIUM_INT:
5491 mCaps.vertexMediumpInt.get(range, precision);
5492 break;
5493 case GL_HIGH_INT:
5494 mCaps.vertexHighpInt.get(range, precision);
5495 break;
5496
5497 default:
5498 UNREACHABLE();
5499 return;
5500 }
5501 break;
5502
5503 case GL_FRAGMENT_SHADER:
5504 switch (precisiontype)
5505 {
5506 case GL_LOW_FLOAT:
5507 mCaps.fragmentLowpFloat.get(range, precision);
5508 break;
5509 case GL_MEDIUM_FLOAT:
5510 mCaps.fragmentMediumpFloat.get(range, precision);
5511 break;
5512 case GL_HIGH_FLOAT:
5513 mCaps.fragmentHighpFloat.get(range, precision);
5514 break;
5515
5516 case GL_LOW_INT:
5517 mCaps.fragmentLowpInt.get(range, precision);
5518 break;
5519 case GL_MEDIUM_INT:
5520 mCaps.fragmentMediumpInt.get(range, precision);
5521 break;
5522 case GL_HIGH_INT:
5523 mCaps.fragmentHighpInt.get(range, precision);
5524 break;
5525
5526 default:
5527 UNREACHABLE();
5528 return;
5529 }
5530 break;
5531
5532 default:
5533 UNREACHABLE();
5534 return;
5535 }
5536}
5537
5538void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5539{
5540 Shader *shaderObject = getShader(shader);
5541 ASSERT(shaderObject);
5542 shaderObject->getSource(bufsize, length, source);
5543}
5544
5545void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5546{
5547 Program *programObject = getProgram(program);
5548 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005549 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005550}
5551
Brandon Jones59770802018-04-02 13:18:42 -07005552void Context::getUniformfvRobust(GLuint program,
5553 GLint location,
5554 GLsizei bufSize,
5555 GLsizei *length,
5556 GLfloat *params)
5557{
5558 getUniformfv(program, location, params);
5559}
5560
Jamie Madillc1d770e2017-04-13 17:31:24 -04005561void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5562{
5563 Program *programObject = getProgram(program);
5564 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005565 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005566}
5567
Brandon Jones59770802018-04-02 13:18:42 -07005568void Context::getUniformivRobust(GLuint program,
5569 GLint location,
5570 GLsizei bufSize,
5571 GLsizei *length,
5572 GLint *params)
5573{
5574 getUniformiv(program, location, params);
5575}
5576
Jamie Madillc1d770e2017-04-13 17:31:24 -04005577GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5578{
5579 Program *programObject = getProgram(program);
5580 ASSERT(programObject);
5581 return programObject->getUniformLocation(name);
5582}
5583
5584GLboolean Context::isBuffer(GLuint buffer)
5585{
5586 if (buffer == 0)
5587 {
5588 return GL_FALSE;
5589 }
5590
5591 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5592}
5593
5594GLboolean Context::isEnabled(GLenum cap)
5595{
5596 return mGLState.getEnableFeature(cap);
5597}
5598
5599GLboolean Context::isFramebuffer(GLuint framebuffer)
5600{
5601 if (framebuffer == 0)
5602 {
5603 return GL_FALSE;
5604 }
5605
5606 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5607}
5608
5609GLboolean Context::isProgram(GLuint program)
5610{
5611 if (program == 0)
5612 {
5613 return GL_FALSE;
5614 }
5615
5616 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5617}
5618
5619GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5620{
5621 if (renderbuffer == 0)
5622 {
5623 return GL_FALSE;
5624 }
5625
5626 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5627}
5628
5629GLboolean Context::isShader(GLuint shader)
5630{
5631 if (shader == 0)
5632 {
5633 return GL_FALSE;
5634 }
5635
5636 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5637}
5638
5639GLboolean Context::isTexture(GLuint texture)
5640{
5641 if (texture == 0)
5642 {
5643 return GL_FALSE;
5644 }
5645
5646 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5647}
5648
5649void Context::linkProgram(GLuint program)
5650{
5651 Program *programObject = getProgram(program);
5652 ASSERT(programObject);
5653 handleError(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005654
5655 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5656 // don't need to worry that:
5657 // 1. Draw calls after link use the new executable code or the old one depending on the link
5658 // result.
5659 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5660 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5661 // ProgramD3D.
5662 if (programObject->isInUse())
5663 {
5664 // isLinked() which forces to resolve linking, will be called.
5665 mGLState.onProgramExecutableChange(programObject);
5666 mStateCache.onProgramExecutableChange(this);
5667 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005668}
5669
5670void Context::releaseShaderCompiler()
5671{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005672 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005673}
5674
5675void Context::shaderBinary(GLsizei n,
5676 const GLuint *shaders,
5677 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005678 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005679 GLsizei length)
5680{
5681 // No binary shader formats are supported.
5682 UNIMPLEMENTED();
5683}
5684
5685void Context::shaderSource(GLuint shader,
5686 GLsizei count,
5687 const GLchar *const *string,
5688 const GLint *length)
5689{
5690 Shader *shaderObject = getShader(shader);
5691 ASSERT(shaderObject);
5692 shaderObject->setSource(count, string, length);
5693}
5694
5695void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5696{
5697 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5698}
5699
5700void Context::stencilMask(GLuint mask)
5701{
5702 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5703}
5704
5705void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5706{
5707 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5708}
5709
5710void Context::uniform1f(GLint location, GLfloat x)
5711{
5712 Program *program = mGLState.getProgram();
5713 program->setUniform1fv(location, 1, &x);
5714}
5715
5716void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5717{
5718 Program *program = mGLState.getProgram();
5719 program->setUniform1fv(location, count, v);
5720}
5721
Jamie Madill7e4eff12018-08-08 15:49:26 -04005722void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005723{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005724 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04005725 {
5726 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04005727 mStateCache.onActiveTextureChange(this);
Jamie Madill81c2e252017-09-09 23:32:46 -04005728 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005729}
5730
Jamie Madill7e4eff12018-08-08 15:49:26 -04005731void Context::uniform1i(GLint location, GLint x)
5732{
5733 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
5734}
5735
Jamie Madillc1d770e2017-04-13 17:31:24 -04005736void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5737{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005738 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005739}
5740
5741void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5742{
5743 GLfloat xy[2] = {x, y};
5744 Program *program = mGLState.getProgram();
5745 program->setUniform2fv(location, 1, xy);
5746}
5747
5748void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5749{
5750 Program *program = mGLState.getProgram();
5751 program->setUniform2fv(location, count, v);
5752}
5753
5754void Context::uniform2i(GLint location, GLint x, GLint y)
5755{
5756 GLint xy[2] = {x, y};
5757 Program *program = mGLState.getProgram();
5758 program->setUniform2iv(location, 1, xy);
5759}
5760
5761void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5762{
5763 Program *program = mGLState.getProgram();
5764 program->setUniform2iv(location, count, v);
5765}
5766
5767void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5768{
5769 GLfloat xyz[3] = {x, y, z};
5770 Program *program = mGLState.getProgram();
5771 program->setUniform3fv(location, 1, xyz);
5772}
5773
5774void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5775{
5776 Program *program = mGLState.getProgram();
5777 program->setUniform3fv(location, count, v);
5778}
5779
5780void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5781{
5782 GLint xyz[3] = {x, y, z};
5783 Program *program = mGLState.getProgram();
5784 program->setUniform3iv(location, 1, xyz);
5785}
5786
5787void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5788{
5789 Program *program = mGLState.getProgram();
5790 program->setUniform3iv(location, count, v);
5791}
5792
5793void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5794{
5795 GLfloat xyzw[4] = {x, y, z, w};
5796 Program *program = mGLState.getProgram();
5797 program->setUniform4fv(location, 1, xyzw);
5798}
5799
5800void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5801{
5802 Program *program = mGLState.getProgram();
5803 program->setUniform4fv(location, count, v);
5804}
5805
5806void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5807{
5808 GLint xyzw[4] = {x, y, z, w};
5809 Program *program = mGLState.getProgram();
5810 program->setUniform4iv(location, 1, xyzw);
5811}
5812
5813void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5814{
5815 Program *program = mGLState.getProgram();
5816 program->setUniform4iv(location, count, v);
5817}
5818
5819void Context::uniformMatrix2fv(GLint location,
5820 GLsizei count,
5821 GLboolean transpose,
5822 const GLfloat *value)
5823{
5824 Program *program = mGLState.getProgram();
5825 program->setUniformMatrix2fv(location, count, transpose, value);
5826}
5827
5828void Context::uniformMatrix3fv(GLint location,
5829 GLsizei count,
5830 GLboolean transpose,
5831 const GLfloat *value)
5832{
5833 Program *program = mGLState.getProgram();
5834 program->setUniformMatrix3fv(location, count, transpose, value);
5835}
5836
5837void Context::uniformMatrix4fv(GLint location,
5838 GLsizei count,
5839 GLboolean transpose,
5840 const GLfloat *value)
5841{
5842 Program *program = mGLState.getProgram();
5843 program->setUniformMatrix4fv(location, count, transpose, value);
5844}
5845
5846void Context::validateProgram(GLuint program)
5847{
5848 Program *programObject = getProgram(program);
5849 ASSERT(programObject);
5850 programObject->validate(mCaps);
5851}
5852
Jiajia Qin5451d532017-11-16 17:16:34 +08005853void Context::validateProgramPipeline(GLuint pipeline)
5854{
5855 UNIMPLEMENTED();
5856}
5857
Jamie Madilld04908b2017-06-09 14:15:35 -04005858void Context::getProgramBinary(GLuint program,
5859 GLsizei bufSize,
5860 GLsizei *length,
5861 GLenum *binaryFormat,
5862 void *binary)
5863{
5864 Program *programObject = getProgram(program);
5865 ASSERT(programObject != nullptr);
5866
5867 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5868}
5869
5870void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5871{
5872 Program *programObject = getProgram(program);
5873 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005874
Jamie Madilld04908b2017-06-09 14:15:35 -04005875 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madillc43cdad2018-08-08 15:49:25 -04005876 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04005877 if (programObject->isInUse())
5878 {
5879 mGLState.setObjectDirty(GL_PROGRAM);
5880 }
Jamie Madilld04908b2017-06-09 14:15:35 -04005881}
5882
Jamie Madillff325f12017-08-26 15:06:05 -04005883void Context::uniform1ui(GLint location, GLuint v0)
5884{
5885 Program *program = mGLState.getProgram();
5886 program->setUniform1uiv(location, 1, &v0);
5887}
5888
5889void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5890{
5891 Program *program = mGLState.getProgram();
5892 const GLuint xy[] = {v0, v1};
5893 program->setUniform2uiv(location, 1, xy);
5894}
5895
5896void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5897{
5898 Program *program = mGLState.getProgram();
5899 const GLuint xyz[] = {v0, v1, v2};
5900 program->setUniform3uiv(location, 1, xyz);
5901}
5902
5903void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5904{
5905 Program *program = mGLState.getProgram();
5906 const GLuint xyzw[] = {v0, v1, v2, v3};
5907 program->setUniform4uiv(location, 1, xyzw);
5908}
5909
5910void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5911{
5912 Program *program = mGLState.getProgram();
5913 program->setUniform1uiv(location, count, value);
5914}
5915void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5916{
5917 Program *program = mGLState.getProgram();
5918 program->setUniform2uiv(location, count, value);
5919}
5920
5921void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5922{
5923 Program *program = mGLState.getProgram();
5924 program->setUniform3uiv(location, count, value);
5925}
5926
5927void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5928{
5929 Program *program = mGLState.getProgram();
5930 program->setUniform4uiv(location, count, value);
5931}
5932
Jamie Madillf0e04492017-08-26 15:28:42 -04005933void Context::genQueries(GLsizei n, GLuint *ids)
5934{
5935 for (GLsizei i = 0; i < n; i++)
5936 {
5937 GLuint handle = mQueryHandleAllocator.allocate();
5938 mQueryMap.assign(handle, nullptr);
5939 ids[i] = handle;
5940 }
5941}
5942
5943void Context::deleteQueries(GLsizei n, const GLuint *ids)
5944{
5945 for (int i = 0; i < n; i++)
5946 {
5947 GLuint query = ids[i];
5948
5949 Query *queryObject = nullptr;
5950 if (mQueryMap.erase(query, &queryObject))
5951 {
5952 mQueryHandleAllocator.release(query);
5953 if (queryObject)
5954 {
5955 queryObject->release(this);
5956 }
5957 }
5958 }
5959}
5960
5961GLboolean Context::isQuery(GLuint id)
5962{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005963 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005964}
5965
Jamie Madillc8c95812017-08-26 18:40:09 -04005966void Context::uniformMatrix2x3fv(GLint location,
5967 GLsizei count,
5968 GLboolean transpose,
5969 const GLfloat *value)
5970{
5971 Program *program = mGLState.getProgram();
5972 program->setUniformMatrix2x3fv(location, count, transpose, value);
5973}
5974
5975void Context::uniformMatrix3x2fv(GLint location,
5976 GLsizei count,
5977 GLboolean transpose,
5978 const GLfloat *value)
5979{
5980 Program *program = mGLState.getProgram();
5981 program->setUniformMatrix3x2fv(location, count, transpose, value);
5982}
5983
5984void Context::uniformMatrix2x4fv(GLint location,
5985 GLsizei count,
5986 GLboolean transpose,
5987 const GLfloat *value)
5988{
5989 Program *program = mGLState.getProgram();
5990 program->setUniformMatrix2x4fv(location, count, transpose, value);
5991}
5992
5993void Context::uniformMatrix4x2fv(GLint location,
5994 GLsizei count,
5995 GLboolean transpose,
5996 const GLfloat *value)
5997{
5998 Program *program = mGLState.getProgram();
5999 program->setUniformMatrix4x2fv(location, count, transpose, value);
6000}
6001
6002void Context::uniformMatrix3x4fv(GLint location,
6003 GLsizei count,
6004 GLboolean transpose,
6005 const GLfloat *value)
6006{
6007 Program *program = mGLState.getProgram();
6008 program->setUniformMatrix3x4fv(location, count, transpose, value);
6009}
6010
6011void Context::uniformMatrix4x3fv(GLint location,
6012 GLsizei count,
6013 GLboolean transpose,
6014 const GLfloat *value)
6015{
6016 Program *program = mGLState.getProgram();
6017 program->setUniformMatrix4x3fv(location, count, transpose, value);
6018}
6019
Jamie Madilld7576732017-08-26 18:49:50 -04006020void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6021{
6022 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6023 {
6024 GLuint vertexArray = arrays[arrayIndex];
6025
6026 if (arrays[arrayIndex] != 0)
6027 {
6028 VertexArray *vertexArrayObject = nullptr;
6029 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6030 {
6031 if (vertexArrayObject != nullptr)
6032 {
6033 detachVertexArray(vertexArray);
6034 vertexArrayObject->onDestroy(this);
6035 }
6036
6037 mVertexArrayHandleAllocator.release(vertexArray);
6038 }
6039 }
6040 }
6041}
6042
6043void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6044{
6045 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6046 {
6047 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6048 mVertexArrayMap.assign(vertexArray, nullptr);
6049 arrays[arrayIndex] = vertexArray;
6050 }
6051}
6052
6053bool Context::isVertexArray(GLuint array)
6054{
6055 if (array == 0)
6056 {
6057 return GL_FALSE;
6058 }
6059
6060 VertexArray *vao = getVertexArray(array);
6061 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6062}
6063
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006064void Context::endTransformFeedback()
6065{
6066 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6067 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006068 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006069}
6070
6071void Context::transformFeedbackVaryings(GLuint program,
6072 GLsizei count,
6073 const GLchar *const *varyings,
6074 GLenum bufferMode)
6075{
6076 Program *programObject = getProgram(program);
6077 ASSERT(programObject);
6078 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6079}
6080
6081void Context::getTransformFeedbackVarying(GLuint program,
6082 GLuint index,
6083 GLsizei bufSize,
6084 GLsizei *length,
6085 GLsizei *size,
6086 GLenum *type,
6087 GLchar *name)
6088{
6089 Program *programObject = getProgram(program);
6090 ASSERT(programObject);
6091 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6092}
6093
6094void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6095{
6096 for (int i = 0; i < n; i++)
6097 {
6098 GLuint transformFeedback = ids[i];
6099 if (transformFeedback == 0)
6100 {
6101 continue;
6102 }
6103
6104 TransformFeedback *transformFeedbackObject = nullptr;
6105 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6106 {
6107 if (transformFeedbackObject != nullptr)
6108 {
6109 detachTransformFeedback(transformFeedback);
6110 transformFeedbackObject->release(this);
6111 }
6112
6113 mTransformFeedbackHandleAllocator.release(transformFeedback);
6114 }
6115 }
6116}
6117
6118void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6119{
6120 for (int i = 0; i < n; i++)
6121 {
6122 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6123 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6124 ids[i] = transformFeedback;
6125 }
6126}
6127
6128bool Context::isTransformFeedback(GLuint id)
6129{
6130 if (id == 0)
6131 {
6132 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6133 // returns FALSE
6134 return GL_FALSE;
6135 }
6136
6137 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6138 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6139}
6140
6141void Context::pauseTransformFeedback()
6142{
6143 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6144 transformFeedback->pause();
6145}
6146
6147void Context::resumeTransformFeedback()
6148{
6149 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6150 transformFeedback->resume();
6151}
6152
Jamie Madill12e957f2017-08-26 21:42:26 -04006153void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6154{
6155 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006156 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006157}
6158
Brandon Jones59770802018-04-02 13:18:42 -07006159void Context::getUniformuivRobust(GLuint program,
6160 GLint location,
6161 GLsizei bufSize,
6162 GLsizei *length,
6163 GLuint *params)
6164{
6165 getUniformuiv(program, location, params);
6166}
6167
Jamie Madill12e957f2017-08-26 21:42:26 -04006168GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6169{
6170 const Program *programObject = getProgram(program);
6171 return programObject->getFragDataLocation(name);
6172}
6173
6174void Context::getUniformIndices(GLuint program,
6175 GLsizei uniformCount,
6176 const GLchar *const *uniformNames,
6177 GLuint *uniformIndices)
6178{
6179 const Program *programObject = getProgram(program);
6180 if (!programObject->isLinked())
6181 {
6182 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6183 {
6184 uniformIndices[uniformId] = GL_INVALID_INDEX;
6185 }
6186 }
6187 else
6188 {
6189 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6190 {
6191 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6192 }
6193 }
6194}
6195
6196void Context::getActiveUniformsiv(GLuint program,
6197 GLsizei uniformCount,
6198 const GLuint *uniformIndices,
6199 GLenum pname,
6200 GLint *params)
6201{
6202 const Program *programObject = getProgram(program);
6203 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6204 {
6205 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006206 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006207 }
6208}
6209
6210GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6211{
6212 const Program *programObject = getProgram(program);
6213 return programObject->getUniformBlockIndex(uniformBlockName);
6214}
6215
6216void Context::getActiveUniformBlockiv(GLuint program,
6217 GLuint uniformBlockIndex,
6218 GLenum pname,
6219 GLint *params)
6220{
6221 const Program *programObject = getProgram(program);
6222 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6223}
6224
Brandon Jones59770802018-04-02 13:18:42 -07006225void Context::getActiveUniformBlockivRobust(GLuint program,
6226 GLuint uniformBlockIndex,
6227 GLenum pname,
6228 GLsizei bufSize,
6229 GLsizei *length,
6230 GLint *params)
6231{
6232 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6233}
6234
Jamie Madill12e957f2017-08-26 21:42:26 -04006235void Context::getActiveUniformBlockName(GLuint program,
6236 GLuint uniformBlockIndex,
6237 GLsizei bufSize,
6238 GLsizei *length,
6239 GLchar *uniformBlockName)
6240{
6241 const Program *programObject = getProgram(program);
6242 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6243}
6244
6245void Context::uniformBlockBinding(GLuint program,
6246 GLuint uniformBlockIndex,
6247 GLuint uniformBlockBinding)
6248{
6249 Program *programObject = getProgram(program);
6250 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006251
6252 if (programObject->isInUse())
6253 {
6254 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006255 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006256 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006257}
6258
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006259GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6260{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006261 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6262 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006263
Jamie Madill70b5bb02017-08-28 13:32:37 -04006264 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006265 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006266 if (error.isError())
6267 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006268 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006269 handleError(error);
6270 return nullptr;
6271 }
6272
Jamie Madill70b5bb02017-08-28 13:32:37 -04006273 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006274}
6275
6276GLboolean Context::isSync(GLsync sync)
6277{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006278 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006279}
6280
6281GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6282{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006283 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006284
6285 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006286 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006287 return result;
6288}
6289
6290void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6291{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006292 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006293 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006294}
6295
6296void Context::getInteger64v(GLenum pname, GLint64 *params)
6297{
6298 GLenum nativeType = GL_NONE;
6299 unsigned int numParams = 0;
6300 getQueryParameterInfo(pname, &nativeType, &numParams);
6301
6302 if (nativeType == GL_INT_64_ANGLEX)
6303 {
6304 getInteger64vImpl(pname, params);
6305 }
6306 else
6307 {
6308 CastStateValues(this, nativeType, pname, numParams, params);
6309 }
6310}
6311
Brandon Jones59770802018-04-02 13:18:42 -07006312void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6313{
6314 getInteger64v(pname, data);
6315}
6316
Corentin Wallez336129f2017-10-17 15:55:40 -04006317void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006318{
6319 Buffer *buffer = mGLState.getTargetBuffer(target);
6320 QueryBufferParameteri64v(buffer, pname, params);
6321}
6322
Brandon Jones59770802018-04-02 13:18:42 -07006323void Context::getBufferParameteri64vRobust(BufferBinding target,
6324 GLenum pname,
6325 GLsizei bufSize,
6326 GLsizei *length,
6327 GLint64 *params)
6328{
6329 getBufferParameteri64v(target, pname, params);
6330}
6331
Jamie Madill3ef140a2017-08-26 23:11:21 -04006332void Context::genSamplers(GLsizei count, GLuint *samplers)
6333{
6334 for (int i = 0; i < count; i++)
6335 {
6336 samplers[i] = mState.mSamplers->createSampler();
6337 }
6338}
6339
6340void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6341{
6342 for (int i = 0; i < count; i++)
6343 {
6344 GLuint sampler = samplers[i];
6345
6346 if (mState.mSamplers->getSampler(sampler))
6347 {
6348 detachSampler(sampler);
6349 }
6350
6351 mState.mSamplers->deleteObject(this, sampler);
6352 }
6353}
6354
6355void Context::getInternalformativ(GLenum target,
6356 GLenum internalformat,
6357 GLenum pname,
6358 GLsizei bufSize,
6359 GLint *params)
6360{
6361 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6362 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6363}
6364
Brandon Jones59770802018-04-02 13:18:42 -07006365void Context::getInternalformativRobust(GLenum target,
6366 GLenum internalformat,
6367 GLenum pname,
6368 GLsizei bufSize,
6369 GLsizei *length,
6370 GLint *params)
6371{
6372 getInternalformativ(target, internalformat, pname, bufSize, params);
6373}
6374
Jiajia Qin5451d532017-11-16 17:16:34 +08006375void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6376{
6377 programUniform1iv(program, location, 1, &v0);
6378}
6379
6380void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6381{
6382 GLint xy[2] = {v0, v1};
6383 programUniform2iv(program, location, 1, xy);
6384}
6385
6386void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6387{
6388 GLint xyz[3] = {v0, v1, v2};
6389 programUniform3iv(program, location, 1, xyz);
6390}
6391
6392void Context::programUniform4i(GLuint program,
6393 GLint location,
6394 GLint v0,
6395 GLint v1,
6396 GLint v2,
6397 GLint v3)
6398{
6399 GLint xyzw[4] = {v0, v1, v2, v3};
6400 programUniform4iv(program, location, 1, xyzw);
6401}
6402
6403void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6404{
6405 programUniform1uiv(program, location, 1, &v0);
6406}
6407
6408void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6409{
6410 GLuint xy[2] = {v0, v1};
6411 programUniform2uiv(program, location, 1, xy);
6412}
6413
6414void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6415{
6416 GLuint xyz[3] = {v0, v1, v2};
6417 programUniform3uiv(program, location, 1, xyz);
6418}
6419
6420void Context::programUniform4ui(GLuint program,
6421 GLint location,
6422 GLuint v0,
6423 GLuint v1,
6424 GLuint v2,
6425 GLuint v3)
6426{
6427 GLuint xyzw[4] = {v0, v1, v2, v3};
6428 programUniform4uiv(program, location, 1, xyzw);
6429}
6430
6431void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6432{
6433 programUniform1fv(program, location, 1, &v0);
6434}
6435
6436void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6437{
6438 GLfloat xy[2] = {v0, v1};
6439 programUniform2fv(program, location, 1, xy);
6440}
6441
6442void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6443{
6444 GLfloat xyz[3] = {v0, v1, v2};
6445 programUniform3fv(program, location, 1, xyz);
6446}
6447
6448void Context::programUniform4f(GLuint program,
6449 GLint location,
6450 GLfloat v0,
6451 GLfloat v1,
6452 GLfloat v2,
6453 GLfloat v3)
6454{
6455 GLfloat xyzw[4] = {v0, v1, v2, v3};
6456 programUniform4fv(program, location, 1, xyzw);
6457}
6458
Jamie Madill81c2e252017-09-09 23:32:46 -04006459void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6460{
6461 Program *programObject = getProgram(program);
6462 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006463 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006464}
6465
Jiajia Qin5451d532017-11-16 17:16:34 +08006466void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6467{
6468 Program *programObject = getProgram(program);
6469 ASSERT(programObject);
6470 programObject->setUniform2iv(location, count, value);
6471}
6472
6473void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6474{
6475 Program *programObject = getProgram(program);
6476 ASSERT(programObject);
6477 programObject->setUniform3iv(location, count, value);
6478}
6479
6480void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6481{
6482 Program *programObject = getProgram(program);
6483 ASSERT(programObject);
6484 programObject->setUniform4iv(location, count, value);
6485}
6486
6487void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6488{
6489 Program *programObject = getProgram(program);
6490 ASSERT(programObject);
6491 programObject->setUniform1uiv(location, count, value);
6492}
6493
6494void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6495{
6496 Program *programObject = getProgram(program);
6497 ASSERT(programObject);
6498 programObject->setUniform2uiv(location, count, value);
6499}
6500
6501void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6502{
6503 Program *programObject = getProgram(program);
6504 ASSERT(programObject);
6505 programObject->setUniform3uiv(location, count, value);
6506}
6507
6508void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6509{
6510 Program *programObject = getProgram(program);
6511 ASSERT(programObject);
6512 programObject->setUniform4uiv(location, count, value);
6513}
6514
6515void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6516{
6517 Program *programObject = getProgram(program);
6518 ASSERT(programObject);
6519 programObject->setUniform1fv(location, count, value);
6520}
6521
6522void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6523{
6524 Program *programObject = getProgram(program);
6525 ASSERT(programObject);
6526 programObject->setUniform2fv(location, count, value);
6527}
6528
6529void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6530{
6531 Program *programObject = getProgram(program);
6532 ASSERT(programObject);
6533 programObject->setUniform3fv(location, count, value);
6534}
6535
6536void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6537{
6538 Program *programObject = getProgram(program);
6539 ASSERT(programObject);
6540 programObject->setUniform4fv(location, count, value);
6541}
6542
6543void Context::programUniformMatrix2fv(GLuint program,
6544 GLint location,
6545 GLsizei count,
6546 GLboolean transpose,
6547 const GLfloat *value)
6548{
6549 Program *programObject = getProgram(program);
6550 ASSERT(programObject);
6551 programObject->setUniformMatrix2fv(location, count, transpose, value);
6552}
6553
6554void Context::programUniformMatrix3fv(GLuint program,
6555 GLint location,
6556 GLsizei count,
6557 GLboolean transpose,
6558 const GLfloat *value)
6559{
6560 Program *programObject = getProgram(program);
6561 ASSERT(programObject);
6562 programObject->setUniformMatrix3fv(location, count, transpose, value);
6563}
6564
6565void Context::programUniformMatrix4fv(GLuint program,
6566 GLint location,
6567 GLsizei count,
6568 GLboolean transpose,
6569 const GLfloat *value)
6570{
6571 Program *programObject = getProgram(program);
6572 ASSERT(programObject);
6573 programObject->setUniformMatrix4fv(location, count, transpose, value);
6574}
6575
6576void Context::programUniformMatrix2x3fv(GLuint program,
6577 GLint location,
6578 GLsizei count,
6579 GLboolean transpose,
6580 const GLfloat *value)
6581{
6582 Program *programObject = getProgram(program);
6583 ASSERT(programObject);
6584 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6585}
6586
6587void Context::programUniformMatrix3x2fv(GLuint program,
6588 GLint location,
6589 GLsizei count,
6590 GLboolean transpose,
6591 const GLfloat *value)
6592{
6593 Program *programObject = getProgram(program);
6594 ASSERT(programObject);
6595 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6596}
6597
6598void Context::programUniformMatrix2x4fv(GLuint program,
6599 GLint location,
6600 GLsizei count,
6601 GLboolean transpose,
6602 const GLfloat *value)
6603{
6604 Program *programObject = getProgram(program);
6605 ASSERT(programObject);
6606 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6607}
6608
6609void Context::programUniformMatrix4x2fv(GLuint program,
6610 GLint location,
6611 GLsizei count,
6612 GLboolean transpose,
6613 const GLfloat *value)
6614{
6615 Program *programObject = getProgram(program);
6616 ASSERT(programObject);
6617 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6618}
6619
6620void Context::programUniformMatrix3x4fv(GLuint program,
6621 GLint location,
6622 GLsizei count,
6623 GLboolean transpose,
6624 const GLfloat *value)
6625{
6626 Program *programObject = getProgram(program);
6627 ASSERT(programObject);
6628 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6629}
6630
6631void Context::programUniformMatrix4x3fv(GLuint program,
6632 GLint location,
6633 GLsizei count,
6634 GLboolean transpose,
6635 const GLfloat *value)
6636{
6637 Program *programObject = getProgram(program);
6638 ASSERT(programObject);
6639 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6640}
6641
Jamie Madill81c2e252017-09-09 23:32:46 -04006642void Context::onTextureChange(const Texture *texture)
6643{
6644 // Conservatively assume all textures are dirty.
6645 // TODO(jmadill): More fine-grained update.
6646 mGLState.setObjectDirty(GL_TEXTURE);
6647}
6648
James Darpiniane8a93c62018-01-04 18:02:24 -08006649bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6650{
6651 return mGLState.isCurrentTransformFeedback(tf);
6652}
James Darpiniane8a93c62018-01-04 18:02:24 -08006653
Yunchao Hea336b902017-08-02 16:05:21 +08006654void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6655{
6656 for (int i = 0; i < count; i++)
6657 {
6658 pipelines[i] = createProgramPipeline();
6659 }
6660}
6661
6662void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6663{
6664 for (int i = 0; i < count; i++)
6665 {
6666 if (pipelines[i] != 0)
6667 {
6668 deleteProgramPipeline(pipelines[i]);
6669 }
6670 }
6671}
6672
6673GLboolean Context::isProgramPipeline(GLuint pipeline)
6674{
6675 if (pipeline == 0)
6676 {
6677 return GL_FALSE;
6678 }
6679
6680 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6681}
6682
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006683void Context::finishFenceNV(GLuint fence)
6684{
6685 FenceNV *fenceObject = getFenceNV(fence);
6686
6687 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006688 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006689}
6690
6691void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6692{
6693 FenceNV *fenceObject = getFenceNV(fence);
6694
6695 ASSERT(fenceObject && fenceObject->isSet());
6696
6697 switch (pname)
6698 {
6699 case GL_FENCE_STATUS_NV:
6700 {
6701 // GL_NV_fence spec:
6702 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6703 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6704 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6705 GLboolean status = GL_TRUE;
6706 if (fenceObject->getStatus() != GL_TRUE)
6707 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006708 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006709 }
6710 *params = status;
6711 break;
6712 }
6713
6714 case GL_FENCE_CONDITION_NV:
6715 {
6716 *params = static_cast<GLint>(fenceObject->getCondition());
6717 break;
6718 }
6719
6720 default:
6721 UNREACHABLE();
6722 }
6723}
6724
6725void Context::getTranslatedShaderSource(GLuint shader,
6726 GLsizei bufsize,
6727 GLsizei *length,
6728 GLchar *source)
6729{
6730 Shader *shaderObject = getShader(shader);
6731 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006732 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006733}
6734
6735void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6736{
6737 Program *programObject = getProgram(program);
6738 ASSERT(programObject);
6739
6740 programObject->getUniformfv(this, location, params);
6741}
6742
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006743void Context::getnUniformfvRobust(GLuint program,
6744 GLint location,
6745 GLsizei bufSize,
6746 GLsizei *length,
6747 GLfloat *params)
6748{
6749 UNIMPLEMENTED();
6750}
6751
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006752void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6753{
6754 Program *programObject = getProgram(program);
6755 ASSERT(programObject);
6756
6757 programObject->getUniformiv(this, location, params);
6758}
6759
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006760void Context::getnUniformivRobust(GLuint program,
6761 GLint location,
6762 GLsizei bufSize,
6763 GLsizei *length,
6764 GLint *params)
6765{
6766 UNIMPLEMENTED();
6767}
6768
6769void Context::getnUniformuivRobust(GLuint program,
6770 GLint location,
6771 GLsizei bufSize,
6772 GLsizei *length,
6773 GLuint *params)
6774{
6775 UNIMPLEMENTED();
6776}
6777
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006778GLboolean Context::isFenceNV(GLuint fence)
6779{
6780 FenceNV *fenceObject = getFenceNV(fence);
6781
6782 if (fenceObject == nullptr)
6783 {
6784 return GL_FALSE;
6785 }
6786
6787 // GL_NV_fence spec:
6788 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6789 // existing fence.
6790 return fenceObject->isSet();
6791}
6792
6793void Context::readnPixels(GLint x,
6794 GLint y,
6795 GLsizei width,
6796 GLsizei height,
6797 GLenum format,
6798 GLenum type,
6799 GLsizei bufSize,
6800 void *data)
6801{
6802 return readPixels(x, y, width, height, format, type, data);
6803}
6804
Jamie Madill007530e2017-12-28 14:27:04 -05006805void Context::setFenceNV(GLuint fence, GLenum condition)
6806{
6807 ASSERT(condition == GL_ALL_COMPLETED_NV);
6808
6809 FenceNV *fenceObject = getFenceNV(fence);
6810 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006811 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006812}
6813
6814GLboolean Context::testFenceNV(GLuint fence)
6815{
6816 FenceNV *fenceObject = getFenceNV(fence);
6817
6818 ASSERT(fenceObject != nullptr);
6819 ASSERT(fenceObject->isSet() == GL_TRUE);
6820
6821 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006822 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006823 if (error.isError())
6824 {
6825 handleError(error);
6826 return GL_TRUE;
6827 }
6828
6829 return result;
6830}
6831
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006832void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006833{
6834 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006835 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006836 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006837}
6838
Jamie Madillfa920eb2018-01-04 11:45:50 -05006839void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006840{
6841 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006842 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006843 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6844}
6845
Jamie Madillfa920eb2018-01-04 11:45:50 -05006846void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6847{
6848 UNIMPLEMENTED();
6849}
6850
Jamie Madill5b772312018-03-08 20:28:32 -05006851bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6852{
6853 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6854 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6855 // to the fact that it is stored internally as a float, and so would require conversion
6856 // if returned from Context::getIntegerv. Since this conversion is already implemented
6857 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6858 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6859 // application.
6860 switch (pname)
6861 {
6862 case GL_COMPRESSED_TEXTURE_FORMATS:
6863 {
6864 *type = GL_INT;
6865 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6866 return true;
6867 }
6868 case GL_SHADER_BINARY_FORMATS:
6869 {
6870 *type = GL_INT;
6871 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6872 return true;
6873 }
6874
6875 case GL_MAX_VERTEX_ATTRIBS:
6876 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6877 case GL_MAX_VARYING_VECTORS:
6878 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6879 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6880 case GL_MAX_TEXTURE_IMAGE_UNITS:
6881 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6882 case GL_MAX_RENDERBUFFER_SIZE:
6883 case GL_NUM_SHADER_BINARY_FORMATS:
6884 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6885 case GL_ARRAY_BUFFER_BINDING:
6886 case GL_FRAMEBUFFER_BINDING:
6887 case GL_RENDERBUFFER_BINDING:
6888 case GL_CURRENT_PROGRAM:
6889 case GL_PACK_ALIGNMENT:
6890 case GL_UNPACK_ALIGNMENT:
6891 case GL_GENERATE_MIPMAP_HINT:
6892 case GL_RED_BITS:
6893 case GL_GREEN_BITS:
6894 case GL_BLUE_BITS:
6895 case GL_ALPHA_BITS:
6896 case GL_DEPTH_BITS:
6897 case GL_STENCIL_BITS:
6898 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6899 case GL_CULL_FACE_MODE:
6900 case GL_FRONT_FACE:
6901 case GL_ACTIVE_TEXTURE:
6902 case GL_STENCIL_FUNC:
6903 case GL_STENCIL_VALUE_MASK:
6904 case GL_STENCIL_REF:
6905 case GL_STENCIL_FAIL:
6906 case GL_STENCIL_PASS_DEPTH_FAIL:
6907 case GL_STENCIL_PASS_DEPTH_PASS:
6908 case GL_STENCIL_BACK_FUNC:
6909 case GL_STENCIL_BACK_VALUE_MASK:
6910 case GL_STENCIL_BACK_REF:
6911 case GL_STENCIL_BACK_FAIL:
6912 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6913 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6914 case GL_DEPTH_FUNC:
6915 case GL_BLEND_SRC_RGB:
6916 case GL_BLEND_SRC_ALPHA:
6917 case GL_BLEND_DST_RGB:
6918 case GL_BLEND_DST_ALPHA:
6919 case GL_BLEND_EQUATION_RGB:
6920 case GL_BLEND_EQUATION_ALPHA:
6921 case GL_STENCIL_WRITEMASK:
6922 case GL_STENCIL_BACK_WRITEMASK:
6923 case GL_STENCIL_CLEAR_VALUE:
6924 case GL_SUBPIXEL_BITS:
6925 case GL_MAX_TEXTURE_SIZE:
6926 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6927 case GL_SAMPLE_BUFFERS:
6928 case GL_SAMPLES:
6929 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6930 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6931 case GL_TEXTURE_BINDING_2D:
6932 case GL_TEXTURE_BINDING_CUBE_MAP:
6933 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6934 {
6935 *type = GL_INT;
6936 *numParams = 1;
6937 return true;
6938 }
6939 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6940 {
6941 if (!getExtensions().packReverseRowOrder)
6942 {
6943 return false;
6944 }
6945 *type = GL_INT;
6946 *numParams = 1;
6947 return true;
6948 }
6949 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6950 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6951 {
6952 if (!getExtensions().textureRectangle)
6953 {
6954 return false;
6955 }
6956 *type = GL_INT;
6957 *numParams = 1;
6958 return true;
6959 }
6960 case GL_MAX_DRAW_BUFFERS_EXT:
6961 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6962 {
6963 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6964 {
6965 return false;
6966 }
6967 *type = GL_INT;
6968 *numParams = 1;
6969 return true;
6970 }
6971 case GL_MAX_VIEWPORT_DIMS:
6972 {
6973 *type = GL_INT;
6974 *numParams = 2;
6975 return true;
6976 }
6977 case GL_VIEWPORT:
6978 case GL_SCISSOR_BOX:
6979 {
6980 *type = GL_INT;
6981 *numParams = 4;
6982 return true;
6983 }
6984 case GL_SHADER_COMPILER:
6985 case GL_SAMPLE_COVERAGE_INVERT:
6986 case GL_DEPTH_WRITEMASK:
6987 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6988 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6989 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6990 // bool-natural
6991 case GL_SAMPLE_COVERAGE:
6992 case GL_SCISSOR_TEST:
6993 case GL_STENCIL_TEST:
6994 case GL_DEPTH_TEST:
6995 case GL_BLEND:
6996 case GL_DITHER:
6997 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6998 {
6999 *type = GL_BOOL;
7000 *numParams = 1;
7001 return true;
7002 }
7003 case GL_COLOR_WRITEMASK:
7004 {
7005 *type = GL_BOOL;
7006 *numParams = 4;
7007 return true;
7008 }
7009 case GL_POLYGON_OFFSET_FACTOR:
7010 case GL_POLYGON_OFFSET_UNITS:
7011 case GL_SAMPLE_COVERAGE_VALUE:
7012 case GL_DEPTH_CLEAR_VALUE:
7013 case GL_LINE_WIDTH:
7014 {
7015 *type = GL_FLOAT;
7016 *numParams = 1;
7017 return true;
7018 }
7019 case GL_ALIASED_LINE_WIDTH_RANGE:
7020 case GL_ALIASED_POINT_SIZE_RANGE:
7021 case GL_DEPTH_RANGE:
7022 {
7023 *type = GL_FLOAT;
7024 *numParams = 2;
7025 return true;
7026 }
7027 case GL_COLOR_CLEAR_VALUE:
7028 case GL_BLEND_COLOR:
7029 {
7030 *type = GL_FLOAT;
7031 *numParams = 4;
7032 return true;
7033 }
7034 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7035 if (!getExtensions().textureFilterAnisotropic)
7036 {
7037 return false;
7038 }
7039 *type = GL_FLOAT;
7040 *numParams = 1;
7041 return true;
7042 case GL_TIMESTAMP_EXT:
7043 if (!getExtensions().disjointTimerQuery)
7044 {
7045 return false;
7046 }
7047 *type = GL_INT_64_ANGLEX;
7048 *numParams = 1;
7049 return true;
7050 case GL_GPU_DISJOINT_EXT:
7051 if (!getExtensions().disjointTimerQuery)
7052 {
7053 return false;
7054 }
7055 *type = GL_INT;
7056 *numParams = 1;
7057 return true;
7058 case GL_COVERAGE_MODULATION_CHROMIUM:
7059 if (!getExtensions().framebufferMixedSamples)
7060 {
7061 return false;
7062 }
7063 *type = GL_INT;
7064 *numParams = 1;
7065 return true;
7066 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7067 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7068 {
7069 return false;
7070 }
7071 *type = GL_INT;
7072 *numParams = 1;
7073 return true;
7074 }
7075
7076 if (getExtensions().debug)
7077 {
7078 switch (pname)
7079 {
7080 case GL_DEBUG_LOGGED_MESSAGES:
7081 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7082 case GL_DEBUG_GROUP_STACK_DEPTH:
7083 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7084 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7085 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7086 case GL_MAX_LABEL_LENGTH:
7087 *type = GL_INT;
7088 *numParams = 1;
7089 return true;
7090
7091 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7092 case GL_DEBUG_OUTPUT:
7093 *type = GL_BOOL;
7094 *numParams = 1;
7095 return true;
7096 }
7097 }
7098
7099 if (getExtensions().multisampleCompatibility)
7100 {
7101 switch (pname)
7102 {
7103 case GL_MULTISAMPLE_EXT:
7104 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7105 *type = GL_BOOL;
7106 *numParams = 1;
7107 return true;
7108 }
7109 }
7110
7111 if (getExtensions().pathRendering)
7112 {
7113 switch (pname)
7114 {
7115 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7116 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7117 *type = GL_FLOAT;
7118 *numParams = 16;
7119 return true;
7120 }
7121 }
7122
7123 if (getExtensions().bindGeneratesResource)
7124 {
7125 switch (pname)
7126 {
7127 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7128 *type = GL_BOOL;
7129 *numParams = 1;
7130 return true;
7131 }
7132 }
7133
7134 if (getExtensions().clientArrays)
7135 {
7136 switch (pname)
7137 {
7138 case GL_CLIENT_ARRAYS_ANGLE:
7139 *type = GL_BOOL;
7140 *numParams = 1;
7141 return true;
7142 }
7143 }
7144
7145 if (getExtensions().sRGBWriteControl)
7146 {
7147 switch (pname)
7148 {
7149 case GL_FRAMEBUFFER_SRGB_EXT:
7150 *type = GL_BOOL;
7151 *numParams = 1;
7152 return true;
7153 }
7154 }
7155
7156 if (getExtensions().robustResourceInitialization &&
7157 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7158 {
7159 *type = GL_BOOL;
7160 *numParams = 1;
7161 return true;
7162 }
7163
7164 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7165 {
7166 *type = GL_BOOL;
7167 *numParams = 1;
7168 return true;
7169 }
7170
jchen1082af6202018-06-22 10:59:52 +08007171 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7172 {
7173 *type = GL_INT;
7174 *numParams = 1;
7175 return true;
7176 }
7177
Jamie Madill5b772312018-03-08 20:28:32 -05007178 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7179 switch (pname)
7180 {
7181 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7182 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7183 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7184 {
7185 return false;
7186 }
7187 *type = GL_INT;
7188 *numParams = 1;
7189 return true;
7190
7191 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7192 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7193 {
7194 return false;
7195 }
7196 *type = GL_INT;
7197 *numParams = 1;
7198 return true;
7199
7200 case GL_PROGRAM_BINARY_FORMATS_OES:
7201 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7202 {
7203 return false;
7204 }
7205 *type = GL_INT;
7206 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7207 return true;
7208
7209 case GL_PACK_ROW_LENGTH:
7210 case GL_PACK_SKIP_ROWS:
7211 case GL_PACK_SKIP_PIXELS:
7212 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7213 {
7214 return false;
7215 }
7216 *type = GL_INT;
7217 *numParams = 1;
7218 return true;
7219 case GL_UNPACK_ROW_LENGTH:
7220 case GL_UNPACK_SKIP_ROWS:
7221 case GL_UNPACK_SKIP_PIXELS:
7222 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7223 {
7224 return false;
7225 }
7226 *type = GL_INT;
7227 *numParams = 1;
7228 return true;
7229 case GL_VERTEX_ARRAY_BINDING:
7230 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7231 {
7232 return false;
7233 }
7234 *type = GL_INT;
7235 *numParams = 1;
7236 return true;
7237 case GL_PIXEL_PACK_BUFFER_BINDING:
7238 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7239 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7240 {
7241 return false;
7242 }
7243 *type = GL_INT;
7244 *numParams = 1;
7245 return true;
7246 case GL_MAX_SAMPLES:
7247 {
7248 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7249 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7250 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7251 {
7252 return false;
7253 }
7254 *type = GL_INT;
7255 *numParams = 1;
7256 return true;
7257
7258 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7259 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7260 {
7261 return false;
7262 }
7263 *type = GL_INT;
7264 *numParams = 1;
7265 return true;
7266 }
7267 }
7268
7269 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7270 {
7271 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7272 {
7273 return false;
7274 }
7275 *type = GL_INT;
7276 *numParams = 1;
7277 return true;
7278 }
7279
7280 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7281 {
7282 *type = GL_INT;
7283 *numParams = 1;
7284 return true;
7285 }
7286
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007287 if (getClientVersion() < Version(2, 0))
7288 {
7289 switch (pname)
7290 {
7291 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007292 case GL_CLIENT_ACTIVE_TEXTURE:
7293 case GL_MATRIX_MODE:
7294 case GL_MAX_TEXTURE_UNITS:
7295 case GL_MAX_MODELVIEW_STACK_DEPTH:
7296 case GL_MAX_PROJECTION_STACK_DEPTH:
7297 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007298 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007299 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007300 case GL_VERTEX_ARRAY_STRIDE:
7301 case GL_NORMAL_ARRAY_STRIDE:
7302 case GL_COLOR_ARRAY_STRIDE:
7303 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7304 case GL_VERTEX_ARRAY_SIZE:
7305 case GL_COLOR_ARRAY_SIZE:
7306 case GL_TEXTURE_COORD_ARRAY_SIZE:
7307 case GL_VERTEX_ARRAY_TYPE:
7308 case GL_NORMAL_ARRAY_TYPE:
7309 case GL_COLOR_ARRAY_TYPE:
7310 case GL_TEXTURE_COORD_ARRAY_TYPE:
7311 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7312 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7313 case GL_COLOR_ARRAY_BUFFER_BINDING:
7314 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7315 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7316 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7317 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007318 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007319 case GL_MODELVIEW_STACK_DEPTH:
7320 case GL_PROJECTION_STACK_DEPTH:
7321 case GL_TEXTURE_STACK_DEPTH:
7322 case GL_LOGIC_OP_MODE:
7323 case GL_BLEND_SRC:
7324 case GL_BLEND_DST:
7325 case GL_PERSPECTIVE_CORRECTION_HINT:
7326 case GL_POINT_SMOOTH_HINT:
7327 case GL_LINE_SMOOTH_HINT:
7328 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007329 *type = GL_INT;
7330 *numParams = 1;
7331 return true;
7332 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007333 case GL_FOG_DENSITY:
7334 case GL_FOG_START:
7335 case GL_FOG_END:
7336 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007337 case GL_POINT_SIZE:
7338 case GL_POINT_SIZE_MIN:
7339 case GL_POINT_SIZE_MAX:
7340 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007341 *type = GL_FLOAT;
7342 *numParams = 1;
7343 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007344 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007345 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007346 *type = GL_FLOAT;
7347 *numParams = 2;
7348 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007349 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007350 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007351 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007352 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007353 *type = GL_FLOAT;
7354 *numParams = 4;
7355 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007356 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007357 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007358 *type = GL_FLOAT;
7359 *numParams = 3;
7360 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007361 case GL_MODELVIEW_MATRIX:
7362 case GL_PROJECTION_MATRIX:
7363 case GL_TEXTURE_MATRIX:
7364 *type = GL_FLOAT;
7365 *numParams = 16;
7366 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007367 case GL_LIGHT_MODEL_TWO_SIDE:
7368 *type = GL_BOOL;
7369 *numParams = 1;
7370 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007371 }
7372 }
7373
Jamie Madill5b772312018-03-08 20:28:32 -05007374 if (getClientVersion() < Version(3, 0))
7375 {
7376 return false;
7377 }
7378
7379 // Check for ES3.0+ parameter names
7380 switch (pname)
7381 {
7382 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7383 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7384 case GL_UNIFORM_BUFFER_BINDING:
7385 case GL_TRANSFORM_FEEDBACK_BINDING:
7386 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7387 case GL_COPY_READ_BUFFER_BINDING:
7388 case GL_COPY_WRITE_BUFFER_BINDING:
7389 case GL_SAMPLER_BINDING:
7390 case GL_READ_BUFFER:
7391 case GL_TEXTURE_BINDING_3D:
7392 case GL_TEXTURE_BINDING_2D_ARRAY:
7393 case GL_MAX_3D_TEXTURE_SIZE:
7394 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7395 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7396 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7397 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7398 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7399 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7400 case GL_MAX_VARYING_COMPONENTS:
7401 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7402 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7403 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7404 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7405 case GL_NUM_EXTENSIONS:
7406 case GL_MAJOR_VERSION:
7407 case GL_MINOR_VERSION:
7408 case GL_MAX_ELEMENTS_INDICES:
7409 case GL_MAX_ELEMENTS_VERTICES:
7410 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7411 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7412 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7413 case GL_UNPACK_IMAGE_HEIGHT:
7414 case GL_UNPACK_SKIP_IMAGES:
7415 {
7416 *type = GL_INT;
7417 *numParams = 1;
7418 return true;
7419 }
7420
7421 case GL_MAX_ELEMENT_INDEX:
7422 case GL_MAX_UNIFORM_BLOCK_SIZE:
7423 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7424 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7425 case GL_MAX_SERVER_WAIT_TIMEOUT:
7426 {
7427 *type = GL_INT_64_ANGLEX;
7428 *numParams = 1;
7429 return true;
7430 }
7431
7432 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7433 case GL_TRANSFORM_FEEDBACK_PAUSED:
7434 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7435 case GL_RASTERIZER_DISCARD:
7436 {
7437 *type = GL_BOOL;
7438 *numParams = 1;
7439 return true;
7440 }
7441
7442 case GL_MAX_TEXTURE_LOD_BIAS:
7443 {
7444 *type = GL_FLOAT;
7445 *numParams = 1;
7446 return true;
7447 }
7448 }
7449
7450 if (getExtensions().requestExtension)
7451 {
7452 switch (pname)
7453 {
7454 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7455 *type = GL_INT;
7456 *numParams = 1;
7457 return true;
7458 }
7459 }
7460
7461 if (getClientVersion() < Version(3, 1))
7462 {
7463 return false;
7464 }
7465
7466 switch (pname)
7467 {
7468 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7469 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7470 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7471 case GL_MAX_FRAMEBUFFER_WIDTH:
7472 case GL_MAX_FRAMEBUFFER_HEIGHT:
7473 case GL_MAX_FRAMEBUFFER_SAMPLES:
7474 case GL_MAX_SAMPLE_MASK_WORDS:
7475 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7476 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7477 case GL_MAX_INTEGER_SAMPLES:
7478 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7479 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7480 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7481 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7482 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7483 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7484 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7485 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7486 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7487 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7488 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7489 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7490 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7491 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7492 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7493 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7494 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7495 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7496 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7497 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7498 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7499 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7500 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7501 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7502 case GL_MAX_UNIFORM_LOCATIONS:
7503 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7504 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7505 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7506 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7507 case GL_MAX_IMAGE_UNITS:
7508 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7509 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7510 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7511 case GL_SHADER_STORAGE_BUFFER_BINDING:
7512 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7513 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007514 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007515 *type = GL_INT;
7516 *numParams = 1;
7517 return true;
7518 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7519 *type = GL_INT_64_ANGLEX;
7520 *numParams = 1;
7521 return true;
7522 case GL_SAMPLE_MASK:
7523 *type = GL_BOOL;
7524 *numParams = 1;
7525 return true;
7526 }
7527
7528 if (getExtensions().geometryShader)
7529 {
7530 switch (pname)
7531 {
7532 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7533 case GL_LAYER_PROVOKING_VERTEX_EXT:
7534 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7535 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7536 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7537 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7538 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7539 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7540 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7541 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7542 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7543 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7544 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7545 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7546 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7547 *type = GL_INT;
7548 *numParams = 1;
7549 return true;
7550 }
7551 }
7552
7553 return false;
7554}
7555
7556bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7557{
7558 if (getClientVersion() < Version(3, 0))
7559 {
7560 return false;
7561 }
7562
7563 switch (target)
7564 {
7565 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7566 case GL_UNIFORM_BUFFER_BINDING:
7567 {
7568 *type = GL_INT;
7569 *numParams = 1;
7570 return true;
7571 }
7572 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7573 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7574 case GL_UNIFORM_BUFFER_START:
7575 case GL_UNIFORM_BUFFER_SIZE:
7576 {
7577 *type = GL_INT_64_ANGLEX;
7578 *numParams = 1;
7579 return true;
7580 }
7581 }
7582
7583 if (getClientVersion() < Version(3, 1))
7584 {
7585 return false;
7586 }
7587
7588 switch (target)
7589 {
7590 case GL_IMAGE_BINDING_LAYERED:
7591 {
7592 *type = GL_BOOL;
7593 *numParams = 1;
7594 return true;
7595 }
7596 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7597 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7598 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7599 case GL_SHADER_STORAGE_BUFFER_BINDING:
7600 case GL_VERTEX_BINDING_BUFFER:
7601 case GL_VERTEX_BINDING_DIVISOR:
7602 case GL_VERTEX_BINDING_OFFSET:
7603 case GL_VERTEX_BINDING_STRIDE:
7604 case GL_SAMPLE_MASK_VALUE:
7605 case GL_IMAGE_BINDING_NAME:
7606 case GL_IMAGE_BINDING_LEVEL:
7607 case GL_IMAGE_BINDING_LAYER:
7608 case GL_IMAGE_BINDING_ACCESS:
7609 case GL_IMAGE_BINDING_FORMAT:
7610 {
7611 *type = GL_INT;
7612 *numParams = 1;
7613 return true;
7614 }
7615 case GL_ATOMIC_COUNTER_BUFFER_START:
7616 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7617 case GL_SHADER_STORAGE_BUFFER_START:
7618 case GL_SHADER_STORAGE_BUFFER_SIZE:
7619 {
7620 *type = GL_INT_64_ANGLEX;
7621 *numParams = 1;
7622 return true;
7623 }
7624 }
7625
7626 return false;
7627}
7628
7629Program *Context::getProgram(GLuint handle) const
7630{
7631 return mState.mShaderPrograms->getProgram(handle);
7632}
7633
7634Shader *Context::getShader(GLuint handle) const
7635{
7636 return mState.mShaderPrograms->getShader(handle);
7637}
7638
7639bool Context::isTextureGenerated(GLuint texture) const
7640{
7641 return mState.mTextures->isHandleGenerated(texture);
7642}
7643
Jamie Madill5b772312018-03-08 20:28:32 -05007644bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7645{
7646 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7647}
7648
7649bool Context::isFramebufferGenerated(GLuint framebuffer) const
7650{
7651 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7652}
7653
7654bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7655{
7656 return mState.mPipelines->isHandleGenerated(pipeline);
7657}
7658
7659bool Context::usingDisplayTextureShareGroup() const
7660{
7661 return mDisplayTextureShareGroup;
7662}
7663
7664GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7665{
7666 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7667 internalformat == GL_DEPTH_STENCIL
7668 ? GL_DEPTH24_STENCIL8
7669 : internalformat;
7670}
7671
jchen1082af6202018-06-22 10:59:52 +08007672void Context::maxShaderCompilerThreads(GLuint count)
7673{
jchen107ae70d82018-07-06 13:47:01 +08007674 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08007675 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007676 // A count of zero specifies a request for no parallel compiling or linking.
7677 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7678 {
7679 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7680 }
7681 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007682}
7683
Jamie Madill2eb65032018-07-30 10:25:57 -04007684bool Context::isGLES1() const
7685{
7686 return mState.getClientVersion() < Version(2, 0);
7687}
7688
Jamie Madilla11819d2018-07-30 10:26:01 -04007689void Context::onSubjectStateChange(const Context *context,
7690 angle::SubjectIndex index,
7691 angle::SubjectMessage message)
7692{
Jamie Madilla11819d2018-07-30 10:26:01 -04007693 switch (index)
7694 {
7695 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007696 switch (message)
7697 {
7698 case angle::SubjectMessage::CONTENTS_CHANGED:
7699 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
7700 mStateCache.onVertexArrayBufferContentsChange(this);
7701 break;
7702 case angle::SubjectMessage::RESOURCE_MAPPED:
7703 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7704 case angle::SubjectMessage::BINDING_CHANGED:
7705 mStateCache.onVertexArrayBufferStateChange(this);
7706 break;
7707 default:
7708 break;
7709 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007710 break;
7711
7712 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007713 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7714 {
7715 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
7716 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007717 break;
7718
7719 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007720 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7721 {
7722 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
7723 }
7724 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04007725 break;
7726
7727 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04007728 if (index < kTextureMaxSubjectIndex)
7729 {
7730 mGLState.onActiveTextureStateChange(index);
Jamie Madilld84b6732018-09-06 15:54:35 -04007731 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007732 }
7733 else
7734 {
7735 ASSERT(index < kUniformBufferMaxSubjectIndex);
7736 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04007737 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007738 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007739 break;
7740 }
7741}
7742
Jamie Madill6b873dd2018-07-12 23:56:30 -04007743// ErrorSet implementation.
7744ErrorSet::ErrorSet(Context *context) : mContext(context)
7745{
7746}
7747
7748ErrorSet::~ErrorSet() = default;
7749
Jamie Madill306b6c12018-07-27 08:12:49 -04007750void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007751{
7752 // This internal enum is used to filter internal errors that are already handled.
7753 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7754 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7755 {
7756 return;
7757 }
7758
7759 if (ANGLE_UNLIKELY(error.isError()))
7760 {
7761 GLenum code = error.getCode();
7762 mErrors.insert(code);
7763 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7764 {
7765 mContext->markContextLost();
7766 }
7767
7768 ASSERT(!error.getMessage().empty());
7769 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7770 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7771 error.getMessage());
7772 }
7773}
7774
7775bool ErrorSet::empty() const
7776{
7777 return mErrors.empty();
7778}
7779
7780GLenum ErrorSet::popError()
7781{
7782 ASSERT(!empty());
7783 GLenum error = *mErrors.begin();
7784 mErrors.erase(mErrors.begin());
7785 return error;
7786}
Jamie Madilldc358af2018-07-31 11:22:13 -04007787
7788// StateCache implementation.
Jamie Madill16e28fd2018-09-12 11:03:05 -04007789StateCache::StateCache(Context *context)
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007790 : mCachedHasAnyEnabledClientAttrib(false),
7791 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04007792 mCachedInstancedVertexElementLimit(0),
7793 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madilldc358af2018-07-31 11:22:13 -04007794{
Jamie Madill16e28fd2018-09-12 11:03:05 -04007795 updateValidDrawModes(context);
Jamie Madilldc358af2018-07-31 11:22:13 -04007796}
7797
7798StateCache::~StateCache() = default;
7799
7800void StateCache::updateActiveAttribsMask(Context *context)
7801{
7802 bool isGLES1 = context->isGLES1();
7803 const State &glState = context->getGLState();
7804
7805 if (!isGLES1 && !glState.getProgram())
7806 {
7807 mCachedActiveBufferedAttribsMask = AttributesMask();
7808 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04007809 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04007810 return;
7811 }
7812
7813 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7814 : glState.getProgram()->getActiveAttribLocationsMask();
7815
7816 const VertexArray *vao = glState.getVertexArray();
7817 ASSERT(vao);
7818
7819 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7820 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04007821 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007822
Jamie Madill0a17e482018-08-31 17:19:11 -04007823 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
7824 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04007825 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007826 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7827}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007828
7829void StateCache::updateVertexElementLimits(Context *context)
7830{
7831 const VertexArray *vao = context->getGLState().getVertexArray();
7832
7833 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7834 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7835
7836 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
7837 // If there are no buffered attributes then we should not limit the draw call count.
7838 if (!vao || !mCachedActiveBufferedAttribsMask.any())
7839 {
7840 return;
7841 }
7842
7843 const auto &vertexAttribs = vao->getVertexAttributes();
7844 const auto &vertexBindings = vao->getVertexBindings();
7845
7846 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
7847 {
7848 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
7849 ASSERT(attrib.enabled);
7850
7851 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
7852 ASSERT(context->isGLES1() ||
7853 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
7854
7855 GLint64 limit = attrib.getCachedElementLimit();
7856 if (binding.getDivisor() > 0)
7857 {
7858 mCachedInstancedVertexElementLimit =
7859 std::min(mCachedInstancedVertexElementLimit, limit);
7860 }
7861 else
7862 {
7863 mCachedNonInstancedVertexElementLimit =
7864 std::min(mCachedNonInstancedVertexElementLimit, limit);
7865 }
7866 }
7867}
Jamie Madillc43cdad2018-08-08 15:49:25 -04007868
Jamie Madilld84b6732018-09-06 15:54:35 -04007869void StateCache::updateBasicDrawStatesError()
7870{
7871 mCachedBasicDrawStatesError = kInvalidPointer;
7872}
7873
7874intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
7875{
7876 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
7877 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
7878 return mCachedBasicDrawStatesError;
7879}
7880
Jamie Madillc43cdad2018-08-08 15:49:25 -04007881void StateCache::onVertexArrayBindingChange(Context *context)
7882{
7883 updateActiveAttribsMask(context);
7884 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007885 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007886}
7887
7888void StateCache::onProgramExecutableChange(Context *context)
7889{
7890 updateActiveAttribsMask(context);
7891 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007892 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04007893 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04007894}
7895
Jamie Madilld84b6732018-09-06 15:54:35 -04007896void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04007897{
7898 updateVertexElementLimits(context);
7899}
7900
Jamie Madilld84b6732018-09-06 15:54:35 -04007901void StateCache::onVertexArrayBufferContentsChange(Context *context)
7902{
7903 updateVertexElementLimits(context);
7904 updateBasicDrawStatesError();
7905}
7906
Jamie Madillc43cdad2018-08-08 15:49:25 -04007907void StateCache::onVertexArrayStateChange(Context *context)
7908{
7909 updateActiveAttribsMask(context);
7910 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007911 updateBasicDrawStatesError();
7912}
7913
7914void StateCache::onVertexArrayBufferStateChange(Context *context)
7915{
7916 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007917}
7918
7919void StateCache::onGLES1ClientStateChange(Context *context)
7920{
7921 updateActiveAttribsMask(context);
7922}
Jamie Madilld84b6732018-09-06 15:54:35 -04007923
7924void StateCache::onDrawFramebufferChange(Context *context)
7925{
7926 updateBasicDrawStatesError();
7927}
7928
7929void StateCache::onContextCapChange(Context *context)
7930{
7931 updateBasicDrawStatesError();
7932}
7933
7934void StateCache::onStencilStateChange(Context *context)
7935{
7936 updateBasicDrawStatesError();
7937}
7938
7939void StateCache::onDefaultVertexAttributeChange(Context *context)
7940{
7941 updateBasicDrawStatesError();
7942}
7943
7944void StateCache::onActiveTextureChange(Context *context)
7945{
7946 updateBasicDrawStatesError();
7947}
7948
7949void StateCache::onQueryChange(Context *context)
7950{
7951 updateBasicDrawStatesError();
7952}
7953
7954void StateCache::onTransformFeedbackChange(Context *context)
7955{
7956 updateBasicDrawStatesError();
7957}
7958
7959void StateCache::onUniformBufferStateChange(Context *context)
7960{
7961 updateBasicDrawStatesError();
7962}
7963
7964void StateCache::onBufferBindingChange(Context *context)
7965{
7966 updateBasicDrawStatesError();
7967}
Jamie Madill526a6f62018-09-12 11:03:05 -04007968
7969void StateCache::updateValidDrawModes(Context *context)
7970{
7971 Program *program = context->getGLState().getProgram();
7972 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
7973 {
7974 mCachedValidDrawModes = {{
7975 true, /* Points */
7976 true, /* Lines */
7977 true, /* LineLoop */
7978 true, /* LineStrip */
7979 true, /* Triangles */
7980 true, /* TriangleStrip */
7981 true, /* TriangleFan */
7982 false, /* LinesAdjacency */
7983 false, /* LineStripAdjacency */
7984 false, /* TrianglesAdjacency */
7985 false, /* TriangleStripAdjacency */
7986 false, /* InvalidEnum */
7987 }};
7988 }
7989 else
7990 {
7991 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
7992
7993 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
7994
7995 mCachedValidDrawModes = {{
7996 gsMode == PrimitiveMode::Points, /* Points */
7997 gsMode == PrimitiveMode::Lines, /* Lines */
7998 gsMode == PrimitiveMode::Lines, /* LineLoop */
7999 gsMode == PrimitiveMode::Lines, /* LineStrip */
8000 gsMode == PrimitiveMode::Triangles, /* Triangles */
8001 gsMode == PrimitiveMode::Triangles, /* TriangleStrip */
8002 gsMode == PrimitiveMode::Triangles, /* TriangleFan */
8003 gsMode == PrimitiveMode::LinesAdjacency, /* LinesAdjacency */
8004 gsMode == PrimitiveMode::LinesAdjacency, /* LineStripAdjacency */
8005 gsMode == PrimitiveMode::TrianglesAdjacency, /* TrianglesAdjacency */
8006 gsMode == PrimitiveMode::TrianglesAdjacency, /* TriangleStripAdjacency */
8007 false, /* InvalidEnum */
8008 }};
8009 }
8010}
Jamie Madillc29968b2016-01-20 11:17:23 -05008011} // namespace gl