blob: 3e1f2f5aa0ba85ff97d7a1fe27bcef905c0988ea [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;
Jamie Madill231c7f52017-04-26 13:45:37 -04001387 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1388 ASSERT(mExtensions.textureFilterAnisotropic);
1389 *params = mExtensions.maxTextureAnisotropy;
1390 break;
1391 case GL_MAX_TEXTURE_LOD_BIAS:
1392 *params = mCaps.maxLODBias;
1393 break;
1394
1395 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1396 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1397 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001398 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1399 // GLES1 constants for modelview/projection matrix.
1400 if (getClientVersion() < Version(2, 0))
1401 {
1402 mGLState.getFloatv(pname, params);
1403 }
1404 else
1405 {
1406 ASSERT(mExtensions.pathRendering);
1407 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1408 memcpy(params, m, 16 * sizeof(GLfloat));
1409 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001410 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001411 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001412
Jamie Madill231c7f52017-04-26 13:45:37 -04001413 default:
1414 mGLState.getFloatv(pname, params);
1415 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001416 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001417}
1418
Jamie Madillc1d770e2017-04-13 17:31:24 -04001419void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001420{
Shannon Woods53a94a82014-06-24 15:20:36 -04001421 // Queries about context capabilities and maximums are answered by Context.
1422 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001423
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001424 switch (pname)
1425 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001426 case GL_MAX_VERTEX_ATTRIBS:
1427 *params = mCaps.maxVertexAttributes;
1428 break;
1429 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1430 *params = mCaps.maxVertexUniformVectors;
1431 break;
1432 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001433 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001434 break;
1435 case GL_MAX_VARYING_VECTORS:
1436 *params = mCaps.maxVaryingVectors;
1437 break;
1438 case GL_MAX_VARYING_COMPONENTS:
1439 *params = mCaps.maxVertexOutputComponents;
1440 break;
1441 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1442 *params = mCaps.maxCombinedTextureImageUnits;
1443 break;
1444 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001445 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001446 break;
1447 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001448 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001449 break;
1450 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1451 *params = mCaps.maxFragmentUniformVectors;
1452 break;
1453 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001454 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001455 break;
1456 case GL_MAX_RENDERBUFFER_SIZE:
1457 *params = mCaps.maxRenderbufferSize;
1458 break;
1459 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1460 *params = mCaps.maxColorAttachments;
1461 break;
1462 case GL_MAX_DRAW_BUFFERS_EXT:
1463 *params = mCaps.maxDrawBuffers;
1464 break;
1465 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1466 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1467 case GL_SUBPIXEL_BITS:
1468 *params = 4;
1469 break;
1470 case GL_MAX_TEXTURE_SIZE:
1471 *params = mCaps.max2DTextureSize;
1472 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001473 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1474 *params = mCaps.maxRectangleTextureSize;
1475 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001476 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1477 *params = mCaps.maxCubeMapTextureSize;
1478 break;
1479 case GL_MAX_3D_TEXTURE_SIZE:
1480 *params = mCaps.max3DTextureSize;
1481 break;
1482 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1483 *params = mCaps.maxArrayTextureLayers;
1484 break;
1485 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1486 *params = mCaps.uniformBufferOffsetAlignment;
1487 break;
1488 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1489 *params = mCaps.maxUniformBufferBindings;
1490 break;
1491 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001492 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001493 break;
1494 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001495 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001496 break;
1497 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1498 *params = mCaps.maxCombinedTextureImageUnits;
1499 break;
1500 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1501 *params = mCaps.maxVertexOutputComponents;
1502 break;
1503 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1504 *params = mCaps.maxFragmentInputComponents;
1505 break;
1506 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1507 *params = mCaps.minProgramTexelOffset;
1508 break;
1509 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1510 *params = mCaps.maxProgramTexelOffset;
1511 break;
1512 case GL_MAJOR_VERSION:
1513 *params = getClientVersion().major;
1514 break;
1515 case GL_MINOR_VERSION:
1516 *params = getClientVersion().minor;
1517 break;
1518 case GL_MAX_ELEMENTS_INDICES:
1519 *params = mCaps.maxElementsIndices;
1520 break;
1521 case GL_MAX_ELEMENTS_VERTICES:
1522 *params = mCaps.maxElementsVertices;
1523 break;
1524 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1525 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1526 break;
1527 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1528 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1529 break;
1530 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1531 *params = mCaps.maxTransformFeedbackSeparateComponents;
1532 break;
1533 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1534 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1535 break;
1536 case GL_MAX_SAMPLES_ANGLE:
1537 *params = mCaps.maxSamples;
1538 break;
1539 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001540 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001541 params[0] = mCaps.maxViewportWidth;
1542 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001543 }
1544 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001545 case GL_COMPRESSED_TEXTURE_FORMATS:
1546 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1547 params);
1548 break;
1549 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1550 *params = mResetStrategy;
1551 break;
1552 case GL_NUM_SHADER_BINARY_FORMATS:
1553 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1554 break;
1555 case GL_SHADER_BINARY_FORMATS:
1556 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1557 break;
1558 case GL_NUM_PROGRAM_BINARY_FORMATS:
1559 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1560 break;
1561 case GL_PROGRAM_BINARY_FORMATS:
1562 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1563 break;
1564 case GL_NUM_EXTENSIONS:
1565 *params = static_cast<GLint>(mExtensionStrings.size());
1566 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001567
Jamie Madill231c7f52017-04-26 13:45:37 -04001568 // GL_KHR_debug
1569 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1570 *params = mExtensions.maxDebugMessageLength;
1571 break;
1572 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1573 *params = mExtensions.maxDebugLoggedMessages;
1574 break;
1575 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1576 *params = mExtensions.maxDebugGroupStackDepth;
1577 break;
1578 case GL_MAX_LABEL_LENGTH:
1579 *params = mExtensions.maxLabelLength;
1580 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001581
Martin Radeve5285d22017-07-14 16:23:53 +03001582 // GL_ANGLE_multiview
1583 case GL_MAX_VIEWS_ANGLE:
1584 *params = mExtensions.maxViews;
1585 break;
1586
Jamie Madill231c7f52017-04-26 13:45:37 -04001587 // GL_EXT_disjoint_timer_query
1588 case GL_GPU_DISJOINT_EXT:
1589 *params = mImplementation->getGPUDisjoint();
1590 break;
1591 case GL_MAX_FRAMEBUFFER_WIDTH:
1592 *params = mCaps.maxFramebufferWidth;
1593 break;
1594 case GL_MAX_FRAMEBUFFER_HEIGHT:
1595 *params = mCaps.maxFramebufferHeight;
1596 break;
1597 case GL_MAX_FRAMEBUFFER_SAMPLES:
1598 *params = mCaps.maxFramebufferSamples;
1599 break;
1600 case GL_MAX_SAMPLE_MASK_WORDS:
1601 *params = mCaps.maxSampleMaskWords;
1602 break;
1603 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1604 *params = mCaps.maxColorTextureSamples;
1605 break;
1606 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1607 *params = mCaps.maxDepthTextureSamples;
1608 break;
1609 case GL_MAX_INTEGER_SAMPLES:
1610 *params = mCaps.maxIntegerSamples;
1611 break;
1612 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1613 *params = mCaps.maxVertexAttribRelativeOffset;
1614 break;
1615 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1616 *params = mCaps.maxVertexAttribBindings;
1617 break;
1618 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1619 *params = mCaps.maxVertexAttribStride;
1620 break;
1621 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001622 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001623 break;
1624 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001625 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001626 break;
1627 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001628 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001629 break;
1630 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001631 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001632 break;
1633 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001634 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001635 break;
1636 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001637 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001638 break;
1639 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001640 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001641 break;
1642 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001643 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001644 break;
1645 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1646 *params = mCaps.minProgramTextureGatherOffset;
1647 break;
1648 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1649 *params = mCaps.maxProgramTextureGatherOffset;
1650 break;
1651 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1652 *params = mCaps.maxComputeWorkGroupInvocations;
1653 break;
1654 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001655 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001656 break;
1657 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001658 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001659 break;
1660 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1661 *params = mCaps.maxComputeSharedMemorySize;
1662 break;
1663 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001664 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001665 break;
1666 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001667 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001668 break;
1669 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001670 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001671 break;
1672 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001673 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001674 break;
1675 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001676 *params =
1677 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001678 break;
1679 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001680 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001681 break;
1682 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1683 *params = mCaps.maxCombinedShaderOutputResources;
1684 break;
1685 case GL_MAX_UNIFORM_LOCATIONS:
1686 *params = mCaps.maxUniformLocations;
1687 break;
1688 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1689 *params = mCaps.maxAtomicCounterBufferBindings;
1690 break;
1691 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1692 *params = mCaps.maxAtomicCounterBufferSize;
1693 break;
1694 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1695 *params = mCaps.maxCombinedAtomicCounterBuffers;
1696 break;
1697 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1698 *params = mCaps.maxCombinedAtomicCounters;
1699 break;
1700 case GL_MAX_IMAGE_UNITS:
1701 *params = mCaps.maxImageUnits;
1702 break;
1703 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1704 *params = mCaps.maxCombinedImageUniforms;
1705 break;
1706 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1707 *params = mCaps.maxShaderStorageBufferBindings;
1708 break;
1709 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1710 *params = mCaps.maxCombinedShaderStorageBlocks;
1711 break;
1712 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1713 *params = mCaps.shaderStorageBufferOffsetAlignment;
1714 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001715
1716 // GL_EXT_geometry_shader
1717 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1718 *params = mCaps.maxFramebufferLayers;
1719 break;
1720 case GL_LAYER_PROVOKING_VERTEX_EXT:
1721 *params = mCaps.layerProvokingVertex;
1722 break;
1723 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001724 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001725 break;
1726 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001727 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001728 break;
1729 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001730 *params =
1731 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001732 break;
1733 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1734 *params = mCaps.maxGeometryInputComponents;
1735 break;
1736 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1737 *params = mCaps.maxGeometryOutputComponents;
1738 break;
1739 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1740 *params = mCaps.maxGeometryOutputVertices;
1741 break;
1742 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1743 *params = mCaps.maxGeometryTotalOutputComponents;
1744 break;
1745 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1746 *params = mCaps.maxGeometryShaderInvocations;
1747 break;
1748 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001749 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001750 break;
1751 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001752 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001753 break;
1754 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001755 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001756 break;
1757 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001758 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001759 break;
1760 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001761 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001762 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001763 // GLES1 emulation: Caps queries
1764 case GL_MAX_TEXTURE_UNITS:
1765 *params = mCaps.maxMultitextureUnits;
1766 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001767 case GL_MAX_MODELVIEW_STACK_DEPTH:
1768 *params = mCaps.maxModelviewMatrixStackDepth;
1769 break;
1770 case GL_MAX_PROJECTION_STACK_DEPTH:
1771 *params = mCaps.maxProjectionMatrixStackDepth;
1772 break;
1773 case GL_MAX_TEXTURE_STACK_DEPTH:
1774 *params = mCaps.maxTextureMatrixStackDepth;
1775 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001776 case GL_MAX_LIGHTS:
1777 *params = mCaps.maxLights;
1778 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001779 case GL_MAX_CLIP_PLANES:
1780 *params = mCaps.maxClipPlanes;
1781 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001782 // GLES1 emulation: Vertex attribute queries
1783 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1784 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1785 case GL_COLOR_ARRAY_BUFFER_BINDING:
1786 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1787 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1788 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1789 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1790 break;
1791 case GL_VERTEX_ARRAY_STRIDE:
1792 case GL_NORMAL_ARRAY_STRIDE:
1793 case GL_COLOR_ARRAY_STRIDE:
1794 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1795 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1796 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1797 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1798 break;
1799 case GL_VERTEX_ARRAY_SIZE:
1800 case GL_COLOR_ARRAY_SIZE:
1801 case GL_TEXTURE_COORD_ARRAY_SIZE:
1802 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1803 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1804 break;
1805 case GL_VERTEX_ARRAY_TYPE:
1806 case GL_COLOR_ARRAY_TYPE:
1807 case GL_NORMAL_ARRAY_TYPE:
1808 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1809 case GL_TEXTURE_COORD_ARRAY_TYPE:
1810 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1811 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1812 break;
1813
jchen1082af6202018-06-22 10:59:52 +08001814 // GL_KHR_parallel_shader_compile
1815 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1816 *params = mGLState.getMaxShaderCompilerThreads();
1817 break;
1818
Jamie Madill231c7f52017-04-26 13:45:37 -04001819 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001820 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001821 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001822 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001823}
1824
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001825void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001826{
Shannon Woods53a94a82014-06-24 15:20:36 -04001827 // Queries about context capabilities and maximums are answered by Context.
1828 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001829 switch (pname)
1830 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001831 case GL_MAX_ELEMENT_INDEX:
1832 *params = mCaps.maxElementIndex;
1833 break;
1834 case GL_MAX_UNIFORM_BLOCK_SIZE:
1835 *params = mCaps.maxUniformBlockSize;
1836 break;
1837 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001838 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001839 break;
1840 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001841 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001842 break;
1843 case GL_MAX_SERVER_WAIT_TIMEOUT:
1844 *params = mCaps.maxServerWaitTimeout;
1845 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001846
Jamie Madill231c7f52017-04-26 13:45:37 -04001847 // GL_EXT_disjoint_timer_query
1848 case GL_TIMESTAMP_EXT:
1849 *params = mImplementation->getTimestamp();
1850 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001851
Jamie Madill231c7f52017-04-26 13:45:37 -04001852 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1853 *params = mCaps.maxShaderStorageBlockSize;
1854 break;
1855 default:
1856 UNREACHABLE();
1857 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001858 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001859}
1860
Geoff Lang70d0f492015-12-10 17:45:46 -05001861void Context::getPointerv(GLenum pname, void **params) const
1862{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001863 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001864}
1865
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001866void Context::getPointervRobustANGLERobust(GLenum pname,
1867 GLsizei bufSize,
1868 GLsizei *length,
1869 void **params)
1870{
1871 UNIMPLEMENTED();
1872}
1873
Martin Radev66fb8202016-07-28 11:45:20 +03001874void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001875{
Shannon Woods53a94a82014-06-24 15:20:36 -04001876 // Queries about context capabilities and maximums are answered by Context.
1877 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001878
1879 GLenum nativeType;
1880 unsigned int numParams;
1881 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1882 ASSERT(queryStatus);
1883
1884 if (nativeType == GL_INT)
1885 {
1886 switch (target)
1887 {
1888 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1889 ASSERT(index < 3u);
1890 *data = mCaps.maxComputeWorkGroupCount[index];
1891 break;
1892 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1893 ASSERT(index < 3u);
1894 *data = mCaps.maxComputeWorkGroupSize[index];
1895 break;
1896 default:
1897 mGLState.getIntegeri_v(target, index, data);
1898 }
1899 }
1900 else
1901 {
1902 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1903 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001904}
1905
Brandon Jones59770802018-04-02 13:18:42 -07001906void Context::getIntegeri_vRobust(GLenum target,
1907 GLuint index,
1908 GLsizei bufSize,
1909 GLsizei *length,
1910 GLint *data)
1911{
1912 getIntegeri_v(target, index, data);
1913}
1914
Martin Radev66fb8202016-07-28 11:45:20 +03001915void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001916{
Shannon Woods53a94a82014-06-24 15:20:36 -04001917 // Queries about context capabilities and maximums are answered by Context.
1918 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001919
1920 GLenum nativeType;
1921 unsigned int numParams;
1922 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1923 ASSERT(queryStatus);
1924
1925 if (nativeType == GL_INT_64_ANGLEX)
1926 {
1927 mGLState.getInteger64i_v(target, index, data);
1928 }
1929 else
1930 {
1931 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1932 }
1933}
1934
Brandon Jones59770802018-04-02 13:18:42 -07001935void Context::getInteger64i_vRobust(GLenum target,
1936 GLuint index,
1937 GLsizei bufSize,
1938 GLsizei *length,
1939 GLint64 *data)
1940{
1941 getInteger64i_v(target, index, data);
1942}
1943
Martin Radev66fb8202016-07-28 11:45:20 +03001944void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1945{
1946 // Queries about context capabilities and maximums are answered by Context.
1947 // Queries about current GL state values are answered by State.
1948
1949 GLenum nativeType;
1950 unsigned int numParams;
1951 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1952 ASSERT(queryStatus);
1953
1954 if (nativeType == GL_BOOL)
1955 {
1956 mGLState.getBooleani_v(target, index, data);
1957 }
1958 else
1959 {
1960 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1961 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001962}
1963
Brandon Jones59770802018-04-02 13:18:42 -07001964void Context::getBooleani_vRobust(GLenum target,
1965 GLuint index,
1966 GLsizei bufSize,
1967 GLsizei *length,
1968 GLboolean *data)
1969{
1970 getBooleani_v(target, index, data);
1971}
1972
Corentin Wallez336129f2017-10-17 15:55:40 -04001973void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001974{
1975 Buffer *buffer = mGLState.getTargetBuffer(target);
1976 QueryBufferParameteriv(buffer, pname, params);
1977}
1978
Brandon Jones59770802018-04-02 13:18:42 -07001979void Context::getBufferParameterivRobust(BufferBinding target,
1980 GLenum pname,
1981 GLsizei bufSize,
1982 GLsizei *length,
1983 GLint *params)
1984{
1985 getBufferParameteriv(target, pname, params);
1986}
1987
He Yunchao010e4db2017-03-03 14:22:06 +08001988void Context::getFramebufferAttachmentParameteriv(GLenum target,
1989 GLenum attachment,
1990 GLenum pname,
1991 GLint *params)
1992{
1993 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001994 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001995}
1996
Brandon Jones59770802018-04-02 13:18:42 -07001997void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1998 GLenum attachment,
1999 GLenum pname,
2000 GLsizei bufSize,
2001 GLsizei *length,
2002 GLint *params)
2003{
2004 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2005}
2006
He Yunchao010e4db2017-03-03 14:22:06 +08002007void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2008{
2009 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2010 QueryRenderbufferiv(this, renderbuffer, pname, params);
2011}
2012
Brandon Jones59770802018-04-02 13:18:42 -07002013void Context::getRenderbufferParameterivRobust(GLenum target,
2014 GLenum pname,
2015 GLsizei bufSize,
2016 GLsizei *length,
2017 GLint *params)
2018{
2019 getRenderbufferParameteriv(target, pname, params);
2020}
2021
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002022void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002023{
2024 Texture *texture = getTargetTexture(target);
2025 QueryTexParameterfv(texture, pname, params);
2026}
2027
Brandon Jones59770802018-04-02 13:18:42 -07002028void Context::getTexParameterfvRobust(TextureType target,
2029 GLenum pname,
2030 GLsizei bufSize,
2031 GLsizei *length,
2032 GLfloat *params)
2033{
2034 getTexParameterfv(target, pname, params);
2035}
2036
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002037void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002038{
2039 Texture *texture = getTargetTexture(target);
2040 QueryTexParameteriv(texture, pname, params);
2041}
Jiajia Qin5451d532017-11-16 17:16:34 +08002042
Brandon Jones59770802018-04-02 13:18:42 -07002043void Context::getTexParameterivRobust(TextureType target,
2044 GLenum pname,
2045 GLsizei bufSize,
2046 GLsizei *length,
2047 GLint *params)
2048{
2049 getTexParameteriv(target, pname, params);
2050}
2051
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002052void Context::getTexParameterIivRobust(TextureType target,
2053 GLenum pname,
2054 GLsizei bufSize,
2055 GLsizei *length,
2056 GLint *params)
2057{
2058 UNIMPLEMENTED();
2059}
2060
2061void Context::getTexParameterIuivRobust(TextureType target,
2062 GLenum pname,
2063 GLsizei bufSize,
2064 GLsizei *length,
2065 GLuint *params)
2066{
2067 UNIMPLEMENTED();
2068}
2069
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002070void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002071{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002072 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002073 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002074}
2075
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002076void Context::getTexLevelParameterivRobust(TextureTarget target,
2077 GLint level,
2078 GLenum pname,
2079 GLsizei bufSize,
2080 GLsizei *length,
2081 GLint *params)
2082{
2083 UNIMPLEMENTED();
2084}
2085
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002086void Context::getTexLevelParameterfv(TextureTarget target,
2087 GLint level,
2088 GLenum pname,
2089 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002090{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002091 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002092 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002093}
2094
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002095void Context::getTexLevelParameterfvRobust(TextureTarget target,
2096 GLint level,
2097 GLenum pname,
2098 GLsizei bufSize,
2099 GLsizei *length,
2100 GLfloat *params)
2101{
2102 UNIMPLEMENTED();
2103}
2104
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002105void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002106{
2107 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002108 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002109 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002110}
2111
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002112void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002113{
2114 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002115 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002116 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002117}
2118
Brandon Jones59770802018-04-02 13:18:42 -07002119void Context::texParameterfvRobust(TextureType target,
2120 GLenum pname,
2121 GLsizei bufSize,
2122 const GLfloat *params)
2123{
2124 texParameterfv(target, pname, params);
2125}
2126
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002127void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002128{
2129 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002130 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002131 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002132}
2133
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002134void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002135{
2136 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002137 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002138 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002139}
2140
Brandon Jones59770802018-04-02 13:18:42 -07002141void Context::texParameterivRobust(TextureType target,
2142 GLenum pname,
2143 GLsizei bufSize,
2144 const GLint *params)
2145{
2146 texParameteriv(target, pname, params);
2147}
2148
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002149void Context::texParameterIivRobust(TextureType target,
2150 GLenum pname,
2151 GLsizei bufSize,
2152 const GLint *params)
2153{
2154 UNIMPLEMENTED();
2155}
2156
2157void Context::texParameterIuivRobust(TextureType target,
2158 GLenum pname,
2159 GLsizei bufSize,
2160 const GLuint *params)
2161{
2162 UNIMPLEMENTED();
2163}
2164
Jamie Madill493f9572018-05-24 19:52:15 -04002165void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002166{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002167 // No-op if count draws no primitives for given mode
2168 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002169 {
2170 return;
2171 }
2172
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002173 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002174 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002175 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002176}
2177
Jamie Madill493f9572018-05-24 19:52:15 -04002178void Context::drawArraysInstanced(PrimitiveMode mode,
2179 GLint first,
2180 GLsizei count,
2181 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002182{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002183 // No-op if count draws no primitives for given mode
2184 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002185 {
2186 return;
2187 }
2188
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002189 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002190 ANGLE_CONTEXT_TRY(
2191 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002192 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2193 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002194}
2195
Jamie Madill493f9572018-05-24 19:52:15 -04002196void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002197{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002198 // No-op if count draws no primitives for given mode
2199 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002200 {
2201 return;
2202 }
2203
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002204 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002205 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002206}
2207
Jamie Madill493f9572018-05-24 19:52:15 -04002208void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002209 GLsizei count,
2210 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002211 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002212 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002213{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002214 // No-op if count draws no primitives for given mode
2215 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002216 {
2217 return;
2218 }
2219
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002220 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002221 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002222 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002223}
2224
Jamie Madill493f9572018-05-24 19:52:15 -04002225void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002226 GLuint start,
2227 GLuint end,
2228 GLsizei count,
2229 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002230 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002231{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002232 // No-op if count draws no primitives for given mode
2233 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002234 {
2235 return;
2236 }
2237
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002238 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002239 ANGLE_CONTEXT_TRY(
2240 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002241}
2242
Jamie Madill493f9572018-05-24 19:52:15 -04002243void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002244{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002245 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002246 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002247}
2248
Jamie Madill493f9572018-05-24 19:52:15 -04002249void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002250{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002251 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002252 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002253}
2254
Jamie Madill675fe712016-12-19 13:07:54 -05002255void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002256{
Jamie Madillafa02a22017-11-23 12:57:38 -05002257 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002258}
2259
Jamie Madill675fe712016-12-19 13:07:54 -05002260void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002261{
Jamie Madillafa02a22017-11-23 12:57:38 -05002262 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002263}
2264
Austin Kinross6ee1e782015-05-29 17:05:37 -07002265void Context::insertEventMarker(GLsizei length, const char *marker)
2266{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002267 ASSERT(mImplementation);
2268 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002269}
2270
2271void Context::pushGroupMarker(GLsizei length, const char *marker)
2272{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002273 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002274
2275 if (marker == nullptr)
2276 {
2277 // From the EXT_debug_marker spec,
2278 // "If <marker> is null then an empty string is pushed on the stack."
2279 mImplementation->pushGroupMarker(length, "");
2280 }
2281 else
2282 {
2283 mImplementation->pushGroupMarker(length, marker);
2284 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002285}
2286
2287void Context::popGroupMarker()
2288{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002289 ASSERT(mImplementation);
2290 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002291}
2292
Geoff Langd8605522016-04-13 10:19:12 -04002293void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2294{
2295 Program *programObject = getProgram(program);
2296 ASSERT(programObject);
2297
2298 programObject->bindUniformLocation(location, name);
2299}
2300
Brandon Jones59770802018-04-02 13:18:42 -07002301void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002302{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002303 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002304}
2305
Brandon Jones59770802018-04-02 13:18:42 -07002306void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002307{
2308 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2309}
2310
Brandon Jones59770802018-04-02 13:18:42 -07002311void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002312{
2313 GLfloat I[16];
2314 angle::Matrix<GLfloat>::setToIdentity(I);
2315
2316 mGLState.loadPathRenderingMatrix(matrixMode, I);
2317}
2318
2319void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2320{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002321 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002322 if (!pathObj)
2323 return;
2324
Geoff Lang9bf86f02018-07-26 11:46:34 -04002325 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002326
2327 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2328}
2329
2330void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2331{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002332 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002333 if (!pathObj)
2334 return;
2335
Geoff Lang9bf86f02018-07-26 11:46:34 -04002336 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002337
2338 mImplementation->stencilStrokePath(pathObj, reference, mask);
2339}
2340
2341void Context::coverFillPath(GLuint path, GLenum coverMode)
2342{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002343 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002344 if (!pathObj)
2345 return;
2346
Geoff Lang9bf86f02018-07-26 11:46:34 -04002347 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002348
2349 mImplementation->coverFillPath(pathObj, coverMode);
2350}
2351
2352void Context::coverStrokePath(GLuint path, GLenum coverMode)
2353{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002354 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002355 if (!pathObj)
2356 return;
2357
Geoff Lang9bf86f02018-07-26 11:46:34 -04002358 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002359
2360 mImplementation->coverStrokePath(pathObj, coverMode);
2361}
2362
2363void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2364{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002365 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002366 if (!pathObj)
2367 return;
2368
Geoff Lang9bf86f02018-07-26 11:46:34 -04002369 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002370
2371 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2372}
2373
2374void Context::stencilThenCoverStrokePath(GLuint path,
2375 GLint reference,
2376 GLuint mask,
2377 GLenum coverMode)
2378{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002379 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002380 if (!pathObj)
2381 return;
2382
Geoff Lang9bf86f02018-07-26 11:46:34 -04002383 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002384
2385 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2386}
2387
Sami Väisänend59ca052016-06-21 16:10:00 +03002388void Context::coverFillPathInstanced(GLsizei numPaths,
2389 GLenum pathNameType,
2390 const void *paths,
2391 GLuint pathBase,
2392 GLenum coverMode,
2393 GLenum transformType,
2394 const GLfloat *transformValues)
2395{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002396 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002397
Geoff Lang9bf86f02018-07-26 11:46:34 -04002398 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002399
2400 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2401}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002402
Sami Väisänend59ca052016-06-21 16:10:00 +03002403void Context::coverStrokePathInstanced(GLsizei numPaths,
2404 GLenum pathNameType,
2405 const void *paths,
2406 GLuint pathBase,
2407 GLenum coverMode,
2408 GLenum transformType,
2409 const GLfloat *transformValues)
2410{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002411 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002412
2413 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002414 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002415
2416 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2417 transformValues);
2418}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002419
Sami Väisänend59ca052016-06-21 16:10:00 +03002420void Context::stencilFillPathInstanced(GLsizei numPaths,
2421 GLenum pathNameType,
2422 const void *paths,
2423 GLuint pathBase,
2424 GLenum fillMode,
2425 GLuint mask,
2426 GLenum transformType,
2427 const GLfloat *transformValues)
2428{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002429 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002430
2431 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002432 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002433
2434 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2435 transformValues);
2436}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002437
Sami Väisänend59ca052016-06-21 16:10:00 +03002438void Context::stencilStrokePathInstanced(GLsizei numPaths,
2439 GLenum pathNameType,
2440 const void *paths,
2441 GLuint pathBase,
2442 GLint reference,
2443 GLuint mask,
2444 GLenum transformType,
2445 const GLfloat *transformValues)
2446{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002447 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002448
Geoff Lang9bf86f02018-07-26 11:46:34 -04002449 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002450
2451 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2452 transformValues);
2453}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002454
Sami Väisänend59ca052016-06-21 16:10:00 +03002455void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2456 GLenum pathNameType,
2457 const void *paths,
2458 GLuint pathBase,
2459 GLenum fillMode,
2460 GLuint mask,
2461 GLenum coverMode,
2462 GLenum transformType,
2463 const GLfloat *transformValues)
2464{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002465 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002466
Geoff Lang9bf86f02018-07-26 11:46:34 -04002467 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002468
2469 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2470 transformType, transformValues);
2471}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002472
Sami Väisänend59ca052016-06-21 16:10:00 +03002473void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2474 GLenum pathNameType,
2475 const void *paths,
2476 GLuint pathBase,
2477 GLint reference,
2478 GLuint mask,
2479 GLenum coverMode,
2480 GLenum transformType,
2481 const GLfloat *transformValues)
2482{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002483 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002484
Geoff Lang9bf86f02018-07-26 11:46:34 -04002485 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002486
2487 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2488 transformType, transformValues);
2489}
2490
Sami Väisänen46eaa942016-06-29 10:26:37 +03002491void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2492{
2493 auto *programObject = getProgram(program);
2494
2495 programObject->bindFragmentInputLocation(location, name);
2496}
2497
2498void Context::programPathFragmentInputGen(GLuint program,
2499 GLint location,
2500 GLenum genMode,
2501 GLint components,
2502 const GLfloat *coeffs)
2503{
2504 auto *programObject = getProgram(program);
2505
Jamie Madillbd044ed2017-06-05 12:59:21 -04002506 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002507}
2508
jchen1015015f72017-03-16 13:54:21 +08002509GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2510{
jchen10fd7c3b52017-03-21 15:36:03 +08002511 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002512 return QueryProgramResourceIndex(programObject, programInterface, name);
2513}
2514
jchen10fd7c3b52017-03-21 15:36:03 +08002515void Context::getProgramResourceName(GLuint program,
2516 GLenum programInterface,
2517 GLuint index,
2518 GLsizei bufSize,
2519 GLsizei *length,
2520 GLchar *name)
2521{
2522 const auto *programObject = getProgram(program);
2523 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2524}
2525
jchen10191381f2017-04-11 13:59:04 +08002526GLint Context::getProgramResourceLocation(GLuint program,
2527 GLenum programInterface,
2528 const GLchar *name)
2529{
2530 const auto *programObject = getProgram(program);
2531 return QueryProgramResourceLocation(programObject, programInterface, name);
2532}
2533
jchen10880683b2017-04-12 16:21:55 +08002534void Context::getProgramResourceiv(GLuint program,
2535 GLenum programInterface,
2536 GLuint index,
2537 GLsizei propCount,
2538 const GLenum *props,
2539 GLsizei bufSize,
2540 GLsizei *length,
2541 GLint *params)
2542{
2543 const auto *programObject = getProgram(program);
2544 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2545 length, params);
2546}
2547
jchen10d9cd7b72017-08-30 15:04:25 +08002548void Context::getProgramInterfaceiv(GLuint program,
2549 GLenum programInterface,
2550 GLenum pname,
2551 GLint *params)
2552{
2553 const auto *programObject = getProgram(program);
2554 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2555}
2556
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002557void Context::getProgramInterfaceivRobust(GLuint program,
2558 GLenum programInterface,
2559 GLenum pname,
2560 GLsizei bufSize,
2561 GLsizei *length,
2562 GLint *params)
2563{
2564 UNIMPLEMENTED();
2565}
2566
Jamie Madill306b6c12018-07-27 08:12:49 -04002567void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002568{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002569 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002570}
2571
2572// Get one of the recorded errors and clear its flag, if any.
2573// [OpenGL ES 2.0.24] section 2.5 page 13.
2574GLenum Context::getError()
2575{
Geoff Langda5777c2014-07-11 09:52:58 -04002576 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002577 {
Geoff Langda5777c2014-07-11 09:52:58 -04002578 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002579 }
Geoff Langda5777c2014-07-11 09:52:58 -04002580 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002581 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002582 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002583 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002584}
2585
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002586// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002587void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002588{
2589 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002590 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002591 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002592 mContextLostForced = true;
2593 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002594 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002595}
2596
Jamie Madill427064d2018-04-13 16:20:34 -04002597bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002598{
2599 return mContextLost;
2600}
2601
Jamie Madillfa920eb2018-01-04 11:45:50 -05002602GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002603{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002604 // Even if the application doesn't want to know about resets, we want to know
2605 // as it will allow us to skip all the calls.
2606 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002607 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002608 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002609 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002610 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002611 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002612
2613 // EXT_robustness, section 2.6: If the reset notification behavior is
2614 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2615 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2616 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002617 }
2618
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002619 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2620 // status should be returned at least once, and GL_NO_ERROR should be returned
2621 // once the device has finished resetting.
2622 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002623 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002624 ASSERT(mResetStatus == GL_NO_ERROR);
2625 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002626
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002627 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002628 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002629 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002630 }
2631 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002632 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002633 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002634 // If markContextLost was used to mark the context lost then
2635 // assume that is not recoverable, and continue to report the
2636 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002637 mResetStatus = mImplementation->getResetStatus();
2638 }
Jamie Madill893ab082014-05-16 16:56:10 -04002639
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002640 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002641}
2642
2643bool Context::isResetNotificationEnabled()
2644{
2645 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2646}
2647
Corentin Walleze3b10e82015-05-20 11:06:25 -04002648const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002649{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002650 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002651}
2652
2653EGLenum Context::getClientType() const
2654{
2655 return mClientType;
2656}
2657
2658EGLenum Context::getRenderBuffer() const
2659{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002660 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2661 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002662 {
2663 return EGL_NONE;
2664 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002665
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002666 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002667 ASSERT(backAttachment != nullptr);
2668 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002669}
2670
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002671VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002672{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002673 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002674 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2675 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002676 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002677 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2678 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002679
Jamie Madill96a483b2017-06-27 16:49:21 -04002680 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002681 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002682
2683 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002684}
2685
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002686TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002687{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002688 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002689 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2690 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002691 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002692 transformFeedback =
2693 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002694 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002695 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002696 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002697
2698 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002699}
2700
2701bool Context::isVertexArrayGenerated(GLuint vertexArray)
2702{
Jamie Madill96a483b2017-06-27 16:49:21 -04002703 ASSERT(mVertexArrayMap.contains(0));
2704 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002705}
2706
2707bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2708{
Jamie Madill96a483b2017-06-27 16:49:21 -04002709 ASSERT(mTransformFeedbackMap.contains(0));
2710 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002711}
2712
Shannon Woods53a94a82014-06-24 15:20:36 -04002713void Context::detachTexture(GLuint texture)
2714{
2715 // Simple pass-through to State's detachTexture method, as textures do not require
2716 // allocation map management either here or in the resource manager at detach time.
2717 // Zero textures are held by the Context, and we don't attempt to request them from
2718 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002719 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002720}
2721
James Darpinian4d9d4832018-03-13 12:43:28 -07002722void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002723{
Yuly Novikov5807a532015-12-03 13:01:22 -05002724 // Simple pass-through to State's detachBuffer method, since
2725 // only buffer attachments to container objects that are bound to the current context
2726 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002727
Yuly Novikov5807a532015-12-03 13:01:22 -05002728 // [OpenGL ES 3.2] section 5.1.2 page 45:
2729 // Attachments to unbound container objects, such as
2730 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2731 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002732 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002733}
2734
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002735void Context::detachFramebuffer(GLuint framebuffer)
2736{
Shannon Woods53a94a82014-06-24 15:20:36 -04002737 // Framebuffer detachment is handled by Context, because 0 is a valid
2738 // Framebuffer object, and a pointer to it must be passed from Context
2739 // to State at binding time.
2740
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002741 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002742 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2743 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2744 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002745
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002746 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002747 {
2748 bindReadFramebuffer(0);
2749 }
2750
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002751 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002752 {
2753 bindDrawFramebuffer(0);
2754 }
2755}
2756
2757void Context::detachRenderbuffer(GLuint renderbuffer)
2758{
Jamie Madilla02315b2017-02-23 14:14:47 -05002759 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002760}
2761
Jamie Madill57a89722013-07-02 11:57:03 -04002762void Context::detachVertexArray(GLuint vertexArray)
2763{
Jamie Madill77a72f62015-04-14 11:18:32 -04002764 // Vertex array detachment is handled by Context, because 0 is a valid
2765 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002766 // binding time.
2767
Jamie Madill57a89722013-07-02 11:57:03 -04002768 // [OpenGL ES 3.0.2] section 2.10 page 43:
2769 // If a vertex array object that is currently bound is deleted, the binding
2770 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002771 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002772 {
2773 bindVertexArray(0);
2774 }
2775}
2776
Geoff Langc8058452014-02-03 12:04:11 -05002777void Context::detachTransformFeedback(GLuint transformFeedback)
2778{
Corentin Walleza2257da2016-04-19 16:43:12 -04002779 // Transform feedback detachment is handled by Context, because 0 is a valid
2780 // transform feedback, and a pointer to it must be passed from Context to State at
2781 // binding time.
2782
2783 // The OpenGL specification doesn't mention what should happen when the currently bound
2784 // transform feedback object is deleted. Since it is a container object, we treat it like
2785 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002786 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002787 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002788 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002789 }
Geoff Langc8058452014-02-03 12:04:11 -05002790}
2791
Jamie Madilldc356042013-07-19 16:36:57 -04002792void Context::detachSampler(GLuint sampler)
2793{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002794 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002795}
2796
Yunchao Hea336b902017-08-02 16:05:21 +08002797void Context::detachProgramPipeline(GLuint pipeline)
2798{
2799 mGLState.detachProgramPipeline(this, pipeline);
2800}
2801
Jamie Madill3ef140a2017-08-26 23:11:21 -04002802void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002803{
Shaodde78e82017-05-22 14:13:27 +08002804 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002805 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002806}
2807
Jamie Madille29d1672013-07-19 16:36:57 -04002808void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2809{
Geoff Langc1984ed2016-10-07 12:41:00 -04002810 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002811 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002812 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002813 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002814}
Jamie Madille29d1672013-07-19 16:36:57 -04002815
Geoff Langc1984ed2016-10-07 12:41:00 -04002816void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2817{
2818 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002819 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002820 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002821 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002822}
2823
Brandon Jones59770802018-04-02 13:18:42 -07002824void Context::samplerParameterivRobust(GLuint sampler,
2825 GLenum pname,
2826 GLsizei bufSize,
2827 const GLint *param)
2828{
2829 samplerParameteriv(sampler, pname, param);
2830}
2831
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002832void Context::samplerParameterIivRobust(GLuint sampler,
2833 GLenum pname,
2834 GLsizei bufSize,
2835 const GLint *param)
2836{
2837 UNIMPLEMENTED();
2838}
2839
2840void Context::samplerParameterIuivRobust(GLuint sampler,
2841 GLenum pname,
2842 GLsizei bufSize,
2843 const GLuint *param)
2844{
2845 UNIMPLEMENTED();
2846}
2847
Jamie Madille29d1672013-07-19 16:36:57 -04002848void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2849{
Geoff Langc1984ed2016-10-07 12:41:00 -04002850 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002851 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002852 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002853 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002854}
2855
Geoff Langc1984ed2016-10-07 12:41:00 -04002856void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002857{
Geoff Langc1984ed2016-10-07 12:41:00 -04002858 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002859 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002860 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002861 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002862}
2863
Brandon Jones59770802018-04-02 13:18:42 -07002864void Context::samplerParameterfvRobust(GLuint sampler,
2865 GLenum pname,
2866 GLsizei bufSize,
2867 const GLfloat *param)
2868{
2869 samplerParameterfv(sampler, pname, param);
2870}
2871
Geoff Langc1984ed2016-10-07 12:41:00 -04002872void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002873{
Geoff Langc1984ed2016-10-07 12:41:00 -04002874 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002875 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002876 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002877 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002878}
Jamie Madill9675b802013-07-19 16:36:59 -04002879
Brandon Jones59770802018-04-02 13:18:42 -07002880void Context::getSamplerParameterivRobust(GLuint sampler,
2881 GLenum pname,
2882 GLsizei bufSize,
2883 GLsizei *length,
2884 GLint *params)
2885{
2886 getSamplerParameteriv(sampler, pname, params);
2887}
2888
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002889void Context::getSamplerParameterIivRobust(GLuint sampler,
2890 GLenum pname,
2891 GLsizei bufSize,
2892 GLsizei *length,
2893 GLint *params)
2894{
2895 UNIMPLEMENTED();
2896}
2897
2898void Context::getSamplerParameterIuivRobust(GLuint sampler,
2899 GLenum pname,
2900 GLsizei bufSize,
2901 GLsizei *length,
2902 GLuint *params)
2903{
2904 UNIMPLEMENTED();
2905}
2906
Geoff Langc1984ed2016-10-07 12:41:00 -04002907void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2908{
2909 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002910 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002911 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002912 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002913}
2914
Brandon Jones59770802018-04-02 13:18:42 -07002915void Context::getSamplerParameterfvRobust(GLuint sampler,
2916 GLenum pname,
2917 GLsizei bufSize,
2918 GLsizei *length,
2919 GLfloat *params)
2920{
2921 getSamplerParameterfv(sampler, pname, params);
2922}
2923
Olli Etuahof0fee072016-03-30 15:11:58 +03002924void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2925{
2926 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002927 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002928}
2929
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002930void Context::initRendererString()
2931{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002932 std::ostringstream rendererString;
2933 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002934 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002935 rendererString << ")";
2936
Geoff Langcec35902014-04-16 10:52:36 -04002937 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002938}
2939
Geoff Langc339c4e2016-11-29 10:37:36 -05002940void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002941{
Geoff Langc339c4e2016-11-29 10:37:36 -05002942 const Version &clientVersion = getClientVersion();
2943
2944 std::ostringstream versionString;
2945 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2946 << ANGLE_VERSION_STRING << ")";
2947 mVersionString = MakeStaticString(versionString.str());
2948
2949 std::ostringstream shadingLanguageVersionString;
2950 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2951 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2952 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2953 << ")";
2954 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002955}
2956
Geoff Langcec35902014-04-16 10:52:36 -04002957void Context::initExtensionStrings()
2958{
Geoff Langc339c4e2016-11-29 10:37:36 -05002959 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2960 std::ostringstream combinedStringStream;
2961 std::copy(strings.begin(), strings.end(),
2962 std::ostream_iterator<const char *>(combinedStringStream, " "));
2963 return MakeStaticString(combinedStringStream.str());
2964 };
2965
2966 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002967 for (const auto &extensionString : mExtensions.getStrings())
2968 {
2969 mExtensionStrings.push_back(MakeStaticString(extensionString));
2970 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002971 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002972
Geoff Langc339c4e2016-11-29 10:37:36 -05002973 mRequestableExtensionStrings.clear();
2974 for (const auto &extensionInfo : GetExtensionInfoMap())
2975 {
2976 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002977 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002978 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002979 {
2980 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2981 }
2982 }
2983 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002984}
2985
Geoff Langc339c4e2016-11-29 10:37:36 -05002986const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002987{
Geoff Langc339c4e2016-11-29 10:37:36 -05002988 switch (name)
2989 {
2990 case GL_VENDOR:
2991 return reinterpret_cast<const GLubyte *>("Google Inc.");
2992
2993 case GL_RENDERER:
2994 return reinterpret_cast<const GLubyte *>(mRendererString);
2995
2996 case GL_VERSION:
2997 return reinterpret_cast<const GLubyte *>(mVersionString);
2998
2999 case GL_SHADING_LANGUAGE_VERSION:
3000 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3001
3002 case GL_EXTENSIONS:
3003 return reinterpret_cast<const GLubyte *>(mExtensionString);
3004
3005 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3006 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3007
3008 default:
3009 UNREACHABLE();
3010 return nullptr;
3011 }
Geoff Langcec35902014-04-16 10:52:36 -04003012}
3013
Geoff Langc339c4e2016-11-29 10:37:36 -05003014const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003015{
Geoff Langc339c4e2016-11-29 10:37:36 -05003016 switch (name)
3017 {
3018 case GL_EXTENSIONS:
3019 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3020
3021 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3022 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3023
3024 default:
3025 UNREACHABLE();
3026 return nullptr;
3027 }
Geoff Langcec35902014-04-16 10:52:36 -04003028}
3029
3030size_t Context::getExtensionStringCount() const
3031{
3032 return mExtensionStrings.size();
3033}
3034
Geoff Lang111a99e2017-10-17 10:58:41 -04003035bool Context::isExtensionRequestable(const char *name)
3036{
3037 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3038 auto extension = extensionInfos.find(name);
3039
Geoff Lang111a99e2017-10-17 10:58:41 -04003040 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003041 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003042}
3043
Geoff Langc339c4e2016-11-29 10:37:36 -05003044void Context::requestExtension(const char *name)
3045{
3046 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3047 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3048 const auto &extension = extensionInfos.at(name);
3049 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003050 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003051
3052 if (mExtensions.*(extension.ExtensionsMember))
3053 {
3054 // Extension already enabled
3055 return;
3056 }
3057
3058 mExtensions.*(extension.ExtensionsMember) = true;
3059 updateCaps();
3060 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003061
Jamie Madill2f348d22017-06-05 10:50:59 -04003062 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3063 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003064
Jamie Madill81c2e252017-09-09 23:32:46 -04003065 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3066 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003067 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003068 for (auto &zeroTexture : mZeroTextures)
3069 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003070 if (zeroTexture.get() != nullptr)
3071 {
3072 zeroTexture->signalDirty(this, InitState::Initialized);
3073 }
Geoff Lang9aded172017-04-05 11:07:56 -04003074 }
3075
Jamie Madillb983a4b2018-08-01 11:34:51 -04003076 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003077}
3078
3079size_t Context::getRequestableExtensionStringCount() const
3080{
3081 return mRequestableExtensionStrings.size();
3082}
3083
Jamie Madill493f9572018-05-24 19:52:15 -04003084void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003085{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003086 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003087 ASSERT(transformFeedback != nullptr);
3088 ASSERT(!transformFeedback->isPaused());
3089
Jamie Madill6c1f6712017-02-14 19:08:04 -05003090 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003091}
3092
3093bool Context::hasActiveTransformFeedback(GLuint program) const
3094{
3095 for (auto pair : mTransformFeedbackMap)
3096 {
3097 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3098 {
3099 return true;
3100 }
3101 }
3102 return false;
3103}
3104
Geoff Lang33f11fb2018-05-07 13:42:47 -04003105Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003106{
3107 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3108
jchen1082af6202018-06-22 10:59:52 +08003109 // Explicitly enable GL_KHR_parallel_shader_compile
3110 supportedExtensions.parallelShaderCompile = true;
3111
Geoff Langb0f917f2017-12-05 13:41:54 -05003112 if (getClientVersion() < ES_2_0)
3113 {
3114 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003115 supportedExtensions.pointSizeArray = true;
3116 supportedExtensions.textureCubeMap = true;
3117 supportedExtensions.pointSprite = true;
3118 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003119 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003120 }
3121
3122 if (getClientVersion() < ES_3_0)
3123 {
3124 // Disable ES3+ extensions
3125 supportedExtensions.colorBufferFloat = false;
3126 supportedExtensions.eglImageExternalEssl3 = false;
3127 supportedExtensions.textureNorm16 = false;
3128 supportedExtensions.multiview = false;
3129 supportedExtensions.maxViews = 1u;
3130 }
3131
3132 if (getClientVersion() < ES_3_1)
3133 {
3134 // Disable ES3.1+ extensions
3135 supportedExtensions.geometryShader = false;
3136 }
3137
3138 if (getClientVersion() > ES_2_0)
3139 {
3140 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3141 // supportedExtensions.sRGB = false;
3142 }
3143
3144 // Some extensions are always available because they are implemented in the GL layer.
3145 supportedExtensions.bindUniformLocation = true;
3146 supportedExtensions.vertexArrayObject = true;
3147 supportedExtensions.bindGeneratesResource = true;
3148 supportedExtensions.clientArrays = true;
3149 supportedExtensions.requestExtension = true;
3150
3151 // Enable the no error extension if the context was created with the flag.
3152 supportedExtensions.noError = mSkipValidation;
3153
3154 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003155 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003156
3157 // Explicitly enable GL_KHR_debug
3158 supportedExtensions.debug = true;
3159 supportedExtensions.maxDebugMessageLength = 1024;
3160 supportedExtensions.maxDebugLoggedMessages = 1024;
3161 supportedExtensions.maxDebugGroupStackDepth = 1024;
3162 supportedExtensions.maxLabelLength = 1024;
3163
3164 // Explicitly enable GL_ANGLE_robust_client_memory
3165 supportedExtensions.robustClientMemory = true;
3166
3167 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003168 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003169
3170 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3171 // supports it.
3172 supportedExtensions.robustBufferAccessBehavior =
3173 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3174
3175 // Enable the cache control query unconditionally.
3176 supportedExtensions.programCacheControl = true;
3177
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003178 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003179 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003180 {
3181 // GL_ANGLE_explicit_context_gles1
3182 supportedExtensions.explicitContextGles1 = true;
3183 // GL_ANGLE_explicit_context
3184 supportedExtensions.explicitContext = true;
3185 }
3186
Geoff Langb0f917f2017-12-05 13:41:54 -05003187 return supportedExtensions;
3188}
3189
Geoff Lang33f11fb2018-05-07 13:42:47 -04003190void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003191{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003192 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003193
Geoff Lang33f11fb2018-05-07 13:42:47 -04003194 mSupportedExtensions = generateSupportedExtensions();
3195 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003196
3197 mLimitations = mImplementation->getNativeLimitations();
3198
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003199 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3200 if (getClientVersion() < Version(2, 0))
3201 {
3202 mCaps.maxMultitextureUnits = 4;
3203 mCaps.maxClipPlanes = 6;
3204 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003205 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3206 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3207 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003208 mCaps.minSmoothPointSize = 1.0f;
3209 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003210 }
3211
Luc Ferronad2ae932018-06-11 15:31:17 -04003212 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003213 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003214
Luc Ferronad2ae932018-06-11 15:31:17 -04003215 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3216
Jamie Madill0f80ed82017-09-19 00:24:56 -04003217 if (getClientVersion() < ES_3_1)
3218 {
3219 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3220 }
3221 else
3222 {
3223 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3224 }
Geoff Lang301d1612014-07-09 10:34:37 -04003225
Jiawei Shao54aafe52018-04-27 14:54:57 +08003226 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3227 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003228 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3229 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3230
3231 // Limit textures as well, so we can use fast bitsets with texture bindings.
3232 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003233 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3234 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3235 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3236 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003237
Jiawei Shaodb342272017-09-27 10:21:45 +08003238 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3239
Geoff Langc287ea62016-09-16 14:46:51 -04003240 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003241 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003242 for (const auto &extensionInfo : GetExtensionInfoMap())
3243 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003244 // If the user has requested that extensions start disabled and they are requestable,
3245 // disable them.
3246 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003247 {
3248 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3249 }
3250 }
3251
3252 // Generate texture caps
3253 updateCaps();
3254}
3255
3256void Context::updateCaps()
3257{
Geoff Lang900013c2014-07-07 11:32:19 -04003258 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003259 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003260
Jamie Madill7b62cf92017-11-02 15:20:49 -04003261 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003262 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003263 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003264 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003265
Geoff Lang0d8b7242015-09-09 14:56:53 -04003266 // Update the format caps based on the client version and extensions.
3267 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3268 // ES3.
3269 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003270 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003271 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003272 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003273 formatCaps.textureAttachment =
3274 formatCaps.textureAttachment &&
3275 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3276 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3277 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003278
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003279 // OpenGL ES does not support multisampling with non-rendererable formats
3280 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003281 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003282 (getClientVersion() < ES_3_1 &&
3283 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003284 {
Geoff Langd87878e2014-09-19 15:42:59 -04003285 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003286 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003287 else
3288 {
3289 // We may have limited the max samples for some required renderbuffer formats due to
3290 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3291 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3292
3293 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3294 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3295 // exception of signed and unsigned integer formats."
3296 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3297 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3298 {
3299 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3300 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3301 }
3302
3303 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3304 if (getClientVersion() >= ES_3_1)
3305 {
3306 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3307 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3308 // the exception that the signed and unsigned integer formats are required only to
3309 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3310 // multisamples, which must be at least one."
3311 if (formatInfo.componentType == GL_INT ||
3312 formatInfo.componentType == GL_UNSIGNED_INT)
3313 {
3314 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3315 }
3316
3317 // GLES 3.1 section 19.3.1.
3318 if (formatCaps.texturable)
3319 {
3320 if (formatInfo.depthBits > 0)
3321 {
3322 mCaps.maxDepthTextureSamples =
3323 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3324 }
3325 else if (formatInfo.redBits > 0)
3326 {
3327 mCaps.maxColorTextureSamples =
3328 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3329 }
3330 }
3331 }
3332 }
Geoff Langd87878e2014-09-19 15:42:59 -04003333
3334 if (formatCaps.texturable && formatInfo.compressed)
3335 {
Geoff Langca271392017-04-05 12:30:00 -04003336 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003337 }
3338
Geoff Langca271392017-04-05 12:30:00 -04003339 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003340 }
Jamie Madill32447362017-06-28 14:53:52 -04003341
3342 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003343 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003344 {
3345 mMemoryProgramCache = nullptr;
3346 }
Corentin Walleze4477002017-12-01 14:39:58 -05003347
3348 // Compute which buffer types are allowed
3349 mValidBufferBindings.reset();
3350 mValidBufferBindings.set(BufferBinding::ElementArray);
3351 mValidBufferBindings.set(BufferBinding::Array);
3352
3353 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3354 {
3355 mValidBufferBindings.set(BufferBinding::PixelPack);
3356 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3357 }
3358
3359 if (getClientVersion() >= ES_3_0)
3360 {
3361 mValidBufferBindings.set(BufferBinding::CopyRead);
3362 mValidBufferBindings.set(BufferBinding::CopyWrite);
3363 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3364 mValidBufferBindings.set(BufferBinding::Uniform);
3365 }
3366
3367 if (getClientVersion() >= ES_3_1)
3368 {
3369 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3370 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3371 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3372 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3373 }
jchen107ae70d82018-07-06 13:47:01 +08003374
3375 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Geoff Lang493daf52014-07-03 13:38:44 -04003376}
3377
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003378void Context::initWorkarounds()
3379{
Jamie Madill761b02c2017-06-23 16:27:06 -04003380 // Apply back-end workarounds.
3381 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3382
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003383 // Lose the context upon out of memory error if the application is
3384 // expecting to watch for those events.
3385 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3386}
3387
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003388// Return true if the draw is a no-op, else return false.
3389// A no-op draw occurs if the count of vertices is less than the minimum required to
3390// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3391bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3392{
3393 return count < kMinimumPrimitiveCounts[mode];
3394}
3395
3396bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3397{
3398 return (instanceCount == 0) || noopDraw(mode, count);
3399}
3400
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003401Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003402{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003403 if (mGLES1Renderer)
3404 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003405 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003406 }
3407
Geoff Lang9bf86f02018-07-26 11:46:34 -04003408 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003409
3410 if (isRobustResourceInitEnabled())
3411 {
3412 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3413 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3414 }
3415
Geoff Langa8cb2872018-03-09 16:09:40 -05003416 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003417 return NoError();
3418}
3419
3420Error Context::prepareForClear(GLbitfield mask)
3421{
Geoff Langa8cb2872018-03-09 16:09:40 -05003422 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003423 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003424 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003425 return NoError();
3426}
3427
3428Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3429{
Geoff Langa8cb2872018-03-09 16:09:40 -05003430 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003431 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3432 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003433 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003434 return NoError();
3435}
3436
Geoff Langa8cb2872018-03-09 16:09:40 -05003437Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003438{
Geoff Langa8cb2872018-03-09 16:09:40 -05003439 ANGLE_TRY(syncDirtyObjects(objectMask));
3440 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003441 return NoError();
3442}
3443
Geoff Langa8cb2872018-03-09 16:09:40 -05003444Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003445{
3446 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003447 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003448 mGLState.clearDirtyBits();
3449 return NoError();
3450}
3451
Geoff Langa8cb2872018-03-09 16:09:40 -05003452Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003453{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003454 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003455 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003456 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003457 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003458}
Jamie Madillc29968b2016-01-20 11:17:23 -05003459
Geoff Langa8cb2872018-03-09 16:09:40 -05003460Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003461{
3462 return mGLState.syncDirtyObjects(this, objectMask);
3463}
3464
Jamie Madillc29968b2016-01-20 11:17:23 -05003465void Context::blitFramebuffer(GLint srcX0,
3466 GLint srcY0,
3467 GLint srcX1,
3468 GLint srcY1,
3469 GLint dstX0,
3470 GLint dstY0,
3471 GLint dstX1,
3472 GLint dstY1,
3473 GLbitfield mask,
3474 GLenum filter)
3475{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003476 if (mask == 0)
3477 {
3478 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3479 // buffers are copied.
3480 return;
3481 }
3482
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003483 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003484 ASSERT(drawFramebuffer);
3485
3486 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3487 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3488
Jamie Madillbc918e72018-03-08 09:47:21 -05003489 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003490
Jamie Madillc564c072017-06-01 12:45:42 -04003491 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003492}
Jamie Madillc29968b2016-01-20 11:17:23 -05003493
3494void Context::clear(GLbitfield mask)
3495{
Geoff Langd4fff502017-09-22 11:28:28 -04003496 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3497 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003498}
3499
3500void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3501{
Geoff Langd4fff502017-09-22 11:28:28 -04003502 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3503 ANGLE_CONTEXT_TRY(
3504 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003505}
3506
3507void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3508{
Geoff Langd4fff502017-09-22 11:28:28 -04003509 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3510 ANGLE_CONTEXT_TRY(
3511 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003512}
3513
3514void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3515{
Geoff Langd4fff502017-09-22 11:28:28 -04003516 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3517 ANGLE_CONTEXT_TRY(
3518 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003519}
3520
3521void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3522{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003523 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003524 ASSERT(framebufferObject);
3525
3526 // If a buffer is not present, the clear has no effect
3527 if (framebufferObject->getDepthbuffer() == nullptr &&
3528 framebufferObject->getStencilbuffer() == nullptr)
3529 {
3530 return;
3531 }
3532
Geoff Langd4fff502017-09-22 11:28:28 -04003533 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3534 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003535}
3536
3537void Context::readPixels(GLint x,
3538 GLint y,
3539 GLsizei width,
3540 GLsizei height,
3541 GLenum format,
3542 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003543 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003544{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003545 if (width == 0 || height == 0)
3546 {
3547 return;
3548 }
3549
Jamie Madillbc918e72018-03-08 09:47:21 -05003550 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003551
Jamie Madillb6664922017-07-25 12:55:04 -04003552 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3553 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003554
3555 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003556 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003557}
3558
Brandon Jones59770802018-04-02 13:18:42 -07003559void Context::readPixelsRobust(GLint x,
3560 GLint y,
3561 GLsizei width,
3562 GLsizei height,
3563 GLenum format,
3564 GLenum type,
3565 GLsizei bufSize,
3566 GLsizei *length,
3567 GLsizei *columns,
3568 GLsizei *rows,
3569 void *pixels)
3570{
3571 readPixels(x, y, width, height, format, type, pixels);
3572}
3573
3574void Context::readnPixelsRobust(GLint x,
3575 GLint y,
3576 GLsizei width,
3577 GLsizei height,
3578 GLenum format,
3579 GLenum type,
3580 GLsizei bufSize,
3581 GLsizei *length,
3582 GLsizei *columns,
3583 GLsizei *rows,
3584 void *data)
3585{
3586 readPixels(x, y, width, height, format, type, data);
3587}
3588
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003589void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003590 GLint level,
3591 GLenum internalformat,
3592 GLint x,
3593 GLint y,
3594 GLsizei width,
3595 GLsizei height,
3596 GLint border)
3597{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003598 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003599 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003600
Jamie Madillc29968b2016-01-20 11:17:23 -05003601 Rectangle sourceArea(x, y, width, height);
3602
Jamie Madill05b35b22017-10-03 09:01:44 -04003603 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003604 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003605 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003606}
3607
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003608void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003609 GLint level,
3610 GLint xoffset,
3611 GLint yoffset,
3612 GLint x,
3613 GLint y,
3614 GLsizei width,
3615 GLsizei height)
3616{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003617 if (width == 0 || height == 0)
3618 {
3619 return;
3620 }
3621
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003622 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003623 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003624
Jamie Madillc29968b2016-01-20 11:17:23 -05003625 Offset destOffset(xoffset, yoffset, 0);
3626 Rectangle sourceArea(x, y, width, height);
3627
Jamie Madill05b35b22017-10-03 09:01:44 -04003628 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003629 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003630 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003631}
3632
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003633void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003634 GLint level,
3635 GLint xoffset,
3636 GLint yoffset,
3637 GLint zoffset,
3638 GLint x,
3639 GLint y,
3640 GLsizei width,
3641 GLsizei height)
3642{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003643 if (width == 0 || height == 0)
3644 {
3645 return;
3646 }
3647
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003648 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003649 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003650
Jamie Madillc29968b2016-01-20 11:17:23 -05003651 Offset destOffset(xoffset, yoffset, zoffset);
3652 Rectangle sourceArea(x, y, width, height);
3653
Jamie Madill05b35b22017-10-03 09:01:44 -04003654 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3655 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003656 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3657 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003658}
3659
3660void Context::framebufferTexture2D(GLenum target,
3661 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003662 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003663 GLuint texture,
3664 GLint level)
3665{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003666 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003667 ASSERT(framebuffer);
3668
3669 if (texture != 0)
3670 {
3671 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003672 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003673 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003674 }
3675 else
3676 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003677 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003678 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003679
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003680 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003681}
3682
3683void Context::framebufferRenderbuffer(GLenum target,
3684 GLenum attachment,
3685 GLenum renderbuffertarget,
3686 GLuint renderbuffer)
3687{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003688 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003689 ASSERT(framebuffer);
3690
3691 if (renderbuffer != 0)
3692 {
3693 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003694
Jamie Madillcc129372018-04-12 09:13:18 -04003695 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003696 renderbufferObject);
3697 }
3698 else
3699 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003700 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003701 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003702
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003703 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003704}
3705
3706void Context::framebufferTextureLayer(GLenum target,
3707 GLenum attachment,
3708 GLuint texture,
3709 GLint level,
3710 GLint layer)
3711{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003712 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003713 ASSERT(framebuffer);
3714
3715 if (texture != 0)
3716 {
3717 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003718 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003719 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003720 }
3721 else
3722 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003723 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003724 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003725
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003726 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003727}
3728
Brandon Jones59770802018-04-02 13:18:42 -07003729void Context::framebufferTextureMultiviewLayered(GLenum target,
3730 GLenum attachment,
3731 GLuint texture,
3732 GLint level,
3733 GLint baseViewIndex,
3734 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003735{
Martin Radev82ef7742017-08-08 17:44:58 +03003736 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3737 ASSERT(framebuffer);
3738
3739 if (texture != 0)
3740 {
3741 Texture *textureObj = getTexture(texture);
3742
Martin Radev18b75ba2017-08-15 15:50:40 +03003743 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003744 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3745 numViews, baseViewIndex);
3746 }
3747 else
3748 {
3749 framebuffer->resetAttachment(this, attachment);
3750 }
3751
3752 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003753}
3754
Brandon Jones59770802018-04-02 13:18:42 -07003755void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3756 GLenum attachment,
3757 GLuint texture,
3758 GLint level,
3759 GLsizei numViews,
3760 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003761{
Martin Radev5dae57b2017-07-14 16:15:55 +03003762 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3763 ASSERT(framebuffer);
3764
3765 if (texture != 0)
3766 {
3767 Texture *textureObj = getTexture(texture);
3768
3769 ImageIndex index = ImageIndex::Make2D(level);
3770 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3771 textureObj, numViews, viewportOffsets);
3772 }
3773 else
3774 {
3775 framebuffer->resetAttachment(this, attachment);
3776 }
3777
3778 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003779}
3780
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003781void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3782{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003783 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3784 ASSERT(framebuffer);
3785
3786 if (texture != 0)
3787 {
3788 Texture *textureObj = getTexture(texture);
3789
3790 ImageIndex index = ImageIndex::MakeFromType(
3791 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3792 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3793 }
3794 else
3795 {
3796 framebuffer->resetAttachment(this, attachment);
3797 }
3798
3799 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003800}
3801
Jamie Madillc29968b2016-01-20 11:17:23 -05003802void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3803{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003804 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003805 ASSERT(framebuffer);
3806 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003807 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003808}
3809
3810void Context::readBuffer(GLenum mode)
3811{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003812 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003813 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003814 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003815}
3816
3817void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3818{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003819 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003820 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003821
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003822 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003823 ASSERT(framebuffer);
3824
3825 // The specification isn't clear what should be done when the framebuffer isn't complete.
3826 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003827 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003828}
3829
3830void Context::invalidateFramebuffer(GLenum target,
3831 GLsizei numAttachments,
3832 const GLenum *attachments)
3833{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003834 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003835 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003836
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003837 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003838 ASSERT(framebuffer);
3839
Jamie Madill427064d2018-04-13 16:20:34 -04003840 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003841 {
Jamie Madill437fa652016-05-03 15:13:24 -04003842 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003843 }
Jamie Madill437fa652016-05-03 15:13:24 -04003844
Jamie Madill4928b7c2017-06-20 12:57:39 -04003845 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003846}
3847
3848void Context::invalidateSubFramebuffer(GLenum target,
3849 GLsizei numAttachments,
3850 const GLenum *attachments,
3851 GLint x,
3852 GLint y,
3853 GLsizei width,
3854 GLsizei height)
3855{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003856 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003857 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003858
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003859 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003860 ASSERT(framebuffer);
3861
Jamie Madill427064d2018-04-13 16:20:34 -04003862 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003863 {
Jamie Madill437fa652016-05-03 15:13:24 -04003864 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003865 }
Jamie Madill437fa652016-05-03 15:13:24 -04003866
3867 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003868 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003869}
3870
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003871void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003872 GLint level,
3873 GLint internalformat,
3874 GLsizei width,
3875 GLsizei height,
3876 GLint border,
3877 GLenum format,
3878 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003879 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003880{
Jamie Madillbc918e72018-03-08 09:47:21 -05003881 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003882
3883 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003884 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003885 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003886 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003887}
3888
Brandon Jones59770802018-04-02 13:18:42 -07003889void Context::texImage2DRobust(TextureTarget target,
3890 GLint level,
3891 GLint internalformat,
3892 GLsizei width,
3893 GLsizei height,
3894 GLint border,
3895 GLenum format,
3896 GLenum type,
3897 GLsizei bufSize,
3898 const void *pixels)
3899{
3900 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3901}
3902
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003903void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003904 GLint level,
3905 GLint internalformat,
3906 GLsizei width,
3907 GLsizei height,
3908 GLsizei depth,
3909 GLint border,
3910 GLenum format,
3911 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003912 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003913{
Jamie Madillbc918e72018-03-08 09:47:21 -05003914 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003915
3916 Extents size(width, height, depth);
3917 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003918 handleError(texture->setImage(this, mGLState.getUnpackState(),
3919 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003920 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003921}
3922
Brandon Jones59770802018-04-02 13:18:42 -07003923void Context::texImage3DRobust(TextureType target,
3924 GLint level,
3925 GLint internalformat,
3926 GLsizei width,
3927 GLsizei height,
3928 GLsizei depth,
3929 GLint border,
3930 GLenum format,
3931 GLenum type,
3932 GLsizei bufSize,
3933 const void *pixels)
3934{
3935 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3936}
3937
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003938void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003939 GLint level,
3940 GLint xoffset,
3941 GLint yoffset,
3942 GLsizei width,
3943 GLsizei height,
3944 GLenum format,
3945 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003946 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003947{
3948 // Zero sized uploads are valid but no-ops
3949 if (width == 0 || height == 0)
3950 {
3951 return;
3952 }
3953
Jamie Madillbc918e72018-03-08 09:47:21 -05003954 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003955
3956 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003957 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003958 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003959 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003960}
3961
Brandon Jones59770802018-04-02 13:18:42 -07003962void Context::texSubImage2DRobust(TextureTarget target,
3963 GLint level,
3964 GLint xoffset,
3965 GLint yoffset,
3966 GLsizei width,
3967 GLsizei height,
3968 GLenum format,
3969 GLenum type,
3970 GLsizei bufSize,
3971 const void *pixels)
3972{
3973 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3974}
3975
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003976void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003977 GLint level,
3978 GLint xoffset,
3979 GLint yoffset,
3980 GLint zoffset,
3981 GLsizei width,
3982 GLsizei height,
3983 GLsizei depth,
3984 GLenum format,
3985 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003986 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003987{
3988 // Zero sized uploads are valid but no-ops
3989 if (width == 0 || height == 0 || depth == 0)
3990 {
3991 return;
3992 }
3993
Jamie Madillbc918e72018-03-08 09:47:21 -05003994 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003995
3996 Box area(xoffset, yoffset, zoffset, width, height, depth);
3997 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003998 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3999 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004000 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004001}
4002
Brandon Jones59770802018-04-02 13:18:42 -07004003void Context::texSubImage3DRobust(TextureType target,
4004 GLint level,
4005 GLint xoffset,
4006 GLint yoffset,
4007 GLint zoffset,
4008 GLsizei width,
4009 GLsizei height,
4010 GLsizei depth,
4011 GLenum format,
4012 GLenum type,
4013 GLsizei bufSize,
4014 const void *pixels)
4015{
4016 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4017 pixels);
4018}
4019
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004020void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004021 GLint level,
4022 GLenum internalformat,
4023 GLsizei width,
4024 GLsizei height,
4025 GLint border,
4026 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004027 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004028{
Jamie Madillbc918e72018-03-08 09:47:21 -05004029 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004030
4031 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004032 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004033 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4034 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004035 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004036}
4037
Brandon Jones59770802018-04-02 13:18:42 -07004038void Context::compressedTexImage2DRobust(TextureTarget target,
4039 GLint level,
4040 GLenum internalformat,
4041 GLsizei width,
4042 GLsizei height,
4043 GLint border,
4044 GLsizei imageSize,
4045 GLsizei dataSize,
4046 const GLvoid *data)
4047{
4048 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4049}
4050
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004051void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004052 GLint level,
4053 GLenum internalformat,
4054 GLsizei width,
4055 GLsizei height,
4056 GLsizei depth,
4057 GLint border,
4058 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004059 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004060{
Jamie Madillbc918e72018-03-08 09:47:21 -05004061 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004062
4063 Extents size(width, height, depth);
4064 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004065 handleError(texture->setCompressedImage(
4066 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004067 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004068}
4069
Brandon Jones59770802018-04-02 13:18:42 -07004070void Context::compressedTexImage3DRobust(TextureType target,
4071 GLint level,
4072 GLenum internalformat,
4073 GLsizei width,
4074 GLsizei height,
4075 GLsizei depth,
4076 GLint border,
4077 GLsizei imageSize,
4078 GLsizei dataSize,
4079 const GLvoid *data)
4080{
4081 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4082 data);
4083}
4084
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004085void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004086 GLint level,
4087 GLint xoffset,
4088 GLint yoffset,
4089 GLsizei width,
4090 GLsizei height,
4091 GLenum format,
4092 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004093 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004094{
Jamie Madillbc918e72018-03-08 09:47:21 -05004095 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004096
4097 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004098 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004099 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4100 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004101 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004102}
4103
Brandon Jones59770802018-04-02 13:18:42 -07004104void Context::compressedTexSubImage2DRobust(TextureTarget target,
4105 GLint level,
4106 GLint xoffset,
4107 GLint yoffset,
4108 GLsizei width,
4109 GLsizei height,
4110 GLenum format,
4111 GLsizei imageSize,
4112 GLsizei dataSize,
4113 const GLvoid *data)
4114{
4115 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4116 data);
4117}
4118
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004119void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004120 GLint level,
4121 GLint xoffset,
4122 GLint yoffset,
4123 GLint zoffset,
4124 GLsizei width,
4125 GLsizei height,
4126 GLsizei depth,
4127 GLenum format,
4128 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004129 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004130{
4131 // Zero sized uploads are valid but no-ops
4132 if (width == 0 || height == 0)
4133 {
4134 return;
4135 }
4136
Jamie Madillbc918e72018-03-08 09:47:21 -05004137 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004138
4139 Box area(xoffset, yoffset, zoffset, width, height, depth);
4140 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004141 handleError(texture->setCompressedSubImage(
4142 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004143 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004144}
4145
Brandon Jones59770802018-04-02 13:18:42 -07004146void Context::compressedTexSubImage3DRobust(TextureType target,
4147 GLint level,
4148 GLint xoffset,
4149 GLint yoffset,
4150 GLint zoffset,
4151 GLsizei width,
4152 GLsizei height,
4153 GLsizei depth,
4154 GLenum format,
4155 GLsizei imageSize,
4156 GLsizei dataSize,
4157 const GLvoid *data)
4158{
4159 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4160 imageSize, data);
4161}
4162
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004163void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004164{
4165 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004166 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004167}
4168
Jamie Madill007530e2017-12-28 14:27:04 -05004169void Context::copyTexture(GLuint sourceId,
4170 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004171 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004172 GLuint destId,
4173 GLint destLevel,
4174 GLint internalFormat,
4175 GLenum destType,
4176 GLboolean unpackFlipY,
4177 GLboolean unpackPremultiplyAlpha,
4178 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004179{
Jamie Madillbc918e72018-03-08 09:47:21 -05004180 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004181
4182 gl::Texture *sourceTexture = getTexture(sourceId);
4183 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004184 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4185 sourceLevel, ConvertToBool(unpackFlipY),
4186 ConvertToBool(unpackPremultiplyAlpha),
4187 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004188}
4189
Jamie Madill007530e2017-12-28 14:27:04 -05004190void Context::copySubTexture(GLuint sourceId,
4191 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004192 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004193 GLuint destId,
4194 GLint destLevel,
4195 GLint xoffset,
4196 GLint yoffset,
4197 GLint x,
4198 GLint y,
4199 GLsizei width,
4200 GLsizei height,
4201 GLboolean unpackFlipY,
4202 GLboolean unpackPremultiplyAlpha,
4203 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004204{
4205 // Zero sized copies are valid but no-ops
4206 if (width == 0 || height == 0)
4207 {
4208 return;
4209 }
4210
Jamie Madillbc918e72018-03-08 09:47:21 -05004211 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004212
4213 gl::Texture *sourceTexture = getTexture(sourceId);
4214 gl::Texture *destTexture = getTexture(destId);
4215 Offset offset(xoffset, yoffset, 0);
4216 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004217 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4218 ConvertToBool(unpackFlipY),
4219 ConvertToBool(unpackPremultiplyAlpha),
4220 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004221}
4222
Jamie Madill007530e2017-12-28 14:27:04 -05004223void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004224{
Jamie Madillbc918e72018-03-08 09:47:21 -05004225 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004226
4227 gl::Texture *sourceTexture = getTexture(sourceId);
4228 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004229 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004230}
4231
Corentin Wallez336129f2017-10-17 15:55:40 -04004232void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004233{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004234 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004235 ASSERT(buffer);
4236
Geoff Lang496c02d2016-10-20 11:38:11 -07004237 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004238}
4239
Brandon Jones59770802018-04-02 13:18:42 -07004240void Context::getBufferPointervRobust(BufferBinding target,
4241 GLenum pname,
4242 GLsizei bufSize,
4243 GLsizei *length,
4244 void **params)
4245{
4246 getBufferPointerv(target, pname, params);
4247}
4248
Corentin Wallez336129f2017-10-17 15:55:40 -04004249void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004250{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004251 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004252 ASSERT(buffer);
4253
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004254 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004255 if (error.isError())
4256 {
Jamie Madill437fa652016-05-03 15:13:24 -04004257 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004258 return nullptr;
4259 }
4260
4261 return buffer->getMapPointer();
4262}
4263
Corentin Wallez336129f2017-10-17 15:55:40 -04004264GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004265{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004266 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004267 ASSERT(buffer);
4268
4269 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004270 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004271 if (error.isError())
4272 {
Jamie Madill437fa652016-05-03 15:13:24 -04004273 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004274 return GL_FALSE;
4275 }
4276
4277 return result;
4278}
4279
Corentin Wallez336129f2017-10-17 15:55:40 -04004280void *Context::mapBufferRange(BufferBinding target,
4281 GLintptr offset,
4282 GLsizeiptr length,
4283 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004284{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004285 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004286 ASSERT(buffer);
4287
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004288 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004289 if (error.isError())
4290 {
Jamie Madill437fa652016-05-03 15:13:24 -04004291 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004292 return nullptr;
4293 }
4294
4295 return buffer->getMapPointer();
4296}
4297
Corentin Wallez336129f2017-10-17 15:55:40 -04004298void Context::flushMappedBufferRange(BufferBinding /*target*/,
4299 GLintptr /*offset*/,
4300 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004301{
4302 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4303}
4304
Jamie Madillbc918e72018-03-08 09:47:21 -05004305Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004306{
Geoff Langa8cb2872018-03-09 16:09:40 -05004307 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004308}
4309
Jamie Madillbc918e72018-03-08 09:47:21 -05004310Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004311{
Geoff Langa8cb2872018-03-09 16:09:40 -05004312 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004313}
4314
Jamie Madillbc918e72018-03-08 09:47:21 -05004315Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004316{
Geoff Langa8cb2872018-03-09 16:09:40 -05004317 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004318}
4319
Geoff Lang9bf86f02018-07-26 11:46:34 -04004320Error Context::syncStateForPathOperation()
4321{
4322 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4323
4324 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4325 ANGLE_TRY(syncDirtyBits());
4326
4327 return NoError();
4328}
4329
Jiajia Qin5451d532017-11-16 17:16:34 +08004330void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4331{
4332 UNIMPLEMENTED();
4333}
4334
Jamie Madillc20ab272016-06-09 07:20:46 -07004335void Context::activeTexture(GLenum texture)
4336{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004337 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004338}
4339
Jamie Madill876429b2017-04-20 15:46:24 -04004340void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004341{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004342 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004343}
4344
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004345void Context::blendEquation(GLenum mode)
4346{
4347 mGLState.setBlendEquation(mode, mode);
4348}
4349
Jamie Madillc20ab272016-06-09 07:20:46 -07004350void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4351{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004352 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004353}
4354
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004355void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4356{
4357 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4358}
4359
Jamie Madillc20ab272016-06-09 07:20:46 -07004360void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4361{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004362 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004363}
4364
Jamie Madill876429b2017-04-20 15:46:24 -04004365void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004366{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004367 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004368}
4369
Jamie Madill876429b2017-04-20 15:46:24 -04004370void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004371{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004372 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004373}
4374
4375void Context::clearStencil(GLint s)
4376{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004377 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004378}
4379
4380void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4381{
Geoff Lang92019432017-11-20 13:09:34 -05004382 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4383 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004384}
4385
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004386void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004387{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004388 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004389}
4390
4391void Context::depthFunc(GLenum func)
4392{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004393 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004394}
4395
4396void Context::depthMask(GLboolean flag)
4397{
Geoff Lang92019432017-11-20 13:09:34 -05004398 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004399}
4400
Jamie Madill876429b2017-04-20 15:46:24 -04004401void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004402{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004403 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004404}
4405
4406void Context::disable(GLenum cap)
4407{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004408 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004409}
4410
4411void Context::disableVertexAttribArray(GLuint index)
4412{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004413 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004414 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004415}
4416
4417void Context::enable(GLenum cap)
4418{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004419 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004420}
4421
4422void Context::enableVertexAttribArray(GLuint index)
4423{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004424 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004425 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004426}
4427
4428void Context::frontFace(GLenum mode)
4429{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004430 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004431}
4432
4433void Context::hint(GLenum target, GLenum mode)
4434{
4435 switch (target)
4436 {
4437 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004438 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004439 break;
4440
4441 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004442 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004443 break;
4444
4445 default:
4446 UNREACHABLE();
4447 return;
4448 }
4449}
4450
4451void Context::lineWidth(GLfloat width)
4452{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004453 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004454}
4455
4456void Context::pixelStorei(GLenum pname, GLint param)
4457{
4458 switch (pname)
4459 {
4460 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004461 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004462 break;
4463
4464 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004465 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004466 break;
4467
4468 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004469 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004470 break;
4471
4472 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004473 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004474 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004475 break;
4476
4477 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004478 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004479 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004480 break;
4481
4482 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004483 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004484 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004485 break;
4486
4487 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004488 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004489 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004490 break;
4491
4492 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004493 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004494 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004495 break;
4496
4497 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004498 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004499 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004500 break;
4501
4502 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004503 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004504 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004505 break;
4506
4507 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004508 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004509 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004510 break;
4511
4512 default:
4513 UNREACHABLE();
4514 return;
4515 }
4516}
4517
4518void Context::polygonOffset(GLfloat factor, GLfloat units)
4519{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004520 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004521}
4522
Jamie Madill876429b2017-04-20 15:46:24 -04004523void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004524{
Geoff Lang92019432017-11-20 13:09:34 -05004525 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004526}
4527
Jiawei Shaodb342272017-09-27 10:21:45 +08004528void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4529{
4530 mGLState.setSampleMaskParams(maskNumber, mask);
4531}
4532
Jamie Madillc20ab272016-06-09 07:20:46 -07004533void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4534{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004535 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004536}
4537
4538void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4539{
4540 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4541 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004542 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004543 }
4544
4545 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4546 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004547 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004548 }
4549}
4550
4551void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4552{
4553 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4554 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004555 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004556 }
4557
4558 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4559 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004560 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004561 }
4562}
4563
4564void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4565{
4566 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4567 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004568 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004569 }
4570
4571 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4572 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004573 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004574 }
4575}
4576
4577void Context::vertexAttrib1f(GLuint index, GLfloat x)
4578{
4579 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004580 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004581}
4582
4583void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4584{
4585 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004586 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004587}
4588
4589void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4590{
4591 GLfloat vals[4] = {x, y, 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::vertexAttrib2fv(GLuint index, const GLfloat *values)
4596{
4597 GLfloat vals[4] = {values[0], values[1], 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::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4602{
4603 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004604 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004605}
4606
4607void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4608{
4609 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004610 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004611}
4612
4613void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4614{
4615 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004616 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004617}
4618
4619void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4620{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004621 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004622}
4623
4624void Context::vertexAttribPointer(GLuint index,
4625 GLint size,
4626 GLenum type,
4627 GLboolean normalized,
4628 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004629 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004630{
Corentin Wallez336129f2017-10-17 15:55:40 -04004631 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004632 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004633 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004634}
4635
Shao80957d92017-02-20 21:25:59 +08004636void Context::vertexAttribFormat(GLuint attribIndex,
4637 GLint size,
4638 GLenum type,
4639 GLboolean normalized,
4640 GLuint relativeOffset)
4641{
Geoff Lang92019432017-11-20 13:09:34 -05004642 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004643 relativeOffset);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004644 mStateCache.onVertexArraySizeChange(this);
Shao80957d92017-02-20 21:25:59 +08004645}
4646
4647void Context::vertexAttribIFormat(GLuint attribIndex,
4648 GLint size,
4649 GLenum type,
4650 GLuint relativeOffset)
4651{
4652 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004653 mStateCache.onVertexArraySizeChange(this);
Shao80957d92017-02-20 21:25:59 +08004654}
4655
4656void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4657{
Shaodde78e82017-05-22 14:13:27 +08004658 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004659 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004660}
4661
Jiajia Qin5451d532017-11-16 17:16:34 +08004662void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004663{
4664 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004665 mStateCache.onVertexArraySizeChange(this);
Shao80957d92017-02-20 21:25:59 +08004666}
4667
Jamie Madillc20ab272016-06-09 07:20:46 -07004668void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4669{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004670 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004671}
4672
4673void Context::vertexAttribIPointer(GLuint index,
4674 GLint size,
4675 GLenum type,
4676 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004677 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004678{
Corentin Wallez336129f2017-10-17 15:55:40 -04004679 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4680 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004681 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004682}
4683
4684void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4685{
4686 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004687 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004688}
4689
4690void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4691{
4692 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004693 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004694}
4695
4696void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4697{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004698 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004699}
4700
4701void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4702{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004703 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004704}
4705
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004706void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4707{
4708 const VertexAttribCurrentValueData &currentValues =
4709 getGLState().getVertexAttribCurrentValue(index);
4710 const VertexArray *vao = getGLState().getVertexArray();
4711 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4712 currentValues, pname, params);
4713}
4714
Brandon Jones59770802018-04-02 13:18:42 -07004715void Context::getVertexAttribivRobust(GLuint index,
4716 GLenum pname,
4717 GLsizei bufSize,
4718 GLsizei *length,
4719 GLint *params)
4720{
4721 getVertexAttribiv(index, pname, params);
4722}
4723
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004724void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4725{
4726 const VertexAttribCurrentValueData &currentValues =
4727 getGLState().getVertexAttribCurrentValue(index);
4728 const VertexArray *vao = getGLState().getVertexArray();
4729 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4730 currentValues, pname, params);
4731}
4732
Brandon Jones59770802018-04-02 13:18:42 -07004733void Context::getVertexAttribfvRobust(GLuint index,
4734 GLenum pname,
4735 GLsizei bufSize,
4736 GLsizei *length,
4737 GLfloat *params)
4738{
4739 getVertexAttribfv(index, pname, params);
4740}
4741
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004742void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4743{
4744 const VertexAttribCurrentValueData &currentValues =
4745 getGLState().getVertexAttribCurrentValue(index);
4746 const VertexArray *vao = getGLState().getVertexArray();
4747 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4748 currentValues, pname, params);
4749}
4750
Brandon Jones59770802018-04-02 13:18:42 -07004751void Context::getVertexAttribIivRobust(GLuint index,
4752 GLenum pname,
4753 GLsizei bufSize,
4754 GLsizei *length,
4755 GLint *params)
4756{
4757 getVertexAttribIiv(index, pname, params);
4758}
4759
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004760void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4761{
4762 const VertexAttribCurrentValueData &currentValues =
4763 getGLState().getVertexAttribCurrentValue(index);
4764 const VertexArray *vao = getGLState().getVertexArray();
4765 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4766 currentValues, pname, params);
4767}
4768
Brandon Jones59770802018-04-02 13:18:42 -07004769void Context::getVertexAttribIuivRobust(GLuint index,
4770 GLenum pname,
4771 GLsizei bufSize,
4772 GLsizei *length,
4773 GLuint *params)
4774{
4775 getVertexAttribIuiv(index, pname, params);
4776}
4777
Jamie Madill876429b2017-04-20 15:46:24 -04004778void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004779{
4780 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4781 QueryVertexAttribPointerv(attrib, pname, pointer);
4782}
4783
Brandon Jones59770802018-04-02 13:18:42 -07004784void Context::getVertexAttribPointervRobust(GLuint index,
4785 GLenum pname,
4786 GLsizei bufSize,
4787 GLsizei *length,
4788 void **pointer)
4789{
4790 getVertexAttribPointerv(index, pname, pointer);
4791}
4792
Jamie Madillc20ab272016-06-09 07:20:46 -07004793void Context::debugMessageControl(GLenum source,
4794 GLenum type,
4795 GLenum severity,
4796 GLsizei count,
4797 const GLuint *ids,
4798 GLboolean enabled)
4799{
4800 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004801 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004802 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004803}
4804
4805void Context::debugMessageInsert(GLenum source,
4806 GLenum type,
4807 GLuint id,
4808 GLenum severity,
4809 GLsizei length,
4810 const GLchar *buf)
4811{
4812 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004813 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004814}
4815
4816void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4817{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004818 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004819}
4820
4821GLuint Context::getDebugMessageLog(GLuint count,
4822 GLsizei bufSize,
4823 GLenum *sources,
4824 GLenum *types,
4825 GLuint *ids,
4826 GLenum *severities,
4827 GLsizei *lengths,
4828 GLchar *messageLog)
4829{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004830 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4831 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004832}
4833
4834void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4835{
4836 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004837 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004838 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004839}
4840
4841void Context::popDebugGroup()
4842{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004843 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004844 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004845}
4846
Corentin Wallez336129f2017-10-17 15:55:40 -04004847void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004848{
4849 Buffer *buffer = mGLState.getTargetBuffer(target);
4850 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004851 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004852}
4853
Corentin Wallez336129f2017-10-17 15:55:40 -04004854void Context::bufferSubData(BufferBinding target,
4855 GLintptr offset,
4856 GLsizeiptr size,
4857 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004858{
4859 if (data == nullptr)
4860 {
4861 return;
4862 }
4863
4864 Buffer *buffer = mGLState.getTargetBuffer(target);
4865 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004866 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004867}
4868
Jamie Madillef300b12016-10-07 15:12:09 -04004869void Context::attachShader(GLuint program, GLuint shader)
4870{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004871 Program *programObject = mState.mShaderPrograms->getProgram(program);
4872 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004873 ASSERT(programObject && shaderObject);
4874 programObject->attachShader(shaderObject);
4875}
4876
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004877const Workarounds &Context::getWorkarounds() const
4878{
4879 return mWorkarounds;
4880}
4881
Corentin Wallez336129f2017-10-17 15:55:40 -04004882void Context::copyBufferSubData(BufferBinding readTarget,
4883 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004884 GLintptr readOffset,
4885 GLintptr writeOffset,
4886 GLsizeiptr size)
4887{
4888 // if size is zero, the copy is a successful no-op
4889 if (size == 0)
4890 {
4891 return;
4892 }
4893
4894 // TODO(jmadill): cache these.
4895 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4896 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4897
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004898 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004899}
4900
Jamie Madill01a80ee2016-11-07 12:06:18 -05004901void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4902{
4903 Program *programObject = getProgram(program);
4904 // TODO(jmadill): Re-use this from the validation if possible.
4905 ASSERT(programObject);
4906 programObject->bindAttributeLocation(index, name);
4907}
4908
Corentin Wallez336129f2017-10-17 15:55:40 -04004909void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004910{
Corentin Wallez336129f2017-10-17 15:55:40 -04004911 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4912 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004913}
4914
Corentin Wallez336129f2017-10-17 15:55:40 -04004915void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004916{
4917 bindBufferRange(target, index, buffer, 0, 0);
4918}
4919
Corentin Wallez336129f2017-10-17 15:55:40 -04004920void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004921 GLuint index,
4922 GLuint buffer,
4923 GLintptr offset,
4924 GLsizeiptr size)
4925{
Corentin Wallez336129f2017-10-17 15:55:40 -04004926 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4927 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004928}
4929
Jamie Madill01a80ee2016-11-07 12:06:18 -05004930void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4931{
4932 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4933 {
4934 bindReadFramebuffer(framebuffer);
4935 }
4936
4937 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4938 {
4939 bindDrawFramebuffer(framebuffer);
4940 }
4941}
4942
4943void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4944{
4945 ASSERT(target == GL_RENDERBUFFER);
4946 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004947 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004948 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004949}
4950
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004951void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004952 GLsizei samples,
4953 GLenum internalformat,
4954 GLsizei width,
4955 GLsizei height,
4956 GLboolean fixedsamplelocations)
4957{
4958 Extents size(width, height, 1);
4959 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004960 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4961 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004962}
4963
4964void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4965{
JiangYizhou5b03f472017-01-09 10:22:53 +08004966 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4967 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004968 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004969 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004970
4971 switch (pname)
4972 {
4973 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004974 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004975 break;
4976 default:
4977 UNREACHABLE();
4978 }
4979}
4980
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004981void Context::getMultisamplefvRobust(GLenum pname,
4982 GLuint index,
4983 GLsizei bufSize,
4984 GLsizei *length,
4985 GLfloat *val)
4986{
4987 UNIMPLEMENTED();
4988}
4989
Jamie Madille8fb6402017-02-14 17:56:40 -05004990void Context::renderbufferStorage(GLenum target,
4991 GLenum internalformat,
4992 GLsizei width,
4993 GLsizei height)
4994{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004995 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4996 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4997
Jamie Madille8fb6402017-02-14 17:56:40 -05004998 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004999 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005000}
5001
5002void Context::renderbufferStorageMultisample(GLenum target,
5003 GLsizei samples,
5004 GLenum internalformat,
5005 GLsizei width,
5006 GLsizei height)
5007{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005008 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5009 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005010
5011 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005012 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005013 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005014}
5015
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005016void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5017{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005018 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04005019 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005020}
5021
JiangYizhoue18e6392017-02-20 10:32:23 +08005022void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5023{
5024 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5025 QueryFramebufferParameteriv(framebuffer, pname, params);
5026}
5027
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005028void Context::getFramebufferParameterivRobust(GLenum target,
5029 GLenum pname,
5030 GLsizei bufSize,
5031 GLsizei *length,
5032 GLint *params)
5033{
5034 UNIMPLEMENTED();
5035}
5036
Jiajia Qin5451d532017-11-16 17:16:34 +08005037void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005038{
5039 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005040 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005041}
5042
Jamie Madilldec86232018-07-11 09:01:18 -04005043bool Context::getScratchBuffer(size_t requstedSizeBytes,
5044 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005045{
Jamie Madilldec86232018-07-11 09:01:18 -04005046 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005047}
5048
Jamie Madilldec86232018-07-11 09:01:18 -04005049bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5050 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005051{
Jamie Madilldec86232018-07-11 09:01:18 -04005052 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005053}
5054
Xinghua Cao10a4d432017-11-28 14:46:26 +08005055Error Context::prepareForDispatch()
5056{
Geoff Langa8cb2872018-03-09 16:09:40 -05005057 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005058
5059 if (isRobustResourceInitEnabled())
5060 {
5061 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5062 }
5063
5064 return NoError();
5065}
5066
Xinghua Cao2b396592017-03-29 15:36:04 +08005067void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5068{
5069 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5070 {
5071 return;
5072 }
5073
Xinghua Cao10a4d432017-11-28 14:46:26 +08005074 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005075 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005076}
5077
Jiajia Qin5451d532017-11-16 17:16:34 +08005078void Context::dispatchComputeIndirect(GLintptr indirect)
5079{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005080 ANGLE_CONTEXT_TRY(prepareForDispatch());
5081 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005082}
5083
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005084void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005085 GLsizei levels,
5086 GLenum internalFormat,
5087 GLsizei width,
5088 GLsizei height)
5089{
5090 Extents size(width, height, 1);
5091 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005092 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005093}
5094
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005095void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005096 GLsizei levels,
5097 GLenum internalFormat,
5098 GLsizei width,
5099 GLsizei height,
5100 GLsizei depth)
5101{
5102 Extents size(width, height, depth);
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
Jiajia Qin5451d532017-11-16 17:16:34 +08005107void Context::memoryBarrier(GLbitfield barriers)
5108{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005109 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005110}
5111
5112void Context::memoryBarrierByRegion(GLbitfield barriers)
5113{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005114 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005115}
5116
Jamie Madillc1d770e2017-04-13 17:31:24 -04005117GLenum Context::checkFramebufferStatus(GLenum target)
5118{
5119 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5120 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005121 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005122}
5123
5124void Context::compileShader(GLuint shader)
5125{
5126 Shader *shaderObject = GetValidShader(this, shader);
5127 if (!shaderObject)
5128 {
5129 return;
5130 }
5131 shaderObject->compile(this);
5132}
5133
5134void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5135{
5136 for (int i = 0; i < n; i++)
5137 {
5138 deleteBuffer(buffers[i]);
5139 }
5140}
5141
5142void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5143{
5144 for (int i = 0; i < n; i++)
5145 {
5146 if (framebuffers[i] != 0)
5147 {
5148 deleteFramebuffer(framebuffers[i]);
5149 }
5150 }
5151}
5152
5153void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5154{
5155 for (int i = 0; i < n; i++)
5156 {
5157 deleteRenderbuffer(renderbuffers[i]);
5158 }
5159}
5160
5161void Context::deleteTextures(GLsizei n, const GLuint *textures)
5162{
5163 for (int i = 0; i < n; i++)
5164 {
5165 if (textures[i] != 0)
5166 {
5167 deleteTexture(textures[i]);
5168 }
5169 }
5170}
5171
5172void Context::detachShader(GLuint program, GLuint shader)
5173{
5174 Program *programObject = getProgram(program);
5175 ASSERT(programObject);
5176
5177 Shader *shaderObject = getShader(shader);
5178 ASSERT(shaderObject);
5179
5180 programObject->detachShader(this, shaderObject);
5181}
5182
5183void Context::genBuffers(GLsizei n, GLuint *buffers)
5184{
5185 for (int i = 0; i < n; i++)
5186 {
5187 buffers[i] = createBuffer();
5188 }
5189}
5190
5191void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5192{
5193 for (int i = 0; i < n; i++)
5194 {
5195 framebuffers[i] = createFramebuffer();
5196 }
5197}
5198
5199void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5200{
5201 for (int i = 0; i < n; i++)
5202 {
5203 renderbuffers[i] = createRenderbuffer();
5204 }
5205}
5206
5207void Context::genTextures(GLsizei n, GLuint *textures)
5208{
5209 for (int i = 0; i < n; i++)
5210 {
5211 textures[i] = createTexture();
5212 }
5213}
5214
5215void Context::getActiveAttrib(GLuint program,
5216 GLuint index,
5217 GLsizei bufsize,
5218 GLsizei *length,
5219 GLint *size,
5220 GLenum *type,
5221 GLchar *name)
5222{
5223 Program *programObject = getProgram(program);
5224 ASSERT(programObject);
5225 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5226}
5227
5228void Context::getActiveUniform(GLuint program,
5229 GLuint index,
5230 GLsizei bufsize,
5231 GLsizei *length,
5232 GLint *size,
5233 GLenum *type,
5234 GLchar *name)
5235{
5236 Program *programObject = getProgram(program);
5237 ASSERT(programObject);
5238 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5239}
5240
5241void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5242{
5243 Program *programObject = getProgram(program);
5244 ASSERT(programObject);
5245 programObject->getAttachedShaders(maxcount, count, shaders);
5246}
5247
5248GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5249{
5250 Program *programObject = getProgram(program);
5251 ASSERT(programObject);
5252 return programObject->getAttributeLocation(name);
5253}
5254
5255void Context::getBooleanv(GLenum pname, GLboolean *params)
5256{
5257 GLenum nativeType;
5258 unsigned int numParams = 0;
5259 getQueryParameterInfo(pname, &nativeType, &numParams);
5260
5261 if (nativeType == GL_BOOL)
5262 {
5263 getBooleanvImpl(pname, params);
5264 }
5265 else
5266 {
5267 CastStateValues(this, nativeType, pname, numParams, params);
5268 }
5269}
5270
Brandon Jones59770802018-04-02 13:18:42 -07005271void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5272{
5273 getBooleanv(pname, params);
5274}
5275
Jamie Madillc1d770e2017-04-13 17:31:24 -04005276void Context::getFloatv(GLenum pname, GLfloat *params)
5277{
5278 GLenum nativeType;
5279 unsigned int numParams = 0;
5280 getQueryParameterInfo(pname, &nativeType, &numParams);
5281
5282 if (nativeType == GL_FLOAT)
5283 {
5284 getFloatvImpl(pname, params);
5285 }
5286 else
5287 {
5288 CastStateValues(this, nativeType, pname, numParams, params);
5289 }
5290}
5291
Brandon Jones59770802018-04-02 13:18:42 -07005292void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5293{
5294 getFloatv(pname, params);
5295}
5296
Jamie Madillc1d770e2017-04-13 17:31:24 -04005297void Context::getIntegerv(GLenum pname, GLint *params)
5298{
5299 GLenum nativeType;
5300 unsigned int numParams = 0;
5301 getQueryParameterInfo(pname, &nativeType, &numParams);
5302
5303 if (nativeType == GL_INT)
5304 {
5305 getIntegervImpl(pname, params);
5306 }
5307 else
5308 {
5309 CastStateValues(this, nativeType, pname, numParams, params);
5310 }
5311}
5312
Brandon Jones59770802018-04-02 13:18:42 -07005313void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5314{
5315 getIntegerv(pname, data);
5316}
5317
Jamie Madillc1d770e2017-04-13 17:31:24 -04005318void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5319{
5320 Program *programObject = getProgram(program);
5321 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005322 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005323}
5324
Brandon Jones59770802018-04-02 13:18:42 -07005325void Context::getProgramivRobust(GLuint program,
5326 GLenum pname,
5327 GLsizei bufSize,
5328 GLsizei *length,
5329 GLint *params)
5330{
5331 getProgramiv(program, pname, params);
5332}
5333
Jiajia Qin5451d532017-11-16 17:16:34 +08005334void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5335{
5336 UNIMPLEMENTED();
5337}
5338
Jamie Madillbe849e42017-05-02 15:49:00 -04005339void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005340{
5341 Program *programObject = getProgram(program);
5342 ASSERT(programObject);
5343 programObject->getInfoLog(bufsize, length, infolog);
5344}
5345
Jiajia Qin5451d532017-11-16 17:16:34 +08005346void Context::getProgramPipelineInfoLog(GLuint pipeline,
5347 GLsizei bufSize,
5348 GLsizei *length,
5349 GLchar *infoLog)
5350{
5351 UNIMPLEMENTED();
5352}
5353
Jamie Madillc1d770e2017-04-13 17:31:24 -04005354void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5355{
5356 Shader *shaderObject = getShader(shader);
5357 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005358 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005359}
5360
Brandon Jones59770802018-04-02 13:18:42 -07005361void Context::getShaderivRobust(GLuint shader,
5362 GLenum pname,
5363 GLsizei bufSize,
5364 GLsizei *length,
5365 GLint *params)
5366{
5367 getShaderiv(shader, pname, params);
5368}
5369
Jamie Madillc1d770e2017-04-13 17:31:24 -04005370void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5371{
5372 Shader *shaderObject = getShader(shader);
5373 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005374 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005375}
5376
5377void Context::getShaderPrecisionFormat(GLenum shadertype,
5378 GLenum precisiontype,
5379 GLint *range,
5380 GLint *precision)
5381{
5382 // TODO(jmadill): Compute shaders.
5383
5384 switch (shadertype)
5385 {
5386 case GL_VERTEX_SHADER:
5387 switch (precisiontype)
5388 {
5389 case GL_LOW_FLOAT:
5390 mCaps.vertexLowpFloat.get(range, precision);
5391 break;
5392 case GL_MEDIUM_FLOAT:
5393 mCaps.vertexMediumpFloat.get(range, precision);
5394 break;
5395 case GL_HIGH_FLOAT:
5396 mCaps.vertexHighpFloat.get(range, precision);
5397 break;
5398
5399 case GL_LOW_INT:
5400 mCaps.vertexLowpInt.get(range, precision);
5401 break;
5402 case GL_MEDIUM_INT:
5403 mCaps.vertexMediumpInt.get(range, precision);
5404 break;
5405 case GL_HIGH_INT:
5406 mCaps.vertexHighpInt.get(range, precision);
5407 break;
5408
5409 default:
5410 UNREACHABLE();
5411 return;
5412 }
5413 break;
5414
5415 case GL_FRAGMENT_SHADER:
5416 switch (precisiontype)
5417 {
5418 case GL_LOW_FLOAT:
5419 mCaps.fragmentLowpFloat.get(range, precision);
5420 break;
5421 case GL_MEDIUM_FLOAT:
5422 mCaps.fragmentMediumpFloat.get(range, precision);
5423 break;
5424 case GL_HIGH_FLOAT:
5425 mCaps.fragmentHighpFloat.get(range, precision);
5426 break;
5427
5428 case GL_LOW_INT:
5429 mCaps.fragmentLowpInt.get(range, precision);
5430 break;
5431 case GL_MEDIUM_INT:
5432 mCaps.fragmentMediumpInt.get(range, precision);
5433 break;
5434 case GL_HIGH_INT:
5435 mCaps.fragmentHighpInt.get(range, precision);
5436 break;
5437
5438 default:
5439 UNREACHABLE();
5440 return;
5441 }
5442 break;
5443
5444 default:
5445 UNREACHABLE();
5446 return;
5447 }
5448}
5449
5450void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5451{
5452 Shader *shaderObject = getShader(shader);
5453 ASSERT(shaderObject);
5454 shaderObject->getSource(bufsize, length, source);
5455}
5456
5457void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5458{
5459 Program *programObject = getProgram(program);
5460 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005461 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005462}
5463
Brandon Jones59770802018-04-02 13:18:42 -07005464void Context::getUniformfvRobust(GLuint program,
5465 GLint location,
5466 GLsizei bufSize,
5467 GLsizei *length,
5468 GLfloat *params)
5469{
5470 getUniformfv(program, location, params);
5471}
5472
Jamie Madillc1d770e2017-04-13 17:31:24 -04005473void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5474{
5475 Program *programObject = getProgram(program);
5476 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005477 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005478}
5479
Brandon Jones59770802018-04-02 13:18:42 -07005480void Context::getUniformivRobust(GLuint program,
5481 GLint location,
5482 GLsizei bufSize,
5483 GLsizei *length,
5484 GLint *params)
5485{
5486 getUniformiv(program, location, params);
5487}
5488
Jamie Madillc1d770e2017-04-13 17:31:24 -04005489GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5490{
5491 Program *programObject = getProgram(program);
5492 ASSERT(programObject);
5493 return programObject->getUniformLocation(name);
5494}
5495
5496GLboolean Context::isBuffer(GLuint buffer)
5497{
5498 if (buffer == 0)
5499 {
5500 return GL_FALSE;
5501 }
5502
5503 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5504}
5505
5506GLboolean Context::isEnabled(GLenum cap)
5507{
5508 return mGLState.getEnableFeature(cap);
5509}
5510
5511GLboolean Context::isFramebuffer(GLuint framebuffer)
5512{
5513 if (framebuffer == 0)
5514 {
5515 return GL_FALSE;
5516 }
5517
5518 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5519}
5520
5521GLboolean Context::isProgram(GLuint program)
5522{
5523 if (program == 0)
5524 {
5525 return GL_FALSE;
5526 }
5527
5528 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5529}
5530
5531GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5532{
5533 if (renderbuffer == 0)
5534 {
5535 return GL_FALSE;
5536 }
5537
5538 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5539}
5540
5541GLboolean Context::isShader(GLuint shader)
5542{
5543 if (shader == 0)
5544 {
5545 return GL_FALSE;
5546 }
5547
5548 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5549}
5550
5551GLboolean Context::isTexture(GLuint texture)
5552{
5553 if (texture == 0)
5554 {
5555 return GL_FALSE;
5556 }
5557
5558 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5559}
5560
5561void Context::linkProgram(GLuint program)
5562{
5563 Program *programObject = getProgram(program);
5564 ASSERT(programObject);
5565 handleError(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005566
5567 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5568 // don't need to worry that:
5569 // 1. Draw calls after link use the new executable code or the old one depending on the link
5570 // result.
5571 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5572 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5573 // ProgramD3D.
5574 if (programObject->isInUse())
5575 {
5576 // isLinked() which forces to resolve linking, will be called.
5577 mGLState.onProgramExecutableChange(programObject);
5578 mStateCache.onProgramExecutableChange(this);
5579 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005580}
5581
5582void Context::releaseShaderCompiler()
5583{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005584 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005585}
5586
5587void Context::shaderBinary(GLsizei n,
5588 const GLuint *shaders,
5589 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005590 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005591 GLsizei length)
5592{
5593 // No binary shader formats are supported.
5594 UNIMPLEMENTED();
5595}
5596
5597void Context::shaderSource(GLuint shader,
5598 GLsizei count,
5599 const GLchar *const *string,
5600 const GLint *length)
5601{
5602 Shader *shaderObject = getShader(shader);
5603 ASSERT(shaderObject);
5604 shaderObject->setSource(count, string, length);
5605}
5606
5607void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5608{
5609 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5610}
5611
5612void Context::stencilMask(GLuint mask)
5613{
5614 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5615}
5616
5617void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5618{
5619 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5620}
5621
5622void Context::uniform1f(GLint location, GLfloat x)
5623{
5624 Program *program = mGLState.getProgram();
5625 program->setUniform1fv(location, 1, &x);
5626}
5627
5628void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5629{
5630 Program *program = mGLState.getProgram();
5631 program->setUniform1fv(location, count, v);
5632}
5633
Jamie Madill7e4eff12018-08-08 15:49:26 -04005634void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005635{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005636 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04005637 {
5638 mGLState.setObjectDirty(GL_PROGRAM);
5639 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005640}
5641
Jamie Madill7e4eff12018-08-08 15:49:26 -04005642void Context::uniform1i(GLint location, GLint x)
5643{
5644 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
5645}
5646
Jamie Madillc1d770e2017-04-13 17:31:24 -04005647void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5648{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005649 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005650}
5651
5652void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5653{
5654 GLfloat xy[2] = {x, y};
5655 Program *program = mGLState.getProgram();
5656 program->setUniform2fv(location, 1, xy);
5657}
5658
5659void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5660{
5661 Program *program = mGLState.getProgram();
5662 program->setUniform2fv(location, count, v);
5663}
5664
5665void Context::uniform2i(GLint location, GLint x, GLint y)
5666{
5667 GLint xy[2] = {x, y};
5668 Program *program = mGLState.getProgram();
5669 program->setUniform2iv(location, 1, xy);
5670}
5671
5672void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5673{
5674 Program *program = mGLState.getProgram();
5675 program->setUniform2iv(location, count, v);
5676}
5677
5678void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5679{
5680 GLfloat xyz[3] = {x, y, z};
5681 Program *program = mGLState.getProgram();
5682 program->setUniform3fv(location, 1, xyz);
5683}
5684
5685void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5686{
5687 Program *program = mGLState.getProgram();
5688 program->setUniform3fv(location, count, v);
5689}
5690
5691void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5692{
5693 GLint xyz[3] = {x, y, z};
5694 Program *program = mGLState.getProgram();
5695 program->setUniform3iv(location, 1, xyz);
5696}
5697
5698void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5699{
5700 Program *program = mGLState.getProgram();
5701 program->setUniform3iv(location, count, v);
5702}
5703
5704void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5705{
5706 GLfloat xyzw[4] = {x, y, z, w};
5707 Program *program = mGLState.getProgram();
5708 program->setUniform4fv(location, 1, xyzw);
5709}
5710
5711void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5712{
5713 Program *program = mGLState.getProgram();
5714 program->setUniform4fv(location, count, v);
5715}
5716
5717void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5718{
5719 GLint xyzw[4] = {x, y, z, w};
5720 Program *program = mGLState.getProgram();
5721 program->setUniform4iv(location, 1, xyzw);
5722}
5723
5724void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5725{
5726 Program *program = mGLState.getProgram();
5727 program->setUniform4iv(location, count, v);
5728}
5729
5730void Context::uniformMatrix2fv(GLint location,
5731 GLsizei count,
5732 GLboolean transpose,
5733 const GLfloat *value)
5734{
5735 Program *program = mGLState.getProgram();
5736 program->setUniformMatrix2fv(location, count, transpose, value);
5737}
5738
5739void Context::uniformMatrix3fv(GLint location,
5740 GLsizei count,
5741 GLboolean transpose,
5742 const GLfloat *value)
5743{
5744 Program *program = mGLState.getProgram();
5745 program->setUniformMatrix3fv(location, count, transpose, value);
5746}
5747
5748void Context::uniformMatrix4fv(GLint location,
5749 GLsizei count,
5750 GLboolean transpose,
5751 const GLfloat *value)
5752{
5753 Program *program = mGLState.getProgram();
5754 program->setUniformMatrix4fv(location, count, transpose, value);
5755}
5756
5757void Context::validateProgram(GLuint program)
5758{
5759 Program *programObject = getProgram(program);
5760 ASSERT(programObject);
5761 programObject->validate(mCaps);
5762}
5763
Jiajia Qin5451d532017-11-16 17:16:34 +08005764void Context::validateProgramPipeline(GLuint pipeline)
5765{
5766 UNIMPLEMENTED();
5767}
5768
Jamie Madilld04908b2017-06-09 14:15:35 -04005769void Context::getProgramBinary(GLuint program,
5770 GLsizei bufSize,
5771 GLsizei *length,
5772 GLenum *binaryFormat,
5773 void *binary)
5774{
5775 Program *programObject = getProgram(program);
5776 ASSERT(programObject != nullptr);
5777
5778 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5779}
5780
5781void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5782{
5783 Program *programObject = getProgram(program);
5784 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005785
Jamie Madilld04908b2017-06-09 14:15:35 -04005786 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madillc43cdad2018-08-08 15:49:25 -04005787 mStateCache.onProgramExecutableChange(this);
Jamie Madilld04908b2017-06-09 14:15:35 -04005788}
5789
Jamie Madillff325f12017-08-26 15:06:05 -04005790void Context::uniform1ui(GLint location, GLuint v0)
5791{
5792 Program *program = mGLState.getProgram();
5793 program->setUniform1uiv(location, 1, &v0);
5794}
5795
5796void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5797{
5798 Program *program = mGLState.getProgram();
5799 const GLuint xy[] = {v0, v1};
5800 program->setUniform2uiv(location, 1, xy);
5801}
5802
5803void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5804{
5805 Program *program = mGLState.getProgram();
5806 const GLuint xyz[] = {v0, v1, v2};
5807 program->setUniform3uiv(location, 1, xyz);
5808}
5809
5810void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5811{
5812 Program *program = mGLState.getProgram();
5813 const GLuint xyzw[] = {v0, v1, v2, v3};
5814 program->setUniform4uiv(location, 1, xyzw);
5815}
5816
5817void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5818{
5819 Program *program = mGLState.getProgram();
5820 program->setUniform1uiv(location, count, value);
5821}
5822void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5823{
5824 Program *program = mGLState.getProgram();
5825 program->setUniform2uiv(location, count, value);
5826}
5827
5828void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5829{
5830 Program *program = mGLState.getProgram();
5831 program->setUniform3uiv(location, count, value);
5832}
5833
5834void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5835{
5836 Program *program = mGLState.getProgram();
5837 program->setUniform4uiv(location, count, value);
5838}
5839
Jamie Madillf0e04492017-08-26 15:28:42 -04005840void Context::genQueries(GLsizei n, GLuint *ids)
5841{
5842 for (GLsizei i = 0; i < n; i++)
5843 {
5844 GLuint handle = mQueryHandleAllocator.allocate();
5845 mQueryMap.assign(handle, nullptr);
5846 ids[i] = handle;
5847 }
5848}
5849
5850void Context::deleteQueries(GLsizei n, const GLuint *ids)
5851{
5852 for (int i = 0; i < n; i++)
5853 {
5854 GLuint query = ids[i];
5855
5856 Query *queryObject = nullptr;
5857 if (mQueryMap.erase(query, &queryObject))
5858 {
5859 mQueryHandleAllocator.release(query);
5860 if (queryObject)
5861 {
5862 queryObject->release(this);
5863 }
5864 }
5865 }
5866}
5867
5868GLboolean Context::isQuery(GLuint id)
5869{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005870 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005871}
5872
Jamie Madillc8c95812017-08-26 18:40:09 -04005873void Context::uniformMatrix2x3fv(GLint location,
5874 GLsizei count,
5875 GLboolean transpose,
5876 const GLfloat *value)
5877{
5878 Program *program = mGLState.getProgram();
5879 program->setUniformMatrix2x3fv(location, count, transpose, value);
5880}
5881
5882void Context::uniformMatrix3x2fv(GLint location,
5883 GLsizei count,
5884 GLboolean transpose,
5885 const GLfloat *value)
5886{
5887 Program *program = mGLState.getProgram();
5888 program->setUniformMatrix3x2fv(location, count, transpose, value);
5889}
5890
5891void Context::uniformMatrix2x4fv(GLint location,
5892 GLsizei count,
5893 GLboolean transpose,
5894 const GLfloat *value)
5895{
5896 Program *program = mGLState.getProgram();
5897 program->setUniformMatrix2x4fv(location, count, transpose, value);
5898}
5899
5900void Context::uniformMatrix4x2fv(GLint location,
5901 GLsizei count,
5902 GLboolean transpose,
5903 const GLfloat *value)
5904{
5905 Program *program = mGLState.getProgram();
5906 program->setUniformMatrix4x2fv(location, count, transpose, value);
5907}
5908
5909void Context::uniformMatrix3x4fv(GLint location,
5910 GLsizei count,
5911 GLboolean transpose,
5912 const GLfloat *value)
5913{
5914 Program *program = mGLState.getProgram();
5915 program->setUniformMatrix3x4fv(location, count, transpose, value);
5916}
5917
5918void Context::uniformMatrix4x3fv(GLint location,
5919 GLsizei count,
5920 GLboolean transpose,
5921 const GLfloat *value)
5922{
5923 Program *program = mGLState.getProgram();
5924 program->setUniformMatrix4x3fv(location, count, transpose, value);
5925}
5926
Jamie Madilld7576732017-08-26 18:49:50 -04005927void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5928{
5929 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5930 {
5931 GLuint vertexArray = arrays[arrayIndex];
5932
5933 if (arrays[arrayIndex] != 0)
5934 {
5935 VertexArray *vertexArrayObject = nullptr;
5936 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5937 {
5938 if (vertexArrayObject != nullptr)
5939 {
5940 detachVertexArray(vertexArray);
5941 vertexArrayObject->onDestroy(this);
5942 }
5943
5944 mVertexArrayHandleAllocator.release(vertexArray);
5945 }
5946 }
5947 }
5948}
5949
5950void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5951{
5952 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5953 {
5954 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5955 mVertexArrayMap.assign(vertexArray, nullptr);
5956 arrays[arrayIndex] = vertexArray;
5957 }
5958}
5959
5960bool Context::isVertexArray(GLuint array)
5961{
5962 if (array == 0)
5963 {
5964 return GL_FALSE;
5965 }
5966
5967 VertexArray *vao = getVertexArray(array);
5968 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5969}
5970
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005971void Context::endTransformFeedback()
5972{
5973 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5974 transformFeedback->end(this);
5975}
5976
5977void Context::transformFeedbackVaryings(GLuint program,
5978 GLsizei count,
5979 const GLchar *const *varyings,
5980 GLenum bufferMode)
5981{
5982 Program *programObject = getProgram(program);
5983 ASSERT(programObject);
5984 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5985}
5986
5987void Context::getTransformFeedbackVarying(GLuint program,
5988 GLuint index,
5989 GLsizei bufSize,
5990 GLsizei *length,
5991 GLsizei *size,
5992 GLenum *type,
5993 GLchar *name)
5994{
5995 Program *programObject = getProgram(program);
5996 ASSERT(programObject);
5997 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5998}
5999
6000void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6001{
6002 for (int i = 0; i < n; i++)
6003 {
6004 GLuint transformFeedback = ids[i];
6005 if (transformFeedback == 0)
6006 {
6007 continue;
6008 }
6009
6010 TransformFeedback *transformFeedbackObject = nullptr;
6011 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6012 {
6013 if (transformFeedbackObject != nullptr)
6014 {
6015 detachTransformFeedback(transformFeedback);
6016 transformFeedbackObject->release(this);
6017 }
6018
6019 mTransformFeedbackHandleAllocator.release(transformFeedback);
6020 }
6021 }
6022}
6023
6024void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6025{
6026 for (int i = 0; i < n; i++)
6027 {
6028 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6029 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6030 ids[i] = transformFeedback;
6031 }
6032}
6033
6034bool Context::isTransformFeedback(GLuint id)
6035{
6036 if (id == 0)
6037 {
6038 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6039 // returns FALSE
6040 return GL_FALSE;
6041 }
6042
6043 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6044 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6045}
6046
6047void Context::pauseTransformFeedback()
6048{
6049 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6050 transformFeedback->pause();
6051}
6052
6053void Context::resumeTransformFeedback()
6054{
6055 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6056 transformFeedback->resume();
6057}
6058
Jamie Madill12e957f2017-08-26 21:42:26 -04006059void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6060{
6061 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006062 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006063}
6064
Brandon Jones59770802018-04-02 13:18:42 -07006065void Context::getUniformuivRobust(GLuint program,
6066 GLint location,
6067 GLsizei bufSize,
6068 GLsizei *length,
6069 GLuint *params)
6070{
6071 getUniformuiv(program, location, params);
6072}
6073
Jamie Madill12e957f2017-08-26 21:42:26 -04006074GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6075{
6076 const Program *programObject = getProgram(program);
6077 return programObject->getFragDataLocation(name);
6078}
6079
6080void Context::getUniformIndices(GLuint program,
6081 GLsizei uniformCount,
6082 const GLchar *const *uniformNames,
6083 GLuint *uniformIndices)
6084{
6085 const Program *programObject = getProgram(program);
6086 if (!programObject->isLinked())
6087 {
6088 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6089 {
6090 uniformIndices[uniformId] = GL_INVALID_INDEX;
6091 }
6092 }
6093 else
6094 {
6095 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6096 {
6097 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6098 }
6099 }
6100}
6101
6102void Context::getActiveUniformsiv(GLuint program,
6103 GLsizei uniformCount,
6104 const GLuint *uniformIndices,
6105 GLenum pname,
6106 GLint *params)
6107{
6108 const Program *programObject = getProgram(program);
6109 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6110 {
6111 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006112 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006113 }
6114}
6115
6116GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6117{
6118 const Program *programObject = getProgram(program);
6119 return programObject->getUniformBlockIndex(uniformBlockName);
6120}
6121
6122void Context::getActiveUniformBlockiv(GLuint program,
6123 GLuint uniformBlockIndex,
6124 GLenum pname,
6125 GLint *params)
6126{
6127 const Program *programObject = getProgram(program);
6128 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6129}
6130
Brandon Jones59770802018-04-02 13:18:42 -07006131void Context::getActiveUniformBlockivRobust(GLuint program,
6132 GLuint uniformBlockIndex,
6133 GLenum pname,
6134 GLsizei bufSize,
6135 GLsizei *length,
6136 GLint *params)
6137{
6138 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6139}
6140
Jamie Madill12e957f2017-08-26 21:42:26 -04006141void Context::getActiveUniformBlockName(GLuint program,
6142 GLuint uniformBlockIndex,
6143 GLsizei bufSize,
6144 GLsizei *length,
6145 GLchar *uniformBlockName)
6146{
6147 const Program *programObject = getProgram(program);
6148 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6149}
6150
6151void Context::uniformBlockBinding(GLuint program,
6152 GLuint uniformBlockIndex,
6153 GLuint uniformBlockBinding)
6154{
6155 Program *programObject = getProgram(program);
6156 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6157}
6158
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006159GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6160{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006161 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6162 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006163
Jamie Madill70b5bb02017-08-28 13:32:37 -04006164 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006165 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006166 if (error.isError())
6167 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006168 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006169 handleError(error);
6170 return nullptr;
6171 }
6172
Jamie Madill70b5bb02017-08-28 13:32:37 -04006173 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006174}
6175
6176GLboolean Context::isSync(GLsync sync)
6177{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006178 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006179}
6180
6181GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6182{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006183 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006184
6185 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006186 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006187 return result;
6188}
6189
6190void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6191{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006192 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006193 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006194}
6195
6196void Context::getInteger64v(GLenum pname, GLint64 *params)
6197{
6198 GLenum nativeType = GL_NONE;
6199 unsigned int numParams = 0;
6200 getQueryParameterInfo(pname, &nativeType, &numParams);
6201
6202 if (nativeType == GL_INT_64_ANGLEX)
6203 {
6204 getInteger64vImpl(pname, params);
6205 }
6206 else
6207 {
6208 CastStateValues(this, nativeType, pname, numParams, params);
6209 }
6210}
6211
Brandon Jones59770802018-04-02 13:18:42 -07006212void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6213{
6214 getInteger64v(pname, data);
6215}
6216
Corentin Wallez336129f2017-10-17 15:55:40 -04006217void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006218{
6219 Buffer *buffer = mGLState.getTargetBuffer(target);
6220 QueryBufferParameteri64v(buffer, pname, params);
6221}
6222
Brandon Jones59770802018-04-02 13:18:42 -07006223void Context::getBufferParameteri64vRobust(BufferBinding target,
6224 GLenum pname,
6225 GLsizei bufSize,
6226 GLsizei *length,
6227 GLint64 *params)
6228{
6229 getBufferParameteri64v(target, pname, params);
6230}
6231
Jamie Madill3ef140a2017-08-26 23:11:21 -04006232void Context::genSamplers(GLsizei count, GLuint *samplers)
6233{
6234 for (int i = 0; i < count; i++)
6235 {
6236 samplers[i] = mState.mSamplers->createSampler();
6237 }
6238}
6239
6240void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6241{
6242 for (int i = 0; i < count; i++)
6243 {
6244 GLuint sampler = samplers[i];
6245
6246 if (mState.mSamplers->getSampler(sampler))
6247 {
6248 detachSampler(sampler);
6249 }
6250
6251 mState.mSamplers->deleteObject(this, sampler);
6252 }
6253}
6254
6255void Context::getInternalformativ(GLenum target,
6256 GLenum internalformat,
6257 GLenum pname,
6258 GLsizei bufSize,
6259 GLint *params)
6260{
6261 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6262 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6263}
6264
Brandon Jones59770802018-04-02 13:18:42 -07006265void Context::getInternalformativRobust(GLenum target,
6266 GLenum internalformat,
6267 GLenum pname,
6268 GLsizei bufSize,
6269 GLsizei *length,
6270 GLint *params)
6271{
6272 getInternalformativ(target, internalformat, pname, bufSize, params);
6273}
6274
Jiajia Qin5451d532017-11-16 17:16:34 +08006275void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6276{
6277 programUniform1iv(program, location, 1, &v0);
6278}
6279
6280void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6281{
6282 GLint xy[2] = {v0, v1};
6283 programUniform2iv(program, location, 1, xy);
6284}
6285
6286void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6287{
6288 GLint xyz[3] = {v0, v1, v2};
6289 programUniform3iv(program, location, 1, xyz);
6290}
6291
6292void Context::programUniform4i(GLuint program,
6293 GLint location,
6294 GLint v0,
6295 GLint v1,
6296 GLint v2,
6297 GLint v3)
6298{
6299 GLint xyzw[4] = {v0, v1, v2, v3};
6300 programUniform4iv(program, location, 1, xyzw);
6301}
6302
6303void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6304{
6305 programUniform1uiv(program, location, 1, &v0);
6306}
6307
6308void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6309{
6310 GLuint xy[2] = {v0, v1};
6311 programUniform2uiv(program, location, 1, xy);
6312}
6313
6314void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6315{
6316 GLuint xyz[3] = {v0, v1, v2};
6317 programUniform3uiv(program, location, 1, xyz);
6318}
6319
6320void Context::programUniform4ui(GLuint program,
6321 GLint location,
6322 GLuint v0,
6323 GLuint v1,
6324 GLuint v2,
6325 GLuint v3)
6326{
6327 GLuint xyzw[4] = {v0, v1, v2, v3};
6328 programUniform4uiv(program, location, 1, xyzw);
6329}
6330
6331void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6332{
6333 programUniform1fv(program, location, 1, &v0);
6334}
6335
6336void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6337{
6338 GLfloat xy[2] = {v0, v1};
6339 programUniform2fv(program, location, 1, xy);
6340}
6341
6342void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6343{
6344 GLfloat xyz[3] = {v0, v1, v2};
6345 programUniform3fv(program, location, 1, xyz);
6346}
6347
6348void Context::programUniform4f(GLuint program,
6349 GLint location,
6350 GLfloat v0,
6351 GLfloat v1,
6352 GLfloat v2,
6353 GLfloat v3)
6354{
6355 GLfloat xyzw[4] = {v0, v1, v2, v3};
6356 programUniform4fv(program, location, 1, xyzw);
6357}
6358
Jamie Madill81c2e252017-09-09 23:32:46 -04006359void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6360{
6361 Program *programObject = getProgram(program);
6362 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006363 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006364}
6365
Jiajia Qin5451d532017-11-16 17:16:34 +08006366void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6367{
6368 Program *programObject = getProgram(program);
6369 ASSERT(programObject);
6370 programObject->setUniform2iv(location, count, value);
6371}
6372
6373void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6374{
6375 Program *programObject = getProgram(program);
6376 ASSERT(programObject);
6377 programObject->setUniform3iv(location, count, value);
6378}
6379
6380void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6381{
6382 Program *programObject = getProgram(program);
6383 ASSERT(programObject);
6384 programObject->setUniform4iv(location, count, value);
6385}
6386
6387void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6388{
6389 Program *programObject = getProgram(program);
6390 ASSERT(programObject);
6391 programObject->setUniform1uiv(location, count, value);
6392}
6393
6394void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6395{
6396 Program *programObject = getProgram(program);
6397 ASSERT(programObject);
6398 programObject->setUniform2uiv(location, count, value);
6399}
6400
6401void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6402{
6403 Program *programObject = getProgram(program);
6404 ASSERT(programObject);
6405 programObject->setUniform3uiv(location, count, value);
6406}
6407
6408void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6409{
6410 Program *programObject = getProgram(program);
6411 ASSERT(programObject);
6412 programObject->setUniform4uiv(location, count, value);
6413}
6414
6415void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6416{
6417 Program *programObject = getProgram(program);
6418 ASSERT(programObject);
6419 programObject->setUniform1fv(location, count, value);
6420}
6421
6422void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6423{
6424 Program *programObject = getProgram(program);
6425 ASSERT(programObject);
6426 programObject->setUniform2fv(location, count, value);
6427}
6428
6429void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6430{
6431 Program *programObject = getProgram(program);
6432 ASSERT(programObject);
6433 programObject->setUniform3fv(location, count, value);
6434}
6435
6436void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6437{
6438 Program *programObject = getProgram(program);
6439 ASSERT(programObject);
6440 programObject->setUniform4fv(location, count, value);
6441}
6442
6443void Context::programUniformMatrix2fv(GLuint program,
6444 GLint location,
6445 GLsizei count,
6446 GLboolean transpose,
6447 const GLfloat *value)
6448{
6449 Program *programObject = getProgram(program);
6450 ASSERT(programObject);
6451 programObject->setUniformMatrix2fv(location, count, transpose, value);
6452}
6453
6454void Context::programUniformMatrix3fv(GLuint program,
6455 GLint location,
6456 GLsizei count,
6457 GLboolean transpose,
6458 const GLfloat *value)
6459{
6460 Program *programObject = getProgram(program);
6461 ASSERT(programObject);
6462 programObject->setUniformMatrix3fv(location, count, transpose, value);
6463}
6464
6465void Context::programUniformMatrix4fv(GLuint program,
6466 GLint location,
6467 GLsizei count,
6468 GLboolean transpose,
6469 const GLfloat *value)
6470{
6471 Program *programObject = getProgram(program);
6472 ASSERT(programObject);
6473 programObject->setUniformMatrix4fv(location, count, transpose, value);
6474}
6475
6476void Context::programUniformMatrix2x3fv(GLuint program,
6477 GLint location,
6478 GLsizei count,
6479 GLboolean transpose,
6480 const GLfloat *value)
6481{
6482 Program *programObject = getProgram(program);
6483 ASSERT(programObject);
6484 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6485}
6486
6487void Context::programUniformMatrix3x2fv(GLuint program,
6488 GLint location,
6489 GLsizei count,
6490 GLboolean transpose,
6491 const GLfloat *value)
6492{
6493 Program *programObject = getProgram(program);
6494 ASSERT(programObject);
6495 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6496}
6497
6498void Context::programUniformMatrix2x4fv(GLuint program,
6499 GLint location,
6500 GLsizei count,
6501 GLboolean transpose,
6502 const GLfloat *value)
6503{
6504 Program *programObject = getProgram(program);
6505 ASSERT(programObject);
6506 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6507}
6508
6509void Context::programUniformMatrix4x2fv(GLuint program,
6510 GLint location,
6511 GLsizei count,
6512 GLboolean transpose,
6513 const GLfloat *value)
6514{
6515 Program *programObject = getProgram(program);
6516 ASSERT(programObject);
6517 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6518}
6519
6520void Context::programUniformMatrix3x4fv(GLuint program,
6521 GLint location,
6522 GLsizei count,
6523 GLboolean transpose,
6524 const GLfloat *value)
6525{
6526 Program *programObject = getProgram(program);
6527 ASSERT(programObject);
6528 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6529}
6530
6531void Context::programUniformMatrix4x3fv(GLuint program,
6532 GLint location,
6533 GLsizei count,
6534 GLboolean transpose,
6535 const GLfloat *value)
6536{
6537 Program *programObject = getProgram(program);
6538 ASSERT(programObject);
6539 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6540}
6541
Jamie Madill81c2e252017-09-09 23:32:46 -04006542void Context::onTextureChange(const Texture *texture)
6543{
6544 // Conservatively assume all textures are dirty.
6545 // TODO(jmadill): More fine-grained update.
6546 mGLState.setObjectDirty(GL_TEXTURE);
6547}
6548
James Darpiniane8a93c62018-01-04 18:02:24 -08006549bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6550{
6551 return mGLState.isCurrentTransformFeedback(tf);
6552}
6553bool Context::isCurrentVertexArray(const VertexArray *va) const
6554{
6555 return mGLState.isCurrentVertexArray(va);
6556}
6557
Yunchao Hea336b902017-08-02 16:05:21 +08006558void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6559{
6560 for (int i = 0; i < count; i++)
6561 {
6562 pipelines[i] = createProgramPipeline();
6563 }
6564}
6565
6566void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6567{
6568 for (int i = 0; i < count; i++)
6569 {
6570 if (pipelines[i] != 0)
6571 {
6572 deleteProgramPipeline(pipelines[i]);
6573 }
6574 }
6575}
6576
6577GLboolean Context::isProgramPipeline(GLuint pipeline)
6578{
6579 if (pipeline == 0)
6580 {
6581 return GL_FALSE;
6582 }
6583
6584 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6585}
6586
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006587void Context::finishFenceNV(GLuint fence)
6588{
6589 FenceNV *fenceObject = getFenceNV(fence);
6590
6591 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006592 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006593}
6594
6595void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6596{
6597 FenceNV *fenceObject = getFenceNV(fence);
6598
6599 ASSERT(fenceObject && fenceObject->isSet());
6600
6601 switch (pname)
6602 {
6603 case GL_FENCE_STATUS_NV:
6604 {
6605 // GL_NV_fence spec:
6606 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6607 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6608 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6609 GLboolean status = GL_TRUE;
6610 if (fenceObject->getStatus() != GL_TRUE)
6611 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006612 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006613 }
6614 *params = status;
6615 break;
6616 }
6617
6618 case GL_FENCE_CONDITION_NV:
6619 {
6620 *params = static_cast<GLint>(fenceObject->getCondition());
6621 break;
6622 }
6623
6624 default:
6625 UNREACHABLE();
6626 }
6627}
6628
6629void Context::getTranslatedShaderSource(GLuint shader,
6630 GLsizei bufsize,
6631 GLsizei *length,
6632 GLchar *source)
6633{
6634 Shader *shaderObject = getShader(shader);
6635 ASSERT(shaderObject);
6636 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6637}
6638
6639void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6640{
6641 Program *programObject = getProgram(program);
6642 ASSERT(programObject);
6643
6644 programObject->getUniformfv(this, location, params);
6645}
6646
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006647void Context::getnUniformfvRobust(GLuint program,
6648 GLint location,
6649 GLsizei bufSize,
6650 GLsizei *length,
6651 GLfloat *params)
6652{
6653 UNIMPLEMENTED();
6654}
6655
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006656void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6657{
6658 Program *programObject = getProgram(program);
6659 ASSERT(programObject);
6660
6661 programObject->getUniformiv(this, location, params);
6662}
6663
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006664void Context::getnUniformivRobust(GLuint program,
6665 GLint location,
6666 GLsizei bufSize,
6667 GLsizei *length,
6668 GLint *params)
6669{
6670 UNIMPLEMENTED();
6671}
6672
6673void Context::getnUniformuivRobust(GLuint program,
6674 GLint location,
6675 GLsizei bufSize,
6676 GLsizei *length,
6677 GLuint *params)
6678{
6679 UNIMPLEMENTED();
6680}
6681
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006682GLboolean Context::isFenceNV(GLuint fence)
6683{
6684 FenceNV *fenceObject = getFenceNV(fence);
6685
6686 if (fenceObject == nullptr)
6687 {
6688 return GL_FALSE;
6689 }
6690
6691 // GL_NV_fence spec:
6692 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6693 // existing fence.
6694 return fenceObject->isSet();
6695}
6696
6697void Context::readnPixels(GLint x,
6698 GLint y,
6699 GLsizei width,
6700 GLsizei height,
6701 GLenum format,
6702 GLenum type,
6703 GLsizei bufSize,
6704 void *data)
6705{
6706 return readPixels(x, y, width, height, format, type, data);
6707}
6708
Jamie Madill007530e2017-12-28 14:27:04 -05006709void Context::setFenceNV(GLuint fence, GLenum condition)
6710{
6711 ASSERT(condition == GL_ALL_COMPLETED_NV);
6712
6713 FenceNV *fenceObject = getFenceNV(fence);
6714 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006715 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006716}
6717
6718GLboolean Context::testFenceNV(GLuint fence)
6719{
6720 FenceNV *fenceObject = getFenceNV(fence);
6721
6722 ASSERT(fenceObject != nullptr);
6723 ASSERT(fenceObject->isSet() == GL_TRUE);
6724
6725 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006726 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006727 if (error.isError())
6728 {
6729 handleError(error);
6730 return GL_TRUE;
6731 }
6732
6733 return result;
6734}
6735
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006736void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006737{
6738 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006739 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006740 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006741}
6742
Jamie Madillfa920eb2018-01-04 11:45:50 -05006743void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006744{
6745 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006746 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006747 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6748}
6749
Jamie Madillfa920eb2018-01-04 11:45:50 -05006750void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6751{
6752 UNIMPLEMENTED();
6753}
6754
Jamie Madill5b772312018-03-08 20:28:32 -05006755bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6756{
6757 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6758 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6759 // to the fact that it is stored internally as a float, and so would require conversion
6760 // if returned from Context::getIntegerv. Since this conversion is already implemented
6761 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6762 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6763 // application.
6764 switch (pname)
6765 {
6766 case GL_COMPRESSED_TEXTURE_FORMATS:
6767 {
6768 *type = GL_INT;
6769 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6770 return true;
6771 }
6772 case GL_SHADER_BINARY_FORMATS:
6773 {
6774 *type = GL_INT;
6775 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6776 return true;
6777 }
6778
6779 case GL_MAX_VERTEX_ATTRIBS:
6780 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6781 case GL_MAX_VARYING_VECTORS:
6782 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6783 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6784 case GL_MAX_TEXTURE_IMAGE_UNITS:
6785 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6786 case GL_MAX_RENDERBUFFER_SIZE:
6787 case GL_NUM_SHADER_BINARY_FORMATS:
6788 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6789 case GL_ARRAY_BUFFER_BINDING:
6790 case GL_FRAMEBUFFER_BINDING:
6791 case GL_RENDERBUFFER_BINDING:
6792 case GL_CURRENT_PROGRAM:
6793 case GL_PACK_ALIGNMENT:
6794 case GL_UNPACK_ALIGNMENT:
6795 case GL_GENERATE_MIPMAP_HINT:
6796 case GL_RED_BITS:
6797 case GL_GREEN_BITS:
6798 case GL_BLUE_BITS:
6799 case GL_ALPHA_BITS:
6800 case GL_DEPTH_BITS:
6801 case GL_STENCIL_BITS:
6802 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6803 case GL_CULL_FACE_MODE:
6804 case GL_FRONT_FACE:
6805 case GL_ACTIVE_TEXTURE:
6806 case GL_STENCIL_FUNC:
6807 case GL_STENCIL_VALUE_MASK:
6808 case GL_STENCIL_REF:
6809 case GL_STENCIL_FAIL:
6810 case GL_STENCIL_PASS_DEPTH_FAIL:
6811 case GL_STENCIL_PASS_DEPTH_PASS:
6812 case GL_STENCIL_BACK_FUNC:
6813 case GL_STENCIL_BACK_VALUE_MASK:
6814 case GL_STENCIL_BACK_REF:
6815 case GL_STENCIL_BACK_FAIL:
6816 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6817 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6818 case GL_DEPTH_FUNC:
6819 case GL_BLEND_SRC_RGB:
6820 case GL_BLEND_SRC_ALPHA:
6821 case GL_BLEND_DST_RGB:
6822 case GL_BLEND_DST_ALPHA:
6823 case GL_BLEND_EQUATION_RGB:
6824 case GL_BLEND_EQUATION_ALPHA:
6825 case GL_STENCIL_WRITEMASK:
6826 case GL_STENCIL_BACK_WRITEMASK:
6827 case GL_STENCIL_CLEAR_VALUE:
6828 case GL_SUBPIXEL_BITS:
6829 case GL_MAX_TEXTURE_SIZE:
6830 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6831 case GL_SAMPLE_BUFFERS:
6832 case GL_SAMPLES:
6833 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6834 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6835 case GL_TEXTURE_BINDING_2D:
6836 case GL_TEXTURE_BINDING_CUBE_MAP:
6837 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6838 {
6839 *type = GL_INT;
6840 *numParams = 1;
6841 return true;
6842 }
6843 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6844 {
6845 if (!getExtensions().packReverseRowOrder)
6846 {
6847 return false;
6848 }
6849 *type = GL_INT;
6850 *numParams = 1;
6851 return true;
6852 }
6853 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6854 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6855 {
6856 if (!getExtensions().textureRectangle)
6857 {
6858 return false;
6859 }
6860 *type = GL_INT;
6861 *numParams = 1;
6862 return true;
6863 }
6864 case GL_MAX_DRAW_BUFFERS_EXT:
6865 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6866 {
6867 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6868 {
6869 return false;
6870 }
6871 *type = GL_INT;
6872 *numParams = 1;
6873 return true;
6874 }
6875 case GL_MAX_VIEWPORT_DIMS:
6876 {
6877 *type = GL_INT;
6878 *numParams = 2;
6879 return true;
6880 }
6881 case GL_VIEWPORT:
6882 case GL_SCISSOR_BOX:
6883 {
6884 *type = GL_INT;
6885 *numParams = 4;
6886 return true;
6887 }
6888 case GL_SHADER_COMPILER:
6889 case GL_SAMPLE_COVERAGE_INVERT:
6890 case GL_DEPTH_WRITEMASK:
6891 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6892 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6893 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6894 // bool-natural
6895 case GL_SAMPLE_COVERAGE:
6896 case GL_SCISSOR_TEST:
6897 case GL_STENCIL_TEST:
6898 case GL_DEPTH_TEST:
6899 case GL_BLEND:
6900 case GL_DITHER:
6901 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6902 {
6903 *type = GL_BOOL;
6904 *numParams = 1;
6905 return true;
6906 }
6907 case GL_COLOR_WRITEMASK:
6908 {
6909 *type = GL_BOOL;
6910 *numParams = 4;
6911 return true;
6912 }
6913 case GL_POLYGON_OFFSET_FACTOR:
6914 case GL_POLYGON_OFFSET_UNITS:
6915 case GL_SAMPLE_COVERAGE_VALUE:
6916 case GL_DEPTH_CLEAR_VALUE:
6917 case GL_LINE_WIDTH:
6918 {
6919 *type = GL_FLOAT;
6920 *numParams = 1;
6921 return true;
6922 }
6923 case GL_ALIASED_LINE_WIDTH_RANGE:
6924 case GL_ALIASED_POINT_SIZE_RANGE:
6925 case GL_DEPTH_RANGE:
6926 {
6927 *type = GL_FLOAT;
6928 *numParams = 2;
6929 return true;
6930 }
6931 case GL_COLOR_CLEAR_VALUE:
6932 case GL_BLEND_COLOR:
6933 {
6934 *type = GL_FLOAT;
6935 *numParams = 4;
6936 return true;
6937 }
6938 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6939 if (!getExtensions().textureFilterAnisotropic)
6940 {
6941 return false;
6942 }
6943 *type = GL_FLOAT;
6944 *numParams = 1;
6945 return true;
6946 case GL_TIMESTAMP_EXT:
6947 if (!getExtensions().disjointTimerQuery)
6948 {
6949 return false;
6950 }
6951 *type = GL_INT_64_ANGLEX;
6952 *numParams = 1;
6953 return true;
6954 case GL_GPU_DISJOINT_EXT:
6955 if (!getExtensions().disjointTimerQuery)
6956 {
6957 return false;
6958 }
6959 *type = GL_INT;
6960 *numParams = 1;
6961 return true;
6962 case GL_COVERAGE_MODULATION_CHROMIUM:
6963 if (!getExtensions().framebufferMixedSamples)
6964 {
6965 return false;
6966 }
6967 *type = GL_INT;
6968 *numParams = 1;
6969 return true;
6970 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6971 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6972 {
6973 return false;
6974 }
6975 *type = GL_INT;
6976 *numParams = 1;
6977 return true;
6978 }
6979
6980 if (getExtensions().debug)
6981 {
6982 switch (pname)
6983 {
6984 case GL_DEBUG_LOGGED_MESSAGES:
6985 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6986 case GL_DEBUG_GROUP_STACK_DEPTH:
6987 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6988 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6989 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6990 case GL_MAX_LABEL_LENGTH:
6991 *type = GL_INT;
6992 *numParams = 1;
6993 return true;
6994
6995 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6996 case GL_DEBUG_OUTPUT:
6997 *type = GL_BOOL;
6998 *numParams = 1;
6999 return true;
7000 }
7001 }
7002
7003 if (getExtensions().multisampleCompatibility)
7004 {
7005 switch (pname)
7006 {
7007 case GL_MULTISAMPLE_EXT:
7008 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7009 *type = GL_BOOL;
7010 *numParams = 1;
7011 return true;
7012 }
7013 }
7014
7015 if (getExtensions().pathRendering)
7016 {
7017 switch (pname)
7018 {
7019 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7020 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7021 *type = GL_FLOAT;
7022 *numParams = 16;
7023 return true;
7024 }
7025 }
7026
7027 if (getExtensions().bindGeneratesResource)
7028 {
7029 switch (pname)
7030 {
7031 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7032 *type = GL_BOOL;
7033 *numParams = 1;
7034 return true;
7035 }
7036 }
7037
7038 if (getExtensions().clientArrays)
7039 {
7040 switch (pname)
7041 {
7042 case GL_CLIENT_ARRAYS_ANGLE:
7043 *type = GL_BOOL;
7044 *numParams = 1;
7045 return true;
7046 }
7047 }
7048
7049 if (getExtensions().sRGBWriteControl)
7050 {
7051 switch (pname)
7052 {
7053 case GL_FRAMEBUFFER_SRGB_EXT:
7054 *type = GL_BOOL;
7055 *numParams = 1;
7056 return true;
7057 }
7058 }
7059
7060 if (getExtensions().robustResourceInitialization &&
7061 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7062 {
7063 *type = GL_BOOL;
7064 *numParams = 1;
7065 return true;
7066 }
7067
7068 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7069 {
7070 *type = GL_BOOL;
7071 *numParams = 1;
7072 return true;
7073 }
7074
jchen1082af6202018-06-22 10:59:52 +08007075 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7076 {
7077 *type = GL_INT;
7078 *numParams = 1;
7079 return true;
7080 }
7081
Jamie Madill5b772312018-03-08 20:28:32 -05007082 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7083 switch (pname)
7084 {
7085 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7086 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7087 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7088 {
7089 return false;
7090 }
7091 *type = GL_INT;
7092 *numParams = 1;
7093 return true;
7094
7095 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7096 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7097 {
7098 return false;
7099 }
7100 *type = GL_INT;
7101 *numParams = 1;
7102 return true;
7103
7104 case GL_PROGRAM_BINARY_FORMATS_OES:
7105 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7106 {
7107 return false;
7108 }
7109 *type = GL_INT;
7110 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7111 return true;
7112
7113 case GL_PACK_ROW_LENGTH:
7114 case GL_PACK_SKIP_ROWS:
7115 case GL_PACK_SKIP_PIXELS:
7116 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7117 {
7118 return false;
7119 }
7120 *type = GL_INT;
7121 *numParams = 1;
7122 return true;
7123 case GL_UNPACK_ROW_LENGTH:
7124 case GL_UNPACK_SKIP_ROWS:
7125 case GL_UNPACK_SKIP_PIXELS:
7126 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7127 {
7128 return false;
7129 }
7130 *type = GL_INT;
7131 *numParams = 1;
7132 return true;
7133 case GL_VERTEX_ARRAY_BINDING:
7134 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7135 {
7136 return false;
7137 }
7138 *type = GL_INT;
7139 *numParams = 1;
7140 return true;
7141 case GL_PIXEL_PACK_BUFFER_BINDING:
7142 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7143 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7144 {
7145 return false;
7146 }
7147 *type = GL_INT;
7148 *numParams = 1;
7149 return true;
7150 case GL_MAX_SAMPLES:
7151 {
7152 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7153 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7154 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7155 {
7156 return false;
7157 }
7158 *type = GL_INT;
7159 *numParams = 1;
7160 return true;
7161
7162 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7163 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7164 {
7165 return false;
7166 }
7167 *type = GL_INT;
7168 *numParams = 1;
7169 return true;
7170 }
7171 }
7172
7173 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7174 {
7175 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7176 {
7177 return false;
7178 }
7179 *type = GL_INT;
7180 *numParams = 1;
7181 return true;
7182 }
7183
7184 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7185 {
7186 *type = GL_INT;
7187 *numParams = 1;
7188 return true;
7189 }
7190
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007191 if (getClientVersion() < Version(2, 0))
7192 {
7193 switch (pname)
7194 {
7195 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007196 case GL_CLIENT_ACTIVE_TEXTURE:
7197 case GL_MATRIX_MODE:
7198 case GL_MAX_TEXTURE_UNITS:
7199 case GL_MAX_MODELVIEW_STACK_DEPTH:
7200 case GL_MAX_PROJECTION_STACK_DEPTH:
7201 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007202 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007203 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007204 case GL_VERTEX_ARRAY_STRIDE:
7205 case GL_NORMAL_ARRAY_STRIDE:
7206 case GL_COLOR_ARRAY_STRIDE:
7207 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7208 case GL_VERTEX_ARRAY_SIZE:
7209 case GL_COLOR_ARRAY_SIZE:
7210 case GL_TEXTURE_COORD_ARRAY_SIZE:
7211 case GL_VERTEX_ARRAY_TYPE:
7212 case GL_NORMAL_ARRAY_TYPE:
7213 case GL_COLOR_ARRAY_TYPE:
7214 case GL_TEXTURE_COORD_ARRAY_TYPE:
7215 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7216 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7217 case GL_COLOR_ARRAY_BUFFER_BINDING:
7218 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7219 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7220 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7221 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007222 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007223 *type = GL_INT;
7224 *numParams = 1;
7225 return true;
7226 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007227 case GL_FOG_DENSITY:
7228 case GL_FOG_START:
7229 case GL_FOG_END:
7230 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007231 case GL_POINT_SIZE:
7232 case GL_POINT_SIZE_MIN:
7233 case GL_POINT_SIZE_MAX:
7234 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007235 *type = GL_FLOAT;
7236 *numParams = 1;
7237 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007238 case GL_SMOOTH_POINT_SIZE_RANGE:
7239 *type = GL_FLOAT;
7240 *numParams = 2;
7241 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007242 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007243 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007244 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007245 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007246 *type = GL_FLOAT;
7247 *numParams = 4;
7248 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007249 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007250 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007251 *type = GL_FLOAT;
7252 *numParams = 3;
7253 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007254 case GL_MODELVIEW_MATRIX:
7255 case GL_PROJECTION_MATRIX:
7256 case GL_TEXTURE_MATRIX:
7257 *type = GL_FLOAT;
7258 *numParams = 16;
7259 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007260 case GL_LIGHT_MODEL_TWO_SIDE:
7261 *type = GL_BOOL;
7262 *numParams = 1;
7263 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007264 }
7265 }
7266
Jamie Madill5b772312018-03-08 20:28:32 -05007267 if (getClientVersion() < Version(3, 0))
7268 {
7269 return false;
7270 }
7271
7272 // Check for ES3.0+ parameter names
7273 switch (pname)
7274 {
7275 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7276 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7277 case GL_UNIFORM_BUFFER_BINDING:
7278 case GL_TRANSFORM_FEEDBACK_BINDING:
7279 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7280 case GL_COPY_READ_BUFFER_BINDING:
7281 case GL_COPY_WRITE_BUFFER_BINDING:
7282 case GL_SAMPLER_BINDING:
7283 case GL_READ_BUFFER:
7284 case GL_TEXTURE_BINDING_3D:
7285 case GL_TEXTURE_BINDING_2D_ARRAY:
7286 case GL_MAX_3D_TEXTURE_SIZE:
7287 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7288 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7289 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7290 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7291 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7292 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7293 case GL_MAX_VARYING_COMPONENTS:
7294 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7295 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7296 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7297 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7298 case GL_NUM_EXTENSIONS:
7299 case GL_MAJOR_VERSION:
7300 case GL_MINOR_VERSION:
7301 case GL_MAX_ELEMENTS_INDICES:
7302 case GL_MAX_ELEMENTS_VERTICES:
7303 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7304 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7305 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7306 case GL_UNPACK_IMAGE_HEIGHT:
7307 case GL_UNPACK_SKIP_IMAGES:
7308 {
7309 *type = GL_INT;
7310 *numParams = 1;
7311 return true;
7312 }
7313
7314 case GL_MAX_ELEMENT_INDEX:
7315 case GL_MAX_UNIFORM_BLOCK_SIZE:
7316 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7317 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7318 case GL_MAX_SERVER_WAIT_TIMEOUT:
7319 {
7320 *type = GL_INT_64_ANGLEX;
7321 *numParams = 1;
7322 return true;
7323 }
7324
7325 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7326 case GL_TRANSFORM_FEEDBACK_PAUSED:
7327 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7328 case GL_RASTERIZER_DISCARD:
7329 {
7330 *type = GL_BOOL;
7331 *numParams = 1;
7332 return true;
7333 }
7334
7335 case GL_MAX_TEXTURE_LOD_BIAS:
7336 {
7337 *type = GL_FLOAT;
7338 *numParams = 1;
7339 return true;
7340 }
7341 }
7342
7343 if (getExtensions().requestExtension)
7344 {
7345 switch (pname)
7346 {
7347 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7348 *type = GL_INT;
7349 *numParams = 1;
7350 return true;
7351 }
7352 }
7353
7354 if (getClientVersion() < Version(3, 1))
7355 {
7356 return false;
7357 }
7358
7359 switch (pname)
7360 {
7361 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7362 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7363 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7364 case GL_MAX_FRAMEBUFFER_WIDTH:
7365 case GL_MAX_FRAMEBUFFER_HEIGHT:
7366 case GL_MAX_FRAMEBUFFER_SAMPLES:
7367 case GL_MAX_SAMPLE_MASK_WORDS:
7368 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7369 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7370 case GL_MAX_INTEGER_SAMPLES:
7371 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7372 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7373 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7374 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7375 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7376 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7377 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7378 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7379 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7380 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7381 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7382 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7383 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7384 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7385 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7386 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7387 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7388 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7389 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7390 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7391 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7392 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7393 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7394 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7395 case GL_MAX_UNIFORM_LOCATIONS:
7396 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7397 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7398 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7399 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7400 case GL_MAX_IMAGE_UNITS:
7401 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7402 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7403 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7404 case GL_SHADER_STORAGE_BUFFER_BINDING:
7405 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7406 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7407 *type = GL_INT;
7408 *numParams = 1;
7409 return true;
7410 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7411 *type = GL_INT_64_ANGLEX;
7412 *numParams = 1;
7413 return true;
7414 case GL_SAMPLE_MASK:
7415 *type = GL_BOOL;
7416 *numParams = 1;
7417 return true;
7418 }
7419
7420 if (getExtensions().geometryShader)
7421 {
7422 switch (pname)
7423 {
7424 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7425 case GL_LAYER_PROVOKING_VERTEX_EXT:
7426 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7427 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7428 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7429 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7430 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7431 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7432 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7433 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7434 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7435 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7436 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7437 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7438 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7439 *type = GL_INT;
7440 *numParams = 1;
7441 return true;
7442 }
7443 }
7444
7445 return false;
7446}
7447
7448bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7449{
7450 if (getClientVersion() < Version(3, 0))
7451 {
7452 return false;
7453 }
7454
7455 switch (target)
7456 {
7457 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7458 case GL_UNIFORM_BUFFER_BINDING:
7459 {
7460 *type = GL_INT;
7461 *numParams = 1;
7462 return true;
7463 }
7464 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7465 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7466 case GL_UNIFORM_BUFFER_START:
7467 case GL_UNIFORM_BUFFER_SIZE:
7468 {
7469 *type = GL_INT_64_ANGLEX;
7470 *numParams = 1;
7471 return true;
7472 }
7473 }
7474
7475 if (getClientVersion() < Version(3, 1))
7476 {
7477 return false;
7478 }
7479
7480 switch (target)
7481 {
7482 case GL_IMAGE_BINDING_LAYERED:
7483 {
7484 *type = GL_BOOL;
7485 *numParams = 1;
7486 return true;
7487 }
7488 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7489 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7490 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7491 case GL_SHADER_STORAGE_BUFFER_BINDING:
7492 case GL_VERTEX_BINDING_BUFFER:
7493 case GL_VERTEX_BINDING_DIVISOR:
7494 case GL_VERTEX_BINDING_OFFSET:
7495 case GL_VERTEX_BINDING_STRIDE:
7496 case GL_SAMPLE_MASK_VALUE:
7497 case GL_IMAGE_BINDING_NAME:
7498 case GL_IMAGE_BINDING_LEVEL:
7499 case GL_IMAGE_BINDING_LAYER:
7500 case GL_IMAGE_BINDING_ACCESS:
7501 case GL_IMAGE_BINDING_FORMAT:
7502 {
7503 *type = GL_INT;
7504 *numParams = 1;
7505 return true;
7506 }
7507 case GL_ATOMIC_COUNTER_BUFFER_START:
7508 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7509 case GL_SHADER_STORAGE_BUFFER_START:
7510 case GL_SHADER_STORAGE_BUFFER_SIZE:
7511 {
7512 *type = GL_INT_64_ANGLEX;
7513 *numParams = 1;
7514 return true;
7515 }
7516 }
7517
7518 return false;
7519}
7520
7521Program *Context::getProgram(GLuint handle) const
7522{
7523 return mState.mShaderPrograms->getProgram(handle);
7524}
7525
7526Shader *Context::getShader(GLuint handle) const
7527{
7528 return mState.mShaderPrograms->getShader(handle);
7529}
7530
7531bool Context::isTextureGenerated(GLuint texture) const
7532{
7533 return mState.mTextures->isHandleGenerated(texture);
7534}
7535
7536bool Context::isBufferGenerated(GLuint buffer) const
7537{
7538 return mState.mBuffers->isHandleGenerated(buffer);
7539}
7540
7541bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7542{
7543 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7544}
7545
7546bool Context::isFramebufferGenerated(GLuint framebuffer) const
7547{
7548 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7549}
7550
7551bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7552{
7553 return mState.mPipelines->isHandleGenerated(pipeline);
7554}
7555
7556bool Context::usingDisplayTextureShareGroup() const
7557{
7558 return mDisplayTextureShareGroup;
7559}
7560
7561GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7562{
7563 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7564 internalformat == GL_DEPTH_STENCIL
7565 ? GL_DEPTH24_STENCIL8
7566 : internalformat;
7567}
7568
jchen1082af6202018-06-22 10:59:52 +08007569void Context::maxShaderCompilerThreads(GLuint count)
7570{
jchen107ae70d82018-07-06 13:47:01 +08007571 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08007572 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007573 // A count of zero specifies a request for no parallel compiling or linking.
7574 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7575 {
7576 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7577 }
7578 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007579}
7580
Jamie Madill2eb65032018-07-30 10:25:57 -04007581bool Context::isGLES1() const
7582{
7583 return mState.getClientVersion() < Version(2, 0);
7584}
7585
Jamie Madilla11819d2018-07-30 10:26:01 -04007586void Context::onSubjectStateChange(const Context *context,
7587 angle::SubjectIndex index,
7588 angle::SubjectMessage message)
7589{
Jamie Madilla11819d2018-07-30 10:26:01 -04007590 switch (index)
7591 {
7592 case kVertexArraySubjectIndex:
7593 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
Jamie Madillc43cdad2018-08-08 15:49:25 -04007594 mStateCache.onVertexArraySizeChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04007595 break;
7596
7597 case kReadFramebufferSubjectIndex:
7598 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
7599 break;
7600
7601 case kDrawFramebufferSubjectIndex:
7602 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
7603 break;
7604
7605 default:
Jamie Madill6c43a012018-08-08 15:49:27 -04007606 ASSERT(index < mGLState.getActiveTexturesCache().size());
7607 mGLState.onActiveTextureStateChange(index);
Jamie Madilla11819d2018-07-30 10:26:01 -04007608 break;
7609 }
7610}
7611
Jamie Madill6b873dd2018-07-12 23:56:30 -04007612// ErrorSet implementation.
7613ErrorSet::ErrorSet(Context *context) : mContext(context)
7614{
7615}
7616
7617ErrorSet::~ErrorSet() = default;
7618
Jamie Madill306b6c12018-07-27 08:12:49 -04007619void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007620{
7621 // This internal enum is used to filter internal errors that are already handled.
7622 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7623 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7624 {
7625 return;
7626 }
7627
7628 if (ANGLE_UNLIKELY(error.isError()))
7629 {
7630 GLenum code = error.getCode();
7631 mErrors.insert(code);
7632 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7633 {
7634 mContext->markContextLost();
7635 }
7636
7637 ASSERT(!error.getMessage().empty());
7638 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7639 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7640 error.getMessage());
7641 }
7642}
7643
7644bool ErrorSet::empty() const
7645{
7646 return mErrors.empty();
7647}
7648
7649GLenum ErrorSet::popError()
7650{
7651 ASSERT(!empty());
7652 GLenum error = *mErrors.begin();
7653 mErrors.erase(mErrors.begin());
7654 return error;
7655}
Jamie Madilldc358af2018-07-31 11:22:13 -04007656
7657// StateCache implementation.
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007658StateCache::StateCache()
7659 : mCachedHasAnyEnabledClientAttrib(false),
7660 mCachedNonInstancedVertexElementLimit(0),
7661 mCachedInstancedVertexElementLimit(0)
Jamie Madilldc358af2018-07-31 11:22:13 -04007662{
7663}
7664
7665StateCache::~StateCache() = default;
7666
7667void StateCache::updateActiveAttribsMask(Context *context)
7668{
7669 bool isGLES1 = context->isGLES1();
7670 const State &glState = context->getGLState();
7671
7672 if (!isGLES1 && !glState.getProgram())
7673 {
7674 mCachedActiveBufferedAttribsMask = AttributesMask();
7675 mCachedActiveClientAttribsMask = AttributesMask();
7676 return;
7677 }
7678
7679 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7680 : glState.getProgram()->getActiveAttribLocationsMask();
7681
7682 const VertexArray *vao = glState.getVertexArray();
7683 ASSERT(vao);
7684
7685 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7686 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
7687
7688 activeAttribs &= enabledAttribs;
7689
7690 mCachedActiveClientAttribsMask = activeAttribs & clientAttribs;
7691 mCachedActiveBufferedAttribsMask = activeAttribs & ~clientAttribs;
7692 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7693}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007694
7695void StateCache::updateVertexElementLimits(Context *context)
7696{
7697 const VertexArray *vao = context->getGLState().getVertexArray();
7698
7699 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7700 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7701
7702 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
7703 // If there are no buffered attributes then we should not limit the draw call count.
7704 if (!vao || !mCachedActiveBufferedAttribsMask.any())
7705 {
7706 return;
7707 }
7708
7709 const auto &vertexAttribs = vao->getVertexAttributes();
7710 const auto &vertexBindings = vao->getVertexBindings();
7711
7712 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
7713 {
7714 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
7715 ASSERT(attrib.enabled);
7716
7717 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
7718 ASSERT(context->isGLES1() ||
7719 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
7720
7721 GLint64 limit = attrib.getCachedElementLimit();
7722 if (binding.getDivisor() > 0)
7723 {
7724 mCachedInstancedVertexElementLimit =
7725 std::min(mCachedInstancedVertexElementLimit, limit);
7726 }
7727 else
7728 {
7729 mCachedNonInstancedVertexElementLimit =
7730 std::min(mCachedNonInstancedVertexElementLimit, limit);
7731 }
7732 }
7733}
Jamie Madillc43cdad2018-08-08 15:49:25 -04007734
7735void StateCache::onVertexArrayBindingChange(Context *context)
7736{
7737 updateActiveAttribsMask(context);
7738 updateVertexElementLimits(context);
7739}
7740
7741void StateCache::onProgramExecutableChange(Context *context)
7742{
7743 updateActiveAttribsMask(context);
7744 updateVertexElementLimits(context);
7745}
7746
7747void StateCache::onVertexArraySizeChange(Context *context)
7748{
7749 updateVertexElementLimits(context);
7750}
7751
7752void StateCache::onVertexArrayStateChange(Context *context)
7753{
7754 updateActiveAttribsMask(context);
7755 updateVertexElementLimits(context);
7756}
7757
7758void StateCache::onGLES1ClientStateChange(Context *context)
7759{
7760 updateActiveAttribsMask(context);
7761}
Jamie Madillc29968b2016-01-20 11:17:23 -05007762} // namespace gl