blob: 0549048c8391e7a026f63fe8bee5db5b22bea28c [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);
464
465 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
466 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
467 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
468
Jamie Madillc67323a2017-11-02 23:11:41 -0400469 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500470 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500471 // No dirty objects.
472
473 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400474 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500475 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400476 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500477 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
478
479 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
480 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
481 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
482 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
483 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
484 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
485 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
486 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
487 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
488 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
489 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400490 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500491 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
492
493 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
494 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700495 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400496 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
497 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500498 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
499 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400500
Xinghua Cao10a4d432017-11-28 14:46:26 +0800501 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
502 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
503 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
504 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
505 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
506 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800507 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800508 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800509
Jamie Madillb4927eb2018-07-16 11:39:46 -0400510 mImplementation->setErrorSet(&mErrors);
511
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400512 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000513}
514
Jamie Madill4928b7c2017-06-20 12:57:39 -0400515egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000516{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700517 if (mGLES1Renderer)
518 {
519 mGLES1Renderer->onDestroy(this, &mGLState);
520 }
521
Jamie Madille7b3fe22018-04-05 09:42:46 -0400522 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400523 ANGLE_TRY(releaseSurface(display));
524
Corentin Wallez80b24112015-08-25 16:41:57 -0400525 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000526 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400527 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000528 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400529 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000530
Corentin Wallez80b24112015-08-25 16:41:57 -0400531 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000532 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400533 if (query.second != nullptr)
534 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400535 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400536 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000537 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400538 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000539
Corentin Wallez80b24112015-08-25 16:41:57 -0400540 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400541 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400542 if (vertexArray.second)
543 {
544 vertexArray.second->onDestroy(this);
545 }
Jamie Madill57a89722013-07-02 11:57:03 -0400546 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400547 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400548
Corentin Wallez80b24112015-08-25 16:41:57 -0400549 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500550 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500551 if (transformFeedback.second != nullptr)
552 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500553 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500554 }
Geoff Langc8058452014-02-03 12:04:11 -0500555 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400556 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500557
Jamie Madill5b772312018-03-08 20:28:32 -0500558 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400559 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800560 if (zeroTexture.get() != nullptr)
561 {
562 ANGLE_TRY(zeroTexture->onDestroy(this));
563 zeroTexture.set(this, nullptr);
564 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400565 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000566
Jamie Madill2f348d22017-06-05 10:50:59 -0400567 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500568
Jamie Madill4928b7c2017-06-20 12:57:39 -0400569 mGLState.reset(this);
570
Jamie Madill6c1f6712017-02-14 19:08:04 -0500571 mState.mBuffers->release(this);
572 mState.mShaderPrograms->release(this);
573 mState.mTextures->release(this);
574 mState.mRenderbuffers->release(this);
575 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400576 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500577 mState.mPaths->release(this);
578 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800579 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400580
jchen107ae70d82018-07-06 13:47:01 +0800581 mThreadPool.reset();
582
Jamie Madill76e471e2017-10-21 09:56:01 -0400583 mImplementation->onDestroy(this);
584
Jamie Madill4928b7c2017-06-20 12:57:39 -0400585 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000586}
587
Jamie Madill70ee0f62017-02-06 16:04:20 -0500588Context::~Context()
589{
590}
591
Geoff Lang75359662018-04-11 01:42:27 -0400592void Context::setLabel(EGLLabelKHR label)
593{
594 mLabel = label;
595}
596
597EGLLabelKHR Context::getLabel() const
598{
599 return mLabel;
600}
601
Jamie Madill4928b7c2017-06-20 12:57:39 -0400602egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000603{
Jamie Madill61e16b42017-06-19 11:13:23 -0400604 mCurrentDisplay = display;
605
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000606 if (!mHasBeenCurrent)
607 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400608 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000609 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500610 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400611 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000612
Corentin Wallezc295e512017-01-27 17:47:50 -0500613 int width = 0;
614 int height = 0;
615 if (surface != nullptr)
616 {
617 width = surface->getWidth();
618 height = surface->getHeight();
619 }
620
621 mGLState.setViewportParams(0, 0, width, height);
622 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000623
624 mHasBeenCurrent = true;
625 }
626
Jamie Madill1b94d432015-08-07 13:23:23 -0400627 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700628 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400629 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400630
Jamie Madill4928b7c2017-06-20 12:57:39 -0400631 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500632
633 Framebuffer *newDefault = nullptr;
634 if (surface != nullptr)
635 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400636 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500637 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400638 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500639 }
640 else
641 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400642 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500643 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000644
Corentin Wallez37c39792015-08-20 14:19:46 -0400645 // Update default framebuffer, the binding of the previous default
646 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400647 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400648 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700649 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400650 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400651 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400652 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700653 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400654 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400655 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400656 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400657 }
Ian Ewell292f0052016-02-04 10:37:32 -0500658
659 // Notify the renderer of a context switch
Luc Ferron5396f2a2018-07-12 08:24:23 -0400660 ANGLE_TRY(mImplementation->onMakeCurrent(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400661 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000662}
663
Jamie Madill4928b7c2017-06-20 12:57:39 -0400664egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400665{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400666 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400667
Geoff Langbf7b95d2018-05-01 16:48:21 -0400668 // Remove the default framebuffer
669 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500670 {
671 mGLState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400672 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500673 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400674
675 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500676 {
677 mGLState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400678 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500679 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400680
681 if (defaultFramebuffer)
682 {
683 defaultFramebuffer->onDestroy(this);
684 delete defaultFramebuffer;
685 }
686
Corentin Wallezc295e512017-01-27 17:47:50 -0500687 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
688
689 if (mCurrentSurface)
690 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400691 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500692 mCurrentSurface = nullptr;
693 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400694
695 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400696}
697
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000698GLuint Context::createBuffer()
699{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500700 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000701}
702
703GLuint Context::createProgram()
704{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500705 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000706}
707
Jiawei Shao385b3e02018-03-21 09:43:28 +0800708GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000709{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500710 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000711}
712
713GLuint Context::createTexture()
714{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500715 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000716}
717
718GLuint Context::createRenderbuffer()
719{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500720 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000721}
722
Brandon Jones59770802018-04-02 13:18:42 -0700723GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300724{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500725 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300726 if (resultOrError.isError())
727 {
728 handleError(resultOrError.getError());
729 return 0;
730 }
731 return resultOrError.getResult();
732}
733
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000734// Returns an unused framebuffer name
735GLuint Context::createFramebuffer()
736{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500737 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000738}
739
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500740void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000741{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500742 for (int i = 0; i < n; i++)
743 {
744 GLuint handle = mFenceNVHandleAllocator.allocate();
745 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
746 fences[i] = handle;
747 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000748}
749
Yunchao Hea336b902017-08-02 16:05:21 +0800750GLuint Context::createProgramPipeline()
751{
752 return mState.mPipelines->createProgramPipeline();
753}
754
Jiawei Shao385b3e02018-03-21 09:43:28 +0800755GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800756{
757 UNIMPLEMENTED();
758 return 0u;
759}
760
James Darpinian4d9d4832018-03-13 12:43:28 -0700761void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000762{
James Darpinian4d9d4832018-03-13 12:43:28 -0700763 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
764 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000765 {
766 detachBuffer(buffer);
767 }
Jamie Madill893ab082014-05-16 16:56:10 -0400768
James Darpinian4d9d4832018-03-13 12:43:28 -0700769 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000770}
771
772void Context::deleteShader(GLuint shader)
773{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500774 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000775}
776
777void Context::deleteProgram(GLuint program)
778{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500779 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000780}
781
782void Context::deleteTexture(GLuint texture)
783{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500784 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000785 {
786 detachTexture(texture);
787 }
788
Jamie Madill6c1f6712017-02-14 19:08:04 -0500789 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000790}
791
792void Context::deleteRenderbuffer(GLuint renderbuffer)
793{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500794 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000795 {
796 detachRenderbuffer(renderbuffer);
797 }
Jamie Madill893ab082014-05-16 16:56:10 -0400798
Jamie Madill6c1f6712017-02-14 19:08:04 -0500799 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000800}
801
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400802void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400803{
804 // The spec specifies the underlying Fence object is not deleted until all current
805 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
806 // and since our API is currently designed for being called from a single thread, we can delete
807 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400808 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400809}
810
Yunchao Hea336b902017-08-02 16:05:21 +0800811void Context::deleteProgramPipeline(GLuint pipeline)
812{
813 if (mState.mPipelines->getProgramPipeline(pipeline))
814 {
815 detachProgramPipeline(pipeline);
816 }
817
818 mState.mPipelines->deleteObject(this, pipeline);
819}
820
Sami Väisänene45e53b2016-05-25 10:36:04 +0300821void Context::deletePaths(GLuint first, GLsizei range)
822{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500823 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300824}
825
Brandon Jones59770802018-04-02 13:18:42 -0700826bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300827{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500828 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300829 if (pathObj == nullptr)
830 return false;
831
832 return pathObj->hasPathData();
833}
834
Brandon Jones59770802018-04-02 13:18:42 -0700835bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300836{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500837 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300838}
839
Brandon Jones59770802018-04-02 13:18:42 -0700840void Context::pathCommands(GLuint path,
841 GLsizei numCommands,
842 const GLubyte *commands,
843 GLsizei numCoords,
844 GLenum coordType,
845 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300846{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500847 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300848
849 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
850}
851
Jamie Madill007530e2017-12-28 14:27:04 -0500852void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300853{
Jamie Madill007530e2017-12-28 14:27:04 -0500854 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300855
856 switch (pname)
857 {
858 case GL_PATH_STROKE_WIDTH_CHROMIUM:
859 pathObj->setStrokeWidth(value);
860 break;
861 case GL_PATH_END_CAPS_CHROMIUM:
862 pathObj->setEndCaps(static_cast<GLenum>(value));
863 break;
864 case GL_PATH_JOIN_STYLE_CHROMIUM:
865 pathObj->setJoinStyle(static_cast<GLenum>(value));
866 break;
867 case GL_PATH_MITER_LIMIT_CHROMIUM:
868 pathObj->setMiterLimit(value);
869 break;
870 case GL_PATH_STROKE_BOUND_CHROMIUM:
871 pathObj->setStrokeBound(value);
872 break;
873 default:
874 UNREACHABLE();
875 break;
876 }
877}
878
Jamie Madill007530e2017-12-28 14:27:04 -0500879void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300880{
Jamie Madill007530e2017-12-28 14:27:04 -0500881 // TODO(jmadill): Should use proper clamping/casting.
882 pathParameterf(path, pname, static_cast<GLfloat>(value));
883}
884
885void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
886{
887 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300888
889 switch (pname)
890 {
891 case GL_PATH_STROKE_WIDTH_CHROMIUM:
892 *value = pathObj->getStrokeWidth();
893 break;
894 case GL_PATH_END_CAPS_CHROMIUM:
895 *value = static_cast<GLfloat>(pathObj->getEndCaps());
896 break;
897 case GL_PATH_JOIN_STYLE_CHROMIUM:
898 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
899 break;
900 case GL_PATH_MITER_LIMIT_CHROMIUM:
901 *value = pathObj->getMiterLimit();
902 break;
903 case GL_PATH_STROKE_BOUND_CHROMIUM:
904 *value = pathObj->getStrokeBound();
905 break;
906 default:
907 UNREACHABLE();
908 break;
909 }
910}
911
Jamie Madill007530e2017-12-28 14:27:04 -0500912void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
913{
914 GLfloat val = 0.0f;
915 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
916 if (value)
917 *value = static_cast<GLint>(val);
918}
919
Brandon Jones59770802018-04-02 13:18:42 -0700920void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300921{
922 mGLState.setPathStencilFunc(func, ref, mask);
923}
924
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000925void Context::deleteFramebuffer(GLuint framebuffer)
926{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500927 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000928 {
929 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000930 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500931
Jamie Madill6c1f6712017-02-14 19:08:04 -0500932 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000933}
934
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500935void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000936{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500937 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000938 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500939 GLuint fence = fences[i];
940
941 FenceNV *fenceObject = nullptr;
942 if (mFenceNVMap.erase(fence, &fenceObject))
943 {
944 mFenceNVHandleAllocator.release(fence);
945 delete fenceObject;
946 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000947 }
948}
949
Geoff Lang70d0f492015-12-10 17:45:46 -0500950Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000951{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500952 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000953}
954
Jamie Madill570f7c82014-07-03 10:38:54 -0400955Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000956{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500957 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000958}
959
Geoff Lang70d0f492015-12-10 17:45:46 -0500960Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000961{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500962 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000963}
964
Jamie Madill70b5bb02017-08-28 13:32:37 -0400965Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400966{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400967 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400968}
969
Jamie Madill57a89722013-07-02 11:57:03 -0400970VertexArray *Context::getVertexArray(GLuint handle) const
971{
Jamie Madill96a483b2017-06-27 16:49:21 -0400972 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400973}
974
Jamie Madilldc356042013-07-19 16:36:57 -0400975Sampler *Context::getSampler(GLuint handle) const
976{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500977 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400978}
979
Geoff Langc8058452014-02-03 12:04:11 -0500980TransformFeedback *Context::getTransformFeedback(GLuint handle) const
981{
Jamie Madill96a483b2017-06-27 16:49:21 -0400982 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500983}
984
Yunchao Hea336b902017-08-02 16:05:21 +0800985ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
986{
987 return mState.mPipelines->getProgramPipeline(handle);
988}
989
Geoff Lang75359662018-04-11 01:42:27 -0400990gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500991{
992 switch (identifier)
993 {
994 case GL_BUFFER:
995 return getBuffer(name);
996 case GL_SHADER:
997 return getShader(name);
998 case GL_PROGRAM:
999 return getProgram(name);
1000 case GL_VERTEX_ARRAY:
1001 return getVertexArray(name);
1002 case GL_QUERY:
1003 return getQuery(name);
1004 case GL_TRANSFORM_FEEDBACK:
1005 return getTransformFeedback(name);
1006 case GL_SAMPLER:
1007 return getSampler(name);
1008 case GL_TEXTURE:
1009 return getTexture(name);
1010 case GL_RENDERBUFFER:
1011 return getRenderbuffer(name);
1012 case GL_FRAMEBUFFER:
1013 return getFramebuffer(name);
1014 default:
1015 UNREACHABLE();
1016 return nullptr;
1017 }
1018}
1019
Geoff Lang75359662018-04-11 01:42:27 -04001020gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001021{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001022 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001023}
1024
Martin Radev9d901792016-07-15 15:58:58 +03001025void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1026{
Geoff Lang75359662018-04-11 01:42:27 -04001027 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001028 ASSERT(object != nullptr);
1029
1030 std::string labelName = GetObjectLabelFromPointer(length, label);
1031 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001032
1033 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1034 // specified object is active until we do this.
1035 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001036}
1037
1038void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1039{
Geoff Lang75359662018-04-11 01:42:27 -04001040 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001041 ASSERT(object != nullptr);
1042
1043 std::string labelName = GetObjectLabelFromPointer(length, label);
1044 object->setLabel(labelName);
1045}
1046
1047void Context::getObjectLabel(GLenum identifier,
1048 GLuint name,
1049 GLsizei bufSize,
1050 GLsizei *length,
1051 GLchar *label) const
1052{
Geoff Lang75359662018-04-11 01:42:27 -04001053 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001054 ASSERT(object != nullptr);
1055
1056 const std::string &objectLabel = object->getLabel();
1057 GetObjectLabelBase(objectLabel, bufSize, length, label);
1058}
1059
1060void Context::getObjectPtrLabel(const void *ptr,
1061 GLsizei bufSize,
1062 GLsizei *length,
1063 GLchar *label) const
1064{
Geoff Lang75359662018-04-11 01:42:27 -04001065 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001066 ASSERT(object != nullptr);
1067
1068 const std::string &objectLabel = object->getLabel();
1069 GetObjectLabelBase(objectLabel, bufSize, length, label);
1070}
1071
Jamie Madilldc356042013-07-19 16:36:57 -04001072bool Context::isSampler(GLuint samplerName) const
1073{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001074 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001075}
1076
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001077void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001078{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001079 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001080
Jamie Madilldedd7b92014-11-05 16:30:36 -05001081 if (handle == 0)
1082 {
1083 texture = mZeroTextures[target].get();
1084 }
1085 else
1086 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001087 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001088 }
1089
1090 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001091 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001092}
1093
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001094void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001095{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001096 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1097 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001098 mGLState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001099 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001100}
1101
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001102void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001103{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001104 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1105 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001106 mGLState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001107 mDrawFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001108}
1109
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001110void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001111{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001112 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001113 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001114 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001115 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001116}
1117
Shao80957d92017-02-20 21:25:59 +08001118void Context::bindVertexBuffer(GLuint bindingIndex,
1119 GLuint bufferHandle,
1120 GLintptr offset,
1121 GLsizei stride)
1122{
1123 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001124 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001125 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001126}
1127
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001128void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001129{
Geoff Lang76b10c92014-09-05 16:28:14 -04001130 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001131 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001132 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001133 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001134}
1135
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001136void Context::bindImageTexture(GLuint unit,
1137 GLuint texture,
1138 GLint level,
1139 GLboolean layered,
1140 GLint layer,
1141 GLenum access,
1142 GLenum format)
1143{
1144 Texture *tex = mState.mTextures->getTexture(texture);
1145 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1146}
1147
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001148void Context::useProgram(GLuint program)
1149{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001150 mGLState.setProgram(this, getProgram(program));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001151 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001152}
1153
Jiajia Qin5451d532017-11-16 17:16:34 +08001154void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1155{
1156 UNIMPLEMENTED();
1157}
1158
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001159void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001160{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001161 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001162 TransformFeedback *transformFeedback =
1163 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001164 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001165}
1166
Yunchao Hea336b902017-08-02 16:05:21 +08001167void Context::bindProgramPipeline(GLuint pipelineHandle)
1168{
1169 ProgramPipeline *pipeline =
1170 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1171 mGLState.setProgramPipelineBinding(this, pipeline);
1172}
1173
Corentin Wallezad3ae902018-03-09 13:40:42 -05001174void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001175{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001176 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001177 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001178
Geoff Lang5aad9672014-09-08 11:10:42 -04001179 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001180 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001181
1182 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001183 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001184}
1185
Corentin Wallezad3ae902018-03-09 13:40:42 -05001186void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001187{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001188 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001189 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001190
Jamie Madill5188a272018-07-25 10:53:56 -04001191 handleError(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001192
Geoff Lang5aad9672014-09-08 11:10:42 -04001193 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001194 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001195}
1196
Corentin Wallezad3ae902018-03-09 13:40:42 -05001197void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001198{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001199 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001200
1201 Query *queryObject = getQuery(id, true, target);
1202 ASSERT(queryObject);
1203
Jamie Madill5188a272018-07-25 10:53:56 -04001204 handleError(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001205}
1206
Corentin Wallezad3ae902018-03-09 13:40:42 -05001207void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001208{
1209 switch (pname)
1210 {
1211 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001212 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001213 break;
1214 case GL_QUERY_COUNTER_BITS_EXT:
1215 switch (target)
1216 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001217 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001218 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1219 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001220 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001221 params[0] = getExtensions().queryCounterBitsTimestamp;
1222 break;
1223 default:
1224 UNREACHABLE();
1225 params[0] = 0;
1226 break;
1227 }
1228 break;
1229 default:
1230 UNREACHABLE();
1231 return;
1232 }
1233}
1234
Corentin Wallezad3ae902018-03-09 13:40:42 -05001235void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001236 GLenum pname,
1237 GLsizei bufSize,
1238 GLsizei *length,
1239 GLint *params)
1240{
1241 getQueryiv(target, pname, params);
1242}
1243
Geoff Lang2186c382016-10-14 10:54:54 -04001244void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001245{
Jamie Madill5188a272018-07-25 10:53:56 -04001246 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001247}
1248
Brandon Jones59770802018-04-02 13:18:42 -07001249void Context::getQueryObjectivRobust(GLuint id,
1250 GLenum pname,
1251 GLsizei bufSize,
1252 GLsizei *length,
1253 GLint *params)
1254{
1255 getQueryObjectiv(id, pname, params);
1256}
1257
Geoff Lang2186c382016-10-14 10:54:54 -04001258void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001259{
Jamie Madill5188a272018-07-25 10:53:56 -04001260 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001261}
1262
Brandon Jones59770802018-04-02 13:18:42 -07001263void Context::getQueryObjectuivRobust(GLuint id,
1264 GLenum pname,
1265 GLsizei bufSize,
1266 GLsizei *length,
1267 GLuint *params)
1268{
1269 getQueryObjectuiv(id, pname, params);
1270}
1271
Geoff Lang2186c382016-10-14 10:54:54 -04001272void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001273{
Jamie Madill5188a272018-07-25 10:53:56 -04001274 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001275}
1276
Brandon Jones59770802018-04-02 13:18:42 -07001277void Context::getQueryObjecti64vRobust(GLuint id,
1278 GLenum pname,
1279 GLsizei bufSize,
1280 GLsizei *length,
1281 GLint64 *params)
1282{
1283 getQueryObjecti64v(id, pname, params);
1284}
1285
Geoff Lang2186c382016-10-14 10:54:54 -04001286void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001287{
Jamie Madill5188a272018-07-25 10:53:56 -04001288 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001289}
1290
Brandon Jones59770802018-04-02 13:18:42 -07001291void Context::getQueryObjectui64vRobust(GLuint id,
1292 GLenum pname,
1293 GLsizei bufSize,
1294 GLsizei *length,
1295 GLuint64 *params)
1296{
1297 getQueryObjectui64v(id, pname, params);
1298}
1299
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001300Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001301{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001302 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001303}
1304
Jamie Madill2f348d22017-06-05 10:50:59 -04001305FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001306{
Jamie Madill96a483b2017-06-27 16:49:21 -04001307 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001308}
1309
Corentin Wallezad3ae902018-03-09 13:40:42 -05001310Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001311{
Jamie Madill96a483b2017-06-27 16:49:21 -04001312 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001313 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001314 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001315 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001316
1317 Query *query = mQueryMap.query(handle);
1318 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001319 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001320 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001321 query = new Query(mImplementation->createQuery(type), handle);
1322 query->addRef();
1323 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001324 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001325 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001326}
1327
Geoff Lang70d0f492015-12-10 17:45:46 -05001328Query *Context::getQuery(GLuint handle) const
1329{
Jamie Madill96a483b2017-06-27 16:49:21 -04001330 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001331}
1332
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001333Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001334{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001335 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1336 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001337}
1338
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001339Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001340{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001341 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001342}
1343
Geoff Lang492a7e42014-11-05 13:27:06 -05001344Compiler *Context::getCompiler() const
1345{
Jamie Madill2f348d22017-06-05 10:50:59 -04001346 if (mCompiler.get() == nullptr)
1347 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001348 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001349 }
1350 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001351}
1352
Jamie Madillc1d770e2017-04-13 17:31:24 -04001353void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001354{
1355 switch (pname)
1356 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001357 case GL_SHADER_COMPILER:
1358 *params = GL_TRUE;
1359 break;
1360 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1361 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1362 break;
1363 default:
1364 mGLState.getBooleanv(pname, params);
1365 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001366 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001367}
1368
Jamie Madillc1d770e2017-04-13 17:31:24 -04001369void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001370{
Shannon Woods53a94a82014-06-24 15:20:36 -04001371 // Queries about context capabilities and maximums are answered by Context.
1372 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001373 switch (pname)
1374 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001375 case GL_ALIASED_LINE_WIDTH_RANGE:
1376 params[0] = mCaps.minAliasedLineWidth;
1377 params[1] = mCaps.maxAliasedLineWidth;
1378 break;
1379 case GL_ALIASED_POINT_SIZE_RANGE:
1380 params[0] = mCaps.minAliasedPointSize;
1381 params[1] = mCaps.maxAliasedPointSize;
1382 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001383 case GL_SMOOTH_POINT_SIZE_RANGE:
1384 params[0] = mCaps.minSmoothPointSize;
1385 params[1] = mCaps.maxSmoothPointSize;
1386 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001387 case GL_SMOOTH_LINE_WIDTH_RANGE:
1388 params[0] = mCaps.minSmoothLineWidth;
1389 params[1] = mCaps.maxSmoothLineWidth;
1390 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001391 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1392 ASSERT(mExtensions.textureFilterAnisotropic);
1393 *params = mExtensions.maxTextureAnisotropy;
1394 break;
1395 case GL_MAX_TEXTURE_LOD_BIAS:
1396 *params = mCaps.maxLODBias;
1397 break;
1398
1399 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1400 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1401 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001402 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1403 // GLES1 constants for modelview/projection matrix.
1404 if (getClientVersion() < Version(2, 0))
1405 {
1406 mGLState.getFloatv(pname, params);
1407 }
1408 else
1409 {
1410 ASSERT(mExtensions.pathRendering);
1411 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1412 memcpy(params, m, 16 * sizeof(GLfloat));
1413 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001414 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001415 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001416
Jamie Madill231c7f52017-04-26 13:45:37 -04001417 default:
1418 mGLState.getFloatv(pname, params);
1419 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001420 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001421}
1422
Jamie Madillc1d770e2017-04-13 17:31:24 -04001423void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001424{
Shannon Woods53a94a82014-06-24 15:20:36 -04001425 // Queries about context capabilities and maximums are answered by Context.
1426 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001427
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001428 switch (pname)
1429 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001430 case GL_MAX_VERTEX_ATTRIBS:
1431 *params = mCaps.maxVertexAttributes;
1432 break;
1433 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1434 *params = mCaps.maxVertexUniformVectors;
1435 break;
1436 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001437 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001438 break;
1439 case GL_MAX_VARYING_VECTORS:
1440 *params = mCaps.maxVaryingVectors;
1441 break;
1442 case GL_MAX_VARYING_COMPONENTS:
1443 *params = mCaps.maxVertexOutputComponents;
1444 break;
1445 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1446 *params = mCaps.maxCombinedTextureImageUnits;
1447 break;
1448 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001449 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001450 break;
1451 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001452 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001453 break;
1454 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1455 *params = mCaps.maxFragmentUniformVectors;
1456 break;
1457 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001458 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001459 break;
1460 case GL_MAX_RENDERBUFFER_SIZE:
1461 *params = mCaps.maxRenderbufferSize;
1462 break;
1463 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1464 *params = mCaps.maxColorAttachments;
1465 break;
1466 case GL_MAX_DRAW_BUFFERS_EXT:
1467 *params = mCaps.maxDrawBuffers;
1468 break;
1469 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1470 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1471 case GL_SUBPIXEL_BITS:
1472 *params = 4;
1473 break;
1474 case GL_MAX_TEXTURE_SIZE:
1475 *params = mCaps.max2DTextureSize;
1476 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001477 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1478 *params = mCaps.maxRectangleTextureSize;
1479 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001480 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1481 *params = mCaps.maxCubeMapTextureSize;
1482 break;
1483 case GL_MAX_3D_TEXTURE_SIZE:
1484 *params = mCaps.max3DTextureSize;
1485 break;
1486 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1487 *params = mCaps.maxArrayTextureLayers;
1488 break;
1489 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1490 *params = mCaps.uniformBufferOffsetAlignment;
1491 break;
1492 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1493 *params = mCaps.maxUniformBufferBindings;
1494 break;
1495 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001496 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001497 break;
1498 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001499 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001500 break;
1501 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1502 *params = mCaps.maxCombinedTextureImageUnits;
1503 break;
1504 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1505 *params = mCaps.maxVertexOutputComponents;
1506 break;
1507 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1508 *params = mCaps.maxFragmentInputComponents;
1509 break;
1510 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1511 *params = mCaps.minProgramTexelOffset;
1512 break;
1513 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1514 *params = mCaps.maxProgramTexelOffset;
1515 break;
1516 case GL_MAJOR_VERSION:
1517 *params = getClientVersion().major;
1518 break;
1519 case GL_MINOR_VERSION:
1520 *params = getClientVersion().minor;
1521 break;
1522 case GL_MAX_ELEMENTS_INDICES:
1523 *params = mCaps.maxElementsIndices;
1524 break;
1525 case GL_MAX_ELEMENTS_VERTICES:
1526 *params = mCaps.maxElementsVertices;
1527 break;
1528 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1529 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1530 break;
1531 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1532 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1533 break;
1534 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1535 *params = mCaps.maxTransformFeedbackSeparateComponents;
1536 break;
1537 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1538 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1539 break;
1540 case GL_MAX_SAMPLES_ANGLE:
1541 *params = mCaps.maxSamples;
1542 break;
1543 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001544 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001545 params[0] = mCaps.maxViewportWidth;
1546 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001547 }
1548 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001549 case GL_COMPRESSED_TEXTURE_FORMATS:
1550 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1551 params);
1552 break;
1553 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1554 *params = mResetStrategy;
1555 break;
1556 case GL_NUM_SHADER_BINARY_FORMATS:
1557 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1558 break;
1559 case GL_SHADER_BINARY_FORMATS:
1560 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1561 break;
1562 case GL_NUM_PROGRAM_BINARY_FORMATS:
1563 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1564 break;
1565 case GL_PROGRAM_BINARY_FORMATS:
1566 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1567 break;
1568 case GL_NUM_EXTENSIONS:
1569 *params = static_cast<GLint>(mExtensionStrings.size());
1570 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001571
Jamie Madill231c7f52017-04-26 13:45:37 -04001572 // GL_KHR_debug
1573 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1574 *params = mExtensions.maxDebugMessageLength;
1575 break;
1576 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1577 *params = mExtensions.maxDebugLoggedMessages;
1578 break;
1579 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1580 *params = mExtensions.maxDebugGroupStackDepth;
1581 break;
1582 case GL_MAX_LABEL_LENGTH:
1583 *params = mExtensions.maxLabelLength;
1584 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001585
Martin Radeve5285d22017-07-14 16:23:53 +03001586 // GL_ANGLE_multiview
1587 case GL_MAX_VIEWS_ANGLE:
1588 *params = mExtensions.maxViews;
1589 break;
1590
Jamie Madill231c7f52017-04-26 13:45:37 -04001591 // GL_EXT_disjoint_timer_query
1592 case GL_GPU_DISJOINT_EXT:
1593 *params = mImplementation->getGPUDisjoint();
1594 break;
1595 case GL_MAX_FRAMEBUFFER_WIDTH:
1596 *params = mCaps.maxFramebufferWidth;
1597 break;
1598 case GL_MAX_FRAMEBUFFER_HEIGHT:
1599 *params = mCaps.maxFramebufferHeight;
1600 break;
1601 case GL_MAX_FRAMEBUFFER_SAMPLES:
1602 *params = mCaps.maxFramebufferSamples;
1603 break;
1604 case GL_MAX_SAMPLE_MASK_WORDS:
1605 *params = mCaps.maxSampleMaskWords;
1606 break;
1607 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1608 *params = mCaps.maxColorTextureSamples;
1609 break;
1610 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1611 *params = mCaps.maxDepthTextureSamples;
1612 break;
1613 case GL_MAX_INTEGER_SAMPLES:
1614 *params = mCaps.maxIntegerSamples;
1615 break;
1616 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1617 *params = mCaps.maxVertexAttribRelativeOffset;
1618 break;
1619 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1620 *params = mCaps.maxVertexAttribBindings;
1621 break;
1622 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1623 *params = mCaps.maxVertexAttribStride;
1624 break;
1625 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001626 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001627 break;
1628 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001629 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001630 break;
1631 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001632 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001633 break;
1634 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001635 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001636 break;
1637 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001638 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001639 break;
1640 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001641 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001642 break;
1643 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001644 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001645 break;
1646 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001647 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001648 break;
1649 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1650 *params = mCaps.minProgramTextureGatherOffset;
1651 break;
1652 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1653 *params = mCaps.maxProgramTextureGatherOffset;
1654 break;
1655 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1656 *params = mCaps.maxComputeWorkGroupInvocations;
1657 break;
1658 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001659 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001660 break;
1661 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001662 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001663 break;
1664 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1665 *params = mCaps.maxComputeSharedMemorySize;
1666 break;
1667 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001668 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001669 break;
1670 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001671 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001672 break;
1673 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001674 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001675 break;
1676 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001677 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001678 break;
1679 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001680 *params =
1681 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001682 break;
1683 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001684 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001685 break;
1686 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1687 *params = mCaps.maxCombinedShaderOutputResources;
1688 break;
1689 case GL_MAX_UNIFORM_LOCATIONS:
1690 *params = mCaps.maxUniformLocations;
1691 break;
1692 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1693 *params = mCaps.maxAtomicCounterBufferBindings;
1694 break;
1695 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1696 *params = mCaps.maxAtomicCounterBufferSize;
1697 break;
1698 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1699 *params = mCaps.maxCombinedAtomicCounterBuffers;
1700 break;
1701 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1702 *params = mCaps.maxCombinedAtomicCounters;
1703 break;
1704 case GL_MAX_IMAGE_UNITS:
1705 *params = mCaps.maxImageUnits;
1706 break;
1707 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1708 *params = mCaps.maxCombinedImageUniforms;
1709 break;
1710 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1711 *params = mCaps.maxShaderStorageBufferBindings;
1712 break;
1713 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1714 *params = mCaps.maxCombinedShaderStorageBlocks;
1715 break;
1716 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1717 *params = mCaps.shaderStorageBufferOffsetAlignment;
1718 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001719
1720 // GL_EXT_geometry_shader
1721 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1722 *params = mCaps.maxFramebufferLayers;
1723 break;
1724 case GL_LAYER_PROVOKING_VERTEX_EXT:
1725 *params = mCaps.layerProvokingVertex;
1726 break;
1727 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001728 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001729 break;
1730 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001731 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001732 break;
1733 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001734 *params =
1735 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001736 break;
1737 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1738 *params = mCaps.maxGeometryInputComponents;
1739 break;
1740 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1741 *params = mCaps.maxGeometryOutputComponents;
1742 break;
1743 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1744 *params = mCaps.maxGeometryOutputVertices;
1745 break;
1746 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1747 *params = mCaps.maxGeometryTotalOutputComponents;
1748 break;
1749 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1750 *params = mCaps.maxGeometryShaderInvocations;
1751 break;
1752 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001753 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001754 break;
1755 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001756 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001757 break;
1758 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001759 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001760 break;
1761 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001762 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001763 break;
1764 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001765 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001766 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001767 // GLES1 emulation: Caps queries
1768 case GL_MAX_TEXTURE_UNITS:
1769 *params = mCaps.maxMultitextureUnits;
1770 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001771 case GL_MAX_MODELVIEW_STACK_DEPTH:
1772 *params = mCaps.maxModelviewMatrixStackDepth;
1773 break;
1774 case GL_MAX_PROJECTION_STACK_DEPTH:
1775 *params = mCaps.maxProjectionMatrixStackDepth;
1776 break;
1777 case GL_MAX_TEXTURE_STACK_DEPTH:
1778 *params = mCaps.maxTextureMatrixStackDepth;
1779 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001780 case GL_MAX_LIGHTS:
1781 *params = mCaps.maxLights;
1782 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001783 case GL_MAX_CLIP_PLANES:
1784 *params = mCaps.maxClipPlanes;
1785 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001786 // GLES1 emulation: Vertex attribute queries
1787 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1788 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1789 case GL_COLOR_ARRAY_BUFFER_BINDING:
1790 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1791 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1792 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1793 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1794 break;
1795 case GL_VERTEX_ARRAY_STRIDE:
1796 case GL_NORMAL_ARRAY_STRIDE:
1797 case GL_COLOR_ARRAY_STRIDE:
1798 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1799 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1800 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1801 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1802 break;
1803 case GL_VERTEX_ARRAY_SIZE:
1804 case GL_COLOR_ARRAY_SIZE:
1805 case GL_TEXTURE_COORD_ARRAY_SIZE:
1806 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1807 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1808 break;
1809 case GL_VERTEX_ARRAY_TYPE:
1810 case GL_COLOR_ARRAY_TYPE:
1811 case GL_NORMAL_ARRAY_TYPE:
1812 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1813 case GL_TEXTURE_COORD_ARRAY_TYPE:
1814 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1815 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1816 break;
1817
jchen1082af6202018-06-22 10:59:52 +08001818 // GL_KHR_parallel_shader_compile
1819 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1820 *params = mGLState.getMaxShaderCompilerThreads();
1821 break;
1822
Jamie Madill231c7f52017-04-26 13:45:37 -04001823 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001824 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001825 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001826 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001827}
1828
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001829void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001830{
Shannon Woods53a94a82014-06-24 15:20:36 -04001831 // Queries about context capabilities and maximums are answered by Context.
1832 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001833 switch (pname)
1834 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001835 case GL_MAX_ELEMENT_INDEX:
1836 *params = mCaps.maxElementIndex;
1837 break;
1838 case GL_MAX_UNIFORM_BLOCK_SIZE:
1839 *params = mCaps.maxUniformBlockSize;
1840 break;
1841 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001842 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001843 break;
1844 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001845 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001846 break;
1847 case GL_MAX_SERVER_WAIT_TIMEOUT:
1848 *params = mCaps.maxServerWaitTimeout;
1849 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001850
Jamie Madill231c7f52017-04-26 13:45:37 -04001851 // GL_EXT_disjoint_timer_query
1852 case GL_TIMESTAMP_EXT:
1853 *params = mImplementation->getTimestamp();
1854 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001855
Jamie Madill231c7f52017-04-26 13:45:37 -04001856 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1857 *params = mCaps.maxShaderStorageBlockSize;
1858 break;
1859 default:
1860 UNREACHABLE();
1861 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001862 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001863}
1864
Geoff Lang70d0f492015-12-10 17:45:46 -05001865void Context::getPointerv(GLenum pname, void **params) const
1866{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001867 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001868}
1869
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001870void Context::getPointervRobustANGLERobust(GLenum pname,
1871 GLsizei bufSize,
1872 GLsizei *length,
1873 void **params)
1874{
1875 UNIMPLEMENTED();
1876}
1877
Martin Radev66fb8202016-07-28 11:45:20 +03001878void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001879{
Shannon Woods53a94a82014-06-24 15:20:36 -04001880 // Queries about context capabilities and maximums are answered by Context.
1881 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001882
1883 GLenum nativeType;
1884 unsigned int numParams;
1885 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1886 ASSERT(queryStatus);
1887
1888 if (nativeType == GL_INT)
1889 {
1890 switch (target)
1891 {
1892 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1893 ASSERT(index < 3u);
1894 *data = mCaps.maxComputeWorkGroupCount[index];
1895 break;
1896 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1897 ASSERT(index < 3u);
1898 *data = mCaps.maxComputeWorkGroupSize[index];
1899 break;
1900 default:
1901 mGLState.getIntegeri_v(target, index, data);
1902 }
1903 }
1904 else
1905 {
1906 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1907 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001908}
1909
Brandon Jones59770802018-04-02 13:18:42 -07001910void Context::getIntegeri_vRobust(GLenum target,
1911 GLuint index,
1912 GLsizei bufSize,
1913 GLsizei *length,
1914 GLint *data)
1915{
1916 getIntegeri_v(target, index, data);
1917}
1918
Martin Radev66fb8202016-07-28 11:45:20 +03001919void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001920{
Shannon Woods53a94a82014-06-24 15:20:36 -04001921 // Queries about context capabilities and maximums are answered by Context.
1922 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001923
1924 GLenum nativeType;
1925 unsigned int numParams;
1926 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1927 ASSERT(queryStatus);
1928
1929 if (nativeType == GL_INT_64_ANGLEX)
1930 {
1931 mGLState.getInteger64i_v(target, index, data);
1932 }
1933 else
1934 {
1935 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1936 }
1937}
1938
Brandon Jones59770802018-04-02 13:18:42 -07001939void Context::getInteger64i_vRobust(GLenum target,
1940 GLuint index,
1941 GLsizei bufSize,
1942 GLsizei *length,
1943 GLint64 *data)
1944{
1945 getInteger64i_v(target, index, data);
1946}
1947
Martin Radev66fb8202016-07-28 11:45:20 +03001948void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1949{
1950 // Queries about context capabilities and maximums are answered by Context.
1951 // Queries about current GL state values are answered by State.
1952
1953 GLenum nativeType;
1954 unsigned int numParams;
1955 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1956 ASSERT(queryStatus);
1957
1958 if (nativeType == GL_BOOL)
1959 {
1960 mGLState.getBooleani_v(target, index, data);
1961 }
1962 else
1963 {
1964 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1965 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001966}
1967
Brandon Jones59770802018-04-02 13:18:42 -07001968void Context::getBooleani_vRobust(GLenum target,
1969 GLuint index,
1970 GLsizei bufSize,
1971 GLsizei *length,
1972 GLboolean *data)
1973{
1974 getBooleani_v(target, index, data);
1975}
1976
Corentin Wallez336129f2017-10-17 15:55:40 -04001977void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001978{
1979 Buffer *buffer = mGLState.getTargetBuffer(target);
1980 QueryBufferParameteriv(buffer, pname, params);
1981}
1982
Brandon Jones59770802018-04-02 13:18:42 -07001983void Context::getBufferParameterivRobust(BufferBinding target,
1984 GLenum pname,
1985 GLsizei bufSize,
1986 GLsizei *length,
1987 GLint *params)
1988{
1989 getBufferParameteriv(target, pname, params);
1990}
1991
He Yunchao010e4db2017-03-03 14:22:06 +08001992void Context::getFramebufferAttachmentParameteriv(GLenum target,
1993 GLenum attachment,
1994 GLenum pname,
1995 GLint *params)
1996{
1997 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001998 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001999}
2000
Brandon Jones59770802018-04-02 13:18:42 -07002001void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2002 GLenum attachment,
2003 GLenum pname,
2004 GLsizei bufSize,
2005 GLsizei *length,
2006 GLint *params)
2007{
2008 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2009}
2010
He Yunchao010e4db2017-03-03 14:22:06 +08002011void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2012{
2013 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2014 QueryRenderbufferiv(this, renderbuffer, pname, params);
2015}
2016
Brandon Jones59770802018-04-02 13:18:42 -07002017void Context::getRenderbufferParameterivRobust(GLenum target,
2018 GLenum pname,
2019 GLsizei bufSize,
2020 GLsizei *length,
2021 GLint *params)
2022{
2023 getRenderbufferParameteriv(target, pname, params);
2024}
2025
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002026void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002027{
2028 Texture *texture = getTargetTexture(target);
2029 QueryTexParameterfv(texture, pname, params);
2030}
2031
Brandon Jones59770802018-04-02 13:18:42 -07002032void Context::getTexParameterfvRobust(TextureType target,
2033 GLenum pname,
2034 GLsizei bufSize,
2035 GLsizei *length,
2036 GLfloat *params)
2037{
2038 getTexParameterfv(target, pname, params);
2039}
2040
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002041void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002042{
2043 Texture *texture = getTargetTexture(target);
2044 QueryTexParameteriv(texture, pname, params);
2045}
Jiajia Qin5451d532017-11-16 17:16:34 +08002046
Brandon Jones59770802018-04-02 13:18:42 -07002047void Context::getTexParameterivRobust(TextureType target,
2048 GLenum pname,
2049 GLsizei bufSize,
2050 GLsizei *length,
2051 GLint *params)
2052{
2053 getTexParameteriv(target, pname, params);
2054}
2055
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002056void Context::getTexParameterIivRobust(TextureType target,
2057 GLenum pname,
2058 GLsizei bufSize,
2059 GLsizei *length,
2060 GLint *params)
2061{
2062 UNIMPLEMENTED();
2063}
2064
2065void Context::getTexParameterIuivRobust(TextureType target,
2066 GLenum pname,
2067 GLsizei bufSize,
2068 GLsizei *length,
2069 GLuint *params)
2070{
2071 UNIMPLEMENTED();
2072}
2073
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002074void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002075{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002076 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002077 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002078}
2079
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002080void Context::getTexLevelParameterivRobust(TextureTarget target,
2081 GLint level,
2082 GLenum pname,
2083 GLsizei bufSize,
2084 GLsizei *length,
2085 GLint *params)
2086{
2087 UNIMPLEMENTED();
2088}
2089
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002090void Context::getTexLevelParameterfv(TextureTarget target,
2091 GLint level,
2092 GLenum pname,
2093 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002094{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002095 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002096 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002097}
2098
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002099void Context::getTexLevelParameterfvRobust(TextureTarget target,
2100 GLint level,
2101 GLenum pname,
2102 GLsizei bufSize,
2103 GLsizei *length,
2104 GLfloat *params)
2105{
2106 UNIMPLEMENTED();
2107}
2108
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002109void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002110{
2111 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002112 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002113 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002114}
2115
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002116void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002117{
2118 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002119 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002120 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002121}
2122
Brandon Jones59770802018-04-02 13:18:42 -07002123void Context::texParameterfvRobust(TextureType target,
2124 GLenum pname,
2125 GLsizei bufSize,
2126 const GLfloat *params)
2127{
2128 texParameterfv(target, pname, params);
2129}
2130
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002131void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002132{
2133 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002134 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002135 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002136}
2137
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002138void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002139{
2140 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002141 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002142 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002143}
2144
Brandon Jones59770802018-04-02 13:18:42 -07002145void Context::texParameterivRobust(TextureType target,
2146 GLenum pname,
2147 GLsizei bufSize,
2148 const GLint *params)
2149{
2150 texParameteriv(target, pname, params);
2151}
2152
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002153void Context::texParameterIivRobust(TextureType target,
2154 GLenum pname,
2155 GLsizei bufSize,
2156 const GLint *params)
2157{
2158 UNIMPLEMENTED();
2159}
2160
2161void Context::texParameterIuivRobust(TextureType target,
2162 GLenum pname,
2163 GLsizei bufSize,
2164 const GLuint *params)
2165{
2166 UNIMPLEMENTED();
2167}
2168
Jamie Madill493f9572018-05-24 19:52:15 -04002169void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002170{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002171 // No-op if count draws no primitives for given mode
2172 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002173 {
2174 return;
2175 }
2176
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002177 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002178 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002179 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002180}
2181
Jamie Madill493f9572018-05-24 19:52:15 -04002182void Context::drawArraysInstanced(PrimitiveMode mode,
2183 GLint first,
2184 GLsizei count,
2185 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002186{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002187 // No-op if count draws no primitives for given mode
2188 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002189 {
2190 return;
2191 }
2192
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002193 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002194 ANGLE_CONTEXT_TRY(
2195 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002196 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2197 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002198}
2199
Jamie Madill493f9572018-05-24 19:52:15 -04002200void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002201{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002202 // No-op if count draws no primitives for given mode
2203 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002204 {
2205 return;
2206 }
2207
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002208 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002209 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002210}
2211
Jamie Madill493f9572018-05-24 19:52:15 -04002212void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002213 GLsizei count,
2214 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002215 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002216 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002217{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002218 // No-op if count draws no primitives for given mode
2219 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002220 {
2221 return;
2222 }
2223
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002224 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002225 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002226 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002227}
2228
Jamie Madill493f9572018-05-24 19:52:15 -04002229void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002230 GLuint start,
2231 GLuint end,
2232 GLsizei count,
2233 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002234 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002235{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002236 // No-op if count draws no primitives for given mode
2237 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002238 {
2239 return;
2240 }
2241
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002242 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002243 ANGLE_CONTEXT_TRY(
2244 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002245}
2246
Jamie Madill493f9572018-05-24 19:52:15 -04002247void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002248{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002249 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002250 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002251}
2252
Jamie Madill493f9572018-05-24 19:52:15 -04002253void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002254{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002255 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002256 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002257}
2258
Jamie Madill675fe712016-12-19 13:07:54 -05002259void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002260{
Jamie Madillafa02a22017-11-23 12:57:38 -05002261 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002262}
2263
Jamie Madill675fe712016-12-19 13:07:54 -05002264void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002265{
Jamie Madillafa02a22017-11-23 12:57:38 -05002266 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002267}
2268
Austin Kinross6ee1e782015-05-29 17:05:37 -07002269void Context::insertEventMarker(GLsizei length, const char *marker)
2270{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002271 ASSERT(mImplementation);
2272 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002273}
2274
2275void Context::pushGroupMarker(GLsizei length, const char *marker)
2276{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002277 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002278
2279 if (marker == nullptr)
2280 {
2281 // From the EXT_debug_marker spec,
2282 // "If <marker> is null then an empty string is pushed on the stack."
2283 mImplementation->pushGroupMarker(length, "");
2284 }
2285 else
2286 {
2287 mImplementation->pushGroupMarker(length, marker);
2288 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002289}
2290
2291void Context::popGroupMarker()
2292{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002293 ASSERT(mImplementation);
2294 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002295}
2296
Geoff Langd8605522016-04-13 10:19:12 -04002297void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2298{
2299 Program *programObject = getProgram(program);
2300 ASSERT(programObject);
2301
2302 programObject->bindUniformLocation(location, name);
2303}
2304
Brandon Jones59770802018-04-02 13:18:42 -07002305void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002306{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002307 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002308}
2309
Brandon Jones59770802018-04-02 13:18:42 -07002310void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002311{
2312 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2313}
2314
Brandon Jones59770802018-04-02 13:18:42 -07002315void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002316{
2317 GLfloat I[16];
2318 angle::Matrix<GLfloat>::setToIdentity(I);
2319
2320 mGLState.loadPathRenderingMatrix(matrixMode, I);
2321}
2322
2323void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2324{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002325 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002326 if (!pathObj)
2327 return;
2328
Geoff Lang9bf86f02018-07-26 11:46:34 -04002329 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002330
2331 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2332}
2333
2334void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2335{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002336 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002337 if (!pathObj)
2338 return;
2339
Geoff Lang9bf86f02018-07-26 11:46:34 -04002340 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002341
2342 mImplementation->stencilStrokePath(pathObj, reference, mask);
2343}
2344
2345void Context::coverFillPath(GLuint path, GLenum coverMode)
2346{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002347 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002348 if (!pathObj)
2349 return;
2350
Geoff Lang9bf86f02018-07-26 11:46:34 -04002351 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002352
2353 mImplementation->coverFillPath(pathObj, coverMode);
2354}
2355
2356void Context::coverStrokePath(GLuint path, GLenum coverMode)
2357{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002358 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002359 if (!pathObj)
2360 return;
2361
Geoff Lang9bf86f02018-07-26 11:46:34 -04002362 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002363
2364 mImplementation->coverStrokePath(pathObj, coverMode);
2365}
2366
2367void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2368{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002369 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002370 if (!pathObj)
2371 return;
2372
Geoff Lang9bf86f02018-07-26 11:46:34 -04002373 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002374
2375 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2376}
2377
2378void Context::stencilThenCoverStrokePath(GLuint path,
2379 GLint reference,
2380 GLuint mask,
2381 GLenum coverMode)
2382{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002383 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002384 if (!pathObj)
2385 return;
2386
Geoff Lang9bf86f02018-07-26 11:46:34 -04002387 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002388
2389 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2390}
2391
Sami Väisänend59ca052016-06-21 16:10:00 +03002392void Context::coverFillPathInstanced(GLsizei numPaths,
2393 GLenum pathNameType,
2394 const void *paths,
2395 GLuint pathBase,
2396 GLenum coverMode,
2397 GLenum transformType,
2398 const GLfloat *transformValues)
2399{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002400 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002401
Geoff Lang9bf86f02018-07-26 11:46:34 -04002402 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002403
2404 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2405}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002406
Sami Väisänend59ca052016-06-21 16:10:00 +03002407void Context::coverStrokePathInstanced(GLsizei numPaths,
2408 GLenum pathNameType,
2409 const void *paths,
2410 GLuint pathBase,
2411 GLenum coverMode,
2412 GLenum transformType,
2413 const GLfloat *transformValues)
2414{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002415 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002416
2417 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002418 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002419
2420 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2421 transformValues);
2422}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002423
Sami Väisänend59ca052016-06-21 16:10:00 +03002424void Context::stencilFillPathInstanced(GLsizei numPaths,
2425 GLenum pathNameType,
2426 const void *paths,
2427 GLuint pathBase,
2428 GLenum fillMode,
2429 GLuint mask,
2430 GLenum transformType,
2431 const GLfloat *transformValues)
2432{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002433 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002434
2435 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002436 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002437
2438 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2439 transformValues);
2440}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002441
Sami Väisänend59ca052016-06-21 16:10:00 +03002442void Context::stencilStrokePathInstanced(GLsizei numPaths,
2443 GLenum pathNameType,
2444 const void *paths,
2445 GLuint pathBase,
2446 GLint reference,
2447 GLuint mask,
2448 GLenum transformType,
2449 const GLfloat *transformValues)
2450{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002451 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002452
Geoff Lang9bf86f02018-07-26 11:46:34 -04002453 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002454
2455 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2456 transformValues);
2457}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002458
Sami Väisänend59ca052016-06-21 16:10:00 +03002459void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2460 GLenum pathNameType,
2461 const void *paths,
2462 GLuint pathBase,
2463 GLenum fillMode,
2464 GLuint mask,
2465 GLenum coverMode,
2466 GLenum transformType,
2467 const GLfloat *transformValues)
2468{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002469 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002470
Geoff Lang9bf86f02018-07-26 11:46:34 -04002471 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002472
2473 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2474 transformType, transformValues);
2475}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002476
Sami Väisänend59ca052016-06-21 16:10:00 +03002477void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2478 GLenum pathNameType,
2479 const void *paths,
2480 GLuint pathBase,
2481 GLint reference,
2482 GLuint mask,
2483 GLenum coverMode,
2484 GLenum transformType,
2485 const GLfloat *transformValues)
2486{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002487 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002488
Geoff Lang9bf86f02018-07-26 11:46:34 -04002489 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002490
2491 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2492 transformType, transformValues);
2493}
2494
Sami Väisänen46eaa942016-06-29 10:26:37 +03002495void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2496{
2497 auto *programObject = getProgram(program);
2498
2499 programObject->bindFragmentInputLocation(location, name);
2500}
2501
2502void Context::programPathFragmentInputGen(GLuint program,
2503 GLint location,
2504 GLenum genMode,
2505 GLint components,
2506 const GLfloat *coeffs)
2507{
2508 auto *programObject = getProgram(program);
2509
jchen103fd614d2018-08-13 12:21:58 +08002510 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002511}
2512
jchen1015015f72017-03-16 13:54:21 +08002513GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2514{
jchen10fd7c3b52017-03-21 15:36:03 +08002515 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002516 return QueryProgramResourceIndex(programObject, programInterface, name);
2517}
2518
jchen10fd7c3b52017-03-21 15:36:03 +08002519void Context::getProgramResourceName(GLuint program,
2520 GLenum programInterface,
2521 GLuint index,
2522 GLsizei bufSize,
2523 GLsizei *length,
2524 GLchar *name)
2525{
2526 const auto *programObject = getProgram(program);
2527 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2528}
2529
jchen10191381f2017-04-11 13:59:04 +08002530GLint Context::getProgramResourceLocation(GLuint program,
2531 GLenum programInterface,
2532 const GLchar *name)
2533{
2534 const auto *programObject = getProgram(program);
2535 return QueryProgramResourceLocation(programObject, programInterface, name);
2536}
2537
jchen10880683b2017-04-12 16:21:55 +08002538void Context::getProgramResourceiv(GLuint program,
2539 GLenum programInterface,
2540 GLuint index,
2541 GLsizei propCount,
2542 const GLenum *props,
2543 GLsizei bufSize,
2544 GLsizei *length,
2545 GLint *params)
2546{
2547 const auto *programObject = getProgram(program);
2548 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2549 length, params);
2550}
2551
jchen10d9cd7b72017-08-30 15:04:25 +08002552void Context::getProgramInterfaceiv(GLuint program,
2553 GLenum programInterface,
2554 GLenum pname,
2555 GLint *params)
2556{
2557 const auto *programObject = getProgram(program);
2558 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2559}
2560
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002561void Context::getProgramInterfaceivRobust(GLuint program,
2562 GLenum programInterface,
2563 GLenum pname,
2564 GLsizei bufSize,
2565 GLsizei *length,
2566 GLint *params)
2567{
2568 UNIMPLEMENTED();
2569}
2570
Jamie Madill306b6c12018-07-27 08:12:49 -04002571void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002572{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002573 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002574}
2575
2576// Get one of the recorded errors and clear its flag, if any.
2577// [OpenGL ES 2.0.24] section 2.5 page 13.
2578GLenum Context::getError()
2579{
Geoff Langda5777c2014-07-11 09:52:58 -04002580 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002581 {
Geoff Langda5777c2014-07-11 09:52:58 -04002582 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002583 }
Geoff Langda5777c2014-07-11 09:52:58 -04002584 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002585 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002586 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002587 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002588}
2589
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002590// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002591void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002592{
2593 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002594 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002595 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002596 mContextLostForced = true;
2597 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002598 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002599}
2600
Jamie Madill427064d2018-04-13 16:20:34 -04002601bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002602{
2603 return mContextLost;
2604}
2605
Jamie Madillfa920eb2018-01-04 11:45:50 -05002606GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002607{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002608 // Even if the application doesn't want to know about resets, we want to know
2609 // as it will allow us to skip all the calls.
2610 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002611 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002612 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002613 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002614 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002615 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002616
2617 // EXT_robustness, section 2.6: If the reset notification behavior is
2618 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2619 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2620 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002621 }
2622
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002623 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2624 // status should be returned at least once, and GL_NO_ERROR should be returned
2625 // once the device has finished resetting.
2626 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002627 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002628 ASSERT(mResetStatus == GL_NO_ERROR);
2629 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002630
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002631 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002632 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002633 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002634 }
2635 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002636 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002637 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002638 // If markContextLost was used to mark the context lost then
2639 // assume that is not recoverable, and continue to report the
2640 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002641 mResetStatus = mImplementation->getResetStatus();
2642 }
Jamie Madill893ab082014-05-16 16:56:10 -04002643
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002644 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002645}
2646
2647bool Context::isResetNotificationEnabled()
2648{
2649 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2650}
2651
Corentin Walleze3b10e82015-05-20 11:06:25 -04002652const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002653{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002654 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002655}
2656
2657EGLenum Context::getClientType() const
2658{
2659 return mClientType;
2660}
2661
2662EGLenum Context::getRenderBuffer() const
2663{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002664 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2665 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002666 {
2667 return EGL_NONE;
2668 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002669
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002670 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002671 ASSERT(backAttachment != nullptr);
2672 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002673}
2674
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002675VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002676{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002677 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002678 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2679 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002680 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002681 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2682 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002683
Jamie Madill96a483b2017-06-27 16:49:21 -04002684 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002685 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002686
2687 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002688}
2689
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002690TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002691{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002692 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002693 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2694 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002695 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002696 transformFeedback =
2697 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002698 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002699 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002700 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002701
2702 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002703}
2704
2705bool Context::isVertexArrayGenerated(GLuint vertexArray)
2706{
Jamie Madill96a483b2017-06-27 16:49:21 -04002707 ASSERT(mVertexArrayMap.contains(0));
2708 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002709}
2710
2711bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2712{
Jamie Madill96a483b2017-06-27 16:49:21 -04002713 ASSERT(mTransformFeedbackMap.contains(0));
2714 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002715}
2716
Shannon Woods53a94a82014-06-24 15:20:36 -04002717void Context::detachTexture(GLuint texture)
2718{
2719 // Simple pass-through to State's detachTexture method, as textures do not require
2720 // allocation map management either here or in the resource manager at detach time.
2721 // Zero textures are held by the Context, and we don't attempt to request them from
2722 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002723 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002724}
2725
James Darpinian4d9d4832018-03-13 12:43:28 -07002726void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002727{
Yuly Novikov5807a532015-12-03 13:01:22 -05002728 // Simple pass-through to State's detachBuffer method, since
2729 // only buffer attachments to container objects that are bound to the current context
2730 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002731
Yuly Novikov5807a532015-12-03 13:01:22 -05002732 // [OpenGL ES 3.2] section 5.1.2 page 45:
2733 // Attachments to unbound container objects, such as
2734 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2735 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002736 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002737}
2738
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002739void Context::detachFramebuffer(GLuint framebuffer)
2740{
Shannon Woods53a94a82014-06-24 15:20:36 -04002741 // Framebuffer detachment is handled by Context, because 0 is a valid
2742 // Framebuffer object, and a pointer to it must be passed from Context
2743 // to State at binding time.
2744
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002745 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002746 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2747 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2748 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002749
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002750 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002751 {
2752 bindReadFramebuffer(0);
2753 }
2754
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002755 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002756 {
2757 bindDrawFramebuffer(0);
2758 }
2759}
2760
2761void Context::detachRenderbuffer(GLuint renderbuffer)
2762{
Jamie Madilla02315b2017-02-23 14:14:47 -05002763 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002764}
2765
Jamie Madill57a89722013-07-02 11:57:03 -04002766void Context::detachVertexArray(GLuint vertexArray)
2767{
Jamie Madill77a72f62015-04-14 11:18:32 -04002768 // Vertex array detachment is handled by Context, because 0 is a valid
2769 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002770 // binding time.
2771
Jamie Madill57a89722013-07-02 11:57:03 -04002772 // [OpenGL ES 3.0.2] section 2.10 page 43:
2773 // If a vertex array object that is currently bound is deleted, the binding
2774 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002775 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002776 {
2777 bindVertexArray(0);
2778 }
2779}
2780
Geoff Langc8058452014-02-03 12:04:11 -05002781void Context::detachTransformFeedback(GLuint transformFeedback)
2782{
Corentin Walleza2257da2016-04-19 16:43:12 -04002783 // Transform feedback detachment is handled by Context, because 0 is a valid
2784 // transform feedback, and a pointer to it must be passed from Context to State at
2785 // binding time.
2786
2787 // The OpenGL specification doesn't mention what should happen when the currently bound
2788 // transform feedback object is deleted. Since it is a container object, we treat it like
2789 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002790 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002791 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002792 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002793 }
Geoff Langc8058452014-02-03 12:04:11 -05002794}
2795
Jamie Madilldc356042013-07-19 16:36:57 -04002796void Context::detachSampler(GLuint sampler)
2797{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002798 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002799}
2800
Yunchao Hea336b902017-08-02 16:05:21 +08002801void Context::detachProgramPipeline(GLuint pipeline)
2802{
2803 mGLState.detachProgramPipeline(this, pipeline);
2804}
2805
Jamie Madill3ef140a2017-08-26 23:11:21 -04002806void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002807{
Shaodde78e82017-05-22 14:13:27 +08002808 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002809 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002810}
2811
Jamie Madille29d1672013-07-19 16:36:57 -04002812void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2813{
Geoff Langc1984ed2016-10-07 12:41:00 -04002814 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002815 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002816 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002817 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002818}
Jamie Madille29d1672013-07-19 16:36:57 -04002819
Geoff Langc1984ed2016-10-07 12:41:00 -04002820void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2821{
2822 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002823 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002824 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002825 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002826}
2827
Brandon Jones59770802018-04-02 13:18:42 -07002828void Context::samplerParameterivRobust(GLuint sampler,
2829 GLenum pname,
2830 GLsizei bufSize,
2831 const GLint *param)
2832{
2833 samplerParameteriv(sampler, pname, param);
2834}
2835
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002836void Context::samplerParameterIivRobust(GLuint sampler,
2837 GLenum pname,
2838 GLsizei bufSize,
2839 const GLint *param)
2840{
2841 UNIMPLEMENTED();
2842}
2843
2844void Context::samplerParameterIuivRobust(GLuint sampler,
2845 GLenum pname,
2846 GLsizei bufSize,
2847 const GLuint *param)
2848{
2849 UNIMPLEMENTED();
2850}
2851
Jamie Madille29d1672013-07-19 16:36:57 -04002852void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2853{
Geoff Langc1984ed2016-10-07 12:41:00 -04002854 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002855 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002856 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002857 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002858}
2859
Geoff Langc1984ed2016-10-07 12:41:00 -04002860void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002861{
Geoff Langc1984ed2016-10-07 12:41:00 -04002862 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002863 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002864 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002865 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002866}
2867
Brandon Jones59770802018-04-02 13:18:42 -07002868void Context::samplerParameterfvRobust(GLuint sampler,
2869 GLenum pname,
2870 GLsizei bufSize,
2871 const GLfloat *param)
2872{
2873 samplerParameterfv(sampler, pname, param);
2874}
2875
Geoff Langc1984ed2016-10-07 12:41:00 -04002876void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002877{
Geoff Langc1984ed2016-10-07 12:41:00 -04002878 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002879 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002880 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002881 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002882}
Jamie Madill9675b802013-07-19 16:36:59 -04002883
Brandon Jones59770802018-04-02 13:18:42 -07002884void Context::getSamplerParameterivRobust(GLuint sampler,
2885 GLenum pname,
2886 GLsizei bufSize,
2887 GLsizei *length,
2888 GLint *params)
2889{
2890 getSamplerParameteriv(sampler, pname, params);
2891}
2892
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002893void Context::getSamplerParameterIivRobust(GLuint sampler,
2894 GLenum pname,
2895 GLsizei bufSize,
2896 GLsizei *length,
2897 GLint *params)
2898{
2899 UNIMPLEMENTED();
2900}
2901
2902void Context::getSamplerParameterIuivRobust(GLuint sampler,
2903 GLenum pname,
2904 GLsizei bufSize,
2905 GLsizei *length,
2906 GLuint *params)
2907{
2908 UNIMPLEMENTED();
2909}
2910
Geoff Langc1984ed2016-10-07 12:41:00 -04002911void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2912{
2913 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002914 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002915 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002916 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002917}
2918
Brandon Jones59770802018-04-02 13:18:42 -07002919void Context::getSamplerParameterfvRobust(GLuint sampler,
2920 GLenum pname,
2921 GLsizei bufSize,
2922 GLsizei *length,
2923 GLfloat *params)
2924{
2925 getSamplerParameterfv(sampler, pname, params);
2926}
2927
Olli Etuahof0fee072016-03-30 15:11:58 +03002928void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2929{
2930 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002931 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002932}
2933
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002934void Context::initRendererString()
2935{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002936 std::ostringstream rendererString;
2937 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002938 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002939 rendererString << ")";
2940
Geoff Langcec35902014-04-16 10:52:36 -04002941 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002942}
2943
Geoff Langc339c4e2016-11-29 10:37:36 -05002944void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002945{
Geoff Langc339c4e2016-11-29 10:37:36 -05002946 const Version &clientVersion = getClientVersion();
2947
2948 std::ostringstream versionString;
2949 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2950 << ANGLE_VERSION_STRING << ")";
2951 mVersionString = MakeStaticString(versionString.str());
2952
2953 std::ostringstream shadingLanguageVersionString;
2954 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2955 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2956 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2957 << ")";
2958 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002959}
2960
Geoff Langcec35902014-04-16 10:52:36 -04002961void Context::initExtensionStrings()
2962{
Geoff Langc339c4e2016-11-29 10:37:36 -05002963 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2964 std::ostringstream combinedStringStream;
2965 std::copy(strings.begin(), strings.end(),
2966 std::ostream_iterator<const char *>(combinedStringStream, " "));
2967 return MakeStaticString(combinedStringStream.str());
2968 };
2969
2970 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002971 for (const auto &extensionString : mExtensions.getStrings())
2972 {
2973 mExtensionStrings.push_back(MakeStaticString(extensionString));
2974 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002975 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002976
Geoff Langc339c4e2016-11-29 10:37:36 -05002977 mRequestableExtensionStrings.clear();
2978 for (const auto &extensionInfo : GetExtensionInfoMap())
2979 {
2980 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002981 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002982 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002983 {
2984 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2985 }
2986 }
2987 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002988}
2989
Geoff Langc339c4e2016-11-29 10:37:36 -05002990const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002991{
Geoff Langc339c4e2016-11-29 10:37:36 -05002992 switch (name)
2993 {
2994 case GL_VENDOR:
2995 return reinterpret_cast<const GLubyte *>("Google Inc.");
2996
2997 case GL_RENDERER:
2998 return reinterpret_cast<const GLubyte *>(mRendererString);
2999
3000 case GL_VERSION:
3001 return reinterpret_cast<const GLubyte *>(mVersionString);
3002
3003 case GL_SHADING_LANGUAGE_VERSION:
3004 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3005
3006 case GL_EXTENSIONS:
3007 return reinterpret_cast<const GLubyte *>(mExtensionString);
3008
3009 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3010 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3011
3012 default:
3013 UNREACHABLE();
3014 return nullptr;
3015 }
Geoff Langcec35902014-04-16 10:52:36 -04003016}
3017
Geoff Langc339c4e2016-11-29 10:37:36 -05003018const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003019{
Geoff Langc339c4e2016-11-29 10:37:36 -05003020 switch (name)
3021 {
3022 case GL_EXTENSIONS:
3023 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3024
3025 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3026 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3027
3028 default:
3029 UNREACHABLE();
3030 return nullptr;
3031 }
Geoff Langcec35902014-04-16 10:52:36 -04003032}
3033
3034size_t Context::getExtensionStringCount() const
3035{
3036 return mExtensionStrings.size();
3037}
3038
Geoff Lang111a99e2017-10-17 10:58:41 -04003039bool Context::isExtensionRequestable(const char *name)
3040{
3041 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3042 auto extension = extensionInfos.find(name);
3043
Geoff Lang111a99e2017-10-17 10:58:41 -04003044 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003045 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003046}
3047
Geoff Langc339c4e2016-11-29 10:37:36 -05003048void Context::requestExtension(const char *name)
3049{
3050 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3051 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3052 const auto &extension = extensionInfos.at(name);
3053 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003054 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003055
3056 if (mExtensions.*(extension.ExtensionsMember))
3057 {
3058 // Extension already enabled
3059 return;
3060 }
3061
3062 mExtensions.*(extension.ExtensionsMember) = true;
3063 updateCaps();
3064 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003065
Jamie Madill2f348d22017-06-05 10:50:59 -04003066 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3067 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003068
Jamie Madill81c2e252017-09-09 23:32:46 -04003069 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3070 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003071 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003072 for (auto &zeroTexture : mZeroTextures)
3073 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003074 if (zeroTexture.get() != nullptr)
3075 {
3076 zeroTexture->signalDirty(this, InitState::Initialized);
3077 }
Geoff Lang9aded172017-04-05 11:07:56 -04003078 }
3079
Jamie Madillb983a4b2018-08-01 11:34:51 -04003080 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003081}
3082
3083size_t Context::getRequestableExtensionStringCount() const
3084{
3085 return mRequestableExtensionStrings.size();
3086}
3087
Jamie Madill493f9572018-05-24 19:52:15 -04003088void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003089{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003090 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003091 ASSERT(transformFeedback != nullptr);
3092 ASSERT(!transformFeedback->isPaused());
3093
Jamie Madill6c1f6712017-02-14 19:08:04 -05003094 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003095}
3096
3097bool Context::hasActiveTransformFeedback(GLuint program) const
3098{
3099 for (auto pair : mTransformFeedbackMap)
3100 {
3101 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3102 {
3103 return true;
3104 }
3105 }
3106 return false;
3107}
3108
Geoff Lang33f11fb2018-05-07 13:42:47 -04003109Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003110{
3111 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3112
jchen1082af6202018-06-22 10:59:52 +08003113 // Explicitly enable GL_KHR_parallel_shader_compile
3114 supportedExtensions.parallelShaderCompile = true;
3115
Geoff Langb0f917f2017-12-05 13:41:54 -05003116 if (getClientVersion() < ES_2_0)
3117 {
3118 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003119 supportedExtensions.pointSizeArray = true;
3120 supportedExtensions.textureCubeMap = true;
3121 supportedExtensions.pointSprite = true;
3122 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003123 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003124 }
3125
3126 if (getClientVersion() < ES_3_0)
3127 {
3128 // Disable ES3+ extensions
3129 supportedExtensions.colorBufferFloat = false;
3130 supportedExtensions.eglImageExternalEssl3 = false;
3131 supportedExtensions.textureNorm16 = false;
3132 supportedExtensions.multiview = false;
3133 supportedExtensions.maxViews = 1u;
3134 }
3135
3136 if (getClientVersion() < ES_3_1)
3137 {
3138 // Disable ES3.1+ extensions
3139 supportedExtensions.geometryShader = false;
3140 }
3141
3142 if (getClientVersion() > ES_2_0)
3143 {
3144 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3145 // supportedExtensions.sRGB = false;
3146 }
3147
3148 // Some extensions are always available because they are implemented in the GL layer.
3149 supportedExtensions.bindUniformLocation = true;
3150 supportedExtensions.vertexArrayObject = true;
3151 supportedExtensions.bindGeneratesResource = true;
3152 supportedExtensions.clientArrays = true;
3153 supportedExtensions.requestExtension = true;
3154
3155 // Enable the no error extension if the context was created with the flag.
3156 supportedExtensions.noError = mSkipValidation;
3157
3158 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003159 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003160
3161 // Explicitly enable GL_KHR_debug
3162 supportedExtensions.debug = true;
3163 supportedExtensions.maxDebugMessageLength = 1024;
3164 supportedExtensions.maxDebugLoggedMessages = 1024;
3165 supportedExtensions.maxDebugGroupStackDepth = 1024;
3166 supportedExtensions.maxLabelLength = 1024;
3167
3168 // Explicitly enable GL_ANGLE_robust_client_memory
3169 supportedExtensions.robustClientMemory = true;
3170
3171 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003172 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003173
3174 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3175 // supports it.
3176 supportedExtensions.robustBufferAccessBehavior =
3177 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3178
3179 // Enable the cache control query unconditionally.
3180 supportedExtensions.programCacheControl = true;
3181
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003182 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003183 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003184 {
3185 // GL_ANGLE_explicit_context_gles1
3186 supportedExtensions.explicitContextGles1 = true;
3187 // GL_ANGLE_explicit_context
3188 supportedExtensions.explicitContext = true;
3189 }
3190
Geoff Langb0f917f2017-12-05 13:41:54 -05003191 return supportedExtensions;
3192}
3193
Geoff Lang33f11fb2018-05-07 13:42:47 -04003194void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003195{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003196 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003197
Geoff Lang33f11fb2018-05-07 13:42:47 -04003198 mSupportedExtensions = generateSupportedExtensions();
3199 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003200
3201 mLimitations = mImplementation->getNativeLimitations();
3202
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003203 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3204 if (getClientVersion() < Version(2, 0))
3205 {
3206 mCaps.maxMultitextureUnits = 4;
3207 mCaps.maxClipPlanes = 6;
3208 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003209 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3210 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3211 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003212 mCaps.minSmoothPointSize = 1.0f;
3213 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003214 mCaps.minSmoothLineWidth = 1.0f;
3215 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003216 }
3217
Luc Ferronad2ae932018-06-11 15:31:17 -04003218 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003219 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003220
Luc Ferronad2ae932018-06-11 15:31:17 -04003221 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3222
Jamie Madill0f80ed82017-09-19 00:24:56 -04003223 if (getClientVersion() < ES_3_1)
3224 {
3225 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3226 }
3227 else
3228 {
3229 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3230 }
Geoff Lang301d1612014-07-09 10:34:37 -04003231
Jiawei Shao54aafe52018-04-27 14:54:57 +08003232 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3233 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003234 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3235 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3236
3237 // Limit textures as well, so we can use fast bitsets with texture bindings.
3238 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003239 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3240 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3241 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3242 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003243
Jiawei Shaodb342272017-09-27 10:21:45 +08003244 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3245
Geoff Langc287ea62016-09-16 14:46:51 -04003246 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003247 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003248 for (const auto &extensionInfo : GetExtensionInfoMap())
3249 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003250 // If the user has requested that extensions start disabled and they are requestable,
3251 // disable them.
3252 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003253 {
3254 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3255 }
3256 }
3257
3258 // Generate texture caps
3259 updateCaps();
3260}
3261
3262void Context::updateCaps()
3263{
Geoff Lang900013c2014-07-07 11:32:19 -04003264 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003265 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003266
Jamie Madill7b62cf92017-11-02 15:20:49 -04003267 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003268 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003269 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003270 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003271
Geoff Lang0d8b7242015-09-09 14:56:53 -04003272 // Update the format caps based on the client version and extensions.
3273 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3274 // ES3.
3275 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003276 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003277 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003278 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003279 formatCaps.textureAttachment =
3280 formatCaps.textureAttachment &&
3281 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3282 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3283 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003284
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003285 // OpenGL ES does not support multisampling with non-rendererable formats
3286 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003287 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003288 (getClientVersion() < ES_3_1 &&
3289 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003290 {
Geoff Langd87878e2014-09-19 15:42:59 -04003291 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003292 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003293 else
3294 {
3295 // We may have limited the max samples for some required renderbuffer formats due to
3296 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3297 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3298
3299 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3300 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3301 // exception of signed and unsigned integer formats."
3302 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3303 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3304 {
3305 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3306 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3307 }
3308
3309 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3310 if (getClientVersion() >= ES_3_1)
3311 {
3312 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3313 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3314 // the exception that the signed and unsigned integer formats are required only to
3315 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3316 // multisamples, which must be at least one."
3317 if (formatInfo.componentType == GL_INT ||
3318 formatInfo.componentType == GL_UNSIGNED_INT)
3319 {
3320 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3321 }
3322
3323 // GLES 3.1 section 19.3.1.
3324 if (formatCaps.texturable)
3325 {
3326 if (formatInfo.depthBits > 0)
3327 {
3328 mCaps.maxDepthTextureSamples =
3329 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3330 }
3331 else if (formatInfo.redBits > 0)
3332 {
3333 mCaps.maxColorTextureSamples =
3334 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3335 }
3336 }
3337 }
3338 }
Geoff Langd87878e2014-09-19 15:42:59 -04003339
3340 if (formatCaps.texturable && formatInfo.compressed)
3341 {
Geoff Langca271392017-04-05 12:30:00 -04003342 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003343 }
3344
Geoff Langca271392017-04-05 12:30:00 -04003345 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003346 }
Jamie Madill32447362017-06-28 14:53:52 -04003347
3348 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003349 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003350 {
3351 mMemoryProgramCache = nullptr;
3352 }
Corentin Walleze4477002017-12-01 14:39:58 -05003353
3354 // Compute which buffer types are allowed
3355 mValidBufferBindings.reset();
3356 mValidBufferBindings.set(BufferBinding::ElementArray);
3357 mValidBufferBindings.set(BufferBinding::Array);
3358
3359 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3360 {
3361 mValidBufferBindings.set(BufferBinding::PixelPack);
3362 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3363 }
3364
3365 if (getClientVersion() >= ES_3_0)
3366 {
3367 mValidBufferBindings.set(BufferBinding::CopyRead);
3368 mValidBufferBindings.set(BufferBinding::CopyWrite);
3369 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3370 mValidBufferBindings.set(BufferBinding::Uniform);
3371 }
3372
3373 if (getClientVersion() >= ES_3_1)
3374 {
3375 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3376 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3377 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3378 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3379 }
jchen107ae70d82018-07-06 13:47:01 +08003380
3381 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Geoff Lang493daf52014-07-03 13:38:44 -04003382}
3383
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003384void Context::initWorkarounds()
3385{
Jamie Madill761b02c2017-06-23 16:27:06 -04003386 // Apply back-end workarounds.
3387 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3388
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003389 // Lose the context upon out of memory error if the application is
3390 // expecting to watch for those events.
3391 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3392}
3393
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003394// Return true if the draw is a no-op, else return false.
3395// A no-op draw occurs if the count of vertices is less than the minimum required to
3396// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3397bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3398{
3399 return count < kMinimumPrimitiveCounts[mode];
3400}
3401
3402bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3403{
3404 return (instanceCount == 0) || noopDraw(mode, count);
3405}
3406
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003407Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003408{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003409 if (mGLES1Renderer)
3410 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003411 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003412 }
3413
Geoff Lang9bf86f02018-07-26 11:46:34 -04003414 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003415
3416 if (isRobustResourceInitEnabled())
3417 {
3418 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3419 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3420 }
3421
Geoff Langa8cb2872018-03-09 16:09:40 -05003422 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003423 return NoError();
3424}
3425
3426Error Context::prepareForClear(GLbitfield mask)
3427{
Geoff Langa8cb2872018-03-09 16:09:40 -05003428 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003429 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003430 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003431 return NoError();
3432}
3433
3434Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3435{
Geoff Langa8cb2872018-03-09 16:09:40 -05003436 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003437 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3438 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003439 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003440 return NoError();
3441}
3442
Geoff Langa8cb2872018-03-09 16:09:40 -05003443Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003444{
Geoff Langa8cb2872018-03-09 16:09:40 -05003445 ANGLE_TRY(syncDirtyObjects(objectMask));
3446 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003447 return NoError();
3448}
3449
Geoff Langa8cb2872018-03-09 16:09:40 -05003450Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003451{
3452 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003453 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003454 mGLState.clearDirtyBits();
3455 return NoError();
3456}
3457
Geoff Langa8cb2872018-03-09 16:09:40 -05003458Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003459{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003460 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003461 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003462 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003463 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003464}
Jamie Madillc29968b2016-01-20 11:17:23 -05003465
Geoff Langa8cb2872018-03-09 16:09:40 -05003466Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003467{
3468 return mGLState.syncDirtyObjects(this, objectMask);
3469}
3470
Jamie Madillc29968b2016-01-20 11:17:23 -05003471void Context::blitFramebuffer(GLint srcX0,
3472 GLint srcY0,
3473 GLint srcX1,
3474 GLint srcY1,
3475 GLint dstX0,
3476 GLint dstY0,
3477 GLint dstX1,
3478 GLint dstY1,
3479 GLbitfield mask,
3480 GLenum filter)
3481{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003482 if (mask == 0)
3483 {
3484 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3485 // buffers are copied.
3486 return;
3487 }
3488
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003489 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003490 ASSERT(drawFramebuffer);
3491
3492 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3493 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3494
Jamie Madillbc918e72018-03-08 09:47:21 -05003495 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003496
Jamie Madillc564c072017-06-01 12:45:42 -04003497 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003498}
Jamie Madillc29968b2016-01-20 11:17:23 -05003499
3500void Context::clear(GLbitfield mask)
3501{
Geoff Langd4fff502017-09-22 11:28:28 -04003502 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3503 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003504}
3505
3506void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3507{
Geoff Langd4fff502017-09-22 11:28:28 -04003508 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3509 ANGLE_CONTEXT_TRY(
3510 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003511}
3512
3513void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3514{
Geoff Langd4fff502017-09-22 11:28:28 -04003515 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3516 ANGLE_CONTEXT_TRY(
3517 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003518}
3519
3520void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3521{
Geoff Langd4fff502017-09-22 11:28:28 -04003522 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3523 ANGLE_CONTEXT_TRY(
3524 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003525}
3526
3527void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3528{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003529 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003530 ASSERT(framebufferObject);
3531
3532 // If a buffer is not present, the clear has no effect
3533 if (framebufferObject->getDepthbuffer() == nullptr &&
3534 framebufferObject->getStencilbuffer() == nullptr)
3535 {
3536 return;
3537 }
3538
Geoff Langd4fff502017-09-22 11:28:28 -04003539 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3540 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003541}
3542
3543void Context::readPixels(GLint x,
3544 GLint y,
3545 GLsizei width,
3546 GLsizei height,
3547 GLenum format,
3548 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003549 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003550{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003551 if (width == 0 || height == 0)
3552 {
3553 return;
3554 }
3555
Jamie Madillbc918e72018-03-08 09:47:21 -05003556 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003557
Jamie Madillb6664922017-07-25 12:55:04 -04003558 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3559 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003560
3561 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003562 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003563}
3564
Brandon Jones59770802018-04-02 13:18:42 -07003565void Context::readPixelsRobust(GLint x,
3566 GLint y,
3567 GLsizei width,
3568 GLsizei height,
3569 GLenum format,
3570 GLenum type,
3571 GLsizei bufSize,
3572 GLsizei *length,
3573 GLsizei *columns,
3574 GLsizei *rows,
3575 void *pixels)
3576{
3577 readPixels(x, y, width, height, format, type, pixels);
3578}
3579
3580void Context::readnPixelsRobust(GLint x,
3581 GLint y,
3582 GLsizei width,
3583 GLsizei height,
3584 GLenum format,
3585 GLenum type,
3586 GLsizei bufSize,
3587 GLsizei *length,
3588 GLsizei *columns,
3589 GLsizei *rows,
3590 void *data)
3591{
3592 readPixels(x, y, width, height, format, type, data);
3593}
3594
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003595void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003596 GLint level,
3597 GLenum internalformat,
3598 GLint x,
3599 GLint y,
3600 GLsizei width,
3601 GLsizei height,
3602 GLint border)
3603{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003604 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003605 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003606
Jamie Madillc29968b2016-01-20 11:17:23 -05003607 Rectangle sourceArea(x, y, width, height);
3608
Jamie Madill05b35b22017-10-03 09:01:44 -04003609 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003610 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003611 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003612}
3613
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003614void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003615 GLint level,
3616 GLint xoffset,
3617 GLint yoffset,
3618 GLint x,
3619 GLint y,
3620 GLsizei width,
3621 GLsizei height)
3622{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003623 if (width == 0 || height == 0)
3624 {
3625 return;
3626 }
3627
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003628 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003629 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003630
Jamie Madillc29968b2016-01-20 11:17:23 -05003631 Offset destOffset(xoffset, yoffset, 0);
3632 Rectangle sourceArea(x, y, width, height);
3633
Jamie Madill05b35b22017-10-03 09:01:44 -04003634 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003635 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003636 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003637}
3638
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003639void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003640 GLint level,
3641 GLint xoffset,
3642 GLint yoffset,
3643 GLint zoffset,
3644 GLint x,
3645 GLint y,
3646 GLsizei width,
3647 GLsizei height)
3648{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003649 if (width == 0 || height == 0)
3650 {
3651 return;
3652 }
3653
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003654 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003655 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003656
Jamie Madillc29968b2016-01-20 11:17:23 -05003657 Offset destOffset(xoffset, yoffset, zoffset);
3658 Rectangle sourceArea(x, y, width, height);
3659
Jamie Madill05b35b22017-10-03 09:01:44 -04003660 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3661 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003662 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3663 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003664}
3665
3666void Context::framebufferTexture2D(GLenum target,
3667 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003668 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003669 GLuint texture,
3670 GLint level)
3671{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003672 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003673 ASSERT(framebuffer);
3674
3675 if (texture != 0)
3676 {
3677 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003678 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003679 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003680 }
3681 else
3682 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003683 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003684 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003685
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003686 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003687}
3688
3689void Context::framebufferRenderbuffer(GLenum target,
3690 GLenum attachment,
3691 GLenum renderbuffertarget,
3692 GLuint renderbuffer)
3693{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003694 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003695 ASSERT(framebuffer);
3696
3697 if (renderbuffer != 0)
3698 {
3699 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003700
Jamie Madillcc129372018-04-12 09:13:18 -04003701 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003702 renderbufferObject);
3703 }
3704 else
3705 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003706 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003707 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003708
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003709 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003710}
3711
3712void Context::framebufferTextureLayer(GLenum target,
3713 GLenum attachment,
3714 GLuint texture,
3715 GLint level,
3716 GLint layer)
3717{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003718 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003719 ASSERT(framebuffer);
3720
3721 if (texture != 0)
3722 {
3723 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003724 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003725 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003726 }
3727 else
3728 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003729 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003730 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003731
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003732 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003733}
3734
Brandon Jones59770802018-04-02 13:18:42 -07003735void Context::framebufferTextureMultiviewLayered(GLenum target,
3736 GLenum attachment,
3737 GLuint texture,
3738 GLint level,
3739 GLint baseViewIndex,
3740 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003741{
Martin Radev82ef7742017-08-08 17:44:58 +03003742 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3743 ASSERT(framebuffer);
3744
3745 if (texture != 0)
3746 {
3747 Texture *textureObj = getTexture(texture);
3748
Martin Radev18b75ba2017-08-15 15:50:40 +03003749 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003750 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3751 numViews, baseViewIndex);
3752 }
3753 else
3754 {
3755 framebuffer->resetAttachment(this, attachment);
3756 }
3757
3758 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003759}
3760
Brandon Jones59770802018-04-02 13:18:42 -07003761void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3762 GLenum attachment,
3763 GLuint texture,
3764 GLint level,
3765 GLsizei numViews,
3766 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003767{
Martin Radev5dae57b2017-07-14 16:15:55 +03003768 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3769 ASSERT(framebuffer);
3770
3771 if (texture != 0)
3772 {
3773 Texture *textureObj = getTexture(texture);
3774
3775 ImageIndex index = ImageIndex::Make2D(level);
3776 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3777 textureObj, numViews, viewportOffsets);
3778 }
3779 else
3780 {
3781 framebuffer->resetAttachment(this, attachment);
3782 }
3783
3784 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003785}
3786
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003787void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3788{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003789 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3790 ASSERT(framebuffer);
3791
3792 if (texture != 0)
3793 {
3794 Texture *textureObj = getTexture(texture);
3795
3796 ImageIndex index = ImageIndex::MakeFromType(
3797 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3798 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3799 }
3800 else
3801 {
3802 framebuffer->resetAttachment(this, attachment);
3803 }
3804
3805 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003806}
3807
Jamie Madillc29968b2016-01-20 11:17:23 -05003808void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3809{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003810 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003811 ASSERT(framebuffer);
3812 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003813 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003814}
3815
3816void Context::readBuffer(GLenum mode)
3817{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003818 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003819 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003820 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003821}
3822
3823void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3824{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003825 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003826 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003827
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003828 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003829 ASSERT(framebuffer);
3830
3831 // The specification isn't clear what should be done when the framebuffer isn't complete.
3832 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003833 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003834}
3835
3836void Context::invalidateFramebuffer(GLenum target,
3837 GLsizei numAttachments,
3838 const GLenum *attachments)
3839{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003840 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003841 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003842
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003843 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003844 ASSERT(framebuffer);
3845
Jamie Madill427064d2018-04-13 16:20:34 -04003846 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003847 {
Jamie Madill437fa652016-05-03 15:13:24 -04003848 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003849 }
Jamie Madill437fa652016-05-03 15:13:24 -04003850
Jamie Madill4928b7c2017-06-20 12:57:39 -04003851 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003852}
3853
3854void Context::invalidateSubFramebuffer(GLenum target,
3855 GLsizei numAttachments,
3856 const GLenum *attachments,
3857 GLint x,
3858 GLint y,
3859 GLsizei width,
3860 GLsizei height)
3861{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003862 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003863 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003864
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003865 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003866 ASSERT(framebuffer);
3867
Jamie Madill427064d2018-04-13 16:20:34 -04003868 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003869 {
Jamie Madill437fa652016-05-03 15:13:24 -04003870 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003871 }
Jamie Madill437fa652016-05-03 15:13:24 -04003872
3873 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003874 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003875}
3876
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003877void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003878 GLint level,
3879 GLint internalformat,
3880 GLsizei width,
3881 GLsizei height,
3882 GLint border,
3883 GLenum format,
3884 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003885 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003886{
Jamie Madillbc918e72018-03-08 09:47:21 -05003887 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003888
3889 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003890 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003891 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003892 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003893}
3894
Brandon Jones59770802018-04-02 13:18:42 -07003895void Context::texImage2DRobust(TextureTarget target,
3896 GLint level,
3897 GLint internalformat,
3898 GLsizei width,
3899 GLsizei height,
3900 GLint border,
3901 GLenum format,
3902 GLenum type,
3903 GLsizei bufSize,
3904 const void *pixels)
3905{
3906 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3907}
3908
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003909void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003910 GLint level,
3911 GLint internalformat,
3912 GLsizei width,
3913 GLsizei height,
3914 GLsizei depth,
3915 GLint border,
3916 GLenum format,
3917 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003918 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003919{
Jamie Madillbc918e72018-03-08 09:47:21 -05003920 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003921
3922 Extents size(width, height, depth);
3923 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003924 handleError(texture->setImage(this, mGLState.getUnpackState(),
3925 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003926 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003927}
3928
Brandon Jones59770802018-04-02 13:18:42 -07003929void Context::texImage3DRobust(TextureType target,
3930 GLint level,
3931 GLint internalformat,
3932 GLsizei width,
3933 GLsizei height,
3934 GLsizei depth,
3935 GLint border,
3936 GLenum format,
3937 GLenum type,
3938 GLsizei bufSize,
3939 const void *pixels)
3940{
3941 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3942}
3943
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003944void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003945 GLint level,
3946 GLint xoffset,
3947 GLint yoffset,
3948 GLsizei width,
3949 GLsizei height,
3950 GLenum format,
3951 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003952 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003953{
3954 // Zero sized uploads are valid but no-ops
3955 if (width == 0 || height == 0)
3956 {
3957 return;
3958 }
3959
Jamie Madillbc918e72018-03-08 09:47:21 -05003960 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003961
3962 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003963 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003964 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003965 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003966}
3967
Brandon Jones59770802018-04-02 13:18:42 -07003968void Context::texSubImage2DRobust(TextureTarget target,
3969 GLint level,
3970 GLint xoffset,
3971 GLint yoffset,
3972 GLsizei width,
3973 GLsizei height,
3974 GLenum format,
3975 GLenum type,
3976 GLsizei bufSize,
3977 const void *pixels)
3978{
3979 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3980}
3981
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003982void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003983 GLint level,
3984 GLint xoffset,
3985 GLint yoffset,
3986 GLint zoffset,
3987 GLsizei width,
3988 GLsizei height,
3989 GLsizei depth,
3990 GLenum format,
3991 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003992 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003993{
3994 // Zero sized uploads are valid but no-ops
3995 if (width == 0 || height == 0 || depth == 0)
3996 {
3997 return;
3998 }
3999
Jamie Madillbc918e72018-03-08 09:47:21 -05004000 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004001
4002 Box area(xoffset, yoffset, zoffset, width, height, depth);
4003 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004004 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
4005 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004006 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004007}
4008
Brandon Jones59770802018-04-02 13:18:42 -07004009void Context::texSubImage3DRobust(TextureType target,
4010 GLint level,
4011 GLint xoffset,
4012 GLint yoffset,
4013 GLint zoffset,
4014 GLsizei width,
4015 GLsizei height,
4016 GLsizei depth,
4017 GLenum format,
4018 GLenum type,
4019 GLsizei bufSize,
4020 const void *pixels)
4021{
4022 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4023 pixels);
4024}
4025
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004026void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004027 GLint level,
4028 GLenum internalformat,
4029 GLsizei width,
4030 GLsizei height,
4031 GLint border,
4032 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004033 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004034{
Jamie Madillbc918e72018-03-08 09:47:21 -05004035 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004036
4037 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004038 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004039 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4040 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004041 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004042}
4043
Brandon Jones59770802018-04-02 13:18:42 -07004044void Context::compressedTexImage2DRobust(TextureTarget target,
4045 GLint level,
4046 GLenum internalformat,
4047 GLsizei width,
4048 GLsizei height,
4049 GLint border,
4050 GLsizei imageSize,
4051 GLsizei dataSize,
4052 const GLvoid *data)
4053{
4054 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4055}
4056
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004057void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004058 GLint level,
4059 GLenum internalformat,
4060 GLsizei width,
4061 GLsizei height,
4062 GLsizei depth,
4063 GLint border,
4064 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004065 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004066{
Jamie Madillbc918e72018-03-08 09:47:21 -05004067 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004068
4069 Extents size(width, height, depth);
4070 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004071 handleError(texture->setCompressedImage(
4072 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004073 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004074}
4075
Brandon Jones59770802018-04-02 13:18:42 -07004076void Context::compressedTexImage3DRobust(TextureType target,
4077 GLint level,
4078 GLenum internalformat,
4079 GLsizei width,
4080 GLsizei height,
4081 GLsizei depth,
4082 GLint border,
4083 GLsizei imageSize,
4084 GLsizei dataSize,
4085 const GLvoid *data)
4086{
4087 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4088 data);
4089}
4090
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004091void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004092 GLint level,
4093 GLint xoffset,
4094 GLint yoffset,
4095 GLsizei width,
4096 GLsizei height,
4097 GLenum format,
4098 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004099 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004100{
Jamie Madillbc918e72018-03-08 09:47:21 -05004101 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004102
4103 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004104 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004105 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4106 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004107 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004108}
4109
Brandon Jones59770802018-04-02 13:18:42 -07004110void Context::compressedTexSubImage2DRobust(TextureTarget target,
4111 GLint level,
4112 GLint xoffset,
4113 GLint yoffset,
4114 GLsizei width,
4115 GLsizei height,
4116 GLenum format,
4117 GLsizei imageSize,
4118 GLsizei dataSize,
4119 const GLvoid *data)
4120{
4121 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4122 data);
4123}
4124
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004125void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004126 GLint level,
4127 GLint xoffset,
4128 GLint yoffset,
4129 GLint zoffset,
4130 GLsizei width,
4131 GLsizei height,
4132 GLsizei depth,
4133 GLenum format,
4134 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004135 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004136{
4137 // Zero sized uploads are valid but no-ops
4138 if (width == 0 || height == 0)
4139 {
4140 return;
4141 }
4142
Jamie Madillbc918e72018-03-08 09:47:21 -05004143 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004144
4145 Box area(xoffset, yoffset, zoffset, width, height, depth);
4146 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004147 handleError(texture->setCompressedSubImage(
4148 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004149 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004150}
4151
Brandon Jones59770802018-04-02 13:18:42 -07004152void Context::compressedTexSubImage3DRobust(TextureType target,
4153 GLint level,
4154 GLint xoffset,
4155 GLint yoffset,
4156 GLint zoffset,
4157 GLsizei width,
4158 GLsizei height,
4159 GLsizei depth,
4160 GLenum format,
4161 GLsizei imageSize,
4162 GLsizei dataSize,
4163 const GLvoid *data)
4164{
4165 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4166 imageSize, data);
4167}
4168
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004169void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004170{
4171 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004172 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004173}
4174
Jamie Madill007530e2017-12-28 14:27:04 -05004175void Context::copyTexture(GLuint sourceId,
4176 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004177 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004178 GLuint destId,
4179 GLint destLevel,
4180 GLint internalFormat,
4181 GLenum destType,
4182 GLboolean unpackFlipY,
4183 GLboolean unpackPremultiplyAlpha,
4184 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004185{
Jamie Madillbc918e72018-03-08 09:47:21 -05004186 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004187
4188 gl::Texture *sourceTexture = getTexture(sourceId);
4189 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004190 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4191 sourceLevel, ConvertToBool(unpackFlipY),
4192 ConvertToBool(unpackPremultiplyAlpha),
4193 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004194}
4195
Jamie Madill007530e2017-12-28 14:27:04 -05004196void Context::copySubTexture(GLuint sourceId,
4197 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004198 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004199 GLuint destId,
4200 GLint destLevel,
4201 GLint xoffset,
4202 GLint yoffset,
4203 GLint x,
4204 GLint y,
4205 GLsizei width,
4206 GLsizei height,
4207 GLboolean unpackFlipY,
4208 GLboolean unpackPremultiplyAlpha,
4209 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004210{
4211 // Zero sized copies are valid but no-ops
4212 if (width == 0 || height == 0)
4213 {
4214 return;
4215 }
4216
Jamie Madillbc918e72018-03-08 09:47:21 -05004217 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004218
4219 gl::Texture *sourceTexture = getTexture(sourceId);
4220 gl::Texture *destTexture = getTexture(destId);
4221 Offset offset(xoffset, yoffset, 0);
4222 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004223 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4224 ConvertToBool(unpackFlipY),
4225 ConvertToBool(unpackPremultiplyAlpha),
4226 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004227}
4228
Jamie Madill007530e2017-12-28 14:27:04 -05004229void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004230{
Jamie Madillbc918e72018-03-08 09:47:21 -05004231 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004232
4233 gl::Texture *sourceTexture = getTexture(sourceId);
4234 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004235 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004236}
4237
Corentin Wallez336129f2017-10-17 15:55:40 -04004238void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004239{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004240 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004241 ASSERT(buffer);
4242
Geoff Lang496c02d2016-10-20 11:38:11 -07004243 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004244}
4245
Brandon Jones59770802018-04-02 13:18:42 -07004246void Context::getBufferPointervRobust(BufferBinding target,
4247 GLenum pname,
4248 GLsizei bufSize,
4249 GLsizei *length,
4250 void **params)
4251{
4252 getBufferPointerv(target, pname, params);
4253}
4254
Corentin Wallez336129f2017-10-17 15:55:40 -04004255void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004256{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004257 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004258 ASSERT(buffer);
4259
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004260 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004261 if (error.isError())
4262 {
Jamie Madill437fa652016-05-03 15:13:24 -04004263 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004264 return nullptr;
4265 }
4266
4267 return buffer->getMapPointer();
4268}
4269
Corentin Wallez336129f2017-10-17 15:55:40 -04004270GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004271{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004272 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004273 ASSERT(buffer);
4274
4275 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004276 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004277 if (error.isError())
4278 {
Jamie Madill437fa652016-05-03 15:13:24 -04004279 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004280 return GL_FALSE;
4281 }
4282
4283 return result;
4284}
4285
Corentin Wallez336129f2017-10-17 15:55:40 -04004286void *Context::mapBufferRange(BufferBinding target,
4287 GLintptr offset,
4288 GLsizeiptr length,
4289 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004290{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004291 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004292 ASSERT(buffer);
4293
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004294 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004295 if (error.isError())
4296 {
Jamie Madill437fa652016-05-03 15:13:24 -04004297 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004298 return nullptr;
4299 }
4300
4301 return buffer->getMapPointer();
4302}
4303
Corentin Wallez336129f2017-10-17 15:55:40 -04004304void Context::flushMappedBufferRange(BufferBinding /*target*/,
4305 GLintptr /*offset*/,
4306 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004307{
4308 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4309}
4310
Jamie Madillbc918e72018-03-08 09:47:21 -05004311Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004312{
Geoff Langa8cb2872018-03-09 16:09:40 -05004313 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004314}
4315
Jamie Madillbc918e72018-03-08 09:47:21 -05004316Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004317{
Geoff Langa8cb2872018-03-09 16:09:40 -05004318 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004319}
4320
Jamie Madillbc918e72018-03-08 09:47:21 -05004321Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004322{
Geoff Langa8cb2872018-03-09 16:09:40 -05004323 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004324}
4325
Geoff Lang9bf86f02018-07-26 11:46:34 -04004326Error Context::syncStateForPathOperation()
4327{
4328 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4329
4330 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4331 ANGLE_TRY(syncDirtyBits());
4332
4333 return NoError();
4334}
4335
Jiajia Qin5451d532017-11-16 17:16:34 +08004336void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4337{
4338 UNIMPLEMENTED();
4339}
4340
Jamie Madillc20ab272016-06-09 07:20:46 -07004341void Context::activeTexture(GLenum texture)
4342{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004343 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004344}
4345
Jamie Madill876429b2017-04-20 15:46:24 -04004346void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004347{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004348 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004349}
4350
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004351void Context::blendEquation(GLenum mode)
4352{
4353 mGLState.setBlendEquation(mode, mode);
4354}
4355
Jamie Madillc20ab272016-06-09 07:20:46 -07004356void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4357{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004358 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004359}
4360
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004361void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4362{
4363 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4364}
4365
Jamie Madillc20ab272016-06-09 07:20:46 -07004366void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4367{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004368 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004369}
4370
Jamie Madill876429b2017-04-20 15:46:24 -04004371void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004372{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004373 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004374}
4375
Jamie Madill876429b2017-04-20 15:46:24 -04004376void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004377{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004378 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004379}
4380
4381void Context::clearStencil(GLint s)
4382{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004383 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004384}
4385
4386void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4387{
Geoff Lang92019432017-11-20 13:09:34 -05004388 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4389 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004390}
4391
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004392void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004393{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004394 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004395}
4396
4397void Context::depthFunc(GLenum func)
4398{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004399 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004400}
4401
4402void Context::depthMask(GLboolean flag)
4403{
Geoff Lang92019432017-11-20 13:09:34 -05004404 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004405}
4406
Jamie Madill876429b2017-04-20 15:46:24 -04004407void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004408{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004409 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004410}
4411
4412void Context::disable(GLenum cap)
4413{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004414 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004415}
4416
4417void Context::disableVertexAttribArray(GLuint index)
4418{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004419 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004420 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004421}
4422
4423void Context::enable(GLenum cap)
4424{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004425 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004426}
4427
4428void Context::enableVertexAttribArray(GLuint index)
4429{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004430 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004431 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004432}
4433
4434void Context::frontFace(GLenum mode)
4435{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004436 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004437}
4438
4439void Context::hint(GLenum target, GLenum mode)
4440{
4441 switch (target)
4442 {
4443 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004444 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004445 break;
4446
4447 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004448 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004449 break;
4450
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004451 case GL_PERSPECTIVE_CORRECTION_HINT:
4452 case GL_POINT_SMOOTH_HINT:
4453 case GL_LINE_SMOOTH_HINT:
4454 case GL_FOG_HINT:
4455 mGLState.gles1().setHint(target, mode);
4456 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004457 default:
4458 UNREACHABLE();
4459 return;
4460 }
4461}
4462
4463void Context::lineWidth(GLfloat width)
4464{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004465 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004466}
4467
4468void Context::pixelStorei(GLenum pname, GLint param)
4469{
4470 switch (pname)
4471 {
4472 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004473 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004474 break;
4475
4476 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004477 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004478 break;
4479
4480 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004481 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004482 break;
4483
4484 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004485 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004486 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004487 break;
4488
4489 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004490 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004491 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004492 break;
4493
4494 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004495 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004496 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004497 break;
4498
4499 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004500 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004501 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004502 break;
4503
4504 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004505 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004506 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004507 break;
4508
4509 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004510 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004511 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004512 break;
4513
4514 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004515 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004516 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004517 break;
4518
4519 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004520 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004521 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004522 break;
4523
4524 default:
4525 UNREACHABLE();
4526 return;
4527 }
4528}
4529
4530void Context::polygonOffset(GLfloat factor, GLfloat units)
4531{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004532 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004533}
4534
Jamie Madill876429b2017-04-20 15:46:24 -04004535void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004536{
Geoff Lang92019432017-11-20 13:09:34 -05004537 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004538}
4539
Jiawei Shaodb342272017-09-27 10:21:45 +08004540void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4541{
4542 mGLState.setSampleMaskParams(maskNumber, mask);
4543}
4544
Jamie Madillc20ab272016-06-09 07:20:46 -07004545void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4546{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004547 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004548}
4549
4550void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4551{
4552 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4553 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004554 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004555 }
4556
4557 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4558 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004559 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004560 }
4561}
4562
4563void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4564{
4565 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4566 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004567 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004568 }
4569
4570 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4571 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004572 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004573 }
4574}
4575
4576void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4577{
4578 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4579 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004580 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004581 }
4582
4583 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4584 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004585 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004586 }
4587}
4588
4589void Context::vertexAttrib1f(GLuint index, GLfloat x)
4590{
4591 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004592 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004593}
4594
4595void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4596{
4597 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004598 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004599}
4600
4601void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4602{
4603 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004604 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004605}
4606
4607void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4608{
4609 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004610 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004611}
4612
4613void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4614{
4615 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004616 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004617}
4618
4619void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4620{
4621 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004622 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004623}
4624
4625void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4626{
4627 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004628 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004629}
4630
4631void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4632{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004633 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004634}
4635
4636void Context::vertexAttribPointer(GLuint index,
4637 GLint size,
4638 GLenum type,
4639 GLboolean normalized,
4640 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004641 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004642{
Corentin Wallez336129f2017-10-17 15:55:40 -04004643 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004644 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004645 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004646}
4647
Shao80957d92017-02-20 21:25:59 +08004648void Context::vertexAttribFormat(GLuint attribIndex,
4649 GLint size,
4650 GLenum type,
4651 GLboolean normalized,
4652 GLuint relativeOffset)
4653{
Geoff Lang92019432017-11-20 13:09:34 -05004654 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004655 relativeOffset);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004656 mStateCache.onVertexArraySizeChange(this);
Shao80957d92017-02-20 21:25:59 +08004657}
4658
4659void Context::vertexAttribIFormat(GLuint attribIndex,
4660 GLint size,
4661 GLenum type,
4662 GLuint relativeOffset)
4663{
4664 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004665 mStateCache.onVertexArraySizeChange(this);
Shao80957d92017-02-20 21:25:59 +08004666}
4667
4668void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4669{
Shaodde78e82017-05-22 14:13:27 +08004670 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004671 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004672}
4673
Jiajia Qin5451d532017-11-16 17:16:34 +08004674void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004675{
4676 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004677 mStateCache.onVertexArraySizeChange(this);
Shao80957d92017-02-20 21:25:59 +08004678}
4679
Jamie Madillc20ab272016-06-09 07:20:46 -07004680void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4681{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004682 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004683}
4684
4685void Context::vertexAttribIPointer(GLuint index,
4686 GLint size,
4687 GLenum type,
4688 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004689 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004690{
Corentin Wallez336129f2017-10-17 15:55:40 -04004691 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4692 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004693 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004694}
4695
4696void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4697{
4698 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004699 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004700}
4701
4702void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4703{
4704 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004705 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004706}
4707
4708void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4709{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004710 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004711}
4712
4713void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4714{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004715 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004716}
4717
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004718void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4719{
4720 const VertexAttribCurrentValueData &currentValues =
4721 getGLState().getVertexAttribCurrentValue(index);
4722 const VertexArray *vao = getGLState().getVertexArray();
4723 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4724 currentValues, pname, params);
4725}
4726
Brandon Jones59770802018-04-02 13:18:42 -07004727void Context::getVertexAttribivRobust(GLuint index,
4728 GLenum pname,
4729 GLsizei bufSize,
4730 GLsizei *length,
4731 GLint *params)
4732{
4733 getVertexAttribiv(index, pname, params);
4734}
4735
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004736void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4737{
4738 const VertexAttribCurrentValueData &currentValues =
4739 getGLState().getVertexAttribCurrentValue(index);
4740 const VertexArray *vao = getGLState().getVertexArray();
4741 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4742 currentValues, pname, params);
4743}
4744
Brandon Jones59770802018-04-02 13:18:42 -07004745void Context::getVertexAttribfvRobust(GLuint index,
4746 GLenum pname,
4747 GLsizei bufSize,
4748 GLsizei *length,
4749 GLfloat *params)
4750{
4751 getVertexAttribfv(index, pname, params);
4752}
4753
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004754void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4755{
4756 const VertexAttribCurrentValueData &currentValues =
4757 getGLState().getVertexAttribCurrentValue(index);
4758 const VertexArray *vao = getGLState().getVertexArray();
4759 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4760 currentValues, pname, params);
4761}
4762
Brandon Jones59770802018-04-02 13:18:42 -07004763void Context::getVertexAttribIivRobust(GLuint index,
4764 GLenum pname,
4765 GLsizei bufSize,
4766 GLsizei *length,
4767 GLint *params)
4768{
4769 getVertexAttribIiv(index, pname, params);
4770}
4771
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004772void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4773{
4774 const VertexAttribCurrentValueData &currentValues =
4775 getGLState().getVertexAttribCurrentValue(index);
4776 const VertexArray *vao = getGLState().getVertexArray();
4777 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4778 currentValues, pname, params);
4779}
4780
Brandon Jones59770802018-04-02 13:18:42 -07004781void Context::getVertexAttribIuivRobust(GLuint index,
4782 GLenum pname,
4783 GLsizei bufSize,
4784 GLsizei *length,
4785 GLuint *params)
4786{
4787 getVertexAttribIuiv(index, pname, params);
4788}
4789
Jamie Madill876429b2017-04-20 15:46:24 -04004790void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004791{
4792 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4793 QueryVertexAttribPointerv(attrib, pname, pointer);
4794}
4795
Brandon Jones59770802018-04-02 13:18:42 -07004796void Context::getVertexAttribPointervRobust(GLuint index,
4797 GLenum pname,
4798 GLsizei bufSize,
4799 GLsizei *length,
4800 void **pointer)
4801{
4802 getVertexAttribPointerv(index, pname, pointer);
4803}
4804
Jamie Madillc20ab272016-06-09 07:20:46 -07004805void Context::debugMessageControl(GLenum source,
4806 GLenum type,
4807 GLenum severity,
4808 GLsizei count,
4809 const GLuint *ids,
4810 GLboolean enabled)
4811{
4812 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004813 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004814 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004815}
4816
4817void Context::debugMessageInsert(GLenum source,
4818 GLenum type,
4819 GLuint id,
4820 GLenum severity,
4821 GLsizei length,
4822 const GLchar *buf)
4823{
4824 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004825 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004826}
4827
4828void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4829{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004830 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004831}
4832
4833GLuint Context::getDebugMessageLog(GLuint count,
4834 GLsizei bufSize,
4835 GLenum *sources,
4836 GLenum *types,
4837 GLuint *ids,
4838 GLenum *severities,
4839 GLsizei *lengths,
4840 GLchar *messageLog)
4841{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004842 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4843 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004844}
4845
4846void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4847{
4848 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004849 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004850 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004851}
4852
4853void Context::popDebugGroup()
4854{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004855 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004856 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004857}
4858
Corentin Wallez336129f2017-10-17 15:55:40 -04004859void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004860{
4861 Buffer *buffer = mGLState.getTargetBuffer(target);
4862 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004863 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004864}
4865
Corentin Wallez336129f2017-10-17 15:55:40 -04004866void Context::bufferSubData(BufferBinding target,
4867 GLintptr offset,
4868 GLsizeiptr size,
4869 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004870{
4871 if (data == nullptr)
4872 {
4873 return;
4874 }
4875
4876 Buffer *buffer = mGLState.getTargetBuffer(target);
4877 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004878 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004879}
4880
Jamie Madillef300b12016-10-07 15:12:09 -04004881void Context::attachShader(GLuint program, GLuint shader)
4882{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004883 Program *programObject = mState.mShaderPrograms->getProgram(program);
4884 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004885 ASSERT(programObject && shaderObject);
4886 programObject->attachShader(shaderObject);
4887}
4888
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004889const Workarounds &Context::getWorkarounds() const
4890{
4891 return mWorkarounds;
4892}
4893
Corentin Wallez336129f2017-10-17 15:55:40 -04004894void Context::copyBufferSubData(BufferBinding readTarget,
4895 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004896 GLintptr readOffset,
4897 GLintptr writeOffset,
4898 GLsizeiptr size)
4899{
4900 // if size is zero, the copy is a successful no-op
4901 if (size == 0)
4902 {
4903 return;
4904 }
4905
4906 // TODO(jmadill): cache these.
4907 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4908 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4909
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004910 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004911}
4912
Jamie Madill01a80ee2016-11-07 12:06:18 -05004913void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4914{
4915 Program *programObject = getProgram(program);
4916 // TODO(jmadill): Re-use this from the validation if possible.
4917 ASSERT(programObject);
4918 programObject->bindAttributeLocation(index, name);
4919}
4920
Corentin Wallez336129f2017-10-17 15:55:40 -04004921void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004922{
Corentin Wallez336129f2017-10-17 15:55:40 -04004923 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4924 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004925}
4926
Corentin Wallez336129f2017-10-17 15:55:40 -04004927void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004928{
4929 bindBufferRange(target, index, buffer, 0, 0);
4930}
4931
Corentin Wallez336129f2017-10-17 15:55:40 -04004932void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004933 GLuint index,
4934 GLuint buffer,
4935 GLintptr offset,
4936 GLsizeiptr size)
4937{
Corentin Wallez336129f2017-10-17 15:55:40 -04004938 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4939 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004940}
4941
Jamie Madill01a80ee2016-11-07 12:06:18 -05004942void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4943{
4944 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4945 {
4946 bindReadFramebuffer(framebuffer);
4947 }
4948
4949 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4950 {
4951 bindDrawFramebuffer(framebuffer);
4952 }
4953}
4954
4955void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4956{
4957 ASSERT(target == GL_RENDERBUFFER);
4958 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004959 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004960 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004961}
4962
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004963void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004964 GLsizei samples,
4965 GLenum internalformat,
4966 GLsizei width,
4967 GLsizei height,
4968 GLboolean fixedsamplelocations)
4969{
4970 Extents size(width, height, 1);
4971 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004972 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4973 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004974}
4975
4976void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4977{
JiangYizhou5b03f472017-01-09 10:22:53 +08004978 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4979 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004980 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004981 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004982
4983 switch (pname)
4984 {
4985 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004986 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004987 break;
4988 default:
4989 UNREACHABLE();
4990 }
4991}
4992
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004993void Context::getMultisamplefvRobust(GLenum pname,
4994 GLuint index,
4995 GLsizei bufSize,
4996 GLsizei *length,
4997 GLfloat *val)
4998{
4999 UNIMPLEMENTED();
5000}
5001
Jamie Madille8fb6402017-02-14 17:56:40 -05005002void Context::renderbufferStorage(GLenum target,
5003 GLenum internalformat,
5004 GLsizei width,
5005 GLsizei height)
5006{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005007 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5008 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5009
Jamie Madille8fb6402017-02-14 17:56:40 -05005010 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04005011 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005012}
5013
5014void Context::renderbufferStorageMultisample(GLenum target,
5015 GLsizei samples,
5016 GLenum internalformat,
5017 GLsizei width,
5018 GLsizei height)
5019{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005020 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5021 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005022
5023 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005024 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005025 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005026}
5027
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005028void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5029{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005030 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04005031 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005032}
5033
JiangYizhoue18e6392017-02-20 10:32:23 +08005034void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5035{
5036 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5037 QueryFramebufferParameteriv(framebuffer, pname, params);
5038}
5039
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005040void Context::getFramebufferParameterivRobust(GLenum target,
5041 GLenum pname,
5042 GLsizei bufSize,
5043 GLsizei *length,
5044 GLint *params)
5045{
5046 UNIMPLEMENTED();
5047}
5048
Jiajia Qin5451d532017-11-16 17:16:34 +08005049void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005050{
5051 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005052 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005053}
5054
Jamie Madilldec86232018-07-11 09:01:18 -04005055bool Context::getScratchBuffer(size_t requstedSizeBytes,
5056 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005057{
Jamie Madilldec86232018-07-11 09:01:18 -04005058 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005059}
5060
Jamie Madilldec86232018-07-11 09:01:18 -04005061bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5062 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005063{
Jamie Madilldec86232018-07-11 09:01:18 -04005064 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005065}
5066
Xinghua Cao10a4d432017-11-28 14:46:26 +08005067Error Context::prepareForDispatch()
5068{
Geoff Langa8cb2872018-03-09 16:09:40 -05005069 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005070
5071 if (isRobustResourceInitEnabled())
5072 {
5073 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5074 }
5075
5076 return NoError();
5077}
5078
Xinghua Cao2b396592017-03-29 15:36:04 +08005079void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5080{
5081 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5082 {
5083 return;
5084 }
5085
Xinghua Cao10a4d432017-11-28 14:46:26 +08005086 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005087 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005088}
5089
Jiajia Qin5451d532017-11-16 17:16:34 +08005090void Context::dispatchComputeIndirect(GLintptr indirect)
5091{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005092 ANGLE_CONTEXT_TRY(prepareForDispatch());
5093 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005094}
5095
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005096void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005097 GLsizei levels,
5098 GLenum internalFormat,
5099 GLsizei width,
5100 GLsizei height)
5101{
5102 Extents size(width, height, 1);
5103 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005104 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005105}
5106
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005107void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005108 GLsizei levels,
5109 GLenum internalFormat,
5110 GLsizei width,
5111 GLsizei height,
5112 GLsizei depth)
5113{
5114 Extents size(width, height, depth);
5115 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005116 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005117}
5118
Jiajia Qin5451d532017-11-16 17:16:34 +08005119void Context::memoryBarrier(GLbitfield barriers)
5120{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005121 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005122}
5123
5124void Context::memoryBarrierByRegion(GLbitfield barriers)
5125{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005126 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005127}
5128
Jamie Madillc1d770e2017-04-13 17:31:24 -04005129GLenum Context::checkFramebufferStatus(GLenum target)
5130{
5131 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5132 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005133 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005134}
5135
5136void Context::compileShader(GLuint shader)
5137{
5138 Shader *shaderObject = GetValidShader(this, shader);
5139 if (!shaderObject)
5140 {
5141 return;
5142 }
5143 shaderObject->compile(this);
5144}
5145
5146void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5147{
5148 for (int i = 0; i < n; i++)
5149 {
5150 deleteBuffer(buffers[i]);
5151 }
5152}
5153
5154void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5155{
5156 for (int i = 0; i < n; i++)
5157 {
5158 if (framebuffers[i] != 0)
5159 {
5160 deleteFramebuffer(framebuffers[i]);
5161 }
5162 }
5163}
5164
5165void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5166{
5167 for (int i = 0; i < n; i++)
5168 {
5169 deleteRenderbuffer(renderbuffers[i]);
5170 }
5171}
5172
5173void Context::deleteTextures(GLsizei n, const GLuint *textures)
5174{
5175 for (int i = 0; i < n; i++)
5176 {
5177 if (textures[i] != 0)
5178 {
5179 deleteTexture(textures[i]);
5180 }
5181 }
5182}
5183
5184void Context::detachShader(GLuint program, GLuint shader)
5185{
5186 Program *programObject = getProgram(program);
5187 ASSERT(programObject);
5188
5189 Shader *shaderObject = getShader(shader);
5190 ASSERT(shaderObject);
5191
5192 programObject->detachShader(this, shaderObject);
5193}
5194
5195void Context::genBuffers(GLsizei n, GLuint *buffers)
5196{
5197 for (int i = 0; i < n; i++)
5198 {
5199 buffers[i] = createBuffer();
5200 }
5201}
5202
5203void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5204{
5205 for (int i = 0; i < n; i++)
5206 {
5207 framebuffers[i] = createFramebuffer();
5208 }
5209}
5210
5211void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5212{
5213 for (int i = 0; i < n; i++)
5214 {
5215 renderbuffers[i] = createRenderbuffer();
5216 }
5217}
5218
5219void Context::genTextures(GLsizei n, GLuint *textures)
5220{
5221 for (int i = 0; i < n; i++)
5222 {
5223 textures[i] = createTexture();
5224 }
5225}
5226
5227void Context::getActiveAttrib(GLuint program,
5228 GLuint index,
5229 GLsizei bufsize,
5230 GLsizei *length,
5231 GLint *size,
5232 GLenum *type,
5233 GLchar *name)
5234{
5235 Program *programObject = getProgram(program);
5236 ASSERT(programObject);
5237 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5238}
5239
5240void Context::getActiveUniform(GLuint program,
5241 GLuint index,
5242 GLsizei bufsize,
5243 GLsizei *length,
5244 GLint *size,
5245 GLenum *type,
5246 GLchar *name)
5247{
5248 Program *programObject = getProgram(program);
5249 ASSERT(programObject);
5250 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5251}
5252
5253void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5254{
5255 Program *programObject = getProgram(program);
5256 ASSERT(programObject);
5257 programObject->getAttachedShaders(maxcount, count, shaders);
5258}
5259
5260GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5261{
5262 Program *programObject = getProgram(program);
5263 ASSERT(programObject);
5264 return programObject->getAttributeLocation(name);
5265}
5266
5267void Context::getBooleanv(GLenum pname, GLboolean *params)
5268{
5269 GLenum nativeType;
5270 unsigned int numParams = 0;
5271 getQueryParameterInfo(pname, &nativeType, &numParams);
5272
5273 if (nativeType == GL_BOOL)
5274 {
5275 getBooleanvImpl(pname, params);
5276 }
5277 else
5278 {
5279 CastStateValues(this, nativeType, pname, numParams, params);
5280 }
5281}
5282
Brandon Jones59770802018-04-02 13:18:42 -07005283void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5284{
5285 getBooleanv(pname, params);
5286}
5287
Jamie Madillc1d770e2017-04-13 17:31:24 -04005288void Context::getFloatv(GLenum pname, GLfloat *params)
5289{
5290 GLenum nativeType;
5291 unsigned int numParams = 0;
5292 getQueryParameterInfo(pname, &nativeType, &numParams);
5293
5294 if (nativeType == GL_FLOAT)
5295 {
5296 getFloatvImpl(pname, params);
5297 }
5298 else
5299 {
5300 CastStateValues(this, nativeType, pname, numParams, params);
5301 }
5302}
5303
Brandon Jones59770802018-04-02 13:18:42 -07005304void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5305{
5306 getFloatv(pname, params);
5307}
5308
Jamie Madillc1d770e2017-04-13 17:31:24 -04005309void Context::getIntegerv(GLenum pname, GLint *params)
5310{
5311 GLenum nativeType;
5312 unsigned int numParams = 0;
5313 getQueryParameterInfo(pname, &nativeType, &numParams);
5314
5315 if (nativeType == GL_INT)
5316 {
5317 getIntegervImpl(pname, params);
5318 }
5319 else
5320 {
5321 CastStateValues(this, nativeType, pname, numParams, params);
5322 }
5323}
5324
Brandon Jones59770802018-04-02 13:18:42 -07005325void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5326{
5327 getIntegerv(pname, data);
5328}
5329
Jamie Madillc1d770e2017-04-13 17:31:24 -04005330void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5331{
5332 Program *programObject = getProgram(program);
5333 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005334 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005335}
5336
Brandon Jones59770802018-04-02 13:18:42 -07005337void Context::getProgramivRobust(GLuint program,
5338 GLenum pname,
5339 GLsizei bufSize,
5340 GLsizei *length,
5341 GLint *params)
5342{
5343 getProgramiv(program, pname, params);
5344}
5345
Jiajia Qin5451d532017-11-16 17:16:34 +08005346void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5347{
5348 UNIMPLEMENTED();
5349}
5350
Jamie Madillbe849e42017-05-02 15:49:00 -04005351void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005352{
5353 Program *programObject = getProgram(program);
5354 ASSERT(programObject);
5355 programObject->getInfoLog(bufsize, length, infolog);
5356}
5357
Jiajia Qin5451d532017-11-16 17:16:34 +08005358void Context::getProgramPipelineInfoLog(GLuint pipeline,
5359 GLsizei bufSize,
5360 GLsizei *length,
5361 GLchar *infoLog)
5362{
5363 UNIMPLEMENTED();
5364}
5365
Jamie Madillc1d770e2017-04-13 17:31:24 -04005366void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5367{
5368 Shader *shaderObject = getShader(shader);
5369 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005370 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005371}
5372
Brandon Jones59770802018-04-02 13:18:42 -07005373void Context::getShaderivRobust(GLuint shader,
5374 GLenum pname,
5375 GLsizei bufSize,
5376 GLsizei *length,
5377 GLint *params)
5378{
5379 getShaderiv(shader, pname, params);
5380}
5381
Jamie Madillc1d770e2017-04-13 17:31:24 -04005382void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5383{
5384 Shader *shaderObject = getShader(shader);
5385 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005386 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005387}
5388
5389void Context::getShaderPrecisionFormat(GLenum shadertype,
5390 GLenum precisiontype,
5391 GLint *range,
5392 GLint *precision)
5393{
5394 // TODO(jmadill): Compute shaders.
5395
5396 switch (shadertype)
5397 {
5398 case GL_VERTEX_SHADER:
5399 switch (precisiontype)
5400 {
5401 case GL_LOW_FLOAT:
5402 mCaps.vertexLowpFloat.get(range, precision);
5403 break;
5404 case GL_MEDIUM_FLOAT:
5405 mCaps.vertexMediumpFloat.get(range, precision);
5406 break;
5407 case GL_HIGH_FLOAT:
5408 mCaps.vertexHighpFloat.get(range, precision);
5409 break;
5410
5411 case GL_LOW_INT:
5412 mCaps.vertexLowpInt.get(range, precision);
5413 break;
5414 case GL_MEDIUM_INT:
5415 mCaps.vertexMediumpInt.get(range, precision);
5416 break;
5417 case GL_HIGH_INT:
5418 mCaps.vertexHighpInt.get(range, precision);
5419 break;
5420
5421 default:
5422 UNREACHABLE();
5423 return;
5424 }
5425 break;
5426
5427 case GL_FRAGMENT_SHADER:
5428 switch (precisiontype)
5429 {
5430 case GL_LOW_FLOAT:
5431 mCaps.fragmentLowpFloat.get(range, precision);
5432 break;
5433 case GL_MEDIUM_FLOAT:
5434 mCaps.fragmentMediumpFloat.get(range, precision);
5435 break;
5436 case GL_HIGH_FLOAT:
5437 mCaps.fragmentHighpFloat.get(range, precision);
5438 break;
5439
5440 case GL_LOW_INT:
5441 mCaps.fragmentLowpInt.get(range, precision);
5442 break;
5443 case GL_MEDIUM_INT:
5444 mCaps.fragmentMediumpInt.get(range, precision);
5445 break;
5446 case GL_HIGH_INT:
5447 mCaps.fragmentHighpInt.get(range, precision);
5448 break;
5449
5450 default:
5451 UNREACHABLE();
5452 return;
5453 }
5454 break;
5455
5456 default:
5457 UNREACHABLE();
5458 return;
5459 }
5460}
5461
5462void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5463{
5464 Shader *shaderObject = getShader(shader);
5465 ASSERT(shaderObject);
5466 shaderObject->getSource(bufsize, length, source);
5467}
5468
5469void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5470{
5471 Program *programObject = getProgram(program);
5472 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005473 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005474}
5475
Brandon Jones59770802018-04-02 13:18:42 -07005476void Context::getUniformfvRobust(GLuint program,
5477 GLint location,
5478 GLsizei bufSize,
5479 GLsizei *length,
5480 GLfloat *params)
5481{
5482 getUniformfv(program, location, params);
5483}
5484
Jamie Madillc1d770e2017-04-13 17:31:24 -04005485void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5486{
5487 Program *programObject = getProgram(program);
5488 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005489 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005490}
5491
Brandon Jones59770802018-04-02 13:18:42 -07005492void Context::getUniformivRobust(GLuint program,
5493 GLint location,
5494 GLsizei bufSize,
5495 GLsizei *length,
5496 GLint *params)
5497{
5498 getUniformiv(program, location, params);
5499}
5500
Jamie Madillc1d770e2017-04-13 17:31:24 -04005501GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5502{
5503 Program *programObject = getProgram(program);
5504 ASSERT(programObject);
5505 return programObject->getUniformLocation(name);
5506}
5507
5508GLboolean Context::isBuffer(GLuint buffer)
5509{
5510 if (buffer == 0)
5511 {
5512 return GL_FALSE;
5513 }
5514
5515 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5516}
5517
5518GLboolean Context::isEnabled(GLenum cap)
5519{
5520 return mGLState.getEnableFeature(cap);
5521}
5522
5523GLboolean Context::isFramebuffer(GLuint framebuffer)
5524{
5525 if (framebuffer == 0)
5526 {
5527 return GL_FALSE;
5528 }
5529
5530 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5531}
5532
5533GLboolean Context::isProgram(GLuint program)
5534{
5535 if (program == 0)
5536 {
5537 return GL_FALSE;
5538 }
5539
5540 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5541}
5542
5543GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5544{
5545 if (renderbuffer == 0)
5546 {
5547 return GL_FALSE;
5548 }
5549
5550 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5551}
5552
5553GLboolean Context::isShader(GLuint shader)
5554{
5555 if (shader == 0)
5556 {
5557 return GL_FALSE;
5558 }
5559
5560 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5561}
5562
5563GLboolean Context::isTexture(GLuint texture)
5564{
5565 if (texture == 0)
5566 {
5567 return GL_FALSE;
5568 }
5569
5570 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5571}
5572
5573void Context::linkProgram(GLuint program)
5574{
5575 Program *programObject = getProgram(program);
5576 ASSERT(programObject);
5577 handleError(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005578
5579 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5580 // don't need to worry that:
5581 // 1. Draw calls after link use the new executable code or the old one depending on the link
5582 // result.
5583 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5584 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5585 // ProgramD3D.
5586 if (programObject->isInUse())
5587 {
5588 // isLinked() which forces to resolve linking, will be called.
5589 mGLState.onProgramExecutableChange(programObject);
5590 mStateCache.onProgramExecutableChange(this);
5591 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005592}
5593
5594void Context::releaseShaderCompiler()
5595{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005596 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005597}
5598
5599void Context::shaderBinary(GLsizei n,
5600 const GLuint *shaders,
5601 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005602 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005603 GLsizei length)
5604{
5605 // No binary shader formats are supported.
5606 UNIMPLEMENTED();
5607}
5608
5609void Context::shaderSource(GLuint shader,
5610 GLsizei count,
5611 const GLchar *const *string,
5612 const GLint *length)
5613{
5614 Shader *shaderObject = getShader(shader);
5615 ASSERT(shaderObject);
5616 shaderObject->setSource(count, string, length);
5617}
5618
5619void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5620{
5621 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5622}
5623
5624void Context::stencilMask(GLuint mask)
5625{
5626 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5627}
5628
5629void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5630{
5631 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5632}
5633
5634void Context::uniform1f(GLint location, GLfloat x)
5635{
5636 Program *program = mGLState.getProgram();
5637 program->setUniform1fv(location, 1, &x);
5638}
5639
5640void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5641{
5642 Program *program = mGLState.getProgram();
5643 program->setUniform1fv(location, count, v);
5644}
5645
Jamie Madill7e4eff12018-08-08 15:49:26 -04005646void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005647{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005648 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04005649 {
5650 mGLState.setObjectDirty(GL_PROGRAM);
5651 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005652}
5653
Jamie Madill7e4eff12018-08-08 15:49:26 -04005654void Context::uniform1i(GLint location, GLint x)
5655{
5656 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
5657}
5658
Jamie Madillc1d770e2017-04-13 17:31:24 -04005659void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5660{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005661 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005662}
5663
5664void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5665{
5666 GLfloat xy[2] = {x, y};
5667 Program *program = mGLState.getProgram();
5668 program->setUniform2fv(location, 1, xy);
5669}
5670
5671void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5672{
5673 Program *program = mGLState.getProgram();
5674 program->setUniform2fv(location, count, v);
5675}
5676
5677void Context::uniform2i(GLint location, GLint x, GLint y)
5678{
5679 GLint xy[2] = {x, y};
5680 Program *program = mGLState.getProgram();
5681 program->setUniform2iv(location, 1, xy);
5682}
5683
5684void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5685{
5686 Program *program = mGLState.getProgram();
5687 program->setUniform2iv(location, count, v);
5688}
5689
5690void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5691{
5692 GLfloat xyz[3] = {x, y, z};
5693 Program *program = mGLState.getProgram();
5694 program->setUniform3fv(location, 1, xyz);
5695}
5696
5697void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5698{
5699 Program *program = mGLState.getProgram();
5700 program->setUniform3fv(location, count, v);
5701}
5702
5703void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5704{
5705 GLint xyz[3] = {x, y, z};
5706 Program *program = mGLState.getProgram();
5707 program->setUniform3iv(location, 1, xyz);
5708}
5709
5710void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5711{
5712 Program *program = mGLState.getProgram();
5713 program->setUniform3iv(location, count, v);
5714}
5715
5716void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5717{
5718 GLfloat xyzw[4] = {x, y, z, w};
5719 Program *program = mGLState.getProgram();
5720 program->setUniform4fv(location, 1, xyzw);
5721}
5722
5723void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5724{
5725 Program *program = mGLState.getProgram();
5726 program->setUniform4fv(location, count, v);
5727}
5728
5729void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5730{
5731 GLint xyzw[4] = {x, y, z, w};
5732 Program *program = mGLState.getProgram();
5733 program->setUniform4iv(location, 1, xyzw);
5734}
5735
5736void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5737{
5738 Program *program = mGLState.getProgram();
5739 program->setUniform4iv(location, count, v);
5740}
5741
5742void Context::uniformMatrix2fv(GLint location,
5743 GLsizei count,
5744 GLboolean transpose,
5745 const GLfloat *value)
5746{
5747 Program *program = mGLState.getProgram();
5748 program->setUniformMatrix2fv(location, count, transpose, value);
5749}
5750
5751void Context::uniformMatrix3fv(GLint location,
5752 GLsizei count,
5753 GLboolean transpose,
5754 const GLfloat *value)
5755{
5756 Program *program = mGLState.getProgram();
5757 program->setUniformMatrix3fv(location, count, transpose, value);
5758}
5759
5760void Context::uniformMatrix4fv(GLint location,
5761 GLsizei count,
5762 GLboolean transpose,
5763 const GLfloat *value)
5764{
5765 Program *program = mGLState.getProgram();
5766 program->setUniformMatrix4fv(location, count, transpose, value);
5767}
5768
5769void Context::validateProgram(GLuint program)
5770{
5771 Program *programObject = getProgram(program);
5772 ASSERT(programObject);
5773 programObject->validate(mCaps);
5774}
5775
Jiajia Qin5451d532017-11-16 17:16:34 +08005776void Context::validateProgramPipeline(GLuint pipeline)
5777{
5778 UNIMPLEMENTED();
5779}
5780
Jamie Madilld04908b2017-06-09 14:15:35 -04005781void Context::getProgramBinary(GLuint program,
5782 GLsizei bufSize,
5783 GLsizei *length,
5784 GLenum *binaryFormat,
5785 void *binary)
5786{
5787 Program *programObject = getProgram(program);
5788 ASSERT(programObject != nullptr);
5789
5790 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5791}
5792
5793void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5794{
5795 Program *programObject = getProgram(program);
5796 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005797
Jamie Madilld04908b2017-06-09 14:15:35 -04005798 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madillc43cdad2018-08-08 15:49:25 -04005799 mStateCache.onProgramExecutableChange(this);
Jamie Madilld04908b2017-06-09 14:15:35 -04005800}
5801
Jamie Madillff325f12017-08-26 15:06:05 -04005802void Context::uniform1ui(GLint location, GLuint v0)
5803{
5804 Program *program = mGLState.getProgram();
5805 program->setUniform1uiv(location, 1, &v0);
5806}
5807
5808void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5809{
5810 Program *program = mGLState.getProgram();
5811 const GLuint xy[] = {v0, v1};
5812 program->setUniform2uiv(location, 1, xy);
5813}
5814
5815void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5816{
5817 Program *program = mGLState.getProgram();
5818 const GLuint xyz[] = {v0, v1, v2};
5819 program->setUniform3uiv(location, 1, xyz);
5820}
5821
5822void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5823{
5824 Program *program = mGLState.getProgram();
5825 const GLuint xyzw[] = {v0, v1, v2, v3};
5826 program->setUniform4uiv(location, 1, xyzw);
5827}
5828
5829void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5830{
5831 Program *program = mGLState.getProgram();
5832 program->setUniform1uiv(location, count, value);
5833}
5834void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5835{
5836 Program *program = mGLState.getProgram();
5837 program->setUniform2uiv(location, count, value);
5838}
5839
5840void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5841{
5842 Program *program = mGLState.getProgram();
5843 program->setUniform3uiv(location, count, value);
5844}
5845
5846void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5847{
5848 Program *program = mGLState.getProgram();
5849 program->setUniform4uiv(location, count, value);
5850}
5851
Jamie Madillf0e04492017-08-26 15:28:42 -04005852void Context::genQueries(GLsizei n, GLuint *ids)
5853{
5854 for (GLsizei i = 0; i < n; i++)
5855 {
5856 GLuint handle = mQueryHandleAllocator.allocate();
5857 mQueryMap.assign(handle, nullptr);
5858 ids[i] = handle;
5859 }
5860}
5861
5862void Context::deleteQueries(GLsizei n, const GLuint *ids)
5863{
5864 for (int i = 0; i < n; i++)
5865 {
5866 GLuint query = ids[i];
5867
5868 Query *queryObject = nullptr;
5869 if (mQueryMap.erase(query, &queryObject))
5870 {
5871 mQueryHandleAllocator.release(query);
5872 if (queryObject)
5873 {
5874 queryObject->release(this);
5875 }
5876 }
5877 }
5878}
5879
5880GLboolean Context::isQuery(GLuint id)
5881{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005882 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005883}
5884
Jamie Madillc8c95812017-08-26 18:40:09 -04005885void Context::uniformMatrix2x3fv(GLint location,
5886 GLsizei count,
5887 GLboolean transpose,
5888 const GLfloat *value)
5889{
5890 Program *program = mGLState.getProgram();
5891 program->setUniformMatrix2x3fv(location, count, transpose, value);
5892}
5893
5894void Context::uniformMatrix3x2fv(GLint location,
5895 GLsizei count,
5896 GLboolean transpose,
5897 const GLfloat *value)
5898{
5899 Program *program = mGLState.getProgram();
5900 program->setUniformMatrix3x2fv(location, count, transpose, value);
5901}
5902
5903void Context::uniformMatrix2x4fv(GLint location,
5904 GLsizei count,
5905 GLboolean transpose,
5906 const GLfloat *value)
5907{
5908 Program *program = mGLState.getProgram();
5909 program->setUniformMatrix2x4fv(location, count, transpose, value);
5910}
5911
5912void Context::uniformMatrix4x2fv(GLint location,
5913 GLsizei count,
5914 GLboolean transpose,
5915 const GLfloat *value)
5916{
5917 Program *program = mGLState.getProgram();
5918 program->setUniformMatrix4x2fv(location, count, transpose, value);
5919}
5920
5921void Context::uniformMatrix3x4fv(GLint location,
5922 GLsizei count,
5923 GLboolean transpose,
5924 const GLfloat *value)
5925{
5926 Program *program = mGLState.getProgram();
5927 program->setUniformMatrix3x4fv(location, count, transpose, value);
5928}
5929
5930void Context::uniformMatrix4x3fv(GLint location,
5931 GLsizei count,
5932 GLboolean transpose,
5933 const GLfloat *value)
5934{
5935 Program *program = mGLState.getProgram();
5936 program->setUniformMatrix4x3fv(location, count, transpose, value);
5937}
5938
Jamie Madilld7576732017-08-26 18:49:50 -04005939void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5940{
5941 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5942 {
5943 GLuint vertexArray = arrays[arrayIndex];
5944
5945 if (arrays[arrayIndex] != 0)
5946 {
5947 VertexArray *vertexArrayObject = nullptr;
5948 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5949 {
5950 if (vertexArrayObject != nullptr)
5951 {
5952 detachVertexArray(vertexArray);
5953 vertexArrayObject->onDestroy(this);
5954 }
5955
5956 mVertexArrayHandleAllocator.release(vertexArray);
5957 }
5958 }
5959 }
5960}
5961
5962void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5963{
5964 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5965 {
5966 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5967 mVertexArrayMap.assign(vertexArray, nullptr);
5968 arrays[arrayIndex] = vertexArray;
5969 }
5970}
5971
5972bool Context::isVertexArray(GLuint array)
5973{
5974 if (array == 0)
5975 {
5976 return GL_FALSE;
5977 }
5978
5979 VertexArray *vao = getVertexArray(array);
5980 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5981}
5982
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005983void Context::endTransformFeedback()
5984{
5985 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5986 transformFeedback->end(this);
5987}
5988
5989void Context::transformFeedbackVaryings(GLuint program,
5990 GLsizei count,
5991 const GLchar *const *varyings,
5992 GLenum bufferMode)
5993{
5994 Program *programObject = getProgram(program);
5995 ASSERT(programObject);
5996 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5997}
5998
5999void Context::getTransformFeedbackVarying(GLuint program,
6000 GLuint index,
6001 GLsizei bufSize,
6002 GLsizei *length,
6003 GLsizei *size,
6004 GLenum *type,
6005 GLchar *name)
6006{
6007 Program *programObject = getProgram(program);
6008 ASSERT(programObject);
6009 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6010}
6011
6012void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6013{
6014 for (int i = 0; i < n; i++)
6015 {
6016 GLuint transformFeedback = ids[i];
6017 if (transformFeedback == 0)
6018 {
6019 continue;
6020 }
6021
6022 TransformFeedback *transformFeedbackObject = nullptr;
6023 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6024 {
6025 if (transformFeedbackObject != nullptr)
6026 {
6027 detachTransformFeedback(transformFeedback);
6028 transformFeedbackObject->release(this);
6029 }
6030
6031 mTransformFeedbackHandleAllocator.release(transformFeedback);
6032 }
6033 }
6034}
6035
6036void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6037{
6038 for (int i = 0; i < n; i++)
6039 {
6040 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6041 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6042 ids[i] = transformFeedback;
6043 }
6044}
6045
6046bool Context::isTransformFeedback(GLuint id)
6047{
6048 if (id == 0)
6049 {
6050 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6051 // returns FALSE
6052 return GL_FALSE;
6053 }
6054
6055 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6056 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6057}
6058
6059void Context::pauseTransformFeedback()
6060{
6061 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6062 transformFeedback->pause();
6063}
6064
6065void Context::resumeTransformFeedback()
6066{
6067 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6068 transformFeedback->resume();
6069}
6070
Jamie Madill12e957f2017-08-26 21:42:26 -04006071void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6072{
6073 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006074 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006075}
6076
Brandon Jones59770802018-04-02 13:18:42 -07006077void Context::getUniformuivRobust(GLuint program,
6078 GLint location,
6079 GLsizei bufSize,
6080 GLsizei *length,
6081 GLuint *params)
6082{
6083 getUniformuiv(program, location, params);
6084}
6085
Jamie Madill12e957f2017-08-26 21:42:26 -04006086GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6087{
6088 const Program *programObject = getProgram(program);
6089 return programObject->getFragDataLocation(name);
6090}
6091
6092void Context::getUniformIndices(GLuint program,
6093 GLsizei uniformCount,
6094 const GLchar *const *uniformNames,
6095 GLuint *uniformIndices)
6096{
6097 const Program *programObject = getProgram(program);
6098 if (!programObject->isLinked())
6099 {
6100 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6101 {
6102 uniformIndices[uniformId] = GL_INVALID_INDEX;
6103 }
6104 }
6105 else
6106 {
6107 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6108 {
6109 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6110 }
6111 }
6112}
6113
6114void Context::getActiveUniformsiv(GLuint program,
6115 GLsizei uniformCount,
6116 const GLuint *uniformIndices,
6117 GLenum pname,
6118 GLint *params)
6119{
6120 const Program *programObject = getProgram(program);
6121 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6122 {
6123 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006124 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006125 }
6126}
6127
6128GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6129{
6130 const Program *programObject = getProgram(program);
6131 return programObject->getUniformBlockIndex(uniformBlockName);
6132}
6133
6134void Context::getActiveUniformBlockiv(GLuint program,
6135 GLuint uniformBlockIndex,
6136 GLenum pname,
6137 GLint *params)
6138{
6139 const Program *programObject = getProgram(program);
6140 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6141}
6142
Brandon Jones59770802018-04-02 13:18:42 -07006143void Context::getActiveUniformBlockivRobust(GLuint program,
6144 GLuint uniformBlockIndex,
6145 GLenum pname,
6146 GLsizei bufSize,
6147 GLsizei *length,
6148 GLint *params)
6149{
6150 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6151}
6152
Jamie Madill12e957f2017-08-26 21:42:26 -04006153void Context::getActiveUniformBlockName(GLuint program,
6154 GLuint uniformBlockIndex,
6155 GLsizei bufSize,
6156 GLsizei *length,
6157 GLchar *uniformBlockName)
6158{
6159 const Program *programObject = getProgram(program);
6160 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6161}
6162
6163void Context::uniformBlockBinding(GLuint program,
6164 GLuint uniformBlockIndex,
6165 GLuint uniformBlockBinding)
6166{
6167 Program *programObject = getProgram(program);
6168 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6169}
6170
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006171GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6172{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006173 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6174 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006175
Jamie Madill70b5bb02017-08-28 13:32:37 -04006176 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006177 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006178 if (error.isError())
6179 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006180 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006181 handleError(error);
6182 return nullptr;
6183 }
6184
Jamie Madill70b5bb02017-08-28 13:32:37 -04006185 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006186}
6187
6188GLboolean Context::isSync(GLsync sync)
6189{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006190 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006191}
6192
6193GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6194{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006195 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006196
6197 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006198 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006199 return result;
6200}
6201
6202void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6203{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006204 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006205 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006206}
6207
6208void Context::getInteger64v(GLenum pname, GLint64 *params)
6209{
6210 GLenum nativeType = GL_NONE;
6211 unsigned int numParams = 0;
6212 getQueryParameterInfo(pname, &nativeType, &numParams);
6213
6214 if (nativeType == GL_INT_64_ANGLEX)
6215 {
6216 getInteger64vImpl(pname, params);
6217 }
6218 else
6219 {
6220 CastStateValues(this, nativeType, pname, numParams, params);
6221 }
6222}
6223
Brandon Jones59770802018-04-02 13:18:42 -07006224void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6225{
6226 getInteger64v(pname, data);
6227}
6228
Corentin Wallez336129f2017-10-17 15:55:40 -04006229void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006230{
6231 Buffer *buffer = mGLState.getTargetBuffer(target);
6232 QueryBufferParameteri64v(buffer, pname, params);
6233}
6234
Brandon Jones59770802018-04-02 13:18:42 -07006235void Context::getBufferParameteri64vRobust(BufferBinding target,
6236 GLenum pname,
6237 GLsizei bufSize,
6238 GLsizei *length,
6239 GLint64 *params)
6240{
6241 getBufferParameteri64v(target, pname, params);
6242}
6243
Jamie Madill3ef140a2017-08-26 23:11:21 -04006244void Context::genSamplers(GLsizei count, GLuint *samplers)
6245{
6246 for (int i = 0; i < count; i++)
6247 {
6248 samplers[i] = mState.mSamplers->createSampler();
6249 }
6250}
6251
6252void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6253{
6254 for (int i = 0; i < count; i++)
6255 {
6256 GLuint sampler = samplers[i];
6257
6258 if (mState.mSamplers->getSampler(sampler))
6259 {
6260 detachSampler(sampler);
6261 }
6262
6263 mState.mSamplers->deleteObject(this, sampler);
6264 }
6265}
6266
6267void Context::getInternalformativ(GLenum target,
6268 GLenum internalformat,
6269 GLenum pname,
6270 GLsizei bufSize,
6271 GLint *params)
6272{
6273 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6274 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6275}
6276
Brandon Jones59770802018-04-02 13:18:42 -07006277void Context::getInternalformativRobust(GLenum target,
6278 GLenum internalformat,
6279 GLenum pname,
6280 GLsizei bufSize,
6281 GLsizei *length,
6282 GLint *params)
6283{
6284 getInternalformativ(target, internalformat, pname, bufSize, params);
6285}
6286
Jiajia Qin5451d532017-11-16 17:16:34 +08006287void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6288{
6289 programUniform1iv(program, location, 1, &v0);
6290}
6291
6292void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6293{
6294 GLint xy[2] = {v0, v1};
6295 programUniform2iv(program, location, 1, xy);
6296}
6297
6298void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6299{
6300 GLint xyz[3] = {v0, v1, v2};
6301 programUniform3iv(program, location, 1, xyz);
6302}
6303
6304void Context::programUniform4i(GLuint program,
6305 GLint location,
6306 GLint v0,
6307 GLint v1,
6308 GLint v2,
6309 GLint v3)
6310{
6311 GLint xyzw[4] = {v0, v1, v2, v3};
6312 programUniform4iv(program, location, 1, xyzw);
6313}
6314
6315void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6316{
6317 programUniform1uiv(program, location, 1, &v0);
6318}
6319
6320void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6321{
6322 GLuint xy[2] = {v0, v1};
6323 programUniform2uiv(program, location, 1, xy);
6324}
6325
6326void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6327{
6328 GLuint xyz[3] = {v0, v1, v2};
6329 programUniform3uiv(program, location, 1, xyz);
6330}
6331
6332void Context::programUniform4ui(GLuint program,
6333 GLint location,
6334 GLuint v0,
6335 GLuint v1,
6336 GLuint v2,
6337 GLuint v3)
6338{
6339 GLuint xyzw[4] = {v0, v1, v2, v3};
6340 programUniform4uiv(program, location, 1, xyzw);
6341}
6342
6343void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6344{
6345 programUniform1fv(program, location, 1, &v0);
6346}
6347
6348void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6349{
6350 GLfloat xy[2] = {v0, v1};
6351 programUniform2fv(program, location, 1, xy);
6352}
6353
6354void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6355{
6356 GLfloat xyz[3] = {v0, v1, v2};
6357 programUniform3fv(program, location, 1, xyz);
6358}
6359
6360void Context::programUniform4f(GLuint program,
6361 GLint location,
6362 GLfloat v0,
6363 GLfloat v1,
6364 GLfloat v2,
6365 GLfloat v3)
6366{
6367 GLfloat xyzw[4] = {v0, v1, v2, v3};
6368 programUniform4fv(program, location, 1, xyzw);
6369}
6370
Jamie Madill81c2e252017-09-09 23:32:46 -04006371void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6372{
6373 Program *programObject = getProgram(program);
6374 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006375 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006376}
6377
Jiajia Qin5451d532017-11-16 17:16:34 +08006378void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6379{
6380 Program *programObject = getProgram(program);
6381 ASSERT(programObject);
6382 programObject->setUniform2iv(location, count, value);
6383}
6384
6385void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6386{
6387 Program *programObject = getProgram(program);
6388 ASSERT(programObject);
6389 programObject->setUniform3iv(location, count, value);
6390}
6391
6392void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6393{
6394 Program *programObject = getProgram(program);
6395 ASSERT(programObject);
6396 programObject->setUniform4iv(location, count, value);
6397}
6398
6399void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6400{
6401 Program *programObject = getProgram(program);
6402 ASSERT(programObject);
6403 programObject->setUniform1uiv(location, count, value);
6404}
6405
6406void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6407{
6408 Program *programObject = getProgram(program);
6409 ASSERT(programObject);
6410 programObject->setUniform2uiv(location, count, value);
6411}
6412
6413void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6414{
6415 Program *programObject = getProgram(program);
6416 ASSERT(programObject);
6417 programObject->setUniform3uiv(location, count, value);
6418}
6419
6420void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6421{
6422 Program *programObject = getProgram(program);
6423 ASSERT(programObject);
6424 programObject->setUniform4uiv(location, count, value);
6425}
6426
6427void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6428{
6429 Program *programObject = getProgram(program);
6430 ASSERT(programObject);
6431 programObject->setUniform1fv(location, count, value);
6432}
6433
6434void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6435{
6436 Program *programObject = getProgram(program);
6437 ASSERT(programObject);
6438 programObject->setUniform2fv(location, count, value);
6439}
6440
6441void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6442{
6443 Program *programObject = getProgram(program);
6444 ASSERT(programObject);
6445 programObject->setUniform3fv(location, count, value);
6446}
6447
6448void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6449{
6450 Program *programObject = getProgram(program);
6451 ASSERT(programObject);
6452 programObject->setUniform4fv(location, count, value);
6453}
6454
6455void Context::programUniformMatrix2fv(GLuint program,
6456 GLint location,
6457 GLsizei count,
6458 GLboolean transpose,
6459 const GLfloat *value)
6460{
6461 Program *programObject = getProgram(program);
6462 ASSERT(programObject);
6463 programObject->setUniformMatrix2fv(location, count, transpose, value);
6464}
6465
6466void Context::programUniformMatrix3fv(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->setUniformMatrix3fv(location, count, transpose, value);
6475}
6476
6477void Context::programUniformMatrix4fv(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->setUniformMatrix4fv(location, count, transpose, value);
6486}
6487
6488void Context::programUniformMatrix2x3fv(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->setUniformMatrix2x3fv(location, count, transpose, value);
6497}
6498
6499void Context::programUniformMatrix3x2fv(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->setUniformMatrix3x2fv(location, count, transpose, value);
6508}
6509
6510void Context::programUniformMatrix2x4fv(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->setUniformMatrix2x4fv(location, count, transpose, value);
6519}
6520
6521void Context::programUniformMatrix4x2fv(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->setUniformMatrix4x2fv(location, count, transpose, value);
6530}
6531
6532void Context::programUniformMatrix3x4fv(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->setUniformMatrix3x4fv(location, count, transpose, value);
6541}
6542
6543void Context::programUniformMatrix4x3fv(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->setUniformMatrix4x3fv(location, count, transpose, value);
6552}
6553
Jamie Madill81c2e252017-09-09 23:32:46 -04006554void Context::onTextureChange(const Texture *texture)
6555{
6556 // Conservatively assume all textures are dirty.
6557 // TODO(jmadill): More fine-grained update.
6558 mGLState.setObjectDirty(GL_TEXTURE);
6559}
6560
James Darpiniane8a93c62018-01-04 18:02:24 -08006561bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6562{
6563 return mGLState.isCurrentTransformFeedback(tf);
6564}
6565bool Context::isCurrentVertexArray(const VertexArray *va) const
6566{
6567 return mGLState.isCurrentVertexArray(va);
6568}
6569
Yunchao Hea336b902017-08-02 16:05:21 +08006570void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6571{
6572 for (int i = 0; i < count; i++)
6573 {
6574 pipelines[i] = createProgramPipeline();
6575 }
6576}
6577
6578void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6579{
6580 for (int i = 0; i < count; i++)
6581 {
6582 if (pipelines[i] != 0)
6583 {
6584 deleteProgramPipeline(pipelines[i]);
6585 }
6586 }
6587}
6588
6589GLboolean Context::isProgramPipeline(GLuint pipeline)
6590{
6591 if (pipeline == 0)
6592 {
6593 return GL_FALSE;
6594 }
6595
6596 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6597}
6598
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006599void Context::finishFenceNV(GLuint fence)
6600{
6601 FenceNV *fenceObject = getFenceNV(fence);
6602
6603 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006604 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006605}
6606
6607void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6608{
6609 FenceNV *fenceObject = getFenceNV(fence);
6610
6611 ASSERT(fenceObject && fenceObject->isSet());
6612
6613 switch (pname)
6614 {
6615 case GL_FENCE_STATUS_NV:
6616 {
6617 // GL_NV_fence spec:
6618 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6619 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6620 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6621 GLboolean status = GL_TRUE;
6622 if (fenceObject->getStatus() != GL_TRUE)
6623 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006624 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006625 }
6626 *params = status;
6627 break;
6628 }
6629
6630 case GL_FENCE_CONDITION_NV:
6631 {
6632 *params = static_cast<GLint>(fenceObject->getCondition());
6633 break;
6634 }
6635
6636 default:
6637 UNREACHABLE();
6638 }
6639}
6640
6641void Context::getTranslatedShaderSource(GLuint shader,
6642 GLsizei bufsize,
6643 GLsizei *length,
6644 GLchar *source)
6645{
6646 Shader *shaderObject = getShader(shader);
6647 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006648 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006649}
6650
6651void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6652{
6653 Program *programObject = getProgram(program);
6654 ASSERT(programObject);
6655
6656 programObject->getUniformfv(this, location, params);
6657}
6658
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006659void Context::getnUniformfvRobust(GLuint program,
6660 GLint location,
6661 GLsizei bufSize,
6662 GLsizei *length,
6663 GLfloat *params)
6664{
6665 UNIMPLEMENTED();
6666}
6667
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006668void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6669{
6670 Program *programObject = getProgram(program);
6671 ASSERT(programObject);
6672
6673 programObject->getUniformiv(this, location, params);
6674}
6675
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006676void Context::getnUniformivRobust(GLuint program,
6677 GLint location,
6678 GLsizei bufSize,
6679 GLsizei *length,
6680 GLint *params)
6681{
6682 UNIMPLEMENTED();
6683}
6684
6685void Context::getnUniformuivRobust(GLuint program,
6686 GLint location,
6687 GLsizei bufSize,
6688 GLsizei *length,
6689 GLuint *params)
6690{
6691 UNIMPLEMENTED();
6692}
6693
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006694GLboolean Context::isFenceNV(GLuint fence)
6695{
6696 FenceNV *fenceObject = getFenceNV(fence);
6697
6698 if (fenceObject == nullptr)
6699 {
6700 return GL_FALSE;
6701 }
6702
6703 // GL_NV_fence spec:
6704 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6705 // existing fence.
6706 return fenceObject->isSet();
6707}
6708
6709void Context::readnPixels(GLint x,
6710 GLint y,
6711 GLsizei width,
6712 GLsizei height,
6713 GLenum format,
6714 GLenum type,
6715 GLsizei bufSize,
6716 void *data)
6717{
6718 return readPixels(x, y, width, height, format, type, data);
6719}
6720
Jamie Madill007530e2017-12-28 14:27:04 -05006721void Context::setFenceNV(GLuint fence, GLenum condition)
6722{
6723 ASSERT(condition == GL_ALL_COMPLETED_NV);
6724
6725 FenceNV *fenceObject = getFenceNV(fence);
6726 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006727 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006728}
6729
6730GLboolean Context::testFenceNV(GLuint fence)
6731{
6732 FenceNV *fenceObject = getFenceNV(fence);
6733
6734 ASSERT(fenceObject != nullptr);
6735 ASSERT(fenceObject->isSet() == GL_TRUE);
6736
6737 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006738 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006739 if (error.isError())
6740 {
6741 handleError(error);
6742 return GL_TRUE;
6743 }
6744
6745 return result;
6746}
6747
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006748void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006749{
6750 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006751 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006752 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006753}
6754
Jamie Madillfa920eb2018-01-04 11:45:50 -05006755void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006756{
6757 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006758 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006759 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6760}
6761
Jamie Madillfa920eb2018-01-04 11:45:50 -05006762void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6763{
6764 UNIMPLEMENTED();
6765}
6766
Jamie Madill5b772312018-03-08 20:28:32 -05006767bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6768{
6769 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6770 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6771 // to the fact that it is stored internally as a float, and so would require conversion
6772 // if returned from Context::getIntegerv. Since this conversion is already implemented
6773 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6774 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6775 // application.
6776 switch (pname)
6777 {
6778 case GL_COMPRESSED_TEXTURE_FORMATS:
6779 {
6780 *type = GL_INT;
6781 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6782 return true;
6783 }
6784 case GL_SHADER_BINARY_FORMATS:
6785 {
6786 *type = GL_INT;
6787 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6788 return true;
6789 }
6790
6791 case GL_MAX_VERTEX_ATTRIBS:
6792 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6793 case GL_MAX_VARYING_VECTORS:
6794 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6795 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6796 case GL_MAX_TEXTURE_IMAGE_UNITS:
6797 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6798 case GL_MAX_RENDERBUFFER_SIZE:
6799 case GL_NUM_SHADER_BINARY_FORMATS:
6800 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6801 case GL_ARRAY_BUFFER_BINDING:
6802 case GL_FRAMEBUFFER_BINDING:
6803 case GL_RENDERBUFFER_BINDING:
6804 case GL_CURRENT_PROGRAM:
6805 case GL_PACK_ALIGNMENT:
6806 case GL_UNPACK_ALIGNMENT:
6807 case GL_GENERATE_MIPMAP_HINT:
6808 case GL_RED_BITS:
6809 case GL_GREEN_BITS:
6810 case GL_BLUE_BITS:
6811 case GL_ALPHA_BITS:
6812 case GL_DEPTH_BITS:
6813 case GL_STENCIL_BITS:
6814 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6815 case GL_CULL_FACE_MODE:
6816 case GL_FRONT_FACE:
6817 case GL_ACTIVE_TEXTURE:
6818 case GL_STENCIL_FUNC:
6819 case GL_STENCIL_VALUE_MASK:
6820 case GL_STENCIL_REF:
6821 case GL_STENCIL_FAIL:
6822 case GL_STENCIL_PASS_DEPTH_FAIL:
6823 case GL_STENCIL_PASS_DEPTH_PASS:
6824 case GL_STENCIL_BACK_FUNC:
6825 case GL_STENCIL_BACK_VALUE_MASK:
6826 case GL_STENCIL_BACK_REF:
6827 case GL_STENCIL_BACK_FAIL:
6828 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6829 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6830 case GL_DEPTH_FUNC:
6831 case GL_BLEND_SRC_RGB:
6832 case GL_BLEND_SRC_ALPHA:
6833 case GL_BLEND_DST_RGB:
6834 case GL_BLEND_DST_ALPHA:
6835 case GL_BLEND_EQUATION_RGB:
6836 case GL_BLEND_EQUATION_ALPHA:
6837 case GL_STENCIL_WRITEMASK:
6838 case GL_STENCIL_BACK_WRITEMASK:
6839 case GL_STENCIL_CLEAR_VALUE:
6840 case GL_SUBPIXEL_BITS:
6841 case GL_MAX_TEXTURE_SIZE:
6842 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6843 case GL_SAMPLE_BUFFERS:
6844 case GL_SAMPLES:
6845 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6846 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6847 case GL_TEXTURE_BINDING_2D:
6848 case GL_TEXTURE_BINDING_CUBE_MAP:
6849 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6850 {
6851 *type = GL_INT;
6852 *numParams = 1;
6853 return true;
6854 }
6855 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6856 {
6857 if (!getExtensions().packReverseRowOrder)
6858 {
6859 return false;
6860 }
6861 *type = GL_INT;
6862 *numParams = 1;
6863 return true;
6864 }
6865 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6866 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6867 {
6868 if (!getExtensions().textureRectangle)
6869 {
6870 return false;
6871 }
6872 *type = GL_INT;
6873 *numParams = 1;
6874 return true;
6875 }
6876 case GL_MAX_DRAW_BUFFERS_EXT:
6877 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6878 {
6879 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6880 {
6881 return false;
6882 }
6883 *type = GL_INT;
6884 *numParams = 1;
6885 return true;
6886 }
6887 case GL_MAX_VIEWPORT_DIMS:
6888 {
6889 *type = GL_INT;
6890 *numParams = 2;
6891 return true;
6892 }
6893 case GL_VIEWPORT:
6894 case GL_SCISSOR_BOX:
6895 {
6896 *type = GL_INT;
6897 *numParams = 4;
6898 return true;
6899 }
6900 case GL_SHADER_COMPILER:
6901 case GL_SAMPLE_COVERAGE_INVERT:
6902 case GL_DEPTH_WRITEMASK:
6903 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6904 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6905 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6906 // bool-natural
6907 case GL_SAMPLE_COVERAGE:
6908 case GL_SCISSOR_TEST:
6909 case GL_STENCIL_TEST:
6910 case GL_DEPTH_TEST:
6911 case GL_BLEND:
6912 case GL_DITHER:
6913 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6914 {
6915 *type = GL_BOOL;
6916 *numParams = 1;
6917 return true;
6918 }
6919 case GL_COLOR_WRITEMASK:
6920 {
6921 *type = GL_BOOL;
6922 *numParams = 4;
6923 return true;
6924 }
6925 case GL_POLYGON_OFFSET_FACTOR:
6926 case GL_POLYGON_OFFSET_UNITS:
6927 case GL_SAMPLE_COVERAGE_VALUE:
6928 case GL_DEPTH_CLEAR_VALUE:
6929 case GL_LINE_WIDTH:
6930 {
6931 *type = GL_FLOAT;
6932 *numParams = 1;
6933 return true;
6934 }
6935 case GL_ALIASED_LINE_WIDTH_RANGE:
6936 case GL_ALIASED_POINT_SIZE_RANGE:
6937 case GL_DEPTH_RANGE:
6938 {
6939 *type = GL_FLOAT;
6940 *numParams = 2;
6941 return true;
6942 }
6943 case GL_COLOR_CLEAR_VALUE:
6944 case GL_BLEND_COLOR:
6945 {
6946 *type = GL_FLOAT;
6947 *numParams = 4;
6948 return true;
6949 }
6950 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6951 if (!getExtensions().textureFilterAnisotropic)
6952 {
6953 return false;
6954 }
6955 *type = GL_FLOAT;
6956 *numParams = 1;
6957 return true;
6958 case GL_TIMESTAMP_EXT:
6959 if (!getExtensions().disjointTimerQuery)
6960 {
6961 return false;
6962 }
6963 *type = GL_INT_64_ANGLEX;
6964 *numParams = 1;
6965 return true;
6966 case GL_GPU_DISJOINT_EXT:
6967 if (!getExtensions().disjointTimerQuery)
6968 {
6969 return false;
6970 }
6971 *type = GL_INT;
6972 *numParams = 1;
6973 return true;
6974 case GL_COVERAGE_MODULATION_CHROMIUM:
6975 if (!getExtensions().framebufferMixedSamples)
6976 {
6977 return false;
6978 }
6979 *type = GL_INT;
6980 *numParams = 1;
6981 return true;
6982 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6983 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6984 {
6985 return false;
6986 }
6987 *type = GL_INT;
6988 *numParams = 1;
6989 return true;
6990 }
6991
6992 if (getExtensions().debug)
6993 {
6994 switch (pname)
6995 {
6996 case GL_DEBUG_LOGGED_MESSAGES:
6997 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6998 case GL_DEBUG_GROUP_STACK_DEPTH:
6999 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7000 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7001 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7002 case GL_MAX_LABEL_LENGTH:
7003 *type = GL_INT;
7004 *numParams = 1;
7005 return true;
7006
7007 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7008 case GL_DEBUG_OUTPUT:
7009 *type = GL_BOOL;
7010 *numParams = 1;
7011 return true;
7012 }
7013 }
7014
7015 if (getExtensions().multisampleCompatibility)
7016 {
7017 switch (pname)
7018 {
7019 case GL_MULTISAMPLE_EXT:
7020 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7021 *type = GL_BOOL;
7022 *numParams = 1;
7023 return true;
7024 }
7025 }
7026
7027 if (getExtensions().pathRendering)
7028 {
7029 switch (pname)
7030 {
7031 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7032 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7033 *type = GL_FLOAT;
7034 *numParams = 16;
7035 return true;
7036 }
7037 }
7038
7039 if (getExtensions().bindGeneratesResource)
7040 {
7041 switch (pname)
7042 {
7043 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7044 *type = GL_BOOL;
7045 *numParams = 1;
7046 return true;
7047 }
7048 }
7049
7050 if (getExtensions().clientArrays)
7051 {
7052 switch (pname)
7053 {
7054 case GL_CLIENT_ARRAYS_ANGLE:
7055 *type = GL_BOOL;
7056 *numParams = 1;
7057 return true;
7058 }
7059 }
7060
7061 if (getExtensions().sRGBWriteControl)
7062 {
7063 switch (pname)
7064 {
7065 case GL_FRAMEBUFFER_SRGB_EXT:
7066 *type = GL_BOOL;
7067 *numParams = 1;
7068 return true;
7069 }
7070 }
7071
7072 if (getExtensions().robustResourceInitialization &&
7073 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7074 {
7075 *type = GL_BOOL;
7076 *numParams = 1;
7077 return true;
7078 }
7079
7080 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7081 {
7082 *type = GL_BOOL;
7083 *numParams = 1;
7084 return true;
7085 }
7086
jchen1082af6202018-06-22 10:59:52 +08007087 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7088 {
7089 *type = GL_INT;
7090 *numParams = 1;
7091 return true;
7092 }
7093
Jamie Madill5b772312018-03-08 20:28:32 -05007094 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7095 switch (pname)
7096 {
7097 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7098 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7099 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7100 {
7101 return false;
7102 }
7103 *type = GL_INT;
7104 *numParams = 1;
7105 return true;
7106
7107 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7108 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7109 {
7110 return false;
7111 }
7112 *type = GL_INT;
7113 *numParams = 1;
7114 return true;
7115
7116 case GL_PROGRAM_BINARY_FORMATS_OES:
7117 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7118 {
7119 return false;
7120 }
7121 *type = GL_INT;
7122 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7123 return true;
7124
7125 case GL_PACK_ROW_LENGTH:
7126 case GL_PACK_SKIP_ROWS:
7127 case GL_PACK_SKIP_PIXELS:
7128 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7129 {
7130 return false;
7131 }
7132 *type = GL_INT;
7133 *numParams = 1;
7134 return true;
7135 case GL_UNPACK_ROW_LENGTH:
7136 case GL_UNPACK_SKIP_ROWS:
7137 case GL_UNPACK_SKIP_PIXELS:
7138 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7139 {
7140 return false;
7141 }
7142 *type = GL_INT;
7143 *numParams = 1;
7144 return true;
7145 case GL_VERTEX_ARRAY_BINDING:
7146 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7147 {
7148 return false;
7149 }
7150 *type = GL_INT;
7151 *numParams = 1;
7152 return true;
7153 case GL_PIXEL_PACK_BUFFER_BINDING:
7154 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7155 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7156 {
7157 return false;
7158 }
7159 *type = GL_INT;
7160 *numParams = 1;
7161 return true;
7162 case GL_MAX_SAMPLES:
7163 {
7164 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7165 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7166 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7167 {
7168 return false;
7169 }
7170 *type = GL_INT;
7171 *numParams = 1;
7172 return true;
7173
7174 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7175 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7176 {
7177 return false;
7178 }
7179 *type = GL_INT;
7180 *numParams = 1;
7181 return true;
7182 }
7183 }
7184
7185 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7186 {
7187 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7188 {
7189 return false;
7190 }
7191 *type = GL_INT;
7192 *numParams = 1;
7193 return true;
7194 }
7195
7196 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7197 {
7198 *type = GL_INT;
7199 *numParams = 1;
7200 return true;
7201 }
7202
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007203 if (getClientVersion() < Version(2, 0))
7204 {
7205 switch (pname)
7206 {
7207 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007208 case GL_CLIENT_ACTIVE_TEXTURE:
7209 case GL_MATRIX_MODE:
7210 case GL_MAX_TEXTURE_UNITS:
7211 case GL_MAX_MODELVIEW_STACK_DEPTH:
7212 case GL_MAX_PROJECTION_STACK_DEPTH:
7213 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007214 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007215 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007216 case GL_VERTEX_ARRAY_STRIDE:
7217 case GL_NORMAL_ARRAY_STRIDE:
7218 case GL_COLOR_ARRAY_STRIDE:
7219 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7220 case GL_VERTEX_ARRAY_SIZE:
7221 case GL_COLOR_ARRAY_SIZE:
7222 case GL_TEXTURE_COORD_ARRAY_SIZE:
7223 case GL_VERTEX_ARRAY_TYPE:
7224 case GL_NORMAL_ARRAY_TYPE:
7225 case GL_COLOR_ARRAY_TYPE:
7226 case GL_TEXTURE_COORD_ARRAY_TYPE:
7227 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7228 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7229 case GL_COLOR_ARRAY_BUFFER_BINDING:
7230 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7231 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7232 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7233 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007234 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007235 case GL_MODELVIEW_STACK_DEPTH:
7236 case GL_PROJECTION_STACK_DEPTH:
7237 case GL_TEXTURE_STACK_DEPTH:
7238 case GL_LOGIC_OP_MODE:
7239 case GL_BLEND_SRC:
7240 case GL_BLEND_DST:
7241 case GL_PERSPECTIVE_CORRECTION_HINT:
7242 case GL_POINT_SMOOTH_HINT:
7243 case GL_LINE_SMOOTH_HINT:
7244 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007245 *type = GL_INT;
7246 *numParams = 1;
7247 return true;
7248 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007249 case GL_FOG_DENSITY:
7250 case GL_FOG_START:
7251 case GL_FOG_END:
7252 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007253 case GL_POINT_SIZE:
7254 case GL_POINT_SIZE_MIN:
7255 case GL_POINT_SIZE_MAX:
7256 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007257 *type = GL_FLOAT;
7258 *numParams = 1;
7259 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007260 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007261 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007262 *type = GL_FLOAT;
7263 *numParams = 2;
7264 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007265 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007266 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007267 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007268 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007269 *type = GL_FLOAT;
7270 *numParams = 4;
7271 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007272 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007273 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007274 *type = GL_FLOAT;
7275 *numParams = 3;
7276 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007277 case GL_MODELVIEW_MATRIX:
7278 case GL_PROJECTION_MATRIX:
7279 case GL_TEXTURE_MATRIX:
7280 *type = GL_FLOAT;
7281 *numParams = 16;
7282 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007283 case GL_LIGHT_MODEL_TWO_SIDE:
7284 *type = GL_BOOL;
7285 *numParams = 1;
7286 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007287 }
7288 }
7289
Jamie Madill5b772312018-03-08 20:28:32 -05007290 if (getClientVersion() < Version(3, 0))
7291 {
7292 return false;
7293 }
7294
7295 // Check for ES3.0+ parameter names
7296 switch (pname)
7297 {
7298 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7299 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7300 case GL_UNIFORM_BUFFER_BINDING:
7301 case GL_TRANSFORM_FEEDBACK_BINDING:
7302 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7303 case GL_COPY_READ_BUFFER_BINDING:
7304 case GL_COPY_WRITE_BUFFER_BINDING:
7305 case GL_SAMPLER_BINDING:
7306 case GL_READ_BUFFER:
7307 case GL_TEXTURE_BINDING_3D:
7308 case GL_TEXTURE_BINDING_2D_ARRAY:
7309 case GL_MAX_3D_TEXTURE_SIZE:
7310 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7311 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7312 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7313 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7314 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7315 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7316 case GL_MAX_VARYING_COMPONENTS:
7317 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7318 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7319 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7320 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7321 case GL_NUM_EXTENSIONS:
7322 case GL_MAJOR_VERSION:
7323 case GL_MINOR_VERSION:
7324 case GL_MAX_ELEMENTS_INDICES:
7325 case GL_MAX_ELEMENTS_VERTICES:
7326 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7327 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7328 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7329 case GL_UNPACK_IMAGE_HEIGHT:
7330 case GL_UNPACK_SKIP_IMAGES:
7331 {
7332 *type = GL_INT;
7333 *numParams = 1;
7334 return true;
7335 }
7336
7337 case GL_MAX_ELEMENT_INDEX:
7338 case GL_MAX_UNIFORM_BLOCK_SIZE:
7339 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7340 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7341 case GL_MAX_SERVER_WAIT_TIMEOUT:
7342 {
7343 *type = GL_INT_64_ANGLEX;
7344 *numParams = 1;
7345 return true;
7346 }
7347
7348 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7349 case GL_TRANSFORM_FEEDBACK_PAUSED:
7350 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7351 case GL_RASTERIZER_DISCARD:
7352 {
7353 *type = GL_BOOL;
7354 *numParams = 1;
7355 return true;
7356 }
7357
7358 case GL_MAX_TEXTURE_LOD_BIAS:
7359 {
7360 *type = GL_FLOAT;
7361 *numParams = 1;
7362 return true;
7363 }
7364 }
7365
7366 if (getExtensions().requestExtension)
7367 {
7368 switch (pname)
7369 {
7370 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7371 *type = GL_INT;
7372 *numParams = 1;
7373 return true;
7374 }
7375 }
7376
7377 if (getClientVersion() < Version(3, 1))
7378 {
7379 return false;
7380 }
7381
7382 switch (pname)
7383 {
7384 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7385 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7386 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7387 case GL_MAX_FRAMEBUFFER_WIDTH:
7388 case GL_MAX_FRAMEBUFFER_HEIGHT:
7389 case GL_MAX_FRAMEBUFFER_SAMPLES:
7390 case GL_MAX_SAMPLE_MASK_WORDS:
7391 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7392 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7393 case GL_MAX_INTEGER_SAMPLES:
7394 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7395 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7396 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7397 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7398 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7399 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7400 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7401 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7402 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7403 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7404 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7405 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7406 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7407 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7408 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7409 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7410 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7411 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7412 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7413 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7414 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7415 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7416 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7417 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7418 case GL_MAX_UNIFORM_LOCATIONS:
7419 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7420 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7421 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7422 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7423 case GL_MAX_IMAGE_UNITS:
7424 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7425 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7426 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7427 case GL_SHADER_STORAGE_BUFFER_BINDING:
7428 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7429 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7430 *type = GL_INT;
7431 *numParams = 1;
7432 return true;
7433 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7434 *type = GL_INT_64_ANGLEX;
7435 *numParams = 1;
7436 return true;
7437 case GL_SAMPLE_MASK:
7438 *type = GL_BOOL;
7439 *numParams = 1;
7440 return true;
7441 }
7442
7443 if (getExtensions().geometryShader)
7444 {
7445 switch (pname)
7446 {
7447 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7448 case GL_LAYER_PROVOKING_VERTEX_EXT:
7449 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7450 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7451 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7452 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7453 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7454 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7455 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7456 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7457 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7458 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7459 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7460 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7461 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7462 *type = GL_INT;
7463 *numParams = 1;
7464 return true;
7465 }
7466 }
7467
7468 return false;
7469}
7470
7471bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7472{
7473 if (getClientVersion() < Version(3, 0))
7474 {
7475 return false;
7476 }
7477
7478 switch (target)
7479 {
7480 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7481 case GL_UNIFORM_BUFFER_BINDING:
7482 {
7483 *type = GL_INT;
7484 *numParams = 1;
7485 return true;
7486 }
7487 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7488 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7489 case GL_UNIFORM_BUFFER_START:
7490 case GL_UNIFORM_BUFFER_SIZE:
7491 {
7492 *type = GL_INT_64_ANGLEX;
7493 *numParams = 1;
7494 return true;
7495 }
7496 }
7497
7498 if (getClientVersion() < Version(3, 1))
7499 {
7500 return false;
7501 }
7502
7503 switch (target)
7504 {
7505 case GL_IMAGE_BINDING_LAYERED:
7506 {
7507 *type = GL_BOOL;
7508 *numParams = 1;
7509 return true;
7510 }
7511 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7512 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7513 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7514 case GL_SHADER_STORAGE_BUFFER_BINDING:
7515 case GL_VERTEX_BINDING_BUFFER:
7516 case GL_VERTEX_BINDING_DIVISOR:
7517 case GL_VERTEX_BINDING_OFFSET:
7518 case GL_VERTEX_BINDING_STRIDE:
7519 case GL_SAMPLE_MASK_VALUE:
7520 case GL_IMAGE_BINDING_NAME:
7521 case GL_IMAGE_BINDING_LEVEL:
7522 case GL_IMAGE_BINDING_LAYER:
7523 case GL_IMAGE_BINDING_ACCESS:
7524 case GL_IMAGE_BINDING_FORMAT:
7525 {
7526 *type = GL_INT;
7527 *numParams = 1;
7528 return true;
7529 }
7530 case GL_ATOMIC_COUNTER_BUFFER_START:
7531 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7532 case GL_SHADER_STORAGE_BUFFER_START:
7533 case GL_SHADER_STORAGE_BUFFER_SIZE:
7534 {
7535 *type = GL_INT_64_ANGLEX;
7536 *numParams = 1;
7537 return true;
7538 }
7539 }
7540
7541 return false;
7542}
7543
7544Program *Context::getProgram(GLuint handle) const
7545{
7546 return mState.mShaderPrograms->getProgram(handle);
7547}
7548
7549Shader *Context::getShader(GLuint handle) const
7550{
7551 return mState.mShaderPrograms->getShader(handle);
7552}
7553
7554bool Context::isTextureGenerated(GLuint texture) const
7555{
7556 return mState.mTextures->isHandleGenerated(texture);
7557}
7558
7559bool Context::isBufferGenerated(GLuint buffer) const
7560{
7561 return mState.mBuffers->isHandleGenerated(buffer);
7562}
7563
7564bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7565{
7566 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7567}
7568
7569bool Context::isFramebufferGenerated(GLuint framebuffer) const
7570{
7571 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7572}
7573
7574bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7575{
7576 return mState.mPipelines->isHandleGenerated(pipeline);
7577}
7578
7579bool Context::usingDisplayTextureShareGroup() const
7580{
7581 return mDisplayTextureShareGroup;
7582}
7583
7584GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7585{
7586 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7587 internalformat == GL_DEPTH_STENCIL
7588 ? GL_DEPTH24_STENCIL8
7589 : internalformat;
7590}
7591
jchen1082af6202018-06-22 10:59:52 +08007592void Context::maxShaderCompilerThreads(GLuint count)
7593{
jchen107ae70d82018-07-06 13:47:01 +08007594 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08007595 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007596 // A count of zero specifies a request for no parallel compiling or linking.
7597 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7598 {
7599 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7600 }
7601 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007602}
7603
Jamie Madill2eb65032018-07-30 10:25:57 -04007604bool Context::isGLES1() const
7605{
7606 return mState.getClientVersion() < Version(2, 0);
7607}
7608
Jamie Madilla11819d2018-07-30 10:26:01 -04007609void Context::onSubjectStateChange(const Context *context,
7610 angle::SubjectIndex index,
7611 angle::SubjectMessage message)
7612{
Jamie Madilla11819d2018-07-30 10:26:01 -04007613 switch (index)
7614 {
7615 case kVertexArraySubjectIndex:
7616 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
Jamie Madillc43cdad2018-08-08 15:49:25 -04007617 mStateCache.onVertexArraySizeChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04007618 break;
7619
7620 case kReadFramebufferSubjectIndex:
7621 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
7622 break;
7623
7624 case kDrawFramebufferSubjectIndex:
7625 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
7626 break;
7627
7628 default:
Jamie Madill6c43a012018-08-08 15:49:27 -04007629 ASSERT(index < mGLState.getActiveTexturesCache().size());
7630 mGLState.onActiveTextureStateChange(index);
Jamie Madilla11819d2018-07-30 10:26:01 -04007631 break;
7632 }
7633}
7634
Jamie Madill6b873dd2018-07-12 23:56:30 -04007635// ErrorSet implementation.
7636ErrorSet::ErrorSet(Context *context) : mContext(context)
7637{
7638}
7639
7640ErrorSet::~ErrorSet() = default;
7641
Jamie Madill306b6c12018-07-27 08:12:49 -04007642void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007643{
7644 // This internal enum is used to filter internal errors that are already handled.
7645 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7646 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7647 {
7648 return;
7649 }
7650
7651 if (ANGLE_UNLIKELY(error.isError()))
7652 {
7653 GLenum code = error.getCode();
7654 mErrors.insert(code);
7655 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7656 {
7657 mContext->markContextLost();
7658 }
7659
7660 ASSERT(!error.getMessage().empty());
7661 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7662 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7663 error.getMessage());
7664 }
7665}
7666
7667bool ErrorSet::empty() const
7668{
7669 return mErrors.empty();
7670}
7671
7672GLenum ErrorSet::popError()
7673{
7674 ASSERT(!empty());
7675 GLenum error = *mErrors.begin();
7676 mErrors.erase(mErrors.begin());
7677 return error;
7678}
Jamie Madilldc358af2018-07-31 11:22:13 -04007679
7680// StateCache implementation.
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007681StateCache::StateCache()
7682 : mCachedHasAnyEnabledClientAttrib(false),
7683 mCachedNonInstancedVertexElementLimit(0),
7684 mCachedInstancedVertexElementLimit(0)
Jamie Madilldc358af2018-07-31 11:22:13 -04007685{
7686}
7687
7688StateCache::~StateCache() = default;
7689
7690void StateCache::updateActiveAttribsMask(Context *context)
7691{
7692 bool isGLES1 = context->isGLES1();
7693 const State &glState = context->getGLState();
7694
7695 if (!isGLES1 && !glState.getProgram())
7696 {
7697 mCachedActiveBufferedAttribsMask = AttributesMask();
7698 mCachedActiveClientAttribsMask = AttributesMask();
7699 return;
7700 }
7701
7702 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7703 : glState.getProgram()->getActiveAttribLocationsMask();
7704
7705 const VertexArray *vao = glState.getVertexArray();
7706 ASSERT(vao);
7707
7708 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7709 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
7710
7711 activeAttribs &= enabledAttribs;
7712
7713 mCachedActiveClientAttribsMask = activeAttribs & clientAttribs;
7714 mCachedActiveBufferedAttribsMask = activeAttribs & ~clientAttribs;
7715 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7716}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007717
7718void StateCache::updateVertexElementLimits(Context *context)
7719{
7720 const VertexArray *vao = context->getGLState().getVertexArray();
7721
7722 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7723 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7724
7725 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
7726 // If there are no buffered attributes then we should not limit the draw call count.
7727 if (!vao || !mCachedActiveBufferedAttribsMask.any())
7728 {
7729 return;
7730 }
7731
7732 const auto &vertexAttribs = vao->getVertexAttributes();
7733 const auto &vertexBindings = vao->getVertexBindings();
7734
7735 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
7736 {
7737 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
7738 ASSERT(attrib.enabled);
7739
7740 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
7741 ASSERT(context->isGLES1() ||
7742 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
7743
7744 GLint64 limit = attrib.getCachedElementLimit();
7745 if (binding.getDivisor() > 0)
7746 {
7747 mCachedInstancedVertexElementLimit =
7748 std::min(mCachedInstancedVertexElementLimit, limit);
7749 }
7750 else
7751 {
7752 mCachedNonInstancedVertexElementLimit =
7753 std::min(mCachedNonInstancedVertexElementLimit, limit);
7754 }
7755 }
7756}
Jamie Madillc43cdad2018-08-08 15:49:25 -04007757
7758void StateCache::onVertexArrayBindingChange(Context *context)
7759{
7760 updateActiveAttribsMask(context);
7761 updateVertexElementLimits(context);
7762}
7763
7764void StateCache::onProgramExecutableChange(Context *context)
7765{
7766 updateActiveAttribsMask(context);
7767 updateVertexElementLimits(context);
7768}
7769
7770void StateCache::onVertexArraySizeChange(Context *context)
7771{
7772 updateVertexElementLimits(context);
7773}
7774
7775void StateCache::onVertexArrayStateChange(Context *context)
7776{
7777 updateActiveAttribsMask(context);
7778 updateVertexElementLimits(context);
7779}
7780
7781void StateCache::onGLES1ClientStateChange(Context *context)
7782{
7783 updateActiveAttribsMask(context);
7784}
Jamie Madillc29968b2016-01-20 11:17:23 -05007785} // namespace gl