blob: 59f0e1320446f237485c3af3fa10497c0c1a7b52 [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 Madill231c7f52017-04-26 13:45:37 -040044#include "libANGLE/renderer/ContextImpl.h"
45#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040046#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040047#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000048
Geoff Langf6db0982015-08-25 13:04:00 -040049namespace
50{
51
Jamie Madillb6664922017-07-25 12:55:04 -040052#define ANGLE_HANDLE_ERR(X) \
53 handleError(X); \
54 return;
55#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
56
Ian Ewell3ffd78b2016-01-22 16:09:42 -050057template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050058std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030059 GLsizei numPaths,
60 const void *paths,
61 GLuint pathBase)
62{
63 std::vector<gl::Path *> ret;
64 ret.reserve(numPaths);
65
66 const auto *nameArray = static_cast<const T *>(paths);
67
68 for (GLsizei i = 0; i < numPaths; ++i)
69 {
70 const GLuint pathName = nameArray[i] + pathBase;
71
72 ret.push_back(resourceManager.getPath(pathName));
73 }
74
75 return ret;
76}
77
Geoff Lang4ddf5af2016-12-01 14:30:44 -050078std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030079 GLsizei numPaths,
80 GLenum pathNameType,
81 const void *paths,
82 GLuint pathBase)
83{
84 switch (pathNameType)
85 {
86 case GL_UNSIGNED_BYTE:
87 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
88
89 case GL_BYTE:
90 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
91
92 case GL_UNSIGNED_SHORT:
93 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
94
95 case GL_SHORT:
96 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
97
98 case GL_UNSIGNED_INT:
99 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
100
101 case GL_INT:
102 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
103 }
104
105 UNREACHABLE();
106 return std::vector<gl::Path *>();
107}
108
109template <typename T>
Jamie Madill5188a272018-07-25 10:53:56 -0400110gl::Error GetQueryObjectParameter(const gl::Context *context,
111 gl::Query *query,
112 GLenum pname,
113 T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500114{
Geoff Lang2186c382016-10-14 10:54:54 -0400115 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116
117 switch (pname)
118 {
119 case GL_QUERY_RESULT_EXT:
Jamie Madill5188a272018-07-25 10:53:56 -0400120 return query->getResult(context, params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500121 case GL_QUERY_RESULT_AVAILABLE_EXT:
122 {
123 bool available;
Jamie Madill5188a272018-07-25 10:53:56 -0400124 gl::Error error = query->isResultAvailable(context, &available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500125 if (!error.isError())
126 {
jchen10a99ed552017-09-22 08:10:32 +0800127 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500128 }
129 return error;
130 }
131 default:
132 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500133 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500134 }
135}
136
Jamie Madill09463932018-04-04 05:26:59 -0400137void MarkTransformFeedbackBufferUsage(const gl::Context *context,
138 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700139 GLsizei count,
140 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400141{
Geoff Lang1a683462015-09-29 15:09:59 -0400142 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400143 {
Jamie Madill09463932018-04-04 05:26:59 -0400144 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400145 }
146}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500147
148// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300149EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500150{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400151 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500152}
153
Martin Radev1be913c2016-07-11 17:59:16 +0300154EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
155{
156 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
157}
158
Geoff Langeb66a6e2016-10-31 13:06:12 -0400159gl::Version GetClientVersion(const egl::AttributeMap &attribs)
160{
161 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
162}
163
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500164GLenum GetResetStrategy(const egl::AttributeMap &attribs)
165{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800166 EGLAttrib attrib =
167 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500168 switch (attrib)
169 {
170 case EGL_NO_RESET_NOTIFICATION:
171 return GL_NO_RESET_NOTIFICATION_EXT;
172 case EGL_LOSE_CONTEXT_ON_RESET:
173 return GL_LOSE_CONTEXT_ON_RESET_EXT;
174 default:
175 UNREACHABLE();
176 return GL_NONE;
177 }
178}
179
180bool GetRobustAccess(const egl::AttributeMap &attribs)
181{
Geoff Lang077f20a2016-11-01 10:08:02 -0400182 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
183 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
184 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500185}
186
187bool GetDebug(const egl::AttributeMap &attribs)
188{
Geoff Lang077f20a2016-11-01 10:08:02 -0400189 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
190 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500191}
192
193bool GetNoError(const egl::AttributeMap &attribs)
194{
195 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
196}
197
Geoff Langc287ea62016-09-16 14:46:51 -0400198bool GetWebGLContext(const egl::AttributeMap &attribs)
199{
200 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
201}
202
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400203bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
204{
205 // If the context is WebGL, extensions are disabled by default
206 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
207 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
208}
209
Geoff Langf41a7152016-09-19 15:11:17 -0400210bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
211{
212 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
213}
214
Geoff Langfeb8c682017-02-13 16:07:35 -0500215bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
216{
217 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
218}
219
Geoff Langb433e872017-10-05 14:01:47 -0400220bool GetRobustResourceInit(const egl::AttributeMap &attribs)
221{
222 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
223}
224
Martin Radev9d901792016-07-15 15:58:58 +0300225std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
226{
227 std::string labelName;
228 if (label != nullptr)
229 {
230 size_t labelLength = length < 0 ? strlen(label) : length;
231 labelName = std::string(label, labelLength);
232 }
233 return labelName;
234}
235
236void GetObjectLabelBase(const std::string &objectLabel,
237 GLsizei bufSize,
238 GLsizei *length,
239 GLchar *label)
240{
241 size_t writeLength = objectLabel.length();
242 if (label != nullptr && bufSize > 0)
243 {
244 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
245 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
246 label[writeLength] = '\0';
247 }
248
249 if (length != nullptr)
250 {
251 *length = static_cast<GLsizei>(writeLength);
252 }
253}
254
Jamie Madill0f80ed82017-09-19 00:24:56 -0400255template <typename CapT, typename MaxT>
256void LimitCap(CapT *cap, MaxT maximum)
257{
258 *cap = std::min(*cap, static_cast<CapT>(maximum));
259}
260
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600261constexpr angle::PackedEnumMap<gl::PrimitiveMode, GLsizei> kMinimumPrimitiveCounts = {{
262 /* Points */ 1,
263 /* Lines */ 2,
264 /* LineLoop */ 2,
265 /* LineStrip */ 2,
266 /* Triangles */ 3,
267 /* TriangleStrip */ 3,
268 /* TriangleFan */ 3,
269 /* LinesAdjacency */ 2,
270 /* LineStripAdjacency */ 2,
271 /* TrianglesAdjacency */ 3,
272 /* TriangleStripAdjacency */ 3,
273}};
274// Indices above are code-gen'd so make sure they don't change
275// if any of these static asserts are hit, must update kMinimumPrimitiveCounts abouve
276static_assert(static_cast<gl::PrimitiveMode>(0) == gl::PrimitiveMode::Points,
277 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
278static_assert(static_cast<gl::PrimitiveMode>(1) == gl::PrimitiveMode::Lines,
279 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
280static_assert(static_cast<gl::PrimitiveMode>(2) == gl::PrimitiveMode::LineLoop,
281 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
282static_assert(static_cast<gl::PrimitiveMode>(3) == gl::PrimitiveMode::LineStrip,
283 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
284static_assert(static_cast<gl::PrimitiveMode>(4) == gl::PrimitiveMode::Triangles,
285 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
286static_assert(static_cast<gl::PrimitiveMode>(5) == gl::PrimitiveMode::TriangleStrip,
287 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
288static_assert(static_cast<gl::PrimitiveMode>(6) == gl::PrimitiveMode::TriangleFan,
289 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
290static_assert(static_cast<gl::PrimitiveMode>(7) == gl::PrimitiveMode::LinesAdjacency,
291 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
292static_assert(static_cast<gl::PrimitiveMode>(8) == gl::PrimitiveMode::LineStripAdjacency,
293 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
294static_assert(static_cast<gl::PrimitiveMode>(9) == gl::PrimitiveMode::TrianglesAdjacency,
295 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
296static_assert(static_cast<gl::PrimitiveMode>(10) == gl::PrimitiveMode::TriangleStripAdjacency,
297 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
298static_assert(static_cast<gl::PrimitiveMode>(11) == gl::PrimitiveMode::EnumCount,
299 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
300
Jamie Madill6c43a012018-08-08 15:49:27 -0400301constexpr angle::SubjectIndex kVertexArraySubjectIndex = gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES + 0;
302constexpr angle::SubjectIndex kReadFramebufferSubjectIndex =
303 gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES + 1;
304constexpr angle::SubjectIndex kDrawFramebufferSubjectIndex =
305 gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES + 2;
Geoff Langf6db0982015-08-25 13:04:00 -0400306} // anonymous namespace
307
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000308namespace gl
309{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000310
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400311Context::Context(rx::EGLImplFactory *implFactory,
312 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400313 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500314 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400315 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500316 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700317 const egl::DisplayExtensions &displayExtensions,
318 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500319 : mState(reinterpret_cast<ContextID>(this),
320 shareContext ? &shareContext->mState : nullptr,
321 shareTextures,
322 GetClientVersion(attribs),
323 &mGLState,
324 mCaps,
325 mTextureCaps,
326 mExtensions,
327 mLimitations),
328 mSkipValidation(GetNoError(attribs)),
329 mDisplayTextureShareGroup(shareTextures != nullptr),
330 mSavedArgsType(nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400331 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400332 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400333 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400334 mGLState(GetDebug(attribs),
335 GetBindGeneratesResource(attribs),
336 GetClientArraysEnabled(attribs),
337 GetRobustResourceInit(attribs),
338 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400339 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500340 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400341 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500342 mHasBeenCurrent(false),
343 mContextLost(false),
344 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700345 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500346 mResetStrategy(GetResetStrategy(attribs)),
347 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400348 mSurfacelessSupported(displayExtensions.surfacelessContext),
349 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400350 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
351 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500352 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400353 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400354 mMemoryProgramCache(memoryProgramCache),
Jamie Madilla11819d2018-07-30 10:26:01 -0400355 mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
356 mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
357 mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400358 mScratchBuffer(1000u),
jchen107ae70d82018-07-06 13:47:01 +0800359 mZeroFilledBuffer(1000u),
360 mThreadPool(nullptr)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000361{
Jamie Madill5b772312018-03-08 20:28:32 -0500362 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400363 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
364 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Geoff Lang33f11fb2018-05-07 13:42:47 -0400365}
Jamie Madill5b772312018-03-08 20:28:32 -0500366
Geoff Lang33f11fb2018-05-07 13:42:47 -0400367void Context::initialize()
368{
369 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400370
Geoff Lang33f11fb2018-05-07 13:42:47 -0400371 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700372 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400373
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400374 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100375
Shannon Woods53a94a82014-06-24 15:20:36 -0400376 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400377
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000378 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400379 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000380 // and cube map texture state vectors respectively associated with them.
381 // In order that access to these initial textures not be lost, they are treated as texture
382 // objects all of whose names are 0.
383
Corentin Wallez99d492c2018-02-27 15:17:10 -0500384 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800385 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500386
Corentin Wallez99d492c2018-02-27 15:17:10 -0500387 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800388 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400389
Geoff Langeb66a6e2016-10-31 13:06:12 -0400390 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400391 {
392 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500393 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800394 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400395
Corentin Wallez99d492c2018-02-27 15:17:10 -0500396 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800397 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400398 }
Geoff Lang3b573612016-10-31 14:08:10 -0400399 if (getClientVersion() >= Version(3, 1))
400 {
401 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500402 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800403 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800404
Jiajia Qin6eafb042016-12-27 17:04:07 +0800405 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
406 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800407 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800408 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800409
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800410 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
411 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400412 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800413 }
Geoff Lang3b573612016-10-31 14:08:10 -0400414 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000415
Geoff Langb0f917f2017-12-05 13:41:54 -0500416 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400417 {
418 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500419 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800420 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400421 }
422
Geoff Langb0f917f2017-12-05 13:41:54 -0500423 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400424 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500425 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800426 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400427 }
428
Jamie Madill4928b7c2017-06-20 12:57:39 -0400429 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500430
Jamie Madill57a89722013-07-02 11:57:03 -0400431 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000432
Geoff Langeb66a6e2016-10-31 13:06:12 -0400433 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400434 {
435 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
436 // In the initial state, a default transform feedback object is bound and treated as
437 // a transform feedback object with a name of zero. That object is bound any time
438 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400439 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400440 }
Geoff Langc8058452014-02-03 12:04:11 -0500441
Corentin Wallez336129f2017-10-17 15:55:40 -0400442 for (auto type : angle::AllEnums<BufferBinding>())
443 {
444 bindBuffer(type, 0);
445 }
446
447 bindRenderbuffer(GL_RENDERBUFFER, 0);
448
449 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
450 {
451 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
452 }
453
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700454 // Initialize GLES1 renderer if appropriate.
455 if (getClientVersion() < Version(2, 0))
456 {
457 mGLES1Renderer.reset(new GLES1Renderer());
458 }
459
Jamie Madillad9f24e2016-02-12 09:27:24 -0500460 // Initialize dirty bit masks
Geoff Lang9bf86f02018-07-26 11:46:34 -0400461 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
462 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
463 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400464 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400465
466 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
467 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
468 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
469
Jamie Madillc67323a2017-11-02 23:11:41 -0400470 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500471 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500472 // No dirty objects.
473
474 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400475 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500476 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400477 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500478 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
479
480 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
481 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
482 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
483 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
484 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
485 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
486 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
487 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
488 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
489 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
490 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400491 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500492 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
493
494 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
495 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700496 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400497 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
498 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500499 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
500 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400501
Xinghua Cao10a4d432017-11-28 14:46:26 +0800502 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
503 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
504 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
505 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
506 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
507 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800508 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800509 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400510 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800511
Jamie Madillb4927eb2018-07-16 11:39:46 -0400512 mImplementation->setErrorSet(&mErrors);
513
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400514 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000515}
516
Jamie Madill4928b7c2017-06-20 12:57:39 -0400517egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000518{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700519 if (mGLES1Renderer)
520 {
521 mGLES1Renderer->onDestroy(this, &mGLState);
522 }
523
Jamie Madille7b3fe22018-04-05 09:42:46 -0400524 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400525 ANGLE_TRY(releaseSurface(display));
526
Corentin Wallez80b24112015-08-25 16:41:57 -0400527 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000528 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400529 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000530 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400531 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000532
Corentin Wallez80b24112015-08-25 16:41:57 -0400533 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000534 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400535 if (query.second != nullptr)
536 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400537 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400538 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000539 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400540 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000541
Corentin Wallez80b24112015-08-25 16:41:57 -0400542 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400543 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400544 if (vertexArray.second)
545 {
546 vertexArray.second->onDestroy(this);
547 }
Jamie Madill57a89722013-07-02 11:57:03 -0400548 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400549 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400550
Corentin Wallez80b24112015-08-25 16:41:57 -0400551 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500552 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500553 if (transformFeedback.second != nullptr)
554 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500555 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500556 }
Geoff Langc8058452014-02-03 12:04:11 -0500557 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400558 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500559
Jamie Madill5b772312018-03-08 20:28:32 -0500560 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400561 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800562 if (zeroTexture.get() != nullptr)
563 {
564 ANGLE_TRY(zeroTexture->onDestroy(this));
565 zeroTexture.set(this, nullptr);
566 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400567 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000568
Jamie Madill2f348d22017-06-05 10:50:59 -0400569 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500570
Jamie Madill4928b7c2017-06-20 12:57:39 -0400571 mGLState.reset(this);
572
Jamie Madill6c1f6712017-02-14 19:08:04 -0500573 mState.mBuffers->release(this);
574 mState.mShaderPrograms->release(this);
575 mState.mTextures->release(this);
576 mState.mRenderbuffers->release(this);
577 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400578 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500579 mState.mPaths->release(this);
580 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800581 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400582
jchen107ae70d82018-07-06 13:47:01 +0800583 mThreadPool.reset();
584
Jamie Madill76e471e2017-10-21 09:56:01 -0400585 mImplementation->onDestroy(this);
586
Jamie Madill4928b7c2017-06-20 12:57:39 -0400587 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000588}
589
Jamie Madill70ee0f62017-02-06 16:04:20 -0500590Context::~Context()
591{
592}
593
Geoff Lang75359662018-04-11 01:42:27 -0400594void Context::setLabel(EGLLabelKHR label)
595{
596 mLabel = label;
597}
598
599EGLLabelKHR Context::getLabel() const
600{
601 return mLabel;
602}
603
Jamie Madill4928b7c2017-06-20 12:57:39 -0400604egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000605{
Jamie Madill61e16b42017-06-19 11:13:23 -0400606 mCurrentDisplay = display;
607
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000608 if (!mHasBeenCurrent)
609 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400610 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000611 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500612 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400613 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000614
Corentin Wallezc295e512017-01-27 17:47:50 -0500615 int width = 0;
616 int height = 0;
617 if (surface != nullptr)
618 {
619 width = surface->getWidth();
620 height = surface->getHeight();
621 }
622
623 mGLState.setViewportParams(0, 0, width, height);
624 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000625
626 mHasBeenCurrent = true;
627 }
628
Jamie Madill1b94d432015-08-07 13:23:23 -0400629 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700630 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400631 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400632
Jamie Madill4928b7c2017-06-20 12:57:39 -0400633 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500634
635 Framebuffer *newDefault = nullptr;
636 if (surface != nullptr)
637 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400638 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500639 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400640 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500641 }
642 else
643 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400644 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500645 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000646
Corentin Wallez37c39792015-08-20 14:19:46 -0400647 // Update default framebuffer, the binding of the previous default
648 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400649 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400650 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700651 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400652 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400653 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400654 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700655 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400656 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400657 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400658 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400659 }
Ian Ewell292f0052016-02-04 10:37:32 -0500660
661 // Notify the renderer of a context switch
Luc Ferron5396f2a2018-07-12 08:24:23 -0400662 ANGLE_TRY(mImplementation->onMakeCurrent(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400663 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000664}
665
Jamie Madill4928b7c2017-06-20 12:57:39 -0400666egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400667{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400668 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400669
Geoff Langbf7b95d2018-05-01 16:48:21 -0400670 // Remove the default framebuffer
671 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500672 {
673 mGLState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400674 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500675 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400676
677 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500678 {
679 mGLState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400680 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500681 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400682
683 if (defaultFramebuffer)
684 {
685 defaultFramebuffer->onDestroy(this);
686 delete defaultFramebuffer;
687 }
688
Corentin Wallezc295e512017-01-27 17:47:50 -0500689 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
690
691 if (mCurrentSurface)
692 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400693 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500694 mCurrentSurface = nullptr;
695 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400696
697 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400698}
699
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000700GLuint Context::createBuffer()
701{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500702 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000703}
704
705GLuint Context::createProgram()
706{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500707 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000708}
709
Jiawei Shao385b3e02018-03-21 09:43:28 +0800710GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000711{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500712 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000713}
714
715GLuint Context::createTexture()
716{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500717 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000718}
719
720GLuint Context::createRenderbuffer()
721{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500722 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000723}
724
Brandon Jones59770802018-04-02 13:18:42 -0700725GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300726{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500727 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300728 if (resultOrError.isError())
729 {
730 handleError(resultOrError.getError());
731 return 0;
732 }
733 return resultOrError.getResult();
734}
735
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000736// Returns an unused framebuffer name
737GLuint Context::createFramebuffer()
738{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500739 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000740}
741
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500742void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000743{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500744 for (int i = 0; i < n; i++)
745 {
746 GLuint handle = mFenceNVHandleAllocator.allocate();
747 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
748 fences[i] = handle;
749 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000750}
751
Yunchao Hea336b902017-08-02 16:05:21 +0800752GLuint Context::createProgramPipeline()
753{
754 return mState.mPipelines->createProgramPipeline();
755}
756
Jiawei Shao385b3e02018-03-21 09:43:28 +0800757GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800758{
759 UNIMPLEMENTED();
760 return 0u;
761}
762
James Darpinian4d9d4832018-03-13 12:43:28 -0700763void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000764{
James Darpinian4d9d4832018-03-13 12:43:28 -0700765 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
766 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000767 {
768 detachBuffer(buffer);
769 }
Jamie Madill893ab082014-05-16 16:56:10 -0400770
James Darpinian4d9d4832018-03-13 12:43:28 -0700771 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000772}
773
774void Context::deleteShader(GLuint shader)
775{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500776 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000777}
778
779void Context::deleteProgram(GLuint program)
780{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500781 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000782}
783
784void Context::deleteTexture(GLuint texture)
785{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500786 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000787 {
788 detachTexture(texture);
789 }
790
Jamie Madill6c1f6712017-02-14 19:08:04 -0500791 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000792}
793
794void Context::deleteRenderbuffer(GLuint renderbuffer)
795{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500796 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000797 {
798 detachRenderbuffer(renderbuffer);
799 }
Jamie Madill893ab082014-05-16 16:56:10 -0400800
Jamie Madill6c1f6712017-02-14 19:08:04 -0500801 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000802}
803
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400804void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400805{
806 // The spec specifies the underlying Fence object is not deleted until all current
807 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
808 // and since our API is currently designed for being called from a single thread, we can delete
809 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400810 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400811}
812
Yunchao Hea336b902017-08-02 16:05:21 +0800813void Context::deleteProgramPipeline(GLuint pipeline)
814{
815 if (mState.mPipelines->getProgramPipeline(pipeline))
816 {
817 detachProgramPipeline(pipeline);
818 }
819
820 mState.mPipelines->deleteObject(this, pipeline);
821}
822
Sami Väisänene45e53b2016-05-25 10:36:04 +0300823void Context::deletePaths(GLuint first, GLsizei range)
824{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500825 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300826}
827
Brandon Jones59770802018-04-02 13:18:42 -0700828bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300829{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500830 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300831 if (pathObj == nullptr)
832 return false;
833
834 return pathObj->hasPathData();
835}
836
Brandon Jones59770802018-04-02 13:18:42 -0700837bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300838{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500839 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300840}
841
Brandon Jones59770802018-04-02 13:18:42 -0700842void Context::pathCommands(GLuint path,
843 GLsizei numCommands,
844 const GLubyte *commands,
845 GLsizei numCoords,
846 GLenum coordType,
847 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300848{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500849 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300850
851 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
852}
853
Jamie Madill007530e2017-12-28 14:27:04 -0500854void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300855{
Jamie Madill007530e2017-12-28 14:27:04 -0500856 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300857
858 switch (pname)
859 {
860 case GL_PATH_STROKE_WIDTH_CHROMIUM:
861 pathObj->setStrokeWidth(value);
862 break;
863 case GL_PATH_END_CAPS_CHROMIUM:
864 pathObj->setEndCaps(static_cast<GLenum>(value));
865 break;
866 case GL_PATH_JOIN_STYLE_CHROMIUM:
867 pathObj->setJoinStyle(static_cast<GLenum>(value));
868 break;
869 case GL_PATH_MITER_LIMIT_CHROMIUM:
870 pathObj->setMiterLimit(value);
871 break;
872 case GL_PATH_STROKE_BOUND_CHROMIUM:
873 pathObj->setStrokeBound(value);
874 break;
875 default:
876 UNREACHABLE();
877 break;
878 }
879}
880
Jamie Madill007530e2017-12-28 14:27:04 -0500881void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300882{
Jamie Madill007530e2017-12-28 14:27:04 -0500883 // TODO(jmadill): Should use proper clamping/casting.
884 pathParameterf(path, pname, static_cast<GLfloat>(value));
885}
886
887void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
888{
889 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300890
891 switch (pname)
892 {
893 case GL_PATH_STROKE_WIDTH_CHROMIUM:
894 *value = pathObj->getStrokeWidth();
895 break;
896 case GL_PATH_END_CAPS_CHROMIUM:
897 *value = static_cast<GLfloat>(pathObj->getEndCaps());
898 break;
899 case GL_PATH_JOIN_STYLE_CHROMIUM:
900 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
901 break;
902 case GL_PATH_MITER_LIMIT_CHROMIUM:
903 *value = pathObj->getMiterLimit();
904 break;
905 case GL_PATH_STROKE_BOUND_CHROMIUM:
906 *value = pathObj->getStrokeBound();
907 break;
908 default:
909 UNREACHABLE();
910 break;
911 }
912}
913
Jamie Madill007530e2017-12-28 14:27:04 -0500914void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
915{
916 GLfloat val = 0.0f;
917 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
918 if (value)
919 *value = static_cast<GLint>(val);
920}
921
Brandon Jones59770802018-04-02 13:18:42 -0700922void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300923{
924 mGLState.setPathStencilFunc(func, ref, mask);
925}
926
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000927void Context::deleteFramebuffer(GLuint framebuffer)
928{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500929 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000930 {
931 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000932 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500933
Jamie Madill6c1f6712017-02-14 19:08:04 -0500934 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000935}
936
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500937void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000938{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500939 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000940 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500941 GLuint fence = fences[i];
942
943 FenceNV *fenceObject = nullptr;
944 if (mFenceNVMap.erase(fence, &fenceObject))
945 {
946 mFenceNVHandleAllocator.release(fence);
947 delete fenceObject;
948 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000949 }
950}
951
Geoff Lang70d0f492015-12-10 17:45:46 -0500952Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000953{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500954 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000955}
956
Jamie Madill570f7c82014-07-03 10:38:54 -0400957Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000958{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500959 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000960}
961
Geoff Lang70d0f492015-12-10 17:45:46 -0500962Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000963{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500964 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000965}
966
Jamie Madill70b5bb02017-08-28 13:32:37 -0400967Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400968{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400969 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400970}
971
Jamie Madill57a89722013-07-02 11:57:03 -0400972VertexArray *Context::getVertexArray(GLuint handle) const
973{
Jamie Madill96a483b2017-06-27 16:49:21 -0400974 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400975}
976
Jamie Madilldc356042013-07-19 16:36:57 -0400977Sampler *Context::getSampler(GLuint handle) const
978{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500979 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400980}
981
Geoff Langc8058452014-02-03 12:04:11 -0500982TransformFeedback *Context::getTransformFeedback(GLuint handle) const
983{
Jamie Madill96a483b2017-06-27 16:49:21 -0400984 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500985}
986
Yunchao Hea336b902017-08-02 16:05:21 +0800987ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
988{
989 return mState.mPipelines->getProgramPipeline(handle);
990}
991
Geoff Lang75359662018-04-11 01:42:27 -0400992gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500993{
994 switch (identifier)
995 {
996 case GL_BUFFER:
997 return getBuffer(name);
998 case GL_SHADER:
999 return getShader(name);
1000 case GL_PROGRAM:
1001 return getProgram(name);
1002 case GL_VERTEX_ARRAY:
1003 return getVertexArray(name);
1004 case GL_QUERY:
1005 return getQuery(name);
1006 case GL_TRANSFORM_FEEDBACK:
1007 return getTransformFeedback(name);
1008 case GL_SAMPLER:
1009 return getSampler(name);
1010 case GL_TEXTURE:
1011 return getTexture(name);
1012 case GL_RENDERBUFFER:
1013 return getRenderbuffer(name);
1014 case GL_FRAMEBUFFER:
1015 return getFramebuffer(name);
1016 default:
1017 UNREACHABLE();
1018 return nullptr;
1019 }
1020}
1021
Geoff Lang75359662018-04-11 01:42:27 -04001022gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001023{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001024 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001025}
1026
Martin Radev9d901792016-07-15 15:58:58 +03001027void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1028{
Geoff Lang75359662018-04-11 01:42:27 -04001029 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001030 ASSERT(object != nullptr);
1031
1032 std::string labelName = GetObjectLabelFromPointer(length, label);
1033 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001034
1035 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1036 // specified object is active until we do this.
1037 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001038}
1039
1040void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1041{
Geoff Lang75359662018-04-11 01:42:27 -04001042 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001043 ASSERT(object != nullptr);
1044
1045 std::string labelName = GetObjectLabelFromPointer(length, label);
1046 object->setLabel(labelName);
1047}
1048
1049void Context::getObjectLabel(GLenum identifier,
1050 GLuint name,
1051 GLsizei bufSize,
1052 GLsizei *length,
1053 GLchar *label) const
1054{
Geoff Lang75359662018-04-11 01:42:27 -04001055 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001056 ASSERT(object != nullptr);
1057
1058 const std::string &objectLabel = object->getLabel();
1059 GetObjectLabelBase(objectLabel, bufSize, length, label);
1060}
1061
1062void Context::getObjectPtrLabel(const void *ptr,
1063 GLsizei bufSize,
1064 GLsizei *length,
1065 GLchar *label) const
1066{
Geoff Lang75359662018-04-11 01:42:27 -04001067 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001068 ASSERT(object != nullptr);
1069
1070 const std::string &objectLabel = object->getLabel();
1071 GetObjectLabelBase(objectLabel, bufSize, length, label);
1072}
1073
Jamie Madilldc356042013-07-19 16:36:57 -04001074bool Context::isSampler(GLuint samplerName) const
1075{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001076 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001077}
1078
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001079void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001080{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001081 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001082
Jamie Madilldedd7b92014-11-05 16:30:36 -05001083 if (handle == 0)
1084 {
1085 texture = mZeroTextures[target].get();
1086 }
1087 else
1088 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001089 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001090 }
1091
1092 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001093 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001094}
1095
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001096void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001097{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001098 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1099 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001100 mGLState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001101 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001102}
1103
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001104void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001105{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001106 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1107 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001108 mGLState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001109 mDrawFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001110}
1111
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001112void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001113{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001114 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001115 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001116 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001117 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001118}
1119
Shao80957d92017-02-20 21:25:59 +08001120void Context::bindVertexBuffer(GLuint bindingIndex,
1121 GLuint bufferHandle,
1122 GLintptr offset,
1123 GLsizei stride)
1124{
1125 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001126 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001127 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001128}
1129
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001130void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001131{
Geoff Lang76b10c92014-09-05 16:28:14 -04001132 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001133 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001134 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001135 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001136}
1137
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001138void Context::bindImageTexture(GLuint unit,
1139 GLuint texture,
1140 GLint level,
1141 GLboolean layered,
1142 GLint layer,
1143 GLenum access,
1144 GLenum format)
1145{
1146 Texture *tex = mState.mTextures->getTexture(texture);
1147 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1148}
1149
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001150void Context::useProgram(GLuint program)
1151{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001152 mGLState.setProgram(this, getProgram(program));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001153 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001154}
1155
Jiajia Qin5451d532017-11-16 17:16:34 +08001156void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1157{
1158 UNIMPLEMENTED();
1159}
1160
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001161void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001162{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001163 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001164 TransformFeedback *transformFeedback =
1165 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001166 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001167}
1168
Yunchao Hea336b902017-08-02 16:05:21 +08001169void Context::bindProgramPipeline(GLuint pipelineHandle)
1170{
1171 ProgramPipeline *pipeline =
1172 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1173 mGLState.setProgramPipelineBinding(this, pipeline);
1174}
1175
Corentin Wallezad3ae902018-03-09 13:40:42 -05001176void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001177{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001178 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001179 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001180
Geoff Lang5aad9672014-09-08 11:10:42 -04001181 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001182 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001183
1184 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001185 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001186}
1187
Corentin Wallezad3ae902018-03-09 13:40:42 -05001188void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001189{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001190 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001191 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001192
Jamie Madill5188a272018-07-25 10:53:56 -04001193 handleError(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001194
Geoff Lang5aad9672014-09-08 11:10:42 -04001195 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001196 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001197}
1198
Corentin Wallezad3ae902018-03-09 13:40:42 -05001199void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001200{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001201 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001202
1203 Query *queryObject = getQuery(id, true, target);
1204 ASSERT(queryObject);
1205
Jamie Madill5188a272018-07-25 10:53:56 -04001206 handleError(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001207}
1208
Corentin Wallezad3ae902018-03-09 13:40:42 -05001209void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001210{
1211 switch (pname)
1212 {
1213 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001214 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001215 break;
1216 case GL_QUERY_COUNTER_BITS_EXT:
1217 switch (target)
1218 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001219 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001220 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1221 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001222 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001223 params[0] = getExtensions().queryCounterBitsTimestamp;
1224 break;
1225 default:
1226 UNREACHABLE();
1227 params[0] = 0;
1228 break;
1229 }
1230 break;
1231 default:
1232 UNREACHABLE();
1233 return;
1234 }
1235}
1236
Corentin Wallezad3ae902018-03-09 13:40:42 -05001237void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001238 GLenum pname,
1239 GLsizei bufSize,
1240 GLsizei *length,
1241 GLint *params)
1242{
1243 getQueryiv(target, pname, params);
1244}
1245
Geoff Lang2186c382016-10-14 10:54:54 -04001246void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001247{
Jamie Madill5188a272018-07-25 10:53:56 -04001248 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001249}
1250
Brandon Jones59770802018-04-02 13:18:42 -07001251void Context::getQueryObjectivRobust(GLuint id,
1252 GLenum pname,
1253 GLsizei bufSize,
1254 GLsizei *length,
1255 GLint *params)
1256{
1257 getQueryObjectiv(id, pname, params);
1258}
1259
Geoff Lang2186c382016-10-14 10:54:54 -04001260void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001261{
Jamie Madill5188a272018-07-25 10:53:56 -04001262 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001263}
1264
Brandon Jones59770802018-04-02 13:18:42 -07001265void Context::getQueryObjectuivRobust(GLuint id,
1266 GLenum pname,
1267 GLsizei bufSize,
1268 GLsizei *length,
1269 GLuint *params)
1270{
1271 getQueryObjectuiv(id, pname, params);
1272}
1273
Geoff Lang2186c382016-10-14 10:54:54 -04001274void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001275{
Jamie Madill5188a272018-07-25 10:53:56 -04001276 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001277}
1278
Brandon Jones59770802018-04-02 13:18:42 -07001279void Context::getQueryObjecti64vRobust(GLuint id,
1280 GLenum pname,
1281 GLsizei bufSize,
1282 GLsizei *length,
1283 GLint64 *params)
1284{
1285 getQueryObjecti64v(id, pname, params);
1286}
1287
Geoff Lang2186c382016-10-14 10:54:54 -04001288void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001289{
Jamie Madill5188a272018-07-25 10:53:56 -04001290 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001291}
1292
Brandon Jones59770802018-04-02 13:18:42 -07001293void Context::getQueryObjectui64vRobust(GLuint id,
1294 GLenum pname,
1295 GLsizei bufSize,
1296 GLsizei *length,
1297 GLuint64 *params)
1298{
1299 getQueryObjectui64v(id, pname, params);
1300}
1301
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001302Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001303{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001304 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001305}
1306
Jamie Madill2f348d22017-06-05 10:50:59 -04001307FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001308{
Jamie Madill96a483b2017-06-27 16:49:21 -04001309 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001310}
1311
Corentin Wallezad3ae902018-03-09 13:40:42 -05001312Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001313{
Jamie Madill96a483b2017-06-27 16:49:21 -04001314 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001315 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001316 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001317 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001318
1319 Query *query = mQueryMap.query(handle);
1320 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001321 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001322 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001323 query = new Query(mImplementation->createQuery(type), handle);
1324 query->addRef();
1325 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001326 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001327 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001328}
1329
Geoff Lang70d0f492015-12-10 17:45:46 -05001330Query *Context::getQuery(GLuint handle) const
1331{
Jamie Madill96a483b2017-06-27 16:49:21 -04001332 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001333}
1334
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001335Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001336{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001337 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1338 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001339}
1340
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001341Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001342{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001343 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001344}
1345
Geoff Lang492a7e42014-11-05 13:27:06 -05001346Compiler *Context::getCompiler() const
1347{
Jamie Madill2f348d22017-06-05 10:50:59 -04001348 if (mCompiler.get() == nullptr)
1349 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001350 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001351 }
1352 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001353}
1354
Jamie Madillc1d770e2017-04-13 17:31:24 -04001355void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001356{
1357 switch (pname)
1358 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001359 case GL_SHADER_COMPILER:
1360 *params = GL_TRUE;
1361 break;
1362 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1363 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1364 break;
1365 default:
1366 mGLState.getBooleanv(pname, params);
1367 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001368 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001369}
1370
Jamie Madillc1d770e2017-04-13 17:31:24 -04001371void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001372{
Shannon Woods53a94a82014-06-24 15:20:36 -04001373 // Queries about context capabilities and maximums are answered by Context.
1374 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001375 switch (pname)
1376 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001377 case GL_ALIASED_LINE_WIDTH_RANGE:
1378 params[0] = mCaps.minAliasedLineWidth;
1379 params[1] = mCaps.maxAliasedLineWidth;
1380 break;
1381 case GL_ALIASED_POINT_SIZE_RANGE:
1382 params[0] = mCaps.minAliasedPointSize;
1383 params[1] = mCaps.maxAliasedPointSize;
1384 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001385 case GL_SMOOTH_POINT_SIZE_RANGE:
1386 params[0] = mCaps.minSmoothPointSize;
1387 params[1] = mCaps.maxSmoothPointSize;
1388 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001389 case GL_SMOOTH_LINE_WIDTH_RANGE:
1390 params[0] = mCaps.minSmoothLineWidth;
1391 params[1] = mCaps.maxSmoothLineWidth;
1392 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001393 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1394 ASSERT(mExtensions.textureFilterAnisotropic);
1395 *params = mExtensions.maxTextureAnisotropy;
1396 break;
1397 case GL_MAX_TEXTURE_LOD_BIAS:
1398 *params = mCaps.maxLODBias;
1399 break;
1400
1401 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1402 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1403 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001404 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1405 // GLES1 constants for modelview/projection matrix.
1406 if (getClientVersion() < Version(2, 0))
1407 {
1408 mGLState.getFloatv(pname, params);
1409 }
1410 else
1411 {
1412 ASSERT(mExtensions.pathRendering);
1413 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1414 memcpy(params, m, 16 * sizeof(GLfloat));
1415 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001416 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001417 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001418
Jamie Madill231c7f52017-04-26 13:45:37 -04001419 default:
1420 mGLState.getFloatv(pname, params);
1421 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001422 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001423}
1424
Jamie Madillc1d770e2017-04-13 17:31:24 -04001425void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001426{
Shannon Woods53a94a82014-06-24 15:20:36 -04001427 // Queries about context capabilities and maximums are answered by Context.
1428 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001429
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001430 switch (pname)
1431 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001432 case GL_MAX_VERTEX_ATTRIBS:
1433 *params = mCaps.maxVertexAttributes;
1434 break;
1435 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1436 *params = mCaps.maxVertexUniformVectors;
1437 break;
1438 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001439 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001440 break;
1441 case GL_MAX_VARYING_VECTORS:
1442 *params = mCaps.maxVaryingVectors;
1443 break;
1444 case GL_MAX_VARYING_COMPONENTS:
1445 *params = mCaps.maxVertexOutputComponents;
1446 break;
1447 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1448 *params = mCaps.maxCombinedTextureImageUnits;
1449 break;
1450 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001451 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001452 break;
1453 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001454 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001455 break;
1456 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1457 *params = mCaps.maxFragmentUniformVectors;
1458 break;
1459 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001460 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001461 break;
1462 case GL_MAX_RENDERBUFFER_SIZE:
1463 *params = mCaps.maxRenderbufferSize;
1464 break;
1465 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1466 *params = mCaps.maxColorAttachments;
1467 break;
1468 case GL_MAX_DRAW_BUFFERS_EXT:
1469 *params = mCaps.maxDrawBuffers;
1470 break;
1471 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1472 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1473 case GL_SUBPIXEL_BITS:
1474 *params = 4;
1475 break;
1476 case GL_MAX_TEXTURE_SIZE:
1477 *params = mCaps.max2DTextureSize;
1478 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001479 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1480 *params = mCaps.maxRectangleTextureSize;
1481 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001482 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1483 *params = mCaps.maxCubeMapTextureSize;
1484 break;
1485 case GL_MAX_3D_TEXTURE_SIZE:
1486 *params = mCaps.max3DTextureSize;
1487 break;
1488 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1489 *params = mCaps.maxArrayTextureLayers;
1490 break;
1491 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1492 *params = mCaps.uniformBufferOffsetAlignment;
1493 break;
1494 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1495 *params = mCaps.maxUniformBufferBindings;
1496 break;
1497 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001498 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001499 break;
1500 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001501 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001502 break;
1503 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1504 *params = mCaps.maxCombinedTextureImageUnits;
1505 break;
1506 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1507 *params = mCaps.maxVertexOutputComponents;
1508 break;
1509 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1510 *params = mCaps.maxFragmentInputComponents;
1511 break;
1512 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1513 *params = mCaps.minProgramTexelOffset;
1514 break;
1515 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1516 *params = mCaps.maxProgramTexelOffset;
1517 break;
1518 case GL_MAJOR_VERSION:
1519 *params = getClientVersion().major;
1520 break;
1521 case GL_MINOR_VERSION:
1522 *params = getClientVersion().minor;
1523 break;
1524 case GL_MAX_ELEMENTS_INDICES:
1525 *params = mCaps.maxElementsIndices;
1526 break;
1527 case GL_MAX_ELEMENTS_VERTICES:
1528 *params = mCaps.maxElementsVertices;
1529 break;
1530 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1531 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1532 break;
1533 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1534 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1535 break;
1536 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1537 *params = mCaps.maxTransformFeedbackSeparateComponents;
1538 break;
1539 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1540 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1541 break;
1542 case GL_MAX_SAMPLES_ANGLE:
1543 *params = mCaps.maxSamples;
1544 break;
1545 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001546 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001547 params[0] = mCaps.maxViewportWidth;
1548 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001549 }
1550 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001551 case GL_COMPRESSED_TEXTURE_FORMATS:
1552 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1553 params);
1554 break;
1555 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1556 *params = mResetStrategy;
1557 break;
1558 case GL_NUM_SHADER_BINARY_FORMATS:
1559 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1560 break;
1561 case GL_SHADER_BINARY_FORMATS:
1562 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1563 break;
1564 case GL_NUM_PROGRAM_BINARY_FORMATS:
1565 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1566 break;
1567 case GL_PROGRAM_BINARY_FORMATS:
1568 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1569 break;
1570 case GL_NUM_EXTENSIONS:
1571 *params = static_cast<GLint>(mExtensionStrings.size());
1572 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001573
Jamie Madill231c7f52017-04-26 13:45:37 -04001574 // GL_KHR_debug
1575 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1576 *params = mExtensions.maxDebugMessageLength;
1577 break;
1578 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1579 *params = mExtensions.maxDebugLoggedMessages;
1580 break;
1581 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1582 *params = mExtensions.maxDebugGroupStackDepth;
1583 break;
1584 case GL_MAX_LABEL_LENGTH:
1585 *params = mExtensions.maxLabelLength;
1586 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001587
Martin Radeve5285d22017-07-14 16:23:53 +03001588 // GL_ANGLE_multiview
1589 case GL_MAX_VIEWS_ANGLE:
1590 *params = mExtensions.maxViews;
1591 break;
1592
Jamie Madill231c7f52017-04-26 13:45:37 -04001593 // GL_EXT_disjoint_timer_query
1594 case GL_GPU_DISJOINT_EXT:
1595 *params = mImplementation->getGPUDisjoint();
1596 break;
1597 case GL_MAX_FRAMEBUFFER_WIDTH:
1598 *params = mCaps.maxFramebufferWidth;
1599 break;
1600 case GL_MAX_FRAMEBUFFER_HEIGHT:
1601 *params = mCaps.maxFramebufferHeight;
1602 break;
1603 case GL_MAX_FRAMEBUFFER_SAMPLES:
1604 *params = mCaps.maxFramebufferSamples;
1605 break;
1606 case GL_MAX_SAMPLE_MASK_WORDS:
1607 *params = mCaps.maxSampleMaskWords;
1608 break;
1609 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1610 *params = mCaps.maxColorTextureSamples;
1611 break;
1612 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1613 *params = mCaps.maxDepthTextureSamples;
1614 break;
1615 case GL_MAX_INTEGER_SAMPLES:
1616 *params = mCaps.maxIntegerSamples;
1617 break;
1618 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1619 *params = mCaps.maxVertexAttribRelativeOffset;
1620 break;
1621 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1622 *params = mCaps.maxVertexAttribBindings;
1623 break;
1624 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1625 *params = mCaps.maxVertexAttribStride;
1626 break;
1627 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001628 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001629 break;
1630 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001631 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001632 break;
1633 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001634 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001635 break;
1636 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001637 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001638 break;
1639 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001640 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001641 break;
1642 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001643 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001644 break;
1645 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001646 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001647 break;
1648 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001649 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001650 break;
1651 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1652 *params = mCaps.minProgramTextureGatherOffset;
1653 break;
1654 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1655 *params = mCaps.maxProgramTextureGatherOffset;
1656 break;
1657 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1658 *params = mCaps.maxComputeWorkGroupInvocations;
1659 break;
1660 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001661 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001662 break;
1663 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001664 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001665 break;
1666 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1667 *params = mCaps.maxComputeSharedMemorySize;
1668 break;
1669 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001670 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001671 break;
1672 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001673 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001674 break;
1675 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001676 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001677 break;
1678 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001679 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001680 break;
1681 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001682 *params =
1683 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001684 break;
1685 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001686 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001687 break;
1688 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1689 *params = mCaps.maxCombinedShaderOutputResources;
1690 break;
1691 case GL_MAX_UNIFORM_LOCATIONS:
1692 *params = mCaps.maxUniformLocations;
1693 break;
1694 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1695 *params = mCaps.maxAtomicCounterBufferBindings;
1696 break;
1697 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1698 *params = mCaps.maxAtomicCounterBufferSize;
1699 break;
1700 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1701 *params = mCaps.maxCombinedAtomicCounterBuffers;
1702 break;
1703 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1704 *params = mCaps.maxCombinedAtomicCounters;
1705 break;
1706 case GL_MAX_IMAGE_UNITS:
1707 *params = mCaps.maxImageUnits;
1708 break;
1709 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1710 *params = mCaps.maxCombinedImageUniforms;
1711 break;
1712 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1713 *params = mCaps.maxShaderStorageBufferBindings;
1714 break;
1715 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1716 *params = mCaps.maxCombinedShaderStorageBlocks;
1717 break;
1718 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1719 *params = mCaps.shaderStorageBufferOffsetAlignment;
1720 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001721
1722 // GL_EXT_geometry_shader
1723 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1724 *params = mCaps.maxFramebufferLayers;
1725 break;
1726 case GL_LAYER_PROVOKING_VERTEX_EXT:
1727 *params = mCaps.layerProvokingVertex;
1728 break;
1729 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001730 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001731 break;
1732 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001733 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001734 break;
1735 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001736 *params =
1737 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001738 break;
1739 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1740 *params = mCaps.maxGeometryInputComponents;
1741 break;
1742 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1743 *params = mCaps.maxGeometryOutputComponents;
1744 break;
1745 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1746 *params = mCaps.maxGeometryOutputVertices;
1747 break;
1748 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1749 *params = mCaps.maxGeometryTotalOutputComponents;
1750 break;
1751 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1752 *params = mCaps.maxGeometryShaderInvocations;
1753 break;
1754 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001755 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001756 break;
1757 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001758 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001759 break;
1760 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001761 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001762 break;
1763 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001764 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001765 break;
1766 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001767 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001768 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001769 // GLES1 emulation: Caps queries
1770 case GL_MAX_TEXTURE_UNITS:
1771 *params = mCaps.maxMultitextureUnits;
1772 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001773 case GL_MAX_MODELVIEW_STACK_DEPTH:
1774 *params = mCaps.maxModelviewMatrixStackDepth;
1775 break;
1776 case GL_MAX_PROJECTION_STACK_DEPTH:
1777 *params = mCaps.maxProjectionMatrixStackDepth;
1778 break;
1779 case GL_MAX_TEXTURE_STACK_DEPTH:
1780 *params = mCaps.maxTextureMatrixStackDepth;
1781 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001782 case GL_MAX_LIGHTS:
1783 *params = mCaps.maxLights;
1784 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001785 case GL_MAX_CLIP_PLANES:
1786 *params = mCaps.maxClipPlanes;
1787 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001788 // GLES1 emulation: Vertex attribute queries
1789 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1790 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1791 case GL_COLOR_ARRAY_BUFFER_BINDING:
1792 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1793 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1794 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1795 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1796 break;
1797 case GL_VERTEX_ARRAY_STRIDE:
1798 case GL_NORMAL_ARRAY_STRIDE:
1799 case GL_COLOR_ARRAY_STRIDE:
1800 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1801 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1802 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1803 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1804 break;
1805 case GL_VERTEX_ARRAY_SIZE:
1806 case GL_COLOR_ARRAY_SIZE:
1807 case GL_TEXTURE_COORD_ARRAY_SIZE:
1808 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1809 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1810 break;
1811 case GL_VERTEX_ARRAY_TYPE:
1812 case GL_COLOR_ARRAY_TYPE:
1813 case GL_NORMAL_ARRAY_TYPE:
1814 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1815 case GL_TEXTURE_COORD_ARRAY_TYPE:
1816 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1817 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1818 break;
1819
jchen1082af6202018-06-22 10:59:52 +08001820 // GL_KHR_parallel_shader_compile
1821 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1822 *params = mGLState.getMaxShaderCompilerThreads();
1823 break;
1824
Jamie Madill231c7f52017-04-26 13:45:37 -04001825 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001826 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001827 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001828 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001829}
1830
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001831void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001832{
Shannon Woods53a94a82014-06-24 15:20:36 -04001833 // Queries about context capabilities and maximums are answered by Context.
1834 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001835 switch (pname)
1836 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001837 case GL_MAX_ELEMENT_INDEX:
1838 *params = mCaps.maxElementIndex;
1839 break;
1840 case GL_MAX_UNIFORM_BLOCK_SIZE:
1841 *params = mCaps.maxUniformBlockSize;
1842 break;
1843 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001844 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001845 break;
1846 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001847 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001848 break;
1849 case GL_MAX_SERVER_WAIT_TIMEOUT:
1850 *params = mCaps.maxServerWaitTimeout;
1851 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001852
Jamie Madill231c7f52017-04-26 13:45:37 -04001853 // GL_EXT_disjoint_timer_query
1854 case GL_TIMESTAMP_EXT:
1855 *params = mImplementation->getTimestamp();
1856 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001857
Jamie Madill231c7f52017-04-26 13:45:37 -04001858 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1859 *params = mCaps.maxShaderStorageBlockSize;
1860 break;
1861 default:
1862 UNREACHABLE();
1863 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001864 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001865}
1866
Geoff Lang70d0f492015-12-10 17:45:46 -05001867void Context::getPointerv(GLenum pname, void **params) const
1868{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001869 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001870}
1871
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001872void Context::getPointervRobustANGLERobust(GLenum pname,
1873 GLsizei bufSize,
1874 GLsizei *length,
1875 void **params)
1876{
1877 UNIMPLEMENTED();
1878}
1879
Martin Radev66fb8202016-07-28 11:45:20 +03001880void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001881{
Shannon Woods53a94a82014-06-24 15:20:36 -04001882 // Queries about context capabilities and maximums are answered by Context.
1883 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001884
1885 GLenum nativeType;
1886 unsigned int numParams;
1887 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1888 ASSERT(queryStatus);
1889
1890 if (nativeType == GL_INT)
1891 {
1892 switch (target)
1893 {
1894 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1895 ASSERT(index < 3u);
1896 *data = mCaps.maxComputeWorkGroupCount[index];
1897 break;
1898 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1899 ASSERT(index < 3u);
1900 *data = mCaps.maxComputeWorkGroupSize[index];
1901 break;
1902 default:
1903 mGLState.getIntegeri_v(target, index, data);
1904 }
1905 }
1906 else
1907 {
1908 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1909 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001910}
1911
Brandon Jones59770802018-04-02 13:18:42 -07001912void Context::getIntegeri_vRobust(GLenum target,
1913 GLuint index,
1914 GLsizei bufSize,
1915 GLsizei *length,
1916 GLint *data)
1917{
1918 getIntegeri_v(target, index, data);
1919}
1920
Martin Radev66fb8202016-07-28 11:45:20 +03001921void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001922{
Shannon Woods53a94a82014-06-24 15:20:36 -04001923 // Queries about context capabilities and maximums are answered by Context.
1924 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001925
1926 GLenum nativeType;
1927 unsigned int numParams;
1928 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1929 ASSERT(queryStatus);
1930
1931 if (nativeType == GL_INT_64_ANGLEX)
1932 {
1933 mGLState.getInteger64i_v(target, index, data);
1934 }
1935 else
1936 {
1937 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1938 }
1939}
1940
Brandon Jones59770802018-04-02 13:18:42 -07001941void Context::getInteger64i_vRobust(GLenum target,
1942 GLuint index,
1943 GLsizei bufSize,
1944 GLsizei *length,
1945 GLint64 *data)
1946{
1947 getInteger64i_v(target, index, data);
1948}
1949
Martin Radev66fb8202016-07-28 11:45:20 +03001950void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1951{
1952 // Queries about context capabilities and maximums are answered by Context.
1953 // Queries about current GL state values are answered by State.
1954
1955 GLenum nativeType;
1956 unsigned int numParams;
1957 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1958 ASSERT(queryStatus);
1959
1960 if (nativeType == GL_BOOL)
1961 {
1962 mGLState.getBooleani_v(target, index, data);
1963 }
1964 else
1965 {
1966 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1967 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001968}
1969
Brandon Jones59770802018-04-02 13:18:42 -07001970void Context::getBooleani_vRobust(GLenum target,
1971 GLuint index,
1972 GLsizei bufSize,
1973 GLsizei *length,
1974 GLboolean *data)
1975{
1976 getBooleani_v(target, index, data);
1977}
1978
Corentin Wallez336129f2017-10-17 15:55:40 -04001979void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001980{
1981 Buffer *buffer = mGLState.getTargetBuffer(target);
1982 QueryBufferParameteriv(buffer, pname, params);
1983}
1984
Brandon Jones59770802018-04-02 13:18:42 -07001985void Context::getBufferParameterivRobust(BufferBinding target,
1986 GLenum pname,
1987 GLsizei bufSize,
1988 GLsizei *length,
1989 GLint *params)
1990{
1991 getBufferParameteriv(target, pname, params);
1992}
1993
He Yunchao010e4db2017-03-03 14:22:06 +08001994void Context::getFramebufferAttachmentParameteriv(GLenum target,
1995 GLenum attachment,
1996 GLenum pname,
1997 GLint *params)
1998{
1999 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002000 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002001}
2002
Brandon Jones59770802018-04-02 13:18:42 -07002003void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2004 GLenum attachment,
2005 GLenum pname,
2006 GLsizei bufSize,
2007 GLsizei *length,
2008 GLint *params)
2009{
2010 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2011}
2012
He Yunchao010e4db2017-03-03 14:22:06 +08002013void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2014{
2015 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2016 QueryRenderbufferiv(this, renderbuffer, pname, params);
2017}
2018
Brandon Jones59770802018-04-02 13:18:42 -07002019void Context::getRenderbufferParameterivRobust(GLenum target,
2020 GLenum pname,
2021 GLsizei bufSize,
2022 GLsizei *length,
2023 GLint *params)
2024{
2025 getRenderbufferParameteriv(target, pname, params);
2026}
2027
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002028void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002029{
2030 Texture *texture = getTargetTexture(target);
2031 QueryTexParameterfv(texture, pname, params);
2032}
2033
Brandon Jones59770802018-04-02 13:18:42 -07002034void Context::getTexParameterfvRobust(TextureType target,
2035 GLenum pname,
2036 GLsizei bufSize,
2037 GLsizei *length,
2038 GLfloat *params)
2039{
2040 getTexParameterfv(target, pname, params);
2041}
2042
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002043void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002044{
2045 Texture *texture = getTargetTexture(target);
2046 QueryTexParameteriv(texture, pname, params);
2047}
Jiajia Qin5451d532017-11-16 17:16:34 +08002048
Brandon Jones59770802018-04-02 13:18:42 -07002049void Context::getTexParameterivRobust(TextureType target,
2050 GLenum pname,
2051 GLsizei bufSize,
2052 GLsizei *length,
2053 GLint *params)
2054{
2055 getTexParameteriv(target, pname, params);
2056}
2057
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002058void Context::getTexParameterIivRobust(TextureType target,
2059 GLenum pname,
2060 GLsizei bufSize,
2061 GLsizei *length,
2062 GLint *params)
2063{
2064 UNIMPLEMENTED();
2065}
2066
2067void Context::getTexParameterIuivRobust(TextureType target,
2068 GLenum pname,
2069 GLsizei bufSize,
2070 GLsizei *length,
2071 GLuint *params)
2072{
2073 UNIMPLEMENTED();
2074}
2075
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002076void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002077{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002078 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002079 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002080}
2081
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002082void Context::getTexLevelParameterivRobust(TextureTarget target,
2083 GLint level,
2084 GLenum pname,
2085 GLsizei bufSize,
2086 GLsizei *length,
2087 GLint *params)
2088{
2089 UNIMPLEMENTED();
2090}
2091
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002092void Context::getTexLevelParameterfv(TextureTarget target,
2093 GLint level,
2094 GLenum pname,
2095 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002096{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002097 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002098 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002099}
2100
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002101void Context::getTexLevelParameterfvRobust(TextureTarget target,
2102 GLint level,
2103 GLenum pname,
2104 GLsizei bufSize,
2105 GLsizei *length,
2106 GLfloat *params)
2107{
2108 UNIMPLEMENTED();
2109}
2110
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002111void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002112{
2113 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002114 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002115 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002116}
2117
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002118void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002119{
2120 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002121 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002122 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002123}
2124
Brandon Jones59770802018-04-02 13:18:42 -07002125void Context::texParameterfvRobust(TextureType target,
2126 GLenum pname,
2127 GLsizei bufSize,
2128 const GLfloat *params)
2129{
2130 texParameterfv(target, pname, params);
2131}
2132
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002133void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002134{
2135 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002136 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002137 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002138}
2139
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002140void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002141{
2142 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002143 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002144 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002145}
2146
Brandon Jones59770802018-04-02 13:18:42 -07002147void Context::texParameterivRobust(TextureType target,
2148 GLenum pname,
2149 GLsizei bufSize,
2150 const GLint *params)
2151{
2152 texParameteriv(target, pname, params);
2153}
2154
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002155void Context::texParameterIivRobust(TextureType target,
2156 GLenum pname,
2157 GLsizei bufSize,
2158 const GLint *params)
2159{
2160 UNIMPLEMENTED();
2161}
2162
2163void Context::texParameterIuivRobust(TextureType target,
2164 GLenum pname,
2165 GLsizei bufSize,
2166 const GLuint *params)
2167{
2168 UNIMPLEMENTED();
2169}
2170
Jamie Madill493f9572018-05-24 19:52:15 -04002171void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002172{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002173 // No-op if count draws no primitives for given mode
2174 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002175 {
2176 return;
2177 }
2178
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002179 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002180 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002181 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002182}
2183
Jamie Madill493f9572018-05-24 19:52:15 -04002184void Context::drawArraysInstanced(PrimitiveMode mode,
2185 GLint first,
2186 GLsizei count,
2187 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002188{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002189 // No-op if count draws no primitives for given mode
2190 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002191 {
2192 return;
2193 }
2194
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002195 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002196 ANGLE_CONTEXT_TRY(
2197 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002198 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2199 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002200}
2201
Jamie Madill493f9572018-05-24 19:52:15 -04002202void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002203{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002204 // No-op if count draws no primitives for given mode
2205 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002206 {
2207 return;
2208 }
2209
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002210 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002211 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002212}
2213
Jamie Madill493f9572018-05-24 19:52:15 -04002214void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002215 GLsizei count,
2216 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002217 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002218 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002219{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002220 // No-op if count draws no primitives for given mode
2221 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002222 {
2223 return;
2224 }
2225
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002226 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002227 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002228 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002229}
2230
Jamie Madill493f9572018-05-24 19:52:15 -04002231void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002232 GLuint start,
2233 GLuint end,
2234 GLsizei count,
2235 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002236 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002237{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002238 // No-op if count draws no primitives for given mode
2239 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002240 {
2241 return;
2242 }
2243
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002244 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002245 ANGLE_CONTEXT_TRY(
2246 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002247}
2248
Jamie Madill493f9572018-05-24 19:52:15 -04002249void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002250{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002251 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002252 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002253}
2254
Jamie Madill493f9572018-05-24 19:52:15 -04002255void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002256{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002257 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002258 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002259}
2260
Jamie Madill675fe712016-12-19 13:07:54 -05002261void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002262{
Jamie Madillafa02a22017-11-23 12:57:38 -05002263 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002264}
2265
Jamie Madill675fe712016-12-19 13:07:54 -05002266void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002267{
Jamie Madillafa02a22017-11-23 12:57:38 -05002268 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002269}
2270
Austin Kinross6ee1e782015-05-29 17:05:37 -07002271void Context::insertEventMarker(GLsizei length, const char *marker)
2272{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002273 ASSERT(mImplementation);
2274 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002275}
2276
2277void Context::pushGroupMarker(GLsizei length, const char *marker)
2278{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002279 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002280
2281 if (marker == nullptr)
2282 {
2283 // From the EXT_debug_marker spec,
2284 // "If <marker> is null then an empty string is pushed on the stack."
2285 mImplementation->pushGroupMarker(length, "");
2286 }
2287 else
2288 {
2289 mImplementation->pushGroupMarker(length, marker);
2290 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002291}
2292
2293void Context::popGroupMarker()
2294{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002295 ASSERT(mImplementation);
2296 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002297}
2298
Geoff Langd8605522016-04-13 10:19:12 -04002299void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2300{
2301 Program *programObject = getProgram(program);
2302 ASSERT(programObject);
2303
2304 programObject->bindUniformLocation(location, name);
2305}
2306
Brandon Jones59770802018-04-02 13:18:42 -07002307void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002308{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002309 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002310}
2311
Brandon Jones59770802018-04-02 13:18:42 -07002312void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002313{
2314 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2315}
2316
Brandon Jones59770802018-04-02 13:18:42 -07002317void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002318{
2319 GLfloat I[16];
2320 angle::Matrix<GLfloat>::setToIdentity(I);
2321
2322 mGLState.loadPathRenderingMatrix(matrixMode, I);
2323}
2324
2325void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2326{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002327 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002328 if (!pathObj)
2329 return;
2330
Geoff Lang9bf86f02018-07-26 11:46:34 -04002331 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002332
2333 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2334}
2335
2336void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2337{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002338 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002339 if (!pathObj)
2340 return;
2341
Geoff Lang9bf86f02018-07-26 11:46:34 -04002342 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002343
2344 mImplementation->stencilStrokePath(pathObj, reference, mask);
2345}
2346
2347void Context::coverFillPath(GLuint path, GLenum coverMode)
2348{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002349 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002350 if (!pathObj)
2351 return;
2352
Geoff Lang9bf86f02018-07-26 11:46:34 -04002353 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002354
2355 mImplementation->coverFillPath(pathObj, coverMode);
2356}
2357
2358void Context::coverStrokePath(GLuint path, GLenum coverMode)
2359{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002360 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002361 if (!pathObj)
2362 return;
2363
Geoff Lang9bf86f02018-07-26 11:46:34 -04002364 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002365
2366 mImplementation->coverStrokePath(pathObj, coverMode);
2367}
2368
2369void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2370{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002371 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002372 if (!pathObj)
2373 return;
2374
Geoff Lang9bf86f02018-07-26 11:46:34 -04002375 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002376
2377 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2378}
2379
2380void Context::stencilThenCoverStrokePath(GLuint path,
2381 GLint reference,
2382 GLuint mask,
2383 GLenum coverMode)
2384{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002385 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002386 if (!pathObj)
2387 return;
2388
Geoff Lang9bf86f02018-07-26 11:46:34 -04002389 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002390
2391 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2392}
2393
Sami Väisänend59ca052016-06-21 16:10:00 +03002394void Context::coverFillPathInstanced(GLsizei numPaths,
2395 GLenum pathNameType,
2396 const void *paths,
2397 GLuint pathBase,
2398 GLenum coverMode,
2399 GLenum transformType,
2400 const GLfloat *transformValues)
2401{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002402 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002403
Geoff Lang9bf86f02018-07-26 11:46:34 -04002404 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002405
2406 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2407}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002408
Sami Väisänend59ca052016-06-21 16:10:00 +03002409void Context::coverStrokePathInstanced(GLsizei numPaths,
2410 GLenum pathNameType,
2411 const void *paths,
2412 GLuint pathBase,
2413 GLenum coverMode,
2414 GLenum transformType,
2415 const GLfloat *transformValues)
2416{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002417 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002418
2419 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002420 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002421
2422 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2423 transformValues);
2424}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002425
Sami Väisänend59ca052016-06-21 16:10:00 +03002426void Context::stencilFillPathInstanced(GLsizei numPaths,
2427 GLenum pathNameType,
2428 const void *paths,
2429 GLuint pathBase,
2430 GLenum fillMode,
2431 GLuint mask,
2432 GLenum transformType,
2433 const GLfloat *transformValues)
2434{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002435 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002436
2437 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002438 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002439
2440 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2441 transformValues);
2442}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002443
Sami Väisänend59ca052016-06-21 16:10:00 +03002444void Context::stencilStrokePathInstanced(GLsizei numPaths,
2445 GLenum pathNameType,
2446 const void *paths,
2447 GLuint pathBase,
2448 GLint reference,
2449 GLuint mask,
2450 GLenum transformType,
2451 const GLfloat *transformValues)
2452{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002453 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002454
Geoff Lang9bf86f02018-07-26 11:46:34 -04002455 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002456
2457 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2458 transformValues);
2459}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002460
Sami Väisänend59ca052016-06-21 16:10:00 +03002461void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2462 GLenum pathNameType,
2463 const void *paths,
2464 GLuint pathBase,
2465 GLenum fillMode,
2466 GLuint mask,
2467 GLenum coverMode,
2468 GLenum transformType,
2469 const GLfloat *transformValues)
2470{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002471 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002472
Geoff Lang9bf86f02018-07-26 11:46:34 -04002473 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002474
2475 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2476 transformType, transformValues);
2477}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002478
Sami Väisänend59ca052016-06-21 16:10:00 +03002479void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2480 GLenum pathNameType,
2481 const void *paths,
2482 GLuint pathBase,
2483 GLint reference,
2484 GLuint mask,
2485 GLenum coverMode,
2486 GLenum transformType,
2487 const GLfloat *transformValues)
2488{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002489 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002490
Geoff Lang9bf86f02018-07-26 11:46:34 -04002491 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002492
2493 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2494 transformType, transformValues);
2495}
2496
Sami Väisänen46eaa942016-06-29 10:26:37 +03002497void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2498{
2499 auto *programObject = getProgram(program);
2500
2501 programObject->bindFragmentInputLocation(location, name);
2502}
2503
2504void Context::programPathFragmentInputGen(GLuint program,
2505 GLint location,
2506 GLenum genMode,
2507 GLint components,
2508 const GLfloat *coeffs)
2509{
2510 auto *programObject = getProgram(program);
2511
jchen103fd614d2018-08-13 12:21:58 +08002512 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002513}
2514
jchen1015015f72017-03-16 13:54:21 +08002515GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2516{
jchen10fd7c3b52017-03-21 15:36:03 +08002517 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002518 return QueryProgramResourceIndex(programObject, programInterface, name);
2519}
2520
jchen10fd7c3b52017-03-21 15:36:03 +08002521void Context::getProgramResourceName(GLuint program,
2522 GLenum programInterface,
2523 GLuint index,
2524 GLsizei bufSize,
2525 GLsizei *length,
2526 GLchar *name)
2527{
2528 const auto *programObject = getProgram(program);
2529 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2530}
2531
jchen10191381f2017-04-11 13:59:04 +08002532GLint Context::getProgramResourceLocation(GLuint program,
2533 GLenum programInterface,
2534 const GLchar *name)
2535{
2536 const auto *programObject = getProgram(program);
2537 return QueryProgramResourceLocation(programObject, programInterface, name);
2538}
2539
jchen10880683b2017-04-12 16:21:55 +08002540void Context::getProgramResourceiv(GLuint program,
2541 GLenum programInterface,
2542 GLuint index,
2543 GLsizei propCount,
2544 const GLenum *props,
2545 GLsizei bufSize,
2546 GLsizei *length,
2547 GLint *params)
2548{
2549 const auto *programObject = getProgram(program);
2550 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2551 length, params);
2552}
2553
jchen10d9cd7b72017-08-30 15:04:25 +08002554void Context::getProgramInterfaceiv(GLuint program,
2555 GLenum programInterface,
2556 GLenum pname,
2557 GLint *params)
2558{
2559 const auto *programObject = getProgram(program);
2560 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2561}
2562
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002563void Context::getProgramInterfaceivRobust(GLuint program,
2564 GLenum programInterface,
2565 GLenum pname,
2566 GLsizei bufSize,
2567 GLsizei *length,
2568 GLint *params)
2569{
2570 UNIMPLEMENTED();
2571}
2572
Jamie Madill306b6c12018-07-27 08:12:49 -04002573void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002574{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002575 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002576}
2577
2578// Get one of the recorded errors and clear its flag, if any.
2579// [OpenGL ES 2.0.24] section 2.5 page 13.
2580GLenum Context::getError()
2581{
Geoff Langda5777c2014-07-11 09:52:58 -04002582 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002583 {
Geoff Langda5777c2014-07-11 09:52:58 -04002584 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002585 }
Geoff Langda5777c2014-07-11 09:52:58 -04002586 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002587 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002588 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002589 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002590}
2591
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002592// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002593void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002594{
2595 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002596 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002597 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002598 mContextLostForced = true;
2599 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002600 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002601}
2602
Jamie Madill427064d2018-04-13 16:20:34 -04002603bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002604{
2605 return mContextLost;
2606}
2607
Jamie Madillfa920eb2018-01-04 11:45:50 -05002608GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002609{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002610 // Even if the application doesn't want to know about resets, we want to know
2611 // as it will allow us to skip all the calls.
2612 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002613 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002614 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002615 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002616 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002617 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002618
2619 // EXT_robustness, section 2.6: If the reset notification behavior is
2620 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2621 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2622 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002623 }
2624
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002625 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2626 // status should be returned at least once, and GL_NO_ERROR should be returned
2627 // once the device has finished resetting.
2628 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002629 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002630 ASSERT(mResetStatus == GL_NO_ERROR);
2631 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002632
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002633 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002634 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002635 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002636 }
2637 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002638 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002639 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002640 // If markContextLost was used to mark the context lost then
2641 // assume that is not recoverable, and continue to report the
2642 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002643 mResetStatus = mImplementation->getResetStatus();
2644 }
Jamie Madill893ab082014-05-16 16:56:10 -04002645
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002646 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002647}
2648
2649bool Context::isResetNotificationEnabled()
2650{
2651 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2652}
2653
Corentin Walleze3b10e82015-05-20 11:06:25 -04002654const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002655{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002656 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002657}
2658
2659EGLenum Context::getClientType() const
2660{
2661 return mClientType;
2662}
2663
2664EGLenum Context::getRenderBuffer() const
2665{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002666 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2667 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002668 {
2669 return EGL_NONE;
2670 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002671
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002672 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002673 ASSERT(backAttachment != nullptr);
2674 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002675}
2676
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002677VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002678{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002679 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002680 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2681 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002682 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002683 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2684 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002685
Jamie Madill96a483b2017-06-27 16:49:21 -04002686 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002687 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002688
2689 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002690}
2691
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002692TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002693{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002694 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002695 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2696 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002697 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002698 transformFeedback =
2699 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002700 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002701 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002702 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002703
2704 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002705}
2706
2707bool Context::isVertexArrayGenerated(GLuint vertexArray)
2708{
Jamie Madill96a483b2017-06-27 16:49:21 -04002709 ASSERT(mVertexArrayMap.contains(0));
2710 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002711}
2712
2713bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2714{
Jamie Madill96a483b2017-06-27 16:49:21 -04002715 ASSERT(mTransformFeedbackMap.contains(0));
2716 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002717}
2718
Shannon Woods53a94a82014-06-24 15:20:36 -04002719void Context::detachTexture(GLuint texture)
2720{
2721 // Simple pass-through to State's detachTexture method, as textures do not require
2722 // allocation map management either here or in the resource manager at detach time.
2723 // Zero textures are held by the Context, and we don't attempt to request them from
2724 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002725 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002726}
2727
James Darpinian4d9d4832018-03-13 12:43:28 -07002728void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002729{
Yuly Novikov5807a532015-12-03 13:01:22 -05002730 // Simple pass-through to State's detachBuffer method, since
2731 // only buffer attachments to container objects that are bound to the current context
2732 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002733
Yuly Novikov5807a532015-12-03 13:01:22 -05002734 // [OpenGL ES 3.2] section 5.1.2 page 45:
2735 // Attachments to unbound container objects, such as
2736 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2737 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002738 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002739}
2740
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002741void Context::detachFramebuffer(GLuint framebuffer)
2742{
Shannon Woods53a94a82014-06-24 15:20:36 -04002743 // Framebuffer detachment is handled by Context, because 0 is a valid
2744 // Framebuffer object, and a pointer to it must be passed from Context
2745 // to State at binding time.
2746
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002747 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002748 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2749 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2750 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002751
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002752 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002753 {
2754 bindReadFramebuffer(0);
2755 }
2756
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002757 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002758 {
2759 bindDrawFramebuffer(0);
2760 }
2761}
2762
2763void Context::detachRenderbuffer(GLuint renderbuffer)
2764{
Jamie Madilla02315b2017-02-23 14:14:47 -05002765 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002766}
2767
Jamie Madill57a89722013-07-02 11:57:03 -04002768void Context::detachVertexArray(GLuint vertexArray)
2769{
Jamie Madill77a72f62015-04-14 11:18:32 -04002770 // Vertex array detachment is handled by Context, because 0 is a valid
2771 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002772 // binding time.
2773
Jamie Madill57a89722013-07-02 11:57:03 -04002774 // [OpenGL ES 3.0.2] section 2.10 page 43:
2775 // If a vertex array object that is currently bound is deleted, the binding
2776 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002777 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002778 {
2779 bindVertexArray(0);
2780 }
2781}
2782
Geoff Langc8058452014-02-03 12:04:11 -05002783void Context::detachTransformFeedback(GLuint transformFeedback)
2784{
Corentin Walleza2257da2016-04-19 16:43:12 -04002785 // Transform feedback detachment is handled by Context, because 0 is a valid
2786 // transform feedback, and a pointer to it must be passed from Context to State at
2787 // binding time.
2788
2789 // The OpenGL specification doesn't mention what should happen when the currently bound
2790 // transform feedback object is deleted. Since it is a container object, we treat it like
2791 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002792 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002793 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002794 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002795 }
Geoff Langc8058452014-02-03 12:04:11 -05002796}
2797
Jamie Madilldc356042013-07-19 16:36:57 -04002798void Context::detachSampler(GLuint sampler)
2799{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002800 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002801}
2802
Yunchao Hea336b902017-08-02 16:05:21 +08002803void Context::detachProgramPipeline(GLuint pipeline)
2804{
2805 mGLState.detachProgramPipeline(this, pipeline);
2806}
2807
Jamie Madill3ef140a2017-08-26 23:11:21 -04002808void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002809{
Shaodde78e82017-05-22 14:13:27 +08002810 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002811 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002812}
2813
Jamie Madille29d1672013-07-19 16:36:57 -04002814void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2815{
Geoff Langc1984ed2016-10-07 12:41:00 -04002816 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002817 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002818 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002819 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002820}
Jamie Madille29d1672013-07-19 16:36:57 -04002821
Geoff Langc1984ed2016-10-07 12:41:00 -04002822void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2823{
2824 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002825 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002826 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002827 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002828}
2829
Brandon Jones59770802018-04-02 13:18:42 -07002830void Context::samplerParameterivRobust(GLuint sampler,
2831 GLenum pname,
2832 GLsizei bufSize,
2833 const GLint *param)
2834{
2835 samplerParameteriv(sampler, pname, param);
2836}
2837
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002838void Context::samplerParameterIivRobust(GLuint sampler,
2839 GLenum pname,
2840 GLsizei bufSize,
2841 const GLint *param)
2842{
2843 UNIMPLEMENTED();
2844}
2845
2846void Context::samplerParameterIuivRobust(GLuint sampler,
2847 GLenum pname,
2848 GLsizei bufSize,
2849 const GLuint *param)
2850{
2851 UNIMPLEMENTED();
2852}
2853
Jamie Madille29d1672013-07-19 16:36:57 -04002854void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2855{
Geoff Langc1984ed2016-10-07 12:41:00 -04002856 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002857 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002858 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002859 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002860}
2861
Geoff Langc1984ed2016-10-07 12:41:00 -04002862void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002863{
Geoff Langc1984ed2016-10-07 12:41:00 -04002864 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002865 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002866 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002867 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002868}
2869
Brandon Jones59770802018-04-02 13:18:42 -07002870void Context::samplerParameterfvRobust(GLuint sampler,
2871 GLenum pname,
2872 GLsizei bufSize,
2873 const GLfloat *param)
2874{
2875 samplerParameterfv(sampler, pname, param);
2876}
2877
Geoff Langc1984ed2016-10-07 12:41:00 -04002878void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002879{
Geoff Langc1984ed2016-10-07 12:41:00 -04002880 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002881 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002882 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002883 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002884}
Jamie Madill9675b802013-07-19 16:36:59 -04002885
Brandon Jones59770802018-04-02 13:18:42 -07002886void Context::getSamplerParameterivRobust(GLuint sampler,
2887 GLenum pname,
2888 GLsizei bufSize,
2889 GLsizei *length,
2890 GLint *params)
2891{
2892 getSamplerParameteriv(sampler, pname, params);
2893}
2894
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002895void Context::getSamplerParameterIivRobust(GLuint sampler,
2896 GLenum pname,
2897 GLsizei bufSize,
2898 GLsizei *length,
2899 GLint *params)
2900{
2901 UNIMPLEMENTED();
2902}
2903
2904void Context::getSamplerParameterIuivRobust(GLuint sampler,
2905 GLenum pname,
2906 GLsizei bufSize,
2907 GLsizei *length,
2908 GLuint *params)
2909{
2910 UNIMPLEMENTED();
2911}
2912
Geoff Langc1984ed2016-10-07 12:41:00 -04002913void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2914{
2915 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002916 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002917 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002918 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002919}
2920
Brandon Jones59770802018-04-02 13:18:42 -07002921void Context::getSamplerParameterfvRobust(GLuint sampler,
2922 GLenum pname,
2923 GLsizei bufSize,
2924 GLsizei *length,
2925 GLfloat *params)
2926{
2927 getSamplerParameterfv(sampler, pname, params);
2928}
2929
Olli Etuahof0fee072016-03-30 15:11:58 +03002930void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2931{
2932 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002933 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002934}
2935
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002936void Context::initRendererString()
2937{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002938 std::ostringstream rendererString;
2939 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002940 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002941 rendererString << ")";
2942
Geoff Langcec35902014-04-16 10:52:36 -04002943 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002944}
2945
Geoff Langc339c4e2016-11-29 10:37:36 -05002946void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002947{
Geoff Langc339c4e2016-11-29 10:37:36 -05002948 const Version &clientVersion = getClientVersion();
2949
2950 std::ostringstream versionString;
2951 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2952 << ANGLE_VERSION_STRING << ")";
2953 mVersionString = MakeStaticString(versionString.str());
2954
2955 std::ostringstream shadingLanguageVersionString;
2956 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2957 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2958 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2959 << ")";
2960 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002961}
2962
Geoff Langcec35902014-04-16 10:52:36 -04002963void Context::initExtensionStrings()
2964{
Geoff Langc339c4e2016-11-29 10:37:36 -05002965 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2966 std::ostringstream combinedStringStream;
2967 std::copy(strings.begin(), strings.end(),
2968 std::ostream_iterator<const char *>(combinedStringStream, " "));
2969 return MakeStaticString(combinedStringStream.str());
2970 };
2971
2972 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002973 for (const auto &extensionString : mExtensions.getStrings())
2974 {
2975 mExtensionStrings.push_back(MakeStaticString(extensionString));
2976 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002977 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002978
Geoff Langc339c4e2016-11-29 10:37:36 -05002979 mRequestableExtensionStrings.clear();
2980 for (const auto &extensionInfo : GetExtensionInfoMap())
2981 {
2982 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002983 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002984 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002985 {
2986 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2987 }
2988 }
2989 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002990}
2991
Geoff Langc339c4e2016-11-29 10:37:36 -05002992const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002993{
Geoff Langc339c4e2016-11-29 10:37:36 -05002994 switch (name)
2995 {
2996 case GL_VENDOR:
2997 return reinterpret_cast<const GLubyte *>("Google Inc.");
2998
2999 case GL_RENDERER:
3000 return reinterpret_cast<const GLubyte *>(mRendererString);
3001
3002 case GL_VERSION:
3003 return reinterpret_cast<const GLubyte *>(mVersionString);
3004
3005 case GL_SHADING_LANGUAGE_VERSION:
3006 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3007
3008 case GL_EXTENSIONS:
3009 return reinterpret_cast<const GLubyte *>(mExtensionString);
3010
3011 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3012 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3013
3014 default:
3015 UNREACHABLE();
3016 return nullptr;
3017 }
Geoff Langcec35902014-04-16 10:52:36 -04003018}
3019
Geoff Langc339c4e2016-11-29 10:37:36 -05003020const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003021{
Geoff Langc339c4e2016-11-29 10:37:36 -05003022 switch (name)
3023 {
3024 case GL_EXTENSIONS:
3025 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3026
3027 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3028 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3029
3030 default:
3031 UNREACHABLE();
3032 return nullptr;
3033 }
Geoff Langcec35902014-04-16 10:52:36 -04003034}
3035
3036size_t Context::getExtensionStringCount() const
3037{
3038 return mExtensionStrings.size();
3039}
3040
Geoff Lang111a99e2017-10-17 10:58:41 -04003041bool Context::isExtensionRequestable(const char *name)
3042{
3043 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3044 auto extension = extensionInfos.find(name);
3045
Geoff Lang111a99e2017-10-17 10:58:41 -04003046 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003047 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003048}
3049
Geoff Langc339c4e2016-11-29 10:37:36 -05003050void Context::requestExtension(const char *name)
3051{
3052 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3053 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3054 const auto &extension = extensionInfos.at(name);
3055 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003056 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003057
3058 if (mExtensions.*(extension.ExtensionsMember))
3059 {
3060 // Extension already enabled
3061 return;
3062 }
3063
3064 mExtensions.*(extension.ExtensionsMember) = true;
3065 updateCaps();
3066 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003067
Jamie Madill2f348d22017-06-05 10:50:59 -04003068 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3069 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003070
Jamie Madill81c2e252017-09-09 23:32:46 -04003071 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3072 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003073 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003074 for (auto &zeroTexture : mZeroTextures)
3075 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003076 if (zeroTexture.get() != nullptr)
3077 {
3078 zeroTexture->signalDirty(this, InitState::Initialized);
3079 }
Geoff Lang9aded172017-04-05 11:07:56 -04003080 }
3081
Jamie Madillb983a4b2018-08-01 11:34:51 -04003082 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003083}
3084
3085size_t Context::getRequestableExtensionStringCount() const
3086{
3087 return mRequestableExtensionStrings.size();
3088}
3089
Jamie Madill493f9572018-05-24 19:52:15 -04003090void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003091{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003092 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003093 ASSERT(transformFeedback != nullptr);
3094 ASSERT(!transformFeedback->isPaused());
3095
Jamie Madill6c1f6712017-02-14 19:08:04 -05003096 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003097}
3098
3099bool Context::hasActiveTransformFeedback(GLuint program) const
3100{
3101 for (auto pair : mTransformFeedbackMap)
3102 {
3103 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3104 {
3105 return true;
3106 }
3107 }
3108 return false;
3109}
3110
Geoff Lang33f11fb2018-05-07 13:42:47 -04003111Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003112{
3113 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3114
jchen1082af6202018-06-22 10:59:52 +08003115 // Explicitly enable GL_KHR_parallel_shader_compile
3116 supportedExtensions.parallelShaderCompile = true;
3117
Geoff Langb0f917f2017-12-05 13:41:54 -05003118 if (getClientVersion() < ES_2_0)
3119 {
3120 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003121 supportedExtensions.pointSizeArray = true;
3122 supportedExtensions.textureCubeMap = true;
3123 supportedExtensions.pointSprite = true;
3124 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003125 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003126 }
3127
3128 if (getClientVersion() < ES_3_0)
3129 {
3130 // Disable ES3+ extensions
3131 supportedExtensions.colorBufferFloat = false;
3132 supportedExtensions.eglImageExternalEssl3 = false;
3133 supportedExtensions.textureNorm16 = false;
3134 supportedExtensions.multiview = false;
3135 supportedExtensions.maxViews = 1u;
3136 }
3137
3138 if (getClientVersion() < ES_3_1)
3139 {
3140 // Disable ES3.1+ extensions
3141 supportedExtensions.geometryShader = false;
3142 }
3143
3144 if (getClientVersion() > ES_2_0)
3145 {
3146 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3147 // supportedExtensions.sRGB = false;
3148 }
3149
3150 // Some extensions are always available because they are implemented in the GL layer.
3151 supportedExtensions.bindUniformLocation = true;
3152 supportedExtensions.vertexArrayObject = true;
3153 supportedExtensions.bindGeneratesResource = true;
3154 supportedExtensions.clientArrays = true;
3155 supportedExtensions.requestExtension = true;
3156
3157 // Enable the no error extension if the context was created with the flag.
3158 supportedExtensions.noError = mSkipValidation;
3159
3160 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003161 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003162
3163 // Explicitly enable GL_KHR_debug
3164 supportedExtensions.debug = true;
3165 supportedExtensions.maxDebugMessageLength = 1024;
3166 supportedExtensions.maxDebugLoggedMessages = 1024;
3167 supportedExtensions.maxDebugGroupStackDepth = 1024;
3168 supportedExtensions.maxLabelLength = 1024;
3169
3170 // Explicitly enable GL_ANGLE_robust_client_memory
3171 supportedExtensions.robustClientMemory = true;
3172
3173 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003174 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003175
3176 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3177 // supports it.
3178 supportedExtensions.robustBufferAccessBehavior =
3179 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3180
3181 // Enable the cache control query unconditionally.
3182 supportedExtensions.programCacheControl = true;
3183
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003184 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003185 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003186 {
3187 // GL_ANGLE_explicit_context_gles1
3188 supportedExtensions.explicitContextGles1 = true;
3189 // GL_ANGLE_explicit_context
3190 supportedExtensions.explicitContext = true;
3191 }
3192
Geoff Langb0f917f2017-12-05 13:41:54 -05003193 return supportedExtensions;
3194}
3195
Geoff Lang33f11fb2018-05-07 13:42:47 -04003196void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003197{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003198 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003199
Geoff Lang33f11fb2018-05-07 13:42:47 -04003200 mSupportedExtensions = generateSupportedExtensions();
3201 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003202
3203 mLimitations = mImplementation->getNativeLimitations();
3204
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003205 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3206 if (getClientVersion() < Version(2, 0))
3207 {
3208 mCaps.maxMultitextureUnits = 4;
3209 mCaps.maxClipPlanes = 6;
3210 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003211 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3212 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3213 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003214 mCaps.minSmoothPointSize = 1.0f;
3215 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003216 mCaps.minSmoothLineWidth = 1.0f;
3217 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003218 }
3219
Luc Ferronad2ae932018-06-11 15:31:17 -04003220 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003221 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003222
Luc Ferronad2ae932018-06-11 15:31:17 -04003223 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3224
Jamie Madill0f80ed82017-09-19 00:24:56 -04003225 if (getClientVersion() < ES_3_1)
3226 {
3227 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3228 }
3229 else
3230 {
3231 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3232 }
Geoff Lang301d1612014-07-09 10:34:37 -04003233
Jiawei Shao54aafe52018-04-27 14:54:57 +08003234 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3235 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003236 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3237 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3238
3239 // Limit textures as well, so we can use fast bitsets with texture bindings.
3240 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003241 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3242 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3243 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3244 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003245
Jiawei Shaodb342272017-09-27 10:21:45 +08003246 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3247
Geoff Langc287ea62016-09-16 14:46:51 -04003248 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003249 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003250 for (const auto &extensionInfo : GetExtensionInfoMap())
3251 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003252 // If the user has requested that extensions start disabled and they are requestable,
3253 // disable them.
3254 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003255 {
3256 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3257 }
3258 }
3259
3260 // Generate texture caps
3261 updateCaps();
3262}
3263
3264void Context::updateCaps()
3265{
Geoff Lang900013c2014-07-07 11:32:19 -04003266 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003267 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003268
Jamie Madill7b62cf92017-11-02 15:20:49 -04003269 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003270 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003271 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003272 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003273
Geoff Lang0d8b7242015-09-09 14:56:53 -04003274 // Update the format caps based on the client version and extensions.
3275 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3276 // ES3.
3277 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003278 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003279 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003280 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003281 formatCaps.textureAttachment =
3282 formatCaps.textureAttachment &&
3283 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3284 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3285 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003286
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003287 // OpenGL ES does not support multisampling with non-rendererable formats
3288 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003289 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003290 (getClientVersion() < ES_3_1 &&
3291 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003292 {
Geoff Langd87878e2014-09-19 15:42:59 -04003293 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003294 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003295 else
3296 {
3297 // We may have limited the max samples for some required renderbuffer formats due to
3298 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3299 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3300
3301 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3302 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3303 // exception of signed and unsigned integer formats."
3304 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3305 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3306 {
3307 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3308 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3309 }
3310
3311 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3312 if (getClientVersion() >= ES_3_1)
3313 {
3314 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3315 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3316 // the exception that the signed and unsigned integer formats are required only to
3317 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3318 // multisamples, which must be at least one."
3319 if (formatInfo.componentType == GL_INT ||
3320 formatInfo.componentType == GL_UNSIGNED_INT)
3321 {
3322 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3323 }
3324
3325 // GLES 3.1 section 19.3.1.
3326 if (formatCaps.texturable)
3327 {
3328 if (formatInfo.depthBits > 0)
3329 {
3330 mCaps.maxDepthTextureSamples =
3331 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3332 }
3333 else if (formatInfo.redBits > 0)
3334 {
3335 mCaps.maxColorTextureSamples =
3336 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3337 }
3338 }
3339 }
3340 }
Geoff Langd87878e2014-09-19 15:42:59 -04003341
3342 if (formatCaps.texturable && formatInfo.compressed)
3343 {
Geoff Langca271392017-04-05 12:30:00 -04003344 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003345 }
3346
Geoff Langca271392017-04-05 12:30:00 -04003347 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003348 }
Jamie Madill32447362017-06-28 14:53:52 -04003349
3350 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003351 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003352 {
3353 mMemoryProgramCache = nullptr;
3354 }
Corentin Walleze4477002017-12-01 14:39:58 -05003355
3356 // Compute which buffer types are allowed
3357 mValidBufferBindings.reset();
3358 mValidBufferBindings.set(BufferBinding::ElementArray);
3359 mValidBufferBindings.set(BufferBinding::Array);
3360
3361 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3362 {
3363 mValidBufferBindings.set(BufferBinding::PixelPack);
3364 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3365 }
3366
3367 if (getClientVersion() >= ES_3_0)
3368 {
3369 mValidBufferBindings.set(BufferBinding::CopyRead);
3370 mValidBufferBindings.set(BufferBinding::CopyWrite);
3371 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3372 mValidBufferBindings.set(BufferBinding::Uniform);
3373 }
3374
3375 if (getClientVersion() >= ES_3_1)
3376 {
3377 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3378 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3379 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3380 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3381 }
jchen107ae70d82018-07-06 13:47:01 +08003382
3383 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Geoff Lang493daf52014-07-03 13:38:44 -04003384}
3385
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003386void Context::initWorkarounds()
3387{
Jamie Madill761b02c2017-06-23 16:27:06 -04003388 // Apply back-end workarounds.
3389 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3390
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003391 // Lose the context upon out of memory error if the application is
3392 // expecting to watch for those events.
3393 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3394}
3395
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003396// Return true if the draw is a no-op, else return false.
3397// A no-op draw occurs if the count of vertices is less than the minimum required to
3398// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3399bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3400{
3401 return count < kMinimumPrimitiveCounts[mode];
3402}
3403
3404bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3405{
3406 return (instanceCount == 0) || noopDraw(mode, count);
3407}
3408
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003409Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003410{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003411 if (mGLES1Renderer)
3412 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003413 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003414 }
3415
Geoff Lang9bf86f02018-07-26 11:46:34 -04003416 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003417
3418 if (isRobustResourceInitEnabled())
3419 {
3420 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3421 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3422 }
3423
Geoff Langa8cb2872018-03-09 16:09:40 -05003424 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003425 return NoError();
3426}
3427
3428Error Context::prepareForClear(GLbitfield mask)
3429{
Geoff Langa8cb2872018-03-09 16:09:40 -05003430 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003431 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003432 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003433 return NoError();
3434}
3435
3436Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3437{
Geoff Langa8cb2872018-03-09 16:09:40 -05003438 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003439 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3440 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003441 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003442 return NoError();
3443}
3444
Geoff Langa8cb2872018-03-09 16:09:40 -05003445Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003446{
Geoff Langa8cb2872018-03-09 16:09:40 -05003447 ANGLE_TRY(syncDirtyObjects(objectMask));
3448 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003449 return NoError();
3450}
3451
Geoff Langa8cb2872018-03-09 16:09:40 -05003452Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003453{
3454 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003455 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003456 mGLState.clearDirtyBits();
3457 return NoError();
3458}
3459
Geoff Langa8cb2872018-03-09 16:09:40 -05003460Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003461{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003462 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003463 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003464 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003465 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003466}
Jamie Madillc29968b2016-01-20 11:17:23 -05003467
Geoff Langa8cb2872018-03-09 16:09:40 -05003468Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003469{
3470 return mGLState.syncDirtyObjects(this, objectMask);
3471}
3472
Jamie Madillc29968b2016-01-20 11:17:23 -05003473void Context::blitFramebuffer(GLint srcX0,
3474 GLint srcY0,
3475 GLint srcX1,
3476 GLint srcY1,
3477 GLint dstX0,
3478 GLint dstY0,
3479 GLint dstX1,
3480 GLint dstY1,
3481 GLbitfield mask,
3482 GLenum filter)
3483{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003484 if (mask == 0)
3485 {
3486 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3487 // buffers are copied.
3488 return;
3489 }
3490
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003491 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003492 ASSERT(drawFramebuffer);
3493
3494 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3495 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3496
Jamie Madillbc918e72018-03-08 09:47:21 -05003497 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003498
Jamie Madillc564c072017-06-01 12:45:42 -04003499 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003500}
Jamie Madillc29968b2016-01-20 11:17:23 -05003501
3502void Context::clear(GLbitfield mask)
3503{
Geoff Langd4fff502017-09-22 11:28:28 -04003504 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3505 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003506}
3507
3508void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3509{
Geoff Langd4fff502017-09-22 11:28:28 -04003510 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3511 ANGLE_CONTEXT_TRY(
3512 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003513}
3514
3515void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3516{
Geoff Langd4fff502017-09-22 11:28:28 -04003517 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3518 ANGLE_CONTEXT_TRY(
3519 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003520}
3521
3522void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3523{
Geoff Langd4fff502017-09-22 11:28:28 -04003524 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3525 ANGLE_CONTEXT_TRY(
3526 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003527}
3528
3529void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3530{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003531 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003532 ASSERT(framebufferObject);
3533
3534 // If a buffer is not present, the clear has no effect
3535 if (framebufferObject->getDepthbuffer() == nullptr &&
3536 framebufferObject->getStencilbuffer() == nullptr)
3537 {
3538 return;
3539 }
3540
Geoff Langd4fff502017-09-22 11:28:28 -04003541 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3542 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003543}
3544
3545void Context::readPixels(GLint x,
3546 GLint y,
3547 GLsizei width,
3548 GLsizei height,
3549 GLenum format,
3550 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003551 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003552{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003553 if (width == 0 || height == 0)
3554 {
3555 return;
3556 }
3557
Jamie Madillbc918e72018-03-08 09:47:21 -05003558 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003559
Jamie Madillb6664922017-07-25 12:55:04 -04003560 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3561 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003562
3563 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003564 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003565}
3566
Brandon Jones59770802018-04-02 13:18:42 -07003567void Context::readPixelsRobust(GLint x,
3568 GLint y,
3569 GLsizei width,
3570 GLsizei height,
3571 GLenum format,
3572 GLenum type,
3573 GLsizei bufSize,
3574 GLsizei *length,
3575 GLsizei *columns,
3576 GLsizei *rows,
3577 void *pixels)
3578{
3579 readPixels(x, y, width, height, format, type, pixels);
3580}
3581
3582void Context::readnPixelsRobust(GLint x,
3583 GLint y,
3584 GLsizei width,
3585 GLsizei height,
3586 GLenum format,
3587 GLenum type,
3588 GLsizei bufSize,
3589 GLsizei *length,
3590 GLsizei *columns,
3591 GLsizei *rows,
3592 void *data)
3593{
3594 readPixels(x, y, width, height, format, type, data);
3595}
3596
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003597void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003598 GLint level,
3599 GLenum internalformat,
3600 GLint x,
3601 GLint y,
3602 GLsizei width,
3603 GLsizei height,
3604 GLint border)
3605{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003606 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003607 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003608
Jamie Madillc29968b2016-01-20 11:17:23 -05003609 Rectangle sourceArea(x, y, width, height);
3610
Jamie Madill05b35b22017-10-03 09:01:44 -04003611 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003612 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003613 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003614}
3615
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003616void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003617 GLint level,
3618 GLint xoffset,
3619 GLint yoffset,
3620 GLint x,
3621 GLint y,
3622 GLsizei width,
3623 GLsizei height)
3624{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003625 if (width == 0 || height == 0)
3626 {
3627 return;
3628 }
3629
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003630 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003631 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003632
Jamie Madillc29968b2016-01-20 11:17:23 -05003633 Offset destOffset(xoffset, yoffset, 0);
3634 Rectangle sourceArea(x, y, width, height);
3635
Jamie Madill05b35b22017-10-03 09:01:44 -04003636 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003637 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003638 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003639}
3640
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003641void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003642 GLint level,
3643 GLint xoffset,
3644 GLint yoffset,
3645 GLint zoffset,
3646 GLint x,
3647 GLint y,
3648 GLsizei width,
3649 GLsizei height)
3650{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003651 if (width == 0 || height == 0)
3652 {
3653 return;
3654 }
3655
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003656 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003657 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003658
Jamie Madillc29968b2016-01-20 11:17:23 -05003659 Offset destOffset(xoffset, yoffset, zoffset);
3660 Rectangle sourceArea(x, y, width, height);
3661
Jamie Madill05b35b22017-10-03 09:01:44 -04003662 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3663 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003664 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3665 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003666}
3667
3668void Context::framebufferTexture2D(GLenum target,
3669 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003670 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003671 GLuint texture,
3672 GLint level)
3673{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003674 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003675 ASSERT(framebuffer);
3676
3677 if (texture != 0)
3678 {
3679 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003680 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003681 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003682 }
3683 else
3684 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003685 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003686 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003687
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003688 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003689}
3690
3691void Context::framebufferRenderbuffer(GLenum target,
3692 GLenum attachment,
3693 GLenum renderbuffertarget,
3694 GLuint renderbuffer)
3695{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003696 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003697 ASSERT(framebuffer);
3698
3699 if (renderbuffer != 0)
3700 {
3701 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003702
Jamie Madillcc129372018-04-12 09:13:18 -04003703 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003704 renderbufferObject);
3705 }
3706 else
3707 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003708 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003709 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003710
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003711 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003712}
3713
3714void Context::framebufferTextureLayer(GLenum target,
3715 GLenum attachment,
3716 GLuint texture,
3717 GLint level,
3718 GLint layer)
3719{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003720 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003721 ASSERT(framebuffer);
3722
3723 if (texture != 0)
3724 {
3725 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003726 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003727 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003728 }
3729 else
3730 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003731 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003732 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003733
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003734 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003735}
3736
Brandon Jones59770802018-04-02 13:18:42 -07003737void Context::framebufferTextureMultiviewLayered(GLenum target,
3738 GLenum attachment,
3739 GLuint texture,
3740 GLint level,
3741 GLint baseViewIndex,
3742 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003743{
Martin Radev82ef7742017-08-08 17:44:58 +03003744 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3745 ASSERT(framebuffer);
3746
3747 if (texture != 0)
3748 {
3749 Texture *textureObj = getTexture(texture);
3750
Martin Radev18b75ba2017-08-15 15:50:40 +03003751 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003752 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3753 numViews, baseViewIndex);
3754 }
3755 else
3756 {
3757 framebuffer->resetAttachment(this, attachment);
3758 }
3759
3760 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003761}
3762
Brandon Jones59770802018-04-02 13:18:42 -07003763void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3764 GLenum attachment,
3765 GLuint texture,
3766 GLint level,
3767 GLsizei numViews,
3768 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003769{
Martin Radev5dae57b2017-07-14 16:15:55 +03003770 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3771 ASSERT(framebuffer);
3772
3773 if (texture != 0)
3774 {
3775 Texture *textureObj = getTexture(texture);
3776
3777 ImageIndex index = ImageIndex::Make2D(level);
3778 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3779 textureObj, numViews, viewportOffsets);
3780 }
3781 else
3782 {
3783 framebuffer->resetAttachment(this, attachment);
3784 }
3785
3786 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003787}
3788
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003789void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3790{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003791 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3792 ASSERT(framebuffer);
3793
3794 if (texture != 0)
3795 {
3796 Texture *textureObj = getTexture(texture);
3797
3798 ImageIndex index = ImageIndex::MakeFromType(
3799 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3800 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3801 }
3802 else
3803 {
3804 framebuffer->resetAttachment(this, attachment);
3805 }
3806
3807 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003808}
3809
Jamie Madillc29968b2016-01-20 11:17:23 -05003810void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3811{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003812 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003813 ASSERT(framebuffer);
3814 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003815 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003816}
3817
3818void Context::readBuffer(GLenum mode)
3819{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003820 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003821 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003822 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003823}
3824
3825void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3826{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003827 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003828 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003829
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003830 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003831 ASSERT(framebuffer);
3832
3833 // The specification isn't clear what should be done when the framebuffer isn't complete.
3834 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003835 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003836}
3837
3838void Context::invalidateFramebuffer(GLenum target,
3839 GLsizei numAttachments,
3840 const GLenum *attachments)
3841{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003842 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003843 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003844
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003845 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003846 ASSERT(framebuffer);
3847
Jamie Madill427064d2018-04-13 16:20:34 -04003848 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003849 {
Jamie Madill437fa652016-05-03 15:13:24 -04003850 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003851 }
Jamie Madill437fa652016-05-03 15:13:24 -04003852
Jamie Madill4928b7c2017-06-20 12:57:39 -04003853 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003854}
3855
3856void Context::invalidateSubFramebuffer(GLenum target,
3857 GLsizei numAttachments,
3858 const GLenum *attachments,
3859 GLint x,
3860 GLint y,
3861 GLsizei width,
3862 GLsizei height)
3863{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003864 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003865 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003866
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003867 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003868 ASSERT(framebuffer);
3869
Jamie Madill427064d2018-04-13 16:20:34 -04003870 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003871 {
Jamie Madill437fa652016-05-03 15:13:24 -04003872 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003873 }
Jamie Madill437fa652016-05-03 15:13:24 -04003874
3875 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003876 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003877}
3878
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003879void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003880 GLint level,
3881 GLint internalformat,
3882 GLsizei width,
3883 GLsizei height,
3884 GLint border,
3885 GLenum format,
3886 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003887 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003888{
Jamie Madillbc918e72018-03-08 09:47:21 -05003889 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003890
3891 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003892 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003893 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003894 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003895}
3896
Brandon Jones59770802018-04-02 13:18:42 -07003897void Context::texImage2DRobust(TextureTarget target,
3898 GLint level,
3899 GLint internalformat,
3900 GLsizei width,
3901 GLsizei height,
3902 GLint border,
3903 GLenum format,
3904 GLenum type,
3905 GLsizei bufSize,
3906 const void *pixels)
3907{
3908 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3909}
3910
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003911void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003912 GLint level,
3913 GLint internalformat,
3914 GLsizei width,
3915 GLsizei height,
3916 GLsizei depth,
3917 GLint border,
3918 GLenum format,
3919 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003920 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003921{
Jamie Madillbc918e72018-03-08 09:47:21 -05003922 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003923
3924 Extents size(width, height, depth);
3925 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003926 handleError(texture->setImage(this, mGLState.getUnpackState(),
3927 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003928 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003929}
3930
Brandon Jones59770802018-04-02 13:18:42 -07003931void Context::texImage3DRobust(TextureType target,
3932 GLint level,
3933 GLint internalformat,
3934 GLsizei width,
3935 GLsizei height,
3936 GLsizei depth,
3937 GLint border,
3938 GLenum format,
3939 GLenum type,
3940 GLsizei bufSize,
3941 const void *pixels)
3942{
3943 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3944}
3945
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003946void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003947 GLint level,
3948 GLint xoffset,
3949 GLint yoffset,
3950 GLsizei width,
3951 GLsizei height,
3952 GLenum format,
3953 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003954 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003955{
3956 // Zero sized uploads are valid but no-ops
3957 if (width == 0 || height == 0)
3958 {
3959 return;
3960 }
3961
Jamie Madillbc918e72018-03-08 09:47:21 -05003962 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003963
3964 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003965 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003966 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003967 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003968}
3969
Brandon Jones59770802018-04-02 13:18:42 -07003970void Context::texSubImage2DRobust(TextureTarget target,
3971 GLint level,
3972 GLint xoffset,
3973 GLint yoffset,
3974 GLsizei width,
3975 GLsizei height,
3976 GLenum format,
3977 GLenum type,
3978 GLsizei bufSize,
3979 const void *pixels)
3980{
3981 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3982}
3983
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003984void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003985 GLint level,
3986 GLint xoffset,
3987 GLint yoffset,
3988 GLint zoffset,
3989 GLsizei width,
3990 GLsizei height,
3991 GLsizei depth,
3992 GLenum format,
3993 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003994 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003995{
3996 // Zero sized uploads are valid but no-ops
3997 if (width == 0 || height == 0 || depth == 0)
3998 {
3999 return;
4000 }
4001
Jamie Madillbc918e72018-03-08 09:47:21 -05004002 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004003
4004 Box area(xoffset, yoffset, zoffset, width, height, depth);
4005 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004006 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
4007 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004008 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004009}
4010
Brandon Jones59770802018-04-02 13:18:42 -07004011void Context::texSubImage3DRobust(TextureType target,
4012 GLint level,
4013 GLint xoffset,
4014 GLint yoffset,
4015 GLint zoffset,
4016 GLsizei width,
4017 GLsizei height,
4018 GLsizei depth,
4019 GLenum format,
4020 GLenum type,
4021 GLsizei bufSize,
4022 const void *pixels)
4023{
4024 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4025 pixels);
4026}
4027
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004028void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004029 GLint level,
4030 GLenum internalformat,
4031 GLsizei width,
4032 GLsizei height,
4033 GLint border,
4034 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004035 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004036{
Jamie Madillbc918e72018-03-08 09:47:21 -05004037 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004038
4039 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004040 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004041 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4042 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004043 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004044}
4045
Brandon Jones59770802018-04-02 13:18:42 -07004046void Context::compressedTexImage2DRobust(TextureTarget target,
4047 GLint level,
4048 GLenum internalformat,
4049 GLsizei width,
4050 GLsizei height,
4051 GLint border,
4052 GLsizei imageSize,
4053 GLsizei dataSize,
4054 const GLvoid *data)
4055{
4056 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4057}
4058
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004059void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004060 GLint level,
4061 GLenum internalformat,
4062 GLsizei width,
4063 GLsizei height,
4064 GLsizei depth,
4065 GLint border,
4066 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004067 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004068{
Jamie Madillbc918e72018-03-08 09:47:21 -05004069 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004070
4071 Extents size(width, height, depth);
4072 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004073 handleError(texture->setCompressedImage(
4074 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004075 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004076}
4077
Brandon Jones59770802018-04-02 13:18:42 -07004078void Context::compressedTexImage3DRobust(TextureType target,
4079 GLint level,
4080 GLenum internalformat,
4081 GLsizei width,
4082 GLsizei height,
4083 GLsizei depth,
4084 GLint border,
4085 GLsizei imageSize,
4086 GLsizei dataSize,
4087 const GLvoid *data)
4088{
4089 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4090 data);
4091}
4092
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004093void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004094 GLint level,
4095 GLint xoffset,
4096 GLint yoffset,
4097 GLsizei width,
4098 GLsizei height,
4099 GLenum format,
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 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004106 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004107 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4108 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004109 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004110}
4111
Brandon Jones59770802018-04-02 13:18:42 -07004112void Context::compressedTexSubImage2DRobust(TextureTarget target,
4113 GLint level,
4114 GLint xoffset,
4115 GLint yoffset,
4116 GLsizei width,
4117 GLsizei height,
4118 GLenum format,
4119 GLsizei imageSize,
4120 GLsizei dataSize,
4121 const GLvoid *data)
4122{
4123 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4124 data);
4125}
4126
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004127void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004128 GLint level,
4129 GLint xoffset,
4130 GLint yoffset,
4131 GLint zoffset,
4132 GLsizei width,
4133 GLsizei height,
4134 GLsizei depth,
4135 GLenum format,
4136 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004137 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004138{
4139 // Zero sized uploads are valid but no-ops
4140 if (width == 0 || height == 0)
4141 {
4142 return;
4143 }
4144
Jamie Madillbc918e72018-03-08 09:47:21 -05004145 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004146
4147 Box area(xoffset, yoffset, zoffset, width, height, depth);
4148 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004149 handleError(texture->setCompressedSubImage(
4150 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004151 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004152}
4153
Brandon Jones59770802018-04-02 13:18:42 -07004154void Context::compressedTexSubImage3DRobust(TextureType target,
4155 GLint level,
4156 GLint xoffset,
4157 GLint yoffset,
4158 GLint zoffset,
4159 GLsizei width,
4160 GLsizei height,
4161 GLsizei depth,
4162 GLenum format,
4163 GLsizei imageSize,
4164 GLsizei dataSize,
4165 const GLvoid *data)
4166{
4167 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4168 imageSize, data);
4169}
4170
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004171void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004172{
4173 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004174 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004175}
4176
Jamie Madill007530e2017-12-28 14:27:04 -05004177void Context::copyTexture(GLuint sourceId,
4178 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004179 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004180 GLuint destId,
4181 GLint destLevel,
4182 GLint internalFormat,
4183 GLenum destType,
4184 GLboolean unpackFlipY,
4185 GLboolean unpackPremultiplyAlpha,
4186 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004187{
Jamie Madillbc918e72018-03-08 09:47:21 -05004188 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004189
4190 gl::Texture *sourceTexture = getTexture(sourceId);
4191 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004192 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4193 sourceLevel, ConvertToBool(unpackFlipY),
4194 ConvertToBool(unpackPremultiplyAlpha),
4195 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004196}
4197
Jamie Madill007530e2017-12-28 14:27:04 -05004198void Context::copySubTexture(GLuint sourceId,
4199 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004200 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004201 GLuint destId,
4202 GLint destLevel,
4203 GLint xoffset,
4204 GLint yoffset,
4205 GLint x,
4206 GLint y,
4207 GLsizei width,
4208 GLsizei height,
4209 GLboolean unpackFlipY,
4210 GLboolean unpackPremultiplyAlpha,
4211 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004212{
4213 // Zero sized copies are valid but no-ops
4214 if (width == 0 || height == 0)
4215 {
4216 return;
4217 }
4218
Jamie Madillbc918e72018-03-08 09:47:21 -05004219 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004220
4221 gl::Texture *sourceTexture = getTexture(sourceId);
4222 gl::Texture *destTexture = getTexture(destId);
4223 Offset offset(xoffset, yoffset, 0);
4224 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004225 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4226 ConvertToBool(unpackFlipY),
4227 ConvertToBool(unpackPremultiplyAlpha),
4228 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004229}
4230
Jamie Madill007530e2017-12-28 14:27:04 -05004231void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004232{
Jamie Madillbc918e72018-03-08 09:47:21 -05004233 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004234
4235 gl::Texture *sourceTexture = getTexture(sourceId);
4236 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004237 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004238}
4239
Corentin Wallez336129f2017-10-17 15:55:40 -04004240void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004241{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004242 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004243 ASSERT(buffer);
4244
Geoff Lang496c02d2016-10-20 11:38:11 -07004245 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004246}
4247
Brandon Jones59770802018-04-02 13:18:42 -07004248void Context::getBufferPointervRobust(BufferBinding target,
4249 GLenum pname,
4250 GLsizei bufSize,
4251 GLsizei *length,
4252 void **params)
4253{
4254 getBufferPointerv(target, pname, params);
4255}
4256
Corentin Wallez336129f2017-10-17 15:55:40 -04004257void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004258{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004259 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004260 ASSERT(buffer);
4261
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004262 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004263 if (error.isError())
4264 {
Jamie Madill437fa652016-05-03 15:13:24 -04004265 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004266 return nullptr;
4267 }
4268
4269 return buffer->getMapPointer();
4270}
4271
Corentin Wallez336129f2017-10-17 15:55:40 -04004272GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004273{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004274 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004275 ASSERT(buffer);
4276
4277 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004278 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004279 if (error.isError())
4280 {
Jamie Madill437fa652016-05-03 15:13:24 -04004281 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004282 return GL_FALSE;
4283 }
4284
4285 return result;
4286}
4287
Corentin Wallez336129f2017-10-17 15:55:40 -04004288void *Context::mapBufferRange(BufferBinding target,
4289 GLintptr offset,
4290 GLsizeiptr length,
4291 GLbitfield 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->mapRange(this, offset, length, 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 -04004306void Context::flushMappedBufferRange(BufferBinding /*target*/,
4307 GLintptr /*offset*/,
4308 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004309{
4310 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4311}
4312
Jamie Madillbc918e72018-03-08 09:47:21 -05004313Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004314{
Geoff Langa8cb2872018-03-09 16:09:40 -05004315 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004316}
4317
Jamie Madillbc918e72018-03-08 09:47:21 -05004318Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004319{
Geoff Langa8cb2872018-03-09 16:09:40 -05004320 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004321}
4322
Jamie Madillbc918e72018-03-08 09:47:21 -05004323Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004324{
Geoff Langa8cb2872018-03-09 16:09:40 -05004325 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004326}
4327
Geoff Lang9bf86f02018-07-26 11:46:34 -04004328Error Context::syncStateForPathOperation()
4329{
4330 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4331
4332 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4333 ANGLE_TRY(syncDirtyBits());
4334
4335 return NoError();
4336}
4337
Jiajia Qin5451d532017-11-16 17:16:34 +08004338void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4339{
4340 UNIMPLEMENTED();
4341}
4342
Jamie Madillc20ab272016-06-09 07:20:46 -07004343void Context::activeTexture(GLenum texture)
4344{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004345 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004346}
4347
Jamie Madill876429b2017-04-20 15:46:24 -04004348void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004349{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004350 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004351}
4352
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004353void Context::blendEquation(GLenum mode)
4354{
4355 mGLState.setBlendEquation(mode, mode);
4356}
4357
Jamie Madillc20ab272016-06-09 07:20:46 -07004358void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4359{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004360 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004361}
4362
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004363void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4364{
4365 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4366}
4367
Jamie Madillc20ab272016-06-09 07:20:46 -07004368void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4369{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004370 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004371}
4372
Jamie Madill876429b2017-04-20 15:46:24 -04004373void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004374{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004375 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004376}
4377
Jamie Madill876429b2017-04-20 15:46:24 -04004378void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004379{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004380 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004381}
4382
4383void Context::clearStencil(GLint s)
4384{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004385 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004386}
4387
4388void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4389{
Geoff Lang92019432017-11-20 13:09:34 -05004390 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4391 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004392}
4393
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004394void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004395{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004396 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004397}
4398
4399void Context::depthFunc(GLenum func)
4400{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004401 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004402}
4403
4404void Context::depthMask(GLboolean flag)
4405{
Geoff Lang92019432017-11-20 13:09:34 -05004406 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004407}
4408
Jamie Madill876429b2017-04-20 15:46:24 -04004409void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004410{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004411 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004412}
4413
4414void Context::disable(GLenum cap)
4415{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004416 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004417}
4418
4419void Context::disableVertexAttribArray(GLuint index)
4420{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004421 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004422 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004423}
4424
4425void Context::enable(GLenum cap)
4426{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004427 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004428}
4429
4430void Context::enableVertexAttribArray(GLuint index)
4431{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004432 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004433 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004434}
4435
4436void Context::frontFace(GLenum mode)
4437{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004438 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004439}
4440
4441void Context::hint(GLenum target, GLenum mode)
4442{
4443 switch (target)
4444 {
4445 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004446 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004447 break;
4448
4449 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004450 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004451 break;
4452
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004453 case GL_PERSPECTIVE_CORRECTION_HINT:
4454 case GL_POINT_SMOOTH_HINT:
4455 case GL_LINE_SMOOTH_HINT:
4456 case GL_FOG_HINT:
4457 mGLState.gles1().setHint(target, mode);
4458 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004459 default:
4460 UNREACHABLE();
4461 return;
4462 }
4463}
4464
4465void Context::lineWidth(GLfloat width)
4466{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004467 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004468}
4469
4470void Context::pixelStorei(GLenum pname, GLint param)
4471{
4472 switch (pname)
4473 {
4474 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004475 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004476 break;
4477
4478 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004479 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004480 break;
4481
4482 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004483 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004484 break;
4485
4486 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004487 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004488 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004489 break;
4490
4491 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004492 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004493 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004494 break;
4495
4496 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004497 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004498 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004499 break;
4500
4501 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004502 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004503 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004504 break;
4505
4506 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004507 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004508 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004509 break;
4510
4511 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004512 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004513 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004514 break;
4515
4516 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004517 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004518 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004519 break;
4520
4521 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004522 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004523 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004524 break;
4525
4526 default:
4527 UNREACHABLE();
4528 return;
4529 }
4530}
4531
4532void Context::polygonOffset(GLfloat factor, GLfloat units)
4533{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004534 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004535}
4536
Jamie Madill876429b2017-04-20 15:46:24 -04004537void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004538{
Geoff Lang92019432017-11-20 13:09:34 -05004539 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004540}
4541
Jiawei Shaodb342272017-09-27 10:21:45 +08004542void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4543{
4544 mGLState.setSampleMaskParams(maskNumber, mask);
4545}
4546
Jamie Madillc20ab272016-06-09 07:20:46 -07004547void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4548{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004549 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004550}
4551
4552void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4553{
4554 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4555 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004556 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004557 }
4558
4559 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4560 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004561 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004562 }
4563}
4564
4565void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4566{
4567 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4568 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004569 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004570 }
4571
4572 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4573 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004574 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004575 }
4576}
4577
4578void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4579{
4580 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4581 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004582 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004583 }
4584
4585 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4586 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004587 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004588 }
4589}
4590
4591void Context::vertexAttrib1f(GLuint index, GLfloat x)
4592{
4593 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004594 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004595}
4596
4597void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4598{
4599 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004600 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004601}
4602
4603void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4604{
4605 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004606 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004607}
4608
4609void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4610{
4611 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004612 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004613}
4614
4615void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4616{
4617 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004618 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004619}
4620
4621void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4622{
4623 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004624 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004625}
4626
4627void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4628{
4629 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004630 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004631}
4632
4633void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4634{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004635 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004636}
4637
4638void Context::vertexAttribPointer(GLuint index,
4639 GLint size,
4640 GLenum type,
4641 GLboolean normalized,
4642 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004643 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004644{
Corentin Wallez336129f2017-10-17 15:55:40 -04004645 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004646 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004647 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004648}
4649
Shao80957d92017-02-20 21:25:59 +08004650void Context::vertexAttribFormat(GLuint attribIndex,
4651 GLint size,
4652 GLenum type,
4653 GLboolean normalized,
4654 GLuint relativeOffset)
4655{
Geoff Lang92019432017-11-20 13:09:34 -05004656 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004657 relativeOffset);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004658 mStateCache.onVertexArraySizeChange(this);
Shao80957d92017-02-20 21:25:59 +08004659}
4660
4661void Context::vertexAttribIFormat(GLuint attribIndex,
4662 GLint size,
4663 GLenum type,
4664 GLuint relativeOffset)
4665{
4666 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004667 mStateCache.onVertexArraySizeChange(this);
Shao80957d92017-02-20 21:25:59 +08004668}
4669
4670void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4671{
Shaodde78e82017-05-22 14:13:27 +08004672 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004673 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004674}
4675
Jiajia Qin5451d532017-11-16 17:16:34 +08004676void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004677{
4678 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004679 mStateCache.onVertexArraySizeChange(this);
Shao80957d92017-02-20 21:25:59 +08004680}
4681
Jamie Madillc20ab272016-06-09 07:20:46 -07004682void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4683{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004684 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004685}
4686
4687void Context::vertexAttribIPointer(GLuint index,
4688 GLint size,
4689 GLenum type,
4690 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004691 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004692{
Corentin Wallez336129f2017-10-17 15:55:40 -04004693 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4694 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004695 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004696}
4697
4698void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4699{
4700 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004701 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004702}
4703
4704void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4705{
4706 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004707 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004708}
4709
4710void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4711{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004712 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004713}
4714
4715void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4716{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004717 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004718}
4719
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004720void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4721{
4722 const VertexAttribCurrentValueData &currentValues =
4723 getGLState().getVertexAttribCurrentValue(index);
4724 const VertexArray *vao = getGLState().getVertexArray();
4725 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4726 currentValues, pname, params);
4727}
4728
Brandon Jones59770802018-04-02 13:18:42 -07004729void Context::getVertexAttribivRobust(GLuint index,
4730 GLenum pname,
4731 GLsizei bufSize,
4732 GLsizei *length,
4733 GLint *params)
4734{
4735 getVertexAttribiv(index, pname, params);
4736}
4737
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004738void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4739{
4740 const VertexAttribCurrentValueData &currentValues =
4741 getGLState().getVertexAttribCurrentValue(index);
4742 const VertexArray *vao = getGLState().getVertexArray();
4743 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4744 currentValues, pname, params);
4745}
4746
Brandon Jones59770802018-04-02 13:18:42 -07004747void Context::getVertexAttribfvRobust(GLuint index,
4748 GLenum pname,
4749 GLsizei bufSize,
4750 GLsizei *length,
4751 GLfloat *params)
4752{
4753 getVertexAttribfv(index, pname, params);
4754}
4755
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004756void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4757{
4758 const VertexAttribCurrentValueData &currentValues =
4759 getGLState().getVertexAttribCurrentValue(index);
4760 const VertexArray *vao = getGLState().getVertexArray();
4761 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4762 currentValues, pname, params);
4763}
4764
Brandon Jones59770802018-04-02 13:18:42 -07004765void Context::getVertexAttribIivRobust(GLuint index,
4766 GLenum pname,
4767 GLsizei bufSize,
4768 GLsizei *length,
4769 GLint *params)
4770{
4771 getVertexAttribIiv(index, pname, params);
4772}
4773
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004774void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4775{
4776 const VertexAttribCurrentValueData &currentValues =
4777 getGLState().getVertexAttribCurrentValue(index);
4778 const VertexArray *vao = getGLState().getVertexArray();
4779 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4780 currentValues, pname, params);
4781}
4782
Brandon Jones59770802018-04-02 13:18:42 -07004783void Context::getVertexAttribIuivRobust(GLuint index,
4784 GLenum pname,
4785 GLsizei bufSize,
4786 GLsizei *length,
4787 GLuint *params)
4788{
4789 getVertexAttribIuiv(index, pname, params);
4790}
4791
Jamie Madill876429b2017-04-20 15:46:24 -04004792void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004793{
4794 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4795 QueryVertexAttribPointerv(attrib, pname, pointer);
4796}
4797
Brandon Jones59770802018-04-02 13:18:42 -07004798void Context::getVertexAttribPointervRobust(GLuint index,
4799 GLenum pname,
4800 GLsizei bufSize,
4801 GLsizei *length,
4802 void **pointer)
4803{
4804 getVertexAttribPointerv(index, pname, pointer);
4805}
4806
Jamie Madillc20ab272016-06-09 07:20:46 -07004807void Context::debugMessageControl(GLenum source,
4808 GLenum type,
4809 GLenum severity,
4810 GLsizei count,
4811 const GLuint *ids,
4812 GLboolean enabled)
4813{
4814 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004815 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004816 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004817}
4818
4819void Context::debugMessageInsert(GLenum source,
4820 GLenum type,
4821 GLuint id,
4822 GLenum severity,
4823 GLsizei length,
4824 const GLchar *buf)
4825{
4826 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004827 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004828}
4829
4830void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4831{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004832 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004833}
4834
4835GLuint Context::getDebugMessageLog(GLuint count,
4836 GLsizei bufSize,
4837 GLenum *sources,
4838 GLenum *types,
4839 GLuint *ids,
4840 GLenum *severities,
4841 GLsizei *lengths,
4842 GLchar *messageLog)
4843{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004844 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4845 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004846}
4847
4848void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4849{
4850 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004851 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004852 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004853}
4854
4855void Context::popDebugGroup()
4856{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004857 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004858 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004859}
4860
Corentin Wallez336129f2017-10-17 15:55:40 -04004861void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004862{
4863 Buffer *buffer = mGLState.getTargetBuffer(target);
4864 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004865 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004866}
4867
Corentin Wallez336129f2017-10-17 15:55:40 -04004868void Context::bufferSubData(BufferBinding target,
4869 GLintptr offset,
4870 GLsizeiptr size,
4871 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004872{
4873 if (data == nullptr)
4874 {
4875 return;
4876 }
4877
4878 Buffer *buffer = mGLState.getTargetBuffer(target);
4879 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004880 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004881}
4882
Jamie Madillef300b12016-10-07 15:12:09 -04004883void Context::attachShader(GLuint program, GLuint shader)
4884{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004885 Program *programObject = mState.mShaderPrograms->getProgram(program);
4886 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004887 ASSERT(programObject && shaderObject);
4888 programObject->attachShader(shaderObject);
4889}
4890
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004891const Workarounds &Context::getWorkarounds() const
4892{
4893 return mWorkarounds;
4894}
4895
Corentin Wallez336129f2017-10-17 15:55:40 -04004896void Context::copyBufferSubData(BufferBinding readTarget,
4897 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004898 GLintptr readOffset,
4899 GLintptr writeOffset,
4900 GLsizeiptr size)
4901{
4902 // if size is zero, the copy is a successful no-op
4903 if (size == 0)
4904 {
4905 return;
4906 }
4907
4908 // TODO(jmadill): cache these.
4909 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4910 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4911
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004912 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004913}
4914
Jamie Madill01a80ee2016-11-07 12:06:18 -05004915void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4916{
4917 Program *programObject = getProgram(program);
4918 // TODO(jmadill): Re-use this from the validation if possible.
4919 ASSERT(programObject);
4920 programObject->bindAttributeLocation(index, name);
4921}
4922
Corentin Wallez336129f2017-10-17 15:55:40 -04004923void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004924{
Corentin Wallez336129f2017-10-17 15:55:40 -04004925 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4926 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004927}
4928
Corentin Wallez336129f2017-10-17 15:55:40 -04004929void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004930{
4931 bindBufferRange(target, index, buffer, 0, 0);
4932}
4933
Corentin Wallez336129f2017-10-17 15:55:40 -04004934void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004935 GLuint index,
4936 GLuint buffer,
4937 GLintptr offset,
4938 GLsizeiptr size)
4939{
Corentin Wallez336129f2017-10-17 15:55:40 -04004940 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4941 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004942}
4943
Jamie Madill01a80ee2016-11-07 12:06:18 -05004944void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4945{
4946 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4947 {
4948 bindReadFramebuffer(framebuffer);
4949 }
4950
4951 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4952 {
4953 bindDrawFramebuffer(framebuffer);
4954 }
4955}
4956
4957void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4958{
4959 ASSERT(target == GL_RENDERBUFFER);
4960 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004961 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004962 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004963}
4964
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004965void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004966 GLsizei samples,
4967 GLenum internalformat,
4968 GLsizei width,
4969 GLsizei height,
4970 GLboolean fixedsamplelocations)
4971{
4972 Extents size(width, height, 1);
4973 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004974 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4975 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004976}
4977
4978void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4979{
JiangYizhou5b03f472017-01-09 10:22:53 +08004980 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4981 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004982 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004983 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004984
4985 switch (pname)
4986 {
4987 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004988 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004989 break;
4990 default:
4991 UNREACHABLE();
4992 }
4993}
4994
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004995void Context::getMultisamplefvRobust(GLenum pname,
4996 GLuint index,
4997 GLsizei bufSize,
4998 GLsizei *length,
4999 GLfloat *val)
5000{
5001 UNIMPLEMENTED();
5002}
5003
Jamie Madille8fb6402017-02-14 17:56:40 -05005004void Context::renderbufferStorage(GLenum target,
5005 GLenum internalformat,
5006 GLsizei width,
5007 GLsizei height)
5008{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005009 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5010 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5011
Jamie Madille8fb6402017-02-14 17:56:40 -05005012 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04005013 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005014}
5015
5016void Context::renderbufferStorageMultisample(GLenum target,
5017 GLsizei samples,
5018 GLenum internalformat,
5019 GLsizei width,
5020 GLsizei height)
5021{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005022 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5023 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005024
5025 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005026 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005027 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005028}
5029
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005030void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5031{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005032 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04005033 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005034}
5035
JiangYizhoue18e6392017-02-20 10:32:23 +08005036void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5037{
5038 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5039 QueryFramebufferParameteriv(framebuffer, pname, params);
5040}
5041
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005042void Context::getFramebufferParameterivRobust(GLenum target,
5043 GLenum pname,
5044 GLsizei bufSize,
5045 GLsizei *length,
5046 GLint *params)
5047{
5048 UNIMPLEMENTED();
5049}
5050
Jiajia Qin5451d532017-11-16 17:16:34 +08005051void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005052{
5053 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005054 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005055}
5056
Jamie Madilldec86232018-07-11 09:01:18 -04005057bool Context::getScratchBuffer(size_t requstedSizeBytes,
5058 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005059{
Jamie Madilldec86232018-07-11 09:01:18 -04005060 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005061}
5062
Jamie Madilldec86232018-07-11 09:01:18 -04005063bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5064 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005065{
Jamie Madilldec86232018-07-11 09:01:18 -04005066 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005067}
5068
Xinghua Cao10a4d432017-11-28 14:46:26 +08005069Error Context::prepareForDispatch()
5070{
Geoff Langa8cb2872018-03-09 16:09:40 -05005071 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005072
5073 if (isRobustResourceInitEnabled())
5074 {
5075 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5076 }
5077
5078 return NoError();
5079}
5080
Xinghua Cao2b396592017-03-29 15:36:04 +08005081void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5082{
5083 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5084 {
5085 return;
5086 }
5087
Xinghua Cao10a4d432017-11-28 14:46:26 +08005088 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005089 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005090}
5091
Jiajia Qin5451d532017-11-16 17:16:34 +08005092void Context::dispatchComputeIndirect(GLintptr indirect)
5093{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005094 ANGLE_CONTEXT_TRY(prepareForDispatch());
5095 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005096}
5097
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005098void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005099 GLsizei levels,
5100 GLenum internalFormat,
5101 GLsizei width,
5102 GLsizei height)
5103{
5104 Extents size(width, height, 1);
5105 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005106 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005107}
5108
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005109void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005110 GLsizei levels,
5111 GLenum internalFormat,
5112 GLsizei width,
5113 GLsizei height,
5114 GLsizei depth)
5115{
5116 Extents size(width, height, depth);
5117 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005118 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005119}
5120
Jiajia Qin5451d532017-11-16 17:16:34 +08005121void Context::memoryBarrier(GLbitfield barriers)
5122{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005123 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005124}
5125
5126void Context::memoryBarrierByRegion(GLbitfield barriers)
5127{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005128 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005129}
5130
Jamie Madillc1d770e2017-04-13 17:31:24 -04005131GLenum Context::checkFramebufferStatus(GLenum target)
5132{
5133 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5134 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005135 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005136}
5137
5138void Context::compileShader(GLuint shader)
5139{
5140 Shader *shaderObject = GetValidShader(this, shader);
5141 if (!shaderObject)
5142 {
5143 return;
5144 }
5145 shaderObject->compile(this);
5146}
5147
5148void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5149{
5150 for (int i = 0; i < n; i++)
5151 {
5152 deleteBuffer(buffers[i]);
5153 }
5154}
5155
5156void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5157{
5158 for (int i = 0; i < n; i++)
5159 {
5160 if (framebuffers[i] != 0)
5161 {
5162 deleteFramebuffer(framebuffers[i]);
5163 }
5164 }
5165}
5166
5167void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5168{
5169 for (int i = 0; i < n; i++)
5170 {
5171 deleteRenderbuffer(renderbuffers[i]);
5172 }
5173}
5174
5175void Context::deleteTextures(GLsizei n, const GLuint *textures)
5176{
5177 for (int i = 0; i < n; i++)
5178 {
5179 if (textures[i] != 0)
5180 {
5181 deleteTexture(textures[i]);
5182 }
5183 }
5184}
5185
5186void Context::detachShader(GLuint program, GLuint shader)
5187{
5188 Program *programObject = getProgram(program);
5189 ASSERT(programObject);
5190
5191 Shader *shaderObject = getShader(shader);
5192 ASSERT(shaderObject);
5193
5194 programObject->detachShader(this, shaderObject);
5195}
5196
5197void Context::genBuffers(GLsizei n, GLuint *buffers)
5198{
5199 for (int i = 0; i < n; i++)
5200 {
5201 buffers[i] = createBuffer();
5202 }
5203}
5204
5205void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5206{
5207 for (int i = 0; i < n; i++)
5208 {
5209 framebuffers[i] = createFramebuffer();
5210 }
5211}
5212
5213void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5214{
5215 for (int i = 0; i < n; i++)
5216 {
5217 renderbuffers[i] = createRenderbuffer();
5218 }
5219}
5220
5221void Context::genTextures(GLsizei n, GLuint *textures)
5222{
5223 for (int i = 0; i < n; i++)
5224 {
5225 textures[i] = createTexture();
5226 }
5227}
5228
5229void Context::getActiveAttrib(GLuint program,
5230 GLuint index,
5231 GLsizei bufsize,
5232 GLsizei *length,
5233 GLint *size,
5234 GLenum *type,
5235 GLchar *name)
5236{
5237 Program *programObject = getProgram(program);
5238 ASSERT(programObject);
5239 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5240}
5241
5242void Context::getActiveUniform(GLuint program,
5243 GLuint index,
5244 GLsizei bufsize,
5245 GLsizei *length,
5246 GLint *size,
5247 GLenum *type,
5248 GLchar *name)
5249{
5250 Program *programObject = getProgram(program);
5251 ASSERT(programObject);
5252 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5253}
5254
5255void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5256{
5257 Program *programObject = getProgram(program);
5258 ASSERT(programObject);
5259 programObject->getAttachedShaders(maxcount, count, shaders);
5260}
5261
5262GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5263{
5264 Program *programObject = getProgram(program);
5265 ASSERT(programObject);
5266 return programObject->getAttributeLocation(name);
5267}
5268
5269void Context::getBooleanv(GLenum pname, GLboolean *params)
5270{
5271 GLenum nativeType;
5272 unsigned int numParams = 0;
5273 getQueryParameterInfo(pname, &nativeType, &numParams);
5274
5275 if (nativeType == GL_BOOL)
5276 {
5277 getBooleanvImpl(pname, params);
5278 }
5279 else
5280 {
5281 CastStateValues(this, nativeType, pname, numParams, params);
5282 }
5283}
5284
Brandon Jones59770802018-04-02 13:18:42 -07005285void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5286{
5287 getBooleanv(pname, params);
5288}
5289
Jamie Madillc1d770e2017-04-13 17:31:24 -04005290void Context::getFloatv(GLenum pname, GLfloat *params)
5291{
5292 GLenum nativeType;
5293 unsigned int numParams = 0;
5294 getQueryParameterInfo(pname, &nativeType, &numParams);
5295
5296 if (nativeType == GL_FLOAT)
5297 {
5298 getFloatvImpl(pname, params);
5299 }
5300 else
5301 {
5302 CastStateValues(this, nativeType, pname, numParams, params);
5303 }
5304}
5305
Brandon Jones59770802018-04-02 13:18:42 -07005306void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5307{
5308 getFloatv(pname, params);
5309}
5310
Jamie Madillc1d770e2017-04-13 17:31:24 -04005311void Context::getIntegerv(GLenum pname, GLint *params)
5312{
5313 GLenum nativeType;
5314 unsigned int numParams = 0;
5315 getQueryParameterInfo(pname, &nativeType, &numParams);
5316
5317 if (nativeType == GL_INT)
5318 {
5319 getIntegervImpl(pname, params);
5320 }
5321 else
5322 {
5323 CastStateValues(this, nativeType, pname, numParams, params);
5324 }
5325}
5326
Brandon Jones59770802018-04-02 13:18:42 -07005327void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5328{
5329 getIntegerv(pname, data);
5330}
5331
Jamie Madillc1d770e2017-04-13 17:31:24 -04005332void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5333{
5334 Program *programObject = getProgram(program);
5335 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005336 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005337}
5338
Brandon Jones59770802018-04-02 13:18:42 -07005339void Context::getProgramivRobust(GLuint program,
5340 GLenum pname,
5341 GLsizei bufSize,
5342 GLsizei *length,
5343 GLint *params)
5344{
5345 getProgramiv(program, pname, params);
5346}
5347
Jiajia Qin5451d532017-11-16 17:16:34 +08005348void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5349{
5350 UNIMPLEMENTED();
5351}
5352
Jamie Madillbe849e42017-05-02 15:49:00 -04005353void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005354{
5355 Program *programObject = getProgram(program);
5356 ASSERT(programObject);
5357 programObject->getInfoLog(bufsize, length, infolog);
5358}
5359
Jiajia Qin5451d532017-11-16 17:16:34 +08005360void Context::getProgramPipelineInfoLog(GLuint pipeline,
5361 GLsizei bufSize,
5362 GLsizei *length,
5363 GLchar *infoLog)
5364{
5365 UNIMPLEMENTED();
5366}
5367
Jamie Madillc1d770e2017-04-13 17:31:24 -04005368void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5369{
5370 Shader *shaderObject = getShader(shader);
5371 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005372 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005373}
5374
Brandon Jones59770802018-04-02 13:18:42 -07005375void Context::getShaderivRobust(GLuint shader,
5376 GLenum pname,
5377 GLsizei bufSize,
5378 GLsizei *length,
5379 GLint *params)
5380{
5381 getShaderiv(shader, pname, params);
5382}
5383
Jamie Madillc1d770e2017-04-13 17:31:24 -04005384void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5385{
5386 Shader *shaderObject = getShader(shader);
5387 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005388 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005389}
5390
5391void Context::getShaderPrecisionFormat(GLenum shadertype,
5392 GLenum precisiontype,
5393 GLint *range,
5394 GLint *precision)
5395{
5396 // TODO(jmadill): Compute shaders.
5397
5398 switch (shadertype)
5399 {
5400 case GL_VERTEX_SHADER:
5401 switch (precisiontype)
5402 {
5403 case GL_LOW_FLOAT:
5404 mCaps.vertexLowpFloat.get(range, precision);
5405 break;
5406 case GL_MEDIUM_FLOAT:
5407 mCaps.vertexMediumpFloat.get(range, precision);
5408 break;
5409 case GL_HIGH_FLOAT:
5410 mCaps.vertexHighpFloat.get(range, precision);
5411 break;
5412
5413 case GL_LOW_INT:
5414 mCaps.vertexLowpInt.get(range, precision);
5415 break;
5416 case GL_MEDIUM_INT:
5417 mCaps.vertexMediumpInt.get(range, precision);
5418 break;
5419 case GL_HIGH_INT:
5420 mCaps.vertexHighpInt.get(range, precision);
5421 break;
5422
5423 default:
5424 UNREACHABLE();
5425 return;
5426 }
5427 break;
5428
5429 case GL_FRAGMENT_SHADER:
5430 switch (precisiontype)
5431 {
5432 case GL_LOW_FLOAT:
5433 mCaps.fragmentLowpFloat.get(range, precision);
5434 break;
5435 case GL_MEDIUM_FLOAT:
5436 mCaps.fragmentMediumpFloat.get(range, precision);
5437 break;
5438 case GL_HIGH_FLOAT:
5439 mCaps.fragmentHighpFloat.get(range, precision);
5440 break;
5441
5442 case GL_LOW_INT:
5443 mCaps.fragmentLowpInt.get(range, precision);
5444 break;
5445 case GL_MEDIUM_INT:
5446 mCaps.fragmentMediumpInt.get(range, precision);
5447 break;
5448 case GL_HIGH_INT:
5449 mCaps.fragmentHighpInt.get(range, precision);
5450 break;
5451
5452 default:
5453 UNREACHABLE();
5454 return;
5455 }
5456 break;
5457
5458 default:
5459 UNREACHABLE();
5460 return;
5461 }
5462}
5463
5464void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5465{
5466 Shader *shaderObject = getShader(shader);
5467 ASSERT(shaderObject);
5468 shaderObject->getSource(bufsize, length, source);
5469}
5470
5471void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5472{
5473 Program *programObject = getProgram(program);
5474 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005475 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005476}
5477
Brandon Jones59770802018-04-02 13:18:42 -07005478void Context::getUniformfvRobust(GLuint program,
5479 GLint location,
5480 GLsizei bufSize,
5481 GLsizei *length,
5482 GLfloat *params)
5483{
5484 getUniformfv(program, location, params);
5485}
5486
Jamie Madillc1d770e2017-04-13 17:31:24 -04005487void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5488{
5489 Program *programObject = getProgram(program);
5490 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005491 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005492}
5493
Brandon Jones59770802018-04-02 13:18:42 -07005494void Context::getUniformivRobust(GLuint program,
5495 GLint location,
5496 GLsizei bufSize,
5497 GLsizei *length,
5498 GLint *params)
5499{
5500 getUniformiv(program, location, params);
5501}
5502
Jamie Madillc1d770e2017-04-13 17:31:24 -04005503GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5504{
5505 Program *programObject = getProgram(program);
5506 ASSERT(programObject);
5507 return programObject->getUniformLocation(name);
5508}
5509
5510GLboolean Context::isBuffer(GLuint buffer)
5511{
5512 if (buffer == 0)
5513 {
5514 return GL_FALSE;
5515 }
5516
5517 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5518}
5519
5520GLboolean Context::isEnabled(GLenum cap)
5521{
5522 return mGLState.getEnableFeature(cap);
5523}
5524
5525GLboolean Context::isFramebuffer(GLuint framebuffer)
5526{
5527 if (framebuffer == 0)
5528 {
5529 return GL_FALSE;
5530 }
5531
5532 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5533}
5534
5535GLboolean Context::isProgram(GLuint program)
5536{
5537 if (program == 0)
5538 {
5539 return GL_FALSE;
5540 }
5541
5542 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5543}
5544
5545GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5546{
5547 if (renderbuffer == 0)
5548 {
5549 return GL_FALSE;
5550 }
5551
5552 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5553}
5554
5555GLboolean Context::isShader(GLuint shader)
5556{
5557 if (shader == 0)
5558 {
5559 return GL_FALSE;
5560 }
5561
5562 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5563}
5564
5565GLboolean Context::isTexture(GLuint texture)
5566{
5567 if (texture == 0)
5568 {
5569 return GL_FALSE;
5570 }
5571
5572 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5573}
5574
5575void Context::linkProgram(GLuint program)
5576{
5577 Program *programObject = getProgram(program);
5578 ASSERT(programObject);
5579 handleError(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005580
5581 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5582 // don't need to worry that:
5583 // 1. Draw calls after link use the new executable code or the old one depending on the link
5584 // result.
5585 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5586 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5587 // ProgramD3D.
5588 if (programObject->isInUse())
5589 {
5590 // isLinked() which forces to resolve linking, will be called.
5591 mGLState.onProgramExecutableChange(programObject);
5592 mStateCache.onProgramExecutableChange(this);
5593 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005594}
5595
5596void Context::releaseShaderCompiler()
5597{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005598 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005599}
5600
5601void Context::shaderBinary(GLsizei n,
5602 const GLuint *shaders,
5603 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005604 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005605 GLsizei length)
5606{
5607 // No binary shader formats are supported.
5608 UNIMPLEMENTED();
5609}
5610
5611void Context::shaderSource(GLuint shader,
5612 GLsizei count,
5613 const GLchar *const *string,
5614 const GLint *length)
5615{
5616 Shader *shaderObject = getShader(shader);
5617 ASSERT(shaderObject);
5618 shaderObject->setSource(count, string, length);
5619}
5620
5621void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5622{
5623 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5624}
5625
5626void Context::stencilMask(GLuint mask)
5627{
5628 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5629}
5630
5631void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5632{
5633 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5634}
5635
5636void Context::uniform1f(GLint location, GLfloat x)
5637{
5638 Program *program = mGLState.getProgram();
5639 program->setUniform1fv(location, 1, &x);
5640}
5641
5642void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5643{
5644 Program *program = mGLState.getProgram();
5645 program->setUniform1fv(location, count, v);
5646}
5647
Jamie Madill7e4eff12018-08-08 15:49:26 -04005648void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005649{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005650 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04005651 {
5652 mGLState.setObjectDirty(GL_PROGRAM);
5653 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005654}
5655
Jamie Madill7e4eff12018-08-08 15:49:26 -04005656void Context::uniform1i(GLint location, GLint x)
5657{
5658 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
5659}
5660
Jamie Madillc1d770e2017-04-13 17:31:24 -04005661void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5662{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005663 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005664}
5665
5666void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5667{
5668 GLfloat xy[2] = {x, y};
5669 Program *program = mGLState.getProgram();
5670 program->setUniform2fv(location, 1, xy);
5671}
5672
5673void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5674{
5675 Program *program = mGLState.getProgram();
5676 program->setUniform2fv(location, count, v);
5677}
5678
5679void Context::uniform2i(GLint location, GLint x, GLint y)
5680{
5681 GLint xy[2] = {x, y};
5682 Program *program = mGLState.getProgram();
5683 program->setUniform2iv(location, 1, xy);
5684}
5685
5686void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5687{
5688 Program *program = mGLState.getProgram();
5689 program->setUniform2iv(location, count, v);
5690}
5691
5692void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5693{
5694 GLfloat xyz[3] = {x, y, z};
5695 Program *program = mGLState.getProgram();
5696 program->setUniform3fv(location, 1, xyz);
5697}
5698
5699void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5700{
5701 Program *program = mGLState.getProgram();
5702 program->setUniform3fv(location, count, v);
5703}
5704
5705void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5706{
5707 GLint xyz[3] = {x, y, z};
5708 Program *program = mGLState.getProgram();
5709 program->setUniform3iv(location, 1, xyz);
5710}
5711
5712void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5713{
5714 Program *program = mGLState.getProgram();
5715 program->setUniform3iv(location, count, v);
5716}
5717
5718void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5719{
5720 GLfloat xyzw[4] = {x, y, z, w};
5721 Program *program = mGLState.getProgram();
5722 program->setUniform4fv(location, 1, xyzw);
5723}
5724
5725void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5726{
5727 Program *program = mGLState.getProgram();
5728 program->setUniform4fv(location, count, v);
5729}
5730
5731void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5732{
5733 GLint xyzw[4] = {x, y, z, w};
5734 Program *program = mGLState.getProgram();
5735 program->setUniform4iv(location, 1, xyzw);
5736}
5737
5738void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5739{
5740 Program *program = mGLState.getProgram();
5741 program->setUniform4iv(location, count, v);
5742}
5743
5744void Context::uniformMatrix2fv(GLint location,
5745 GLsizei count,
5746 GLboolean transpose,
5747 const GLfloat *value)
5748{
5749 Program *program = mGLState.getProgram();
5750 program->setUniformMatrix2fv(location, count, transpose, value);
5751}
5752
5753void Context::uniformMatrix3fv(GLint location,
5754 GLsizei count,
5755 GLboolean transpose,
5756 const GLfloat *value)
5757{
5758 Program *program = mGLState.getProgram();
5759 program->setUniformMatrix3fv(location, count, transpose, value);
5760}
5761
5762void Context::uniformMatrix4fv(GLint location,
5763 GLsizei count,
5764 GLboolean transpose,
5765 const GLfloat *value)
5766{
5767 Program *program = mGLState.getProgram();
5768 program->setUniformMatrix4fv(location, count, transpose, value);
5769}
5770
5771void Context::validateProgram(GLuint program)
5772{
5773 Program *programObject = getProgram(program);
5774 ASSERT(programObject);
5775 programObject->validate(mCaps);
5776}
5777
Jiajia Qin5451d532017-11-16 17:16:34 +08005778void Context::validateProgramPipeline(GLuint pipeline)
5779{
5780 UNIMPLEMENTED();
5781}
5782
Jamie Madilld04908b2017-06-09 14:15:35 -04005783void Context::getProgramBinary(GLuint program,
5784 GLsizei bufSize,
5785 GLsizei *length,
5786 GLenum *binaryFormat,
5787 void *binary)
5788{
5789 Program *programObject = getProgram(program);
5790 ASSERT(programObject != nullptr);
5791
5792 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5793}
5794
5795void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5796{
5797 Program *programObject = getProgram(program);
5798 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005799
Jamie Madilld04908b2017-06-09 14:15:35 -04005800 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madillc43cdad2018-08-08 15:49:25 -04005801 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04005802 if (programObject->isInUse())
5803 {
5804 mGLState.setObjectDirty(GL_PROGRAM);
5805 }
Jamie Madilld04908b2017-06-09 14:15:35 -04005806}
5807
Jamie Madillff325f12017-08-26 15:06:05 -04005808void Context::uniform1ui(GLint location, GLuint v0)
5809{
5810 Program *program = mGLState.getProgram();
5811 program->setUniform1uiv(location, 1, &v0);
5812}
5813
5814void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5815{
5816 Program *program = mGLState.getProgram();
5817 const GLuint xy[] = {v0, v1};
5818 program->setUniform2uiv(location, 1, xy);
5819}
5820
5821void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5822{
5823 Program *program = mGLState.getProgram();
5824 const GLuint xyz[] = {v0, v1, v2};
5825 program->setUniform3uiv(location, 1, xyz);
5826}
5827
5828void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5829{
5830 Program *program = mGLState.getProgram();
5831 const GLuint xyzw[] = {v0, v1, v2, v3};
5832 program->setUniform4uiv(location, 1, xyzw);
5833}
5834
5835void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5836{
5837 Program *program = mGLState.getProgram();
5838 program->setUniform1uiv(location, count, value);
5839}
5840void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5841{
5842 Program *program = mGLState.getProgram();
5843 program->setUniform2uiv(location, count, value);
5844}
5845
5846void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5847{
5848 Program *program = mGLState.getProgram();
5849 program->setUniform3uiv(location, count, value);
5850}
5851
5852void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5853{
5854 Program *program = mGLState.getProgram();
5855 program->setUniform4uiv(location, count, value);
5856}
5857
Jamie Madillf0e04492017-08-26 15:28:42 -04005858void Context::genQueries(GLsizei n, GLuint *ids)
5859{
5860 for (GLsizei i = 0; i < n; i++)
5861 {
5862 GLuint handle = mQueryHandleAllocator.allocate();
5863 mQueryMap.assign(handle, nullptr);
5864 ids[i] = handle;
5865 }
5866}
5867
5868void Context::deleteQueries(GLsizei n, const GLuint *ids)
5869{
5870 for (int i = 0; i < n; i++)
5871 {
5872 GLuint query = ids[i];
5873
5874 Query *queryObject = nullptr;
5875 if (mQueryMap.erase(query, &queryObject))
5876 {
5877 mQueryHandleAllocator.release(query);
5878 if (queryObject)
5879 {
5880 queryObject->release(this);
5881 }
5882 }
5883 }
5884}
5885
5886GLboolean Context::isQuery(GLuint id)
5887{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005888 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005889}
5890
Jamie Madillc8c95812017-08-26 18:40:09 -04005891void Context::uniformMatrix2x3fv(GLint location,
5892 GLsizei count,
5893 GLboolean transpose,
5894 const GLfloat *value)
5895{
5896 Program *program = mGLState.getProgram();
5897 program->setUniformMatrix2x3fv(location, count, transpose, value);
5898}
5899
5900void Context::uniformMatrix3x2fv(GLint location,
5901 GLsizei count,
5902 GLboolean transpose,
5903 const GLfloat *value)
5904{
5905 Program *program = mGLState.getProgram();
5906 program->setUniformMatrix3x2fv(location, count, transpose, value);
5907}
5908
5909void Context::uniformMatrix2x4fv(GLint location,
5910 GLsizei count,
5911 GLboolean transpose,
5912 const GLfloat *value)
5913{
5914 Program *program = mGLState.getProgram();
5915 program->setUniformMatrix2x4fv(location, count, transpose, value);
5916}
5917
5918void Context::uniformMatrix4x2fv(GLint location,
5919 GLsizei count,
5920 GLboolean transpose,
5921 const GLfloat *value)
5922{
5923 Program *program = mGLState.getProgram();
5924 program->setUniformMatrix4x2fv(location, count, transpose, value);
5925}
5926
5927void Context::uniformMatrix3x4fv(GLint location,
5928 GLsizei count,
5929 GLboolean transpose,
5930 const GLfloat *value)
5931{
5932 Program *program = mGLState.getProgram();
5933 program->setUniformMatrix3x4fv(location, count, transpose, value);
5934}
5935
5936void Context::uniformMatrix4x3fv(GLint location,
5937 GLsizei count,
5938 GLboolean transpose,
5939 const GLfloat *value)
5940{
5941 Program *program = mGLState.getProgram();
5942 program->setUniformMatrix4x3fv(location, count, transpose, value);
5943}
5944
Jamie Madilld7576732017-08-26 18:49:50 -04005945void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5946{
5947 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5948 {
5949 GLuint vertexArray = arrays[arrayIndex];
5950
5951 if (arrays[arrayIndex] != 0)
5952 {
5953 VertexArray *vertexArrayObject = nullptr;
5954 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5955 {
5956 if (vertexArrayObject != nullptr)
5957 {
5958 detachVertexArray(vertexArray);
5959 vertexArrayObject->onDestroy(this);
5960 }
5961
5962 mVertexArrayHandleAllocator.release(vertexArray);
5963 }
5964 }
5965 }
5966}
5967
5968void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5969{
5970 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5971 {
5972 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5973 mVertexArrayMap.assign(vertexArray, nullptr);
5974 arrays[arrayIndex] = vertexArray;
5975 }
5976}
5977
5978bool Context::isVertexArray(GLuint array)
5979{
5980 if (array == 0)
5981 {
5982 return GL_FALSE;
5983 }
5984
5985 VertexArray *vao = getVertexArray(array);
5986 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5987}
5988
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005989void Context::endTransformFeedback()
5990{
5991 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5992 transformFeedback->end(this);
5993}
5994
5995void Context::transformFeedbackVaryings(GLuint program,
5996 GLsizei count,
5997 const GLchar *const *varyings,
5998 GLenum bufferMode)
5999{
6000 Program *programObject = getProgram(program);
6001 ASSERT(programObject);
6002 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6003}
6004
6005void Context::getTransformFeedbackVarying(GLuint program,
6006 GLuint index,
6007 GLsizei bufSize,
6008 GLsizei *length,
6009 GLsizei *size,
6010 GLenum *type,
6011 GLchar *name)
6012{
6013 Program *programObject = getProgram(program);
6014 ASSERT(programObject);
6015 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6016}
6017
6018void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6019{
6020 for (int i = 0; i < n; i++)
6021 {
6022 GLuint transformFeedback = ids[i];
6023 if (transformFeedback == 0)
6024 {
6025 continue;
6026 }
6027
6028 TransformFeedback *transformFeedbackObject = nullptr;
6029 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6030 {
6031 if (transformFeedbackObject != nullptr)
6032 {
6033 detachTransformFeedback(transformFeedback);
6034 transformFeedbackObject->release(this);
6035 }
6036
6037 mTransformFeedbackHandleAllocator.release(transformFeedback);
6038 }
6039 }
6040}
6041
6042void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6043{
6044 for (int i = 0; i < n; i++)
6045 {
6046 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6047 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6048 ids[i] = transformFeedback;
6049 }
6050}
6051
6052bool Context::isTransformFeedback(GLuint id)
6053{
6054 if (id == 0)
6055 {
6056 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6057 // returns FALSE
6058 return GL_FALSE;
6059 }
6060
6061 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6062 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6063}
6064
6065void Context::pauseTransformFeedback()
6066{
6067 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6068 transformFeedback->pause();
6069}
6070
6071void Context::resumeTransformFeedback()
6072{
6073 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6074 transformFeedback->resume();
6075}
6076
Jamie Madill12e957f2017-08-26 21:42:26 -04006077void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6078{
6079 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006080 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006081}
6082
Brandon Jones59770802018-04-02 13:18:42 -07006083void Context::getUniformuivRobust(GLuint program,
6084 GLint location,
6085 GLsizei bufSize,
6086 GLsizei *length,
6087 GLuint *params)
6088{
6089 getUniformuiv(program, location, params);
6090}
6091
Jamie Madill12e957f2017-08-26 21:42:26 -04006092GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6093{
6094 const Program *programObject = getProgram(program);
6095 return programObject->getFragDataLocation(name);
6096}
6097
6098void Context::getUniformIndices(GLuint program,
6099 GLsizei uniformCount,
6100 const GLchar *const *uniformNames,
6101 GLuint *uniformIndices)
6102{
6103 const Program *programObject = getProgram(program);
6104 if (!programObject->isLinked())
6105 {
6106 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6107 {
6108 uniformIndices[uniformId] = GL_INVALID_INDEX;
6109 }
6110 }
6111 else
6112 {
6113 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6114 {
6115 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6116 }
6117 }
6118}
6119
6120void Context::getActiveUniformsiv(GLuint program,
6121 GLsizei uniformCount,
6122 const GLuint *uniformIndices,
6123 GLenum pname,
6124 GLint *params)
6125{
6126 const Program *programObject = getProgram(program);
6127 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6128 {
6129 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006130 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006131 }
6132}
6133
6134GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6135{
6136 const Program *programObject = getProgram(program);
6137 return programObject->getUniformBlockIndex(uniformBlockName);
6138}
6139
6140void Context::getActiveUniformBlockiv(GLuint program,
6141 GLuint uniformBlockIndex,
6142 GLenum pname,
6143 GLint *params)
6144{
6145 const Program *programObject = getProgram(program);
6146 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6147}
6148
Brandon Jones59770802018-04-02 13:18:42 -07006149void Context::getActiveUniformBlockivRobust(GLuint program,
6150 GLuint uniformBlockIndex,
6151 GLenum pname,
6152 GLsizei bufSize,
6153 GLsizei *length,
6154 GLint *params)
6155{
6156 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6157}
6158
Jamie Madill12e957f2017-08-26 21:42:26 -04006159void Context::getActiveUniformBlockName(GLuint program,
6160 GLuint uniformBlockIndex,
6161 GLsizei bufSize,
6162 GLsizei *length,
6163 GLchar *uniformBlockName)
6164{
6165 const Program *programObject = getProgram(program);
6166 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6167}
6168
6169void Context::uniformBlockBinding(GLuint program,
6170 GLuint uniformBlockIndex,
6171 GLuint uniformBlockBinding)
6172{
6173 Program *programObject = getProgram(program);
6174 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006175
6176 if (programObject->isInUse())
6177 {
6178 mGLState.setObjectDirty(GL_PROGRAM);
6179 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006180}
6181
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006182GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6183{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006184 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6185 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006186
Jamie Madill70b5bb02017-08-28 13:32:37 -04006187 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006188 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006189 if (error.isError())
6190 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006191 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006192 handleError(error);
6193 return nullptr;
6194 }
6195
Jamie Madill70b5bb02017-08-28 13:32:37 -04006196 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006197}
6198
6199GLboolean Context::isSync(GLsync sync)
6200{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006201 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006202}
6203
6204GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6205{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006206 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006207
6208 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006209 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006210 return result;
6211}
6212
6213void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6214{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006215 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006216 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006217}
6218
6219void Context::getInteger64v(GLenum pname, GLint64 *params)
6220{
6221 GLenum nativeType = GL_NONE;
6222 unsigned int numParams = 0;
6223 getQueryParameterInfo(pname, &nativeType, &numParams);
6224
6225 if (nativeType == GL_INT_64_ANGLEX)
6226 {
6227 getInteger64vImpl(pname, params);
6228 }
6229 else
6230 {
6231 CastStateValues(this, nativeType, pname, numParams, params);
6232 }
6233}
6234
Brandon Jones59770802018-04-02 13:18:42 -07006235void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6236{
6237 getInteger64v(pname, data);
6238}
6239
Corentin Wallez336129f2017-10-17 15:55:40 -04006240void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006241{
6242 Buffer *buffer = mGLState.getTargetBuffer(target);
6243 QueryBufferParameteri64v(buffer, pname, params);
6244}
6245
Brandon Jones59770802018-04-02 13:18:42 -07006246void Context::getBufferParameteri64vRobust(BufferBinding target,
6247 GLenum pname,
6248 GLsizei bufSize,
6249 GLsizei *length,
6250 GLint64 *params)
6251{
6252 getBufferParameteri64v(target, pname, params);
6253}
6254
Jamie Madill3ef140a2017-08-26 23:11:21 -04006255void Context::genSamplers(GLsizei count, GLuint *samplers)
6256{
6257 for (int i = 0; i < count; i++)
6258 {
6259 samplers[i] = mState.mSamplers->createSampler();
6260 }
6261}
6262
6263void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6264{
6265 for (int i = 0; i < count; i++)
6266 {
6267 GLuint sampler = samplers[i];
6268
6269 if (mState.mSamplers->getSampler(sampler))
6270 {
6271 detachSampler(sampler);
6272 }
6273
6274 mState.mSamplers->deleteObject(this, sampler);
6275 }
6276}
6277
6278void Context::getInternalformativ(GLenum target,
6279 GLenum internalformat,
6280 GLenum pname,
6281 GLsizei bufSize,
6282 GLint *params)
6283{
6284 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6285 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6286}
6287
Brandon Jones59770802018-04-02 13:18:42 -07006288void Context::getInternalformativRobust(GLenum target,
6289 GLenum internalformat,
6290 GLenum pname,
6291 GLsizei bufSize,
6292 GLsizei *length,
6293 GLint *params)
6294{
6295 getInternalformativ(target, internalformat, pname, bufSize, params);
6296}
6297
Jiajia Qin5451d532017-11-16 17:16:34 +08006298void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6299{
6300 programUniform1iv(program, location, 1, &v0);
6301}
6302
6303void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6304{
6305 GLint xy[2] = {v0, v1};
6306 programUniform2iv(program, location, 1, xy);
6307}
6308
6309void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6310{
6311 GLint xyz[3] = {v0, v1, v2};
6312 programUniform3iv(program, location, 1, xyz);
6313}
6314
6315void Context::programUniform4i(GLuint program,
6316 GLint location,
6317 GLint v0,
6318 GLint v1,
6319 GLint v2,
6320 GLint v3)
6321{
6322 GLint xyzw[4] = {v0, v1, v2, v3};
6323 programUniform4iv(program, location, 1, xyzw);
6324}
6325
6326void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6327{
6328 programUniform1uiv(program, location, 1, &v0);
6329}
6330
6331void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6332{
6333 GLuint xy[2] = {v0, v1};
6334 programUniform2uiv(program, location, 1, xy);
6335}
6336
6337void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6338{
6339 GLuint xyz[3] = {v0, v1, v2};
6340 programUniform3uiv(program, location, 1, xyz);
6341}
6342
6343void Context::programUniform4ui(GLuint program,
6344 GLint location,
6345 GLuint v0,
6346 GLuint v1,
6347 GLuint v2,
6348 GLuint v3)
6349{
6350 GLuint xyzw[4] = {v0, v1, v2, v3};
6351 programUniform4uiv(program, location, 1, xyzw);
6352}
6353
6354void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6355{
6356 programUniform1fv(program, location, 1, &v0);
6357}
6358
6359void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6360{
6361 GLfloat xy[2] = {v0, v1};
6362 programUniform2fv(program, location, 1, xy);
6363}
6364
6365void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6366{
6367 GLfloat xyz[3] = {v0, v1, v2};
6368 programUniform3fv(program, location, 1, xyz);
6369}
6370
6371void Context::programUniform4f(GLuint program,
6372 GLint location,
6373 GLfloat v0,
6374 GLfloat v1,
6375 GLfloat v2,
6376 GLfloat v3)
6377{
6378 GLfloat xyzw[4] = {v0, v1, v2, v3};
6379 programUniform4fv(program, location, 1, xyzw);
6380}
6381
Jamie Madill81c2e252017-09-09 23:32:46 -04006382void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6383{
6384 Program *programObject = getProgram(program);
6385 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006386 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006387}
6388
Jiajia Qin5451d532017-11-16 17:16:34 +08006389void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6390{
6391 Program *programObject = getProgram(program);
6392 ASSERT(programObject);
6393 programObject->setUniform2iv(location, count, value);
6394}
6395
6396void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6397{
6398 Program *programObject = getProgram(program);
6399 ASSERT(programObject);
6400 programObject->setUniform3iv(location, count, value);
6401}
6402
6403void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6404{
6405 Program *programObject = getProgram(program);
6406 ASSERT(programObject);
6407 programObject->setUniform4iv(location, count, value);
6408}
6409
6410void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6411{
6412 Program *programObject = getProgram(program);
6413 ASSERT(programObject);
6414 programObject->setUniform1uiv(location, count, value);
6415}
6416
6417void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6418{
6419 Program *programObject = getProgram(program);
6420 ASSERT(programObject);
6421 programObject->setUniform2uiv(location, count, value);
6422}
6423
6424void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6425{
6426 Program *programObject = getProgram(program);
6427 ASSERT(programObject);
6428 programObject->setUniform3uiv(location, count, value);
6429}
6430
6431void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6432{
6433 Program *programObject = getProgram(program);
6434 ASSERT(programObject);
6435 programObject->setUniform4uiv(location, count, value);
6436}
6437
6438void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6439{
6440 Program *programObject = getProgram(program);
6441 ASSERT(programObject);
6442 programObject->setUniform1fv(location, count, value);
6443}
6444
6445void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6446{
6447 Program *programObject = getProgram(program);
6448 ASSERT(programObject);
6449 programObject->setUniform2fv(location, count, value);
6450}
6451
6452void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6453{
6454 Program *programObject = getProgram(program);
6455 ASSERT(programObject);
6456 programObject->setUniform3fv(location, count, value);
6457}
6458
6459void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6460{
6461 Program *programObject = getProgram(program);
6462 ASSERT(programObject);
6463 programObject->setUniform4fv(location, count, value);
6464}
6465
6466void Context::programUniformMatrix2fv(GLuint program,
6467 GLint location,
6468 GLsizei count,
6469 GLboolean transpose,
6470 const GLfloat *value)
6471{
6472 Program *programObject = getProgram(program);
6473 ASSERT(programObject);
6474 programObject->setUniformMatrix2fv(location, count, transpose, value);
6475}
6476
6477void Context::programUniformMatrix3fv(GLuint program,
6478 GLint location,
6479 GLsizei count,
6480 GLboolean transpose,
6481 const GLfloat *value)
6482{
6483 Program *programObject = getProgram(program);
6484 ASSERT(programObject);
6485 programObject->setUniformMatrix3fv(location, count, transpose, value);
6486}
6487
6488void Context::programUniformMatrix4fv(GLuint program,
6489 GLint location,
6490 GLsizei count,
6491 GLboolean transpose,
6492 const GLfloat *value)
6493{
6494 Program *programObject = getProgram(program);
6495 ASSERT(programObject);
6496 programObject->setUniformMatrix4fv(location, count, transpose, value);
6497}
6498
6499void Context::programUniformMatrix2x3fv(GLuint program,
6500 GLint location,
6501 GLsizei count,
6502 GLboolean transpose,
6503 const GLfloat *value)
6504{
6505 Program *programObject = getProgram(program);
6506 ASSERT(programObject);
6507 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6508}
6509
6510void Context::programUniformMatrix3x2fv(GLuint program,
6511 GLint location,
6512 GLsizei count,
6513 GLboolean transpose,
6514 const GLfloat *value)
6515{
6516 Program *programObject = getProgram(program);
6517 ASSERT(programObject);
6518 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6519}
6520
6521void Context::programUniformMatrix2x4fv(GLuint program,
6522 GLint location,
6523 GLsizei count,
6524 GLboolean transpose,
6525 const GLfloat *value)
6526{
6527 Program *programObject = getProgram(program);
6528 ASSERT(programObject);
6529 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6530}
6531
6532void Context::programUniformMatrix4x2fv(GLuint program,
6533 GLint location,
6534 GLsizei count,
6535 GLboolean transpose,
6536 const GLfloat *value)
6537{
6538 Program *programObject = getProgram(program);
6539 ASSERT(programObject);
6540 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6541}
6542
6543void Context::programUniformMatrix3x4fv(GLuint program,
6544 GLint location,
6545 GLsizei count,
6546 GLboolean transpose,
6547 const GLfloat *value)
6548{
6549 Program *programObject = getProgram(program);
6550 ASSERT(programObject);
6551 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6552}
6553
6554void Context::programUniformMatrix4x3fv(GLuint program,
6555 GLint location,
6556 GLsizei count,
6557 GLboolean transpose,
6558 const GLfloat *value)
6559{
6560 Program *programObject = getProgram(program);
6561 ASSERT(programObject);
6562 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6563}
6564
Jamie Madill81c2e252017-09-09 23:32:46 -04006565void Context::onTextureChange(const Texture *texture)
6566{
6567 // Conservatively assume all textures are dirty.
6568 // TODO(jmadill): More fine-grained update.
6569 mGLState.setObjectDirty(GL_TEXTURE);
6570}
6571
James Darpiniane8a93c62018-01-04 18:02:24 -08006572bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6573{
6574 return mGLState.isCurrentTransformFeedback(tf);
6575}
James Darpiniane8a93c62018-01-04 18:02:24 -08006576
Yunchao Hea336b902017-08-02 16:05:21 +08006577void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6578{
6579 for (int i = 0; i < count; i++)
6580 {
6581 pipelines[i] = createProgramPipeline();
6582 }
6583}
6584
6585void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6586{
6587 for (int i = 0; i < count; i++)
6588 {
6589 if (pipelines[i] != 0)
6590 {
6591 deleteProgramPipeline(pipelines[i]);
6592 }
6593 }
6594}
6595
6596GLboolean Context::isProgramPipeline(GLuint pipeline)
6597{
6598 if (pipeline == 0)
6599 {
6600 return GL_FALSE;
6601 }
6602
6603 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6604}
6605
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006606void Context::finishFenceNV(GLuint fence)
6607{
6608 FenceNV *fenceObject = getFenceNV(fence);
6609
6610 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006611 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006612}
6613
6614void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6615{
6616 FenceNV *fenceObject = getFenceNV(fence);
6617
6618 ASSERT(fenceObject && fenceObject->isSet());
6619
6620 switch (pname)
6621 {
6622 case GL_FENCE_STATUS_NV:
6623 {
6624 // GL_NV_fence spec:
6625 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6626 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6627 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6628 GLboolean status = GL_TRUE;
6629 if (fenceObject->getStatus() != GL_TRUE)
6630 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006631 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006632 }
6633 *params = status;
6634 break;
6635 }
6636
6637 case GL_FENCE_CONDITION_NV:
6638 {
6639 *params = static_cast<GLint>(fenceObject->getCondition());
6640 break;
6641 }
6642
6643 default:
6644 UNREACHABLE();
6645 }
6646}
6647
6648void Context::getTranslatedShaderSource(GLuint shader,
6649 GLsizei bufsize,
6650 GLsizei *length,
6651 GLchar *source)
6652{
6653 Shader *shaderObject = getShader(shader);
6654 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006655 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006656}
6657
6658void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6659{
6660 Program *programObject = getProgram(program);
6661 ASSERT(programObject);
6662
6663 programObject->getUniformfv(this, location, params);
6664}
6665
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006666void Context::getnUniformfvRobust(GLuint program,
6667 GLint location,
6668 GLsizei bufSize,
6669 GLsizei *length,
6670 GLfloat *params)
6671{
6672 UNIMPLEMENTED();
6673}
6674
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006675void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6676{
6677 Program *programObject = getProgram(program);
6678 ASSERT(programObject);
6679
6680 programObject->getUniformiv(this, location, params);
6681}
6682
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006683void Context::getnUniformivRobust(GLuint program,
6684 GLint location,
6685 GLsizei bufSize,
6686 GLsizei *length,
6687 GLint *params)
6688{
6689 UNIMPLEMENTED();
6690}
6691
6692void Context::getnUniformuivRobust(GLuint program,
6693 GLint location,
6694 GLsizei bufSize,
6695 GLsizei *length,
6696 GLuint *params)
6697{
6698 UNIMPLEMENTED();
6699}
6700
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006701GLboolean Context::isFenceNV(GLuint fence)
6702{
6703 FenceNV *fenceObject = getFenceNV(fence);
6704
6705 if (fenceObject == nullptr)
6706 {
6707 return GL_FALSE;
6708 }
6709
6710 // GL_NV_fence spec:
6711 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6712 // existing fence.
6713 return fenceObject->isSet();
6714}
6715
6716void Context::readnPixels(GLint x,
6717 GLint y,
6718 GLsizei width,
6719 GLsizei height,
6720 GLenum format,
6721 GLenum type,
6722 GLsizei bufSize,
6723 void *data)
6724{
6725 return readPixels(x, y, width, height, format, type, data);
6726}
6727
Jamie Madill007530e2017-12-28 14:27:04 -05006728void Context::setFenceNV(GLuint fence, GLenum condition)
6729{
6730 ASSERT(condition == GL_ALL_COMPLETED_NV);
6731
6732 FenceNV *fenceObject = getFenceNV(fence);
6733 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006734 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006735}
6736
6737GLboolean Context::testFenceNV(GLuint fence)
6738{
6739 FenceNV *fenceObject = getFenceNV(fence);
6740
6741 ASSERT(fenceObject != nullptr);
6742 ASSERT(fenceObject->isSet() == GL_TRUE);
6743
6744 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006745 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006746 if (error.isError())
6747 {
6748 handleError(error);
6749 return GL_TRUE;
6750 }
6751
6752 return result;
6753}
6754
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006755void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006756{
6757 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006758 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006759 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006760}
6761
Jamie Madillfa920eb2018-01-04 11:45:50 -05006762void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006763{
6764 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006765 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006766 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6767}
6768
Jamie Madillfa920eb2018-01-04 11:45:50 -05006769void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6770{
6771 UNIMPLEMENTED();
6772}
6773
Jamie Madill5b772312018-03-08 20:28:32 -05006774bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6775{
6776 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6777 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6778 // to the fact that it is stored internally as a float, and so would require conversion
6779 // if returned from Context::getIntegerv. Since this conversion is already implemented
6780 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6781 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6782 // application.
6783 switch (pname)
6784 {
6785 case GL_COMPRESSED_TEXTURE_FORMATS:
6786 {
6787 *type = GL_INT;
6788 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6789 return true;
6790 }
6791 case GL_SHADER_BINARY_FORMATS:
6792 {
6793 *type = GL_INT;
6794 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6795 return true;
6796 }
6797
6798 case GL_MAX_VERTEX_ATTRIBS:
6799 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6800 case GL_MAX_VARYING_VECTORS:
6801 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6802 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6803 case GL_MAX_TEXTURE_IMAGE_UNITS:
6804 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6805 case GL_MAX_RENDERBUFFER_SIZE:
6806 case GL_NUM_SHADER_BINARY_FORMATS:
6807 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6808 case GL_ARRAY_BUFFER_BINDING:
6809 case GL_FRAMEBUFFER_BINDING:
6810 case GL_RENDERBUFFER_BINDING:
6811 case GL_CURRENT_PROGRAM:
6812 case GL_PACK_ALIGNMENT:
6813 case GL_UNPACK_ALIGNMENT:
6814 case GL_GENERATE_MIPMAP_HINT:
6815 case GL_RED_BITS:
6816 case GL_GREEN_BITS:
6817 case GL_BLUE_BITS:
6818 case GL_ALPHA_BITS:
6819 case GL_DEPTH_BITS:
6820 case GL_STENCIL_BITS:
6821 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6822 case GL_CULL_FACE_MODE:
6823 case GL_FRONT_FACE:
6824 case GL_ACTIVE_TEXTURE:
6825 case GL_STENCIL_FUNC:
6826 case GL_STENCIL_VALUE_MASK:
6827 case GL_STENCIL_REF:
6828 case GL_STENCIL_FAIL:
6829 case GL_STENCIL_PASS_DEPTH_FAIL:
6830 case GL_STENCIL_PASS_DEPTH_PASS:
6831 case GL_STENCIL_BACK_FUNC:
6832 case GL_STENCIL_BACK_VALUE_MASK:
6833 case GL_STENCIL_BACK_REF:
6834 case GL_STENCIL_BACK_FAIL:
6835 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6836 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6837 case GL_DEPTH_FUNC:
6838 case GL_BLEND_SRC_RGB:
6839 case GL_BLEND_SRC_ALPHA:
6840 case GL_BLEND_DST_RGB:
6841 case GL_BLEND_DST_ALPHA:
6842 case GL_BLEND_EQUATION_RGB:
6843 case GL_BLEND_EQUATION_ALPHA:
6844 case GL_STENCIL_WRITEMASK:
6845 case GL_STENCIL_BACK_WRITEMASK:
6846 case GL_STENCIL_CLEAR_VALUE:
6847 case GL_SUBPIXEL_BITS:
6848 case GL_MAX_TEXTURE_SIZE:
6849 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6850 case GL_SAMPLE_BUFFERS:
6851 case GL_SAMPLES:
6852 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6853 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6854 case GL_TEXTURE_BINDING_2D:
6855 case GL_TEXTURE_BINDING_CUBE_MAP:
6856 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6857 {
6858 *type = GL_INT;
6859 *numParams = 1;
6860 return true;
6861 }
6862 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6863 {
6864 if (!getExtensions().packReverseRowOrder)
6865 {
6866 return false;
6867 }
6868 *type = GL_INT;
6869 *numParams = 1;
6870 return true;
6871 }
6872 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6873 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6874 {
6875 if (!getExtensions().textureRectangle)
6876 {
6877 return false;
6878 }
6879 *type = GL_INT;
6880 *numParams = 1;
6881 return true;
6882 }
6883 case GL_MAX_DRAW_BUFFERS_EXT:
6884 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6885 {
6886 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6887 {
6888 return false;
6889 }
6890 *type = GL_INT;
6891 *numParams = 1;
6892 return true;
6893 }
6894 case GL_MAX_VIEWPORT_DIMS:
6895 {
6896 *type = GL_INT;
6897 *numParams = 2;
6898 return true;
6899 }
6900 case GL_VIEWPORT:
6901 case GL_SCISSOR_BOX:
6902 {
6903 *type = GL_INT;
6904 *numParams = 4;
6905 return true;
6906 }
6907 case GL_SHADER_COMPILER:
6908 case GL_SAMPLE_COVERAGE_INVERT:
6909 case GL_DEPTH_WRITEMASK:
6910 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6911 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6912 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6913 // bool-natural
6914 case GL_SAMPLE_COVERAGE:
6915 case GL_SCISSOR_TEST:
6916 case GL_STENCIL_TEST:
6917 case GL_DEPTH_TEST:
6918 case GL_BLEND:
6919 case GL_DITHER:
6920 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6921 {
6922 *type = GL_BOOL;
6923 *numParams = 1;
6924 return true;
6925 }
6926 case GL_COLOR_WRITEMASK:
6927 {
6928 *type = GL_BOOL;
6929 *numParams = 4;
6930 return true;
6931 }
6932 case GL_POLYGON_OFFSET_FACTOR:
6933 case GL_POLYGON_OFFSET_UNITS:
6934 case GL_SAMPLE_COVERAGE_VALUE:
6935 case GL_DEPTH_CLEAR_VALUE:
6936 case GL_LINE_WIDTH:
6937 {
6938 *type = GL_FLOAT;
6939 *numParams = 1;
6940 return true;
6941 }
6942 case GL_ALIASED_LINE_WIDTH_RANGE:
6943 case GL_ALIASED_POINT_SIZE_RANGE:
6944 case GL_DEPTH_RANGE:
6945 {
6946 *type = GL_FLOAT;
6947 *numParams = 2;
6948 return true;
6949 }
6950 case GL_COLOR_CLEAR_VALUE:
6951 case GL_BLEND_COLOR:
6952 {
6953 *type = GL_FLOAT;
6954 *numParams = 4;
6955 return true;
6956 }
6957 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6958 if (!getExtensions().textureFilterAnisotropic)
6959 {
6960 return false;
6961 }
6962 *type = GL_FLOAT;
6963 *numParams = 1;
6964 return true;
6965 case GL_TIMESTAMP_EXT:
6966 if (!getExtensions().disjointTimerQuery)
6967 {
6968 return false;
6969 }
6970 *type = GL_INT_64_ANGLEX;
6971 *numParams = 1;
6972 return true;
6973 case GL_GPU_DISJOINT_EXT:
6974 if (!getExtensions().disjointTimerQuery)
6975 {
6976 return false;
6977 }
6978 *type = GL_INT;
6979 *numParams = 1;
6980 return true;
6981 case GL_COVERAGE_MODULATION_CHROMIUM:
6982 if (!getExtensions().framebufferMixedSamples)
6983 {
6984 return false;
6985 }
6986 *type = GL_INT;
6987 *numParams = 1;
6988 return true;
6989 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6990 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6991 {
6992 return false;
6993 }
6994 *type = GL_INT;
6995 *numParams = 1;
6996 return true;
6997 }
6998
6999 if (getExtensions().debug)
7000 {
7001 switch (pname)
7002 {
7003 case GL_DEBUG_LOGGED_MESSAGES:
7004 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7005 case GL_DEBUG_GROUP_STACK_DEPTH:
7006 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7007 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7008 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7009 case GL_MAX_LABEL_LENGTH:
7010 *type = GL_INT;
7011 *numParams = 1;
7012 return true;
7013
7014 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7015 case GL_DEBUG_OUTPUT:
7016 *type = GL_BOOL;
7017 *numParams = 1;
7018 return true;
7019 }
7020 }
7021
7022 if (getExtensions().multisampleCompatibility)
7023 {
7024 switch (pname)
7025 {
7026 case GL_MULTISAMPLE_EXT:
7027 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7028 *type = GL_BOOL;
7029 *numParams = 1;
7030 return true;
7031 }
7032 }
7033
7034 if (getExtensions().pathRendering)
7035 {
7036 switch (pname)
7037 {
7038 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7039 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7040 *type = GL_FLOAT;
7041 *numParams = 16;
7042 return true;
7043 }
7044 }
7045
7046 if (getExtensions().bindGeneratesResource)
7047 {
7048 switch (pname)
7049 {
7050 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7051 *type = GL_BOOL;
7052 *numParams = 1;
7053 return true;
7054 }
7055 }
7056
7057 if (getExtensions().clientArrays)
7058 {
7059 switch (pname)
7060 {
7061 case GL_CLIENT_ARRAYS_ANGLE:
7062 *type = GL_BOOL;
7063 *numParams = 1;
7064 return true;
7065 }
7066 }
7067
7068 if (getExtensions().sRGBWriteControl)
7069 {
7070 switch (pname)
7071 {
7072 case GL_FRAMEBUFFER_SRGB_EXT:
7073 *type = GL_BOOL;
7074 *numParams = 1;
7075 return true;
7076 }
7077 }
7078
7079 if (getExtensions().robustResourceInitialization &&
7080 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7081 {
7082 *type = GL_BOOL;
7083 *numParams = 1;
7084 return true;
7085 }
7086
7087 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7088 {
7089 *type = GL_BOOL;
7090 *numParams = 1;
7091 return true;
7092 }
7093
jchen1082af6202018-06-22 10:59:52 +08007094 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7095 {
7096 *type = GL_INT;
7097 *numParams = 1;
7098 return true;
7099 }
7100
Jamie Madill5b772312018-03-08 20:28:32 -05007101 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7102 switch (pname)
7103 {
7104 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7105 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7106 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7107 {
7108 return false;
7109 }
7110 *type = GL_INT;
7111 *numParams = 1;
7112 return true;
7113
7114 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7115 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7116 {
7117 return false;
7118 }
7119 *type = GL_INT;
7120 *numParams = 1;
7121 return true;
7122
7123 case GL_PROGRAM_BINARY_FORMATS_OES:
7124 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7125 {
7126 return false;
7127 }
7128 *type = GL_INT;
7129 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7130 return true;
7131
7132 case GL_PACK_ROW_LENGTH:
7133 case GL_PACK_SKIP_ROWS:
7134 case GL_PACK_SKIP_PIXELS:
7135 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7136 {
7137 return false;
7138 }
7139 *type = GL_INT;
7140 *numParams = 1;
7141 return true;
7142 case GL_UNPACK_ROW_LENGTH:
7143 case GL_UNPACK_SKIP_ROWS:
7144 case GL_UNPACK_SKIP_PIXELS:
7145 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7146 {
7147 return false;
7148 }
7149 *type = GL_INT;
7150 *numParams = 1;
7151 return true;
7152 case GL_VERTEX_ARRAY_BINDING:
7153 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7154 {
7155 return false;
7156 }
7157 *type = GL_INT;
7158 *numParams = 1;
7159 return true;
7160 case GL_PIXEL_PACK_BUFFER_BINDING:
7161 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7162 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7163 {
7164 return false;
7165 }
7166 *type = GL_INT;
7167 *numParams = 1;
7168 return true;
7169 case GL_MAX_SAMPLES:
7170 {
7171 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7172 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7173 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7174 {
7175 return false;
7176 }
7177 *type = GL_INT;
7178 *numParams = 1;
7179 return true;
7180
7181 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7182 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7183 {
7184 return false;
7185 }
7186 *type = GL_INT;
7187 *numParams = 1;
7188 return true;
7189 }
7190 }
7191
7192 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7193 {
7194 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7195 {
7196 return false;
7197 }
7198 *type = GL_INT;
7199 *numParams = 1;
7200 return true;
7201 }
7202
7203 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7204 {
7205 *type = GL_INT;
7206 *numParams = 1;
7207 return true;
7208 }
7209
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007210 if (getClientVersion() < Version(2, 0))
7211 {
7212 switch (pname)
7213 {
7214 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007215 case GL_CLIENT_ACTIVE_TEXTURE:
7216 case GL_MATRIX_MODE:
7217 case GL_MAX_TEXTURE_UNITS:
7218 case GL_MAX_MODELVIEW_STACK_DEPTH:
7219 case GL_MAX_PROJECTION_STACK_DEPTH:
7220 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007221 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007222 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007223 case GL_VERTEX_ARRAY_STRIDE:
7224 case GL_NORMAL_ARRAY_STRIDE:
7225 case GL_COLOR_ARRAY_STRIDE:
7226 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7227 case GL_VERTEX_ARRAY_SIZE:
7228 case GL_COLOR_ARRAY_SIZE:
7229 case GL_TEXTURE_COORD_ARRAY_SIZE:
7230 case GL_VERTEX_ARRAY_TYPE:
7231 case GL_NORMAL_ARRAY_TYPE:
7232 case GL_COLOR_ARRAY_TYPE:
7233 case GL_TEXTURE_COORD_ARRAY_TYPE:
7234 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7235 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7236 case GL_COLOR_ARRAY_BUFFER_BINDING:
7237 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7238 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7239 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7240 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007241 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007242 case GL_MODELVIEW_STACK_DEPTH:
7243 case GL_PROJECTION_STACK_DEPTH:
7244 case GL_TEXTURE_STACK_DEPTH:
7245 case GL_LOGIC_OP_MODE:
7246 case GL_BLEND_SRC:
7247 case GL_BLEND_DST:
7248 case GL_PERSPECTIVE_CORRECTION_HINT:
7249 case GL_POINT_SMOOTH_HINT:
7250 case GL_LINE_SMOOTH_HINT:
7251 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007252 *type = GL_INT;
7253 *numParams = 1;
7254 return true;
7255 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007256 case GL_FOG_DENSITY:
7257 case GL_FOG_START:
7258 case GL_FOG_END:
7259 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007260 case GL_POINT_SIZE:
7261 case GL_POINT_SIZE_MIN:
7262 case GL_POINT_SIZE_MAX:
7263 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007264 *type = GL_FLOAT;
7265 *numParams = 1;
7266 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007267 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007268 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007269 *type = GL_FLOAT;
7270 *numParams = 2;
7271 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007272 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007273 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007274 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007275 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007276 *type = GL_FLOAT;
7277 *numParams = 4;
7278 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007279 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007280 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007281 *type = GL_FLOAT;
7282 *numParams = 3;
7283 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007284 case GL_MODELVIEW_MATRIX:
7285 case GL_PROJECTION_MATRIX:
7286 case GL_TEXTURE_MATRIX:
7287 *type = GL_FLOAT;
7288 *numParams = 16;
7289 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007290 case GL_LIGHT_MODEL_TWO_SIDE:
7291 *type = GL_BOOL;
7292 *numParams = 1;
7293 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007294 }
7295 }
7296
Jamie Madill5b772312018-03-08 20:28:32 -05007297 if (getClientVersion() < Version(3, 0))
7298 {
7299 return false;
7300 }
7301
7302 // Check for ES3.0+ parameter names
7303 switch (pname)
7304 {
7305 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7306 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7307 case GL_UNIFORM_BUFFER_BINDING:
7308 case GL_TRANSFORM_FEEDBACK_BINDING:
7309 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7310 case GL_COPY_READ_BUFFER_BINDING:
7311 case GL_COPY_WRITE_BUFFER_BINDING:
7312 case GL_SAMPLER_BINDING:
7313 case GL_READ_BUFFER:
7314 case GL_TEXTURE_BINDING_3D:
7315 case GL_TEXTURE_BINDING_2D_ARRAY:
7316 case GL_MAX_3D_TEXTURE_SIZE:
7317 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7318 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7319 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7320 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7321 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7322 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7323 case GL_MAX_VARYING_COMPONENTS:
7324 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7325 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7326 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7327 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7328 case GL_NUM_EXTENSIONS:
7329 case GL_MAJOR_VERSION:
7330 case GL_MINOR_VERSION:
7331 case GL_MAX_ELEMENTS_INDICES:
7332 case GL_MAX_ELEMENTS_VERTICES:
7333 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7334 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7335 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7336 case GL_UNPACK_IMAGE_HEIGHT:
7337 case GL_UNPACK_SKIP_IMAGES:
7338 {
7339 *type = GL_INT;
7340 *numParams = 1;
7341 return true;
7342 }
7343
7344 case GL_MAX_ELEMENT_INDEX:
7345 case GL_MAX_UNIFORM_BLOCK_SIZE:
7346 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7347 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7348 case GL_MAX_SERVER_WAIT_TIMEOUT:
7349 {
7350 *type = GL_INT_64_ANGLEX;
7351 *numParams = 1;
7352 return true;
7353 }
7354
7355 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7356 case GL_TRANSFORM_FEEDBACK_PAUSED:
7357 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7358 case GL_RASTERIZER_DISCARD:
7359 {
7360 *type = GL_BOOL;
7361 *numParams = 1;
7362 return true;
7363 }
7364
7365 case GL_MAX_TEXTURE_LOD_BIAS:
7366 {
7367 *type = GL_FLOAT;
7368 *numParams = 1;
7369 return true;
7370 }
7371 }
7372
7373 if (getExtensions().requestExtension)
7374 {
7375 switch (pname)
7376 {
7377 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7378 *type = GL_INT;
7379 *numParams = 1;
7380 return true;
7381 }
7382 }
7383
7384 if (getClientVersion() < Version(3, 1))
7385 {
7386 return false;
7387 }
7388
7389 switch (pname)
7390 {
7391 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7392 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7393 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7394 case GL_MAX_FRAMEBUFFER_WIDTH:
7395 case GL_MAX_FRAMEBUFFER_HEIGHT:
7396 case GL_MAX_FRAMEBUFFER_SAMPLES:
7397 case GL_MAX_SAMPLE_MASK_WORDS:
7398 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7399 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7400 case GL_MAX_INTEGER_SAMPLES:
7401 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7402 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7403 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7404 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7405 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7406 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7407 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7408 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7409 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7410 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7411 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7412 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7413 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7414 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7415 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7416 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7417 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7418 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7419 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7420 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7421 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7422 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7423 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7424 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7425 case GL_MAX_UNIFORM_LOCATIONS:
7426 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7427 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7428 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7429 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7430 case GL_MAX_IMAGE_UNITS:
7431 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7432 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7433 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7434 case GL_SHADER_STORAGE_BUFFER_BINDING:
7435 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7436 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7437 *type = GL_INT;
7438 *numParams = 1;
7439 return true;
7440 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7441 *type = GL_INT_64_ANGLEX;
7442 *numParams = 1;
7443 return true;
7444 case GL_SAMPLE_MASK:
7445 *type = GL_BOOL;
7446 *numParams = 1;
7447 return true;
7448 }
7449
7450 if (getExtensions().geometryShader)
7451 {
7452 switch (pname)
7453 {
7454 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7455 case GL_LAYER_PROVOKING_VERTEX_EXT:
7456 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7457 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7458 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7459 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7460 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7461 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7462 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7463 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7464 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7465 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7466 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7467 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7468 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7469 *type = GL_INT;
7470 *numParams = 1;
7471 return true;
7472 }
7473 }
7474
7475 return false;
7476}
7477
7478bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7479{
7480 if (getClientVersion() < Version(3, 0))
7481 {
7482 return false;
7483 }
7484
7485 switch (target)
7486 {
7487 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7488 case GL_UNIFORM_BUFFER_BINDING:
7489 {
7490 *type = GL_INT;
7491 *numParams = 1;
7492 return true;
7493 }
7494 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7495 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7496 case GL_UNIFORM_BUFFER_START:
7497 case GL_UNIFORM_BUFFER_SIZE:
7498 {
7499 *type = GL_INT_64_ANGLEX;
7500 *numParams = 1;
7501 return true;
7502 }
7503 }
7504
7505 if (getClientVersion() < Version(3, 1))
7506 {
7507 return false;
7508 }
7509
7510 switch (target)
7511 {
7512 case GL_IMAGE_BINDING_LAYERED:
7513 {
7514 *type = GL_BOOL;
7515 *numParams = 1;
7516 return true;
7517 }
7518 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7519 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7520 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7521 case GL_SHADER_STORAGE_BUFFER_BINDING:
7522 case GL_VERTEX_BINDING_BUFFER:
7523 case GL_VERTEX_BINDING_DIVISOR:
7524 case GL_VERTEX_BINDING_OFFSET:
7525 case GL_VERTEX_BINDING_STRIDE:
7526 case GL_SAMPLE_MASK_VALUE:
7527 case GL_IMAGE_BINDING_NAME:
7528 case GL_IMAGE_BINDING_LEVEL:
7529 case GL_IMAGE_BINDING_LAYER:
7530 case GL_IMAGE_BINDING_ACCESS:
7531 case GL_IMAGE_BINDING_FORMAT:
7532 {
7533 *type = GL_INT;
7534 *numParams = 1;
7535 return true;
7536 }
7537 case GL_ATOMIC_COUNTER_BUFFER_START:
7538 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7539 case GL_SHADER_STORAGE_BUFFER_START:
7540 case GL_SHADER_STORAGE_BUFFER_SIZE:
7541 {
7542 *type = GL_INT_64_ANGLEX;
7543 *numParams = 1;
7544 return true;
7545 }
7546 }
7547
7548 return false;
7549}
7550
7551Program *Context::getProgram(GLuint handle) const
7552{
7553 return mState.mShaderPrograms->getProgram(handle);
7554}
7555
7556Shader *Context::getShader(GLuint handle) const
7557{
7558 return mState.mShaderPrograms->getShader(handle);
7559}
7560
7561bool Context::isTextureGenerated(GLuint texture) const
7562{
7563 return mState.mTextures->isHandleGenerated(texture);
7564}
7565
7566bool Context::isBufferGenerated(GLuint buffer) const
7567{
7568 return mState.mBuffers->isHandleGenerated(buffer);
7569}
7570
7571bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7572{
7573 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7574}
7575
7576bool Context::isFramebufferGenerated(GLuint framebuffer) const
7577{
7578 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7579}
7580
7581bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7582{
7583 return mState.mPipelines->isHandleGenerated(pipeline);
7584}
7585
7586bool Context::usingDisplayTextureShareGroup() const
7587{
7588 return mDisplayTextureShareGroup;
7589}
7590
7591GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7592{
7593 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7594 internalformat == GL_DEPTH_STENCIL
7595 ? GL_DEPTH24_STENCIL8
7596 : internalformat;
7597}
7598
jchen1082af6202018-06-22 10:59:52 +08007599void Context::maxShaderCompilerThreads(GLuint count)
7600{
jchen107ae70d82018-07-06 13:47:01 +08007601 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08007602 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007603 // A count of zero specifies a request for no parallel compiling or linking.
7604 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7605 {
7606 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7607 }
7608 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007609}
7610
Jamie Madill2eb65032018-07-30 10:25:57 -04007611bool Context::isGLES1() const
7612{
7613 return mState.getClientVersion() < Version(2, 0);
7614}
7615
Jamie Madilla11819d2018-07-30 10:26:01 -04007616void Context::onSubjectStateChange(const Context *context,
7617 angle::SubjectIndex index,
7618 angle::SubjectMessage message)
7619{
Jamie Madilla11819d2018-07-30 10:26:01 -04007620 switch (index)
7621 {
7622 case kVertexArraySubjectIndex:
7623 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
Jamie Madillc43cdad2018-08-08 15:49:25 -04007624 mStateCache.onVertexArraySizeChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04007625 break;
7626
7627 case kReadFramebufferSubjectIndex:
7628 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
7629 break;
7630
7631 case kDrawFramebufferSubjectIndex:
7632 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
7633 break;
7634
7635 default:
Jamie Madill6c43a012018-08-08 15:49:27 -04007636 ASSERT(index < mGLState.getActiveTexturesCache().size());
7637 mGLState.onActiveTextureStateChange(index);
Jamie Madilla11819d2018-07-30 10:26:01 -04007638 break;
7639 }
7640}
7641
Jamie Madill6b873dd2018-07-12 23:56:30 -04007642// ErrorSet implementation.
7643ErrorSet::ErrorSet(Context *context) : mContext(context)
7644{
7645}
7646
7647ErrorSet::~ErrorSet() = default;
7648
Jamie Madill306b6c12018-07-27 08:12:49 -04007649void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007650{
7651 // This internal enum is used to filter internal errors that are already handled.
7652 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7653 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7654 {
7655 return;
7656 }
7657
7658 if (ANGLE_UNLIKELY(error.isError()))
7659 {
7660 GLenum code = error.getCode();
7661 mErrors.insert(code);
7662 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7663 {
7664 mContext->markContextLost();
7665 }
7666
7667 ASSERT(!error.getMessage().empty());
7668 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7669 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7670 error.getMessage());
7671 }
7672}
7673
7674bool ErrorSet::empty() const
7675{
7676 return mErrors.empty();
7677}
7678
7679GLenum ErrorSet::popError()
7680{
7681 ASSERT(!empty());
7682 GLenum error = *mErrors.begin();
7683 mErrors.erase(mErrors.begin());
7684 return error;
7685}
Jamie Madilldc358af2018-07-31 11:22:13 -04007686
7687// StateCache implementation.
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007688StateCache::StateCache()
7689 : mCachedHasAnyEnabledClientAttrib(false),
7690 mCachedNonInstancedVertexElementLimit(0),
7691 mCachedInstancedVertexElementLimit(0)
Jamie Madilldc358af2018-07-31 11:22:13 -04007692{
7693}
7694
7695StateCache::~StateCache() = default;
7696
7697void StateCache::updateActiveAttribsMask(Context *context)
7698{
7699 bool isGLES1 = context->isGLES1();
7700 const State &glState = context->getGLState();
7701
7702 if (!isGLES1 && !glState.getProgram())
7703 {
7704 mCachedActiveBufferedAttribsMask = AttributesMask();
7705 mCachedActiveClientAttribsMask = AttributesMask();
7706 return;
7707 }
7708
7709 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7710 : glState.getProgram()->getActiveAttribLocationsMask();
7711
7712 const VertexArray *vao = glState.getVertexArray();
7713 ASSERT(vao);
7714
7715 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7716 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
7717
7718 activeAttribs &= enabledAttribs;
7719
7720 mCachedActiveClientAttribsMask = activeAttribs & clientAttribs;
7721 mCachedActiveBufferedAttribsMask = activeAttribs & ~clientAttribs;
7722 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7723}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007724
7725void StateCache::updateVertexElementLimits(Context *context)
7726{
7727 const VertexArray *vao = context->getGLState().getVertexArray();
7728
7729 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7730 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7731
7732 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
7733 // If there are no buffered attributes then we should not limit the draw call count.
7734 if (!vao || !mCachedActiveBufferedAttribsMask.any())
7735 {
7736 return;
7737 }
7738
7739 const auto &vertexAttribs = vao->getVertexAttributes();
7740 const auto &vertexBindings = vao->getVertexBindings();
7741
7742 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
7743 {
7744 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
7745 ASSERT(attrib.enabled);
7746
7747 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
7748 ASSERT(context->isGLES1() ||
7749 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
7750
7751 GLint64 limit = attrib.getCachedElementLimit();
7752 if (binding.getDivisor() > 0)
7753 {
7754 mCachedInstancedVertexElementLimit =
7755 std::min(mCachedInstancedVertexElementLimit, limit);
7756 }
7757 else
7758 {
7759 mCachedNonInstancedVertexElementLimit =
7760 std::min(mCachedNonInstancedVertexElementLimit, limit);
7761 }
7762 }
7763}
Jamie Madillc43cdad2018-08-08 15:49:25 -04007764
7765void StateCache::onVertexArrayBindingChange(Context *context)
7766{
7767 updateActiveAttribsMask(context);
7768 updateVertexElementLimits(context);
7769}
7770
7771void StateCache::onProgramExecutableChange(Context *context)
7772{
7773 updateActiveAttribsMask(context);
7774 updateVertexElementLimits(context);
7775}
7776
7777void StateCache::onVertexArraySizeChange(Context *context)
7778{
7779 updateVertexElementLimits(context);
7780}
7781
7782void StateCache::onVertexArrayStateChange(Context *context)
7783{
7784 updateActiveAttribsMask(context);
7785 updateVertexElementLimits(context);
7786}
7787
7788void StateCache::onGLES1ClientStateChange(Context *context)
7789{
7790 updateActiveAttribsMask(context);
7791}
Jamie Madillc29968b2016-01-20 11:17:23 -05007792} // namespace gl