blob: 7029d79ac442a9707ae84f69d852352a94770332 [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Tobin Ehlisd7890bc2018-06-29 11:57:22 -060017#include "common/PackedEnums.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030018#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040019#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050020#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050021#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050022#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050023#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040024#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050025#include "libANGLE/Fence.h"
26#include "libANGLE/Framebuffer.h"
27#include "libANGLE/FramebufferAttachment.h"
Lingfeng Yang461b09a2018-04-23 09:02:09 -070028#include "libANGLE/GLES1Renderer.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030029#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080031#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050033#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050034#include "libANGLE/ResourceManager.h"
35#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050036#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050037#include "libANGLE/Texture.h"
38#include "libANGLE/TransformFeedback.h"
39#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070040#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040041#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030042#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040043#include "libANGLE/queryutils.h"
Jamie Madill6d32cef2018-08-14 02:34:28 -040044#include "libANGLE/renderer/BufferImpl.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040045#include "libANGLE/renderer/ContextImpl.h"
46#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040047#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040048#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000049
Geoff Langf6db0982015-08-25 13:04:00 -040050namespace
51{
52
Jamie Madillb6664922017-07-25 12:55:04 -040053#define ANGLE_HANDLE_ERR(X) \
54 handleError(X); \
55 return;
56#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
57
Ian Ewell3ffd78b2016-01-22 16:09:42 -050058template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050059std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030060 GLsizei numPaths,
61 const void *paths,
62 GLuint pathBase)
63{
64 std::vector<gl::Path *> ret;
65 ret.reserve(numPaths);
66
67 const auto *nameArray = static_cast<const T *>(paths);
68
69 for (GLsizei i = 0; i < numPaths; ++i)
70 {
71 const GLuint pathName = nameArray[i] + pathBase;
72
73 ret.push_back(resourceManager.getPath(pathName));
74 }
75
76 return ret;
77}
78
Geoff Lang4ddf5af2016-12-01 14:30:44 -050079std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030080 GLsizei numPaths,
81 GLenum pathNameType,
82 const void *paths,
83 GLuint pathBase)
84{
85 switch (pathNameType)
86 {
87 case GL_UNSIGNED_BYTE:
88 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
89
90 case GL_BYTE:
91 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
92
93 case GL_UNSIGNED_SHORT:
94 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
95
96 case GL_SHORT:
97 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
98
99 case GL_UNSIGNED_INT:
100 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
101
102 case GL_INT:
103 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
104 }
105
106 UNREACHABLE();
107 return std::vector<gl::Path *>();
108}
109
110template <typename T>
Jamie Madill5188a272018-07-25 10:53:56 -0400111gl::Error GetQueryObjectParameter(const gl::Context *context,
112 gl::Query *query,
113 GLenum pname,
114 T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500115{
Geoff Lang2186c382016-10-14 10:54:54 -0400116 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500117
118 switch (pname)
119 {
120 case GL_QUERY_RESULT_EXT:
Jamie Madill5188a272018-07-25 10:53:56 -0400121 return query->getResult(context, params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500122 case GL_QUERY_RESULT_AVAILABLE_EXT:
123 {
124 bool available;
Jamie Madill5188a272018-07-25 10:53:56 -0400125 gl::Error error = query->isResultAvailable(context, &available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500126 if (!error.isError())
127 {
jchen10a99ed552017-09-22 08:10:32 +0800128 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500129 }
130 return error;
131 }
132 default:
133 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500134 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500135 }
136}
137
Jamie Madill09463932018-04-04 05:26:59 -0400138void MarkTransformFeedbackBufferUsage(const gl::Context *context,
139 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700140 GLsizei count,
141 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400142{
Geoff Lang1a683462015-09-29 15:09:59 -0400143 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400144 {
Jamie Madill09463932018-04-04 05:26:59 -0400145 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400146 }
147}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148
149// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500151{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500153}
154
Martin Radev1be913c2016-07-11 17:59:16 +0300155EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
156{
157 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
158}
159
Geoff Langeb66a6e2016-10-31 13:06:12 -0400160gl::Version GetClientVersion(const egl::AttributeMap &attribs)
161{
162 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
163}
164
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165GLenum GetResetStrategy(const egl::AttributeMap &attribs)
166{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800167 EGLAttrib attrib =
168 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500169 switch (attrib)
170 {
171 case EGL_NO_RESET_NOTIFICATION:
172 return GL_NO_RESET_NOTIFICATION_EXT;
173 case EGL_LOSE_CONTEXT_ON_RESET:
174 return GL_LOSE_CONTEXT_ON_RESET_EXT;
175 default:
176 UNREACHABLE();
177 return GL_NONE;
178 }
179}
180
181bool GetRobustAccess(const egl::AttributeMap &attribs)
182{
Geoff Lang077f20a2016-11-01 10:08:02 -0400183 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
184 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
185 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500186}
187
188bool GetDebug(const egl::AttributeMap &attribs)
189{
Geoff Lang077f20a2016-11-01 10:08:02 -0400190 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
191 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500192}
193
194bool GetNoError(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Langc287ea62016-09-16 14:46:51 -0400199bool GetWebGLContext(const egl::AttributeMap &attribs)
200{
Jamie Madill4230d482018-09-14 10:14:45 -0400201 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
Geoff Langc287ea62016-09-16 14:46:51 -0400202}
203
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400204bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
205{
206 // If the context is WebGL, extensions are disabled by default
207 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
208 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
209}
210
Geoff Langf41a7152016-09-19 15:11:17 -0400211bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
212{
Jamie Madill4230d482018-09-14 10:14:45 -0400213 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
Geoff Langf41a7152016-09-19 15:11:17 -0400214}
215
Geoff Langfeb8c682017-02-13 16:07:35 -0500216bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
217{
218 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
219}
220
Geoff Langb433e872017-10-05 14:01:47 -0400221bool GetRobustResourceInit(const egl::AttributeMap &attribs)
222{
223 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
224}
225
Martin Radev9d901792016-07-15 15:58:58 +0300226std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
227{
228 std::string labelName;
229 if (label != nullptr)
230 {
231 size_t labelLength = length < 0 ? strlen(label) : length;
232 labelName = std::string(label, labelLength);
233 }
234 return labelName;
235}
236
237void GetObjectLabelBase(const std::string &objectLabel,
238 GLsizei bufSize,
239 GLsizei *length,
240 GLchar *label)
241{
242 size_t writeLength = objectLabel.length();
243 if (label != nullptr && bufSize > 0)
244 {
245 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
246 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
247 label[writeLength] = '\0';
248 }
249
250 if (length != nullptr)
251 {
252 *length = static_cast<GLsizei>(writeLength);
253 }
254}
255
Jamie Madill0f80ed82017-09-19 00:24:56 -0400256template <typename CapT, typename MaxT>
257void LimitCap(CapT *cap, MaxT maximum)
258{
259 *cap = std::min(*cap, static_cast<CapT>(maximum));
260}
261
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600262constexpr angle::PackedEnumMap<gl::PrimitiveMode, GLsizei> kMinimumPrimitiveCounts = {{
Jamie Madill526a6f62018-09-12 11:03:05 -0400263 1, /* Points */
264 2, /* Lines */
265 2, /* LineLoop */
266 2, /* LineStrip */
267 3, /* Triangles */
268 3, /* TriangleStrip */
269 3, /* TriangleFan */
270 2, /* LinesAdjacency */
271 2, /* LineStripAdjacency */
272 3, /* TrianglesAdjacency */
273 3, /* TriangleStripAdjacency */
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600274}};
275// Indices above are code-gen'd so make sure they don't change
276// if any of these static asserts are hit, must update kMinimumPrimitiveCounts abouve
277static_assert(static_cast<gl::PrimitiveMode>(0) == gl::PrimitiveMode::Points,
278 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
279static_assert(static_cast<gl::PrimitiveMode>(1) == gl::PrimitiveMode::Lines,
280 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
281static_assert(static_cast<gl::PrimitiveMode>(2) == gl::PrimitiveMode::LineLoop,
282 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
283static_assert(static_cast<gl::PrimitiveMode>(3) == gl::PrimitiveMode::LineStrip,
284 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
285static_assert(static_cast<gl::PrimitiveMode>(4) == gl::PrimitiveMode::Triangles,
286 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
287static_assert(static_cast<gl::PrimitiveMode>(5) == gl::PrimitiveMode::TriangleStrip,
288 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
289static_assert(static_cast<gl::PrimitiveMode>(6) == gl::PrimitiveMode::TriangleFan,
290 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
291static_assert(static_cast<gl::PrimitiveMode>(7) == gl::PrimitiveMode::LinesAdjacency,
292 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
293static_assert(static_cast<gl::PrimitiveMode>(8) == gl::PrimitiveMode::LineStripAdjacency,
294 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
295static_assert(static_cast<gl::PrimitiveMode>(9) == gl::PrimitiveMode::TrianglesAdjacency,
296 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
297static_assert(static_cast<gl::PrimitiveMode>(10) == gl::PrimitiveMode::TriangleStripAdjacency,
298 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
299static_assert(static_cast<gl::PrimitiveMode>(11) == gl::PrimitiveMode::EnumCount,
300 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
301
Jamie Madill6d32cef2018-08-14 02:34:28 -0400302enum SubjectIndexes : angle::SubjectIndex
303{
304 kTexture0SubjectIndex = 0,
305 kTextureMaxSubjectIndex = kTexture0SubjectIndex + gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
306 kUniformBuffer0SubjectIndex = kTextureMaxSubjectIndex,
307 kUniformBufferMaxSubjectIndex =
308 kUniformBuffer0SubjectIndex + gl::IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS,
309 kVertexArraySubjectIndex = kUniformBufferMaxSubjectIndex,
310 kReadFramebufferSubjectIndex,
311 kDrawFramebufferSubjectIndex
312};
Geoff Langf6db0982015-08-25 13:04:00 -0400313} // anonymous namespace
314
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000315namespace gl
316{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000317
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400318Context::Context(rx::EGLImplFactory *implFactory,
319 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400320 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500321 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400322 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500323 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700324 const egl::DisplayExtensions &displayExtensions,
325 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500326 : mState(reinterpret_cast<ContextID>(this),
327 shareContext ? &shareContext->mState : nullptr,
328 shareTextures,
329 GetClientVersion(attribs),
330 &mGLState,
331 mCaps,
332 mTextureCaps,
333 mExtensions,
334 mLimitations),
335 mSkipValidation(GetNoError(attribs)),
336 mDisplayTextureShareGroup(shareTextures != nullptr),
337 mSavedArgsType(nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400338 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400339 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400340 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400341 mGLState(GetDebug(attribs),
342 GetBindGeneratesResource(attribs),
343 GetClientArraysEnabled(attribs),
344 GetRobustResourceInit(attribs),
345 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400346 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500347 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400348 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500349 mHasBeenCurrent(false),
350 mContextLost(false),
351 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700352 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500353 mResetStrategy(GetResetStrategy(attribs)),
354 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400355 mSurfacelessSupported(displayExtensions.surfacelessContext),
356 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400357 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
358 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500359 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400360 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400361 mMemoryProgramCache(memoryProgramCache),
Jamie Madill16e28fd2018-09-12 11:03:05 -0400362 mStateCache(this),
Jamie Madilla11819d2018-07-30 10:26:01 -0400363 mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
364 mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
365 mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400366 mScratchBuffer(1000u),
jchen107ae70d82018-07-06 13:47:01 +0800367 mZeroFilledBuffer(1000u),
368 mThreadPool(nullptr)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000369{
Jamie Madill5b772312018-03-08 20:28:32 -0500370 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400371 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
372 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Jamie Madill6d32cef2018-08-14 02:34:28 -0400373
374 for (angle::SubjectIndex uboIndex = kUniformBuffer0SubjectIndex;
375 uboIndex < kUniformBufferMaxSubjectIndex; ++uboIndex)
376 {
377 mUniformBufferObserverBindings.emplace_back(this, uboIndex);
378 }
Geoff Lang33f11fb2018-05-07 13:42:47 -0400379}
Jamie Madill5b772312018-03-08 20:28:32 -0500380
Geoff Lang33f11fb2018-05-07 13:42:47 -0400381void Context::initialize()
382{
383 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400384
Geoff Lang33f11fb2018-05-07 13:42:47 -0400385 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700386 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400387
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400388 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100389
Shannon Woods53a94a82014-06-24 15:20:36 -0400390 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400391
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000392 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400393 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000394 // and cube map texture state vectors respectively associated with them.
395 // In order that access to these initial textures not be lost, they are treated as texture
396 // objects all of whose names are 0.
397
Corentin Wallez99d492c2018-02-27 15:17:10 -0500398 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800399 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500400
Corentin Wallez99d492c2018-02-27 15:17:10 -0500401 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800402 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400403
Geoff Langeb66a6e2016-10-31 13:06:12 -0400404 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400405 {
406 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500407 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800408 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400409
Corentin Wallez99d492c2018-02-27 15:17:10 -0500410 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800411 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400412 }
Geoff Lang3b573612016-10-31 14:08:10 -0400413 if (getClientVersion() >= Version(3, 1))
414 {
Olli Etuahod310a432018-08-24 15:40:23 +0300415 // TODO(http://anglebug.com/2775): These could also be enabled via extension
Geoff Lang3b573612016-10-31 14:08:10 -0400416 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500417 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800418 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Olli Etuahod310a432018-08-24 15:40:23 +0300419 Texture *zeroTexture2DMultisampleArray =
420 new Texture(mImplementation.get(), 0, TextureType::_2DMultisampleArray);
421 mZeroTextures[TextureType::_2DMultisampleArray].set(this, zeroTexture2DMultisampleArray);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800422
Jiajia Qin6eafb042016-12-27 17:04:07 +0800423 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
424 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800425 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800426 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800427
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800428 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
429 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400430 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800431 }
Geoff Lang3b573612016-10-31 14:08:10 -0400432 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000433
Geoff Langb0f917f2017-12-05 13:41:54 -0500434 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400435 {
436 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500437 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800438 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400439 }
440
Geoff Langb0f917f2017-12-05 13:41:54 -0500441 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400442 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500443 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800444 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400445 }
446
Jamie Madill4928b7c2017-06-20 12:57:39 -0400447 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500448
Jamie Madill57a89722013-07-02 11:57:03 -0400449 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000450
Geoff Langeb66a6e2016-10-31 13:06:12 -0400451 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400452 {
453 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
454 // In the initial state, a default transform feedback object is bound and treated as
455 // a transform feedback object with a name of zero. That object is bound any time
456 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400457 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400458 }
Geoff Langc8058452014-02-03 12:04:11 -0500459
Corentin Wallez336129f2017-10-17 15:55:40 -0400460 for (auto type : angle::AllEnums<BufferBinding>())
461 {
462 bindBuffer(type, 0);
463 }
464
465 bindRenderbuffer(GL_RENDERBUFFER, 0);
466
467 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
468 {
469 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
470 }
471
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700472 // Initialize GLES1 renderer if appropriate.
473 if (getClientVersion() < Version(2, 0))
474 {
475 mGLES1Renderer.reset(new GLES1Renderer());
476 }
477
Jamie Madillad9f24e2016-02-12 09:27:24 -0500478 // Initialize dirty bit masks
Geoff Lang9bf86f02018-07-26 11:46:34 -0400479 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
480 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
481 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400482 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400483
484 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
485 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
486 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
487
Jamie Madillc67323a2017-11-02 23:11:41 -0400488 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500489 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500490 // No dirty objects.
491
492 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400493 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500494 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400495 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500496 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
497
498 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
499 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
500 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
501 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
502 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
503 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
504 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
505 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
506 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
507 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
508 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400509 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500510 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
511
512 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
513 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700514 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400515 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
516 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500517 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
518 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400519
Xinghua Cao10a4d432017-11-28 14:46:26 +0800520 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
jchen1099118c12018-09-10 16:28:51 +0800521 mComputeDirtyBits.set(State::DIRTY_BIT_UNIFORM_BUFFER_BINDINGS);
522 mComputeDirtyBits.set(State::DIRTY_BIT_ATOMIC_COUNTER_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800523 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
524 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
525 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
526 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
jchen1099118c12018-09-10 16:28:51 +0800527 mComputeDirtyBits.set(State::DIRTY_BIT_IMAGE_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800528 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800529 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400530 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800531
Jamie Madillb4927eb2018-07-16 11:39:46 -0400532 mImplementation->setErrorSet(&mErrors);
533
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400534 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000535}
536
Jamie Madill4928b7c2017-06-20 12:57:39 -0400537egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000538{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700539 if (mGLES1Renderer)
540 {
541 mGLES1Renderer->onDestroy(this, &mGLState);
542 }
543
Jamie Madille7b3fe22018-04-05 09:42:46 -0400544 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400545 ANGLE_TRY(releaseSurface(display));
546
Corentin Wallez80b24112015-08-25 16:41:57 -0400547 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000548 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400549 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000550 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400551 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000552
Corentin Wallez80b24112015-08-25 16:41:57 -0400553 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000554 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400555 if (query.second != nullptr)
556 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400557 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400558 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000559 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400560 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000561
Corentin Wallez80b24112015-08-25 16:41:57 -0400562 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400563 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400564 if (vertexArray.second)
565 {
566 vertexArray.second->onDestroy(this);
567 }
Jamie Madill57a89722013-07-02 11:57:03 -0400568 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400569 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400570
Corentin Wallez80b24112015-08-25 16:41:57 -0400571 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500572 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500573 if (transformFeedback.second != nullptr)
574 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500575 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500576 }
Geoff Langc8058452014-02-03 12:04:11 -0500577 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400578 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500579
Jamie Madill5b772312018-03-08 20:28:32 -0500580 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400581 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800582 if (zeroTexture.get() != nullptr)
583 {
584 ANGLE_TRY(zeroTexture->onDestroy(this));
585 zeroTexture.set(this, nullptr);
586 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400587 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000588
Jamie Madill2f348d22017-06-05 10:50:59 -0400589 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500590
Jamie Madill4928b7c2017-06-20 12:57:39 -0400591 mGLState.reset(this);
592
Jamie Madill6c1f6712017-02-14 19:08:04 -0500593 mState.mBuffers->release(this);
594 mState.mShaderPrograms->release(this);
595 mState.mTextures->release(this);
596 mState.mRenderbuffers->release(this);
597 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400598 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500599 mState.mPaths->release(this);
600 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800601 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400602
jchen107ae70d82018-07-06 13:47:01 +0800603 mThreadPool.reset();
604
Jamie Madill76e471e2017-10-21 09:56:01 -0400605 mImplementation->onDestroy(this);
606
Jamie Madill4928b7c2017-06-20 12:57:39 -0400607 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000608}
609
Jamie Madill70ee0f62017-02-06 16:04:20 -0500610Context::~Context()
611{
612}
613
Geoff Lang75359662018-04-11 01:42:27 -0400614void Context::setLabel(EGLLabelKHR label)
615{
616 mLabel = label;
617}
618
619EGLLabelKHR Context::getLabel() const
620{
621 return mLabel;
622}
623
Jamie Madill4928b7c2017-06-20 12:57:39 -0400624egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000625{
Jamie Madill61e16b42017-06-19 11:13:23 -0400626 mCurrentDisplay = display;
627
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000628 if (!mHasBeenCurrent)
629 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400630 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000631 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500632 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400633 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000634
Corentin Wallezc295e512017-01-27 17:47:50 -0500635 int width = 0;
636 int height = 0;
637 if (surface != nullptr)
638 {
639 width = surface->getWidth();
640 height = surface->getHeight();
641 }
642
643 mGLState.setViewportParams(0, 0, width, height);
644 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000645
646 mHasBeenCurrent = true;
647 }
648
Jamie Madill1b94d432015-08-07 13:23:23 -0400649 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700650 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400651 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400652
Jamie Madill4928b7c2017-06-20 12:57:39 -0400653 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500654
655 Framebuffer *newDefault = nullptr;
656 if (surface != nullptr)
657 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400658 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500659 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400660 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500661 }
662 else
663 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400664 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500665 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000666
Corentin Wallez37c39792015-08-20 14:19:46 -0400667 // Update default framebuffer, the binding of the previous default
668 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400669 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400670 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700671 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400672 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400673 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400674 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700675 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400676 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400677 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400678 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400679 }
Ian Ewell292f0052016-02-04 10:37:32 -0500680
681 // Notify the renderer of a context switch
Luc Ferron5396f2a2018-07-12 08:24:23 -0400682 ANGLE_TRY(mImplementation->onMakeCurrent(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400683 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000684}
685
Jamie Madill4928b7c2017-06-20 12:57:39 -0400686egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400687{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400688 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400689
Geoff Langbf7b95d2018-05-01 16:48:21 -0400690 // Remove the default framebuffer
691 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500692 {
693 mGLState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400694 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500695 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400696
697 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500698 {
699 mGLState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400700 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500701 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400702
703 if (defaultFramebuffer)
704 {
705 defaultFramebuffer->onDestroy(this);
706 delete defaultFramebuffer;
707 }
708
Corentin Wallezc295e512017-01-27 17:47:50 -0500709 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
710
711 if (mCurrentSurface)
712 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400713 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500714 mCurrentSurface = nullptr;
715 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400716
717 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400718}
719
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000720GLuint Context::createBuffer()
721{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500722 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000723}
724
725GLuint Context::createProgram()
726{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500727 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000728}
729
Jiawei Shao385b3e02018-03-21 09:43:28 +0800730GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000731{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500732 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000733}
734
735GLuint Context::createTexture()
736{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500737 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000738}
739
740GLuint Context::createRenderbuffer()
741{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500742 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000743}
744
Brandon Jones59770802018-04-02 13:18:42 -0700745GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300746{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500747 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300748 if (resultOrError.isError())
749 {
750 handleError(resultOrError.getError());
751 return 0;
752 }
753 return resultOrError.getResult();
754}
755
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000756// Returns an unused framebuffer name
757GLuint Context::createFramebuffer()
758{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500759 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000760}
761
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500762void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000763{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500764 for (int i = 0; i < n; i++)
765 {
766 GLuint handle = mFenceNVHandleAllocator.allocate();
767 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
768 fences[i] = handle;
769 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000770}
771
Yunchao Hea336b902017-08-02 16:05:21 +0800772GLuint Context::createProgramPipeline()
773{
774 return mState.mPipelines->createProgramPipeline();
775}
776
Jiawei Shao385b3e02018-03-21 09:43:28 +0800777GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800778{
779 UNIMPLEMENTED();
780 return 0u;
781}
782
James Darpinian4d9d4832018-03-13 12:43:28 -0700783void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000784{
James Darpinian4d9d4832018-03-13 12:43:28 -0700785 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
786 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000787 {
788 detachBuffer(buffer);
789 }
Jamie Madill893ab082014-05-16 16:56:10 -0400790
James Darpinian4d9d4832018-03-13 12:43:28 -0700791 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000792}
793
794void Context::deleteShader(GLuint shader)
795{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500796 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000797}
798
799void Context::deleteProgram(GLuint program)
800{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500801 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000802}
803
804void Context::deleteTexture(GLuint texture)
805{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500806 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000807 {
808 detachTexture(texture);
809 }
810
Jamie Madill6c1f6712017-02-14 19:08:04 -0500811 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000812}
813
814void Context::deleteRenderbuffer(GLuint renderbuffer)
815{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500816 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000817 {
818 detachRenderbuffer(renderbuffer);
819 }
Jamie Madill893ab082014-05-16 16:56:10 -0400820
Jamie Madill6c1f6712017-02-14 19:08:04 -0500821 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000822}
823
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400824void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400825{
826 // The spec specifies the underlying Fence object is not deleted until all current
827 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
828 // and since our API is currently designed for being called from a single thread, we can delete
829 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400830 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400831}
832
Yunchao Hea336b902017-08-02 16:05:21 +0800833void Context::deleteProgramPipeline(GLuint pipeline)
834{
835 if (mState.mPipelines->getProgramPipeline(pipeline))
836 {
837 detachProgramPipeline(pipeline);
838 }
839
840 mState.mPipelines->deleteObject(this, pipeline);
841}
842
Sami Väisänene45e53b2016-05-25 10:36:04 +0300843void Context::deletePaths(GLuint first, GLsizei range)
844{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500845 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300846}
847
Brandon Jones59770802018-04-02 13:18:42 -0700848bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300849{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500850 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300851 if (pathObj == nullptr)
852 return false;
853
854 return pathObj->hasPathData();
855}
856
Brandon Jones59770802018-04-02 13:18:42 -0700857bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300858{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500859 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300860}
861
Brandon Jones59770802018-04-02 13:18:42 -0700862void Context::pathCommands(GLuint path,
863 GLsizei numCommands,
864 const GLubyte *commands,
865 GLsizei numCoords,
866 GLenum coordType,
867 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300868{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500869 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300870
871 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
872}
873
Jamie Madill007530e2017-12-28 14:27:04 -0500874void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300875{
Jamie Madill007530e2017-12-28 14:27:04 -0500876 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300877
878 switch (pname)
879 {
880 case GL_PATH_STROKE_WIDTH_CHROMIUM:
881 pathObj->setStrokeWidth(value);
882 break;
883 case GL_PATH_END_CAPS_CHROMIUM:
884 pathObj->setEndCaps(static_cast<GLenum>(value));
885 break;
886 case GL_PATH_JOIN_STYLE_CHROMIUM:
887 pathObj->setJoinStyle(static_cast<GLenum>(value));
888 break;
889 case GL_PATH_MITER_LIMIT_CHROMIUM:
890 pathObj->setMiterLimit(value);
891 break;
892 case GL_PATH_STROKE_BOUND_CHROMIUM:
893 pathObj->setStrokeBound(value);
894 break;
895 default:
896 UNREACHABLE();
897 break;
898 }
899}
900
Jamie Madill007530e2017-12-28 14:27:04 -0500901void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300902{
Jamie Madill007530e2017-12-28 14:27:04 -0500903 // TODO(jmadill): Should use proper clamping/casting.
904 pathParameterf(path, pname, static_cast<GLfloat>(value));
905}
906
907void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
908{
909 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300910
911 switch (pname)
912 {
913 case GL_PATH_STROKE_WIDTH_CHROMIUM:
914 *value = pathObj->getStrokeWidth();
915 break;
916 case GL_PATH_END_CAPS_CHROMIUM:
917 *value = static_cast<GLfloat>(pathObj->getEndCaps());
918 break;
919 case GL_PATH_JOIN_STYLE_CHROMIUM:
920 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
921 break;
922 case GL_PATH_MITER_LIMIT_CHROMIUM:
923 *value = pathObj->getMiterLimit();
924 break;
925 case GL_PATH_STROKE_BOUND_CHROMIUM:
926 *value = pathObj->getStrokeBound();
927 break;
928 default:
929 UNREACHABLE();
930 break;
931 }
932}
933
Jamie Madill007530e2017-12-28 14:27:04 -0500934void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
935{
936 GLfloat val = 0.0f;
937 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
938 if (value)
939 *value = static_cast<GLint>(val);
940}
941
Brandon Jones59770802018-04-02 13:18:42 -0700942void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300943{
944 mGLState.setPathStencilFunc(func, ref, mask);
945}
946
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000947void Context::deleteFramebuffer(GLuint framebuffer)
948{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500949 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000950 {
951 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000952 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500953
Jamie Madill6c1f6712017-02-14 19:08:04 -0500954 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000955}
956
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500957void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000958{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500959 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000960 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500961 GLuint fence = fences[i];
962
963 FenceNV *fenceObject = nullptr;
964 if (mFenceNVMap.erase(fence, &fenceObject))
965 {
966 mFenceNVHandleAllocator.release(fence);
967 delete fenceObject;
968 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000969 }
970}
971
Geoff Lang70d0f492015-12-10 17:45:46 -0500972Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000973{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500974 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000975}
976
Geoff Lang70d0f492015-12-10 17:45:46 -0500977Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000978{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500979 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000980}
981
Jamie Madill70b5bb02017-08-28 13:32:37 -0400982Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400983{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400984 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400985}
986
Jamie Madill57a89722013-07-02 11:57:03 -0400987VertexArray *Context::getVertexArray(GLuint handle) const
988{
Jamie Madill96a483b2017-06-27 16:49:21 -0400989 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400990}
991
Jamie Madilldc356042013-07-19 16:36:57 -0400992Sampler *Context::getSampler(GLuint handle) const
993{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500994 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400995}
996
Geoff Langc8058452014-02-03 12:04:11 -0500997TransformFeedback *Context::getTransformFeedback(GLuint handle) const
998{
Jamie Madill96a483b2017-06-27 16:49:21 -0400999 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -05001000}
1001
Yunchao Hea336b902017-08-02 16:05:21 +08001002ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
1003{
1004 return mState.mPipelines->getProgramPipeline(handle);
1005}
1006
Geoff Lang75359662018-04-11 01:42:27 -04001007gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001008{
1009 switch (identifier)
1010 {
1011 case GL_BUFFER:
1012 return getBuffer(name);
1013 case GL_SHADER:
1014 return getShader(name);
1015 case GL_PROGRAM:
1016 return getProgram(name);
1017 case GL_VERTEX_ARRAY:
1018 return getVertexArray(name);
1019 case GL_QUERY:
1020 return getQuery(name);
1021 case GL_TRANSFORM_FEEDBACK:
1022 return getTransformFeedback(name);
1023 case GL_SAMPLER:
1024 return getSampler(name);
1025 case GL_TEXTURE:
1026 return getTexture(name);
1027 case GL_RENDERBUFFER:
1028 return getRenderbuffer(name);
1029 case GL_FRAMEBUFFER:
1030 return getFramebuffer(name);
1031 default:
1032 UNREACHABLE();
1033 return nullptr;
1034 }
1035}
1036
Geoff Lang75359662018-04-11 01:42:27 -04001037gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001038{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001039 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001040}
1041
Martin Radev9d901792016-07-15 15:58:58 +03001042void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1043{
Geoff Lang75359662018-04-11 01:42:27 -04001044 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001045 ASSERT(object != nullptr);
1046
1047 std::string labelName = GetObjectLabelFromPointer(length, label);
1048 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001049
1050 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1051 // specified object is active until we do this.
1052 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001053}
1054
1055void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1056{
Geoff Lang75359662018-04-11 01:42:27 -04001057 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001058 ASSERT(object != nullptr);
1059
1060 std::string labelName = GetObjectLabelFromPointer(length, label);
1061 object->setLabel(labelName);
1062}
1063
1064void Context::getObjectLabel(GLenum identifier,
1065 GLuint name,
1066 GLsizei bufSize,
1067 GLsizei *length,
1068 GLchar *label) const
1069{
Geoff Lang75359662018-04-11 01:42:27 -04001070 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001071 ASSERT(object != nullptr);
1072
1073 const std::string &objectLabel = object->getLabel();
1074 GetObjectLabelBase(objectLabel, bufSize, length, label);
1075}
1076
1077void Context::getObjectPtrLabel(const void *ptr,
1078 GLsizei bufSize,
1079 GLsizei *length,
1080 GLchar *label) const
1081{
Geoff Lang75359662018-04-11 01:42:27 -04001082 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001083 ASSERT(object != nullptr);
1084
1085 const std::string &objectLabel = object->getLabel();
1086 GetObjectLabelBase(objectLabel, bufSize, length, label);
1087}
1088
Jamie Madilldc356042013-07-19 16:36:57 -04001089bool Context::isSampler(GLuint samplerName) const
1090{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001091 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001092}
1093
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001094void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001095{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001096 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001097
Jamie Madilldedd7b92014-11-05 16:30:36 -05001098 if (handle == 0)
1099 {
1100 texture = mZeroTextures[target].get();
1101 }
1102 else
1103 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001104 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001105 }
1106
1107 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001108 mGLState.setSamplerTexture(this, target, texture);
Jamie Madilld84b6732018-09-06 15:54:35 -04001109 mStateCache.onActiveTextureChange(this);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001110}
1111
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001112void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001113{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001114 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1115 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001116 mGLState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001117 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001118}
1119
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001120void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001121{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001122 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1123 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001124 mGLState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001125 mDrawFramebufferObserverBinding.bind(framebuffer);
Jamie Madilld84b6732018-09-06 15:54:35 -04001126 mStateCache.onDrawFramebufferChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001127}
1128
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001129void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001130{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001131 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001132 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001133 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001134 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001135}
1136
Shao80957d92017-02-20 21:25:59 +08001137void Context::bindVertexBuffer(GLuint bindingIndex,
1138 GLuint bufferHandle,
1139 GLintptr offset,
1140 GLsizei stride)
1141{
1142 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001143 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001144 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001145}
1146
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001147void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001148{
Geoff Lang76b10c92014-09-05 16:28:14 -04001149 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001150 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001151 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001152 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001153}
1154
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001155void Context::bindImageTexture(GLuint unit,
1156 GLuint texture,
1157 GLint level,
1158 GLboolean layered,
1159 GLint layer,
1160 GLenum access,
1161 GLenum format)
1162{
1163 Texture *tex = mState.mTextures->getTexture(texture);
1164 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1165}
1166
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001167void Context::useProgram(GLuint program)
1168{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001169 mGLState.setProgram(this, getProgram(program));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001170 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001171}
1172
Jiajia Qin5451d532017-11-16 17:16:34 +08001173void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1174{
1175 UNIMPLEMENTED();
1176}
1177
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001178void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001179{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001180 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001181 TransformFeedback *transformFeedback =
1182 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001183 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Jamie Madilld84b6732018-09-06 15:54:35 -04001184 mStateCache.onTransformFeedbackChange(this);
Geoff Langc8058452014-02-03 12:04:11 -05001185}
1186
Yunchao Hea336b902017-08-02 16:05:21 +08001187void Context::bindProgramPipeline(GLuint pipelineHandle)
1188{
1189 ProgramPipeline *pipeline =
1190 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1191 mGLState.setProgramPipelineBinding(this, pipeline);
1192}
1193
Corentin Wallezad3ae902018-03-09 13:40:42 -05001194void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001195{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001196 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001197 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001198
Geoff Lang5aad9672014-09-08 11:10:42 -04001199 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001200 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001201
1202 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001203 mGLState.setActiveQuery(this, target, queryObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04001204 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001205}
1206
Corentin Wallezad3ae902018-03-09 13:40:42 -05001207void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001208{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001209 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001210 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001211
Jamie Madill5188a272018-07-25 10:53:56 -04001212 handleError(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001213
Geoff Lang5aad9672014-09-08 11:10:42 -04001214 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001215 mGLState.setActiveQuery(this, target, nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04001216 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001217}
1218
Corentin Wallezad3ae902018-03-09 13:40:42 -05001219void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001220{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001221 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001222
1223 Query *queryObject = getQuery(id, true, target);
1224 ASSERT(queryObject);
1225
Jamie Madill5188a272018-07-25 10:53:56 -04001226 handleError(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001227}
1228
Corentin Wallezad3ae902018-03-09 13:40:42 -05001229void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001230{
1231 switch (pname)
1232 {
1233 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001234 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001235 break;
1236 case GL_QUERY_COUNTER_BITS_EXT:
1237 switch (target)
1238 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001239 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001240 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1241 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001242 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001243 params[0] = getExtensions().queryCounterBitsTimestamp;
1244 break;
1245 default:
1246 UNREACHABLE();
1247 params[0] = 0;
1248 break;
1249 }
1250 break;
1251 default:
1252 UNREACHABLE();
1253 return;
1254 }
1255}
1256
Corentin Wallezad3ae902018-03-09 13:40:42 -05001257void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001258 GLenum pname,
1259 GLsizei bufSize,
1260 GLsizei *length,
1261 GLint *params)
1262{
1263 getQueryiv(target, pname, params);
1264}
1265
Geoff Lang2186c382016-10-14 10:54:54 -04001266void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001267{
Jamie Madill5188a272018-07-25 10:53:56 -04001268 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001269}
1270
Brandon Jones59770802018-04-02 13:18:42 -07001271void Context::getQueryObjectivRobust(GLuint id,
1272 GLenum pname,
1273 GLsizei bufSize,
1274 GLsizei *length,
1275 GLint *params)
1276{
1277 getQueryObjectiv(id, pname, params);
1278}
1279
Geoff Lang2186c382016-10-14 10:54:54 -04001280void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001281{
Jamie Madill5188a272018-07-25 10:53:56 -04001282 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001283}
1284
Brandon Jones59770802018-04-02 13:18:42 -07001285void Context::getQueryObjectuivRobust(GLuint id,
1286 GLenum pname,
1287 GLsizei bufSize,
1288 GLsizei *length,
1289 GLuint *params)
1290{
1291 getQueryObjectuiv(id, pname, params);
1292}
1293
Geoff Lang2186c382016-10-14 10:54:54 -04001294void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001295{
Jamie Madill5188a272018-07-25 10:53:56 -04001296 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001297}
1298
Brandon Jones59770802018-04-02 13:18:42 -07001299void Context::getQueryObjecti64vRobust(GLuint id,
1300 GLenum pname,
1301 GLsizei bufSize,
1302 GLsizei *length,
1303 GLint64 *params)
1304{
1305 getQueryObjecti64v(id, pname, params);
1306}
1307
Geoff Lang2186c382016-10-14 10:54:54 -04001308void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001309{
Jamie Madill5188a272018-07-25 10:53:56 -04001310 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001311}
1312
Brandon Jones59770802018-04-02 13:18:42 -07001313void Context::getQueryObjectui64vRobust(GLuint id,
1314 GLenum pname,
1315 GLsizei bufSize,
1316 GLsizei *length,
1317 GLuint64 *params)
1318{
1319 getQueryObjectui64v(id, pname, params);
1320}
1321
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001322Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001323{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001324 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001325}
1326
Jamie Madill2f348d22017-06-05 10:50:59 -04001327FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001328{
Jamie Madill96a483b2017-06-27 16:49:21 -04001329 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001330}
1331
Corentin Wallezad3ae902018-03-09 13:40:42 -05001332Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001333{
Jamie Madill96a483b2017-06-27 16:49:21 -04001334 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001335 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001336 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001337 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001338
1339 Query *query = mQueryMap.query(handle);
1340 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001341 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001342 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001343 query = new Query(mImplementation->createQuery(type), handle);
1344 query->addRef();
1345 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001346 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001347 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001348}
1349
Geoff Lang70d0f492015-12-10 17:45:46 -05001350Query *Context::getQuery(GLuint handle) const
1351{
Jamie Madill96a483b2017-06-27 16:49:21 -04001352 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001353}
1354
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001355Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001356{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001357 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1358 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001359}
1360
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001361Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001362{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001363 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001364}
1365
Geoff Lang492a7e42014-11-05 13:27:06 -05001366Compiler *Context::getCompiler() const
1367{
Jamie Madill2f348d22017-06-05 10:50:59 -04001368 if (mCompiler.get() == nullptr)
1369 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001370 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001371 }
1372 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001373}
1374
Jamie Madillc1d770e2017-04-13 17:31:24 -04001375void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001376{
1377 switch (pname)
1378 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001379 case GL_SHADER_COMPILER:
1380 *params = GL_TRUE;
1381 break;
1382 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1383 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1384 break;
1385 default:
1386 mGLState.getBooleanv(pname, params);
1387 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001388 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001389}
1390
Jamie Madillc1d770e2017-04-13 17:31:24 -04001391void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001392{
Shannon Woods53a94a82014-06-24 15:20:36 -04001393 // Queries about context capabilities and maximums are answered by Context.
1394 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001395 switch (pname)
1396 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001397 case GL_ALIASED_LINE_WIDTH_RANGE:
1398 params[0] = mCaps.minAliasedLineWidth;
1399 params[1] = mCaps.maxAliasedLineWidth;
1400 break;
1401 case GL_ALIASED_POINT_SIZE_RANGE:
1402 params[0] = mCaps.minAliasedPointSize;
1403 params[1] = mCaps.maxAliasedPointSize;
1404 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001405 case GL_SMOOTH_POINT_SIZE_RANGE:
1406 params[0] = mCaps.minSmoothPointSize;
1407 params[1] = mCaps.maxSmoothPointSize;
1408 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001409 case GL_SMOOTH_LINE_WIDTH_RANGE:
1410 params[0] = mCaps.minSmoothLineWidth;
1411 params[1] = mCaps.maxSmoothLineWidth;
1412 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001413 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1414 ASSERT(mExtensions.textureFilterAnisotropic);
1415 *params = mExtensions.maxTextureAnisotropy;
1416 break;
1417 case GL_MAX_TEXTURE_LOD_BIAS:
1418 *params = mCaps.maxLODBias;
1419 break;
1420
1421 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1422 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1423 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001424 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1425 // GLES1 constants for modelview/projection matrix.
1426 if (getClientVersion() < Version(2, 0))
1427 {
1428 mGLState.getFloatv(pname, params);
1429 }
1430 else
1431 {
1432 ASSERT(mExtensions.pathRendering);
1433 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1434 memcpy(params, m, 16 * sizeof(GLfloat));
1435 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001436 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001437 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001438
Jamie Madill231c7f52017-04-26 13:45:37 -04001439 default:
1440 mGLState.getFloatv(pname, params);
1441 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001442 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001443}
1444
Jamie Madillc1d770e2017-04-13 17:31:24 -04001445void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001446{
Shannon Woods53a94a82014-06-24 15:20:36 -04001447 // Queries about context capabilities and maximums are answered by Context.
1448 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001449
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001450 switch (pname)
1451 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001452 case GL_MAX_VERTEX_ATTRIBS:
1453 *params = mCaps.maxVertexAttributes;
1454 break;
1455 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1456 *params = mCaps.maxVertexUniformVectors;
1457 break;
1458 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001459 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001460 break;
1461 case GL_MAX_VARYING_VECTORS:
1462 *params = mCaps.maxVaryingVectors;
1463 break;
1464 case GL_MAX_VARYING_COMPONENTS:
1465 *params = mCaps.maxVertexOutputComponents;
1466 break;
1467 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1468 *params = mCaps.maxCombinedTextureImageUnits;
1469 break;
1470 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001471 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001472 break;
1473 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001474 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001475 break;
1476 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1477 *params = mCaps.maxFragmentUniformVectors;
1478 break;
1479 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001480 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001481 break;
1482 case GL_MAX_RENDERBUFFER_SIZE:
1483 *params = mCaps.maxRenderbufferSize;
1484 break;
1485 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1486 *params = mCaps.maxColorAttachments;
1487 break;
1488 case GL_MAX_DRAW_BUFFERS_EXT:
1489 *params = mCaps.maxDrawBuffers;
1490 break;
1491 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1492 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1493 case GL_SUBPIXEL_BITS:
1494 *params = 4;
1495 break;
1496 case GL_MAX_TEXTURE_SIZE:
1497 *params = mCaps.max2DTextureSize;
1498 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001499 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1500 *params = mCaps.maxRectangleTextureSize;
1501 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001502 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1503 *params = mCaps.maxCubeMapTextureSize;
1504 break;
1505 case GL_MAX_3D_TEXTURE_SIZE:
1506 *params = mCaps.max3DTextureSize;
1507 break;
1508 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1509 *params = mCaps.maxArrayTextureLayers;
1510 break;
1511 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1512 *params = mCaps.uniformBufferOffsetAlignment;
1513 break;
1514 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1515 *params = mCaps.maxUniformBufferBindings;
1516 break;
1517 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001518 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001519 break;
1520 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001521 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001522 break;
1523 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1524 *params = mCaps.maxCombinedTextureImageUnits;
1525 break;
1526 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1527 *params = mCaps.maxVertexOutputComponents;
1528 break;
1529 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1530 *params = mCaps.maxFragmentInputComponents;
1531 break;
1532 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1533 *params = mCaps.minProgramTexelOffset;
1534 break;
1535 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1536 *params = mCaps.maxProgramTexelOffset;
1537 break;
1538 case GL_MAJOR_VERSION:
1539 *params = getClientVersion().major;
1540 break;
1541 case GL_MINOR_VERSION:
1542 *params = getClientVersion().minor;
1543 break;
1544 case GL_MAX_ELEMENTS_INDICES:
1545 *params = mCaps.maxElementsIndices;
1546 break;
1547 case GL_MAX_ELEMENTS_VERTICES:
1548 *params = mCaps.maxElementsVertices;
1549 break;
1550 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1551 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1552 break;
1553 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1554 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1555 break;
1556 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1557 *params = mCaps.maxTransformFeedbackSeparateComponents;
1558 break;
1559 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1560 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1561 break;
1562 case GL_MAX_SAMPLES_ANGLE:
1563 *params = mCaps.maxSamples;
1564 break;
1565 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001566 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001567 params[0] = mCaps.maxViewportWidth;
1568 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001569 }
1570 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001571 case GL_COMPRESSED_TEXTURE_FORMATS:
1572 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1573 params);
1574 break;
1575 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1576 *params = mResetStrategy;
1577 break;
1578 case GL_NUM_SHADER_BINARY_FORMATS:
1579 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1580 break;
1581 case GL_SHADER_BINARY_FORMATS:
1582 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1583 break;
1584 case GL_NUM_PROGRAM_BINARY_FORMATS:
1585 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1586 break;
1587 case GL_PROGRAM_BINARY_FORMATS:
1588 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1589 break;
1590 case GL_NUM_EXTENSIONS:
1591 *params = static_cast<GLint>(mExtensionStrings.size());
1592 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001593
Jamie Madill231c7f52017-04-26 13:45:37 -04001594 // GL_KHR_debug
1595 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1596 *params = mExtensions.maxDebugMessageLength;
1597 break;
1598 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1599 *params = mExtensions.maxDebugLoggedMessages;
1600 break;
1601 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1602 *params = mExtensions.maxDebugGroupStackDepth;
1603 break;
1604 case GL_MAX_LABEL_LENGTH:
1605 *params = mExtensions.maxLabelLength;
1606 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001607
Martin Radeve5285d22017-07-14 16:23:53 +03001608 // GL_ANGLE_multiview
1609 case GL_MAX_VIEWS_ANGLE:
1610 *params = mExtensions.maxViews;
1611 break;
1612
Jamie Madill231c7f52017-04-26 13:45:37 -04001613 // GL_EXT_disjoint_timer_query
1614 case GL_GPU_DISJOINT_EXT:
1615 *params = mImplementation->getGPUDisjoint();
1616 break;
1617 case GL_MAX_FRAMEBUFFER_WIDTH:
1618 *params = mCaps.maxFramebufferWidth;
1619 break;
1620 case GL_MAX_FRAMEBUFFER_HEIGHT:
1621 *params = mCaps.maxFramebufferHeight;
1622 break;
1623 case GL_MAX_FRAMEBUFFER_SAMPLES:
1624 *params = mCaps.maxFramebufferSamples;
1625 break;
1626 case GL_MAX_SAMPLE_MASK_WORDS:
1627 *params = mCaps.maxSampleMaskWords;
1628 break;
1629 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1630 *params = mCaps.maxColorTextureSamples;
1631 break;
1632 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1633 *params = mCaps.maxDepthTextureSamples;
1634 break;
1635 case GL_MAX_INTEGER_SAMPLES:
1636 *params = mCaps.maxIntegerSamples;
1637 break;
1638 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1639 *params = mCaps.maxVertexAttribRelativeOffset;
1640 break;
1641 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1642 *params = mCaps.maxVertexAttribBindings;
1643 break;
1644 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1645 *params = mCaps.maxVertexAttribStride;
1646 break;
1647 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001648 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001649 break;
1650 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001651 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001652 break;
1653 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001654 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001655 break;
1656 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001657 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001658 break;
1659 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001660 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001661 break;
1662 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001663 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001664 break;
1665 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001666 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001667 break;
1668 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001669 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001670 break;
1671 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1672 *params = mCaps.minProgramTextureGatherOffset;
1673 break;
1674 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1675 *params = mCaps.maxProgramTextureGatherOffset;
1676 break;
1677 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1678 *params = mCaps.maxComputeWorkGroupInvocations;
1679 break;
1680 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001681 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001682 break;
1683 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001684 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001685 break;
1686 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1687 *params = mCaps.maxComputeSharedMemorySize;
1688 break;
1689 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001690 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001691 break;
1692 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001693 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001694 break;
1695 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001696 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001697 break;
1698 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001699 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001700 break;
1701 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001702 *params =
1703 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001704 break;
1705 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001706 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001707 break;
1708 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1709 *params = mCaps.maxCombinedShaderOutputResources;
1710 break;
1711 case GL_MAX_UNIFORM_LOCATIONS:
1712 *params = mCaps.maxUniformLocations;
1713 break;
1714 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1715 *params = mCaps.maxAtomicCounterBufferBindings;
1716 break;
1717 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1718 *params = mCaps.maxAtomicCounterBufferSize;
1719 break;
1720 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1721 *params = mCaps.maxCombinedAtomicCounterBuffers;
1722 break;
1723 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1724 *params = mCaps.maxCombinedAtomicCounters;
1725 break;
1726 case GL_MAX_IMAGE_UNITS:
1727 *params = mCaps.maxImageUnits;
1728 break;
1729 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1730 *params = mCaps.maxCombinedImageUniforms;
1731 break;
1732 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1733 *params = mCaps.maxShaderStorageBufferBindings;
1734 break;
1735 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1736 *params = mCaps.maxCombinedShaderStorageBlocks;
1737 break;
1738 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1739 *params = mCaps.shaderStorageBufferOffsetAlignment;
1740 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001741
1742 // GL_EXT_geometry_shader
1743 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1744 *params = mCaps.maxFramebufferLayers;
1745 break;
1746 case GL_LAYER_PROVOKING_VERTEX_EXT:
1747 *params = mCaps.layerProvokingVertex;
1748 break;
1749 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001750 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001751 break;
1752 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001753 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001754 break;
1755 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001756 *params =
1757 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001758 break;
1759 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1760 *params = mCaps.maxGeometryInputComponents;
1761 break;
1762 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1763 *params = mCaps.maxGeometryOutputComponents;
1764 break;
1765 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1766 *params = mCaps.maxGeometryOutputVertices;
1767 break;
1768 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1769 *params = mCaps.maxGeometryTotalOutputComponents;
1770 break;
1771 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1772 *params = mCaps.maxGeometryShaderInvocations;
1773 break;
1774 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001775 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001776 break;
1777 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001778 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001779 break;
1780 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001781 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001782 break;
1783 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001784 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001785 break;
1786 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001787 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001788 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001789 // GLES1 emulation: Caps queries
1790 case GL_MAX_TEXTURE_UNITS:
1791 *params = mCaps.maxMultitextureUnits;
1792 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001793 case GL_MAX_MODELVIEW_STACK_DEPTH:
1794 *params = mCaps.maxModelviewMatrixStackDepth;
1795 break;
1796 case GL_MAX_PROJECTION_STACK_DEPTH:
1797 *params = mCaps.maxProjectionMatrixStackDepth;
1798 break;
1799 case GL_MAX_TEXTURE_STACK_DEPTH:
1800 *params = mCaps.maxTextureMatrixStackDepth;
1801 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001802 case GL_MAX_LIGHTS:
1803 *params = mCaps.maxLights;
1804 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001805 case GL_MAX_CLIP_PLANES:
1806 *params = mCaps.maxClipPlanes;
1807 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001808 // GLES1 emulation: Vertex attribute queries
1809 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1810 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1811 case GL_COLOR_ARRAY_BUFFER_BINDING:
1812 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1813 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1814 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1815 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1816 break;
1817 case GL_VERTEX_ARRAY_STRIDE:
1818 case GL_NORMAL_ARRAY_STRIDE:
1819 case GL_COLOR_ARRAY_STRIDE:
1820 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1821 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1822 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1823 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1824 break;
1825 case GL_VERTEX_ARRAY_SIZE:
1826 case GL_COLOR_ARRAY_SIZE:
1827 case GL_TEXTURE_COORD_ARRAY_SIZE:
1828 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1829 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1830 break;
1831 case GL_VERTEX_ARRAY_TYPE:
1832 case GL_COLOR_ARRAY_TYPE:
1833 case GL_NORMAL_ARRAY_TYPE:
1834 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1835 case GL_TEXTURE_COORD_ARRAY_TYPE:
1836 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1837 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1838 break;
1839
jchen1082af6202018-06-22 10:59:52 +08001840 // GL_KHR_parallel_shader_compile
1841 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1842 *params = mGLState.getMaxShaderCompilerThreads();
1843 break;
1844
Jamie Madill231c7f52017-04-26 13:45:37 -04001845 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001846 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001847 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001848 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001849}
1850
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001851void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001852{
Shannon Woods53a94a82014-06-24 15:20:36 -04001853 // Queries about context capabilities and maximums are answered by Context.
1854 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001855 switch (pname)
1856 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001857 case GL_MAX_ELEMENT_INDEX:
1858 *params = mCaps.maxElementIndex;
1859 break;
1860 case GL_MAX_UNIFORM_BLOCK_SIZE:
1861 *params = mCaps.maxUniformBlockSize;
1862 break;
1863 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001864 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001865 break;
1866 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001867 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001868 break;
1869 case GL_MAX_SERVER_WAIT_TIMEOUT:
1870 *params = mCaps.maxServerWaitTimeout;
1871 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001872
Jamie Madill231c7f52017-04-26 13:45:37 -04001873 // GL_EXT_disjoint_timer_query
1874 case GL_TIMESTAMP_EXT:
1875 *params = mImplementation->getTimestamp();
1876 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001877
Jamie Madill231c7f52017-04-26 13:45:37 -04001878 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1879 *params = mCaps.maxShaderStorageBlockSize;
1880 break;
1881 default:
1882 UNREACHABLE();
1883 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001884 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001885}
1886
Geoff Lang70d0f492015-12-10 17:45:46 -05001887void Context::getPointerv(GLenum pname, void **params) const
1888{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001889 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001890}
1891
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001892void Context::getPointervRobustANGLERobust(GLenum pname,
1893 GLsizei bufSize,
1894 GLsizei *length,
1895 void **params)
1896{
1897 UNIMPLEMENTED();
1898}
1899
Martin Radev66fb8202016-07-28 11:45:20 +03001900void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001901{
Shannon Woods53a94a82014-06-24 15:20:36 -04001902 // Queries about context capabilities and maximums are answered by Context.
1903 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001904
1905 GLenum nativeType;
1906 unsigned int numParams;
1907 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1908 ASSERT(queryStatus);
1909
1910 if (nativeType == GL_INT)
1911 {
1912 switch (target)
1913 {
1914 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1915 ASSERT(index < 3u);
1916 *data = mCaps.maxComputeWorkGroupCount[index];
1917 break;
1918 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1919 ASSERT(index < 3u);
1920 *data = mCaps.maxComputeWorkGroupSize[index];
1921 break;
1922 default:
1923 mGLState.getIntegeri_v(target, index, data);
1924 }
1925 }
1926 else
1927 {
1928 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1929 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001930}
1931
Brandon Jones59770802018-04-02 13:18:42 -07001932void Context::getIntegeri_vRobust(GLenum target,
1933 GLuint index,
1934 GLsizei bufSize,
1935 GLsizei *length,
1936 GLint *data)
1937{
1938 getIntegeri_v(target, index, data);
1939}
1940
Martin Radev66fb8202016-07-28 11:45:20 +03001941void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001942{
Shannon Woods53a94a82014-06-24 15:20:36 -04001943 // Queries about context capabilities and maximums are answered by Context.
1944 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001945
1946 GLenum nativeType;
1947 unsigned int numParams;
1948 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1949 ASSERT(queryStatus);
1950
1951 if (nativeType == GL_INT_64_ANGLEX)
1952 {
1953 mGLState.getInteger64i_v(target, index, data);
1954 }
1955 else
1956 {
1957 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1958 }
1959}
1960
Brandon Jones59770802018-04-02 13:18:42 -07001961void Context::getInteger64i_vRobust(GLenum target,
1962 GLuint index,
1963 GLsizei bufSize,
1964 GLsizei *length,
1965 GLint64 *data)
1966{
1967 getInteger64i_v(target, index, data);
1968}
1969
Martin Radev66fb8202016-07-28 11:45:20 +03001970void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1971{
1972 // Queries about context capabilities and maximums are answered by Context.
1973 // Queries about current GL state values are answered by State.
1974
1975 GLenum nativeType;
1976 unsigned int numParams;
1977 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1978 ASSERT(queryStatus);
1979
1980 if (nativeType == GL_BOOL)
1981 {
1982 mGLState.getBooleani_v(target, index, data);
1983 }
1984 else
1985 {
1986 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1987 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001988}
1989
Brandon Jones59770802018-04-02 13:18:42 -07001990void Context::getBooleani_vRobust(GLenum target,
1991 GLuint index,
1992 GLsizei bufSize,
1993 GLsizei *length,
1994 GLboolean *data)
1995{
1996 getBooleani_v(target, index, data);
1997}
1998
Corentin Wallez336129f2017-10-17 15:55:40 -04001999void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002000{
2001 Buffer *buffer = mGLState.getTargetBuffer(target);
2002 QueryBufferParameteriv(buffer, pname, params);
2003}
2004
Brandon Jones59770802018-04-02 13:18:42 -07002005void Context::getBufferParameterivRobust(BufferBinding target,
2006 GLenum pname,
2007 GLsizei bufSize,
2008 GLsizei *length,
2009 GLint *params)
2010{
2011 getBufferParameteriv(target, pname, params);
2012}
2013
He Yunchao010e4db2017-03-03 14:22:06 +08002014void Context::getFramebufferAttachmentParameteriv(GLenum target,
2015 GLenum attachment,
2016 GLenum pname,
2017 GLint *params)
2018{
2019 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002020 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002021}
2022
Brandon Jones59770802018-04-02 13:18:42 -07002023void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2024 GLenum attachment,
2025 GLenum pname,
2026 GLsizei bufSize,
2027 GLsizei *length,
2028 GLint *params)
2029{
2030 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2031}
2032
He Yunchao010e4db2017-03-03 14:22:06 +08002033void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2034{
2035 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2036 QueryRenderbufferiv(this, renderbuffer, pname, params);
2037}
2038
Brandon Jones59770802018-04-02 13:18:42 -07002039void Context::getRenderbufferParameterivRobust(GLenum target,
2040 GLenum pname,
2041 GLsizei bufSize,
2042 GLsizei *length,
2043 GLint *params)
2044{
2045 getRenderbufferParameteriv(target, pname, params);
2046}
2047
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002048void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002049{
2050 Texture *texture = getTargetTexture(target);
2051 QueryTexParameterfv(texture, pname, params);
2052}
2053
Brandon Jones59770802018-04-02 13:18:42 -07002054void Context::getTexParameterfvRobust(TextureType target,
2055 GLenum pname,
2056 GLsizei bufSize,
2057 GLsizei *length,
2058 GLfloat *params)
2059{
2060 getTexParameterfv(target, pname, params);
2061}
2062
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002063void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002064{
2065 Texture *texture = getTargetTexture(target);
2066 QueryTexParameteriv(texture, pname, params);
2067}
Jiajia Qin5451d532017-11-16 17:16:34 +08002068
Brandon Jones59770802018-04-02 13:18:42 -07002069void Context::getTexParameterivRobust(TextureType target,
2070 GLenum pname,
2071 GLsizei bufSize,
2072 GLsizei *length,
2073 GLint *params)
2074{
2075 getTexParameteriv(target, pname, params);
2076}
2077
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002078void Context::getTexParameterIivRobust(TextureType target,
2079 GLenum pname,
2080 GLsizei bufSize,
2081 GLsizei *length,
2082 GLint *params)
2083{
2084 UNIMPLEMENTED();
2085}
2086
2087void Context::getTexParameterIuivRobust(TextureType target,
2088 GLenum pname,
2089 GLsizei bufSize,
2090 GLsizei *length,
2091 GLuint *params)
2092{
2093 UNIMPLEMENTED();
2094}
2095
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002096void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002097{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002098 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002099 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002100}
2101
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002102void Context::getTexLevelParameterivRobust(TextureTarget target,
2103 GLint level,
2104 GLenum pname,
2105 GLsizei bufSize,
2106 GLsizei *length,
2107 GLint *params)
2108{
2109 UNIMPLEMENTED();
2110}
2111
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002112void Context::getTexLevelParameterfv(TextureTarget target,
2113 GLint level,
2114 GLenum pname,
2115 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002116{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002117 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002118 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002119}
2120
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002121void Context::getTexLevelParameterfvRobust(TextureTarget target,
2122 GLint level,
2123 GLenum pname,
2124 GLsizei bufSize,
2125 GLsizei *length,
2126 GLfloat *params)
2127{
2128 UNIMPLEMENTED();
2129}
2130
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002131void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002132{
2133 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002134 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002135 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002136}
2137
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002138void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002139{
2140 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002141 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002142 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002143}
2144
Brandon Jones59770802018-04-02 13:18:42 -07002145void Context::texParameterfvRobust(TextureType target,
2146 GLenum pname,
2147 GLsizei bufSize,
2148 const GLfloat *params)
2149{
2150 texParameterfv(target, pname, params);
2151}
2152
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002153void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002154{
2155 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002156 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002157 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002158}
2159
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002160void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002161{
2162 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002163 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002164 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002165}
2166
Brandon Jones59770802018-04-02 13:18:42 -07002167void Context::texParameterivRobust(TextureType target,
2168 GLenum pname,
2169 GLsizei bufSize,
2170 const GLint *params)
2171{
2172 texParameteriv(target, pname, params);
2173}
2174
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002175void Context::texParameterIivRobust(TextureType target,
2176 GLenum pname,
2177 GLsizei bufSize,
2178 const GLint *params)
2179{
2180 UNIMPLEMENTED();
2181}
2182
2183void Context::texParameterIuivRobust(TextureType target,
2184 GLenum pname,
2185 GLsizei bufSize,
2186 const GLuint *params)
2187{
2188 UNIMPLEMENTED();
2189}
2190
Jamie Madill493f9572018-05-24 19:52:15 -04002191void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002192{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002193 // No-op if count draws no primitives for given mode
2194 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002195 {
2196 return;
2197 }
2198
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002199 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002200 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002201 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002202}
2203
Jamie Madill493f9572018-05-24 19:52:15 -04002204void Context::drawArraysInstanced(PrimitiveMode mode,
2205 GLint first,
2206 GLsizei count,
2207 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002208{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002209 // No-op if count draws no primitives for given mode
2210 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002211 {
2212 return;
2213 }
2214
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002215 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002216 ANGLE_CONTEXT_TRY(
2217 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002218 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2219 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002220}
2221
Jamie Madill493f9572018-05-24 19:52:15 -04002222void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002223{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002224 // No-op if count draws no primitives for given mode
2225 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002226 {
2227 return;
2228 }
2229
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002230 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002231 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002232}
2233
Jamie Madill493f9572018-05-24 19:52:15 -04002234void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002235 GLsizei count,
2236 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002237 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002238 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002239{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002240 // No-op if count draws no primitives for given mode
2241 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002242 {
2243 return;
2244 }
2245
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002246 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002247 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002248 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002249}
2250
Jamie Madill493f9572018-05-24 19:52:15 -04002251void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002252 GLuint start,
2253 GLuint end,
2254 GLsizei count,
2255 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002256 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002257{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002258 // No-op if count draws no primitives for given mode
2259 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002260 {
2261 return;
2262 }
2263
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002264 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002265 ANGLE_CONTEXT_TRY(
2266 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002267}
2268
Jamie Madill493f9572018-05-24 19:52:15 -04002269void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002270{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002271 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002272 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002273}
2274
Jamie Madill493f9572018-05-24 19:52:15 -04002275void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002276{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002277 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002278 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002279}
2280
Jamie Madill675fe712016-12-19 13:07:54 -05002281void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002282{
Jamie Madillafa02a22017-11-23 12:57:38 -05002283 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002284}
2285
Jamie Madill675fe712016-12-19 13:07:54 -05002286void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002287{
Jamie Madillafa02a22017-11-23 12:57:38 -05002288 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002289}
2290
Austin Kinross6ee1e782015-05-29 17:05:37 -07002291void Context::insertEventMarker(GLsizei length, const char *marker)
2292{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002293 ASSERT(mImplementation);
2294 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002295}
2296
2297void Context::pushGroupMarker(GLsizei length, const char *marker)
2298{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002299 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002300
2301 if (marker == nullptr)
2302 {
2303 // From the EXT_debug_marker spec,
2304 // "If <marker> is null then an empty string is pushed on the stack."
2305 mImplementation->pushGroupMarker(length, "");
2306 }
2307 else
2308 {
2309 mImplementation->pushGroupMarker(length, marker);
2310 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002311}
2312
2313void Context::popGroupMarker()
2314{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002315 ASSERT(mImplementation);
2316 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002317}
2318
Geoff Langd8605522016-04-13 10:19:12 -04002319void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2320{
2321 Program *programObject = getProgram(program);
2322 ASSERT(programObject);
2323
2324 programObject->bindUniformLocation(location, name);
2325}
2326
Brandon Jones59770802018-04-02 13:18:42 -07002327void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002328{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002329 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002330}
2331
Brandon Jones59770802018-04-02 13:18:42 -07002332void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002333{
2334 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2335}
2336
Brandon Jones59770802018-04-02 13:18:42 -07002337void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002338{
2339 GLfloat I[16];
2340 angle::Matrix<GLfloat>::setToIdentity(I);
2341
2342 mGLState.loadPathRenderingMatrix(matrixMode, I);
2343}
2344
2345void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2346{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002347 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002348 if (!pathObj)
2349 return;
2350
Geoff Lang9bf86f02018-07-26 11:46:34 -04002351 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002352
2353 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2354}
2355
2356void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2357{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002358 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002359 if (!pathObj)
2360 return;
2361
Geoff Lang9bf86f02018-07-26 11:46:34 -04002362 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002363
2364 mImplementation->stencilStrokePath(pathObj, reference, mask);
2365}
2366
2367void Context::coverFillPath(GLuint path, GLenum coverMode)
2368{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002369 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002370 if (!pathObj)
2371 return;
2372
Geoff Lang9bf86f02018-07-26 11:46:34 -04002373 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002374
2375 mImplementation->coverFillPath(pathObj, coverMode);
2376}
2377
2378void Context::coverStrokePath(GLuint path, GLenum coverMode)
2379{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002380 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002381 if (!pathObj)
2382 return;
2383
Geoff Lang9bf86f02018-07-26 11:46:34 -04002384 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002385
2386 mImplementation->coverStrokePath(pathObj, coverMode);
2387}
2388
2389void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2390{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002391 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002392 if (!pathObj)
2393 return;
2394
Geoff Lang9bf86f02018-07-26 11:46:34 -04002395 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002396
2397 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2398}
2399
2400void Context::stencilThenCoverStrokePath(GLuint path,
2401 GLint reference,
2402 GLuint mask,
2403 GLenum coverMode)
2404{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002405 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002406 if (!pathObj)
2407 return;
2408
Geoff Lang9bf86f02018-07-26 11:46:34 -04002409 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002410
2411 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2412}
2413
Sami Väisänend59ca052016-06-21 16:10:00 +03002414void Context::coverFillPathInstanced(GLsizei numPaths,
2415 GLenum pathNameType,
2416 const void *paths,
2417 GLuint pathBase,
2418 GLenum coverMode,
2419 GLenum transformType,
2420 const GLfloat *transformValues)
2421{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002422 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002423
Geoff Lang9bf86f02018-07-26 11:46:34 -04002424 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002425
2426 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2427}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002428
Sami Väisänend59ca052016-06-21 16:10:00 +03002429void Context::coverStrokePathInstanced(GLsizei numPaths,
2430 GLenum pathNameType,
2431 const void *paths,
2432 GLuint pathBase,
2433 GLenum coverMode,
2434 GLenum transformType,
2435 const GLfloat *transformValues)
2436{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002437 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002438
2439 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002440 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002441
2442 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2443 transformValues);
2444}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002445
Sami Väisänend59ca052016-06-21 16:10:00 +03002446void Context::stencilFillPathInstanced(GLsizei numPaths,
2447 GLenum pathNameType,
2448 const void *paths,
2449 GLuint pathBase,
2450 GLenum fillMode,
2451 GLuint mask,
2452 GLenum transformType,
2453 const GLfloat *transformValues)
2454{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002455 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002456
2457 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002458 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002459
2460 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2461 transformValues);
2462}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002463
Sami Väisänend59ca052016-06-21 16:10:00 +03002464void Context::stencilStrokePathInstanced(GLsizei numPaths,
2465 GLenum pathNameType,
2466 const void *paths,
2467 GLuint pathBase,
2468 GLint reference,
2469 GLuint mask,
2470 GLenum transformType,
2471 const GLfloat *transformValues)
2472{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002473 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002474
Geoff Lang9bf86f02018-07-26 11:46:34 -04002475 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002476
2477 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2478 transformValues);
2479}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002480
Sami Väisänend59ca052016-06-21 16:10:00 +03002481void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2482 GLenum pathNameType,
2483 const void *paths,
2484 GLuint pathBase,
2485 GLenum fillMode,
2486 GLuint mask,
2487 GLenum coverMode,
2488 GLenum transformType,
2489 const GLfloat *transformValues)
2490{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002491 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002492
Geoff Lang9bf86f02018-07-26 11:46:34 -04002493 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002494
2495 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2496 transformType, transformValues);
2497}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002498
Sami Väisänend59ca052016-06-21 16:10:00 +03002499void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2500 GLenum pathNameType,
2501 const void *paths,
2502 GLuint pathBase,
2503 GLint reference,
2504 GLuint mask,
2505 GLenum coverMode,
2506 GLenum transformType,
2507 const GLfloat *transformValues)
2508{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002509 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002510
Geoff Lang9bf86f02018-07-26 11:46:34 -04002511 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002512
2513 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2514 transformType, transformValues);
2515}
2516
Sami Väisänen46eaa942016-06-29 10:26:37 +03002517void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2518{
2519 auto *programObject = getProgram(program);
2520
2521 programObject->bindFragmentInputLocation(location, name);
2522}
2523
2524void Context::programPathFragmentInputGen(GLuint program,
2525 GLint location,
2526 GLenum genMode,
2527 GLint components,
2528 const GLfloat *coeffs)
2529{
2530 auto *programObject = getProgram(program);
2531
jchen103fd614d2018-08-13 12:21:58 +08002532 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002533}
2534
jchen1015015f72017-03-16 13:54:21 +08002535GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2536{
jchen10fd7c3b52017-03-21 15:36:03 +08002537 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002538 return QueryProgramResourceIndex(programObject, programInterface, name);
2539}
2540
jchen10fd7c3b52017-03-21 15:36:03 +08002541void Context::getProgramResourceName(GLuint program,
2542 GLenum programInterface,
2543 GLuint index,
2544 GLsizei bufSize,
2545 GLsizei *length,
2546 GLchar *name)
2547{
2548 const auto *programObject = getProgram(program);
2549 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2550}
2551
jchen10191381f2017-04-11 13:59:04 +08002552GLint Context::getProgramResourceLocation(GLuint program,
2553 GLenum programInterface,
2554 const GLchar *name)
2555{
2556 const auto *programObject = getProgram(program);
2557 return QueryProgramResourceLocation(programObject, programInterface, name);
2558}
2559
jchen10880683b2017-04-12 16:21:55 +08002560void Context::getProgramResourceiv(GLuint program,
2561 GLenum programInterface,
2562 GLuint index,
2563 GLsizei propCount,
2564 const GLenum *props,
2565 GLsizei bufSize,
2566 GLsizei *length,
2567 GLint *params)
2568{
2569 const auto *programObject = getProgram(program);
2570 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2571 length, params);
2572}
2573
jchen10d9cd7b72017-08-30 15:04:25 +08002574void Context::getProgramInterfaceiv(GLuint program,
2575 GLenum programInterface,
2576 GLenum pname,
2577 GLint *params)
2578{
2579 const auto *programObject = getProgram(program);
2580 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2581}
2582
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002583void Context::getProgramInterfaceivRobust(GLuint program,
2584 GLenum programInterface,
2585 GLenum pname,
2586 GLsizei bufSize,
2587 GLsizei *length,
2588 GLint *params)
2589{
2590 UNIMPLEMENTED();
2591}
2592
Jamie Madill306b6c12018-07-27 08:12:49 -04002593void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002594{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002595 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002596}
2597
2598// Get one of the recorded errors and clear its flag, if any.
2599// [OpenGL ES 2.0.24] section 2.5 page 13.
2600GLenum Context::getError()
2601{
Geoff Langda5777c2014-07-11 09:52:58 -04002602 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002603 {
Geoff Langda5777c2014-07-11 09:52:58 -04002604 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002605 }
Geoff Langda5777c2014-07-11 09:52:58 -04002606 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002607 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002608 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002609 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002610}
2611
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002612// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002613void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002614{
2615 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002616 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002617 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002618 mContextLostForced = true;
2619 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002620 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002621}
2622
Jamie Madill427064d2018-04-13 16:20:34 -04002623bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002624{
2625 return mContextLost;
2626}
2627
Jamie Madillfa920eb2018-01-04 11:45:50 -05002628GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002629{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002630 // Even if the application doesn't want to know about resets, we want to know
2631 // as it will allow us to skip all the calls.
2632 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002633 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002634 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002635 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002636 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002637 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002638
2639 // EXT_robustness, section 2.6: If the reset notification behavior is
2640 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2641 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2642 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002643 }
2644
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002645 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2646 // status should be returned at least once, and GL_NO_ERROR should be returned
2647 // once the device has finished resetting.
2648 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002649 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002650 ASSERT(mResetStatus == GL_NO_ERROR);
2651 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002652
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002653 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002654 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002655 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002656 }
2657 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002658 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002659 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002660 // If markContextLost was used to mark the context lost then
2661 // assume that is not recoverable, and continue to report the
2662 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002663 mResetStatus = mImplementation->getResetStatus();
2664 }
Jamie Madill893ab082014-05-16 16:56:10 -04002665
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002666 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002667}
2668
2669bool Context::isResetNotificationEnabled()
2670{
2671 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2672}
2673
Corentin Walleze3b10e82015-05-20 11:06:25 -04002674const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002675{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002676 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002677}
2678
2679EGLenum Context::getClientType() const
2680{
2681 return mClientType;
2682}
2683
2684EGLenum Context::getRenderBuffer() const
2685{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002686 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2687 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002688 {
2689 return EGL_NONE;
2690 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002691
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002692 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002693 ASSERT(backAttachment != nullptr);
2694 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002695}
2696
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002697VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002698{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002699 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002700 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2701 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002702 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002703 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2704 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002705
Jamie Madill96a483b2017-06-27 16:49:21 -04002706 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002707 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002708
2709 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002710}
2711
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002712TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002713{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002714 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002715 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2716 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002717 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002718 transformFeedback =
2719 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002720 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002721 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002722 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002723
2724 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002725}
2726
2727bool Context::isVertexArrayGenerated(GLuint vertexArray)
2728{
Jamie Madill96a483b2017-06-27 16:49:21 -04002729 ASSERT(mVertexArrayMap.contains(0));
2730 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002731}
2732
2733bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2734{
Jamie Madill96a483b2017-06-27 16:49:21 -04002735 ASSERT(mTransformFeedbackMap.contains(0));
2736 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002737}
2738
Shannon Woods53a94a82014-06-24 15:20:36 -04002739void Context::detachTexture(GLuint texture)
2740{
2741 // Simple pass-through to State's detachTexture method, as textures do not require
2742 // allocation map management either here or in the resource manager at detach time.
2743 // Zero textures are held by the Context, and we don't attempt to request them from
2744 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002745 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002746}
2747
James Darpinian4d9d4832018-03-13 12:43:28 -07002748void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002749{
Yuly Novikov5807a532015-12-03 13:01:22 -05002750 // Simple pass-through to State's detachBuffer method, since
2751 // only buffer attachments to container objects that are bound to the current context
2752 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002753
Yuly Novikov5807a532015-12-03 13:01:22 -05002754 // [OpenGL ES 3.2] section 5.1.2 page 45:
2755 // Attachments to unbound container objects, such as
2756 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2757 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002758 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002759}
2760
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002761void Context::detachFramebuffer(GLuint framebuffer)
2762{
Shannon Woods53a94a82014-06-24 15:20:36 -04002763 // Framebuffer detachment is handled by Context, because 0 is a valid
2764 // Framebuffer object, and a pointer to it must be passed from Context
2765 // to State at binding time.
2766
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002767 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002768 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2769 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2770 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002771
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002772 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002773 {
2774 bindReadFramebuffer(0);
2775 }
2776
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002777 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002778 {
2779 bindDrawFramebuffer(0);
2780 }
2781}
2782
2783void Context::detachRenderbuffer(GLuint renderbuffer)
2784{
Jamie Madilla02315b2017-02-23 14:14:47 -05002785 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002786}
2787
Jamie Madill57a89722013-07-02 11:57:03 -04002788void Context::detachVertexArray(GLuint vertexArray)
2789{
Jamie Madill77a72f62015-04-14 11:18:32 -04002790 // Vertex array detachment is handled by Context, because 0 is a valid
2791 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002792 // binding time.
2793
Jamie Madill57a89722013-07-02 11:57:03 -04002794 // [OpenGL ES 3.0.2] section 2.10 page 43:
2795 // If a vertex array object that is currently bound is deleted, the binding
2796 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002797 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002798 {
2799 bindVertexArray(0);
2800 }
2801}
2802
Geoff Langc8058452014-02-03 12:04:11 -05002803void Context::detachTransformFeedback(GLuint transformFeedback)
2804{
Corentin Walleza2257da2016-04-19 16:43:12 -04002805 // Transform feedback detachment is handled by Context, because 0 is a valid
2806 // transform feedback, and a pointer to it must be passed from Context to State at
2807 // binding time.
2808
2809 // The OpenGL specification doesn't mention what should happen when the currently bound
2810 // transform feedback object is deleted. Since it is a container object, we treat it like
2811 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002812 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002813 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002814 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002815 }
Geoff Langc8058452014-02-03 12:04:11 -05002816}
2817
Jamie Madilldc356042013-07-19 16:36:57 -04002818void Context::detachSampler(GLuint sampler)
2819{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002820 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002821}
2822
Yunchao Hea336b902017-08-02 16:05:21 +08002823void Context::detachProgramPipeline(GLuint pipeline)
2824{
2825 mGLState.detachProgramPipeline(this, pipeline);
2826}
2827
Jamie Madill3ef140a2017-08-26 23:11:21 -04002828void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002829{
Shaodde78e82017-05-22 14:13:27 +08002830 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002831 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002832}
2833
Jamie Madille29d1672013-07-19 16:36:57 -04002834void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2835{
Geoff Langc1984ed2016-10-07 12:41:00 -04002836 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002837 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002838 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002839 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002840}
Jamie Madille29d1672013-07-19 16:36:57 -04002841
Geoff Langc1984ed2016-10-07 12:41:00 -04002842void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2843{
2844 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002845 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002846 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002847 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002848}
2849
Brandon Jones59770802018-04-02 13:18:42 -07002850void Context::samplerParameterivRobust(GLuint sampler,
2851 GLenum pname,
2852 GLsizei bufSize,
2853 const GLint *param)
2854{
2855 samplerParameteriv(sampler, pname, param);
2856}
2857
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002858void Context::samplerParameterIivRobust(GLuint sampler,
2859 GLenum pname,
2860 GLsizei bufSize,
2861 const GLint *param)
2862{
2863 UNIMPLEMENTED();
2864}
2865
2866void Context::samplerParameterIuivRobust(GLuint sampler,
2867 GLenum pname,
2868 GLsizei bufSize,
2869 const GLuint *param)
2870{
2871 UNIMPLEMENTED();
2872}
2873
Jamie Madille29d1672013-07-19 16:36:57 -04002874void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2875{
Geoff Langc1984ed2016-10-07 12:41:00 -04002876 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002877 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002878 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002879 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002880}
2881
Geoff Langc1984ed2016-10-07 12:41:00 -04002882void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002883{
Geoff Langc1984ed2016-10-07 12:41:00 -04002884 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002885 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002886 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002887 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002888}
2889
Brandon Jones59770802018-04-02 13:18:42 -07002890void Context::samplerParameterfvRobust(GLuint sampler,
2891 GLenum pname,
2892 GLsizei bufSize,
2893 const GLfloat *param)
2894{
2895 samplerParameterfv(sampler, pname, param);
2896}
2897
Geoff Langc1984ed2016-10-07 12:41:00 -04002898void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002899{
Geoff Langc1984ed2016-10-07 12:41:00 -04002900 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002901 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002902 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002903 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002904}
Jamie Madill9675b802013-07-19 16:36:59 -04002905
Brandon Jones59770802018-04-02 13:18:42 -07002906void Context::getSamplerParameterivRobust(GLuint sampler,
2907 GLenum pname,
2908 GLsizei bufSize,
2909 GLsizei *length,
2910 GLint *params)
2911{
2912 getSamplerParameteriv(sampler, pname, params);
2913}
2914
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002915void Context::getSamplerParameterIivRobust(GLuint sampler,
2916 GLenum pname,
2917 GLsizei bufSize,
2918 GLsizei *length,
2919 GLint *params)
2920{
2921 UNIMPLEMENTED();
2922}
2923
2924void Context::getSamplerParameterIuivRobust(GLuint sampler,
2925 GLenum pname,
2926 GLsizei bufSize,
2927 GLsizei *length,
2928 GLuint *params)
2929{
2930 UNIMPLEMENTED();
2931}
2932
Geoff Langc1984ed2016-10-07 12:41:00 -04002933void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2934{
2935 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002936 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002937 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002938 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002939}
2940
Brandon Jones59770802018-04-02 13:18:42 -07002941void Context::getSamplerParameterfvRobust(GLuint sampler,
2942 GLenum pname,
2943 GLsizei bufSize,
2944 GLsizei *length,
2945 GLfloat *params)
2946{
2947 getSamplerParameterfv(sampler, pname, params);
2948}
2949
Olli Etuahof0fee072016-03-30 15:11:58 +03002950void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2951{
2952 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002953 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002954}
2955
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002956void Context::initRendererString()
2957{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002958 std::ostringstream rendererString;
2959 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002960 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002961 rendererString << ")";
2962
Geoff Langcec35902014-04-16 10:52:36 -04002963 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002964}
2965
Geoff Langc339c4e2016-11-29 10:37:36 -05002966void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002967{
Geoff Langc339c4e2016-11-29 10:37:36 -05002968 const Version &clientVersion = getClientVersion();
2969
2970 std::ostringstream versionString;
2971 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2972 << ANGLE_VERSION_STRING << ")";
2973 mVersionString = MakeStaticString(versionString.str());
2974
2975 std::ostringstream shadingLanguageVersionString;
2976 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2977 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2978 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2979 << ")";
2980 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002981}
2982
Geoff Langcec35902014-04-16 10:52:36 -04002983void Context::initExtensionStrings()
2984{
Geoff Langc339c4e2016-11-29 10:37:36 -05002985 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2986 std::ostringstream combinedStringStream;
2987 std::copy(strings.begin(), strings.end(),
2988 std::ostream_iterator<const char *>(combinedStringStream, " "));
2989 return MakeStaticString(combinedStringStream.str());
2990 };
2991
2992 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002993 for (const auto &extensionString : mExtensions.getStrings())
2994 {
2995 mExtensionStrings.push_back(MakeStaticString(extensionString));
2996 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002997 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002998
Geoff Langc339c4e2016-11-29 10:37:36 -05002999 mRequestableExtensionStrings.clear();
3000 for (const auto &extensionInfo : GetExtensionInfoMap())
3001 {
3002 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003003 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003004 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003005 {
3006 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3007 }
3008 }
3009 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003010}
3011
Geoff Langc339c4e2016-11-29 10:37:36 -05003012const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003013{
Geoff Langc339c4e2016-11-29 10:37:36 -05003014 switch (name)
3015 {
3016 case GL_VENDOR:
3017 return reinterpret_cast<const GLubyte *>("Google Inc.");
3018
3019 case GL_RENDERER:
3020 return reinterpret_cast<const GLubyte *>(mRendererString);
3021
3022 case GL_VERSION:
3023 return reinterpret_cast<const GLubyte *>(mVersionString);
3024
3025 case GL_SHADING_LANGUAGE_VERSION:
3026 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3027
3028 case GL_EXTENSIONS:
3029 return reinterpret_cast<const GLubyte *>(mExtensionString);
3030
3031 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3032 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3033
3034 default:
3035 UNREACHABLE();
3036 return nullptr;
3037 }
Geoff Langcec35902014-04-16 10:52:36 -04003038}
3039
Geoff Langc339c4e2016-11-29 10:37:36 -05003040const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003041{
Geoff Langc339c4e2016-11-29 10:37:36 -05003042 switch (name)
3043 {
3044 case GL_EXTENSIONS:
3045 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3046
3047 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3048 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3049
3050 default:
3051 UNREACHABLE();
3052 return nullptr;
3053 }
Geoff Langcec35902014-04-16 10:52:36 -04003054}
3055
3056size_t Context::getExtensionStringCount() const
3057{
3058 return mExtensionStrings.size();
3059}
3060
Geoff Lang111a99e2017-10-17 10:58:41 -04003061bool Context::isExtensionRequestable(const char *name)
3062{
3063 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3064 auto extension = extensionInfos.find(name);
3065
Geoff Lang111a99e2017-10-17 10:58:41 -04003066 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003067 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003068}
3069
Geoff Langc339c4e2016-11-29 10:37:36 -05003070void Context::requestExtension(const char *name)
3071{
3072 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3073 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3074 const auto &extension = extensionInfos.at(name);
3075 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003076 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003077
3078 if (mExtensions.*(extension.ExtensionsMember))
3079 {
3080 // Extension already enabled
3081 return;
3082 }
3083
3084 mExtensions.*(extension.ExtensionsMember) = true;
3085 updateCaps();
3086 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003087
Jamie Madill2f348d22017-06-05 10:50:59 -04003088 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3089 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003090
Jamie Madill81c2e252017-09-09 23:32:46 -04003091 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3092 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003093 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003094 for (auto &zeroTexture : mZeroTextures)
3095 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003096 if (zeroTexture.get() != nullptr)
3097 {
3098 zeroTexture->signalDirty(this, InitState::Initialized);
3099 }
Geoff Lang9aded172017-04-05 11:07:56 -04003100 }
3101
Jamie Madillb983a4b2018-08-01 11:34:51 -04003102 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003103}
3104
3105size_t Context::getRequestableExtensionStringCount() const
3106{
3107 return mRequestableExtensionStrings.size();
3108}
3109
Jamie Madill493f9572018-05-24 19:52:15 -04003110void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003111{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003112 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003113 ASSERT(transformFeedback != nullptr);
3114 ASSERT(!transformFeedback->isPaused());
3115
Jamie Madill6c1f6712017-02-14 19:08:04 -05003116 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Jamie Madilld84b6732018-09-06 15:54:35 -04003117 mStateCache.onTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003118}
3119
3120bool Context::hasActiveTransformFeedback(GLuint program) const
3121{
3122 for (auto pair : mTransformFeedbackMap)
3123 {
3124 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3125 {
3126 return true;
3127 }
3128 }
3129 return false;
3130}
3131
Geoff Lang33f11fb2018-05-07 13:42:47 -04003132Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003133{
3134 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3135
jchen1082af6202018-06-22 10:59:52 +08003136 // Explicitly enable GL_KHR_parallel_shader_compile
3137 supportedExtensions.parallelShaderCompile = true;
3138
Geoff Langb0f917f2017-12-05 13:41:54 -05003139 if (getClientVersion() < ES_2_0)
3140 {
3141 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003142 supportedExtensions.pointSizeArray = true;
3143 supportedExtensions.textureCubeMap = true;
3144 supportedExtensions.pointSprite = true;
3145 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003146 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003147 }
3148
3149 if (getClientVersion() < ES_3_0)
3150 {
3151 // Disable ES3+ extensions
3152 supportedExtensions.colorBufferFloat = false;
3153 supportedExtensions.eglImageExternalEssl3 = false;
3154 supportedExtensions.textureNorm16 = false;
3155 supportedExtensions.multiview = false;
3156 supportedExtensions.maxViews = 1u;
3157 }
3158
3159 if (getClientVersion() < ES_3_1)
3160 {
3161 // Disable ES3.1+ extensions
3162 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003163
3164 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3165 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003166 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003167 }
3168
3169 if (getClientVersion() > ES_2_0)
3170 {
3171 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3172 // supportedExtensions.sRGB = false;
3173 }
3174
3175 // Some extensions are always available because they are implemented in the GL layer.
3176 supportedExtensions.bindUniformLocation = true;
3177 supportedExtensions.vertexArrayObject = true;
3178 supportedExtensions.bindGeneratesResource = true;
3179 supportedExtensions.clientArrays = true;
3180 supportedExtensions.requestExtension = true;
3181
3182 // Enable the no error extension if the context was created with the flag.
3183 supportedExtensions.noError = mSkipValidation;
3184
3185 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003186 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003187
3188 // Explicitly enable GL_KHR_debug
3189 supportedExtensions.debug = true;
3190 supportedExtensions.maxDebugMessageLength = 1024;
3191 supportedExtensions.maxDebugLoggedMessages = 1024;
3192 supportedExtensions.maxDebugGroupStackDepth = 1024;
3193 supportedExtensions.maxLabelLength = 1024;
3194
3195 // Explicitly enable GL_ANGLE_robust_client_memory
3196 supportedExtensions.robustClientMemory = true;
3197
3198 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003199 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003200
3201 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3202 // supports it.
3203 supportedExtensions.robustBufferAccessBehavior =
3204 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3205
3206 // Enable the cache control query unconditionally.
3207 supportedExtensions.programCacheControl = true;
3208
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003209 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003210 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003211 {
3212 // GL_ANGLE_explicit_context_gles1
3213 supportedExtensions.explicitContextGles1 = true;
3214 // GL_ANGLE_explicit_context
3215 supportedExtensions.explicitContext = true;
3216 }
3217
Geoff Langb0f917f2017-12-05 13:41:54 -05003218 return supportedExtensions;
3219}
3220
Geoff Lang33f11fb2018-05-07 13:42:47 -04003221void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003222{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003223 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003224
Geoff Lang33f11fb2018-05-07 13:42:47 -04003225 mSupportedExtensions = generateSupportedExtensions();
3226 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003227
3228 mLimitations = mImplementation->getNativeLimitations();
3229
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003230 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3231 if (getClientVersion() < Version(2, 0))
3232 {
3233 mCaps.maxMultitextureUnits = 4;
3234 mCaps.maxClipPlanes = 6;
3235 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003236 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3237 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3238 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003239 mCaps.minSmoothPointSize = 1.0f;
3240 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003241 mCaps.minSmoothLineWidth = 1.0f;
3242 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003243 }
3244
Luc Ferronad2ae932018-06-11 15:31:17 -04003245 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003246 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003247
Luc Ferronad2ae932018-06-11 15:31:17 -04003248 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3249
Jamie Madill0f80ed82017-09-19 00:24:56 -04003250 if (getClientVersion() < ES_3_1)
3251 {
3252 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3253 }
3254 else
3255 {
3256 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3257 }
Geoff Lang301d1612014-07-09 10:34:37 -04003258
Jiawei Shao54aafe52018-04-27 14:54:57 +08003259 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3260 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003261 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3262
Jamie Madill0f80ed82017-09-19 00:24:56 -04003263 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3264 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3265
3266 // Limit textures as well, so we can use fast bitsets with texture bindings.
3267 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003268 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3269 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3270 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3271 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003272
Jiawei Shaodb342272017-09-27 10:21:45 +08003273 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3274
Geoff Langc287ea62016-09-16 14:46:51 -04003275 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003276 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003277 for (const auto &extensionInfo : GetExtensionInfoMap())
3278 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003279 // If the user has requested that extensions start disabled and they are requestable,
3280 // disable them.
3281 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003282 {
3283 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3284 }
3285 }
3286
3287 // Generate texture caps
3288 updateCaps();
3289}
3290
3291void Context::updateCaps()
3292{
Geoff Lang900013c2014-07-07 11:32:19 -04003293 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003294 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003295
Jamie Madill7b62cf92017-11-02 15:20:49 -04003296 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003297 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003298 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003299 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003300
Geoff Lang0d8b7242015-09-09 14:56:53 -04003301 // Update the format caps based on the client version and extensions.
3302 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3303 // ES3.
3304 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003305 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003306 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003307 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003308 formatCaps.textureAttachment =
3309 formatCaps.textureAttachment &&
3310 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3311 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3312 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003313
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003314 // OpenGL ES does not support multisampling with non-rendererable formats
3315 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003316 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003317 (getClientVersion() < ES_3_1 &&
3318 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003319 {
Geoff Langd87878e2014-09-19 15:42:59 -04003320 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003321 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003322 else
3323 {
3324 // We may have limited the max samples for some required renderbuffer formats due to
3325 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3326 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3327
3328 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3329 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3330 // exception of signed and unsigned integer formats."
3331 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3332 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3333 {
3334 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3335 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3336 }
3337
3338 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3339 if (getClientVersion() >= ES_3_1)
3340 {
3341 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3342 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3343 // the exception that the signed and unsigned integer formats are required only to
3344 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3345 // multisamples, which must be at least one."
3346 if (formatInfo.componentType == GL_INT ||
3347 formatInfo.componentType == GL_UNSIGNED_INT)
3348 {
3349 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3350 }
3351
3352 // GLES 3.1 section 19.3.1.
3353 if (formatCaps.texturable)
3354 {
3355 if (formatInfo.depthBits > 0)
3356 {
3357 mCaps.maxDepthTextureSamples =
3358 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3359 }
3360 else if (formatInfo.redBits > 0)
3361 {
3362 mCaps.maxColorTextureSamples =
3363 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3364 }
3365 }
3366 }
3367 }
Geoff Langd87878e2014-09-19 15:42:59 -04003368
3369 if (formatCaps.texturable && formatInfo.compressed)
3370 {
Geoff Langca271392017-04-05 12:30:00 -04003371 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003372 }
3373
Geoff Langca271392017-04-05 12:30:00 -04003374 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003375 }
Jamie Madill32447362017-06-28 14:53:52 -04003376
3377 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003378 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003379 {
3380 mMemoryProgramCache = nullptr;
3381 }
Corentin Walleze4477002017-12-01 14:39:58 -05003382
3383 // Compute which buffer types are allowed
3384 mValidBufferBindings.reset();
3385 mValidBufferBindings.set(BufferBinding::ElementArray);
3386 mValidBufferBindings.set(BufferBinding::Array);
3387
3388 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3389 {
3390 mValidBufferBindings.set(BufferBinding::PixelPack);
3391 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3392 }
3393
3394 if (getClientVersion() >= ES_3_0)
3395 {
3396 mValidBufferBindings.set(BufferBinding::CopyRead);
3397 mValidBufferBindings.set(BufferBinding::CopyWrite);
3398 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3399 mValidBufferBindings.set(BufferBinding::Uniform);
3400 }
3401
3402 if (getClientVersion() >= ES_3_1)
3403 {
3404 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3405 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3406 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3407 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3408 }
jchen107ae70d82018-07-06 13:47:01 +08003409
3410 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Geoff Lang493daf52014-07-03 13:38:44 -04003411}
3412
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003413void Context::initWorkarounds()
3414{
Jamie Madill761b02c2017-06-23 16:27:06 -04003415 // Apply back-end workarounds.
3416 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3417
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003418 // Lose the context upon out of memory error if the application is
3419 // expecting to watch for those events.
3420 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3421}
3422
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003423// Return true if the draw is a no-op, else return false.
3424// A no-op draw occurs if the count of vertices is less than the minimum required to
3425// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3426bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3427{
3428 return count < kMinimumPrimitiveCounts[mode];
3429}
3430
3431bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3432{
3433 return (instanceCount == 0) || noopDraw(mode, count);
3434}
3435
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003436Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003437{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003438 if (mGLES1Renderer)
3439 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003440 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003441 }
3442
Geoff Lang9bf86f02018-07-26 11:46:34 -04003443 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003444
3445 if (isRobustResourceInitEnabled())
3446 {
3447 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3448 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3449 }
3450
Geoff Langa8cb2872018-03-09 16:09:40 -05003451 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003452 return NoError();
3453}
3454
3455Error Context::prepareForClear(GLbitfield mask)
3456{
Geoff Langa8cb2872018-03-09 16:09:40 -05003457 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003458 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003459 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003460 return NoError();
3461}
3462
3463Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3464{
Geoff Langa8cb2872018-03-09 16:09:40 -05003465 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003466 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3467 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003468 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003469 return NoError();
3470}
3471
Geoff Langa8cb2872018-03-09 16:09:40 -05003472Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003473{
Geoff Langa8cb2872018-03-09 16:09:40 -05003474 ANGLE_TRY(syncDirtyObjects(objectMask));
3475 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003476 return NoError();
3477}
3478
Geoff Langa8cb2872018-03-09 16:09:40 -05003479Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003480{
3481 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003482 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003483 mGLState.clearDirtyBits();
3484 return NoError();
3485}
3486
Geoff Langa8cb2872018-03-09 16:09:40 -05003487Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003488{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003489 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003490 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003491 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003492 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003493}
Jamie Madillc29968b2016-01-20 11:17:23 -05003494
Geoff Langa8cb2872018-03-09 16:09:40 -05003495Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003496{
3497 return mGLState.syncDirtyObjects(this, objectMask);
3498}
3499
Jamie Madillc29968b2016-01-20 11:17:23 -05003500void Context::blitFramebuffer(GLint srcX0,
3501 GLint srcY0,
3502 GLint srcX1,
3503 GLint srcY1,
3504 GLint dstX0,
3505 GLint dstY0,
3506 GLint dstX1,
3507 GLint dstY1,
3508 GLbitfield mask,
3509 GLenum filter)
3510{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003511 if (mask == 0)
3512 {
3513 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3514 // buffers are copied.
3515 return;
3516 }
3517
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003518 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003519 ASSERT(drawFramebuffer);
3520
3521 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3522 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3523
Jamie Madillbc918e72018-03-08 09:47:21 -05003524 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003525
Jamie Madillc564c072017-06-01 12:45:42 -04003526 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003527}
Jamie Madillc29968b2016-01-20 11:17:23 -05003528
3529void Context::clear(GLbitfield mask)
3530{
Geoff Langd4fff502017-09-22 11:28:28 -04003531 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3532 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003533}
3534
3535void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3536{
Geoff Langd4fff502017-09-22 11:28:28 -04003537 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3538 ANGLE_CONTEXT_TRY(
3539 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003540}
3541
3542void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3543{
Geoff Langd4fff502017-09-22 11:28:28 -04003544 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3545 ANGLE_CONTEXT_TRY(
3546 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003547}
3548
3549void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3550{
Geoff Langd4fff502017-09-22 11:28:28 -04003551 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3552 ANGLE_CONTEXT_TRY(
3553 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003554}
3555
3556void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3557{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003558 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003559 ASSERT(framebufferObject);
3560
3561 // If a buffer is not present, the clear has no effect
3562 if (framebufferObject->getDepthbuffer() == nullptr &&
3563 framebufferObject->getStencilbuffer() == nullptr)
3564 {
3565 return;
3566 }
3567
Geoff Langd4fff502017-09-22 11:28:28 -04003568 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3569 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003570}
3571
3572void Context::readPixels(GLint x,
3573 GLint y,
3574 GLsizei width,
3575 GLsizei height,
3576 GLenum format,
3577 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003578 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003579{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003580 if (width == 0 || height == 0)
3581 {
3582 return;
3583 }
3584
Jamie Madillbc918e72018-03-08 09:47:21 -05003585 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003586
Jamie Madillb6664922017-07-25 12:55:04 -04003587 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3588 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003589
3590 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003591 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003592}
3593
Brandon Jones59770802018-04-02 13:18:42 -07003594void Context::readPixelsRobust(GLint x,
3595 GLint y,
3596 GLsizei width,
3597 GLsizei height,
3598 GLenum format,
3599 GLenum type,
3600 GLsizei bufSize,
3601 GLsizei *length,
3602 GLsizei *columns,
3603 GLsizei *rows,
3604 void *pixels)
3605{
3606 readPixels(x, y, width, height, format, type, pixels);
3607}
3608
3609void Context::readnPixelsRobust(GLint x,
3610 GLint y,
3611 GLsizei width,
3612 GLsizei height,
3613 GLenum format,
3614 GLenum type,
3615 GLsizei bufSize,
3616 GLsizei *length,
3617 GLsizei *columns,
3618 GLsizei *rows,
3619 void *data)
3620{
3621 readPixels(x, y, width, height, format, type, data);
3622}
3623
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003624void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003625 GLint level,
3626 GLenum internalformat,
3627 GLint x,
3628 GLint y,
3629 GLsizei width,
3630 GLsizei height,
3631 GLint border)
3632{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003633 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003634 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003635
Jamie Madillc29968b2016-01-20 11:17:23 -05003636 Rectangle sourceArea(x, y, width, height);
3637
Jamie Madill05b35b22017-10-03 09:01:44 -04003638 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003639 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003640 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003641}
3642
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003643void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003644 GLint level,
3645 GLint xoffset,
3646 GLint yoffset,
3647 GLint x,
3648 GLint y,
3649 GLsizei width,
3650 GLsizei height)
3651{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003652 if (width == 0 || height == 0)
3653 {
3654 return;
3655 }
3656
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003657 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003658 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003659
Jamie Madillc29968b2016-01-20 11:17:23 -05003660 Offset destOffset(xoffset, yoffset, 0);
3661 Rectangle sourceArea(x, y, width, height);
3662
Jamie Madill05b35b22017-10-03 09:01:44 -04003663 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003664 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003665 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003666}
3667
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003668void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003669 GLint level,
3670 GLint xoffset,
3671 GLint yoffset,
3672 GLint zoffset,
3673 GLint x,
3674 GLint y,
3675 GLsizei width,
3676 GLsizei height)
3677{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003678 if (width == 0 || height == 0)
3679 {
3680 return;
3681 }
3682
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003683 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003684 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003685
Jamie Madillc29968b2016-01-20 11:17:23 -05003686 Offset destOffset(xoffset, yoffset, zoffset);
3687 Rectangle sourceArea(x, y, width, height);
3688
Jamie Madill05b35b22017-10-03 09:01:44 -04003689 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3690 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003691 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3692 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003693}
3694
3695void Context::framebufferTexture2D(GLenum target,
3696 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003697 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003698 GLuint texture,
3699 GLint level)
3700{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003701 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003702 ASSERT(framebuffer);
3703
3704 if (texture != 0)
3705 {
3706 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003707 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003708 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003709 }
3710 else
3711 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003712 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003713 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003714
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003715 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003716}
3717
3718void Context::framebufferRenderbuffer(GLenum target,
3719 GLenum attachment,
3720 GLenum renderbuffertarget,
3721 GLuint renderbuffer)
3722{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003723 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003724 ASSERT(framebuffer);
3725
3726 if (renderbuffer != 0)
3727 {
3728 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003729
Jamie Madillcc129372018-04-12 09:13:18 -04003730 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003731 renderbufferObject);
3732 }
3733 else
3734 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003735 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003736 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003737
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003738 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003739}
3740
3741void Context::framebufferTextureLayer(GLenum target,
3742 GLenum attachment,
3743 GLuint texture,
3744 GLint level,
3745 GLint layer)
3746{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003747 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003748 ASSERT(framebuffer);
3749
3750 if (texture != 0)
3751 {
3752 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003753 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003754 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003755 }
3756 else
3757 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003758 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003759 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003760
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003761 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003762}
3763
Brandon Jones59770802018-04-02 13:18:42 -07003764void Context::framebufferTextureMultiviewLayered(GLenum target,
3765 GLenum attachment,
3766 GLuint texture,
3767 GLint level,
3768 GLint baseViewIndex,
3769 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003770{
Martin Radev82ef7742017-08-08 17:44:58 +03003771 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3772 ASSERT(framebuffer);
3773
3774 if (texture != 0)
3775 {
3776 Texture *textureObj = getTexture(texture);
3777
Martin Radev18b75ba2017-08-15 15:50:40 +03003778 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003779 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3780 numViews, baseViewIndex);
3781 }
3782 else
3783 {
3784 framebuffer->resetAttachment(this, attachment);
3785 }
3786
3787 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003788}
3789
Brandon Jones59770802018-04-02 13:18:42 -07003790void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3791 GLenum attachment,
3792 GLuint texture,
3793 GLint level,
3794 GLsizei numViews,
3795 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003796{
Martin Radev5dae57b2017-07-14 16:15:55 +03003797 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3798 ASSERT(framebuffer);
3799
3800 if (texture != 0)
3801 {
3802 Texture *textureObj = getTexture(texture);
3803
3804 ImageIndex index = ImageIndex::Make2D(level);
3805 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3806 textureObj, numViews, viewportOffsets);
3807 }
3808 else
3809 {
3810 framebuffer->resetAttachment(this, attachment);
3811 }
3812
3813 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003814}
3815
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003816void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3817{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003818 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3819 ASSERT(framebuffer);
3820
3821 if (texture != 0)
3822 {
3823 Texture *textureObj = getTexture(texture);
3824
3825 ImageIndex index = ImageIndex::MakeFromType(
3826 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3827 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3828 }
3829 else
3830 {
3831 framebuffer->resetAttachment(this, attachment);
3832 }
3833
3834 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003835}
3836
Jamie Madillc29968b2016-01-20 11:17:23 -05003837void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3838{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003839 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003840 ASSERT(framebuffer);
3841 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003842 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04003843 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003844}
3845
3846void Context::readBuffer(GLenum mode)
3847{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003848 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003849 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003850 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003851}
3852
3853void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3854{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003855 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003856 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003857
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003858 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003859 ASSERT(framebuffer);
3860
3861 // The specification isn't clear what should be done when the framebuffer isn't complete.
3862 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003863 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003864}
3865
3866void Context::invalidateFramebuffer(GLenum target,
3867 GLsizei numAttachments,
3868 const GLenum *attachments)
3869{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003870 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003871 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003872
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003873 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003874 ASSERT(framebuffer);
3875
Jamie Madill427064d2018-04-13 16:20:34 -04003876 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003877 {
Jamie Madill437fa652016-05-03 15:13:24 -04003878 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003879 }
Jamie Madill437fa652016-05-03 15:13:24 -04003880
Jamie Madill4928b7c2017-06-20 12:57:39 -04003881 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003882}
3883
3884void Context::invalidateSubFramebuffer(GLenum target,
3885 GLsizei numAttachments,
3886 const GLenum *attachments,
3887 GLint x,
3888 GLint y,
3889 GLsizei width,
3890 GLsizei height)
3891{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003892 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003893 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003894
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003895 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003896 ASSERT(framebuffer);
3897
Jamie Madill427064d2018-04-13 16:20:34 -04003898 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003899 {
Jamie Madill437fa652016-05-03 15:13:24 -04003900 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003901 }
Jamie Madill437fa652016-05-03 15:13:24 -04003902
3903 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003904 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003905}
3906
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003907void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003908 GLint level,
3909 GLint internalformat,
3910 GLsizei width,
3911 GLsizei height,
3912 GLint border,
3913 GLenum format,
3914 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003915 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003916{
Jamie Madillbc918e72018-03-08 09:47:21 -05003917 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003918
3919 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003920 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003921 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003922 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003923}
3924
Brandon Jones59770802018-04-02 13:18:42 -07003925void Context::texImage2DRobust(TextureTarget target,
3926 GLint level,
3927 GLint internalformat,
3928 GLsizei width,
3929 GLsizei height,
3930 GLint border,
3931 GLenum format,
3932 GLenum type,
3933 GLsizei bufSize,
3934 const void *pixels)
3935{
3936 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3937}
3938
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003939void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003940 GLint level,
3941 GLint internalformat,
3942 GLsizei width,
3943 GLsizei height,
3944 GLsizei depth,
3945 GLint border,
3946 GLenum format,
3947 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003948 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003949{
Jamie Madillbc918e72018-03-08 09:47:21 -05003950 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003951
3952 Extents size(width, height, depth);
3953 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003954 handleError(texture->setImage(this, mGLState.getUnpackState(),
3955 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003956 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003957}
3958
Brandon Jones59770802018-04-02 13:18:42 -07003959void Context::texImage3DRobust(TextureType target,
3960 GLint level,
3961 GLint internalformat,
3962 GLsizei width,
3963 GLsizei height,
3964 GLsizei depth,
3965 GLint border,
3966 GLenum format,
3967 GLenum type,
3968 GLsizei bufSize,
3969 const void *pixels)
3970{
3971 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3972}
3973
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003974void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003975 GLint level,
3976 GLint xoffset,
3977 GLint yoffset,
3978 GLsizei width,
3979 GLsizei height,
3980 GLenum format,
3981 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003982 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003983{
3984 // Zero sized uploads are valid but no-ops
3985 if (width == 0 || height == 0)
3986 {
3987 return;
3988 }
3989
Jamie Madillbc918e72018-03-08 09:47:21 -05003990 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003991
3992 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003993 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04003994
3995 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
3996
3997 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target, level,
3998 area, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003999}
4000
Brandon Jones59770802018-04-02 13:18:42 -07004001void Context::texSubImage2DRobust(TextureTarget target,
4002 GLint level,
4003 GLint xoffset,
4004 GLint yoffset,
4005 GLsizei width,
4006 GLsizei height,
4007 GLenum format,
4008 GLenum type,
4009 GLsizei bufSize,
4010 const void *pixels)
4011{
4012 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4013}
4014
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004015void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004016 GLint level,
4017 GLint xoffset,
4018 GLint yoffset,
4019 GLint zoffset,
4020 GLsizei width,
4021 GLsizei height,
4022 GLsizei depth,
4023 GLenum format,
4024 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004025 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004026{
4027 // Zero sized uploads are valid but no-ops
4028 if (width == 0 || height == 0 || depth == 0)
4029 {
4030 return;
4031 }
4032
Jamie Madillbc918e72018-03-08 09:47:21 -05004033 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004034
4035 Box area(xoffset, yoffset, zoffset, width, height, depth);
4036 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004037
4038 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4039
4040 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004041 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004042 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004043}
4044
Brandon Jones59770802018-04-02 13:18:42 -07004045void Context::texSubImage3DRobust(TextureType target,
4046 GLint level,
4047 GLint xoffset,
4048 GLint yoffset,
4049 GLint zoffset,
4050 GLsizei width,
4051 GLsizei height,
4052 GLsizei depth,
4053 GLenum format,
4054 GLenum type,
4055 GLsizei bufSize,
4056 const void *pixels)
4057{
4058 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4059 pixels);
4060}
4061
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004062void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004063 GLint level,
4064 GLenum internalformat,
4065 GLsizei width,
4066 GLsizei height,
4067 GLint border,
4068 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004069 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004070{
Jamie Madillbc918e72018-03-08 09:47:21 -05004071 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004072
4073 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004074 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004075 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4076 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004077 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004078}
4079
Brandon Jones59770802018-04-02 13:18:42 -07004080void Context::compressedTexImage2DRobust(TextureTarget target,
4081 GLint level,
4082 GLenum internalformat,
4083 GLsizei width,
4084 GLsizei height,
4085 GLint border,
4086 GLsizei imageSize,
4087 GLsizei dataSize,
4088 const GLvoid *data)
4089{
4090 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4091}
4092
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004093void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004094 GLint level,
4095 GLenum internalformat,
4096 GLsizei width,
4097 GLsizei height,
4098 GLsizei depth,
4099 GLint border,
4100 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004101 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004102{
Jamie Madillbc918e72018-03-08 09:47:21 -05004103 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004104
4105 Extents size(width, height, depth);
4106 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004107 handleError(texture->setCompressedImage(
4108 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004109 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004110}
4111
Brandon Jones59770802018-04-02 13:18:42 -07004112void Context::compressedTexImage3DRobust(TextureType target,
4113 GLint level,
4114 GLenum internalformat,
4115 GLsizei width,
4116 GLsizei height,
4117 GLsizei depth,
4118 GLint border,
4119 GLsizei imageSize,
4120 GLsizei dataSize,
4121 const GLvoid *data)
4122{
4123 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4124 data);
4125}
4126
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004127void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004128 GLint level,
4129 GLint xoffset,
4130 GLint yoffset,
4131 GLsizei width,
4132 GLsizei height,
4133 GLenum format,
4134 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004135 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004136{
Jamie Madillbc918e72018-03-08 09:47:21 -05004137 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004138
4139 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004140 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004141 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4142 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004143 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004144}
4145
Brandon Jones59770802018-04-02 13:18:42 -07004146void Context::compressedTexSubImage2DRobust(TextureTarget target,
4147 GLint level,
4148 GLint xoffset,
4149 GLint yoffset,
4150 GLsizei width,
4151 GLsizei height,
4152 GLenum format,
4153 GLsizei imageSize,
4154 GLsizei dataSize,
4155 const GLvoid *data)
4156{
4157 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4158 data);
4159}
4160
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004161void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004162 GLint level,
4163 GLint xoffset,
4164 GLint yoffset,
4165 GLint zoffset,
4166 GLsizei width,
4167 GLsizei height,
4168 GLsizei depth,
4169 GLenum format,
4170 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004171 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004172{
4173 // Zero sized uploads are valid but no-ops
4174 if (width == 0 || height == 0)
4175 {
4176 return;
4177 }
4178
Jamie Madillbc918e72018-03-08 09:47:21 -05004179 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004180
4181 Box area(xoffset, yoffset, zoffset, width, height, depth);
4182 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004183 handleError(texture->setCompressedSubImage(
4184 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004185 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004186}
4187
Brandon Jones59770802018-04-02 13:18:42 -07004188void Context::compressedTexSubImage3DRobust(TextureType target,
4189 GLint level,
4190 GLint xoffset,
4191 GLint yoffset,
4192 GLint zoffset,
4193 GLsizei width,
4194 GLsizei height,
4195 GLsizei depth,
4196 GLenum format,
4197 GLsizei imageSize,
4198 GLsizei dataSize,
4199 const GLvoid *data)
4200{
4201 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4202 imageSize, data);
4203}
4204
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004205void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004206{
4207 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004208 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004209}
4210
Jamie Madill007530e2017-12-28 14:27:04 -05004211void Context::copyTexture(GLuint sourceId,
4212 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004213 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004214 GLuint destId,
4215 GLint destLevel,
4216 GLint internalFormat,
4217 GLenum destType,
4218 GLboolean unpackFlipY,
4219 GLboolean unpackPremultiplyAlpha,
4220 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004221{
Jamie Madillbc918e72018-03-08 09:47:21 -05004222 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004223
4224 gl::Texture *sourceTexture = getTexture(sourceId);
4225 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004226 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4227 sourceLevel, ConvertToBool(unpackFlipY),
4228 ConvertToBool(unpackPremultiplyAlpha),
4229 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004230}
4231
Jamie Madill007530e2017-12-28 14:27:04 -05004232void Context::copySubTexture(GLuint sourceId,
4233 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004234 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004235 GLuint destId,
4236 GLint destLevel,
4237 GLint xoffset,
4238 GLint yoffset,
4239 GLint x,
4240 GLint y,
4241 GLsizei width,
4242 GLsizei height,
4243 GLboolean unpackFlipY,
4244 GLboolean unpackPremultiplyAlpha,
4245 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004246{
4247 // Zero sized copies are valid but no-ops
4248 if (width == 0 || height == 0)
4249 {
4250 return;
4251 }
4252
Jamie Madillbc918e72018-03-08 09:47:21 -05004253 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004254
4255 gl::Texture *sourceTexture = getTexture(sourceId);
4256 gl::Texture *destTexture = getTexture(destId);
4257 Offset offset(xoffset, yoffset, 0);
4258 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004259 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4260 ConvertToBool(unpackFlipY),
4261 ConvertToBool(unpackPremultiplyAlpha),
4262 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004263}
4264
Jamie Madill007530e2017-12-28 14:27:04 -05004265void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004266{
Jamie Madillbc918e72018-03-08 09:47:21 -05004267 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004268
4269 gl::Texture *sourceTexture = getTexture(sourceId);
4270 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004271 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004272}
4273
Corentin Wallez336129f2017-10-17 15:55:40 -04004274void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004275{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004276 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004277 ASSERT(buffer);
4278
Geoff Lang496c02d2016-10-20 11:38:11 -07004279 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004280}
4281
Brandon Jones59770802018-04-02 13:18:42 -07004282void Context::getBufferPointervRobust(BufferBinding target,
4283 GLenum pname,
4284 GLsizei bufSize,
4285 GLsizei *length,
4286 void **params)
4287{
4288 getBufferPointerv(target, pname, params);
4289}
4290
Corentin Wallez336129f2017-10-17 15:55:40 -04004291void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004292{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004293 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004294 ASSERT(buffer);
4295
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004296 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004297 if (error.isError())
4298 {
Jamie Madill437fa652016-05-03 15:13:24 -04004299 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004300 return nullptr;
4301 }
4302
4303 return buffer->getMapPointer();
4304}
4305
Corentin Wallez336129f2017-10-17 15:55:40 -04004306GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004307{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004308 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004309 ASSERT(buffer);
4310
4311 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004312 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004313 if (error.isError())
4314 {
Jamie Madill437fa652016-05-03 15:13:24 -04004315 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004316 return GL_FALSE;
4317 }
4318
4319 return result;
4320}
4321
Corentin Wallez336129f2017-10-17 15:55:40 -04004322void *Context::mapBufferRange(BufferBinding target,
4323 GLintptr offset,
4324 GLsizeiptr length,
4325 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004326{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004327 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004328 ASSERT(buffer);
4329
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004330 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004331 if (error.isError())
4332 {
Jamie Madill437fa652016-05-03 15:13:24 -04004333 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004334 return nullptr;
4335 }
4336
4337 return buffer->getMapPointer();
4338}
4339
Corentin Wallez336129f2017-10-17 15:55:40 -04004340void Context::flushMappedBufferRange(BufferBinding /*target*/,
4341 GLintptr /*offset*/,
4342 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004343{
4344 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4345}
4346
Jamie Madillbc918e72018-03-08 09:47:21 -05004347Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004348{
Geoff Langa8cb2872018-03-09 16:09:40 -05004349 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004350}
4351
Jamie Madillbc918e72018-03-08 09:47:21 -05004352Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004353{
Geoff Langa8cb2872018-03-09 16:09:40 -05004354 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004355}
4356
Jamie Madillbc918e72018-03-08 09:47:21 -05004357Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004358{
Geoff Langa8cb2872018-03-09 16:09:40 -05004359 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004360}
4361
Geoff Lang9bf86f02018-07-26 11:46:34 -04004362Error Context::syncStateForPathOperation()
4363{
4364 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4365
4366 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4367 ANGLE_TRY(syncDirtyBits());
4368
4369 return NoError();
4370}
4371
Jiajia Qin5451d532017-11-16 17:16:34 +08004372void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4373{
4374 UNIMPLEMENTED();
4375}
4376
Jamie Madillc20ab272016-06-09 07:20:46 -07004377void Context::activeTexture(GLenum texture)
4378{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004379 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004380}
4381
Jamie Madill876429b2017-04-20 15:46:24 -04004382void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004383{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004384 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004385}
4386
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004387void Context::blendEquation(GLenum mode)
4388{
4389 mGLState.setBlendEquation(mode, mode);
4390}
4391
Jamie Madillc20ab272016-06-09 07:20:46 -07004392void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4393{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004394 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004395}
4396
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004397void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4398{
4399 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4400}
4401
Jamie Madillc20ab272016-06-09 07:20:46 -07004402void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4403{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004404 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004405}
4406
Jamie Madill876429b2017-04-20 15:46:24 -04004407void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004408{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004409 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004410}
4411
Jamie Madill876429b2017-04-20 15:46:24 -04004412void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004413{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004414 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004415}
4416
4417void Context::clearStencil(GLint s)
4418{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004419 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004420}
4421
4422void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4423{
Geoff Lang92019432017-11-20 13:09:34 -05004424 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4425 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004426}
4427
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004428void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004429{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004430 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004431}
4432
4433void Context::depthFunc(GLenum func)
4434{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004435 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004436}
4437
4438void Context::depthMask(GLboolean flag)
4439{
Geoff Lang92019432017-11-20 13:09:34 -05004440 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004441}
4442
Jamie Madill876429b2017-04-20 15:46:24 -04004443void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004444{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004445 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004446}
4447
4448void Context::disable(GLenum cap)
4449{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004450 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004451 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004452}
4453
4454void Context::disableVertexAttribArray(GLuint index)
4455{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004456 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004457 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004458}
4459
4460void Context::enable(GLenum cap)
4461{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004462 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004463 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004464}
4465
4466void Context::enableVertexAttribArray(GLuint index)
4467{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004468 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004469 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004470}
4471
4472void Context::frontFace(GLenum mode)
4473{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004474 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004475}
4476
4477void Context::hint(GLenum target, GLenum mode)
4478{
4479 switch (target)
4480 {
4481 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004482 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004483 break;
4484
4485 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004486 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004487 break;
4488
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004489 case GL_PERSPECTIVE_CORRECTION_HINT:
4490 case GL_POINT_SMOOTH_HINT:
4491 case GL_LINE_SMOOTH_HINT:
4492 case GL_FOG_HINT:
4493 mGLState.gles1().setHint(target, mode);
4494 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004495 default:
4496 UNREACHABLE();
4497 return;
4498 }
4499}
4500
4501void Context::lineWidth(GLfloat width)
4502{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004503 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004504}
4505
4506void Context::pixelStorei(GLenum pname, GLint param)
4507{
4508 switch (pname)
4509 {
4510 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004511 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004512 break;
4513
4514 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004515 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004516 break;
4517
4518 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004519 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004520 break;
4521
4522 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004523 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004524 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004525 break;
4526
4527 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004528 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004529 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004530 break;
4531
4532 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004533 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004534 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004535 break;
4536
4537 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004538 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004539 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004540 break;
4541
4542 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004543 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004544 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004545 break;
4546
4547 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004548 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004549 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004550 break;
4551
4552 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004553 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004554 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004555 break;
4556
4557 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004558 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004559 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004560 break;
4561
4562 default:
4563 UNREACHABLE();
4564 return;
4565 }
4566}
4567
4568void Context::polygonOffset(GLfloat factor, GLfloat units)
4569{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004570 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004571}
4572
Jamie Madill876429b2017-04-20 15:46:24 -04004573void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004574{
Geoff Lang92019432017-11-20 13:09:34 -05004575 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004576}
4577
Jiawei Shaodb342272017-09-27 10:21:45 +08004578void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4579{
4580 mGLState.setSampleMaskParams(maskNumber, mask);
4581}
4582
Jamie Madillc20ab272016-06-09 07:20:46 -07004583void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4584{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004585 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004586}
4587
4588void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4589{
4590 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4591 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004592 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004593 }
4594
4595 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4596 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004597 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004598 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004599
4600 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004601}
4602
4603void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4604{
4605 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4606 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004607 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004608 }
4609
4610 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4611 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004612 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004613 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004614
4615 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004616}
4617
4618void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4619{
4620 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4621 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004622 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004623 }
4624
4625 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4626 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004627 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004628 }
4629}
4630
4631void Context::vertexAttrib1f(GLuint index, GLfloat x)
4632{
4633 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004634 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004635 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004636}
4637
4638void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4639{
4640 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004641 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004642 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004643}
4644
4645void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4646{
4647 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004648 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004649 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004650}
4651
4652void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4653{
4654 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004655 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004656 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004657}
4658
4659void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4660{
4661 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004662 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004663 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004664}
4665
4666void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4667{
4668 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004669 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004670 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004671}
4672
4673void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4674{
4675 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004676 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004677 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004678}
4679
4680void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4681{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004682 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004683 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004684}
4685
4686void Context::vertexAttribPointer(GLuint index,
4687 GLint size,
4688 GLenum type,
4689 GLboolean normalized,
4690 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004691 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004692{
Corentin Wallez336129f2017-10-17 15:55:40 -04004693 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004694 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004695 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004696}
4697
Shao80957d92017-02-20 21:25:59 +08004698void Context::vertexAttribFormat(GLuint attribIndex,
4699 GLint size,
4700 GLenum type,
4701 GLboolean normalized,
4702 GLuint relativeOffset)
4703{
Geoff Lang92019432017-11-20 13:09:34 -05004704 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004705 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004706 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004707}
4708
4709void Context::vertexAttribIFormat(GLuint attribIndex,
4710 GLint size,
4711 GLenum type,
4712 GLuint relativeOffset)
4713{
4714 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004715 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004716}
4717
4718void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4719{
Shaodde78e82017-05-22 14:13:27 +08004720 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004721 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004722}
4723
Jiajia Qin5451d532017-11-16 17:16:34 +08004724void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004725{
4726 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004727 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004728}
4729
Jamie Madillc20ab272016-06-09 07:20:46 -07004730void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4731{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004732 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004733}
4734
4735void Context::vertexAttribIPointer(GLuint index,
4736 GLint size,
4737 GLenum type,
4738 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004739 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004740{
Corentin Wallez336129f2017-10-17 15:55:40 -04004741 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4742 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004743 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004744}
4745
4746void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4747{
4748 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004749 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004750 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004751}
4752
4753void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4754{
4755 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004756 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004757 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004758}
4759
4760void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4761{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004762 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004763 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004764}
4765
4766void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4767{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004768 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004769 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004770}
4771
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004772void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4773{
4774 const VertexAttribCurrentValueData &currentValues =
4775 getGLState().getVertexAttribCurrentValue(index);
4776 const VertexArray *vao = getGLState().getVertexArray();
4777 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4778 currentValues, pname, params);
4779}
4780
Brandon Jones59770802018-04-02 13:18:42 -07004781void Context::getVertexAttribivRobust(GLuint index,
4782 GLenum pname,
4783 GLsizei bufSize,
4784 GLsizei *length,
4785 GLint *params)
4786{
4787 getVertexAttribiv(index, pname, params);
4788}
4789
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004790void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4791{
4792 const VertexAttribCurrentValueData &currentValues =
4793 getGLState().getVertexAttribCurrentValue(index);
4794 const VertexArray *vao = getGLState().getVertexArray();
4795 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4796 currentValues, pname, params);
4797}
4798
Brandon Jones59770802018-04-02 13:18:42 -07004799void Context::getVertexAttribfvRobust(GLuint index,
4800 GLenum pname,
4801 GLsizei bufSize,
4802 GLsizei *length,
4803 GLfloat *params)
4804{
4805 getVertexAttribfv(index, pname, params);
4806}
4807
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004808void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4809{
4810 const VertexAttribCurrentValueData &currentValues =
4811 getGLState().getVertexAttribCurrentValue(index);
4812 const VertexArray *vao = getGLState().getVertexArray();
4813 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4814 currentValues, pname, params);
4815}
4816
Brandon Jones59770802018-04-02 13:18:42 -07004817void Context::getVertexAttribIivRobust(GLuint index,
4818 GLenum pname,
4819 GLsizei bufSize,
4820 GLsizei *length,
4821 GLint *params)
4822{
4823 getVertexAttribIiv(index, pname, params);
4824}
4825
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004826void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4827{
4828 const VertexAttribCurrentValueData &currentValues =
4829 getGLState().getVertexAttribCurrentValue(index);
4830 const VertexArray *vao = getGLState().getVertexArray();
4831 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4832 currentValues, pname, params);
4833}
4834
Brandon Jones59770802018-04-02 13:18:42 -07004835void Context::getVertexAttribIuivRobust(GLuint index,
4836 GLenum pname,
4837 GLsizei bufSize,
4838 GLsizei *length,
4839 GLuint *params)
4840{
4841 getVertexAttribIuiv(index, pname, params);
4842}
4843
Jamie Madill876429b2017-04-20 15:46:24 -04004844void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004845{
4846 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4847 QueryVertexAttribPointerv(attrib, pname, pointer);
4848}
4849
Brandon Jones59770802018-04-02 13:18:42 -07004850void Context::getVertexAttribPointervRobust(GLuint index,
4851 GLenum pname,
4852 GLsizei bufSize,
4853 GLsizei *length,
4854 void **pointer)
4855{
4856 getVertexAttribPointerv(index, pname, pointer);
4857}
4858
Jamie Madillc20ab272016-06-09 07:20:46 -07004859void Context::debugMessageControl(GLenum source,
4860 GLenum type,
4861 GLenum severity,
4862 GLsizei count,
4863 const GLuint *ids,
4864 GLboolean enabled)
4865{
4866 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004867 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004868 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004869}
4870
4871void Context::debugMessageInsert(GLenum source,
4872 GLenum type,
4873 GLuint id,
4874 GLenum severity,
4875 GLsizei length,
4876 const GLchar *buf)
4877{
4878 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004879 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004880}
4881
4882void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4883{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004884 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004885}
4886
4887GLuint Context::getDebugMessageLog(GLuint count,
4888 GLsizei bufSize,
4889 GLenum *sources,
4890 GLenum *types,
4891 GLuint *ids,
4892 GLenum *severities,
4893 GLsizei *lengths,
4894 GLchar *messageLog)
4895{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004896 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4897 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004898}
4899
4900void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4901{
4902 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004903 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004904 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004905}
4906
4907void Context::popDebugGroup()
4908{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004909 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004910 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004911}
4912
Corentin Wallez336129f2017-10-17 15:55:40 -04004913void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004914{
4915 Buffer *buffer = mGLState.getTargetBuffer(target);
4916 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004917 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004918}
4919
Corentin Wallez336129f2017-10-17 15:55:40 -04004920void Context::bufferSubData(BufferBinding target,
4921 GLintptr offset,
4922 GLsizeiptr size,
4923 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004924{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06004925 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04004926 {
4927 return;
4928 }
4929
4930 Buffer *buffer = mGLState.getTargetBuffer(target);
4931 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004932 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004933}
4934
Jamie Madillef300b12016-10-07 15:12:09 -04004935void Context::attachShader(GLuint program, GLuint shader)
4936{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004937 Program *programObject = mState.mShaderPrograms->getProgram(program);
4938 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004939 ASSERT(programObject && shaderObject);
4940 programObject->attachShader(shaderObject);
4941}
4942
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004943const Workarounds &Context::getWorkarounds() const
4944{
4945 return mWorkarounds;
4946}
4947
Corentin Wallez336129f2017-10-17 15:55:40 -04004948void Context::copyBufferSubData(BufferBinding readTarget,
4949 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004950 GLintptr readOffset,
4951 GLintptr writeOffset,
4952 GLsizeiptr size)
4953{
4954 // if size is zero, the copy is a successful no-op
4955 if (size == 0)
4956 {
4957 return;
4958 }
4959
4960 // TODO(jmadill): cache these.
4961 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4962 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4963
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004964 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004965}
4966
Jamie Madill01a80ee2016-11-07 12:06:18 -05004967void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4968{
4969 Program *programObject = getProgram(program);
4970 // TODO(jmadill): Re-use this from the validation if possible.
4971 ASSERT(programObject);
4972 programObject->bindAttributeLocation(index, name);
4973}
4974
Corentin Wallez336129f2017-10-17 15:55:40 -04004975void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004976{
Corentin Wallez336129f2017-10-17 15:55:40 -04004977 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4978 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04004979 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004980}
4981
Corentin Wallez336129f2017-10-17 15:55:40 -04004982void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004983{
4984 bindBufferRange(target, index, buffer, 0, 0);
4985}
4986
Corentin Wallez336129f2017-10-17 15:55:40 -04004987void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004988 GLuint index,
4989 GLuint buffer,
4990 GLintptr offset,
4991 GLsizeiptr size)
4992{
Jamie Madill6d32cef2018-08-14 02:34:28 -04004993 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4994 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
4995 if (target == BufferBinding::Uniform)
4996 {
4997 mUniformBufferObserverBindings[index].bind(object ? object->getImplementation() : nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04004998 mStateCache.onUniformBufferStateChange(this);
4999 }
5000 else
5001 {
5002 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005003 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005004}
5005
Jamie Madill01a80ee2016-11-07 12:06:18 -05005006void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5007{
5008 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5009 {
5010 bindReadFramebuffer(framebuffer);
5011 }
5012
5013 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5014 {
5015 bindDrawFramebuffer(framebuffer);
5016 }
5017}
5018
5019void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5020{
5021 ASSERT(target == GL_RENDERBUFFER);
5022 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005023 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005024 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005025}
5026
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005027void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005028 GLsizei samples,
5029 GLenum internalformat,
5030 GLsizei width,
5031 GLsizei height,
5032 GLboolean fixedsamplelocations)
5033{
5034 Extents size(width, height, 1);
5035 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005036 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5037 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005038}
5039
Olli Etuaho89664842018-08-24 14:45:36 +03005040void Context::texStorage3DMultisample(TextureType target,
5041 GLsizei samples,
5042 GLenum internalformat,
5043 GLsizei width,
5044 GLsizei height,
5045 GLsizei depth,
5046 GLboolean fixedsamplelocations)
5047{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005048 Extents size(width, height, depth);
5049 Texture *texture = getTargetTexture(target);
5050 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5051 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005052}
5053
JiangYizhoubddc46b2016-12-09 09:50:51 +08005054void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5055{
JiangYizhou5b03f472017-01-09 10:22:53 +08005056 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5057 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005058 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005059 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005060
5061 switch (pname)
5062 {
5063 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04005064 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005065 break;
5066 default:
5067 UNREACHABLE();
5068 }
5069}
5070
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005071void Context::getMultisamplefvRobust(GLenum pname,
5072 GLuint index,
5073 GLsizei bufSize,
5074 GLsizei *length,
5075 GLfloat *val)
5076{
5077 UNIMPLEMENTED();
5078}
5079
Jamie Madille8fb6402017-02-14 17:56:40 -05005080void Context::renderbufferStorage(GLenum target,
5081 GLenum internalformat,
5082 GLsizei width,
5083 GLsizei height)
5084{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005085 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5086 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5087
Jamie Madille8fb6402017-02-14 17:56:40 -05005088 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04005089 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005090}
5091
5092void Context::renderbufferStorageMultisample(GLenum target,
5093 GLsizei samples,
5094 GLenum internalformat,
5095 GLsizei width,
5096 GLsizei height)
5097{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005098 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5099 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005100
5101 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005102 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005103 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005104}
5105
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005106void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5107{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005108 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04005109 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005110}
5111
JiangYizhoue18e6392017-02-20 10:32:23 +08005112void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5113{
5114 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5115 QueryFramebufferParameteriv(framebuffer, pname, params);
5116}
5117
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005118void Context::getFramebufferParameterivRobust(GLenum target,
5119 GLenum pname,
5120 GLsizei bufSize,
5121 GLsizei *length,
5122 GLint *params)
5123{
5124 UNIMPLEMENTED();
5125}
5126
Jiajia Qin5451d532017-11-16 17:16:34 +08005127void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005128{
5129 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005130 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005131}
5132
Jamie Madilldec86232018-07-11 09:01:18 -04005133bool Context::getScratchBuffer(size_t requstedSizeBytes,
5134 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005135{
Jamie Madilldec86232018-07-11 09:01:18 -04005136 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005137}
5138
Jamie Madilldec86232018-07-11 09:01:18 -04005139bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5140 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005141{
Jamie Madilldec86232018-07-11 09:01:18 -04005142 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005143}
5144
Xinghua Cao10a4d432017-11-28 14:46:26 +08005145Error Context::prepareForDispatch()
5146{
Geoff Langa8cb2872018-03-09 16:09:40 -05005147 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005148
5149 if (isRobustResourceInitEnabled())
5150 {
5151 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5152 }
5153
5154 return NoError();
5155}
5156
Xinghua Cao2b396592017-03-29 15:36:04 +08005157void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5158{
5159 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5160 {
5161 return;
5162 }
5163
Xinghua Cao10a4d432017-11-28 14:46:26 +08005164 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005165 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005166}
5167
Jiajia Qin5451d532017-11-16 17:16:34 +08005168void Context::dispatchComputeIndirect(GLintptr indirect)
5169{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005170 ANGLE_CONTEXT_TRY(prepareForDispatch());
5171 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005172}
5173
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005174void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005175 GLsizei levels,
5176 GLenum internalFormat,
5177 GLsizei width,
5178 GLsizei height)
5179{
5180 Extents size(width, height, 1);
5181 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005182 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005183}
5184
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005185void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005186 GLsizei levels,
5187 GLenum internalFormat,
5188 GLsizei width,
5189 GLsizei height,
5190 GLsizei depth)
5191{
5192 Extents size(width, height, depth);
5193 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005194 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005195}
5196
Jiajia Qin5451d532017-11-16 17:16:34 +08005197void Context::memoryBarrier(GLbitfield barriers)
5198{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005199 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005200}
5201
5202void Context::memoryBarrierByRegion(GLbitfield barriers)
5203{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005204 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005205}
5206
Jamie Madillc1d770e2017-04-13 17:31:24 -04005207GLenum Context::checkFramebufferStatus(GLenum target)
5208{
5209 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5210 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005211 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005212}
5213
5214void Context::compileShader(GLuint shader)
5215{
5216 Shader *shaderObject = GetValidShader(this, shader);
5217 if (!shaderObject)
5218 {
5219 return;
5220 }
5221 shaderObject->compile(this);
5222}
5223
5224void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5225{
5226 for (int i = 0; i < n; i++)
5227 {
5228 deleteBuffer(buffers[i]);
5229 }
5230}
5231
5232void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5233{
5234 for (int i = 0; i < n; i++)
5235 {
5236 if (framebuffers[i] != 0)
5237 {
5238 deleteFramebuffer(framebuffers[i]);
5239 }
5240 }
5241}
5242
5243void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5244{
5245 for (int i = 0; i < n; i++)
5246 {
5247 deleteRenderbuffer(renderbuffers[i]);
5248 }
5249}
5250
5251void Context::deleteTextures(GLsizei n, const GLuint *textures)
5252{
5253 for (int i = 0; i < n; i++)
5254 {
5255 if (textures[i] != 0)
5256 {
5257 deleteTexture(textures[i]);
5258 }
5259 }
5260}
5261
5262void Context::detachShader(GLuint program, GLuint shader)
5263{
5264 Program *programObject = getProgram(program);
5265 ASSERT(programObject);
5266
5267 Shader *shaderObject = getShader(shader);
5268 ASSERT(shaderObject);
5269
5270 programObject->detachShader(this, shaderObject);
5271}
5272
5273void Context::genBuffers(GLsizei n, GLuint *buffers)
5274{
5275 for (int i = 0; i < n; i++)
5276 {
5277 buffers[i] = createBuffer();
5278 }
5279}
5280
5281void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5282{
5283 for (int i = 0; i < n; i++)
5284 {
5285 framebuffers[i] = createFramebuffer();
5286 }
5287}
5288
5289void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5290{
5291 for (int i = 0; i < n; i++)
5292 {
5293 renderbuffers[i] = createRenderbuffer();
5294 }
5295}
5296
5297void Context::genTextures(GLsizei n, GLuint *textures)
5298{
5299 for (int i = 0; i < n; i++)
5300 {
5301 textures[i] = createTexture();
5302 }
5303}
5304
5305void Context::getActiveAttrib(GLuint program,
5306 GLuint index,
5307 GLsizei bufsize,
5308 GLsizei *length,
5309 GLint *size,
5310 GLenum *type,
5311 GLchar *name)
5312{
5313 Program *programObject = getProgram(program);
5314 ASSERT(programObject);
5315 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5316}
5317
5318void Context::getActiveUniform(GLuint program,
5319 GLuint index,
5320 GLsizei bufsize,
5321 GLsizei *length,
5322 GLint *size,
5323 GLenum *type,
5324 GLchar *name)
5325{
5326 Program *programObject = getProgram(program);
5327 ASSERT(programObject);
5328 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5329}
5330
5331void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5332{
5333 Program *programObject = getProgram(program);
5334 ASSERT(programObject);
5335 programObject->getAttachedShaders(maxcount, count, shaders);
5336}
5337
5338GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5339{
5340 Program *programObject = getProgram(program);
5341 ASSERT(programObject);
5342 return programObject->getAttributeLocation(name);
5343}
5344
5345void Context::getBooleanv(GLenum pname, GLboolean *params)
5346{
5347 GLenum nativeType;
5348 unsigned int numParams = 0;
5349 getQueryParameterInfo(pname, &nativeType, &numParams);
5350
5351 if (nativeType == GL_BOOL)
5352 {
5353 getBooleanvImpl(pname, params);
5354 }
5355 else
5356 {
5357 CastStateValues(this, nativeType, pname, numParams, params);
5358 }
5359}
5360
Brandon Jones59770802018-04-02 13:18:42 -07005361void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5362{
5363 getBooleanv(pname, params);
5364}
5365
Jamie Madillc1d770e2017-04-13 17:31:24 -04005366void Context::getFloatv(GLenum pname, GLfloat *params)
5367{
5368 GLenum nativeType;
5369 unsigned int numParams = 0;
5370 getQueryParameterInfo(pname, &nativeType, &numParams);
5371
5372 if (nativeType == GL_FLOAT)
5373 {
5374 getFloatvImpl(pname, params);
5375 }
5376 else
5377 {
5378 CastStateValues(this, nativeType, pname, numParams, params);
5379 }
5380}
5381
Brandon Jones59770802018-04-02 13:18:42 -07005382void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5383{
5384 getFloatv(pname, params);
5385}
5386
Jamie Madillc1d770e2017-04-13 17:31:24 -04005387void Context::getIntegerv(GLenum pname, GLint *params)
5388{
5389 GLenum nativeType;
5390 unsigned int numParams = 0;
5391 getQueryParameterInfo(pname, &nativeType, &numParams);
5392
5393 if (nativeType == GL_INT)
5394 {
5395 getIntegervImpl(pname, params);
5396 }
5397 else
5398 {
5399 CastStateValues(this, nativeType, pname, numParams, params);
5400 }
5401}
5402
Brandon Jones59770802018-04-02 13:18:42 -07005403void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5404{
5405 getIntegerv(pname, data);
5406}
5407
Jamie Madillc1d770e2017-04-13 17:31:24 -04005408void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5409{
5410 Program *programObject = getProgram(program);
5411 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005412 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005413}
5414
Brandon Jones59770802018-04-02 13:18:42 -07005415void Context::getProgramivRobust(GLuint program,
5416 GLenum pname,
5417 GLsizei bufSize,
5418 GLsizei *length,
5419 GLint *params)
5420{
5421 getProgramiv(program, pname, params);
5422}
5423
Jiajia Qin5451d532017-11-16 17:16:34 +08005424void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5425{
5426 UNIMPLEMENTED();
5427}
5428
Jamie Madillbe849e42017-05-02 15:49:00 -04005429void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005430{
5431 Program *programObject = getProgram(program);
5432 ASSERT(programObject);
5433 programObject->getInfoLog(bufsize, length, infolog);
5434}
5435
Jiajia Qin5451d532017-11-16 17:16:34 +08005436void Context::getProgramPipelineInfoLog(GLuint pipeline,
5437 GLsizei bufSize,
5438 GLsizei *length,
5439 GLchar *infoLog)
5440{
5441 UNIMPLEMENTED();
5442}
5443
Jamie Madillc1d770e2017-04-13 17:31:24 -04005444void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5445{
5446 Shader *shaderObject = getShader(shader);
5447 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005448 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005449}
5450
Brandon Jones59770802018-04-02 13:18:42 -07005451void Context::getShaderivRobust(GLuint shader,
5452 GLenum pname,
5453 GLsizei bufSize,
5454 GLsizei *length,
5455 GLint *params)
5456{
5457 getShaderiv(shader, pname, params);
5458}
5459
Jamie Madillc1d770e2017-04-13 17:31:24 -04005460void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5461{
5462 Shader *shaderObject = getShader(shader);
5463 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005464 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005465}
5466
5467void Context::getShaderPrecisionFormat(GLenum shadertype,
5468 GLenum precisiontype,
5469 GLint *range,
5470 GLint *precision)
5471{
5472 // TODO(jmadill): Compute shaders.
5473
5474 switch (shadertype)
5475 {
5476 case GL_VERTEX_SHADER:
5477 switch (precisiontype)
5478 {
5479 case GL_LOW_FLOAT:
5480 mCaps.vertexLowpFloat.get(range, precision);
5481 break;
5482 case GL_MEDIUM_FLOAT:
5483 mCaps.vertexMediumpFloat.get(range, precision);
5484 break;
5485 case GL_HIGH_FLOAT:
5486 mCaps.vertexHighpFloat.get(range, precision);
5487 break;
5488
5489 case GL_LOW_INT:
5490 mCaps.vertexLowpInt.get(range, precision);
5491 break;
5492 case GL_MEDIUM_INT:
5493 mCaps.vertexMediumpInt.get(range, precision);
5494 break;
5495 case GL_HIGH_INT:
5496 mCaps.vertexHighpInt.get(range, precision);
5497 break;
5498
5499 default:
5500 UNREACHABLE();
5501 return;
5502 }
5503 break;
5504
5505 case GL_FRAGMENT_SHADER:
5506 switch (precisiontype)
5507 {
5508 case GL_LOW_FLOAT:
5509 mCaps.fragmentLowpFloat.get(range, precision);
5510 break;
5511 case GL_MEDIUM_FLOAT:
5512 mCaps.fragmentMediumpFloat.get(range, precision);
5513 break;
5514 case GL_HIGH_FLOAT:
5515 mCaps.fragmentHighpFloat.get(range, precision);
5516 break;
5517
5518 case GL_LOW_INT:
5519 mCaps.fragmentLowpInt.get(range, precision);
5520 break;
5521 case GL_MEDIUM_INT:
5522 mCaps.fragmentMediumpInt.get(range, precision);
5523 break;
5524 case GL_HIGH_INT:
5525 mCaps.fragmentHighpInt.get(range, precision);
5526 break;
5527
5528 default:
5529 UNREACHABLE();
5530 return;
5531 }
5532 break;
5533
5534 default:
5535 UNREACHABLE();
5536 return;
5537 }
5538}
5539
5540void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5541{
5542 Shader *shaderObject = getShader(shader);
5543 ASSERT(shaderObject);
5544 shaderObject->getSource(bufsize, length, source);
5545}
5546
5547void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5548{
5549 Program *programObject = getProgram(program);
5550 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005551 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005552}
5553
Brandon Jones59770802018-04-02 13:18:42 -07005554void Context::getUniformfvRobust(GLuint program,
5555 GLint location,
5556 GLsizei bufSize,
5557 GLsizei *length,
5558 GLfloat *params)
5559{
5560 getUniformfv(program, location, params);
5561}
5562
Jamie Madillc1d770e2017-04-13 17:31:24 -04005563void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5564{
5565 Program *programObject = getProgram(program);
5566 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005567 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005568}
5569
Brandon Jones59770802018-04-02 13:18:42 -07005570void Context::getUniformivRobust(GLuint program,
5571 GLint location,
5572 GLsizei bufSize,
5573 GLsizei *length,
5574 GLint *params)
5575{
5576 getUniformiv(program, location, params);
5577}
5578
Jamie Madillc1d770e2017-04-13 17:31:24 -04005579GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5580{
5581 Program *programObject = getProgram(program);
5582 ASSERT(programObject);
5583 return programObject->getUniformLocation(name);
5584}
5585
5586GLboolean Context::isBuffer(GLuint buffer)
5587{
5588 if (buffer == 0)
5589 {
5590 return GL_FALSE;
5591 }
5592
5593 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5594}
5595
5596GLboolean Context::isEnabled(GLenum cap)
5597{
5598 return mGLState.getEnableFeature(cap);
5599}
5600
5601GLboolean Context::isFramebuffer(GLuint framebuffer)
5602{
5603 if (framebuffer == 0)
5604 {
5605 return GL_FALSE;
5606 }
5607
5608 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5609}
5610
5611GLboolean Context::isProgram(GLuint program)
5612{
5613 if (program == 0)
5614 {
5615 return GL_FALSE;
5616 }
5617
5618 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5619}
5620
5621GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5622{
5623 if (renderbuffer == 0)
5624 {
5625 return GL_FALSE;
5626 }
5627
5628 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5629}
5630
5631GLboolean Context::isShader(GLuint shader)
5632{
5633 if (shader == 0)
5634 {
5635 return GL_FALSE;
5636 }
5637
5638 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5639}
5640
5641GLboolean Context::isTexture(GLuint texture)
5642{
5643 if (texture == 0)
5644 {
5645 return GL_FALSE;
5646 }
5647
5648 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5649}
5650
5651void Context::linkProgram(GLuint program)
5652{
5653 Program *programObject = getProgram(program);
5654 ASSERT(programObject);
5655 handleError(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005656
5657 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5658 // don't need to worry that:
5659 // 1. Draw calls after link use the new executable code or the old one depending on the link
5660 // result.
5661 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5662 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5663 // ProgramD3D.
5664 if (programObject->isInUse())
5665 {
5666 // isLinked() which forces to resolve linking, will be called.
5667 mGLState.onProgramExecutableChange(programObject);
5668 mStateCache.onProgramExecutableChange(this);
5669 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005670}
5671
5672void Context::releaseShaderCompiler()
5673{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005674 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005675}
5676
5677void Context::shaderBinary(GLsizei n,
5678 const GLuint *shaders,
5679 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005680 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005681 GLsizei length)
5682{
5683 // No binary shader formats are supported.
5684 UNIMPLEMENTED();
5685}
5686
5687void Context::shaderSource(GLuint shader,
5688 GLsizei count,
5689 const GLchar *const *string,
5690 const GLint *length)
5691{
5692 Shader *shaderObject = getShader(shader);
5693 ASSERT(shaderObject);
5694 shaderObject->setSource(count, string, length);
5695}
5696
5697void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5698{
5699 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5700}
5701
5702void Context::stencilMask(GLuint mask)
5703{
5704 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5705}
5706
5707void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5708{
5709 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5710}
5711
5712void Context::uniform1f(GLint location, GLfloat x)
5713{
5714 Program *program = mGLState.getProgram();
5715 program->setUniform1fv(location, 1, &x);
5716}
5717
5718void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5719{
5720 Program *program = mGLState.getProgram();
5721 program->setUniform1fv(location, count, v);
5722}
5723
Jamie Madill7e4eff12018-08-08 15:49:26 -04005724void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005725{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005726 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04005727 {
5728 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04005729 mStateCache.onActiveTextureChange(this);
Jamie Madill81c2e252017-09-09 23:32:46 -04005730 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005731}
5732
Jamie Madill7e4eff12018-08-08 15:49:26 -04005733void Context::uniform1i(GLint location, GLint x)
5734{
5735 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
5736}
5737
Jamie Madillc1d770e2017-04-13 17:31:24 -04005738void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5739{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005740 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005741}
5742
5743void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5744{
5745 GLfloat xy[2] = {x, y};
5746 Program *program = mGLState.getProgram();
5747 program->setUniform2fv(location, 1, xy);
5748}
5749
5750void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5751{
5752 Program *program = mGLState.getProgram();
5753 program->setUniform2fv(location, count, v);
5754}
5755
5756void Context::uniform2i(GLint location, GLint x, GLint y)
5757{
5758 GLint xy[2] = {x, y};
5759 Program *program = mGLState.getProgram();
5760 program->setUniform2iv(location, 1, xy);
5761}
5762
5763void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5764{
5765 Program *program = mGLState.getProgram();
5766 program->setUniform2iv(location, count, v);
5767}
5768
5769void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5770{
5771 GLfloat xyz[3] = {x, y, z};
5772 Program *program = mGLState.getProgram();
5773 program->setUniform3fv(location, 1, xyz);
5774}
5775
5776void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5777{
5778 Program *program = mGLState.getProgram();
5779 program->setUniform3fv(location, count, v);
5780}
5781
5782void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5783{
5784 GLint xyz[3] = {x, y, z};
5785 Program *program = mGLState.getProgram();
5786 program->setUniform3iv(location, 1, xyz);
5787}
5788
5789void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5790{
5791 Program *program = mGLState.getProgram();
5792 program->setUniform3iv(location, count, v);
5793}
5794
5795void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5796{
5797 GLfloat xyzw[4] = {x, y, z, w};
5798 Program *program = mGLState.getProgram();
5799 program->setUniform4fv(location, 1, xyzw);
5800}
5801
5802void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5803{
5804 Program *program = mGLState.getProgram();
5805 program->setUniform4fv(location, count, v);
5806}
5807
5808void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5809{
5810 GLint xyzw[4] = {x, y, z, w};
5811 Program *program = mGLState.getProgram();
5812 program->setUniform4iv(location, 1, xyzw);
5813}
5814
5815void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5816{
5817 Program *program = mGLState.getProgram();
5818 program->setUniform4iv(location, count, v);
5819}
5820
5821void Context::uniformMatrix2fv(GLint location,
5822 GLsizei count,
5823 GLboolean transpose,
5824 const GLfloat *value)
5825{
5826 Program *program = mGLState.getProgram();
5827 program->setUniformMatrix2fv(location, count, transpose, value);
5828}
5829
5830void Context::uniformMatrix3fv(GLint location,
5831 GLsizei count,
5832 GLboolean transpose,
5833 const GLfloat *value)
5834{
5835 Program *program = mGLState.getProgram();
5836 program->setUniformMatrix3fv(location, count, transpose, value);
5837}
5838
5839void Context::uniformMatrix4fv(GLint location,
5840 GLsizei count,
5841 GLboolean transpose,
5842 const GLfloat *value)
5843{
5844 Program *program = mGLState.getProgram();
5845 program->setUniformMatrix4fv(location, count, transpose, value);
5846}
5847
5848void Context::validateProgram(GLuint program)
5849{
5850 Program *programObject = getProgram(program);
5851 ASSERT(programObject);
5852 programObject->validate(mCaps);
5853}
5854
Jiajia Qin5451d532017-11-16 17:16:34 +08005855void Context::validateProgramPipeline(GLuint pipeline)
5856{
5857 UNIMPLEMENTED();
5858}
5859
Jamie Madilld04908b2017-06-09 14:15:35 -04005860void Context::getProgramBinary(GLuint program,
5861 GLsizei bufSize,
5862 GLsizei *length,
5863 GLenum *binaryFormat,
5864 void *binary)
5865{
5866 Program *programObject = getProgram(program);
5867 ASSERT(programObject != nullptr);
5868
5869 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5870}
5871
5872void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5873{
5874 Program *programObject = getProgram(program);
5875 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005876
Jamie Madilld04908b2017-06-09 14:15:35 -04005877 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madillc43cdad2018-08-08 15:49:25 -04005878 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04005879 if (programObject->isInUse())
5880 {
5881 mGLState.setObjectDirty(GL_PROGRAM);
5882 }
Jamie Madilld04908b2017-06-09 14:15:35 -04005883}
5884
Jamie Madillff325f12017-08-26 15:06:05 -04005885void Context::uniform1ui(GLint location, GLuint v0)
5886{
5887 Program *program = mGLState.getProgram();
5888 program->setUniform1uiv(location, 1, &v0);
5889}
5890
5891void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5892{
5893 Program *program = mGLState.getProgram();
5894 const GLuint xy[] = {v0, v1};
5895 program->setUniform2uiv(location, 1, xy);
5896}
5897
5898void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5899{
5900 Program *program = mGLState.getProgram();
5901 const GLuint xyz[] = {v0, v1, v2};
5902 program->setUniform3uiv(location, 1, xyz);
5903}
5904
5905void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5906{
5907 Program *program = mGLState.getProgram();
5908 const GLuint xyzw[] = {v0, v1, v2, v3};
5909 program->setUniform4uiv(location, 1, xyzw);
5910}
5911
5912void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5913{
5914 Program *program = mGLState.getProgram();
5915 program->setUniform1uiv(location, count, value);
5916}
5917void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5918{
5919 Program *program = mGLState.getProgram();
5920 program->setUniform2uiv(location, count, value);
5921}
5922
5923void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5924{
5925 Program *program = mGLState.getProgram();
5926 program->setUniform3uiv(location, count, value);
5927}
5928
5929void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5930{
5931 Program *program = mGLState.getProgram();
5932 program->setUniform4uiv(location, count, value);
5933}
5934
Jamie Madillf0e04492017-08-26 15:28:42 -04005935void Context::genQueries(GLsizei n, GLuint *ids)
5936{
5937 for (GLsizei i = 0; i < n; i++)
5938 {
5939 GLuint handle = mQueryHandleAllocator.allocate();
5940 mQueryMap.assign(handle, nullptr);
5941 ids[i] = handle;
5942 }
5943}
5944
5945void Context::deleteQueries(GLsizei n, const GLuint *ids)
5946{
5947 for (int i = 0; i < n; i++)
5948 {
5949 GLuint query = ids[i];
5950
5951 Query *queryObject = nullptr;
5952 if (mQueryMap.erase(query, &queryObject))
5953 {
5954 mQueryHandleAllocator.release(query);
5955 if (queryObject)
5956 {
5957 queryObject->release(this);
5958 }
5959 }
5960 }
5961}
5962
5963GLboolean Context::isQuery(GLuint id)
5964{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005965 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005966}
5967
Jamie Madillc8c95812017-08-26 18:40:09 -04005968void Context::uniformMatrix2x3fv(GLint location,
5969 GLsizei count,
5970 GLboolean transpose,
5971 const GLfloat *value)
5972{
5973 Program *program = mGLState.getProgram();
5974 program->setUniformMatrix2x3fv(location, count, transpose, value);
5975}
5976
5977void Context::uniformMatrix3x2fv(GLint location,
5978 GLsizei count,
5979 GLboolean transpose,
5980 const GLfloat *value)
5981{
5982 Program *program = mGLState.getProgram();
5983 program->setUniformMatrix3x2fv(location, count, transpose, value);
5984}
5985
5986void Context::uniformMatrix2x4fv(GLint location,
5987 GLsizei count,
5988 GLboolean transpose,
5989 const GLfloat *value)
5990{
5991 Program *program = mGLState.getProgram();
5992 program->setUniformMatrix2x4fv(location, count, transpose, value);
5993}
5994
5995void Context::uniformMatrix4x2fv(GLint location,
5996 GLsizei count,
5997 GLboolean transpose,
5998 const GLfloat *value)
5999{
6000 Program *program = mGLState.getProgram();
6001 program->setUniformMatrix4x2fv(location, count, transpose, value);
6002}
6003
6004void Context::uniformMatrix3x4fv(GLint location,
6005 GLsizei count,
6006 GLboolean transpose,
6007 const GLfloat *value)
6008{
6009 Program *program = mGLState.getProgram();
6010 program->setUniformMatrix3x4fv(location, count, transpose, value);
6011}
6012
6013void Context::uniformMatrix4x3fv(GLint location,
6014 GLsizei count,
6015 GLboolean transpose,
6016 const GLfloat *value)
6017{
6018 Program *program = mGLState.getProgram();
6019 program->setUniformMatrix4x3fv(location, count, transpose, value);
6020}
6021
Jamie Madilld7576732017-08-26 18:49:50 -04006022void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6023{
6024 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6025 {
6026 GLuint vertexArray = arrays[arrayIndex];
6027
6028 if (arrays[arrayIndex] != 0)
6029 {
6030 VertexArray *vertexArrayObject = nullptr;
6031 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6032 {
6033 if (vertexArrayObject != nullptr)
6034 {
6035 detachVertexArray(vertexArray);
6036 vertexArrayObject->onDestroy(this);
6037 }
6038
6039 mVertexArrayHandleAllocator.release(vertexArray);
6040 }
6041 }
6042 }
6043}
6044
6045void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6046{
6047 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6048 {
6049 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6050 mVertexArrayMap.assign(vertexArray, nullptr);
6051 arrays[arrayIndex] = vertexArray;
6052 }
6053}
6054
6055bool Context::isVertexArray(GLuint array)
6056{
6057 if (array == 0)
6058 {
6059 return GL_FALSE;
6060 }
6061
6062 VertexArray *vao = getVertexArray(array);
6063 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6064}
6065
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006066void Context::endTransformFeedback()
6067{
6068 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6069 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006070 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006071}
6072
6073void Context::transformFeedbackVaryings(GLuint program,
6074 GLsizei count,
6075 const GLchar *const *varyings,
6076 GLenum bufferMode)
6077{
6078 Program *programObject = getProgram(program);
6079 ASSERT(programObject);
6080 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6081}
6082
6083void Context::getTransformFeedbackVarying(GLuint program,
6084 GLuint index,
6085 GLsizei bufSize,
6086 GLsizei *length,
6087 GLsizei *size,
6088 GLenum *type,
6089 GLchar *name)
6090{
6091 Program *programObject = getProgram(program);
6092 ASSERT(programObject);
6093 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6094}
6095
6096void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6097{
6098 for (int i = 0; i < n; i++)
6099 {
6100 GLuint transformFeedback = ids[i];
6101 if (transformFeedback == 0)
6102 {
6103 continue;
6104 }
6105
6106 TransformFeedback *transformFeedbackObject = nullptr;
6107 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6108 {
6109 if (transformFeedbackObject != nullptr)
6110 {
6111 detachTransformFeedback(transformFeedback);
6112 transformFeedbackObject->release(this);
6113 }
6114
6115 mTransformFeedbackHandleAllocator.release(transformFeedback);
6116 }
6117 }
6118}
6119
6120void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6121{
6122 for (int i = 0; i < n; i++)
6123 {
6124 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6125 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6126 ids[i] = transformFeedback;
6127 }
6128}
6129
6130bool Context::isTransformFeedback(GLuint id)
6131{
6132 if (id == 0)
6133 {
6134 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6135 // returns FALSE
6136 return GL_FALSE;
6137 }
6138
6139 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6140 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6141}
6142
6143void Context::pauseTransformFeedback()
6144{
6145 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6146 transformFeedback->pause();
6147}
6148
6149void Context::resumeTransformFeedback()
6150{
6151 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6152 transformFeedback->resume();
6153}
6154
Jamie Madill12e957f2017-08-26 21:42:26 -04006155void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6156{
6157 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006158 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006159}
6160
Brandon Jones59770802018-04-02 13:18:42 -07006161void Context::getUniformuivRobust(GLuint program,
6162 GLint location,
6163 GLsizei bufSize,
6164 GLsizei *length,
6165 GLuint *params)
6166{
6167 getUniformuiv(program, location, params);
6168}
6169
Jamie Madill12e957f2017-08-26 21:42:26 -04006170GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6171{
6172 const Program *programObject = getProgram(program);
6173 return programObject->getFragDataLocation(name);
6174}
6175
6176void Context::getUniformIndices(GLuint program,
6177 GLsizei uniformCount,
6178 const GLchar *const *uniformNames,
6179 GLuint *uniformIndices)
6180{
6181 const Program *programObject = getProgram(program);
6182 if (!programObject->isLinked())
6183 {
6184 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6185 {
6186 uniformIndices[uniformId] = GL_INVALID_INDEX;
6187 }
6188 }
6189 else
6190 {
6191 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6192 {
6193 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6194 }
6195 }
6196}
6197
6198void Context::getActiveUniformsiv(GLuint program,
6199 GLsizei uniformCount,
6200 const GLuint *uniformIndices,
6201 GLenum pname,
6202 GLint *params)
6203{
6204 const Program *programObject = getProgram(program);
6205 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6206 {
6207 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006208 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006209 }
6210}
6211
6212GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6213{
6214 const Program *programObject = getProgram(program);
6215 return programObject->getUniformBlockIndex(uniformBlockName);
6216}
6217
6218void Context::getActiveUniformBlockiv(GLuint program,
6219 GLuint uniformBlockIndex,
6220 GLenum pname,
6221 GLint *params)
6222{
6223 const Program *programObject = getProgram(program);
6224 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6225}
6226
Brandon Jones59770802018-04-02 13:18:42 -07006227void Context::getActiveUniformBlockivRobust(GLuint program,
6228 GLuint uniformBlockIndex,
6229 GLenum pname,
6230 GLsizei bufSize,
6231 GLsizei *length,
6232 GLint *params)
6233{
6234 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6235}
6236
Jamie Madill12e957f2017-08-26 21:42:26 -04006237void Context::getActiveUniformBlockName(GLuint program,
6238 GLuint uniformBlockIndex,
6239 GLsizei bufSize,
6240 GLsizei *length,
6241 GLchar *uniformBlockName)
6242{
6243 const Program *programObject = getProgram(program);
6244 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6245}
6246
6247void Context::uniformBlockBinding(GLuint program,
6248 GLuint uniformBlockIndex,
6249 GLuint uniformBlockBinding)
6250{
6251 Program *programObject = getProgram(program);
6252 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006253
6254 if (programObject->isInUse())
6255 {
6256 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006257 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006258 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006259}
6260
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006261GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6262{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006263 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6264 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006265
Jamie Madill70b5bb02017-08-28 13:32:37 -04006266 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006267 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006268 if (error.isError())
6269 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006270 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006271 handleError(error);
6272 return nullptr;
6273 }
6274
Jamie Madill70b5bb02017-08-28 13:32:37 -04006275 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006276}
6277
6278GLboolean Context::isSync(GLsync sync)
6279{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006280 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006281}
6282
6283GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6284{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006285 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006286
6287 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006288 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006289 return result;
6290}
6291
6292void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6293{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006294 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006295 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006296}
6297
6298void Context::getInteger64v(GLenum pname, GLint64 *params)
6299{
6300 GLenum nativeType = GL_NONE;
6301 unsigned int numParams = 0;
6302 getQueryParameterInfo(pname, &nativeType, &numParams);
6303
6304 if (nativeType == GL_INT_64_ANGLEX)
6305 {
6306 getInteger64vImpl(pname, params);
6307 }
6308 else
6309 {
6310 CastStateValues(this, nativeType, pname, numParams, params);
6311 }
6312}
6313
Brandon Jones59770802018-04-02 13:18:42 -07006314void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6315{
6316 getInteger64v(pname, data);
6317}
6318
Corentin Wallez336129f2017-10-17 15:55:40 -04006319void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006320{
6321 Buffer *buffer = mGLState.getTargetBuffer(target);
6322 QueryBufferParameteri64v(buffer, pname, params);
6323}
6324
Brandon Jones59770802018-04-02 13:18:42 -07006325void Context::getBufferParameteri64vRobust(BufferBinding target,
6326 GLenum pname,
6327 GLsizei bufSize,
6328 GLsizei *length,
6329 GLint64 *params)
6330{
6331 getBufferParameteri64v(target, pname, params);
6332}
6333
Jamie Madill3ef140a2017-08-26 23:11:21 -04006334void Context::genSamplers(GLsizei count, GLuint *samplers)
6335{
6336 for (int i = 0; i < count; i++)
6337 {
6338 samplers[i] = mState.mSamplers->createSampler();
6339 }
6340}
6341
6342void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6343{
6344 for (int i = 0; i < count; i++)
6345 {
6346 GLuint sampler = samplers[i];
6347
6348 if (mState.mSamplers->getSampler(sampler))
6349 {
6350 detachSampler(sampler);
6351 }
6352
6353 mState.mSamplers->deleteObject(this, sampler);
6354 }
6355}
6356
6357void Context::getInternalformativ(GLenum target,
6358 GLenum internalformat,
6359 GLenum pname,
6360 GLsizei bufSize,
6361 GLint *params)
6362{
6363 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6364 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6365}
6366
Brandon Jones59770802018-04-02 13:18:42 -07006367void Context::getInternalformativRobust(GLenum target,
6368 GLenum internalformat,
6369 GLenum pname,
6370 GLsizei bufSize,
6371 GLsizei *length,
6372 GLint *params)
6373{
6374 getInternalformativ(target, internalformat, pname, bufSize, params);
6375}
6376
Jiajia Qin5451d532017-11-16 17:16:34 +08006377void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6378{
6379 programUniform1iv(program, location, 1, &v0);
6380}
6381
6382void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6383{
6384 GLint xy[2] = {v0, v1};
6385 programUniform2iv(program, location, 1, xy);
6386}
6387
6388void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6389{
6390 GLint xyz[3] = {v0, v1, v2};
6391 programUniform3iv(program, location, 1, xyz);
6392}
6393
6394void Context::programUniform4i(GLuint program,
6395 GLint location,
6396 GLint v0,
6397 GLint v1,
6398 GLint v2,
6399 GLint v3)
6400{
6401 GLint xyzw[4] = {v0, v1, v2, v3};
6402 programUniform4iv(program, location, 1, xyzw);
6403}
6404
6405void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6406{
6407 programUniform1uiv(program, location, 1, &v0);
6408}
6409
6410void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6411{
6412 GLuint xy[2] = {v0, v1};
6413 programUniform2uiv(program, location, 1, xy);
6414}
6415
6416void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6417{
6418 GLuint xyz[3] = {v0, v1, v2};
6419 programUniform3uiv(program, location, 1, xyz);
6420}
6421
6422void Context::programUniform4ui(GLuint program,
6423 GLint location,
6424 GLuint v0,
6425 GLuint v1,
6426 GLuint v2,
6427 GLuint v3)
6428{
6429 GLuint xyzw[4] = {v0, v1, v2, v3};
6430 programUniform4uiv(program, location, 1, xyzw);
6431}
6432
6433void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6434{
6435 programUniform1fv(program, location, 1, &v0);
6436}
6437
6438void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6439{
6440 GLfloat xy[2] = {v0, v1};
6441 programUniform2fv(program, location, 1, xy);
6442}
6443
6444void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6445{
6446 GLfloat xyz[3] = {v0, v1, v2};
6447 programUniform3fv(program, location, 1, xyz);
6448}
6449
6450void Context::programUniform4f(GLuint program,
6451 GLint location,
6452 GLfloat v0,
6453 GLfloat v1,
6454 GLfloat v2,
6455 GLfloat v3)
6456{
6457 GLfloat xyzw[4] = {v0, v1, v2, v3};
6458 programUniform4fv(program, location, 1, xyzw);
6459}
6460
Jamie Madill81c2e252017-09-09 23:32:46 -04006461void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6462{
6463 Program *programObject = getProgram(program);
6464 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006465 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006466}
6467
Jiajia Qin5451d532017-11-16 17:16:34 +08006468void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6469{
6470 Program *programObject = getProgram(program);
6471 ASSERT(programObject);
6472 programObject->setUniform2iv(location, count, value);
6473}
6474
6475void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6476{
6477 Program *programObject = getProgram(program);
6478 ASSERT(programObject);
6479 programObject->setUniform3iv(location, count, value);
6480}
6481
6482void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6483{
6484 Program *programObject = getProgram(program);
6485 ASSERT(programObject);
6486 programObject->setUniform4iv(location, count, value);
6487}
6488
6489void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6490{
6491 Program *programObject = getProgram(program);
6492 ASSERT(programObject);
6493 programObject->setUniform1uiv(location, count, value);
6494}
6495
6496void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6497{
6498 Program *programObject = getProgram(program);
6499 ASSERT(programObject);
6500 programObject->setUniform2uiv(location, count, value);
6501}
6502
6503void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6504{
6505 Program *programObject = getProgram(program);
6506 ASSERT(programObject);
6507 programObject->setUniform3uiv(location, count, value);
6508}
6509
6510void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6511{
6512 Program *programObject = getProgram(program);
6513 ASSERT(programObject);
6514 programObject->setUniform4uiv(location, count, value);
6515}
6516
6517void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6518{
6519 Program *programObject = getProgram(program);
6520 ASSERT(programObject);
6521 programObject->setUniform1fv(location, count, value);
6522}
6523
6524void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6525{
6526 Program *programObject = getProgram(program);
6527 ASSERT(programObject);
6528 programObject->setUniform2fv(location, count, value);
6529}
6530
6531void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6532{
6533 Program *programObject = getProgram(program);
6534 ASSERT(programObject);
6535 programObject->setUniform3fv(location, count, value);
6536}
6537
6538void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6539{
6540 Program *programObject = getProgram(program);
6541 ASSERT(programObject);
6542 programObject->setUniform4fv(location, count, value);
6543}
6544
6545void Context::programUniformMatrix2fv(GLuint program,
6546 GLint location,
6547 GLsizei count,
6548 GLboolean transpose,
6549 const GLfloat *value)
6550{
6551 Program *programObject = getProgram(program);
6552 ASSERT(programObject);
6553 programObject->setUniformMatrix2fv(location, count, transpose, value);
6554}
6555
6556void Context::programUniformMatrix3fv(GLuint program,
6557 GLint location,
6558 GLsizei count,
6559 GLboolean transpose,
6560 const GLfloat *value)
6561{
6562 Program *programObject = getProgram(program);
6563 ASSERT(programObject);
6564 programObject->setUniformMatrix3fv(location, count, transpose, value);
6565}
6566
6567void Context::programUniformMatrix4fv(GLuint program,
6568 GLint location,
6569 GLsizei count,
6570 GLboolean transpose,
6571 const GLfloat *value)
6572{
6573 Program *programObject = getProgram(program);
6574 ASSERT(programObject);
6575 programObject->setUniformMatrix4fv(location, count, transpose, value);
6576}
6577
6578void Context::programUniformMatrix2x3fv(GLuint program,
6579 GLint location,
6580 GLsizei count,
6581 GLboolean transpose,
6582 const GLfloat *value)
6583{
6584 Program *programObject = getProgram(program);
6585 ASSERT(programObject);
6586 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6587}
6588
6589void Context::programUniformMatrix3x2fv(GLuint program,
6590 GLint location,
6591 GLsizei count,
6592 GLboolean transpose,
6593 const GLfloat *value)
6594{
6595 Program *programObject = getProgram(program);
6596 ASSERT(programObject);
6597 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6598}
6599
6600void Context::programUniformMatrix2x4fv(GLuint program,
6601 GLint location,
6602 GLsizei count,
6603 GLboolean transpose,
6604 const GLfloat *value)
6605{
6606 Program *programObject = getProgram(program);
6607 ASSERT(programObject);
6608 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6609}
6610
6611void Context::programUniformMatrix4x2fv(GLuint program,
6612 GLint location,
6613 GLsizei count,
6614 GLboolean transpose,
6615 const GLfloat *value)
6616{
6617 Program *programObject = getProgram(program);
6618 ASSERT(programObject);
6619 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6620}
6621
6622void Context::programUniformMatrix3x4fv(GLuint program,
6623 GLint location,
6624 GLsizei count,
6625 GLboolean transpose,
6626 const GLfloat *value)
6627{
6628 Program *programObject = getProgram(program);
6629 ASSERT(programObject);
6630 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6631}
6632
6633void Context::programUniformMatrix4x3fv(GLuint program,
6634 GLint location,
6635 GLsizei count,
6636 GLboolean transpose,
6637 const GLfloat *value)
6638{
6639 Program *programObject = getProgram(program);
6640 ASSERT(programObject);
6641 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6642}
6643
Jamie Madill81c2e252017-09-09 23:32:46 -04006644void Context::onTextureChange(const Texture *texture)
6645{
6646 // Conservatively assume all textures are dirty.
6647 // TODO(jmadill): More fine-grained update.
6648 mGLState.setObjectDirty(GL_TEXTURE);
6649}
6650
James Darpiniane8a93c62018-01-04 18:02:24 -08006651bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6652{
6653 return mGLState.isCurrentTransformFeedback(tf);
6654}
James Darpiniane8a93c62018-01-04 18:02:24 -08006655
Yunchao Hea336b902017-08-02 16:05:21 +08006656void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6657{
6658 for (int i = 0; i < count; i++)
6659 {
6660 pipelines[i] = createProgramPipeline();
6661 }
6662}
6663
6664void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6665{
6666 for (int i = 0; i < count; i++)
6667 {
6668 if (pipelines[i] != 0)
6669 {
6670 deleteProgramPipeline(pipelines[i]);
6671 }
6672 }
6673}
6674
6675GLboolean Context::isProgramPipeline(GLuint pipeline)
6676{
6677 if (pipeline == 0)
6678 {
6679 return GL_FALSE;
6680 }
6681
6682 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6683}
6684
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006685void Context::finishFenceNV(GLuint fence)
6686{
6687 FenceNV *fenceObject = getFenceNV(fence);
6688
6689 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006690 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006691}
6692
6693void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6694{
6695 FenceNV *fenceObject = getFenceNV(fence);
6696
6697 ASSERT(fenceObject && fenceObject->isSet());
6698
6699 switch (pname)
6700 {
6701 case GL_FENCE_STATUS_NV:
6702 {
6703 // GL_NV_fence spec:
6704 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6705 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6706 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6707 GLboolean status = GL_TRUE;
6708 if (fenceObject->getStatus() != GL_TRUE)
6709 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006710 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006711 }
6712 *params = status;
6713 break;
6714 }
6715
6716 case GL_FENCE_CONDITION_NV:
6717 {
6718 *params = static_cast<GLint>(fenceObject->getCondition());
6719 break;
6720 }
6721
6722 default:
6723 UNREACHABLE();
6724 }
6725}
6726
6727void Context::getTranslatedShaderSource(GLuint shader,
6728 GLsizei bufsize,
6729 GLsizei *length,
6730 GLchar *source)
6731{
6732 Shader *shaderObject = getShader(shader);
6733 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006734 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006735}
6736
6737void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6738{
6739 Program *programObject = getProgram(program);
6740 ASSERT(programObject);
6741
6742 programObject->getUniformfv(this, location, params);
6743}
6744
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006745void Context::getnUniformfvRobust(GLuint program,
6746 GLint location,
6747 GLsizei bufSize,
6748 GLsizei *length,
6749 GLfloat *params)
6750{
6751 UNIMPLEMENTED();
6752}
6753
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006754void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6755{
6756 Program *programObject = getProgram(program);
6757 ASSERT(programObject);
6758
6759 programObject->getUniformiv(this, location, params);
6760}
6761
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006762void Context::getnUniformivRobust(GLuint program,
6763 GLint location,
6764 GLsizei bufSize,
6765 GLsizei *length,
6766 GLint *params)
6767{
6768 UNIMPLEMENTED();
6769}
6770
6771void Context::getnUniformuivRobust(GLuint program,
6772 GLint location,
6773 GLsizei bufSize,
6774 GLsizei *length,
6775 GLuint *params)
6776{
6777 UNIMPLEMENTED();
6778}
6779
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006780GLboolean Context::isFenceNV(GLuint fence)
6781{
6782 FenceNV *fenceObject = getFenceNV(fence);
6783
6784 if (fenceObject == nullptr)
6785 {
6786 return GL_FALSE;
6787 }
6788
6789 // GL_NV_fence spec:
6790 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6791 // existing fence.
6792 return fenceObject->isSet();
6793}
6794
6795void Context::readnPixels(GLint x,
6796 GLint y,
6797 GLsizei width,
6798 GLsizei height,
6799 GLenum format,
6800 GLenum type,
6801 GLsizei bufSize,
6802 void *data)
6803{
6804 return readPixels(x, y, width, height, format, type, data);
6805}
6806
Jamie Madill007530e2017-12-28 14:27:04 -05006807void Context::setFenceNV(GLuint fence, GLenum condition)
6808{
6809 ASSERT(condition == GL_ALL_COMPLETED_NV);
6810
6811 FenceNV *fenceObject = getFenceNV(fence);
6812 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006813 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006814}
6815
6816GLboolean Context::testFenceNV(GLuint fence)
6817{
6818 FenceNV *fenceObject = getFenceNV(fence);
6819
6820 ASSERT(fenceObject != nullptr);
6821 ASSERT(fenceObject->isSet() == GL_TRUE);
6822
6823 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006824 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006825 if (error.isError())
6826 {
6827 handleError(error);
6828 return GL_TRUE;
6829 }
6830
6831 return result;
6832}
6833
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006834void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006835{
6836 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006837 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006838 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006839}
6840
Jamie Madillfa920eb2018-01-04 11:45:50 -05006841void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006842{
6843 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006844 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006845 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6846}
6847
Jamie Madillfa920eb2018-01-04 11:45:50 -05006848void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6849{
6850 UNIMPLEMENTED();
6851}
6852
Jamie Madill5b772312018-03-08 20:28:32 -05006853bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6854{
6855 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6856 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6857 // to the fact that it is stored internally as a float, and so would require conversion
6858 // if returned from Context::getIntegerv. Since this conversion is already implemented
6859 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6860 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6861 // application.
6862 switch (pname)
6863 {
6864 case GL_COMPRESSED_TEXTURE_FORMATS:
6865 {
6866 *type = GL_INT;
6867 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6868 return true;
6869 }
6870 case GL_SHADER_BINARY_FORMATS:
6871 {
6872 *type = GL_INT;
6873 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6874 return true;
6875 }
6876
6877 case GL_MAX_VERTEX_ATTRIBS:
6878 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6879 case GL_MAX_VARYING_VECTORS:
6880 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6881 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6882 case GL_MAX_TEXTURE_IMAGE_UNITS:
6883 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6884 case GL_MAX_RENDERBUFFER_SIZE:
6885 case GL_NUM_SHADER_BINARY_FORMATS:
6886 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6887 case GL_ARRAY_BUFFER_BINDING:
6888 case GL_FRAMEBUFFER_BINDING:
6889 case GL_RENDERBUFFER_BINDING:
6890 case GL_CURRENT_PROGRAM:
6891 case GL_PACK_ALIGNMENT:
6892 case GL_UNPACK_ALIGNMENT:
6893 case GL_GENERATE_MIPMAP_HINT:
6894 case GL_RED_BITS:
6895 case GL_GREEN_BITS:
6896 case GL_BLUE_BITS:
6897 case GL_ALPHA_BITS:
6898 case GL_DEPTH_BITS:
6899 case GL_STENCIL_BITS:
6900 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6901 case GL_CULL_FACE_MODE:
6902 case GL_FRONT_FACE:
6903 case GL_ACTIVE_TEXTURE:
6904 case GL_STENCIL_FUNC:
6905 case GL_STENCIL_VALUE_MASK:
6906 case GL_STENCIL_REF:
6907 case GL_STENCIL_FAIL:
6908 case GL_STENCIL_PASS_DEPTH_FAIL:
6909 case GL_STENCIL_PASS_DEPTH_PASS:
6910 case GL_STENCIL_BACK_FUNC:
6911 case GL_STENCIL_BACK_VALUE_MASK:
6912 case GL_STENCIL_BACK_REF:
6913 case GL_STENCIL_BACK_FAIL:
6914 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6915 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6916 case GL_DEPTH_FUNC:
6917 case GL_BLEND_SRC_RGB:
6918 case GL_BLEND_SRC_ALPHA:
6919 case GL_BLEND_DST_RGB:
6920 case GL_BLEND_DST_ALPHA:
6921 case GL_BLEND_EQUATION_RGB:
6922 case GL_BLEND_EQUATION_ALPHA:
6923 case GL_STENCIL_WRITEMASK:
6924 case GL_STENCIL_BACK_WRITEMASK:
6925 case GL_STENCIL_CLEAR_VALUE:
6926 case GL_SUBPIXEL_BITS:
6927 case GL_MAX_TEXTURE_SIZE:
6928 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6929 case GL_SAMPLE_BUFFERS:
6930 case GL_SAMPLES:
6931 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6932 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6933 case GL_TEXTURE_BINDING_2D:
6934 case GL_TEXTURE_BINDING_CUBE_MAP:
6935 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6936 {
6937 *type = GL_INT;
6938 *numParams = 1;
6939 return true;
6940 }
6941 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6942 {
6943 if (!getExtensions().packReverseRowOrder)
6944 {
6945 return false;
6946 }
6947 *type = GL_INT;
6948 *numParams = 1;
6949 return true;
6950 }
6951 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6952 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6953 {
6954 if (!getExtensions().textureRectangle)
6955 {
6956 return false;
6957 }
6958 *type = GL_INT;
6959 *numParams = 1;
6960 return true;
6961 }
6962 case GL_MAX_DRAW_BUFFERS_EXT:
6963 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6964 {
6965 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6966 {
6967 return false;
6968 }
6969 *type = GL_INT;
6970 *numParams = 1;
6971 return true;
6972 }
6973 case GL_MAX_VIEWPORT_DIMS:
6974 {
6975 *type = GL_INT;
6976 *numParams = 2;
6977 return true;
6978 }
6979 case GL_VIEWPORT:
6980 case GL_SCISSOR_BOX:
6981 {
6982 *type = GL_INT;
6983 *numParams = 4;
6984 return true;
6985 }
6986 case GL_SHADER_COMPILER:
6987 case GL_SAMPLE_COVERAGE_INVERT:
6988 case GL_DEPTH_WRITEMASK:
6989 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6990 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6991 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6992 // bool-natural
6993 case GL_SAMPLE_COVERAGE:
6994 case GL_SCISSOR_TEST:
6995 case GL_STENCIL_TEST:
6996 case GL_DEPTH_TEST:
6997 case GL_BLEND:
6998 case GL_DITHER:
6999 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7000 {
7001 *type = GL_BOOL;
7002 *numParams = 1;
7003 return true;
7004 }
7005 case GL_COLOR_WRITEMASK:
7006 {
7007 *type = GL_BOOL;
7008 *numParams = 4;
7009 return true;
7010 }
7011 case GL_POLYGON_OFFSET_FACTOR:
7012 case GL_POLYGON_OFFSET_UNITS:
7013 case GL_SAMPLE_COVERAGE_VALUE:
7014 case GL_DEPTH_CLEAR_VALUE:
7015 case GL_LINE_WIDTH:
7016 {
7017 *type = GL_FLOAT;
7018 *numParams = 1;
7019 return true;
7020 }
7021 case GL_ALIASED_LINE_WIDTH_RANGE:
7022 case GL_ALIASED_POINT_SIZE_RANGE:
7023 case GL_DEPTH_RANGE:
7024 {
7025 *type = GL_FLOAT;
7026 *numParams = 2;
7027 return true;
7028 }
7029 case GL_COLOR_CLEAR_VALUE:
7030 case GL_BLEND_COLOR:
7031 {
7032 *type = GL_FLOAT;
7033 *numParams = 4;
7034 return true;
7035 }
7036 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7037 if (!getExtensions().textureFilterAnisotropic)
7038 {
7039 return false;
7040 }
7041 *type = GL_FLOAT;
7042 *numParams = 1;
7043 return true;
7044 case GL_TIMESTAMP_EXT:
7045 if (!getExtensions().disjointTimerQuery)
7046 {
7047 return false;
7048 }
7049 *type = GL_INT_64_ANGLEX;
7050 *numParams = 1;
7051 return true;
7052 case GL_GPU_DISJOINT_EXT:
7053 if (!getExtensions().disjointTimerQuery)
7054 {
7055 return false;
7056 }
7057 *type = GL_INT;
7058 *numParams = 1;
7059 return true;
7060 case GL_COVERAGE_MODULATION_CHROMIUM:
7061 if (!getExtensions().framebufferMixedSamples)
7062 {
7063 return false;
7064 }
7065 *type = GL_INT;
7066 *numParams = 1;
7067 return true;
7068 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7069 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7070 {
7071 return false;
7072 }
7073 *type = GL_INT;
7074 *numParams = 1;
7075 return true;
7076 }
7077
7078 if (getExtensions().debug)
7079 {
7080 switch (pname)
7081 {
7082 case GL_DEBUG_LOGGED_MESSAGES:
7083 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7084 case GL_DEBUG_GROUP_STACK_DEPTH:
7085 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7086 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7087 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7088 case GL_MAX_LABEL_LENGTH:
7089 *type = GL_INT;
7090 *numParams = 1;
7091 return true;
7092
7093 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7094 case GL_DEBUG_OUTPUT:
7095 *type = GL_BOOL;
7096 *numParams = 1;
7097 return true;
7098 }
7099 }
7100
7101 if (getExtensions().multisampleCompatibility)
7102 {
7103 switch (pname)
7104 {
7105 case GL_MULTISAMPLE_EXT:
7106 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7107 *type = GL_BOOL;
7108 *numParams = 1;
7109 return true;
7110 }
7111 }
7112
7113 if (getExtensions().pathRendering)
7114 {
7115 switch (pname)
7116 {
7117 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7118 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7119 *type = GL_FLOAT;
7120 *numParams = 16;
7121 return true;
7122 }
7123 }
7124
7125 if (getExtensions().bindGeneratesResource)
7126 {
7127 switch (pname)
7128 {
7129 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7130 *type = GL_BOOL;
7131 *numParams = 1;
7132 return true;
7133 }
7134 }
7135
7136 if (getExtensions().clientArrays)
7137 {
7138 switch (pname)
7139 {
7140 case GL_CLIENT_ARRAYS_ANGLE:
7141 *type = GL_BOOL;
7142 *numParams = 1;
7143 return true;
7144 }
7145 }
7146
7147 if (getExtensions().sRGBWriteControl)
7148 {
7149 switch (pname)
7150 {
7151 case GL_FRAMEBUFFER_SRGB_EXT:
7152 *type = GL_BOOL;
7153 *numParams = 1;
7154 return true;
7155 }
7156 }
7157
7158 if (getExtensions().robustResourceInitialization &&
7159 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7160 {
7161 *type = GL_BOOL;
7162 *numParams = 1;
7163 return true;
7164 }
7165
7166 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7167 {
7168 *type = GL_BOOL;
7169 *numParams = 1;
7170 return true;
7171 }
7172
jchen1082af6202018-06-22 10:59:52 +08007173 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7174 {
7175 *type = GL_INT;
7176 *numParams = 1;
7177 return true;
7178 }
7179
Jamie Madill5b772312018-03-08 20:28:32 -05007180 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7181 switch (pname)
7182 {
7183 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7184 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7185 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7186 {
7187 return false;
7188 }
7189 *type = GL_INT;
7190 *numParams = 1;
7191 return true;
7192
7193 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7194 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7195 {
7196 return false;
7197 }
7198 *type = GL_INT;
7199 *numParams = 1;
7200 return true;
7201
7202 case GL_PROGRAM_BINARY_FORMATS_OES:
7203 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7204 {
7205 return false;
7206 }
7207 *type = GL_INT;
7208 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7209 return true;
7210
7211 case GL_PACK_ROW_LENGTH:
7212 case GL_PACK_SKIP_ROWS:
7213 case GL_PACK_SKIP_PIXELS:
7214 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7215 {
7216 return false;
7217 }
7218 *type = GL_INT;
7219 *numParams = 1;
7220 return true;
7221 case GL_UNPACK_ROW_LENGTH:
7222 case GL_UNPACK_SKIP_ROWS:
7223 case GL_UNPACK_SKIP_PIXELS:
7224 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7225 {
7226 return false;
7227 }
7228 *type = GL_INT;
7229 *numParams = 1;
7230 return true;
7231 case GL_VERTEX_ARRAY_BINDING:
7232 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7233 {
7234 return false;
7235 }
7236 *type = GL_INT;
7237 *numParams = 1;
7238 return true;
7239 case GL_PIXEL_PACK_BUFFER_BINDING:
7240 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7241 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7242 {
7243 return false;
7244 }
7245 *type = GL_INT;
7246 *numParams = 1;
7247 return true;
7248 case GL_MAX_SAMPLES:
7249 {
7250 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7251 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7252 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7253 {
7254 return false;
7255 }
7256 *type = GL_INT;
7257 *numParams = 1;
7258 return true;
7259
7260 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7261 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7262 {
7263 return false;
7264 }
7265 *type = GL_INT;
7266 *numParams = 1;
7267 return true;
7268 }
7269 }
7270
7271 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7272 {
7273 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7274 {
7275 return false;
7276 }
7277 *type = GL_INT;
7278 *numParams = 1;
7279 return true;
7280 }
7281
7282 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7283 {
7284 *type = GL_INT;
7285 *numParams = 1;
7286 return true;
7287 }
7288
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007289 if (getClientVersion() < Version(2, 0))
7290 {
7291 switch (pname)
7292 {
7293 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007294 case GL_CLIENT_ACTIVE_TEXTURE:
7295 case GL_MATRIX_MODE:
7296 case GL_MAX_TEXTURE_UNITS:
7297 case GL_MAX_MODELVIEW_STACK_DEPTH:
7298 case GL_MAX_PROJECTION_STACK_DEPTH:
7299 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007300 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007301 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007302 case GL_VERTEX_ARRAY_STRIDE:
7303 case GL_NORMAL_ARRAY_STRIDE:
7304 case GL_COLOR_ARRAY_STRIDE:
7305 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7306 case GL_VERTEX_ARRAY_SIZE:
7307 case GL_COLOR_ARRAY_SIZE:
7308 case GL_TEXTURE_COORD_ARRAY_SIZE:
7309 case GL_VERTEX_ARRAY_TYPE:
7310 case GL_NORMAL_ARRAY_TYPE:
7311 case GL_COLOR_ARRAY_TYPE:
7312 case GL_TEXTURE_COORD_ARRAY_TYPE:
7313 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7314 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7315 case GL_COLOR_ARRAY_BUFFER_BINDING:
7316 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7317 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7318 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7319 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007320 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007321 case GL_MODELVIEW_STACK_DEPTH:
7322 case GL_PROJECTION_STACK_DEPTH:
7323 case GL_TEXTURE_STACK_DEPTH:
7324 case GL_LOGIC_OP_MODE:
7325 case GL_BLEND_SRC:
7326 case GL_BLEND_DST:
7327 case GL_PERSPECTIVE_CORRECTION_HINT:
7328 case GL_POINT_SMOOTH_HINT:
7329 case GL_LINE_SMOOTH_HINT:
7330 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007331 *type = GL_INT;
7332 *numParams = 1;
7333 return true;
7334 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007335 case GL_FOG_DENSITY:
7336 case GL_FOG_START:
7337 case GL_FOG_END:
7338 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007339 case GL_POINT_SIZE:
7340 case GL_POINT_SIZE_MIN:
7341 case GL_POINT_SIZE_MAX:
7342 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007343 *type = GL_FLOAT;
7344 *numParams = 1;
7345 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007346 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007347 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007348 *type = GL_FLOAT;
7349 *numParams = 2;
7350 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007351 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007352 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007353 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007354 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007355 *type = GL_FLOAT;
7356 *numParams = 4;
7357 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007358 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007359 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007360 *type = GL_FLOAT;
7361 *numParams = 3;
7362 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007363 case GL_MODELVIEW_MATRIX:
7364 case GL_PROJECTION_MATRIX:
7365 case GL_TEXTURE_MATRIX:
7366 *type = GL_FLOAT;
7367 *numParams = 16;
7368 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007369 case GL_LIGHT_MODEL_TWO_SIDE:
7370 *type = GL_BOOL;
7371 *numParams = 1;
7372 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007373 }
7374 }
7375
Jamie Madill5b772312018-03-08 20:28:32 -05007376 if (getClientVersion() < Version(3, 0))
7377 {
7378 return false;
7379 }
7380
7381 // Check for ES3.0+ parameter names
7382 switch (pname)
7383 {
7384 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7385 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7386 case GL_UNIFORM_BUFFER_BINDING:
7387 case GL_TRANSFORM_FEEDBACK_BINDING:
7388 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7389 case GL_COPY_READ_BUFFER_BINDING:
7390 case GL_COPY_WRITE_BUFFER_BINDING:
7391 case GL_SAMPLER_BINDING:
7392 case GL_READ_BUFFER:
7393 case GL_TEXTURE_BINDING_3D:
7394 case GL_TEXTURE_BINDING_2D_ARRAY:
7395 case GL_MAX_3D_TEXTURE_SIZE:
7396 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7397 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7398 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7399 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7400 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7401 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7402 case GL_MAX_VARYING_COMPONENTS:
7403 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7404 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7405 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7406 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7407 case GL_NUM_EXTENSIONS:
7408 case GL_MAJOR_VERSION:
7409 case GL_MINOR_VERSION:
7410 case GL_MAX_ELEMENTS_INDICES:
7411 case GL_MAX_ELEMENTS_VERTICES:
7412 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7413 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7414 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7415 case GL_UNPACK_IMAGE_HEIGHT:
7416 case GL_UNPACK_SKIP_IMAGES:
7417 {
7418 *type = GL_INT;
7419 *numParams = 1;
7420 return true;
7421 }
7422
7423 case GL_MAX_ELEMENT_INDEX:
7424 case GL_MAX_UNIFORM_BLOCK_SIZE:
7425 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7426 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7427 case GL_MAX_SERVER_WAIT_TIMEOUT:
7428 {
7429 *type = GL_INT_64_ANGLEX;
7430 *numParams = 1;
7431 return true;
7432 }
7433
7434 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7435 case GL_TRANSFORM_FEEDBACK_PAUSED:
7436 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7437 case GL_RASTERIZER_DISCARD:
7438 {
7439 *type = GL_BOOL;
7440 *numParams = 1;
7441 return true;
7442 }
7443
7444 case GL_MAX_TEXTURE_LOD_BIAS:
7445 {
7446 *type = GL_FLOAT;
7447 *numParams = 1;
7448 return true;
7449 }
7450 }
7451
7452 if (getExtensions().requestExtension)
7453 {
7454 switch (pname)
7455 {
7456 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7457 *type = GL_INT;
7458 *numParams = 1;
7459 return true;
7460 }
7461 }
7462
7463 if (getClientVersion() < Version(3, 1))
7464 {
7465 return false;
7466 }
7467
7468 switch (pname)
7469 {
7470 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7471 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7472 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7473 case GL_MAX_FRAMEBUFFER_WIDTH:
7474 case GL_MAX_FRAMEBUFFER_HEIGHT:
7475 case GL_MAX_FRAMEBUFFER_SAMPLES:
7476 case GL_MAX_SAMPLE_MASK_WORDS:
7477 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7478 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7479 case GL_MAX_INTEGER_SAMPLES:
7480 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7481 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7482 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7483 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7484 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7485 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7486 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7487 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7488 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7489 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7490 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7491 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7492 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7493 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7494 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7495 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7496 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7497 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7498 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7499 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7500 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7501 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7502 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7503 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7504 case GL_MAX_UNIFORM_LOCATIONS:
7505 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7506 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7507 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7508 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7509 case GL_MAX_IMAGE_UNITS:
7510 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7511 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7512 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7513 case GL_SHADER_STORAGE_BUFFER_BINDING:
7514 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7515 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007516 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007517 *type = GL_INT;
7518 *numParams = 1;
7519 return true;
7520 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7521 *type = GL_INT_64_ANGLEX;
7522 *numParams = 1;
7523 return true;
7524 case GL_SAMPLE_MASK:
7525 *type = GL_BOOL;
7526 *numParams = 1;
7527 return true;
7528 }
7529
7530 if (getExtensions().geometryShader)
7531 {
7532 switch (pname)
7533 {
7534 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7535 case GL_LAYER_PROVOKING_VERTEX_EXT:
7536 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7537 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7538 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7539 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7540 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7541 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7542 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7543 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7544 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7545 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7546 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7547 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7548 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7549 *type = GL_INT;
7550 *numParams = 1;
7551 return true;
7552 }
7553 }
7554
7555 return false;
7556}
7557
7558bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7559{
7560 if (getClientVersion() < Version(3, 0))
7561 {
7562 return false;
7563 }
7564
7565 switch (target)
7566 {
7567 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7568 case GL_UNIFORM_BUFFER_BINDING:
7569 {
7570 *type = GL_INT;
7571 *numParams = 1;
7572 return true;
7573 }
7574 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7575 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7576 case GL_UNIFORM_BUFFER_START:
7577 case GL_UNIFORM_BUFFER_SIZE:
7578 {
7579 *type = GL_INT_64_ANGLEX;
7580 *numParams = 1;
7581 return true;
7582 }
7583 }
7584
7585 if (getClientVersion() < Version(3, 1))
7586 {
7587 return false;
7588 }
7589
7590 switch (target)
7591 {
7592 case GL_IMAGE_BINDING_LAYERED:
7593 {
7594 *type = GL_BOOL;
7595 *numParams = 1;
7596 return true;
7597 }
7598 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7599 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7600 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7601 case GL_SHADER_STORAGE_BUFFER_BINDING:
7602 case GL_VERTEX_BINDING_BUFFER:
7603 case GL_VERTEX_BINDING_DIVISOR:
7604 case GL_VERTEX_BINDING_OFFSET:
7605 case GL_VERTEX_BINDING_STRIDE:
7606 case GL_SAMPLE_MASK_VALUE:
7607 case GL_IMAGE_BINDING_NAME:
7608 case GL_IMAGE_BINDING_LEVEL:
7609 case GL_IMAGE_BINDING_LAYER:
7610 case GL_IMAGE_BINDING_ACCESS:
7611 case GL_IMAGE_BINDING_FORMAT:
7612 {
7613 *type = GL_INT;
7614 *numParams = 1;
7615 return true;
7616 }
7617 case GL_ATOMIC_COUNTER_BUFFER_START:
7618 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7619 case GL_SHADER_STORAGE_BUFFER_START:
7620 case GL_SHADER_STORAGE_BUFFER_SIZE:
7621 {
7622 *type = GL_INT_64_ANGLEX;
7623 *numParams = 1;
7624 return true;
7625 }
7626 }
7627
7628 return false;
7629}
7630
7631Program *Context::getProgram(GLuint handle) const
7632{
7633 return mState.mShaderPrograms->getProgram(handle);
7634}
7635
7636Shader *Context::getShader(GLuint handle) const
7637{
7638 return mState.mShaderPrograms->getShader(handle);
7639}
7640
7641bool Context::isTextureGenerated(GLuint texture) const
7642{
7643 return mState.mTextures->isHandleGenerated(texture);
7644}
7645
Jamie Madill5b772312018-03-08 20:28:32 -05007646bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7647{
7648 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7649}
7650
7651bool Context::isFramebufferGenerated(GLuint framebuffer) const
7652{
7653 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7654}
7655
7656bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7657{
7658 return mState.mPipelines->isHandleGenerated(pipeline);
7659}
7660
7661bool Context::usingDisplayTextureShareGroup() const
7662{
7663 return mDisplayTextureShareGroup;
7664}
7665
7666GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7667{
7668 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7669 internalformat == GL_DEPTH_STENCIL
7670 ? GL_DEPTH24_STENCIL8
7671 : internalformat;
7672}
7673
jchen1082af6202018-06-22 10:59:52 +08007674void Context::maxShaderCompilerThreads(GLuint count)
7675{
jchen107ae70d82018-07-06 13:47:01 +08007676 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08007677 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007678 // A count of zero specifies a request for no parallel compiling or linking.
7679 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7680 {
7681 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7682 }
7683 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007684}
7685
Jamie Madill2eb65032018-07-30 10:25:57 -04007686bool Context::isGLES1() const
7687{
7688 return mState.getClientVersion() < Version(2, 0);
7689}
7690
Jamie Madilla11819d2018-07-30 10:26:01 -04007691void Context::onSubjectStateChange(const Context *context,
7692 angle::SubjectIndex index,
7693 angle::SubjectMessage message)
7694{
Jamie Madilla11819d2018-07-30 10:26:01 -04007695 switch (index)
7696 {
7697 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007698 switch (message)
7699 {
7700 case angle::SubjectMessage::CONTENTS_CHANGED:
7701 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
7702 mStateCache.onVertexArrayBufferContentsChange(this);
7703 break;
7704 case angle::SubjectMessage::RESOURCE_MAPPED:
7705 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7706 case angle::SubjectMessage::BINDING_CHANGED:
7707 mStateCache.onVertexArrayBufferStateChange(this);
7708 break;
7709 default:
7710 break;
7711 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007712 break;
7713
7714 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007715 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7716 {
7717 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
7718 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007719 break;
7720
7721 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007722 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7723 {
7724 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
7725 }
7726 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04007727 break;
7728
7729 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04007730 if (index < kTextureMaxSubjectIndex)
7731 {
7732 mGLState.onActiveTextureStateChange(index);
Jamie Madilld84b6732018-09-06 15:54:35 -04007733 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007734 }
7735 else
7736 {
7737 ASSERT(index < kUniformBufferMaxSubjectIndex);
7738 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04007739 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007740 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007741 break;
7742 }
7743}
7744
Jamie Madill6b873dd2018-07-12 23:56:30 -04007745// ErrorSet implementation.
7746ErrorSet::ErrorSet(Context *context) : mContext(context)
7747{
7748}
7749
7750ErrorSet::~ErrorSet() = default;
7751
Jamie Madill306b6c12018-07-27 08:12:49 -04007752void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007753{
7754 // This internal enum is used to filter internal errors that are already handled.
7755 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7756 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7757 {
7758 return;
7759 }
7760
7761 if (ANGLE_UNLIKELY(error.isError()))
7762 {
7763 GLenum code = error.getCode();
7764 mErrors.insert(code);
7765 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7766 {
7767 mContext->markContextLost();
7768 }
7769
7770 ASSERT(!error.getMessage().empty());
7771 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7772 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7773 error.getMessage());
7774 }
7775}
7776
7777bool ErrorSet::empty() const
7778{
7779 return mErrors.empty();
7780}
7781
7782GLenum ErrorSet::popError()
7783{
7784 ASSERT(!empty());
7785 GLenum error = *mErrors.begin();
7786 mErrors.erase(mErrors.begin());
7787 return error;
7788}
Jamie Madilldc358af2018-07-31 11:22:13 -04007789
7790// StateCache implementation.
Jamie Madill16e28fd2018-09-12 11:03:05 -04007791StateCache::StateCache(Context *context)
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007792 : mCachedHasAnyEnabledClientAttrib(false),
7793 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04007794 mCachedInstancedVertexElementLimit(0),
7795 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madilldc358af2018-07-31 11:22:13 -04007796{
Jamie Madill16e28fd2018-09-12 11:03:05 -04007797 updateValidDrawModes(context);
Jamie Madilldc358af2018-07-31 11:22:13 -04007798}
7799
7800StateCache::~StateCache() = default;
7801
7802void StateCache::updateActiveAttribsMask(Context *context)
7803{
7804 bool isGLES1 = context->isGLES1();
7805 const State &glState = context->getGLState();
7806
7807 if (!isGLES1 && !glState.getProgram())
7808 {
7809 mCachedActiveBufferedAttribsMask = AttributesMask();
7810 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04007811 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04007812 return;
7813 }
7814
7815 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7816 : glState.getProgram()->getActiveAttribLocationsMask();
7817
7818 const VertexArray *vao = glState.getVertexArray();
7819 ASSERT(vao);
7820
7821 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7822 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04007823 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007824
Jamie Madill0a17e482018-08-31 17:19:11 -04007825 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
7826 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04007827 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007828 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7829}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007830
7831void StateCache::updateVertexElementLimits(Context *context)
7832{
7833 const VertexArray *vao = context->getGLState().getVertexArray();
7834
7835 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7836 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7837
7838 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
7839 // If there are no buffered attributes then we should not limit the draw call count.
7840 if (!vao || !mCachedActiveBufferedAttribsMask.any())
7841 {
7842 return;
7843 }
7844
7845 const auto &vertexAttribs = vao->getVertexAttributes();
7846 const auto &vertexBindings = vao->getVertexBindings();
7847
7848 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
7849 {
7850 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
7851 ASSERT(attrib.enabled);
7852
7853 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
7854 ASSERT(context->isGLES1() ||
7855 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
7856
7857 GLint64 limit = attrib.getCachedElementLimit();
7858 if (binding.getDivisor() > 0)
7859 {
7860 mCachedInstancedVertexElementLimit =
7861 std::min(mCachedInstancedVertexElementLimit, limit);
7862 }
7863 else
7864 {
7865 mCachedNonInstancedVertexElementLimit =
7866 std::min(mCachedNonInstancedVertexElementLimit, limit);
7867 }
7868 }
7869}
Jamie Madillc43cdad2018-08-08 15:49:25 -04007870
Jamie Madilld84b6732018-09-06 15:54:35 -04007871void StateCache::updateBasicDrawStatesError()
7872{
7873 mCachedBasicDrawStatesError = kInvalidPointer;
7874}
7875
7876intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
7877{
7878 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
7879 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
7880 return mCachedBasicDrawStatesError;
7881}
7882
Jamie Madillc43cdad2018-08-08 15:49:25 -04007883void StateCache::onVertexArrayBindingChange(Context *context)
7884{
7885 updateActiveAttribsMask(context);
7886 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007887 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007888}
7889
7890void StateCache::onProgramExecutableChange(Context *context)
7891{
7892 updateActiveAttribsMask(context);
7893 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007894 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04007895 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04007896}
7897
Jamie Madilld84b6732018-09-06 15:54:35 -04007898void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04007899{
7900 updateVertexElementLimits(context);
7901}
7902
Jamie Madilld84b6732018-09-06 15:54:35 -04007903void StateCache::onVertexArrayBufferContentsChange(Context *context)
7904{
7905 updateVertexElementLimits(context);
7906 updateBasicDrawStatesError();
7907}
7908
Jamie Madillc43cdad2018-08-08 15:49:25 -04007909void StateCache::onVertexArrayStateChange(Context *context)
7910{
7911 updateActiveAttribsMask(context);
7912 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007913 updateBasicDrawStatesError();
7914}
7915
7916void StateCache::onVertexArrayBufferStateChange(Context *context)
7917{
7918 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007919}
7920
7921void StateCache::onGLES1ClientStateChange(Context *context)
7922{
7923 updateActiveAttribsMask(context);
7924}
Jamie Madilld84b6732018-09-06 15:54:35 -04007925
7926void StateCache::onDrawFramebufferChange(Context *context)
7927{
7928 updateBasicDrawStatesError();
7929}
7930
7931void StateCache::onContextCapChange(Context *context)
7932{
7933 updateBasicDrawStatesError();
7934}
7935
7936void StateCache::onStencilStateChange(Context *context)
7937{
7938 updateBasicDrawStatesError();
7939}
7940
7941void StateCache::onDefaultVertexAttributeChange(Context *context)
7942{
7943 updateBasicDrawStatesError();
7944}
7945
7946void StateCache::onActiveTextureChange(Context *context)
7947{
7948 updateBasicDrawStatesError();
7949}
7950
7951void StateCache::onQueryChange(Context *context)
7952{
7953 updateBasicDrawStatesError();
7954}
7955
7956void StateCache::onTransformFeedbackChange(Context *context)
7957{
7958 updateBasicDrawStatesError();
7959}
7960
7961void StateCache::onUniformBufferStateChange(Context *context)
7962{
7963 updateBasicDrawStatesError();
7964}
7965
7966void StateCache::onBufferBindingChange(Context *context)
7967{
7968 updateBasicDrawStatesError();
7969}
Jamie Madill526a6f62018-09-12 11:03:05 -04007970
7971void StateCache::updateValidDrawModes(Context *context)
7972{
7973 Program *program = context->getGLState().getProgram();
7974 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
7975 {
7976 mCachedValidDrawModes = {{
7977 true, /* Points */
7978 true, /* Lines */
7979 true, /* LineLoop */
7980 true, /* LineStrip */
7981 true, /* Triangles */
7982 true, /* TriangleStrip */
7983 true, /* TriangleFan */
7984 false, /* LinesAdjacency */
7985 false, /* LineStripAdjacency */
7986 false, /* TrianglesAdjacency */
7987 false, /* TriangleStripAdjacency */
7988 false, /* InvalidEnum */
7989 }};
7990 }
7991 else
7992 {
7993 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
7994
7995 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
7996
7997 mCachedValidDrawModes = {{
7998 gsMode == PrimitiveMode::Points, /* Points */
7999 gsMode == PrimitiveMode::Lines, /* Lines */
8000 gsMode == PrimitiveMode::Lines, /* LineLoop */
8001 gsMode == PrimitiveMode::Lines, /* LineStrip */
8002 gsMode == PrimitiveMode::Triangles, /* Triangles */
8003 gsMode == PrimitiveMode::Triangles, /* TriangleStrip */
8004 gsMode == PrimitiveMode::Triangles, /* TriangleFan */
8005 gsMode == PrimitiveMode::LinesAdjacency, /* LinesAdjacency */
8006 gsMode == PrimitiveMode::LinesAdjacency, /* LineStripAdjacency */
8007 gsMode == PrimitiveMode::TrianglesAdjacency, /* TrianglesAdjacency */
8008 gsMode == PrimitiveMode::TrianglesAdjacency, /* TriangleStripAdjacency */
8009 false, /* InvalidEnum */
8010 }};
8011 }
8012}
Jamie Madillc29968b2016-01-20 11:17:23 -05008013} // namespace gl